adding zend project folders into old campcaster.
This commit is contained in:
parent
56abfaf28e
commit
7ef0c18b26
4045 changed files with 1054952 additions and 0 deletions
64
library/Zend/View/Helper/Abstract.php
Normal file
64
library/Zend/View/Helper/Abstract.php
Normal file
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Abstract.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_View_Helper_Interface
|
||||
*/
|
||||
require_once 'Zend/View/Helper/Interface.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_View_Helper_Abstract implements Zend_View_Helper_Interface
|
||||
{
|
||||
/**
|
||||
* View object
|
||||
*
|
||||
* @var Zend_View_Interface
|
||||
*/
|
||||
public $view = null;
|
||||
|
||||
/**
|
||||
* Set the View object
|
||||
*
|
||||
* @param Zend_View_Interface $view
|
||||
* @return Zend_View_Helper_Abstract
|
||||
*/
|
||||
public function setView(Zend_View_Interface $view)
|
||||
{
|
||||
$this->view = $view;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Strategy pattern: currently unutilized
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function direct()
|
||||
{
|
||||
}
|
||||
}
|
164
library/Zend/View/Helper/Action.php
Normal file
164
library/Zend/View/Helper/Action.php
Normal file
|
@ -0,0 +1,164 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: Action.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/** Zend_View_Helper_Abstract.php */
|
||||
require_once 'Zend/View/Helper/Abstract.php';
|
||||
|
||||
/**
|
||||
* Helper for rendering output of a controller action
|
||||
*
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_Action extends Zend_View_Helper_Abstract
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $defaultModule;
|
||||
|
||||
/**
|
||||
* @var Zend_Controller_Dispatcher_Interface
|
||||
*/
|
||||
public $dispatcher;
|
||||
|
||||
/**
|
||||
* @var Zend_Controller_Request_Abstract
|
||||
*/
|
||||
public $request;
|
||||
|
||||
/**
|
||||
* @var Zend_Controller_Response_Abstract
|
||||
*/
|
||||
public $response;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Grab local copies of various MVC objects
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$front = Zend_Controller_Front::getInstance();
|
||||
$modules = $front->getControllerDirectory();
|
||||
if (empty($modules)) {
|
||||
require_once 'Zend/View/Exception.php';
|
||||
$e = new Zend_View_Exception('Action helper depends on valid front controller instance');
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$request = $front->getRequest();
|
||||
$response = $front->getResponse();
|
||||
|
||||
if (empty($request) || empty($response)) {
|
||||
require_once 'Zend/View/Exception.php';
|
||||
$e = new Zend_View_Exception('Action view helper requires both a registered request and response object in the front controller instance');
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$this->request = clone $request;
|
||||
$this->response = clone $response;
|
||||
$this->dispatcher = clone $front->getDispatcher();
|
||||
$this->defaultModule = $front->getDefaultModule();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset object states
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function resetObjects()
|
||||
{
|
||||
$params = $this->request->getUserParams();
|
||||
foreach (array_keys($params) as $key) {
|
||||
$this->request->setParam($key, null);
|
||||
}
|
||||
|
||||
$this->response->clearBody();
|
||||
$this->response->clearHeaders()
|
||||
->clearRawHeaders();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve rendered contents of a controller action
|
||||
*
|
||||
* If the action results in a forward or redirect, returns empty string.
|
||||
*
|
||||
* @param string $action
|
||||
* @param string $controller
|
||||
* @param string $module Defaults to default module
|
||||
* @param array $params
|
||||
* @return string
|
||||
*/
|
||||
public function action($action, $controller, $module = null, array $params = array())
|
||||
{
|
||||
$this->resetObjects();
|
||||
if (null === $module) {
|
||||
$module = $this->defaultModule;
|
||||
}
|
||||
|
||||
// clone the view object to prevent over-writing of view variables
|
||||
$viewRendererObj = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
|
||||
Zend_Controller_Action_HelperBroker::addHelper(clone $viewRendererObj);
|
||||
|
||||
$this->request->setParams($params)
|
||||
->setModuleName($module)
|
||||
->setControllerName($controller)
|
||||
->setActionName($action)
|
||||
->setDispatched(true);
|
||||
|
||||
$this->dispatcher->dispatch($this->request, $this->response);
|
||||
|
||||
// reset the viewRenderer object to it's original state
|
||||
Zend_Controller_Action_HelperBroker::addHelper($viewRendererObj);
|
||||
|
||||
|
||||
if (!$this->request->isDispatched()
|
||||
|| $this->response->isRedirect())
|
||||
{
|
||||
// forwards and redirects render nothing
|
||||
return '';
|
||||
}
|
||||
|
||||
$return = $this->response->getBody();
|
||||
$this->resetObjects();
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone the current View
|
||||
*
|
||||
* @return Zend_View_Interface
|
||||
*/
|
||||
public function cloneView()
|
||||
{
|
||||
$view = clone $this->view;
|
||||
$view->clearVars();
|
||||
return $view;
|
||||
}
|
||||
}
|
116
library/Zend/View/Helper/BaseUrl.php
Normal file
116
library/Zend/View/Helper/BaseUrl.php
Normal file
|
@ -0,0 +1,116 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: BaseUrl.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/** @see Zend_View_Helper_Abstract */
|
||||
require_once 'Zend/View/Helper/Abstract.php';
|
||||
|
||||
/**
|
||||
* Helper for retrieving the BaseUrl
|
||||
*
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_BaseUrl extends Zend_View_Helper_Abstract
|
||||
{
|
||||
/**
|
||||
* BaseUrl
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_baseUrl;
|
||||
|
||||
/**
|
||||
* Returns site's base url, or file with base url prepended
|
||||
*
|
||||
* $file is appended to the base url for simplicity
|
||||
*
|
||||
* @param string|null $file
|
||||
* @return string
|
||||
*/
|
||||
public function baseUrl($file = null)
|
||||
{
|
||||
// Get baseUrl
|
||||
$baseUrl = $this->getBaseUrl();
|
||||
|
||||
// Remove trailing slashes
|
||||
if (null !== $file) {
|
||||
$file = '/' . ltrim($file, '/\\');
|
||||
}
|
||||
|
||||
return $baseUrl . $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set BaseUrl
|
||||
*
|
||||
* @param string $base
|
||||
* @return Zend_View_Helper_BaseUrl
|
||||
*/
|
||||
public function setBaseUrl($base)
|
||||
{
|
||||
$this->_baseUrl = rtrim($base, '/\\');
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get BaseUrl
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getBaseUrl()
|
||||
{
|
||||
if ($this->_baseUrl === null) {
|
||||
/** @see Zend_Controller_Front */
|
||||
require_once 'Zend/Controller/Front.php';
|
||||
$baseUrl = Zend_Controller_Front::getInstance()->getBaseUrl();
|
||||
|
||||
// Remove scriptname, eg. index.php from baseUrl
|
||||
$baseUrl = $this->_removeScriptName($baseUrl);
|
||||
|
||||
$this->setBaseUrl($baseUrl);
|
||||
}
|
||||
|
||||
return $this->_baseUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove Script filename from baseurl
|
||||
*
|
||||
* @param string $url
|
||||
* @return string
|
||||
*/
|
||||
protected function _removeScriptName($url)
|
||||
{
|
||||
if (!isset($_SERVER['SCRIPT_NAME'])) {
|
||||
// We can't do much now can we? (Well, we could parse out by ".")
|
||||
return $url;
|
||||
}
|
||||
|
||||
if (($pos = strripos($url, basename($_SERVER['SCRIPT_NAME']))) !== false) {
|
||||
$url = substr($url, 0, $pos);
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
}
|
119
library/Zend/View/Helper/Currency.php
Normal file
119
library/Zend/View/Helper/Currency.php
Normal file
|
@ -0,0 +1,119 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id:$
|
||||
*/
|
||||
|
||||
/** Zend_View_Helper_Abstract.php */
|
||||
require_once 'Zend/View/Helper/Abstract.php';
|
||||
|
||||
/**
|
||||
* Currency view helper
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_Currency extends Zend_View_Helper_Abstract
|
||||
{
|
||||
/**
|
||||
* Currency object
|
||||
*
|
||||
* @var Zend_Currency
|
||||
*/
|
||||
protected $_currency;
|
||||
|
||||
/**
|
||||
* Constructor for manually handling
|
||||
*
|
||||
* @param Zend_Currency $currency Instance of Zend_Currency
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($currency = null)
|
||||
{
|
||||
if ($currency === null) {
|
||||
require_once 'Zend/Registry.php';
|
||||
if (Zend_Registry::isRegistered('Zend_Currency')) {
|
||||
$currency = Zend_Registry::get('Zend_Currency');
|
||||
}
|
||||
}
|
||||
|
||||
$this->setCurrency($currency);
|
||||
}
|
||||
|
||||
/**
|
||||
* Output a formatted currency
|
||||
*
|
||||
* @param integer|float $value Currency value to output
|
||||
* @param string|Zend_Locale|Zend_Currency $currency OPTIONAL Currency to use for this call
|
||||
* @return string Formatted currency
|
||||
*/
|
||||
public function currency($value = null, $currency = null)
|
||||
{
|
||||
if ($value === null) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
if (is_string($currency) || ($currency instanceof Zend_Locale)) {
|
||||
require_once 'Zend/Locale.php';
|
||||
if (Zend_Locale::isLocale($currency)) {
|
||||
$currency = array('locale' => $currency);
|
||||
}
|
||||
}
|
||||
|
||||
if (is_string($currency)) {
|
||||
$currency = array('currency' => $currency);
|
||||
}
|
||||
|
||||
if (is_array($currency)) {
|
||||
return $this->_currency->toCurrency($value, $currency);
|
||||
}
|
||||
|
||||
return $this->_currency->toCurrency($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a currency to use
|
||||
*
|
||||
* @param Zend_Currency|String|Zend_Locale $currency Currency to use
|
||||
* @throws Zend_View_Exception When no or a false currency was set
|
||||
* @return Zend_View_Helper_Currency
|
||||
*/
|
||||
public function setCurrency($currency = null)
|
||||
{
|
||||
if (!$currency instanceof Zend_Currency) {
|
||||
require_once 'Zend/Currency.php';
|
||||
$currency = new Zend_Currency($currency);
|
||||
}
|
||||
$this->_currency = $currency;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve currency object
|
||||
*
|
||||
* @return Zend_Currency|null
|
||||
*/
|
||||
public function getCurrency()
|
||||
{
|
||||
return $this->_currency;
|
||||
}
|
||||
}
|
226
library/Zend/View/Helper/Cycle.php
Normal file
226
library/Zend/View/Helper/Cycle.php
Normal file
|
@ -0,0 +1,226 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: Cycle.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Helper for alternating between set of values
|
||||
*
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_Cycle implements Iterator
|
||||
{
|
||||
|
||||
/**
|
||||
* Default name
|
||||
* @var string
|
||||
*/
|
||||
const DEFAULT_NAME = 'default';
|
||||
|
||||
/**
|
||||
* Pointers
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_pointers = array(self::DEFAULT_NAME =>-1) ;
|
||||
|
||||
/**
|
||||
* Array of values
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_data = array(self::DEFAULT_NAME=>array());
|
||||
|
||||
/**
|
||||
* Actual name of cycle
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_name = self::DEFAULT_NAME;
|
||||
|
||||
/**
|
||||
* Add elements to alternate
|
||||
*
|
||||
* @param array $data
|
||||
* @param string $name
|
||||
* @return Zend_View_Helper_Cycle
|
||||
*/
|
||||
public function cycle(array $data = array(), $name = self::DEFAULT_NAME)
|
||||
{
|
||||
if(!empty($data))
|
||||
$this->_data[$name] = $data;
|
||||
|
||||
$this->setName($name);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add elements to alternate
|
||||
*
|
||||
* @param array $data
|
||||
* @param string $name
|
||||
* @return Zend_View_Helper_Cycle
|
||||
*/
|
||||
public function assign(Array $data , $name = self::DEFAULT_NAME)
|
||||
{
|
||||
$this->setName($name);
|
||||
$this->_data[$name] = $data;
|
||||
$this->rewind();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets actual name of cycle
|
||||
*
|
||||
* @param $name
|
||||
* @return Zend_View_Helper_Cycle
|
||||
*/
|
||||
public function setName($name = self::DEFAULT_NAME)
|
||||
{
|
||||
$this->_name = $name;
|
||||
|
||||
if(!isset($this->_data[$this->_name]))
|
||||
$this->_data[$this->_name] = array();
|
||||
|
||||
if(!isset($this->_pointers[$this->_name]))
|
||||
$this->rewind();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets actual name of cycle
|
||||
*
|
||||
* @param $name
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->_name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return all elements
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAll()
|
||||
{
|
||||
return $this->_data[$this->_name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn helper into string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function toString()
|
||||
{
|
||||
return (string) $this->_data[$this->_name][$this->key()];
|
||||
}
|
||||
|
||||
/**
|
||||
* Cast to string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Move to next value
|
||||
*
|
||||
* @return Zend_View_Helper_Cycle
|
||||
*/
|
||||
public function next()
|
||||
{
|
||||
$count = count($this->_data[$this->_name]);
|
||||
if ($this->_pointers[$this->_name] == ($count - 1))
|
||||
$this->_pointers[$this->_name] = 0;
|
||||
else
|
||||
$this->_pointers[$this->_name] = ++$this->_pointers[$this->_name];
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move to previous value
|
||||
*
|
||||
* @return Zend_View_Helper_Cycle
|
||||
*/
|
||||
public function prev()
|
||||
{
|
||||
$count = count($this->_data[$this->_name]);
|
||||
if ($this->_pointers[$this->_name] <= 0)
|
||||
$this->_pointers[$this->_name] = $count - 1;
|
||||
else
|
||||
$this->_pointers[$this->_name] = --$this->_pointers[$this->_name];
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return iteration number
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function key()
|
||||
{
|
||||
if ($this->_pointers[$this->_name] < 0)
|
||||
return 0;
|
||||
else
|
||||
return $this->_pointers[$this->_name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Rewind pointer
|
||||
*
|
||||
* @return Zend_View_Helper_Cycle
|
||||
*/
|
||||
public function rewind()
|
||||
{
|
||||
$this->_pointers[$this->_name] = -1;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if element is valid
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function valid()
|
||||
{
|
||||
return isset($this->_data[$this->_name][$this->key()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return current element
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function current()
|
||||
{
|
||||
return $this->_data[$this->_name][$this->key()];
|
||||
}
|
||||
}
|
95
library/Zend/View/Helper/DeclareVars.php
Normal file
95
library/Zend/View/Helper/DeclareVars.php
Normal file
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: DeclareVars.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/** Zend_View_Helper_Abstract.php */
|
||||
require_once 'Zend/View/Helper/Abstract.php';
|
||||
|
||||
/**
|
||||
* Helper for declaring default values of template variables
|
||||
*
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_DeclareVars extends Zend_View_Helper_Abstract
|
||||
{
|
||||
/**
|
||||
* The view object that created this helper object.
|
||||
* @var Zend_View
|
||||
*/
|
||||
public $view;
|
||||
|
||||
/**
|
||||
* Declare template vars to set default values and avoid notices when using strictVars
|
||||
*
|
||||
* Primarily for use when using {@link Zend_View_Abstract::strictVars() Zend_View strictVars()},
|
||||
* this helper can be used to declare template variables that may or may
|
||||
* not already be set in the view object, as well as to set default values.
|
||||
* Arrays passed as arguments to the method will be used to set default
|
||||
* values; otherwise, if the variable does not exist, it is set to an empty
|
||||
* string.
|
||||
*
|
||||
* Usage:
|
||||
* <code>
|
||||
* $this->declareVars(
|
||||
* 'varName1',
|
||||
* 'varName2',
|
||||
* array('varName3' => 'defaultValue',
|
||||
* 'varName4' => array()
|
||||
* )
|
||||
* );
|
||||
* </code>
|
||||
*
|
||||
* @param string|array variable number of arguments, all string names of variables to test
|
||||
* @return void
|
||||
*/
|
||||
public function declareVars()
|
||||
{
|
||||
$args = func_get_args();
|
||||
foreach($args as $key) {
|
||||
if (is_array($key)) {
|
||||
foreach ($key as $name => $value) {
|
||||
$this->_declareVar($name, $value);
|
||||
}
|
||||
} else if (!isset($view->$key)) {
|
||||
$this->_declareVar($key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a view variable
|
||||
*
|
||||
* Checks to see if a $key is set in the view object; if not, sets it to $value.
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $value Defaults to an empty string
|
||||
* @return void
|
||||
*/
|
||||
protected function _declareVar($key, $value = '')
|
||||
{
|
||||
if (!isset($this->view->$key)) {
|
||||
$this->view->$key = $value;
|
||||
}
|
||||
}
|
||||
}
|
209
library/Zend/View/Helper/Doctype.php
Normal file
209
library/Zend/View/Helper/Doctype.php
Normal file
|
@ -0,0 +1,209 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: Doctype.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/** Zend_Registry */
|
||||
require_once 'Zend/Registry.php';
|
||||
|
||||
/** Zend_View_Helper_Abstract.php */
|
||||
require_once 'Zend/View/Helper/Abstract.php';
|
||||
|
||||
/**
|
||||
* Helper for setting and retrieving the doctype
|
||||
*
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_Doctype extends Zend_View_Helper_Abstract
|
||||
{
|
||||
/**#@+
|
||||
* DocType constants
|
||||
*/
|
||||
const XHTML11 = 'XHTML11';
|
||||
const XHTML1_STRICT = 'XHTML1_STRICT';
|
||||
const XHTML1_TRANSITIONAL = 'XHTML1_TRANSITIONAL';
|
||||
const XHTML1_FRAMESET = 'XHTML1_FRAMESET';
|
||||
const XHTML_BASIC1 = 'XHTML_BASIC1';
|
||||
const XHTML5 = 'XHTML5';
|
||||
const HTML4_STRICT = 'HTML4_STRICT';
|
||||
const HTML4_LOOSE = 'HTML4_LOOSE';
|
||||
const HTML4_FRAMESET = 'HTML4_FRAMESET';
|
||||
const HTML5 = 'HTML5';
|
||||
const CUSTOM_XHTML = 'CUSTOM_XHTML';
|
||||
const CUSTOM = 'CUSTOM';
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
* Default DocType
|
||||
* @var string
|
||||
*/
|
||||
protected $_defaultDoctype = self::HTML4_LOOSE;
|
||||
|
||||
/**
|
||||
* Registry containing current doctype and mappings
|
||||
* @var ArrayObject
|
||||
*/
|
||||
protected $_registry;
|
||||
|
||||
/**
|
||||
* Registry key in which helper is stored
|
||||
* @var string
|
||||
*/
|
||||
protected $_regKey = 'Zend_View_Helper_Doctype';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Map constants to doctype strings, and set default doctype
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
if (!Zend_Registry::isRegistered($this->_regKey)) {
|
||||
$this->_registry = new ArrayObject(array(
|
||||
'doctypes' => array(
|
||||
self::XHTML11 => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">',
|
||||
self::XHTML1_STRICT => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
|
||||
self::XHTML1_TRANSITIONAL => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
|
||||
self::XHTML1_FRAMESET => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">',
|
||||
self::XHTML_BASIC1 => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd">',
|
||||
self::XHTML5 => '<!DOCTYPE html>',
|
||||
self::HTML4_STRICT => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">',
|
||||
self::HTML4_LOOSE => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">',
|
||||
self::HTML4_FRAMESET => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">',
|
||||
self::HTML5 => '<!DOCTYPE html>',
|
||||
)
|
||||
));
|
||||
Zend_Registry::set($this->_regKey, $this->_registry);
|
||||
$this->setDoctype($this->_defaultDoctype);
|
||||
} else {
|
||||
$this->_registry = Zend_Registry::get($this->_regKey);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set or retrieve doctype
|
||||
*
|
||||
* @param string $doctype
|
||||
* @return Zend_View_Helper_Doctype
|
||||
*/
|
||||
public function doctype($doctype = null)
|
||||
{
|
||||
if (null !== $doctype) {
|
||||
switch ($doctype) {
|
||||
case self::XHTML11:
|
||||
case self::XHTML1_STRICT:
|
||||
case self::XHTML1_TRANSITIONAL:
|
||||
case self::XHTML1_FRAMESET:
|
||||
case self::XHTML_BASIC1:
|
||||
case self::XHTML5:
|
||||
case self::HTML4_STRICT:
|
||||
case self::HTML4_LOOSE:
|
||||
case self::HTML4_FRAMESET:
|
||||
case self::HTML5:
|
||||
$this->setDoctype($doctype);
|
||||
break;
|
||||
default:
|
||||
if (substr($doctype, 0, 9) != '<!DOCTYPE') {
|
||||
require_once 'Zend/View/Exception.php';
|
||||
$e = new Zend_View_Exception('The specified doctype is malformed');
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
if (stristr($doctype, 'xhtml')) {
|
||||
$type = self::CUSTOM_XHTML;
|
||||
} else {
|
||||
$type = self::CUSTOM;
|
||||
}
|
||||
$this->setDoctype($type);
|
||||
$this->_registry['doctypes'][$type] = $doctype;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set doctype
|
||||
*
|
||||
* @param string $doctype
|
||||
* @return Zend_View_Helper_Doctype
|
||||
*/
|
||||
public function setDoctype($doctype)
|
||||
{
|
||||
$this->_registry['doctype'] = $doctype;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve doctype
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDoctype()
|
||||
{
|
||||
return $this->_registry['doctype'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get doctype => string mappings
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDoctypes()
|
||||
{
|
||||
return $this->_registry['doctypes'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Is doctype XHTML?
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isXhtml()
|
||||
{
|
||||
return (stristr($this->getDoctype(), 'xhtml') ? true : false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is doctype HTML5? (HeadMeta uses this for validation)
|
||||
*
|
||||
* @return booleean
|
||||
*/
|
||||
public function isHtml5() {
|
||||
return (stristr($this->doctype(), '<!DOCTYPE html>') ? true : false);
|
||||
}
|
||||
|
||||
/**
|
||||
* String representation of doctype
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
$doctypes = $this->getDoctypes();
|
||||
return $doctypes[$this->getDoctype()];
|
||||
}
|
||||
}
|
79
library/Zend/View/Helper/Fieldset.php
Normal file
79
library/Zend/View/Helper/Fieldset.php
Normal file
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: Fieldset.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/** Zend_View_Helper_FormElement */
|
||||
require_once 'Zend/View/Helper/FormElement.php';
|
||||
|
||||
/**
|
||||
* Helper for rendering fieldsets
|
||||
*
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_Fieldset extends Zend_View_Helper_FormElement
|
||||
{
|
||||
/**
|
||||
* Render HTML form
|
||||
*
|
||||
* @param string $name Form name
|
||||
* @param string $content Form content
|
||||
* @param array $attribs HTML form attributes
|
||||
* @return string
|
||||
*/
|
||||
public function fieldset($name, $content, $attribs = null)
|
||||
{
|
||||
$info = $this->_getInfo($name, $content, $attribs);
|
||||
extract($info);
|
||||
|
||||
// get legend
|
||||
$legend = '';
|
||||
if (isset($attribs['legend'])) {
|
||||
$legendString = trim($attribs['legend']);
|
||||
if (!empty($legendString)) {
|
||||
$legend = '<legend>'
|
||||
. (($escape) ? $this->view->escape($legendString) : $legendString)
|
||||
. '</legend>' . PHP_EOL;
|
||||
}
|
||||
unset($attribs['legend']);
|
||||
}
|
||||
|
||||
// get id
|
||||
if (!empty($id)) {
|
||||
$id = ' id="' . $this->view->escape($id) . '"';
|
||||
} else {
|
||||
$id = '';
|
||||
}
|
||||
|
||||
// render fieldset
|
||||
$xhtml = '<fieldset'
|
||||
. $id
|
||||
. $this->_htmlAttribs($attribs)
|
||||
. '>'
|
||||
. $legend
|
||||
. $content
|
||||
. '</fieldset>';
|
||||
|
||||
return $xhtml;
|
||||
}
|
||||
}
|
71
library/Zend/View/Helper/Form.php
Normal file
71
library/Zend/View/Helper/Form.php
Normal file
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: Form.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/** Zend_View_Helper_FormElement */
|
||||
require_once 'Zend/View/Helper/FormElement.php';
|
||||
|
||||
/**
|
||||
* Helper for rendering HTML forms
|
||||
*
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_Form extends Zend_View_Helper_FormElement
|
||||
{
|
||||
/**
|
||||
* Render HTML form
|
||||
*
|
||||
* @param string $name Form name
|
||||
* @param null|array $attribs HTML form attributes
|
||||
* @param false|string $content Form content
|
||||
* @return string
|
||||
*/
|
||||
public function form($name, $attribs = null, $content = false)
|
||||
{
|
||||
$info = $this->_getInfo($name, $content, $attribs);
|
||||
extract($info);
|
||||
|
||||
if (!empty($id)) {
|
||||
$id = ' id="' . $this->view->escape($id) . '"';
|
||||
} else {
|
||||
$id = '';
|
||||
}
|
||||
|
||||
if (array_key_exists('id', $attribs) && empty($attribs['id'])) {
|
||||
unset($attribs['id']);
|
||||
}
|
||||
|
||||
$xhtml = '<form'
|
||||
. $id
|
||||
. $this->_htmlAttribs($attribs)
|
||||
. '>';
|
||||
|
||||
if (false !== $content) {
|
||||
$xhtml .= $content
|
||||
. '</form>';
|
||||
}
|
||||
|
||||
return $xhtml;
|
||||
}
|
||||
}
|
105
library/Zend/View/Helper/FormButton.php
Normal file
105
library/Zend/View/Helper/FormButton.php
Normal file
|
@ -0,0 +1,105 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: FormButton.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Abstract class for extension
|
||||
*/
|
||||
require_once 'Zend/View/Helper/FormElement.php';
|
||||
|
||||
|
||||
/**
|
||||
* Helper to generate a "button" element
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_FormButton extends Zend_View_Helper_FormElement
|
||||
{
|
||||
/**
|
||||
* Generates a 'button' element.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string|array $name If a string, the element name. If an
|
||||
* array, all other parameters are ignored, and the array elements
|
||||
* are extracted in place of added parameters.
|
||||
*
|
||||
* @param mixed $value The element value.
|
||||
*
|
||||
* @param array $attribs Attributes for the element tag.
|
||||
*
|
||||
* @return string The element XHTML.
|
||||
*/
|
||||
public function formButton($name, $value = null, $attribs = null)
|
||||
{
|
||||
$info = $this->_getInfo($name, $value, $attribs);
|
||||
extract($info); // name, id, value, attribs, options, listsep, disable
|
||||
|
||||
// Get content
|
||||
$content = '';
|
||||
if (isset($attribs['content'])) {
|
||||
$content = $attribs['content'];
|
||||
unset($attribs['content']);
|
||||
} else {
|
||||
$content = $value;
|
||||
}
|
||||
|
||||
// Ensure type is sane
|
||||
$type = 'button';
|
||||
if (isset($attribs['type'])) {
|
||||
$attribs['type'] = strtolower($attribs['type']);
|
||||
if (in_array($attribs['type'], array('submit', 'reset', 'button'))) {
|
||||
$type = $attribs['type'];
|
||||
}
|
||||
unset($attribs['type']);
|
||||
}
|
||||
|
||||
// build the element
|
||||
if ($disable) {
|
||||
$attribs['disabled'] = 'disabled';
|
||||
}
|
||||
|
||||
$content = ($escape) ? $this->view->escape($content) : $content;
|
||||
|
||||
$xhtml = '<button'
|
||||
. ' name="' . $this->view->escape($name) . '"'
|
||||
. ' id="' . $this->view->escape($id) . '"'
|
||||
. ' type="' . $type . '"';
|
||||
|
||||
// add a value if one is given
|
||||
if (!empty($value)) {
|
||||
$xhtml .= ' value="' . $this->view->escape($value) . '"';
|
||||
}
|
||||
|
||||
// add attributes and close start tag
|
||||
$xhtml .= $this->_htmlAttribs($attribs) . '>';
|
||||
|
||||
// add content and end tag
|
||||
$xhtml .= $content . '</button>';
|
||||
|
||||
return $xhtml;
|
||||
}
|
||||
}
|
163
library/Zend/View/Helper/FormCheckbox.php
Normal file
163
library/Zend/View/Helper/FormCheckbox.php
Normal file
|
@ -0,0 +1,163 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: FormCheckbox.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Abstract class for extension
|
||||
*/
|
||||
require_once 'Zend/View/Helper/FormElement.php';
|
||||
|
||||
|
||||
/**
|
||||
* Helper to generate a "checkbox" element
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_FormCheckbox extends Zend_View_Helper_FormElement
|
||||
{
|
||||
/**
|
||||
* Default checked/unchecked options
|
||||
* @var array
|
||||
*/
|
||||
protected static $_defaultCheckedOptions = array(
|
||||
'checkedValue' => '1',
|
||||
'uncheckedValue' => '0'
|
||||
);
|
||||
|
||||
/**
|
||||
* Generates a 'checkbox' element.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string|array $name If a string, the element name. If an
|
||||
* array, all other parameters are ignored, and the array elements
|
||||
* are extracted in place of added parameters.
|
||||
* @param mixed $value The element value.
|
||||
* @param array $attribs Attributes for the element tag.
|
||||
* @return string The element XHTML.
|
||||
*/
|
||||
public function formCheckbox($name, $value = null, $attribs = null, array $checkedOptions = null)
|
||||
{
|
||||
$info = $this->_getInfo($name, $value, $attribs);
|
||||
extract($info); // name, id, value, attribs, options, listsep, disable
|
||||
|
||||
$checked = false;
|
||||
if (isset($attribs['checked']) && $attribs['checked']) {
|
||||
$checked = true;
|
||||
unset($attribs['checked']);
|
||||
} elseif (isset($attribs['checked'])) {
|
||||
$checked = false;
|
||||
unset($attribs['checked']);
|
||||
}
|
||||
|
||||
$checkedOptions = self::determineCheckboxInfo($value, $checked, $checkedOptions);
|
||||
|
||||
// is the element disabled?
|
||||
$disabled = '';
|
||||
if ($disable) {
|
||||
$disabled = ' disabled="disabled"';
|
||||
}
|
||||
|
||||
// XHTML or HTML end tag?
|
||||
$endTag = ' />';
|
||||
if (($this->view instanceof Zend_View_Abstract) && !$this->view->doctype()->isXhtml()) {
|
||||
$endTag= '>';
|
||||
}
|
||||
|
||||
// build the element
|
||||
$xhtml = '';
|
||||
if (!$disable && !strstr($name, '[]')) {
|
||||
$xhtml = $this->_hidden($name, $checkedOptions['uncheckedValue']);
|
||||
}
|
||||
$xhtml .= '<input type="checkbox"'
|
||||
. ' name="' . $this->view->escape($name) . '"'
|
||||
. ' id="' . $this->view->escape($id) . '"'
|
||||
. ' value="' . $this->view->escape($checkedOptions['checkedValue']) . '"'
|
||||
. $checkedOptions['checkedString']
|
||||
. $disabled
|
||||
. $this->_htmlAttribs($attribs)
|
||||
. $endTag;
|
||||
|
||||
return $xhtml;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine checkbox information
|
||||
*
|
||||
* @param string $value
|
||||
* @param bool $checked
|
||||
* @param array|null $checkedOptions
|
||||
* @return array
|
||||
*/
|
||||
public static function determineCheckboxInfo($value, $checked, array $checkedOptions = null)
|
||||
{
|
||||
// Checked/unchecked values
|
||||
$checkedValue = null;
|
||||
$uncheckedValue = null;
|
||||
if (is_array($checkedOptions)) {
|
||||
if (array_key_exists('checkedValue', $checkedOptions)) {
|
||||
$checkedValue = (string) $checkedOptions['checkedValue'];
|
||||
unset($checkedOptions['checkedValue']);
|
||||
}
|
||||
if (array_key_exists('uncheckedValue', $checkedOptions)) {
|
||||
$uncheckedValue = (string) $checkedOptions['uncheckedValue'];
|
||||
unset($checkedOptions['uncheckedValue']);
|
||||
}
|
||||
if (null === $checkedValue) {
|
||||
$checkedValue = (string) array_shift($checkedOptions);
|
||||
}
|
||||
if (null === $uncheckedValue) {
|
||||
$uncheckedValue = (string) array_shift($checkedOptions);
|
||||
}
|
||||
} elseif ($value !== null) {
|
||||
$uncheckedValue = self::$_defaultCheckedOptions['uncheckedValue'];
|
||||
} else {
|
||||
$checkedValue = self::$_defaultCheckedOptions['checkedValue'];
|
||||
$uncheckedValue = self::$_defaultCheckedOptions['uncheckedValue'];
|
||||
}
|
||||
|
||||
// is the element checked?
|
||||
$checkedString = '';
|
||||
if ($checked || ((string) $value === $checkedValue)) {
|
||||
$checkedString = ' checked="checked"';
|
||||
$checked = true;
|
||||
} else {
|
||||
$checked = false;
|
||||
}
|
||||
|
||||
// Checked value should be value if no checked options provided
|
||||
if ($checkedValue == null) {
|
||||
$checkedValue = $value;
|
||||
}
|
||||
|
||||
return array(
|
||||
'checked' => $checked,
|
||||
'checkedString' => $checkedString,
|
||||
'checkedValue' => $checkedValue,
|
||||
'uncheckedValue' => $uncheckedValue,
|
||||
);
|
||||
}
|
||||
}
|
204
library/Zend/View/Helper/FormElement.php
Normal file
204
library/Zend/View/Helper/FormElement.php
Normal file
|
@ -0,0 +1,204 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: FormElement.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_View_Helper_HtmlElement
|
||||
*/
|
||||
require_once 'Zend/View/Helper/HtmlElement.php';
|
||||
|
||||
/**
|
||||
* Base helper for form elements. Extend this, don't use it on its own.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_View_Helper_FormElement extends Zend_View_Helper_HtmlElement
|
||||
{
|
||||
/**
|
||||
* @var Zend_Translate
|
||||
*/
|
||||
protected $_translator;
|
||||
|
||||
/**
|
||||
* Get translator
|
||||
*
|
||||
* @return Zend_Translate
|
||||
*/
|
||||
public function getTranslator()
|
||||
{
|
||||
return $this->_translator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set translator
|
||||
*
|
||||
* @param $translator|null Zend_Translate
|
||||
* @return Zend_View_Helper_FormElement
|
||||
*/
|
||||
public function setTranslator($translator = null)
|
||||
{
|
||||
if (null === $translator) {
|
||||
$this->_translator = null;
|
||||
} elseif ($translator instanceof Zend_Translate_Adapter) {
|
||||
$this->_translator = $translator;
|
||||
} elseif ($translator instanceof Zend_Translate) {
|
||||
$this->_translator = $translator->getAdapter();
|
||||
} else {
|
||||
require_once 'Zend/View/Exception.php';
|
||||
$e = new Zend_View_Exception('Invalid translator specified');
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts parameter arguments to an element info array.
|
||||
*
|
||||
* E.g, formExample($name, $value, $attribs, $options, $listsep) is
|
||||
* the same thing as formExample(array('name' => ...)).
|
||||
*
|
||||
* Note that you cannot pass a 'disable' param; you need to pass
|
||||
* it as an 'attribs' key.
|
||||
*
|
||||
* @access protected
|
||||
*
|
||||
* @return array An element info array with keys for name, value,
|
||||
* attribs, options, listsep, disable, and escape.
|
||||
*/
|
||||
protected function _getInfo($name, $value = null, $attribs = null,
|
||||
$options = null, $listsep = null
|
||||
) {
|
||||
// the baseline info. note that $name serves a dual purpose;
|
||||
// if an array, it's an element info array that will override
|
||||
// these baseline values. as such, ignore it for the 'name'
|
||||
// if it's an array.
|
||||
$info = array(
|
||||
'name' => is_array($name) ? '' : $name,
|
||||
'id' => is_array($name) ? '' : $name,
|
||||
'value' => $value,
|
||||
'attribs' => $attribs,
|
||||
'options' => $options,
|
||||
'listsep' => $listsep,
|
||||
'disable' => false,
|
||||
'escape' => true,
|
||||
);
|
||||
|
||||
// override with named args
|
||||
if (is_array($name)) {
|
||||
// only set keys that are already in info
|
||||
foreach ($info as $key => $val) {
|
||||
if (isset($name[$key])) {
|
||||
$info[$key] = $name[$key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// force attribs to an array, per note from Orjan Persson.
|
||||
settype($info['attribs'], 'array');
|
||||
|
||||
// Normalize readonly tag
|
||||
if (isset($info['attribs']['readonly'])
|
||||
&& $info['attribs']['readonly'] != 'readonly')
|
||||
{
|
||||
$info['attribs']['readonly'] = 'readonly';
|
||||
}
|
||||
|
||||
// Disable attribute
|
||||
if (isset($info['attribs']['disable'])
|
||||
&& is_scalar($info['attribs']['disable']))
|
||||
{
|
||||
// disable the element
|
||||
$info['disable'] = (bool)$info['attribs']['disable'];
|
||||
unset($info['attribs']['disable']);
|
||||
} elseif (isset($info['attribs']['disable'])
|
||||
&& is_array($info['attribs']['disable']))
|
||||
{
|
||||
$info['disable'] = $info['attribs']['disable'];
|
||||
unset($info['attribs']['disable']);
|
||||
}
|
||||
|
||||
// Set ID for element
|
||||
if (isset($info['attribs']['id'])) {
|
||||
$info['id'] = (string) $info['attribs']['id'];
|
||||
} elseif (!isset($info['attribs']['id']) && !empty($info['name'])) {
|
||||
$id = $info['name'];
|
||||
if (substr($id, -2) == '[]') {
|
||||
$id = substr($id, 0, strlen($id) - 2);
|
||||
}
|
||||
if (strstr($id, ']')) {
|
||||
$id = trim($id, ']');
|
||||
$id = str_replace('][', '-', $id);
|
||||
$id = str_replace('[', '-', $id);
|
||||
}
|
||||
$info['id'] = $id;
|
||||
}
|
||||
|
||||
// Determine escaping from attributes
|
||||
if (isset($info['attribs']['escape'])) {
|
||||
$info['escape'] = (bool) $info['attribs']['escape'];
|
||||
}
|
||||
|
||||
// Determine listsetp from attributes
|
||||
if (isset($info['attribs']['listsep'])) {
|
||||
$info['listsep'] = (string) $info['attribs']['listsep'];
|
||||
}
|
||||
|
||||
// Remove attribs that might overwrite the other keys. We do this LAST
|
||||
// because we needed the other attribs values earlier.
|
||||
foreach ($info as $key => $val) {
|
||||
if (isset($info['attribs'][$key])) {
|
||||
unset($info['attribs'][$key]);
|
||||
}
|
||||
}
|
||||
|
||||
// done!
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a hidden element.
|
||||
*
|
||||
* We have this as a common method because other elements often
|
||||
* need hidden elements for their operation.
|
||||
*
|
||||
* @access protected
|
||||
*
|
||||
* @param $name The element name.
|
||||
*
|
||||
* @param $value The element value.
|
||||
*
|
||||
* @param $attribs Attributes for the element.
|
||||
*
|
||||
* @return string A hidden element.
|
||||
*/
|
||||
protected function _hidden($name, $value = null, $attribs = null)
|
||||
{
|
||||
return '<input type="hidden"'
|
||||
. ' name="' . $this->view->escape($name) . '"'
|
||||
. ' value="' . $this->view->escape($value) . '"'
|
||||
. $this->_htmlAttribs($attribs) . $this->getClosingBracket();
|
||||
}
|
||||
}
|
157
library/Zend/View/Helper/FormErrors.php
Normal file
157
library/Zend/View/Helper/FormErrors.php
Normal file
|
@ -0,0 +1,157 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: FormErrors.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstract class for extension
|
||||
*/
|
||||
require_once 'Zend/View/Helper/FormElement.php';
|
||||
|
||||
|
||||
/**
|
||||
* Helper to render errors for a form element
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_FormErrors extends Zend_View_Helper_FormElement
|
||||
{
|
||||
/**
|
||||
* @var Zend_Form_Element
|
||||
*/
|
||||
protected $_element;
|
||||
|
||||
/**#@+
|
||||
* @var string Element block start/end tags and separator
|
||||
*/
|
||||
protected $_htmlElementEnd = '</li></ul>';
|
||||
protected $_htmlElementStart = '<ul%s><li>';
|
||||
protected $_htmlElementSeparator = '</li><li>';
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
* Render form errors
|
||||
*
|
||||
* @param string|array $errors Error(s) to render
|
||||
* @param array $options
|
||||
* @return string
|
||||
*/
|
||||
public function formErrors($errors, array $options = null)
|
||||
{
|
||||
$escape = true;
|
||||
if (isset($options['escape'])) {
|
||||
$escape = (bool) $options['escape'];
|
||||
unset($options['escape']);
|
||||
}
|
||||
|
||||
if (empty($options['class'])) {
|
||||
$options['class'] = 'errors';
|
||||
}
|
||||
|
||||
$start = $this->getElementStart();
|
||||
if (strstr($start, '%s')) {
|
||||
$attribs = $this->_htmlAttribs($options);
|
||||
$start = sprintf($start, $attribs);
|
||||
}
|
||||
|
||||
if ($escape) {
|
||||
foreach ($errors as $key => $error) {
|
||||
$errors[$key] = $this->view->escape($error);
|
||||
}
|
||||
}
|
||||
|
||||
$html = $start
|
||||
. implode($this->getElementSeparator(), (array) $errors)
|
||||
. $this->getElementEnd();
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set end string for displaying errors
|
||||
*
|
||||
* @param string $string
|
||||
* @return Zend_View_Helper_FormErrors
|
||||
*/
|
||||
public function setElementEnd($string)
|
||||
{
|
||||
$this->_htmlElementEnd = (string) $string;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve end string for displaying errors
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getElementEnd()
|
||||
{
|
||||
return $this->_htmlElementEnd;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set separator string for displaying errors
|
||||
*
|
||||
* @param string $string
|
||||
* @return Zend_View_Helper_FormErrors
|
||||
*/
|
||||
public function setElementSeparator($string)
|
||||
{
|
||||
$this->_htmlElementSeparator = (string) $string;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve separator string for displaying errors
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getElementSeparator()
|
||||
{
|
||||
return $this->_htmlElementSeparator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set start string for displaying errors
|
||||
*
|
||||
* @param string $string
|
||||
* @return Zend_View_Helper_FormErrors
|
||||
*/
|
||||
public function setElementStart($string)
|
||||
{
|
||||
$this->_htmlElementStart = (string) $string;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve start string for displaying errors
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getElementStart()
|
||||
{
|
||||
return $this->_htmlElementStart;
|
||||
}
|
||||
|
||||
}
|
81
library/Zend/View/Helper/FormFile.php
Normal file
81
library/Zend/View/Helper/FormFile.php
Normal file
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: FormFile.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Abstract class for extension
|
||||
*/
|
||||
require_once 'Zend/View/Helper/FormElement.php';
|
||||
|
||||
|
||||
/**
|
||||
* Helper to generate a "file" element
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_FormFile extends Zend_View_Helper_FormElement
|
||||
{
|
||||
/**
|
||||
* Generates a 'file' element.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string|array $name If a string, the element name. If an
|
||||
* array, all other parameters are ignored, and the array elements
|
||||
* are extracted in place of added parameters.
|
||||
*
|
||||
* @param array $attribs Attributes for the element tag.
|
||||
*
|
||||
* @return string The element XHTML.
|
||||
*/
|
||||
public function formFile($name, $attribs = null)
|
||||
{
|
||||
$info = $this->_getInfo($name, null, $attribs);
|
||||
extract($info); // name, id, value, attribs, options, listsep, disable
|
||||
|
||||
// is it disabled?
|
||||
$disabled = '';
|
||||
if ($disable) {
|
||||
$disabled = ' disabled="disabled"';
|
||||
}
|
||||
|
||||
// XHTML or HTML end tag?
|
||||
$endTag = ' />';
|
||||
if (($this->view instanceof Zend_View_Abstract) && !$this->view->doctype()->isXhtml()) {
|
||||
$endTag= '>';
|
||||
}
|
||||
|
||||
// build the element
|
||||
$xhtml = '<input type="file"'
|
||||
. ' name="' . $this->view->escape($name) . '"'
|
||||
. ' id="' . $this->view->escape($id) . '"'
|
||||
. $disabled
|
||||
. $this->_htmlAttribs($attribs)
|
||||
. $endTag;
|
||||
|
||||
return $xhtml;
|
||||
}
|
||||
}
|
66
library/Zend/View/Helper/FormHidden.php
Normal file
66
library/Zend/View/Helper/FormHidden.php
Normal file
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: FormHidden.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Abstract class for extension
|
||||
*/
|
||||
require_once 'Zend/View/Helper/FormElement.php';
|
||||
|
||||
|
||||
/**
|
||||
* Helper to generate a "hidden" element
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_FormHidden extends Zend_View_Helper_FormElement
|
||||
{
|
||||
/**
|
||||
* Generates a 'hidden' element.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string|array $name If a string, the element name. If an
|
||||
* array, all other parameters are ignored, and the array elements
|
||||
* are extracted in place of added parameters.
|
||||
* @param mixed $value The element value.
|
||||
* @param array $attribs Attributes for the element tag.
|
||||
* @return string The element XHTML.
|
||||
*/
|
||||
public function formHidden($name, $value = null, array $attribs = null)
|
||||
{
|
||||
$info = $this->_getInfo($name, $value, $attribs);
|
||||
extract($info); // name, value, attribs, options, listsep, disable
|
||||
if (isset($id)) {
|
||||
if (isset($attribs) && is_array($attribs)) {
|
||||
$attribs['id'] = $id;
|
||||
} else {
|
||||
$attribs = array('id' => $id);
|
||||
}
|
||||
}
|
||||
return $this->_hidden($name, $value, $attribs);
|
||||
}
|
||||
}
|
101
library/Zend/View/Helper/FormImage.php
Normal file
101
library/Zend/View/Helper/FormImage.php
Normal file
|
@ -0,0 +1,101 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: FormImage.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Abstract class for extension
|
||||
*/
|
||||
require_once 'Zend/View/Helper/FormElement.php';
|
||||
|
||||
|
||||
/**
|
||||
* Helper to generate an "image" element
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_FormImage extends Zend_View_Helper_FormElement
|
||||
{
|
||||
/**
|
||||
* Generates an 'image' element.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string|array $name If a string, the element name. If an
|
||||
* array, all other parameters are ignored, and the array elements
|
||||
* are extracted in place of added parameters.
|
||||
*
|
||||
* @param mixed $value The source ('src="..."') for the image.
|
||||
*
|
||||
* @param array $attribs Attributes for the element tag.
|
||||
*
|
||||
* @return string The element XHTML.
|
||||
*/
|
||||
public function formImage($name, $value = null, $attribs = null)
|
||||
{
|
||||
$info = $this->_getInfo($name, $value, $attribs);
|
||||
extract($info); // name, value, attribs, options, listsep, disable
|
||||
|
||||
// Determine if we should use the value or the src attribute
|
||||
if (isset($attribs['src'])) {
|
||||
$src = ' src="' . $this->view->escape($attribs['src']) . '"';
|
||||
unset($attribs['src']);
|
||||
} else {
|
||||
$src = ' src="' . $this->view->escape($value) . '"';
|
||||
unset($value);
|
||||
}
|
||||
|
||||
// Do we have a value?
|
||||
if (isset($value) && !empty($value)) {
|
||||
$value = ' value="' . $this->view->escape($value) . '"';
|
||||
} else {
|
||||
$value = '';
|
||||
}
|
||||
|
||||
// Disabled?
|
||||
$disabled = '';
|
||||
if ($disable) {
|
||||
$disabled = ' disabled="disabled"';
|
||||
}
|
||||
|
||||
// XHTML or HTML end tag?
|
||||
$endTag = ' />';
|
||||
if (($this->view instanceof Zend_View_Abstract) && !$this->view->doctype()->isXhtml()) {
|
||||
$endTag= '>';
|
||||
}
|
||||
|
||||
// build the element
|
||||
$xhtml = '<input type="image"'
|
||||
. ' name="' . $this->view->escape($name) . '"'
|
||||
. ' id="' . $this->view->escape($id) . '"'
|
||||
. $src
|
||||
. $value
|
||||
. $disabled
|
||||
. $this->_htmlAttribs($attribs)
|
||||
. $endTag;
|
||||
|
||||
return $xhtml;
|
||||
}
|
||||
}
|
72
library/Zend/View/Helper/FormLabel.php
Normal file
72
library/Zend/View/Helper/FormLabel.php
Normal file
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: FormLabel.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/** Zend_View_Helper_FormElement **/
|
||||
require_once 'Zend/View/Helper/FormElement.php';
|
||||
|
||||
/**
|
||||
* Form label helper
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_FormLabel extends Zend_View_Helper_FormElement
|
||||
{
|
||||
/**
|
||||
* Generates a 'label' element.
|
||||
*
|
||||
* @param string $name The form element name for which the label is being generated
|
||||
* @param string $value The label text
|
||||
* @param array $attribs Form element attributes (used to determine if disabled)
|
||||
* @return string The element XHTML.
|
||||
*/
|
||||
public function formLabel($name, $value = null, array $attribs = array())
|
||||
{
|
||||
$info = $this->_getInfo($name, $value, $attribs);
|
||||
extract($info); // name, value, attribs, options, listsep, disable, escape
|
||||
|
||||
// build the element
|
||||
if ($disable) {
|
||||
// disabled; display nothing
|
||||
return '';
|
||||
}
|
||||
|
||||
$value = ($escape) ? $this->view->escape($value) : $value;
|
||||
$for = (empty($attribs['disableFor']) || !$attribs['disableFor'])
|
||||
? ' for="' . $this->view->escape($id) . '"'
|
||||
: '';
|
||||
if (array_key_exists('disableFor', $attribs)) {
|
||||
unset($attribs['disableFor']);
|
||||
}
|
||||
|
||||
// enabled; display label
|
||||
$xhtml = '<label'
|
||||
. $for
|
||||
. $this->_htmlAttribs($attribs)
|
||||
. '>' . $value . '</label>';
|
||||
|
||||
return $xhtml;
|
||||
}
|
||||
}
|
74
library/Zend/View/Helper/FormMultiCheckbox.php
Normal file
74
library/Zend/View/Helper/FormMultiCheckbox.php
Normal file
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: FormMultiCheckbox.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
|
||||
/** Zend_View_Helper_FormRadio */
|
||||
require_once 'Zend/View/Helper/FormRadio.php';
|
||||
|
||||
|
||||
/**
|
||||
* Helper to generate a set of checkbox button elements
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_FormMultiCheckbox extends Zend_View_Helper_FormRadio
|
||||
{
|
||||
/**
|
||||
* Input type to use
|
||||
* @var string
|
||||
*/
|
||||
protected $_inputType = 'checkbox';
|
||||
|
||||
/**
|
||||
* Whether or not this element represents an array collection by default
|
||||
* @var bool
|
||||
*/
|
||||
protected $_isArray = true;
|
||||
|
||||
/**
|
||||
* Generates a set of checkbox button elements.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string|array $name If a string, the element name. If an
|
||||
* array, all other parameters are ignored, and the array elements
|
||||
* are extracted in place of added parameters.
|
||||
*
|
||||
* @param mixed $value The checkbox value to mark as 'checked'.
|
||||
*
|
||||
* @param array $options An array of key-value pairs where the array
|
||||
* key is the checkbox value, and the array value is the radio text.
|
||||
*
|
||||
* @param array|string $attribs Attributes added to each radio.
|
||||
*
|
||||
* @return string The radio buttons XHTML.
|
||||
*/
|
||||
public function formMultiCheckbox($name, $value = null, $attribs = null,
|
||||
$options = null, $listsep = "<br />\n")
|
||||
{
|
||||
return $this->formRadio($name, $value, $attribs, $options, $listsep);
|
||||
}
|
||||
}
|
61
library/Zend/View/Helper/FormNote.php
Normal file
61
library/Zend/View/Helper/FormNote.php
Normal file
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: FormNote.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Abstract class for extension
|
||||
*/
|
||||
require_once 'Zend/View/Helper/FormElement.php';
|
||||
|
||||
|
||||
/**
|
||||
* Helper to show an HTML note
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_FormNote extends Zend_View_Helper_FormElement
|
||||
{
|
||||
/**
|
||||
* Helper to show a "note" based on a hidden value.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string|array $name If a string, the element name. If an
|
||||
* array, all other parameters are ignored, and the array elements
|
||||
* are extracted in place of added parameters.
|
||||
*
|
||||
* @param array $value The note to display. HTML is *not* escaped; the
|
||||
* note is displayed as-is.
|
||||
*
|
||||
* @return string The element XHTML.
|
||||
*/
|
||||
public function formNote($name, $value = null)
|
||||
{
|
||||
$info = $this->_getInfo($name, $value);
|
||||
extract($info); // name, value, attribs, options, listsep, disable
|
||||
return $value;
|
||||
}
|
||||
}
|
95
library/Zend/View/Helper/FormPassword.php
Normal file
95
library/Zend/View/Helper/FormPassword.php
Normal file
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: FormPassword.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Abstract class for extension
|
||||
*/
|
||||
require_once 'Zend/View/Helper/FormElement.php';
|
||||
|
||||
|
||||
/**
|
||||
* Helper to generate a "password" element
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_FormPassword extends Zend_View_Helper_FormElement
|
||||
{
|
||||
/**
|
||||
* Generates a 'password' element.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string|array $name If a string, the element name. If an
|
||||
* array, all other parameters are ignored, and the array elements
|
||||
* are extracted in place of added parameters.
|
||||
*
|
||||
* @param mixed $value The element value.
|
||||
*
|
||||
* @param array $attribs Attributes for the element tag.
|
||||
*
|
||||
* @return string The element XHTML.
|
||||
*/
|
||||
public function formPassword($name, $value = null, $attribs = null)
|
||||
{
|
||||
$info = $this->_getInfo($name, $value, $attribs);
|
||||
extract($info); // name, value, attribs, options, listsep, disable
|
||||
|
||||
// is it disabled?
|
||||
$disabled = '';
|
||||
if ($disable) {
|
||||
// disabled
|
||||
$disabled = ' disabled="disabled"';
|
||||
}
|
||||
|
||||
// determine the XHTML value
|
||||
$valueString = ' value=""';
|
||||
if (array_key_exists('renderPassword', $attribs)) {
|
||||
if ($attribs['renderPassword']) {
|
||||
$valueString = ' value="' . $this->view->escape($value) . '"';
|
||||
}
|
||||
unset($attribs['renderPassword']);
|
||||
}
|
||||
|
||||
// XHTML or HTML end tag?
|
||||
$endTag = ' />';
|
||||
if (($this->view instanceof Zend_View_Abstract) && !$this->view->doctype()->isXhtml()) {
|
||||
$endTag= '>';
|
||||
}
|
||||
|
||||
// render the element
|
||||
$xhtml = '<input type="password"'
|
||||
. ' name="' . $this->view->escape($name) . '"'
|
||||
. ' id="' . $this->view->escape($id) . '"'
|
||||
. $valueString
|
||||
. $disabled
|
||||
. $this->_htmlAttribs($attribs)
|
||||
. $endTag;
|
||||
|
||||
return $xhtml;
|
||||
}
|
||||
|
||||
}
|
183
library/Zend/View/Helper/FormRadio.php
Normal file
183
library/Zend/View/Helper/FormRadio.php
Normal file
|
@ -0,0 +1,183 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: FormRadio.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Abstract class for extension
|
||||
*/
|
||||
require_once 'Zend/View/Helper/FormElement.php';
|
||||
|
||||
|
||||
/**
|
||||
* Helper to generate a set of radio button elements
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_FormRadio extends Zend_View_Helper_FormElement
|
||||
{
|
||||
/**
|
||||
* Input type to use
|
||||
* @var string
|
||||
*/
|
||||
protected $_inputType = 'radio';
|
||||
|
||||
/**
|
||||
* Whether or not this element represents an array collection by default
|
||||
* @var bool
|
||||
*/
|
||||
protected $_isArray = false;
|
||||
|
||||
/**
|
||||
* Generates a set of radio button elements.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string|array $name If a string, the element name. If an
|
||||
* array, all other parameters are ignored, and the array elements
|
||||
* are extracted in place of added parameters.
|
||||
*
|
||||
* @param mixed $value The radio value to mark as 'checked'.
|
||||
*
|
||||
* @param array $options An array of key-value pairs where the array
|
||||
* key is the radio value, and the array value is the radio text.
|
||||
*
|
||||
* @param array|string $attribs Attributes added to each radio.
|
||||
*
|
||||
* @return string The radio buttons XHTML.
|
||||
*/
|
||||
public function formRadio($name, $value = null, $attribs = null,
|
||||
$options = null, $listsep = "<br />\n")
|
||||
{
|
||||
|
||||
$info = $this->_getInfo($name, $value, $attribs, $options, $listsep);
|
||||
extract($info); // name, value, attribs, options, listsep, disable
|
||||
|
||||
// retrieve attributes for labels (prefixed with 'label_' or 'label')
|
||||
$label_attribs = array();
|
||||
foreach ($attribs as $key => $val) {
|
||||
$tmp = false;
|
||||
$keyLen = strlen($key);
|
||||
if ((6 < $keyLen) && (substr($key, 0, 6) == 'label_')) {
|
||||
$tmp = substr($key, 6);
|
||||
} elseif ((5 < $keyLen) && (substr($key, 0, 5) == 'label')) {
|
||||
$tmp = substr($key, 5);
|
||||
}
|
||||
|
||||
if ($tmp) {
|
||||
// make sure first char is lowercase
|
||||
$tmp[0] = strtolower($tmp[0]);
|
||||
$label_attribs[$tmp] = $val;
|
||||
unset($attribs[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
$labelPlacement = 'append';
|
||||
foreach ($label_attribs as $key => $val) {
|
||||
switch (strtolower($key)) {
|
||||
case 'placement':
|
||||
unset($label_attribs[$key]);
|
||||
$val = strtolower($val);
|
||||
if (in_array($val, array('prepend', 'append'))) {
|
||||
$labelPlacement = $val;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// the radio button values and labels
|
||||
$options = (array) $options;
|
||||
|
||||
// build the element
|
||||
$xhtml = '';
|
||||
$list = array();
|
||||
|
||||
// should the name affect an array collection?
|
||||
$name = $this->view->escape($name);
|
||||
if ($this->_isArray && ('[]' != substr($name, -2))) {
|
||||
$name .= '[]';
|
||||
}
|
||||
|
||||
// ensure value is an array to allow matching multiple times
|
||||
$value = (array) $value;
|
||||
|
||||
// XHTML or HTML end tag?
|
||||
$endTag = ' />';
|
||||
if (($this->view instanceof Zend_View_Abstract) && !$this->view->doctype()->isXhtml()) {
|
||||
$endTag= '>';
|
||||
}
|
||||
|
||||
// add radio buttons to the list.
|
||||
require_once 'Zend/Filter/Alnum.php';
|
||||
$filter = new Zend_Filter_Alnum();
|
||||
foreach ($options as $opt_value => $opt_label) {
|
||||
|
||||
// Should the label be escaped?
|
||||
if ($escape) {
|
||||
$opt_label = $this->view->escape($opt_label);
|
||||
}
|
||||
|
||||
// is it disabled?
|
||||
$disabled = '';
|
||||
if (true === $disable) {
|
||||
$disabled = ' disabled="disabled"';
|
||||
} elseif (is_array($disable) && in_array($opt_value, $disable)) {
|
||||
$disabled = ' disabled="disabled"';
|
||||
}
|
||||
|
||||
// is it checked?
|
||||
$checked = '';
|
||||
if (in_array($opt_value, $value)) {
|
||||
$checked = ' checked="checked"';
|
||||
}
|
||||
|
||||
// generate ID
|
||||
$optId = $id . '-' . $filter->filter($opt_value);
|
||||
|
||||
// Wrap the radios in labels
|
||||
$radio = '<label'
|
||||
. $this->_htmlAttribs($label_attribs) . ' for="' . $optId . '">'
|
||||
. (('prepend' == $labelPlacement) ? $opt_label : '')
|
||||
. '<input type="' . $this->_inputType . '"'
|
||||
. ' name="' . $name . '"'
|
||||
. ' id="' . $optId . '"'
|
||||
. ' value="' . $this->view->escape($opt_value) . '"'
|
||||
. $checked
|
||||
. $disabled
|
||||
. $this->_htmlAttribs($attribs)
|
||||
. $endTag
|
||||
. (('append' == $labelPlacement) ? $opt_label : '')
|
||||
. '</label>';
|
||||
|
||||
// add to the array of radio buttons
|
||||
$list[] = $radio;
|
||||
}
|
||||
|
||||
// done!
|
||||
$xhtml .= implode($listsep, $list);
|
||||
|
||||
return $xhtml;
|
||||
}
|
||||
}
|
88
library/Zend/View/Helper/FormReset.php
Normal file
88
library/Zend/View/Helper/FormReset.php
Normal file
|
@ -0,0 +1,88 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: FormReset.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Abstract class for extension
|
||||
*/
|
||||
require_once 'Zend/View/Helper/FormElement.php';
|
||||
|
||||
|
||||
/**
|
||||
* Helper to generate a "reset" button
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_FormReset extends Zend_View_Helper_FormElement
|
||||
{
|
||||
/**
|
||||
* Generates a 'reset' button.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string|array $name If a string, the element name. If an
|
||||
* array, all other parameters are ignored, and the array elements
|
||||
* are extracted in place of added parameters.
|
||||
*
|
||||
* @param mixed $value The element value.
|
||||
*
|
||||
* @param array $attribs Attributes for the element tag.
|
||||
*
|
||||
* @return string The element XHTML.
|
||||
*/
|
||||
public function formReset($name = '', $value = 'Reset', $attribs = null)
|
||||
{
|
||||
$info = $this->_getInfo($name, $value, $attribs);
|
||||
extract($info); // name, value, attribs, options, listsep, disable
|
||||
|
||||
// check if disabled
|
||||
$disabled = '';
|
||||
if ($disable) {
|
||||
$disabled = ' disabled="disabled"';
|
||||
}
|
||||
|
||||
// get closing tag
|
||||
$endTag = '>';
|
||||
if ($this->view->doctype()->isXhtml()) {
|
||||
$endTag = ' />';
|
||||
}
|
||||
|
||||
// Render button
|
||||
$xhtml = '<input type="reset"'
|
||||
. ' name="' . $this->view->escape($name) . '"'
|
||||
. ' id="' . $this->view->escape($id) . '"'
|
||||
. $disabled;
|
||||
|
||||
// add a value if one is given
|
||||
if (! empty($value)) {
|
||||
$xhtml .= ' value="' . $this->view->escape($value) . '"';
|
||||
}
|
||||
|
||||
// add attributes, close, and return
|
||||
$xhtml .= $this->_htmlAttribs($attribs) . $endTag;
|
||||
return $xhtml;
|
||||
}
|
||||
}
|
178
library/Zend/View/Helper/FormSelect.php
Normal file
178
library/Zend/View/Helper/FormSelect.php
Normal file
|
@ -0,0 +1,178 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: FormSelect.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Abstract class for extension
|
||||
*/
|
||||
require_once 'Zend/View/Helper/FormElement.php';
|
||||
|
||||
|
||||
/**
|
||||
* Helper to generate "select" list of options
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_FormSelect extends Zend_View_Helper_FormElement
|
||||
{
|
||||
/**
|
||||
* Generates 'select' list of options.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string|array $name If a string, the element name. If an
|
||||
* array, all other parameters are ignored, and the array elements
|
||||
* are extracted in place of added parameters.
|
||||
*
|
||||
* @param mixed $value The option value to mark as 'selected'; if an
|
||||
* array, will mark all values in the array as 'selected' (used for
|
||||
* multiple-select elements).
|
||||
*
|
||||
* @param array|string $attribs Attributes added to the 'select' tag.
|
||||
*
|
||||
* @param array $options An array of key-value pairs where the array
|
||||
* key is the radio value, and the array value is the radio text.
|
||||
*
|
||||
* @param string $listsep When disabled, use this list separator string
|
||||
* between list values.
|
||||
*
|
||||
* @return string The select tag and options XHTML.
|
||||
*/
|
||||
public function formSelect($name, $value = null, $attribs = null,
|
||||
$options = null, $listsep = "<br />\n")
|
||||
{
|
||||
$info = $this->_getInfo($name, $value, $attribs, $options, $listsep);
|
||||
extract($info); // name, id, value, attribs, options, listsep, disable
|
||||
|
||||
// force $value to array so we can compare multiple values to multiple
|
||||
// options; also ensure it's a string for comparison purposes.
|
||||
$value = array_map('strval', (array) $value);
|
||||
|
||||
// check if element may have multiple values
|
||||
$multiple = '';
|
||||
|
||||
if (substr($name, -2) == '[]') {
|
||||
// multiple implied by the name
|
||||
$multiple = ' multiple="multiple"';
|
||||
}
|
||||
|
||||
if (isset($attribs['multiple'])) {
|
||||
// Attribute set
|
||||
if ($attribs['multiple']) {
|
||||
// True attribute; set multiple attribute
|
||||
$multiple = ' multiple="multiple"';
|
||||
|
||||
// Make sure name indicates multiple values are allowed
|
||||
if (!empty($multiple) && (substr($name, -2) != '[]')) {
|
||||
$name .= '[]';
|
||||
}
|
||||
} else {
|
||||
// False attribute; ensure attribute not set
|
||||
$multiple = '';
|
||||
}
|
||||
unset($attribs['multiple']);
|
||||
}
|
||||
|
||||
// now start building the XHTML.
|
||||
$disabled = '';
|
||||
if (true === $disable) {
|
||||
$disabled = ' disabled="disabled"';
|
||||
}
|
||||
|
||||
// Build the surrounding select element first.
|
||||
$xhtml = '<select'
|
||||
. ' name="' . $this->view->escape($name) . '"'
|
||||
. ' id="' . $this->view->escape($id) . '"'
|
||||
. $multiple
|
||||
. $disabled
|
||||
. $this->_htmlAttribs($attribs)
|
||||
. ">\n ";
|
||||
|
||||
// build the list of options
|
||||
$list = array();
|
||||
$translator = $this->getTranslator();
|
||||
foreach ((array) $options as $opt_value => $opt_label) {
|
||||
if (is_array($opt_label)) {
|
||||
$opt_disable = '';
|
||||
if (is_array($disable) && in_array($opt_value, $disable)) {
|
||||
$opt_disable = ' disabled="disabled"';
|
||||
}
|
||||
if (null !== $translator) {
|
||||
$opt_value = $translator->translate($opt_value);
|
||||
}
|
||||
$list[] = '<optgroup'
|
||||
. $opt_disable
|
||||
. ' label="' . $this->view->escape($opt_value) .'">';
|
||||
foreach ($opt_label as $val => $lab) {
|
||||
$list[] = $this->_build($val, $lab, $value, $disable);
|
||||
}
|
||||
$list[] = '</optgroup>';
|
||||
} else {
|
||||
$list[] = $this->_build($opt_value, $opt_label, $value, $disable);
|
||||
}
|
||||
}
|
||||
|
||||
// add the options to the xhtml and close the select
|
||||
$xhtml .= implode("\n ", $list) . "\n</select>";
|
||||
|
||||
return $xhtml;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the actual <option> tag
|
||||
*
|
||||
* @param string $value Options Value
|
||||
* @param string $label Options Label
|
||||
* @param array $selected The option value(s) to mark as 'selected'
|
||||
* @param array|bool $disable Whether the select is disabled, or individual options are
|
||||
* @return string Option Tag XHTML
|
||||
*/
|
||||
protected function _build($value, $label, $selected, $disable)
|
||||
{
|
||||
if (is_bool($disable)) {
|
||||
$disable = array();
|
||||
}
|
||||
|
||||
$opt = '<option'
|
||||
. ' value="' . $this->view->escape($value) . '"'
|
||||
. ' label="' . $this->view->escape($label) . '"';
|
||||
|
||||
// selected?
|
||||
if (in_array((string) $value, $selected)) {
|
||||
$opt .= ' selected="selected"';
|
||||
}
|
||||
|
||||
// disabled?
|
||||
if (in_array($value, $disable)) {
|
||||
$opt .= ' disabled="disabled"';
|
||||
}
|
||||
|
||||
$opt .= '>' . $this->view->escape($label) . "</option>";
|
||||
|
||||
return $opt;
|
||||
}
|
||||
|
||||
}
|
84
library/Zend/View/Helper/FormSubmit.php
Normal file
84
library/Zend/View/Helper/FormSubmit.php
Normal file
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: FormSubmit.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Abstract class for extension
|
||||
*/
|
||||
require_once 'Zend/View/Helper/FormElement.php';
|
||||
|
||||
|
||||
/**
|
||||
* Helper to generate a "submit" button
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_FormSubmit extends Zend_View_Helper_FormElement
|
||||
{
|
||||
/**
|
||||
* Generates a 'submit' button.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string|array $name If a string, the element name. If an
|
||||
* array, all other parameters are ignored, and the array elements
|
||||
* are extracted in place of added parameters.
|
||||
*
|
||||
* @param mixed $value The element value.
|
||||
*
|
||||
* @param array $attribs Attributes for the element tag.
|
||||
*
|
||||
* @return string The element XHTML.
|
||||
*/
|
||||
public function formSubmit($name, $value = null, $attribs = null)
|
||||
{
|
||||
$info = $this->_getInfo($name, $value, $attribs);
|
||||
extract($info); // name, value, attribs, options, listsep, disable
|
||||
|
||||
// check if disabled
|
||||
$disabled = '';
|
||||
if ($disable) {
|
||||
$disabled = ' disabled="disabled"';
|
||||
}
|
||||
|
||||
// XHTML or HTML end tag?
|
||||
$endTag = ' />';
|
||||
if (($this->view instanceof Zend_View_Abstract) && !$this->view->doctype()->isXhtml()) {
|
||||
$endTag= '>';
|
||||
}
|
||||
|
||||
// Render the button.
|
||||
$xhtml = '<input type="submit"'
|
||||
. ' name="' . $this->view->escape($name) . '"'
|
||||
. ' id="' . $this->view->escape($id) . '"'
|
||||
. ' value="' . $this->view->escape($value) . '"'
|
||||
. $disabled
|
||||
. $this->_htmlAttribs($attribs)
|
||||
. $endTag;
|
||||
|
||||
return $xhtml;
|
||||
}
|
||||
}
|
84
library/Zend/View/Helper/FormText.php
Normal file
84
library/Zend/View/Helper/FormText.php
Normal file
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: FormText.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Abstract class for extension
|
||||
*/
|
||||
require_once 'Zend/View/Helper/FormElement.php';
|
||||
|
||||
|
||||
/**
|
||||
* Helper to generate a "text" element
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_FormText extends Zend_View_Helper_FormElement
|
||||
{
|
||||
/**
|
||||
* Generates a 'text' element.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string|array $name If a string, the element name. If an
|
||||
* array, all other parameters are ignored, and the array elements
|
||||
* are used in place of added parameters.
|
||||
*
|
||||
* @param mixed $value The element value.
|
||||
*
|
||||
* @param array $attribs Attributes for the element tag.
|
||||
*
|
||||
* @return string The element XHTML.
|
||||
*/
|
||||
public function formText($name, $value = null, $attribs = null)
|
||||
{
|
||||
$info = $this->_getInfo($name, $value, $attribs);
|
||||
extract($info); // name, value, attribs, options, listsep, disable
|
||||
|
||||
// build the element
|
||||
$disabled = '';
|
||||
if ($disable) {
|
||||
// disabled
|
||||
$disabled = ' disabled="disabled"';
|
||||
}
|
||||
|
||||
// XHTML or HTML end tag?
|
||||
$endTag = ' />';
|
||||
if (($this->view instanceof Zend_View_Abstract) && !$this->view->doctype()->isXhtml()) {
|
||||
$endTag= '>';
|
||||
}
|
||||
|
||||
$xhtml = '<input type="text"'
|
||||
. ' name="' . $this->view->escape($name) . '"'
|
||||
. ' id="' . $this->view->escape($id) . '"'
|
||||
. ' value="' . $this->view->escape($value) . '"'
|
||||
. $disabled
|
||||
. $this->_htmlAttribs($attribs)
|
||||
. $endTag;
|
||||
|
||||
return $xhtml;
|
||||
}
|
||||
}
|
104
library/Zend/View/Helper/FormTextarea.php
Normal file
104
library/Zend/View/Helper/FormTextarea.php
Normal file
|
@ -0,0 +1,104 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: FormTextarea.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Abstract class for extension
|
||||
*/
|
||||
require_once 'Zend/View/Helper/FormElement.php';
|
||||
|
||||
|
||||
/**
|
||||
* Helper to generate a "textarea" element
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_FormTextarea extends Zend_View_Helper_FormElement
|
||||
{
|
||||
/**
|
||||
* The default number of rows for a textarea.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $rows = 24;
|
||||
|
||||
/**
|
||||
* The default number of columns for a textarea.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $cols = 80;
|
||||
|
||||
/**
|
||||
* Generates a 'textarea' element.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string|array $name If a string, the element name. If an
|
||||
* array, all other parameters are ignored, and the array elements
|
||||
* are extracted in place of added parameters.
|
||||
*
|
||||
* @param mixed $value The element value.
|
||||
*
|
||||
* @param array $attribs Attributes for the element tag.
|
||||
*
|
||||
* @return string The element XHTML.
|
||||
*/
|
||||
public function formTextarea($name, $value = null, $attribs = null)
|
||||
{
|
||||
$info = $this->_getInfo($name, $value, $attribs);
|
||||
extract($info); // name, value, attribs, options, listsep, disable
|
||||
|
||||
// is it disabled?
|
||||
$disabled = '';
|
||||
if ($disable) {
|
||||
// disabled.
|
||||
$disabled = ' disabled="disabled"';
|
||||
}
|
||||
|
||||
// Make sure that there are 'rows' and 'cols' values
|
||||
// as required by the spec. noted by Orjan Persson.
|
||||
if (empty($attribs['rows'])) {
|
||||
$attribs['rows'] = (int) $this->rows;
|
||||
}
|
||||
if (empty($attribs['cols'])) {
|
||||
$attribs['cols'] = (int) $this->cols;
|
||||
}
|
||||
|
||||
// build the element
|
||||
$xhtml = '<textarea name="' . $this->view->escape($name) . '"'
|
||||
. ' id="' . $this->view->escape($id) . '"'
|
||||
. $disabled
|
||||
. $this->_htmlAttribs($attribs) . '>'
|
||||
. $this->view->escape($value) . '</textarea>';
|
||||
|
||||
return $xhtml;
|
||||
}
|
||||
}
|
437
library/Zend/View/Helper/HeadLink.php
Normal file
437
library/Zend/View/Helper/HeadLink.php
Normal file
|
@ -0,0 +1,437 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: HeadLink.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/** Zend_View_Helper_Placeholder_Container_Standalone */
|
||||
require_once 'Zend/View/Helper/Placeholder/Container/Standalone.php';
|
||||
|
||||
/**
|
||||
* Zend_Layout_View_Helper_HeadLink
|
||||
*
|
||||
* @see http://www.w3.org/TR/xhtml1/dtds.html
|
||||
* @uses Zend_View_Helper_Placeholder_Container_Standalone
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_HeadLink extends Zend_View_Helper_Placeholder_Container_Standalone
|
||||
{
|
||||
/**
|
||||
* $_validAttributes
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_itemKeys = array('charset', 'href', 'hreflang', 'media', 'rel', 'rev', 'type', 'title', 'extras');
|
||||
|
||||
/**
|
||||
* @var string registry key
|
||||
*/
|
||||
protected $_regKey = 'Zend_View_Helper_HeadLink';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Use PHP_EOL as separator
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->setSeparator(PHP_EOL);
|
||||
}
|
||||
|
||||
/**
|
||||
* headLink() - View Helper Method
|
||||
*
|
||||
* Returns current object instance. Optionally, allows passing array of
|
||||
* values to build link.
|
||||
*
|
||||
* @return Zend_View_Helper_HeadLink
|
||||
*/
|
||||
public function headLink(array $attributes = null, $placement = Zend_View_Helper_Placeholder_Container_Abstract::APPEND)
|
||||
{
|
||||
if (null !== $attributes) {
|
||||
$item = $this->createData($attributes);
|
||||
switch ($placement) {
|
||||
case Zend_View_Helper_Placeholder_Container_Abstract::SET:
|
||||
$this->set($item);
|
||||
break;
|
||||
case Zend_View_Helper_Placeholder_Container_Abstract::PREPEND:
|
||||
$this->prepend($item);
|
||||
break;
|
||||
case Zend_View_Helper_Placeholder_Container_Abstract::APPEND:
|
||||
default:
|
||||
$this->append($item);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overload method access
|
||||
*
|
||||
* Creates the following virtual methods:
|
||||
* - appendStylesheet($href, $media, $conditionalStylesheet, $extras)
|
||||
* - offsetSetStylesheet($index, $href, $media, $conditionalStylesheet, $extras)
|
||||
* - prependStylesheet($href, $media, $conditionalStylesheet, $extras)
|
||||
* - setStylesheet($href, $media, $conditionalStylesheet, $extras)
|
||||
* - appendAlternate($href, $type, $title, $extras)
|
||||
* - offsetSetAlternate($index, $href, $type, $title, $extras)
|
||||
* - prependAlternate($href, $type, $title, $extras)
|
||||
* - setAlternate($href, $type, $title, $extras)
|
||||
*
|
||||
* Items that may be added in the future:
|
||||
* - Navigation? need to find docs on this
|
||||
* - public function appendStart()
|
||||
* - public function appendContents()
|
||||
* - public function appendPrev()
|
||||
* - public function appendNext()
|
||||
* - public function appendIndex()
|
||||
* - public function appendEnd()
|
||||
* - public function appendGlossary()
|
||||
* - public function appendAppendix()
|
||||
* - public function appendHelp()
|
||||
* - public function appendBookmark()
|
||||
* - Other?
|
||||
* - public function appendCopyright()
|
||||
* - public function appendChapter()
|
||||
* - public function appendSection()
|
||||
* - public function appendSubsection()
|
||||
*
|
||||
* @param mixed $method
|
||||
* @param mixed $args
|
||||
* @return void
|
||||
*/
|
||||
public function __call($method, $args)
|
||||
{
|
||||
if (preg_match('/^(?P<action>set|(ap|pre)pend|offsetSet)(?P<type>Stylesheet|Alternate)$/', $method, $matches)) {
|
||||
$argc = count($args);
|
||||
$action = $matches['action'];
|
||||
$type = $matches['type'];
|
||||
$index = null;
|
||||
|
||||
if ('offsetSet' == $action) {
|
||||
if (0 < $argc) {
|
||||
$index = array_shift($args);
|
||||
--$argc;
|
||||
}
|
||||
}
|
||||
|
||||
if (1 > $argc) {
|
||||
require_once 'Zend/View/Exception.php';
|
||||
$e = new Zend_View_Exception(sprintf('%s requires at least one argument', $method));
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
if (is_array($args[0])) {
|
||||
$item = $this->createData($args[0]);
|
||||
} else {
|
||||
$dataMethod = 'createData' . $type;
|
||||
$item = $this->$dataMethod($args);
|
||||
}
|
||||
|
||||
if ($item) {
|
||||
if ('offsetSet' == $action) {
|
||||
$this->offsetSet($index, $item);
|
||||
} else {
|
||||
$this->$action($item);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
return parent::__call($method, $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if value is valid
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return boolean
|
||||
*/
|
||||
protected function _isValid($value)
|
||||
{
|
||||
if (!$value instanceof stdClass) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$vars = get_object_vars($value);
|
||||
$keys = array_keys($vars);
|
||||
$intersection = array_intersect($this->_itemKeys, $keys);
|
||||
if (empty($intersection)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* append()
|
||||
*
|
||||
* @param array $value
|
||||
* @return void
|
||||
*/
|
||||
public function append($value)
|
||||
{
|
||||
if (!$this->_isValid($value)) {
|
||||
require_once 'Zend/View/Exception.php';
|
||||
$e = new Zend_View_Exception('append() expects a data token; please use one of the custom append*() methods');
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return $this->getContainer()->append($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* offsetSet()
|
||||
*
|
||||
* @param string|int $index
|
||||
* @param array $value
|
||||
* @return void
|
||||
*/
|
||||
public function offsetSet($index, $value)
|
||||
{
|
||||
if (!$this->_isValid($value)) {
|
||||
require_once 'Zend/View/Exception.php';
|
||||
$e = new Zend_View_Exception('offsetSet() expects a data token; please use one of the custom offsetSet*() methods');
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return $this->getContainer()->offsetSet($index, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* prepend()
|
||||
*
|
||||
* @param array $value
|
||||
* @return Zend_Layout_ViewHelper_HeadLink
|
||||
*/
|
||||
public function prepend($value)
|
||||
{
|
||||
if (!$this->_isValid($value)) {
|
||||
require_once 'Zend/View/Exception.php';
|
||||
$e = new Zend_View_Exception('prepend() expects a data token; please use one of the custom prepend*() methods');
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return $this->getContainer()->prepend($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* set()
|
||||
*
|
||||
* @param array $value
|
||||
* @return Zend_Layout_ViewHelper_HeadLink
|
||||
*/
|
||||
public function set($value)
|
||||
{
|
||||
if (!$this->_isValid($value)) {
|
||||
require_once 'Zend/View/Exception.php';
|
||||
$e = new Zend_View_Exception('set() expects a data token; please use one of the custom set*() methods');
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return $this->getContainer()->set($value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create HTML link element from data item
|
||||
*
|
||||
* @param stdClass $item
|
||||
* @return string
|
||||
*/
|
||||
public function itemToString(stdClass $item)
|
||||
{
|
||||
$attributes = (array) $item;
|
||||
$link = '<link ';
|
||||
|
||||
foreach ($this->_itemKeys as $itemKey) {
|
||||
if (isset($attributes[$itemKey])) {
|
||||
if(is_array($attributes[$itemKey])) {
|
||||
foreach($attributes[$itemKey] as $key => $value) {
|
||||
$link .= sprintf('%s="%s" ', $key, ($this->_autoEscape) ? $this->_escape($value) : $value);
|
||||
}
|
||||
} else {
|
||||
$link .= sprintf('%s="%s" ', $itemKey, ($this->_autoEscape) ? $this->_escape($attributes[$itemKey]) : $attributes[$itemKey]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->view instanceof Zend_View_Abstract) {
|
||||
$link .= ($this->view->doctype()->isXhtml()) ? '/>' : '>';
|
||||
} else {
|
||||
$link .= '/>';
|
||||
}
|
||||
|
||||
if (($link == '<link />') || ($link == '<link >')) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (isset($attributes['conditionalStylesheet'])
|
||||
&& !empty($attributes['conditionalStylesheet'])
|
||||
&& is_string($attributes['conditionalStylesheet']))
|
||||
{
|
||||
$link = '<!--[if ' . $attributes['conditionalStylesheet'] . ']> ' . $link . '<![endif]-->';
|
||||
}
|
||||
|
||||
return $link;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render link elements as string
|
||||
*
|
||||
* @param string|int $indent
|
||||
* @return string
|
||||
*/
|
||||
public function toString($indent = null)
|
||||
{
|
||||
$indent = (null !== $indent)
|
||||
? $this->getWhitespace($indent)
|
||||
: $this->getIndent();
|
||||
|
||||
$items = array();
|
||||
$this->getContainer()->ksort();
|
||||
foreach ($this as $item) {
|
||||
$items[] = $this->itemToString($item);
|
||||
}
|
||||
|
||||
return $indent . implode($this->_escape($this->getSeparator()) . $indent, $items);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create data item for stack
|
||||
*
|
||||
* @param array $attributes
|
||||
* @return stdClass
|
||||
*/
|
||||
public function createData(array $attributes)
|
||||
{
|
||||
$data = (object) $attributes;
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create item for stylesheet link item
|
||||
*
|
||||
* @param array $args
|
||||
* @return stdClass|false Returns fals if stylesheet is a duplicate
|
||||
*/
|
||||
public function createDataStylesheet(array $args)
|
||||
{
|
||||
$rel = 'stylesheet';
|
||||
$type = 'text/css';
|
||||
$media = 'screen';
|
||||
$conditionalStylesheet = false;
|
||||
$href = array_shift($args);
|
||||
|
||||
if ($this->_isDuplicateStylesheet($href)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (0 < count($args)) {
|
||||
$media = array_shift($args);
|
||||
if(is_array($media)) {
|
||||
$media = implode(',', $media);
|
||||
} else {
|
||||
$media = (string) $media;
|
||||
}
|
||||
}
|
||||
if (0 < count($args)) {
|
||||
$conditionalStylesheet = array_shift($args);
|
||||
if(!empty($conditionalStylesheet) && is_string($conditionalStylesheet)) {
|
||||
$conditionalStylesheet = (string) $conditionalStylesheet;
|
||||
} else {
|
||||
$conditionalStylesheet = null;
|
||||
}
|
||||
}
|
||||
|
||||
if(0 < count($args) && is_array($args[0])) {
|
||||
$extras = array_shift($args);
|
||||
$extras = (array) $extras;
|
||||
}
|
||||
|
||||
$attributes = compact('rel', 'type', 'href', 'media', 'conditionalStylesheet', 'extras');
|
||||
return $this->createData($attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the linked stylesheet a duplicate?
|
||||
*
|
||||
* @param string $uri
|
||||
* @return bool
|
||||
*/
|
||||
protected function _isDuplicateStylesheet($uri)
|
||||
{
|
||||
foreach ($this->getContainer() as $item) {
|
||||
if (($item->rel == 'stylesheet') && ($item->href == $uri)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create item for alternate link item
|
||||
*
|
||||
* @param array $args
|
||||
* @return stdClass
|
||||
*/
|
||||
public function createDataAlternate(array $args)
|
||||
{
|
||||
if (3 > count($args)) {
|
||||
require_once 'Zend/View/Exception.php';
|
||||
$e = new Zend_View_Exception(sprintf('Alternate tags require 3 arguments; %s provided', count($args)));
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$rel = 'alternate';
|
||||
$href = array_shift($args);
|
||||
$type = array_shift($args);
|
||||
$title = array_shift($args);
|
||||
|
||||
if(0 < count($args) && is_array($args[0])) {
|
||||
$extras = array_shift($args);
|
||||
$extras = (array) $extras;
|
||||
|
||||
if(isset($extras['media']) && is_array($extras['media'])) {
|
||||
$extras['media'] = implode(',', $extras['media']);
|
||||
}
|
||||
}
|
||||
|
||||
$href = (string) $href;
|
||||
$type = (string) $type;
|
||||
$title = (string) $title;
|
||||
|
||||
$attributes = compact('rel', 'href', 'type', 'title', 'extras');
|
||||
return $this->createData($attributes);
|
||||
}
|
||||
}
|
412
library/Zend/View/Helper/HeadMeta.php
Normal file
412
library/Zend/View/Helper/HeadMeta.php
Normal file
|
@ -0,0 +1,412 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: HeadMeta.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/** Zend_View_Helper_Placeholder_Container_Standalone */
|
||||
require_once 'Zend/View/Helper/Placeholder/Container/Standalone.php';
|
||||
|
||||
/**
|
||||
* Zend_Layout_View_Helper_HeadMeta
|
||||
*
|
||||
* @see http://www.w3.org/TR/xhtml1/dtds.html
|
||||
* @uses Zend_View_Helper_Placeholder_Container_Standalone
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_HeadMeta extends Zend_View_Helper_Placeholder_Container_Standalone
|
||||
{
|
||||
/**
|
||||
* Types of attributes
|
||||
* @var array
|
||||
*/
|
||||
protected $_typeKeys = array('name', 'http-equiv', 'charset');
|
||||
protected $_requiredKeys = array('content');
|
||||
protected $_modifierKeys = array('lang', 'scheme');
|
||||
|
||||
/**
|
||||
* @var string registry key
|
||||
*/
|
||||
protected $_regKey = 'Zend_View_Helper_HeadMeta';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Set separator to PHP_EOL
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->setSeparator(PHP_EOL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve object instance; optionally add meta tag
|
||||
*
|
||||
* @param string $content
|
||||
* @param string $keyValue
|
||||
* @param string $keyType
|
||||
* @param array $modifiers
|
||||
* @param string $placement
|
||||
* @return Zend_View_Helper_HeadMeta
|
||||
*/
|
||||
public function headMeta($content = null, $keyValue = null, $keyType = 'name', $modifiers = array(), $placement = Zend_View_Helper_Placeholder_Container_Abstract::APPEND)
|
||||
{
|
||||
if ((null !== $content) && (null !== $keyValue)) {
|
||||
$item = $this->createData($keyType, $keyValue, $content, $modifiers);
|
||||
$action = strtolower($placement);
|
||||
switch ($action) {
|
||||
case 'append':
|
||||
case 'prepend':
|
||||
case 'set':
|
||||
$this->$action($item);
|
||||
break;
|
||||
default:
|
||||
$this->append($item);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _normalizeType($type)
|
||||
{
|
||||
switch ($type) {
|
||||
case 'Name':
|
||||
return 'name';
|
||||
case 'HttpEquiv':
|
||||
return 'http-equiv';
|
||||
default:
|
||||
require_once 'Zend/View/Exception.php';
|
||||
$e = new Zend_View_Exception(sprintf('Invalid type "%s" passed to _normalizeType', $type));
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Overload method access
|
||||
*
|
||||
* Allows the following 'virtual' methods:
|
||||
* - appendName($keyValue, $content, $modifiers = array())
|
||||
* - offsetGetName($index, $keyValue, $content, $modifers = array())
|
||||
* - prependName($keyValue, $content, $modifiers = array())
|
||||
* - setName($keyValue, $content, $modifiers = array())
|
||||
* - appendHttpEquiv($keyValue, $content, $modifiers = array())
|
||||
* - offsetGetHttpEquiv($index, $keyValue, $content, $modifers = array())
|
||||
* - prependHttpEquiv($keyValue, $content, $modifiers = array())
|
||||
* - setHttpEquiv($keyValue, $content, $modifiers = array())
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $args
|
||||
* @return Zend_View_Helper_HeadMeta
|
||||
*/
|
||||
public function __call($method, $args)
|
||||
{
|
||||
if (preg_match('/^(?P<action>set|(pre|ap)pend|offsetSet)(?P<type>Name|HttpEquiv)$/', $method, $matches)) {
|
||||
$action = $matches['action'];
|
||||
$type = $this->_normalizeType($matches['type']);
|
||||
$argc = count($args);
|
||||
$index = null;
|
||||
|
||||
if ('offsetSet' == $action) {
|
||||
if (0 < $argc) {
|
||||
$index = array_shift($args);
|
||||
--$argc;
|
||||
}
|
||||
}
|
||||
|
||||
if (2 > $argc) {
|
||||
require_once 'Zend/View/Exception.php';
|
||||
$e = new Zend_View_Exception('Too few arguments provided; requires key value, and content');
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
if (3 > $argc) {
|
||||
$args[] = array();
|
||||
}
|
||||
|
||||
$item = $this->createData($type, $args[0], $args[1], $args[2]);
|
||||
|
||||
if ('offsetSet' == $action) {
|
||||
return $this->offsetSet($index, $item);
|
||||
}
|
||||
|
||||
$this->$action($item);
|
||||
return $this;
|
||||
}
|
||||
|
||||
return parent::__call($method, $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an HTML5-style meta charset tag. Something like <meta charset="utf-8">
|
||||
*
|
||||
* Not valid in a non-HTML5 doctype
|
||||
*
|
||||
* @param string $charset
|
||||
* @return Zend_View_Helper_HeadMeta Provides a fluent interface
|
||||
*/
|
||||
public function setCharset($charset)
|
||||
{
|
||||
$item = new stdClass;
|
||||
$item->type = 'charset';
|
||||
$item->charset = $charset;
|
||||
$item->content = null;
|
||||
$item->modifiers = array();
|
||||
$this->set($item);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if item is valid
|
||||
*
|
||||
* @param mixed $item
|
||||
* @return boolean
|
||||
*/
|
||||
protected function _isValid($item)
|
||||
{
|
||||
if ((!$item instanceof stdClass)
|
||||
|| !isset($item->type)
|
||||
|| !isset($item->modifiers))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isset($item->content)
|
||||
&& (! $this->view->doctype()->isHtml5()
|
||||
|| (! $this->view->doctype()->isHtml5() && $item->type !== 'charset'))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append
|
||||
*
|
||||
* @param string $value
|
||||
* @return void
|
||||
* @throws Zend_View_Exception
|
||||
*/
|
||||
public function append($value)
|
||||
{
|
||||
if (!$this->_isValid($value)) {
|
||||
require_once 'Zend/View/Exception.php';
|
||||
$e = new Zend_View_Exception('Invalid value passed to append; please use appendMeta()');
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return $this->getContainer()->append($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* OffsetSet
|
||||
*
|
||||
* @param string|int $index
|
||||
* @param string $value
|
||||
* @return void
|
||||
* @throws Zend_View_Exception
|
||||
*/
|
||||
public function offsetSet($index, $value)
|
||||
{
|
||||
if (!$this->_isValid($value)) {
|
||||
require_once 'Zend/View/Exception.php';
|
||||
$e = new Zend_View_Exception('Invalid value passed to offsetSet; please use offsetSetName() or offsetSetHttpEquiv()');
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return $this->getContainer()->offsetSet($index, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* OffsetUnset
|
||||
*
|
||||
* @param string|int $index
|
||||
* @return void
|
||||
* @throws Zend_View_Exception
|
||||
*/
|
||||
public function offsetUnset($index)
|
||||
{
|
||||
if (!in_array($index, $this->getContainer()->getKeys())) {
|
||||
require_once 'Zend/View/Exception.php';
|
||||
$e = new Zend_View_Exception('Invalid index passed to offsetUnset()');
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return $this->getContainer()->offsetUnset($index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepend
|
||||
*
|
||||
* @param string $value
|
||||
* @return void
|
||||
* @throws Zend_View_Exception
|
||||
*/
|
||||
public function prepend($value)
|
||||
{
|
||||
if (!$this->_isValid($value)) {
|
||||
require_once 'Zend/View/Exception.php';
|
||||
$e = new Zend_View_Exception('Invalid value passed to prepend; please use prependMeta()');
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return $this->getContainer()->prepend($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set
|
||||
*
|
||||
* @param string $value
|
||||
* @return void
|
||||
* @throws Zend_View_Exception
|
||||
*/
|
||||
public function set($value)
|
||||
{
|
||||
if (!$this->_isValid($value)) {
|
||||
require_once 'Zend/View/Exception.php';
|
||||
$e = new Zend_View_Exception('Invalid value passed to set; please use setMeta()');
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$container = $this->getContainer();
|
||||
foreach ($container->getArrayCopy() as $index => $item) {
|
||||
if ($item->type == $value->type && $item->{$item->type} == $value->{$value->type}) {
|
||||
$this->offsetUnset($index);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->append($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build meta HTML string
|
||||
*
|
||||
* @param string $type
|
||||
* @param string $typeValue
|
||||
* @param string $content
|
||||
* @param array $modifiers
|
||||
* @return string
|
||||
*/
|
||||
public function itemToString(stdClass $item)
|
||||
{
|
||||
if (!in_array($item->type, $this->_typeKeys)) {
|
||||
require_once 'Zend/View/Exception.php';
|
||||
$e = new Zend_View_Exception(sprintf('Invalid type "%s" provided for meta', $item->type));
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
$type = $item->type;
|
||||
|
||||
$modifiersString = '';
|
||||
foreach ($item->modifiers as $key => $value) {
|
||||
if ($this->view->doctype()->isHtml5()
|
||||
&& $key == 'scheme') {
|
||||
require_once 'Zend/View/Exception.php';
|
||||
throw new Zend_View_Exception('Invalid modifier '
|
||||
. '"scheme" provided; not supported by HTML5');
|
||||
}
|
||||
if (!in_array($key, $this->_modifierKeys)) {
|
||||
continue;
|
||||
}
|
||||
$modifiersString .= $key . '="' . $this->_escape($value) . '" ';
|
||||
}
|
||||
|
||||
if ($this->view instanceof Zend_View_Abstract) {
|
||||
if ($this->view->doctype()->isHtml5()
|
||||
&& $type == 'charset') {
|
||||
$tpl = ($this->view->doctype()->isXhtml())
|
||||
? '<meta %s="%s"/>'
|
||||
: '<meta %s="%s">';
|
||||
} elseif ($this->view->doctype()->isXhtml()) {
|
||||
$tpl = '<meta %s="%s" content="%s" %s/>';
|
||||
} else {
|
||||
$tpl = '<meta %s="%s" content="%s" %s>';
|
||||
}
|
||||
} else {
|
||||
$tpl = '<meta %s="%s" content="%s" %s/>';
|
||||
}
|
||||
|
||||
$meta = sprintf(
|
||||
$tpl,
|
||||
$type,
|
||||
$this->_escape($item->$type),
|
||||
$this->_escape($item->content),
|
||||
$modifiersString
|
||||
);
|
||||
return $meta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render placeholder as string
|
||||
*
|
||||
* @param string|int $indent
|
||||
* @return string
|
||||
*/
|
||||
public function toString($indent = null)
|
||||
{
|
||||
$indent = (null !== $indent)
|
||||
? $this->getWhitespace($indent)
|
||||
: $this->getIndent();
|
||||
|
||||
$items = array();
|
||||
$this->getContainer()->ksort();
|
||||
try {
|
||||
foreach ($this as $item) {
|
||||
$items[] = $this->itemToString($item);
|
||||
}
|
||||
} catch (Zend_View_Exception $e) {
|
||||
trigger_error($e->getMessage(), E_USER_WARNING);
|
||||
return '';
|
||||
}
|
||||
return $indent . implode($this->_escape($this->getSeparator()) . $indent, $items);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create data item for inserting into stack
|
||||
*
|
||||
* @param string $type
|
||||
* @param string $typeValue
|
||||
* @param string $content
|
||||
* @param array $modifiers
|
||||
* @return stdClass
|
||||
*/
|
||||
public function createData($type, $typeValue, $content, array $modifiers)
|
||||
{
|
||||
$data = new stdClass;
|
||||
$data->type = $type;
|
||||
$data->$type = $typeValue;
|
||||
$data->content = $content;
|
||||
$data->modifiers = $modifiers;
|
||||
return $data;
|
||||
}
|
||||
}
|
495
library/Zend/View/Helper/HeadScript.php
Normal file
495
library/Zend/View/Helper/HeadScript.php
Normal file
|
@ -0,0 +1,495 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: HeadScript.php 20364 2010-01-17 23:00:14Z mabe $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/** Zend_View_Helper_Placeholder_Container_Standalone */
|
||||
require_once 'Zend/View/Helper/Placeholder/Container/Standalone.php';
|
||||
|
||||
/**
|
||||
* Helper for setting and retrieving script elements for HTML head section
|
||||
*
|
||||
* @uses Zend_View_Helper_Placeholder_Container_Standalone
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_HeadScript extends Zend_View_Helper_Placeholder_Container_Standalone
|
||||
{
|
||||
/**#@+
|
||||
* Script type contants
|
||||
* @const string
|
||||
*/
|
||||
const FILE = 'FILE';
|
||||
const SCRIPT = 'SCRIPT';
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
* Registry key for placeholder
|
||||
* @var string
|
||||
*/
|
||||
protected $_regKey = 'Zend_View_Helper_HeadScript';
|
||||
|
||||
/**
|
||||
* Are arbitrary attributes allowed?
|
||||
* @var bool
|
||||
*/
|
||||
protected $_arbitraryAttributes = false;
|
||||
|
||||
/**#@+
|
||||
* Capture type and/or attributes (used for hinting during capture)
|
||||
* @var string
|
||||
*/
|
||||
protected $_captureLock;
|
||||
protected $_captureScriptType = null;
|
||||
protected $_captureScriptAttrs = null;
|
||||
protected $_captureType;
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
* Optional allowed attributes for script tag
|
||||
* @var array
|
||||
*/
|
||||
protected $_optionalAttributes = array(
|
||||
'charset', 'defer', 'language', 'src'
|
||||
);
|
||||
|
||||
/**
|
||||
* Required attributes for script tag
|
||||
* @var string
|
||||
*/
|
||||
protected $_requiredAttributes = array('type');
|
||||
|
||||
/**
|
||||
* Whether or not to format scripts using CDATA; used only if doctype
|
||||
* helper is not accessible
|
||||
* @var bool
|
||||
*/
|
||||
public $useCdata = false;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Set separator to PHP_EOL.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->setSeparator(PHP_EOL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return headScript object
|
||||
*
|
||||
* Returns headScript helper object; optionally, allows specifying a script
|
||||
* or script file to include.
|
||||
*
|
||||
* @param string $mode Script or file
|
||||
* @param string $spec Script/url
|
||||
* @param string $placement Append, prepend, or set
|
||||
* @param array $attrs Array of script attributes
|
||||
* @param string $type Script type and/or array of script attributes
|
||||
* @return Zend_View_Helper_HeadScript
|
||||
*/
|
||||
public function headScript($mode = Zend_View_Helper_HeadScript::FILE, $spec = null, $placement = 'APPEND', array $attrs = array(), $type = 'text/javascript')
|
||||
{
|
||||
if ((null !== $spec) && is_string($spec)) {
|
||||
$action = ucfirst(strtolower($mode));
|
||||
$placement = strtolower($placement);
|
||||
switch ($placement) {
|
||||
case 'set':
|
||||
case 'prepend':
|
||||
case 'append':
|
||||
$action = $placement . $action;
|
||||
break;
|
||||
default:
|
||||
$action = 'append' . $action;
|
||||
break;
|
||||
}
|
||||
$this->$action($spec, $type, $attrs);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start capture action
|
||||
*
|
||||
* @param mixed $captureType
|
||||
* @param string $typeOrAttrs
|
||||
* @return void
|
||||
*/
|
||||
public function captureStart($captureType = Zend_View_Helper_Placeholder_Container_Abstract::APPEND, $type = 'text/javascript', $attrs = array())
|
||||
{
|
||||
if ($this->_captureLock) {
|
||||
require_once 'Zend/View/Helper/Placeholder/Container/Exception.php';
|
||||
$e = new Zend_View_Helper_Placeholder_Container_Exception('Cannot nest headScript captures');
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$this->_captureLock = true;
|
||||
$this->_captureType = $captureType;
|
||||
$this->_captureScriptType = $type;
|
||||
$this->_captureScriptAttrs = $attrs;
|
||||
ob_start();
|
||||
}
|
||||
|
||||
/**
|
||||
* End capture action and store
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function captureEnd()
|
||||
{
|
||||
$content = ob_get_clean();
|
||||
$type = $this->_captureScriptType;
|
||||
$attrs = $this->_captureScriptAttrs;
|
||||
$this->_captureScriptType = null;
|
||||
$this->_captureScriptAttrs = null;
|
||||
$this->_captureLock = false;
|
||||
|
||||
switch ($this->_captureType) {
|
||||
case Zend_View_Helper_Placeholder_Container_Abstract::SET:
|
||||
case Zend_View_Helper_Placeholder_Container_Abstract::PREPEND:
|
||||
case Zend_View_Helper_Placeholder_Container_Abstract::APPEND:
|
||||
$action = strtolower($this->_captureType) . 'Script';
|
||||
break;
|
||||
default:
|
||||
$action = 'appendScript';
|
||||
break;
|
||||
}
|
||||
$this->$action($content, $type, $attrs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Overload method access
|
||||
*
|
||||
* Allows the following method calls:
|
||||
* - appendFile($src, $type = 'text/javascript', $attrs = array())
|
||||
* - offsetSetFile($index, $src, $type = 'text/javascript', $attrs = array())
|
||||
* - prependFile($src, $type = 'text/javascript', $attrs = array())
|
||||
* - setFile($src, $type = 'text/javascript', $attrs = array())
|
||||
* - appendScript($script, $type = 'text/javascript', $attrs = array())
|
||||
* - offsetSetScript($index, $src, $type = 'text/javascript', $attrs = array())
|
||||
* - prependScript($script, $type = 'text/javascript', $attrs = array())
|
||||
* - setScript($script, $type = 'text/javascript', $attrs = array())
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $args
|
||||
* @return Zend_View_Helper_HeadScript
|
||||
* @throws Zend_View_Exception if too few arguments or invalid method
|
||||
*/
|
||||
public function __call($method, $args)
|
||||
{
|
||||
if (preg_match('/^(?P<action>set|(ap|pre)pend|offsetSet)(?P<mode>File|Script)$/', $method, $matches)) {
|
||||
if (1 > count($args)) {
|
||||
require_once 'Zend/View/Exception.php';
|
||||
$e = new Zend_View_Exception(sprintf('Method "%s" requires at least one argument', $method));
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$action = $matches['action'];
|
||||
$mode = strtolower($matches['mode']);
|
||||
$type = 'text/javascript';
|
||||
$attrs = array();
|
||||
|
||||
if ('offsetSet' == $action) {
|
||||
$index = array_shift($args);
|
||||
if (1 > count($args)) {
|
||||
require_once 'Zend/View/Exception.php';
|
||||
$e = new Zend_View_Exception(sprintf('Method "%s" requires at least two arguments, an index and source', $method));
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
$content = $args[0];
|
||||
|
||||
if (isset($args[1])) {
|
||||
$type = (string) $args[1];
|
||||
}
|
||||
if (isset($args[2])) {
|
||||
$attrs = (array) $args[2];
|
||||
}
|
||||
|
||||
switch ($mode) {
|
||||
case 'script':
|
||||
$item = $this->createData($type, $attrs, $content);
|
||||
if ('offsetSet' == $action) {
|
||||
$this->offsetSet($index, $item);
|
||||
} else {
|
||||
$this->$action($item);
|
||||
}
|
||||
break;
|
||||
case 'file':
|
||||
default:
|
||||
if (!$this->_isDuplicate($content)) {
|
||||
$attrs['src'] = $content;
|
||||
$item = $this->createData($type, $attrs);
|
||||
if ('offsetSet' == $action) {
|
||||
$this->offsetSet($index, $item);
|
||||
} else {
|
||||
$this->$action($item);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
return parent::__call($method, $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the file specified a duplicate?
|
||||
*
|
||||
* @param string $file
|
||||
* @return bool
|
||||
*/
|
||||
protected function _isDuplicate($file)
|
||||
{
|
||||
foreach ($this->getContainer() as $item) {
|
||||
if (($item->source === null)
|
||||
&& array_key_exists('src', $item->attributes)
|
||||
&& ($file == $item->attributes['src']))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the script provided valid?
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param string $method
|
||||
* @return bool
|
||||
*/
|
||||
protected function _isValid($value)
|
||||
{
|
||||
if ((!$value instanceof stdClass)
|
||||
|| !isset($value->type)
|
||||
|| (!isset($value->source) && !isset($value->attributes)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override append
|
||||
*
|
||||
* @param string $value
|
||||
* @return void
|
||||
*/
|
||||
public function append($value)
|
||||
{
|
||||
if (!$this->_isValid($value)) {
|
||||
require_once 'Zend/View/Exception.php';
|
||||
$e = new Zend_View_Exception('Invalid argument passed to append(); please use one of the helper methods, appendScript() or appendFile()');
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return $this->getContainer()->append($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override prepend
|
||||
*
|
||||
* @param string $value
|
||||
* @return void
|
||||
*/
|
||||
public function prepend($value)
|
||||
{
|
||||
if (!$this->_isValid($value)) {
|
||||
require_once 'Zend/View/Exception.php';
|
||||
$e = new Zend_View_Exception('Invalid argument passed to prepend(); please use one of the helper methods, prependScript() or prependFile()');
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return $this->getContainer()->prepend($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override set
|
||||
*
|
||||
* @param string $value
|
||||
* @return void
|
||||
*/
|
||||
public function set($value)
|
||||
{
|
||||
if (!$this->_isValid($value)) {
|
||||
require_once 'Zend/View/Exception.php';
|
||||
$e = new Zend_View_Exception('Invalid argument passed to set(); please use one of the helper methods, setScript() or setFile()');
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return $this->getContainer()->set($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override offsetSet
|
||||
*
|
||||
* @param string|int $index
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function offsetSet($index, $value)
|
||||
{
|
||||
if (!$this->_isValid($value)) {
|
||||
require_once 'Zend/View/Exception.php';
|
||||
$e = new Zend_View_Exception('Invalid argument passed to offsetSet(); please use one of the helper methods, offsetSetScript() or offsetSetFile()');
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$this->_isValid($value);
|
||||
return $this->getContainer()->offsetSet($index, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set flag indicating if arbitrary attributes are allowed
|
||||
*
|
||||
* @param bool $flag
|
||||
* @return Zend_View_Helper_HeadScript
|
||||
*/
|
||||
public function setAllowArbitraryAttributes($flag)
|
||||
{
|
||||
$this->_arbitraryAttributes = (bool) $flag;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Are arbitrary attributes allowed?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function arbitraryAttributesAllowed()
|
||||
{
|
||||
return $this->_arbitraryAttributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create script HTML
|
||||
*
|
||||
* @param string $type
|
||||
* @param array $attributes
|
||||
* @param string $content
|
||||
* @param string|int $indent
|
||||
* @return string
|
||||
*/
|
||||
public function itemToString($item, $indent, $escapeStart, $escapeEnd)
|
||||
{
|
||||
$attrString = '';
|
||||
if (!empty($item->attributes)) {
|
||||
foreach ($item->attributes as $key => $value) {
|
||||
if (!$this->arbitraryAttributesAllowed()
|
||||
&& !in_array($key, $this->_optionalAttributes))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if ('defer' == $key) {
|
||||
$value = 'defer';
|
||||
}
|
||||
$attrString .= sprintf(' %s="%s"', $key, ($this->_autoEscape) ? $this->_escape($value) : $value);
|
||||
}
|
||||
}
|
||||
|
||||
$type = ($this->_autoEscape) ? $this->_escape($item->type) : $item->type;
|
||||
$html = '<script type="' . $type . '"' . $attrString . '>';
|
||||
if (!empty($item->source)) {
|
||||
$html .= PHP_EOL . $indent . ' ' . $escapeStart . PHP_EOL . $item->source . $indent . ' ' . $escapeEnd . PHP_EOL . $indent;
|
||||
}
|
||||
$html .= '</script>';
|
||||
|
||||
if (isset($item->attributes['conditional'])
|
||||
&& !empty($item->attributes['conditional'])
|
||||
&& is_string($item->attributes['conditional']))
|
||||
{
|
||||
$html = $indent . '<!--[if ' . $item->attributes['conditional'] . ']> ' . $html . '<![endif]-->';
|
||||
} else {
|
||||
$html = $indent . $html;
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve string representation
|
||||
*
|
||||
* @param string|int $indent
|
||||
* @return string
|
||||
*/
|
||||
public function toString($indent = null)
|
||||
{
|
||||
$indent = (null !== $indent)
|
||||
? $this->getWhitespace($indent)
|
||||
: $this->getIndent();
|
||||
|
||||
if ($this->view) {
|
||||
$useCdata = $this->view->doctype()->isXhtml() ? true : false;
|
||||
} else {
|
||||
$useCdata = $this->useCdata ? true : false;
|
||||
}
|
||||
$escapeStart = ($useCdata) ? '//<![CDATA[' : '//<!--';
|
||||
$escapeEnd = ($useCdata) ? '//]]>' : '//-->';
|
||||
|
||||
$items = array();
|
||||
$this->getContainer()->ksort();
|
||||
foreach ($this as $item) {
|
||||
if (!$this->_isValid($item)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$items[] = $this->itemToString($item, $indent, $escapeStart, $escapeEnd);
|
||||
}
|
||||
|
||||
$return = implode($this->getSeparator(), $items);
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create data item containing all necessary components of script
|
||||
*
|
||||
* @param string $type
|
||||
* @param array $attributes
|
||||
* @param string $content
|
||||
* @return stdClass
|
||||
*/
|
||||
public function createData($type, array $attributes, $content = null)
|
||||
{
|
||||
$data = new stdClass();
|
||||
$data->type = $type;
|
||||
$data->attributes = $attributes;
|
||||
$data->source = $content;
|
||||
return $data;
|
||||
}
|
||||
}
|
419
library/Zend/View/Helper/HeadStyle.php
Normal file
419
library/Zend/View/Helper/HeadStyle.php
Normal file
|
@ -0,0 +1,419 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: HeadStyle.php 20104 2010-01-06 21:26:01Z matthew $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/** Zend_View_Helper_Placeholder_Container_Standalone */
|
||||
require_once 'Zend/View/Helper/Placeholder/Container/Standalone.php';
|
||||
|
||||
/**
|
||||
* Helper for setting and retrieving stylesheets
|
||||
*
|
||||
* @uses Zend_View_Helper_Placeholder_Container_Standalone
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_HeadStyle extends Zend_View_Helper_Placeholder_Container_Standalone
|
||||
{
|
||||
/**
|
||||
* Registry key for placeholder
|
||||
* @var string
|
||||
*/
|
||||
protected $_regKey = 'Zend_View_Helper_HeadStyle';
|
||||
|
||||
/**
|
||||
* Allowed optional attributes
|
||||
* @var array
|
||||
*/
|
||||
protected $_optionalAttributes = array('lang', 'title', 'media', 'dir');
|
||||
|
||||
/**
|
||||
* Allowed media types
|
||||
* @var array
|
||||
*/
|
||||
protected $_mediaTypes = array(
|
||||
'all', 'aural', 'braille', 'handheld', 'print',
|
||||
'projection', 'screen', 'tty', 'tv'
|
||||
);
|
||||
|
||||
/**
|
||||
* Capture type and/or attributes (used for hinting during capture)
|
||||
* @var string
|
||||
*/
|
||||
protected $_captureAttrs = null;
|
||||
|
||||
/**
|
||||
* Capture lock
|
||||
* @var bool
|
||||
*/
|
||||
protected $_captureLock;
|
||||
|
||||
/**
|
||||
* Capture type (append, prepend, set)
|
||||
* @var string
|
||||
*/
|
||||
protected $_captureType;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Set separator to PHP_EOL.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->setSeparator(PHP_EOL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return headStyle object
|
||||
*
|
||||
* Returns headStyle helper object; optionally, allows specifying
|
||||
*
|
||||
* @param string $content Stylesheet contents
|
||||
* @param string $placement Append, prepend, or set
|
||||
* @param string|array $attributes Optional attributes to utilize
|
||||
* @return Zend_View_Helper_HeadStyle
|
||||
*/
|
||||
public function headStyle($content = null, $placement = 'APPEND', $attributes = array())
|
||||
{
|
||||
if ((null !== $content) && is_string($content)) {
|
||||
switch (strtoupper($placement)) {
|
||||
case 'SET':
|
||||
$action = 'setStyle';
|
||||
break;
|
||||
case 'PREPEND':
|
||||
$action = 'prependStyle';
|
||||
break;
|
||||
case 'APPEND':
|
||||
default:
|
||||
$action = 'appendStyle';
|
||||
break;
|
||||
}
|
||||
$this->$action($content, $attributes);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overload method calls
|
||||
*
|
||||
* Allows the following method calls:
|
||||
* - appendStyle($content, $attributes = array())
|
||||
* - offsetSetStyle($index, $content, $attributes = array())
|
||||
* - prependStyle($content, $attributes = array())
|
||||
* - setStyle($content, $attributes = array())
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $args
|
||||
* @return void
|
||||
* @throws Zend_View_Exception When no $content provided or invalid method
|
||||
*/
|
||||
public function __call($method, $args)
|
||||
{
|
||||
if (preg_match('/^(?P<action>set|(ap|pre)pend|offsetSet)(Style)$/', $method, $matches)) {
|
||||
$index = null;
|
||||
$argc = count($args);
|
||||
$action = $matches['action'];
|
||||
|
||||
if ('offsetSet' == $action) {
|
||||
if (0 < $argc) {
|
||||
$index = array_shift($args);
|
||||
--$argc;
|
||||
}
|
||||
}
|
||||
|
||||
if (1 > $argc) {
|
||||
require_once 'Zend/View/Exception.php';
|
||||
$e = new Zend_View_Exception(sprintf('Method "%s" requires minimally content for the stylesheet', $method));
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$content = $args[0];
|
||||
$attrs = array();
|
||||
if (isset($args[1])) {
|
||||
$attrs = (array) $args[1];
|
||||
}
|
||||
|
||||
$item = $this->createData($content, $attrs);
|
||||
|
||||
if ('offsetSet' == $action) {
|
||||
$this->offsetSet($index, $item);
|
||||
} else {
|
||||
$this->$action($item);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
return parent::__call($method, $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a value is a valid style tag
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param string $method
|
||||
* @return boolean
|
||||
*/
|
||||
protected function _isValid($value)
|
||||
{
|
||||
if ((!$value instanceof stdClass)
|
||||
|| !isset($value->content)
|
||||
|| !isset($value->attributes))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override append to enforce style creation
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function append($value)
|
||||
{
|
||||
if (!$this->_isValid($value)) {
|
||||
require_once 'Zend/View/Exception.php';
|
||||
$e = new Zend_View_Exception('Invalid value passed to append; please use appendStyle()');
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return $this->getContainer()->append($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override offsetSet to enforce style creation
|
||||
*
|
||||
* @param string|int $index
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function offsetSet($index, $value)
|
||||
{
|
||||
if (!$this->_isValid($value)) {
|
||||
require_once 'Zend/View/Exception.php';
|
||||
$e = new Zend_View_Exception('Invalid value passed to offsetSet; please use offsetSetStyle()');
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return $this->getContainer()->offsetSet($index, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override prepend to enforce style creation
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function prepend($value)
|
||||
{
|
||||
if (!$this->_isValid($value)) {
|
||||
require_once 'Zend/View/Exception.php';
|
||||
$e = new Zend_View_Exception('Invalid value passed to prepend; please use prependStyle()');
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return $this->getContainer()->prepend($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override set to enforce style creation
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function set($value)
|
||||
{
|
||||
if (!$this->_isValid($value)) {
|
||||
require_once 'Zend/View/Exception.php';
|
||||
$e = new Zend_View_Exception('Invalid value passed to set; please use setStyle()');
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return $this->getContainer()->set($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start capture action
|
||||
*
|
||||
* @param mixed $captureType
|
||||
* @param string $typeOrAttrs
|
||||
* @return void
|
||||
*/
|
||||
public function captureStart($type = Zend_View_Helper_Placeholder_Container_Abstract::APPEND, $attrs = null)
|
||||
{
|
||||
if ($this->_captureLock) {
|
||||
require_once 'Zend/View/Helper/Placeholder/Container/Exception.php';
|
||||
$e = new Zend_View_Helper_Placeholder_Container_Exception('Cannot nest headStyle captures');
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$this->_captureLock = true;
|
||||
$this->_captureAttrs = $attrs;
|
||||
$this->_captureType = $type;
|
||||
ob_start();
|
||||
}
|
||||
|
||||
/**
|
||||
* End capture action and store
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function captureEnd()
|
||||
{
|
||||
$content = ob_get_clean();
|
||||
$attrs = $this->_captureAttrs;
|
||||
$this->_captureAttrs = null;
|
||||
$this->_captureLock = false;
|
||||
|
||||
switch ($this->_captureType) {
|
||||
case Zend_View_Helper_Placeholder_Container_Abstract::SET:
|
||||
$this->setStyle($content, $attrs);
|
||||
break;
|
||||
case Zend_View_Helper_Placeholder_Container_Abstract::PREPEND:
|
||||
$this->prependStyle($content, $attrs);
|
||||
break;
|
||||
case Zend_View_Helper_Placeholder_Container_Abstract::APPEND:
|
||||
default:
|
||||
$this->appendStyle($content, $attrs);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert content and attributes into valid style tag
|
||||
*
|
||||
* @param stdClass $item Item to render
|
||||
* @param string $indent Indentation to use
|
||||
* @return string
|
||||
*/
|
||||
public function itemToString(stdClass $item, $indent)
|
||||
{
|
||||
$attrString = '';
|
||||
if (!empty($item->attributes)) {
|
||||
$enc = 'UTF-8';
|
||||
if ($this->view instanceof Zend_View_Interface
|
||||
&& method_exists($this->view, 'getEncoding')
|
||||
) {
|
||||
$enc = $this->view->getEncoding();
|
||||
}
|
||||
foreach ($item->attributes as $key => $value) {
|
||||
if (!in_array($key, $this->_optionalAttributes)) {
|
||||
continue;
|
||||
}
|
||||
if ('media' == $key) {
|
||||
if(false === strpos($value, ',')) {
|
||||
if (!in_array($value, $this->_mediaTypes)) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
$media_types = explode(',', $value);
|
||||
$value = '';
|
||||
foreach($media_types as $type) {
|
||||
$type = trim($type);
|
||||
if (!in_array($type, $this->_mediaTypes)) {
|
||||
continue;
|
||||
}
|
||||
$value .= $type .',';
|
||||
}
|
||||
$value = substr($value, 0, -1);
|
||||
}
|
||||
}
|
||||
$attrString .= sprintf(' %s="%s"', $key, htmlspecialchars($value, ENT_COMPAT, $enc));
|
||||
}
|
||||
}
|
||||
|
||||
$html = '<style type="text/css"' . $attrString . '>' . PHP_EOL
|
||||
. $indent . '<!--' . PHP_EOL . $indent . $item->content . PHP_EOL . $indent . '-->' . PHP_EOL
|
||||
. '</style>';
|
||||
|
||||
if (isset($item->attributes['conditional'])
|
||||
&& !empty($item->attributes['conditional'])
|
||||
&& is_string($item->attributes['conditional']))
|
||||
{
|
||||
$html = '<!--[if ' . $item->attributes['conditional'] . ']> ' . $html . '<![endif]-->';
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create string representation of placeholder
|
||||
*
|
||||
* @param string|int $indent
|
||||
* @return string
|
||||
*/
|
||||
public function toString($indent = null)
|
||||
{
|
||||
$indent = (null !== $indent)
|
||||
? $this->getWhitespace($indent)
|
||||
: $this->getIndent();
|
||||
|
||||
$items = array();
|
||||
$this->getContainer()->ksort();
|
||||
foreach ($this as $item) {
|
||||
if (!$this->_isValid($item)) {
|
||||
continue;
|
||||
}
|
||||
$items[] = $this->itemToString($item, $indent);
|
||||
}
|
||||
|
||||
$return = $indent . implode($this->getSeparator() . $indent, $items);
|
||||
$return = preg_replace("/(\r\n?|\n)/", '$1' . $indent, $return);
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create data item for use in stack
|
||||
*
|
||||
* @param string $content
|
||||
* @param array $attributes
|
||||
* @return stdClass
|
||||
*/
|
||||
public function createData($content, array $attributes)
|
||||
{
|
||||
if (!isset($attributes['media'])) {
|
||||
$attributes['media'] = 'screen';
|
||||
} else if(is_array($attributes['media'])) {
|
||||
$attributes['media'] = implode(',', $attributes['media']);
|
||||
}
|
||||
|
||||
$data = new stdClass();
|
||||
$data->content = $content;
|
||||
$data->attributes = $attributes;
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
181
library/Zend/View/Helper/HeadTitle.php
Normal file
181
library/Zend/View/Helper/HeadTitle.php
Normal file
|
@ -0,0 +1,181 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: HeadTitle.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/** Zend_View_Helper_Placeholder_Container_Standalone */
|
||||
require_once 'Zend/View/Helper/Placeholder/Container/Standalone.php';
|
||||
|
||||
/**
|
||||
* Helper for setting and retrieving title element for HTML head
|
||||
*
|
||||
* @uses Zend_View_Helper_Placeholder_Container_Standalone
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_HeadTitle extends Zend_View_Helper_Placeholder_Container_Standalone
|
||||
{
|
||||
/**
|
||||
* Registry key for placeholder
|
||||
* @var string
|
||||
*/
|
||||
protected $_regKey = 'Zend_View_Helper_HeadTitle';
|
||||
|
||||
/**
|
||||
* Whether or not auto-translation is enabled
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_translate = false;
|
||||
|
||||
/**
|
||||
* Translation object
|
||||
*
|
||||
* @var Zend_Translate_Adapter
|
||||
*/
|
||||
protected $_translator;
|
||||
|
||||
/**
|
||||
* Retrieve placeholder for title element and optionally set state
|
||||
*
|
||||
* @param string $title
|
||||
* @param string $setType
|
||||
* @param string $separator
|
||||
* @return Zend_View_Helper_HeadTitle
|
||||
*/
|
||||
public function headTitle($title = null, $setType = Zend_View_Helper_Placeholder_Container_Abstract::APPEND)
|
||||
{
|
||||
$title = (string) $title;
|
||||
if ($title !== '') {
|
||||
if ($setType == Zend_View_Helper_Placeholder_Container_Abstract::SET) {
|
||||
$this->set($title);
|
||||
} elseif ($setType == Zend_View_Helper_Placeholder_Container_Abstract::PREPEND) {
|
||||
$this->prepend($title);
|
||||
} else {
|
||||
$this->append($title);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a translation Adapter for translation
|
||||
*
|
||||
* @param Zend_Translate|Zend_Translate_Adapter $translate
|
||||
* @return Zend_View_Helper_HeadTitle
|
||||
*/
|
||||
public function setTranslator($translate)
|
||||
{
|
||||
if ($translate instanceof Zend_Translate_Adapter) {
|
||||
$this->_translator = $translate;
|
||||
} elseif ($translate instanceof Zend_Translate) {
|
||||
$this->_translator = $translate->getAdapter();
|
||||
} else {
|
||||
require_once 'Zend/View/Exception.php';
|
||||
$e = new Zend_View_Exception("You must set an instance of Zend_Translate or Zend_Translate_Adapter");
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/*
|
||||
* Retrieve translation object
|
||||
*
|
||||
* If none is currently registered, attempts to pull it from the registry
|
||||
* using the key 'Zend_Translate'.
|
||||
*
|
||||
* @return Zend_Translate_Adapter|null
|
||||
*/
|
||||
public function getTranslator()
|
||||
{
|
||||
if (null === $this->_translator) {
|
||||
require_once 'Zend/Registry.php';
|
||||
if (Zend_Registry::isRegistered('Zend_Translate')) {
|
||||
$this->setTranslator(Zend_Registry::get('Zend_Translate'));
|
||||
}
|
||||
}
|
||||
return $this->_translator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables translation
|
||||
*
|
||||
* @return Zend_View_Helper_HeadTitle
|
||||
*/
|
||||
public function enableTranslation()
|
||||
{
|
||||
$this->_translate = true;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables translation
|
||||
*
|
||||
* @return Zend_View_Helper_HeadTitle
|
||||
*/
|
||||
public function disableTranslation()
|
||||
{
|
||||
$this->_translate = false;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn helper into string
|
||||
*
|
||||
* @param string|null $indent
|
||||
* @param string|null $locale
|
||||
* @return string
|
||||
*/
|
||||
public function toString($indent = null, $locale = null)
|
||||
{
|
||||
$indent = (null !== $indent)
|
||||
? $this->getWhitespace($indent)
|
||||
: $this->getIndent();
|
||||
|
||||
$items = array();
|
||||
|
||||
if($this->_translate && $translator = $this->getTranslator()) {
|
||||
foreach ($this as $item) {
|
||||
$items[] = $translator->translate($item, $locale);
|
||||
}
|
||||
} else {
|
||||
foreach ($this as $item) {
|
||||
$items[] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
$separator = $this->getSeparator();
|
||||
$output = '';
|
||||
if(($prefix = $this->getPrefix())) {
|
||||
$output .= $prefix;
|
||||
}
|
||||
$output .= implode($separator, $items);
|
||||
if(($postfix = $this->getPostfix())) {
|
||||
$output .= $postfix;
|
||||
}
|
||||
|
||||
$output = ($this->_autoEscape) ? $this->_escape($output) : $output;
|
||||
|
||||
return $indent . '<title>' . $output . '</title>';
|
||||
}
|
||||
}
|
141
library/Zend/View/Helper/HtmlElement.php
Normal file
141
library/Zend/View/Helper/HtmlElement.php
Normal file
|
@ -0,0 +1,141 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: HtmlElement.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_View_Helper_Abstract
|
||||
*/
|
||||
require_once 'Zend/View/Helper/Abstract.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_View_Helper_HtmlElement extends Zend_View_Helper_Abstract
|
||||
{
|
||||
/**
|
||||
* EOL character
|
||||
*/
|
||||
const EOL = "\n";
|
||||
|
||||
/**
|
||||
* The tag closing bracket
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_closingBracket = null;
|
||||
|
||||
/**
|
||||
* Get the tag closing bracket
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getClosingBracket()
|
||||
{
|
||||
if (!$this->_closingBracket) {
|
||||
if ($this->_isXhtml()) {
|
||||
$this->_closingBracket = ' />';
|
||||
} else {
|
||||
$this->_closingBracket = '>';
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_closingBracket;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is doctype XHTML?
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function _isXhtml()
|
||||
{
|
||||
$doctype = $this->view->doctype();
|
||||
return $doctype->isXhtml();
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an associative array to a string of tag attributes.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param array $attribs From this array, each key-value pair is
|
||||
* converted to an attribute name and value.
|
||||
*
|
||||
* @return string The XHTML for the attributes.
|
||||
*/
|
||||
protected function _htmlAttribs($attribs)
|
||||
{
|
||||
$xhtml = '';
|
||||
foreach ((array) $attribs as $key => $val) {
|
||||
$key = $this->view->escape($key);
|
||||
|
||||
if (('on' == substr($key, 0, 2)) || ('constraints' == $key)) {
|
||||
// Don't escape event attributes; _do_ substitute double quotes with singles
|
||||
if (!is_scalar($val)) {
|
||||
// non-scalar data should be cast to JSON first
|
||||
require_once 'Zend/Json.php';
|
||||
$val = Zend_Json::encode($val);
|
||||
}
|
||||
$val = preg_replace('/"([^"]*)":/', '$1:', $val);
|
||||
} else {
|
||||
if (is_array($val)) {
|
||||
$val = implode(' ', $val);
|
||||
}
|
||||
$val = $this->view->escape($val);
|
||||
}
|
||||
|
||||
if ('id' == $key) {
|
||||
$val = $this->_normalizeId($val);
|
||||
}
|
||||
|
||||
if (strpos($val, '"') !== false) {
|
||||
$xhtml .= " $key='$val'";
|
||||
} else {
|
||||
$xhtml .= " $key=\"$val\"";
|
||||
}
|
||||
|
||||
}
|
||||
return $xhtml;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize an ID
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
protected function _normalizeId($value)
|
||||
{
|
||||
if (strstr($value, '[')) {
|
||||
if ('[]' == substr($value, -2)) {
|
||||
$value = substr($value, 0, strlen($value) - 2);
|
||||
}
|
||||
$value = trim($value, ']');
|
||||
$value = str_replace('][', '-', $value);
|
||||
$value = str_replace('[', '-', $value);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
}
|
60
library/Zend/View/Helper/HtmlFlash.php
Normal file
60
library/Zend/View/Helper/HtmlFlash.php
Normal file
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: HtmlFlash.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_View_Helper_HtmlObject
|
||||
*/
|
||||
require_once 'Zend/View/Helper/HtmlObject.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_HtmlFlash extends Zend_View_Helper_HtmlObject
|
||||
{
|
||||
/**
|
||||
* Default file type for a flash applet
|
||||
*
|
||||
*/
|
||||
const TYPE = 'application/x-shockwave-flash';
|
||||
|
||||
/**
|
||||
* Output a flash movie object tag
|
||||
*
|
||||
* @param string $data The flash file
|
||||
* @param array $attribs Attribs for the object tag
|
||||
* @param array $params Params for in the object tag
|
||||
* @param string $content Alternative content
|
||||
* @return string
|
||||
*/
|
||||
public function htmlFlash($data, array $attribs = array(), array $params = array(), $content = null)
|
||||
{
|
||||
// Params
|
||||
$params = array_merge(array('movie' => $data,
|
||||
'quality' => 'high'), $params);
|
||||
|
||||
return $this->htmlObject($data, self::TYPE, $attribs, $params, $content);
|
||||
}
|
||||
}
|
90
library/Zend/View/Helper/HtmlList.php
Normal file
90
library/Zend/View/Helper/HtmlList.php
Normal file
|
@ -0,0 +1,90 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: HtmlList.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Zend_View_Helper_FormELement
|
||||
*/
|
||||
require_once 'Zend/View/Helper/FormElement.php';
|
||||
|
||||
/**
|
||||
* Helper for ordered and unordered lists
|
||||
*
|
||||
* @uses Zend_View_Helper_FormElement
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_HtmlList extends Zend_View_Helper_FormElement
|
||||
{
|
||||
|
||||
/**
|
||||
* Generates a 'List' element.
|
||||
*
|
||||
* @param array $items Array with the elements of the list
|
||||
* @param boolean $ordered Specifies ordered/unordered list; default unordered
|
||||
* @param array $attribs Attributes for the ol/ul tag.
|
||||
* @return string The list XHTML.
|
||||
*/
|
||||
public function htmlList(array $items, $ordered = false, $attribs = false, $escape = true)
|
||||
{
|
||||
if (!is_array($items)) {
|
||||
require_once 'Zend/View/Exception.php';
|
||||
$e = new Zend_View_Exception('First param must be an array');
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$list = '';
|
||||
|
||||
foreach ($items as $item) {
|
||||
if (!is_array($item)) {
|
||||
if ($escape) {
|
||||
$item = $this->view->escape($item);
|
||||
}
|
||||
$list .= '<li>' . $item . '</li>' . self::EOL;
|
||||
} else {
|
||||
if (6 < strlen($list)) {
|
||||
$list = substr($list, 0, strlen($list) - 6)
|
||||
. $this->htmlList($item, $ordered, $attribs, $escape) . '</li>' . self::EOL;
|
||||
} else {
|
||||
$list .= '<li>' . $this->htmlList($item, $ordered, $attribs, $escape) . '</li>' . self::EOL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($attribs) {
|
||||
$attribs = $this->_htmlAttribs($attribs);
|
||||
} else {
|
||||
$attribs = '';
|
||||
}
|
||||
|
||||
$tag = 'ul';
|
||||
if ($ordered) {
|
||||
$tag = 'ol';
|
||||
}
|
||||
|
||||
return '<' . $tag . $attribs . '>' . self::EOL . $list . '</' . $tag . '>' . self::EOL;
|
||||
}
|
||||
}
|
80
library/Zend/View/Helper/HtmlObject.php
Normal file
80
library/Zend/View/Helper/HtmlObject.php
Normal file
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: HtmlObject.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_View_Helper_HtmlElement
|
||||
*/
|
||||
require_once 'Zend/View/Helper/HtmlElement.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_HtmlObject extends Zend_View_Helper_HtmlElement
|
||||
{
|
||||
/**
|
||||
* Output an object set
|
||||
*
|
||||
* @param string $data The data file
|
||||
* @param string $type Data file type
|
||||
* @param array $attribs Attribs for the object tag
|
||||
* @param array $params Params for in the object tag
|
||||
* @param string $content Alternative content for object
|
||||
* @return string
|
||||
*/
|
||||
public function htmlObject($data, $type, array $attribs = array(), array $params = array(), $content = null)
|
||||
{
|
||||
// Merge data and type
|
||||
$attribs = array_merge(array('data' => $data,
|
||||
'type' => $type), $attribs);
|
||||
|
||||
// Params
|
||||
$paramHtml = array();
|
||||
$closingBracket = $this->getClosingBracket();
|
||||
|
||||
foreach ($params as $param => $options) {
|
||||
if (is_string($options)) {
|
||||
$options = array('value' => $options);
|
||||
}
|
||||
|
||||
$options = array_merge(array('name' => $param), $options);
|
||||
|
||||
$paramHtml[] = '<param' . $this->_htmlAttribs($options) . $closingBracket;
|
||||
}
|
||||
|
||||
// Content
|
||||
if (is_array($content)) {
|
||||
$content = implode(self::EOL, $content);
|
||||
}
|
||||
|
||||
// Object header
|
||||
$xhtml = '<object' . $this->_htmlAttribs($attribs) . '>' . self::EOL
|
||||
. implode(self::EOL, $paramHtml) . self::EOL
|
||||
. ($content ? $content . self::EOL : '')
|
||||
. '</object>';
|
||||
|
||||
return $xhtml;
|
||||
}
|
||||
}
|
75
library/Zend/View/Helper/HtmlPage.php
Normal file
75
library/Zend/View/Helper/HtmlPage.php
Normal file
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: HtmlPage.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_View_Helper_HtmlObject
|
||||
*/
|
||||
require_once 'Zend/View/Helper/HtmlObject.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_HtmlPage extends Zend_View_Helper_HtmlObject
|
||||
{
|
||||
/**
|
||||
* Default file type for html
|
||||
*
|
||||
*/
|
||||
const TYPE = 'text/html';
|
||||
|
||||
/**
|
||||
* Object classid
|
||||
*
|
||||
*/
|
||||
const ATTRIB_CLASSID = 'clsid:25336920-03F9-11CF-8FD0-00AA00686F13';
|
||||
|
||||
/**
|
||||
* Default attributes
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_attribs = array('classid' => self::ATTRIB_CLASSID);
|
||||
|
||||
/**
|
||||
* Output a html object tag
|
||||
*
|
||||
* @param string $data The html url
|
||||
* @param array $attribs Attribs for the object tag
|
||||
* @param array $params Params for in the object tag
|
||||
* @param string $content Alternative content
|
||||
* @return string
|
||||
*/
|
||||
public function htmlPage($data, array $attribs = array(), array $params = array(), $content = null)
|
||||
{
|
||||
// Attrs
|
||||
$attribs = array_merge($this->_attribs, $attribs);
|
||||
|
||||
// Params
|
||||
$params = array_merge(array('data' => $data), $params);
|
||||
|
||||
return $this->htmlObject($data, self::TYPE, $attribs, $params, $content);
|
||||
}
|
||||
}
|
82
library/Zend/View/Helper/HtmlQuicktime.php
Normal file
82
library/Zend/View/Helper/HtmlQuicktime.php
Normal file
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: HtmlQuicktime.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_View_Helper_HtmlObject
|
||||
*/
|
||||
require_once 'Zend/View/Helper/HtmlObject.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_HtmlQuicktime extends Zend_View_Helper_HtmlObject
|
||||
{
|
||||
/**
|
||||
* Default file type for a movie applet
|
||||
*
|
||||
*/
|
||||
const TYPE = 'video/quicktime';
|
||||
|
||||
/**
|
||||
* Object classid
|
||||
*
|
||||
*/
|
||||
const ATTRIB_CLASSID = 'clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B';
|
||||
|
||||
/**
|
||||
* Object Codebase
|
||||
*
|
||||
*/
|
||||
const ATTRIB_CODEBASE = 'http://www.apple.com/qtactivex/qtplugin.cab';
|
||||
|
||||
/**
|
||||
* Default attributes
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_attribs = array('classid' => self::ATTRIB_CLASSID,
|
||||
'codebase' => self::ATTRIB_CODEBASE);
|
||||
|
||||
/**
|
||||
* Output a quicktime movie object tag
|
||||
*
|
||||
* @param string $data The quicktime file
|
||||
* @param array $attribs Attribs for the object tag
|
||||
* @param array $params Params for in the object tag
|
||||
* @param string $content Alternative content
|
||||
* @return string
|
||||
*/
|
||||
public function htmlQuicktime($data, array $attribs = array(), array $params = array(), $content = null)
|
||||
{
|
||||
// Attrs
|
||||
$attribs = array_merge($this->_attribs, $attribs);
|
||||
|
||||
// Params
|
||||
$params = array_merge(array('src' => $data), $params);
|
||||
|
||||
return $this->htmlObject($data, self::TYPE, $attribs, $params, $content);
|
||||
}
|
||||
}
|
61
library/Zend/View/Helper/InlineScript.php
Normal file
61
library/Zend/View/Helper/InlineScript.php
Normal file
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: InlineScript.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/** Zend_View_Helper_HeadScript */
|
||||
require_once 'Zend/View/Helper/HeadScript.php';
|
||||
|
||||
/**
|
||||
* Helper for setting and retrieving script elements for inclusion in HTML body
|
||||
* section
|
||||
*
|
||||
* @uses Zend_View_Helper_Head_Script
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_InlineScript extends Zend_View_Helper_HeadScript
|
||||
{
|
||||
/**
|
||||
* Registry key for placeholder
|
||||
* @var string
|
||||
*/
|
||||
protected $_regKey = 'Zend_View_Helper_InlineScript';
|
||||
|
||||
/**
|
||||
* Return InlineScript object
|
||||
*
|
||||
* Returns InlineScript helper object; optionally, allows specifying a
|
||||
* script or script file to include.
|
||||
*
|
||||
* @param string $mode Script or file
|
||||
* @param string $spec Script/url
|
||||
* @param string $placement Append, prepend, or set
|
||||
* @param array $attrs Array of script attributes
|
||||
* @param string $type Script type and/or array of script attributes
|
||||
* @return Zend_View_Helper_InlineScript
|
||||
*/
|
||||
public function inlineScript($mode = Zend_View_Helper_HeadScript::FILE, $spec = null, $placement = 'APPEND', array $attrs = array(), $type = 'text/javascript')
|
||||
{
|
||||
return $this->headScript($mode, $spec, $placement, $attrs, $type);
|
||||
}
|
||||
}
|
46
library/Zend/View/Helper/Interface.php
Normal file
46
library/Zend/View/Helper/Interface.php
Normal file
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
interface Zend_View_Helper_Interface
|
||||
{
|
||||
/**
|
||||
* Set the View object
|
||||
*
|
||||
* @param Zend_View_Interface $view
|
||||
* @return Zend_View_Helper_Interface
|
||||
*/
|
||||
public function setView(Zend_View_Interface $view);
|
||||
|
||||
/**
|
||||
* Strategy pattern: helper method to invoke
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function direct();
|
||||
}
|
80
library/Zend/View/Helper/Json.php
Normal file
80
library/Zend/View/Helper/Json.php
Normal file
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: Json.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/** Zend_Json */
|
||||
require_once 'Zend/Json.php';
|
||||
|
||||
/** Zend_Controller_Front */
|
||||
require_once 'Zend/Controller/Front.php';
|
||||
|
||||
/** Zend_View_Helper_Abstract.php */
|
||||
require_once 'Zend/View/Helper/Abstract.php';
|
||||
|
||||
/**
|
||||
* Helper for simplifying JSON responses
|
||||
*
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_Json extends Zend_View_Helper_Abstract
|
||||
{
|
||||
/**
|
||||
* Encode data as JSON, disable layouts, and set response header
|
||||
*
|
||||
* If $keepLayouts is true, does not disable layouts.
|
||||
*
|
||||
* @param mixed $data
|
||||
* @param bool $keepLayouts
|
||||
* NOTE: if boolean, establish $keepLayouts to true|false
|
||||
* if array, admit params for Zend_Json::encode as enableJsonExprFinder=>true|false
|
||||
* this array can contains a 'keepLayout'=>true|false
|
||||
* that will not be passed to Zend_Json::encode method but will be used here
|
||||
* @return string|void
|
||||
*/
|
||||
public function json($data, $keepLayouts = false)
|
||||
{
|
||||
$options = array();
|
||||
if (is_array($keepLayouts))
|
||||
{
|
||||
$options = $keepLayouts;
|
||||
$keepLayouts = (array_key_exists('keepLayouts', $keepLayouts))
|
||||
? $keepLayouts['keepLayouts']
|
||||
: false;
|
||||
unset($options['keepLayouts']);
|
||||
}
|
||||
|
||||
$data = Zend_Json::encode($data, null, $options);
|
||||
if (!$keepLayouts) {
|
||||
require_once 'Zend/Layout.php';
|
||||
$layout = Zend_Layout::getMvcInstance();
|
||||
if ($layout instanceof Zend_Layout) {
|
||||
$layout->disableLayout();
|
||||
}
|
||||
}
|
||||
|
||||
$response = Zend_Controller_Front::getInstance()->getResponse();
|
||||
$response->setHeader('Content-Type', 'application/json');
|
||||
return $data;
|
||||
}
|
||||
}
|
81
library/Zend/View/Helper/Layout.php
Normal file
81
library/Zend/View/Helper/Layout.php
Normal file
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: Layout.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/** Zend_View_Helper_Abstract.php */
|
||||
require_once 'Zend/View/Helper/Abstract.php';
|
||||
|
||||
/**
|
||||
* View helper for retrieving layout object
|
||||
*
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_Layout extends Zend_View_Helper_Abstract
|
||||
{
|
||||
/** @var Zend_Layout */
|
||||
protected $_layout;
|
||||
|
||||
/**
|
||||
* Get layout object
|
||||
*
|
||||
* @return Zend_Layout
|
||||
*/
|
||||
public function getLayout()
|
||||
{
|
||||
if (null === $this->_layout) {
|
||||
require_once 'Zend/Layout.php';
|
||||
$this->_layout = Zend_Layout::getMvcInstance();
|
||||
if (null === $this->_layout) {
|
||||
// Implicitly creates layout object
|
||||
$this->_layout = new Zend_Layout();
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_layout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set layout object
|
||||
*
|
||||
* @param Zend_Layout $layout
|
||||
* @return Zend_Layout_Controller_Action_Helper_Layout
|
||||
*/
|
||||
public function setLayout(Zend_Layout $layout)
|
||||
{
|
||||
$this->_layout = $layout;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return layout object
|
||||
*
|
||||
* Usage: $this->layout()->setLayout('alternate');
|
||||
*
|
||||
* @return Zend_Layout
|
||||
*/
|
||||
public function layout()
|
||||
{
|
||||
return $this->getLayout();
|
||||
}
|
||||
}
|
338
library/Zend/View/Helper/Navigation.php
Normal file
338
library/Zend/View/Helper/Navigation.php
Normal file
|
@ -0,0 +1,338 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Navigation.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_View_Helper_Navigation_HelperAbstract
|
||||
*/
|
||||
require_once 'Zend/View/Helper/Navigation/HelperAbstract.php';
|
||||
|
||||
/**
|
||||
* Proxy helper for retrieving navigational helpers and forwarding calls
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_Navigation
|
||||
extends Zend_View_Helper_Navigation_HelperAbstract
|
||||
{
|
||||
/**
|
||||
* View helper namespace
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const NS = 'Zend_View_Helper_Navigation';
|
||||
|
||||
/**
|
||||
* Default proxy to use in {@link render()}
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_defaultProxy = 'menu';
|
||||
|
||||
/**
|
||||
* Contains references to proxied helpers
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_helpers = array();
|
||||
|
||||
/**
|
||||
* Whether container should be injected when proxying
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_injectContainer = true;
|
||||
|
||||
/**
|
||||
* Whether ACL should be injected when proxying
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_injectAcl = true;
|
||||
|
||||
/**
|
||||
* Whether translator should be injected when proxying
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_injectTranslator = true;
|
||||
|
||||
/**
|
||||
* Helper entry point
|
||||
*
|
||||
* @param Zend_Navigation_Container $container [optional] container to
|
||||
* operate on
|
||||
* @return Zend_View_Helper_Navigation fluent interface, returns
|
||||
* self
|
||||
*/
|
||||
public function navigation(Zend_Navigation_Container $container = null)
|
||||
{
|
||||
if (null !== $container) {
|
||||
$this->setContainer($container);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic overload: Proxy to other navigation helpers or the container
|
||||
*
|
||||
* Examples of usage from a view script or layout:
|
||||
* <code>
|
||||
* // proxy to Menu helper and render container:
|
||||
* echo $this->navigation()->menu();
|
||||
*
|
||||
* // proxy to Breadcrumbs helper and set indentation:
|
||||
* $this->navigation()->breadcrumbs()->setIndent(8);
|
||||
*
|
||||
* // proxy to container and find all pages with 'blog' route:
|
||||
* $blogPages = $this->navigation()->findAllByRoute('blog');
|
||||
* </code>
|
||||
*
|
||||
* @param string $method helper name or method name in
|
||||
* container
|
||||
* @param array $arguments [optional] arguments to pass
|
||||
* @return mixed returns what the proxied call returns
|
||||
* @throws Zend_View_Exception if proxying to a helper, and the
|
||||
* helper is not an instance of the
|
||||
* interface specified in
|
||||
* {@link findHelper()}
|
||||
* @throws Zend_Navigation_Exception if method does not exist in container
|
||||
*/
|
||||
public function __call($method, array $arguments = array())
|
||||
{
|
||||
// check if call should proxy to another helper
|
||||
if ($helper = $this->findHelper($method, false)) {
|
||||
return call_user_func_array(array($helper, $method), $arguments);
|
||||
}
|
||||
|
||||
// default behaviour: proxy call to container
|
||||
return parent::__call($method, $arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the helper matching $proxy
|
||||
*
|
||||
* The helper must implement the interface
|
||||
* {@link Zend_View_Helper_Navigation_Helper}.
|
||||
*
|
||||
* @param string $proxy helper name
|
||||
* @param bool $strict [optional] whether
|
||||
* exceptions should be
|
||||
* thrown if something goes
|
||||
* wrong. Default is true.
|
||||
* @return Zend_View_Helper_Navigation_Helper helper instance
|
||||
* @throws Zend_Loader_PluginLoader_Exception if $strict is true and
|
||||
* helper cannot be found
|
||||
* @throws Zend_View_Exception if $strict is true and
|
||||
* helper does not implement
|
||||
* the specified interface
|
||||
*/
|
||||
public function findHelper($proxy, $strict = true)
|
||||
{
|
||||
if (isset($this->_helpers[$proxy])) {
|
||||
return $this->_helpers[$proxy];
|
||||
}
|
||||
|
||||
if (!$this->view->getPluginLoader('helper')->getPaths(self::NS)) {
|
||||
$this->view->addHelperPath(
|
||||
str_replace('_', '/', self::NS),
|
||||
self::NS);
|
||||
}
|
||||
|
||||
if ($strict) {
|
||||
$helper = $this->view->getHelper($proxy);
|
||||
} else {
|
||||
try {
|
||||
$helper = $this->view->getHelper($proxy);
|
||||
} catch (Zend_Loader_PluginLoader_Exception $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$helper instanceof Zend_View_Helper_Navigation_Helper) {
|
||||
if ($strict) {
|
||||
require_once 'Zend/View/Exception.php';
|
||||
$e = new Zend_View_Exception(sprintf(
|
||||
'Proxy helper "%s" is not an instance of ' .
|
||||
'Zend_View_Helper_Navigation_Helper',
|
||||
get_class($helper)));
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->_inject($helper);
|
||||
$this->_helpers[$proxy] = $helper;
|
||||
|
||||
return $helper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Injects container, ACL, and translator to the given $helper if this
|
||||
* helper is configured to do so
|
||||
*
|
||||
* @param Zend_View_Helper_Navigation_Helper $helper helper instance
|
||||
* @return void
|
||||
*/
|
||||
protected function _inject(Zend_View_Helper_Navigation_Helper $helper)
|
||||
{
|
||||
if ($this->getInjectContainer() && !$helper->hasContainer()) {
|
||||
$helper->setContainer($this->getContainer());
|
||||
}
|
||||
|
||||
if ($this->getInjectAcl()) {
|
||||
if (!$helper->hasAcl()) {
|
||||
$helper->setAcl($this->getAcl());
|
||||
}
|
||||
if (!$helper->hasRole()) {
|
||||
$helper->setRole($this->getRole());
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->getInjectTranslator() && !$helper->hasTranslator()) {
|
||||
$helper->setTranslator($this->getTranslator());
|
||||
}
|
||||
}
|
||||
|
||||
// Accessors:
|
||||
|
||||
/**
|
||||
* Sets the default proxy to use in {@link render()}
|
||||
*
|
||||
* @param string $proxy default proxy
|
||||
* @return Zend_View_Helper_Navigation fluent interface, returns self
|
||||
*/
|
||||
public function setDefaultProxy($proxy)
|
||||
{
|
||||
$this->_defaultProxy = (string) $proxy;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default proxy to use in {@link render()}
|
||||
*
|
||||
* @return string the default proxy to use in {@link render()}
|
||||
*/
|
||||
public function getDefaultProxy()
|
||||
{
|
||||
return $this->_defaultProxy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether container should be injected when proxying
|
||||
*
|
||||
* @param bool $injectContainer [optional] whether container should
|
||||
* be injected when proxying. Default
|
||||
* is true.
|
||||
* @return Zend_View_Helper_Navigation fluent interface, returns self
|
||||
*/
|
||||
public function setInjectContainer($injectContainer = true)
|
||||
{
|
||||
$this->_injectContainer = (bool) $injectContainer;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether container should be injected when proxying
|
||||
*
|
||||
* @return bool whether container should be injected when proxying
|
||||
*/
|
||||
public function getInjectContainer()
|
||||
{
|
||||
return $this->_injectContainer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether ACL should be injected when proxying
|
||||
*
|
||||
* @param bool $injectAcl [optional] whether ACL should be
|
||||
* injected when proxying. Default is
|
||||
* true.
|
||||
* @return Zend_View_Helper_Navigation fluent interface, returns self
|
||||
*/
|
||||
public function setInjectAcl($injectAcl = true)
|
||||
{
|
||||
$this->_injectAcl = (bool) $injectAcl;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether ACL should be injected when proxying
|
||||
*
|
||||
* @return bool whether ACL should be injected when proxying
|
||||
*/
|
||||
public function getInjectAcl()
|
||||
{
|
||||
return $this->_injectAcl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether translator should be injected when proxying
|
||||
*
|
||||
* @param bool $injectTranslator [optional] whether translator should
|
||||
* be injected when proxying. Default
|
||||
* is true.
|
||||
* @return Zend_View_Helper_Navigation fluent interface, returns self
|
||||
*/
|
||||
public function setInjectTranslator($injectTranslator = true)
|
||||
{
|
||||
$this->_injectTranslator = (bool) $injectTranslator;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether translator should be injected when proxying
|
||||
*
|
||||
* @return bool whether translator should be injected when proxying
|
||||
*/
|
||||
public function getInjectTranslator()
|
||||
{
|
||||
return $this->_injectTranslator;
|
||||
}
|
||||
|
||||
// Zend_View_Helper_Navigation_Helper:
|
||||
|
||||
/**
|
||||
* Renders helper
|
||||
*
|
||||
* @param Zend_Navigation_Container $container [optional] container to
|
||||
* render. Default is to
|
||||
* render the container
|
||||
* registered in the helper.
|
||||
* @return string helper output
|
||||
* @throws Zend_Loader_PluginLoader_Exception if helper cannot be found
|
||||
* @throws Zend_View_Exception if helper doesn't implement
|
||||
* the interface specified in
|
||||
* {@link findHelper()}
|
||||
*/
|
||||
public function render(Zend_Navigation_Container $container = null)
|
||||
{
|
||||
$helper = $this->findHelper($this->getDefaultProxy());
|
||||
return $helper->render($container);
|
||||
}
|
||||
}
|
331
library/Zend/View/Helper/Navigation/Breadcrumbs.php
Normal file
331
library/Zend/View/Helper/Navigation/Breadcrumbs.php
Normal file
|
@ -0,0 +1,331 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Breadcrumbs.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_View_Helper_Navigation_HelperAbstract
|
||||
*/
|
||||
require_once 'Zend/View/Helper/Navigation/HelperAbstract.php';
|
||||
|
||||
/**
|
||||
* Helper for printing breadcrumbs
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_Navigation_Breadcrumbs
|
||||
extends Zend_View_Helper_Navigation_HelperAbstract
|
||||
{
|
||||
/**
|
||||
* Breadcrumbs separator string
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_separator = ' > ';
|
||||
|
||||
/**
|
||||
* The minimum depth a page must have to be included when rendering
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_minDepth = 1;
|
||||
|
||||
/**
|
||||
* Whether last page in breadcrumb should be hyperlinked
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_linkLast = false;
|
||||
|
||||
/**
|
||||
* Partial view script to use for rendering menu
|
||||
*
|
||||
* @var string|array
|
||||
*/
|
||||
protected $_partial;
|
||||
|
||||
/**
|
||||
* View helper entry point:
|
||||
* Retrieves helper and optionally sets container to operate on
|
||||
*
|
||||
* @param Zend_Navigation_Container $container [optional] container to
|
||||
* operate on
|
||||
* @return Zend_View_Helper_Navigation_Breadcrumbs fluent interface,
|
||||
* returns self
|
||||
*/
|
||||
public function breadcrumbs(Zend_Navigation_Container $container = null)
|
||||
{
|
||||
if (null !== $container) {
|
||||
$this->setContainer($container);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
// Accessors:
|
||||
|
||||
/**
|
||||
* Sets breadcrumb separator
|
||||
*
|
||||
* @param string $separator separator string
|
||||
* @return Zend_View_Helper_Navigation_Breadcrumbs fluent interface,
|
||||
* returns self
|
||||
*/
|
||||
public function setSeparator($separator)
|
||||
{
|
||||
if (is_string($separator)) {
|
||||
$this->_separator = $separator;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns breadcrumb separator
|
||||
*
|
||||
* @return string breadcrumb separator
|
||||
*/
|
||||
public function getSeparator()
|
||||
{
|
||||
return $this->_separator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether last page in breadcrumbs should be hyperlinked
|
||||
*
|
||||
* @param bool $linkLast whether last page should
|
||||
* be hyperlinked
|
||||
* @return Zend_View_Helper_Navigation_Breadcrumbs fluent interface,
|
||||
* returns self
|
||||
*/
|
||||
public function setLinkLast($linkLast)
|
||||
{
|
||||
$this->_linkLast = (bool) $linkLast;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether last page in breadcrumbs should be hyperlinked
|
||||
*
|
||||
* @return bool whether last page in breadcrumbs should be hyperlinked
|
||||
*/
|
||||
public function getLinkLast()
|
||||
{
|
||||
return $this->_linkLast;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets which partial view script to use for rendering menu
|
||||
*
|
||||
* @param string|array $partial partial view script or
|
||||
* null. If an array is
|
||||
* given, it is expected to
|
||||
* contain two values;
|
||||
* the partial view script
|
||||
* to use, and the module
|
||||
* where the script can be
|
||||
* found.
|
||||
* @return Zend_View_Helper_Navigation_Breadcrumbs fluent interface,
|
||||
* returns self
|
||||
*/
|
||||
public function setPartial($partial)
|
||||
{
|
||||
if (null === $partial || is_string($partial) || is_array($partial)) {
|
||||
$this->_partial = $partial;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns partial view script to use for rendering menu
|
||||
*
|
||||
* @return string|array|null
|
||||
*/
|
||||
public function getPartial()
|
||||
{
|
||||
return $this->_partial;
|
||||
}
|
||||
|
||||
// Render methods:
|
||||
|
||||
/**
|
||||
* Renders breadcrumbs by chaining 'a' elements with the separator
|
||||
* registered in the helper
|
||||
*
|
||||
* @param Zend_Navigation_Container $container [optional] container to
|
||||
* render. Default is to
|
||||
* render the container
|
||||
* registered in the helper.
|
||||
* @return string helper output
|
||||
*/
|
||||
public function renderStraight(Zend_Navigation_Container $container = null)
|
||||
{
|
||||
if (null === $container) {
|
||||
$container = $this->getContainer();
|
||||
}
|
||||
|
||||
// find deepest active
|
||||
if (!$active = $this->findActive($container)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$active = $active['page'];
|
||||
|
||||
// put the deepest active page last in breadcrumbs
|
||||
if ($this->getLinkLast()) {
|
||||
$html = $this->htmlify($active);
|
||||
} else {
|
||||
$html = $active->getLabel();
|
||||
if ($this->getUseTranslator() && $t = $this->getTranslator()) {
|
||||
$html = $t->translate($html);
|
||||
}
|
||||
$html = $this->view->escape($html);
|
||||
}
|
||||
|
||||
// walk back to root
|
||||
while ($parent = $active->getParent()) {
|
||||
if ($parent instanceof Zend_Navigation_Page) {
|
||||
// prepend crumb to html
|
||||
$html = $this->htmlify($parent)
|
||||
. $this->getSeparator()
|
||||
. $html;
|
||||
}
|
||||
|
||||
if ($parent === $container) {
|
||||
// at the root of the given container
|
||||
break;
|
||||
}
|
||||
|
||||
$active = $parent;
|
||||
}
|
||||
|
||||
return strlen($html) ? $this->getIndent() . $html : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the given $container by invoking the partial view helper
|
||||
*
|
||||
* The container will simply be passed on as a model to the view script,
|
||||
* so in the script it will be available in <code>$this->container</code>.
|
||||
*
|
||||
* @param Zend_Navigation_Container $container [optional] container to
|
||||
* pass to view script.
|
||||
* Default is to use the
|
||||
* container registered in the
|
||||
* helper.
|
||||
* @param string|array $partial [optional] partial view
|
||||
* script to use. Default is
|
||||
* to use the partial
|
||||
* registered in the helper.
|
||||
* If an array is given, it is
|
||||
* expected to contain two
|
||||
* values; the partial view
|
||||
* script to use, and the
|
||||
* module where the script can
|
||||
* be found.
|
||||
* @return string helper output
|
||||
*/
|
||||
public function renderPartial(Zend_Navigation_Container $container = null,
|
||||
$partial = null)
|
||||
{
|
||||
if (null === $container) {
|
||||
$container = $this->getContainer();
|
||||
}
|
||||
|
||||
if (null === $partial) {
|
||||
$partial = $this->getPartial();
|
||||
}
|
||||
|
||||
if (empty($partial)) {
|
||||
require_once 'Zend/View/Exception.php';
|
||||
$e = new Zend_View_Exception(
|
||||
'Unable to render menu: No partial view script provided'
|
||||
);
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
// put breadcrumb pages in model
|
||||
$model = array('pages' => array());
|
||||
if ($active = $this->findActive($container)) {
|
||||
$active = $active['page'];
|
||||
$model['pages'][] = $active;
|
||||
while ($parent = $active->getParent()) {
|
||||
if ($parent instanceof Zend_Navigation_Page) {
|
||||
$model['pages'][] = $parent;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
if ($parent === $container) {
|
||||
// break if at the root of the given container
|
||||
break;
|
||||
}
|
||||
|
||||
$active = $parent;
|
||||
}
|
||||
$model['pages'] = array_reverse($model['pages']);
|
||||
}
|
||||
|
||||
if (is_array($partial)) {
|
||||
if (count($partial) != 2) {
|
||||
require_once 'Zend/View/Exception.php';
|
||||
$e = new Zend_View_Exception(
|
||||
'Unable to render menu: A view partial supplied as '
|
||||
. 'an array must contain two values: partial view '
|
||||
. 'script and module where script can be found'
|
||||
);
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return $this->view->partial($partial[0], $partial[1], $model);
|
||||
}
|
||||
|
||||
return $this->view->partial($partial, null, $model);
|
||||
}
|
||||
|
||||
// Zend_View_Helper_Navigation_Helper:
|
||||
|
||||
/**
|
||||
* Renders helper
|
||||
*
|
||||
* Implements {@link Zend_View_Helper_Navigation_Helper::render()}.
|
||||
*
|
||||
* @param Zend_Navigation_Container $container [optional] container to
|
||||
* render. Default is to
|
||||
* render the container
|
||||
* registered in the helper.
|
||||
* @return string helper output
|
||||
*/
|
||||
public function render(Zend_Navigation_Container $container = null)
|
||||
{
|
||||
if ($partial = $this->getPartial()) {
|
||||
return $this->renderPartial($container, $partial);
|
||||
} else {
|
||||
return $this->renderStraight($container);
|
||||
}
|
||||
}
|
||||
}
|
212
library/Zend/View/Helper/Navigation/Helper.php
Normal file
212
library/Zend/View/Helper/Navigation/Helper.php
Normal file
|
@ -0,0 +1,212 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Helper.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* Interface for navigational helpers
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
interface Zend_View_Helper_Navigation_Helper
|
||||
{
|
||||
/**
|
||||
* Sets navigation container the helper should operate on by default
|
||||
*
|
||||
* @param Zend_Navigation_Container $container [optional] container to
|
||||
* operate on. Default is
|
||||
* null, which indicates that
|
||||
* the container should be
|
||||
* reset.
|
||||
* @return Zend_View_Helper_Navigation_Helper fluent interface, returns
|
||||
* self
|
||||
*/
|
||||
public function setContainer(Zend_Navigation_Container $container = null);
|
||||
|
||||
/**
|
||||
* Returns the navigation container the helper operates on by default
|
||||
*
|
||||
* @return Zend_Navigation_Container navigation container
|
||||
*/
|
||||
public function getContainer();
|
||||
|
||||
/**
|
||||
* Sets translator to use in helper
|
||||
*
|
||||
* @param mixed $translator [optional] translator.
|
||||
* Expects an object of type
|
||||
* {@link Zend_Translate_Adapter}
|
||||
* or {@link Zend_Translate},
|
||||
* or null. Default is null.
|
||||
* @return Zend_View_Helper_Navigation_Helper fluent interface, returns
|
||||
* self
|
||||
*/
|
||||
public function setTranslator($translator = null);
|
||||
|
||||
/**
|
||||
* Returns translator used in helper
|
||||
*
|
||||
* @return Zend_Translate_Adapter|null translator or null
|
||||
*/
|
||||
public function getTranslator();
|
||||
|
||||
/**
|
||||
* Sets ACL to use when iterating pages
|
||||
*
|
||||
* @param Zend_Acl $acl [optional] ACL instance
|
||||
* @return Zend_View_Helper_Navigation_Helper fluent interface, returns
|
||||
* self
|
||||
*/
|
||||
public function setAcl(Zend_Acl $acl = null);
|
||||
|
||||
/**
|
||||
* Returns ACL or null if it isn't set using {@link setAcl()} or
|
||||
* {@link setDefaultAcl()}
|
||||
*
|
||||
* @return Zend_Acl|null ACL object or null
|
||||
*/
|
||||
public function getAcl();
|
||||
|
||||
/**
|
||||
* Sets ACL role to use when iterating pages
|
||||
*
|
||||
* @param mixed $role [optional] role to set.
|
||||
* Expects a string, an
|
||||
* instance of type
|
||||
* {@link Zend_Acl_Role_Interface},
|
||||
* or null. Default is null.
|
||||
* @throws Zend_View_Exception if $role is invalid
|
||||
* @return Zend_View_Helper_Navigation_Helper fluent interface, returns
|
||||
* self
|
||||
*/
|
||||
public function setRole($role = null);
|
||||
|
||||
/**
|
||||
* Returns ACL role to use when iterating pages, or null if it isn't set
|
||||
*
|
||||
* @return string|Zend_Acl_Role_Interface|null role or null
|
||||
*/
|
||||
public function getRole();
|
||||
|
||||
/**
|
||||
* Sets whether ACL should be used
|
||||
*
|
||||
* @param bool $useAcl [optional] whether ACL
|
||||
* should be used. Default is
|
||||
* true.
|
||||
* @return Zend_View_Helper_Navigation_Helper fluent interface, returns
|
||||
* self
|
||||
*/
|
||||
public function setUseAcl($useAcl = true);
|
||||
|
||||
/**
|
||||
* Returns whether ACL should be used
|
||||
*
|
||||
* @return bool whether ACL should be used
|
||||
*/
|
||||
public function getUseAcl();
|
||||
|
||||
/**
|
||||
* Return renderInvisible flag
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getRenderInvisible();
|
||||
|
||||
/**
|
||||
* Render invisible items?
|
||||
*
|
||||
* @param bool $renderInvisible [optional] boolean flag
|
||||
* @return Zend_View_Helper_Navigation_HelperAbstract fluent interface
|
||||
* returns self
|
||||
*/
|
||||
public function setRenderInvisible($renderInvisible = true);
|
||||
|
||||
/**
|
||||
* Sets whether translator should be used
|
||||
*
|
||||
* @param bool $useTranslator [optional] whether
|
||||
* translator should be used.
|
||||
* Default is true.
|
||||
* @return Zend_View_Helper_Navigation_Helper fluent interface, returns
|
||||
* self
|
||||
*/
|
||||
public function setUseTranslator($useTranslator = true);
|
||||
|
||||
/**
|
||||
* Returns whether translator should be used
|
||||
*
|
||||
* @return bool whether translator should be used
|
||||
*/
|
||||
public function getUseTranslator();
|
||||
|
||||
/**
|
||||
* Checks if the helper has a container
|
||||
*
|
||||
* @return bool whether the helper has a container or not
|
||||
*/
|
||||
public function hasContainer();
|
||||
|
||||
/**
|
||||
* Checks if the helper has an ACL instance
|
||||
*
|
||||
* @return bool whether the helper has a an ACL instance or not
|
||||
*/
|
||||
public function hasAcl();
|
||||
|
||||
/**
|
||||
* Checks if the helper has an ACL role
|
||||
*
|
||||
* @return bool whether the helper has a an ACL role or not
|
||||
*/
|
||||
public function hasRole();
|
||||
|
||||
/**
|
||||
* Checks if the helper has a translator
|
||||
*
|
||||
* @return bool whether the helper has a translator or not
|
||||
*/
|
||||
public function hasTranslator();
|
||||
|
||||
/**
|
||||
* Magic overload: Should proxy to {@link render()}.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString();
|
||||
|
||||
/**
|
||||
* Renders helper
|
||||
*
|
||||
* @param Zend_Navigation_Container $container [optional] container to
|
||||
* render. Default is null,
|
||||
* which indicates that the
|
||||
* helper should render the
|
||||
* container returned by
|
||||
* {@link getContainer()}.
|
||||
* @return string helper output
|
||||
* @throws Zend_View_Exception if unable to render
|
||||
*/
|
||||
public function render(Zend_Navigation_Container $container = null);
|
||||
}
|
855
library/Zend/View/Helper/Navigation/HelperAbstract.php
Normal file
855
library/Zend/View/Helper/Navigation/HelperAbstract.php
Normal file
|
@ -0,0 +1,855 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: HelperAbstract.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_View_Helper_Navigation_Helper
|
||||
*/
|
||||
require_once 'Zend/View/Helper/Navigation/Helper.php';
|
||||
|
||||
/**
|
||||
* @see Zend_View_Helper_HtmlElement
|
||||
*/
|
||||
require_once 'Zend/View/Helper/HtmlElement.php';
|
||||
|
||||
/**
|
||||
* Base class for navigational helpers
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_View_Helper_Navigation_HelperAbstract
|
||||
extends Zend_View_Helper_HtmlElement
|
||||
implements Zend_View_Helper_Navigation_Helper
|
||||
{
|
||||
/**
|
||||
* Container to operate on by default
|
||||
*
|
||||
* @var Zend_Navigation_Container
|
||||
*/
|
||||
protected $_container;
|
||||
|
||||
/**
|
||||
* The minimum depth a page must have to be included when rendering
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_minDepth;
|
||||
|
||||
/**
|
||||
* The maximum depth a page can have to be included when rendering
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_maxDepth;
|
||||
|
||||
/**
|
||||
* Indentation string
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_indent = '';
|
||||
|
||||
/**
|
||||
* Translator
|
||||
*
|
||||
* @var Zend_Translate_Adapter
|
||||
*/
|
||||
protected $_translator;
|
||||
|
||||
/**
|
||||
* ACL to use when iterating pages
|
||||
*
|
||||
* @var Zend_Acl
|
||||
*/
|
||||
protected $_acl;
|
||||
|
||||
/**
|
||||
* Wheter invisible items should be rendered by this helper
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_renderInvisible = false;
|
||||
|
||||
/**
|
||||
* ACL role to use when iterating pages
|
||||
*
|
||||
* @var string|Zend_Acl_Role_Interface
|
||||
*/
|
||||
protected $_role;
|
||||
|
||||
/**
|
||||
* Whether translator should be used for page labels and titles
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_useTranslator = true;
|
||||
|
||||
/**
|
||||
* Whether ACL should be used for filtering out pages
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_useAcl = true;
|
||||
|
||||
/**
|
||||
* Default ACL to use when iterating pages if not explicitly set in the
|
||||
* instance by calling {@link setAcl()}
|
||||
*
|
||||
* @var Zend_Acl
|
||||
*/
|
||||
protected static $_defaultAcl;
|
||||
|
||||
/**
|
||||
* Default ACL role to use when iterating pages if not explicitly set in the
|
||||
* instance by calling {@link setRole()}
|
||||
*
|
||||
* @var string|Zend_Acl_Role_Interface
|
||||
*/
|
||||
protected static $_defaultRole;
|
||||
|
||||
// Accessors:
|
||||
|
||||
/**
|
||||
* Sets navigation container the helper operates on by default
|
||||
*
|
||||
* Implements {@link Zend_View_Helper_Navigation_Interface::setContainer()}.
|
||||
*
|
||||
* @param Zend_Navigation_Container $container [optional] container
|
||||
* to operate on.
|
||||
* Default is null,
|
||||
* meaning container
|
||||
* will be reset.
|
||||
* @return Zend_View_Helper_Navigation_HelperAbstract fluent interface,
|
||||
* returns self
|
||||
*/
|
||||
public function setContainer(Zend_Navigation_Container $container = null)
|
||||
{
|
||||
$this->_container = $container;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the navigation container helper operates on by default
|
||||
*
|
||||
* Implements {@link Zend_View_Helper_Navigation_Interface::getContainer()}.
|
||||
*
|
||||
* If a helper is not explicitly set in this helper instance by calling
|
||||
* {@link setContainer()} or by passing it through the helper entry point,
|
||||
* this method will look in {@link Zend_Registry} for a container by using
|
||||
* the key 'Zend_Navigation'.
|
||||
*
|
||||
* If no container is set, and nothing is found in Zend_Registry, a new
|
||||
* container will be instantiated and stored in the helper.
|
||||
*
|
||||
* @return Zend_Navigation_Container navigation container
|
||||
*/
|
||||
public function getContainer()
|
||||
{
|
||||
if (null === $this->_container) {
|
||||
// try to fetch from registry first
|
||||
require_once 'Zend/Registry.php';
|
||||
if (Zend_Registry::isRegistered('Zend_Navigation')) {
|
||||
$nav = Zend_Registry::get('Zend_Navigation');
|
||||
if ($nav instanceof Zend_Navigation_Container) {
|
||||
return $this->_container = $nav;
|
||||
}
|
||||
}
|
||||
|
||||
// nothing found in registry, create new container
|
||||
require_once 'Zend/Navigation.php';
|
||||
$this->_container = new Zend_Navigation();
|
||||
}
|
||||
|
||||
return $this->_container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the minimum depth a page must have to be included when rendering
|
||||
*
|
||||
* @param int $minDepth [optional] minimum
|
||||
* depth. Default is
|
||||
* null, which sets
|
||||
* no minimum depth.
|
||||
* @return Zend_View_Helper_Navigation_HelperAbstract fluent interface,
|
||||
* returns self
|
||||
*/
|
||||
public function setMinDepth($minDepth = null)
|
||||
{
|
||||
if (null === $minDepth || is_int($minDepth)) {
|
||||
$this->_minDepth = $minDepth;
|
||||
} else {
|
||||
$this->_minDepth = (int) $minDepth;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns minimum depth a page must have to be included when rendering
|
||||
*
|
||||
* @return int|null minimum depth or null
|
||||
*/
|
||||
public function getMinDepth()
|
||||
{
|
||||
if (!is_int($this->_minDepth) || $this->_minDepth < 0) {
|
||||
return 0;
|
||||
}
|
||||
return $this->_minDepth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the maximum depth a page can have to be included when rendering
|
||||
*
|
||||
* @param int $maxDepth [optional] maximum
|
||||
* depth. Default is
|
||||
* null, which sets no
|
||||
* maximum depth.
|
||||
* @return Zend_View_Helper_Navigation_HelperAbstract fluent interface,
|
||||
* returns self
|
||||
*/
|
||||
public function setMaxDepth($maxDepth = null)
|
||||
{
|
||||
if (null === $maxDepth || is_int($maxDepth)) {
|
||||
$this->_maxDepth = $maxDepth;
|
||||
} else {
|
||||
$this->_maxDepth = (int) $maxDepth;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns maximum depth a page can have to be included when rendering
|
||||
*
|
||||
* @return int|null maximum depth or null
|
||||
*/
|
||||
public function getMaxDepth()
|
||||
{
|
||||
return $this->_maxDepth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the indentation string for using in {@link render()}, optionally a
|
||||
* number of spaces to indent with
|
||||
*
|
||||
* @param string|int $indent indentation string or
|
||||
* number of spaces
|
||||
* @return Zend_View_Helper_Navigation_HelperAbstract fluent interface,
|
||||
* returns self
|
||||
*/
|
||||
public function setIndent($indent)
|
||||
{
|
||||
$this->_indent = $this->_getWhitespace($indent);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns indentation
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getIndent()
|
||||
{
|
||||
return $this->_indent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets translator to use in helper
|
||||
*
|
||||
* Implements {@link Zend_View_Helper_Navigation_Helper::setTranslator()}.
|
||||
*
|
||||
* @param mixed $translator [optional] translator.
|
||||
* Expects an object of
|
||||
* type
|
||||
* {@link Zend_Translate_Adapter}
|
||||
* or {@link Zend_Translate},
|
||||
* or null. Default is
|
||||
* null, which sets no
|
||||
* translator.
|
||||
* @return Zend_View_Helper_Navigation_HelperAbstract fluent interface,
|
||||
* returns self
|
||||
*/
|
||||
public function setTranslator($translator = null)
|
||||
{
|
||||
if (null == $translator ||
|
||||
$translator instanceof Zend_Translate_Adapter) {
|
||||
$this->_translator = $translator;
|
||||
} elseif ($translator instanceof Zend_Translate) {
|
||||
$this->_translator = $translator->getAdapter();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns translator used in helper
|
||||
*
|
||||
* Implements {@link Zend_View_Helper_Navigation_Helper::getTranslator()}.
|
||||
*
|
||||
* @return Zend_Translate_Adapter|null translator or null
|
||||
*/
|
||||
public function getTranslator()
|
||||
{
|
||||
if (null === $this->_translator) {
|
||||
require_once 'Zend/Registry.php';
|
||||
if (Zend_Registry::isRegistered('Zend_Translate')) {
|
||||
$this->setTranslator(Zend_Registry::get('Zend_Translate'));
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_translator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets ACL to use when iterating pages
|
||||
*
|
||||
* Implements {@link Zend_View_Helper_Navigation_Helper::setAcl()}.
|
||||
*
|
||||
* @param Zend_Acl $acl [optional] ACL object.
|
||||
* Default is null.
|
||||
* @return Zend_View_Helper_Navigation_HelperAbstract fluent interface,
|
||||
* returns self
|
||||
*/
|
||||
public function setAcl(Zend_Acl $acl = null)
|
||||
{
|
||||
$this->_acl = $acl;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns ACL or null if it isn't set using {@link setAcl()} or
|
||||
* {@link setDefaultAcl()}
|
||||
*
|
||||
* Implements {@link Zend_View_Helper_Navigation_Helper::getAcl()}.
|
||||
*
|
||||
* @return Zend_Acl|null ACL object or null
|
||||
*/
|
||||
public function getAcl()
|
||||
{
|
||||
if ($this->_acl === null && self::$_defaultAcl !== null) {
|
||||
return self::$_defaultAcl;
|
||||
}
|
||||
|
||||
return $this->_acl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets ACL role(s) to use when iterating pages
|
||||
*
|
||||
* Implements {@link Zend_View_Helper_Navigation_Helper::setRole()}.
|
||||
*
|
||||
* @param mixed $role [optional] role to
|
||||
* set. Expects a string,
|
||||
* an instance of type
|
||||
* {@link Zend_Acl_Role_Interface},
|
||||
* or null. Default is
|
||||
* null, which will set
|
||||
* no role.
|
||||
* @throws Zend_View_Exception if $role is invalid
|
||||
* @return Zend_View_Helper_Navigation_HelperAbstract fluent interface,
|
||||
* returns self
|
||||
*/
|
||||
public function setRole($role = null)
|
||||
{
|
||||
if (null === $role || is_string($role) ||
|
||||
$role instanceof Zend_Acl_Role_Interface) {
|
||||
$this->_role = $role;
|
||||
} else {
|
||||
require_once 'Zend/View/Exception.php';
|
||||
$e = new Zend_View_Exception(sprintf(
|
||||
'$role must be a string, null, or an instance of '
|
||||
. 'Zend_Acl_Role_Interface; %s given',
|
||||
gettype($role)
|
||||
));
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns ACL role to use when iterating pages, or null if it isn't set
|
||||
* using {@link setRole()} or {@link setDefaultRole()}
|
||||
*
|
||||
* Implements {@link Zend_View_Helper_Navigation_Helper::getRole()}.
|
||||
*
|
||||
* @return string|Zend_Acl_Role_Interface|null role or null
|
||||
*/
|
||||
public function getRole()
|
||||
{
|
||||
if ($this->_role === null && self::$_defaultRole !== null) {
|
||||
return self::$_defaultRole;
|
||||
}
|
||||
|
||||
return $this->_role;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether ACL should be used
|
||||
*
|
||||
* Implements {@link Zend_View_Helper_Navigation_Helper::setUseAcl()}.
|
||||
*
|
||||
* @param bool $useAcl [optional] whether ACL
|
||||
* should be used.
|
||||
* Default is true.
|
||||
* @return Zend_View_Helper_Navigation_HelperAbstract fluent interface,
|
||||
* returns self
|
||||
*/
|
||||
public function setUseAcl($useAcl = true)
|
||||
{
|
||||
$this->_useAcl = (bool) $useAcl;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether ACL should be used
|
||||
*
|
||||
* Implements {@link Zend_View_Helper_Navigation_Helper::getUseAcl()}.
|
||||
*
|
||||
* @return bool whether ACL should be used
|
||||
*/
|
||||
public function getUseAcl()
|
||||
{
|
||||
return $this->_useAcl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return renderInvisible flag
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getRenderInvisible()
|
||||
{
|
||||
return $this->_renderInvisible;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render invisible items?
|
||||
*
|
||||
* @param bool $renderInvisible [optional] boolean flag
|
||||
* @return Zend_View_Helper_Navigation_HelperAbstract fluent interface
|
||||
* returns self
|
||||
*/
|
||||
public function setRenderInvisible($renderInvisible = true)
|
||||
{
|
||||
$this->_renderInvisible = (bool) $renderInvisible;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether translator should be used
|
||||
*
|
||||
* Implements {@link Zend_View_Helper_Navigation_Helper::setUseTranslator()}.
|
||||
*
|
||||
* @param bool $useTranslator [optional] whether
|
||||
* translator should be
|
||||
* used. Default is true.
|
||||
* @return Zend_View_Helper_Navigation_HelperAbstract fluent interface,
|
||||
* returns self
|
||||
*/
|
||||
public function setUseTranslator($useTranslator = true)
|
||||
{
|
||||
$this->_useTranslator = (bool) $useTranslator;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether translator should be used
|
||||
*
|
||||
* Implements {@link Zend_View_Helper_Navigation_Helper::getUseTranslator()}.
|
||||
*
|
||||
* @return bool whether translator should be used
|
||||
*/
|
||||
public function getUseTranslator()
|
||||
{
|
||||
return $this->_useTranslator;
|
||||
}
|
||||
|
||||
// Magic overloads:
|
||||
|
||||
/**
|
||||
* Magic overload: Proxy calls to the navigation container
|
||||
*
|
||||
* @param string $method method name in container
|
||||
* @param array $arguments [optional] arguments to pass
|
||||
* @return mixed returns what the container returns
|
||||
* @throws Zend_Navigation_Exception if method does not exist in container
|
||||
*/
|
||||
public function __call($method, array $arguments = array())
|
||||
{
|
||||
return call_user_func_array(
|
||||
array($this->getContainer(), $method),
|
||||
$arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic overload: Proxy to {@link render()}.
|
||||
*
|
||||
* This method will trigger an E_USER_ERROR if rendering the helper causes
|
||||
* an exception to be thrown.
|
||||
*
|
||||
* Implements {@link Zend_View_Helper_Navigation_Helper::__toString()}.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
try {
|
||||
return $this->render();
|
||||
} catch (Exception $e) {
|
||||
$msg = get_class($e) . ': ' . $e->getMessage();
|
||||
trigger_error($msg, E_USER_ERROR);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
// Public methods:
|
||||
|
||||
/**
|
||||
* Finds the deepest active page in the given container
|
||||
*
|
||||
* @param Zend_Navigation_Container $container container to search
|
||||
* @param int|null $minDepth [optional] minimum depth
|
||||
* required for page to be
|
||||
* valid. Default is to use
|
||||
* {@link getMinDepth()}. A
|
||||
* null value means no minimum
|
||||
* depth required.
|
||||
* @param int|null $minDepth [optional] maximum depth
|
||||
* a page can have to be
|
||||
* valid. Default is to use
|
||||
* {@link getMaxDepth()}. A
|
||||
* null value means no maximum
|
||||
* depth required.
|
||||
* @return array an associative array with
|
||||
* the values 'depth' and
|
||||
* 'page', or an empty array
|
||||
* if not found
|
||||
*/
|
||||
public function findActive(Zend_Navigation_Container $container,
|
||||
$minDepth = null,
|
||||
$maxDepth = -1)
|
||||
{
|
||||
if (!is_int($minDepth)) {
|
||||
$minDepth = $this->getMinDepth();
|
||||
}
|
||||
if ((!is_int($maxDepth) || $maxDepth < 0) && null !== $maxDepth) {
|
||||
$maxDepth = $this->getMaxDepth();
|
||||
}
|
||||
|
||||
$found = null;
|
||||
$foundDepth = -1;
|
||||
$iterator = new RecursiveIteratorIterator($container,
|
||||
RecursiveIteratorIterator::CHILD_FIRST);
|
||||
|
||||
foreach ($iterator as $page) {
|
||||
$currDepth = $iterator->getDepth();
|
||||
if ($currDepth < $minDepth || !$this->accept($page)) {
|
||||
// page is not accepted
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($page->isActive(false) && $currDepth > $foundDepth) {
|
||||
// found an active page at a deeper level than before
|
||||
$found = $page;
|
||||
$foundDepth = $currDepth;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_int($maxDepth) && $foundDepth > $maxDepth) {
|
||||
while ($foundDepth > $maxDepth) {
|
||||
if (--$foundDepth < $minDepth) {
|
||||
$found = null;
|
||||
break;
|
||||
}
|
||||
|
||||
$found = $found->getParent();
|
||||
if (!$found instanceof Zend_Navigation_Page) {
|
||||
$found = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($found) {
|
||||
return array('page' => $found, 'depth' => $foundDepth);
|
||||
} else {
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the helper has a container
|
||||
*
|
||||
* Implements {@link Zend_View_Helper_Navigation_Helper::hasContainer()}.
|
||||
*
|
||||
* @return bool whether the helper has a container or not
|
||||
*/
|
||||
public function hasContainer()
|
||||
{
|
||||
return null !== $this->_container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the helper has an ACL instance
|
||||
*
|
||||
* Implements {@link Zend_View_Helper_Navigation_Helper::hasAcl()}.
|
||||
*
|
||||
* @return bool whether the helper has a an ACL instance or not
|
||||
*/
|
||||
public function hasAcl()
|
||||
{
|
||||
return null !== $this->_acl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the helper has an ACL role
|
||||
*
|
||||
* Implements {@link Zend_View_Helper_Navigation_Helper::hasRole()}.
|
||||
*
|
||||
* @return bool whether the helper has a an ACL role or not
|
||||
*/
|
||||
public function hasRole()
|
||||
{
|
||||
return null !== $this->_role;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the helper has a translator
|
||||
*
|
||||
* Implements {@link Zend_View_Helper_Navigation_Helper::hasTranslator()}.
|
||||
*
|
||||
* @return bool whether the helper has a translator or not
|
||||
*/
|
||||
public function hasTranslator()
|
||||
{
|
||||
return null !== $this->_translator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an HTML string containing an 'a' element for the given page
|
||||
*
|
||||
* @param Zend_Navigation_Page $page page to generate HTML for
|
||||
* @return string HTML string for the given page
|
||||
*/
|
||||
public function htmlify(Zend_Navigation_Page $page)
|
||||
{
|
||||
// get label and title for translating
|
||||
$label = $page->getLabel();
|
||||
$title = $page->getTitle();
|
||||
|
||||
if ($this->getUseTranslator() && $t = $this->getTranslator()) {
|
||||
if (is_string($label) && !empty($label)) {
|
||||
$label = $t->translate($label);
|
||||
}
|
||||
if (is_string($title) && !empty($title)) {
|
||||
$title = $t->translate($title);
|
||||
}
|
||||
}
|
||||
|
||||
// get attribs for anchor element
|
||||
$attribs = array(
|
||||
'id' => $page->getId(),
|
||||
'title' => $title,
|
||||
'class' => $page->getClass(),
|
||||
'href' => $page->getHref(),
|
||||
'target' => $page->getTarget()
|
||||
);
|
||||
|
||||
return '<a' . $this->_htmlAttribs($attribs) . '>'
|
||||
. $this->view->escape($label)
|
||||
. '</a>';
|
||||
}
|
||||
|
||||
// Iterator filter methods:
|
||||
|
||||
/**
|
||||
* Determines whether a page should be accepted when iterating
|
||||
*
|
||||
* Rules:
|
||||
* - If a page is not visible it is not accepted, unless RenderInvisible has
|
||||
* been set to true.
|
||||
* - If helper has no ACL, page is accepted
|
||||
* - If helper has ACL, but no role, page is not accepted
|
||||
* - If helper has ACL and role:
|
||||
* - Page is accepted if it has no resource or privilege
|
||||
* - Page is accepted if ACL allows page's resource or privilege
|
||||
* - If page is accepted by the rules above and $recursive is true, the page
|
||||
* will not be accepted if it is the descendant of a non-accepted page.
|
||||
*
|
||||
* @param Zend_Navigation_Page $page page to check
|
||||
* @param bool $recursive [optional] if true, page will not
|
||||
* be accepted if it is the
|
||||
* descendant of a page that is not
|
||||
* accepted. Default is true.
|
||||
* @return bool whether page should be accepted
|
||||
*/
|
||||
public function accept(Zend_Navigation_Page $page, $recursive = true)
|
||||
{
|
||||
// accept by default
|
||||
$accept = true;
|
||||
|
||||
if (!$page->isVisible(false) && !$this->getRenderInvisible()) {
|
||||
// don't accept invisible pages
|
||||
$accept = false;
|
||||
} elseif ($this->getUseAcl() && !$this->_acceptAcl($page)) {
|
||||
// acl is not amused
|
||||
$accept = false;
|
||||
}
|
||||
|
||||
if ($accept && $recursive) {
|
||||
$parent = $page->getParent();
|
||||
if ($parent instanceof Zend_Navigation_Page) {
|
||||
$accept = $this->accept($parent, true);
|
||||
}
|
||||
}
|
||||
|
||||
return $accept;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether a page should be accepted by ACL when iterating
|
||||
*
|
||||
* Rules:
|
||||
* - If helper has no ACL, page is accepted
|
||||
* - If page has a resource or privilege defined, page is accepted
|
||||
* if the ACL allows access to it using the helper's role
|
||||
* - If page has no resource or privilege, page is accepted
|
||||
*
|
||||
* @param Zend_Navigation_Page $page page to check
|
||||
* @return bool whether page is accepted by ACL
|
||||
*/
|
||||
protected function _acceptAcl(Zend_Navigation_Page $page)
|
||||
{
|
||||
if (!$acl = $this->getAcl()) {
|
||||
// no acl registered means don't use acl
|
||||
return true;
|
||||
}
|
||||
|
||||
$role = $this->getRole();
|
||||
$resource = $page->getResource();
|
||||
$privilege = $page->getPrivilege();
|
||||
|
||||
if ($resource || $privilege) {
|
||||
// determine using helper role and page resource/privilege
|
||||
return $acl->isAllowed($role, $resource, $privilege);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Util methods:
|
||||
|
||||
/**
|
||||
* Retrieve whitespace representation of $indent
|
||||
*
|
||||
* @param int|string $indent
|
||||
* @return string
|
||||
*/
|
||||
protected function _getWhitespace($indent)
|
||||
{
|
||||
if (is_int($indent)) {
|
||||
$indent = str_repeat(' ', $indent);
|
||||
}
|
||||
|
||||
return (string) $indent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an associative array to a string of tag attributes.
|
||||
*
|
||||
* Overloads {@link Zend_View_Helper_HtmlElement::_htmlAttribs()}.
|
||||
*
|
||||
* @param array $attribs an array where each key-value pair is converted
|
||||
* to an attribute name and value
|
||||
* @return string an attribute string
|
||||
*/
|
||||
protected function _htmlAttribs($attribs)
|
||||
{
|
||||
// filter out null values and empty string values
|
||||
foreach ($attribs as $key => $value) {
|
||||
if ($value === null || (is_string($value) && !strlen($value))) {
|
||||
unset($attribs[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
return parent::_htmlAttribs($attribs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize an ID
|
||||
*
|
||||
* Overrides {@link Zend_View_Helper_HtmlElement::_normalizeId()}.
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
protected function _normalizeId($value)
|
||||
{
|
||||
$prefix = get_class($this);
|
||||
$prefix = strtolower(trim(substr($prefix, strrpos($prefix, '_')), '_'));
|
||||
|
||||
return $prefix . '-' . $value;
|
||||
}
|
||||
|
||||
// Static methods:
|
||||
|
||||
/**
|
||||
* Sets default ACL to use if another ACL is not explicitly set
|
||||
*
|
||||
* @param Zend_Acl $acl [optional] ACL object. Default is null, which
|
||||
* sets no ACL object.
|
||||
* @return void
|
||||
*/
|
||||
public static function setDefaultAcl(Zend_Acl $acl = null)
|
||||
{
|
||||
self::$_defaultAcl = $acl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets default ACL role(s) to use when iterating pages if not explicitly
|
||||
* set later with {@link setRole()}
|
||||
*
|
||||
* @param midex $role [optional] role to set. Expects null,
|
||||
* string, or an instance of
|
||||
* {@link Zend_Acl_Role_Interface}.
|
||||
* Default is null, which sets no default
|
||||
* role.
|
||||
* @throws Zend_View_Exception if role is invalid
|
||||
* @return void
|
||||
*/
|
||||
public static function setDefaultRole($role = null)
|
||||
{
|
||||
if (null === $role ||
|
||||
is_string($role) ||
|
||||
$role instanceof Zend_Acl_Role_Interface) {
|
||||
self::$_defaultRole = $role;
|
||||
} else {
|
||||
require_once 'Zend/View/Exception.php';
|
||||
throw new Zend_View_Exception(
|
||||
'$role must be null|string|Zend_Acl_Role_Interface'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
783
library/Zend/View/Helper/Navigation/Links.php
Normal file
783
library/Zend/View/Helper/Navigation/Links.php
Normal file
|
@ -0,0 +1,783 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Links.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_View_Helper_Navigation_HelperAbstract
|
||||
*/
|
||||
require_once 'Zend/View/Helper/Navigation/HelperAbstract.php';
|
||||
|
||||
/**
|
||||
* Helper for printing <link> elements
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_Navigation_Links
|
||||
extends Zend_View_Helper_Navigation_HelperAbstract
|
||||
{
|
||||
/**#@+
|
||||
* Constants used for specifying which link types to find and render
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const RENDER_ALTERNATE = 0x0001;
|
||||
const RENDER_STYLESHEET = 0x0002;
|
||||
const RENDER_START = 0x0004;
|
||||
const RENDER_NEXT = 0x0008;
|
||||
const RENDER_PREV = 0x0010;
|
||||
const RENDER_CONTENTS = 0x0020;
|
||||
const RENDER_INDEX = 0x0040;
|
||||
const RENDER_GLOSSARY = 0x0080;
|
||||
const RENDER_COPYRIGHT = 0x0100;
|
||||
const RENDER_CHAPTER = 0x0200;
|
||||
const RENDER_SECTION = 0x0400;
|
||||
const RENDER_SUBSECTION = 0x0800;
|
||||
const RENDER_APPENDIX = 0x1000;
|
||||
const RENDER_HELP = 0x2000;
|
||||
const RENDER_BOOKMARK = 0x4000;
|
||||
const RENDER_CUSTOM = 0x8000;
|
||||
const RENDER_ALL = 0xffff;
|
||||
/**#@+**/
|
||||
|
||||
/**
|
||||
* Maps render constants to W3C link types
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $_RELATIONS = array(
|
||||
self::RENDER_ALTERNATE => 'alternate',
|
||||
self::RENDER_STYLESHEET => 'stylesheet',
|
||||
self::RENDER_START => 'start',
|
||||
self::RENDER_NEXT => 'next',
|
||||
self::RENDER_PREV => 'prev',
|
||||
self::RENDER_CONTENTS => 'contents',
|
||||
self::RENDER_INDEX => 'index',
|
||||
self::RENDER_GLOSSARY => 'glossary',
|
||||
self::RENDER_COPYRIGHT => 'copyright',
|
||||
self::RENDER_CHAPTER => 'chapter',
|
||||
self::RENDER_SECTION => 'section',
|
||||
self::RENDER_SUBSECTION => 'subsection',
|
||||
self::RENDER_APPENDIX => 'appendix',
|
||||
self::RENDER_HELP => 'help',
|
||||
self::RENDER_BOOKMARK => 'bookmark'
|
||||
);
|
||||
|
||||
/**
|
||||
* The helper's render flag
|
||||
*
|
||||
* @see render()
|
||||
* @see setRenderFlag()
|
||||
* @var int
|
||||
*/
|
||||
protected $_renderFlag = self::RENDER_ALL;
|
||||
|
||||
/**
|
||||
* Root container
|
||||
*
|
||||
* Used for preventing methods to traverse above the container given to
|
||||
* the {@link render()} method.
|
||||
*
|
||||
* @see _findRoot()
|
||||
*
|
||||
* @var Zend_Navigation_Container
|
||||
*/
|
||||
protected $_root;
|
||||
|
||||
/**
|
||||
* View helper entry point:
|
||||
* Retrieves helper and optionally sets container to operate on
|
||||
*
|
||||
* @param Zend_Navigation_Container $container [optional] container to
|
||||
* operate on
|
||||
* @return Zend_View_Helper_Navigation_Links fluent interface, returns
|
||||
* self
|
||||
*/
|
||||
public function links(Zend_Navigation_Container $container = null)
|
||||
{
|
||||
if (null !== $container) {
|
||||
$this->setContainer($container);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic overload: Proxy calls to {@link findRelation()} or container
|
||||
*
|
||||
* Examples of finder calls:
|
||||
* <code>
|
||||
* // METHOD // SAME AS
|
||||
* $h->findRelNext($page); // $h->findRelation($page, 'rel', 'next')
|
||||
* $h->findRevSection($page); // $h->findRelation($page, 'rev', 'section');
|
||||
* $h->findRelFoo($page); // $h->findRelation($page, 'rel', 'foo');
|
||||
* </code>
|
||||
*
|
||||
* @param string $method method name
|
||||
* @param array $arguments method arguments
|
||||
* @throws Zend_Navigation_Exception if method does not exist in container
|
||||
*/
|
||||
public function __call($method, array $arguments = array())
|
||||
{
|
||||
if (@preg_match('/find(Rel|Rev)(.+)/', $method, $match)) {
|
||||
return $this->findRelation($arguments[0],
|
||||
strtolower($match[1]),
|
||||
strtolower($match[2]));
|
||||
}
|
||||
|
||||
return parent::__call($method, $arguments);
|
||||
}
|
||||
|
||||
// Accessors:
|
||||
|
||||
/**
|
||||
* Sets the helper's render flag
|
||||
*
|
||||
* The helper uses the bitwise '&' operator against the hex values of the
|
||||
* render constants. This means that the flag can is "bitwised" value of
|
||||
* the render constants. Examples:
|
||||
* <code>
|
||||
* // render all links except glossary
|
||||
* $flag = Zend_View_Helper_Navigation_Links:RENDER_ALL ^
|
||||
* Zend_View_Helper_Navigation_Links:RENDER_GLOSSARY;
|
||||
* $helper->setRenderFlag($flag);
|
||||
*
|
||||
* // render only chapters and sections
|
||||
* $flag = Zend_View_Helper_Navigation_Links:RENDER_CHAPTER |
|
||||
* Zend_View_Helper_Navigation_Links:RENDER_SECTION;
|
||||
* $helper->setRenderFlag($flag);
|
||||
*
|
||||
* // render only relations that are not native W3C relations
|
||||
* $helper->setRenderFlag(Zend_View_Helper_Navigation_Links:RENDER_CUSTOM);
|
||||
*
|
||||
* // render all relations (default)
|
||||
* $helper->setRenderFlag(Zend_View_Helper_Navigation_Links:RENDER_ALL);
|
||||
* </code>
|
||||
*
|
||||
* Note that custom relations can also be rendered directly using the
|
||||
* {@link renderLink()} method.
|
||||
*
|
||||
* @param int $renderFlag render flag
|
||||
* @return Zend_View_Helper_Navigation_Links fluent interface, returns self
|
||||
*/
|
||||
public function setRenderFlag($renderFlag)
|
||||
{
|
||||
$this->_renderFlag = (int) $renderFlag;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the helper's render flag
|
||||
*
|
||||
* @return int render flag
|
||||
*/
|
||||
public function getRenderFlag()
|
||||
{
|
||||
return $this->_renderFlag;
|
||||
}
|
||||
|
||||
// Finder methods:
|
||||
|
||||
/**
|
||||
* Finds all relations (forward and reverse) for the given $page
|
||||
*
|
||||
* The form of the returned array:
|
||||
* <code>
|
||||
* // $page denotes an instance of Zend_Navigation_Page
|
||||
* $returned = array(
|
||||
* 'rel' => array(
|
||||
* 'alternate' => array($page, $page, $page),
|
||||
* 'start' => array($page),
|
||||
* 'next' => array($page),
|
||||
* 'prev' => array($page),
|
||||
* 'canonical' => array($page)
|
||||
* ),
|
||||
* 'rev' => array(
|
||||
* 'section' => array($page)
|
||||
* )
|
||||
* );
|
||||
* </code>
|
||||
*
|
||||
* @param Zend_Navigation_Page $page page to find links for
|
||||
* @return array related pages
|
||||
*/
|
||||
public function findAllRelations(Zend_Navigation_Page $page,
|
||||
$flag = null)
|
||||
{
|
||||
if (!is_int($flag)) {
|
||||
$flag = self::RENDER_ALL;
|
||||
}
|
||||
|
||||
$result = array('rel' => array(), 'rev' => array());
|
||||
$native = array_values(self::$_RELATIONS);
|
||||
|
||||
foreach (array_keys($result) as $rel) {
|
||||
$meth = 'getDefined' . ucfirst($rel);
|
||||
$types = array_merge($native, array_diff($page->$meth(), $native));
|
||||
|
||||
foreach ($types as $type) {
|
||||
if (!$relFlag = array_search($type, self::$_RELATIONS)) {
|
||||
$relFlag = self::RENDER_CUSTOM;
|
||||
}
|
||||
if (!($flag & $relFlag)) {
|
||||
continue;
|
||||
}
|
||||
if ($found = $this->findRelation($page, $rel, $type)) {
|
||||
if (!is_array($found)) {
|
||||
$found = array($found);
|
||||
}
|
||||
$result[$rel][$type] = $found;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds relations of the given $rel=$type from $page
|
||||
*
|
||||
* This method will first look for relations in the page instance, then
|
||||
* by searching the root container if nothing was found in the page.
|
||||
*
|
||||
* @param Zend_Navigation_Page $page page to find relations for
|
||||
* @param string $rel relation, "rel" or "rev"
|
||||
* @param string $type link type, e.g. 'start', 'next'
|
||||
* @return Zend_Navigaiton_Page|array|null page(s), or null if not found
|
||||
* @throws Zend_View_Exception if $rel is not "rel" or "rev"
|
||||
*/
|
||||
public function findRelation(Zend_Navigation_Page $page, $rel, $type)
|
||||
{
|
||||
if (!in_array($rel, array('rel', 'rev'))) {
|
||||
require_once 'Zend/View/Exception.php';
|
||||
$e = new Zend_View_Exception(sprintf(
|
||||
'Invalid argument: $rel must be "rel" or "rev"; "%s" given',
|
||||
$rel));
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
if (!$result = $this->_findFromProperty($page, $rel, $type)) {
|
||||
$result = $this->_findFromSearch($page, $rel, $type);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds relations of given $type for $page by checking if the
|
||||
* relation is specified as a property of $page
|
||||
*
|
||||
* @param Zend_Navigation_Page $page page to find relations for
|
||||
* @param string $rel relation, 'rel' or 'rev'
|
||||
* @param string $type link type, e.g. 'start', 'next'
|
||||
* @return Zend_Navigation_Page|array|null page(s), or null if not found
|
||||
*/
|
||||
protected function _findFromProperty(Zend_Navigation_Page $page, $rel, $type)
|
||||
{
|
||||
$method = 'get' . ucfirst($rel);
|
||||
if ($result = $page->$method($type)) {
|
||||
if ($result = $this->_convertToPages($result)) {
|
||||
if (!is_array($result)) {
|
||||
$result = array($result);
|
||||
}
|
||||
|
||||
foreach ($result as $key => $page) {
|
||||
if (!$this->accept($page)) {
|
||||
unset($result[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
return count($result) == 1 ? $result[0] : $result;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds relations of given $rel=$type for $page by using the helper to
|
||||
* search for the relation in the root container
|
||||
*
|
||||
* @param Zend_Navigation_Page $page page to find relations for
|
||||
* @param string $rel relation, 'rel' or 'rev'
|
||||
* @param string $type link type, e.g. 'start', 'next', etc
|
||||
* @return array|null array of pages, or null if not found
|
||||
*/
|
||||
protected function _findFromSearch(Zend_Navigation_Page $page, $rel, $type)
|
||||
{
|
||||
$found = null;
|
||||
|
||||
$method = 'search' . ucfirst($rel) . ucfirst($type);
|
||||
if (method_exists($this, $method)) {
|
||||
$found = $this->$method($page);
|
||||
}
|
||||
|
||||
return $found;
|
||||
}
|
||||
|
||||
// Search methods:
|
||||
|
||||
/**
|
||||
* Searches the root container for the forward 'start' relation of the given
|
||||
* $page
|
||||
*
|
||||
* From {@link http://www.w3.org/TR/html4/types.html#type-links}:
|
||||
* Refers to the first document in a collection of documents. This link type
|
||||
* tells search engines which document is considered by the author to be the
|
||||
* starting point of the collection.
|
||||
*
|
||||
* @param Zend_Navigation_Page $page page to find relation for
|
||||
* @return Zend_Navigation_Page|null page or null
|
||||
*/
|
||||
public function searchRelStart(Zend_Navigation_Page $page)
|
||||
{
|
||||
$found = $this->_findRoot($page);
|
||||
if (!$found instanceof Zend_Navigation_Page) {
|
||||
$found->rewind();
|
||||
$found = $found->current();
|
||||
}
|
||||
|
||||
if ($found === $page || !$this->accept($found)) {
|
||||
$found = null;
|
||||
}
|
||||
|
||||
return $found;
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches the root container for the forward 'next' relation of the given
|
||||
* $page
|
||||
*
|
||||
* From {@link http://www.w3.org/TR/html4/types.html#type-links}:
|
||||
* Refers to the next document in a linear sequence of documents. User
|
||||
* agents may choose to preload the "next" document, to reduce the perceived
|
||||
* load time.
|
||||
*
|
||||
* @param Zend_Navigation_Page $page page to find relation for
|
||||
* @return Zend_Navigation_Page|null page(s) or null
|
||||
*/
|
||||
public function searchRelNext(Zend_Navigation_Page $page)
|
||||
{
|
||||
$found = null;
|
||||
$break = false;
|
||||
$iterator = new RecursiveIteratorIterator($this->_findRoot($page),
|
||||
RecursiveIteratorIterator::SELF_FIRST);
|
||||
foreach ($iterator as $intermediate) {
|
||||
if ($intermediate === $page) {
|
||||
// current page; break at next accepted page
|
||||
$break = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($break && $this->accept($intermediate)) {
|
||||
$found = $intermediate;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $found;
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches the root container for the forward 'prev' relation of the given
|
||||
* $page
|
||||
*
|
||||
* From {@link http://www.w3.org/TR/html4/types.html#type-links}:
|
||||
* Refers to the previous document in an ordered series of documents. Some
|
||||
* user agents also support the synonym "Previous".
|
||||
*
|
||||
* @param Zend_Navigation_Page $page page to find relation for
|
||||
* @return Zend_Navigation_Page|null page or null
|
||||
*/
|
||||
public function searchRelPrev(Zend_Navigation_Page $page)
|
||||
{
|
||||
$found = null;
|
||||
$prev = null;
|
||||
$iterator = new RecursiveIteratorIterator(
|
||||
$this->_findRoot($page),
|
||||
RecursiveIteratorIterator::SELF_FIRST);
|
||||
foreach ($iterator as $intermediate) {
|
||||
if (!$this->accept($intermediate)) {
|
||||
continue;
|
||||
}
|
||||
if ($intermediate === $page) {
|
||||
$found = $prev;
|
||||
break;
|
||||
}
|
||||
|
||||
$prev = $intermediate;
|
||||
}
|
||||
|
||||
return $found;
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches the root container for forward 'chapter' relations of the given
|
||||
* $page
|
||||
*
|
||||
* From {@link http://www.w3.org/TR/html4/types.html#type-links}:
|
||||
* Refers to a document serving as a chapter in a collection of documents.
|
||||
*
|
||||
* @param Zend_Navigation_Page $page page to find relation for
|
||||
* @return Zend_Navigation_Page|array|null page(s) or null
|
||||
*/
|
||||
public function searchRelChapter(Zend_Navigation_Page $page)
|
||||
{
|
||||
$found = array();
|
||||
|
||||
// find first level of pages
|
||||
$root = $this->_findRoot($page);
|
||||
|
||||
// find start page(s)
|
||||
$start = $this->findRelation($page, 'rel', 'start');
|
||||
if (!is_array($start)) {
|
||||
$start = array($start);
|
||||
}
|
||||
|
||||
foreach ($root as $chapter) {
|
||||
// exclude self and start page from chapters
|
||||
if ($chapter !== $page &&
|
||||
!in_array($chapter, $start) &&
|
||||
$this->accept($chapter)) {
|
||||
$found[] = $chapter;
|
||||
}
|
||||
}
|
||||
|
||||
switch (count($found)) {
|
||||
case 0:
|
||||
return null;
|
||||
case 1:
|
||||
return $found[0];
|
||||
default:
|
||||
return $found;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches the root container for forward 'section' relations of the given
|
||||
* $page
|
||||
*
|
||||
* From {@link http://www.w3.org/TR/html4/types.html#type-links}:
|
||||
* Refers to a document serving as a section in a collection of documents.
|
||||
*
|
||||
* @param Zend_Navigation_Page $page page to find relation for
|
||||
* @return Zend_Navigation_Page|array|null page(s) or null
|
||||
*/
|
||||
public function searchRelSection(Zend_Navigation_Page $page)
|
||||
{
|
||||
$found = array();
|
||||
|
||||
// check if given page has pages and is a chapter page
|
||||
if ($page->hasPages() && $this->_findRoot($page)->hasPage($page)) {
|
||||
foreach ($page as $section) {
|
||||
if ($this->accept($section)) {
|
||||
$found[] = $section;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch (count($found)) {
|
||||
case 0:
|
||||
return null;
|
||||
case 1:
|
||||
return $found[0];
|
||||
default:
|
||||
return $found;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches the root container for forward 'subsection' relations of the
|
||||
* given $page
|
||||
*
|
||||
* From {@link http://www.w3.org/TR/html4/types.html#type-links}:
|
||||
* Refers to a document serving as a subsection in a collection of
|
||||
* documents.
|
||||
*
|
||||
* @param Zend_Navigation_Page $page page to find relation for
|
||||
* @return Zend_Navigation_Page|array|null page(s) or null
|
||||
*/
|
||||
public function searchRelSubsection(Zend_Navigation_Page $page)
|
||||
{
|
||||
$found = array();
|
||||
|
||||
if ($page->hasPages()) {
|
||||
// given page has child pages, loop chapters
|
||||
foreach ($this->_findRoot($page) as $chapter) {
|
||||
// is page a section?
|
||||
if ($chapter->hasPage($page)) {
|
||||
foreach ($page as $subsection) {
|
||||
if ($this->accept($subsection)) {
|
||||
$found[] = $subsection;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch (count($found)) {
|
||||
case 0:
|
||||
return null;
|
||||
case 1:
|
||||
return $found[0];
|
||||
default:
|
||||
return $found;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches the root container for the reverse 'section' relation of the
|
||||
* given $page
|
||||
*
|
||||
* From {@link http://www.w3.org/TR/html4/types.html#type-links}:
|
||||
* Refers to a document serving as a section in a collection of documents.
|
||||
*
|
||||
* @param Zend_Navigation_Page $page page to find relation for
|
||||
* @return Zend_Navigation_Page|null page(s) or null
|
||||
*/
|
||||
public function searchRevSection(Zend_Navigation_Page $page)
|
||||
{
|
||||
$found = null;
|
||||
|
||||
if ($parent = $page->getParent()) {
|
||||
if ($parent instanceof Zend_Navigation_Page &&
|
||||
$this->_findRoot($page)->hasPage($parent)) {
|
||||
$found = $parent;
|
||||
}
|
||||
}
|
||||
|
||||
return $found;
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches the root container for the reverse 'section' relation of the
|
||||
* given $page
|
||||
*
|
||||
* From {@link http://www.w3.org/TR/html4/types.html#type-links}:
|
||||
* Refers to a document serving as a subsection in a collection of
|
||||
* documents.
|
||||
*
|
||||
* @param Zend_Navigation_Page $page page to find relation for
|
||||
* @return Zend_Navigation_Page|null page(s) or null
|
||||
*/
|
||||
public function searchRevSubsection(Zend_Navigation_Page $page)
|
||||
{
|
||||
$found = null;
|
||||
|
||||
if ($parent = $page->getParent()) {
|
||||
if ($parent instanceof Zend_Navigation_Page) {
|
||||
$root = $this->_findRoot($page);
|
||||
foreach ($root as $chapter) {
|
||||
if ($chapter->hasPage($parent)) {
|
||||
$found = $parent;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $found;
|
||||
}
|
||||
|
||||
// Util methods:
|
||||
|
||||
/**
|
||||
* Returns the root container of the given page
|
||||
*
|
||||
* When rendering a container, the render method still store the given
|
||||
* container as the root container, and unset it when done rendering. This
|
||||
* makes sure finder methods will not traverse above the container given
|
||||
* to the render method.
|
||||
*
|
||||
* @param Zend_Navigaiton_Page $page page to find root for
|
||||
* @return Zend_Navigation_Container the root container of the given page
|
||||
*/
|
||||
protected function _findRoot(Zend_Navigation_Page $page)
|
||||
{
|
||||
if ($this->_root) {
|
||||
return $this->_root;
|
||||
}
|
||||
|
||||
$root = $page;
|
||||
|
||||
while ($parent = $page->getParent()) {
|
||||
$root = $parent;
|
||||
if ($parent instanceof Zend_Navigation_Page) {
|
||||
$page = $parent;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $root;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a $mixed value to an array of pages
|
||||
*
|
||||
* @param mixed $mixed mixed value to get page(s) from
|
||||
* @param bool $recursive whether $value should be looped
|
||||
* if it is an array or a config
|
||||
* @return Zend_Navigation_Page|array|null empty if unable to convert
|
||||
*/
|
||||
protected function _convertToPages($mixed, $recursive = true)
|
||||
{
|
||||
if (is_object($mixed)) {
|
||||
if ($mixed instanceof Zend_Navigation_Page) {
|
||||
// value is a page instance; return directly
|
||||
return $mixed;
|
||||
} elseif ($mixed instanceof Zend_Navigation_Container) {
|
||||
// value is a container; return pages in it
|
||||
$pages = array();
|
||||
foreach ($mixed as $page) {
|
||||
$pages[] = $page;
|
||||
}
|
||||
return $pages;
|
||||
} elseif ($mixed instanceof Zend_Config) {
|
||||
// convert config object to array and extract
|
||||
return $this->_convertToPages($mixed->toArray(), $recursive);
|
||||
}
|
||||
} elseif (is_string($mixed)) {
|
||||
// value is a string; make an URI page
|
||||
return Zend_Navigation_Page::factory(array(
|
||||
'type' => 'uri',
|
||||
'uri' => $mixed
|
||||
));
|
||||
} elseif (is_array($mixed) && !empty($mixed)) {
|
||||
if ($recursive && is_numeric(key($mixed))) {
|
||||
// first key is numeric; assume several pages
|
||||
$pages = array();
|
||||
foreach ($mixed as $value) {
|
||||
if ($value = $this->_convertToPages($value, false)) {
|
||||
$pages[] = $value;
|
||||
}
|
||||
}
|
||||
return $pages;
|
||||
} else {
|
||||
// pass array to factory directly
|
||||
try {
|
||||
$page = Zend_Navigation_Page::factory($mixed);
|
||||
return $page;
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// nothing found
|
||||
return null;
|
||||
}
|
||||
|
||||
// Render methods:
|
||||
|
||||
/**
|
||||
* Renders the given $page as a link element, with $attrib = $relation
|
||||
*
|
||||
* @param Zend_Navigation_Page $page the page to render the link for
|
||||
* @param string $attrib the attribute to use for $type,
|
||||
* either 'rel' or 'rev'
|
||||
* @param string $relation relation type, muse be one of;
|
||||
* alternate, appendix, bookmark,
|
||||
* chapter, contents, copyright,
|
||||
* glossary, help, home, index, next,
|
||||
* prev, section, start, stylesheet,
|
||||
* subsection
|
||||
* @return string rendered link element
|
||||
* @throws Zend_View_Exception if $attrib is invalid
|
||||
*/
|
||||
public function renderLink(Zend_Navigation_Page $page, $attrib, $relation)
|
||||
{
|
||||
if (!in_array($attrib, array('rel', 'rev'))) {
|
||||
require_once 'Zend/View/Exception.php';
|
||||
$e = new Zend_View_Exception(sprintf(
|
||||
'Invalid relation attribute "%s", must be "rel" or "rev"',
|
||||
$attrib));
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
if (!$href = $page->getHref()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// TODO: add more attribs
|
||||
// http://www.w3.org/TR/html401/struct/links.html#h-12.2
|
||||
$attribs = array(
|
||||
$attrib => $relation,
|
||||
'href' => $href,
|
||||
'title' => $page->getLabel()
|
||||
);
|
||||
|
||||
return '<link' .
|
||||
$this->_htmlAttribs($attribs) .
|
||||
$this->getClosingBracket();
|
||||
}
|
||||
|
||||
// Zend_View_Helper_Navigation_Helper:
|
||||
|
||||
/**
|
||||
* Renders helper
|
||||
*
|
||||
* Implements {@link Zend_View_Helper_Navigation_Helper::render()}.
|
||||
*
|
||||
* @param Zend_Navigation_Container $container [optional] container to
|
||||
* render. Default is to
|
||||
* render the container
|
||||
* registered in the helper.
|
||||
* @return string helper output
|
||||
*/
|
||||
public function render(Zend_Navigation_Container $container = null)
|
||||
{
|
||||
if (null === $container) {
|
||||
$container = $this->getContainer();
|
||||
}
|
||||
|
||||
if ($active = $this->findActive($container)) {
|
||||
$active = $active['page'];
|
||||
} else {
|
||||
// no active page
|
||||
return '';
|
||||
}
|
||||
|
||||
$output = '';
|
||||
$indent = $this->getIndent();
|
||||
$this->_root = $container;
|
||||
|
||||
$result = $this->findAllRelations($active, $this->getRenderFlag());
|
||||
foreach ($result as $attrib => $types) {
|
||||
foreach ($types as $relation => $pages) {
|
||||
foreach ($pages as $page) {
|
||||
if ($r = $this->renderLink($page, $attrib, $relation)) {
|
||||
$output .= $indent . $r . self::EOL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->_root = null;
|
||||
|
||||
// return output (trim last newline by spec)
|
||||
return strlen($output) ? rtrim($output, self::EOL) : '';
|
||||
}
|
||||
}
|
647
library/Zend/View/Helper/Navigation/Menu.php
Normal file
647
library/Zend/View/Helper/Navigation/Menu.php
Normal file
|
@ -0,0 +1,647 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Menu.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_View_Helper_Navigation_HelperAbstract
|
||||
*/
|
||||
require_once 'Zend/View/Helper/Navigation/HelperAbstract.php';
|
||||
|
||||
/**
|
||||
* Helper for rendering menus from navigation containers
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_Navigation_Menu
|
||||
extends Zend_View_Helper_Navigation_HelperAbstract
|
||||
{
|
||||
/**
|
||||
* CSS class to use for the ul element
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_ulClass = 'navigation';
|
||||
|
||||
/**
|
||||
* Whether only active branch should be rendered
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_onlyActiveBranch = false;
|
||||
|
||||
/**
|
||||
* Whether parents should be rendered when only rendering active branch
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_renderParents = true;
|
||||
|
||||
/**
|
||||
* Partial view script to use for rendering menu
|
||||
*
|
||||
* @var string|array
|
||||
*/
|
||||
protected $_partial = null;
|
||||
|
||||
/**
|
||||
* View helper entry point:
|
||||
* Retrieves helper and optionally sets container to operate on
|
||||
*
|
||||
* @param Zend_Navigation_Container $container [optional] container to
|
||||
* operate on
|
||||
* @return Zend_View_Helper_Navigation_Menu fluent interface,
|
||||
* returns self
|
||||
*/
|
||||
public function menu(Zend_Navigation_Container $container = null)
|
||||
{
|
||||
if (null !== $container) {
|
||||
$this->setContainer($container);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
// Accessors:
|
||||
|
||||
/**
|
||||
* Sets CSS class to use for the first 'ul' element when rendering
|
||||
*
|
||||
* @param string $ulClass CSS class to set
|
||||
* @return Zend_View_Helper_Navigation_Menu fluent interface, returns self
|
||||
*/
|
||||
public function setUlClass($ulClass)
|
||||
{
|
||||
if (is_string($ulClass)) {
|
||||
$this->_ulClass = $ulClass;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns CSS class to use for the first 'ul' element when rendering
|
||||
*
|
||||
* @return string CSS class
|
||||
*/
|
||||
public function getUlClass()
|
||||
{
|
||||
return $this->_ulClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a flag indicating whether only active branch should be rendered
|
||||
*
|
||||
* @param bool $flag [optional] render only active
|
||||
* branch. Default is true.
|
||||
* @return Zend_View_Helper_Navigation_Menu fluent interface, returns self
|
||||
*/
|
||||
public function setOnlyActiveBranch($flag = true)
|
||||
{
|
||||
$this->_onlyActiveBranch = (bool) $flag;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a flag indicating whether only active branch should be rendered
|
||||
*
|
||||
* By default, this value is false, meaning the entire menu will be
|
||||
* be rendered.
|
||||
*
|
||||
* @return bool whether only active branch should be rendered
|
||||
*/
|
||||
public function getOnlyActiveBranch()
|
||||
{
|
||||
return $this->_onlyActiveBranch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables/disables rendering of parents when only rendering active branch
|
||||
*
|
||||
* See {@link setOnlyActiveBranch()} for more information.
|
||||
*
|
||||
* @param bool $flag [optional] render parents when
|
||||
* rendering active branch.
|
||||
* Default is true.
|
||||
* @return Zend_View_Helper_Navigation_Menu fluent interface, returns self
|
||||
*/
|
||||
public function setRenderParents($flag = true)
|
||||
{
|
||||
$this->_renderParents = (bool) $flag;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns flag indicating whether parents should be rendered when rendering
|
||||
* only the active branch
|
||||
*
|
||||
* By default, this value is true.
|
||||
*
|
||||
* @return bool whether parents should be rendered
|
||||
*/
|
||||
public function getRenderParents()
|
||||
{
|
||||
return $this->_renderParents;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets which partial view script to use for rendering menu
|
||||
*
|
||||
* @param string|array $partial partial view script or null. If
|
||||
* an array is given, it is
|
||||
* expected to contain two values;
|
||||
* the partial view script to use,
|
||||
* and the module where the script
|
||||
* can be found.
|
||||
* @return Zend_View_Helper_Navigation_Menu fluent interface, returns self
|
||||
*/
|
||||
public function setPartial($partial)
|
||||
{
|
||||
if (null === $partial || is_string($partial) || is_array($partial)) {
|
||||
$this->_partial = $partial;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns partial view script to use for rendering menu
|
||||
*
|
||||
* @return string|array|null
|
||||
*/
|
||||
public function getPartial()
|
||||
{
|
||||
return $this->_partial;
|
||||
}
|
||||
|
||||
// Public methods:
|
||||
|
||||
/**
|
||||
* Returns an HTML string containing an 'a' element for the given page if
|
||||
* the page's href is not empty, and a 'span' element if it is empty
|
||||
*
|
||||
* Overrides {@link Zend_View_Helper_Navigation_Abstract::htmlify()}.
|
||||
*
|
||||
* @param Zend_Navigation_Page $page page to generate HTML for
|
||||
* @return string HTML string for the given page
|
||||
*/
|
||||
public function htmlify(Zend_Navigation_Page $page)
|
||||
{
|
||||
// get label and title for translating
|
||||
$label = $page->getLabel();
|
||||
$title = $page->getTitle();
|
||||
|
||||
// translate label and title?
|
||||
if ($this->getUseTranslator() && $t = $this->getTranslator()) {
|
||||
if (is_string($label) && !empty($label)) {
|
||||
$label = $t->translate($label);
|
||||
}
|
||||
if (is_string($title) && !empty($title)) {
|
||||
$title = $t->translate($title);
|
||||
}
|
||||
}
|
||||
|
||||
// get attribs for element
|
||||
$attribs = array(
|
||||
'id' => $page->getId(),
|
||||
'title' => $title,
|
||||
'class' => $page->getClass()
|
||||
);
|
||||
|
||||
// does page have a href?
|
||||
if ($href = $page->getHref()) {
|
||||
$element = 'a';
|
||||
$attribs['href'] = $href;
|
||||
$attribs['target'] = $page->getTarget();
|
||||
} else {
|
||||
$element = 'span';
|
||||
}
|
||||
|
||||
return '<' . $element . $this->_htmlAttribs($attribs) . '>'
|
||||
. $this->view->escape($label)
|
||||
. '</' . $element . '>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes given render options
|
||||
*
|
||||
* @param array $options [optional] options to normalize
|
||||
* @return array normalized options
|
||||
*/
|
||||
protected function _normalizeOptions(array $options = array())
|
||||
{
|
||||
if (isset($options['indent'])) {
|
||||
$options['indent'] = $this->_getWhitespace($options['indent']);
|
||||
} else {
|
||||
$options['indent'] = $this->getIndent();
|
||||
}
|
||||
|
||||
if (isset($options['ulClass']) && $options['ulClass'] !== null) {
|
||||
$options['ulClass'] = (string) $options['ulClass'];
|
||||
} else {
|
||||
$options['ulClass'] = $this->getUlClass();
|
||||
}
|
||||
|
||||
if (array_key_exists('minDepth', $options)) {
|
||||
if (null !== $options['minDepth']) {
|
||||
$options['minDepth'] = (int) $options['minDepth'];
|
||||
}
|
||||
} else {
|
||||
$options['minDepth'] = $this->getMinDepth();
|
||||
}
|
||||
|
||||
if ($options['minDepth'] < 0 || $options['minDepth'] === null) {
|
||||
$options['minDepth'] = 0;
|
||||
}
|
||||
|
||||
if (array_key_exists('maxDepth', $options)) {
|
||||
if (null !== $options['maxDepth']) {
|
||||
$options['maxDepth'] = (int) $options['maxDepth'];
|
||||
}
|
||||
} else {
|
||||
$options['maxDepth'] = $this->getMaxDepth();
|
||||
}
|
||||
|
||||
if (!isset($options['onlyActiveBranch'])) {
|
||||
$options['onlyActiveBranch'] = $this->getOnlyActiveBranch();
|
||||
}
|
||||
|
||||
if (!isset($options['renderParents'])) {
|
||||
$options['renderParents'] = $this->getRenderParents();
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
// Render methods:
|
||||
|
||||
/**
|
||||
* Renders the deepest active menu within [$minDepth, $maxDeth], (called
|
||||
* from {@link renderMenu()})
|
||||
*
|
||||
* @param Zend_Navigation_Container $container container to render
|
||||
* @param array $active active page and depth
|
||||
* @param string $ulClass CSS class for first UL
|
||||
* @param string $indent initial indentation
|
||||
* @param int|null $minDepth minimum depth
|
||||
* @param int|null $maxDepth maximum depth
|
||||
* @return string rendered menu
|
||||
*/
|
||||
protected function _renderDeepestMenu(Zend_Navigation_Container $container,
|
||||
$ulClass,
|
||||
$indent,
|
||||
$minDepth,
|
||||
$maxDepth)
|
||||
{
|
||||
if (!$active = $this->findActive($container, $minDepth - 1, $maxDepth)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// special case if active page is one below minDepth
|
||||
if ($active['depth'] < $minDepth) {
|
||||
if (!$active['page']->hasPages()) {
|
||||
return '';
|
||||
}
|
||||
} else if (!$active['page']->hasPages()) {
|
||||
// found pages has no children; render siblings
|
||||
$active['page'] = $active['page']->getParent();
|
||||
} else if (is_int($maxDepth) && $active['depth'] +1 > $maxDepth) {
|
||||
// children are below max depth; render siblings
|
||||
$active['page'] = $active['page']->getParent();
|
||||
}
|
||||
|
||||
$ulClass = $ulClass ? ' class="' . $ulClass . '"' : '';
|
||||
$html = $indent . '<ul' . $ulClass . '>' . self::EOL;
|
||||
|
||||
foreach ($active['page'] as $subPage) {
|
||||
if (!$this->accept($subPage)) {
|
||||
continue;
|
||||
}
|
||||
$liClass = $subPage->isActive(true) ? ' class="active"' : '';
|
||||
$html .= $indent . ' <li' . $liClass . '>' . self::EOL;
|
||||
$html .= $indent . ' ' . $this->htmlify($subPage) . self::EOL;
|
||||
$html .= $indent . ' </li>' . self::EOL;
|
||||
}
|
||||
|
||||
$html .= $indent . '</ul>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a normal menu (called from {@link renderMenu()})
|
||||
*
|
||||
* @param Zend_Navigation_Container $container container to render
|
||||
* @param string $ulClass CSS class for first UL
|
||||
* @param string $indent initial indentation
|
||||
* @param int|null $minDepth minimum depth
|
||||
* @param int|null $maxDepth maximum depth
|
||||
* @param bool $onlyActive render only active branch?
|
||||
* @return string
|
||||
*/
|
||||
protected function _renderMenu(Zend_Navigation_Container $container,
|
||||
$ulClass,
|
||||
$indent,
|
||||
$minDepth,
|
||||
$maxDepth,
|
||||
$onlyActive)
|
||||
{
|
||||
$html = '';
|
||||
|
||||
// find deepest active
|
||||
if ($found = $this->findActive($container, $minDepth, $maxDepth)) {
|
||||
$foundPage = $found['page'];
|
||||
$foundDepth = $found['depth'];
|
||||
} else {
|
||||
$foundPage = null;
|
||||
}
|
||||
|
||||
// create iterator
|
||||
$iterator = new RecursiveIteratorIterator($container,
|
||||
RecursiveIteratorIterator::SELF_FIRST);
|
||||
if (is_int($maxDepth)) {
|
||||
$iterator->setMaxDepth($maxDepth);
|
||||
}
|
||||
|
||||
// iterate container
|
||||
$prevDepth = -1;
|
||||
foreach ($iterator as $page) {
|
||||
$depth = $iterator->getDepth();
|
||||
$isActive = $page->isActive(true);
|
||||
if ($depth < $minDepth || !$this->accept($page)) {
|
||||
// page is below minDepth or not accepted by acl/visibilty
|
||||
continue;
|
||||
} else if ($onlyActive && !$isActive) {
|
||||
// page is not active itself, but might be in the active branch
|
||||
$accept = false;
|
||||
if ($foundPage) {
|
||||
if ($foundPage->hasPage($page)) {
|
||||
// accept if page is a direct child of the active page
|
||||
$accept = true;
|
||||
} else if ($foundPage->getParent()->hasPage($page)) {
|
||||
// page is a sibling of the active page...
|
||||
if (!$foundPage->hasPages() ||
|
||||
is_int($maxDepth) && $foundDepth + 1 > $maxDepth) {
|
||||
// accept if active page has no children, or the
|
||||
// children are too deep to be rendered
|
||||
$accept = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$accept) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// make sure indentation is correct
|
||||
$depth -= $minDepth;
|
||||
$myIndent = $indent . str_repeat(' ', $depth);
|
||||
|
||||
if ($depth > $prevDepth) {
|
||||
// start new ul tag
|
||||
if ($ulClass && $depth == 0) {
|
||||
$ulClass = ' class="' . $ulClass . '"';
|
||||
} else {
|
||||
$ulClass = '';
|
||||
}
|
||||
$html .= $myIndent . '<ul' . $ulClass . '>' . self::EOL;
|
||||
} else if ($prevDepth > $depth) {
|
||||
// close li/ul tags until we're at current depth
|
||||
for ($i = $prevDepth; $i > $depth; $i--) {
|
||||
$ind = $indent . str_repeat(' ', $i);
|
||||
$html .= $ind . ' </li>' . self::EOL;
|
||||
$html .= $ind . '</ul>' . self::EOL;
|
||||
}
|
||||
// close previous li tag
|
||||
$html .= $myIndent . ' </li>' . self::EOL;
|
||||
} else {
|
||||
// close previous li tag
|
||||
$html .= $myIndent . ' </li>' . self::EOL;
|
||||
}
|
||||
|
||||
// render li tag and page
|
||||
$liClass = $isActive ? ' class="active"' : '';
|
||||
$html .= $myIndent . ' <li' . $liClass . '>' . self::EOL
|
||||
. $myIndent . ' ' . $this->htmlify($page) . self::EOL;
|
||||
|
||||
// store as previous depth for next iteration
|
||||
$prevDepth = $depth;
|
||||
}
|
||||
|
||||
if ($html) {
|
||||
// done iterating container; close open ul/li tags
|
||||
for ($i = $prevDepth+1; $i > 0; $i--) {
|
||||
$myIndent = $indent . str_repeat(' ', $i-1);
|
||||
$html .= $myIndent . ' </li>' . self::EOL
|
||||
. $myIndent . '</ul>' . self::EOL;
|
||||
}
|
||||
$html = rtrim($html, self::EOL);
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders helper
|
||||
*
|
||||
* Renders a HTML 'ul' for the given $container. If $container is not given,
|
||||
* the container registered in the helper will be used.
|
||||
*
|
||||
* Available $options:
|
||||
*
|
||||
*
|
||||
* @param Zend_Navigation_Container $container [optional] container to
|
||||
* create menu from. Default
|
||||
* is to use the container
|
||||
* retrieved from
|
||||
* {@link getContainer()}.
|
||||
* @param array $options [optional] options for
|
||||
* controlling rendering
|
||||
* @return string rendered menu
|
||||
*/
|
||||
public function renderMenu(Zend_Navigation_Container $container = null,
|
||||
array $options = array())
|
||||
{
|
||||
if (null === $container) {
|
||||
$container = $this->getContainer();
|
||||
}
|
||||
|
||||
$options = $this->_normalizeOptions($options);
|
||||
|
||||
if ($options['onlyActiveBranch'] && !$options['renderParents']) {
|
||||
$html = $this->_renderDeepestMenu($container,
|
||||
$options['ulClass'],
|
||||
$options['indent'],
|
||||
$options['minDepth'],
|
||||
$options['maxDepth']);
|
||||
} else {
|
||||
$html = $this->_renderMenu($container,
|
||||
$options['ulClass'],
|
||||
$options['indent'],
|
||||
$options['minDepth'],
|
||||
$options['maxDepth'],
|
||||
$options['onlyActiveBranch']);
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the inner-most sub menu for the active page in the $container
|
||||
*
|
||||
* This is a convenience method which is equivalent to the following call:
|
||||
* <code>
|
||||
* renderMenu($container, array(
|
||||
* 'indent' => $indent,
|
||||
* 'ulClass' => $ulClass,
|
||||
* 'minDepth' => null,
|
||||
* 'maxDepth' => null,
|
||||
* 'onlyActiveBranch' => true,
|
||||
* 'renderParents' => false
|
||||
* ));
|
||||
* </code>
|
||||
*
|
||||
* @param Zend_Navigation_Container $container [optional] container to
|
||||
* render. Default is to render
|
||||
* the container registered in
|
||||
* the helper.
|
||||
* @param string $ulClass [optional] CSS class to
|
||||
* use for UL element. Default
|
||||
* is to use the value from
|
||||
* {@link getUlClass()}.
|
||||
* @param string|int $indent [optional] indentation as
|
||||
* a string or number of
|
||||
* spaces. Default is to use
|
||||
* the value retrieved from
|
||||
* {@link getIndent()}.
|
||||
* @return string rendered content
|
||||
*/
|
||||
public function renderSubMenu(Zend_Navigation_Container $container = null,
|
||||
$ulClass = null,
|
||||
$indent = null)
|
||||
{
|
||||
return $this->renderMenu($container, array(
|
||||
'indent' => $indent,
|
||||
'ulClass' => $ulClass,
|
||||
'minDepth' => null,
|
||||
'maxDepth' => null,
|
||||
'onlyActiveBranch' => true,
|
||||
'renderParents' => false
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the given $container by invoking the partial view helper
|
||||
*
|
||||
* The container will simply be passed on as a model to the view script
|
||||
* as-is, and will be available in the partial script as 'container', e.g.
|
||||
* <code>echo 'Number of pages: ', count($this->container);</code>.
|
||||
*
|
||||
* @param Zend_Navigation_Container $container [optional] container to
|
||||
* pass to view script. Default
|
||||
* is to use the container
|
||||
* registered in the helper.
|
||||
* @param string|array $partial [optional] partial view
|
||||
* script to use. Default is to
|
||||
* use the partial registered
|
||||
* in the helper. If an array
|
||||
* is given, it is expected to
|
||||
* contain two values; the
|
||||
* partial view script to use,
|
||||
* and the module where the
|
||||
* script can be found.
|
||||
* @return string helper output
|
||||
*/
|
||||
public function renderPartial(Zend_Navigation_Container $container = null,
|
||||
$partial = null)
|
||||
{
|
||||
if (null === $container) {
|
||||
$container = $this->getContainer();
|
||||
}
|
||||
|
||||
if (null === $partial) {
|
||||
$partial = $this->getPartial();
|
||||
}
|
||||
|
||||
if (empty($partial)) {
|
||||
require_once 'Zend/View/Exception.php';
|
||||
$e = new Zend_View_Exception(
|
||||
'Unable to render menu: No partial view script provided'
|
||||
);
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$model = array(
|
||||
'container' => $container
|
||||
);
|
||||
|
||||
if (is_array($partial)) {
|
||||
if (count($partial) != 2) {
|
||||
require_once 'Zend/View/Exception.php';
|
||||
$e = new Zend_View_Exception(
|
||||
'Unable to render menu: A view partial supplied as '
|
||||
. 'an array must contain two values: partial view '
|
||||
. 'script and module where script can be found'
|
||||
);
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return $this->view->partial($partial[0], $partial[1], $model);
|
||||
}
|
||||
|
||||
return $this->view->partial($partial, null, $model);
|
||||
}
|
||||
|
||||
// Zend_View_Helper_Navigation_Helper:
|
||||
|
||||
/**
|
||||
* Renders menu
|
||||
*
|
||||
* Implements {@link Zend_View_Helper_Navigation_Helper::render()}.
|
||||
*
|
||||
* If a partial view is registered in the helper, the menu will be rendered
|
||||
* using the given partial script. If no partial is registered, the menu
|
||||
* will be rendered as an 'ul' element by the helper's internal method.
|
||||
*
|
||||
* @see renderPartial()
|
||||
* @see renderMenu()
|
||||
*
|
||||
* @param Zend_Navigation_Container $container [optional] container to
|
||||
* render. Default is to
|
||||
* render the container
|
||||
* registered in the helper.
|
||||
* @return string helper output
|
||||
*/
|
||||
public function render(Zend_Navigation_Container $container = null)
|
||||
{
|
||||
if ($partial = $this->getPartial()) {
|
||||
return $this->renderPartial($container, $partial);
|
||||
} else {
|
||||
return $this->renderMenu($container);
|
||||
}
|
||||
}
|
||||
}
|
483
library/Zend/View/Helper/Navigation/Sitemap.php
Normal file
483
library/Zend/View/Helper/Navigation/Sitemap.php
Normal file
|
@ -0,0 +1,483 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Sitemap.php 20104 2010-01-06 21:26:01Z matthew $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_View_Helper_Navigation_HelperAbstract
|
||||
*/
|
||||
require_once 'Zend/View/Helper/Navigation/HelperAbstract.php';
|
||||
|
||||
/**
|
||||
* Helper for printing sitemaps
|
||||
*
|
||||
* @link http://www.sitemaps.org/protocol.php
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_Navigation_Sitemap
|
||||
extends Zend_View_Helper_Navigation_HelperAbstract
|
||||
{
|
||||
/**
|
||||
* Namespace for the <urlset> tag
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const SITEMAP_NS = 'http://www.sitemaps.org/schemas/sitemap/0.9';
|
||||
|
||||
/**
|
||||
* Schema URL
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const SITEMAP_XSD = 'http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd';
|
||||
|
||||
/**
|
||||
* Whether XML output should be formatted
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_formatOutput = false;
|
||||
|
||||
/**
|
||||
* Whether the XML declaration should be included in XML output
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_useXmlDeclaration = true;
|
||||
|
||||
/**
|
||||
* Whether sitemap should be validated using Zend_Validate_Sitemap_*
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_useSitemapValidators = true;
|
||||
|
||||
/**
|
||||
* Whether sitemap should be schema validated when generated
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_useSchemaValidation = false;
|
||||
|
||||
/**
|
||||
* Server url
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_serverUrl;
|
||||
|
||||
/**
|
||||
* View helper entry point:
|
||||
* Retrieves helper and optionally sets container to operate on
|
||||
*
|
||||
* @param Zend_Navigation_Container $container [optional] container to
|
||||
* operate on
|
||||
* @return Zend_View_Helper_Navigation_Sitemap fluent interface, returns
|
||||
* self
|
||||
*/
|
||||
public function sitemap(Zend_Navigation_Container $container = null)
|
||||
{
|
||||
if (null !== $container) {
|
||||
$this->setContainer($container);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
// Accessors:
|
||||
|
||||
/**
|
||||
* Sets whether XML output should be formatted
|
||||
*
|
||||
* @param bool $formatOutput [optional] whether output
|
||||
* should be formatted. Default
|
||||
* is true.
|
||||
* @return Zend_View_Helper_Navigation_Sitemap fluent interface, returns
|
||||
* self
|
||||
*/
|
||||
public function setFormatOutput($formatOutput = true)
|
||||
{
|
||||
$this->_formatOutput = (bool) $formatOutput;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether XML output should be formatted
|
||||
*
|
||||
* @return bool whether XML output should be formatted
|
||||
*/
|
||||
public function getFormatOutput()
|
||||
{
|
||||
return $this->_formatOutput;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether the XML declaration should be used in output
|
||||
*
|
||||
* @param bool $useXmlDecl whether XML delcaration
|
||||
* should be rendered
|
||||
* @return Zend_View_Helper_Navigation_Sitemap fluent interface, returns
|
||||
* self
|
||||
*/
|
||||
public function setUseXmlDeclaration($useXmlDecl)
|
||||
{
|
||||
$this->_useXmlDeclaration = (bool) $useXmlDecl;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the XML declaration should be used in output
|
||||
*
|
||||
* @return bool whether the XML declaration should be used in output
|
||||
*/
|
||||
public function getUseXmlDeclaration()
|
||||
{
|
||||
return $this->_useXmlDeclaration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether sitemap should be validated using Zend_Validate_Sitemap_*
|
||||
*
|
||||
* @param bool $useSitemapValidators whether sitemap validators
|
||||
* should be used
|
||||
* @return Zend_View_Helper_Navigation_Sitemap fluent interface, returns
|
||||
* self
|
||||
*/
|
||||
public function setUseSitemapValidators($useSitemapValidators)
|
||||
{
|
||||
$this->_useSitemapValidators = (bool) $useSitemapValidators;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether sitemap should be validated using Zend_Validate_Sitemap_*
|
||||
*
|
||||
* @return bool whether sitemap should be validated using validators
|
||||
*/
|
||||
public function getUseSitemapValidators()
|
||||
{
|
||||
return $this->_useSitemapValidators;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether sitemap should be schema validated when generated
|
||||
*
|
||||
* @param bool $schemaValidation whether sitemap should
|
||||
* validated using XSD Schema
|
||||
* @return Zend_View_Helper_Navigation_Sitemap fluent interface, returns
|
||||
* self
|
||||
*/
|
||||
public function setUseSchemaValidation($schemaValidation)
|
||||
{
|
||||
$this->_useSchemaValidation = (bool) $schemaValidation;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if sitemap should be schema validated when generated
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getUseSchemaValidation()
|
||||
{
|
||||
return $this->_useSchemaValidation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets server url (scheme and host-related stuff without request URI)
|
||||
*
|
||||
* E.g. http://www.example.com
|
||||
*
|
||||
* @param string $serverUrl server URL to set (only
|
||||
* scheme and host)
|
||||
* @throws Zend_Uri_Exception if invalid server URL
|
||||
* @return Zend_View_Helper_Navigation_Sitemap fluent interface, returns
|
||||
* self
|
||||
*/
|
||||
public function setServerUrl($serverUrl)
|
||||
{
|
||||
require_once 'Zend/Uri.php';
|
||||
$uri = Zend_Uri::factory($serverUrl);
|
||||
$uri->setFragment('');
|
||||
$uri->setPath('');
|
||||
$uri->setQuery('');
|
||||
|
||||
if ($uri->valid()) {
|
||||
$this->_serverUrl = $uri->getUri();
|
||||
} else {
|
||||
require_once 'Zend/Uri/Exception.php';
|
||||
$e = new Zend_Uri_Exception(sprintf(
|
||||
'Invalid server URL: "%s"',
|
||||
$serverUrl));
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns server URL
|
||||
*
|
||||
* @return string server URL
|
||||
*/
|
||||
public function getServerUrl()
|
||||
{
|
||||
if (!isset($this->_serverUrl)) {
|
||||
$this->_serverUrl = $this->view->serverUrl();
|
||||
}
|
||||
|
||||
return $this->_serverUrl;
|
||||
}
|
||||
|
||||
// Helper methods:
|
||||
|
||||
/**
|
||||
* Escapes string for XML usage
|
||||
*
|
||||
* @param string $string string to escape
|
||||
* @return string escaped string
|
||||
*/
|
||||
protected function _xmlEscape($string)
|
||||
{
|
||||
$enc = 'UTF-8';
|
||||
if ($this->view instanceof Zend_View_Interface
|
||||
&& method_exists($this->view, 'getEncoding')
|
||||
) {
|
||||
$enc = $this->view->getEncoding();
|
||||
}
|
||||
|
||||
// TODO: remove check when minimum PHP version is >= 5.2.3
|
||||
if (version_compare(PHP_VERSION, '5.2.3', '>=')) {
|
||||
// do not encode existing HTML entities
|
||||
return htmlspecialchars($string, ENT_QUOTES, $enc, false);
|
||||
} else {
|
||||
$string = preg_replace('/&(?!(?:#\d++|[a-z]++);)/ui', '&', $string);
|
||||
$string = str_replace(array('<', '>', '\'', '"'), array('<', '>', ''', '"'), $string);
|
||||
return $string;
|
||||
}
|
||||
}
|
||||
|
||||
// Public methods:
|
||||
|
||||
/**
|
||||
* Returns an escaped absolute URL for the given page
|
||||
*
|
||||
* @param Zend_Navigation_Page $page page to get URL from
|
||||
* @return string
|
||||
*/
|
||||
public function url(Zend_Navigation_Page $page)
|
||||
{
|
||||
$href = $page->getHref();
|
||||
|
||||
if (!isset($href{0})) {
|
||||
// no href
|
||||
return '';
|
||||
} elseif ($href{0} == '/') {
|
||||
// href is relative to root; use serverUrl helper
|
||||
$url = $this->getServerUrl() . $href;
|
||||
} elseif (preg_match('/^[a-z]+:/im', (string) $href)) {
|
||||
// scheme is given in href; assume absolute URL already
|
||||
$url = (string) $href;
|
||||
} else {
|
||||
// href is relative to current document; use url helpers
|
||||
$url = $this->getServerUrl()
|
||||
. rtrim($this->view->url(), '/') . '/'
|
||||
. $href;
|
||||
}
|
||||
|
||||
return $this->_xmlEscape($url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a DOMDocument containing the Sitemap XML for the given container
|
||||
*
|
||||
* @param Zend_Navigation_Container $container [optional] container to get
|
||||
* breadcrumbs from, defaults
|
||||
* to what is registered in the
|
||||
* helper
|
||||
* @return DOMDocument DOM representation of the
|
||||
* container
|
||||
* @throws Zend_View_Exception if schema validation is on
|
||||
* and the sitemap is invalid
|
||||
* according to the sitemap
|
||||
* schema, or if sitemap
|
||||
* validators are used and the
|
||||
* loc element fails validation
|
||||
*/
|
||||
public function getDomSitemap(Zend_Navigation_Container $container = null)
|
||||
{
|
||||
if (null === $container) {
|
||||
$container = $this->getContainer();
|
||||
}
|
||||
|
||||
// check if we should validate using our own validators
|
||||
if ($this->getUseSitemapValidators()) {
|
||||
require_once 'Zend/Validate/Sitemap/Changefreq.php';
|
||||
require_once 'Zend/Validate/Sitemap/Lastmod.php';
|
||||
require_once 'Zend/Validate/Sitemap/Loc.php';
|
||||
require_once 'Zend/Validate/Sitemap/Priority.php';
|
||||
|
||||
// create validators
|
||||
$locValidator = new Zend_Validate_Sitemap_Loc();
|
||||
$lastmodValidator = new Zend_Validate_Sitemap_Lastmod();
|
||||
$changefreqValidator = new Zend_Validate_Sitemap_Changefreq();
|
||||
$priorityValidator = new Zend_Validate_Sitemap_Priority();
|
||||
}
|
||||
|
||||
// create document
|
||||
$dom = new DOMDocument('1.0', 'UTF-8');
|
||||
$dom->formatOutput = $this->getFormatOutput();
|
||||
|
||||
// ...and urlset (root) element
|
||||
$urlSet = $dom->createElementNS(self::SITEMAP_NS, 'urlset');
|
||||
$dom->appendChild($urlSet);
|
||||
|
||||
// create iterator
|
||||
$iterator = new RecursiveIteratorIterator($container,
|
||||
RecursiveIteratorIterator::SELF_FIRST);
|
||||
|
||||
$maxDepth = $this->getMaxDepth();
|
||||
if (is_int($maxDepth)) {
|
||||
$iterator->setMaxDepth($maxDepth);
|
||||
}
|
||||
$minDepth = $this->getMinDepth();
|
||||
if (!is_int($minDepth) || $minDepth < 0) {
|
||||
$minDepth = 0;
|
||||
}
|
||||
|
||||
// iterate container
|
||||
foreach ($iterator as $page) {
|
||||
if ($iterator->getDepth() < $minDepth || !$this->accept($page)) {
|
||||
// page should not be included
|
||||
continue;
|
||||
}
|
||||
|
||||
// get absolute url from page
|
||||
if (!$url = $this->url($page)) {
|
||||
// skip page if it has no url (rare case)
|
||||
continue;
|
||||
}
|
||||
|
||||
// create url node for this page
|
||||
$urlNode = $dom->createElementNS(self::SITEMAP_NS, 'url');
|
||||
$urlSet->appendChild($urlNode);
|
||||
|
||||
if ($this->getUseSitemapValidators() &&
|
||||
!$locValidator->isValid($url)) {
|
||||
require_once 'Zend/View/Exception.php';
|
||||
$e = new Zend_View_Exception(sprintf(
|
||||
'Encountered an invalid URL for Sitemap XML: "%s"',
|
||||
$url));
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
// put url in 'loc' element
|
||||
$urlNode->appendChild($dom->createElementNS(self::SITEMAP_NS,
|
||||
'loc', $url));
|
||||
|
||||
// add 'lastmod' element if a valid lastmod is set in page
|
||||
if (isset($page->lastmod)) {
|
||||
$lastmod = strtotime((string) $page->lastmod);
|
||||
|
||||
// prevent 1970-01-01...
|
||||
if ($lastmod !== false) {
|
||||
$lastmod = date('c', $lastmod);
|
||||
}
|
||||
|
||||
if (!$this->getUseSitemapValidators() ||
|
||||
$lastmodValidator->isValid($lastmod)) {
|
||||
$urlNode->appendChild(
|
||||
$dom->createElementNS(self::SITEMAP_NS, 'lastmod',
|
||||
$lastmod)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// add 'changefreq' element if a valid changefreq is set in page
|
||||
if (isset($page->changefreq)) {
|
||||
$changefreq = $page->changefreq;
|
||||
if (!$this->getUseSitemapValidators() ||
|
||||
$changefreqValidator->isValid($changefreq)) {
|
||||
$urlNode->appendChild(
|
||||
$dom->createElementNS(self::SITEMAP_NS, 'changefreq',
|
||||
$changefreq)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// add 'priority' element if a valid priority is set in page
|
||||
if (isset($page->priority)) {
|
||||
$priority = $page->priority;
|
||||
if (!$this->getUseSitemapValidators() ||
|
||||
$priorityValidator->isValid($priority)) {
|
||||
$urlNode->appendChild(
|
||||
$dom->createElementNS(self::SITEMAP_NS, 'priority',
|
||||
$priority)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// validate using schema if specified
|
||||
if ($this->getUseSchemaValidation()) {
|
||||
if (!@$dom->schemaValidate(self::SITEMAP_XSD)) {
|
||||
require_once 'Zend/View/Exception.php';
|
||||
$e = new Zend_View_Exception(sprintf(
|
||||
'Sitemap is invalid according to XML Schema at "%s"',
|
||||
self::SITEMAP_XSD));
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
return $dom;
|
||||
}
|
||||
|
||||
// Zend_View_Helper_Navigation_Helper:
|
||||
|
||||
/**
|
||||
* Renders helper
|
||||
*
|
||||
* Implements {@link Zend_View_Helper_Navigation_Helper::render()}.
|
||||
*
|
||||
* @param Zend_Navigation_Container $container [optional] container to
|
||||
* render. Default is to
|
||||
* render the container
|
||||
* registered in the helper.
|
||||
* @return string helper output
|
||||
*/
|
||||
public function render(Zend_Navigation_Container $container = null)
|
||||
{
|
||||
$dom = $this->getDomSitemap($container);
|
||||
|
||||
$xml = $this->getUseXmlDeclaration() ?
|
||||
$dom->saveXML() :
|
||||
$dom->saveXML($dom->documentElement);
|
||||
|
||||
return rtrim($xml, PHP_EOL);
|
||||
}
|
||||
}
|
145
library/Zend/View/Helper/PaginationControl.php
Normal file
145
library/Zend/View/Helper/PaginationControl.php
Normal file
|
@ -0,0 +1,145 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: PaginationControl.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_PaginationControl
|
||||
{
|
||||
/**
|
||||
* View instance
|
||||
*
|
||||
* @var Zend_View_Instance
|
||||
*/
|
||||
public $view = null;
|
||||
|
||||
/**
|
||||
* Default view partial
|
||||
*
|
||||
* @var string|array
|
||||
*/
|
||||
protected static $_defaultViewPartial = null;
|
||||
|
||||
/**
|
||||
* Sets the view instance.
|
||||
*
|
||||
* @param Zend_View_Interface $view View instance
|
||||
* @return Zend_View_Helper_PaginationControl
|
||||
*/
|
||||
public function setView(Zend_View_Interface $view)
|
||||
{
|
||||
$this->view = $view;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default view partial.
|
||||
*
|
||||
* @param string|array $partial View partial
|
||||
*/
|
||||
public static function setDefaultViewPartial($partial)
|
||||
{
|
||||
self::$_defaultViewPartial = $partial;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default view partial
|
||||
*
|
||||
* @return string|array
|
||||
*/
|
||||
public static function getDefaultViewPartial()
|
||||
{
|
||||
return self::$_defaultViewPartial;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the provided pages. This checks if $view->paginator is set and,
|
||||
* if so, uses that. Also, if no scrolling style or partial are specified,
|
||||
* the defaults will be used (if set).
|
||||
*
|
||||
* @param Zend_Paginator (Optional) $paginator
|
||||
* @param string $scrollingStyle (Optional) Scrolling style
|
||||
* @param string $partial (Optional) View partial
|
||||
* @param array|string $params (Optional) params to pass to the partial
|
||||
* @return string
|
||||
* @throws Zend_View_Exception
|
||||
*/
|
||||
public function paginationControl(Zend_Paginator $paginator = null, $scrollingStyle = null, $partial = null, $params = null)
|
||||
{
|
||||
if ($paginator === null) {
|
||||
if (isset($this->view->paginator) and $this->view->paginator !== null and $this->view->paginator instanceof Zend_Paginator) {
|
||||
$paginator = $this->view->paginator;
|
||||
} else {
|
||||
/**
|
||||
* @see Zend_View_Exception
|
||||
*/
|
||||
require_once 'Zend/View/Exception.php';
|
||||
|
||||
$e = new Zend_View_Exception('No paginator instance provided or incorrect type');
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
if ($partial === null) {
|
||||
if (self::$_defaultViewPartial === null) {
|
||||
/**
|
||||
* @see Zend_View_Exception
|
||||
*/
|
||||
require_once 'Zend/View/Exception.php';
|
||||
$e = new Zend_View_Exception('No view partial provided and no default set');
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$partial = self::$_defaultViewPartial;
|
||||
}
|
||||
|
||||
$pages = get_object_vars($paginator->getPages($scrollingStyle));
|
||||
|
||||
if ($params !== null) {
|
||||
$pages = array_merge($pages, (array) $params);
|
||||
}
|
||||
|
||||
if (is_array($partial)) {
|
||||
if (count($partial) != 2) {
|
||||
/**
|
||||
* @see Zend_View_Exception
|
||||
*/
|
||||
require_once 'Zend/View/Exception.php';
|
||||
$e = new Zend_View_Exception('A view partial supplied as an array must contain two values: the filename and its module');
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
if ($partial[1] !== null) {
|
||||
return $this->view->partial($partial[0], $partial[1], $pages);
|
||||
}
|
||||
|
||||
$partial = $partial[0];
|
||||
}
|
||||
|
||||
return $this->view->partial($partial, $pages);
|
||||
}
|
||||
}
|
149
library/Zend/View/Helper/Partial.php
Normal file
149
library/Zend/View/Helper/Partial.php
Normal file
|
@ -0,0 +1,149 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: Partial.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/** Zend_View_Helper_Abstract.php */
|
||||
require_once 'Zend/View/Helper/Abstract.php';
|
||||
|
||||
/**
|
||||
* Helper for rendering a template fragment in its own variable scope.
|
||||
*
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_Partial extends Zend_View_Helper_Abstract
|
||||
{
|
||||
/**
|
||||
* Variable to which object will be assigned
|
||||
* @var string
|
||||
*/
|
||||
protected $_objectKey;
|
||||
|
||||
/**
|
||||
* Renders a template fragment within a variable scope distinct from the
|
||||
* calling View object.
|
||||
*
|
||||
* If no arguments are passed, returns the helper instance.
|
||||
*
|
||||
* If the $model is an array, it is passed to the view object's assign()
|
||||
* method.
|
||||
*
|
||||
* If the $model is an object, it first checks to see if the object
|
||||
* implements a 'toArray' method; if so, it passes the result of that
|
||||
* method to to the view object's assign() method. Otherwise, the result of
|
||||
* get_object_vars() is passed.
|
||||
*
|
||||
* @param string $name Name of view script
|
||||
* @param string|array $module If $model is empty, and $module is an array,
|
||||
* these are the variables to populate in the
|
||||
* view. Otherwise, the module in which the
|
||||
* partial resides
|
||||
* @param array $model Variables to populate in the view
|
||||
* @return string|Zend_View_Helper_Partial
|
||||
*/
|
||||
public function partial($name = null, $module = null, $model = null)
|
||||
{
|
||||
if (0 == func_num_args()) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$view = $this->cloneView();
|
||||
if (isset($this->partialCounter)) {
|
||||
$view->partialCounter = $this->partialCounter;
|
||||
}
|
||||
if ((null !== $module) && is_string($module)) {
|
||||
require_once 'Zend/Controller/Front.php';
|
||||
$moduleDir = Zend_Controller_Front::getInstance()->getControllerDirectory($module);
|
||||
if (null === $moduleDir) {
|
||||
require_once 'Zend/View/Helper/Partial/Exception.php';
|
||||
$e = new Zend_View_Helper_Partial_Exception('Cannot render partial; module does not exist');
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
$viewsDir = dirname($moduleDir) . '/views';
|
||||
$view->addBasePath($viewsDir);
|
||||
} elseif ((null == $model) && (null !== $module)
|
||||
&& (is_array($module) || is_object($module)))
|
||||
{
|
||||
$model = $module;
|
||||
}
|
||||
|
||||
if (!empty($model)) {
|
||||
if (is_array($model)) {
|
||||
$view->assign($model);
|
||||
} elseif (is_object($model)) {
|
||||
if (null !== ($objectKey = $this->getObjectKey())) {
|
||||
$view->assign($objectKey, $model);
|
||||
} elseif (method_exists($model, 'toArray')) {
|
||||
$view->assign($model->toArray());
|
||||
} else {
|
||||
$view->assign(get_object_vars($model));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $view->render($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone the current View
|
||||
*
|
||||
* @return Zend_View_Interface
|
||||
*/
|
||||
public function cloneView()
|
||||
{
|
||||
$view = clone $this->view;
|
||||
$view->clearVars();
|
||||
return $view;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set object key
|
||||
*
|
||||
* @param string $key
|
||||
* @return Zend_View_Helper_Partial
|
||||
*/
|
||||
public function setObjectKey($key)
|
||||
{
|
||||
if (null === $key) {
|
||||
$this->_objectKey = null;
|
||||
} else {
|
||||
$this->_objectKey = (string) $key;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve object key
|
||||
*
|
||||
* The objectKey is the variable to which an object in the iterator will be
|
||||
* assigned.
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public function getObjectKey()
|
||||
{
|
||||
return $this->_objectKey;
|
||||
}
|
||||
}
|
39
library/Zend/View/Helper/Partial/Exception.php
Normal file
39
library/Zend/View/Helper/Partial/Exception.php
Normal file
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
|
||||
/** Zend_View_Exception */
|
||||
require_once 'Zend/View/Exception.php';
|
||||
|
||||
|
||||
/**
|
||||
* Exception for Zend_View_Helper_Partial class.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_Partial_Exception extends Zend_View_Exception
|
||||
{
|
||||
}
|
98
library/Zend/View/Helper/PartialLoop.php
Normal file
98
library/Zend/View/Helper/PartialLoop.php
Normal file
|
@ -0,0 +1,98 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: PartialLoop.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/** Zend_View_Helper_Partial */
|
||||
require_once 'Zend/View/Helper/Partial.php';
|
||||
|
||||
/**
|
||||
* Helper for rendering a template fragment in its own variable scope; iterates
|
||||
* over data provided and renders for each iteration.
|
||||
*
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_PartialLoop extends Zend_View_Helper_Partial
|
||||
{
|
||||
|
||||
/**
|
||||
* Marker to where the pointer is at in the loop
|
||||
* @var integer
|
||||
*/
|
||||
protected $partialCounter = 0;
|
||||
|
||||
/**
|
||||
* Renders a template fragment within a variable scope distinct from the
|
||||
* calling View object.
|
||||
*
|
||||
* If no arguments are provided, returns object instance.
|
||||
*
|
||||
* @param string $name Name of view script
|
||||
* @param string|array $module If $model is empty, and $module is an array,
|
||||
* these are the variables to populate in the
|
||||
* view. Otherwise, the module in which the
|
||||
* partial resides
|
||||
* @param array $model Variables to populate in the view
|
||||
* @return string
|
||||
*/
|
||||
public function partialLoop($name = null, $module = null, $model = null)
|
||||
{
|
||||
if (0 == func_num_args()) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
if ((null === $model) && (null !== $module)) {
|
||||
$model = $module;
|
||||
$module = null;
|
||||
}
|
||||
|
||||
if (!is_array($model)
|
||||
&& (!$model instanceof Traversable)
|
||||
&& (is_object($model) && !method_exists($model, 'toArray'))
|
||||
) {
|
||||
require_once 'Zend/View/Helper/Partial/Exception.php';
|
||||
$e = new Zend_View_Helper_Partial_Exception('PartialLoop helper requires iterable data');
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
if (is_object($model)
|
||||
&& (!$model instanceof Traversable)
|
||||
&& method_exists($model, 'toArray')
|
||||
) {
|
||||
$model = $model->toArray();
|
||||
}
|
||||
|
||||
$content = '';
|
||||
// reset the counter if it's call again
|
||||
$this->partialCounter = 0;
|
||||
foreach ($model as $item) {
|
||||
// increment the counter variable
|
||||
$this->partialCounter++;
|
||||
|
||||
$content .= $this->partial($name, $module, $item);
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
}
|
87
library/Zend/View/Helper/Placeholder.php
Normal file
87
library/Zend/View/Helper/Placeholder.php
Normal file
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: Placeholder.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/** Zend_View_Helper_Placeholder_Registry */
|
||||
require_once 'Zend/View/Helper/Placeholder/Registry.php';
|
||||
|
||||
/** Zend_View_Helper_Abstract.php */
|
||||
require_once 'Zend/View/Helper/Abstract.php';
|
||||
|
||||
/**
|
||||
* Helper for passing data between otherwise segregated Views. It's called
|
||||
* Placeholder to make its typical usage obvious, but can be used just as easily
|
||||
* for non-Placeholder things. That said, the support for this is only
|
||||
* guaranteed to effect subsequently rendered templates, and of course Layouts.
|
||||
*
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_Placeholder extends Zend_View_Helper_Abstract
|
||||
{
|
||||
/**
|
||||
* Placeholder items
|
||||
* @var array
|
||||
*/
|
||||
protected $_items = array();
|
||||
|
||||
/**
|
||||
* @var Zend_View_Helper_Placeholder_Registry
|
||||
*/
|
||||
protected $_registry;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Retrieve container registry from Zend_Registry, or create new one and register it.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->_registry = Zend_View_Helper_Placeholder_Registry::getRegistry();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Placeholder helper
|
||||
*
|
||||
* @param string $name
|
||||
* @return Zend_View_Helper_Placeholder_Container_Abstract
|
||||
*/
|
||||
public function placeholder($name)
|
||||
{
|
||||
$name = (string) $name;
|
||||
return $this->_registry->getContainer($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the registry
|
||||
*
|
||||
* @return Zend_View_Helper_Placeholder_Registry
|
||||
*/
|
||||
public function getRegistry()
|
||||
{
|
||||
return $this->_registry;
|
||||
}
|
||||
}
|
36
library/Zend/View/Helper/Placeholder/Container.php
Normal file
36
library/Zend/View/Helper/Placeholder/Container.php
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: Container.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/** Zend_View_Helper_Placeholder_Container_Abstract */
|
||||
require_once 'Zend/View/Helper/Placeholder/Container/Abstract.php';
|
||||
|
||||
/**
|
||||
* Container for placeholder values
|
||||
*
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_Placeholder_Container extends Zend_View_Helper_Placeholder_Container_Abstract
|
||||
{
|
||||
}
|
378
library/Zend/View/Helper/Placeholder/Container/Abstract.php
Normal file
378
library/Zend/View/Helper/Placeholder/Container/Abstract.php
Normal file
|
@ -0,0 +1,378 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: Abstract.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstract class representing container for placeholder values
|
||||
*
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_View_Helper_Placeholder_Container_Abstract extends ArrayObject
|
||||
{
|
||||
/**
|
||||
* Whether or not to override all contents of placeholder
|
||||
* @const string
|
||||
*/
|
||||
const SET = 'SET';
|
||||
|
||||
/**
|
||||
* Whether or not to append contents to placeholder
|
||||
* @const string
|
||||
*/
|
||||
const APPEND = 'APPEND';
|
||||
|
||||
/**
|
||||
* Whether or not to prepend contents to placeholder
|
||||
* @const string
|
||||
*/
|
||||
const PREPEND = 'PREPEND';
|
||||
|
||||
/**
|
||||
* What text to prefix the placeholder with when rendering
|
||||
* @var string
|
||||
*/
|
||||
protected $_prefix = '';
|
||||
|
||||
/**
|
||||
* What text to append the placeholder with when rendering
|
||||
* @var string
|
||||
*/
|
||||
protected $_postfix = '';
|
||||
|
||||
/**
|
||||
* What string to use between individual items in the placeholder when rendering
|
||||
* @var string
|
||||
*/
|
||||
protected $_separator = '';
|
||||
|
||||
/**
|
||||
* What string to use as the indentation of output, this will typically be spaces. Eg: ' '
|
||||
* @var string
|
||||
*/
|
||||
protected $_indent = '';
|
||||
|
||||
/**
|
||||
* Whether or not we're already capturing for this given container
|
||||
* @var bool
|
||||
*/
|
||||
protected $_captureLock = false;
|
||||
|
||||
/**
|
||||
* What type of capture (overwrite (set), append, prepend) to use
|
||||
* @var string
|
||||
*/
|
||||
protected $_captureType;
|
||||
|
||||
/**
|
||||
* Key to which to capture content
|
||||
* @var string
|
||||
*/
|
||||
protected $_captureKey;
|
||||
|
||||
/**
|
||||
* Constructor - This is needed so that we can attach a class member as the ArrayObject container
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(array(), parent::ARRAY_AS_PROPS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a single value
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function set($value)
|
||||
{
|
||||
$this->exchangeArray(array($value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepend a value to the top of the container
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function prepend($value)
|
||||
{
|
||||
$values = $this->getArrayCopy();
|
||||
array_unshift($values, $value);
|
||||
$this->exchangeArray($values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve container value
|
||||
*
|
||||
* If single element registered, returns that element; otherwise,
|
||||
* serializes to array.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
if (1 == count($this)) {
|
||||
$keys = $this->getKeys();
|
||||
$key = array_shift($keys);
|
||||
return $this[$key];
|
||||
}
|
||||
|
||||
return $this->getArrayCopy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set prefix for __toString() serialization
|
||||
*
|
||||
* @param string $prefix
|
||||
* @return Zend_View_Helper_Placeholder_Container
|
||||
*/
|
||||
public function setPrefix($prefix)
|
||||
{
|
||||
$this->_prefix = (string) $prefix;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve prefix
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPrefix()
|
||||
{
|
||||
return $this->_prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set postfix for __toString() serialization
|
||||
*
|
||||
* @param string $postfix
|
||||
* @return Zend_View_Helper_Placeholder_Container
|
||||
*/
|
||||
public function setPostfix($postfix)
|
||||
{
|
||||
$this->_postfix = (string) $postfix;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve postfix
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPostfix()
|
||||
{
|
||||
return $this->_postfix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set separator for __toString() serialization
|
||||
*
|
||||
* Used to implode elements in container
|
||||
*
|
||||
* @param string $separator
|
||||
* @return Zend_View_Helper_Placeholder_Container
|
||||
*/
|
||||
public function setSeparator($separator)
|
||||
{
|
||||
$this->_separator = (string) $separator;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve separator
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSeparator()
|
||||
{
|
||||
return $this->_separator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the indentation string for __toString() serialization,
|
||||
* optionally, if a number is passed, it will be the number of spaces
|
||||
*
|
||||
* @param string|int $indent
|
||||
* @return Zend_View_Helper_Placeholder_Container_Abstract
|
||||
*/
|
||||
public function setIndent($indent)
|
||||
{
|
||||
$this->_indent = $this->getWhitespace($indent);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve indentation
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getIndent()
|
||||
{
|
||||
return $this->_indent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve whitespace representation of $indent
|
||||
*
|
||||
* @param int|string $indent
|
||||
* @return string
|
||||
*/
|
||||
public function getWhitespace($indent)
|
||||
{
|
||||
if (is_int($indent)) {
|
||||
$indent = str_repeat(' ', $indent);
|
||||
}
|
||||
|
||||
return (string) $indent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start capturing content to push into placeholder
|
||||
*
|
||||
* @param int $type How to capture content into placeholder; append, prepend, or set
|
||||
* @return void
|
||||
* @throws Zend_View_Helper_Placeholder_Exception if nested captures detected
|
||||
*/
|
||||
public function captureStart($type = Zend_View_Helper_Placeholder_Container_Abstract::APPEND, $key = null)
|
||||
{
|
||||
if ($this->_captureLock) {
|
||||
require_once 'Zend/View/Helper/Placeholder/Container/Exception.php';
|
||||
$e = new Zend_View_Helper_Placeholder_Container_Exception('Cannot nest placeholder captures for the same placeholder');
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$this->_captureLock = true;
|
||||
$this->_captureType = $type;
|
||||
if ((null !== $key) && is_scalar($key)) {
|
||||
$this->_captureKey = (string) $key;
|
||||
}
|
||||
ob_start();
|
||||
}
|
||||
|
||||
/**
|
||||
* End content capture
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function captureEnd()
|
||||
{
|
||||
$data = ob_get_clean();
|
||||
$key = null;
|
||||
$this->_captureLock = false;
|
||||
if (null !== $this->_captureKey) {
|
||||
$key = $this->_captureKey;
|
||||
}
|
||||
switch ($this->_captureType) {
|
||||
case self::SET:
|
||||
if (null !== $key) {
|
||||
$this[$key] = $data;
|
||||
} else {
|
||||
$this->exchangeArray(array($data));
|
||||
}
|
||||
break;
|
||||
case self::PREPEND:
|
||||
if (null !== $key) {
|
||||
$array = array($key => $data);
|
||||
$values = $this->getArrayCopy();
|
||||
$final = $array + $values;
|
||||
$this->exchangeArray($final);
|
||||
} else {
|
||||
$this->prepend($data);
|
||||
}
|
||||
break;
|
||||
case self::APPEND:
|
||||
default:
|
||||
if (null !== $key) {
|
||||
if (empty($this[$key])) {
|
||||
$this[$key] = $data;
|
||||
} else {
|
||||
$this[$key] .= $data;
|
||||
}
|
||||
} else {
|
||||
$this[$this->nextIndex()] = $data;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get keys
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getKeys()
|
||||
{
|
||||
$array = $this->getArrayCopy();
|
||||
return array_keys($array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Next Index
|
||||
*
|
||||
* as defined by the PHP manual
|
||||
* @return int
|
||||
*/
|
||||
public function nextIndex()
|
||||
{
|
||||
$keys = $this->getKeys();
|
||||
if (0 == count($keys)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return $nextIndex = max($keys) + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the placeholder
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function toString($indent = null)
|
||||
{
|
||||
$indent = ($indent !== null)
|
||||
? $this->getWhitespace($indent)
|
||||
: $this->getIndent();
|
||||
|
||||
$items = $this->getArrayCopy();
|
||||
$return = $indent
|
||||
. $this->getPrefix()
|
||||
. implode($this->getSeparator(), $items)
|
||||
. $this->getPostfix();
|
||||
$return = preg_replace("/(\r\n?|\n)/", '$1' . $indent, $return);
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize object to string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->toString();
|
||||
}
|
||||
}
|
39
library/Zend/View/Helper/Placeholder/Container/Exception.php
Normal file
39
library/Zend/View/Helper/Placeholder/Container/Exception.php
Normal file
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
|
||||
/** Zend_View_Exception */
|
||||
require_once 'Zend/View/Exception.php';
|
||||
|
||||
|
||||
/**
|
||||
* Exception for Zend_View_Helper_Placeholder_Container class.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_Placeholder_Container_Exception extends Zend_View_Exception
|
||||
{
|
||||
}
|
324
library/Zend/View/Helper/Placeholder/Container/Standalone.php
Normal file
324
library/Zend/View/Helper/Placeholder/Container/Standalone.php
Normal file
|
@ -0,0 +1,324 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: Standalone.php 20143 2010-01-08 15:17:11Z matthew $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/** Zend_View_Helper_Placeholder_Registry */
|
||||
require_once 'Zend/View/Helper/Placeholder/Registry.php';
|
||||
|
||||
/** Zend_View_Helper_Abstract.php */
|
||||
require_once 'Zend/View/Helper/Abstract.php';
|
||||
|
||||
/**
|
||||
* Base class for targetted placeholder helpers
|
||||
*
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_View_Helper_Placeholder_Container_Standalone extends Zend_View_Helper_Abstract implements IteratorAggregate, Countable, ArrayAccess
|
||||
{
|
||||
/**
|
||||
* @var Zend_View_Helper_Placeholder_Container_Abstract
|
||||
*/
|
||||
protected $_container;
|
||||
|
||||
/**
|
||||
* @var Zend_View_Helper_Placeholder_Registry
|
||||
*/
|
||||
protected $_registry;
|
||||
|
||||
/**
|
||||
* Registry key under which container registers itself
|
||||
* @var string
|
||||
*/
|
||||
protected $_regKey;
|
||||
|
||||
/**
|
||||
* Flag wheter to automatically escape output, must also be
|
||||
* enforced in the child class if __toString/toString is overriden
|
||||
* @var book
|
||||
*/
|
||||
protected $_autoEscape = true;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->setRegistry(Zend_View_Helper_Placeholder_Registry::getRegistry());
|
||||
$this->setContainer($this->getRegistry()->getContainer($this->_regKey));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve registry
|
||||
*
|
||||
* @return Zend_View_Helper_Placeholder_Registry
|
||||
*/
|
||||
public function getRegistry()
|
||||
{
|
||||
return $this->_registry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set registry object
|
||||
*
|
||||
* @param Zend_View_Helper_Placeholder_Registry $registry
|
||||
* @return Zend_View_Helper_Placeholder_Container_Standalone
|
||||
*/
|
||||
public function setRegistry(Zend_View_Helper_Placeholder_Registry $registry)
|
||||
{
|
||||
$this->_registry = $registry;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether or not auto escaping should be used
|
||||
*
|
||||
* @param bool $autoEscape whether or not to auto escape output
|
||||
* @return Zend_View_Helper_Placeholder_Container_Standalone
|
||||
*/
|
||||
public function setAutoEscape($autoEscape = true)
|
||||
{
|
||||
$this->_autoEscape = ($autoEscape) ? true : false;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether autoEscaping is enabled or disabled
|
||||
*
|
||||
* return bool
|
||||
*/
|
||||
public function getAutoEscape()
|
||||
{
|
||||
return $this->_autoEscape;
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape a string
|
||||
*
|
||||
* @param string $string
|
||||
* @return string
|
||||
*/
|
||||
protected function _escape($string)
|
||||
{
|
||||
$enc = 'UTF-8';
|
||||
if ($this->view instanceof Zend_View_Interface
|
||||
&& method_exists($this->view, 'getEncoding')
|
||||
) {
|
||||
$enc = $this->view->getEncoding();
|
||||
}
|
||||
|
||||
return htmlspecialchars((string) $string, ENT_COMPAT, $enc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set container on which to operate
|
||||
*
|
||||
* @param Zend_View_Helper_Placeholder_Container_Abstract $container
|
||||
* @return Zend_View_Helper_Placeholder_Container_Standalone
|
||||
*/
|
||||
public function setContainer(Zend_View_Helper_Placeholder_Container_Abstract $container)
|
||||
{
|
||||
$this->_container = $container;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve placeholder container
|
||||
*
|
||||
* @return Zend_View_Helper_Placeholder_Container_Abstract
|
||||
*/
|
||||
public function getContainer()
|
||||
{
|
||||
return $this->_container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overloading: set property value
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function __set($key, $value)
|
||||
{
|
||||
$container = $this->getContainer();
|
||||
$container[$key] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overloading: retrieve property
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get($key)
|
||||
{
|
||||
$container = $this->getContainer();
|
||||
if (isset($container[$key])) {
|
||||
return $container[$key];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overloading: check if property is set
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function __isset($key)
|
||||
{
|
||||
$container = $this->getContainer();
|
||||
return isset($container[$key]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Overloading: unset property
|
||||
*
|
||||
* @param string $key
|
||||
* @return void
|
||||
*/
|
||||
public function __unset($key)
|
||||
{
|
||||
$container = $this->getContainer();
|
||||
if (isset($container[$key])) {
|
||||
unset($container[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Overload
|
||||
*
|
||||
* Proxy to container methods
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $args
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($method, $args)
|
||||
{
|
||||
$container = $this->getContainer();
|
||||
if (method_exists($container, $method)) {
|
||||
$return = call_user_func_array(array($container, $method), $args);
|
||||
if ($return === $container) {
|
||||
// If the container is returned, we really want the current object
|
||||
return $this;
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
require_once 'Zend/View/Exception.php';
|
||||
$e = new Zend_View_Exception('Method "' . $method . '" does not exist');
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
/**
|
||||
* String representation
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function toString()
|
||||
{
|
||||
return $this->getContainer()->toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Cast to string representation
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Countable
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
$container = $this->getContainer();
|
||||
return count($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* ArrayAccess: offsetExists
|
||||
*
|
||||
* @param string|int $offset
|
||||
* @return bool
|
||||
*/
|
||||
public function offsetExists($offset)
|
||||
{
|
||||
return $this->getContainer()->offsetExists($offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* ArrayAccess: offsetGet
|
||||
*
|
||||
* @param string|int $offset
|
||||
* @return mixed
|
||||
*/
|
||||
public function offsetGet($offset)
|
||||
{
|
||||
return $this->getContainer()->offsetGet($offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* ArrayAccess: offsetSet
|
||||
*
|
||||
* @param string|int $offset
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function offsetSet($offset, $value)
|
||||
{
|
||||
return $this->getContainer()->offsetSet($offset, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* ArrayAccess: offsetUnset
|
||||
*
|
||||
* @param string|int $offset
|
||||
* @return void
|
||||
*/
|
||||
public function offsetUnset($offset)
|
||||
{
|
||||
return $this->getContainer()->offsetUnset($offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* IteratorAggregate: get Iterator
|
||||
*
|
||||
* @return Iterator
|
||||
*/
|
||||
public function getIterator()
|
||||
{
|
||||
return $this->getContainer()->getIterator();
|
||||
}
|
||||
}
|
188
library/Zend/View/Helper/Placeholder/Registry.php
Normal file
188
library/Zend/View/Helper/Placeholder/Registry.php
Normal file
|
@ -0,0 +1,188 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: Registry.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/** Zend_Registry */
|
||||
require_once 'Zend/Registry.php';
|
||||
|
||||
/** Zend_View_Helper_Placeholder_Container_Abstract */
|
||||
require_once 'Zend/View/Helper/Placeholder/Container/Abstract.php';
|
||||
|
||||
/** Zend_View_Helper_Placeholder_Container */
|
||||
require_once 'Zend/View/Helper/Placeholder/Container.php';
|
||||
|
||||
/**
|
||||
* Registry for placeholder containers
|
||||
*
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_Placeholder_Registry
|
||||
{
|
||||
/**
|
||||
* Zend_Registry key under which placeholder registry exists
|
||||
* @const string
|
||||
*/
|
||||
const REGISTRY_KEY = 'Zend_View_Helper_Placeholder_Registry';
|
||||
|
||||
/**
|
||||
* Default container class
|
||||
* @var string
|
||||
*/
|
||||
protected $_containerClass = 'Zend_View_Helper_Placeholder_Container';
|
||||
|
||||
/**
|
||||
* Placeholder containers
|
||||
* @var array
|
||||
*/
|
||||
protected $_items = array();
|
||||
|
||||
/**
|
||||
* Retrieve or create registry instnace
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function getRegistry()
|
||||
{
|
||||
if (Zend_Registry::isRegistered(self::REGISTRY_KEY)) {
|
||||
$registry = Zend_Registry::get(self::REGISTRY_KEY);
|
||||
} else {
|
||||
$registry = new self();
|
||||
Zend_Registry::set(self::REGISTRY_KEY, $registry);
|
||||
}
|
||||
|
||||
return $registry;
|
||||
}
|
||||
|
||||
/**
|
||||
* createContainer
|
||||
*
|
||||
* @param string $key
|
||||
* @param array $value
|
||||
* @return Zend_View_Helper_Placeholder_Container_Abstract
|
||||
*/
|
||||
public function createContainer($key, array $value = array())
|
||||
{
|
||||
$key = (string) $key;
|
||||
|
||||
$this->_items[$key] = new $this->_containerClass(array());
|
||||
return $this->_items[$key];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a placeholder container
|
||||
*
|
||||
* @param string $key
|
||||
* @return Zend_View_Helper_Placeholder_Container_Abstract
|
||||
*/
|
||||
public function getContainer($key)
|
||||
{
|
||||
$key = (string) $key;
|
||||
if (isset($this->_items[$key])) {
|
||||
return $this->_items[$key];
|
||||
}
|
||||
|
||||
$container = $this->createContainer($key);
|
||||
|
||||
return $container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does a particular container exist?
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function containerExists($key)
|
||||
{
|
||||
$key = (string) $key;
|
||||
$return = array_key_exists($key, $this->_items);
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the container for an item in the registry
|
||||
*
|
||||
* @param string $key
|
||||
* @param Zend_View_Placeholder_Container_Abstract $container
|
||||
* @return Zend_View_Placeholder_Registry
|
||||
*/
|
||||
public function setContainer($key, Zend_View_Helper_Placeholder_Container_Abstract $container)
|
||||
{
|
||||
$key = (string) $key;
|
||||
$this->_items[$key] = $container;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a container
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function deleteContainer($key)
|
||||
{
|
||||
$key = (string) $key;
|
||||
if (isset($this->_items[$key])) {
|
||||
unset($this->_items[$key]);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the container class to use
|
||||
*
|
||||
* @param string $name
|
||||
* @return Zend_View_Helper_Placeholder_Registry
|
||||
*/
|
||||
public function setContainerClass($name)
|
||||
{
|
||||
if (!class_exists($name)) {
|
||||
require_once 'Zend/Loader.php';
|
||||
Zend_Loader::loadClass($name);
|
||||
}
|
||||
|
||||
$reflection = new ReflectionClass($name);
|
||||
if (!$reflection->isSubclassOf(new ReflectionClass('Zend_View_Helper_Placeholder_Container_Abstract'))) {
|
||||
require_once 'Zend/View/Helper/Placeholder/Registry/Exception.php';
|
||||
$e = new Zend_View_Helper_Placeholder_Registry_Exception('Invalid Container class specified');
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$this->_containerClass = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the container class
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getContainerClass()
|
||||
{
|
||||
return $this->_containerClass;
|
||||
}
|
||||
}
|
39
library/Zend/View/Helper/Placeholder/Registry/Exception.php
Normal file
39
library/Zend/View/Helper/Placeholder/Registry/Exception.php
Normal file
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
|
||||
/** Zend_View_Exception */
|
||||
require_once 'Zend/View/Exception.php';
|
||||
|
||||
|
||||
/**
|
||||
* Exception for Zend_View_Helper_Placeholder_Registry class.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_Placeholder_Registry_Exception extends Zend_View_Exception
|
||||
{
|
||||
}
|
53
library/Zend/View/Helper/RenderToPlaceholder.php
Normal file
53
library/Zend/View/Helper/RenderToPlaceholder.php
Normal file
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: RenderToPlaceholder.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/** Zend_View_Helper_Abstract.php */
|
||||
require_once 'Zend/View/Helper/Abstract.php';
|
||||
|
||||
/**
|
||||
* Renders a template and stores the rendered output as a placeholder
|
||||
* variable for later use.
|
||||
*
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
class Zend_View_Helper_RenderToPlaceholder extends Zend_View_Helper_Abstract
|
||||
{
|
||||
|
||||
/**
|
||||
* Renders a template and stores the rendered output as a placeholder
|
||||
* variable for later use.
|
||||
*
|
||||
* @param $script The template script to render
|
||||
* @param $placeholder The placeholder variable name in which to store the rendered output
|
||||
* @return void
|
||||
*/
|
||||
public function renderToPlaceholder($script, $placeholder)
|
||||
{
|
||||
$this->view->placeholder($placeholder)->captureStart();
|
||||
echo $this->view->render($script);
|
||||
$this->view->placeholder($placeholder)->captureEnd();
|
||||
}
|
||||
}
|
144
library/Zend/View/Helper/ServerUrl.php
Normal file
144
library/Zend/View/Helper/ServerUrl.php
Normal file
|
@ -0,0 +1,144 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: ServerUrl.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* Helper for returning the current server URL (optionally with request URI)
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_ServerUrl
|
||||
{
|
||||
/**
|
||||
* Scheme
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_scheme;
|
||||
|
||||
/**
|
||||
* Host (including port)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_host;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
if (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] === true)) {
|
||||
$scheme = 'https';
|
||||
} else {
|
||||
$scheme = 'http';
|
||||
}
|
||||
$this->setScheme($scheme);
|
||||
|
||||
if (isset($_SERVER['HTTP_HOST']) && !empty($_SERVER['HTTP_HOST'])) {
|
||||
$this->setHost($_SERVER['HTTP_HOST']);
|
||||
} else if (isset($_SERVER['SERVER_NAME'], $_SERVER['SERVER_PORT'])) {
|
||||
$name = $_SERVER['SERVER_NAME'];
|
||||
$port = $_SERVER['SERVER_PORT'];
|
||||
|
||||
if (($scheme == 'http' && $port == 80) ||
|
||||
($scheme == 'https' && $port == 443)) {
|
||||
$this->setHost($name);
|
||||
} else {
|
||||
$this->setHost($name . ':' . $port);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* View helper entry point:
|
||||
* Returns the current host's URL like http://site.com
|
||||
*
|
||||
* @param string|boolean $requestUri [optional] if true, the request URI
|
||||
* found in $_SERVER will be appended
|
||||
* as a path. If a string is given, it
|
||||
* will be appended as a path. Default
|
||||
* is to not append any path.
|
||||
* @return string server url
|
||||
*/
|
||||
public function serverUrl($requestUri = null)
|
||||
{
|
||||
if ($requestUri === true) {
|
||||
$path = $_SERVER['REQUEST_URI'];
|
||||
} else if (is_string($requestUri)) {
|
||||
$path = $requestUri;
|
||||
} else {
|
||||
$path = '';
|
||||
}
|
||||
|
||||
return $this->getScheme() . '://' . $this->getHost() . $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns host
|
||||
*
|
||||
* @return string host
|
||||
*/
|
||||
public function getHost()
|
||||
{
|
||||
return $this->_host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets host
|
||||
*
|
||||
* @param string $host new host
|
||||
* @return Zend_View_Helper_ServerUrl fluent interface, returns self
|
||||
*/
|
||||
public function setHost($host)
|
||||
{
|
||||
$this->_host = $host;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns scheme (typically http or https)
|
||||
*
|
||||
* @return string scheme (typically http or https)
|
||||
*/
|
||||
public function getScheme()
|
||||
{
|
||||
return $this->_scheme;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets scheme (typically http or https)
|
||||
*
|
||||
* @param string $scheme new scheme (typically http or https)
|
||||
* @return Zend_View_Helper_ServerUrl fluent interface, returns self
|
||||
*/
|
||||
public function setScheme($scheme)
|
||||
{
|
||||
$this->_scheme = $scheme;
|
||||
return $this;
|
||||
}
|
||||
}
|
180
library/Zend/View/Helper/Translate.php
Normal file
180
library/Zend/View/Helper/Translate.php
Normal file
|
@ -0,0 +1,180 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Translate.php 20140 2010-01-08 05:21:04Z thomas $
|
||||
*/
|
||||
|
||||
/** Zend_Locale */
|
||||
require_once 'Zend/Locale.php';
|
||||
|
||||
/** Zend_View_Helper_Abstract.php */
|
||||
require_once 'Zend/View/Helper/Abstract.php';
|
||||
|
||||
/**
|
||||
* Translation view helper
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_Translate extends Zend_View_Helper_Abstract
|
||||
{
|
||||
/**
|
||||
* Translation object
|
||||
*
|
||||
* @var Zend_Translate_Adapter
|
||||
*/
|
||||
protected $_translator;
|
||||
|
||||
/**
|
||||
* Constructor for manually handling
|
||||
*
|
||||
* @param Zend_Translate|Zend_Translate_Adapter $translate Instance of Zend_Translate
|
||||
*/
|
||||
public function __construct($translate = null)
|
||||
{
|
||||
if ($translate !== null) {
|
||||
$this->setTranslator($translate);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate a message
|
||||
* You can give multiple params or an array of params.
|
||||
* If you want to output another locale just set it as last single parameter
|
||||
* Example 1: translate('%1\$s + %2\$s', $value1, $value2, $locale);
|
||||
* Example 2: translate('%1\$s + %2\$s', array($value1, $value2), $locale);
|
||||
*
|
||||
* @param string $messageid Id of the message to be translated
|
||||
* @return string|Zend_View_Helper_Translate Translated message
|
||||
*/
|
||||
public function translate($messageid = null)
|
||||
{
|
||||
if ($messageid === null) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$translate = $this->getTranslator();
|
||||
$options = func_get_args();
|
||||
|
||||
array_shift($options);
|
||||
$count = count($options);
|
||||
$locale = null;
|
||||
if ($count > 0) {
|
||||
if (Zend_Locale::isLocale($options[($count - 1)], null, false) !== false) {
|
||||
$locale = array_pop($options);
|
||||
}
|
||||
}
|
||||
|
||||
if ((count($options) === 1) and (is_array($options[0]) === true)) {
|
||||
$options = $options[0];
|
||||
}
|
||||
|
||||
if ($translate !== null) {
|
||||
$messageid = $translate->translate($messageid, $locale);
|
||||
}
|
||||
|
||||
if (count($options) === 0) {
|
||||
return $messageid;
|
||||
}
|
||||
|
||||
return vsprintf($messageid, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a translation Adapter for translation
|
||||
*
|
||||
* @param Zend_Translate|Zend_Translate_Adapter $translate Instance of Zend_Translate
|
||||
* @throws Zend_View_Exception When no or a false instance was set
|
||||
* @return Zend_View_Helper_Translate
|
||||
*/
|
||||
public function setTranslator($translate)
|
||||
{
|
||||
if ($translate instanceof Zend_Translate_Adapter) {
|
||||
$this->_translator = $translate;
|
||||
} else if ($translate instanceof Zend_Translate) {
|
||||
$this->_translator = $translate->getAdapter();
|
||||
} else {
|
||||
require_once 'Zend/View/Exception.php';
|
||||
$e = new Zend_View_Exception('You must set an instance of Zend_Translate or Zend_Translate_Adapter');
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve translation object
|
||||
*
|
||||
* @return Zend_Translate_Adapter|null
|
||||
*/
|
||||
public function getTranslator()
|
||||
{
|
||||
if ($this->_translator === null) {
|
||||
require_once 'Zend/Registry.php';
|
||||
if (Zend_Registry::isRegistered('Zend_Translate')) {
|
||||
$this->setTranslator(Zend_Registry::get('Zend_Translate'));
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_translator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set's an new locale for all further translations
|
||||
*
|
||||
* @param string|Zend_Locale $locale New locale to set
|
||||
* @throws Zend_View_Exception When no Zend_Translate instance was set
|
||||
* @return Zend_View_Helper_Translate
|
||||
*/
|
||||
public function setLocale($locale = null)
|
||||
{
|
||||
$translate = $this->getTranslator();
|
||||
if ($translate === null) {
|
||||
require_once 'Zend/View/Exception.php';
|
||||
$e = new Zend_View_Exception('You must set an instance of Zend_Translate or Zend_Translate_Adapter');
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$translate->setLocale($locale);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the set locale for translations
|
||||
*
|
||||
* @throws Zend_View_Exception When no Zend_Translate instance was set
|
||||
* @return string|Zend_Locale
|
||||
*/
|
||||
public function getLocale()
|
||||
{
|
||||
$translate = $this->getTranslator();
|
||||
if ($translate === null) {
|
||||
require_once 'Zend/View/Exception.php';
|
||||
$e = new Zend_View_Exception('You must set an instance of Zend_Translate or Zend_Translate_Adapter');
|
||||
$e->setView($this->view);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return $translate->getLocale();
|
||||
}
|
||||
}
|
51
library/Zend/View/Helper/Url.php
Normal file
51
library/Zend/View/Helper/Url.php
Normal file
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: Url.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/** Zend_View_Helper_Abstract.php */
|
||||
require_once 'Zend/View/Helper/Abstract.php';
|
||||
|
||||
/**
|
||||
* Helper for making easy links and getting urls that depend on the routes and router
|
||||
*
|
||||
* @package Zend_View
|
||||
* @subpackage Helper
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_View_Helper_Url extends Zend_View_Helper_Abstract
|
||||
{
|
||||
/**
|
||||
* Generates an url given the name of a route.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param array $urlOptions Options passed to the assemble method of the Route object.
|
||||
* @param mixed $name The name of a Route to use. If null it will use the current Route
|
||||
* @param bool $reset Whether or not to reset the route defaults with those provided
|
||||
* @return string Url for the link href attribute.
|
||||
*/
|
||||
public function url(array $urlOptions = array(), $name = null, $reset = false, $encode = true)
|
||||
{
|
||||
$router = Zend_Controller_Front::getInstance()->getRouter();
|
||||
return $router->assemble($urlOptions, $name, $reset, $encode);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue