adding zend project folders into old campcaster.

This commit is contained in:
naomiaro 2010-12-07 14:19:27 -05:00
parent 56abfaf28e
commit 7ef0c18b26
4045 changed files with 1054952 additions and 0 deletions

View file

@ -0,0 +1,254 @@
<?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_Form
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Decorator_Interface */
require_once 'Zend/Form/Decorator/Interface.php';
/**
* Zend_Form_Decorator_Abstract
*
* @category Zend
* @package Zend_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Abstract.php 21147 2010-02-23 14:42:04Z yoshida@zend.co.jp $
*/
abstract class Zend_Form_Decorator_Abstract implements Zend_Form_Decorator_Interface
{
/**
* Placement constants
*/
const APPEND = 'APPEND';
const PREPEND = 'PREPEND';
/**
* Default placement: append
* @var string
*/
protected $_placement = 'APPEND';
/**
* @var Zend_Form_Element|Zend_Form
*/
protected $_element;
/**
* Decorator options
* @var array
*/
protected $_options = array();
/**
* Separator between new content and old
* @var string
*/
protected $_separator = PHP_EOL;
/**
* Constructor
*
* @param array|Zend_Config $options
* @return void
*/
public function __construct($options = null)
{
if (is_array($options)) {
$this->setOptions($options);
} elseif ($options instanceof Zend_Config) {
$this->setConfig($options);
}
}
/**
* Set options
*
* @param array $options
* @return Zend_Form_Decorator_Abstract
*/
public function setOptions(array $options)
{
$this->_options = $options;
return $this;
}
/**
* Set options from config object
*
* @param Zend_Config $config
* @return Zend_Form_Decorator_Abstract
*/
public function setConfig(Zend_Config $config)
{
return $this->setOptions($config->toArray());
}
/**
* Set option
*
* @param string $key
* @param mixed $value
* @return Zend_Form_Decorator_Abstract
*/
public function setOption($key, $value)
{
$this->_options[(string) $key] = $value;
return $this;
}
/**
* Get option
*
* @param string $key
* @return mixed
*/
public function getOption($key)
{
$key = (string) $key;
if (isset($this->_options[$key])) {
return $this->_options[$key];
}
return null;
}
/**
* Retrieve options
*
* @return array
*/
public function getOptions()
{
return $this->_options;
}
/**
* Remove single option
*
* @param mixed $key
* @return void
*/
public function removeOption($key)
{
if (null !== $this->getOption($key)) {
unset($this->_options[$key]);
return true;
}
return false;
}
/**
* Clear all options
*
* @return Zend_Form_Decorator_Abstract
*/
public function clearOptions()
{
$this->_options = array();
return $this;
}
/**
* Set current form element
*
* @param Zend_Form_Element|Zend_Form $element
* @return Zend_Form_Decorator_Abstract
* @throws Zend_Form_Decorator_Exception on invalid element type
*/
public function setElement($element)
{
if ((!$element instanceof Zend_Form_Element)
&& (!$element instanceof Zend_Form)
&& (!$element instanceof Zend_Form_DisplayGroup))
{
require_once 'Zend/Form/Decorator/Exception.php';
throw new Zend_Form_Decorator_Exception('Invalid element type passed to decorator');
}
$this->_element = $element;
return $this;
}
/**
* Retrieve current element
*
* @return Zend_Form_Element|Zend_Form
*/
public function getElement()
{
return $this->_element;
}
/**
* Determine if decorator should append or prepend content
*
* @return string
*/
public function getPlacement()
{
$placement = $this->_placement;
if (null !== ($placementOpt = $this->getOption('placement'))) {
$placementOpt = strtoupper($placementOpt);
switch ($placementOpt) {
case self::APPEND:
case self::PREPEND:
$placement = $this->_placement = $placementOpt;
break;
case false:
$placement = $this->_placement = null;
break;
default:
break;
}
$this->removeOption('placement');
}
return $placement;
}
/**
* Retrieve separator to use between old and new content
*
* @return string
*/
public function getSeparator()
{
$separator = $this->_separator;
if (null !== ($separatorOpt = $this->getOption('separator'))) {
$separator = $this->_separator = (string) $separatorOpt;
$this->removeOption('separator');
}
return $separator;
}
/**
* Decorate content and/or element
*
* @param string $content
* @return string
* @throws Zend_Form_Decorator_Exception when unimplemented
*/
public function render($content)
{
require_once 'Zend/Form/Decorator/Exception.php';
throw new Zend_Form_Decorator_Exception('render() not implemented');
}
}

View file

@ -0,0 +1,128 @@
<?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_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Decorator_Abstract */
require_once 'Zend/Form/Decorator/Abstract.php';
/**
* Zend_Form_Decorator_Callback
*
* Execute an arbitrary callback to decorate an element. Callbacks should take
* three arguments, $content, $element, and $options:
*
* function mycallback($content, $element, array $options)
* {
* }
*
* and should return a string. ($options are whatever options were provided to
* the decorator.)
*
* To specify a callback, pass a valid callback as the 'callback' option.
*
* Callback results will be either appended, prepended, or replace the provided
* content. To replace the content, specify a placement of boolean false;
* defaults to append content.
*
* @category Zend
* @package Zend_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Callback.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
class Zend_Form_Decorator_Callback extends Zend_Form_Decorator_Abstract
{
/**
* Callback
* @var string|array
*/
protected $_callback;
/**
* Set callback
*
* @param callback $callback
* @return Zend_Form_Decorator_Callback
* @throws Zend_Form_Exception
*/
public function setCallback($callback)
{
if (!is_callable($callback)) {
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception('Invalid callback provided to callback decorator');
}
$this->_callback = $callback;
return $this;
}
/**
* Get registered callback
*
* If not previously registered, checks to see if it exists in registered
* options.
*
* @return null|string|array
*/
public function getCallback()
{
if (null === $this->_callback) {
if (null !== ($callback = $this->getOption('callback'))) {
$this->setCallback($callback);
$this->removeOption('callback');
}
}
return $this->_callback;
}
/**
* Render
*
* If no callback registered, returns callback. Otherwise, gets return
* value of callback and either appends, prepends, or replaces passed in
* content.
*
* @param string $content
* @return string
*/
public function render($content)
{
$callback = $this->getCallback();
if (null === $callback) {
return $content;
}
$placement = $this->getPlacement();
$separator = $this->getSeparator();
$response = call_user_func($callback, $content, $this->getElement(), $this->getOptions());
switch ($placement) {
case self::APPEND:
return $content . $separator . $response;
case self::PREPEND:
return $response . $separator . $content;
default:
// replace content
return $response;
}
}
}

View file

@ -0,0 +1,72 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** @see Zend_Form_Decorator_Abstract */
require_once 'Zend/Form/Decorator/Abstract.php';
/**
* Captcha generic decorator
*
* Adds captcha adapter output
*
* @category Zend
* @package Zend_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Captcha.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
class Zend_Form_Decorator_Captcha extends Zend_Form_Decorator_Abstract
{
/**
* Render captcha
*
* @param string $content
* @return string
*/
public function render($content)
{
$element = $this->getElement();
if (!method_exists($element, 'getCaptcha')) {
return $content;
}
$view = $element->getView();
if (null === $view) {
return $content;
}
$placement = $this->getPlacement();
$separator = $this->getSeparator();
$captcha = $element->getCaptcha();
$markup = $captcha->render($view, $element);
switch ($placement) {
case 'PREPEND':
$content = $markup . $separator . $content;
break;
case 'APPEND':
default:
$content = $content . $separator . $markup;
}
return $content;
}
}

View file

@ -0,0 +1,78 @@
<?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_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** @see Zend_Form_Decorator_Abstract */
require_once 'Zend/Form/Decorator/Abstract.php';
/**
* Word-based captcha decorator
*
* Adds hidden field for ID and text input field for captcha text
*
* @category Zend
* @package Zend_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Word.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
class Zend_Form_Decorator_Captcha_Word extends Zend_Form_Decorator_Abstract
{
/**
* Render captcha
*
* @param string $content
* @return string
*/
public function render($content)
{
$element = $this->getElement();
$view = $element->getView();
if (null === $view) {
return $content;
}
$name = $element->getFullyQualifiedName();
$hiddenName = $name . '[id]';
$textName = $name . '[input]';
$label = $element->getDecorator("Label");
if($label) {
$label->setOption("id", $element->getId()."-input");
}
$placement = $this->getPlacement();
$separator = $this->getSeparator();
$hidden = $view->formHidden($hiddenName, $element->getValue(), $element->getAttribs());
$text = $view->formText($textName, '', $element->getAttribs());
switch ($placement) {
case 'PREPEND':
$content = $hidden . $separator . $text . $separator . $content;
break;
case 'APPEND':
default:
$content = $content . $separator . $hidden . $separator . $text;
}
return $content;
}
}

View file

@ -0,0 +1,199 @@
<?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_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Decorator_Abstract */
require_once 'Zend/Form/Decorator/Abstract.php';
/**
* Zend_Form_Decorator_Description
*
* Accepts the options:
* - separator: separator to use between label and content (defaults to PHP_EOL)
* - placement: whether to append or prepend label to content (defaults to prepend)
* - tag: if set, used to wrap the label in an additional HTML tag
* - class: if set, override default class used with HTML tag
* - escape: whether or not to escape description (true by default)
*
* Any other options passed will be used as HTML attributes of the HTML tag used.
*
* @category Zend
* @package Zend_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Description.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
class Zend_Form_Decorator_Description extends Zend_Form_Decorator_Abstract
{
/**
* Whether or not to escape the description
* @var bool
*/
protected $_escape;
/**
* Default placement: append
* @var string
*/
protected $_placement = 'APPEND';
/**
* HTML tag with which to surround description
* @var string
*/
protected $_tag;
/**
* Set HTML tag with which to surround description
*
* @param string $tag
* @return Zend_Form_Decorator_Description
*/
public function setTag($tag)
{
$this->_tag = (string) $tag;
return $this;
}
/**
* Get HTML tag, if any, with which to surround description
*
* @return string
*/
public function getTag()
{
if (null === $this->_tag) {
$tag = $this->getOption('tag');
if (null !== $tag) {
$this->removeOption('tag');
} else {
$tag = 'p';
}
$this->setTag($tag);
return $tag;
}
return $this->_tag;
}
/**
* Get class with which to define description
*
* Defaults to 'hint'
*
* @return string
*/
public function getClass()
{
$class = $this->getOption('class');
if (null === $class) {
$class = 'hint';
$this->setOption('class', $class);
}
return $class;
}
/**
* Set whether or not to escape description
*
* @param bool $flag
* @return Zend_Form_Decorator_Description
*/
public function setEscape($flag)
{
$this->_escape = (bool) $flag;
return $this;
}
/**
* Get escape flag
*
* @return true
*/
public function getEscape()
{
if (null === $this->_escape) {
if (null !== ($escape = $this->getOption('escape'))) {
$this->setEscape($escape);
$this->removeOption('escape');
} else {
$this->setEscape(true);
}
}
return $this->_escape;
}
/**
* Render a description
*
* @param string $content
* @return string
*/
public function render($content)
{
$element = $this->getElement();
$view = $element->getView();
if (null === $view) {
return $content;
}
$description = $element->getDescription();
$description = trim($description);
if (!empty($description) && (null !== ($translator = $element->getTranslator()))) {
$description = $translator->translate($description);
}
if (empty($description)) {
return $content;
}
$separator = $this->getSeparator();
$placement = $this->getPlacement();
$tag = $this->getTag();
$class = $this->getClass();
$escape = $this->getEscape();
$options = $this->getOptions();
if ($escape) {
$description = $view->escape($description);
}
if (!empty($tag)) {
require_once 'Zend/Form/Decorator/HtmlTag.php';
$options['tag'] = $tag;
$decorator = new Zend_Form_Decorator_HtmlTag($options);
$description = $decorator->render($description);
}
switch ($placement) {
case self::PREPEND:
return $description . $separator . $content;
case self::APPEND:
default:
return $content . $separator . $description;
}
}
}

View file

@ -0,0 +1,63 @@
<?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_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Decorator_Abstract */
require_once 'Zend/Form/Decorator/Abstract.php';
/**
* Zend_Form_Decorator_DtDdWrapper
*
* Creates an empty <dt> item, and wraps the content in a <dd>. Used as a
* default decorator for subforms and display groups.
*
* @category Zend
* @package Zend_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: DtDdWrapper.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
class Zend_Form_Decorator_DtDdWrapper extends Zend_Form_Decorator_Abstract
{
/**
* Default placement: surround content
* @var string
*/
protected $_placement = null;
/**
* Render
*
* Renders as the following:
* <dt></dt>
* <dd>$content</dd>
*
* @param string $content
* @return string
*/
public function render($content)
{
$elementName = $this->getElement()->getName();
return '<dt id="' . $elementName . '-label">&nbsp;</dt>' .
'<dd id="' . $elementName . '-element">' . $content . '</dd>';
}
}

View file

@ -0,0 +1,69 @@
<?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_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Decorator_Abstract */
require_once 'Zend/Form/Decorator/Abstract.php';
/**
* Zend_Form_Decorator_Errors
*
* Any options passed will be used as HTML attributes of the ul tag for the errors.
*
* @category Zend
* @package Zend_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Errors.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
class Zend_Form_Decorator_Errors extends Zend_Form_Decorator_Abstract
{
/**
* Render errors
*
* @param string $content
* @return string
*/
public function render($content)
{
$element = $this->getElement();
$view = $element->getView();
if (null === $view) {
return $content;
}
$errors = $element->getMessages();
if (empty($errors)) {
return $content;
}
$separator = $this->getSeparator();
$placement = $this->getPlacement();
$errors = $view->formErrors($errors, $this->getOptions());
switch ($placement) {
case self::APPEND:
return $content . $separator . $errors;
case self::PREPEND:
return $errors . $separator . $content;
}
}
}

