From 8eefbb2158c43b51a8c33e6c480cbe61539b9535 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Mon, 27 Aug 2012 04:16:04 -0400
Subject: [PATCH] Add option to enable HTML editor on forwarding (#1488517)

---
 program/include/rcube_output_html.php |  117 +++++++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 78 insertions(+), 39 deletions(-)

diff --git a/program/include/rcube_output_html.php b/program/include/rcube_output_html.php
index a047aba..a071ee3 100644
--- a/program/include/rcube_output_html.php
+++ b/program/include/rcube_output_html.php
@@ -17,10 +17,7 @@
  +-----------------------------------------------------------------------+
  | Author: Thomas Bruederli <roundcube@gmail.com>                        |
  +-----------------------------------------------------------------------+
-
- $Id$
-
- */
+*/
 
 
 /**
@@ -70,14 +67,21 @@
         $this->set_env('task', $task);
         $this->set_env('x_frame_options', $this->config->get('x_frame_options', 'sameorigin'));
 
+        // add cookie info
+        $this->set_env('cookie_domain', ini_get('session.cookie_domain'));
+        $this->set_env('cookie_path', ini_get('session.cookie_path'));
+        $this->set_env('cookie_secure', ini_get('session.cookie_secure'));
+
         // load the correct skin (in case user-defined)
-        $this->set_skin($this->config->get('skin'));
+        $skin = $this->config->get('skin');
+        $this->set_skin($skin);
+        $this->set_env('skin', $skin);
 
         // add common javascripts
-        $this->add_script('var '.JS_OBJECT_NAME.' = new rcube_webmail();', 'head_top');
+        $this->add_script('var '.rcmail::JS_OBJECT_NAME.' = new rcube_webmail();', 'head_top');
 
         // don't wait for page onload. Call init at the bottom of the page (delayed)
-        $this->add_script(JS_OBJECT_NAME.'.init();', 'docready');
+        $this->add_script(rcmail::JS_OBJECT_NAME.'.init();', 'docready');
 
         $this->scripts_path = 'program/js/';
         $this->include_script('jquery.min.js');
@@ -150,7 +154,7 @@
         else {
             $skin_path = $this->config->get('skin_path');
             if (!$skin_path) {
-                $skin_path = 'skins/default';
+                $skin_path = 'skins/' . rcube_config::DEFAULT_SKIN;
             }
             $valid = !$skin;
         }
@@ -183,7 +187,7 @@
      */
     public function add_gui_object($obj, $id)
     {
-        $this->add_script(JS_OBJECT_NAME.".gui_object('$obj', '$id');");
+        $this->add_script(rcmail::JS_OBJECT_NAME.".gui_object('$obj', '$id');");
     }
 
 
@@ -457,7 +461,7 @@
     {
         $out = '';
         if (!$this->framed && !empty($this->js_env)) {
-            $out .= JS_OBJECT_NAME . '.set_env('.self::json_serialize($this->js_env).");\n";
+            $out .= rcmail::JS_OBJECT_NAME . '.set_env('.self::json_serialize($this->js_env).");\n";
         }
         if (!empty($this->js_labels)) {
             $this->command('add_label', $this->js_labels);
@@ -470,7 +474,7 @@
             $parent = $this->framed || preg_match('/^parent\./', $method);
             $out .= sprintf(
                 "%s.%s(%s);\n",
-                ($parent ? 'if(window.parent && parent.'.JS_OBJECT_NAME.') parent.' : '') . JS_OBJECT_NAME,
+                ($parent ? 'if(window.parent && parent.'.rcmail::JS_OBJECT_NAME.') parent.' : '') . rcmail::JS_OBJECT_NAME,
                 preg_replace('/^parent\./', '', $method),
                 implode(',', $args)
             );
@@ -644,7 +648,7 @@
                 "\$_SESSION['\\1']",
                 "\$this->app->config->get('\\1',get_boolean('\\3'))",
                 "\$this->env['\\1']",
-                "rcube_ui::get_input_value('\\1', rcube_ui::INPUT_GPC)",
+                "rcube_utils::get_input_value('\\1', rcube_utils::INPUT_GPC)",
                 "\$_COOKIE['\\1']",
                 "\$this->browser->{'\\1'}",
                 $this->template_name,
@@ -697,10 +701,31 @@
             // show a label
             case 'label':
                 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));
-                    return !$attrib['noshow'] ? (get_boolean((string)$attrib['html']) ? $label : html::quote($label)) : '';
+
+                    $label   = $this->app->gettext($attrib + array('vars' => $vars));
+                    $quoting = !empty($attrib['quoting']) ? strtolower($attrib['quoting']) : (get_boolean((string)$attrib['html']) ? 'no' : '');
+
+                    switch ($quoting) {
+                        case 'no':
+                        case 'raw':
+                            break;
+                        case 'javascript':
+                        case 'js':
+                            $label = rcmail::JQ($label);
+                            break;
+                        default:
+                            $label = html::quote($label);
+                            break;
+                    }
+
+                    return $label;
                 }
                 break;
 
