From 2f8b1036da42ec3d15a51c6b17a473f9f4df71d3 Mon Sep 17 00:00:00 2001
From: Thomas Bruederli <bruederli@kolabsys.com>
Date: Sat, 07 Feb 2015 12:33:24 -0500
Subject: [PATCH] Bump version and copyright year

---
 program/lib/Roundcube/html.php |  133 +++++++++++++++++++++++++++++++++-----------
 1 files changed, 100 insertions(+), 33 deletions(-)

diff --git a/program/lib/Roundcube/html.php b/program/lib/Roundcube/html.php
index 522a823..f18cad0 100644
--- a/program/lib/Roundcube/html.php
+++ b/program/lib/Roundcube/html.php
@@ -3,7 +3,7 @@
 /*
  +-----------------------------------------------------------------------+
  | This file is part of the Roundcube Webmail client                     |
- | Copyright (C) 2005-2011, The Roundcube Dev Team                       |
+ | Copyright (C) 2005-2013, The Roundcube Dev Team                       |
  |                                                                       |
  | Licensed under the GNU General Public License version 3 or            |
  | any later version with exceptions for skins & plugins.                |
@@ -21,7 +21,7 @@
  * Class for HTML code creation
  *
  * @package    Framework
- * @subpackage HTML
+ * @subpackage View
  */
 class html
 {
@@ -32,8 +32,9 @@
 
     public static $doctype = 'xhtml';
     public static $lc_tags = true;
-    public static $common_attrib = array('id','class','style','title','align');
-    public static $containers = array('iframe','div','span','p','h1','h2','h3','form','textarea','table','thead','tbody','tr','th','td','style','script');
+    public static $common_attrib = array('id','class','style','title','align','unselectable','tabindex','role');
+    public static $containers = array('iframe','div','span','p','h1','h2','h3','ul','form','textarea','table','thead','tbody','tr','th','td','style','script');
+
 
     /**
      * Constructor
@@ -152,7 +153,7 @@
             $attr = array('src' => $attr);
         }
         return self::tag('img', $attr + array('alt' => ''), null, array_merge(self::$common_attrib,
-            array('src','alt','width','height','border','usemap','onclick')));
+            array('src','alt','width','height','border','usemap','onclick','onerror')));
     }
 
     /**
@@ -217,7 +218,7 @@
             $attr = array('src' => $attr);
         }
         return self::tag('iframe', $attr, $cont, array_merge(self::$common_attrib,
-            array('src','name','width','height','border','frameborder')));
+            array('src','name','width','height','border','frameborder','onload','allowfullscreen')));
     }
 
     /**
@@ -268,17 +269,27 @@
             return '';
         }
 
-        $allowed_f = array_flip((array)$allowed);
+        $allowed_f  = array_flip((array)$allowed);
         $attrib_arr = array();
+
         foreach ($attrib as $key => $value) {
             // skip size if not numeric
             if ($key == 'size' && !is_numeric($value)) {
                 continue;
             }
 
-            // ignore "internal" or not allowed attributes
-            if ($key == 'nl' || ($allowed && !isset($allowed_f[$key])) || $value === null) {
+            // ignore "internal" or empty attributes
+            if ($key == 'nl' || $value === null) {
                 continue;
+            }
+
+            // ignore not allowed attributes, except aria-* and data-*
+            if (!empty($allowed)) {
+                $is_data_attr = @substr_compare($key, 'data-', 0, 5) === 0;
+                $is_aria_attr = @substr_compare($key, 'aria-', 0, 5) === 0;
+                if (!$is_aria_attr && !$is_data_attr && !isset($allowed_f[$key])) {
+                    continue;
+                }
             }
 
             // skip empty eventhandlers
@@ -287,7 +298,7 @@
             }
 
             // attributes with no value
-            if (in_array($key, array('checked', 'multiple', 'disabled', 'selected'))) {
+            if (in_array($key, array('checked', 'multiple', 'disabled', 'selected', 'autofocus'))) {
                 if ($value) {
                     $attrib_arr[] = $key . '="' . $key . '"';
                 }
@@ -332,7 +343,16 @@
      */
     public static function quote($str)
     {
-        return @htmlspecialchars($str, ENT_COMPAT, RCUBE_CHARSET);
+        static $flags;
+
+        if (!$flags) {
+            $flags = ENT_COMPAT;
+            if (defined('ENT_SUBSTITUTE')) {
+                $flags |= ENT_SUBSTITUTE;
+            }
+        }
+
+        return @htmlspecialchars($str, $flags, RCUBE_CHARSET);
     }
 }
 