View file

@ -0,0 +1,37 @@
<?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_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Exception */
require_once 'Zend/Form/Exception.php';
/**
* Exception for Zend_Form component.
*
* @category Zend
* @package Zend_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Form_Decorator_Exception extends Zend_Form_Exception
{
}

View file

@ -0,0 +1,155 @@
<?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_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Decorator_Abstract */
require_once 'Zend/Form/Decorator/Abstract.php';
/**
* Zend_Form_Decorator_Fieldset
*
* Any options passed will be used as HTML attributes of the fieldset tag.
*
* @category Zend
* @package Zend_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Fieldset.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
class Zend_Form_Decorator_Fieldset extends Zend_Form_Decorator_Abstract
{
/**
* Attribs that should be removed prior to rendering
* @var array
*/
public $stripAttribs = array(
'action',
'enctype',
'helper',
'method',
'name',
);
/**
* Fieldset legend
* @var string
*/
protected $_legend;
/**
* Default placement: surround content
* @var string
*/
protected $_placement = null;
/**
* Get options
*
* Merges in element attributes as well.
*
* @return array
*/
public function getOptions()
{
$options = parent::getOptions();
if (null !== ($element = $this->getElement())) {
$attribs = $element->getAttribs();
$options = array_merge($options, $attribs);
$this->setOptions($options);
}
return $options;
}
/**
* Set legend
*
* @param string $value
* @return Zend_Form_Decorator_Fieldset
*/
public function setLegend($value)
{
$this->_legend = (string) $value;
return $this;
}
/**
* Get legend
*
* @return string
*/
public function getLegend()
{
$legend = $this->_legend;
if ((null === $legend) && (null !== ($element = $this->getElement()))) {
if (method_exists($element, 'getLegend')) {
$legend = $element->getLegend();
$this->setLegend($legend);
}
}
if ((null === $legend) && (null !== ($legend = $this->getOption('legend')))) {
$this->setLegend($legend);
$this->removeOption('legend');
}
return $legend;
}
/**
* Render a fieldset
*
* @param string $content
* @return string
*/
public function render($content)
{
$element = $this->getElement();
$view = $element->getView();
if (null === $view) {
return $content;
}
$legend = $this->getLegend();
$attribs = $this->getOptions();
$name = $element->getFullyQualifiedName();
$id = $element->getId();
if (!empty($id)) {
$attribs['id'] = 'fieldset-' . $id;
}
if (null !== $legend) {
if (null !== ($translator = $element->getTranslator())) {
$legend = $translator->translate($legend);
}
$attribs['legend'] = $legend;
}
foreach (array_keys($attribs) as $attrib) {
$testAttrib = strtolower($attrib);
if (in_array($testAttrib, $this->stripAttribs)) {
unset($attribs[$attrib]);
}
}
return $view->fieldset($name, $content, $attribs);
}
}

View file

@ -0,0 +1,142 @@
<?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_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Decorator_Abstract */
require_once 'Zend/Form/Decorator/Abstract.php';
/** Zend_Form_Decorator_Marker_File_Interface */
require_once 'Zend/Form/Decorator/Marker/File/Interface.php';
/** Zend_File_Transfer_Adapter_Http */
require_once 'Zend/File/Transfer/Adapter/Http.php';
/**
* Zend_Form_Decorator_File
*
* Fixes the rendering for all subform and multi file elements
*
* @category Zend
* @package Zend_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: File.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
class Zend_Form_Decorator_File
extends Zend_Form_Decorator_Abstract
implements Zend_Form_Decorator_Marker_File_Interface
{
/**
* Attributes that should not be passed to helper
* @var array
*/
protected $_attribBlacklist = array('helper', 'placement', 'separator', 'value');
/**
* Default placement: append
* @var string
*/
protected $_placement = 'APPEND';
/**
* Get attributes to pass to file helper
*
* @return array
*/
public function getAttribs()
{
$attribs = $this->getOptions();
if (null !== ($element = $this->getElement())) {
$attribs = array_merge($attribs, $element->getAttribs());
}
foreach ($this->_attribBlacklist as $key) {
if (array_key_exists($key, $attribs)) {
unset($attribs[$key]);
}
}
return $attribs;
}
/**
* Render a form file
*
* @param string $content
* @return string
*/
public function render($content)
{
$element = $this->getElement();
if (!$element instanceof Zend_Form_Element) {
return $content;
}
$view = $element->getView();
if (!$view instanceof Zend_View_Interface) {
return $content;
}
$name = $element->getName();
$attribs = $this->getAttribs();
if (!array_key_exists('id', $attribs)) {
$attribs['id'] = $name;
}
$separator = $this->getSeparator();
$placement = $this->getPlacement();
$markup = array();
$size = $element->getMaxFileSize();
if ($size > 0) {
$element->setMaxFileSize(0);
$markup[] = $view->formHidden('MAX_FILE_SIZE', $size);
}
if (Zend_File_Transfer_Adapter_Http::isApcAvailable()) {
$markup[] = $view->formHidden(ini_get('apc.rfc1867_name'), uniqid(), array('id' => 'progress_key'));
} else if (Zend_File_Transfer_Adapter_Http::isUploadProgressAvailable()) {
$markup[] = $view->formHidden('UPLOAD_IDENTIFIER', uniqid(), array('id' => 'progress_key'));
}
if ($element->isArray()) {
$name .= "[]";
$count = $element->getMultiFile();
for ($i = 0; $i < $count; ++$i) {
$htmlAttribs = $attribs;
$htmlAttribs['id'] .= '-' . $i;
$markup[] = $view->formFile($name, $htmlAttribs);
}
} else {
$markup[] = $view->formFile($name, $attribs);
}
$markup = implode($separator, $markup);
switch ($placement) {
case self::PREPEND:
return $markup . $separator . $content;
case self::APPEND:
default:
return $content . $separator . $markup;
}
}
}

View file

@ -0,0 +1,134 @@
<?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_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Decorator_Abstract */
require_once 'Zend/Form/Decorator/Abstract.php';
/**
* Zend_Form_Decorator_Form
*
* Render a Zend_Form object.
*
* Accepts following options:
* - separator: Separator to use between elements
* - helper: which view helper to use when rendering form. Should accept three
* arguments, string content, a name, and an array of attributes.
*
* Any other options passed will be used as HTML attributes of the form tag.
*
* @category Zend
* @package Zend_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Form.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
class Zend_Form_Decorator_Form extends Zend_Form_Decorator_Abstract
{
/**
* Default view helper
* @var string
*/
protected $_helper = 'form';
/**
* Set view helper for rendering form
*
* @param string $helper
* @return Zend_Form_Decorator_Form
*/
public function setHelper($helper)
{
$this->_helper = (string) $helper;
return $this;
}
/**
* Get view helper for rendering form
*
* @return string
*/
public function getHelper()
{
if (null !== ($helper = $this->getOption('helper'))) {
$this->setHelper($helper);
$this->removeOption('helper');
}
return $this->_helper;
}
/**
* Retrieve decorator options
*
* Assures that form action and method are set, and sets appropriate
* encoding type if current method is POST.
*
* @return array
*/
public function getOptions()
{
if (null !== ($element = $this->getElement())) {
if ($element instanceof Zend_Form) {
$element->getAction();
$method = $element->getMethod();
if ($method == Zend_Form::METHOD_POST) {
$this->setOption('enctype', 'application/x-www-form-urlencoded');
}
foreach ($element->getAttribs() as $key => $value) {
$this->setOption($key, $value);
}
} elseif ($element instanceof Zend_Form_DisplayGroup) {
foreach ($element->getAttribs() as $key => $value) {
$this->setOption($key, $value);
}
}
}
if (isset($this->_options['method'])) {
$this->_options['method'] = strtolower($this->_options['method']);
}
return $this->_options;
}
/**
* Render a form
*
* Replaces $content entirely from currently set element.
*
* @param string $content
* @return string
*/
public function render($content)
{
$form = $this->getElement();
$view = $form->getView();
if (null === $view) {
return $content;
}
$helper = $this->getHelper();
$attribs = $this->getOptions();
$name = $form->getFullyQualifiedName();
$attribs['id'] = $form->getId();
return $view->$helper($name, $attribs, $content);
}
}

View file

@ -0,0 +1,126 @@
<?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_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Decorator_Abstract */
require_once 'Zend/Form/Decorator/Abstract.php';
/**
* Zend_Form_Decorator_FormElements
*
* Render all form elements registered with current form
*
* Accepts following options:
* - separator: Separator to use between elements
*
* Any other options passed will be used as HTML attributes of the form tag.
*
* @category Zend
* @package Zend_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: FormElements.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
class Zend_Form_Decorator_FormElements extends Zend_Form_Decorator_Abstract
{
/**
* Merges given two belongsTo (array notation) strings
*
* @param string $baseBelongsTo
* @param string $belongsTo
* @return string
*/
public function mergeBelongsTo($baseBelongsTo, $belongsTo)
{
$endOfArrayName = strpos($belongsTo, '[');
if ($endOfArrayName === false) {
return $baseBelongsTo . '[' . $belongsTo . ']';
}
$arrayName = substr($belongsTo, 0, $endOfArrayName);
return $baseBelongsTo . '[' . $arrayName . ']' . substr($belongsTo, $endOfArrayName);
}
/**
* Render form elements
*
* @param string $content
* @return string
*/
public function render($content)
{
$form = $this->getElement();
if ((!$form instanceof Zend_Form) && (!$form instanceof Zend_Form_DisplayGroup)) {
return $content;
}
$belongsTo = ($form instanceof Zend_Form) ? $form->getElementsBelongTo() : null;
$elementContent = '';
$separator = $this->getSeparator();
$translator = $form->getTranslator();
$items = array();
$view = $form->getView();
foreach ($form as $item) {
$item->setView($view)
->setTranslator($translator);
if ($item instanceof Zend_Form_Element) {
$item->setBelongsTo($belongsTo);
} elseif (!empty($belongsTo) && ($item instanceof Zend_Form)) {
if ($item->isArray()) {
$name = $this->mergeBelongsTo($belongsTo, $item->getElementsBelongTo());
$item->setElementsBelongTo($name, true);
} else {
$item->setElementsBelongTo($belongsTo, true);
}
} elseif (!empty($belongsTo) && ($item instanceof Zend_Form_DisplayGroup)) {
foreach ($item as $element) {
$element->setBelongsTo($belongsTo);
}
}
$items[] = $item->render();
if (($item instanceof Zend_Form_Element_File)
|| (($item instanceof Zend_Form)
&& (Zend_Form::ENCTYPE_MULTIPART == $item->getEnctype()))
|| (($item instanceof Zend_Form_DisplayGroup)
&& (Zend_Form::ENCTYPE_MULTIPART == $item->getAttrib('enctype')))
) {
if ($form instanceof Zend_Form) {
$form->setEnctype(Zend_Form::ENCTYPE_MULTIPART);
} elseif ($form instanceof Zend_Form_DisplayGroup) {
$form->setAttrib('enctype', Zend_Form::ENCTYPE_MULTIPART);
}
}
}
$elementContent = implode($separator, $items);
switch ($this->getPlacement()) {
case self::PREPEND:
return $elementContent . $separator . $content;
case self::APPEND:
default:
return $content . $separator . $elementContent;
}
}
}

View file

