PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins_repo/openXWorkflow/www/admin/plugins/openXWorkflow/library/Zend/View/Helper/Doctype.php

https://github.com/orchestra-io/sample-openx
PHP | 194 lines | 96 code | 14 blank | 84 comment | 8 complexity | 716404514c7b87d8ee2c72f66edb9eb7 MD5 | raw file
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @package Zend_View
  16. * @subpackage Helper
  17. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @version $Id: Placeholder.php 7078 2007-12-11 14:29:33Z matthew $
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /** Zend_Registry */
  22. require_once 'Zend/Registry.php';
  23. /** Zend_View_Helper_Abstract.php */
  24. require_once 'Zend/View/Helper/Abstract.php';
  25. /**
  26. * Helper for setting and retrieving the doctype
  27. *
  28. * @package Zend_View
  29. * @subpackage Helper
  30. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. */
  33. class Zend_View_Helper_Doctype extends Zend_View_Helper_Abstract
  34. {
  35. /**#@+
  36. * DocType constants
  37. */
  38. const XHTML11 = 'XHTML11';
  39. const XHTML1_STRICT = 'XHTML1_STRICT';
  40. const XHTML1_TRANSITIONAL = 'XHTML1_TRANSITIONAL';
  41. const XHTML1_FRAMESET = 'XHTML1_FRAMESET';
  42. const XHTML_BASIC1 = 'XHTML_BASIC1';
  43. const HTML4_STRICT = 'HTML4_STRICT';
  44. const HTML4_LOOSE = 'HTML4_LOOSE';
  45. const HTML4_FRAMESET = 'HTML4_FRAMESET';
  46. const HTML5 = 'HTML5';
  47. const CUSTOM_XHTML = 'CUSTOM_XHTML';
  48. const CUSTOM = 'CUSTOM';
  49. /**#@-*/
  50. /**
  51. * Default DocType
  52. * @var string
  53. */
  54. protected $_defaultDoctype = self::HTML4_LOOSE;
  55. /**
  56. * Registry containing current doctype and mappings
  57. * @var ArrayObject
  58. */
  59. protected $_registry;
  60. /**
  61. * Registry key in which helper is stored
  62. * @var string
  63. */
  64. protected $_regKey = 'Zend_View_Helper_Doctype';
  65. /**
  66. * Constructor
  67. *
  68. * Map constants to doctype strings, and set default doctype
  69. *
  70. * @return void
  71. */
  72. public function __construct()
  73. {
  74. if (!Zend_Registry::isRegistered($this->_regKey)) {
  75. $this->_registry = new ArrayObject(array(
  76. 'doctypes' => array(
  77. self::XHTML11 => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">',
  78. self::XHTML1_STRICT => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
  79. self::XHTML1_TRANSITIONAL => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
  80. self::XHTML1_FRAMESET => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">',
  81. self::XHTML_BASIC1 => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd">',
  82. self::HTML4_STRICT => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">',
  83. self::HTML4_LOOSE => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">',
  84. self::HTML4_FRAMESET => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">',
  85. self::HTML5 => '<!DOCTYPE html>',
  86. )
  87. ));
  88. Zend_Registry::set($this->_regKey, $this->_registry);
  89. $this->setDoctype($this->_defaultDoctype);
  90. } else {
  91. $this->_registry = Zend_Registry::get($this->_regKey);
  92. }
  93. }
  94. /**
  95. * Set or retrieve doctype
  96. *
  97. * @param string $doctype
  98. * @return Zend_View_Helper_Doctype
  99. */
  100. public function doctype($doctype = null)
  101. {
  102. if (null !== $doctype) {
  103. switch ($doctype) {
  104. case self::XHTML11:
  105. case self::XHTML1_STRICT:
  106. case self::XHTML1_TRANSITIONAL:
  107. case self::XHTML1_FRAMESET:
  108. case self::XHTML_BASIC1:
  109. case self::HTML4_STRICT:
  110. case self::HTML4_LOOSE:
  111. case self::HTML4_FRAMESET:
  112. case self::HTML5:
  113. $this->setDoctype($doctype);
  114. break;
  115. default:
  116. if (substr($doctype, 0, 9) != '<!DOCTYPE') {
  117. require_once 'Zend/View/Exception.php';
  118. throw new Zend_View_Exception('The specified doctype is malformed');
  119. }
  120. if (stristr($doctype, 'xhtml')) {
  121. $type = self::CUSTOM_XHTML;
  122. } else {
  123. $type = self::CUSTOM;
  124. }
  125. $this->setDoctype($type);
  126. $this->_registry['doctypes'][$type] = $doctype;
  127. break;
  128. }
  129. }
  130. return $this;
  131. }
  132. /**
  133. * Set doctype
  134. *
  135. * @param string $doctype
  136. * @return Zend_View_Helper_Doctype
  137. */
  138. public function setDoctype($doctype)
  139. {
  140. $this->_registry['doctype'] = $doctype;
  141. return $this;
  142. }
  143. /**
  144. * Retrieve doctype
  145. *
  146. * @return string
  147. */
  148. public function getDoctype()
  149. {
  150. return $this->_registry['doctype'];
  151. }
  152. /**
  153. * Get doctype => string mappings
  154. *
  155. * @return array
  156. */
  157. public function getDoctypes()
  158. {
  159. return $this->_registry['doctypes'];
  160. }
  161. /**
  162. * Is doctype XHTML?
  163. *
  164. * @return boolean
  165. */
  166. public function isXhtml()
  167. {
  168. return (stristr($this->getDoctype(), 'xhtml') ? true : false);
  169. }
  170. /**
  171. * String representation of doctype
  172. *
  173. * @return string
  174. */
  175. public function __toString()
  176. {
  177. $doctypes = $this->getDoctypes();
  178. return $doctypes[$this->getDoctype()];
  179. }
  180. }