?
FormImage.php 0000666 00000006141 15125276704 0007142 0 ustar 00 <?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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* 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-2008 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;
}
}
FormMultiCheckbox.php 0000666 00000004455 15125276704 0010667 0 ustar 00 <?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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** 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-2008 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);
}
}
FormLabel.php 0000666 00000004245 15125276704 0007142 0 ustar 00 <?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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** 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-2008 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
$xhtml = '';
} else {
$value = ($escape) ? $this->view->escape($value) : $value;
// enabled; display label
$xhtml = '<label'
. ' for="' . $this->view->escape($id) . '"'
. $this->_htmlAttribs($attribs)
. '>' . $value . '</label>';
}
return $xhtml;
}
}
FormTextarea.php 0000666 00000005720 15125276704 0007677 0 ustar 00 <?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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* 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-2008 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;
}
}
HeadScript.php 0000666 00000035657 15125276704 0007340 0 ustar 00 <?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.
*
* @package Zend_View
* @subpackage Helper
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Placeholder.php 7078 2007-12-11 14:29:33Z 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 script elements for HTML head section
*
* @uses Zend_View_Helper_Placeholder_Container_Standalone
* @package Zend_View
* @subpackage Helper
* @copyright Copyright (c) 2005-2008 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';
throw new Zend_View_Helper_Placeholder_Container_Exception('Cannot nest headScript captures');
}
$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';
throw new Zend_View_Exception(sprintf('Method "%s" requires at least one argument', $method));
}
$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';
throw new Zend_View_Exception(sprintf('Method "%s" requires at least two arguments, an index and source', $method));
}
}
$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';
throw new Zend_View_Exception('Invalid argument passed to append(); please use one of the helper methods, appendScript() or appendFile()');
}
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';
throw new Zend_View_Exception('Invalid argument passed to prepend(); please use one of the helper methods, prependScript() or prependFile()');
}
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';
throw new Zend_View_Exception('Invalid argument passed to set(); please use one of the helper methods, setScript() or setFile()');
}
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';
throw new Zend_View_Exception('Invalid argument passed to offsetSet(); please use one of the helper methods, offsetSetScript() or offsetSetFile()');
}
$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 = $indent . '<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 = '<!--[if ' . $item->attributes['conditional'] . ']> ' . $html . '<![endif]-->';
}
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;
}
}
Interface.php 0000666 00000002604 15125276704 0007174 0 ustar 00 <?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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Interface.php 10664 2008-08-05 10:56:06Z matthew $
*/
/**
* @category Zend
* @package Zend_View
* @subpackage Helper
* @copyright Copyright (c) 2005-2008 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();
}
HtmlElement.php 0000666 00000007671 15125276704 0007523 0 ustar 00 <?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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: HtmlElement.php 12477 2008-11-09 01:55:35Z yoshida@zend.co.jp $
*/
/**
* @see Zend_View_Helper_Abstract
*/
require_once 'Zend/View/Helper/Abstract.php';
/**
* @category Zend
* @package Zend_View
* @subpackage Helper
* @copyright Copyright (c) 2005-2008 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;
}
}
HtmlQuicktime.php 0000666 00000004660 15125276704 0010060 0 ustar 00 <?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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: HtmlQuicktime.php 10192 2008-07-18 20:14:57Z matthew $
*/
/**
* @see Zend_View_Helper_HtmlObject
*/
require_once 'Zend/View/Helper/HtmlObject.php';
/**
* @category Zend
* @package Zend_View
* @subpackage Helper
* @copyright Copyright (c) 2005-2008 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);
}
}
HtmlObject.php 0000666 00000005212 15125276704 0007325 0 ustar 00 <?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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: HtmlObject.php 10192 2008-07-18 20:14:57Z matthew $
*/
/**
* @see Zend_View_Helper_HtmlElement
*/
require_once 'Zend/View/Helper/HtmlElement.php';
/**
* @category Zend
* @package Zend_View
* @subpackage Helper
* @copyright Copyright (c) 2005-2008 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;
}
}
HtmlFlash.php 0000666 00000003711 15125276704 0007156 0 ustar 00 <?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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: HtmlFlash.php 11525 2008-09-26 18:40:19Z norm2782 $
*/
/**
* @see Zend_View_Helper_HtmlObject
*/
require_once 'Zend/View/Helper/HtmlObject.php';
/**
* @category Zend
* @package Zend_View
* @subpackage Helper
* @copyright Copyright (c) 2005-2008 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);
}
}
PaginationControl.php 0000666 00000010617 15125276704 0010731 0 ustar 00 <?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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: PaginationControl.php 12321 2008-11-06 10:44:41Z doctorrock83 $
*/
/**
* @category Zend
* @package Zend_View
* @copyright Copyright (c) 2005-2008 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
*/
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 $partial View partial
*/
public static function setDefaultViewPartial($partial)
{
self::$_defaultViewPartial = $partial;
}
/**
* Gets the default view partial
*
* @return string
*/
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';
throw new Zend_View_Exception('No paginator instance provided or incorrect type');
}
}
if ($partial === null) {
if (self::$_defaultViewPartial === null) {
/**
* @see Zend_View_Exception
*/
require_once 'Zend/View/Exception.php';
throw new Zend_View_Exception('No view partial provided and no default set');
}
$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';
throw new Zend_View_Exception('A view partial supplied as an array must contain two values: the filename and its module');
}
if ($partial[1] !== null) {
return $this->view->partial($partial[0], $partial[1], $pages);
}
$partial = $partial[0];
}
return $this->view->partial($partial, $pages);
}
} HeadTitle.php 0000666 00000012352 15125276704 0007140 0 ustar 00 <?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.
*
* @package Zend_View
* @subpackage Helper
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Placeholder.php 7078 2007-12-11 14:29:33Z 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 title element for HTML head
*
* @uses Zend_View_Helper_Placeholder_Container_Standalone
* @package Zend_View
* @subpackage Helper
* @copyright Copyright (c) 2005-2008 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)
{
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';
throw new Zend_View_Exception("You must set an instance of Zend_Translate or Zend_Translate_Adapter");
}
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>';
}
}
FormFile.php 0000666 00000004645 15125276704 0007006 0 ustar 00 <?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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* 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-2008 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;
}
}
FormElement.php 0000666 00000013117 15125276704 0007512 0 ustar 00 <?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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* @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-2008 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
{
/**
* 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();
}
}
HeadStyle.php 0000666 00000027624 15125276704 0007167 0 ustar 00 <?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.
*
* @package Zend_View
* @subpackage Helper
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Placeholder.php 7078 2007-12-11 14:29:33Z 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-2008 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';
throw new Zend_View_Exception(sprintf('Method "%s" requires minimally content for the stylesheet', $method));
}
$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';
throw new Zend_View_Exception('Invalid value passed to append; please use appendStyle()');
}
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';
throw new Zend_View_Exception('Invalid value passed to offsetSet; please use offsetSetStyle()');
}
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';
throw new Zend_View_Exception('Invalid value passed to prepend; please use prependStyle()');
}
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';
throw new Zend_View_Exception('Invalid value passed to set; please use setStyle()');
}
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';
throw new Zend_View_Helper_Placeholder_Container_Exception('Cannot nest headStyle captures');
}
$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)) {
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) {
if (!in_array($type, $this->_mediaTypes)) {
continue;
}
$value .= $type .',';
}
$value = substr($value, 0, -1);
}
}
$attrString .= sprintf(' %s="%s"', $key, htmlspecialchars($value));
}
}
$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;
}
}
Partial/Exception.php 0000666 00000002333 15125276704 0010625 0 ustar 00 <?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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Exception.php 8064 2008-02-16 10:58:39Z thomas $
* @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-2008 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
{
}
Fieldset.php 0000666 00000004630 15125276704 0007034 0 ustar 00 <?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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Fieldset.php 11301 2008-09-08 20:09:10Z matthew $
* @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-2008 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;
}
}
FormButton.php 0000666 00000006242 15125276704 0007375 0 ustar 00 <?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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* 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-2008 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;
}
}
FormNote.php 0000666 00000003517 15125276704 0007031 0 ustar 00 <?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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* 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-2008 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;
}
}
Placeholder.php 0000666 00000005036 15125276704 0007520 0 ustar 00 <?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.
*
* @package Zend_View
* @subpackage Helper
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Placeholder.php 10664 2008-08-05 10:56:06Z 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';
/**
* 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-2008 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;
}
}
FormSelect.php 0000666 00000013540 15125276704 0007340 0 ustar 00 <?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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* 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-2008 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();
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"';
}
$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;
}
}
Placeholder/Registry/Exception.php 0000666 00000002365 15125276704 0013270 0 ustar 00 <?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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Exception.php 8064 2008-02-16 10:58:39Z thomas $
* @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-2008 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
{
}
Placeholder/Container.php 0000666 00000002373 15125276704 0011443 0 ustar 00 <?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.
*
* @package Zend_View
* @subpackage Helper
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Container.php 9099 2008-03-30 19:35:47Z thomas $
* @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-2008 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
{
}
Placeholder/Registry.php 0000666 00000011702 15125276704 0011325 0 ustar 00 <?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.
*
* @package Zend_View
* @subpackage Helper
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Registry.php 9099 2008-03-30 19:35:47Z thomas $
* @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-2008 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)
{
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';
throw new Zend_View_Helper_Placeholder_Registry_Exception('Invalid Container class specified');
}
$this->_containerClass = $name;
return $this;
}
/**
* Retrieve the container class
*
* @return string
*/
public function getContainerClass()
{
return $this->_containerClass;
}
}
Placeholder/Container/Abstract.php 0000666 00000023175 15125276704 0013211 0 ustar 00 <?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.
*
* @package Zend_View
* @subpackage Helper
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Abstract.php 9099 2008-03-30 19:35:47Z thomas $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Abstract class representing container for placeholder values
*
* @package Zend_View
* @subpackage Helpers
* @copyright Copyright (c) 2005-2008 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';
throw new Zend_View_Helper_Placeholder_Container_Exception('Cannot nest placeholder captures for the same placeholder');
}
$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();
}
}
Placeholder/Container/Exception.php 0000666 00000002367 15125276704 0013404 0 ustar 00 <?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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Exception.php 8064 2008-02-16 10:58:39Z thomas $
* @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-2008 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
{
}
Placeholder/Container/Standalone.php 0000666 00000017376 15125276704 0013544 0 ustar 00 <?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.
*
* @package Zend_View
* @subpackage Helper
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Standalone.php 13198 2008-12-13 13:51:40Z 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-2008 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)
{
if ($this->view instanceof Zend_View_Interface) {
return $this->view->escape($string);
}
return htmlentities((string) $string, null, 'UTF-8');
}
/**
* 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';
throw new Zend_View_Exception('Method "' . $method . '" does not exist');
}
/**
* 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();
}
}
Partial.php 0000666 00000011402 15125276704 0006664 0 ustar 00 <?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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Partial.php 12577 2008-11-12 01:31:34Z sidhighwind $
* @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-2008 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';
throw new Zend_View_Helper_Partial_Exception('Cannot render partial; module does not exist');
}
$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;
}
}
FormReset.php 0000666 00000005161 15125276704 0007203 0 ustar 00 <?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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* 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-2008 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;
}
}
RenderToPlaceholder.php 0000666 00000002715 15125276704 0011164 0 ustar 00 <?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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id:$
* @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-2008 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
{
public function renderToPlaceholder($script, $placeholder)
{
$this->view->placeholder($placeholder)->captureStart();
echo $this->view->render($script);
$this->view->placeholder($placeholder)->captureEnd();
}
}
PartialLoop.php 0000666 00000006304 15125276704 0007523 0 ustar 00 <?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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: PartialLoop.php 13032 2008-12-05 02:43:17Z sidhighwind $
* @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-2008 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';
throw new Zend_View_Helper_Partial_Exception('PartialLoop helper requires iterable data');
}
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;
}
}
FormPassword.php 0000666 00000005622 15125276704 0007725 0 ustar 00 <?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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* 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-2008 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;
}
}
Abstract.php 0000666 00000003305 15125276704 0007036 0 ustar 00 <?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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Abstract.php 10664 2008-08-05 10:56:06Z matthew $
*/
/**
* @see Zend_View_Helper_Interface
*/
require_once 'Zend/View/Helper/Interface.php';
/**
* @category Zend
* @package Zend_View
* @subpackage Helper
* @copyright Copyright (c) 2005-2008 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()
{
}
}
NumberTextBox.php 0000666 00000004016 15125471063 0010034 0 ustar 00 <?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_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: NumberTextBox.php 9998 2008-07-08 19:54:41Z matthew $
*/
/** Zend_Dojo_View_Helper_Dijit */
require_once 'Zend/Dojo/View/Helper/Dijit.php';
/**
* Dojo NumberTextBox dijit
*
* @uses Zend_Dojo_View_Helper_Dijit
* @package Zend_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Dojo_View_Helper_NumberTextBox extends Zend_Dojo_View_Helper_Dijit
{
/**
* Dijit being used
* @var string
*/
protected $_dijit = 'dijit.form.NumberTextBox';
/**
* HTML element type
* @var string
*/
protected $_elementType = 'text';
/**
* Dojo module to use
* @var string
*/
protected $_module = 'dijit.form.NumberTextBox';
/**
* dijit.form.NumberTextBox
*
* @param int $id
* @param mixed $value
* @param array $params Parameters to use for dijit creation
* @param array $attribs HTML attributes
* @return string
*/
public function numberTextBox($id, $value = null, array $params = array(), array $attribs = array())
{
return $this->_createFormElement($id, $value, $params, $attribs);
}
}
DateTextBox.php 0000666 00000004000 15125471063 0007452 0 ustar 00 <?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_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: DateTextBox.php 9998 2008-07-08 19:54:41Z matthew $
*/
/** Zend_Dojo_View_Helper_Dijit */
require_once 'Zend/Dojo/View/Helper/Dijit.php';
/**
* Dojo DateTextBox dijit
*
* @uses Zend_Dojo_View_Helper_Dijit
* @package Zend_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Dojo_View_Helper_DateTextBox extends Zend_Dojo_View_Helper_Dijit
{
/**
* Dijit being used
* @var string
*/
protected $_dijit = 'dijit.form.DateTextBox';
/**
* HTML element type
* @var string
*/
protected $_elementType = 'text';
/**
* Dojo module to use
* @var string
*/
protected $_module = 'dijit.form.DateTextBox';
/**
* dijit.form.DateTextBox
*
* @param int $id
* @param mixed $value
* @param array $params Parameters to use for dijit creation
* @param array $attribs HTML attributes
* @return string
*/
public function dateTextBox($id, $value = null, array $params = array(), array $attribs = array())
{
return $this->_createFormElement($id, $value, $params, $attribs);
}
}
NumberSpinner.php 0000666 00000005551 15125471063 0010062 0 ustar 00 <?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_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: NumberSpinner.php 10043 2008-07-11 15:41:54Z matthew $
*/
/** Zend_Dojo_View_Helper_Dijit */
require_once 'Zend/Dojo/View/Helper/Dijit.php';
/**
* Dojo NumberSpinner dijit
*
* @uses Zend_Dojo_View_Helper_Dijit
* @package Zend_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Dojo_View_Helper_NumberSpinner extends Zend_Dojo_View_Helper_Dijit
{
/**
* Dijit being used
* @var string
*/
protected $_dijit = 'dijit.form.NumberSpinner';
/**
* HTML element type
* @var string
*/
protected $_elementType = 'text';
/**
* Dojo module to use
* @var string
*/
protected $_module = 'dijit.form.NumberSpinner';
/**
* dijit.form.NumberSpinner
*
* @param int $id
* @param mixed $value
* @param array $params Parameters to use for dijit creation
* @param array $attribs HTML attributes
* @return string
*/
public function numberSpinner($id, $value = null, array $params = array(), array $attribs = array())
{
// Get constraints and serialize to JSON if necessary
if (array_key_exists('constraints', $params)) {
if (!is_array($params['constraints'])) {
unset($params['constraints']);
}
} else {
$constraints = array();
if (array_key_exists('min', $params)) {
$constraints['min'] = $params['min'];
unset($params['min']);
}
if (array_key_exists('max', $params)) {
$constraints['max'] = $params['max'];
unset($params['max']);
}
if (array_key_exists('places', $params)) {
$constraints['places'] = $params['places'];
unset($params['places']);
}
$params['constraints'] = $constraints;
}
return $this->_createFormElement($id, $value, $params, $attribs);
}
}
AccordionPane.php 0000666 00000004062 15125471063 0007774 0 ustar 00 <?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_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: AccordionPane.php 10067 2008-07-12 21:05:32Z matthew $
*/
/** Zend_Dojo_View_Helper_DijitContainer */
require_once 'Zend/Dojo/View/Helper/DijitContainer.php';
/**
* Dojo AccordionPane dijit
*
* @uses Zend_Dojo_View_Helper_DijitContainer
* @package Zend_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Dojo_View_Helper_AccordionPane extends Zend_Dojo_View_Helper_DijitContainer
{
/**
* Dijit being used
* @var string
*/
protected $_dijit = 'dijit.layout.AccordionPane';
/**
* Module being used
* @var string
*/
protected $_module = 'dijit.layout.AccordionContainer';
/**
* dijit.layout.AccordionPane
*
* @param int $id
* @param string $content
* @param array $params Parameters to use for dijit creation
* @param array $attribs HTML attributes
* @return string
*/
public function accordionPane($id = null, $content = '', array $params = array(), array $attribs = array())
{
if (0 === func_num_args()) {
return $this;
}
return $this->_createLayoutContainer($id, $content, $params, $attribs);
}
}
RadioButton.php 0000666 00000005600 15125471063 0007520 0 ustar 00 <?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_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: RadioButton.php 10091 2008-07-15 03:46:37Z matthew $
*/
/** Zend_Dojo_View_Helper_Dijit */
require_once 'Zend/Dojo/View/Helper/Dijit.php';
/**
* Dojo RadioButton dijit
*
* @uses Zend_Dojo_View_Helper_Dijit
* @package Zend_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Dojo_View_Helper_RadioButton extends Zend_Dojo_View_Helper_Dijit
{
/**
* Dijit being used
* @var string
*/
protected $_dijit = 'dijit.form.RadioButton';
/**
* Dojo module to use
* @var string
*/
protected $_module = 'dijit.form.CheckBox';
/**
* dijit.form.RadioButton
*
* @param string $id
* @param string $value
* @param array $params Parameters to use for dijit creation
* @param array $attribs HTML attributes
* @param array $options Array of radio options
* @param string $listsep String with which to separate options
* @return string
*/
public function radioButton(
$id,
$value = null,
array $params = array(),
array $attribs = array(),
array $options = null,
$listsep = "<br />\n"
) {
$attribs['name'] = $id;
if (!array_key_exists('id', $attribs)) {
$attribs['id'] = $id;
}
$attribs = $this->_prepareDijit($attribs, $params, 'element');
if (is_array($options) && $this->_useProgrammatic() && !$this->_useProgrammaticNoScript()) {
$baseId = $id;
if (array_key_exists('id', $attribs)) {
$baseId = $attribs['id'];
}
require_once 'Zend/Filter/Alnum.php';
$filter = new Zend_Filter_Alnum();
foreach (array_keys($options) as $key) {
$optId = $baseId . '-' . $filter->filter($key);
$this->_createDijit($this->_dijit, $optId, array());
}
}
return $this->view->formRadio($id, $value, $attribs, $options, $listsep);
}
}
Button.php 0000666 00000004072 15125471063 0006543 0 ustar 00 <?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_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Button.php 10091 2008-07-15 03:46:37Z matthew $
*/
/** Zend_Dojo_View_Helper_Dijit */
require_once 'Zend/Dojo/View/Helper/Dijit.php';
/**
* Dojo Button dijit
*
* @uses Zend_Dojo_View_Helper_Dijit
* @package Zend_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Dojo_View_Helper_Button extends Zend_Dojo_View_Helper_Dijit
{
/**
* Dijit being used
* @var string
*/
protected $_dijit = 'dijit.form.Button';
/**
* Dojo module to use
* @var string
*/
protected $_module = 'dijit.form.Button';
/**
* dijit.form.Button
*
* @param string $id
* @param string $value
* @param array $params Parameters to use for dijit creation
* @param array $attribs HTML attributes
* @return string
*/
public function button($id, $value = null, array $params = array(), array $attribs = array())
{
$attribs['name'] = $id;
if (!array_key_exists('id', $attribs)) {
$attribs['id'] = $id;
}
$attribs = $this->_prepareDijit($attribs, $params, 'element');
return $this->view->formButton($id, $value, $attribs);
}
}
Form.php 0000666 00000005163 15125471063 0006175 0 ustar 00 <?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_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Form.php 10196 2008-07-18 22:01:18Z matthew $
*/
/** Zend_Dojo_View_Helper_Dijit */
require_once 'Zend/Dojo/View/Helper/Dijit.php';
/**
* Dojo Form dijit
*
* @uses Zend_Dojo_View_Helper_Dijit
* @package Zend_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Dojo_View_Helper_Form extends Zend_Dojo_View_Helper_Dijit
{
/**
* Dijit being used
* @var string
*/
protected $_dijit = 'dijit.form.Form';
/**
* Module being used
* @var string
*/
protected $_module = 'dijit.form.Form';
/**
* @var Zend_View_Helper_Form
*/
protected $_helper;
/**
* dijit.form.Form
*
* @param string $id
* @param null|array $attribs HTML attributes
* @param false|string $content
* @return string
*/
public function form($id, $attribs = null, $content = false)
{
if (!is_array($attribs)) {
$attribs = (array) $attribs;
}
if (array_key_exists('id', $attribs)) {
$attribs['name'] = $id;
} else {
$attribs['id'] = $id;
}
if (false === $content) {
$content = '';
}
$attribs = $this->_prepareDijit($attribs, array(), 'layout');
return $this->getFormHelper()->form($id, $attribs, $content);
}
/**
* Get standard form helper
*
* @return Zend_View_Helper_Form
*/
public function getFormHelper()
{
if (null === $this->_helper) {
require_once 'Zend/View/Helper/Form.php';
$this->_helper = new Zend_View_Helper_Form;
$this->_helper->setView($this->view);
}
return $this->_helper;
}
}
TimeTextBox.php 0000666 00000004000 15125471063 0007473 0 ustar 00 <?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_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: TimeTextBox.php 9998 2008-07-08 19:54:41Z matthew $
*/
/** Zend_Dojo_View_Helper_Dijit */
require_once 'Zend/Dojo/View/Helper/Dijit.php';
/**
* Dojo TimeTextBox dijit
*
* @uses Zend_Dojo_View_Helper_Dijit
* @package Zend_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Dojo_View_Helper_TimeTextBox extends Zend_Dojo_View_Helper_Dijit
{
/**
* Dijit being used
* @var string
*/
protected $_dijit = 'dijit.form.TimeTextBox';
/**
* HTML element type
* @var string
*/
protected $_elementType = 'text';
/**
* Dojo module to use
* @var string
*/
protected $_module = 'dijit.form.TimeTextBox';
/**
* dijit.form.TimeTextBox
*
* @param int $id
* @param mixed $value
* @param array $params Parameters to use for dijit creation
* @param array $attribs HTML attributes
* @return string
*/
public function timeTextBox($id, $value = null, array $params = array(), array $attribs = array())
{
return $this->_createFormElement($id, $value, $params, $attribs);
}
}
SplitContainer.php 0000666 00000004070 15125471063 0010224 0 ustar 00 <?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_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: SplitContainer.php 10067 2008-07-12 21:05:32Z matthew $
*/
/** Zend_Dojo_View_Helper_DijitContainer */
require_once 'Zend/Dojo/View/Helper/DijitContainer.php';
/**
* Dojo SplitContainer dijit
*
* @uses Zend_Dojo_View_Helper_DijitContainer
* @package Zend_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Dojo_View_Helper_SplitContainer extends Zend_Dojo_View_Helper_DijitContainer
{
/**
* Dijit being used
* @var string
*/
protected $_dijit = 'dijit.layout.SplitContainer';
/**
* Dojo module to use
* @var string
*/
protected $_module = 'dijit.layout.SplitContainer';
/**
* dijit.layout.SplitContainer
*
* @param string $id
* @param string $content
* @param array $params Parameters to use for dijit creation
* @param array $attribs HTML attributes
* @return string
*/
public function splitContainer($id = null, $content = '', array $params = array(), array $attribs = array())
{
if (0 === func_num_args()) {
return $this;
}
return $this->_createLayoutContainer($id, $content, $params, $attribs);
}
}
CheckBox.php 0000666 00000006371 15125471063 0006762 0 ustar 00 <?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_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: CheckBox.php 11292 2008-09-08 18:51:39Z matthew $
*/
/** Zend_Dojo_View_Helper_Dijit */
require_once 'Zend/Dojo/View/Helper/Dijit.php';
/**
* Dojo CheckBox dijit
*
* @uses Zend_Dojo_View_Helper_Dijit
* @package Zend_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Dojo_View_Helper_CheckBox extends Zend_Dojo_View_Helper_Dijit
{
/**
* Dijit being used
* @var string
*/
protected $_dijit = 'dijit.form.CheckBox';
/**
* Element type
* @var string
*/
protected $_elementType = 'checkbox';
/**
* Dojo module to use
* @var string
*/
protected $_module = 'dijit.form.CheckBox';
/**
* dijit.form.CheckBox
*
* @param int $id
* @param string $content
* @param array $params Parameters to use for dijit creation
* @param array $attribs HTML attributes
* @param array $checkedOptions Should contain either two items, or the keys checkedValue and unCheckedValue
* @return string
*/
public function checkBox($id, $value = null, array $params = array(), array $attribs = array(), array $checkedOptions = null)
{
// Prepare the checkbox options
require_once 'Zend/View/Helper/FormCheckbox.php';
$checked = false;
if (isset($attribs['checked']) && $attribs['checked']) {
$checked = true;
} elseif (isset($attribs['checked'])) {
$checked = false;
}
$checkboxInfo = Zend_View_Helper_FormCheckbox::determineCheckboxInfo($value, $checked, $checkedOptions);
$attribs['checked'] = $checkboxInfo['checked'];
if (!array_key_exists('id', $attribs)) {
$attribs['id'] = $id;
}
$attribs = $this->_prepareDijit($attribs, $params, 'element');
// strip options so they don't show up in markup
if (array_key_exists('options', $attribs)) {
unset($attribs['options']);
}
// and now we create it:
$html = '';
if (!strstr($id, '[]')) {
// hidden element for unchecked value
$html .= $this->_renderHiddenElement($id, $checkboxInfo['unCheckedValue']);
}
// and final element
$html .= $this->_createFormElement($id, $checkboxInfo['checkedValue'], $params, $attribs);
return $html;
}
}
DijitContainer.php 0000666 00000005556 15125471063 0010206 0 ustar 00 <?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_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: DijitContainer.php 11744 2008-10-08 18:06:15Z matthew $
*/
/** Zend_Dojo_View_Helper_Dijit */
require_once 'Zend/Dojo/View/Helper/Dijit.php';
/**
* Dijit layout container base class
*
* @uses Zend_Dojo_View_Helper_Dijit
* @package Zend_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Dojo_View_Helper_DijitContainer extends Zend_Dojo_View_Helper_Dijit
{
/**
* Capture locks
* @var array
*/
protected $_captureLock = array();
/**
* Metadata information to use with captured content
* @var array
*/
protected $_captureInfo = array();
/**
* Begin capturing content for layout container
*
* @param string $id
* @param array $params
* @param array $attribs
* @return void
*/
public function captureStart($id, array $params = array(), array $attribs = array())
{
if (array_key_exists($id, $this->_captureLock)) {
require_once 'Zend/Dojo/View/Exception.php';
throw new Zend_Dojo_View_Exception(sprintf('Lock already exists for id "%s"', $id));
}
$this->_captureLock[$id] = true;
$this->_captureInfo[$id] = array(
'params' => $params,
'attribs' => $attribs,
);
ob_start();
return;
}
/**
* Finish capturing content for layout container
*
* @param string $id
* @return string
*/
public function captureEnd($id)
{
if (!array_key_exists($id, $this->_captureLock)) {
require_once 'Zend/Dojo/View/Exception.php';
throw new Zend_Dojo_View_Exception(sprintf('No capture lock exists for id "%s"; nothing to capture', $id));
}
$content = ob_get_clean();
extract($this->_captureInfo[$id]);
unset($this->_captureLock[$id], $this->_captureInfo[$id]);
return $this->_createLayoutContainer($id, $content, $params, $attribs);
}
}
ComboBox.php 0000666 00000011655 15125471063 0007005 0 ustar 00 <?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_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: ComboBox.php 14300 2009-03-13 15:24:35Z matthew $
*/
/** Zend_Dojo_View_Helper_Dijit */
require_once 'Zend/Dojo/View/Helper/Dijit.php';
/**
* Dojo ComboBox dijit
*
* @uses Zend_Dojo_View_Helper_Dijit
* @package Zend_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Dojo_View_Helper_ComboBox extends Zend_Dojo_View_Helper_Dijit
{
/**
* Dijit being used
* @var string
*/
protected $_dijit = 'dijit.form.ComboBox';
/**
* HTML element type
* @var string
*/
protected $_elementType = 'text';
/**
* Dojo module to use
* @var string
*/
protected $_module = 'dijit.form.ComboBox';
/**
* dijit.form.ComboBox
*
* @param int $id
* @param mixed $value
* @param array $params Parameters to use for dijit creation
* @param array $attribs HTML attributes
* @param array|null $options Select options
* @return string
*/
public function comboBox($id, $value = null, array $params = array(), array $attribs = array(), array $options = null)
{
$html = '';
if (!array_key_exists('id', $attribs)) {
$attribs['id'] = $id;
}
if (array_key_exists('store', $params) && is_array($params['store'])) {
// using dojo.data datastore
if (false !== ($store = $this->_renderStore($params['store']))) {
$params['store'] = $params['store']['store'];
if (is_string($store)) {
$html .= $store;
}
$html .= $this->_createFormElement($id, $value, $params, $attribs);
return $html;
}
unset($params['store']);
} elseif (array_key_exists('store', $params)) {
if (array_key_exists('storeType', $params)) {
$storeParams = array(
'store' => $params['store'],
'type' => $params['storeType'],
);
unset($params['storeType']);
if (array_key_exists('storeParams', $params)) {
$storeParams['params'] = $params['storeParams'];
unset($params['storeParams']);
}
if (false !== ($store = $this->_renderStore($storeParams))) {
if (is_string($store)) {
$html .= $store;
}
}
}
$html .= $this->_createFormElement($id, $value, $params, $attribs);
return $html;
}
// do as normal select
$attribs = $this->_prepareDijit($attribs, $params, 'element');
return $this->view->formSelect($id, $value, $attribs, $options);
}
/**
* Render data store element
*
* Renders to dojo view helper
*
* @param array $params
* @return string|false
*/
protected function _renderStore(array $params)
{
if (!array_key_exists('store', $params) || !array_key_exists('type', $params)) {
return false;
}
$this->dojo->requireModule($params['type']);
$extraParams = array();
$storeParams = array(
'dojoType' => $params['type'],
'jsId' => $params['store'],
);
if (array_key_exists('params', $params)) {
$storeParams = array_merge($storeParams, $params['params']);
$extraParams = $params['params'];
}
if ($this->_useProgrammatic()) {
if (!$this->_useProgrammaticNoScript()) {
require_once 'Zend/Json.php';
$js = 'var ' . $storeParams['jsId'] . ' = '
. 'new ' . $storeParams['dojoType'] . '('
. Zend_Json::encode($extraParams)
. ");\n";
$this->dojo->addJavascript($js);
}
return true;
}
return '<div' . $this->_htmlAttribs($storeParams) . '></div>';
}
}
Editor.php 0000666 00000007275 15125471063 0006526 0 ustar 00 <?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_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: $
*/
/** Zend_Dojo_View_Helper_Textarea */
require_once 'Zend/Dojo/View/Helper/Textarea.php';
/** Zend_Json */
require_once 'Zend/Json.php';
/**
* Dojo Editor dijit
*
* @uses Zend_Dojo_View_Helper_Textarea
* @package Zend_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Dojo_View_Helper_Editor extends Zend_Dojo_View_Helper_Textarea
{
/**
* @param string Dijit type
*/
protected $_dijit = 'dijit.Editor';
/**
* @var string Dijit module to load
*/
protected $_module = 'dijit.Editor';
/**
* JSON-encoded parameters
* @var array
*/
protected $_jsonParams = array('captureEvents', 'events', 'plugins');
/**
* dijit.Editor
*
* @param string $id
* @param string $value
* @param array $params
* @param array $attribs
* @return string
*/
public function editor($id, $value = null, $params = array(), $attribs = array())
{
$hiddenName = $id;
if (array_key_exists('id', $attribs)) {
$hiddenId = $attribs['id'];
} else {
$hiddenId = $hiddenName;
}
$hiddenId = $this->_normalizeId($hiddenId);
$textareaName = $this->_normalizeEditorName($hiddenName);
$textareaId = $hiddenId . '-Editor';
$hiddenAttribs = array(
'id' => $hiddenId,
'name' => $hiddenName,
'value' => $value,
'type' => 'hidden',
);
$attribs['id'] = $textareaId;
$this->_createGetParentFormFunction();
$this->_createEditorOnSubmit($hiddenId, $textareaId);
$html = '<input' . $this->_htmlAttribs($hiddenAttribs) . $this->getClosingBracket()
. $this->textarea($textareaName, $value, $params, $attribs);
return $html;
}
/**
* Normalize editor element name
*
* @param string $name
* @return string
*/
protected function _normalizeEditorName($name)
{
if ('[]' == substr($name, -2)) {
$name = substr($name, 0, strlen($name) - 2);
$name .= '[Editor][]';
} else {
$name .= '[Editor]';
}
return $name;
}
/**
* Create onSubmit binding for element
*
* @param string $hiddenId
* @param string $editorId
* @return void
*/
protected function _createEditorOnSubmit($hiddenId, $editorId)
{
$this->dojo->onLoadCaptureStart();
echo <<<EOJ
function() {
var form = zend.findParentForm(dojo.byId('$hiddenId'));
dojo.connect(form, 'onsubmit', function () {
dojo.byId('$hiddenId').value = dijit.byId('$editorId').getValue(false);
});
}
EOJ;
$this->dojo->onLoadCaptureEnd();
}
}
Dojo/Container.php 0000666 00000064021 15125471063 0010105 0 ustar 00 <?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_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Container.php 14166 2009-02-25 17:58:58Z matthew $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Dojo */
require_once 'Zend/Dojo.php';
/**
* Container for Dojo View Helper
*
*
* @package Zend_Dojo
* @subpackage View
* @copyright Copyright (C) 2008 - Present, Zend Technologies, Inc.
* @license New BSD {@link http://framework.zend.com/license/new-bsd}
*/
class Zend_Dojo_View_Helper_Dojo_Container
{
/**
* @var Zend_View_Interface
*/
public $view;
/**
* addOnLoad capture lock
* @var bool
*/
protected $_captureLock = false;
/**
* addOnLoad object on which to apply lambda
* @var string
*/
protected $_captureObj;
/**
* Base CDN url to utilize
* @var string
*/
protected $_cdnBase = Zend_Dojo::CDN_BASE_GOOGLE;
/**
* Path segment following version string of CDN path
* @var string
*/
protected $_cdnDojoPath = Zend_Dojo::CDN_DOJO_PATH_GOOGLE;
/**
* Dojo version to use from CDN
* @var string
*/
protected $_cdnVersion = '1.2.0';
/**
* Has the dijit loader been registered?
* @var bool
*/
protected $_dijitLoaderRegistered = false;
/**
* Registered programmatic dijits
* @var array
*/
protected $_dijits = array();
/**
* Dojo configuration
* @var array
*/
protected $_djConfig = array();
/**
* Whether or not dojo is enabled
* @var bool
*/
protected $_enabled = false;
/**
* Are we rendering as XHTML?
* @var bool
*/
protected $_isXhtml = false;
/**
* Arbitrary javascript to include in dojo script
* @var array
*/
protected $_javascriptStatements = array();
/**
* Dojo layers (custom builds) to use
* @var array
*/
protected $_layers = array();
/**
* Relative path to dojo
* @var string
*/
protected $_localPath = null;
/**
* Root of dojo where all dojo files are installed
* @var string
*/
protected $_localRelativePath = null;
/**
* Modules to require
* @var array
*/
protected $_modules = array();
/**
* Registered module paths
* @var array
*/
protected $_modulePaths = array();
/**
* Actions to perform on window load
* @var array
*/
protected $_onLoadActions = array();
/**
* Register the Dojo stylesheet?
* @var bool
*/
protected $_registerDojoStylesheet = false;
/**
* Style sheet modules to load
* @var array
*/
protected $_stylesheetModules = array();
/**
* Local stylesheets
* @var array
*/
protected $_stylesheets = array();
/**
* Set view object
*
* @param Zend_Dojo_View_Interface $view
* @return void
*/
public function setView(Zend_View_Interface $view)
{
$this->view = $view;
}
/**
* Enable dojo
*
* @return Zend_Dojo_View_Helper_Dojo_Container
*/
public function enable()
{
$this->_enabled = true;
return $this;
}
/**
* Disable dojo
*
* @return Zend_Dojo_View_Helper_Dojo_Container
*/
public function disable()
{
$this->_enabled = false;
return $this;
}
/**
* Is dojo enabled?
*
* @return bool
*/
public function isEnabled()
{
return $this->_enabled;
}
/**
* Specify a module to require
*
* @param string $module
* @return Zend_Dojo_View_Helper_Dojo_Container
*/
public function requireModule($module)
{
if (!is_string($module) && !is_array($module)) {
require_once 'Zend/Dojo/View/Exception.php';
throw new Zend_Dojo_View_Exception('Invalid module name specified; must be a string or an array of strings');
}
$module = (array) $module;
foreach ($module as $mod) {
if (!preg_match('/^[a-z][a-z0-9._-]+$/i', $mod)) {
require_once 'Zend/Dojo/View/Exception.php';
throw new Zend_Dojo_View_Exception(sprintf('Module name specified, "%s", contains invalid characters', (string) $mod));
}
if (!in_array($mod, $this->_modules)) {
$this->_modules[] = $mod;
}
}
return $this;
}
/**
* Retrieve list of modules to require
*
* @return array
*/
public function getModules()
{
return $this->_modules;
}
/**
* Register a module path
*
* @param string $path
* @return Zend_Dojo_View_Helper_Dojo_Container
*/
public function registerModulePath($module, $path)
{
$path = (string) $path;
if (!in_array($module, $this->_modulePaths)) {
$this->_modulePaths[$module] = $path;
}
return $this;
}
/**
* List registered module paths
*
* @return array
*/
public function getModulePaths()
{
return $this->_modulePaths;
}
/**
* Add layer (custom build) path
*
* @param string $path
* @return Zend_Dojo_View_Helper_Dojo_Container
*/
public function addLayer($path)
{
$path = (string) $path;
if (!in_array($path, $this->_layers)) {
$this->_layers[] = $path;
}
return $this;
}
/**
* Get registered layers
*
* @return array
*/
public function getLayers()
{
return $this->_layers;
}
/**
* Remove a registered layer
*
* @param string $path
* @return Zend_Dojo_View_Helper_Dojo_Container
*/
public function removeLayer($path)
{
$path = (string) $path;
$layers = array_flip($this->_layers);
if (array_key_exists($path, $layers)) {
unset($layers[$path]);
$this->_layers = array_keys($layers);
}
return $this;
}
/**
* Clear all registered layers
*
* @return Zend_Dojo_View_Helper_Dojo_Container
*/
public function clearLayers()
{
$this->_layers = array();
return $this;
}
/**
* Set CDN base path
*
* @param string $url
* @return Zend_Dojo_View_Helper_Dojo_Container
*/
public function setCdnBase($url)
{
$this->_cdnBase = (string) $url;
return $this;
}
/**
* Return CDN base URL
*
* @return string
*/
public function getCdnBase()
{
return $this->_cdnBase;
}
/**
* Use CDN, using version specified
*
* @param string $version
* @return Zend_Dojo_View_Helper_Dojo_Container
*/
public function setCdnVersion($version = null)
{
$this->enable();
if (preg_match('/^[1-9]\.[0-9](\.[0-9])?$/', $version)) {
$this->_cdnVersion = $version;
}
return $this;
}
/**
* Get CDN version
*
* @return string
*/
public function getCdnVersion()
{
return $this->_cdnVersion;
}
/**
* Set CDN path to dojo (relative to CDN base + version)
*
* @param string $path
* @return Zend_Dojo_View_Helper_Dojo_Container
*/
public function setCdnDojoPath($path)
{
$this->_cdnDojoPath = (string) $path;
return $this;
}
/**
* Get CDN path to dojo (relative to CDN base + version)
*
* @return string
*/
public function getCdnDojoPath()
{
return $this->_cdnDojoPath;
}
/**
* Are we using the CDN?
*
* @return bool
*/
public function useCdn()
{
return !$this->useLocalPath();
}
/**
* Set path to local dojo
*
* @param string $path
* @return Zend_Dojo_View_Helper_Dojo_Container
*/
public function setLocalPath($path)
{
$this->enable();
$this->_localPath = (string) $path;
return $this;
}
/**
* Get local path to dojo
*
* @return string
*/
public function getLocalPath()
{
return $this->_localPath;
}
/**
* Are we using a local path?
*
* @return bool
*/
public function useLocalPath()
{
return (null === $this->_localPath) ? false : true;
}
/**
* Set Dojo configuration
*
* @param string $option
* @param mixed $value
* @return Zend_Dojo_View_Helper_Dojo_Container
*/
public function setDjConfig(array $config)
{
$this->_djConfig = $config;
return $this;
}
/**
* Set Dojo configuration option
*
* @param string $option
* @param mixed $value
* @return Zend_Dojo_View_Helper_Dojo_Container
*/
public function setDjConfigOption($option, $value)
{
$option = (string) $option;
$this->_djConfig[$option] = $value;
return $this;
}
/**
* Retrieve dojo configuration values
*
* @return array
*/
public function getDjConfig()
{
return $this->_djConfig;
}
/**
* Get dojo configuration value
*
* @param string $option
* @param mixed $default
* @return mixed
*/
public function getDjConfigOption($option, $default = null)
{
$option = (string) $option;
if (array_key_exists($option, $this->_djConfig)) {
return $this->_djConfig[$option];
}
return $default;
}
/**
* Add a stylesheet by module name
*
* @param string $module
* @return Zend_Dojo_View_Helper_Dojo_Container
*/
public function addStylesheetModule($module)
{
if (!preg_match('/^[a-z0-9]+\.[a-z0-9_-]+(\.[a-z0-9_-]+)*$/i', $module)) {
require_once 'Zend/Dojo/View/Exception.php';
throw new Zend_Dojo_View_Exception('Invalid stylesheet module specified');
}
if (in_array($module, $this->_stylesheetModules)) {
return $this;
}
$this->_stylesheetModules[] = $module;
return $this;
}
/**
* Get all stylesheet modules currently registered
*
* @return array
*/
public function getStylesheetModules()
{
return $this->_stylesheetModules;
}
/**
* Add a stylesheet
*
* @param string $path
* @return Zend_Dojo_View_Helper_Dojo_Container
*/
public function addStylesheet($path)
{
$path = (string) $path;
if (!in_array($path, $this->_stylesheets)) {
$this->_stylesheets[] = (string) $path;
}
return $this;
}
/**
* Register the dojo.css stylesheet?
*
* With no arguments, returns the status of the flag; with arguments, sets
* the flag and returns the object.
*
* @param null|bool $flag
* @return Zend_Dojo_View_Helper_Dojo_Container|bool
*/
public function registerDojoStylesheet($flag = null)
{
if (null === $flag) {
return $this->_registerDojoStylesheet;
}
$this->_registerDojoStylesheet = (bool) $flag;
return $this;
}
/**
* Retrieve registered stylesheets
*
* @return array
*/
public function getStylesheets()
{
return $this->_stylesheets;
}
/**
* Add a script to execute onLoad
*
* dojo.addOnLoad accepts:
* - function name
* - lambda
*
* @param string $callback Lambda
* @return Zend_Dojo_View_Helper_Dojo_Container
*/
public function addOnLoad($callback)
{
if (!in_array($callback, $this->_onLoadActions, true)) {
$this->_onLoadActions[] = $callback;
}
return $this;
}
/**
* Prepend an onLoad event to the list of onLoad actions
*
* @param string $callback Lambda
* @return Zend_Dojo_View_Helper_Dojo_Container
*/
public function prependOnLoad($callback)
{
if (!in_array($callback, $this->_onLoadActions, true)) {
array_unshift($this->_onLoadActions, $callback);
}
return $this;
}
/**
* Retrieve all registered onLoad actions
*
* @return array
*/
public function getOnLoadActions()
{
return $this->_onLoadActions;
}
/**
* Start capturing routines to run onLoad
*
* @return bool
*/
public function onLoadCaptureStart()
{
if ($this->_captureLock) {
require_once 'Zend/Dojo/View/Exception.php';
throw new Zend_Dojo_View_Exception('Cannot nest onLoad captures');
}
$this->_captureLock = true;
ob_start();
return;
}
/**
* Stop capturing routines to run onLoad
*
* @return bool
*/
public function onLoadCaptureEnd()
{
$data = ob_get_clean();
$this->_captureLock = false;
$this->addOnLoad($data);
return true;
}
/**
* Add a programmatic dijit
*
* @param string $id
* @param array $params
* @return Zend_Dojo_View_Helper_Dojo_Container
*/
public function addDijit($id, array $params)
{
if (array_key_exists($id, $this->_dijits)) {
require_once 'Zend/Dojo/View/Exception.php';
throw new Zend_Dojo_View_Exception(sprintf('Duplicate dijit with id "%s" already registered', $id));
}
$this->_dijits[$id] = array(
'id' => $id,
'params' => $params,
);
return $this;
}
/**
* Set a programmatic dijit (overwrites)
*
* @param string $id
* @param array $params
* @return Zend_Dojo_View_Helper_Dojo_Container
*/
public function setDijit($id, array $params)
{
$this->removeDijit($id);
return $this->addDijit($id, $params);
}
/**
* Add multiple dijits at once
*
* Expects an array of id => array $params pairs
*
* @param array $dijits
* @return Zend_Dojo_View_Helper_Dojo_Container
*/
public function addDijits(array $dijits)
{
foreach ($dijits as $id => $params) {
$this->addDijit($id, $params);
}
return $this;
}
/**
* Set multiple dijits at once (overwrites)
*
* Expects an array of id => array $params pairs
*
* @param array $dijits
* @return Zend_Dojo_View_Helper_Dojo_Container
*/
public function setDijits(array $dijits)
{
$this->clearDijits();
return $this->addDijits($dijits);
}
/**
* Is the given programmatic dijit already registered?
*
* @param string $id
* @return bool
*/
public function hasDijit($id)
{
return array_key_exists($id, $this->_dijits);
}
/**
* Retrieve a dijit by id
*
* @param string $id
* @return array|null
*/
public function getDijit($id)
{
if ($this->hasDijit($id)) {
return $this->_dijits[$id]['params'];
}
return null;
}
/**
* Retrieve all dijits
*
* Returns dijits as an array of assoc arrays
*
* @return array
*/
public function getDijits()
{
return array_values($this->_dijits);
}
/**
* Remove a programmatic dijit if it exists
*
* @param string $id
* @return Zend_Dojo_View_Helper_Dojo_Container
*/
public function removeDijit($id)
{
if (array_key_exists($id, $this->_dijits)) {
unset($this->_dijits[$id]);
}
return $this;
}
/**
* Clear all dijits
*
* @return Zend_Dojo_View_Helper_Dojo_Container
*/
public function clearDijits()
{
$this->_dijits = array();
return $this;
}
/**
* Render dijits as JSON structure
*
* @return string
*/
public function dijitsToJson()
{
require_once 'Zend/Json.php';
return Zend_Json::encode($this->getDijits());
}
/**
* Create dijit loader functionality
*
* @return void
*/
public function registerDijitLoader()
{
if (!$this->_dijitLoaderRegistered) {
$js =<<<EOJ
function() {
dojo.forEach(zendDijits, function(info) {
var n = dojo.byId(info.id);
if (null != n) {
dojo.attr(n, dojo.mixin({ id: info.id }, info.params));
}
});
dojo.parser.parse();
}
EOJ;
$this->requireModule('dojo.parser');
$this->prependOnLoad($js);
$this->addJavascript('var zendDijits = ' . $this->dijitsToJson() . ';');
$this->_dijitLoaderRegistered = true;
}
}
/**
* Add arbitrary javascript to execute in dojo JS container
*
* @param string $js
* @return Zend_Dojo_View_Helper_Dojo_Container
*/
public function addJavascript($js)
{
$js = preg_replace('/^\s*(.*?)\s*$/s', '$1', $js);
if (!in_array(substr($js, -1), array(';', '}'))) {
$js .= ';';
}
if (in_array($js, $this->_javascriptStatements)) {
return $this;
}
$this->_javascriptStatements[] = $js;
return $this;
}
/**
* Return all registered javascript statements
*
* @return array
*/
public function getJavascript()
{
return $this->_javascriptStatements;
}
/**
* Clear arbitrary javascript stack
*
* @return Zend_Dojo_View_Helper_Dojo_Container
*/
public function clearJavascript()
{
$this->_javascriptStatements = array();
return $this;
}
/**
* Capture arbitrary javascript to include in dojo script
*
* @return void
*/
public function javascriptCaptureStart()
{
if ($this->_captureLock) {
require_once 'Zend/Dojo/View/Exception.php';
throw new Zend_Dojo_View_Exception('Cannot nest captures');
}
$this->_captureLock = true;
ob_start();
return;
}
/**
* Finish capturing arbitrary javascript to include in dojo script
*
* @return true
*/
public function javascriptCaptureEnd()
{
$data = ob_get_clean();
$this->_captureLock = false;
$this->addJavascript($data);
return true;
}
/**
* String representation of dojo environment
*
* @return string
*/
public function __toString()
{
if (!$this->isEnabled()) {
return '';
}
$this->_isXhtml = $this->view->doctype()->isXhtml();
if (Zend_Dojo_View_Helper_Dojo::useDeclarative()) {
if (null === $this->getDjConfigOption('parseOnLoad')) {
$this->setDjConfigOption('parseOnLoad', true);
}
}
if (!empty($this->_dijits)) {
$this->registerDijitLoader();
}
$html = $this->_renderStylesheets() . PHP_EOL
. $this->_renderDjConfig() . PHP_EOL
. $this->_renderDojoScriptTag() . PHP_EOL
. $this->_renderLayers() . PHP_EOL
. $this->_renderExtras();
return $html;
}
/**
* Retrieve local path to dojo resources for building relative paths
*
* @return string
*/
protected function _getLocalRelativePath()
{
if (null === $this->_localRelativePath) {
$localPath = $this->getLocalPath();
$localPath = preg_replace('|[/\\\\]dojo[/\\\\]dojo.js[^/\\\\]*$|i', '', $localPath);
$this->_localRelativePath = $localPath;
}
return $this->_localRelativePath;
}
/**
* Render dojo stylesheets
*
* @return string
*/
protected function _renderStylesheets()
{
if ($this->useCdn()) {
$base = $this->getCdnBase()
. $this->getCdnVersion();
} else {
$base = $this->_getLocalRelativePath();
}
$registeredStylesheets = $this->getStylesheetModules();
foreach ($registeredStylesheets as $stylesheet) {
$themeName = substr($stylesheet, strrpos($stylesheet, '.') + 1);
$stylesheet = str_replace('.', '/', $stylesheet);
$stylesheets[] = $base . '/' . $stylesheet . '/' . $themeName . '.css';
}
foreach ($this->getStylesheets() as $stylesheet) {
$stylesheets[] = $stylesheet;
}
if ($this->_registerDojoStylesheet) {
$stylesheets[] = $base . '/dojo/resources/dojo.css';
}
if (empty($stylesheets)) {
return '';
}
array_reverse($stylesheets);
$style = '<style type="text/css">' . PHP_EOL
. (($this->_isXhtml) ? '<!--' : '<!--') . PHP_EOL;
foreach ($stylesheets as $stylesheet) {
$style .= ' @import "' . $stylesheet . '";' . PHP_EOL;
}
$style .= (($this->_isXhtml) ? '-->' : '-->') . PHP_EOL
. '</style>';
return $style;
}
/**
* Render DjConfig values
*
* @return string
*/
protected function _renderDjConfig()
{
$djConfigValues = $this->getDjConfig();
if (empty($djConfigValues)) {
return '';
}
require_once 'Zend/Json.php';
$scriptTag = '<script type="text/javascript">' . PHP_EOL
. (($this->_isXhtml) ? '//<![CDATA[' : '//<!--') . PHP_EOL
. ' var djConfig = ' . Zend_Json::encode($djConfigValues) . ';' . PHP_EOL
. (($this->_isXhtml) ? '//]]>' : '//-->') . PHP_EOL
. '</script>';
return $scriptTag;
}
/**
* Render dojo script tag
*
* Renders Dojo script tag by utilizing either local path provided or the
* CDN. If any djConfig values were set, they will be serialized and passed
* with that attribute.
*
* @return string
*/
protected function _renderDojoScriptTag()
{
if ($this->useCdn()) {
$source = $this->getCdnBase()
. $this->getCdnVersion()
. $this->getCdnDojoPath();
} else {
$source = $this->getLocalPath();
}
$scriptTag = '<script type="text/javascript" src="' . $source . '"></script>';
return $scriptTag;
}
/**
* Render layers (custom builds) as script tags
*
* @return string
*/
protected function _renderLayers()
{
$layers = $this->getLayers();
if (empty($layers)) {
return '';
}
$html = array();
foreach ($layers as $path) {
$html[] = sprintf(
'<script type="text/javascript" src="%s"></script>',
htmlentities($path, ENT_QUOTES)
);
}
return implode("\n", $html);
}
/**
* Render dojo module paths and requires
*
* @return string
*/
protected function _renderExtras()
{
$js = array();
$modulePaths = $this->getModulePaths();
if (!empty($modulePaths)) {
foreach ($modulePaths as $module => $path) {
$js[] = 'dojo.registerModulePath("' . $this->view->escape($module) . '", "' . $this->view->escape($path) . '");';
}
}
$modules = $this->getModules();
if (!empty($modules)) {
foreach ($modules as $module) {
$js[] = 'dojo.require("' . $this->view->escape($module) . '");';
}
}
$onLoadActions = array();
foreach ($this->getOnLoadActions() as $callback) {
$onLoadActions[] = 'dojo.addOnLoad(' . $callback . ');';
}
$javascript = implode("\n ", $this->getJavascript());
$content = '';
if (!empty($js)) {
$content .= implode("\n ", $js) . "\n";
}
if (!empty($onLoadActions)) {
$content .= implode("\n ", $onLoadActions) . "\n";
}
if (!empty($javascript)) {
$content .= $javascript . "\n";
}
if (preg_match('/^\s*$/s', $content)) {
return '';
}
$html = '<script type="text/javascript">' . PHP_EOL
. (($this->_isXhtml) ? '//<![CDATA[' : '//<!--') . PHP_EOL
. $content
. (($this->_isXhtml) ? '//]]>' : '//-->') . PHP_EOL
. PHP_EOL . '</script>';
return $html;
}
}
Dojo.php 0000666 00000011315 15125471063 0006161 0 ustar 00 <?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_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Dojo.php 10024 2008-07-10 14:04:33Z matthew $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Registry */
require_once 'Zend/Registry.php';
/**
* Zend_Dojo_View_Helper_Dojo: Dojo View Helper
*
* Allows specifying stylesheets, path to dojo, module paths, and onLoad
* events.
*
* @package Zend_Dojo
* @subpackage View
* @copyright Copyright (C) 2008 - Present, Zend Technologies, Inc.
* @license New BSD {@link http://framework.zend.com/license/new-bsd}
*/
class Zend_Dojo_View_Helper_Dojo
{
/**#@+
* @const Programmatic dijit creation style constants
*/
const PROGRAMMATIC_SCRIPT = 1;
const PROGRAMMATIC_NOSCRIPT = -1;
/**#@-*/
/**
* @var Zend_View_Interface
*/
public $view;
/**
* @var Zend_Dojo_View_Helper_Dojo_Container
*/
protected $_container;
/**
* @var bool Whether or not dijits should be declared programmatically
*/
protected static $_useProgrammatic = true;
/**
* Initialize helper
*
* Retrieve container from registry or create new container and store in
* registry.
*
* @return void
*/
public function __construct()
{
$registry = Zend_Registry::getInstance();
if (!isset($registry[__CLASS__])) {
require_once 'Zend/Dojo/View/Helper/Dojo/Container.php';
$container = new Zend_Dojo_View_Helper_Dojo_Container();
$registry[__CLASS__] = $container;
}
$this->_container = $registry[__CLASS__];
}
/**
* Set view object
*
* @param Zend_Dojo_View_Interface $view
* @return void
*/
public function setView(Zend_View_Interface $view)
{
$this->view = $view;
$this->_container->setView($view);
}
/**
* Return dojo container
*
* @return Zend_Dojo_View_Helper_Dojo_Container
*/
public function dojo()
{
return $this->_container;
}
/**
* Proxy to container methods
*
* @param string $method
* @param array $args
* @return mixed
* @throws Zend_Dojo_View_Exception For invalid method calls
*/
public function __call($method, $args)
{
if (!method_exists($this->_container, $method)) {
require_once 'Zend/Dojo/View/Exception.php';
throw new Zend_Dojo_View_Exception(sprintf('Invalid method "%s" called on dojo view helper', $method));
}
return call_user_func_array(array($this->_container, $method), $args);
}
/**
* Set whether or not dijits should be created declaratively
*
* @return void
*/
public static function setUseDeclarative()
{
self::$_useProgrammatic = false;
}
/**
* Set whether or not dijits should be created programmatically
*
* Optionally, specifiy whether or not dijit helpers should generate the
* programmatic dojo.
*
* @param int $style
* @return void
*/
public static function setUseProgrammatic($style = self::PROGRAMMATIC_SCRIPT)
{
if (!in_array($style, array(self::PROGRAMMATIC_SCRIPT, self::PROGRAMMATIC_NOSCRIPT))) {
$style = self::PROGRAMMATIC_SCRIPT;
}
self::$_useProgrammatic = $style;
}
/**
* Should dijits be created declaratively?
*
* @return bool
*/
public static function useDeclarative()
{
return (false === self::$_useProgrammatic);
}
/**
* Should dijits be created programmatically?
*
* @return bool
*/
public static function useProgrammatic()
{
return (false !== self::$_useProgrammatic);
}
/**
* Should dijits be created programmatically but without scripts?
*
* @return bool
*/
public static function useProgrammaticNoScript()
{
return (self::PROGRAMMATIC_NOSCRIPT === self::$_useProgrammatic);
}
}
Textarea.php 0000666 00000004473 15125471063 0007052 0 ustar 00 <?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_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Textarea.php 10256 2008-07-21 14:09:27Z matthew $
*/
/** Zend_Dojo_View_Helper_Dijit */
require_once 'Zend/Dojo/View/Helper/Dijit.php';
/**
* Dojo Textarea dijit
*
* @uses Zend_Dojo_View_Helper_Dijit
* @package Zend_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Dojo_View_Helper_Textarea extends Zend_Dojo_View_Helper_Dijit
{
/**
* Dijit being used
* @var string
*/
protected $_dijit = 'dijit.form.Textarea';
/**
* HTML element type
* @var string
*/
protected $_elementType = 'text';
/**
* Dojo module to use
* @var string
*/
protected $_module = 'dijit.form.Textarea';
/**
* dijit.form.Textarea
*
* @param int $id
* @param mixed $value
* @param array $params Parameters to use for dijit creation
* @param array $attribs HTML attributes
* @return string
*/
public function textarea($id, $value = null, array $params = array(), array $attribs = array())
{
if (!array_key_exists('id', $attribs)) {
$attribs['id'] = $id;
}
$attribs['name'] = $id;
$attribs['type'] = $this->_elementType;
$attribs = $this->_prepareDijit($attribs, $params, 'textarea');
$html = '<textarea' . $this->_htmlAttribs($attribs) . '>'
. $value
. "</textarea>\n";
return $html;
}
}
VerticalSlider.php 0000666 00000003627 15125471063 0010211 0 ustar 00 <?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_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: VerticalSlider.php 9965 2008-07-06 14:46:20Z matthew $
*/
/** Zend_Dojo_View_Helper_Slider */
require_once 'Zend/Dojo/View/Helper/Slider.php';
/**
* Dojo VerticalSlider dijit
*
* @uses Zend_Dojo_View_Helper_Slider
* @package Zend_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Dojo_View_Helper_VerticalSlider extends Zend_Dojo_View_Helper_Slider
{
/**
* Dijit being used
* @var string
*/
protected $_dijit = 'dijit.form.VerticalSlider';
/**
* Slider type
* @var string
*/
protected $_sliderType = 'Vertical';
/**
* dijit.form.VerticalSlider
*
* @param int $id
* @param mixed $value
* @param array $params Parameters to use for dijit creation
* @param array $attribs HTML attributes
* @return string
*/
public function verticalSlider($id, $value = null, array $params = array(), array $attribs = array())
{
return $this->prepareSlider($id, $value, $params, $attribs);
}
}
TextBox.php 0000666 00000003744 15125471063 0006672 0 ustar 00 <?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_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: TextBox.php 9998 2008-07-08 19:54:41Z matthew $
*/
/** Zend_Dojo_View_Helper_Dijit */
require_once 'Zend/Dojo/View/Helper/Dijit.php';
/**
* Dojo TextBox dijit
*
* @uses Zend_Dojo_View_Helper_Dijit
* @package Zend_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Dojo_View_Helper_TextBox extends Zend_Dojo_View_Helper_Dijit
{
/**
* Dijit being used
* @var string
*/
protected $_dijit = 'dijit.form.TextBox';
/**
* HTML element type
* @var string
*/
protected $_elementType = 'text';
/**
* Dojo module to use
* @var string
*/
protected $_module = 'dijit.form.TextBox';
/**
* dijit.form.TextBox
*
* @param int $id
* @param mixed $value
* @param array $params Parameters to use for dijit creation
* @param array $attribs HTML attributes
* @return string
*/
public function textBox($id, $value = null, array $params = array(), array $attribs = array())
{
return $this->_createFormElement($id, $value, $params, $attribs);
}
}
SubmitButton.php 0000666 00000004447 15125471063 0007735 0 ustar 00 <?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_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: SubmitButton.php 12692 2008-11-18 20:30:09Z matthew $
*/
/** Zend_Dojo_View_Helper_Button */
require_once 'Zend/Dojo/View/Helper/Button.php';
/**
* Dojo Button dijit tied to submit input
*
* @uses Zend_Dojo_View_Helper_Button
* @package Zend_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Dojo_View_Helper_SubmitButton extends Zend_Dojo_View_Helper_Button
{
/**
* @var string Submit input
*/
protected $_elementType = 'submit';
/**
* dijit.form.Button tied to submit input
*
* @param string $id
* @param string $value
* @param array $params Parameters to use for dijit creation
* @param array $attribs HTML attributes
* @return string
*/
public function submitButton($id, $value = null, array $params = array(), array $attribs = array())
{
if (!array_key_exists('label', $params)) {
$params['label'] = $value;
}
if (empty($params['label']) && !empty($params['content'])) {
$params['label'] = $params['content'];
$value = $params['content'];
}
if (empty($params['label']) && !empty($attribs['content'])) {
$params['label'] = $attribs['content'];
$value = $attribs['content'];
unset($attribs['content']);
}
return $this->_createFormElement($id, $value, $params, $attribs);
}
}
Dijit.php 0000666 00000021211 15125471063 0006325 0 ustar 00 <?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_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Dijit.php 12281 2008-11-04 14:40:05Z matthew $
*/
/** Zend_View_Helper_HtmlElement */
require_once 'Zend/View/Helper/HtmlElement.php';
/**
* Dojo dijit base class
*
* @uses Zend_View_Helper_Abstract
* @package Zend_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Dojo_View_Helper_Dijit extends Zend_View_Helper_HtmlElement
{
/**
* @var Zend_Dojo_View_Helper_Dojo_Container
*/
public $dojo;
/**
* Dijit being used
* @var string
*/
protected $_dijit;
/**
* Element type
* @var string
*/
protected $_elementType;
/**
* Parameters that should be JSON encoded
* @var array
*/
protected $_jsonParams = array('constraints');
/**
* Dojo module to use
* @var string
*/
protected $_module;
/**
* Set view
*
* Set view and enable dojo
*
* @param Zend_View_Interface $view
* @return Zend_Dojo_View_Helper_Dijit
*/
public function setView(Zend_View_Interface $view)
{
parent::setView($view);
$this->dojo = $this->view->dojo();
$this->dojo->enable();
return $this;
}
/**
* Whether or not to use declarative dijit creation
*
* @return bool
*/
protected function _useDeclarative()
{
return Zend_Dojo_View_Helper_Dojo::useDeclarative();
}
/**
* Whether or not to use programmatic dijit creation
*
* @return bool
*/
protected function _useProgrammatic()
{
return Zend_Dojo_View_Helper_Dojo::useProgrammatic();
}
/**
* Whether or not to use programmatic dijit creation w/o script creation
*
* @return bool
*/
protected function _useProgrammaticNoScript()
{
return Zend_Dojo_View_Helper_Dojo::useProgrammaticNoScript();
}
/**
* Create a layout container
*
* @param int $id
* @param string $content
* @param array $params
* @param array $attribs
* @param string|null $dijit
* @return string
*/
protected function _createLayoutContainer($id, $content, array $params, array $attribs, $dijit = null)
{
$attribs['id'] = $id;
$attribs = $this->_prepareDijit($attribs, $params, 'layout', $dijit);
$html = '<div' . $this->_htmlAttribs($attribs) . '>'
. $content
. "</div>\n";
return $html;
}
/**
* Create HTML representation of a dijit form element
*
* @param string $id
* @param string $value
* @param array $params
* @param array $attribs
* @param string|null $dijit
* @return string
*/
public function _createFormElement($id, $value, array $params, array $attribs, $dijit = null)
{
if (!array_key_exists('id', $attribs)) {
$attribs['id'] = $id;
}
$attribs['name'] = $id;
$attribs['value'] = (string) $value;
$attribs['type'] = $this->_elementType;
$attribs = $this->_prepareDijit($attribs, $params, 'element', $dijit);
$html = '<input'
. $this->_htmlAttribs($attribs)
. $this->getClosingBracket();
return $html;
}
/**
* Merge attributes and parameters
*
* Also sets up requires
*
* @param array $attribs
* @param array $params
* @param string $type
* @param string $dijit Dijit type to use (otherwise, pull from $_dijit)
* @return array
*/
protected function _prepareDijit(array $attribs, array $params, $type, $dijit = null)
{
$this->dojo->requireModule($this->_module);
switch ($type) {
case 'layout':
$stripParams = array('id');
break;
case 'element':
$stripParams = array('id', 'name', 'value', 'type');
foreach (array('checked', 'disabled', 'readonly') as $attrib) {
if (array_key_exists($attrib, $attribs)) {
if ($attribs[$attrib]) {
$attribs[$attrib] = $attrib;
} else {
unset($attribs[$attrib]);
}
}
}
break;
case 'textarea':
$stripParams = array('id', 'name', 'type');
break;
default:
}
foreach ($stripParams as $param) {
if (array_key_exists($param, $params)) {
unset($params[$param]);
}
}
// Normalize constraints, if present
foreach ($this->_jsonParams as $param) {
if (array_key_exists($param, $params)) {
require_once 'Zend/Json.php';
if (is_array($params[$param])) {
$values = array();
foreach ($params[$param] as $key => $value) {
if (!is_scalar($value)) {
continue;
}
$values[$key] = $value;
}
} elseif (is_string($params[$param])) {
$values = (array) $params[$param];
} else {
$values = array();
}
$values = Zend_Json::encode($values);
if ($this->_useDeclarative()) {
$values = str_replace('"', "'", $values);
}
$params[$param] = $values;
}
}
$dijit = (null === $dijit) ? $this->_dijit : $dijit;
if ($this->_useDeclarative()) {
$attribs = array_merge($attribs, $params);
$attribs['dojoType'] = $dijit;
} elseif (!$this->_useProgrammaticNoScript()) {
$this->_createDijit($dijit, $attribs['id'], $params);
}
return $attribs;
}
/**
* Create a dijit programmatically
*
* @param string $dijit
* @param string $id
* @param array $params
* @return void
*/
protected function _createDijit($dijit, $id, array $params)
{
$params['dojoType'] = $dijit;
array_walk_recursive($params, array($this, '_castBoolToString'));
$this->dojo->setDijit($id, $params);
}
/**
* Cast a boolean to a string value
*
* @param mixed $item
* @param string $key
* @return void
*/
protected function _castBoolToString(&$item, $key)
{
if (!is_bool($item)) {
return;
}
$item = ($item) ? "true" : "false";
}
/**
* Render a hidden element to hold a value
*
* @param string $id
* @param string|int|float $value
* @return string
*/
protected function _renderHiddenElement($id, $value)
{
$hiddenAttribs = array(
'name' => $id,
'value' => (string) $value,
'type' => 'hidden',
);
return '<input' . $this->_htmlAttribs($hiddenAttribs) . $this->getClosingBracket();
}
/**
* Create JS function for retrieving parent form
*
* @return void
*/
protected function _createGetParentFormFunction()
{
$function =<<<EOJ
if (zend == undefined) {
var zend = {};
}
zend.findParentForm = function(elementNode) {
while (elementNode.nodeName.toLowerCase() != 'form') {
elementNode = elementNode.parentNode;
}
return elementNode;
};
EOJ;
$this->dojo->addJavascript($function);
}
}
TabContainer.php 0000666 00000004052 15125471063 0007637 0 ustar 00 <?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_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: TabContainer.php 10067 2008-07-12 21:05:32Z matthew $
*/
/** Zend_Dojo_View_Helper_DijitContainer */
require_once 'Zend/Dojo/View/Helper/DijitContainer.php';
/**
* Dojo TabContainer dijit
*
* @uses Zend_Dojo_View_Helper_DijitContainer
* @package Zend_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Dojo_View_Helper_TabContainer extends Zend_Dojo_View_Helper_DijitContainer
{
/**
* Dijit being used
* @var string
*/
protected $_dijit = 'dijit.layout.TabContainer';
/**
* Dojo module to use
* @var string
*/
protected $_module = 'dijit.layout.TabContainer';
/**
* dijit.layout.TabContainer
*
* @param string $id
* @param string $content
* @param array $params Parameters to use for dijit creation
* @param array $attribs HTML attributes
* @return string
*/
public function tabContainer($id = null, $content = '', array $params = array(), array $attribs = array())
{
if (0 === func_num_args()) {
return $this;
}
return $this->_createLayoutContainer($id, $content, $params, $attribs);
}
}
StackContainer.php 0000666 00000004070 15125471063 0010176 0 ustar 00 <?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_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: StackContainer.php 10067 2008-07-12 21:05:32Z matthew $
*/
/** Zend_Dojo_View_Helper_DijitContainer */
require_once 'Zend/Dojo/View/Helper/DijitContainer.php';
/**
* Dojo StackContainer dijit
*
* @uses Zend_Dojo_View_Helper_DijitContainer
* @package Zend_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Dojo_View_Helper_StackContainer extends Zend_Dojo_View_Helper_DijitContainer
{
/**
* Dijit being used
* @var string
*/
protected $_dijit = 'dijit.layout.StackContainer';
/**
* Dojo module to use
* @var string
*/
protected $_module = 'dijit.layout.StackContainer';
/**
* dijit.layout.StackContainer
*
* @param string $id
* @param string $content
* @param array $params Parameters to use for dijit creation
* @param array $attribs HTML attributes
* @return string
*/
public function stackContainer($id = null, $content = '', array $params = array(), array $attribs = array())
{
if (0 === func_num_args()) {
return $this;
}
return $this->_createLayoutContainer($id, $content, $params, $attribs);
}
}
ContentPane.php 0000666 00000004042 15125471063 0007503 0 ustar 00 <?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_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: ContentPane.php 10067 2008-07-12 21:05:32Z matthew $
*/
/** Zend_Dojo_View_Helper_DijitContainer */
require_once 'Zend/Dojo/View/Helper/DijitContainer.php';
/**
* Dojo ContentPane dijit
*
* @uses Zend_Dojo_View_Helper_DijitContainer
* @package Zend_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Dojo_View_Helper_ContentPane extends Zend_Dojo_View_Helper_DijitContainer
{
/**
* Dijit being used
* @var string
*/
protected $_dijit = 'dijit.layout.ContentPane';
/**
* Module being used
* @var string
*/
protected $_module = 'dijit.layout.ContentPane';
/**
* dijit.layout.ContentPane
*
* @param string $id
* @param string $content
* @param array $params Parameters to use for dijit creation
* @param array $attribs HTML attributes
* @return string
*/
public function contentPane($id = null, $content = '', array $params = array(), array $attribs = array())
{
if (0 === func_num_args()) {
return $this;
}
return $this->_createLayoutContainer($id, $content, $params, $attribs);
}
}
Slider.php 0000666 00000021116 15125471063 0006510 0 ustar 00 <?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_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Slider.php 13658 2009-01-15 23:37:30Z matthew $
*/
/** Zend_Dojo_View_Helper_Dijit */
require_once 'Zend/Dojo/View/Helper/Dijit.php';
/**
* Abstract class for Dojo Slider dijits
*
* @uses Zend_Dojo_View_Helper_Dijit
* @package Zend_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Dojo_View_Helper_Slider extends Zend_Dojo_View_Helper_Dijit
{
/**
* Dojo module to use
* @var string
*/
protected $_module = 'dijit.form.Slider';
/**
* Required slider parameters
* @var array
*/
protected $_requiredParams = array('minimum', 'maximum', 'discreteValues');
/**
* Slider type -- vertical or horizontal
* @var string
*/
protected $_sliderType;
/**
* dijit.form.Slider
*
* @param int $id
* @param mixed $value
* @param array $params Parameters to use for dijit creation
* @param array $attribs HTML attributes
* @return string
*/
public function prepareSlider($id, $value = null, array $params = array(), array $attribs = array())
{
$this->_sliderType = strtolower($this->_sliderType);
// Prepare two items: a hidden element to store the value, and the slider
$hidden = $this->_renderHiddenElement($id, $value);
$hidden = preg_replace('/(name=")([^"]*)"/', 'id="$2" $1$2"', $hidden);
foreach ($this->_requiredParams as $param) {
if (!array_key_exists($param, $params)) {
require_once 'Zend/Dojo/View/Exception.php';
throw new Zend_Dojo_View_Exception('prepareSlider() requires minimally the "minimum", "maximum", and "discreteValues" parameters');
}
}
$content = '';
$params['value'] = $value;
if (!array_key_exists('onChange', $attribs)) {
$attribs['onChange'] = "dojo.byId('" . $id . "').value = arguments[0];";
}
$id = str_replace('][', '-', $id);
$id = str_replace(array('[', ']'), '-', $id);
$id = rtrim($id, '-');
$id .= '-slider';
switch ($this->_sliderType) {
case 'horizontal':
if (array_key_exists('topDecoration', $params)) {
$content .= $this->_prepareDecoration('topDecoration', $id, $params['topDecoration']);
unset($params['topDecoration']);
}
if (array_key_exists('bottomDecoration', $params)) {
$content .= $this->_prepareDecoration('bottomDecoration', $id, $params['bottomDecoration']);
unset($params['bottomDecoration']);
}
if (array_key_exists('leftDecoration', $params)) {
unset($params['leftDecoration']);
}
if (array_key_exists('rightDecoration', $params)) {
unset($params['rightDecoration']);
}
break;
case 'vertical':
if (array_key_exists('leftDecoration', $params)) {
$content .= $this->_prepareDecoration('leftDecoration', $id, $params['leftDecoration']);
unset($params['leftDecoration']);
}
if (array_key_exists('rightDecoration', $params)) {
$content .= $this->_prepareDecoration('rightDecoration', $id, $params['rightDecoration']);
unset($params['rightDecoration']);
}
if (array_key_exists('topDecoration', $params)) {
unset($params['topDecoration']);
}
if (array_key_exists('bottomDecoration', $params)) {
unset($params['bottomDecoration']);
}
break;
default:
require_once 'Zend/Dojo/View/Exception.php';
throw new Zend_Dojo_View_Exception('Invalid slider type; slider must be horizontal or vertical');
}
return $hidden . $this->_createLayoutContainer($id, $content, $params, $attribs);
}
/**
* Prepare slider decoration
*
* @param string $position
* @param string $id
* @param array $decInfo
* @return string
*/
protected function _prepareDecoration($position, $id, $decInfo)
{
if (!in_array($position, array('topDecoration', 'bottomDecoration', 'leftDecoration', 'rightDecoration'))) {
return '';
}
if (!is_array($decInfo)
|| !array_key_exists('labels', $decInfo)
|| !is_array($decInfo['labels'])
) {
return '';
}
$id .= '-' . $position;
if (!array_key_exists('dijit', $decInfo)) {
$dijit = 'dijit.form.' . ucfirst($this->_sliderType) . 'Rule';
} else {
$dijit = $decInfo['dijit'];
if ('dijit.form.' != substr($dijit, 0, 10)) {
$dijit = 'dijit.form.' . $dijit;
}
}
$params = array();
$attribs = array();
$labels = $decInfo['labels'];
if (array_key_exists('params', $decInfo)) {
$params = $decInfo['params'];
}
if (array_key_exists('attribs', $decInfo)) {
$attribs = $decInfo['attribs'];
}
$containerParams = null;
if (array_key_exists('container', $params)) {
$containerParams = $params['container'];
unset($params['container']);
}
if (array_key_exists('labels', $params)) {
$labelsParams = $params['labels'];
unset($params['labels']);
} else {
$labelsParams = $params;
}
if (null === $containerParams) {
$containerParams = $params;
}
$containerAttribs = null;
if (array_key_exists('container', $attribs)) {
$containerAttribs = $attribs['container'];
unset($attribs['container']);
}
if (array_key_exists('labels', $attribs)) {
$labelsAttribs = $attribs['labels'];
unset($attribs['labels']);
} else {
$labelsAttribs = $attribs;
}
if (null === $containerAttribs) {
$containerAttribs = $attribs;
}
$containerParams['container'] = $position;
$labelsParams['container'] = $position;
$labelList = $this->_prepareLabelsList($id, $labelsParams, $labelsAttribs, $labels);
$dijit = 'dijit.form.' . ucfirst($this->_sliderType) . 'Rule';
$containerAttribs['id'] = $id;
$containerAttribs = $this->_prepareDijit($containerAttribs, $containerParams, 'layout', $dijit);
$containerHtml = '<div' . $this->_htmlAttribs($containerAttribs) . "></div>\n";
switch ($position) {
case 'topDecoration':
case 'leftDecoration':
return $labelList . $containerHtml;
case 'bottomDecoration':
case 'rightDecoration':
return $containerHtml . $labelList;
}
}
/**
* Prepare slider label list
*
* @param string $id
* @param array $params
* @param array $attribs
* @param array $labels
* @return string
*/
protected function _prepareLabelsList($id, array $params, array $attribs, array $labels)
{
$attribs['id'] = $id . '-labels';
$dijit = 'dijit.form.' . ucfirst($this->_sliderType) . 'RuleLabels';
$attribs = $this->_prepareDijit($attribs, $params, 'layout', $dijit);
return $this->view->htmlList($labels, true, $attribs);
}
}
SimpleTextarea.php 0000666 00000004462 15125471063 0010222 0 ustar 00 <?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_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: $
*/
/** Zend_Dojo_View_Helper_Dijit */
require_once 'Zend/Dojo/View/Helper/Dijit.php';
/**
* dijit.form.SimpleTextarea view helper
*
* @uses Zend_Dojo_View_Helper_Dijit
* @package Zend_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Dojo_View_Helper_SimpleTextarea extends Zend_Dojo_View_Helper_Dijit
{
/**
* @var string Dijit type
*/
protected $_dijit = 'dijit.form.SimpleTextarea';
/**
* @var string HTML element type
*/
protected $_elementType = 'textarea';
/**
* @var string Dojo module
*/
protected $_module = 'dijit.form.SimpleTextarea';
/**
* dijit.form.SimpleTextarea
*
* @param string $id
* @param string $value
* @param array $params Parameters to use for dijit creation
* @param array $attribs HTML attributes
* @return string
*/
public function simpleTextarea($id, $value = null, array $params = array(), array $attribs = array())
{
if (!array_key_exists('id', $attribs)) {
$attribs['id'] = $id;
}
$attribs['name'] = $id;
$attribs['type'] = $this->_elementType;
$attribs = $this->_prepareDijit($attribs, $params, 'textarea');
$html = '<textarea' . $this->_htmlAttribs($attribs) . '>'
. $this->view->escape($value)
. "</textarea>\n";
return $html;
}
}
FlashMessenger.php 0000666 00000015742 15125617502 0010204 0 ustar 00 <?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_Controller
* @subpackage Zend_Controller_Action_Helper
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* @see Zend_Session
*/
require_once 'Zend/Session.php';
/**
* @see Zend_Controller_Action_Helper_Abstract
*/
require_once 'Zend/Controller/Action/Helper/Abstract.php';
/**
* Flash Messenger - implement session-based messages
*
* @uses Zend_Controller_Action_Helper_Abstract
* @category Zend
* @package Zend_Controller
* @subpackage Zend_Controller_Action_Helper
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: $
*/
class Zend_Controller_Action_Helper_FlashMessenger extends Zend_Controller_Action_Helper_Abstract implements IteratorAggregate, Countable
{
/**
* $_messages - Messages from previous request
*
* @var array
*/
static protected $_messages = array();
/**
* $_session - Zend_Session storage object
*
* @var Zend_Session
*/
static protected $_session = null;
/**
* $_messageAdded - Wether a message has been previously added
*
* @var boolean
*/
static protected $_messageAdded = false;
/**
* $_namespace - Instance namespace, default is 'default'
*
* @var string
*/
protected $_namespace = 'default';
/**
* __construct() - Instance constructor, needed to get iterators, etc
*
* @param string $namespace
* @return void
*/
public function __construct()
{
if (!self::$_session instanceof Zend_Session_Namespace) {
self::$_session = new Zend_Session_Namespace($this->getName());
foreach (self::$_session as $namespace => $messages) {
self::$_messages[$namespace] = $messages;
unset(self::$_session->{$namespace});
}
}
}
/**
* postDispatch() - runs after action is dispatched, in this
* case, it is resetting the namespace in case we have forwarded to a different
* action, Flashmessage will be 'clean' (default namespace)
*
* @return Zend_Controller_Action_Helper_FlashMessenger Provides a fluent interface
*/
public function postDispatch()
{
$this->resetNamespace();
return $this;
}
/**
* setNamespace() - change the namespace messages are added to, useful for
* per action controller messaging between requests
*
* @param string $namespace
* @return Zend_Controller_Action_Helper_FlashMessenger Provides a fluent interface
*/
public function setNamespace($namespace = 'default')
{
$this->_namespace = $namespace;
return $this;
}
/**
* resetNamespace() - reset the namespace to the default
*
* @return Zend_Controller_Action_Helper_FlashMessenger Provides a fluent interface
*/
public function resetNamespace()
{
$this->setNamespace();
return $this;
}
/**
* addMessage() - Add a message to flash message
*
* @param string $message
* @return Zend_Controller_Action_Helper_FlashMessenger Provides a fluent interface
*/
public function addMessage($message)
{
if (self::$_messageAdded === false) {
self::$_session->setExpirationHops(1, null, true);
}
if (!is_array(self::$_session->{$this->_namespace})) {
self::$_session->{$this->_namespace} = array();
}
self::$_session->{$this->_namespace}[] = $message;
return $this;
}
/**
* hasMessages() - Wether a specific namespace has messages
*
* @return boolean
*/
public function hasMessages()
{
return isset(self::$_messages[$this->_namespace]);
}
/**
* getMessages() - Get messages from a specific namespace
*
* @return array
*/
public function getMessages()
{
if ($this->hasMessages()) {
return self::$_messages[$this->_namespace];
}
return array();
}
/**
* Clear all messages from the previous request & current namespace
*
* @return boolean True if messages were cleared, false if none existed
*/
public function clearMessages()
{
if ($this->hasMessages()) {
unset(self::$_messages[$this->_namespace]);
return true;
}
return false;
}
/**
* hasCurrentMessages() - check to see if messages have been added to current
* namespace within this request
*
* @return boolean
*/
public function hasCurrentMessages()
{
return isset(self::$_session->{$this->_namespace});
}
/**
* getCurrentMessages() - get messages that have been added to the current
* namespace within this request
*
* @return array
*/
public function getCurrentMessages()
{
if ($this->hasCurrentMessages()) {
return self::$_session->{$this->_namespace};
}
return array();
}
/**
* clear messages from the current request & current namespace
*
* @return boolean
*/
public function clearCurrentMessages()
{
if ($this->hasCurrentMessages()) {
unset(self::$_session->{$this->_namespace});
return true;
}
return false;
}
/**
* getIterator() - complete the IteratorAggregate interface, for iterating
*
* @return ArrayObject
*/
public function getIterator()
{
if ($this->hasMessages()) {
return new ArrayObject($this->getMessages());
}
return new ArrayObject();
}
/**
* count() - Complete the countable interface
*
* @return int
*/
public function count()
{
if ($this->hasMessages()) {
return count($this->getMessages());
}
return 0;
}
/**
* Strategy pattern: proxy to addMessage()
*
* @param string $message
* @return void
*/
public function direct($message)
{
return $this->addMessage($message);
}
}
Url.php 0000666 00000007623 15125617502 0006037 0 ustar 00 <?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_Controller
* @subpackage Zend_Controller_Action_Helper
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Url.php 12526 2008-11-10 20:25:20Z ralph $
*/
/**
* @see Zend_Controller_Action_Helper_Abstract
*/
require_once 'Zend/Controller/Action/Helper/Abstract.php';
/**
* Helper for creating URLs for redirects and other tasks
*
* @uses Zend_Controller_Action_Helper_Abstract
* @category Zend
* @package Zend_Controller
* @subpackage Zend_Controller_Action_Helper
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Controller_Action_Helper_Url extends Zend_Controller_Action_Helper_Abstract
{
/**
* Create URL based on default route
*
* @param string $action
* @param string $controller
* @param string $module
* @param array $params
* @return string
*/
public function simple($action, $controller = null, $module = null, array $params = null)
{
$request = $this->getRequest();
if (null === $controller) {
$controller = $request->getControllerName();
}
if (null === $module) {
$module = $request->getModuleName();
}
$url = $controller . '/' . $action;
if ($module != $this->getFrontController()->getDispatcher()->getDefaultModule()) {
$url = $module . '/' . $url;
}
if ('' !== ($baseUrl = $this->getFrontController()->getBaseUrl())) {
$url = $baseUrl . '/' . $url;
}
if (null !== $params) {
$paramPairs = array();
foreach ($params as $key => $value) {
$paramPairs[] = urlencode($key) . '/' . urlencode($value);
}
$paramString = implode('/', $paramPairs);
$url .= '/' . $paramString;
}
$url = '/' . ltrim($url, '/');
return $url;
}
/**
* Assembles a URL based on a given route
*
* This method will typically be used for more complex operations, as it
* ties into the route objects registered with the router.
*
* @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 boolean $reset
* @param boolean $encode
* @return string Url for the link href attribute.
*/
public function url($urlOptions = array(), $name = null, $reset = false, $encode = true)
{
$router = $this->getFrontController()->getRouter();
return $router->assemble($urlOptions, $name, $reset, $encode);
}
/**
* Perform helper when called as $this->_helper->url() from an action controller
*
* Proxies to {@link simple()}
*
* @param string $action
* @param string $controller
* @param string $module
* @param array $params
* @return string
*/
public function direct($action, $controller = null, $module = null, array $params = null)
{
return $this->simple($action, $controller, $module, $params);
}
}
Json.php 0000666 00000007051 15125617502 0006201 0 ustar 00 <?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_Controller
* @subpackage Zend_Controller_Action_Helper
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Json.php 9098 2008-03-30 19:29:10Z thomas $
*/
/**
* @see Zend_Controller_Action_Helper_Abstract
*/
require_once 'Zend/Controller/Action/Helper/Abstract.php';
/**
* Simplify AJAX context switching based on requested format
*
* @uses Zend_Controller_Action_Helper_Abstract
* @category Zend
* @package Zend_Controller
* @subpackage Zend_Controller_Action_Helper
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Controller_Action_Helper_Json extends Zend_Controller_Action_Helper_Abstract
{
/**
* Suppress exit when sendJson() called
* @var boolean
*/
public $suppressExit = false;
/**
* Create JSON response
*
* Encodes and returns data to JSON. Content-Type header set to
* 'application/json', and disables layouts and viewRenderer (if being
* used).
*
* @param mixed $data
* @param boolean $keepLayouts
* @throws Zend_Controller_Action_Helper_Json
* @return string
*/
public function encodeJson($data, $keepLayouts = false)
{
/**
* @see Zend_View_Helper_Json
*/
require_once 'Zend/View/Helper/Json.php';
$jsonHelper = new Zend_View_Helper_Json();
$data = $jsonHelper->json($data, $keepLayouts);
if (!$keepLayouts) {
/**
* @see Zend_Controller_Action_HelperBroker
*/
require_once 'Zend/Controller/Action/HelperBroker.php';
Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->setNoRender(true);
}
return $data;
}
/**
* Encode JSON response and immediately send
*
* @param mixed $data
* @param boolean $keepLayouts
* @return string|void
*/
public function sendJson($data, $keepLayouts = false)
{
$data = $this->encodeJson($data, $keepLayouts);
$response = $this->getResponse();
$response->setBody($data);
if (!$this->suppressExit) {
$response->sendResponse();
exit;
}
return $data;
}
/**
* Strategy pattern: call helper as helper broker method
*
* Allows encoding JSON. If $sendNow is true, immediately sends JSON
* response.
*
* @param mixed $data
* @param boolean $sendNow
* @param boolean $keepLayouts
* @return string|void
*/
public function direct($data, $sendNow = true, $keepLayouts = false)
{
if ($sendNow) {
return $this->sendJson($data, $keepLayouts);
}
return $this->encodeJson($data, $keepLayouts);
}
}
ActionStack.php 0000666 00000011303 15125617502 0007466 0 ustar 00 <?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_Controller
* @subpackage Zend_Controller_Action_Helper
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: ActionStack.php 11493 2008-09-23 14:25:11Z doctorrock83 $
*/
/**
* @see Zend_Controller_Action_Helper_Abstract
*/
require_once 'Zend/Controller/Action/Helper/Abstract.php';
/**
* Add to action stack
*
* @uses Zend_Controller_Action_Helper_Abstract
* @category Zend
* @package Zend_Controller
* @subpackage Zend_Controller_Action_Helper
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Controller_Action_Helper_ActionStack extends Zend_Controller_Action_Helper_Abstract
{
/**
* @var Zend_Controller_Plugin_ActionStack
*/
protected $_actionStack;
/**
* Constructor
*
* Register action stack plugin
*
* @return void
*/
public function __construct()
{
$front = Zend_Controller_Front::getInstance();
if (!$front->hasPlugin('Zend_Controller_Plugin_ActionStack')) {
/**
* @see Zend_Controller_Plugin_ActionStack
*/
require_once 'Zend/Controller/Plugin/ActionStack.php';
$this->_actionStack = new Zend_Controller_Plugin_ActionStack();
$front->registerPlugin($this->_actionStack, 97);
} else {
$this->_actionStack = $front->getPlugin('Zend_Controller_Plugin_ActionStack');
}
}
/**
* Push onto the stack
*
* @param Zend_Controller_Request_Abstract $next
* @return Zend_Controller_Action_Helper_ActionStack Provides a fluent interface
*/
public function pushStack(Zend_Controller_Request_Abstract $next)
{
$this->_actionStack->pushStack($next);
return $this;
}
/**
* Push a new action onto the stack
*
* @param string $action
* @param string $controller
* @param string $module
* @param array $params
* @throws Zend_Controller_Action_Exception
* @return Zend_Controller_Action_Helper_ActionStack
*/
public function actionToStack($action, $controller = null, $module = null, array $params = array())
{
if ($action instanceof Zend_Controller_Request_Abstract) {
return $this->pushStack($action);
} elseif (!is_string($action)) {
/**
* @see Zend_Controller_Action_Exception
*/
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception('ActionStack requires either a request object or minimally a string action');
}
$request = $this->getRequest();
if ($request instanceof Zend_Controller_Request_Abstract === false){
/**
* @see Zend_Controller_Action_Exception
*/
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception('Request object not set yet');
}
$controller = (null === $controller) ? $request->getControllerName() : $controller;
$module = (null === $module) ? $request->getModuleName() : $module;
/**
* @see Zend_Controller_Request_Simple
*/
require_once 'Zend/Controller/Request/Simple.php';
$newRequest = new Zend_Controller_Request_Simple($action, $controller, $module, $params);
return $this->pushStack($newRequest);
}
/**
* Perform helper when called as $this->_helper->actionStack() from an action controller
*
* Proxies to {@link simple()}
*
* @param string $action
* @param string $controller
* @param string $module
* @param array $params
* @return boolean
*/
public function direct($action, $controller = null, $module = null, array $params = array())
{
return $this->actionToStack($action, $controller, $module, $params);
}
}
Redirector.php 0000666 00000036174 15125617502 0007402 0 ustar 00 <?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_Controller
* @subpackage Zend_Controller_Action_Helper
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* @see Zend_Controller_Action_Exception
*/
require_once 'Zend/Controller/Action/Exception.php';
/**
* @see Zend_Controller_Action_Helper_Abstract
*/
require_once 'Zend/Controller/Action/Helper/Abstract.php';
/**
* @category Zend
* @package Zend_Controller
* @subpackage Zend_Controller_Action_Helper
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Controller_Action_Helper_Redirector extends Zend_Controller_Action_Helper_Abstract
{
/**
* HTTP status code for redirects
* @var int
*/
protected $_code = 302;
/**
* Whether or not calls to _redirect() should exit script execution
* @var boolean
*/
protected $_exit = true;
/**
* Whether or not _redirect() should attempt to prepend the base URL to the
* passed URL (if it's a relative URL)
* @var boolean
*/
protected $_prependBase = true;
/**
* Url to which to redirect
* @var string
*/
protected $_redirectUrl = null;
/**
* Whether or not to use an absolute URI when redirecting
* @var boolean
*/
protected $_useAbsoluteUri = false;
/**
* Retrieve HTTP status code to emit on {@link _redirect()} call
*
* @return int
*/
public function getCode()
{
return $this->_code;
}
/**
* Validate HTTP status redirect code
*
* @param int $code
* @throws Zend_Controller_Action_Exception on invalid HTTP status code
* @return true
*/
protected function _checkCode($code)
{
$code = (int)$code;
if ((300 > $code) || (307 < $code) || (304 == $code) || (306 == $code)) {
/**
* @see Zend_Controller_Exception
*/
require_once 'Zend/Controller/Exception.php';
throw new Zend_Controller_Action_Exception('Invalid redirect HTTP status code (' . $code . ')');
}
return true;
}
/**
* Retrieve HTTP status code for {@link _redirect()} behaviour
*
* @param int $code
* @return Zend_Controller_Action_Helper_Redirector Provides a fluent interface
*/
public function setCode($code)
{
$this->_checkCode($code);
$this->_code = $code;
return $this;
}
/**
* Retrieve flag for whether or not {@link _redirect()} will exit when finished.
*
* @return boolean
*/
public function getExit()
{
return $this->_exit;
}
/**
* Retrieve exit flag for {@link _redirect()} behaviour
*
* @param boolean $flag
* @return Zend_Controller_Action_Helper_Redirector Provides a fluent interface
*/
public function setExit($flag)
{
$this->_exit = ($flag) ? true : false;
return $this;
}
/**
* Retrieve flag for whether or not {@link _redirect()} will prepend the
* base URL on relative URLs
*
* @return boolean
*/
public function getPrependBase()
{
return $this->_prependBase;
}
/**
* Retrieve 'prepend base' flag for {@link _redirect()} behaviour
*
* @param boolean $flag
* @return Zend_Controller_Action_Helper_Redirector Provides a fluent interface
*/
public function setPrependBase($flag)
{
$this->_prependBase = ($flag) ? true : false;
return $this;
}
/**
* Return use absolute URI flag
*
* @return boolean
*/
public function getUseAbsoluteUri()
{
return $this->_useAbsoluteUri;
}
/**
* Set use absolute URI flag
*
* @param boolean $flag
* @return Zend_Controller_Action_Helper_Redirector Provides a fluent interface
*/
public function setUseAbsoluteUri($flag = true)
{
$this->_useAbsoluteUri = ($flag) ? true : false;
return $this;
}
/**
* Set redirect in response object
*
* @return void
*/
protected function _redirect($url)
{
if ($this->getUseAbsoluteUri() && !preg_match('#^(https?|ftp)://#', $url)) {
$host = (isset($_SERVER['HTTP_HOST'])?$_SERVER['HTTP_HOST']:'');
$proto = (isset($_SERVER['HTTPS'])&&$_SERVER['HTTPS']!=="off") ? 'https' : 'http';
$port = (isset($_SERVER['SERVER_PORT'])?$_SERVER['SERVER_PORT']:80);
$uri = $proto . '://' . $host;
if ((('http' == $proto) && (80 != $port)) || (('https' == $proto) && (443 != $port))) {
$uri .= ':' . $port;
}
$url = $uri . '/' . ltrim($url, '/');
}
$this->_redirectUrl = $url;
$this->getResponse()->setRedirect($url, $this->getCode());
}
/**
* Retrieve currently set URL for redirect
*
* @return string
*/
public function getRedirectUrl()
{
return $this->_redirectUrl;
}
/**
* Determine if the baseUrl should be prepended, and prepend if necessary
*
* @param string $url
* @return string
*/
protected function _prependBase($url)
{
if ($this->getPrependBase()) {
$request = $this->getRequest();
if ($request instanceof Zend_Controller_Request_Http) {
$base = rtrim($request->getBaseUrl(), '/');
if (!empty($base) && ('/' != $base)) {
$url = $base . '/' . ltrim($url, '/');
} else {
$url = '/' . ltrim($url, '/');
}
}
}
return $url;
}
/**
* Set a redirect URL of the form /module/controller/action/params
*
* @param string $action
* @param string $controller
* @param string $module
* @param array $params
* @return void
*/
public function setGotoSimple($action, $controller = null, $module = null, array $params = array())
{
$dispatcher = $this->getFrontController()->getDispatcher();
$request = $this->getRequest();
$curModule = $request->getModuleName();
$useDefaultController = false;
if (null === $controller && null !== $module) {
$useDefaultController = true;
}
if (null === $module) {
$module = $curModule;
}
if ($module == $dispatcher->getDefaultModule()) {
$module = '';
}
if (null === $controller && !$useDefaultController) {
$controller = $request->getControllerName();
if (empty($controller)) {
$controller = $dispatcher->getDefaultControllerName();
}
}
$params['module'] = $module;
$params['controller'] = $controller;
$params['action'] = $action;
$router = $this->getFrontController()->getRouter();
$url = $router->assemble($params, 'default', true);
$this->_redirect($url);
}
/**
* Build a URL based on a route
*
* @param array $urlOptions
* @param string $name Route name
* @param boolean $reset
* @param boolean $encode
* @return void
*/
public function setGotoRoute(array $urlOptions = array(), $name = null, $reset = false, $encode = true)
{
$router = $this->getFrontController()->getRouter();
$url = $router->assemble($urlOptions, $name, $reset, $encode);
$this->_redirect($url);
}
/**
* Set a redirect URL string
*
* By default, emits a 302 HTTP status header, prepends base URL as defined
* in request object if url is relative, and halts script execution by
* calling exit().
*
* $options is an optional associative array that can be used to control
* redirect behaviour. The available option keys are:
* - exit: boolean flag indicating whether or not to halt script execution when done
* - prependBase: boolean flag indicating whether or not to prepend the base URL when a relative URL is provided
* - code: integer HTTP status code to use with redirect. Should be between 300 and 307.
*
* _redirect() sets the Location header in the response object. If you set
* the exit flag to false, you can override this header later in code
* execution.
*
* If the exit flag is true (true by default), _redirect() will write and
* close the current session, if any.
*
* @param string $url
* @param array $options
* @return void
*/
public function setGotoUrl($url, array $options = array())
{
// prevent header injections
$url = str_replace(array("\n", "\r"), '', $url);
$exit = $this->getExit();
$prependBase = $this->getPrependBase();
$code = $this->getCode();
if (null !== $options) {
if (isset($options['exit'])) {
$this->setExit(($options['exit']) ? true : false);
}
if (isset($options['prependBase'])) {
$this->setPrependBase(($options['prependBase']) ? true : false);
}
if (isset($options['code'])) {
$this->setCode($options['code']);
}
}
// If relative URL, decide if we should prepend base URL
if (!preg_match('|^[a-z]+://|', $url)) {
$url = $this->_prependBase($url);
}
$this->_redirect($url);
}
/**
* Perform a redirect to an action/controller/module with params
*
* @param string $action
* @param string $controller
* @param string $module
* @param array $params
* @return void
*/
public function gotoSimple($action, $controller = null, $module = null, array $params = array())
{
$this->setGotoSimple($action, $controller, $module, $params);
if ($this->getExit()) {
$this->redirectAndExit();
}
}
/**
* Perform a redirect to an action/controller/module with params, forcing an immdiate exit
*
* @param mixed $action
* @param mixed $controller
* @param mixed $module
* @param array $params
* @return void
*/
public function gotoSimpleAndExit($action, $controller = null, $module = null, array $params = array())
{
$this->setGotoSimple($action, $controller, $module, $params);
$this->redirectAndExit();
}
/**
* Redirect to a route-based URL
*
* Uses route's assemble method tobuild the URL; route is specified by $name;
* default route is used if none provided.
*
* @param array $urlOptions Array of key/value pairs used to assemble URL
* @param string $name
* @param boolean $reset
* @param boolean $encode
* @return void
*/
public function gotoRoute(array $urlOptions = array(), $name = null, $reset = false, $encode = true)
{
$this->setGotoRoute($urlOptions, $name, $reset, $encode);
if ($this->getExit()) {
$this->redirectAndExit();
}
}
/**
* Redirect to a route-based URL, and immediately exit
*
* Uses route's assemble method tobuild the URL; route is specified by $name;
* default route is used if none provided.
*
* @param array $urlOptions Array of key/value pairs used to assemble URL
* @param string $name
* @param boolean $reset
* @return void
*/
public function gotoRouteAndExit(array $urlOptions = array(), $name = null, $reset = false)
{
$this->setGotoRoute($urlOptions, $name, $reset);
$this->redirectAndExit();
}
/**
* Perform a redirect to a url
*
* @param string $url
* @param array $options
* @return void
*/
public function gotoUrl($url, array $options = array())
{
$this->setGotoUrl($url, $options);
if ($this->getExit()) {
$this->redirectAndExit();
}
}
/**
* Set a URL string for a redirect, perform redirect, and immediately exit
*
* @param string $url
* @param array $options
* @return void
*/
public function gotoUrlAndExit($url, array $options = array())
{
$this->gotoUrl($url, $options);
$this->redirectAndExit();
}
/**
* exit(): Perform exit for redirector
*
* @return void
*/
public function redirectAndExit()
{
// Close session, if started
if (class_exists('Zend_Session', false) && Zend_Session::isStarted()) {
Zend_Session::writeClose();
} elseif (isset($_SESSION)) {
session_write_close();
}
$this->getResponse()->sendHeaders();
exit();
}
/**
* direct(): Perform helper when called as
* $this->_helper->redirector($action, $controller, $module, $params)
*
* @param string $action
* @param string $controller
* @param string $module
* @param array $params
* @return void
*/
public function direct($action, $controller = null, $module = null, array $params = array())
{
$this->gotoSimple($action, $controller, $module, $params);
}
/**
* Overloading
*
* Overloading for old 'goto', 'setGoto', and 'gotoAndExit' methods
*
* @param string $method
* @param array $args
* @return mixed
* @throws Zend_Controller_Action_Exception for invalid methods
*/
public function __call($method, $args)
{
$method = strtolower($method);
if ('goto' == $method) {
return call_user_func_array(array($this, 'gotoSimple'), $args);
}
if ('setgoto' == $method) {
return call_user_func_array(array($this, 'setGotoSimple'), $args);
}
if ('gotoandexit' == $method) {
return call_user_func_array(array($this, 'gotoSimpleAndExit'), $args);
}
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception(sprintf('Invalid method "%s" called on redirector', $method));
}
}
ViewRenderer.php 0000666 00000072107 15125617502 0007675 0 ustar 00 <?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_Controller
* @subpackage Zend_Controller_Action_Helper
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* @see Zend_Controller_Action_Helper_Abstract
*/
require_once 'Zend/Controller/Action/Helper/Abstract.php';
/**
* @see Zend_View
*/
require_once 'Zend/View.php';
/**
* View script integration
*
* Zend_Controller_Action_Helper_ViewRenderer provides transparent view
* integration for action controllers. It allows you to create a view object
* once, and populate it throughout all actions. Several global options may be
* set:
*
* - noController: if set true, render() will not look for view scripts in
* subdirectories named after the controller
* - viewSuffix: what view script filename suffix to use
*
* The helper autoinitializes the action controller view preDispatch(). It
* determines the path to the class file, and then determines the view base
* directory from there. It also uses the module name as a class prefix for
* helpers and views such that if your module name is 'Search', it will set the
* helper class prefix to 'Search_View_Helper' and the filter class prefix to ;
* 'Search_View_Filter'.
*
* Usage:
* <code>
* // In your bootstrap:
* Zend_Controller_Action_HelperBroker::addHelper(new Zend_Controller_Action_Helper_ViewRenderer());
*
* // In your action controller methods:
* $viewHelper = $this->_helper->getHelper('view');
*
* // Don't use controller subdirectories
* $viewHelper->setNoController(true);
*
* // Specify a different script to render:
* $this->_helper->view('form');
*
* </code>
*
* @uses Zend_Controller_Action_Helper_Abstract
* @package Zend_Controller
* @subpackage Zend_Controller_Action_Helper
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Controller_Action_Helper_ViewRenderer extends Zend_Controller_Action_Helper_Abstract
{
/**
* @var Zend_View_Interface
*/
public $view;
/**
* Word delimiters
* @var array
*/
protected $_delimiters;
/**
* Front controller instance
* @var Zend_Controller_Front
*/
protected $_frontController;
/**
* @var Zend_Filter_Inflector
*/
protected $_inflector;
/**
* Inflector target
* @var string
*/
protected $_inflectorTarget = '';
/**
* Current module directory
* @var string
*/
protected $_moduleDir = '';
/**
* Whether or not to autorender using controller name as subdirectory;
* global setting (not reset at next invocation)
* @var boolean
*/
protected $_neverController = false;
/**
* Whether or not to autorender postDispatch; global setting (not reset at
* next invocation)
* @var boolean
*/
protected $_neverRender = false;
/**
* Whether or not to use a controller name as a subdirectory when rendering
* @var boolean
*/
protected $_noController = false;
/**
* Whether or not to autorender postDispatch; per controller/action setting (reset
* at next invocation)
* @var boolean
*/
protected $_noRender = false;
/**
* Characters representing path delimiters in the controller
* @var string|array
*/
protected $_pathDelimiters;
/**
* Which named segment of the response to utilize
* @var string
*/
protected $_responseSegment = null;
/**
* Which action view script to render
* @var string
*/
protected $_scriptAction = null;
/**
* View object basePath
* @var string
*/
protected $_viewBasePathSpec = ':moduleDir/views';
/**
* View script path specification string
* @var string
*/
protected $_viewScriptPathSpec = ':controller/:action.:suffix';
/**
* View script path specification string, minus controller segment
* @var string
*/
protected $_viewScriptPathNoControllerSpec = ':action.:suffix';
/**
* View script suffix
* @var string
*/
protected $_viewSuffix = 'phtml';
/**
* Constructor
*
* Optionally set view object and options.
*
* @param Zend_View_Interface $view
* @param array $options
* @return void
*/
public function __construct(Zend_View_Interface $view = null, array $options = array())
{
if (null !== $view) {
$this->setView($view);
}
if (!empty($options)) {
$this->_setOptions($options);
}
}
/**
* Clone - also make sure the view is cloned.
*
* @return void
*/
public function __clone()
{
if (isset($this->view) && $this->view instanceof Zend_View_Interface) {
$this->view = clone $this->view;
}
}
/**
* Set the view object
*
* @param Zend_View_Interface $view
* @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
*/
public function setView(Zend_View_Interface $view)
{
$this->view = $view;
return $this;
}
/**
* Get current module name
*
* @return string
*/
public function getModule()
{
$request = $this->getRequest();
$module = $request->getModuleName();
if (null === $module) {
$module = $this->getFrontController()->getDispatcher()->getDefaultModule();
}
return $module;
}
/**
* Get module directory
*
* @throws Zend_Controller_Action_Exception
* @return string
*/
public function getModuleDirectory()
{
$module = $this->getModule();
$moduleDir = $this->getFrontController()->getControllerDirectory($module);
if ((null === $moduleDir) || is_array($moduleDir)) {
/**
* @see Zend_Controller_Action_Exception
*/
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception('ViewRenderer cannot locate module directory');
}
$this->_moduleDir = dirname($moduleDir);
return $this->_moduleDir;
}
/**
* Get inflector
*
* @return Zend_Filter_Inflector
*/
public function getInflector()
{
if (null === $this->_inflector) {
/**
* @see Zend_Filter_Inflector
*/
require_once 'Zend/Filter/Inflector.php';
/**
* @see Zend_Filter_PregReplace
*/
require_once 'Zend/Filter/PregReplace.php';
/**
* @see Zend_Filter_Word_UnderscoreToSeparator
*/
require_once 'Zend/Filter/Word/UnderscoreToSeparator.php';
$this->_inflector = new Zend_Filter_Inflector();
$this->_inflector->setStaticRuleReference('moduleDir', $this->_moduleDir) // moduleDir must be specified before the less specific 'module'
->addRules(array(
':module' => array('Word_CamelCaseToDash', 'StringToLower'),
':controller' => array('Word_CamelCaseToDash', new Zend_Filter_Word_UnderscoreToSeparator('/'), 'StringToLower', new Zend_Filter_PregReplace('/\./', '-')),
':action' => array('Word_CamelCaseToDash', new Zend_Filter_PregReplace('#[^a-z0-9' . preg_quote('/', '#') . ']+#i', '-'), 'StringToLower'),
))
->setStaticRuleReference('suffix', $this->_viewSuffix)
->setTargetReference($this->_inflectorTarget);
}
// Ensure that module directory is current
$this->getModuleDirectory();
return $this->_inflector;
}
/**
* Set inflector
*
* @param Zend_Filter_Inflector $inflector
* @param boolean $reference Whether the moduleDir, target, and suffix should be set as references to ViewRenderer properties
* @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
*/
public function setInflector(Zend_Filter_Inflector $inflector, $reference = false)
{
$this->_inflector = $inflector;
if ($reference) {
$this->_inflector->setStaticRuleReference('suffix', $this->_viewSuffix)
->setStaticRuleReference('moduleDir', $this->_moduleDir)
->setTargetReference($this->_inflectorTarget);
}
return $this;
}
/**
* Set inflector target
*
* @param string $target
* @return void
*/
protected function _setInflectorTarget($target)
{
$this->_inflectorTarget = (string) $target;
}
/**
* Set internal module directory representation
*
* @param string $dir
* @return void
*/
protected function _setModuleDir($dir)
{
$this->_moduleDir = (string) $dir;
}
/**
* Get internal module directory representation
*
* @return string
*/
protected function _getModuleDir()
{
return $this->_moduleDir;
}
/**
* Generate a class prefix for helper and filter classes
*
* @return string
*/
protected function _generateDefaultPrefix()
{
$default = 'Zend_View';
if (null === $this->_actionController) {
return $default;
}
$class = get_class($this->_actionController);
if (!strstr($class, '_')) {
return $default;
}
$module = $this->getModule();
if ('default' == $module) {
return $default;
}
$prefix = substr($class, 0, strpos($class, '_')) . '_View';
return $prefix;
}
/**
* Retrieve base path based on location of current action controller
*
* @return string
*/
protected function _getBasePath()
{
if (null === $this->_actionController) {
return './views';
}
$inflector = $this->getInflector();
$this->_setInflectorTarget($this->getViewBasePathSpec());
$dispatcher = $this->_frontController->getDispatcher();
$request = $this->getRequest();
$parts = array(
'module' => (($moduleName = $request->getModuleName()) != '') ? $dispatcher->formatModuleName($moduleName) : $moduleName,
'controller' => $request->getControllerName(),
'action' => $dispatcher->formatActionName($request->getActionName())
);
$path = $inflector->filter($parts);
return $path;
}
/**
* Set options
*
* @param array $options
* @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
*/
protected function _setOptions(array $options)
{
foreach ($options as $key => $value)
{
switch ($key) {
case 'neverRender':
case 'neverController':
case 'noController':
case 'noRender':
$property = '_' . $key;
$this->{$property} = ($value) ? true : false;
break;
case 'responseSegment':
case 'scriptAction':
case 'viewBasePathSpec':
case 'viewScriptPathSpec':
case 'viewScriptPathNoControllerSpec':
case 'viewSuffix':
$property = '_' . $key;
$this->{$property} = (string) $value;
break;
default:
break;
}
}
return $this;
}
/**
* Initialize the view object
*
* $options may contain the following keys:
* - neverRender - flag dis/enabling postDispatch() autorender (affects all subsequent calls)
* - noController - flag indicating whether or not to look for view scripts in subdirectories named after the controller
* - noRender - flag indicating whether or not to autorender postDispatch()
* - responseSegment - which named response segment to render a view script to
* - scriptAction - what action script to render
* - viewBasePathSpec - specification to use for determining view base path
* - viewScriptPathSpec - specification to use for determining view script paths
* - viewScriptPathNoControllerSpec - specification to use for determining view script paths when noController flag is set
* - viewSuffix - what view script filename suffix to use
*
* @param string $path
* @param string $prefix
* @param array $options
* @throws Zend_Controller_Action_Exception
* @return void
*/
public function initView($path = null, $prefix = null, array $options = array())
{
if (null === $this->view) {
$this->setView(new Zend_View());
}
// Reset some flags every time
$options['noController'] = (isset($options['noController'])) ? $options['noController'] : false;
$options['noRender'] = (isset($options['noRender'])) ? $options['noRender'] : false;
$this->_scriptAction = null;
$this->_responseSegment = null;
// Set options first; may be used to determine other initializations
$this->_setOptions($options);
// Get base view path
if (empty($path)) {
$path = $this->_getBasePath();
if (empty($path)) {
/**
* @see Zend_Controller_Action_Exception
*/
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception('ViewRenderer initialization failed: retrieved view base path is empty');
}
}
if (null === $prefix) {
$prefix = $this->_generateDefaultPrefix();
}
// Determine if this path has already been registered
$currentPaths = $this->view->getScriptPaths();
$path = str_replace(array('/', '\\'), '/', $path);
$pathExists = false;
foreach ($currentPaths as $tmpPath) {
$tmpPath = str_replace(array('/', '\\'), '/', $tmpPath);
if (strstr($tmpPath, $path)) {
$pathExists = true;
break;
}
}
if (!$pathExists) {
$this->view->addBasePath($path, $prefix);
}
// Register view with action controller (unless already registered)
if ((null !== $this->_actionController) && (null === $this->_actionController->view)) {
$this->_actionController->view = $this->view;
$this->_actionController->viewSuffix = $this->_viewSuffix;
}
}
/**
* init - initialize view
*
* @return void
*/
public function init()
{
if ($this->getFrontController()->getParam('noViewRenderer')) {
return;
}
$this->initView();
}
/**
* Set view basePath specification
*
* Specification can contain one or more of the following:
* - :moduleDir - current module directory
* - :controller - name of current controller in the request
* - :action - name of current action in the request
* - :module - name of current module in the request
*
* @param string $path
* @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
*/
public function setViewBasePathSpec($path)
{
$this->_viewBasePathSpec = (string) $path;
return $this;
}
/**
* Retrieve the current view basePath specification string
*
* @return string
*/
public function getViewBasePathSpec()
{
return $this->_viewBasePathSpec;
}
/**
* Set view script path specification
*
* Specification can contain one or more of the following:
* - :moduleDir - current module directory
* - :controller - name of current controller in the request
* - :action - name of current action in the request
* - :module - name of current module in the request
*
* @param string $path
* @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
*/
public function setViewScriptPathSpec($path)
{
$this->_viewScriptPathSpec = (string) $path;
return $this;
}
/**
* Retrieve the current view script path specification string
*
* @return string
*/
public function getViewScriptPathSpec()
{
return $this->_viewScriptPathSpec;
}
/**
* Set view script path specification (no controller variant)
*
* Specification can contain one or more of the following:
* - :moduleDir - current module directory
* - :controller - name of current controller in the request
* - :action - name of current action in the request
* - :module - name of current module in the request
*
* :controller will likely be ignored in this variant.
*
* @param string $path
* @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
*/
public function setViewScriptPathNoControllerSpec($path)
{
$this->_viewScriptPathNoControllerSpec = (string) $path;
return $this;
}
/**
* Retrieve the current view script path specification string (no controller variant)
*
* @return string
*/
public function getViewScriptPathNoControllerSpec()
{
return $this->_viewScriptPathNoControllerSpec;
}
/**
* Get a view script based on an action and/or other variables
*
* Uses values found in current request if no values passed in $vars.
*
* If {@link $_noController} is set, uses {@link $_viewScriptPathNoControllerSpec};
* otherwise, uses {@link $_viewScriptPathSpec}.
*
* @param string $action
* @param array $vars
* @return string
*/
public function getViewScript($action = null, array $vars = array())
{
$request = $this->getRequest();
if ((null === $action) && (!isset($vars['action']))) {
$action = $this->getScriptAction();
if (null === $action) {
$action = $request->getActionName();
}
$vars['action'] = $action;
} elseif (null !== $action) {
$vars['action'] = $action;
}
$inflector = $this->getInflector();
if ($this->getNoController() || $this->getNeverController()) {
$this->_setInflectorTarget($this->getViewScriptPathNoControllerSpec());
} else {
$this->_setInflectorTarget($this->getViewScriptPathSpec());
}
return $this->_translateSpec($vars);
}
/**
* Set the neverRender flag (i.e., globally dis/enable autorendering)
*
* @param boolean $flag
* @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
*/
public function setNeverRender($flag = true)
{
$this->_neverRender = ($flag) ? true : false;
return $this;
}
/**
* Retrieve neverRender flag value
*
* @return boolean
*/
public function getNeverRender()
{
return $this->_neverRender;
}
/**
* Set the noRender flag (i.e., whether or not to autorender)
*
* @param boolean $flag
* @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
*/
public function setNoRender($flag = true)
{
$this->_noRender = ($flag) ? true : false;
return $this;
}
/**
* Retrieve noRender flag value
*
* @return boolean
*/
public function getNoRender()
{
return $this->_noRender;
}
/**
* Set the view script to use
*
* @param string $name
* @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
*/
public function setScriptAction($name)
{
$this->_scriptAction = (string) $name;
return $this;
}
/**
* Retrieve view script name
*
* @return string
*/
public function getScriptAction()
{
return $this->_scriptAction;
}
/**
* Set the response segment name
*
* @param string $name
* @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
*/
public function setResponseSegment($name)
{
if (null === $name) {
$this->_responseSegment = null;
} else {
$this->_responseSegment = (string) $name;
}
return $this;
}
/**
* Retrieve named response segment name
*
* @return string
*/
public function getResponseSegment()
{
return $this->_responseSegment;
}
/**
* Set the noController flag (i.e., whether or not to render into controller subdirectories)
*
* @param boolean $flag
* @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
*/
public function setNoController($flag = true)
{
$this->_noController = ($flag) ? true : false;
return $this;
}
/**
* Retrieve noController flag value
*
* @return boolean
*/
public function getNoController()
{
return $this->_noController;
}
/**
* Set the neverController flag (i.e., whether or not to render into controller subdirectories)
*
* @param boolean $flag
* @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
*/
public function setNeverController($flag = true)
{
$this->_neverController = ($flag) ? true : false;
return $this;
}
/**
* Retrieve neverController flag value
*
* @return boolean
*/
public function getNeverController()
{
return $this->_neverController;
}
/**
* Set view script suffix
*
* @param string $suffix
* @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
*/
public function setViewSuffix($suffix)
{
$this->_viewSuffix = (string) $suffix;
return $this;
}
/**
* Get view script suffix
*
* @return string
*/
public function getViewSuffix()
{
return $this->_viewSuffix;
}
/**
* Set options for rendering a view script
*
* @param string $action View script to render
* @param string $name Response named segment to render to
* @param boolean $noController Whether or not to render within a subdirectory named after the controller
* @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
*/
public function setRender($action = null, $name = null, $noController = null)
{
if (null !== $action) {
$this->setScriptAction($action);
}
if (null !== $name) {
$this->setResponseSegment($name);
}
if (null !== $noController) {
$this->setNoController($noController);
}
return $this;
}
/**
* Inflect based on provided vars
*
* Allowed variables are:
* - :moduleDir - current module directory
* - :module - current module name
* - :controller - current controller name
* - :action - current action name
* - :suffix - view script file suffix
*
* @param array $vars
* @return string
*/
protected function _translateSpec(array $vars = array())
{
$inflector = $this->getInflector();
$request = $this->getRequest();
$dispatcher = $this->_frontController->getDispatcher();
$module = $dispatcher->formatModuleName($request->getModuleName());
$controller = $request->getControllerName();
$action = $dispatcher->formatActionName($request->getActionName());
$params = compact('module', 'controller', 'action');
foreach ($vars as $key => $value) {
switch ($key) {
case 'module':
case 'controller':
case 'action':
case 'moduleDir':
case 'suffix':
$params[$key] = (string) $value;
break;
default:
break;
}
}
if (isset($params['suffix'])) {
$origSuffix = $this->getViewSuffix();
$this->setViewSuffix($params['suffix']);
}
if (isset($params['moduleDir'])) {
$origModuleDir = $this->_getModuleDir();
$this->_setModuleDir($params['moduleDir']);
}
$filtered = $inflector->filter($params);
if (isset($params['suffix'])) {
$this->setViewSuffix($origSuffix);
}
if (isset($params['moduleDir'])) {
$this->_setModuleDir($origModuleDir);
}
return $filtered;
}
/**
* Render a view script (optionally to a named response segment)
*
* Sets the noRender flag to true when called.
*
* @param string $script
* @param string $name
* @return void
*/
public function renderScript($script, $name = null)
{
if (null === $name) {
$name = $this->getResponseSegment();
}
$this->getResponse()->appendBody(
$this->view->render($script),
$name
);
$this->setNoRender();
}
/**
* Render a view based on path specifications
*
* Renders a view based on the view script path specifications.
*
* @param string $action
* @param string $name
* @param boolean $noController
* @return void
*/
public function render($action = null, $name = null, $noController = null)
{
$this->setRender($action, $name, $noController);
$path = $this->getViewScript();
$this->renderScript($path, $name);
}
/**
* Render a script based on specification variables
*
* Pass an action, and one or more specification variables (view script suffix)
* to determine the view script path, and render that script.
*
* @param string $action
* @param array $vars
* @param string $name
* @return void
*/
public function renderBySpec($action = null, array $vars = array(), $name = null)
{
if (null !== $name) {
$this->setResponseSegment($name);
}
$path = $this->getViewScript($action, $vars);
$this->renderScript($path);
}
/**
* postDispatch - auto render a view
*
* Only autorenders if:
* - _noRender is false
* - action controller is present
* - request has not been re-dispatched (i.e., _forward() has not been called)
* - response is not a redirect
*
* @return void
*/
public function postDispatch()
{
if ($this->_shouldRender()) {
$this->render();
}
}
/**
* Should the ViewRenderer render a view script?
*
* @return boolean
*/
protected function _shouldRender()
{
return (!$this->getFrontController()->getParam('noViewRenderer')
&& !$this->_neverRender
&& !$this->_noRender
&& (null !== $this->_actionController)
&& $this->getRequest()->isDispatched()
&& !$this->getResponse()->isRedirect()
);
}
/**
* Use this helper as a method; proxies to setRender()
*
* @param string $action
* @param string $name
* @param boolean $noController
* @return void
*/
public function direct($action = null, $name = null, $noController = null)
{
$this->setRender($action, $name, $noController);
}
}
ContextSwitch.php 0000666 00000123333 15125617502 0010100 0 ustar 00 <?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_Controller
* @subpackage Zend_Controller_Action_Helper
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: ContextSwitch.php 12812 2008-11-24 20:46:45Z matthew $
*/
/**
* @see Zend_Controller_Action_Helper_Abstract
*/
require_once 'Zend/Controller/Action/Helper/Abstract.php';
/**
* Simplify context switching based on requested format
*
* @uses Zend_Controller_Action_Helper_Abstract
* @category Zend
* @package Zend_Controller
* @subpackage Zend_Controller_Action_Helper
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Controller_Action_Helper_ContextSwitch extends Zend_Controller_Action_Helper_Abstract
{
/**
* Trigger type constants
*/
const TRIGGER_INIT = 'TRIGGER_INIT';
const TRIGGER_POST = 'TRIGGER_POST';
/**
* Supported contexts
* @var array
*/
protected $_contexts = array();
/**
* JSON auto-serialization flag
* @var boolean
*/
protected $_autoJsonSerialization = true;
/**
* Controller property key to utilize for context switching
* @var string
*/
protected $_contextKey = 'contexts';
/**
* Request parameter containing requested context
* @var string
*/
protected $_contextParam = 'format';
/**
* Current context
* @var string
*/
protected $_currentContext;
/**
* Default context (xml)
* @var string
*/
protected $_defaultContext = 'xml';
/**
* Whether or not to disable layouts when switching contexts
* @var boolean
*/
protected $_disableLayout = true;
/**
* Methods that require special configuration
* @var array
*/
protected $_specialConfig = array(
'setSuffix',
'setHeaders',
'setCallbacks',
);
/**
* Methods that are not configurable via setOptions and setConfig
* @var array
*/
protected $_unconfigurable = array(
'setOptions',
'setConfig',
'setHeader',
'setCallback',
'setContext',
'setActionContext',
'setActionContexts',
);
/**
* @var Zend_Controller_Action_Helper_ViewRenderer
*/
protected $_viewRenderer;
/**
* Original view suffix prior to detecting context switch
* @var string
*/
protected $_viewSuffixOrig;
/**
* Constructor
*
* @param array|Zend_Config $options
* @return void
*/
public function __construct($options = null)
{
if ($options instanceof Zend_Config) {
$this->setConfig($options);
} elseif (is_array($options)) {
$this->setOptions($options);
}
if (empty($this->_contexts)) {
$this->addContexts(array(
'json' => array(
'suffix' => 'json',
'headers' => array('Content-Type' => 'application/json'),
'callbacks' => array(
'init' => 'initJsonContext',
'post' => 'postJsonContext'
)
),
'xml' => array(
'suffix' => 'xml',
'headers' => array('Content-Type' => 'application/xml'),
)
));
}
$this->init();
}
/**
* Initialize at start of action controller
*
* Reset the view script suffix to the original state, or store the
* original state.
*
* @return void
*/
public function init()
{
if (null === $this->_viewSuffixOrig) {
$this->_viewSuffixOrig = $this->_getViewRenderer()->getViewSuffix();
} else {
$this->_getViewRenderer()->setViewSuffix($this->_viewSuffixOrig);
}
}
/**
* Configure object from array of options
*
* @param array $options
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
public function setOptions(array $options)
{
if (isset($options['contexts'])) {
$this->setContexts($options['contexts']);
unset($options['contexts']);
}
foreach ($options as $key => $value) {
$method = 'set' . ucfirst($key);
if (in_array($method, $this->_unconfigurable)) {
continue;
}
if (in_array($method, $this->_specialConfig)) {
$method = '_' . $method;
}
if (method_exists($this, $method)) {
$this->$method($value);
}
}
return $this;
}
/**
* Set object state from config object
*
* @param Zend_Config $config
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
public function setConfig(Zend_Config $config)
{
return $this->setOptions($config->toArray());
}
/**
* Strategy pattern: return object
*
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
public function direct()
{
return $this;
}
/**
* Initialize context detection and switching
*
* @param mixed $format
* @throws Zend_Controller_Action_Exception
* @return void
*/
public function initContext($format = null)
{
$this->_currentContext = null;
$controller = $this->getActionController();
$request = $this->getRequest();
$action = $request->getActionName();
// Return if no context switching enabled, or no context switching
// enabled for this action
$contexts = $this->getActionContexts($action);
if (empty($contexts)) {
return;
}
// Return if no context parameter provided
if (!$context = $request->getParam($this->getContextParam())) {
if ($format === null) {
return;
}
$context = $format;
$format = null;
}
// Check if context allowed by action controller
if (!$this->hasActionContext($action, $context)) {
return;
}
// Return if invalid context parameter provided and no format or invalid
// format provided
if (!$this->hasContext($context)) {
if (empty($format) || !$this->hasContext($format)) {
return;
}
}
// Use provided format if passed
if (!empty($format) && $this->hasContext($format)) {
$context = $format;
}
$suffix = $this->getSuffix($context);
$this->_getViewRenderer()->setViewSuffix($suffix);
$headers = $this->getHeaders($context);
if (!empty($headers)) {
$response = $this->getResponse();
foreach ($headers as $header => $content) {
$response->setHeader($header, $content);
}
}
if ($this->getAutoDisableLayout()) {
/**
* @see Zend_Layout
*/
require_once 'Zend/Layout.php';
$layout = Zend_Layout::getMvcInstance();
if (null !== $layout) {
$layout->disableLayout();
}
}
if (null !== ($callback = $this->getCallback($context, self::TRIGGER_INIT))) {
if (is_string($callback) && method_exists($this, $callback)) {
$this->$callback();
} elseif (is_string($callback) && function_exists($callback)) {
$callback();
} elseif (is_array($callback)) {
call_user_func($callback);
} else {
/**
* @see Zend_Controller_Action_Exception
*/
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception(sprintf('Invalid context callback registered for context "%s"', $context));
}
}
$this->_currentContext = $context;
}
/**
* JSON context extra initialization
*
* Turns off viewRenderer auto-rendering
*
* @return void
*/
public function initJsonContext()
{
if (!$this->getAutoJsonSerialization()) {
return;
}
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
$view = $viewRenderer->view;
if ($view instanceof Zend_View_Interface) {
$viewRenderer->setNoRender(true);
}
}
/**
* Should JSON contexts auto-serialize?
*
* @param boolean $flag
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
public function setAutoJsonSerialization($flag)
{
$this->_autoJsonSerialization = (bool) $flag;
return $this;
}
/**
* Get JSON context auto-serialization flag
*
* @return boolean
*/
public function getAutoJsonSerialization()
{
return $this->_autoJsonSerialization;
}
/**
* Set suffix from array
*
* @param array $spec
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
protected function _setSuffix(array $spec)
{
foreach ($spec as $context => $suffixInfo) {
if (!is_string($context)) {
$context = null;
}
if (is_string($suffixInfo)) {
$this->setSuffix($context, $suffixInfo);
continue;
} elseif (is_array($suffixInfo)) {
if (isset($suffixInfo['suffix'])) {
$suffix = $suffixInfo['suffix'];
$prependViewRendererSuffix = true;
if ((null === $context) && isset($suffixInfo['context'])) {
$context = $suffixInfo['context'];
}
if (isset($suffixInfo['prependViewRendererSuffix'])) {
$prependViewRendererSuffix = $suffixInfo['prependViewRendererSuffix'];
}
$this->setSuffix($context, $suffix, $prependViewRendererSuffix);
continue;
}
$count = count($suffixInfo);
switch (true) {
case (($count < 2) && (null === $context)):
/**
* @see Zend_Controller_Action_Exception
*/
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception('Invalid suffix information provided in config');
case ($count < 2):
$suffix = array_shift($suffixInfo);
$this->setSuffix($context, $suffix);
break;
case (($count < 3) && (null === $context)):
$context = array_shift($suffixInfo);
$suffix = array_shift($suffixInfo);
$this->setSuffix($context, $suffix);
break;
case (($count == 3) && (null === $context)):
$context = array_shift($suffixInfo);
$suffix = array_shift($suffixInfo);
$prependViewRendererSuffix = array_shift($suffixInfo);
$this->setSuffix($context, $suffix, $prependViewRendererSuffix);
break;
case ($count >= 2):
$suffix = array_shift($suffixInfo);
$prependViewRendererSuffix = array_shift($suffixInfo);
$this->setSuffix($context, $suffix, $prependViewRendererSuffix);
break;
}
}
}
return $this;
}
/**
* Customize view script suffix to use when switching context.
*
* Passing an empty suffix value to the setters disables the view script
* suffix change.
*
* @param string $context Context type for which to set suffix
* @param string $suffix Suffix to use
* @param boolean $prependViewRendererSuffix Whether or not to prepend the new suffix to the viewrenderer suffix
* @throws Zend_Controller_Action_Exception
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
public function setSuffix($context, $suffix, $prependViewRendererSuffix = true)
{
if (!isset($this->_contexts[$context])) {
/**
* @see Zend_Controller_Action_Exception
*/
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception(sprintf('Cannot set suffix; invalid context type "%s"', $context));
}
if (empty($suffix)) {
$suffix = '';
}
if (is_array($suffix)) {
if (isset($suffix['prependViewRendererSuffix'])) {
$prependViewRendererSuffix = $suffix['prependViewRendererSuffix'];
}
if (isset($suffix['suffix'])) {
$suffix = $suffix['suffix'];
} else {
$suffix = '';
}
}
$suffix = (string) $suffix;
if ($prependViewRendererSuffix) {
if (empty($suffix)) {
$suffix = $this->_getViewRenderer()->getViewSuffix();
} else {
$suffix .= '.' . $this->_getViewRenderer()->getViewSuffix();
}
}
$this->_contexts[$context]['suffix'] = $suffix;
return $this;
}
/**
* Retrieve suffix for given context type
*
* @param string $type Context type
* @throws Zend_Controller_Action_Exception
* @return string
*/
public function getSuffix($type)
{
if (!isset($this->_contexts[$type])) {
/**
* @see Zend_Controller_Action_Exception
*/
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception(sprintf('Cannot retrieve suffix; invalid context type "%s"', $type));
}
return $this->_contexts[$type]['suffix'];
}
/**
* Does the given context exist?
*
* @param string $context
* @param boolean $throwException
* @throws Zend_Controller_Action_Exception if context does not exist and throwException is true
* @return bool
*/
public function hasContext($context, $throwException = false)
{
if (is_string($context)) {
if (isset($this->_contexts[$context])) {
return true;
}
} elseif (is_array($context)) {
$error = false;
foreach ($context as $test) {
if (!isset($this->_contexts[$test])) {
$error = (string) $test;
break;
}
}
if (false === $error) {
return true;
}
$context = $error;
} elseif (true === $context) {
return true;
}
if ($throwException) {
/**
* @see Zend_Controller_Action_Exception
*/
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception(sprintf('Context "%s" does not exist', $context));
}
return false;
}
/**
* Add header to context
*
* @param string $context
* @param string $header
* @param string $content
* @throws Zend_Controller_Action_Exception
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
public function addHeader($context, $header, $content)
{
$context = (string) $context;
$this->hasContext($context, true);
$header = (string) $header;
$content = (string) $content;
if (isset($this->_contexts[$context]['headers'][$header])) {
/**
* @see Zend_Controller_Action_Exception
*/
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception(sprintf('Cannot add "%s" header to context "%s": already exists', $header, $context));
}
$this->_contexts[$context]['headers'][$header] = $content;
return $this;
}
/**
* Customize response header to use when switching context
*
* Passing an empty header value to the setters disables the response
* header.
*
* @param string $type Context type for which to set suffix
* @param string $header Header to set
* @param string $content Header content
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
public function setHeader($context, $header, $content)
{
$this->hasContext($context, true);
$context = (string) $context;
$header = (string) $header;
$content = (string) $content;
$this->_contexts[$context]['headers'][$header] = $content;
return $this;
}
/**
* Add multiple headers at once for a given context
*
* @param string $context
* @param array $headers
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
public function addHeaders($context, array $headers)
{
foreach ($headers as $header => $content) {
$this->addHeader($context, $header, $content);
}
return $this;
}
/**
* Set headers from context => headers pairs
*
* @param array $options
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
protected function _setHeaders(array $options)
{
foreach ($options as $context => $headers) {
if (!is_array($headers)) {
continue;
}
$this->setHeaders($context, $headers);
}
return $this;
}
/**
* Set multiple headers at once for a given context
*
* @param string $context
* @param array $headers
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
public function setHeaders($context, array $headers)
{
$this->clearHeaders($context);
foreach ($headers as $header => $content) {
$this->setHeader($context, $header, $content);
}
return $this;
}
/**
* Retrieve context header
*
* Returns the value of a given header for a given context type
*
* @param string $context
* @param string $header
* @return string|null
*/
public function getHeader($context, $header)
{
$this->hasContext($context, true);
$context = (string) $context;
$header = (string) $header;
if (isset($this->_contexts[$context]['headers'][$header])) {
return $this->_contexts[$context]['headers'][$header];
}
return null;
}
/**
* Retrieve context headers
*
* Returns all headers for a context as key/value pairs
*
* @param string $context
* @return array
*/
public function getHeaders($context)
{
$this->hasContext($context, true);
$context = (string) $context;
return $this->_contexts[$context]['headers'];
}
/**
* Remove a single header from a context
*
* @param string $context
* @param string $header
* @return boolean
*/
public function removeHeader($context, $header)
{
$this->hasContext($context, true);
$context = (string) $context;
$header = (string) $header;
if (isset($this->_contexts[$context]['headers'][$header])) {
unset($this->_contexts[$context]['headers'][$header]);
return true;
}
return false;
}
/**
* Clear all headers for a given context
*
* @param string $context
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
public function clearHeaders($context)
{
$this->hasContext($context, true);
$context = (string) $context;
$this->_contexts[$context]['headers'] = array();
return $this;
}
/**
* Validate trigger and return in normalized form
*
* @param string $trigger
* @throws Zend_Controller_Action_Exception
* @return string
*/
protected function _validateTrigger($trigger)
{
$trigger = strtoupper($trigger);
if ('TRIGGER_' !== substr($trigger, 0, 8)) {
$trigger = 'TRIGGER_' . $trigger;
}
if (!in_array($trigger, array(self::TRIGGER_INIT, self::TRIGGER_POST))) {
/**
* @see Zend_Controller_Action_Exception
*/
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception(sprintf('Invalid trigger "%s"', $trigger));
}
return $trigger;
}
/**
* Set a callback for a given context and trigger
*
* @param string $context
* @param string $trigger
* @param string|array $callback
* @throws Zend_Controller_Action_Exception
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
public function setCallback($context, $trigger, $callback)
{
$this->hasContext($context, true);
$trigger = $this->_validateTrigger($trigger);
if (!is_string($callback)) {
if (!is_array($callback) || (2 != count($callback))) {
/**
* @see Zend_Controller_Action_Exception
*/
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception('Invalid callback specified');
}
}
$this->_contexts[$context]['callbacks'][$trigger] = $callback;
return $this;
}
/**
* Set callbacks from array of context => callbacks pairs
*
* @param array $options
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
protected function _setCallbacks(array $options)
{
foreach ($options as $context => $callbacks) {
if (!is_array($callbacks)) {
continue;
}
$this->setCallbacks($context, $callbacks);
}
return $this;
}
/**
* Set callbacks for a given context
*
* Callbacks should be in trigger/callback pairs.
*
* @param string $context
* @param array $callbacks
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
public function setCallbacks($context, array $callbacks)
{
$this->hasContext($context, true);
$context = (string) $context;
if (!isset($this->_contexts[$context]['callbacks'])) {
$this->_contexts[$context]['callbacks'] = array();
}
foreach ($callbacks as $trigger => $callback) {
$this->setCallback($context, $trigger, $callback);
}
return $this;
}
/**
* Get a single callback for a given context and trigger
*
* @param string $context
* @param string $trigger
* @return string|array|null
*/
public function getCallback($context, $trigger)
{
$this->hasContext($context, true);
$trigger = $this->_validateTrigger($trigger);
if (isset($this->_contexts[$context]['callbacks'][$trigger])) {
return $this->_contexts[$context]['callbacks'][$trigger];
}
return null;
}
/**
* Get all callbacks for a given context
*
* @param string $context
* @return array
*/
public function getCallbacks($context)
{
$this->hasContext($context, true);
return $this->_contexts[$context]['callbacks'];
}
/**
* Clear a callback for a given context and trigger
*
* @param string $context
* @param string $trigger
* @return boolean
*/
public function removeCallback($context, $trigger)
{
$this->hasContext($context, true);
$trigger = $this->_validateTrigger($trigger);
if (isset($this->_contexts[$context]['callbacks'][$trigger])) {
unset($this->_contexts[$context]['callbacks'][$trigger]);
return true;
}
return false;
}
/**
* Clear all callbacks for a given context
*
* @param string $context
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
public function clearCallbacks($context)
{
$this->hasContext($context, true);
$this->_contexts[$context]['callbacks'] = array();
return $this;
}
/**
* Set name of parameter to use when determining context format
*
* @param string $name
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
public function setContextParam($name)
{
$this->_contextParam = (string) $name;
return $this;
}
/**
* Return context format request parameter name
*
* @return string
*/
public function getContextParam()
{
return $this->_contextParam;
}
/**
* Indicate default context to use when no context format provided
*
* @param string $type
* @throws Zend_Controller_Action_Exception
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
public function setDefaultContext($type)
{
if (!isset($this->_contexts[$type])) {
/**
* @see Zend_Controller_Action_Exception
*/
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception(sprintf('Cannot set default context; invalid context type "%s"', $type));
}
$this->_defaultContext = $type;
return $this;
}
/**
* Return default context
*
* @return string
*/
public function getDefaultContext()
{
return $this->_defaultContext;
}
/**
* Set flag indicating if layout should be disabled
*
* @param boolean $flag
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
public function setAutoDisableLayout($flag)
{
$this->_disableLayout = ($flag) ? true : false;
return $this;
}
/**
* Retrieve auto layout disable flag
*
* @return boolean
*/
public function getAutoDisableLayout()
{
return $this->_disableLayout;
}
/**
* Add new context
*
* @param string $context Context type
* @param array $spec Context specification
* @throws Zend_Controller_Action_Exception
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
public function addContext($context, array $spec)
{
if ($this->hasContext($context)) {
/**
* @see Zend_Controller_Action_Exception
*/
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception(sprintf('Cannot add context "%s"; already exists', $context));
}
$context = (string) $context;
$this->_contexts[$context] = array();
$this->setSuffix($context, (isset($spec['suffix']) ? $spec['suffix'] : ''))
->setHeaders($context, (isset($spec['headers']) ? $spec['headers'] : array()))
->setCallbacks($context, (isset($spec['callbacks']) ? $spec['callbacks'] : array()));
return $this;
}
/**
* Overwrite existing context
*
* @param string $context Context type
* @param array $spec Context specification
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
public function setContext($context, array $spec)
{
$this->removeContext($context);
return $this->addContext($context, $spec);
}
/**
* Add multiple contexts
*
* @param array $contexts
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
public function addContexts(array $contexts)
{
foreach ($contexts as $context => $spec) {
$this->addContext($context, $spec);
}
return $this;
}
/**
* Set multiple contexts, after first removing all
*
* @param array $contexts
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
public function setContexts(array $contexts)
{
$this->clearContexts();
foreach ($contexts as $context => $spec) {
$this->addContext($context, $spec);
}
return $this;
}
/**
* Retrieve context specification
*
* @param string $context
* @return array|null
*/
public function getContext($context)
{
if ($this->hasContext($context)) {
return $this->_contexts[(string) $context];
}
return null;
}
/**
* Retrieve context definitions
*
* @return array
*/
public function getContexts()
{
return $this->_contexts;
}
/**
* Remove a context
*
* @param string $context
* @return boolean
*/
public function removeContext($context)
{
if ($this->hasContext($context)) {
unset($this->_contexts[(string) $context]);
return true;
}
return false;
}
/**
* Remove all contexts
*
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
public function clearContexts()
{
$this->_contexts = array();
return $this;
}
/**
* Return current context, if any
*
* @return null|string
*/
public function getCurrentContext()
{
return $this->_currentContext;
}
/**
* Post dispatch processing
*
* Execute postDispatch callback for current context, if available
*
* @throws Zend_Controller_Action_Exception
* @return void
*/
public function postDispatch()
{
$context = $this->getCurrentContext();
if (null !== $context) {
if (null !== ($callback = $this->getCallback($context, self::TRIGGER_POST))) {
if (is_string($callback) && method_exists($this, $callback)) {
$this->$callback();
} elseif (is_string($callback) && function_exists($callback)) {
$callback();
} elseif (is_array($callback)) {
call_user_func($callback);
} else {
/**
* @see Zend_Controller_Action_Exception
*/
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception(sprintf('Invalid postDispatch context callback registered for context "%s"', $context));
}
}
}
}
/**
* JSON post processing
*
* JSON serialize view variables to response body
*
* @return void
*/
public function postJsonContext()
{
if (!$this->getAutoJsonSerialization()) {
return;
}
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
$view = $viewRenderer->view;
if ($view instanceof Zend_View_Interface) {
/**
* @see Zend_Json
*/
if(method_exists($view, 'getVars')) {
require_once 'Zend/Json.php';
$vars = Zend_Json::encode($view->getVars());
$this->getResponse()->setBody($vars);
} else {
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception('View does not implement the getVars() method needed to encode the view into JSON');
}
}
}
/**
* Add one or more contexts to an action
*
* @param string $action
* @param string|array $context
* @return Zend_Controller_Action_Helper_ContextSwitch|void Provides a fluent interface
*/
public function addActionContext($action, $context)
{
$this->hasContext($context, true);
$controller = $this->getActionController();
if (null === $controller) {
return;
}
$action = (string) $action;
$contextKey = $this->_contextKey;
if (!isset($controller->$contextKey)) {
$controller->$contextKey = array();
}
if (true === $context) {
$contexts = $this->getContexts();
$controller->{$contextKey}[$action] = array_keys($contexts);
return $this;
}
$context = (array) $context;
if (!isset($controller->{$contextKey}[$action])) {
$controller->{$contextKey}[$action] = $context;
} else {
$controller->{$contextKey}[$action] = array_merge(
$controller->{$contextKey}[$action],
$context
);
}
return $this;
}
/**
* Set a context as available for a given controller action
*
* @param string $action
* @param string|array $context
* @return Zend_Controller_Action_Helper_ContextSwitch|void Provides a fluent interface
*/
public function setActionContext($action, $context)
{
$this->hasContext($context, true);
$controller = $this->getActionController();
if (null === $controller) {
return;
}
$action = (string) $action;
$contextKey = $this->_contextKey;
if (!isset($controller->$contextKey)) {
$controller->$contextKey = array();
}
if (true === $context) {
$contexts = $this->getContexts();
$controller->{$contextKey}[$action] = array_keys($contexts);
} else {
$controller->{$contextKey}[$action] = (array) $context;
}
return $this;
}
/**
* Add multiple action/context pairs at once
*
* @param array $contexts
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
public function addActionContexts(array $contexts)
{
foreach ($contexts as $action => $context) {
$this->addActionContext($action, $context);
}
return $this;
}
/**
* Overwrite and set multiple action contexts at once
*
* @param array $contexts
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
public function setActionContexts(array $contexts)
{
foreach ($contexts as $action => $context) {
$this->setActionContext($action, $context);
}
return $this;
}
/**
* Does a particular controller action have the given context(s)?
*
* @param string $action
* @param string|array $context
* @throws Zend_Controller_Action_Exception
* @return boolean
*/
public function hasActionContext($action, $context)
{
$this->hasContext($context, true);
$controller = $this->getActionController();
if (null === $controller) {
return false;
}
$action = (string) $action;
$contextKey = $this->_contextKey;
if (!isset($controller->{$contextKey})) {
return false;
}
$allContexts = $controller->{$contextKey};
if (!is_array($allContexts)) {
/**
* @see Zend_Controller_Action_Exception
*/
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception("Invalid contexts found for controller");
}
if (!isset($allContexts[$action])) {
return false;
}
if (true === $allContexts[$action]) {
return true;
}
$contexts = $allContexts[$action];
if (!is_array($contexts)) {
/**
* @see Zend_Controller_Action_Exception
*/
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception(sprintf("Invalid contexts found for action '%s'", $action));
}
if (is_string($context) && in_array($context, $contexts)) {
return true;
} elseif (is_array($context)) {
$found = true;
foreach ($context as $test) {
if (!in_array($test, $contexts)) {
$found = false;
break;
}
}
return $found;
}
return false;
}
/**
* Get contexts for a given action or all actions in the controller
*
* @param string $action
* @return array
*/
public function getActionContexts($action = null)
{
$controller = $this->getActionController();
if (null === $controller) {
return array();
}
$action = (string) $action;
$contextKey = $this->_contextKey;
if (!isset($controller->$contextKey)) {
return array();
}
if (null !== $action) {
if (isset($controller->{$contextKey}[$action])) {
return $controller->{$contextKey}[$action];
} else {
return array();
}
}
return $controller->$contextKey;
}
/**
* Remove one or more contexts for a given controller action
*
* @param string $action
* @param string|array $context
* @return boolean
*/
public function removeActionContext($action, $context)
{
if ($this->hasActionContext($action, $context)) {
$controller = $this->getActionController();
$contextKey = $this->_contextKey;
$action = (string) $action;
$contexts = $controller->$contextKey;
$actionContexts = $contexts[$action];
$contexts = (array) $context;
foreach ($contexts as $context) {
$index = array_search($context, $actionContexts);
if (false !== $index) {
unset($controller->{$contextKey}[$action][$index]);
}
}
return true;
}
return false;
}
/**
* Clear all contexts for a given controller action or all actions
*
* @param string $action
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
public function clearActionContexts($action = null)
{
$controller = $this->getActionController();
$contextKey = $this->_contextKey;
if (!isset($controller->$contextKey) || empty($controller->$contextKey)) {
return $this;
}
if (null === $action) {
$controller->$contextKey = array();
return $this;
}
$action = (string) $action;
if (isset($controller->{$contextKey}[$action])) {
unset($controller->{$contextKey}[$action]);
}
return $this;
}
/**
* Retrieve ViewRenderer
*
* @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
*/
protected function _getViewRenderer()
{
if (null === $this->_viewRenderer) {
$this->_viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
}
return $this->_viewRenderer;
}
}
Layout.php 0000666 00000012007 15125720012 0006531 0 ustar 00 <?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_Controller
* @subpackage Zend_Controller_Action
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Layout.php 11508 2008-09-24 14:21:30Z doctorrock83 $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Controller_Action_Helper_Abstract */
require_once 'Zend/Controller/Action/Helper/Abstract.php';
/**
* Helper for interacting with Zend_Layout objects
*
* @uses Zend_Controller_Action_Helper_Abstract
* @category Zend
* @package Zend_Controller
* @subpackage Zend_Controller_Action
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Layout_Controller_Action_Helper_Layout extends Zend_Controller_Action_Helper_Abstract
{
/**
* @var Zend_Controller_Front
*/
protected $_frontController;
/**
* @var Zend_Layout
*/
protected $_layout;
/**
* @var bool
*/
protected $_isActionControllerSuccessful = false;
/**
* Constructor
*
* @param Zend_Layout $layout
* @return void
*/
public function __construct(Zend_Layout $layout = null)
{
if (null !== $layout) {
$this->setLayoutInstance($layout);
} else {
/**
* @see Zend_Layout
*/
require_once 'Zend/Layout.php';
$layout = Zend_Layout::getMvcInstance();
}
if (null !== $layout) {
$pluginClass = $layout->getPluginClass();
$front = $this->getFrontController();
if ($front->hasPlugin($pluginClass)) {
$plugin = $front->getPlugin($pluginClass);
$plugin->setLayoutActionHelper($this);
}
}
}
public function init()
{
$this->_isActionControllerSuccessful = false;
}
/**
* Get front controller instance
*
* @return Zend_Controller_Front
*/
public function getFrontController()
{
if (null === $this->_frontController) {
/**
* @see Zend_Controller_Front
*/
require_once 'Zend/Controller/Front.php';
$this->_frontController = Zend_Controller_Front::getInstance();
}
return $this->_frontController;
}
/**
* Get layout object
*
* @return Zend_Layout
*/
public function getLayoutInstance()
{
if (null === $this->_layout) {
/**
* @see Zend_Layout
*/
require_once 'Zend/Layout.php';
if (null === ($this->_layout = Zend_Layout::getMvcInstance())) {
$this->_layout = new Zend_Layout();
}
}
return $this->_layout;
}
/**
* Set layout object
*
* @param Zend_Layout $layout
* @return Zend_Layout_Controller_Action_Helper_Layout
*/
public function setLayoutInstance(Zend_Layout $layout)
{
$this->_layout = $layout;
return $this;
}
/**
* Mark Action Controller (according to this plugin) as Running successfully
*
* @return Zend_Layout_Controller_Action_Helper_Layout
*/
public function postDispatch()
{
$this->_isActionControllerSuccessful = true;
return $this;
}
/**
* Did the previous action successfully complete?
*
* @return bool
*/
public function isActionControllerSuccessful()
{
return $this->_isActionControllerSuccessful;
}
/**
* Strategy pattern; call object as method
*
* Returns layout object
*
* @return Zend_Layout
*/
public function direct()
{
return $this->getLayoutInstance();
}
/**
* Proxy method calls to layout object
*
* @param string $method
* @param array $args
* @return mixed
*/
public function __call($method, $args)
{
$layout = $this->getLayoutInstance();
if (method_exists($layout, $method)) {
return call_user_func_array(array($layout, $method), $args);
}
require_once 'Zend/Layout/Exception.php';
throw new Zend_Layout_Exception(sprintf("Invalid method '%s' called on layout action helper", $method));
}
}