@ -0,0 +1,397 @@
<?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_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Decorator_Abstract */
require_once 'Zend/Form/Decorator/Abstract.php';
/**
* Zend_Form_Decorator_FormErrors
*
* Displays all form errors in one view.
*
* Any options passed will be used as HTML attributes of the ul tag for the errors.
*
* @category Zend
* @package Zend_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: FormErrors.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
class Zend_Form_Decorator_FormErrors extends Zend_Form_Decorator_Abstract
{
/**
* Default values for markup options
* @var array
*/
protected $_defaults = array(
'ignoreSubForms' => false,
'markupElementLabelEnd' => '</b>',
'markupElementLabelStart' => '<b>',
'markupListEnd' => '</ul>',
'markupListItemEnd' => '</li>',
'markupListItemStart' => '<li>',
'markupListStart' => '<ul class="form-errors">',
);
/**#@+
* Markup options
* @var string
*/
protected $_ignoreSubForms;
protected $_markupElementLabelEnd;
protected $_markupElementLabelStart;
protected $_markupListEnd;
protected $_markupListItemEnd;
protected $_markupListItemStart;
protected $_markupListStart;
/**#@-*/
/**
* Render errors
*
* @param string $content
* @return string
*/
public function render($content)
{
$form = $this->getElement();
if (!$form instanceof Zend_Form) {
return $content;
}
$view = $form->getView();
if (null === $view) {
return $content;
}
$this->initOptions();
$markup = $this->_recurseForm($form, $view);
if (empty($markup)) {
return $content;
}
$markup = $this->getMarkupListStart()
. $markup
. $this->getMarkupListEnd();
switch ($this->getPlacement()) {
case self::APPEND:
return $content . $this->getSeparator() . $markup;
case self::PREPEND:
return $markup . $this->getSeparator() . $content;
}
}
/**
* Initialize options
*
* @return void
*/
public function initOptions()
{
$this->getMarkupElementLabelEnd();
$this->getMarkupElementLabelStart();
$this->getMarkupListEnd();
$this->getMarkupListItemEnd();
$this->getMarkupListItemStart();
$this->getMarkupListStart();
$this->getPlacement();
$this->getSeparator();
$this->ignoreSubForms();
}
/**
* Retrieve markupElementLabelStart
*
* @return string
*/
public function getMarkupElementLabelStart()
{
if (null === $this->_markupElementLabelStart) {
if (null === ($markupElementLabelStart = $this->getOption('markupElementLabelStart'))) {
$this->setMarkupElementLabelStart($this->_defaults['markupElementLabelStart']);
} else {
$this->setMarkupElementLabelStart($markupElementLabelStart);
$this->removeOption('markupElementLabelStart');
}
}
return $this->_markupElementLabelStart;
}
/**
* Set markupElementLabelStart
*
* @param string $markupElementLabelStart
* @return Zend_Form_Decorator_FormErrors
*/
public function setMarkupElementLabelStart($markupElementLabelStart)
{
$this->_markupElementLabelStart = $markupElementLabelStart;
return $this;
}
/**
* Retrieve markupElementLabelEnd
*
* @return string
*/
public function getMarkupElementLabelEnd()
{
if (null === $this->_markupElementLabelEnd) {
if (null === ($markupElementLabelEnd = $this->getOption('markupElementLabelEnd'))) {
$this->setMarkupElementLabelEnd($this->_defaults['markupElementLabelEnd']);
} else {
$this->setMarkupElementLabelEnd($markupElementLabelEnd);
$this->removeOption('markupElementLabelEnd');
}
}
return $this->_markupElementLabelEnd;
}
/**
* Set markupElementLabelEnd
*
* @param string $markupElementLabelEnd
* @return Zend_Form_Decorator_FormErrors
*/
public function setMarkupElementLabelEnd($markupElementLabelEnd)
{
$this->_markupElementLabelEnd = $markupElementLabelEnd;
return $this;
}
/**
* Retrieve markupListStart
*
* @return string
*/
public function getMarkupListStart()
{
if (null === $this->_markupListStart) {
if (null === ($markupListStart = $this->getOption('markupListStart'))) {
$this->setMarkupListStart($this->_defaults['markupListStart']);
} else {
$this->setMarkupListStart($markupListStart);
$this->removeOption('markupListStart');
}
}
return $this->_markupListStart;
}
/**
* Set markupListStart
*
* @param string $markupListStart
* @return Zend_Form_Decorator_FormErrors
*/
public function setMarkupListStart($markupListStart)
{
$this->_markupListStart = $markupListStart;
return $this;
}
/**
* Retrieve markupListEnd
*
* @return string
*/
public function getMarkupListEnd()
{
if (null === $this->_markupListEnd) {
if (null === ($markupListEnd = $this->getOption('markupListEnd'))) {
$this->setMarkupListEnd($this->_defaults['markupListEnd']);
} else {
$this->setMarkupListEnd($markupListEnd);
$this->removeOption('markupListEnd');
}
}
return $this->_markupListEnd;
}
/**
* Set markupListEnd
*
* @param string $markupListEnd
* @return Zend_Form_Decorator_FormErrors
*/
public function setMarkupListEnd($markupListEnd)
{
$this->_markupListEnd = $markupListEnd;
return $this;
}
/**
* Retrieve markupListItemStart
*
* @return string
*/
public function getMarkupListItemStart()
{
if (null === $this->_markupListItemStart) {
if (null === ($markupListItemStart = $this->getOption('markupListItemStart'))) {
$this->setMarkupListItemStart($this->_defaults['markupListItemStart']);
} else {
$this->setMarkupListItemStart($markupListItemStart);
$this->removeOption('markupListItemStart');
}
}
return $this->_markupListItemStart;
}
/**
* Set markupListItemStart
*
* @param string $markupListItemStart
* @return Zend_Form_Decorator_FormErrors
*/
public function setMarkupListItemStart($markupListItemStart)
{
$this->_markupListItemStart = $markupListItemStart;
return $this;
}
/**
* Retrieve markupListItemEnd
*
* @return string
*/
public function getMarkupListItemEnd()
{
if (null === $this->_markupListItemEnd) {
if (null === ($markupListItemEnd = $this->getOption('markupListItemEnd'))) {
$this->setMarkupListItemEnd($this->_defaults['markupListItemEnd']);
} else {
$this->setMarkupListItemEnd($markupListItemEnd);
$this->removeOption('markupListItemEnd');
}
}
return $this->_markupListItemEnd;
}
/**
* Set markupListItemEnd
*
* @param string $markupListItemEnd
* @return Zend_Form_Decorator_FormErrors
*/
public function setMarkupListItemEnd($markupListItemEnd)
{
$this->_markupListItemEnd = $markupListItemEnd;
return $this;
}
/**
* Retrieve ignoreSubForms
*
* @return bool
*/
public function ignoreSubForms()
{
if (null === $this->_ignoreSubForms) {
if (null === ($ignoreSubForms = $this->getOption('ignoreSubForms'))) {
$this->setIgnoreSubForms($this->_defaults['ignoreSubForms']);
} else {
$this->setIgnoreSubForms($ignoreSubForms);
$this->removeOption('ignoreSubForms');
}
}
return $this->_ignoreSubForms;
}
/**
* Set ignoreSubForms
*
* @param bool $ignoreSubForms
* @return Zend_Form_Decorator_FormErrors
*/
public function setIgnoreSubForms($ignoreSubForms)
{
$this->_ignoreSubForms = (bool) $ignoreSubForms;
return $this;
}
/**
* Render element label
*
* @param Zend_Form_Element $element
* @param Zend_View_Interface $view
* @return string
*/
public function renderLabel(Zend_Form_Element $element, Zend_View_Interface $view)
{
$label = $element->getLabel();
if (empty($label)) {
$label = $element->getName();
}
return $this->getMarkupElementLabelStart()
. $view->escape($label)
. $this->getMarkupElementLabelEnd();
}
/**
* Recurse through a form object, rendering errors
*
* @param Zend_Form $form
* @param Zend_View_Interface $view
* @return string
*/
protected function _recurseForm(Zend_Form $form, Zend_View_Interface $view)
{
$content = '';
$errors = $form->getMessages();
if ($form instanceof Zend_Form_SubForm) {
$name = $form->getName();
if ((1 == count($errors)) && array_key_exists($name, $errors)) {
$errors = $errors[$name];
}
}
if (empty($errors)) {
return $content;
}
foreach ($errors as $name => $list) {
$element = $form->$name;
if ($element instanceof Zend_Form_Element) {
$element->setView($view);
$content .= $this->getMarkupListItemStart()
. $this->renderLabel($element, $view)
. $view->formErrors($list, $this->getOptions())
. $this->getMarkupListItemEnd();
} elseif (!$this->ignoreSubForms() && ($element instanceof Zend_Form)) {
$content .= $this->getMarkupListStart()
. $this->_recurseForm($element, $view)
. $this->getMarkupListEnd();
}
}
return $content;
}
}

View file

@ -0,0 +1,251 @@
<?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_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* @see Zend_Form_Decorator_Abstract
*/
require_once 'Zend/Form/Decorator/Abstract.php';
/**
* Zend_Form_Decorator_Element_HtmlTag
*
* Wraps content in an HTML block tag.
*
* Options accepted are:
* - tag: tag to use in decorator
* - noAttribs: do not render attributes in the opening tag
* - placement: 'append' or 'prepend'. If 'append', renders opening and
* closing tag after content; if prepend, renders opening and closing tag
* before content.
* - openOnly: render opening tag only
* - closeOnly: render closing tag only
*
* Any other options passed are processed as HTML attributes of the tag.
*
* @category Zend
* @package Zend_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: HtmlTag.php 20104 2010-01-06 21:26:01Z matthew $
*/
class Zend_Form_Decorator_HtmlTag extends Zend_Form_Decorator_Abstract
{
/**
* Character encoding to use when escaping attributes
* @var string
*/
protected $_encoding;
/**
* Placement; default to surround content
* @var string
*/
protected $_placement = null;
/**
* HTML tag to use
* @var string
*/
protected $_tag;
/**
* @var Zend_Filter
*/
protected $_tagFilter;
/**
* Convert options to tag attributes
*
* @return string
*/
protected function _htmlAttribs(array $attribs)
{
$xhtml = '';
$enc = $this->_getEncoding();
foreach ((array) $attribs as $key => $val) {
$key = htmlspecialchars($key, ENT_COMPAT, $enc);
if (is_array($val)) {
$val = implode(' ', $val);
}
$val = htmlspecialchars($val, ENT_COMPAT, $enc);
$xhtml .= " $key=\"$val\"";
}
return $xhtml;
}
/**
* Normalize tag
*
* Ensures tag is alphanumeric characters only, and all lowercase.
*
* @param string $tag
* @return string
*/
public function normalizeTag($tag)
{
if (!isset($this->_tagFilter)) {
require_once 'Zend/Filter.php';
require_once 'Zend/Filter/Alnum.php';
require_once 'Zend/Filter/StringToLower.php';
$this->_tagFilter = new Zend_Filter();
$this->_tagFilter->addFilter(new Zend_Filter_Alnum())
->addFilter(new Zend_Filter_StringToLower());
}
return $this->_tagFilter->filter($tag);
}
/**
* Set tag to use
*
* @param string $tag
* @return Zend_Form_Decorator_HtmlTag
*/
public function setTag($tag)
{
$this->_tag = $this->normalizeTag($tag);
return $this;
}
/**
* Get tag
*
* If no tag is registered, either via setTag() or as an option, uses 'div'.
*
* @return string
*/
public function getTag()
{
if (null === $this->_tag) {
if (null === ($tag = $this->getOption('tag'))) {
$this->setTag('div');
} else {
$this->setTag($tag);
$this->removeOption('tag');
}
}
return $this->_tag;
}
/**
* Get the formatted open tag
*
* @param string $tag
* @param array $attribs
* @return string
*/
protected function _getOpenTag($tag, array $attribs = null)
{
$html = '<' . $tag;
if (null !== $attribs) {
$html .= $this->_htmlAttribs($attribs);
}
$html .= '>';
return $html;
}
/**
* Get formatted closing tag
*
* @param string $tag
* @return string
*/
protected function _getCloseTag($tag)
{
return '</' . $tag . '>';
}
/**
* Render content wrapped in an HTML tag
*
* @param string $content
* @return string
*/
public function render($content)
{
$tag = $this->getTag();
$placement = $this->getPlacement();
$noAttribs = $this->getOption('noAttribs');
$openOnly = $this->getOption('openOnly');
$closeOnly = $this->getOption('closeOnly');
$this->removeOption('noAttribs');
$this->removeOption('openOnly');
$this->removeOption('closeOnly');
$attribs = null;
if (!$noAttribs) {
$attribs = $this->getOptions();
}
switch ($placement) {
case self::APPEND:
if ($closeOnly) {
return $content . $this->_getCloseTag($tag);
}
if ($openOnly) {
return $content . $this->_getOpenTag($tag, $attribs);
}
return $content
. $this->_getOpenTag($tag, $attribs)
. $this->_getCloseTag($tag);
case self::PREPEND:
if ($closeOnly) {
return $this->_getCloseTag($tag) . $content;
}
if ($openOnly) {
return $this->_getOpenTag($tag, $attribs) . $content;
}
return $this->_getOpenTag($tag, $attribs)
. $this->_getCloseTag($tag)
. $content;
default:
return (($openOnly || !$closeOnly) ? $this->_getOpenTag($tag, $attribs) : '')
. $content
. (($closeOnly || !$openOnly) ? $this->_getCloseTag($tag) : '');
}
}
/**
* Get encoding for use with htmlspecialchars()
*
* @return string
*/
protected function _getEncoding()
{
if (null !== $this->_encoding) {
return $this->_encoding;
}
if (null === ($element = $this->getElement())) {
$this->_encoding = 'UTF-8';
} elseif (null === ($view = $element->getView())) {
$this->_encoding = 'UTF-8';
} elseif (!$view instanceof Zend_View_Abstract
&& !method_exists($view, 'getEncoding')
) {
$this->_encoding = 'UTF-8';
} else {
$this->_encoding = $view->getEncoding();
}
return $this->_encoding;
}
}

View file

@ -0,0 +1,154 @@
<?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_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Decorator_Abstract */
require_once 'Zend/Form/Decorator/Abstract.php';
/**
* Zend_Form_Decorator_Image
*
* Accepts the options:
* - separator: separator to use between image and content (defaults to PHP_EOL)
* - placement: whether to append or prepend label to content (defaults to append)
* - tag: if set, used to wrap the label in an additional HTML tag
*
* Any other options passed will be used as HTML attributes of the image tag.
*
* @category Zend
* @package Zend_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Image.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
class Zend_Form_Decorator_Image extends Zend_Form_Decorator_Abstract
{
/**
* Attributes that should not be passed to helper
* @var array
*/
protected $_attribBlacklist = array('helper', 'placement', 'separator', 'tag');
/**
* Default placement: append
* @var string
*/
protected $_placement = 'APPEND';
/**
* HTML tag with which to surround image
* @var string
*/
protected $_tag;
/**
* Set HTML tag with which to surround label
*
* @param string $tag
* @return Zend_Form_Decorator_Image
*/
public function setTag($tag)
{
$this->_tag = (string) $tag;
return $this;
}
/**
* Get HTML tag, if any, with which to surround label
*
* @return void
*/
public function getTag()
{
if (null === $this->_tag) {
$tag = $this->getOption('tag');
if (null !== $tag) {
$this->removeOption('tag');
$this->setTag($tag);
}
return $tag;
}
return $this->_tag;
}
/**
* Get attributes to pass to image helper
*
* @return array
*/
public function getAttribs()
{
$attribs = $this->getOptions();
if (null !== ($element = $this->getElement())) {
$attribs['alt'] = $element->getLabel();
$attribs = array_merge($attribs, $element->getAttribs());
}
foreach ($this->_attribBlacklist as $key) {
if (array_key_exists($key, $attribs)) {
unset($attribs[$key]);
}
}
return $attribs;
}
/**
* Render a form image
*
* @param string $content
* @return string
*/
public function render($content)
{
$element = $this->getElement();
$view = $element->getView();
if (null === $view) {
return $content;
}
$tag = $this->getTag();
$placement = $this->getPlacement();
$separator = $this->getSeparator();
$name = $element->getFullyQualifiedName();
$attribs = $this->getAttribs();
$attribs['id'] = $element->getId();
$image = $view->formImage($name, $element->getImageValue(), $attribs);
if (null !== $tag) {
require_once 'Zend/Form/Decorator/HtmlTag.php';
$decorator = new Zend_Form_Decorator_HtmlTag();
$decorator->setOptions(array('tag' => $tag));
$image = $decorator->render($image);
}
switch ($placement) {
case self::PREPEND:
return $image . $separator . $content;
case self::APPEND:
default:
return $content . $separator . $image;
}
}
}

