Happy New Year
[squirrelmail.git] / plugins / preview_pane / functions.php
CommitLineData
505e00aa 1<?php
2
3/**
d4e46166 4 * SquirrelMail Preview Pane Plugin
5 *
c4faef33 6 * @copyright 1999-2020 The SquirrelMail Project Team
37779891 7 * @author Paul Lesniewski <paul@squirrelmail.org>
d4e46166 8 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
9 * @version $Id$
10 * @package plugins
11 * @subpackage preview_pane
12 */
505e00aa 13
14
15/**
d4e46166 16 * Build user options for display on "Display Preferences" page
17 */
505e00aa 18function preview_pane_show_options_do()
19{
20
21 if (!checkForJavascript()) return;
22
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);
93081a3e 28 $previewPane_autohide = getPref($data_dir, $username, 'previewPane_autohide', 0);
505e00aa 29
30
31 global $optpage_data;
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,
38 );
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,
45 );
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,
53 );
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,
010ff205 59 'refresh' => SMOPT_REFRESH_NONE,
505e00aa 60 );
93081a3e 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,
67 );
505e00aa 68
69}
70
71
72/**
d4e46166 73 * This function determines if the preview pane is in use
74 * (and JavaScript is available)
75 *
76 * @return boolean TRUE if the preview pane should be showing currently.
77 */
505e00aa 78function show_preview_pane()
79{
e1b9b863 80 global $data_dir, $username;
505e00aa 81 $use_previewPane = getPref($data_dir, $username, 'use_previewPane', 0);
82 return (checkForJavascript() && $use_previewPane);
83}
84
85
86/**
d4e46166 87 * Adds preview pane open/close (and clear) buttons next to
88 * "provider link"
89 */
e1b9b863 90function preview_pane_open_close_buttons_do()
91{
92
93 if (!show_preview_pane()) return;
94
b5e94525 95 global $data_dir, $username, $base_uri, $oTemplate;
e1b9b863 96 $previewPane_vertical_split = getPref($data_dir, $username, 'previewPane_vertical_split', 0);
97 if ($previewPane_vertical_split)
98 {
010ff205 99 $orientation = 'cols';
e1b9b863 100 $up_arrow = '&larr;';
101 $down_arrow = '&rarr;';
102 }
103 else
104 {
010ff205 105 $orientation = 'rows';
e1b9b863 106 $up_arrow = '&uarr;';
107 $down_arrow = '&darr;';
108 }
109
110
111 $previewPane_size = getPref($data_dir, $username, 'previewPane_size', 300);
112
b5e94525 113 $oTemplate->assign('previewPane_size', $previewPane_size);
114 $oTemplate->assign('base_uri', $base_uri);
010ff205 115 $oTemplate->assign('orientation', $orientation);
4c5be18d 116 $oTemplate->assign('down_arrow', $down_arrow, FALSE);
117 $oTemplate->assign('up_arrow', $up_arrow, FALSE);
e1b9b863 118
b5e94525 119 $output = $oTemplate->fetch('plugins/preview_pane/collapse_buttons.tpl');
e1b9b863 120
121 return array('provider_link_before' => $output);
122
123}
124
125
126/**
d4e46166 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.
131 */
505e00aa 132function preview_pane_message_list_do()
133{
134
135 if (!checkForJavascript()) return;
136
8e455945 137 // globalize $pp_refresh_top, $pp_forceTopURL and $pp_noPageHeader to synch
a22d1671 138 // with other plugins (sent_confirmation, for example)
139 //
505e00aa 140 global $plugins, $archive_mail_button_has_been_printed,
8e455945 141 $username, $data_dir, $PHP_SELF, $base_uri, $pp_refresh_top,
a22d1671 142 $pp_forceTopURL, $pp_noPageHeader;
505e00aa 143
144
8e455945 145 sqgetGlobalVar('pp_refresh_top', $pp_refresh_top, SQ_GET);
505e00aa 146 $output = '';
147 $use_previewPane = getPref($data_dir, $username, 'use_previewPane', 0);
148
149
150 // add refresh function called from code built in function
151 // preview_pane_change_message_target_do()
152 //
a67cf487 153 if ($use_previewPane == 1)
8e455945 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)
505e00aa 157 {
158// sqgetGlobalVar('REQUEST_URI', $request_uri, SQ_SERVER);
159 $request_uri = $PHP_SELF;
010ff205 160 $output .= "<script type=\"text/javascript\" language=\"JavaScript\">\n<!--\n function pp_refresh() { document.location = '$request_uri'; }\n// -->\n</script>\n";
505e00aa 161 }
162
163
164 if ($use_previewPane == 1)
165 {
6f62ecc1 166 // why isn't this already available?
167 include_once(SM_PATH . 'functions/forms.php');
168
169 $output .= addButton(_("Clear Preview"), 'clear_preview',
170 array('onclick' => 'parent.bottom.document.location=\''
a22d1671 171 . $base_uri . 'plugins/preview_pane/empty_frame.php\'; '))
6f62ecc1 172
505e00aa 173
174
175 // don't let message list load into preview pane at all
176 //
010ff205 177 . "\n<script language='JavaScript' type='text/javascript'>\n"
505e00aa 178 . "<!--\n"
179 . "\n"
180 . " if (self.name == 'bottom')\n"
a22d1671 181 . " {\n";
182
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')
187 {
188// $output .= " parent.right.document.location = '" . $_SERVER['REQUEST_URI'] . "&pp=yes';\n";
189 $output .= " parent.right.document.location = '" . $PHP_SELF . "&pp=yes';\n";
190 }
191
192
8e455945 193 // if someone else asks for it, force the message list to reload
194 //
195 else if ($pp_refresh_top)
cb1bb466 196 $output.= " if (typeof(parent.right.pp_refresh) != 'undefined')\n"
197 . " parent.right.pp_refresh()\n\n";
8e455945 198
199
a22d1671 200 $output .= " document.location = '" . $base_uri . "plugins/preview_pane/empty_frame.php'\n"
505e00aa 201 . " }\n"
202 . "//-->\n"
203 . "</script>\n";
204 }
205
206 return array('mailbox_index_after' => $output);
207
208}
209
210
211/**
d4e46166 212 * Points message targets to open in the preview pane
213 * (and possibly refresh message list as well)
214 */
010ff205 215function preview_pane_change_message_target_do($args)
505e00aa 216{
217
218 if (!checkForJavascript()) return;
219
220 global $data_dir, $username, $target, $onclick, $PHP_SELF;
221// sqgetGlobalVar('REQUEST_URI', $request_uri, SQ_SERVER);
222 $request_uri = $PHP_SELF;
223
224
225 if (getPref($data_dir, $username, 'use_previewPane', 0) == 1)
226 {
227 $pp_refresh_message_list = getPref($data_dir, $username, 'pp_refresh_message_list', 1);
010ff205 228 $aMsg = $args[3];
505e00aa 229
230 $target = 'bottom';
010ff205 231
232
233 // introduce a delay so read messages actually
234 // refresh after they are read, but only if they
235 // have not already been seen
236 //
237 if ($pp_refresh_message_list && empty($aMsg['FLAGS']['\seen']))
238// old code without refresh delay
505e00aa 239// $onclick .= ' onclick="document.location=\'' . $request_uri . '\'; " ';
240 $onclick .= ' setTimeout(\'pp_refresh()\', 500); ';
241 }
242
243}
244
245
246