Happy 2014
[squirrelmail.git] / plugins / preview_pane / functions.php
index fef1e0cf260d1f46ee874f92095f20c85653899e..3725feef76989fc69a0014ae268409ace2f423de 100644 (file)
@@ -1,22 +1,20 @@
 <?php
 
 /**
-  * SquirrelMail Preview Pane Plugin
-  *
-  * @copyright &copy; 1999-2007 The SquirrelMail Project Team
-  * @author Paul Lesneiwski <paul@squirrelmail.org>
-  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
-  * @version $Id$
-  * @package plugins
-  * @subpackage preview_pane
-  *
-  */
+ * SquirrelMail Preview Pane Plugin
+ *
+ * @copyright 1999-2014 The SquirrelMail Project Team
+ * @author Paul Lesniewski <paul@squirrelmail.org>
+ * @license http://opensource.org/licenses/gpl-license.php GNU Public License
+ * @version $Id$
+ * @package plugins
+ * @subpackage preview_pane
+ */
 
 
 /**
-  * Build user options for display on "Display Preferences" page
-  *
-  */
+ * Build user options for display on "Display Preferences" page
+ */
 function preview_pane_show_options_do() 
 {
 
@@ -27,6 +25,7 @@ function preview_pane_show_options_do()
    $previewPane_vertical_split = getPref($data_dir, $username, 'previewPane_vertical_split', 0);
    $previewPane_size = getPref($data_dir, $username, 'previewPane_size', 300);
    $pp_refresh_message_list = getPref($data_dir, $username, 'pp_refresh_message_list', 1);
+   $previewPane_autohide = getPref($data_dir, $username, 'previewPane_autohide', 0);
 
 
    global $optpage_data;
@@ -57,6 +56,13 @@ function preview_pane_show_options_do()
       'caption'       => _("Always Refresh Message List<br />When Using Preview Pane"),
       'type'          => SMOPT_TYPE_BOOLEAN,
       'initial_value' => $pp_refresh_message_list,
+      'refresh'       => SMOPT_REFRESH_NONE,
+   );
+   $optpage_data['vals'][1][] = array(
+      'name'          => 'previewPane_autohide',
+      'caption'       => _("Automatically Hide Preview Pane<br />When Not Reading Messages"),
+      'type'          => SMOPT_TYPE_BOOLEAN,
+      'initial_value' => $previewPane_autohide,
       'refresh'       => SMOPT_REFRESH_ALL,
    );
 