View file

@ -0,0 +1,123 @@
<?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_Form
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_Form_Decorator_Interface
*
* @category Zend
* @package Zend_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
interface Zend_Form_Decorator_Interface
{
/**
* Constructor
*
* Accept options during initialization.
*
* @param array|Zend_Config $options
* @return void
*/
public function __construct($options = null);
/**
* Set an element to decorate
*
* While the name is "setElement", a form decorator could decorate either
* an element or a form object.
*
* @param mixed $element
* @return Zend_Form_Decorator_Interface
*/
public function setElement($element);
/**
* Retrieve current element
*
* @return mixed
*/
public function getElement();
/**
* Set decorator options from an array
*
* @param array $options
* @return Zend_Form_Decorator_Interface
*/
public function setOptions(array $options);
/**
* Set decorator options from a config object
*
* @param Zend_Config $config
* @return Zend_Form_Decorator_Interface
*/
public function setConfig(Zend_Config $config);
/**
* Set a single option
*
* @param string $key
* @param mixed $value
* @return Zend_Form_Decorator_Interface
*/
public function setOption($key, $value);
/**
* Retrieve a single option
*
* @param string $key
* @return mixed
*/
public function getOption($key);
/**
* Retrieve decorator options
*
* @return array
*/
public function getOptions();
/**
* Delete a single option
*
* @param string $key
* @return bool
*/
public function removeOption($key);
/**
* Clear all options
*
* @return Zend_Form_Decorator_Interface
*/
public function clearOptions();
/**
* Render the element
*
* @param string $content Content to decorate
* @return string
*/
public function render($content);
}

View file

@ -0,0 +1,332 @@
<?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_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Decorator_Abstract */
require_once 'Zend/Form/Decorator/Abstract.php';
/**
* Zend_Form_Decorator_Label
*
* Accepts the options:
* - separator: separator to use between label and content (defaults to PHP_EOL)
* - placement: whether to append or prepend label to content (defaults to prepend)
* - tag: if set, used to wrap the label in an additional HTML tag
* - opt(ional)Prefix: a prefix to the label to use when the element is optional
* - opt(iona)lSuffix: a suffix to the label to use when the element is optional
* - req(uired)Prefix: a prefix to the label to use when the element is required
* - req(uired)Suffix: a suffix to the label to use when the element is required
*
* Any other options passed will be used as HTML attributes of the label tag.
*
* @category Zend
* @package Zend_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Label.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
class Zend_Form_Decorator_Label extends Zend_Form_Decorator_Abstract
{
/**
* Default placement: prepend
* @var string
*/
protected $_placement = 'PREPEND';
/**
* HTML tag with which to surround label
* @var string
*/
protected $_tag;
/**
* Set element ID
*
* @param string $id
* @return Zend_Form_Decorator_Label
*/
public function setId($id)
{
$this->setOption('id', $id);
return $this;
}
/**
* Retrieve element ID (used in 'for' attribute)
*
* If none set in decorator, looks first for element 'id' attribute, and
* defaults to element name.
*
* @return string
*/
public function getId()
{
$id = $this->getOption('id');
if (null === $id) {
if (null !== ($element = $this->getElement())) {
$id = $element->getId();
$this->setId($id);
}
}
return $id;
}
/**
* Set HTML tag with which to surround label
*
* @param string $tag
* @return Zend_Form_Decorator_Label
*/
public function setTag($tag)
{
if (empty($tag)) {
$this->_tag = null;
} else {
$this->_tag = (string) $tag;
}
$this->removeOption('tag');
return $this;
}
/**
* Get HTML tag, if any, with which to surround label
*
* @return void
*/
public function getTag()
{
if (null === $this->_tag) {
$tag = $this->getOption('tag');
if (null !== $tag) {
$this->removeOption('tag');
$this->setTag($tag);
}
return $tag;
}
return $this->_tag;
}
/**
* Get class with which to define label
*
* Appends either 'optional' or 'required' to class, depending on whether
* or not the element is required.
*
* @return string
*/
public function getClass()
{
$class = '';
$element = $this->getElement();
$decoratorClass = $this->getOption('class');
if (!empty($decoratorClass)) {
$class .= ' ' . $decoratorClass;
}
$type = $element->isRequired() ? 'required' : 'optional';
if (!strstr($class, $type)) {
$class .= ' ' . $type;
$class = trim($class);
}
return $class;
}
/**
* Load an optional/required suffix/prefix key
*
* @param string $key
* @return void
*/
protected function _loadOptReqKey($key)
{
if (!isset($this->$key)) {
$value = $this->getOption($key);
$this->$key = (string) $value;
if (null !== $value) {
$this->removeOption($key);
}
}
}
/**
* Overloading
*
* Currently overloads:
*
* - getOpt(ional)Prefix()
* - getOpt(ional)Suffix()
* - getReq(uired)Prefix()
* - getReq(uired)Suffix()
* - setOpt(ional)Prefix()
* - setOpt(ional)Suffix()
* - setReq(uired)Prefix()
* - setReq(uired)Suffix()
*
* @param string $method
* @param array $args
* @return mixed
* @throws Zend_Form_Exception for unsupported methods
*/
public function __call($method, $args)
{
$tail = substr($method, -6);
$head = substr($method, 0, 3);
if (in_array($head, array('get', 'set'))
&& (('Prefix' == $tail) || ('Suffix' == $tail))
) {
$position = substr($method, -6);
$type = strtolower(substr($method, 3, 3));
switch ($type) {
case 'req':
$key = 'required' . $position;
break;
case 'opt':
$key = 'optional' . $position;
break;
default:
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception(sprintf('Invalid method "%s" called in Label decorator, and detected as type %s', $method, $type));
}
switch ($head) {
case 'set':
if (0 === count($args)) {
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception(sprintf('Method "%s" requires at least one argument; none provided', $method));
}
$value = array_shift($args);
$this->$key = $value;
return $this;
case 'get':
default:
if (null === ($element = $this->getElement())) {
$this->_loadOptReqKey($key);
} elseif (isset($element->$key)) {
$this->$key = (string) $element->$key;
} else {
$this->_loadOptReqKey($key);
}
return $this->$key;
}
}
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception(sprintf('Invalid method "%s" called in Label decorator', $method));
}
/**
* Get label to render
*
* @return void
*/
public function getLabel()
{
if (null === ($element = $this->getElement())) {
return '';
}
$label = $element->getLabel();
$label = trim($label);
if (empty($label)) {
return '';
}
if (null !== ($translator = $element->getTranslator())) {
$label = $translator->translate($label);
}
$optPrefix = $this->getOptPrefix();
$optSuffix = $this->getOptSuffix();
$reqPrefix = $this->getReqPrefix();
$reqSuffix = $this->getReqSuffix();
$separator = $this->getSeparator();
if (!empty($label)) {
if ($element->isRequired()) {
$label = $reqPrefix . $label . $reqSuffix;
} else {
$label = $optPrefix . $label . $optSuffix;
}
}
return $label;
}
/**
* Render a label
*
* @param string $content
* @return string
*/
public function render($content)
{
$element = $this->getElement();
$view = $element->getView();
if (null === $view) {
return $content;
}
$label = $this->getLabel();
$separator = $this->getSeparator();
$placement = $this->getPlacement();
$tag = $this->getTag();
$id = $this->getId();
$class = $this->getClass();
$options = $this->getOptions();
if (empty($label) && empty($tag)) {
return $content;
}
if (!empty($label)) {
$options['class'] = $class;
$label = $view->formLabel($element->getFullyQualifiedName(), trim($label), $options);
} else {
$label = '&nbsp;';
}
if (null !== $tag) {
require_once 'Zend/Form/Decorator/HtmlTag.php';
$decorator = new Zend_Form_Decorator_HtmlTag();
$decorator->setOptions(array('tag' => $tag,
'id' => $this->getElement()->getName() . '-label'));
$label = $decorator->render($label);
}
switch ($placement) {
case self::APPEND:
return $content . $separator . $label;
case self::PREPEND:
return $label . $separator . $content;
}
}
}

View file

@ -0,0 +1,33 @@
<?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_Form
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_Form_Decorator_Marker_File_Interface
*
* @category Zend
* @package Zend_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
interface Zend_Form_Decorator_Marker_File_Interface
{
}

View file

@ -0,0 +1,90 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Decorator_FormElements */
require_once 'Zend/Form/Decorator/FormElements.php';
/**
* Zend_Form_Decorator_PrepareElements
*
* Render all form elements registered with current form
*
* Accepts following options:
* - separator: Separator to use between elements
*
* Any other options passed will be used as HTML attributes of the form tag.
*
* @category Zend
* @package Zend_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: PrepareElements.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
class Zend_Form_Decorator_PrepareElements extends Zend_Form_Decorator_FormElements
{
/**
* Render form elements
*
* @param string $content
* @return string
*/
public function render($content)
{
$form = $this->getElement();
if ((!$form instanceof Zend_Form) && (!$form instanceof Zend_Form_DisplayGroup)) {
return $content;
}
$this->_recursivelyPrepareForm($form);
return $content;
}
protected function _recursivelyPrepareForm(Zend_Form $form)
{
$belongsTo = ($form instanceof Zend_Form) ? $form->getElementsBelongTo() : null;
$elementContent = '';
$separator = $this->getSeparator();
$translator = $form->getTranslator();
$view = $form->getView();
foreach ($form as $item) {
$item->setView($view)
->setTranslator($translator);
if ($item instanceof Zend_Form_Element) {
$item->setBelongsTo($belongsTo);
} elseif (!empty($belongsTo) && ($item instanceof Zend_Form)) {
if ($item->isArray()) {
$name = $this->mergeBelongsTo($belongsTo, $item->getElementsBelongTo());
$item->setElementsBelongTo($name, true);
} else {
$item->setElementsBelongTo($belongsTo, true);
}
$this->_recursivelyPrepareForm($item);
} elseif (!empty($belongsTo) && ($item instanceof Zend_Form_DisplayGroup)) {
foreach ($item as $element) {
$element->setBelongsTo($belongsTo);
}
}
}
}
}

View file

@ -0,0 +1,58 @@
<?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_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Decorator_Abstract */
require_once 'Zend/Form/Decorator/Abstract.php';
/**
* Zend_Form_Decorator_Tooltip
*
* Will translate the title attribute, if available
*
* @category Zend
* @package Zend_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Tooltip.php$
*/
class Zend_Form_Decorator_Tooltip extends Zend_Form_Decorator_Abstract
{
/**
* Translates the title attribute if it is available, if the translator is available
* and if the translator is not disable on the element being rendered.
*
* @param string $content
* @return string
*/
public function render($content)
{
if (null !== ($title = $this->getElement()->getAttrib('title'))) {
if (null !== ($translator = $this->getElement()->getTranslator())) {
$title = $translator->translate($title);
}
}
$this->getElement()->setAttrib('title', $title);
return $content;
}
}

View file