@@ -340,16 +360,18 @@
 /**
  * Class to create an HTML input field
  *
- * @package HTML
+ * @package    Framework
+ * @subpackage View
  */
 class html_inputfield extends html
 {
     protected $tagname = 'input';
     protected $type = 'text';
     protected $allowed = array(
-        'type','name','value','size','tabindex','autocapitalize',
+        'type','name','value','size','tabindex','autocapitalize','required',
         'autocomplete','checked','onchange','onclick','disabled','readonly',
-        'spellcheck','results','maxlength','src','multiple','placeholder',
+        'spellcheck','results','maxlength','src','multiple','accept',
+        'placeholder','autofocus',
     );
 
     /**
@@ -395,7 +417,8 @@
 /**
  * Class to create an HTML password field
  *
- * @package HTML
+ * @package    Framework
+ * @subpackage View
  */
 class html_passwordfield extends html_inputfield
 {
@@ -405,9 +428,9 @@
 /**
  * Class to create an hidden HTML input field
  *
- * @package HTML
+ * @package    Framework
+ * @subpackage View
  */
-
 class html_hiddenfield extends html
 {
     protected $tagname = 'input';
@@ -455,7 +478,8 @@
 /**
  * Class to create HTML radio buttons
  *
- * @package HTML
+ * @package    Framework
+ * @subpackage View
  */
 class html_radiobutton extends html_inputfield
 {
@@ -485,7 +509,8 @@
 /**
  * Class to create HTML checkboxes
  *
- * @package HTML
+ * @package    Framework
+ * @subpackage View
  */
 class html_checkbox extends html_inputfield
 {
@@ -515,7 +540,8 @@
 /**
  * Class to create an HTML textarea
  *
- * @package HTML
+ * @package    Framework
+ * @subpackage View
  */
 class html_textarea extends html
 {
@@ -573,7 +599,8 @@
  * print $select->show('CH');
  * </pre>
  *
- * @package HTML
+ * @package    Framework
+ * @subpackage View
  */
 class html_select extends html
 {
@@ -587,16 +614,17 @@
      *
      * @param mixed $names  Option name or array with option names
      * @param mixed $values Option value or array with option values
+     * @param array $attrib Additional attributes for the option entry
      */
-    public function add($names, $values = null)
+    public function add($names, $values = null, $attrib = array())
     {
         if (is_array($names)) {
             foreach ($names as $i => $text) {
-                $this->options[] = array('text' => $text, 'value' => $values[$i]);
+                $this->options[] = array('text' => $text, 'value' => $values[$i]) + $attrib;
             }
         }
         else {
-            $this->options[] = array('text' => $names, 'value' => $values);
+            $this->options[] = array('text' => $names, 'value' => $values) + $attrib;
         }
     }
 
@@ -627,7 +655,7 @@
                 $option_content = self::quote($option_content);
             }
 
-            $this->content .= self::tag('option', $attr, $option_content);
+            $this->content .= self::tag('option', $attr + $option, $option_content, array('value','label','class','style','title','disabled','selected'));
         }
 
         return parent::show();
@@ -638,7 +666,8 @@
 /**
  * Class to build an HTML table
  *
- * @package HTML
+ * @package    Framework
+ * @subpackage View
  */
 class html_table extends html
 {
@@ -658,8 +687,13 @@
      */
     public function __construct($attrib = array())
     {
-        $default_attrib = self::$doctype == 'xhtml' ? array('summary' => '', 'border' => 0) : array();
-        $this->attrib = array_merge($attrib, $default_attrib);
+        $default_attrib = self::$doctype == 'xhtml' ? array('summary' => '', 'border' => '0') : array();
+        $this->attrib   = array_merge($attrib, $default_attrib);
+
+        if (!empty($attrib['tagname']) && $attrib['tagname'] != 'table') {
+          $this->tagname = $attrib['tagname'];
+          $this->allowed = self::$common_attrib;
+        }
     }
 
     /**
@@ -761,6 +795,11 @@
             $index = $this->rowindex;
         }
 
+        // make sure row object exists (#1489094)
+        if (!$this->rows[$index]) {
+            $this->rows[$index] = new stdClass;
+        }
+
         $this->rows[$index]->attrib = $attr;
     }
 
@@ -798,19 +837,20 @@
         if (!empty($this->header)) {
             $rowcontent = '';
             foreach ($this->header as $c => $col) {
-                $rowcontent .= self::tag('td', $col->attrib, $col->content);
+                $rowcontent .= self::tag($this->_head_tagname(), $col->attrib, $col->content);
             }
-            $thead = self::tag('thead', null, self::tag('tr', null, $rowcontent, parent::$common_attrib));
+            $thead = $this->tagname == 'table' ? self::tag('thead', null, self::tag('tr', null, $rowcontent, parent::$common_attrib)) :
+                self::tag($this->_row_tagname(), array('class' => 'thead'), $rowcontent, parent::$common_attrib);
         }
 
         foreach ($this->rows as $r => $row) {
             $rowcontent = '';
             foreach ($row->cells as $c => $col) {
-                $rowcontent .= self::tag('td', $col->attrib, $col->content);
+                $rowcontent .= self::tag($this->_col_tagname(), $col->attrib, $col->content);
             }
 
             if ($r < $this->rowindex || count($row->cells)) {
-                $tbody .= self::tag('tr', $row->attrib, $rowcontent, parent::$common_attrib);
+                $tbody .= self::tag($this->_row_tagname(), $row->attrib, $rowcontent, parent::$common_attrib);
             }
         }
 
@@ -819,7 +859,7 @@
         }
 
         // add <tbody>
-        $this->content = $thead . self::tag('tbody', null, $tbody);
+        $this->content = $thead . ($this->tagname == 'table' ? self::tag('tbody', null, $tbody) : $tbody);
 
         unset($this->attrib['cols'], $this->attrib['rowsonly']);
         return parent::show();
@@ -844,4 +884,31 @@
         $this->rowindex = 0;
     }
 
+    /**
+     * Getter for the corresponding tag name for table row elements
+     */
+    private function _row_tagname()
+    {
+        static $row_tagnames = array('table' => 'tr', 'ul' => 'li', '*' => 'div');
+        return $row_tagnames[$this->tagname] ?: $row_tagnames['*'];
+    }
+
+    /**
+     * Getter for the corresponding tag name for table row elements
+     */
+    private function _head_tagname()
+    {
+        static $head_tagnames = array('table' => 'th', '*' => 'span');
+        return $head_tagnames[$this->tagname] ?: $head_tagnames['*'];
+    }
+
+    /**
+     * Getter for the corresponding tag name for table cell elements
+     */
+    private function _col_tagname()
+    {
+        static $col_tagnames = array('table' => 'td', '*' => 'span');
+        return $col_tagnames[$this->tagname] ?: $col_tagnames['*'];
+    }
+
 }

--
Gitblit v1.9.1