functions.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <?php
  2. /**
  3. * SquirrelMail Preview Pane Plugin
  4. *
  5. * @copyright &copy; 1999-2007 The SquirrelMail Project Team
  6. * @author Paul Lesneiwski <paul@squirrelmail.org>
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. * @version $Id$
  9. * @package plugins
  10. * @subpackage preview_pane
  11. *
  12. */
  13. /**
  14. * Build user options for display on "Display Preferences" page
  15. *
  16. */
  17. function preview_pane_show_options_do()
  18. {
  19. if (!checkForJavascript()) return;
  20. global $data_dir, $username;
  21. $use_previewPane = getPref($data_dir, $username, 'use_previewPane', 0);
  22. $previewPane_vertical_split = getPref($data_dir, $username, 'previewPane_vertical_split', 0);
  23. $previewPane_size = getPref($data_dir, $username, 'previewPane_size', 300);
  24. $pp_refresh_message_list = getPref($data_dir, $username, 'pp_refresh_message_list', 1);
  25. $previewPane_autohide = getPref($data_dir, $username, 'previewPane_autohide', 0);
  26. global $optpage_data;
  27. $optpage_data['vals'][1][] = array(
  28. 'name' => 'use_previewPane',
  29. 'caption' => _("Show Message Preview Pane"),
  30. 'type' => SMOPT_TYPE_BOOLEAN,
  31. 'initial_value' => $use_previewPane,
  32. 'refresh' => SMOPT_REFRESH_ALL,
  33. );
  34. $optpage_data['vals'][1][] = array(
  35. 'name' => 'previewPane_vertical_split',
  36. 'caption' => _("Split Preview Pane Vertically"),
  37. 'type' => SMOPT_TYPE_BOOLEAN,
  38. 'initial_value' => $previewPane_vertical_split,
  39. 'refresh' => SMOPT_REFRESH_ALL,
  40. );
  41. $optpage_data['vals'][1][] = array(
  42. 'name' => 'previewPane_size',
  43. 'caption' => _("Message Preview Pane Size"),
  44. 'type' => SMOPT_TYPE_INTEGER,
  45. 'initial_value' => $previewPane_size,
  46. 'refresh' => SMOPT_REFRESH_ALL,
  47. 'size' => SMOPT_SIZE_TINY,
  48. );
  49. $optpage_data['vals'][1][] = array(
  50. 'name' => 'pp_refresh_message_list',
  51. 'caption' => _("Always Refresh Message List<br />When Using Preview Pane"),
  52. 'type' => SMOPT_TYPE_BOOLEAN,
  53. 'initial_value' => $pp_refresh_message_list,
  54. 'refresh' => SMOPT_REFRESH_NONE,
  55. );
  56. $optpage_data['vals'][1][] = array(
  57. 'name' => 'previewPane_autohide',
  58. 'caption' => _("Automatically Hide Preview Pane<br />When Not Reading Messages"),
  59. 'type' => SMOPT_TYPE_BOOLEAN,
  60. 'initial_value' => $previewPane_autohide,
  61. 'refresh' => SMOPT_REFRESH_ALL,
  62. );
  63. }
  64. /**
  65. * This function determines if the preview pane is in use
  66. * (and JavaScript is available)
  67. *
  68. * @return boolean TRUE if the preview pane should be showing currently.
  69. *
  70. */
  71. function show_preview_pane()
  72. {
  73. global $data_dir, $username;
  74. $use_previewPane = getPref($data_dir, $username, 'use_previewPane', 0);
  75. return (checkForJavascript() && $use_previewPane);
  76. }
  77. /**
  78. * Adds preview pane open/close (and clear) buttons next to
  79. * "provider link"
  80. *
  81. */
  82. function preview_pane_open_close_buttons_do()
  83. {
  84. if (!show_preview_pane()) return;
  85. global $data_dir, $username, $base_uri, $oTemplate;
  86. $previewPane_vertical_split = getPref($data_dir, $username, 'previewPane_vertical_split', 0);
  87. if ($previewPane_vertical_split)
  88. {
  89. $orientation = 'cols';
  90. $up_arrow = '&larr;';
  91. $down_arrow = '&rarr;';
  92. }
  93. else
  94. {
  95. $orientation = 'rows';
  96. $up_arrow = '&uarr;';
  97. $down_arrow = '&darr;';
  98. }
  99. $previewPane_size = getPref($data_dir, $username, 'previewPane_size', 300);
  100. $oTemplate->assign('previewPane_size', $previewPane_size);
  101. $oTemplate->assign('base_uri', $base_uri);
  102. $oTemplate->assign('orientation', $orientation);
  103. $oTemplate->assign('down_arrow', $down_arrow, FALSE);
  104. $oTemplate->assign('up_arrow', $up_arrow, FALSE);
  105. $output = $oTemplate->fetch('plugins/preview_pane/collapse_buttons.tpl');
  106. return array('provider_link_before' => $output);
  107. }
  108. /**
  109. * Construct button that clears out any preview pane
  110. * contents and inserts JavaScript function used by
  111. * message subject link onclick handler. Also disallows
  112. * the message list to be loaded into the bottom frame.
  113. *
  114. */
  115. function preview_pane_message_list_do()
  116. {
  117. if (!checkForJavascript()) return;
  118. // globalize $pp_refresh_top, $pp_forceTopURL and $pp_noPageHeader to synch
  119. // with other plugins (sent_confirmation, for example)
  120. //
  121. global $plugins, $archive_mail_button_has_been_printed,
  122. $username, $data_dir, $PHP_SELF, $base_uri, $pp_refresh_top,
  123. $pp_forceTopURL, $pp_noPageHeader;
  124. sqgetGlobalVar('pp_refresh_top', $pp_refresh_top, SQ_GET);
  125. $output = '';
  126. $use_previewPane = getPref($data_dir, $username, 'use_previewPane', 0);
  127. // add refresh function called from code built in function
  128. // preview_pane_change_message_target_do()
  129. //
  130. if ($use_previewPane == 1)
  131. // Bah, let's put this in anyway (even when the "always refresh thing is off),
  132. // in case someone else wants to use it
  133. // && getPref($data_dir, $username, 'pp_refresh_message_list', 1) == 1)
  134. {
  135. // sqgetGlobalVar('REQUEST_URI', $request_uri, SQ_SERVER);
  136. $request_uri = $PHP_SELF;
  137. $output .= "<script type=\"text/javascript\" language=\"JavaScript\">\n<!--\n function pp_refresh() { document.location = '$request_uri'; }\n// -->\n</script>\n";
  138. }
  139. if ($use_previewPane == 1)
  140. {
  141. // why isn't this already available?
  142. include_once(SM_PATH . 'functions/forms.php');
  143. $output .= addButton(_("Clear Preview"), 'clear_preview',
  144. array('onclick' => 'parent.bottom.document.location=\''
  145. . $base_uri . 'plugins/preview_pane/empty_frame.php\'; '))
  146. // don't let message list load into preview pane at all
  147. //
  148. . "\n<script language='JavaScript' type='text/javascript'>\n"
  149. . "<!--\n"
  150. . "\n"
  151. . " if (self.name == 'bottom')\n"
  152. . " {\n";
  153. // NOTE: we can also force the top frame to the URL that was being
  154. // loaded in the bottom, but this is usually overkill...
  155. // unless another plugin told us to do so (such as sent_confirmation)
  156. if ($pp_forceTopURL == 'yes')
  157. {
  158. // $output .= " parent.right.document.location = '" . $_SERVER['REQUEST_URI'] . "&pp=yes';\n";
  159. $output .= " parent.right.document.location = '" . $PHP_SELF . "&pp=yes';\n";
  160. }
  161. // if someone else asks for it, force the message list to reload
  162. //
  163. else if ($pp_refresh_top)
  164. $output.= " if (typeof(parent.right.pp_refresh) != 'undefined')\n"
  165. . " parent.right.pp_refresh()\n\n";
  166. $output .= " document.location = '" . $base_uri . "plugins/preview_pane/empty_frame.php'\n"
  167. . " }\n"
  168. . "//-->\n"
  169. . "</script>\n";
  170. }
  171. return array('mailbox_index_after' => $output);
  172. }
  173. /**
  174. * Points message targets to open in the preview pane
  175. * (and possibly refresh message list as well)
  176. *
  177. */
  178. function preview_pane_change_message_target_do($args)
  179. {
  180. if (!checkForJavascript()) return;
  181. global $data_dir, $username, $target, $onclick, $PHP_SELF;
  182. // sqgetGlobalVar('REQUEST_URI', $request_uri, SQ_SERVER);
  183. $request_uri = $PHP_SELF;
  184. if (getPref($data_dir, $username, 'use_previewPane', 0) == 1)
  185. {
  186. $pp_refresh_message_list = getPref($data_dir, $username, 'pp_refresh_message_list', 1);
  187. $aMsg = $args[3];
  188. $target = 'bottom';
  189. // introduce a delay so read messages actually
  190. // refresh after they are read, but only if they
  191. // have not already been seen
  192. //
  193. if ($pp_refresh_message_list && empty($aMsg['FLAGS']['\seen']))
  194. // old code without refresh delay
  195. // $onclick .= ' onclick="document.location=\'' . $request_uri . '\'; " ';
  196. $onclick .= ' setTimeout(\'pp_refresh()\', 500); ';
  197. }
  198. }