@ -0,0 +1,256 @@
<?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_Form
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Decorator_Abstract */
require_once 'Zend/Form/Decorator/Abstract.php';
/**
* Zend_Form_Decorator_ViewHelper
*
* Decorate an element by using a view helper to render it.
*
* Accepts the following options:
* - separator: string with which to separate passed in content and generated content
* - placement: whether to append or prepend the generated content to the passed in content
* - helper: the name of the view helper to use
*
* Assumes the view helper accepts three parameters, the name, value, and
* optional attributes; these will be provided by the element.
*
* @category Zend
* @package Zend_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: ViewHelper.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
class Zend_Form_Decorator_ViewHelper extends Zend_Form_Decorator_Abstract
{
/**
* Element types that represent buttons
* @var array
*/
protected $_buttonTypes = array(
'Zend_Form_Element_Button',
'Zend_Form_Element_Reset',
'Zend_Form_Element_Submit',
);
/**
* View helper to use when rendering
* @var string
*/
protected $_helper;
/**
* Set view helper to use when rendering
*
* @param string $helper
* @return Zend_Form_Decorator_Element_ViewHelper
*/
public function setHelper($helper)
{
$this->_helper = (string) $helper;
return $this;
}
/**
* Retrieve view helper for rendering element
*
* @return string
*/
public function getHelper()
{
if (null === $this->_helper) {
$options = $this->getOptions();
if (isset($options['helper'])) {
$this->setHelper($options['helper']);
$this->removeOption('helper');
} else {
$element = $this->getElement();
if (null !== $element) {
if (null !== ($helper = $element->getAttrib('helper'))) {
$this->setHelper($helper);
} else {
$type = $element->getType();
if ($pos = strrpos($type, '_')) {
$type = substr($type, $pos + 1);
}
$this->setHelper('form' . ucfirst($type));
}
}
}
}
return $this->_helper;
}
/**
* Get name
*
* If element is a Zend_Form_Element, will attempt to namespace it if the
* element belongs to an array.
*
* @return string
*/
public function getName()
{
if (null === ($element = $this->getElement())) {
return '';
}
$name = $element->getName();
if (!$element instanceof Zend_Form_Element) {
return $name;
}
if (null !== ($belongsTo = $element->getBelongsTo())) {
$name = $belongsTo . '['
. $name
. ']';
}
if ($element->isArray()) {
$name .= '[]';
}
return $name;
}
/**
* Retrieve element attributes
*
* Set id to element name and/or array item.
*
* @return array
*/
public function getElementAttribs()
{
if (null === ($element = $this->getElement())) {
return null;
}
$attribs = $element->getAttribs();
if (isset($attribs['helper'])) {
unset($attribs['helper']);
}
if (method_exists($element, 'getSeparator')) {
if (null !== ($listsep = $element->getSeparator())) {
$attribs['listsep'] = $listsep;
}
}
if (isset($attribs['id'])) {
return $attribs;
}
$id = $element->getName();
if ($element instanceof Zend_Form_Element) {
if (null !== ($belongsTo = $element->getBelongsTo())) {
$belongsTo = preg_replace('/\[([^\]]+)\]/', '-$1', $belongsTo);
$id = $belongsTo . '-' . $id;
}
}
$element->setAttrib('id', $id);
$attribs['id'] = $id;
return $attribs;
}
/**
* Get value
*
* If element type is one of the button types, returns the label.
*
* @param Zend_Form_Element $element
* @return string|null
*/
public function getValue($element)
{
if (!$element instanceof Zend_Form_Element) {
return null;
}
foreach ($this->_buttonTypes as $type) {
if ($element instanceof $type) {
if (stristr($type, 'button')) {
$element->content = $element->getLabel();
return null;
}
return $element->getLabel();
}
}
return $element->getValue();
}
/**
* Render an element using a view helper
*
* Determine view helper from 'viewHelper' option, or, if none set, from
* the element type. Then call as
* helper($element->getName(), $element->getValue(), $element->getAttribs())
*
* @param string $content
* @return string
* @throws Zend_Form_Decorator_Exception if element or view are not registered
*/
public function render($content)
{
$element = $this->getElement();
$view = $element->getView();
if (null === $view) {
require_once 'Zend/Form/Decorator/Exception.php';
throw new Zend_Form_Decorator_Exception('ViewHelper decorator cannot render without a registered view object');
}
if (method_exists($element, 'getMultiOptions')) {
$element->getMultiOptions();
}
$helper = $this->getHelper();
$separator = $this->getSeparator();
$value = $this->getValue($element);
$attribs = $this->getElementAttribs();
$name = $element->getFullyQualifiedName();
$id = $element->getId();
$attribs['id'] = $id;
$helperObject = $view->getHelper($helper);
if (method_exists($helperObject, 'setTranslator')) {
$helperObject->setTranslator($element->getTranslator());
}
$elementContent = $view->$helper($name, $value, $attribs, $element->options);
switch ($this->getPlacement()) {
case self::APPEND:
return $content . $separator . $elementContent;
case self::PREPEND:
return $elementContent . $separator . $content;
default:
return $elementContent;
}
}
}

View file

@ -0,0 +1,144 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Decorator_Abstract */
require_once 'Zend/Form/Decorator/Abstract.php';
/**
* Zend_Form_Decorator_ViewScript
*
* Render a view script as a decorator
*
* Accepts the options:
* - separator: separator to use between view script content and provided content (defaults to PHP_EOL)
* - placement: whether to append or prepend view script content to provided content (defaults to prepend)
* - viewScript: view script to use
*
* The view script is rendered as a partial; the element being decorated is
* passed in as the 'element' variable:
* <code>
* // in view script:
* echo $this->element->getLabel();
* </code>
*
* Any options other than separator, placement, and viewScript are passed to
* the partial as local variables.
*
* @category Zend
* @package Zend_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: ViewScript.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
class Zend_Form_Decorator_ViewScript extends Zend_Form_Decorator_Abstract
{
/**
* Default placement: append
* @var string
*/
protected $_placement = 'APPEND';
/**
* View script to render
* @var string
*/
protected $_viewScript;
/**
* Set view script
*
* @param string $script
* @return Zend_Form_Decorator_ViewScript
*/
public function setViewScript($script)
{
$this->_viewScript = (string) $script;
return $this;
}
/**
* Get view script
*
* @return string|null
*/
public function getViewScript()
{
if (null === $this->_viewScript) {
if (null !== ($element = $this->getElement())) {
if (null !== ($viewScript = $element->getAttrib('viewScript'))) {
$this->setViewScript($viewScript);
return $viewScript;
}
}
if (null !== ($viewScript = $this->getOption('viewScript'))) {
$this->setViewScript($viewScript)
->removeOption('viewScript');
}
}
return $this->_viewScript;
}
/**
* Render a view script
*
* @param string $content
* @return string
*/
public function render($content)
{
$element = $this->getElement();
$view = $element->getView();
if (null === $view) {
return $content;
}
$viewScript = $this->getViewScript();
if (empty($viewScript)) {
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception('No view script registered with ViewScript decorator');
}
$separator = $this->getSeparator();
$placement = $this->getPlacement();
$vars = $this->getOptions();
$vars['element'] = $element;
$vars['content'] = $content;
$vars['decorator'] = $this;
$renderedContent = $view->partial($viewScript, $vars);
// Get placement again to see if it has changed
$placement = $this->getPlacement();
switch ($placement) {
case self::PREPEND:
return $renderedContent . $separator . $content;
case self::APPEND:
return $content . $separator . $renderedContent;
default:
return $renderedContent;
}
}
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,42 @@
<?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_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Element_Submit */
require_once 'Zend/Form/Element/Submit.php';
/**
* Button form element
*
* @category Zend
* @package Zend_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Button.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
class Zend_Form_Element_Button extends Zend_Form_Element_Submit
{
/**
* Use formButton view helper by default
* @var string
*/
public $helper = 'formButton';
}

View file

@ -0,0 +1,305 @@
<?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_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Captcha.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/** @see Zend_Form_Element_Xhtml */
require_once 'Zend/Form/Element/Xhtml.php';
/** @see Zend_Captcha_Adapter */
require_once 'Zend/Captcha/Adapter.php';
/**
* Generic captcha element
*
* This element allows to insert CAPTCHA into the form in order
* to validate that human is submitting the form. The actual
* logic is contained in the captcha adapter.
*
* @see http://en.wikipedia.org/wiki/Captcha
*
* @category Zend
* @package Zend_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Form_Element_Captcha extends Zend_Form_Element_Xhtml
{
/**
* Captcha plugin type constant
*/
const CAPTCHA = 'CAPTCHA';
/**
* Captcha adapter
*
* @var Zend_Captcha_Adapter
*/
protected $_captcha;
/**
* Get captcha adapter
*
* @return Zend_Captcha_Adapter
*/
public function getCaptcha()
{
return $this->_captcha;
}
/**
* Set captcha adapter
*
* @param string|array|Zend_Captcha_Adapter $captcha
* @param array $options
*/
public function setCaptcha($captcha, $options = array())
{
if ($captcha instanceof Zend_Captcha_Adapter) {
$instance = $captcha;
} else {
if (is_array($captcha)) {
if (array_key_exists('captcha', $captcha)) {
$name = $captcha['captcha'];
unset($captcha['captcha']);
} else {
$name = array_shift($captcha);
}
$options = array_merge($options, $captcha);
} else {
$name = $captcha;
}
$name = $this->getPluginLoader(self::CAPTCHA)->load($name);
if (empty($options)) {
$instance = new $name;
} else {
$r = new ReflectionClass($name);
if ($r->hasMethod('__construct')) {
$instance = $r->newInstanceArgs(array($options));
} else {
$instance = $r->newInstance();
}
}
}
$this->_captcha = $instance;
$this->_captcha->setName($this->getName());
return $this;
}
/**
* Constructor
*
* $spec may be:
* - string: name of element
* - array: options with which to configure element
* - Zend_Config: Zend_Config with options for configuring element
*
* @param string|array|Zend_Config $spec
* @return void
*/
public function __construct($spec, $options = null)
{
parent::__construct($spec, $options);
$this->setAllowEmpty(true)
->setRequired(true)
->setAutoInsertNotEmptyValidator(false)
->addValidator($this->getCaptcha(), true);
}
/**
* Return all attributes
*
* @return array
*/
public function getAttribs()
{
$attribs = get_object_vars($this);
unset($attribs['helper']);
foreach ($attribs as $key => $value) {
if ('_' == substr($key, 0, 1)) {
unset($attribs[$key]);
}
}
return $attribs;
}
/**
* Set options
*
* Overrides to allow passing captcha options
*
* @param array $options
* @return Zend_Form_Element_Captcha
*/
public function setOptions(array $options)
{
parent::setOptions($options);
if (array_key_exists('captcha', $options)) {
if (array_key_exists('captchaOptions', $options)) {
$this->setCaptcha($options['captcha'], $options['captchaOptions']);
unset($options['captchaOptions']);
} else {
$this->setCaptcha($options['captcha']);
}
unset($options['captcha']);
}
return $this;
}
/**
* Render form element
*
* @param Zend_View_Interface $view
* @return string
*/
public function render(Zend_View_Interface $view = null)
{
$captcha = $this->getCaptcha();
$captcha->setName($this->getFullyQualifiedName());
$decorators = $this->getDecorators();
$decorator = $captcha->getDecorator();
if (!empty($decorator)) {
array_unshift($decorators, $decorator);
}
$decorator = array('Captcha', array('captcha' => $captcha));
array_unshift($decorators, $decorator);
$this->setDecorators($decorators);
$this->setValue($this->getCaptcha()->generate());
return parent::render($view);
}
/**
* Retrieve plugin loader for validator or filter chain
*
* Support for plugin loader for Captcha adapters
*
* @param string $type
* @return Zend_Loader_PluginLoader
* @throws Zend_Loader_Exception on invalid type.
*/
public function getPluginLoader($type)
{
$type = strtoupper($type);
if ($type == self::CAPTCHA) {
if (!isset($this->_loaders[$type])) {
require_once 'Zend/Loader/PluginLoader.php';
$this->_loaders[$type] = new Zend_Loader_PluginLoader(
array('Zend_Captcha' => 'Zend/Captcha/')
);
}
return $this->_loaders[$type];
} else {
return parent::getPluginLoader($type);
}
}
/**
* Add prefix path for plugin loader for captcha adapters
*
* This method handles the captcha type, the rest is handled by
* the parent
* @param string $prefix
* @param string $path
* @param string $type
* @return Zend_Form_Element
* @see Zend_Form_Element::addPrefixPath
*/
public function addPrefixPath($prefix, $path, $type = null)
{
$type = strtoupper($type);
switch ($type) {
case null:
$loader = $this->getPluginLoader(self::CAPTCHA);
$cPrefix = rtrim($prefix, '_') . '_Captcha';
$cPath = rtrim($path, '/\\') . '/Captcha';
$loader->addPrefixPath($cPrefix, $cPath);
return parent::addPrefixPath($prefix, $path);
case self::CAPTCHA:
$loader = $this->getPluginLoader($type);
$loader->addPrefixPath($prefix, $path);
return $this;
default:
return parent::addPrefixPath($prefix, $path, $type);
}
}
/**
* Load default decorators
*
* @return void
*/
public function loadDefaultDecorators()
{
if ($this->loadDefaultDecoratorsIsDisabled()) {
return;
}
$decorators = $this->getDecorators();
if (empty($decorators)) {
$this->addDecorator('Errors')
->addDecorator('Description', array('tag' => 'p', 'class' => 'description'))
->addDecorator('HtmlTag', array('tag' => 'dd'))
->addDecorator('Label', array('tag' => 'dt'));
}
}
/**
* Is the captcha valid?
*
* @param mixed $value
* @param mixed $context
* @return boolean
*/
public function isValid($value, $context = null)
{
$this->getCaptcha()->setName($this->getName());
$belongsTo = $this->getBelongsTo();
if (empty($belongsTo) || !is_array($context)) {
return parent::isValid($value, $context);
}
$name = $this->getFullyQualifiedName();
$root = substr($name, 0, strpos($name, '['));
$segments = substr($name, strpos($name, '['));
$segments = ltrim($segments, '[');
$segments = rtrim($segments, ']');
$segments = explode('][', $segments);
array_unshift($segments, $root);
array_pop($segments);
$newContext = $context;
foreach ($segments as $segment) {
if (array_key_exists($segment, $newContext)) {
$newContext = $newContext[$segment];
}
}
return parent::isValid($value, $newContext);
}
}

View file

