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.
18 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
19 * @version $Id: HeadTitle.php 16971 2009-07-22 18:05:45Z mikaelkael $
20 * @license http://framework.zend.com/license/new-bsd New BSD License
23 /** Zend_View_Helper_Placeholder_Container_Standalone */
24 require_once 'Zend/View/Helper/Placeholder/Container/Standalone.php';
27 * Helper for setting and retrieving title element for HTML head
29 * @uses Zend_View_Helper_Placeholder_Container_Standalone
32 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
33 * @license http://framework.zend.com/license/new-bsd New BSD License
35 class Zend_View_Helper_HeadTitle
extends Zend_View_Helper_Placeholder_Container_Standalone
38 * Registry key for placeholder
41 protected $_regKey = 'Zend_View_Helper_HeadTitle';
44 * Whether or not auto-translation is enabled
47 protected $_translate = false;
52 * @var Zend_Translate_Adapter
54 protected $_translator;
57 * Retrieve placeholder for title element and optionally set state
59 * @param string $title
60 * @param string $setType
61 * @param string $separator
62 * @return Zend_View_Helper_HeadTitle
64 public function headTitle($title = null, $setType = Zend_View_Helper_Placeholder_Container_Abstract
::APPEND
)
67 if ($setType == Zend_View_Helper_Placeholder_Container_Abstract
::SET
) {
69 } elseif ($setType == Zend_View_Helper_Placeholder_Container_Abstract
::PREPEND
) {
70 $this->prepend($title);
72 $this->append($title);
80 * Sets a translation Adapter for translation
82 * @param Zend_Translate|Zend_Translate_Adapter $translate
83 * @return Zend_View_Helper_HeadTitle
85 public function setTranslator($translate)
87 if ($translate instanceof Zend_Translate_Adapter
) {
88 $this->_translator
= $translate;
89 } elseif ($translate instanceof Zend_Translate
) {
90 $this->_translator
= $translate->getAdapter();
92 require_once 'Zend/View/Exception.php';
93 throw new Zend_View_Exception("You must set an instance of Zend_Translate or Zend_Translate_Adapter");
99 * Retrieve translation object
101 * If none is currently registered, attempts to pull it from the registry
102 * using the key 'Zend_Translate'.
104 * @return Zend_Translate_Adapter|null
106 public function getTranslator()
108 if (null === $this->_translator
) {
109 require_once 'Zend/Registry.php';
110 if (Zend_Registry
::isRegistered('Zend_Translate')) {
111 $this->setTranslator(Zend_Registry
::get('Zend_Translate'));
114 return $this->_translator
;
118 * Enables translation
120 * @return Zend_View_Helper_HeadTitle
122 public function enableTranslation()
124 $this->_translate
= true;
129 * Disables translation
131 * @return Zend_View_Helper_HeadTitle
133 public function disableTranslation()
135 $this->_translate
= false;
140 * Turn helper into string
142 * @param string|null $indent
143 * @param string|null $locale
146 public function toString($indent = null, $locale = null)
148 $indent = (null !== $indent)
149 ?
$this->getWhitespace($indent)
150 : $this->getIndent();
154 if($this->_translate
&& $translator = $this->getTranslator()) {
155 foreach ($this as $item) {
156 $items[] = $translator->translate($item, $locale);
159 foreach ($this as $item) {
164 $separator = $this->getSeparator();
166 if(($prefix = $this->getPrefix())) {
169 $output .= implode($separator, $items);
170 if(($postfix = $this->getPostfix())) {
174 $output = ($this->_autoEscape
) ?
$this->_escape($output) : $output;
176 return $indent . '<title>' . $output . '</title>';