Warning, file /webapps/ocs-webserver/library/Zend/View/Helper/Doctype.php was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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  * @version    $Id$
0020  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0021  */
0022 
0023 /** Zend_Registry */
0024 // require_once 'Zend/Registry.php';
0025 
0026 /** Zend_View_Helper_Abstract.php */
0027 // require_once 'Zend/View/Helper/Abstract.php';
0028 
0029 /**
0030  * Helper for setting and retrieving the doctype
0031  *
0032  * @package    Zend_View
0033  * @subpackage Helper
0034  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0035  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0036  */
0037 class Zend_View_Helper_Doctype extends Zend_View_Helper_Abstract
0038 {
0039     /**#@+
0040      * DocType constants
0041      */
0042     const XHTML11             = 'XHTML11';
0043     const XHTML1_STRICT       = 'XHTML1_STRICT';
0044     const XHTML1_TRANSITIONAL = 'XHTML1_TRANSITIONAL';
0045     const XHTML1_FRAMESET     = 'XHTML1_FRAMESET';
0046     const XHTML1_RDFA         = 'XHTML1_RDFA';
0047     const XHTML1_RDFA11       = 'XHTML1_RDFA11';
0048     const XHTML_BASIC1        = 'XHTML_BASIC1';
0049     const XHTML5              = 'XHTML5';
0050     const HTML4_STRICT        = 'HTML4_STRICT';
0051     const HTML4_LOOSE         = 'HTML4_LOOSE';
0052     const HTML4_FRAMESET      = 'HTML4_FRAMESET';
0053     const HTML5               = 'HTML5';
0054     const CUSTOM_XHTML        = 'CUSTOM_XHTML';
0055     const CUSTOM              = 'CUSTOM';
0056     /**#@-*/
0057 
0058     /**
0059      * Default DocType
0060      * @var string
0061      */
0062     protected $_defaultDoctype = self::HTML4_LOOSE;
0063 
0064     /**
0065      * Registry containing current doctype and mappings
0066      * @var ArrayObject
0067      */
0068     protected $_registry;
0069 
0070     /**
0071      * Registry key in which helper is stored
0072      * @var string
0073      */
0074     protected $_regKey = 'Zend_View_Helper_Doctype';
0075 
0076     /**
0077      * Constructor
0078      *
0079      * Map constants to doctype strings, and set default doctype
0080      *
0081      * @return void
0082      */
0083     public function __construct()
0084     {
0085         if (!Zend_Registry::isRegistered($this->_regKey)) {
0086             $this->_registry = new ArrayObject(array(
0087                 'doctypes' => array(
0088                     self::XHTML11             => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">',
0089                     self::XHTML1_STRICT       => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
0090                     self::XHTML1_TRANSITIONAL => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
0091                     self::XHTML1_FRAMESET     => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">',
0092                     self::XHTML1_RDFA         => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">',
0093                     self::XHTML1_RDFA11       => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">',
0094                     self::XHTML_BASIC1        => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd">',
0095                     self::XHTML5              => '<!DOCTYPE html>',
0096                     self::HTML4_STRICT        => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">',
0097                     self::HTML4_LOOSE         => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">',
0098                     self::HTML4_FRAMESET      => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">',
0099                     self::HTML5               => '<!DOCTYPE html>',
0100                 )
0101             ));
0102             Zend_Registry::set($this->_regKey, $this->_registry);
0103             $this->setDoctype($this->_defaultDoctype);
0104         } else {
0105             $this->_registry = Zend_Registry::get($this->_regKey);
0106         }
0107     }
0108 
0109     /**
0110      * Set or retrieve doctype
0111      *
0112      * @param  string $doctype
0113      * @return Zend_View_Helper_Doctype
0114      */
0115     public function doctype($doctype = null)
0116     {
0117         if (null !== $doctype) {
0118             switch ($doctype) {
0119                 case self::XHTML11:
0120                 case self::XHTML1_STRICT:
0121                 case self::XHTML1_TRANSITIONAL:
0122                 case self::XHTML1_FRAMESET:
0123                 case self::XHTML_BASIC1:
0124                 case self::XHTML1_RDFA:
0125                 case self::XHTML1_RDFA11:
0126                 case self::XHTML5:
0127                 case self::HTML4_STRICT:
0128                 case self::HTML4_LOOSE:
0129                 case self::HTML4_FRAMESET:
0130                 case self::HTML5:
0131                     $this->setDoctype($doctype);
0132                     break;
0133                 default:
0134                     if (substr($doctype, 0, 9) != '<!DOCTYPE') {
0135                         // require_once 'Zend/View/Exception.php';
0136                         $e = new Zend_View_Exception('The specified doctype is malformed');
0137                         $e->setView($this->view);
0138                         throw $e;
0139                     }
0140                     if (stristr($doctype, 'xhtml')) {
0141                         $type = self::CUSTOM_XHTML;
0142                     } else {
0143                         $type = self::CUSTOM;
0144                     }
0145                     $this->setDoctype($type);
0146                     $this->_registry['doctypes'][$type] = $doctype;
0147                     break;
0148             }
0149         }
0150 
0151         return $this;
0152     }
0153 
0154     /**
0155      * Set doctype
0156      *
0157      * @param  string $doctype
0158      * @return Zend_View_Helper_Doctype
0159      */
0160     public function setDoctype($doctype)
0161     {
0162         $this->_registry['doctype'] = $doctype;
0163         return $this;
0164     }
0165 
0166     /**
0167      * Retrieve doctype
0168      *
0169      * @return string
0170      */
0171     public function getDoctype()
0172     {
0173         return $this->_registry['doctype'];
0174     }
0175 
0176     /**
0177      * Get doctype => string mappings
0178      *
0179      * @return array
0180      */
0181     public function getDoctypes()
0182     {
0183         return $this->_registry['doctypes'];
0184     }
0185 
0186     /**
0187      * Is doctype XHTML?
0188      *
0189      * @return boolean
0190      */
0191     public function isXhtml()
0192     {
0193         return (stristr($this->getDoctype(), 'xhtml') ? true : false);
0194     }
0195 
0196     /**
0197      * Is doctype strict?
0198      *
0199      * @return boolean
0200      */
0201     public function isStrict()
0202     {
0203         switch ( $this->getDoctype() )
0204         {
0205             case self::XHTML1_STRICT:
0206             case self::XHTML11:
0207             case self::HTML4_STRICT:
0208                 return true;
0209             default: 
0210                 return false;
0211         }
0212     }
0213     
0214     /**
0215      * Is doctype HTML5? (HeadMeta uses this for validation)
0216      *
0217      * @return booleean
0218      */
0219     public function isHtml5() {
0220         return (stristr($this->doctype(), '<!DOCTYPE html>') ? true : false);
0221     }
0222     
0223     /**
0224      * Is doctype RDFa?
0225      *
0226      * @return booleean
0227      */
0228     public function isRdfa() {
0229         return (stristr($this->getDoctype(), 'rdfa') ? true : false);
0230     }
0231 
0232     /**
0233      * String representation of doctype
0234      *
0235      * @return string
0236      */
0237     public function __toString()
0238     {
0239         $doctypes = $this->getDoctypes();
0240         return $doctypes[$this->getDoctype()];
0241     }
0242 }