Add (un)collapse buttons
[squirrelmail.git] / plugins / preview_pane / functions.php
CommitLineData
505e00aa 1<?php
2
3/**
4 * SquirrelMail Preview Pane Plugin
5 *
6 * @copyright &copy; 1999-2007 The SquirrelMail Project Team
7 * @author Paul Lesneiwski <paul@squirrelmail.org>
8 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
9 * @version $Id$
10 * @package plugins
11 * @subpackage preview_pane
12 *
13 */
14
15
16/**
17 * Build user options for display on "Display Preferences" page
18 *
19 */
20function preview_pane_show_options_do()
21{
22
23 if (!checkForJavascript()) return;
24
25 global $data_dir, $username;
26 $use_previewPane = getPref($data_dir, $username, 'use_previewPane', 0);
27 $previewPane_vertical_split = getPref($data_dir, $username, 'previewPane_vertical_split', 0);
28 $previewPane_size = getPref($data_dir, $username, 'previewPane_size', 300);
29 $pp_refresh_message_list = getPref($data_dir, $username, 'pp_refresh_message_list', 1);
30
31
32 global $optpage_data;
33 $optpage_data['vals'][1][] = array(
34 'name' => 'use_previewPane',
35 'caption' => _("Show Message Preview Pane"),
36 'type' => SMOPT_TYPE_BOOLEAN,
37 'initial_value' => $use_previewPane,
38 'refresh' => SMOPT_REFRESH_ALL,
39 );
40 $optpage_data['vals'][1][] = array(
41 'name' => 'previewPane_vertical_split',
42 'caption' => _("Split Preview Pane Vertically"),
43 'type' => SMOPT_TYPE_BOOLEAN,
44 'initial_value' => $previewPane_vertical_split,
45 'refresh' => SMOPT_REFRESH_ALL,
46 );
47 $optpage_data['vals'][1][] = array(
48 'name' => 'previewPane_size',
49 'caption' => _("Message Preview Pane Size"),
50 'type' => SMOPT_TYPE_INTEGER,
51 'initial_value' => $previewPane_size,
52 'refresh' => SMOPT_REFRESH_ALL,
53 'size' => SMOPT_SIZE_TINY,
54 );
55 $optpage_data['vals'][1][] = array(
56 'name' => 'pp_refresh_message_list',
57 'caption' => _("Always Refresh Message List<br />When Using Preview Pane"),
58 'type' => SMOPT_TYPE_BOOLEAN,
59 'initial_value' => $pp_refresh_message_list,
60 'refresh' => SMOPT_REFRESH_ALL,
61 );
62
63}
64
65
66/**
67 * This function determines if the preview pane is in use
68 * (and JavaScript is available)
69 *
70 * @return boolean TRUE if the preview pane should be showing currently.
71 *
72 */
73function show_preview_pane()
74{
e1b9b863 75 global $data_dir, $username;
505e00aa 76 $use_previewPane = getPref($data_dir, $username, 'use_previewPane', 0);
77 return (checkForJavascript() && $use_previewPane);
78}
79
80
e1b9b863 81/**
82 * Adds preview pane open/close (and clear) buttons next to
83 * "provider link"
84 *
85 */
86function preview_pane_open_close_buttons_do()
87{
88
89 if (!show_preview_pane()) return;
90
91 global $data_dir, $username, $base_uri;
92 $previewPane_vertical_split = getPref($data_dir, $username, 'previewPane_vertical_split', 0);
93 if ($previewPane_vertical_split)
94 {
95 $split = 'cols';
96 $up_arrow = '&larr;';
97 $down_arrow = '&rarr;';
98 }
99 else
100 {
101 $split = 'rows';
102 $up_arrow = '&uarr;';
103 $down_arrow = '&darr;';
104 }
105
106
107 $previewPane_size = getPref($data_dir, $username, 'previewPane_size', 300);
108
109
110 $output = "\n<script type=\"text/javascript\">\n"
111 . "<!--\n"
112 . " function set_preview_pane_size(new_size)\n"
113 . " {\n"
114 . " if (document.all)\n"
115 . " {\n"
116 . " parent.document.all[\"fs2\"].$split = \"*, \" + new_size;\n"
117 . " }\n"
118 . " else if (this.document.getElementById)\n"
119 . " {\n"
120 . " parent.document.getElementById(\"fs2\").$split = \"*, \" + new_size;\n"
121 . " }\n"
122 . " }\n"
123 . "// -->\n</script>\n"
124 . '<form style="margin:0">'
125 . '<input type="button" value="' . $down_arrow . '" onclick="set_preview_pane_size(0)" />'
126 . '<input type="button" value="X" onclick="parent.bottom.document.location=\'' . $base_uri . 'plugins/preview_pane/empty_frame.php\'" />'
127 . '<input type="button" value="' . $up_arrow . '" onclick="set_preview_pane_size(' . $previewPane_size . ')" />'
128 . '</form>';
129
130 return array('provider_link_before' => $output);
131
132}
133
134
505e00aa 135/**
136 * Construct button that clears out any preview pane
137 * contents and inserts JavaScript function used by
138 * message subject link onclick handler. Also disallows
139 * the message list to be loaded into the bottom frame.
140 *
141 */
142function preview_pane_message_list_do()
143{
144
145 if (!checkForJavascript()) return;
146
8e455945 147 // globalize $pp_refresh_top, $pp_forceTopURL and $pp_noPageHeader to synch
a22d1671 148 // with other plugins (sent_confirmation, for example)
149 //
505e00aa 150 global $plugins, $archive_mail_button_has_been_printed,
8e455945 151 $username, $data_dir, $PHP_SELF, $base_uri, $pp_refresh_top,
a22d1671 152 $pp_forceTopURL, $pp_noPageHeader;
505e00aa 153
154
8e455945 155 sqgetGlobalVar('pp_refresh_top', $pp_refresh_top, SQ_GET);
505e00aa 156 $output = '';
157 $use_previewPane = getPref($data_dir, $username, 'use_previewPane', 0);
158
159
160 // add refresh function called from code built in function
161 // preview_pane_change_message_target_do()
162 //
a67cf487 163 if ($use_previewPane == 1)
8e455945 164// Bah, let's put this in anyway (even when the "always refresh thing is off),
165// in case someone else wants to use it
166// && getPref($data_dir, $username, 'pp_refresh_message_list', 1) == 1)
505e00aa 167 {
168// sqgetGlobalVar('REQUEST_URI', $request_uri, SQ_SERVER);
169 $request_uri = $PHP_SELF;
170 $output .= "<script type=\"text/javascript\">\n<!--\n function pp_refresh() { document.location = '$request_uri'; }\n// -->\n</script>\n";
171 }
172
173
174 if ($use_previewPane == 1)
175 {
6f62ecc1 176 // why isn't this already available?
177 include_once(SM_PATH . 'functions/forms.php');
178
179 $output .= addButton(_("Clear Preview"), 'clear_preview',
180 array('onclick' => 'parent.bottom.document.location=\''
a22d1671 181 . $base_uri . 'plugins/preview_pane/empty_frame.php\'; '))
6f62ecc1 182
505e00aa 183
184
185 // don't let message list load into preview pane at all
186 //
187 . "\n<script language='javascript' type='text/javascript'>\n"
188 . "<!--\n"
189 . "\n"
190 . " if (self.name == 'bottom')\n"
a22d1671 191 . " {\n";
192
193// NOTE: we can also force the top frame to the URL that was being
194// loaded in the bottom, but this is usually overkill...
195// unless another plugin told us to do so (such as sent_confirmation)
196 if ($pp_forceTopURL == 'yes')
197 {
198// $output .= " parent.right.document.location = '" . $_SERVER['REQUEST_URI'] . "&pp=yes';\n";
199 $output .= " parent.right.document.location = '" . $PHP_SELF . "&pp=yes';\n";
200 }
201
202
8e455945 203 // if someone else asks for it, force the message list to reload
204 //
205 else if ($pp_refresh_top)
cb1bb466 206 $output.= " if (typeof(parent.right.pp_refresh) != 'undefined')\n"
207 . " parent.right.pp_refresh()\n\n";
8e455945 208
209
a22d1671 210 $output .= " document.location = '" . $base_uri . "plugins/preview_pane/empty_frame.php'\n"
505e00aa 211 . " }\n"
212 . "//-->\n"
213 . "</script>\n";
214 }
215
216 return array('mailbox_index_after' => $output);
217
218}
219
220
221/**
222 * Points message targets to open in the preview pane
223 * (and possibly refresh message list as well)
224 *
225 */
226function preview_pane_change_message_target_do()
227{
228
229 if (!checkForJavascript()) return;
230
231 global $data_dir, $username, $target, $onclick, $PHP_SELF;
232// sqgetGlobalVar('REQUEST_URI', $request_uri, SQ_SERVER);
233 $request_uri = $PHP_SELF;
234
235
236 if (getPref($data_dir, $username, 'use_previewPane', 0) == 1)
237 {
238 $pp_refresh_message_list = getPref($data_dir, $username, 'pp_refresh_message_list', 1);
239
240 $target = 'bottom';
241 if ($pp_refresh_message_list)
242// introduce a delay so read messages actually refresh after they are read
243// $onclick .= ' onclick="document.location=\'' . $request_uri . '\'; " ';
244 $onclick .= ' setTimeout(\'pp_refresh()\', 500); ';
245 }
246
247}
248
249
250