From 38bf401cf88bc88d3b4d96fee8d2166cc2cac8c6 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Sun, 01 Dec 2013 04:55:13 -0500
Subject: [PATCH] Fix performance of listing writeable folders (#1489451)

---
 program/include/rcmail_output_html.php |   56 ++++++++++++++++++++++++++++++++------------------------
 1 files changed, 32 insertions(+), 24 deletions(-)

diff --git a/program/include/rcmail_output_html.php b/program/include/rcmail_output_html.php
index 39f79d1..6db826e 100644
--- a/program/include/rcmail_output_html.php
+++ b/program/include/rcmail_output_html.php
@@ -310,12 +310,14 @@
      */
     public function reset($all = false)
     {
+        $framed = $this->framed;
         $env = $all ? null : array_intersect_key($this->env, array('extwin'=>1, 'framed'=>1));
 
         parent::reset();
 
         // let some env variables survive
         $this->env = $this->js_env = $env;
+        $this->framed = $framed || $this->env['framed'];
         $this->js_labels    = array();
         $this->js_commands  = array();
         $this->script_files = array();
@@ -323,6 +325,11 @@
         $this->header       = '';
         $this->footer       = '';
         $this->body         = '';
+
+        // load defaults
+        if (!$all) {
+            $this->__construct();
+        }
     }
 
     /**
@@ -925,16 +932,18 @@
                 else if ($object == 'logo') {
                     $attrib += array('alt' => $this->xml_command(array('', 'object', 'name="productname"')));
 
-                    if (is_array($this->config->get('skin_logo'))) {
-                       if (isset($attrib['type']) && array_key_exists($attrib['type'], $this->config->get('skin_logo'))) {
-                           $attrib['src'] = $this->config->get('skin_logo')[$attrib['type']];
-                       }
-                       elseif (array_key_exists('default', $this->config->get('skin_logo'))) {
-                           $attrib['src'] = $this->config->get('skin_logo')['default'];
-                       }
-                    }
-                    elseif ($logo = $this->config->get('skin_logo')) {
-                        $attrib['src'] = $logo;
+                    if ($logo = $this->config->get('skin_logo')) {
+                        if (is_array($logo)) {
+                            if ($template_logo = $logo[$this->template_name]) {
+                                $attrib['src'] = $template_logo;
+                            }
+                            elseif ($template_logo = $logo['*']) {
+                                $attrib['src'] = $template_logo;
+                            }
+                        }
+                        else {
+                            $attrib['src'] = $logo;
+                        }
                     }
 
                     $content = html::img($attrib);
@@ -1053,7 +1062,7 @@
         // these commands can be called directly via url
         $a_static_commands = array('compose', 'list', 'preferences', 'folders', 'identities');
 
-        if (!($attrib['command'] || $attrib['name'])) {
+        if (!($attrib['command'] || $attrib['name'] || $attrib['href'])) {
             return '';
         }
 
@@ -1163,7 +1172,7 @@
         }
         else if ($attrib['type'] == 'link') {
             $btn_content = isset($attrib['content']) ? $attrib['content'] : ($attrib['label'] ? $attrib['label'] : $attrib['command']);
-            $link_attrib = array('href', 'onclick', 'title', 'id', 'class', 'style', 'tabindex', 'target');
+            $link_attrib = array_merge(html::$common_attrib, array('href', 'onclick', 'tabindex', 'target'));
             if ($attrib['innerclass'])
                 $btn_content = html::span($attrib['innerclass'], $btn_content);
         }
@@ -1201,8 +1210,6 @@
      */
     public function include_script($file, $position='head')
     {
-        static $sa_files = array();
-
         if (!preg_match('|^https?://|i', $file) && $file[0] != '/') {
             $file = $this->scripts_path . $file;
             if ($fs = @filemtime($file)) {
@@ -1210,17 +1217,13 @@
             }
         }
 
-        if (in_array($file, $sa_files)) {
-            return;
-        }
-
-        $sa_files[] = $file;
-
         if (!is_array($this->script_files[$position])) {
             $this->script_files[$position] = array();
         }
 
-        $this->script_files[$position][] = $file;
+        if (!in_array($file, $this->script_files[$position])) {
+            $this->script_files[$position][] = $file;
+        }
     }
 
     /**
@@ -1278,7 +1281,12 @@
      */
     public function _write($templ = '', $base_path = '')
     {
-        $output = empty($templ) ? $this->default_template : trim($templ);
+        $output = trim($templ);
+
+        if (empty($output)) {
+            $output   = $this->default_template;
+            $is_empty = true;
+        }
 
         // set default page title
         if (empty($this->pagetitle)) {
@@ -1369,8 +1377,8 @@
         }
 
         // add css files in head, before scripts, for speed up with parallel downloads
-        if (!empty($this->css_files) && 
-            (($pos = stripos($output, '<script ')) || ($pos = stripos($output, '</head>')))
+        if (!empty($this->css_files) && !$is_empty
+            && (($pos = stripos($output, '<script ')) || ($pos = stripos($output, '</head>')))
         ) {
             $css = '';
             foreach ($this->css_files as $file) {

--
Gitblit v1.9.1