web/lib/Zend/View/Helper/HeadScript.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  * @version    $Id: HeadScript.php 20363 2010-01-17 22:55:25Z mabe $
    19  * @version    $Id: HeadScript.php 24960 2012-06-15 14:09:34Z adamlundrigan $
    20  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    20  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    21  */
    21  */
    22 
    22 
    23 /** Zend_View_Helper_Placeholder_Container_Standalone */
    23 /** Zend_View_Helper_Placeholder_Container_Standalone */
    24 require_once 'Zend/View/Helper/Placeholder/Container/Standalone.php';
    24 require_once 'Zend/View/Helper/Placeholder/Container/Standalone.php';
    27  * Helper for setting and retrieving script elements for HTML head section
    27  * Helper for setting and retrieving script elements for HTML head section
    28  *
    28  *
    29  * @uses       Zend_View_Helper_Placeholder_Container_Standalone
    29  * @uses       Zend_View_Helper_Placeholder_Container_Standalone
    30  * @package    Zend_View
    30  * @package    Zend_View
    31  * @subpackage Helper
    31  * @subpackage Helper
    32  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    32  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    33  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    33  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    34  */
    34  */
    35 class Zend_View_Helper_HeadScript extends Zend_View_Helper_Placeholder_Container_Standalone
    35 class Zend_View_Helper_HeadScript extends Zend_View_Helper_Placeholder_Container_Standalone
    36 {
    36 {
    37     /**#@+
    37     /**#@+
   243                         $this->$action($item);
   243                         $this->$action($item);
   244                     }
   244                     }
   245                     break;
   245                     break;
   246                 case 'file':
   246                 case 'file':
   247                 default:
   247                 default:
   248                     if (!$this->_isDuplicate($content)) {
   248                     if (!$this->_isDuplicate($content) || $action=='set') {
   249                         $attrs['src'] = $content;
   249                         $attrs['src'] = $content;
   250                         $item = $this->createData($type, $attrs);
   250                         $item = $this->createData($type, $attrs);
   251                         if ('offsetSet' == $action) {
   251                         if ('offsetSet' == $action) {
   252                             $this->offsetSet($index, $item);
   252                             $this->offsetSet($index, $item);
   253                         } else {
   253                         } else {
   369             $e = new Zend_View_Exception('Invalid argument passed to offsetSet(); please use one of the helper methods, offsetSetScript() or offsetSetFile()');
   369             $e = new Zend_View_Exception('Invalid argument passed to offsetSet(); please use one of the helper methods, offsetSetScript() or offsetSetFile()');
   370             $e->setView($this->view);
   370             $e->setView($this->view);
   371             throw $e;
   371             throw $e;
   372         }
   372         }
   373 
   373 
   374         $this->_isValid($value);
       
   375         return $this->getContainer()->offsetSet($index, $value);
   374         return $this->getContainer()->offsetSet($index, $value);
   376     }
   375     }
   377 
   376 
   378     /**
   377     /**
   379      * Set flag indicating if arbitrary attributes are allowed
   378      * Set flag indicating if arbitrary attributes are allowed
   409     public function itemToString($item, $indent, $escapeStart, $escapeEnd)
   408     public function itemToString($item, $indent, $escapeStart, $escapeEnd)
   410     {
   409     {
   411         $attrString = '';
   410         $attrString = '';
   412         if (!empty($item->attributes)) {
   411         if (!empty($item->attributes)) {
   413             foreach ($item->attributes as $key => $value) {
   412             foreach ($item->attributes as $key => $value) {
   414                 if (!$this->arbitraryAttributesAllowed()
   413                 if ((!$this->arbitraryAttributesAllowed() && !in_array($key, $this->_optionalAttributes))
   415                     && !in_array($key, $this->_optionalAttributes))
   414                     || in_array($key, array('conditional', 'noescape')))
   416                 {
   415                 {
   417                     continue;
   416                     continue;
   418                 }
   417                 }
   419                 if ('defer' == $key) {
   418                 if ('defer' == $key) {
   420                     $value = 'defer';
   419                     $value = 'defer';
   421                 }
   420                 }
   422                 $attrString .= sprintf(' %s="%s"', $key, ($this->_autoEscape) ? $this->_escape($value) : $value);
   421                 $attrString .= sprintf(' %s="%s"', $key, ($this->_autoEscape) ? $this->_escape($value) : $value);
   423             }
   422             }
   424         }
   423         }
   425 
   424 
       
   425         $addScriptEscape = !(isset($item->attributes['noescape']) && filter_var($item->attributes['noescape'], FILTER_VALIDATE_BOOLEAN));
       
   426 
   426         $type = ($this->_autoEscape) ? $this->_escape($item->type) : $item->type;
   427         $type = ($this->_autoEscape) ? $this->_escape($item->type) : $item->type;
   427         $html  = '<script type="' . $type . '"' . $attrString . '>';
   428         $html  = '<script type="' . $type . '"' . $attrString . '>';
   428         if (!empty($item->source)) {
   429         if (!empty($item->source)) {
   429               $html .= PHP_EOL . $indent . '    ' . $escapeStart . PHP_EOL . $item->source . $indent . '    ' . $escapeEnd . PHP_EOL . $indent;
   430             $html .= PHP_EOL ;
       
   431 
       
   432             if ($addScriptEscape) {
       
   433                 $html .= $indent . '    ' . $escapeStart . PHP_EOL;
       
   434             }
       
   435 
       
   436             $html .= $indent . '    ' . $item->source;
       
   437 
       
   438             if ($addScriptEscape) {
       
   439                 $html .= $indent . '    ' . $escapeEnd . PHP_EOL;
       
   440             }
       
   441 
       
   442             $html .= $indent;
   430         }
   443         }
   431         $html .= '</script>';
   444         $html .= '</script>';
   432 
   445 
   433         if (isset($item->attributes['conditional'])
   446         if (isset($item->attributes['conditional'])
   434             && !empty($item->attributes['conditional'])
   447             && !empty($item->attributes['conditional'])