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: HeadMeta.php 20096 2010-01-06 02:05:09Z bkarwin $ |
19 * @version $Id: HeadMeta.php 24776 2012-05-08 18:36:40Z 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'; |
28 * |
28 * |
29 * @see http://www.w3.org/TR/xhtml1/dtds.html |
29 * @see http://www.w3.org/TR/xhtml1/dtds.html |
30 * @uses Zend_View_Helper_Placeholder_Container_Standalone |
30 * @uses Zend_View_Helper_Placeholder_Container_Standalone |
31 * @package Zend_View |
31 * @package Zend_View |
32 * @subpackage Helper |
32 * @subpackage Helper |
33 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
33 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
34 * @license http://framework.zend.com/license/new-bsd New BSD License |
34 * @license http://framework.zend.com/license/new-bsd New BSD License |
35 */ |
35 */ |
36 class Zend_View_Helper_HeadMeta extends Zend_View_Helper_Placeholder_Container_Standalone |
36 class Zend_View_Helper_HeadMeta extends Zend_View_Helper_Placeholder_Container_Standalone |
37 { |
37 { |
38 /** |
38 /** |
39 * Types of attributes |
39 * Types of attributes |
40 * @var array |
40 * @var array |
41 */ |
41 */ |
42 protected $_typeKeys = array('name', 'http-equiv', 'charset'); |
42 protected $_typeKeys = array('name', 'http-equiv', 'charset', 'property'); |
43 protected $_requiredKeys = array('content'); |
43 protected $_requiredKeys = array('content'); |
44 protected $_modifierKeys = array('lang', 'scheme'); |
44 protected $_modifierKeys = array('lang', 'scheme'); |
45 |
45 |
46 /** |
46 /** |
47 * @var string registry key |
47 * @var string registry key |
116 * - setName($keyValue, $content, $modifiers = array()) |
118 * - setName($keyValue, $content, $modifiers = array()) |
117 * - appendHttpEquiv($keyValue, $content, $modifiers = array()) |
119 * - appendHttpEquiv($keyValue, $content, $modifiers = array()) |
118 * - offsetGetHttpEquiv($index, $keyValue, $content, $modifers = array()) |
120 * - offsetGetHttpEquiv($index, $keyValue, $content, $modifers = array()) |
119 * - prependHttpEquiv($keyValue, $content, $modifiers = array()) |
121 * - prependHttpEquiv($keyValue, $content, $modifiers = array()) |
120 * - setHttpEquiv($keyValue, $content, $modifiers = array()) |
122 * - setHttpEquiv($keyValue, $content, $modifiers = array()) |
|
123 * - appendProperty($keyValue, $content, $modifiers = array()) |
|
124 * - offsetGetProperty($index, $keyValue, $content, $modifiers = array()) |
|
125 * - prependProperty($keyValue, $content, $modifiers = array()) |
|
126 * - setProperty($keyValue, $content, $modifiers = array()) |
121 * |
127 * |
122 * @param string $method |
128 * @param string $method |
123 * @param array $args |
129 * @param array $args |
124 * @return Zend_View_Helper_HeadMeta |
130 * @return Zend_View_Helper_HeadMeta |
125 */ |
131 */ |
126 public function __call($method, $args) |
132 public function __call($method, $args) |
127 { |
133 { |
128 if (preg_match('/^(?P<action>set|(pre|ap)pend|offsetSet)(?P<type>Name|HttpEquiv)$/', $method, $matches)) { |
134 if (preg_match('/^(?P<action>set|(pre|ap)pend|offsetSet)(?P<type>Name|HttpEquiv|Property)$/', $method, $matches)) { |
129 $action = $matches['action']; |
135 $action = $matches['action']; |
130 $type = $this->_normalizeType($matches['type']); |
136 $type = $this->_normalizeType($matches['type']); |
131 $argc = count($args); |
137 $argc = count($args); |
132 $index = null; |
138 $index = null; |
133 |
139 |
160 } |
166 } |
161 |
167 |
162 return parent::__call($method, $args); |
168 return parent::__call($method, $args); |
163 } |
169 } |
164 |
170 |
165 /** |
171 /** |
166 * Create an HTML5-style meta charset tag. Something like <meta charset="utf-8"> |
172 * Create an HTML5-style meta charset tag. Something like <meta charset="utf-8"> |
167 * |
173 * |
168 * Not valid in a non-HTML5 doctype |
174 * Not valid in a non-HTML5 doctype |
169 * |
175 * |
170 * @param string $charset |
176 * @param string $charset |
171 * @return Zend_View_Helper_HeadMeta Provides a fluent interface |
177 * @return Zend_View_Helper_HeadMeta Provides a fluent interface |
172 */ |
178 */ |
173 public function setCharset($charset) |
179 public function setCharset($charset) |
174 { |
180 { |
175 $item = new stdClass; |
181 $item = new stdClass; |
176 $item->type = 'charset'; |
182 $item->type = 'charset'; |
177 $item->charset = $charset; |
183 $item->charset = $charset; |
194 || !isset($item->modifiers)) |
200 || !isset($item->modifiers)) |
195 { |
201 { |
196 return false; |
202 return false; |
197 } |
203 } |
198 |
204 |
|
205 $isHtml5 = is_null($this->view) ? false : $this->view->doctype()->isHtml5(); |
|
206 |
199 if (!isset($item->content) |
207 if (!isset($item->content) |
200 && (! $this->view->doctype()->isHtml5() |
208 && (! $isHtml5 || (! $isHtml5 && $item->type !== 'charset'))) { |
201 || (! $this->view->doctype()->isHtml5() && $item->type !== 'charset'))) { |
209 return false; |
|
210 } |
|
211 |
|
212 // <meta property= ... /> is only supported with doctype RDFa |
|
213 if ( !is_null($this->view) && !$this->view->doctype()->isRdfa() |
|
214 && $item->type === 'property') { |
202 return false; |
215 return false; |
203 } |
216 } |
204 |
217 |
205 return true; |
218 return true; |
206 } |
219 } |
327 } |
340 } |
328 $type = $item->type; |
341 $type = $item->type; |
329 |
342 |
330 $modifiersString = ''; |
343 $modifiersString = ''; |
331 foreach ($item->modifiers as $key => $value) { |
344 foreach ($item->modifiers as $key => $value) { |
332 if ($this->view->doctype()->isHtml5() |
345 if (!is_null($this->view) && $this->view->doctype()->isHtml5() |
333 && $key == 'scheme') { |
346 && $key == 'scheme') { |
334 require_once 'Zend/View/Exception.php'; |
347 require_once 'Zend/View/Exception.php'; |
335 throw new Zend_View_Exception('Invalid modifier ' |
348 throw new Zend_View_Exception('Invalid modifier ' |
336 . '"scheme" provided; not supported by HTML5'); |
349 . '"scheme" provided; not supported by HTML5'); |
337 } |
350 } |
342 } |
355 } |
343 |
356 |
344 if ($this->view instanceof Zend_View_Abstract) { |
357 if ($this->view instanceof Zend_View_Abstract) { |
345 if ($this->view->doctype()->isHtml5() |
358 if ($this->view->doctype()->isHtml5() |
346 && $type == 'charset') { |
359 && $type == 'charset') { |
347 $tpl = ($this->view->doctype()->isXhtml()) |
360 $tpl = ($this->view->doctype()->isXhtml()) |
348 ? '<meta %s="%s"/>' |
361 ? '<meta %s="%s"/>' |
349 : '<meta %s="%s">'; |
362 : '<meta %s="%s">'; |
350 } elseif ($this->view->doctype()->isXhtml()) { |
363 } elseif ($this->view->doctype()->isXhtml()) { |
351 $tpl = '<meta %s="%s" content="%s" %s/>'; |
364 $tpl = '<meta %s="%s" content="%s" %s/>'; |
352 } else { |
365 } else { |
353 $tpl = '<meta %s="%s" content="%s" %s>'; |
366 $tpl = '<meta %s="%s" content="%s" %s>'; |
354 } |
367 } |
361 $type, |
374 $type, |
362 $this->_escape($item->$type), |
375 $this->_escape($item->$type), |
363 $this->_escape($item->content), |
376 $this->_escape($item->content), |
364 $modifiersString |
377 $modifiersString |
365 ); |
378 ); |
|
379 |
|
380 if (isset($item->modifiers['conditional']) |
|
381 && !empty($item->modifiers['conditional']) |
|
382 && is_string($item->modifiers['conditional'])) |
|
383 { |
|
384 $meta = '<!--[if ' . $this->_escape($item->modifiers['conditional']) . ']>' . $meta . '<![endif]-->'; |
|
385 } |
|
386 |
366 return $meta; |
387 return $meta; |
367 } |
388 } |
368 |
389 |
369 /** |
390 /** |
370 * Render placeholder as string |
391 * Render placeholder as string |