fef1e0cf260d1f46ee874f92095f20c85653899e
[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_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 */
73 function show_preview_pane()
74 {
75 $use_previewPane = getPref($data_dir, $username, 'use_previewPane', 0);
76 return (checkForJavascript() && $use_previewPane);
77 }
78
79
80 /**
81 * Construct button that clears out any preview pane
82 * contents and inserts JavaScript function used by
83 * message subject link onclick handler. Also disallows
84 * the message list to be loaded into the bottom frame.
85 *
86 */
87 function preview_pane_message_list_do()
88 {
89
90 if (!checkForJavascript()) return;
91
92 // globalize $pp_refresh_top, $pp_forceTopURL and $pp_noPageHeader to synch
93 // with other plugins (sent_confirmation, for example)
94 //
95 global $plugins, $archive_mail_button_has_been_printed,
96 $username, $data_dir, $PHP_SELF, $base_uri, $pp_refresh_top,
97 $pp_forceTopURL, $pp_noPageHeader;
98
99
100 sqgetGlobalVar('pp_refresh_top', $pp_refresh_top, SQ_GET);
101 $output = '';
102 $use_previewPane = getPref($data_dir, $username, 'use_previewPane', 0);
103
104
105 // add refresh function called from code built in function
106 // preview_pane_change_message_target_do()
107 //
108 if ($use_previewPane == 1
109 // Bah, let's put this in anyway (even when the "always refresh thing is off),
110 // in case someone else wants to use it
111 // && getPref($data_dir, $username, 'pp_refresh_message_list', 1) == 1)
112 {
113 // sqgetGlobalVar('REQUEST_URI', $request_uri, SQ_SERVER);
114 $request_uri = $PHP_SELF;
115 $output .= "<script type=\"text/javascript\">\n<!--\n function pp_refresh() { document.location = '$request_uri'; }\n// -->\n</script>\n";
116 }
117
118
119 if ($use_previewPane == 1)
120 {
121 // why isn't this already available?
122 include_once(SM_PATH . 'functions/forms.php');
123
124 $output .= addButton(_("Clear Preview"), 'clear_preview',
125 array('onclick' => 'parent.bottom.document.location=\''
126 . $base_uri . 'plugins/preview_pane/empty_frame.php\'; '))
127
128
129
130 // don't let message list load into preview pane at all
131 //
132 . "\n<script language='javascript' type='text/javascript'>\n"
133 . "<!--\n"
134 . "\n"
135 . " if (self.name == 'bottom')\n"
136 . " {\n";
137
138 // NOTE: we can also force the top frame to the URL that was being
139 // loaded in the bottom, but this is usually overkill...
140 // unless another plugin told us to do so (such as sent_confirmation)
141 if ($pp_forceTopURL == 'yes')
142 {
143 // $output .= " parent.right.document.location = '" . $_SERVER['REQUEST_URI'] . "&pp=yes';\n";
144 $output .= " parent.right.document.location = '" . $PHP_SELF . "&pp=yes';\n";
145 }
146
147
148 // if someone else asks for it, force the message list to reload
149 //
150 else if ($pp_refresh_top)
151 echo " if (typeof(parent.right.pp_refresh) != 'undefined')\n"
152 . " parent.right.pp_refresh()\n\n";
153
154
155 $output .= " document.location = '" . $base_uri . "plugins/preview_pane/empty_frame.php'\n"
156 . " }\n"
157 . "//-->\n"
158 . "</script>\n";
159 }
160
161 return array('mailbox_index_after' => $output);
162
163 }
164
165
166 /**
167 * Points message targets to open in the preview pane
168 * (and possibly refresh message list as well)
169 *
170 */
171 function preview_pane_change_message_target_do()
172 {
173
174 if (!checkForJavascript()) return;
175
176 global $data_dir, $username, $target, $onclick, $PHP_SELF;
177 // sqgetGlobalVar('REQUEST_URI', $request_uri, SQ_SERVER);
178 $request_uri = $PHP_SELF;
179
180
181 if (getPref($data_dir, $username, 'use_previewPane', 0) == 1)
182 {
183 $pp_refresh_message_list = getPref($data_dir, $username, 'pp_refresh_message_list', 1);
184
185 $target = 'bottom';
186 if ($pp_refresh_message_list)
187 // introduce a delay so read messages actually refresh after they are read
188 // $onclick .= ' onclick="document.location=\'' . $request_uri . '\'; " ';
189 $onclick .= ' setTimeout(\'pp_refresh()\', 500); ';
190 }
191
192 }
193
194
195