@@ -64,26 +70,65 @@ function preview_pane_show_options_do()
 
 
 /**
-  * This function determines if the preview pane is in use 
-  * (and JavaScript is available)
-  *
-  * @return boolean TRUE if the preview pane should be showing currently.
-  *
-  */
+ * This function determines if the preview pane is in use 
+ * (and JavaScript is available)
+ *
+ * @return boolean TRUE if the preview pane should be showing currently.
+ */
 function show_preview_pane() 
 {
+   global $data_dir, $username;
    $use_previewPane = getPref($data_dir, $username, 'use_previewPane', 0);
    return (checkForJavascript() && $use_previewPane);
 }
 
 
 /**
-  * Construct button that clears out any preview pane
-  * contents and inserts JavaScript function used by 
-  * message subject link onclick handler.  Also disallows 
-  * the message list to be loaded into the bottom frame.
-  *
-  */
+ * Adds preview pane open/close (and clear) buttons next to
+ * "provider link"
+ */
+function preview_pane_open_close_buttons_do()
+{
+
+   if (!show_preview_pane()) return;
+
+   global $data_dir, $username, $base_uri, $oTemplate;
+   $previewPane_vertical_split = getPref($data_dir, $username, 'previewPane_vertical_split', 0);
+   if ($previewPane_vertical_split)
+   {
+      $orientation = 'cols';
+      $up_arrow = '&larr;';
+      $down_arrow = '&rarr;';
+   }
+   else
+   {
+      $orientation = 'rows';
+      $up_arrow = '&uarr;';
+      $down_arrow = '&darr;';
+   }
+
+
+   $previewPane_size = getPref($data_dir, $username, 'previewPane_size', 300);
+
+   $oTemplate->assign('previewPane_size', $previewPane_size);
+   $oTemplate->assign('base_uri', $base_uri);
+   $oTemplate->assign('orientation', $orientation);
+   $oTemplate->assign('down_arrow', $down_arrow, FALSE);
+   $oTemplate->assign('up_arrow', $up_arrow, FALSE);
+
+   $output = $oTemplate->fetch('plugins/preview_pane/collapse_buttons.tpl');
+
+   return array('provider_link_before' => $output);
+
+}
+
+
+/**
+ * Construct button that clears out any preview pane
+ * contents and inserts JavaScript function used by 
+ * message subject link onclick handler.  Also disallows 
+ * the message list to be loaded into the bottom frame.
+ */
 function preview_pane_message_list_do()
 {
 
@@ -105,14 +150,14 @@ function preview_pane_message_list_do()
    // add refresh function called from code built in function
    // preview_pane_change_message_target_do()
    //
-   if ($use_previewPane == 1
+   if ($use_previewPane == 1)
 // Bah, let's put this in anyway (even when the "always refresh thing is off),
 // in case someone else wants to use it
 //    && getPref($data_dir, $username, 'pp_refresh_message_list', 1) == 1)
    {
 //      sqgetGlobalVar('REQUEST_URI', $request_uri, SQ_SERVER);
       $request_uri = $PHP_SELF;
-      $output .= "<script type=\"text/javascript\">\n<!--\n function pp_refresh() { document.location = '$request_uri'; }\n// -->\n</script>\n";
+      $output .= "<script type=\"text/javascript\" language=\"JavaScript\">\n<!--\n function pp_refresh() { document.location = '$request_uri'; }\n// -->\n</script>\n";
    }
 
 
@@ -129,7 +174,7 @@ function preview_pane_message_list_do()
 
       // don't let message list load into preview pane at all
       //
-         . "\n<script language='javascript' type='text/javascript'>\n"
+         . "\n<script language='JavaScript' type='text/javascript'>\n"
          . "<!--\n"
          . "\n"
          . "   if (self.name == 'bottom')\n"
@@ -148,8 +193,8 @@ function preview_pane_message_list_do()
       // if someone else asks for it, force the message list to reload 
       //
       else if ($pp_refresh_top)
-         echo "      if (typeof(parent.right.pp_refresh) != 'undefined')\n"
-            . "         parent.right.pp_refresh()\n\n";
+         $output.= "      if (typeof(parent.right.pp_refresh) != 'undefined')\n"
+                 . "         parent.right.pp_refresh()\n\n";
 
 
       $output .= "      document.location = '" . $base_uri . "plugins/preview_pane/empty_frame.php'\n"
@@ -164,11 +209,10 @@ function preview_pane_message_list_do()
 
 
 /**
-  * Points message targets to open in the preview pane
-  * (and possibly refresh message list as well)
-  *
-  */
-function preview_pane_change_message_target_do()
+ * Points message targets to open in the preview pane
+ * (and possibly refresh message list as well)
+ */
+function preview_pane_change_message_target_do($args)
 {
 
    if (!checkForJavascript()) return;
@@ -181,10 +225,17 @@ function preview_pane_change_message_target_do()
    if (getPref($data_dir, $username, 'use_previewPane', 0) == 1)
    {
       $pp_refresh_message_list = getPref($data_dir, $username, 'pp_refresh_message_list', 1);
+      $aMsg = $args[3];
 
       $target = 'bottom';
-      if ($pp_refresh_message_list)
-// introduce a delay so read messages actually refresh after they are read
+
+
+      // introduce a delay so read messages actually 
+      // refresh after they are read, but only if they
+      // have not already been seen
+      //
+      if ($pp_refresh_message_list && empty($aMsg['FLAGS']['\seen']))
+// old code without refresh delay 
 //         $onclick .= ' onclick="document.location=\'' . $request_uri . '\'; " ';
          $onclick .= ' setTimeout(\'pp_refresh()\', 500); ';
    }