Add preview pane to advanced default template. This serves as an example of how...
[squirrelmail.git] / plugins / preview_pane / functions.php
... / ...
CommitLineData
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{
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 */
87function preview_pane_message_list_do()
88{
89
90 if (!checkForJavascript()) return;
91
92 global $plugins, $archive_mail_button_has_been_printed,
93 $username, $data_dir, $PHP_SELF, $base_uri;
94
95
96 $output = '';
97 $use_previewPane = getPref($data_dir, $username, 'use_previewPane', 0);
98
99
100 // add refresh function called from code built in function
101 // preview_pane_change_message_target_do()
102 //
103 if ($use_previewPane == 1
104 && getPref($data_dir, $username, 'pp_refresh_message_list', 1) == 1)
105 {
106// sqgetGlobalVar('REQUEST_URI', $request_uri, SQ_SERVER);
107 $request_uri = $PHP_SELF;
108 $output .= "<script type=\"text/javascript\">\n<!--\n function pp_refresh() { document.location = '$request_uri'; }\n// -->\n</script>\n";
109 }
110
111
112 if ($use_previewPane == 1)
113 {
114 $output .= '<input type="button" value="' . _("Clear Preview")
115 . '" onclick="parent.bottom.document.location=\'' . SM_PATH
116 . 'plugins/preview_pane/empty_frame.php\'" />'
117
118
119 // don't let message list load into preview pane at all
120 //
121 . "\n<script language='javascript' type='text/javascript'>\n"
122 . "<!--\n"
123 . "\n"
124 . " if (self.name == 'bottom')\n"
125 . " {\n"
126 . " document.location = '" . $base_uri . "plugins/preview_pane/empty_frame.php'\n"
127 . " }\n"
128 . "//-->\n"
129 . "</script>\n";
130 }
131
132 return array('mailbox_index_after' => $output);
133
134}
135
136
137/**
138 * Points message targets to open in the preview pane
139 * (and possibly refresh message list as well)
140 *
141 */
142function preview_pane_change_message_target_do()
143{
144
145 if (!checkForJavascript()) return;
146
147 global $data_dir, $username, $target, $onclick, $PHP_SELF;
148// sqgetGlobalVar('REQUEST_URI', $request_uri, SQ_SERVER);
149 $request_uri = $PHP_SELF;
150
151
152 if (getPref($data_dir, $username, 'use_previewPane', 0) == 1)
153 {
154 $pp_refresh_message_list = getPref($data_dir, $username, 'pp_refresh_message_list', 1);
155
156 $target = 'bottom';
157 if ($pp_refresh_message_list)
158// introduce a delay so read messages actually refresh after they are read
159// $onclick .= ' onclick="document.location=\'' . $request_uri . '\'; " ';
160 $onclick .= ' setTimeout(\'pp_refresh()\', 500); ';
161 }
162
163}
164
165
166