Adding comment for future developer(s)
[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
81/**
e1b9b863 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
b5e94525 91 global $data_dir, $username, $base_uri, $oTemplate;
e1b9b863 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
b5e94525 109 $oTemplate->assign('previewPane_size', $previewPane_size);
110 $oTemplate->assign('base_uri', $base_uri);
111 $oTemplate->assign('split', $split);
112 $oTemplate->assign('down_arrow', $down_arrow);
113 $oTemplate->assign('up_arrow', $up_arrow);
e1b9b863 114
b5e94525 115 $output = $oTemplate->fetch('plugins/preview_pane/collapse_buttons.tpl');
e1b9b863 116
117 return array('provider_link_before' => $output);
118
119}
120
121
122/**
505e00aa 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 */
129function preview_pane_message_list_do()
130{
131
132 if (!checkForJavascript()) return;
133
8e455945 134 // globalize $pp_refresh_top, $pp_forceTopURL and $pp_noPageHeader to synch
a22d1671 135 // with other plugins (sent_confirmation, for example)
136 //
505e00aa 137 global $plugins, $archive_mail_button_has_been_printed,
8e455945 138 $username, $data_dir, $PHP_SELF, $base_uri, $pp_refresh_top,
a22d1671 139 $pp_forceTopURL, $pp_noPageHeader;
505e00aa 140
141
8e455945 142 sqgetGlobalVar('pp_refresh_top', $pp_refresh_top, SQ_GET);
505e00aa 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 //
a67cf487 150 if ($use_previewPane == 1)
8e455945 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)
505e00aa 154 {
155// sqgetGlobalVar('REQUEST_URI', $request_uri, SQ_SERVER);
156 $request_uri = $PHP_SELF;
157 $output .= "<script type=\"text/javascript\">\n<!--\n function pp_refresh() { document.location = '$request_uri'; }\n// -->\n</script>\n";
158 }
159
160
161 if ($use_previewPane == 1)
162 {
6f62ecc1 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=\''
a22d1671 168 . $base_uri . 'plugins/preview_pane/empty_frame.php\'; '))
6f62ecc1 169
505e00aa 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"
a22d1671 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
8e455945 190 // if someone else asks for it, force the message list to reload
191 //
192 else if ($pp_refresh_top)
cb1bb466 193 $output.= " if (typeof(parent.right.pp_refresh) != 'undefined')\n"
194 . " parent.right.pp_refresh()\n\n";
8e455945 195
196
a22d1671 197 $output .= " document.location = '" . $base_uri . "plugins/preview_pane/empty_frame.php'\n"
505e00aa 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 */
213function preview_pane_change_message_target_do()
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
227 $target = 'bottom';
228 if ($pp_refresh_message_list)
229// introduce a delay so read messages actually refresh after they are read
230// $onclick .= ' onclick="document.location=\'' . $request_uri . '\'; " ';
231 $onclick .= ' setTimeout(\'pp_refresh()\', 500); ';
232 }
233
234}
235
236
237