| | |
| | | <?php |
| | | |
| | | /* |
| | | /** |
| | | +-----------------------------------------------------------------------+ |
| | | | This file is part of the Roundcube Webmail client | |
| | | | Copyright (C) 2005-2013, The Roundcube Dev Team | |
| | |
| | | +-----------------------------------------------------------------------+ |
| | | */ |
| | | |
| | | |
| | | /** |
| | | * Class for HTML code creation |
| | | * |
| | |
| | | class html |
| | | { |
| | | protected $tagname; |
| | | protected $attrib = array(); |
| | | protected $attrib = array(); |
| | | protected $allowed = array(); |
| | | protected $content; |
| | | |
| | |
| | | * @param string $tagname Tag name |
| | | * @param array $attrib Tag attributes as key/value pairs |
| | | * @param string $content Optinal Tag content (creates a container tag) |
| | | * @param array $allowed_attrib List with allowed attributes, omit to allow all |
| | | * @param array $allowed List with allowed attributes, omit to allow all |
| | | * |
| | | * @return string The XHTML tag |
| | | */ |
| | | public static function tag($tagname, $attrib = array(), $content = null, $allowed_attrib = null) |
| | | public static function tag($tagname, $attrib = array(), $content = null, $allowed = null) |
| | | { |
| | | if (is_string($attrib)) |
| | | if (is_string($attrib)) { |
| | | $attrib = array('class' => $attrib); |
| | | } |
| | | |
| | | $inline_tags = array('a','span','img'); |
| | | $suffix = $attrib['nl'] || ($content && $attrib['nl'] !== false && !in_array($tagname, $inline_tags)) ? "\n" : ''; |
| | |
| | | if (isset($content) || in_array($tagname, self::$containers)) { |
| | | $suffix = $attrib['noclose'] ? $suffix : '</' . $tagname . '>' . $suffix; |
| | | unset($attrib['noclose'], $attrib['nl']); |
| | | return '<' . $tagname . self::attrib_string($attrib, $allowed_attrib) . '>' . $content . $suffix; |
| | | return '<' . $tagname . self::attrib_string($attrib, $allowed) . '>' . $content . $suffix; |
| | | } |
| | | else { |
| | | return '<' . $tagname . self::attrib_string($attrib, $allowed_attrib) . '>' . $suffix; |
| | | return '<' . $tagname . self::attrib_string($attrib, $allowed) . '>' . $suffix; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Return DOCTYPE tag of specified type |
| | | * |
| | | * @param string $type Document type (html5, xhtml, 'xhtml-trans, xhtml-strict) |
| | | */ |
| | | public static function doctype($type) |
| | | { |
| | |
| | | * |
| | | * @param mixed $attr Hash array with tag attributes or string with class name |
| | | * @param string $cont Div content |
| | | * |
| | | * @return string HTML code |
| | | * @see html::tag() |
| | | */ |
| | |
| | | if (is_string($attr)) { |
| | | $attr = array('class' => $attr); |
| | | } |
| | | |
| | | return self::tag('div', $attr, $cont, array_merge(self::$common_attrib, array('onclick'))); |
| | | } |
| | | |
| | |
| | | * |
| | | * @param mixed $attr Hash array with tag attributes or string with class name |
| | | * @param string $cont Paragraph content |
| | | * |
| | | * @return string HTML code |
| | | * @see html::tag() |
| | | */ |
| | |
| | | if (is_string($attr)) { |
| | | $attr = array('class' => $attr); |
| | | } |
| | | |
| | | return self::tag('p', $attr, $cont, self::$common_attrib); |
| | | } |
| | | |
| | |
| | | * Derrived method to create <img /> |
| | | * |
| | | * @param mixed $attr Hash array with tag attributes or string with image source (src) |
| | | * |
| | | * @return string HTML code |
| | | * @see html::tag() |
| | | */ |
| | |
| | | if (is_string($attr)) { |
| | | $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','onerror'))); |
| | | } |
| | |
| | | * |
| | | * @param mixed $attr Hash array with tag attributes or string with link location (href) |
| | | * @param string $cont Link content |
| | | * |
| | | * @return string HTML code |
| | | * @see html::tag() |
| | | */ |
| | |
| | | if (is_string($attr)) { |
| | | $attr = array('href' => $attr); |
| | | } |
| | | |
| | | return self::tag('a', $attr, $cont, array_merge(self::$common_attrib, |
| | | array('href','target','name','rel','onclick','onmouseover','onmouseout','onmousedown','onmouseup'))); |
| | | } |
| | |
| | | * |
| | | * @param mixed $attr Hash array with tag attributes or string with class name |
| | | * @param string $cont Tag content |
| | | * |
| | | * @return string HTML code |
| | | * @see html::tag() |
| | | */ |
| | |
| | | if (is_string($attr)) { |
| | | $attr = array('class' => $attr); |
| | | } |
| | | |
| | | return self::tag('span', $attr, $cont, self::$common_attrib); |
| | | } |
| | | |
| | |
| | | * |
| | | * @param mixed $attr Hash array with tag attributes or string with 'for' attrib |
| | | * @param string $cont Tag content |
| | | * |
| | | * @return string HTML code |
| | | * @see html::tag() |
| | | */ |
| | |
| | | if (is_string($attr)) { |
| | | $attr = array('for' => $attr); |
| | | } |
| | | |
| | | return self::tag('label', $attr, $cont, array_merge(self::$common_attrib, array('for'))); |
| | | } |
| | | |
| | |
| | | * Derrived method to create <iframe></iframe> |
| | | * |
| | | * @param mixed $attr Hash array with tag attributes or string with frame source (src) |
| | | * |
| | | * @return string HTML code |
| | | * @see html::tag() |
| | | */ |
| | |
| | | if (is_string($attr)) { |
| | | $attr = array('src' => $attr); |
| | | } |
| | | |
| | | return self::tag('iframe', $attr, $cont, array_merge(self::$common_attrib, |
| | | array('src','name','width','height','border','frameborder','onload','allowfullscreen'))); |
| | | } |
| | |
| | | /** |
| | | * Derrived method to create <script> tags |
| | | * |
| | | * @param mixed $attr Hash array with tag attributes or string with script source (src) |
| | | * @param mixed $attr Hash array with tag attributes or string with script source (src) |
| | | * @param string $cont Javascript code to be placed as tag content |
| | | * |
| | | * @return string HTML code |
| | | * @see html::tag() |
| | | */ |
| | |
| | | /** |
| | | * Derrived method for line breaks |
| | | * |
| | | * @param array $attrib Associative arry with tag attributes |
| | | * |
| | | * @return string HTML code |
| | | * @see html::tag() |
| | | */ |
| | |
| | | /** |
| | | * Create string with attributes |
| | | * |
| | | * @param array $attrib Associative arry with tag attributes |
| | | * @param array $attrib Associative arry with tag attributes |
| | | * @param array $allowed List of allowed attributes |
| | | * |
| | | * @return string Valid attribute string |
| | | */ |
| | | public static function attrib_string($attrib = array(), $allowed = null) |
| | |
| | | * Convert a HTML attribute string attributes to an associative array (name => value) |
| | | * |
| | | * @param string Input string |
| | | * |
| | | * @return array Key-value pairs of parsed attributes |
| | | */ |
| | | public static function parse_attrib_string($str) |
| | |
| | | class html_inputfield extends html |
| | | { |
| | | protected $tagname = 'input'; |
| | | protected $type = 'text'; |
| | | protected $type = 'text'; |
| | | protected $allowed = array( |
| | | 'type','name','value','size','tabindex','autocapitalize','required', |
| | | 'autocomplete','checked','onchange','onclick','disabled','readonly', |
| | |
| | | /** |
| | | * Compose input tag |
| | | * |
| | | * @param string $value Field value |
| | | * @param string $value Field value |
| | | * @param array $attrib Additional attributes to override |
| | | * |
| | | * @return string HTML output |
| | | */ |
| | | public function show($value = null, $attrib = null) |
| | |
| | | } |
| | | // set type |
| | | $this->attrib['type'] = $this->type; |
| | | |
| | | return parent::show(); |
| | | } |
| | | } |
| | |
| | | class html_hiddenfield extends html |
| | | { |
| | | protected $tagname = 'input'; |
| | | protected $type = 'hidden'; |
| | | protected $fields_arr = array(); |
| | | protected $type = 'hidden'; |
| | | protected $allowed = array('type','name','value','onchange','disabled','readonly'); |
| | | protected $fields_arr = array(); |
| | | |
| | | /** |
| | | * Constructor |
| | |
| | | foreach ($this->fields_arr as $attrib) { |
| | | $out .= self::tag($this->tagname, array('type' => $this->type) + $attrib); |
| | | } |
| | | |
| | | return $out; |
| | | } |
| | | } |
| | |
| | | * |
| | | * @param string $value Value of the checked field |
| | | * @param array $attrib Additional attributes to override |
| | | * |
| | | * @return string HTML output |
| | | */ |
| | | public function show($value = '', $attrib = null) |
| | |
| | | * |
| | | * @param string $value Value of the checked field |
| | | * @param array $attrib Additional attributes to override |
| | | * |
| | | * @return string HTML output |
| | | */ |
| | | public function show($value = '', $attrib = null) |
| | |
| | | * |
| | | * @param string $value Textbox value |
| | | * @param array $attrib Additional attributes to override |
| | | * |
| | | * @return string HTML output |
| | | */ |
| | | public function show($value = '', $attrib = null) |
| | |
| | | * |
| | | * @param string $select Value of the selection option |
| | | * @param array $attrib Additional attributes to override |
| | | * |
| | | * @return string HTML output |
| | | */ |
| | | public function show($select = array(), $attrib = null) |
| | |
| | | protected $allowed = array('id','class','style','width','summary', |
| | | 'cellpadding','cellspacing','border'); |
| | | |
| | | private $header = array(); |
| | | private $rows = array(); |
| | | private $header = array(); |
| | | private $rows = array(); |
| | | private $rowindex = 0; |
| | | private $colindex = 0; |
| | | |
| | |
| | | $this->colindex = 0; |
| | | $this->rows[$this->rowindex] = new stdClass; |
| | | $this->rows[$this->rowindex]->attrib = $attr; |
| | | $this->rows[$this->rowindex]->cells = array(); |
| | | $this->rows[$this->rowindex]->cells = array(); |
| | | } |
| | | |
| | | /** |
| | |
| | | * Build HTML output of the table data |
| | | * |
| | | * @param array $attrib Table attributes |
| | | * |
| | | * @return string The final table HTML code |
| | | */ |
| | | public function show($attrib = null) |
| | |
| | | static $col_tagnames = array('table' => 'td', '*' => 'span'); |
| | | return $col_tagnames[$this->tagname] ?: $col_tagnames['*']; |
| | | } |
| | | |
| | | } |