web/lib/Zend/View/Helper/Navigation/Sitemap.php
changeset 807 877f952ae2bd
parent 207 621fa6caec0c
child 1230 68c69c656a2c
equal deleted inserted replaced
805:5e7a0fedabdf 807:877f952ae2bd
    13  * to license@zend.com so we can send you a copy immediately.
    13  * to license@zend.com so we can send you a copy immediately.
    14  *
    14  *
    15  * @category   Zend
    15  * @category   Zend
    16  * @package    Zend_View
    16  * @package    Zend_View
    17  * @subpackage Helper
    17  * @subpackage Helper
    18  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    18  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    20  * @version    $Id: Sitemap.php 20104 2010-01-06 21:26:01Z matthew $
    20  * @version    $Id: Sitemap.php 25239 2013-01-22 09:45:01Z frosch $
    21  */
    21  */
    22 
    22 
    23 /**
    23 /**
    24  * @see Zend_View_Helper_Navigation_HelperAbstract
    24  * @see Zend_View_Helper_Navigation_HelperAbstract
    25  */
    25  */
    31  * @link http://www.sitemaps.org/protocol.php
    31  * @link http://www.sitemaps.org/protocol.php
    32  *
    32  *
    33  * @category   Zend
    33  * @category   Zend
    34  * @package    Zend_View
    34  * @package    Zend_View
    35  * @subpackage Helper
    35  * @subpackage Helper
    36  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    36  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    37  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    37  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    38  */
    38  */
    39 class Zend_View_Helper_Navigation_Sitemap
    39 class Zend_View_Helper_Navigation_Sitemap
    40     extends Zend_View_Helper_Navigation_HelperAbstract
    40     extends Zend_View_Helper_Navigation_HelperAbstract
    41 {
    41 {
    52      * @var string
    52      * @var string
    53      */
    53      */
    54     const SITEMAP_XSD = 'http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd';
    54     const SITEMAP_XSD = 'http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd';
    55 
    55 
    56     /**
    56     /**
    57      * Whether XML output should be formatted
       
    58      *
       
    59      * @var bool
       
    60      */
       
    61     protected $_formatOutput = false;
       
    62 
       
    63     /**
       
    64      * Whether the XML declaration should be included in XML output
    57      * Whether the XML declaration should be included in XML output
    65      *
    58      *
    66      * @var bool
    59      * @var bool
    67      */
    60      */
    68     protected $_useXmlDeclaration = true;
    61     protected $_useXmlDeclaration = true;
   105 
    98 
   106         return $this;
    99         return $this;
   107     }
   100     }
   108 
   101 
   109     // Accessors:
   102     // Accessors:
   110 
       
   111     /**
       
   112      * Sets whether XML output should be formatted
       
   113      *
       
   114      * @param  bool $formatOutput                   [optional] whether output
       
   115      *                                              should be formatted. Default
       
   116      *                                              is true.
       
   117      * @return Zend_View_Helper_Navigation_Sitemap  fluent interface, returns
       
   118      *                                              self
       
   119      */
       
   120     public function setFormatOutput($formatOutput = true)
       
   121     {
       
   122         $this->_formatOutput = (bool) $formatOutput;
       
   123         return $this;
       
   124     }
       
   125 
       
   126     /**
       
   127      * Returns whether XML output should be formatted
       
   128      *
       
   129      * @return bool  whether XML output should be formatted
       
   130      */
       
   131     public function getFormatOutput()
       
   132     {
       
   133         return $this->_formatOutput;
       
   134     }
       
   135 
   103 
   136     /**
   104     /**
   137      * Sets whether the XML declaration should be used in output
   105      * Sets whether the XML declaration should be used in output
   138      *
   106      *
   139      * @param  bool $useXmlDecl                     whether XML delcaration
   107      * @param  bool $useXmlDecl                     whether XML delcaration
   267             && method_exists($this->view, 'getEncoding')
   235             && method_exists($this->view, 'getEncoding')
   268         ) {
   236         ) {
   269             $enc = $this->view->getEncoding();
   237             $enc = $this->view->getEncoding();
   270         }
   238         }
   271 
   239 
   272         // TODO: remove check when minimum PHP version is >= 5.2.3
   240         // do not encode existing HTML entities
   273         if (version_compare(PHP_VERSION, '5.2.3', '>=')) {
   241         return htmlspecialchars($string, ENT_QUOTES, $enc, false);
   274             // do not encode existing HTML entities
       
   275             return htmlspecialchars($string, ENT_QUOTES, $enc, false);
       
   276         } else {
       
   277             $string = preg_replace('/&(?!(?:#\d++|[a-z]++);)/ui', '&', $string);
       
   278             $string = str_replace(array('<', '>', '\'', '"'), array('&lt;', '&gt;', '&#39;', '&quot;'), $string);
       
   279             return $string;
       
   280         }
       
   281     }
   242     }
   282 
   243 
   283     // Public methods:
   244     // Public methods:
   284 
   245 
   285     /**
   246     /**
   476 
   437 
   477         $xml = $this->getUseXmlDeclaration() ?
   438         $xml = $this->getUseXmlDeclaration() ?
   478                $dom->saveXML() :
   439                $dom->saveXML() :
   479                $dom->saveXML($dom->documentElement);
   440                $dom->saveXML($dom->documentElement);
   480 
   441 
   481         return rtrim($xml, PHP_EOL);
   442         return rtrim($xml, self::EOL);
   482     }
   443     }
   483 }
   444 }