functions.php 7.7 KB

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