import v1.0.0-RC4 | 2009-05-20
This commit is contained in:
42
libs/Zend/Form/Element/Button.php
Normal file
42
libs/Zend/Form/Element/Button.php
Normal 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-2008 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-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Button.php 8064 2008-02-16 10:58:39Z thomas $
|
||||
*/
|
||||
class Zend_Form_Element_Button extends Zend_Form_Element_Submit
|
||||
{
|
||||
/**
|
||||
* Use formButton view helper by default
|
||||
* @var string
|
||||
*/
|
||||
public $helper = 'formButton';
|
||||
}
|
260
libs/Zend/Form/Element/Captcha.php
Normal file
260
libs/Zend/Form/Element/Captcha.php
Normal file
@ -0,0 +1,260 @@
|
||||
<?php
|
||||
|
||||
/** Zend_Form_Element_Xhtml */
|
||||
require_once 'Zend/Form/Element/Xhtml.php';
|
||||
|
||||
/** 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
|
||||
*
|
||||
*/
|
||||
class Zend_Form_Element_Captcha extends Zend_Form_Element_Xhtml
|
||||
{
|
||||
/**
|
||||
* @const string Captch 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set options
|
||||
*
|
||||
* Overrides to allow passing captcha options
|
||||
*
|
||||
* @param array $options
|
||||
* @return Zend_Form_Element_Captcha
|
||||
*/
|
||||
public function setOptions(array $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 parent::setOptions($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 $path
|
||||
* @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);
|
||||
}
|
||||
}
|
209
libs/Zend/Form/Element/Checkbox.php
Normal file
209
libs/Zend/Form/Element/Checkbox.php
Normal file
@ -0,0 +1,209 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Form
|
||||
* @subpackage Element
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/** Zend_Form_Element_Xhtml */
|
||||
require_once 'Zend/Form/Element/Xhtml.php';
|
||||
|
||||
/**
|
||||
* Checkbox form element
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Form
|
||||
* @subpackage Element
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Checkbox.php 9323 2008-04-25 21:13:17Z matthew $
|
||||
*/
|
||||
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';
|
||||
|
||||
/**
|
||||
* 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;
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render
|
||||
*
|
||||
* Ensure that options property is set when rendering.
|
||||
*
|
||||
* @param Zend_View_Interface $view
|
||||
* @return string
|
||||
*/
|
||||
public function render(Zend_View_Interface $view = null)
|
||||
{
|
||||
$this->options = array(
|
||||
'checked' => $this->getCheckedValue(),
|
||||
'unChecked' => $this->getUncheckedValue(),
|
||||
);
|
||||
return parent::render($view);
|
||||
}
|
||||
}
|
37
libs/Zend/Form/Element/Exception.php
Normal file
37
libs/Zend/Form/Element/Exception.php
Normal 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-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: Exception.php 8064 2008-02-16 10:58:39Z thomas $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/** Zend_Form_Exception */
|
||||
require_once 'Zend/Form/Exception.php';
|
||||
|
||||
/**
|
||||
* Exception for Zend_Form component.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Form
|
||||
* @subpackage Element
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Form_Element_Exception extends Zend_Form_Exception
|
||||
{
|
||||
}
|
615
libs/Zend/Form/Element/File.php
Normal file
615
libs/Zend/Form/Element/File.php
Normal file
@ -0,0 +1,615 @@
|
||||
<?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-2008 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-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: File.php 12267 2008-11-02 21:13:14Z thomas $
|
||||
*/
|
||||
class Zend_Form_Element_File extends Zend_Form_Element_Xhtml
|
||||
{
|
||||
/**
|
||||
* @const string 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 integer Internal multifile counter
|
||||
*/
|
||||
protected $_counter = 1;
|
||||
|
||||
/**
|
||||
* @var integer Maximum file size for MAX_FILE_SIZE attribut of form
|
||||
*/
|
||||
protected static $_maxFileSize = 0;
|
||||
|
||||
/**
|
||||
* Load default decorators
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function loadDefaultDecorators()
|
||||
{
|
||||
if ($this->loadDefaultDecoratorsIsDisabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$decorators = $this->getDecorators();
|
||||
if (empty($decorators)) {
|
||||
$this->addDecorator('File')
|
||||
->addDecorator('Errors')
|
||||
->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');
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
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
|
||||
*
|
||||
* @param string $value
|
||||
* @return boolean
|
||||
*/
|
||||
public function receive($value = null)
|
||||
{
|
||||
if (!$this->_validated) {
|
||||
if (!$this->isValid($value)) {
|
||||
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 $this->getTransferAdapter()->getErrors();
|
||||
}
|
||||
|
||||
/**
|
||||
* Are there errors registered?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasErrors()
|
||||
{
|
||||
return $this->getTransferAdapter()->hasErrors();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve error messages; proxy to transfer adapter
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMessages()
|
||||
{
|
||||
return $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
|
||||
* @return string
|
||||
*/
|
||||
public function getFileName($value = null)
|
||||
{
|
||||
if (empty($value)) {
|
||||
$value = $this->getName();
|
||||
}
|
||||
|
||||
return $this->getTransferAdapter()->getFileName($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
|
||||
*
|
||||
* @param integer $size
|
||||
* @return integer
|
||||
*/
|
||||
public function setMaxFileSize($size)
|
||||
{
|
||||
self::$_maxFileSize = $size;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the maximum file size of the form
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getMaxFileSize()
|
||||
{
|
||||
return self::$_maxFileSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the file, returns null or the filename only
|
||||
* For the complete path, use getFileName
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
if (!is_null($this->_value)) {
|
||||
return $this->_value;
|
||||
}
|
||||
|
||||
$content = current($this->getTransferAdapter()->getFileInfo($this->getName()));
|
||||
if (!isset($content['name'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!$this->isValid(null)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!$this->receive()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$filename = basename($this->getFileName());
|
||||
$this->_value = $filename;
|
||||
return $filename;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disallow setting the value
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return Zend_Form_Element_File
|
||||
*/
|
||||
public function setValue($value)
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
}
|
259
libs/Zend/Form/Element/Hash.php
Normal file
259
libs/Zend/Form/Element/Hash.php
Normal 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-2008 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-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Hash.php 11332 2008-09-10 16:35:45Z matthew $
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
42
libs/Zend/Form/Element/Hidden.php
Normal file
42
libs/Zend/Form/Element/Hidden.php
Normal 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-2008 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-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Hidden.php 8064 2008-02-16 10:58:39Z thomas $
|
||||
*/
|
||||
class Zend_Form_Element_Hidden extends Zend_Form_Element_Xhtml
|
||||
{
|
||||
/**
|
||||
* Use formHidden view helper by default
|
||||
* @var string
|
||||
*/
|
||||
public $helper = 'formHidden';
|
||||
}
|
129
libs/Zend/Form/Element/Image.php
Normal file
129
libs/Zend/Form/Element/Image.php
Normal file
@ -0,0 +1,129 @@
|
||||
<?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-2008 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-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Image.php 8680 2008-03-07 22:25:35Z matthew $
|
||||
*/
|
||||
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('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));
|
||||
}
|
||||
}
|
318
libs/Zend/Form/Element/Multi.php
Normal file
318
libs/Zend/Form/Element/Multi.php
Normal 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-2008 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-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Multi.php 12527 2008-11-10 21:00:57Z thomas $
|
||||
*/
|
||||
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 true;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
52
libs/Zend/Form/Element/MultiCheckbox.php
Normal file
52
libs/Zend/Form/Element/MultiCheckbox.php
Normal 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-2008 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-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: MultiCheckbox.php 8628 2008-03-07 15:04:13Z matthew $
|
||||
*/
|
||||
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;
|
||||
}
|
54
libs/Zend/Form/Element/Multiselect.php
Normal file
54
libs/Zend/Form/Element/Multiselect.php
Normal 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-2008 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-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Multiselect.php 8628 2008-03-07 15:04:13Z matthew $
|
||||
*/
|
||||
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;
|
||||
}
|
88
libs/Zend/Form/Element/Password.php
Normal file
88
libs/Zend/Form/Element/Password.php
Normal file
@ -0,0 +1,88 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Form
|
||||
* @subpackage Element
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/** Zend_Form_Element_Xhtml */
|
||||
require_once 'Zend/Form/Element/Xhtml.php';
|
||||
|
||||
/**
|
||||
* Password form element
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Form
|
||||
* @subpackage Element
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Password.php 9337 2008-04-28 18:14:48Z matthew $
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
42
libs/Zend/Form/Element/Radio.php
Normal file
42
libs/Zend/Form/Element/Radio.php
Normal 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-2008 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-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Radio.php 8064 2008-02-16 10:58:39Z thomas $
|
||||
*/
|
||||
class Zend_Form_Element_Radio extends Zend_Form_Element_Multi
|
||||
{
|
||||
/**
|
||||
* Use formRadio view helper by default
|
||||
* @var string
|
||||
*/
|
||||
public $helper = 'formRadio';
|
||||
}
|
42
libs/Zend/Form/Element/Reset.php
Normal file
42
libs/Zend/Form/Element/Reset.php
Normal 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-2008 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-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Reset.php 8064 2008-02-16 10:58:39Z thomas $
|
||||
*/
|
||||
class Zend_Form_Element_Reset extends Zend_Form_Element_Submit
|
||||
{
|
||||
/**
|
||||
* Use formReset view helper by default
|
||||
* @var string
|
||||
*/
|
||||
public $helper = 'formReset';
|
||||
}
|
42
libs/Zend/Form/Element/Select.php
Normal file
42
libs/Zend/Form/Element/Select.php
Normal 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-2008 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-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Select.php 8064 2008-02-16 10:58:39Z thomas $
|
||||
*/
|
||||
class Zend_Form_Element_Select extends Zend_Form_Element_Multi
|
||||
{
|
||||
/**
|
||||
* Use formSelect view helper by default
|
||||
* @var string
|
||||
*/
|
||||
public $helper = 'formSelect';
|
||||
}
|
121
libs/Zend/Form/Element/Submit.php
Normal file
121
libs/Zend/Form/Element/Submit.php
Normal file
@ -0,0 +1,121 @@
|
||||
<?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-2008 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-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Submit.php 8585 2008-03-06 19:32:34Z matthew $
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
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('ViewHelper')
|
||||
->addDecorator('DtDdWrapper');
|
||||
}
|
||||
}
|
||||
}
|
42
libs/Zend/Form/Element/Text.php
Normal file
42
libs/Zend/Form/Element/Text.php
Normal 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-2008 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-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Text.php 8064 2008-02-16 10:58:39Z thomas $
|
||||
*/
|
||||
class Zend_Form_Element_Text extends Zend_Form_Element_Xhtml
|
||||
{
|
||||
/**
|
||||
* Default form view helper to use for rendering
|
||||
* @var string
|
||||
*/
|
||||
public $helper = 'formText';
|
||||
}
|
42
libs/Zend/Form/Element/Textarea.php
Normal file
42
libs/Zend/Form/Element/Textarea.php
Normal 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-2008 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-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Textarea.php 8064 2008-02-16 10:58:39Z thomas $
|
||||
*/
|
||||
class Zend_Form_Element_Textarea extends Zend_Form_Element_Xhtml
|
||||
{
|
||||
/**
|
||||
* Use formTextarea view helper by default
|
||||
* @var string
|
||||
*/
|
||||
public $helper = 'formTextarea';
|
||||
}
|
37
libs/Zend/Form/Element/Xhtml.php
Normal file
37
libs/Zend/Form/Element/Xhtml.php
Normal 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-2008 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-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Xhtml.php 8064 2008-02-16 10:58:39Z thomas $
|
||||
*/
|
||||
abstract class Zend_Form_Element_Xhtml extends Zend_Form_Element
|
||||
{
|
||||
}
|
Reference in New Issue
Block a user