Add ability to show login error from the IMAP server instead of traditional "Unknown...
[squirrelmail.git] / plugins / preview_pane / functions.php
1 <?php
2
3 /**
4 * SquirrelMail Preview Pane Plugin
5 *
6 * @copyright 1999-2014 The SquirrelMail Project Team
7 * @author Paul Lesniewski <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 * Build user options for display on "Display Preferences" page
17 */
18 function 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);
28 $previewPane_autohide = getPref($data_dir, $username, 'previewPane_autohide', 0);
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,
59 'refresh' => SMOPT_REFRESH_NONE,
60 );
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 );
68
69 }
70
71
72 /**
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 */
78 function show_preview_pane()
79 {
80 global $data_dir, $username;
81 $use_previewPane = getPref($data_dir, $username, 'use_previewPane', 0);
82 return (checkForJavascript() && $use_previewPane);
83 }
84
85
86 /**
87 * Adds preview pane open/close (and clear) buttons next to
88 * "provider link"
89 */
90 function preview_pane_open_close_buttons_do()
91 {
92
93 if (!show_preview_pane()) return;
94
95 global $data_dir, $username, $base_uri, $oTemplate;
96 $previewPane_vertical_split = getPref($data_dir, $username, 'previewPane_vertical_split', 0);
97 if ($previewPane_vertical_split)
98 {
99 $orientation = 'cols';
100 $up_arrow = '&larr;';
101 $down_arrow = '&rarr;';
102 }
103 else
104 {
105 $orientation = 'rows';
106 $up_arrow = '&uarr;';
107 $down_arrow = '&darr;';
108 }
109
110
111 $previewPane_size = getPref($data_dir, $username, 'previewPane_size', 300);
112
113 $oTemplate->assign('previewPane_size', $previewPane_size);
114 $oTemplate->assign('base_uri', $base_uri);
115 $oTemplate->assign('orientation', $orientation);
116 $oTemplate->assign('down_arrow', $down_arrow, FALSE);
117 $oTemplate->assign('up_arrow', $up_arrow, FALSE);
118
119 $output = $oTemplate->fetch('plugins/preview_pane/collapse_buttons.tpl');
120
121 return array('provider_link_before' => $output);
122
123 }
124
125
126 /**
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 */
132 function preview_pane_message_list_do()
133 {
134
135 if (!checkForJavascript()) return;
136
137 // globalize $pp_refresh_top, $pp_forceTopURL and $pp_noPageHeader to synch
138 // with other plugins (sent_confirmation, for example)
139 //
140 global $plugins, $archive_mail_button_has_been_printed,
141 $username, $data_dir, $PHP_SELF, $base_uri, $pp_refresh_top,
142 $pp_forceTopURL, $pp_noPageHeader;
143
144
145 sqgetGlobalVar('pp_refresh_top', $pp_refresh_top, SQ_GET);
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 //
153 if ($use_previewPane == 1)
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)
157 {
158 // sqgetGlobalVar('REQUEST_URI', $request_uri, SQ_SERVER);
159 $request_uri = $PHP_SELF;
160 $output .= "<script type=\"text/javascript\" language=\"JavaScript\">\n<!--\n function pp_refresh() { document.location = '$request_uri'; }\n// -->\n</script>\n";
161 }
162
163
164 if ($use_previewPane == 1)
165 {
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=\''
171 . $base_uri . 'plugins/preview_pane/empty_frame.php\'; '))
172
173
174
175 // don't let message list load into preview pane at all
176 //
177 . "\n<script language='JavaScript' type='text/javascript'>\n"
178 . "<!--\n"
179 . "\n"
180 . " if (self.name == 'bottom')\n"
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
193 // if someone else asks for it, force the message list to reload
194 //
195 else if ($pp_refresh_top)
196 $output.= " if (typeof(parent.right.pp_refresh) != 'undefined')\n"
197 . " parent.right.pp_refresh()\n\n";
198
199
200 $output .= " document.location = '" . $base_uri . "plugins/preview_pane/empty_frame.php'\n"
201 . " }\n"
202 . "//-->\n"
203 . "</script>\n";
204 }
205
206 return array('mailbox_index_after' => $output);
207
208 }
209
210
211 /**
212 * Points message targets to open in the preview pane
213 * (and possibly refresh message list as well)
214 */
215 function preview_pane_change_message_target_do($args)
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);
228 $aMsg = $args[3];
229
230 $target = 'bottom';
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
239 // $onclick .= ' onclick="document.location=\'' . $request_uri . '\'; " ';
240 $onclick .= ' setTimeout(\'pp_refresh()\', 500); ';
241 }
242
243 }
244
245
246