4 * SquirrelMail Preview Pane Plugin
6 * @copyright 1999-2010 The SquirrelMail Project Team
7 * @author Paul Lesniewski <paul@squirrelmail.org>
8 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
11 * @subpackage preview_pane
16 * Build user options for display on "Display Preferences" page
18 function preview_pane_show_options_do()
21 if (!checkForJavascript()) return;
23 global $data_dir, $username;
24 $use_previewPane = getPref($data_dir, $username, 'use_previewPane', 0);
25 $previewPane_vertical_split = getPref($data_dir, $username, 'previewPane_vertical_split', 0);
26 $previewPane_size = getPref($data_dir, $username, 'previewPane_size', 300);
27 $pp_refresh_message_list = getPref($data_dir, $username, 'pp_refresh_message_list', 1);
28 $previewPane_autohide = getPref($data_dir, $username, 'previewPane_autohide', 0);
32 $optpage_data['vals'][1][] = array(
33 'name' => 'use_previewPane',
34 'caption' => _("Show Message Preview Pane"),
35 'type' => SMOPT_TYPE_BOOLEAN
,
36 'initial_value' => $use_previewPane,
37 'refresh' => SMOPT_REFRESH_ALL
,
39 $optpage_data['vals'][1][] = array(
40 'name' => 'previewPane_vertical_split',
41 'caption' => _("Split Preview Pane Vertically"),
42 'type' => SMOPT_TYPE_BOOLEAN
,
43 'initial_value' => $previewPane_vertical_split,
44 'refresh' => SMOPT_REFRESH_ALL
,
46 $optpage_data['vals'][1][] = array(
47 'name' => 'previewPane_size',
48 'caption' => _("Message Preview Pane Size"),
49 'type' => SMOPT_TYPE_INTEGER
,
50 'initial_value' => $previewPane_size,
51 'refresh' => SMOPT_REFRESH_ALL
,
52 'size' => SMOPT_SIZE_TINY
,
54 $optpage_data['vals'][1][] = array(
55 'name' => 'pp_refresh_message_list',
56 'caption' => _("Always Refresh Message List<br />When Using Preview Pane"),
57 'type' => SMOPT_TYPE_BOOLEAN
,
58 'initial_value' => $pp_refresh_message_list,
59 'refresh' => SMOPT_REFRESH_NONE
,
61 $optpage_data['vals'][1][] = array(
62 'name' => 'previewPane_autohide',
63 'caption' => _("Automatically Hide Preview Pane<br />When Not Reading Messages"),
64 'type' => SMOPT_TYPE_BOOLEAN
,
65 'initial_value' => $previewPane_autohide,
66 'refresh' => SMOPT_REFRESH_ALL
,
73 * This function determines if the preview pane is in use
74 * (and JavaScript is available)
76 * @return boolean TRUE if the preview pane should be showing currently.
78 function show_preview_pane()
80 global $data_dir, $username;
81 $use_previewPane = getPref($data_dir, $username, 'use_previewPane', 0);
82 return (checkForJavascript() && $use_previewPane);
87 * Adds preview pane open/close (and clear) buttons next to
90 function preview_pane_open_close_buttons_do()
93 if (!show_preview_pane()) return;
95 global $data_dir, $username, $base_uri, $oTemplate;
96 $previewPane_vertical_split = getPref($data_dir, $username, 'previewPane_vertical_split', 0);
97 if ($previewPane_vertical_split)
99 $orientation = 'cols';
100 $up_arrow = '←';
101 $down_arrow = '→';
105 $orientation = 'rows';
106 $up_arrow = '↑';
107 $down_arrow = '↓';
111 $previewPane_size = getPref($data_dir, $username, 'previewPane_size', 300);
113 $oTemplate->assign('previewPane_size', $previewPane_size);
114 $oTemplate->assign('base_uri', $base_uri);
115 $oTemplate->assign('orientation', $orientation);
116 $oTemplate->assign('down_arrow', $down_arrow, FALSE);
117 $oTemplate->assign('up_arrow', $up_arrow, FALSE);
119 $output = $oTemplate->fetch('plugins/preview_pane/collapse_buttons.tpl');
121 return array('provider_link_before' => $output);
127 * Construct button that clears out any preview pane
128 * contents and inserts JavaScript function used by
129 * message subject link onclick handler. Also disallows
130 * the message list to be loaded into the bottom frame.
132 function preview_pane_message_list_do()
135 if (!checkForJavascript()) return;
137 // globalize $pp_refresh_top, $pp_forceTopURL and $pp_noPageHeader to synch
138 // with other plugins (sent_confirmation, for example)
140 global $plugins, $archive_mail_button_has_been_printed,
141 $username, $data_dir, $PHP_SELF, $base_uri, $pp_refresh_top,
142 $pp_forceTopURL, $pp_noPageHeader;
145 sqgetGlobalVar('pp_refresh_top', $pp_refresh_top, SQ_GET
);
147 $use_previewPane = getPref($data_dir, $username, 'use_previewPane', 0);
150 // add refresh function called from code built in function
151 // preview_pane_change_message_target_do()
153 if ($use_previewPane == 1)
154 // Bah, let's put this in anyway (even when the "always refresh thing is off),
155 // in case someone else wants to use it
156 // && getPref($data_dir, $username, 'pp_refresh_message_list', 1) == 1)
158 // sqgetGlobalVar('REQUEST_URI', $request_uri, SQ_SERVER);
159 $request_uri = $PHP_SELF;
160 $output .= "<script type=\"text/javascript\" language=\"JavaScript\">\n<!--\n function pp_refresh() { document.location = '$request_uri'; }\n// -->\n</script>\n";
164 if ($use_previewPane == 1)
166 // why isn't this already available?
167 include_once(SM_PATH
. 'functions/forms.php');
169 $output .= addButton(_("Clear Preview"), 'clear_preview',
170 array('onclick' => 'parent.bottom.document.location=\''
171 . $base_uri . 'plugins/preview_pane/empty_frame.php\'; '))
175 // don't let message list load into preview pane at all
177 . "\n<script language='JavaScript' type='text/javascript'>\n"
180 . " if (self.name == 'bottom')\n"
183 // NOTE: we can also force the top frame to the URL that was being
184 // loaded in the bottom, but this is usually overkill...
185 // unless another plugin told us to do so (such as sent_confirmation)
186 if ($pp_forceTopURL == 'yes')
188 // $output .= " parent.right.document.location = '" . $_SERVER['REQUEST_URI'] . "&pp=yes';\n";
189 $output .= " parent.right.document.location = '" . $PHP_SELF . "&pp=yes';\n";
193 // if someone else asks for it, force the message list to reload
195 else if ($pp_refresh_top)
196 $output.= " if (typeof(parent.right.pp_refresh) != 'undefined')\n"
197 . " parent.right.pp_refresh()\n\n";
200 $output .= " document.location = '" . $base_uri . "plugins/preview_pane/empty_frame.php'\n"
206 return array('mailbox_index_after' => $output);
212 * Points message targets to open in the preview pane
213 * (and possibly refresh message list as well)
215 function preview_pane_change_message_target_do($args)
218 if (!checkForJavascript()) return;
220 global $data_dir, $username, $target, $onclick, $PHP_SELF;
221 // sqgetGlobalVar('REQUEST_URI', $request_uri, SQ_SERVER);
222 $request_uri = $PHP_SELF;
225 if (getPref($data_dir, $username, 'use_previewPane', 0) == 1)
227 $pp_refresh_message_list = getPref($data_dir, $username, 'pp_refresh_message_list', 1);
233 // introduce a delay so read messages actually
234 // refresh after they are read, but only if they
235 // have not already been seen
237 if ($pp_refresh_message_list && empty($aMsg['FLAGS']['\seen']))
238 // old code without refresh delay
239 // $onclick .= ' onclick="document.location=\'' . $request_uri . '\'; " ';
240 $onclick .= ' setTimeout(\'pp_refresh()\', 500); ';