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