@ -0,0 +1,203 @@
<?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_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Element_Xhtml */
require_once 'Zend/Form/Element/Xhtml.php';
/**
* Checkbox form element
*
* @category Zend
* @package Zend_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Checkbox.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
class Zend_Form_Element_Checkbox extends Zend_Form_Element_Xhtml
{
/**
* Is the checkbox checked?
* @var bool
*/
public $checked = false;
/**
* Use formCheckbox view helper by default
* @var string
*/
public $helper = 'formCheckbox';
/**
* Options that will be passed to the view helper
* @var array
*/
public $options = array(
'checkedValue' => '1',
'uncheckedValue' => '0',
);
/**
* Value when checked
* @var string
*/
protected $_checkedValue = '1';
/**
* Value when not checked
* @var string
*/
protected $_uncheckedValue = '0';
/**
* Current value
* @var string 0 or 1
*/
protected $_value = '0';
/**
* Set options
*
* Intercept checked and unchecked values and set them early; test stored
* value against checked and unchecked values after configuration.
*
* @param array $options
* @return Zend_Form_Element_Checkbox
*/
public function setOptions(array $options)
{
if (array_key_exists('checkedValue', $options)) {
$this->setCheckedValue($options['checkedValue']);
unset($options['checkedValue']);
}
if (array_key_exists('uncheckedValue', $options)) {
$this->setUncheckedValue($options['uncheckedValue']);
unset($options['uncheckedValue']);
}
parent::setOptions($options);
$curValue = $this->getValue();
$test = array($this->getCheckedValue(), $this->getUncheckedValue());
if (!in_array($curValue, $test)) {
$this->setValue($curValue);
}
return $this;
}
/**
* Set value
*
* If value matches checked value, sets to that value, and sets the checked
* flag to true.
*
* Any other value causes the unchecked value to be set as the current
* value, and the checked flag to be set as false.
*
*
* @param mixed $value
* @return Zend_Form_Element_Checkbox
*/
public function setValue($value)
{
if ($value == $this->getCheckedValue()) {
parent::setValue($value);
$this->checked = true;
} else {
parent::setValue($this->getUncheckedValue());
$this->checked = false;
}
return $this;
}
/**
* Set checked value
*
* @param string $value
* @return Zend_Form_Element_Checkbox
*/
public function setCheckedValue($value)
{
$this->_checkedValue = (string) $value;
$this->options['checkedValue'] = $value;
return $this;
}
/**
* Get value when checked
*
* @return string
*/
public function getCheckedValue()
{
return $this->_checkedValue;
}
/**
* Set unchecked value
*
* @param string $value
* @return Zend_Form_Element_Checkbox
*/
public function setUncheckedValue($value)
{
$this->_uncheckedValue = (string) $value;
$this->options['uncheckedValue'] = $value;
return $this;
}
/**
* Get value when not checked
*
* @return string
*/
public function getUncheckedValue()
{
return $this->_uncheckedValue;
}
/**
* Set checked flag
*
* @param bool $flag
* @return Zend_Form_Element_Checkbox
*/
public function setChecked($flag)
{
$this->checked = (bool) $flag;
if ($this->checked) {
$this->setValue($this->getCheckedValue());
} else {
$this->setValue($this->getUncheckedValue());
}
return $this;
}
/**
* Get checked flag
*
* @return bool
*/
public function isChecked()
{
return $this->checked;
}
}

View file

@ -0,0 +1,37 @@
<?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_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Exception */
require_once 'Zend/Form/Exception.php';
/**
* Exception for Zend_Form component.
*
* @category Zend
* @package Zend_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Form_Element_Exception extends Zend_Form_Exception
{
}

View file

@ -0,0 +1,911 @@
<?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_Form
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Element_Xhtml */
require_once 'Zend/Form/Element/Xhtml.php';
/**
* Zend_Form_Element
*
* @category Zend
* @package Zend_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: File.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
class Zend_Form_Element_File extends Zend_Form_Element_Xhtml
{
/**
* Plugin loader type
*/
const TRANSFER_ADAPTER = 'TRANSFER_ADAPTER';
/**
* @var string Default view helper
*/
public $helper = 'formFile';
/**
* @var Zend_File_Transfer_Adapter_Abstract
*/
protected $_adapter;
/**
* @var boolean Already validated ?
*/
protected $_validated = false;
/**
* @var boolean Disable value to be equal to file content
*/
protected $_valueDisabled = false;
/**
* @var integer Internal multifile counter
*/
protected $_counter = 1;
/**
* @var integer Maximum file size for MAX_FILE_SIZE attribut of form
*/
protected static $_maxFileSize = -1;
/**
* Load default decorators
*
* @return void
*/
public function loadDefaultDecorators()
{
if ($this->loadDefaultDecoratorsIsDisabled()) {
return;
}
$decorators = $this->getDecorators();
if (empty($decorators)) {
$this->addDecorator('File')
->addDecorator('Errors')
->addDecorator('Description', array('tag' => 'p', 'class' => 'description'))
->addDecorator('HtmlTag', array('tag' => 'dd'))
->addDecorator('Label', array('tag' => 'dt'));
}
}
/**
* Set plugin loader
*
* @param Zend_Loader_PluginLoader_Interface $loader
* @param string $type
* @return Zend_Form_Element_File
*/
public function setPluginLoader(Zend_Loader_PluginLoader_Interface $loader, $type)
{
$type = strtoupper($type);
if ($type != self::TRANSFER_ADAPTER) {
return parent::setPluginLoader($loader, $type);
}
$this->_loaders[$type] = $loader;
return $this;
}
/**
* Get Plugin Loader
*
* @param string $type
* @return Zend_Loader_PluginLoader_Interface
*/
public function getPluginLoader($type)
{
$type = strtoupper($type);
if ($type != self::TRANSFER_ADAPTER) {
return parent::getPluginLoader($type);
}
if (!array_key_exists($type, $this->_loaders)) {
require_once 'Zend/Loader/PluginLoader.php';
$loader = new Zend_Loader_PluginLoader(array(
'Zend_File_Transfer_Adapter' => 'Zend/File/Transfer/Adapter/',
));
$this->setPluginLoader($loader, self::TRANSFER_ADAPTER);
}
return $this->_loaders[$type];
}
/**
* Add prefix path for plugin loader
*
* @param string $prefix
* @param string $path
* @param string $type
* @return Zend_Form_Element_File
*/
public function addPrefixPath($prefix, $path, $type = null)
{
$type = strtoupper($type);
if (!empty($type) && ($type != self::TRANSFER_ADAPTER)) {
return parent::addPrefixPath($prefix, $path, $type);
}
if (empty($type)) {
$pluginPrefix = rtrim($prefix, '_') . '_Transfer_Adapter';
$pluginPath = rtrim($path, DIRECTORY_SEPARATOR) . '/Transfer/Adapter/';
$loader = $this->getPluginLoader(self::TRANSFER_ADAPTER);
$loader->addPrefixPath($pluginPrefix, $pluginPath);
return parent::addPrefixPath($prefix, $path, null);
}
$loader = $this->getPluginLoader($type);
$loader->addPrefixPath($prefix, $path);
return $this;
}
/**
* Set transfer adapter
*
* @param string|Zend_File_Transfer_Adapter_Abstract $adapter
* @return Zend_Form_Element_File
*/
public function setTransferAdapter($adapter)
{
if ($adapter instanceof Zend_File_Transfer_Adapter_Abstract) {
$this->_adapter = $adapter;
} elseif (is_string($adapter)) {
$loader = $this->getPluginLoader(self::TRANSFER_ADAPTER);
$class = $loader->load($adapter);
$this->_adapter = new $class;
} else {
require_once 'Zend/Form/Element/Exception.php';
throw new Zend_Form_Element_Exception('Invalid adapter specified');
}
foreach (array('filter', 'validate') as $type) {
$loader = $this->getPluginLoader($type);
$this->_adapter->setPluginLoader($loader, $type);
}
return $this;
}
/**
* Get transfer adapter
*
* Lazy loads HTTP transfer adapter when no adapter registered.
*
* @return Zend_File_Transfer_Adapter_Abstract
*/
public function getTransferAdapter()
{
if (null === $this->_adapter) {
$this->setTransferAdapter('Http');
}
return $this->_adapter;
}
/**
* Add Validator; proxy to adapter
*
* @param string|Zend_Validate_Interface $validator
* @param bool $breakChainOnFailure
* @param mixed $options
* @return Zend_Form_Element_File
*/
public function addValidator($validator, $breakChainOnFailure = false, $options = array())
{
$adapter = $this->getTransferAdapter();
$adapter->addValidator($validator, $breakChainOnFailure, $options, $this->getName());
$this->_validated = false;
return $this;
}
/**
* Add multiple validators at once; proxy to adapter
*
* @param array $validators
* @return Zend_Form_Element_File
*/
public function addValidators(array $validators)
{
$adapter = $this->getTransferAdapter();
$adapter->addValidators($validators, $this->getName());
$this->_validated = false;
return $this;
}
/**
* Add multiple validators at once, overwriting; proxy to adapter
*
* @param array $validators
* @return Zend_Form_Element_File
*/
public function setValidators(array $validators)
{
$adapter = $this->getTransferAdapter();
$adapter->setValidators($validators, $this->getName());
$this->_validated = false;
return $this;
}
/**
* Retrieve validator by name; proxy to adapter
*
* @param string $name
* @return Zend_Validate_Interface|null
*/
public function getValidator($name)
{
$adapter = $this->getTransferAdapter();
return $adapter->getValidator($name);
}
/**
* Retrieve all validators; proxy to adapter
*
* @return array
*/
public function getValidators()
{
$adapter = $this->getTransferAdapter();
$validators = $adapter->getValidators($this->getName());
if ($validators === null) {
$validators = array();
}
return $validators;
}
/**
* Remove validator by name; proxy to adapter
*
* @param string $name
* @return Zend_Form_Element_File
*/
public function removeValidator($name)
{
$adapter = $this->getTransferAdapter();
$adapter->removeValidator($name);
$this->_validated = false;
return $this;
}
/**
* Remove all validators; proxy to adapter
*
* @return Zend_Form_Element_File
*/
public function clearValidators()
{
$adapter = $this->getTransferAdapter();
$adapter->clearValidators();
$this->_validated = false;
return $this;
}
/**
* Add Filter; proxy to adapter
*
* @param string|array $filter Type of filter to add
* @param string|array $options Options to set for the filter
* @return Zend_Form_Element_File
*/
public function addFilter($filter, $options = null)
{
$adapter = $this->getTransferAdapter();
$adapter->addFilter($filter, $options, $this->getName());
return $this;
}
/**
* Add Multiple filters at once; proxy to adapter
*
* @param array $filters
* @return Zend_Form_Element_File
*/
public function addFilters(array $filters)
{
$adapter = $this->getTransferAdapter();
$adapter->addFilters($filters, $this->getName());
return $this;
}
/**
* Sets a filter for the class, erasing all previous set; proxy to adapter
*
* @param string|array $filter Filter to set
* @return Zend_Form_Element_File
*/
public function setFilters(array $filters)
{
$adapter = $this->getTransferAdapter();
$adapter->setFilters($filters, $this->getName());
return $this;
}
/**
* Retrieve individual filter; proxy to adapter
*
* @param string $name
* @return Zend_Filter_Interface|null
*/
public function getFilter($name)
{
$adapter = $this->getTransferAdapter();
return $adapter->getFilter($name);
}
/**
* Returns all set filters; proxy to adapter
*
* @return array List of set filters
*/
public function getFilters()
{
$adapter = $this->getTransferAdapter();
$filters = $adapter->getFilters($this->getName());
if ($filters === null) {
$filters = array();
}
return $filters;
}
/**
* Remove an individual filter; proxy to adapter
*
* @param string $name
* @return Zend_Form_Element_File
*/
public function removeFilter($name)
{
$adapter = $this->getTransferAdapter();
$adapter->removeFilter($name);
return $this;
}
/**
* Remove all filters; proxy to adapter
*
* @return Zend_Form_Element_File
*/
public function clearFilters()
{
$adapter = $this->getTransferAdapter();
$adapter->clearFilters();
return $this;
}
/**
* Validate upload
*
* @param string $value File, can be optional, give null to validate all files
* @param mixed $context
* @return bool
*/
public function isValid($value, $context = null)
{
if ($this->_validated) {
return true;
}
$adapter = $this->getTransferAdapter();
$translator = $this->getTranslator();
if ($translator !== null) {
$adapter->setTranslator($translator);
}
if (!$this->isRequired()) {
$adapter->setOptions(array('ignoreNoFile' => true), $this->getName());
} else {
$adapter->setOptions(array('ignoreNoFile' => false), $this->getName());
if ($this->autoInsertNotEmptyValidator() and
!$this->getValidator('NotEmpty'))
{
$validators = $this->getValidators();
$notEmpty = array('validator' => 'NotEmpty', 'breakChainOnFailure' => true);
array_unshift($validators, $notEmpty);
$this->setValidators($validators);
}
}
if($adapter->isValid($this->getName())) {
$this->_validated = true;
return true;
}
$this->_validated = false;
return false;
}
/**
* Receive the uploaded file
*
* @return boolean
*/
public function receive()
{
if (!$this->_validated) {
if (!$this->isValid($this->getName())) {
return false;
}
}
$adapter = $this->getTransferAdapter();
if ($adapter->receive($this->getName())) {
return true;
}
return false;
}
/**
* Retrieve error codes; proxy to transfer adapter
*
* @return array
*/
public function getErrors()
{
return parent::getErrors() + $this->getTransferAdapter()->getErrors();
}
/**
* Are there errors registered?
*
* @return bool
*/
public function hasErrors()
{
return (parent::hasErrors() || $this->getTransferAdapter()->hasErrors());
}
/**
* Retrieve error messages; proxy to transfer adapter
*
* @return array
*/
public function getMessages()
{
return parent::getMessages() + $this->getTransferAdapter()->getMessages();
}
/**
* Set the upload destination
*
* @param string $path
* @return Zend_Form_Element_File
*/
public function setDestination($path)
{
$this->getTransferAdapter()->setDestination($path, $this->getName());
return $this;
}
/**
* Get the upload destination
*
* @return string
*/
public function getDestination()
{
return $this->getTransferAdapter()->getDestination($this->getName());
}
/**
* Get the final filename
*
* @param string $value (Optional) Element or file to return
* @param boolean $path (Optional) Return also the path, defaults to true
* @return string
*/
public function getFileName($value = null, $path = true)
{
if (empty($value)) {
$value = $this->getName();
}
return $this->getTransferAdapter()->getFileName($value, $path);
}
/**
* Get internal file informations
*
* @param string $value (Optional) Element or file to return
* @return array
*/
public function getFileInfo($value = null)
{
if (empty($value)) {
$value = $this->getName();
}
return $this->getTransferAdapter()->getFileInfo($value);
}
/**
* Set a multifile element
*
* @param integer $count Number of file elements
* @return Zend_Form_Element_File Provides fluent interface
*/
public function setMultiFile($count)
{
if ((integer) $count < 2) {
$this->setIsArray(false);
$this->_counter = 1;
} else {
$this->setIsArray(true);
$this->_counter = (integer) $count;
}
return $this;
}
/**
* Returns the multifile element number
*
* @return integer
*/
public function getMultiFile()
{
return $this->_counter;
}
/**
* Sets the maximum file size of the form
*
* @return integer
*/
public function getMaxFileSize()
{
if (self::$_maxFileSize < 0) {
$ini = $this->_convertIniToInteger(trim(ini_get('post_max_size')));
$max = $this->_convertIniToInteger(trim(ini_get('upload_max_filesize')));
$min = max($ini, $max);
if ($ini > 0) {
$min = min($min, $ini);
}
if ($max > 0) {
$min = min($min, $max);
}
self::$_maxFileSize = $min;
}
return self::$_maxFileSize;
}
/**
* Sets the maximum file size of the form
*
* @param integer $size
* @return integer
*/
public function setMaxFileSize($size)
{
$ini = $this->_convertIniToInteger(trim(ini_get('post_max_size')));
$max = $this->_convertIniToInteger(trim(ini_get('upload_max_filesize')));
if (($max > -1) && ($size > $max)) {
trigger_error("Your 'upload_max_filesize' config setting limits the maximum filesize to '$max'. You tried to set '$size'.", E_USER_NOTICE);
$size = $max;
}
if (($ini > -1) && ($size > $ini)) {
trigger_error("Your 'post_max_size' config setting limits the maximum filesize to '$ini'. You tried to set '$size'.", E_USER_NOTICE);
$size = $ini;
}
self::$_maxFileSize = $size;
return $this;
}
/**
* Converts a ini setting to a integer value
*
* @param string $setting
* @return integer
*/
private function _convertIniToInteger($setting)
{
if (!is_numeric($setting)) {
$type = strtoupper(substr($setting, -1));
$setting = (integer) substr($setting, 0, -1);
switch ($type) {
case 'K' :
$setting *= 1024;
break;
case 'M' :
$setting *= 1024 * 1024;
break;
case 'G' :
$setting *= 1024 * 1024 * 1024;
break;
default :
break;
}
}
return (integer) $setting;
}
/**
* Set if the file will be uploaded when getting the value
* This defaults to false which will force receive() when calling getValues()
*
* @param boolean $flag Sets if the file is handled as the elements value
* @return Zend_Form_Element_File
*/
public function setValueDisabled($flag)
{
$this->_valueDisabled = (bool) $flag;
return $this;
}
/**
* Returns if the file will be uploaded when calling getValues()
*
* @return boolean Receive the file on calling getValues()?
*/
public function isValueDisabled()
{
return $this->_valueDisabled;
}
/**
* Processes the file, returns null or the filename only
* For the complete path, use getFileName
*
* @return null|string
*/
public function getValue()
{
if ($this->_value !== null) {
return $this->_value;
}
$content = $this->getTransferAdapter()->getFileName($this->getName());
if (empty($content)) {
return null;
}
if (!$this->isValid(null)) {
return null;
}
if (!$this->_valueDisabled && !$this->receive()) {
return null;
}
return $this->getFileName(null, false);
}
/**
* Disallow setting the value
*
* @param mixed $value
* @return Zend_Form_Element_File
*/
public function setValue($value)
{
return $this;
}
/**
* Set translator object for localization
*
* @param Zend_Translate|null $translator
* @return Zend_Form_Element_File
*/
public function setTranslator($translator = null)
{
$adapter = $this->getTransferAdapter();
$adapter->setTranslator($translator);
parent::setTranslator($translator);
return $this;
}
/**
* Retrieve localization translator object
*
* @return Zend_Translate_Adapter|null
*/
public function getTranslator()
{
if ($this->translatorIsDisabled()) {
return null;
}
$translator = $this->getTransferAdapter()->getTranslator();
if (null === $translator) {
require_once 'Zend/Form.php';
return Zend_Form::getDefaultTranslator();
}
return $translator;
}
/**
* Indicate whether or not translation should be disabled
*
* @param bool $flag
* @return Zend_Form_Element_File
*/
public function setDisableTranslator($flag)
{
$adapter = $this->getTransferAdapter();
$adapter->setDisableTranslator($flag);
$this->_translatorDisabled = (bool) $flag;
return $this;
}
/**
* Is translation disabled?
*
* @return bool
*/
public function translatorIsDisabled()
{
$adapter = $this->getTransferAdapter();
return $adapter->translatorIsDisabled();
}
/**
* Was the file received?
*
* @return bool
*/
public function isReceived()
{
$adapter = $this->getTransferAdapter();
return $adapter->isReceived($this->getName());
}
/**
* Was the file uploaded?
*
* @return bool
*/
public function isUploaded()
{
$adapter = $this->getTransferAdapter();
return $adapter->isUploaded($this->getName());
}
/**
* Has the file been filtered?
*
* @return bool
*/
public function isFiltered()
{
$adapter = $this->getTransferAdapter();
return $adapter->isFiltered($this->getName());
}
/**
* Returns the hash for this file element
*
* @param string $hash (Optional) Hash algorithm to use
* @return string|array Hashstring
*/
public function getHash($hash = 'crc32')
{
$adapter = $this->getTransferAdapter();
return $adapter->getHash($hash, $this->getName());
}
/**
* Returns the filesize for this file element
*
* @return string|array Filesize
*/
public function getFileSize()
{
$adapter = $this->getTransferAdapter();
return $adapter->getFileSize($this->getName());
}
/**
* Returns the mimetype for this file element
*
* @return string|array Mimetype
*/
public function getMimeType()
{
$adapter = $this->getTransferAdapter();
return $adapter->getMimeType($this->getName());
}
/**
* Render form element
* Checks for decorator interface to prevent errors
*
* @param Zend_View_Interface $view
* @return string
*/
public function render(Zend_View_Interface $view = null)
{
$marker = false;
foreach ($this->getDecorators() as $decorator) {
if ($decorator instanceof Zend_Form_Decorator_Marker_File_Interface) {
$marker = true;
}
}
if (!$marker) {
require_once 'Zend/Form/Element/Exception.php';
throw new Zend_Form_Element_Exception('No file decorator found... unable to render file element');
}
return parent::render($view);
}
/**
* Retrieve error messages and perform translation and value substitution
*
* @return array
*/
protected function _getErrorMessages()
{
$translator = $this->getTranslator();
$messages = $this->getErrorMessages();
$value = $this->getFileName();
foreach ($messages as $key => $message) {
if (null !== $translator) {
$message = $translator->translate($message);
}
if ($this->isArray() || is_array($value)) {
$aggregateMessages = array();
foreach ($value as $val) {
$aggregateMessages[] = str_replace('%value%', $val, $message);
}
if (!empty($aggregateMessages)) {
$messages[$key] = $aggregateMessages;
}
} else {
$messages[$key] = str_replace('%value%', $value, $message);
}
}
return $messages;
}
}

