Update preview pane functionality so it only refreshes message list when viewing...
[squirrelmail.git] / plugins / preview_pane / functions.php
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 */
20 function 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_NONE,
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 */
73 function show_preview_pane()
74 {
75 global $data_dir, $username;
76 $use_previewPane = getPref($data_dir, $username, 'use_previewPane', 0);
77 return (checkForJavascript() && $use_previewPane);
78 }
79
80
81 /**
82 * Adds preview pane open/close (and clear) buttons next to
83 * "provider link"
84 *
85 */
86 function preview_pane_open_close_buttons_do()
87 {
88
89 if (!show_preview_pane()) return;
90
91 global $data_dir, $username, $base_uri, $oTemplate;
92 $previewPane_vertical_split = getPref($data_dir, $username, 'previewPane_vertical_split', 0);
93 if ($previewPane_vertical_split)
94 {
95 $orientation = 'cols';
96 $up_arrow = '&larr;';
97 $down_arrow = '&rarr;';
98 }
99 else
100 {
101 $orientation = 'rows';
102 $up_arrow = '&uarr;';
103 $down_arrow = '&darr;';
104 }
105
106
107 $previewPane_size = getPref($data_dir, $username, 'previewPane_size', 300);
108
109 $oTemplate->assign('previewPane_size', $previewPane_size);
110 $oTemplate->assign('base_uri', $base_uri);
111 $oTemplate->assign('orientation', $orientation);
112 $oTemplate->assign('down_arrow', $down_arrow);
113 $oTemplate->assign('up_arrow', $up_arrow);
114
115 $output = $oTemplate->fetch('plugins/preview_pane/collapse_buttons.tpl');
116
117 return array('provider_link_before' => $output);
118
119 }
120
121
122 /**
123 * Construct button that clears out any preview pane
124 * contents and inserts JavaScript function used by
125 * message subject link onclick handler. Also disallows
126 * the message list to be loaded into the bottom frame.
127 *
128 */
129 function preview_pane_message_list_do()
130 {
131
132 if (!checkForJavascript()) return;
133
134 // globalize $pp_refresh_top, $pp_forceTopURL and $pp_noPageHeader to synch
135 // with other plugins (sent_confirmation, for example)
136 //
137 global $plugins, $archive_mail_button_has_been_printed,
138 $username, $data_dir, $PHP_SELF, $base_uri, $pp_refresh_top,
139 $pp_forceTopURL, $pp_noPageHeader;
140
141
142 sqgetGlobalVar('pp_refresh_top', $pp_refresh_top, SQ_GET);
143 $output = '';
144 $use_previewPane = getPref($data_dir, $username, 'use_previewPane', 0);
145
146
147 // add refresh function called from code built in function
148 // preview_pane_change_message_target_do()
149 //
150 if ($use_previewPane == 1)
151 // Bah, let's put this in anyway (even when the "always refresh thing is off),
152 // in case someone else wants to use it
153 // && getPref($data_dir, $username, 'pp_refresh_message_list', 1) == 1)
154 {
155 // sqgetGlobalVar('REQUEST_URI', $request_uri, SQ_SERVER);
156 $request_uri = $PHP_SELF;
157 $output .= "<script type=\"text/javascript\" language=\"JavaScript\">\n<!--\n function pp_refresh() { document.location = '$request_uri'; }\n// -->\n</script>\n";
158 }
159
160
161 if ($use_previewPane == 1)
162 {
163 // why isn't this already available?
164 include_once(SM_PATH . 'functions/forms.php');
165
166 $output .= addButton(_("Clear Preview"), 'clear_preview',
167 array('onclick' => 'parent.bottom.document.location=\''
168 . $base_uri . 'plugins/preview_pane/empty_frame.php\'; '))
169
170
171
172 // don't let message list load into preview pane at all
173 //
174 . "\n<script language='JavaScript' type='text/javascript'>\n"
175 . "<!--\n"
176 . "\n"
177 . " if (self.name == 'bottom')\n"
178 . " {\n";
179
180 // NOTE: we can also force the top frame to the URL that was being
181 // loaded in the bottom, but this is usually overkill...
182 // unless another plugin told us to do so (such as sent_confirmation)
183 if ($pp_forceTopURL == 'yes')
184 {
185 // $output .= " parent.right.document.location = '" . $_SERVER['REQUEST_URI'] . "&pp=yes';\n";
186 $output .= " parent.right.document.location = '" . $PHP_SELF . "&pp=yes';\n";
187 }
188
189
190 // if someone else asks for it, force the message list to reload
191 //
192 else if ($pp_refresh_top)
193 $output.= " if (typeof(parent.right.pp_refresh) != 'undefined')\n"
194 . " parent.right.pp_refresh()\n\n";
195
196
197 $output .= " document.location = '" . $base_uri . "plugins/preview_pane/empty_frame.php'\n"
198 . " }\n"
199 . "//-->\n"
200 . "</script>\n";
201 }
202
203 return array('mailbox_index_after' => $output);
204
205 }
206
207
208 /**
209 * Points message targets to open in the preview pane
210 * (and possibly refresh message list as well)
211 *
212 */
213 function preview_pane_change_message_target_do($args)
214 {
215
216 if (!checkForJavascript()) return;
217
218 global $data_dir, $username, $target, $onclick, $PHP_SELF;
219 // sqgetGlobalVar('REQUEST_URI', $request_uri, SQ_SERVER);
220 $request_uri = $PHP_SELF;
221
222
223 if (getPref($data_dir, $username, 'use_previewPane', 0) == 1)
224 {
225 $pp_refresh_message_list = getPref($data_dir, $username, 'pp_refresh_message_list', 1);
226 $aMsg = $args[3];
227
228 $target = 'bottom';
229
230
231 // introduce a delay so read messages actually
232 // refresh after they are read, but only if they
233 // have not already been seen
234 //
235 if ($pp_refresh_message_list && empty($aMsg['FLAGS']['\seen']))
236 // old code without refresh delay
237 // $onclick .= ' onclick="document.location=\'' . $request_uri . '\'; " ';
238 $onclick .= ' setTimeout(\'pp_refresh()\', 500); ';
239 }
240
241 }
242
243
244