*prechod na novsiu verziu ZF
[sport-group.git] / library / Zend / View / Helper / HeadTitle.php
blob5099e6f3158bf12f240923704cf649557a6a21d1
1 <?php
2 /**
3 * Zend Framework
5 * LICENSE
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.
15 * @category Zend
16 * @package Zend_View
17 * @subpackage Helper
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';
26 /**
27 * Helper for setting and retrieving title element for HTML head
29 * @uses Zend_View_Helper_Placeholder_Container_Standalone
30 * @package Zend_View
31 * @subpackage Helper
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
37 /**
38 * Registry key for placeholder
39 * @var string
41 protected $_regKey = 'Zend_View_Helper_HeadTitle';
43 /**
44 * Whether or not auto-translation is enabled
45 * @var boolean
47 protected $_translate = false;
49 /**
50 * Translation object
52 * @var Zend_Translate_Adapter
54 protected $_translator;
56 /**
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)
66 if ($title) {
67 if ($setType == Zend_View_Helper_Placeholder_Container_Abstract::SET) {
68 $this->set($title);
69 } elseif ($setType == Zend_View_Helper_Placeholder_Container_Abstract::PREPEND) {
70 $this->prepend($title);
71 } else {
72 $this->append($title);
76 return $this;
79 /**
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();
91 } else {
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");
95 return $this;
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;
125 return $this;
129 * Disables translation
131 * @return Zend_View_Helper_HeadTitle
133 public function disableTranslation()
135 $this->_translate = false;
136 return $this;
140 * Turn helper into string
142 * @param string|null $indent
143 * @param string|null $locale
144 * @return string
146 public function toString($indent = null, $locale = null)
148 $indent = (null !== $indent)
149 ? $this->getWhitespace($indent)
150 : $this->getIndent();
152 $items = array();
154 if($this->_translate && $translator = $this->getTranslator()) {
155 foreach ($this as $item) {
156 $items[] = $translator->translate($item, $locale);
158 } else {
159 foreach ($this as $item) {
160 $items[] = $item;
164 $separator = $this->getSeparator();
165 $output = '';
166 if(($prefix = $this->getPrefix())) {
167 $output .= $prefix;
169 $output .= implode($separator, $items);
170 if(($postfix = $this->getPostfix())) {
171 $output .= $postfix;
174 $output = ($this->_autoEscape) ? $this->_escape($output) : $output;
176 return $indent . '<title>' . $output . '</title>';