@@ -770,6 +795,13 @@
                         if (preg_match('/Revision:\s(\d+)/', @shell_exec('svn info'), $regs))
                           $ver .= ' [SVN r'.$regs[1].']';
                     }
+                    else if (is_file(INSTALL_PATH . '.git/index')) {
+                        if (preg_match('/Date:\s+([^\n]+)/', @shell_exec('git log -1'), $regs)) {
+                            if ($date = date('Ymd.Hi', strtotime($regs[1]))) {
+                                $ver .= ' [GIT '.$date.']';
+                            }
+                        }
+                    }
                     $content = html::quote($ver);
                 }
                 else if ($object == 'steptitle') {
@@ -812,7 +844,7 @@
                         }
                         break;
                     case 'request':
-                        $value = rcube_ui::get_input_value($name, rcube_ui::INPUT_GPC);
+                        $value = rcube_utils::get_input_value($name, rcube_utils::INPUT_GPC);
                         break;
                     case 'session':
                         $value = $_SESSION[$name];
@@ -917,7 +949,7 @@
         if ($attrib['command']) {
             $this->add_script(sprintf(
                 "%s.register_button('%s', '%s', '%s', '%s', '%s', '%s');",
-                JS_OBJECT_NAME,
+                rcmail::JS_OBJECT_NAME,
                 $command,
                 $attrib['id'],
                 $attrib['type'],
@@ -929,7 +961,7 @@
             // make valid href to specific buttons
             if (in_array($attrib['command'], rcmail::$main_tasks)) {
                 $attrib['href']    = $this->app->url(array('task' => $attrib['command']));
-                $attrib['onclick'] = sprintf("%s.command('switch-task','%s');return false", JS_OBJECT_NAME, $attrib['command']);
+                $attrib['onclick'] = sprintf("%s.command('switch-task','%s',null,event); return false", rcmail::JS_OBJECT_NAME, $attrib['command']);
             }
             else if ($attrib['task'] && in_array($attrib['task'], rcmail::$main_tasks)) {
                 $attrib['href'] = $this->app->url(array('action' => $attrib['command'], 'task' => $attrib['task']));
@@ -952,8 +984,8 @@
         }
         else if ($command && !$attrib['onclick']) {
             $attrib['onclick'] = sprintf(
-                "return %s.command('%s','%s',this)",
-                JS_OBJECT_NAME,
+                "return %s.command('%s','%s',this,event)",
+                rcmail::JS_OBJECT_NAME,
                 $command,
                 $attrib['prop']
             );
@@ -1206,7 +1238,7 @@
             array($this, 'file_callback'), $output);
 
         // trigger hook with final HTML content to be sent
-        $hook = rcmail::get_instance()->plugins->exec_hook("send_page", array('content' => $output));
+        $hook = $this->app->plugins->exec_hook("send_page", array('content' => $output));
         if (!$hook['abort']) {
             if ($this->charset != RCMAIL_CHARSET) {
                 echo rcube_charset::convert($hook['content'], RCMAIL_CHARSET, $this->charset);
@@ -1225,21 +1257,21 @@
      */
     protected function file_callback($matches)
     {
-	    $file = $matches[3];
+        $file = $matches[3];
 
         // correct absolute paths
-	    if ($file[0] == '/') {
-	        $file = $this->base_path . $file;
+        if ($file[0] == '/') {
+            $file = $this->base_path . $file;
         }
 
         // add file modification timestamp
-	    if (preg_match('/\.(js|css)$/', $file)) {
+        if (preg_match('/\.(js|css)$/', $file)) {
             if ($fs = @filemtime($file)) {
                 $file .= '?s=' . $fs;
             }
         }
 
-	    return $matches[1] . '=' . $matches[2] . $file . $matches[4];
+        return $matches[1] . '=' . $matches[2] . $file . $matches[4];
     }
 
 
@@ -1328,7 +1360,7 @@
             $username = $this->app->user->get_username();
         }
 
-        return rcube_idn_to_utf8($username);
+        return rcube_utils::idn_to_utf8($username);
     }
 
 
@@ -1347,9 +1379,12 @@
         $_SESSION['temp'] = true;
 
         // save original url
-        $url = rcube_ui::get_input_value('_url', rcube_ui::INPUT_POST);
+        $url = rcube_utils::get_input_value('_url', rcube_utils::INPUT_POST);
         if (empty($url) && !preg_match('/_(task|action)=logout/', $_SERVER['QUERY_STRING']))
             $url = $_SERVER['QUERY_STRING'];
+
+        // Disable autocapitalization on iPad/iPhone (#1488609)
+        $attrib['autocapitalize'] = 'off';
 
         // set atocomplete attribute
         $user_attrib = $autocomplete > 0 ? array() : array('autocomplete' => 'off');
@@ -1397,7 +1432,7 @@
         $table = new html_table(array('cols' => 2));
 
         $table->add('title', html::label('rcmloginuser', html::quote($this->app->gettext('username'))));
-        $table->add('input', $input_user->show(rcube_ui::get_input_value('_user', rcube_ui::INPUT_GPC)));
+        $table->add('input', $input_user->show(rcube_utils::get_input_value('_user', rcube_utils::INPUT_GPC)));
 
         $table->add('title', html::label('rcmloginpwd', html::quote($this->app->gettext('password'))));
         $table->add('input', $input_pass->show());
@@ -1405,7 +1440,7 @@
         // add host selection row
         if (is_object($input_host) && !$hide_host) {
             $table->add('title', html::label('rcmloginhost', html::quote($this->app->gettext('server'))));
-            $table->add('input', $input_host->show(rcube_ui::get_input_value('_host', rcube_ui::INPUT_GPC)));
+            $table->add('input', $input_host->show(rcube_utils::get_input_value('_host', rcube_utils::INPUT_GPC)));
         }
 
         $out  = $input_task->show();
@@ -1481,7 +1516,7 @@
         if (empty($attrib['form'])) {
             $out = $this->form_tag(array(
                 'name' => "rcmqsearchform",
-                'onsubmit' => JS_OBJECT_NAME . ".command('search');return false;",
+                'onsubmit' => rcmail::JS_OBJECT_NAME . ".command('search'); return false",
                 'style' => "display:inline"),
                 $out);
         }
@@ -1560,16 +1595,20 @@
             'GB2312'       => 'GB2312 ('.$this->app->gettext('chinese').')',
         );
 
-        if (!empty($_POST['_charset']))
-	        $set = $_POST['_charset'];
-	    else if (!empty($attrib['selected']))
-	        $set = $attrib['selected'];
-	    else
-	        $set = $this->get_charset();
+        if (!empty($_POST['_charset'])) {
+            $set = $_POST['_charset'];
+        }
+        else if (!empty($attrib['selected'])) {
+            $set = $attrib['selected'];
+        }
+        else {
+            $set = $this->get_charset();
+        }
 
-	    $set = strtoupper($set);
-	    if (!isset($charsets[$set]))
-	        $charsets[$set] = $set;
+        $set = strtoupper($set);
+        if (!isset($charsets[$set])) {
+            $charsets[$set] = $set;
+        }
 
         $select = new html_select($field_attrib);
         $select->add(array_values($charsets), array_keys($charsets));

--
Gitblit v1.9.1