File indexing completed on 2024-12-22 05:37:13
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_View 0017 * @subpackage Helper 0018 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0019 * @license http://framework.zend.com/license/new-bsd New BSD License 0020 * @version $Id$ 0021 */ 0022 0023 /** 0024 * @see Zend_View_Helper_Abstract 0025 */ 0026 // require_once 'Zend/View/Helper/Abstract.php'; 0027 0028 /** 0029 * @category Zend 0030 * @package Zend_View 0031 * @subpackage Helper 0032 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0033 * @license http://framework.zend.com/license/new-bsd New BSD License 0034 */ 0035 abstract class Zend_View_Helper_HtmlElement extends Zend_View_Helper_Abstract 0036 { 0037 /** 0038 * EOL character 0039 */ 0040 const EOL = "\n"; 0041 0042 /** 0043 * The tag closing bracket 0044 * 0045 * @var string 0046 */ 0047 protected $_closingBracket = null; 0048 0049 /** 0050 * Get the tag closing bracket 0051 * 0052 * @return string 0053 */ 0054 public function getClosingBracket() 0055 { 0056 if (!$this->_closingBracket) { 0057 if ($this->_isXhtml()) { 0058 $this->_closingBracket = ' />'; 0059 } else { 0060 $this->_closingBracket = '>'; 0061 } 0062 } 0063 0064 return $this->_closingBracket; 0065 } 0066 0067 /** 0068 * Is doctype XHTML? 0069 * 0070 * @return boolean 0071 */ 0072 protected function _isXhtml() 0073 { 0074 $doctype = $this->view->doctype(); 0075 return $doctype->isXhtml(); 0076 } 0077 0078 /** 0079 * Is doctype HTML5? 0080 * 0081 * @return boolean 0082 */ 0083 protected function _isHtml5() 0084 { 0085 $doctype = $this->view->doctype(); 0086 return $doctype->isHtml5(); 0087 } 0088 0089 /** 0090 * Is doctype strict? 0091 * 0092 * @return boolean 0093 */ 0094 protected function _isStrictDoctype() 0095 { 0096 $doctype = $this->view->doctype(); 0097 return $doctype->isStrict(); 0098 } 0099 0100 /** 0101 * Converts an associative array to a string of tag attributes. 0102 * 0103 * @access public 0104 * 0105 * @param array $attribs From this array, each key-value pair is 0106 * converted to an attribute name and value. 0107 * 0108 * @return string The XHTML for the attributes. 0109 */ 0110 protected function _htmlAttribs($attribs) 0111 { 0112 $xhtml = ''; 0113 foreach ((array) $attribs as $key => $val) { 0114 $key = $this->view->escape($key); 0115 0116 if (('on' == substr($key, 0, 2)) || ('constraints' == $key)) { 0117 // Don't escape event attributes; _do_ substitute double quotes with singles 0118 if (!is_scalar($val)) { 0119 // non-scalar data should be cast to JSON first 0120 // require_once 'Zend/Json.php'; 0121 $val = Zend_Json::encode($val); 0122 } 0123 // Escape single quotes inside event attribute values. 0124 // This will create html, where the attribute value has 0125 // single quotes around it, and escaped single quotes or 0126 // non-escaped double quotes inside of it 0127 $val = str_replace('\'', ''', $val); 0128 } else { 0129 if (is_array($val)) { 0130 $val = implode(' ', $val); 0131 } 0132 $val = $this->view->escape($val); 0133 } 0134 0135 if ('id' == $key) { 0136 $val = $this->_normalizeId($val); 0137 } 0138 0139 if (strpos($val, '"') !== false) { 0140 $xhtml .= " $key='$val'"; 0141 } else { 0142 $xhtml .= " $key=\"$val\""; 0143 } 0144 0145 } 0146 return $xhtml; 0147 } 0148 0149 /** 0150 * Normalize an ID 0151 * 0152 * @param string $value 0153 * @return string 0154 */ 0155 protected function _normalizeId($value) 0156 { 0157 if (strstr($value, '[')) { 0158 if ('[]' == substr($value, -2)) { 0159 $value = substr($value, 0, strlen($value) - 2); 0160 } 0161 $value = trim($value, ']'); 0162 $value = str_replace('][', '-', $value); 0163 $value = str_replace('[', '-', $value); 0164 } 0165 return $value; 0166 } 0167 }