General IMP:: cleanup; improvements to display
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 20 Nov 2008 20:50:45 +0000 (13:50 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 20 Nov 2008 20:50:45 +0000 (13:50 -0700)
Improvements to print message display (don't show status boxes or
summary icons).

imp/config/hooks.php.dist
imp/lib/IMP.php
imp/lib/Mime/Viewer/html.php
imp/lib/UI/Message.php
imp/message.php

index 2e3e8b4..00686e2 100644 (file)
@@ -51,7 +51,7 @@
 //         require_once IMP_BASE . '/lib/MIME/Contents.php';
 //         require_once IMP_BASE . '/lib/UI/Message.php';
 //
-//         IMP::printMode(true);
+//         IMP::$printMode = true;
 //         $contents = new IMP_Contents($message);
 //         $contents->showSummaryLinks(false);
 //         $contents->buildMessage();
index 77988ca..4a6a25e 100644 (file)
@@ -49,6 +49,21 @@ class IMP
     // String used to separate indexes.
     const IDX_SEP = "\1";
 
+    /* Are we currently in "print" mode? */
+    static public $printMode = false;
+
+    /* displayFolder() cache. */
+    static protected $_displaycache = array();
+
+    /* hideDeletedMsgs() cache. */
+    static protected $_delhide = null;
+
+    /* getAuthKey() cache. */
+    static protected $_authkey = null;
+
+    /* _filesystemGC() cache. */
+    static protected $_dirlist = array();
+
     /**
      * Makes sure the user has been authenticated to view the page.
      *
@@ -458,7 +473,7 @@ class IMP
      */
     static public function displayFolder($folder)
     {
-        static $cache = array();
+        $cache = self::$_displaycache;
 
         if (isset($cache[$folder])) {
             return $cache[$folder];
@@ -822,22 +837,6 @@ class IMP
     }
 
     /**
-     * Are we currently in "print" mode?
-     *
-     * @param boolean $mode  True if in print mode, false if not.
-     *
-     * @return boolean  Returns true if in "print" mode.
-     */
-    static public function printMode($mode = null)
-    {
-        static $print = false;
-        if (($mode !== null)) {
-            $print = $mode;
-        }
-        return $print;
-    }
-
-    /**
      * Get message indices list.
      *
      * @param mixed $indices  The following inputs are allowed:
@@ -1022,9 +1021,9 @@ class IMP
      */
     static public function hideDeletedMsgs($force = false)
     {
-        static $delhide;
+        $delhide = &self::$_delhide;
 
-        if (!isset($delhide) || $force) {
+        if (is_null($delhide) || $force) {
             if ($GLOBALS['prefs']->getValue('use_vtrash')) {
                 $delhide = !$GLOBALS['imp_search']->isVTrashFolder();
             } else {
@@ -1688,7 +1687,7 @@ class IMP
      */
     static protected function _filesystemGC($type)
     {
-        static $dir_list = array();
+        $dir_list = &self::$_dirlist;
 
         $ptr = $GLOBALS['conf']['server'][(($type == 'css') ? 'cachecssparams' : 'cachejsparams')];
         $dir = $ptr['file_location'];
@@ -1722,7 +1721,7 @@ class IMP
      */
     static public function getAuthKey()
     {
-        static $key = null;
+        $key = &IMP::$_authkey;
 
         if (is_null($key)) {
             $key = Secret::getKey(Auth::getProvider() == 'imp' ? 'auth' : 'imp');
index b13fe38..8350ba7 100644 (file)
@@ -194,7 +194,7 @@ class IMP_Horde_Mime_Viewer_html extends Horde_Mime_Viewer_html
 
         /* Only display images if specifically allowed by user. */
         if ($inline &&
-            !IMP::printMode() &&
+            !IMP::$printMode &&
             $GLOBALS['prefs']->getValue('html_image_replacement') &&
             preg_match($this->_img_regex, $data)) {
             /* Make sure the URL parameters are correct for the current
index 130ab83..491dc71 100644 (file)
@@ -373,11 +373,10 @@ class IMP_UI_Message
      */
     public function formatStatusMsg($data)
     {
-        if (empty($data)) {
+        if (empty($data) || IMP::$printMode) {
             return '';
         }
 
-        // TODO - $data['type']
         $class = 'mimeStatusMessage';
 
         $out = array('<table ' . (isset($data['id']) ? ('id="' . $data['id'] . '" ') : '') . 'class="' . $class . '">');
index 3fcfb25..cd516ea 100644 (file)
@@ -44,8 +44,6 @@ if (!$imp_mailbox->isValidIndex()) {
     exit;
 }
 
-$printer_friendly = false;
-
 /* Set the current time zone. */
 NLS::setTimeZone();
 
@@ -88,8 +86,7 @@ case 'whitelist':
     break;
 
 case 'print_message':
-    $printer_friendly = true;
-    IMP::printMode(true);
+    IMP::$printMode = true;
     break;
 
 case 'delete_message':
@@ -265,11 +262,11 @@ if (!empty($format_date)) {
 }
 
 /* Build From address links. */
-$display_headers['from'] = $imp_ui->buildAddressLinks($envelope['from'], $self_link, !$printer_friendly);
+$display_headers['from'] = $imp_ui->buildAddressLinks($envelope['from'], $self_link, !IMP::$printMode);
 
 /* Add country/flag image. Try X-Originating-IP first, then fall back to the
  * sender's domain name. */
-if (!$printer_friendly) {
+if (!IMP::$printMode) {
     $from_img = '';
     $origin_host = str_replace(array('[', ']'), '', $mime_headers->getValue('X-Originating-IP'));
     if ($origin_host) {
@@ -295,7 +292,7 @@ if (!$printer_friendly) {
 /* Build To/Cc/Bcc links. */
 foreach (array('to', 'cc', 'bcc') as $val) {
     $msgAddresses[] = $mime_headers->getValue($val);
-    $addr_val = $imp_ui->buildAddressLinks($envelope[$val], $self_link, !$printer_friendly);
+    $addr_val = $imp_ui->buildAddressLinks($envelope[$val], $self_link, !IMP::$printMode);
     if (!empty($addr_val)) {
         $display_headers[$val] = $addr_val;
     }
@@ -329,7 +326,7 @@ case 'low':
 }
 
 /* Build Reply-To address links. */
-$reply_to = $imp_ui->buildAddressLinks($envelope['reply-to'], $self_link, !$printer_friendly);
+$reply_to = $imp_ui->buildAddressLinks($envelope['reply-to'], $self_link, !IMP::$printMode);
 if (!empty($reply_to) &&
     (!($from = $display_headers['from']) || ($from != $reply_to))) {
     $display_headers['reply-to'] = $reply_to;
@@ -408,7 +405,7 @@ if (!Horde_Mime_Address::addrArray2String(array_merge($envelope['to'], $envelope
 }
 
 /* Retrieve any history information for this message. */
-if (!$printer_friendly && !empty($conf['maillog']['use_maillog'])) {
+if (!IMP::$printMode && !empty($conf['maillog']['use_maillog'])) {
     /* Do MDN processing now. */
     if ($imp_ui->MDNCheck($mime_headers, Util::getFormData('mdn_confirm'))) {
         $confirm_link = Horde::link(Util::addParameter($selfURL, 'mdn_confirm', 1)) . _("HERE") . '</a>';
@@ -417,7 +414,7 @@ if (!$printer_friendly && !empty($conf['maillog']['use_maillog'])) {
 }
 
 /* Everything below here is related to preparing the output. */
-if (!$printer_friendly) {
+if (!IMP::$printMode) {
     /* Set the status information of the message. */
     $identity = $status = null;
     if (!$use_pop) {
@@ -617,7 +614,8 @@ foreach ($all_list_headers as $head => $val) {
 }
 
 /* Determine the fields that will appear in the MIME info entries. */
-$part_info = array('icon', 'description', 'type', 'size', 'download', 'download_zip', 'img_save', 'strip');
+$part_info = $part_info_display = array('icon', 'description', 'type', 'size');
+$part_info_action = array('download', 'download_zip', 'img_save', 'strip');
 
 $parts_list = $imp_contents->getContentTypeMap();
 $strip_atc = $prefs->getValue('strip_attachments');
@@ -632,9 +630,10 @@ if ($show_parts == 'all') {
 $contents_mask = IMP_Contents::SUMMARY_BYTES |
     IMP_Contents::SUMMARY_SIZE |
     IMP_Contents::SUMMARY_ICON;
-if ($printer_friendly) {
+if (IMP::$printMode) {
     $contents_mask |= IMP_Contents::SUMMARY_DESCRIP_NOLINK;
 } else {
+    $part_info_display = array_merge($part_info_display, $part_info_action);
     $contents_mask |= IMP_Contents::SUMMARY_DESCRIP_LINK |
         IMP_Contents::SUMMARY_DOWNLOAD |
         IMP_Contents::SUMMARY_DOWNLOAD_ZIP |
@@ -679,7 +678,7 @@ foreach ($parts_list as $mime_id => $mime_type) {
         $tmp_summary = $tmp_status = array();
 
         $summary = $imp_contents->getSummary($id, $contents_mask);
-        foreach ($part_info as $val) {
+        foreach ($part_info_display as $val) {
             $tmp_summary[] = $summary[$val];
         }
 
@@ -698,7 +697,7 @@ if (!strlen($msgtext)) {
 }
 
 /* Build the Attachments menu. */
-if (!$printer_friendly) {
+if (!IMP::$printMode) {
     $a_template->set('atc', Horde::widget('#', _("Attachments"), 'widget hasmenu', '', '', _("Attachments"), true));
     if ($show_parts != 'all') {
         $a_template->set('show_parts_all', Horde::widget(Util::addParameter($headersURL, array('show_parts' => 'all')), _("Show All Message Parts"), 'widget', '', '', _("Show All Message Parts"), true));
@@ -728,13 +727,20 @@ if (!empty($atc_parts) && ($show_parts != 'none')) {
         foreach ($part_info as $val) {
             $tmp[] = '<td>' . $summary[$val] . '</td>';
         }
+        if (!IMP::$printMode) {
+            $tmp[] = '<td>';
+            foreach ($part_info_action as $val) {
+                $tmp[] = $summary[$val];
+            }
+            $tmp[] = '</td>';
+        }
         $tmp[] = '</tr>';
     }
 
     $hdrs[] = array('name' => ($show_parts == 'all') ? _("Parts") : _("Attachments"), 'val' => '<table>' . implode('', $tmp) . '</table>', 'i' => (++$i % 2));
 }
 
-if ($printer_friendly && !empty($conf['print']['add_printedby'])) {
+if (IMP::$printMode && !empty($conf['print']['add_printedby'])) {
     $hdrs[] = array('name' => _("Printed By"), 'val' => $user_identity->getFullname() ? $user_identity->getFullname() : Auth::getAuth(), 'i' => (++$i % 2));
 }
 
@@ -746,16 +752,14 @@ Horde::addScriptFile('prototype.js', 'horde', true);
 Horde::addScriptFile('popup.js', 'imp', true);
 Horde::addScriptFile('message.js', 'imp', true);
 require IMP_TEMPLATES . '/common-header.inc';
-if (!$printer_friendly) {
+if (!IMP::$printMode) {
     if (!empty($conf['maillog']['use_maillog'])) {
         IMP_Maillog::displayLog($envelope['message-id']);
     }
     IMP::menu();
     IMP::status();
     IMP::quota();
-}
 
-if (!$printer_friendly) {
     echo $t_template->fetch(IMP_TEMPLATES . '/message/navbar_top.html');
     echo $n_template->fetch(IMP_TEMPLATES . '/message/navbar_navigate.html');
     echo $a_template->fetch(IMP_TEMPLATES . '/message/navbar_actions.html');
@@ -763,7 +767,7 @@ if (!$printer_friendly) {
 
 echo $m_template->fetch(IMP_TEMPLATES . '/message/message.html');
 
-if (!$printer_friendly) {
+if (!IMP::$printMode) {
     echo '<input type="hidden" name="flag" id="flag" value="" />';
     $a_template->set('isbottom', true);
     echo $a_template->fetch(IMP_TEMPLATES . '/message/navbar_actions.html');
@@ -777,7 +781,7 @@ if (!$printer_friendly) {
     echo $n_template->fetch(IMP_TEMPLATES . '/message/navbar_navigate.html');
 }
 
-if ($browser->hasFeature('javascript') && $printer_friendly) {
+if ($browser->hasFeature('javascript') && IMP::$printMode) {
     require $registry->get('templates', 'horde') . '/javascript/print.js';
 }