From d26e94ae9456c6bf13392884e28a32c60f7301b0 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Sat, 18 Oct 2014 08:50:10 -0400
Subject: [PATCH] Small CS fixes after PR merge

---
 program/include/rcmail_output_html.php |   86 +++++++++++++++++++++++++++++--------------
 1 files changed, 58 insertions(+), 28 deletions(-)

diff --git a/program/include/rcmail_output_html.php b/program/include/rcmail_output_html.php
index 6594209..0f2a0a6 100644
--- a/program/include/rcmail_output_html.php
+++ b/program/include/rcmail_output_html.php
@@ -419,15 +419,6 @@
      */
     public function write($template = '')
     {
-        // unlock interface after iframe load
-        $unlock = preg_replace('/[^a-z0-9]/i', '', $_REQUEST['_unlock']);
-        if ($this->framed) {
-            array_unshift($this->js_commands, array('iframe_loaded', $unlock));
-        }
-        else if ($unlock) {
-            array_unshift($this->js_commands, array('hide_message', $unlock));
-        }
-
         if (!empty($this->script_files)) {
             $this->set_env('request_token', $this->app->get_request_token());
         }
@@ -439,6 +430,8 @@
         if ($framed) {
             $this->scripts      = array();
             $this->script_files = array();
+            $this->header       = '';
+            $this->footer       = '';
         }
 
         // write all javascript commands
@@ -572,18 +565,31 @@
      */
     protected function get_js_commands(&$framed = null)
     {
-        if (!$this->framed && !empty($this->js_env)) {
-            $this->command('set_env', $this->js_env);
-        }
-
-        if (!empty($this->js_labels)) {
-            $this->command('add_label', $this->js_labels);
-        }
-
-        $out = '';
+        $out             = '';
         $parent_commands = 0;
+        $top_commands    = array();
 
-        foreach ($this->js_commands as $i => $args) {
+        // these should be always on top,
+        // e.g. hide_message() below depends on env.framed
+        if (!$this->framed && !empty($this->js_env)) {
+            $top_commands[] = array('set_env', $this->js_env);
+        }
+        if (!empty($this->js_labels)) {
+            $top_commands[] = array('add_label', $this->js_labels);
+        }
+
+        // unlock interface after iframe load
+        $unlock = preg_replace('/[^a-z0-9]/i', '', $_REQUEST['_unlock']);
+        if ($this->framed) {
+            $top_commands[] = array('iframe_loaded', $unlock);
+        }
+        else if ($unlock) {
+            $top_commands[] = array('hide_message', $unlock);
+        }
+
+        $commands = array_merge($top_commands, $this->js_commands);
+
+        foreach ($commands as $i => $args) {
             $method = array_shift($args);
             $parent = $this->framed || preg_match('/^parent\./', $method);
 
@@ -604,7 +610,7 @@
             $out .= sprintf("%s(%s);\n", $method, implode(',', $args));
         }
 
-        $framed = $parent_prefix && $parent_commands == count($this->js_commands);
+        $framed = $parent_prefix && $parent_commands == count($commands);
 
         // make the output more compact if all commands go to parent window
         if ($framed) {
@@ -921,16 +927,16 @@
                     $attrib['name'] = $this->eval_expression($attrib['expression']);
 
                 if ($attrib['name'] || $attrib['command']) {
-                    // @FIXME: 'noshow' is useless, remove?
-                    if ($attrib['noshow']) {
-                        return '';
-                    }
-
                     $vars = $attrib + array('product' => $this->config->get('product_name'));
                     unset($vars['name'], $vars['command']);
 
                     $label   = $this->app->gettext($attrib + array('vars' => $vars));
                     $quoting = !empty($attrib['quoting']) ? strtolower($attrib['quoting']) : (rcube_utils::get_boolean((string)$attrib['html']) ? 'no' : '');
+
+                    // 'noshow' can be used in skins to define new labels
+                    if ($attrib['noshow']) {
+                        return '';
+                    }
 
                     switch ($quoting) {
                         case 'no':
@@ -1133,7 +1139,8 @@
      */
     public function button($attrib)
     {
-        static $s_button_count = 100;
+        static $s_button_count   = 100;
+        static $disabled_actions = null;
 
         // these commands can be called directly via url
         $a_static_commands = array('compose', 'list', 'preferences', 'folders', 'identities');
@@ -1142,9 +1149,14 @@
             return '';
         }
 
+
         // try to find out the button type
         if ($attrib['type']) {
             $attrib['type'] = strtolower($attrib['type']);
+            if ($pos = strpos($attrib['type'], '-menuitem')) {
+                $attrib['type'] = substr($attrib['type'], 0, -9);
+                $menuitem = true;
+            }
         }
         else {
             $attrib['type'] = ($attrib['image'] || $attrib['imagepas'] || $attrib['imageact']) ? 'image' : 'link';
@@ -1152,8 +1164,21 @@
 
         $command = $attrib['command'];
 
-        if ($attrib['task'])
-          $command = $attrib['task'] . '.' . $command;
+        if ($attrib['task']) {
+            $element = $command = $attrib['task'] . '.' . $command;
+        }
+        else {
+            $element = ($this->env['task'] ? $this->env['task'] . '.' : '') . $command;
+        }
+
+        if ($disabled_actions === null) {
+            $disabled_actions = (array) $this->config->get('disabled_actions');
+        }
+
+        // remove buttons for disabled actions
+        if (in_array($element, $disabled_actions)) {
+            return '';
+        }
 
         if (!$attrib['image']) {
             $attrib['image'] = $attrib['imagepas'] ? $attrib['imagepas'] : $attrib['imageact'];
@@ -1286,6 +1311,11 @@
             $out = html::tag($attrib['wrapper'], null, $out);
         }
 
+        if ($menuitem) {
+            $class = $attrib['menuitem-class'] ? ' class="' . $attrib['menuitem-class'] . '"' : '';
+            $out   = '<li role="menuitem"' . $class . '>' . $out . '</li>';
+        }
+
         return $out;
     }
 

--
Gitblit v1.9.1