View file

@ -0,0 +1,259 @@
<?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_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Element_Xhtml */
require_once 'Zend/Form/Element/Xhtml.php';
/**
* CSRF form protection
*
* @category Zend
* @package Zend_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Hash.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
class Zend_Form_Element_Hash extends Zend_Form_Element_Xhtml
{
/**
* Use formHidden view helper by default
* @var string
*/
public $helper = 'formHidden';
/**
* Actual hash used.
*
* @var mixed
*/
protected $_hash;
/**
* Salt for CSRF token
* @var string
*/
protected $_salt = 'salt';
/**
* @var Zend_Session_Namespace
*/
protected $_session;
/**
* TTL for CSRF token
* @var int
*/
protected $_timeout = 300;
/**
* Constructor
*
* Creates session namespace for CSRF token, and adds validator for CSRF
* token.
*
* @param string|array|Zend_Config $spec
* @param array|Zend_Config $options
* @return void
*/
public function __construct($spec, $options = null)
{
parent::__construct($spec, $options);
$this->setAllowEmpty(false)
->setRequired(true)
->initCsrfValidator();
}
/**
* Set session object
*
* @param Zend_Session_Namespace $session
* @return Zend_Form_Element_Hash
*/
public function setSession($session)
{
$this->_session = $session;
return $this;
}
/**
* Get session object
*
* Instantiate session object if none currently exists
*
* @return Zend_Session_Namespace
*/
public function getSession()
{
if (null === $this->_session) {
require_once 'Zend/Session/Namespace.php';
$this->_session = new Zend_Session_Namespace($this->getSessionName());
}
return $this->_session;
}
/**
* Initialize CSRF validator
*
* Creates Session namespace, and initializes CSRF token in session.
* Additionally, adds validator for validating CSRF token.
*
* @return Zend_Form_Element_Hash
*/
public function initCsrfValidator()
{
$session = $this->getSession();
if (isset($session->hash)) {
$rightHash = $session->hash;
} else {
$rightHash = null;
}
$this->addValidator('Identical', true, array($rightHash));
return $this;
}
/**
* Salt for CSRF token
*
* @param string $salt
* @return Zend_Form_Element_Hash
*/
public function setSalt($salt)
{
$this->_salt = (string) $salt;
return $this;
}
/**
* Retrieve salt for CSRF token
*
* @return string
*/
public function getSalt()
{
return $this->_salt;
}
/**
* Retrieve CSRF token
*
* If no CSRF token currently exists, generates one.
*
* @return string
*/
public function getHash()
{
if (null === $this->_hash) {
$this->_generateHash();
}
return $this->_hash;
}
/**
* Get session namespace for CSRF token
*
* Generates a session namespace based on salt, element name, and class.
*
* @return string
*/
public function getSessionName()
{
return __CLASS__ . '_' . $this->getSalt() . '_' . $this->getName();
}
/**
* Set timeout for CSRF session token
*
* @param int $ttl
* @return Zend_Form_Element_Hash
*/
public function setTimeout($ttl)
{
$this->_timeout = (int) $ttl;
return $this;
}
/**
* Get CSRF session token timeout
*
* @return int
*/
public function getTimeout()
{
return $this->_timeout;
}
/**
* Override getLabel() to always be empty
*
* @return null
*/
public function getLabel()
{
return null;
}
/**
* Initialize CSRF token in session
*
* @return void
*/
public function initCsrfToken()
{
$session = $this->getSession();
$session->setExpirationHops(1, null, true);
$session->setExpirationSeconds($this->getTimeout());
$session->hash = $this->getHash();
}
/**
* Render CSRF token in form
*
* @param Zend_View_Interface $view
* @return string
*/
public function render(Zend_View_Interface $view = null)
{
$this->initCsrfToken();
return parent::render($view);
}
/**
* Generate CSRF token
*
* Generates CSRF token and stores both in {@link $_hash} and element
* value.
*
* @return void
*/
protected function _generateHash()
{
$this->_hash = md5(
mt_rand(1,1000000)
. $this->getSalt()
. $this->getName()
. mt_rand(1,1000000)
);
$this->setValue($this->_hash);
}
}

View file

@ -0,0 +1,42 @@
<?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_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Element_Xhtml */
require_once 'Zend/Form/Element/Xhtml.php';
/**
* Hidden form element
*
* @category Zend
* @package Zend_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Hidden.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
class Zend_Form_Element_Hidden extends Zend_Form_Element_Xhtml
{
/**
* Use formHidden view helper by default
* @var string
*/
public $helper = 'formHidden';
}

View file

@ -0,0 +1,131 @@
<?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_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Element_Xhtml */
require_once 'Zend/Form/Element/Xhtml.php';
/**
* Image form element
*
* @category Zend
* @package Zend_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Image.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
class Zend_Form_Element_Image extends Zend_Form_Element_Xhtml
{
/**
* What view helper to use when using view helper decorator
* @var string
*/
public $helper = 'formImage';
/**
* Image source
* @var string
*/
public $src;
/**
* Image value
* @var mixed
*/
protected $_imageValue;
/**
* Load default decorators
*
* @return void
*/
public function loadDefaultDecorators()
{
if ($this->loadDefaultDecoratorsIsDisabled()) {
return;
}
$decorators = $this->getDecorators();
if (empty($decorators)) {
$this->addDecorator('Tooltip')
->addDecorator('Image')
->addDecorator('Errors')
->addDecorator('HtmlTag', array('tag' => 'dd'))
->addDecorator('Label', array('tag' => 'dt'));
}
}
/**
* Set image path
*
* @param string $path
* @return Zend_Form_Element_Image
*/
public function setImage($path)
{
$this->src = (string) $path;
return $this;
}
/**
* Get image path
*
* @return string
*/
public function getImage()
{
return $this->src;
}
/**
* Set image value to use when submitted
*
* @param mixed $value
* @return Zend_Form_Element_Image
*/
public function setImageValue($value)
{
$this->_imageValue = $value;
return $this;
}
/**
* Get image value to use when submitted
*
* @return mixed
*/
public function getImageValue()
{
return $this->_imageValue;
}
/**
* Was this element used to submit the form?
*
* @return bool
*/
public function isChecked()
{
$imageValue = $this->getImageValue();
return ((null !== $imageValue) && ($this->getValue() == $imageValue));
}
}

