00001 <?php 00024 require_once 'Zend/Registry.php'; 00025 00027 require_once 'Zend/View/Helper/Abstract.php'; 00028 00037 class Zend_View_Helper_Doctype extends Zend_View_Helper_Abstract 00038 { 00042 const XHTML11 = 'XHTML11'; 00043 const XHTML1_STRICT = 'XHTML1_STRICT'; 00044 const XHTML1_TRANSITIONAL = 'XHTML1_TRANSITIONAL'; 00045 const XHTML1_FRAMESET = 'XHTML1_FRAMESET'; 00046 const XHTML_BASIC1 = 'XHTML_BASIC1'; 00047 const HTML4_STRICT = 'HTML4_STRICT'; 00048 const HTML4_LOOSE = 'HTML4_LOOSE'; 00049 const HTML4_FRAMESET = 'HTML4_FRAMESET'; 00050 const HTML5 = 'HTML5'; 00051 const CUSTOM_XHTML = 'CUSTOM_XHTML'; 00052 const CUSTOM = 'CUSTOM'; 00059 protected $_defaultDoctype = self::HTML4_LOOSE; 00060 00065 protected $_registry; 00066 00071 protected $_regKey = 'Zend_View_Helper_Doctype'; 00072 00080 public function __construct() 00081 { 00082 if (!Zend_Registry::isRegistered($this->_regKey)) { 00083 $this->_registry = new ArrayObject(array( 00084 'doctypes' => array( 00085 self::XHTML11 => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">', 00086 self::XHTML1_STRICT => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">', 00087 self::XHTML1_TRANSITIONAL => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">', 00088 self::XHTML1_FRAMESET => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">', 00089 self::XHTML_BASIC1 => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd">', 00090 self::HTML4_STRICT => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">', 00091 self::HTML4_LOOSE => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">', 00092 self::HTML4_FRAMESET => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">', 00093 self::HTML5 => '<!DOCTYPE html>', 00094 ) 00095 )); 00096 Zend_Registry::set($this->_regKey, $this->_registry); 00097 $this->setDoctype($this->_defaultDoctype); 00098 } else { 00099 $this->_registry = Zend_Registry::get($this->_regKey); 00100 } 00101 } 00102 00109 public function doctype($doctype = null) 00110 { 00111 if (null !== $doctype) { 00112 switch ($doctype) { 00113 case self::XHTML11: 00114 case self::XHTML1_STRICT: 00115 case self::XHTML1_TRANSITIONAL: 00116 case self::XHTML1_FRAMESET: 00117 case self::XHTML_BASIC1: 00118 case self::HTML4_STRICT: 00119 case self::HTML4_LOOSE: 00120 case self::HTML4_FRAMESET: 00121 case self::HTML5: 00122 $this->setDoctype($doctype); 00123 break; 00124 default: 00125 if (substr($doctype, 0, 9) != '<!DOCTYPE') { 00126 require_once 'Zend/View/Exception.php'; 00127 throw new Zend_View_Exception('The specified doctype is malformed'); 00128 } 00129 if (stristr($doctype, 'xhtml')) { 00130 $type = self::CUSTOM_XHTML; 00131 } else { 00132 $type = self::CUSTOM; 00133 } 00134 $this->setDoctype($type); 00135 $this->_registry['doctypes'][$type] = $doctype; 00136 break; 00137 } 00138 } 00139 00140 return $this; 00141 } 00142 00149 public function setDoctype($doctype) 00150 { 00151 $this->_registry['doctype'] = $doctype; 00152 return $this; 00153 } 00154 00160 public function getDoctype() 00161 { 00162 return $this->_registry['doctype']; 00163 } 00164 00170 public function getDoctypes() 00171 { 00172 return $this->_registry['doctypes']; 00173 } 00174 00180 public function isXhtml() 00181 { 00182 return (stristr($this->getDoctype(), 'xhtml') ? true : false); 00183 } 00184 00190 public function __toString() 00191 { 00192 $doctypes = $this->getDoctypes(); 00193 return $doctypes[$this->getDoctype()]; 00194 } 00195 }