• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List

E:/E/GEAMP/www/openbiz/openbiz/others/Zend/View/Helper/HtmlElement.php

00001 <?php
00026 require_once 'Zend/View/Helper/Abstract.php';
00027 
00035 abstract class Zend_View_Helper_HtmlElement extends Zend_View_Helper_Abstract
00036 {
00040     const EOL = "\n";
00041 
00047     protected $_closingBracket = null;
00048 
00054     public function getClosingBracket()
00055     {
00056         if (!$this->_closingBracket) {
00057             if ($this->_isXhtml()) {
00058                 $this->_closingBracket = ' />';
00059             } else {
00060                 $this->_closingBracket = '>';
00061             }
00062         }
00063 
00064         return $this->_closingBracket;
00065     }
00066 
00072     protected function _isXhtml()
00073     {
00074         $doctype = $this->view->doctype();
00075         return $doctype->isXhtml();
00076     }
00077 
00088     protected function _htmlAttribs($attribs)
00089     {
00090         $xhtml = '';
00091         foreach ((array) $attribs as $key => $val) {
00092             $key = $this->view->escape($key);
00093 
00094             if (('on' == substr($key, 0, 2)) || ('constraints' == $key)) {
00095                 // Don't escape event attributes; _do_ substitute double quotes with singles
00096                 if (!is_scalar($val)) {
00097                     // non-scalar data should be cast to JSON first
00098                     require_once 'Zend/Json.php';
00099                     $val = Zend_Json::encode($val);
00100                 }
00101                 $val = preg_replace('/"([^"]*)":/', '$1:', $val);
00102             } else {
00103                 if (is_array($val)) {
00104                     $val = implode(' ', $val);
00105                 }
00106                 $val = $this->view->escape($val);
00107             }
00108 
00109             if ('id' == $key) {
00110                 $val = $this->_normalizeId($val);
00111             }
00112 
00113             if (strpos($val, '"') !== false) {
00114                 $xhtml .= " $key='$val'";
00115             } else {
00116                 $xhtml .= " $key=\"$val\"";
00117             }
00118 
00119         }
00120         return $xhtml;
00121     }
00122 
00129     protected function _normalizeId($value)
00130     {
00131         if (strstr($value, '[')) {
00132             if ('[]' == substr($value, -2)) {
00133                 $value = substr($value, 0, strlen($value) - 2);
00134             }
00135             $value = trim($value, ']');
00136             $value = str_replace('][', '-', $value);
00137             $value = str_replace('[', '-', $value);
00138         }
00139         return $value;
00140     }
00141 }

Generated on Thu Apr 19 2012 17:01:18 for openbiz by  doxygen 1.7.2