import v1.1.0_beta1 | 2009-08-21

This commit is contained in:
2019-07-17 22:16:19 +02:00
parent 2c1152f0d3
commit 8dee6b1a10
2306 changed files with 251360 additions and 23428 deletions

View File

@ -46,7 +46,7 @@ require_once 'Zend/Form/Decorator/Abstract.php';
* @subpackage Decorator
* @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: Callback.php 8064 2008-02-16 10:58:39Z thomas $
* @version $Id: Callback.php 15916 2009-06-06 14:47:55Z matthew $
*/
class Zend_Form_Decorator_Callback extends Zend_Form_Decorator_Abstract
{
@ -59,24 +59,16 @@ class Zend_Form_Decorator_Callback extends Zend_Form_Decorator_Abstract
/**
* Set callback
*
* @param string|array $callback
* @param callback $callback
* @return Zend_Form_Decorator_Callback
* @throws Zend_Form_Exception
*/
public function setCallback($callback)
{
if (!is_string($callback) && !is_array($callback)) {
if (!is_callable($callback)) {
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception('Invalid callback provided to callback decorator');
}
if (is_array($callback)) {
if (2 !== count($callback)) {
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception('Invalid method callback provided to callback decorator');
}
}
$this->_callback = $callback;
return $this;
}

View File

@ -54,6 +54,11 @@ class Zend_Form_Decorator_Captcha_Word extends Zend_Form_Decorator_Abstract
$hiddenName = $name . '[id]';
$textName = $name . '[input]';
$label = $element->getDecorator("Label");
if($label) {
$label->setOption("id", "$name-input");
}
$placement = $this->getPlacement();
$separator = $this->getSeparator();

View File

@ -25,15 +25,15 @@ 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
* 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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: DtDdWrapper.php 9309 2008-04-25 16:06:59Z matthew $
* @version $Id: DtDdWrapper.php 13615 2009-01-13 19:52:10Z norm2782 $
*/
class Zend_Form_Decorator_DtDdWrapper extends Zend_Form_Decorator_Abstract
{
@ -44,17 +44,20 @@ class Zend_Form_Decorator_DtDdWrapper extends Zend_Form_Decorator_Abstract
protected $_placement = null;
/**
* Render
* Render
*
* Renders as the following:
* <dt></dt>
* <dd>$content</dd>
*
* @param string $content
*
* @param string $content
* @return string
*/
public function render($content)
{
return '<dt>&nbsp;</dt><dd>' . $content . '</dd>';
$elementName = $this->getElement()->getName();
return '<dt id="' . $elementName . '-label">&nbsp;</dt>' .
'<dd id="' . $elementName . '-element">' . $content . '</dd>';
}
}

View File

@ -22,11 +22,17 @@
/** 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
@ -34,7 +40,9 @@ require_once 'Zend/Form/Decorator/Abstract.php';
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: $
*/
class Zend_Form_Decorator_File extends Zend_Form_Decorator_Abstract
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
@ -50,7 +58,7 @@ class Zend_Form_Decorator_File extends Zend_Form_Decorator_Abstract
/**
* Get attributes to pass to file helper
*
*
* @return array
*/
public function getAttribs()
@ -72,8 +80,8 @@ class Zend_Form_Decorator_File extends Zend_Form_Decorator_Abstract
/**
* Render a form file
*
* @param string $content
*
* @param string $content
* @return string
*/
public function render($content)
@ -103,6 +111,12 @@ class Zend_Form_Decorator_File extends Zend_Form_Decorator_Abstract
$markup[] = $view->formHidden('MAX_FILE_SIZE', $size);
}
if (Zend_File_Transfer_Adapter_Http::isApcAvailable()) {
$markup[] = $view->formHidden('APC_UPLOAD_PROGRESS', 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();

View File

@ -31,13 +31,13 @@ require_once 'Zend/Form/Decorator/Abstract.php';
* - 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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: FormElements.php 12347 2008-11-06 21:45:56Z matthew $
* @version $Id: FormElements.php 13988 2009-02-05 20:55:38Z thomas $
*/
class Zend_Form_Decorator_FormElements extends Zend_Form_Decorator_Abstract
{
@ -64,7 +64,7 @@ class Zend_Form_Decorator_FormElements extends Zend_Form_Decorator_Abstract
/**
* Render form elements
*
* @param string $content
* @param string $content
* @return string
*/
public function render($content)
@ -97,7 +97,21 @@ class Zend_Form_Decorator_FormElements extends Zend_Form_Decorator_Abstract
$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);

View File

@ -35,13 +35,13 @@ require_once 'Zend/Form/Decorator/Abstract.php';
* - 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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Label.php 12383 2008-11-07 19:38:55Z matthew $
* @version $Id: Label.php 13615 2009-01-13 19:52:10Z norm2782 $
*/
class Zend_Form_Decorator_Label extends Zend_Form_Decorator_Abstract
{
@ -59,8 +59,8 @@ class Zend_Form_Decorator_Label extends Zend_Form_Decorator_Abstract
/**
* Set element ID
*
* @param string $id
*
* @param string $id
* @return Zend_Form_Decorator_Label
*/
public function setId($id)
@ -72,9 +72,9 @@ class Zend_Form_Decorator_Label extends Zend_Form_Decorator_Abstract
/**
* Retrieve element ID (used in 'for' attribute)
*
* If none set in decorator, looks first for element 'id' attribute, and
* If none set in decorator, looks first for element 'id' attribute, and
* defaults to element name.
*
*
* @return string
*/
public function getId()
@ -92,8 +92,8 @@ class Zend_Form_Decorator_Label extends Zend_Form_Decorator_Abstract
/**
* Set HTML tag with which to surround label
*
* @param string $tag
*
* @param string $tag
* @return Zend_Form_Decorator_Label
*/
public function setTag($tag)
@ -108,7 +108,7 @@ class Zend_Form_Decorator_Label extends Zend_Form_Decorator_Abstract
/**
* Get HTML tag, if any, with which to surround label
*
*
* @return void
*/
public function getTag()
@ -128,9 +128,9 @@ class Zend_Form_Decorator_Label extends Zend_Form_Decorator_Abstract
/**
* Get class with which to define label
*
* Appends either 'optional' or 'required' to class, depending on whether
* Appends either 'optional' or 'required' to class, depending on whether
* or not the element is required.
*
*
* @return string
*/
public function getClass()
@ -155,8 +155,8 @@ class Zend_Form_Decorator_Label extends Zend_Form_Decorator_Abstract
/**
* Load an optional/required suffix/prefix key
*
* @param string $key
*
* @param string $key
* @return void
*/
protected function _loadOptReqKey($key)
@ -183,9 +183,9 @@ class Zend_Form_Decorator_Label extends Zend_Form_Decorator_Abstract
* - setOpt(ional)Suffix()
* - setReq(uired)Prefix()
* - setReq(uired)Suffix()
*
* @param string $method
* @param array $args
*
* @param string $method
* @param array $args
* @return mixed
* @throws Zend_Form_Exception for unsupported methods
*/
@ -238,7 +238,7 @@ class Zend_Form_Decorator_Label extends Zend_Form_Decorator_Abstract
/**
* Get label to render
*
*
* @return void
*/
public function getLabel()
@ -278,8 +278,8 @@ class Zend_Form_Decorator_Label extends Zend_Form_Decorator_Abstract
/**
* Render a label
*
* @param string $content
*
* @param string $content
* @return string
*/
public function render($content)
@ -305,7 +305,7 @@ class Zend_Form_Decorator_Label extends Zend_Form_Decorator_Abstract
if (!empty($label)) {
$options['class'] = $class;
$label = $view->formLabel($element->getFullyQualifiedName(), trim($label), $options);
$label = $view->formLabel($element->getFullyQualifiedName(), trim($label), $options);
} else {
$label = '&nbsp;';
}
@ -313,7 +313,9 @@ class Zend_Form_Decorator_Label extends Zend_Form_Decorator_Abstract
if (null !== $tag) {
require_once 'Zend/Form/Decorator/HtmlTag.php';
$decorator = new Zend_Form_Decorator_HtmlTag();
$decorator->setOptions(array('tag' => $tag));
$decorator->setOptions(array('tag' => $tag,
'id' => $this->getElement()->getName() . '-label'));
$label = $decorator->render($label);
}

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-2008 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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Interface.php 8064 2008-02-16 10:58:39Z thomas $
*/
interface Zend_Form_Decorator_Marker_File_Interface
{
}

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-2008 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-2009 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

@ -39,7 +39,7 @@ require_once 'Zend/Form/Decorator/Abstract.php';
* @subpackage Decorator
* @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: ViewHelper.php 12374 2008-11-07 17:49:43Z matthew $
* @version $Id: ViewHelper.php 15671 2009-05-21 22:48:04Z matthew $
*/
class Zend_Form_Decorator_ViewHelper extends Zend_Form_Decorator_Abstract
{
@ -238,6 +238,11 @@ class Zend_Form_Decorator_ViewHelper extends Zend_Form_Decorator_Abstract
$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:

View File

@ -25,7 +25,7 @@
* @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
* @version $Id: DisplayGroup.php 11315 2008-09-09 19:14:31Z matthew $
* @version $Id: DisplayGroup.php 12786 2008-11-23 14:15:48Z matthew $
*/
class Zend_Form_DisplayGroup implements Iterator,Countable
{
@ -645,8 +645,7 @@ class Zend_Form_DisplayGroup implements Iterator,Countable
if (null === $options) {
$decorator = new $class;
} else {
$r = new ReflectionClass($class);
$decorator = $r->newInstance($options);
$decorator = new $class($options);
}
return $decorator;

View File

@ -25,14 +25,14 @@ require_once 'Zend/Filter.php';
require_once 'Zend/Validate/Interface.php';
/**
* Zend_Form_Element
*
* 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: Element.php 12328 2008-11-06 16:49:03Z matthew $
* @version $Id: Element.php 13615 2009-01-13 19:52:10Z norm2782 $
*/
class Zend_Form_Element implements Zend_Validate_Interface
{
@ -68,7 +68,7 @@ class Zend_Form_Element implements Zend_Validate_Interface
protected $_belongsTo;
/**
* Element decorators
* Element decorators
* @var array
*/
protected $_decorators = array();
@ -204,8 +204,8 @@ class Zend_Form_Element implements Zend_Validate_Interface
* - 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
*
* @param string|array|Zend_Config $spec
* @return void
* @throws Zend_Form_Exception if no element name after initialization
*/
@ -217,8 +217,8 @@ class Zend_Form_Element implements Zend_Validate_Interface
$this->setOptions($spec);
} elseif ($spec instanceof Zend_Config) {
$this->setConfig($spec);
}
}
if (is_string($spec) && is_array($options)) {
$this->setOptions($options);
} elseif (is_string($spec) && ($options instanceof Zend_Config)) {
@ -243,7 +243,7 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Initialize object; used by extending classes
*
*
* @return void
*/
public function init()
@ -252,8 +252,8 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Set flag to disable loading default decorators
*
* @param bool $flag
*
* @param bool $flag
* @return Zend_Form_Element
*/
public function setDisableLoadDefaultDecorators($flag)
@ -264,7 +264,7 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Should we load the default decorators?
*
*
* @return bool
*/
public function loadDefaultDecoratorsIsDisabled()
@ -274,7 +274,7 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Load default decorators
*
*
* @return void
*/
public function loadDefaultDecorators()
@ -288,15 +288,16 @@ class Zend_Form_Element implements Zend_Validate_Interface
$this->addDecorator('ViewHelper')
->addDecorator('Errors')
->addDecorator('Description', array('tag' => 'p', 'class' => 'description'))
->addDecorator('HtmlTag', array('tag' => 'dd'))
->addDecorator('HtmlTag', array('tag' => 'dd',
'id' => $this->getName() . '-element'))
->addDecorator('Label', array('tag' => 'dt'));
}
}
/**
* Set object state from options array
*
* @param array $options
*
* @param array $options
* @return Zend_Form_Element
*/
public function setOptions(array $options)
@ -336,8 +337,8 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Set object state from Zend_Config object
*
* @param Zend_Config $config
*
* @param Zend_Config $config
* @return Zend_Form_Element
*/
public function setConfig(Zend_Config $config)
@ -350,8 +351,8 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Set translator object for localization
*
* @param Zend_Translate|null $translator
*
* @param Zend_Translate|null $translator
* @return Zend_Form_Element
*/
public function setTranslator($translator = null)
@ -371,7 +372,7 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Retrieve localization translator object
*
*
* @return Zend_Translate_Adapter|null
*/
public function getTranslator()
@ -389,8 +390,8 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Indicate whether or not translation should be disabled
*
* @param bool $flag
*
* @param bool $flag
* @return Zend_Form_Element
*/
public function setDisableTranslator($flag)
@ -401,7 +402,7 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Is translation disabled?
*
*
* @return bool
*/
public function translatorIsDisabled()
@ -413,8 +414,8 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Filter a name to only allow valid variable characters
*
* @param string $value
*
* @param string $value
* @param bool $allowBrackets
* @return string
*/
@ -429,8 +430,8 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Set element name
*
* @param string $name
*
* @param string $name
* @return Zend_Form_Element
*/
public function setName($name)
@ -447,7 +448,7 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Return element name
*
*
* @return string
*/
public function getName()
@ -459,7 +460,7 @@ class Zend_Form_Element implements Zend_Validate_Interface
* Get fully qualified name
*
* Places name as subitem of array and/or appends brackets.
*
*
* @return string
*/
public function getFullyQualifiedName()
@ -479,7 +480,7 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Get element id
*
*
* @return string
*/
public function getId()
@ -508,8 +509,8 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Set element value
*
* @param mixed $value
*
* @param mixed $value
* @return Zend_Form_Element
*/
public function setValue($value)
@ -520,9 +521,9 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Filter a value
*
* @param string $value
* @param string $key
*
* @param string $value
* @param string $key
* @return void
*/
protected function _filterValue(&$value, &$key)
@ -534,7 +535,7 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Retrieve filtered element value
*
*
* @return mixed
*/
public function getValue()
@ -552,7 +553,7 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Retrieve unfiltered element value
*
*
* @return mixed
*/
public function getUnfilteredValue()
@ -562,8 +563,8 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Set element label
*
* @param string $label
*
* @param string $label
* @return Zend_Form_Element
*/
public function setLabel($label)
@ -574,7 +575,7 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Retrieve element label
*
*
* @return string
*/
public function getLabel()
@ -584,8 +585,8 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Set element order
*
* @param int $order
*
* @param int $order
* @return Zend_Form_Element
*/
public function setOrder($order)
@ -596,7 +597,7 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Retrieve element order
*
*
* @return int
*/
public function getOrder()
@ -606,7 +607,7 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Set required flag
*
*
* @param bool $flag Default value is true
* @return Zend_Form_Element
*/
@ -618,7 +619,7 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Is the element required?
*
*
* @return bool
*/
public function isRequired()
@ -628,8 +629,8 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Set flag indicating whether a NotEmpty validator should be inserted when element is required
*
* @param bool $flag
*
* @param bool $flag
* @return Zend_Form_Element
*/
public function setAutoInsertNotEmptyValidator($flag)
@ -640,7 +641,7 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Get flag indicating whether a NotEmpty validator should be inserted when element is required
*
*
* @return bool
*/
public function autoInsertNotEmptyValidator()
@ -650,8 +651,8 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Set element description
*
* @param string $description
*
* @param string $description
* @return Zend_Form_Element
*/
public function setDescription($description)
@ -662,7 +663,7 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Retrieve element description
*
*
* @return string
*/
public function getDescription()
@ -675,8 +676,8 @@ class Zend_Form_Element implements Zend_Validate_Interface
*
* When the allow empty flag is enabled and the required flag is false, the
* element will validate with empty values.
*
* @param bool $flag
*
* @param bool $flag
* @return Zend_Form_Element
*/
public function setAllowEmpty($flag)
@ -687,7 +688,7 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Get 'allow empty' flag
*
*
* @return bool
*/
public function getAllowEmpty()
@ -697,8 +698,8 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Set ignore flag (used when retrieving values at form level)
*
* @param bool $flag
*
* @param bool $flag
* @return Zend_Form_Element
*/
public function setIgnore($flag)
@ -709,7 +710,7 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Get ignore flag (used when retrieving values at form level)
*
*
* @return bool
*/
public function getIgnore()
@ -719,8 +720,8 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Set flag indicating if element represents an array
*
* @param bool $flag
*
* @param bool $flag
* @return Zend_Form_Element
*/
public function setIsArray($flag)
@ -731,7 +732,7 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Is the element representing an array?
*
*
* @return bool
*/
public function isArray()
@ -741,8 +742,8 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Set array to which element belongs
*
* @param string $array
*
* @param string $array
* @return Zend_Form_Element
*/
public function setBelongsTo($array)
@ -757,7 +758,7 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Return array name to which element belongs
*
*
* @return string
*/
public function getBelongsTo()
@ -767,7 +768,7 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Return element type
*
*
* @return string
*/
public function getType()
@ -781,9 +782,9 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Set element attribute
*
* @param string $name
* @param mixed $value
*
* @param string $name
* @param mixed $value
* @return Zend_Form_Element
* @throws Zend_Form_Exception for invalid $name values
*/
@ -806,8 +807,8 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Set multiple attributes at once
*
* @param array $attribs
*
* @param array $attribs
* @return Zend_Form_Element
*/
public function setAttribs(array $attribs)
@ -821,8 +822,8 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Retrieve element attribute
*
* @param string $name
*
* @param string $name
* @return string
*/
public function getAttrib($name)
@ -837,7 +838,7 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Return all attributes
*
*
* @return array
*/
public function getAttribs()
@ -856,8 +857,8 @@ class Zend_Form_Element implements Zend_Validate_Interface
* Overloading: retrieve object property
*
* Prevents access to properties beginning with '_'.
*
* @param string $key
*
* @param string $key
* @return mixed
*/
public function __get($key)
@ -890,9 +891,9 @@ class Zend_Form_Element implements Zend_Validate_Interface
* Overloading: allow rendering specific decorators
*
* Call renderDecoratorName() to render a specific decorator.
*
* @param string $method
* @param array $args
*
* @param string $method
* @param array $args
* @return string
* @throws Zend_Form_Exception for invalid decorator or invalid method call
*/
@ -921,8 +922,8 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Set plugin loader to use for validator or filter chain
*
* @param Zend_Loader_PluginLoader_Interface $loader
*
* @param Zend_Loader_PluginLoader_Interface $loader
* @param string $type 'decorator', 'filter', or 'validate'
* @return Zend_Form_Element
* @throws Zend_Form_Exception on invalid type
@ -945,10 +946,10 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Retrieve plugin loader for validator or filter chain
*
* Instantiates with default rules if none available for that type. Use
* Instantiates with default rules if none available for that type. Use
* 'decorator', 'filter', or 'validate' for $type.
*
* @param string $type
*
* @param string $type
* @return Zend_Loader_PluginLoader
* @throws Zend_Loader_Exception on invalid type.
*/
@ -981,15 +982,15 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Add prefix path for plugin loader
*
* If no $type specified, assumes it is a base path for both filters and
* If no $type specified, assumes it is a base path for both filters and
* validators, and sets each according to the following rules:
* - decorators: $prefix = $prefix . '_Decorator'
* - filters: $prefix = $prefix . '_Filter'
* - validators: $prefix = $prefix . '_Validate'
*
* Otherwise, the path prefix is set on the appropriate plugin loader.
*
* @param string $path
*
* @param string $path
* @return Zend_Form_Element
* @throws Zend_Form_Exception for invalid type
*/
@ -1022,15 +1023,15 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Add many prefix paths at once
*
* @param array $spec
*
* @param array $spec
* @return Zend_Form_Element
*/
public function addPrefixPaths(array $spec)
{
if (isset($spec['prefix']) && isset($spec['path'])) {
return $this->addPrefixPath($spec['prefix'], $spec['path']);
}
}
foreach ($spec as $type => $paths) {
if (is_numeric($type) && is_array($paths)) {
$type = null;
@ -1068,10 +1069,10 @@ class Zend_Form_Element implements Zend_Validate_Interface
* Add validator to validation chain
*
* Note: will overwrite existing validators if they are of the same class.
*
* @param string|Zend_Validate_Interface $validator
*
* @param string|Zend_Validate_Interface $validator
* @param bool $breakChainOnFailure
* @param array $options
* @param array $options
* @return Zend_Form_Element
* @throws Zend_Form_Exception if invalid validator type
*/
@ -1103,8 +1104,8 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Add multiple validators
*
* @param array $validators
*
* @param array $validators
* @return Zend_Form_Element
*/
public function addValidators(array $validators)
@ -1153,8 +1154,8 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Set multiple validators, overwriting previous validators
*
* @param array $validators
*
* @param array $validators
* @return Zend_Form_Element
*/
public function setValidators(array $validators)
@ -1165,8 +1166,8 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Retrieve a single validator by name
*
* @param string $name
*
* @param string $name
* @return Zend_Validate_Interface|false False if not found, validator otherwise
*/
public function getValidator($name)
@ -1196,7 +1197,7 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Retrieve all validators
*
*
* @return array
*/
public function getValidators()
@ -1215,8 +1216,8 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Remove a single validator by name
*
* @param string $name
*
* @param string $name
* @return bool
*/
public function removeValidator($name)
@ -1241,7 +1242,7 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Clear all validators
*
*
* @return Zend_Form_Element
*/
public function clearValidators()
@ -1253,15 +1254,15 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Validate element value
*
* If a translation adapter is registered, any error messages will be
* translated according to the current locale, using the given error code;
* if no matching translation is found, the original message will be
* If a translation adapter is registered, any error messages will be
* translated according to the current locale, using the given error code;
* if no matching translation is found, the original message will be
* utilized.
*
* Note: The *filtered* value is validated.
*
* @param mixed $value
* @param mixed $context
*
* @param mixed $value
* @param mixed $context
* @return boolean
*/
public function isValid($value, $context = null)
@ -1269,15 +1270,15 @@ class Zend_Form_Element implements Zend_Validate_Interface
$this->setValue($value);
$value = $this->getValue();
if ((('' === $value) || (null === $value))
&& !$this->isRequired()
if ((('' === $value) || (null === $value))
&& !$this->isRequired()
&& $this->getAllowEmpty()
) {
return true;
}
if ($this->isRequired()
&& $this->autoInsertNotEmptyValidator()
if ($this->isRequired()
&& $this->autoInsertNotEmptyValidator()
&& !$this->getValidator('NotEmpty'))
{
$validators = $this->getValidators();
@ -1341,8 +1342,8 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Add a custom error message to return in the event of failed validation
*
* @param string $message
*
* @param string $message
* @return Zend_Form_Element
*/
public function addErrorMessage($message)
@ -1353,8 +1354,8 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Add multiple custom error messages to return in the event of failed validation
*
* @param array $messages
*
* @param array $messages
* @return Zend_Form_Element
*/
public function addErrorMessages(array $messages)
@ -1367,8 +1368,8 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Same as addErrorMessages(), but clears custom error message stack first
*
* @param array $messages
*
* @param array $messages
* @return Zend_Form_Element
*/
public function setErrorMessages(array $messages)
@ -1379,7 +1380,7 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Retrieve custom error messages
*
*
* @return array
*/
public function getErrorMessages()
@ -1389,7 +1390,7 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Clear custom error messages stack
*
*
* @return Zend_Form_Element
*/
public function clearErrorMessages()
@ -1400,7 +1401,7 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Mark the element as being in a failed validation state
*
*
* @return Zend_Form_Element
*/
public function markAsError()
@ -1418,8 +1419,8 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Add an error message and mark element as failed validation
*
* @param string $message
*
* @param string $message
* @return Zend_Form_Element
*/
public function addError($message)
@ -1431,8 +1432,8 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Add multiple error messages and flag element as failed validation
*
* @param array $messages
*
* @param array $messages
* @return Zend_Form_Element
*/
public function addErrors(array $messages)
@ -1445,8 +1446,8 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Overwrite any previously set error messages and flag as failed validation
*
* @param array $messages
*
* @param array $messages
* @return Zend_Form_Element
*/
public function setErrors(array $messages)
@ -1457,7 +1458,7 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Are there errors registered?
*
*
* @return bool
*/
public function hasErrors()
@ -1467,7 +1468,7 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Retrieve validator chain errors
*
*
* @return array
*/
public function getErrors()
@ -1477,7 +1478,7 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Retrieve error messages
*
*
* @return array
*/
public function getMessages()
@ -1490,8 +1491,8 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Add a filter to the element
*
* @param string|Zend_Filter_Interface $filter
*
* @param string|Zend_Filter_Interface $filter
* @return Zend_Form_Element
*/
public function addFilter($filter, $options = array())
@ -1501,7 +1502,7 @@ class Zend_Form_Element implements Zend_Validate_Interface
} elseif (is_string($filter)) {
$name = $filter;
$filter = array(
'filter' => $filter,
'filter' => $filter,
'options' => $options,
);
$this->_filters[$name] = $filter;
@ -1517,8 +1518,8 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Add filters to element
*
* @param array $filters
*
* @param array $filters
* @return Zend_Form_Element
*/
public function addFilters(array $filters)
@ -1561,8 +1562,8 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Add filters to element, overwriting any already existing
*
* @param array $filters
*
* @param array $filters
* @return Zend_Form_Element
*/
public function setFilters(array $filters)
@ -1573,8 +1574,8 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Retrieve a single filter by name
*
* @param string $name
*
* @param string $name
* @return Zend_Filter_Interface
*/
public function getFilter($name)
@ -1605,7 +1606,7 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Get all filters
*
*
* @return array
*/
public function getFilters()
@ -1624,8 +1625,8 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Remove a filter by name
*
* @param string $name
*
* @param string $name
* @return Zend_Form_Element
*/
public function removeFilter($name)
@ -1650,7 +1651,7 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Clear all filters
*
*
* @return Zend_Form_Element
*/
public function clearFilters()
@ -1663,8 +1664,8 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Set view object
*
* @param Zend_View_Interface $view
*
* @param Zend_View_Interface $view
* @return Zend_Form_Element
*/
public function setView(Zend_View_Interface $view = null)
@ -1677,7 +1678,7 @@ class Zend_Form_Element implements Zend_Validate_Interface
* Retrieve view object
*
* Retrieves from ViewRenderer if none previously set.
*
*
* @return null|Zend_View_Interface
*/
public function getView()
@ -1692,9 +1693,9 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Instantiate a decorator based on class name or class name fragment
*
* @param string $name
* @param null|array $options
*
* @param string $name
* @param null|array $options
* @return Zend_Form_Decorator_Interface
*/
protected function _getDecorator($name, $options)
@ -1703,8 +1704,7 @@ class Zend_Form_Element implements Zend_Validate_Interface
if (null === $options) {
$decorator = new $class;
} else {
$r = new ReflectionClass($class);
$decorator = $r->newInstance($options);
$decorator = new $class($options);
}
return $decorator;
@ -1712,8 +1712,8 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Add a decorator for rendering the element
*
* @param string|Zend_Form_Decorator_Interface $decorator
*
* @param string|Zend_Form_Decorator_Interface $decorator
* @param array|Zend_Config $options Options with which to initialize decorator
* @return Zend_Form_Element
*/
@ -1755,8 +1755,8 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Add many decorators at once
*
* @param array $decorators
*
* @param array $decorators
* @return Zend_Form_Element
*/
public function addDecorators(array $decorators)
@ -1799,8 +1799,8 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Overwrite all decorators
*
* @param array $decorators
*
* @param array $decorators
* @return Zend_Form_Element
*/
public function setDecorators(array $decorators)
@ -1811,8 +1811,8 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Retrieve a registered decorator
*
* @param string $name
*
* @param string $name
* @return false|Zend_Form_Decorator_Abstract
*/
public function getDecorator($name)
@ -1843,7 +1843,7 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Retrieve all decorators
*
*
* @return array
*/
public function getDecorators()
@ -1858,8 +1858,8 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Remove a single decorator
*
* @param string $name
*
* @param string $name
* @return bool
*/
public function removeDecorator($name)
@ -1884,7 +1884,7 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Clear all decorators
*
*
* @return Zend_Form_Element
*/
public function clearDecorators()
@ -1895,8 +1895,8 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Render form element
*
* @param Zend_View_Interface $view
*
* @param Zend_View_Interface $view
* @return string
*/
public function render(Zend_View_Interface $view = null)
@ -1917,7 +1917,7 @@ class Zend_Form_Element implements Zend_Validate_Interface
* String representation of form element
*
* Proxies to {@link render()}.
*
*
* @return string
*/
public function __toString()
@ -1933,8 +1933,8 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Lazy-load a filter
*
* @param array $filter
*
* @param array $filter
* @return Zend_Filter_Interface
*/
protected function _loadFilter(array $filter)
@ -1982,7 +1982,7 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Lazy-load a validator
*
*
* @param array $validator Validator definition
* @return Zend_Validate_Interface
*/
@ -2047,7 +2047,7 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Lazy-load a decorator
*
*
* @param array $decorator Decorator type and options
* @param mixed $name Decorator name or alias
* @return Zend_Form_Decorator_Interface
@ -2085,7 +2085,7 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Retrieve error messages and perform translation and value substitution
*
*
* @return array
*/
protected function _getErrorMessages()
@ -2112,7 +2112,7 @@ class Zend_Form_Element implements Zend_Validate_Interface
/**
* Are there custom error messages registered?
*
*
* @return bool
*/
protected function _hasErrorMessages()

View File

@ -1,4 +1,23 @@
<?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';
@ -15,6 +34,11 @@ require_once 'Zend/Captcha/Adapter.php';
*
* @see http://en.wikipedia.org/wiki/Captcha
*
* @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_Captcha extends Zend_Form_Element_Xhtml
{
@ -101,6 +125,24 @@ class Zend_Form_Element_Captcha extends Zend_Form_Element_Xhtml
->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
*

View File

@ -29,7 +29,7 @@ require_once 'Zend/Form/Element/Xhtml.php';
* @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 $
* @version $Id: File.php 15768 2009-05-25 20:34:32Z thomas $
*/
class Zend_Form_Element_File extends Zend_Form_Element_Xhtml
{
@ -53,6 +53,11 @@ class Zend_Form_Element_File extends Zend_Form_Element_Xhtml
*/
protected $_validated = false;
/**
* @var boolean Disable value to be equal to file content
*/
protected $_valueDisabled = false;
/**
* @var integer Internal multifile counter
*/
@ -61,7 +66,7 @@ class Zend_Form_Element_File extends Zend_Form_Element_Xhtml
/**
* @var integer Maximum file size for MAX_FILE_SIZE attribut of form
*/
protected static $_maxFileSize = 0;
protected static $_maxFileSize = -1;
/**
* Load default decorators
@ -78,6 +83,7 @@ class Zend_Form_Element_File extends Zend_Form_Element_Xhtml
if (empty($decorators)) {
$this->addDecorator('File')
->addDecorator('Errors')
->addDecorator('Description')
->addDecorator('HtmlTag', array('tag' => 'dd'))
->addDecorator('Label', array('tag' => 'dt'));
}
@ -145,7 +151,7 @@ class Zend_Form_Element_File extends Zend_Form_Element_Xhtml
if (empty($type)) {
$pluginPrefix = rtrim($prefix, '_') . '_Transfer_Adapter';
$pluginPath = rtrim($path, DIRECTORY_SEPARATOR) . '/Transfer/Adapter/';
$loader = $this->getPluginLoader(self::TRANSFER_ADAPTER);
$loader = $this->getPluginLoader(self::TRANSFER_ADAPTER);
$loader->addPrefixPath($pluginPrefix, $pluginPath);
return parent::addPrefixPath($prefix, $path, null);
}
@ -174,6 +180,11 @@ class Zend_Form_Element_File extends Zend_Form_Element_Xhtml
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;
}
@ -407,7 +418,11 @@ class Zend_Form_Element_File extends Zend_Form_Element_Xhtml
return true;
}
$adapter = $this->getTransferAdapter();
$adapter = $this->getTransferAdapter();
$translator = $this->getTranslator();
if ($translator !== null) {
$adapter->setTranslator($translator);
}
if (!$this->isRequired()) {
$adapter->setOptions(array('ignoreNoFile' => true), $this->getName());
@ -435,13 +450,12 @@ class Zend_Form_Element_File extends Zend_Form_Element_Xhtml
/**
* Receive the uploaded file
*
* @param string $value
* @return boolean
*/
public function receive($value = null)
public function receive()
{
if (!$this->_validated) {
if (!$this->isValid($value)) {
if (!$this->isValid($this->getName())) {
return false;
}
}
@ -461,7 +475,7 @@ class Zend_Form_Element_File extends Zend_Form_Element_Xhtml
*/
public function getErrors()
{
return $this->getTransferAdapter()->getErrors();
return parent::getErrors() + $this->getTransferAdapter()->getErrors();
}
/**
@ -471,7 +485,7 @@ class Zend_Form_Element_File extends Zend_Form_Element_Xhtml
*/
public function hasErrors()
{
return $this->getTransferAdapter()->hasErrors();
return (parent::hasErrors() || $this->getTransferAdapter()->hasErrors());
}
/**
@ -481,7 +495,7 @@ class Zend_Form_Element_File extends Zend_Form_Element_Xhtml
*/
public function getMessages()
{
return $this->getTransferAdapter()->getMessages();
return parent::getMessages() + $this->getTransferAdapter()->getMessages();
}
/**
@ -509,16 +523,32 @@ class Zend_Form_Element_File extends Zend_Form_Element_Xhtml
/**
* Get the final filename
*
* @param string $value (Optional) Element or file to return
* @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)
public function getFileName($value = null, $path = true)
{
if (empty($value)) {
$value = $this->getName();
}
return $this->getTransferAdapter()->getFileName($value);
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);
}
/**
@ -553,23 +583,107 @@ class Zend_Form_Element_File extends Zend_Form_Element_Xhtml
/**
* Sets the maximum file size of the form
*
* @param integer $size
* @return integer
*/
public function setMaxFileSize($size)
public function getMaxFileSize()
{
self::$_maxFileSize = $size;
return $this;
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 getMaxFileSize()
public function setMaxFileSize($size)
{
return self::$_maxFileSize;
$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;
}
/**
@ -580,12 +694,12 @@ class Zend_Form_Element_File extends Zend_Form_Element_Xhtml
*/
public function getValue()
{
if (!is_null($this->_value)) {
if ($this->_value !== null) {
return $this->_value;
}
$content = current($this->getTransferAdapter()->getFileInfo($this->getName()));
if (!isset($content['name'])) {
$content = $this->getTransferAdapter()->getFileName($this->getName());
if (empty($content)) {
return null;
}
@ -593,13 +707,11 @@ class Zend_Form_Element_File extends Zend_Form_Element_Xhtml
return null;
}
if (!$this->receive()) {
if (!$this->_valueDisabled && !$this->receive()) {
return null;
}
$filename = basename($this->getFileName());
$this->_value = $filename;
return $filename;
return $this->getFileName(null, false);
}
/**
@ -612,4 +724,179 @@ class Zend_Form_Element_File extends Zend_Form_Element_Xhtml
{
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()
{
$adapter = $this->getTransferAdapter();
return $adapter->getTranslator();
}
/**
* 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

@ -30,7 +30,7 @@ require_once 'Zend/Form/Element/Xhtml.php';
* @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 $
* @version $Id: Image.php 14637 2009-04-04 13:53:25Z mcleod@spaceweb.nl $
*/
class Zend_Form_Element_Image extends Zend_Form_Element_Xhtml
{
@ -65,7 +65,8 @@ class Zend_Form_Element_Image extends Zend_Form_Element_Xhtml
$decorators = $this->getDecorators();
if (empty($decorators)) {
$this->addDecorator('Image')
$this->addDecorator('Tooltip')
->addDecorator('Image')
->addDecorator('Errors')
->addDecorator('HtmlTag', array('tag' => 'dd'))
->addDecorator('Label', array('tag' => 'dt'));
@ -126,4 +127,5 @@ class Zend_Form_Element_Image extends Zend_Form_Element_Xhtml
$imageValue = $this->getImageValue();
return ((null !== $imageValue) && ($this->getValue() == $imageValue));
}
}

View File

@ -30,7 +30,7 @@ require_once 'Zend/Form/Element/Xhtml.php';
* @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 $
* @version $Id: Multi.php 16137 2009-06-18 18:38:25Z matthew $
*/
abstract class Zend_Form_Element_Multi extends Zend_Form_Element_Xhtml
{
@ -278,7 +278,7 @@ abstract class Zend_Form_Element_Multi extends Zend_Form_Element_Xhtml
protected function _translateOption($option, $value)
{
if ($this->translatorIsDisabled()) {
return true;
return false;
}
if (!isset($this->_translated[$option]) && !empty($value)) {

View File

@ -30,7 +30,7 @@ require_once 'Zend/Form/Element/Xhtml.php';
* @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 $
* @version $Id: Submit.php 14637 2009-04-04 13:53:25Z mcleod@spaceweb.nl $
*/
class Zend_Form_Element_Submit extends Zend_Form_Element_Xhtml
{
@ -114,7 +114,8 @@ class Zend_Form_Element_Submit extends Zend_Form_Element_Xhtml
$decorators = $this->getDecorators();
if (empty($decorators)) {
$this->addDecorator('ViewHelper')
$this->addDecorator('Tooltip')
->addDecorator('ViewHelper')
->addDecorator('DtDdWrapper');
}
}