View file

@ -0,0 +1,318 @@
<?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_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Element_Xhtml */
require_once 'Zend/Form/Element/Xhtml.php';
/**
* Base class for multi-option form elements
*
* @category Zend
* @package Zend_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Multi.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
abstract class Zend_Form_Element_Multi extends Zend_Form_Element_Xhtml
{
/**
* Array of options for multi-item
* @var array
*/
public $options = array();
/**
* Flag: autoregister inArray validator?
* @var bool
*/
protected $_registerInArrayValidator = true;
/**
* Separator to use between options; defaults to '<br />'.
* @var string
*/
protected $_separator = '<br />';
/**
* Which values are translated already?
* @var array
*/
protected $_translated = array();
/**
* Retrieve separator
*
* @return mixed
*/
public function getSeparator()
{
return $this->_separator;
}
/**
* Set separator
*
* @param mixed $separator
* @return self
*/
public function setSeparator($separator)
{
$this->_separator = $separator;
return $this;
}
/**
* Retrieve options array
*
* @return array
*/
protected function _getMultiOptions()
{
if (null === $this->options || !is_array($this->options)) {
$this->options = array();
}
return $this->options;
}
/**
* Add an option
*
* @param string $option
* @param string $value
* @return Zend_Form_Element_Multi
*/
public function addMultiOption($option, $value = '')
{
$option = (string) $option;
$this->_getMultiOptions();
if (!$this->_translateOption($option, $value)) {
$this->options[$option] = $value;
}
return $this;
}
/**
* Add many options at once
*
* @param array $options
* @return Zend_Form_Element_Multi
*/
public function addMultiOptions(array $options)
{
foreach ($options as $option => $value) {
if (is_array($value)
&& array_key_exists('key', $value)
&& array_key_exists('value', $value)
) {
$this->addMultiOption($value['key'], $value['value']);
} else {
$this->addMultiOption($option, $value);
}
}
return $this;
}
/**
* Set all options at once (overwrites)
*
* @param array $options
* @return Zend_Form_Element_Multi
*/
public function setMultiOptions(array $options)
{
$this->clearMultiOptions();
return $this->addMultiOptions($options);
}
/**
* Retrieve single multi option
*
* @param string $option
* @return mixed
*/
public function getMultiOption($option)
{
$option = (string) $option;
$this->_getMultiOptions();
if (isset($this->options[$option])) {
$this->_translateOption($option, $this->options[$option]);
return $this->options[$option];
}
return null;
}
/**
* Retrieve options
*
* @return array
*/
public function getMultiOptions()
{
$this->_getMultiOptions();
foreach ($this->options as $option => $value) {
$this->_translateOption($option, $value);
}
return $this->options;
}
/**
* Remove a single multi option
*
* @param string $option
* @return bool
*/
public function removeMultiOption($option)
{
$option = (string) $option;
$this->_getMultiOptions();
if (isset($this->options[$option])) {
unset($this->options[$option]);
if (isset($this->_translated[$option])) {
unset($this->_translated[$option]);
}
return true;
}
return false;
}
/**
* Clear all options
*
* @return Zend_Form_Element_Multi
*/
public function clearMultiOptions()
{
$this->options = array();
$this->_translated = array();
return $this;
}
/**
* Set flag indicating whether or not to auto-register inArray validator
*
* @param bool $flag
* @return Zend_Form_Element_Multi
*/
public function setRegisterInArrayValidator($flag)
{
$this->_registerInArrayValidator = (bool) $flag;
return $this;
}
/**
* Get status of auto-register inArray validator flag
*
* @return bool
*/
public function registerInArrayValidator()
{
return $this->_registerInArrayValidator;
}
/**
* Is the value provided valid?
*
* Autoregisters InArray validator if necessary.
*
* @param string $value
* @param mixed $context
* @return bool
*/
public function isValid($value, $context = null)
{
if ($this->registerInArrayValidator()) {
if (!$this->getValidator('InArray')) {
$multiOptions = $this->getMultiOptions();
$options = array();
foreach ($multiOptions as $opt_value => $opt_label) {
// optgroup instead of option label
if (is_array($opt_label)) {
$options = array_merge($options, array_keys($opt_label));
}
else {
$options[] = $opt_value;
}
}
$this->addValidator(
'InArray',
true,
array($options)
);
}
}
return parent::isValid($value, $context);
}
/**
* Translate an option
*
* @param string $option
* @param string $value
* @return bool
*/
protected function _translateOption($option, $value)
{
if ($this->translatorIsDisabled()) {
return false;
}
if (!isset($this->_translated[$option]) && !empty($value)) {
$this->options[$option] = $this->_translateValue($value);
if ($this->options[$option] === $value) {
return false;
}
$this->_translated[$option] = true;
return true;
}
return false;
}
/**
* Translate a multi option value
*
* @param string $value
* @return string
*/
protected function _translateValue($value)
{
if (is_array($value)) {
foreach ($value as $key => $val) {
$value[$key] = $this->_translateValue($val);
}
return $value;
} else {
if (null !== ($translator = $this->getTranslator())) {
if ($translator->isTranslated($value)) {
return $translator->translate($value);
}
}
return $value;
}
}
}

View file

@ -0,0 +1,52 @@
<?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_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Element_Multi */
require_once 'Zend/Form/Element/Multi.php';
/**
* MultiCheckbox form element
*
* Allows specifyinc a (multi-)dimensional associative array of values to use
* as labelled checkboxes; these will return an array of values for those
* checkboxes selected.
*
* @category Zend
* @package Zend_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: MultiCheckbox.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
class Zend_Form_Element_MultiCheckbox extends Zend_Form_Element_Multi
{
/**
* Use formMultiCheckbox view helper by default
* @var string
*/
public $helper = 'formMultiCheckbox';
/**
* MultiCheckbox is an array of values by default
* @var bool
*/
protected $_isArray = true;
}

View file

@ -0,0 +1,54 @@
<?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_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Element_Select */
require_once 'Zend/Form/Element/Select.php';
/**
* Multiselect form element
*
* @category Zend
* @package Zend_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Multiselect.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
class Zend_Form_Element_Multiselect extends Zend_Form_Element_Select
{
/**
* 'multiple' attribute
* @var string
*/
public $multiple = 'multiple';
/**
* Use formSelect view helper by default
* @var string
*/
public $helper = 'formSelect';
/**
* Multiselect is an array of values by default
* @var bool
*/
protected $_isArray = true;
}

View file

@ -0,0 +1,88 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Element_Xhtml */
require_once 'Zend/Form/Element/Xhtml.php';
/**
* Password form element
*
* @category Zend
* @package Zend_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Password.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
class Zend_Form_Element_Password extends Zend_Form_Element_Xhtml
{
/**
* Use formPassword view helper by default
* @var string
*/
public $helper = 'formPassword';
/**
* Whether or not to render the password
* @var bool
*/
public $renderPassword = false;
/**
* Set flag indicating whether or not to render the password
* @param bool $flag
* @return Zend_Form_Element_Password
*/
public function setRenderPassword($flag)
{
$this->renderPassword = (bool) $flag;
return $this;
}
/**
* Get value of renderPassword flag
*
* @return bool
*/
public function renderPassword()
{
return $this->renderPassword;
}
/**
* Override isValid()
*
* Ensure that validation error messages mask password value.
*
* @param string $value
* @param mixed $context
* @return bool
*/
public function isValid($value, $context = null)
{
foreach ($this->getValidators() as $validator) {
if ($validator instanceof Zend_Validate_Abstract) {
$validator->setObscureValue(true);
}
}
return parent::isValid($value, $context);
}
}

View file

@ -0,0 +1,57 @@
<?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_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Element_Multi */
require_once 'Zend/Form/Element/Multi.php';
/**
* Radio form element
*
* @category Zend
* @package Zend_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Radio.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
class Zend_Form_Element_Radio extends Zend_Form_Element_Multi
{
/**
* Use formRadio view helper by default
* @var string
*/
public $helper = 'formRadio';
/**
* Load default decorators
*
* Disables "for" attribute of label if label decorator enabled.
*
* @return void
*/
public function loadDefaultDecorators()
{
parent::loadDefaultDecorators();
if (false !== $decorator = $this->getDecorator('Label')) {
$decorator->setOption('disableFor', true);
}
}
}

View file

@ -0,0 +1,42 @@
<?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_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Element_Submit */
require_once 'Zend/Form/Element/Submit.php';
/**
* Reset form element
*
* @category Zend
* @package Zend_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Reset.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
class Zend_Form_Element_Reset extends Zend_Form_Element_Submit
{
/**
* Use formReset view helper by default
* @var string
*/
public $helper = 'formReset';
}

View file

@ -0,0 +1,42 @@
<?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_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Element_Multi */
require_once 'Zend/Form/Element/Multi.php';
/**
* Select.php form element
*
* @category Zend
* @package Zend_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Select.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
class Zend_Form_Element_Select extends Zend_Form_Element_Multi
{
/**
* Use formSelect view helper by default
* @var string
*/
public $helper = 'formSelect';
}

View file

@ -0,0 +1,126 @@
<?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_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Element_Xhtml */
require_once 'Zend/Form/Element/Xhtml.php';
/**
* Submit form element
*
* @category Zend
* @package Zend_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Submit.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
class Zend_Form_Element_Submit extends Zend_Form_Element_Xhtml
{
/**
* Default view helper to use
* @var string
*/
public $helper = 'formSubmit';
/**
* Constructor
*
* @param string|array|Zend_Config $spec Element name or configuration
* @param string|array|Zend_Config $options Element value or configuration
* @return void
*/
public function __construct($spec, $options = null)
{
if (is_string($spec) && ((null !== $options) && is_string($options))) {
$options = array('label' => $options);
}
if (!isset($options['ignore'])) {
$options['ignore'] = true;
}
parent::__construct($spec, $options);
}
/**
* Return label
*
* If no label is present, returns the currently set name.
*
* If a translator is present, returns the translated label.
*
* @return string
*/
public function getLabel()
{
$value = parent::getLabel();
if (null === $value) {
$value = $this->getName();
}
if (null !== ($translator = $this->getTranslator())) {
return $translator->translate($value);
}
return $value;
}
/**
* Has this submit button been selected?
*
* @return bool
*/
public function isChecked()
{
$value = $this->getValue();
if (empty($value)) {
return false;
}
if ($value != $this->getLabel()) {
return false;
}
return true;
}
/**
* Default decorators
*
* Uses only 'Submit' and 'DtDdWrapper' decorators by default.
*
* @return void
*/
public function loadDefaultDecorators()
{
if ($this->loadDefaultDecoratorsIsDisabled()) {
return;
}
$decorators = $this->getDecorators();
if (empty($decorators)) {
$this->addDecorator('Tooltip')
->addDecorator('ViewHelper')
->addDecorator('DtDdWrapper');
}
}
}

View file

@ -0,0 +1,42 @@
<?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_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Element_Xhtml */
require_once 'Zend/Form/Element/Xhtml.php';
/**
* Text form element
*
* @category Zend
* @package Zend_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Text.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
class Zend_Form_Element_Text extends Zend_Form_Element_Xhtml
{
/**
* Default form view helper to use for rendering
* @var string
*/
public $helper = 'formText';
}

View file

@ -0,0 +1,42 @@
<?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_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Element_Xhtml */
require_once 'Zend/Form/Element/Xhtml.php';
/**
* Textarea form element
*
* @category Zend
* @package Zend_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Textarea.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
class Zend_Form_Element_Textarea extends Zend_Form_Element_Xhtml
{
/**
* Use formTextarea view helper by default
* @var string
*/
public $helper = 'formTextarea';
}

View file

@ -0,0 +1,37 @@
<?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_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Element */
require_once 'Zend/Form/Element.php';
/**
* Base element for XHTML elements
*
* @category Zend
* @package Zend_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Xhtml.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
abstract class Zend_Form_Element_Xhtml extends Zend_Form_Element
{
}

View file

@ -0,0 +1,35 @@
<?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_Form
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Exception */
require_once 'Zend/Exception.php';
/**
* Exception for Zend_Form component.
*
* @category Zend
* @package Zend_Form
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Form_Exception extends Zend_Exception
{
}

View file

@ -0,0 +1,60 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Form
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form */
require_once 'Zend/Form.php';
/**
* Zend_Form_SubForm
*
* @category Zend
* @package Zend_Form
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: SubForm.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
class Zend_Form_SubForm extends Zend_Form
{
/**
* Whether or not form elements are members of an array
* @var bool
*/
protected $_isArray = true;
/**
* Load the default decorators
*
* @return void
*/
public function loadDefaultDecorators()
{
if ($this->loadDefaultDecoratorsIsDisabled()) {
return;
}
$decorators = $this->getDecorators();
if (empty($decorators)) {
$this->addDecorator('FormElements')
->addDecorator('HtmlTag', array('tag' => 'dl'))
->addDecorator('Fieldset')
->addDecorator('DtDdWrapper');
}
}
}