From 8ca6cc32b2c789a3149861159ad258f2cb9491e3 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 14:39:39 +0200 Subject: Adding upstream version 2.11.4. Signed-off-by: Daniel Baumann --- library/vendor/Zend/Form/Decorator/Abstract.php | 251 +++ library/vendor/Zend/Form/Decorator/Callback.php | 126 ++ library/vendor/Zend/Form/Decorator/Captcha.php | 71 + library/vendor/Zend/Form/Decorator/Description.php | 197 ++ library/vendor/Zend/Form/Decorator/DtDdWrapper.php | 69 + library/vendor/Zend/Form/Decorator/Errors.php | 76 + library/vendor/Zend/Form/Decorator/Exception.php | 36 + library/vendor/Zend/Form/Decorator/Fieldset.php | 156 ++ library/vendor/Zend/Form/Decorator/File.php | 140 ++ library/vendor/Zend/Form/Decorator/Form.php | 133 ++ .../vendor/Zend/Form/Decorator/FormElements.php | 140 ++ library/vendor/Zend/Form/Decorator/FormErrors.php | 514 +++++ library/vendor/Zend/Form/Decorator/HtmlTag.php | 253 +++ library/vendor/Zend/Form/Decorator/Image.php | 152 ++ library/vendor/Zend/Form/Decorator/Interface.php | 123 ++ library/vendor/Zend/Form/Decorator/Label.php | 461 ++++ .../Zend/Form/Decorator/Marker/File/Interface.php | 33 + .../vendor/Zend/Form/Decorator/PrepareElements.php | 89 + library/vendor/Zend/Form/Decorator/Tooltip.php | 57 + library/vendor/Zend/Form/Decorator/ViewHelper.php | 266 +++ library/vendor/Zend/Form/Decorator/ViewScript.php | 190 ++ library/vendor/Zend/Form/DisplayGroup.php | 1172 ++++++++++ library/vendor/Zend/Form/Element.php | 2280 ++++++++++++++++++++ library/vendor/Zend/Form/Element/Button.php | 55 + library/vendor/Zend/Form/Element/Checkbox.php | 202 ++ library/vendor/Zend/Form/Element/Exception.php | 36 + library/vendor/Zend/Form/Element/File.php | 910 ++++++++ library/vendor/Zend/Form/Element/Hidden.php | 41 + library/vendor/Zend/Form/Element/Image.php | 131 ++ library/vendor/Zend/Form/Element/Multi.php | 316 +++ library/vendor/Zend/Form/Element/MultiCheckbox.php | 72 + library/vendor/Zend/Form/Element/Multiselect.php | 53 + library/vendor/Zend/Form/Element/Note.php | 63 + library/vendor/Zend/Form/Element/Password.php | 87 + library/vendor/Zend/Form/Element/Radio.php | 65 + library/vendor/Zend/Form/Element/Reset.php | 41 + library/vendor/Zend/Form/Element/Select.php | 47 + library/vendor/Zend/Form/Element/Submit.php | 126 ++ library/vendor/Zend/Form/Element/Text.php | 41 + library/vendor/Zend/Form/Element/Textarea.php | 41 + library/vendor/Zend/Form/Element/Xhtml.php | 36 + library/vendor/Zend/Form/Exception.php | 34 + library/vendor/Zend/Form/SubForm.php | 60 + 43 files changed, 9442 insertions(+) create mode 100644 library/vendor/Zend/Form/Decorator/Abstract.php create mode 100644 library/vendor/Zend/Form/Decorator/Callback.php create mode 100644 library/vendor/Zend/Form/Decorator/Captcha.php create mode 100644 library/vendor/Zend/Form/Decorator/Description.php create mode 100644 library/vendor/Zend/Form/Decorator/DtDdWrapper.php create mode 100644 library/vendor/Zend/Form/Decorator/Errors.php create mode 100644 library/vendor/Zend/Form/Decorator/Exception.php create mode 100644 library/vendor/Zend/Form/Decorator/Fieldset.php create mode 100644 library/vendor/Zend/Form/Decorator/File.php create mode 100644 library/vendor/Zend/Form/Decorator/Form.php create mode 100644 library/vendor/Zend/Form/Decorator/FormElements.php create mode 100644 library/vendor/Zend/Form/Decorator/FormErrors.php create mode 100644 library/vendor/Zend/Form/Decorator/HtmlTag.php create mode 100644 library/vendor/Zend/Form/Decorator/Image.php create mode 100644 library/vendor/Zend/Form/Decorator/Interface.php create mode 100644 library/vendor/Zend/Form/Decorator/Label.php create mode 100644 library/vendor/Zend/Form/Decorator/Marker/File/Interface.php create mode 100644 library/vendor/Zend/Form/Decorator/PrepareElements.php create mode 100644 library/vendor/Zend/Form/Decorator/Tooltip.php create mode 100644 library/vendor/Zend/Form/Decorator/ViewHelper.php create mode 100644 library/vendor/Zend/Form/Decorator/ViewScript.php create mode 100644 library/vendor/Zend/Form/DisplayGroup.php create mode 100644 library/vendor/Zend/Form/Element.php create mode 100644 library/vendor/Zend/Form/Element/Button.php create mode 100644 library/vendor/Zend/Form/Element/Checkbox.php create mode 100644 library/vendor/Zend/Form/Element/Exception.php create mode 100644 library/vendor/Zend/Form/Element/File.php create mode 100644 library/vendor/Zend/Form/Element/Hidden.php create mode 100644 library/vendor/Zend/Form/Element/Image.php create mode 100644 library/vendor/Zend/Form/Element/Multi.php create mode 100644 library/vendor/Zend/Form/Element/MultiCheckbox.php create mode 100644 library/vendor/Zend/Form/Element/Multiselect.php create mode 100644 library/vendor/Zend/Form/Element/Note.php create mode 100644 library/vendor/Zend/Form/Element/Password.php create mode 100644 library/vendor/Zend/Form/Element/Radio.php create mode 100644 library/vendor/Zend/Form/Element/Reset.php create mode 100644 library/vendor/Zend/Form/Element/Select.php create mode 100644 library/vendor/Zend/Form/Element/Submit.php create mode 100644 library/vendor/Zend/Form/Element/Text.php create mode 100644 library/vendor/Zend/Form/Element/Textarea.php create mode 100644 library/vendor/Zend/Form/Element/Xhtml.php create mode 100644 library/vendor/Zend/Form/Exception.php create mode 100644 library/vendor/Zend/Form/SubForm.php (limited to 'library/vendor/Zend/Form') diff --git a/library/vendor/Zend/Form/Decorator/Abstract.php b/library/vendor/Zend/Form/Decorator/Abstract.php new file mode 100644 index 0000000..93c5a05 --- /dev/null +++ b/library/vendor/Zend/Form/Decorator/Abstract.php @@ -0,0 +1,251 @@ +setOptions($options); + } elseif ($options instanceof Zend_Config) { + $this->setConfig($options); + } + } + + /** + * Set options + * + * @param array $options + * @return Zend_Form_Decorator_Abstract + */ + public function setOptions(array $options) + { + $this->_options = $options; + return $this; + } + + /** + * Set options from config object + * + * @param Zend_Config $config + * @return Zend_Form_Decorator_Abstract + */ + public function setConfig(Zend_Config $config) + { + return $this->setOptions($config->toArray()); + } + + /** + * Set option + * + * @param string $key + * @param mixed $value + * @return Zend_Form_Decorator_Abstract + */ + public function setOption($key, $value) + { + $this->_options[(string) $key] = $value; + return $this; + } + + /** + * Get option + * + * @param string $key + * @return mixed + */ + public function getOption($key) + { + $key = (string) $key; + if (isset($this->_options[$key])) { + return $this->_options[$key]; + } + + return null; + } + + /** + * Retrieve options + * + * @return array + */ + public function getOptions() + { + return $this->_options; + } + + /** + * Remove single option + * + * @param mixed $key + * @return void + */ + public function removeOption($key) + { + if (null !== $this->getOption($key)) { + unset($this->_options[$key]); + return true; + } + + return false; + } + + /** + * Clear all options + * + * @return Zend_Form_Decorator_Abstract + */ + public function clearOptions() + { + $this->_options = array(); + return $this; + } + + /** + * Set current form element + * + * @param Zend_Form_Element|Zend_Form $element + * @return Zend_Form_Decorator_Abstract + * @throws Zend_Form_Decorator_Exception on invalid element type + */ + public function setElement($element) + { + if ((!$element instanceof Zend_Form_Element) + && (!$element instanceof Zend_Form) + && (!$element instanceof Zend_Form_DisplayGroup)) + { + throw new Zend_Form_Decorator_Exception('Invalid element type passed to decorator'); + } + + $this->_element = $element; + return $this; + } + + /** + * Retrieve current element + * + * @return Zend_Form_Element|Zend_Form + */ + public function getElement() + { + return $this->_element; + } + + /** + * Determine if decorator should append or prepend content + * + * @return string + */ + public function getPlacement() + { + $placement = $this->_placement; + if (null !== ($placementOpt = $this->getOption('placement'))) { + $placementOpt = strtoupper($placementOpt); + switch ($placementOpt) { + case self::APPEND: + case self::PREPEND: + $placement = $this->_placement = $placementOpt; + break; + case false: + $placement = $this->_placement = null; + break; + default: + break; + } + $this->removeOption('placement'); + } + + return $placement; + } + + /** + * Retrieve separator to use between old and new content + * + * @return string + */ + public function getSeparator() + { + $separator = $this->_separator; + if (null !== ($separatorOpt = $this->getOption('separator'))) { + $separator = $this->_separator = (string) $separatorOpt; + $this->removeOption('separator'); + } + return $separator; + } + + /** + * Decorate content and/or element + * + * @param string $content + * @return string + * @throws Zend_Form_Decorator_Exception when unimplemented + */ + public function render($content) + { + throw new Zend_Form_Decorator_Exception('render() not implemented'); + } +} diff --git a/library/vendor/Zend/Form/Decorator/Callback.php b/library/vendor/Zend/Form/Decorator/Callback.php new file mode 100644 index 0000000..fb759fd --- /dev/null +++ b/library/vendor/Zend/Form/Decorator/Callback.php @@ -0,0 +1,126 @@ +_callback = $callback; + return $this; + } + + /** + * Get registered callback + * + * If not previously registered, checks to see if it exists in registered + * options. + * + * @return null|string|array + */ + public function getCallback() + { + if (null === $this->_callback) { + if (null !== ($callback = $this->getOption('callback'))) { + $this->setCallback($callback); + $this->removeOption('callback'); + } + } + + return $this->_callback; + } + + /** + * Render + * + * If no callback registered, returns callback. Otherwise, gets return + * value of callback and either appends, prepends, or replaces passed in + * content. + * + * @param string $content + * @return string + */ + public function render($content) + { + $callback = $this->getCallback(); + if (null === $callback) { + return $content; + } + + $placement = $this->getPlacement(); + $separator = $this->getSeparator(); + + $response = call_user_func($callback, $content, $this->getElement(), $this->getOptions()); + + switch ($placement) { + case self::APPEND: + return $content . $separator . $response; + case self::PREPEND: + return $response . $separator . $content; + default: + // replace content + return $response; + } + } +} diff --git a/library/vendor/Zend/Form/Decorator/Captcha.php b/library/vendor/Zend/Form/Decorator/Captcha.php new file mode 100644 index 0000000..914189e --- /dev/null +++ b/library/vendor/Zend/Form/Decorator/Captcha.php @@ -0,0 +1,71 @@ +getElement(); + if (!method_exists($element, 'getCaptcha')) { + return $content; + } + + $view = $element->getView(); + if (null === $view) { + return $content; + } + + $placement = $this->getPlacement(); + $separator = $this->getSeparator(); + + $captcha = $element->getCaptcha(); + $markup = $captcha->render($view, $element); + switch ($placement) { + case 'PREPEND': + $content = $markup . $separator . $content; + break; + case 'APPEND': + default: + $content = $content . $separator . $markup; + } + return $content; + } +} diff --git a/library/vendor/Zend/Form/Decorator/Description.php b/library/vendor/Zend/Form/Decorator/Description.php new file mode 100644 index 0000000..63dfdbc --- /dev/null +++ b/library/vendor/Zend/Form/Decorator/Description.php @@ -0,0 +1,197 @@ +_tag = (string) $tag; + return $this; + } + + /** + * Get HTML tag, if any, with which to surround description + * + * @return string + */ + public function getTag() + { + if (null === $this->_tag) { + $tag = $this->getOption('tag'); + if (null !== $tag) { + $this->removeOption('tag'); + } else { + $tag = 'p'; + } + + $this->setTag($tag); + return $tag; + } + + return $this->_tag; + } + + /** + * Get class with which to define description + * + * Defaults to 'hint' + * + * @return string + */ + public function getClass() + { + $class = $this->getOption('class'); + if (null === $class) { + $class = 'hint'; + $this->setOption('class', $class); + } + + return $class; + } + + /** + * Set whether or not to escape description + * + * @param bool $flag + * @return Zend_Form_Decorator_Description + */ + public function setEscape($flag) + { + $this->_escape = (bool) $flag; + return $this; + } + + /** + * Get escape flag + * + * @return true + */ + public function getEscape() + { + if (null === $this->_escape) { + if (null !== ($escape = $this->getOption('escape'))) { + $this->setEscape($escape); + $this->removeOption('escape'); + } else { + $this->setEscape(true); + } + } + + return $this->_escape; + } + + /** + * Render a description + * + * @param string $content + * @return string + */ + public function render($content) + { + $element = $this->getElement(); + $view = $element->getView(); + if (null === $view) { + return $content; + } + + $description = $element->getDescription(); + $description = trim($description ?? ''); + + if (!empty($description) && (null !== ($translator = $element->getTranslator()))) { + $description = $translator->translate($description); + } + + if (empty($description)) { + return $content; + } + + $separator = $this->getSeparator(); + $placement = $this->getPlacement(); + $tag = $this->getTag(); + $class = $this->getClass(); + $escape = $this->getEscape(); + + $options = $this->getOptions(); + + if ($escape) { + $description = $view->escape($description); + } + + if (!empty($tag)) { + $options['tag'] = $tag; + $decorator = new Zend_Form_Decorator_HtmlTag($options); + $description = $decorator->render($description); + } + + switch ($placement) { + case self::PREPEND: + return $description . $separator . $content; + case self::APPEND: + default: + return $content . $separator . $description; + } + } +} diff --git a/library/vendor/Zend/Form/Decorator/DtDdWrapper.php b/library/vendor/Zend/Form/Decorator/DtDdWrapper.php new file mode 100644 index 0000000..b569fab --- /dev/null +++ b/library/vendor/Zend/Form/Decorator/DtDdWrapper.php @@ -0,0 +1,69 @@ + item, and wraps the content in a
. Used as a + * default decorator for subforms and display groups. + * + * @category Zend + * @package Zend_Form + * @subpackage Decorator + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +class Zend_Form_Decorator_DtDdWrapper extends Zend_Form_Decorator_Abstract +{ + /** + * Default placement: surround content + * @var string + */ + protected $_placement = null; + + /** + * Render + * + * Renders as the following: + *
$dtLabel
+ *
$content
+ * + * $dtLabel can be set via 'dtLabel' option, defaults to '\ ' + * + * @param string $content + * @return string + */ + public function render($content) + { + $elementName = $this->getElement()->getName(); + + $dtLabel = $this->getOption('dtLabel'); + if( null === $dtLabel ) { + $dtLabel = ' '; + } + + return '
' . $dtLabel . '
' . + '
' . $content . '
'; + } +} diff --git a/library/vendor/Zend/Form/Decorator/Errors.php b/library/vendor/Zend/Form/Decorator/Errors.php new file mode 100644 index 0000000..24fc3d9 --- /dev/null +++ b/library/vendor/Zend/Form/Decorator/Errors.php @@ -0,0 +1,76 @@ +getElement(); + $view = $element->getView(); + if (null === $view) { + return $content; + } + + // Get error messages + if ($element instanceof Zend_Form + && null !== $element->getElementsBelongTo() + ) { + $errors = $element->getMessages(null, true); + } else { + $errors = $element->getMessages(); + } + + if (empty($errors)) { + return $content; + } + + $separator = $this->getSeparator(); + $placement = $this->getPlacement(); + $errors = $view->formErrors($errors, $this->getOptions()); + + switch ($placement) { + case self::APPEND: + return $content . $separator . $errors; + case self::PREPEND: + return $errors . $separator . $content; + } + } +} diff --git a/library/vendor/Zend/Form/Decorator/Exception.php b/library/vendor/Zend/Form/Decorator/Exception.php new file mode 100644 index 0000000..6d86f32 --- /dev/null +++ b/library/vendor/Zend/Form/Decorator/Exception.php @@ -0,0 +1,36 @@ +getElement())) { + $attribs = $element->getAttribs(); + $options = array_merge($attribs, $options); + $this->setOptions($options); + } + return $options; + } + + /** + * Set legend + * + * @param string $value + * @return Zend_Form_Decorator_Fieldset + */ + public function setLegend($value) + { + $this->_legend = (string) $value; + return $this; + } + + /** + * Get legend + * + * @return string + */ + public function getLegend() + { + $legend = $this->_legend; + if ((null === $legend) && (null !== ($element = $this->getElement()))) { + if (method_exists($element, 'getLegend')) { + $legend = $element->getLegend(); + $this->setLegend($legend); + } + } + if ((null === $legend) && (null !== ($legend = $this->getOption('legend')))) { + $this->setLegend($legend); + $this->removeOption('legend'); + } + + return $legend; + } + + /** + * Render a fieldset + * + * @param string $content + * @return string + */ + public function render($content) + { + $element = $this->getElement(); + $view = $element->getView(); + if (null === $view) { + return $content; + } + + $legend = $this->getLegend(); + $attribs = $this->getOptions(); + $name = $element->getFullyQualifiedName(); + $id = (string)$element->getId(); + + if ((!array_key_exists('id', $attribs) || $attribs['id'] == $id) && '' !== $id) { + $attribs['id'] = 'fieldset-' . $id; + } + + if (null !== $legend) { + if (null !== ($translator = $element->getTranslator())) { + $legend = $translator->translate($legend); + } + + $attribs['legend'] = $legend; + } + + foreach (array_keys($attribs) as $attrib) { + $testAttrib = strtolower($attrib); + if (in_array($testAttrib, $this->stripAttribs)) { + unset($attribs[$attrib]); + } + } + + return $view->fieldset($name, $content, $attribs); + } +} diff --git a/library/vendor/Zend/Form/Decorator/File.php b/library/vendor/Zend/Form/Decorator/File.php new file mode 100644 index 0000000..d7141de --- /dev/null +++ b/library/vendor/Zend/Form/Decorator/File.php @@ -0,0 +1,140 @@ +getOptions(); + + if (null !== ($element = $this->getElement())) { + $attribs = array_merge($attribs, $element->getAttribs()); + } + + foreach ($this->_attribBlacklist as $key) { + if (array_key_exists($key, $attribs)) { + unset($attribs[$key]); + } + } + + return $attribs; + } + + /** + * Render a form file + * + * @param string $content + * @return string + */ + public function render($content) + { + $element = $this->getElement(); + if (!$element instanceof Zend_Form_Element) { + return $content; + } + + $view = $element->getView(); + if (!$view instanceof Zend_View_Interface) { + return $content; + } + + $name = $element->getName(); + $attribs = $this->getAttribs(); + if (!array_key_exists('id', $attribs)) { + $attribs['id'] = $name; + } + + $separator = $this->getSeparator(); + $placement = $this->getPlacement(); + $markup = array(); + $size = $element->getMaxFileSize(); + if ($size > 0) { + $element->setMaxFileSize(0); + $markup[] = $view->formHidden('MAX_FILE_SIZE', $size); + } + + if (Zend_File_Transfer_Adapter_Http::isApcAvailable()) { + $markup[] = $view->formHidden(ini_get('apc.rfc1867_name'), uniqid(), array('id' => 'progress_key')); + } else if (Zend_File_Transfer_Adapter_Http::isUploadProgressAvailable()) { + $markup[] = $view->formHidden('UPLOAD_IDENTIFIER', uniqid(), array('id' => 'progress_key')); + } + + $helper = $element->helper; + if ($element->isArray()) { + $name .= "[]"; + $count = $element->getMultiFile(); + for ($i = 0; $i < $count; ++$i) { + $htmlAttribs = $attribs; + $htmlAttribs['id'] .= '-' . $i; + $markup[] = $view->$helper($name, $htmlAttribs); + } + } else { + $markup[] = $view->$helper($name, $attribs); + } + + $markup = implode($separator, $markup); + + switch ($placement) { + case self::PREPEND: + return $markup . $separator . $content; + case self::APPEND: + default: + return $content . $separator . $markup; + } + } +} diff --git a/library/vendor/Zend/Form/Decorator/Form.php b/library/vendor/Zend/Form/Decorator/Form.php new file mode 100644 index 0000000..c885731 --- /dev/null +++ b/library/vendor/Zend/Form/Decorator/Form.php @@ -0,0 +1,133 @@ +_helper = (string) $helper; + return $this; + } + + /** + * Get view helper for rendering form + * + * @return string + */ + public function getHelper() + { + if (null !== ($helper = $this->getOption('helper'))) { + $this->setHelper($helper); + $this->removeOption('helper'); + } + return $this->_helper; + } + + /** + * Retrieve decorator options + * + * Assures that form action and method are set, and sets appropriate + * encoding type if current method is POST. + * + * @return array + */ + public function getOptions() + { + if (null !== ($element = $this->getElement())) { + if ($element instanceof Zend_Form) { + $element->getAction(); + $method = $element->getMethod(); + if ($method == Zend_Form::METHOD_POST) { + $this->setOption('enctype', 'application/x-www-form-urlencoded'); + } + foreach ($element->getAttribs() as $key => $value) { + $this->setOption($key, $value); + } + } elseif ($element instanceof Zend_Form_DisplayGroup) { + foreach ($element->getAttribs() as $key => $value) { + $this->setOption($key, $value); + } + } + } + + if (isset($this->_options['method'])) { + $this->_options['method'] = strtolower($this->_options['method']); + } + + return $this->_options; + } + + /** + * Render a form + * + * Replaces $content entirely from currently set element. + * + * @param string $content + * @return string + */ + public function render($content) + { + $form = $this->getElement(); + $view = $form->getView(); + if (null === $view) { + return $content; + } + + $helper = $this->getHelper(); + $attribs = $this->getOptions(); + $name = $form->getFullyQualifiedName(); + $attribs['id'] = $form->getId(); + return $view->$helper($name, $attribs, $content); + } +} diff --git a/library/vendor/Zend/Form/Decorator/FormElements.php b/library/vendor/Zend/Form/Decorator/FormElements.php new file mode 100644 index 0000000..c2fb136 --- /dev/null +++ b/library/vendor/Zend/Form/Decorator/FormElements.php @@ -0,0 +1,140 @@ +getElement(); + if ((!$form instanceof Zend_Form) && (!$form instanceof Zend_Form_DisplayGroup)) { + return $content; + } + + $belongsTo = ($form instanceof Zend_Form) ? $form->getElementsBelongTo() : null; + $elementContent = ''; + $displayGroups = ($form instanceof Zend_Form) ? $form->getDisplayGroups() : array(); + $separator = $this->getSeparator(); + $translator = $form->getTranslator(); + $items = array(); + $view = $form->getView(); + foreach ($form as $item) { + $item->setView($view); + + // Set translator + if (!$item->hasTranslator()) { + $item->setTranslator($translator); + } + + if ($item instanceof Zend_Form_Element) { + foreach ($displayGroups as $group) { + $elementName = $item->getName(); + $element = $group->getElement($elementName); + if ($element) { + // Element belongs to display group; only render in that + // context. + continue 2; + } + } + $item->setBelongsTo($belongsTo); + } elseif (!empty($belongsTo) && ($item instanceof Zend_Form)) { + if ($item->isArray()) { + $name = $this->mergeBelongsTo($belongsTo, $item->getElementsBelongTo()); + $item->setElementsBelongTo($name, true); + } else { + $item->setElementsBelongTo($belongsTo, true); + } + } elseif (!empty($belongsTo) && ($item instanceof Zend_Form_DisplayGroup)) { + foreach ($item as $element) { + $element->setBelongsTo($belongsTo); + } + } + + $items[] = $item->render(); + + if (($item instanceof Zend_Form_Element_File) + || (($item instanceof Zend_Form) + && (Zend_Form::ENCTYPE_MULTIPART == $item->getEnctype())) + || (($item instanceof Zend_Form_DisplayGroup) + && (Zend_Form::ENCTYPE_MULTIPART == $item->getAttrib('enctype'))) + ) { + if ($form instanceof Zend_Form) { + $form->setEnctype(Zend_Form::ENCTYPE_MULTIPART); + } elseif ($form instanceof Zend_Form_DisplayGroup) { + $form->setAttrib('enctype', Zend_Form::ENCTYPE_MULTIPART); + } + } + } + $elementContent = implode($separator, $items); + + switch ($this->getPlacement()) { + case self::PREPEND: + return $elementContent . $separator . $content; + case self::APPEND: + default: + return $content . $separator . $elementContent; + } + } +} diff --git a/library/vendor/Zend/Form/Decorator/FormErrors.php b/library/vendor/Zend/Form/Decorator/FormErrors.php new file mode 100644 index 0000000..70c9353 --- /dev/null +++ b/library/vendor/Zend/Form/Decorator/FormErrors.php @@ -0,0 +1,514 @@ + false, + 'showCustomFormErrors' => true, + 'onlyCustomFormErrors' => false, + 'markupElementLabelEnd' => '', + 'markupElementLabelStart' => '', + 'markupListEnd' => '', + 'markupListItemEnd' => '', + 'markupListItemStart' => '
  • ', + 'markupListStart' => '
      ', + ); + + /**#@+ + * Markup options + * @var string + */ + protected $_ignoreSubForms; + protected $_showCustomFormErrors; + protected $_onlyCustomFormErrors; + protected $_markupElementLabelEnd; + protected $_markupElementLabelStart; + protected $_markupListEnd; + protected $_markupListItemEnd; + protected $_markupListItemStart; + protected $_markupListStart; + /**#@-*/ + + /** + * Whether or not to escape error label and error message + * @var bool + */ + protected $_escape; + + /** + * Render errors + * + * @param string $content + * @return string + */ + public function render($content) + { + $form = $this->getElement(); + if (!$form instanceof Zend_Form) { + return $content; + } + + $view = $form->getView(); + if (null === $view) { + return $content; + } + + $this->initOptions(); + $markup = $this->_recurseForm($form, $view); + + if (empty($markup)) { + return $content; + } + + $markup = $this->getMarkupListStart() + . $markup + . $this->getMarkupListEnd(); + + switch ($this->getPlacement()) { + case self::APPEND: + return $content . $this->getSeparator() . $markup; + case self::PREPEND: + return $markup . $this->getSeparator() . $content; + } + } + + /** + * Initialize options + * + * @return void + */ + public function initOptions() + { + $this->getMarkupElementLabelEnd(); + $this->getMarkupElementLabelStart(); + $this->getMarkupListEnd(); + $this->getMarkupListItemEnd(); + $this->getMarkupListItemStart(); + $this->getMarkupListStart(); + $this->getPlacement(); + $this->getSeparator(); + $this->ignoreSubForms(); + $this->getShowCustomFormErrors(); + $this->getOnlyCustomFormErrors(); + } + + /** + * Retrieve markupElementLabelStart + * + * @return string + */ + public function getMarkupElementLabelStart() + { + if (null === $this->_markupElementLabelStart) { + if (null === ($markupElementLabelStart = $this->getOption('markupElementLabelStart'))) { + $this->setMarkupElementLabelStart($this->_defaults['markupElementLabelStart']); + } else { + $this->setMarkupElementLabelStart($markupElementLabelStart); + $this->removeOption('markupElementLabelStart'); + } + } + + return $this->_markupElementLabelStart; + } + + /** + * Set markupElementLabelStart + * + * @param string $markupElementLabelStart + * @return Zend_Form_Decorator_FormErrors + */ + public function setMarkupElementLabelStart($markupElementLabelStart) + { + $this->_markupElementLabelStart = $markupElementLabelStart; + return $this; + } + + /** + * Retrieve markupElementLabelEnd + * + * @return string + */ + public function getMarkupElementLabelEnd() + { + if (null === $this->_markupElementLabelEnd) { + if (null === ($markupElementLabelEnd = $this->getOption('markupElementLabelEnd'))) { + $this->setMarkupElementLabelEnd($this->_defaults['markupElementLabelEnd']); + } else { + $this->setMarkupElementLabelEnd($markupElementLabelEnd); + $this->removeOption('markupElementLabelEnd'); + } + } + + return $this->_markupElementLabelEnd; + } + + /** + * Set markupElementLabelEnd + * + * @param string $markupElementLabelEnd + * @return Zend_Form_Decorator_FormErrors + */ + public function setMarkupElementLabelEnd($markupElementLabelEnd) + { + $this->_markupElementLabelEnd = $markupElementLabelEnd; + return $this; + } + + /** + * Retrieve markupListStart + * + * @return string + */ + public function getMarkupListStart() + { + if (null === $this->_markupListStart) { + if (null === ($markupListStart = $this->getOption('markupListStart'))) { + $this->setMarkupListStart($this->_defaults['markupListStart']); + } else { + $this->setMarkupListStart($markupListStart); + $this->removeOption('markupListStart'); + } + } + + return $this->_markupListStart; + } + + /** + * Set markupListStart + * + * @param string $markupListStart + * @return Zend_Form_Decorator_FormErrors + */ + public function setMarkupListStart($markupListStart) + { + $this->_markupListStart = $markupListStart; + return $this; + } + + /** + * Retrieve markupListEnd + * + * @return string + */ + public function getMarkupListEnd() + { + if (null === $this->_markupListEnd) { + if (null === ($markupListEnd = $this->getOption('markupListEnd'))) { + $this->setMarkupListEnd($this->_defaults['markupListEnd']); + } else { + $this->setMarkupListEnd($markupListEnd); + $this->removeOption('markupListEnd'); + } + } + + return $this->_markupListEnd; + } + + /** + * Set markupListEnd + * + * @param string $markupListEnd + * @return Zend_Form_Decorator_FormErrors + */ + public function setMarkupListEnd($markupListEnd) + { + $this->_markupListEnd = $markupListEnd; + return $this; + } + + /** + * Retrieve markupListItemStart + * + * @return string + */ + public function getMarkupListItemStart() + { + if (null === $this->_markupListItemStart) { + if (null === ($markupListItemStart = $this->getOption('markupListItemStart'))) { + $this->setMarkupListItemStart($this->_defaults['markupListItemStart']); + } else { + $this->setMarkupListItemStart($markupListItemStart); + $this->removeOption('markupListItemStart'); + } + } + + return $this->_markupListItemStart; + } + + /** + * Set markupListItemStart + * + * @param string $markupListItemStart + * @return Zend_Form_Decorator_FormErrors + */ + public function setMarkupListItemStart($markupListItemStart) + { + $this->_markupListItemStart = $markupListItemStart; + return $this; + } + + /** + * Retrieve markupListItemEnd + * + * @return string + */ + public function getMarkupListItemEnd() + { + if (null === $this->_markupListItemEnd) { + if (null === ($markupListItemEnd = $this->getOption('markupListItemEnd'))) { + $this->setMarkupListItemEnd($this->_defaults['markupListItemEnd']); + } else { + $this->setMarkupListItemEnd($markupListItemEnd); + $this->removeOption('markupListItemEnd'); + } + } + + return $this->_markupListItemEnd; + } + + /** + * Set markupListItemEnd + * + * @param string $markupListItemEnd + * @return Zend_Form_Decorator_FormErrors + */ + public function setMarkupListItemEnd($markupListItemEnd) + { + $this->_markupListItemEnd = $markupListItemEnd; + return $this; + } + + /** + * Retrieve ignoreSubForms + * + * @return bool + */ + public function ignoreSubForms() + { + if (null === $this->_ignoreSubForms) { + if (null === ($ignoreSubForms = $this->getOption('ignoreSubForms'))) { + $this->setIgnoreSubForms($this->_defaults['ignoreSubForms']); + } else { + $this->setIgnoreSubForms($ignoreSubForms); + $this->removeOption('ignoreSubForms'); + } + } + + return $this->_ignoreSubForms; + } + + /** + * Set ignoreSubForms + * + * @param bool $ignoreSubForms + * @return Zend_Form_Decorator_FormErrors + */ + public function setIgnoreSubForms($ignoreSubForms) + { + $this->_ignoreSubForms = (bool) $ignoreSubForms; + return $this; + } + + /** + * Get showCustomFormErrors + * + * @return bool + */ + public function getShowCustomFormErrors() + { + if (null === $this->_showCustomFormErrors) { + if (null === ($show = $this->getOption('showCustomFormErrors'))) { + $this->setShowCustomFormErrors($this->_defaults['showCustomFormErrors']); + } else { + $this->setShowCustomFormErrors($show); + $this->removeOption('showCustomFormErrors'); + } + } + return $this->_showCustomFormErrors; + } + + /** + * Set showCustomFormErrors + * + * @param bool $showCustomFormErrors + * @return Zend_Form_Decorator_FormErrors + */ + public function setShowCustomFormErrors($showCustomFormErrors) + { + $this->_showCustomFormErrors = (bool)$showCustomFormErrors; + return $this; + } + + /** + * Get onlyCustomFormErrors + * + * @return bool + */ + public function getOnlyCustomFormErrors() + { + if (null === $this->_onlyCustomFormErrors) { + if (null === ($show = $this->getOption('onlyCustomFormErrors'))) { + $this->setOnlyCustomFormErrors($this->_defaults['onlyCustomFormErrors']); + } else { + $this->setOnlyCustomFormErrors($show); + $this->removeOption('onlyCustomFormErrors'); + } + } + return $this->_onlyCustomFormErrors; + } + + /** + * Set onlyCustomFormErrors, whether to display elements messages + * in addition to custom form messages. + * + * @param bool $onlyCustomFormErrors + * @return Zend_Form_Decorator_FormErrors + */ + public function setOnlyCustomFormErrors($onlyCustomFormErrors) + { + $this->_onlyCustomFormErrors = (bool)$onlyCustomFormErrors; + return $this; + } + + /** + * Set whether or not to escape error label and error message + * + * Sets also the 'escape' option for the view helper + * + * @param bool $flag + * @return Zend_Form_Decorator_FormErrors + */ + public function setEscape($flag) + { + $this->_escape = (bool) $flag; + + // Set also option for view helper + $this->setOption('escape', $this->_escape); + return $this; + } + + /** + * Get escape flag + * + * @return bool + */ + public function getEscape() + { + if (null === $this->_escape) { + if (null !== ($escape = $this->getOption('escape'))) { + $this->setEscape($escape); + } else { + $this->setEscape(true); + } + } + + return $this->_escape; + } + + /** + * Render element label + * + * @param Zend_Form_Element $element + * @param Zend_View_Interface $view + * @return string + */ + public function renderLabel(Zend_Form_Element $element, Zend_View_Interface $view) + { + $label = $element->getLabel(); + if (empty($label)) { + $label = $element->getName(); + + // Translate element name + if (null !== ($translator = $element->getTranslator())) { + $label = $translator->translate($label); + } + } + + if ($this->getEscape()) { + $label = $view->escape($label); + } + + return $this->getMarkupElementLabelStart() + . $label + . $this->getMarkupElementLabelEnd(); + } + + /** + * Recurse through a form object, rendering errors + * + * @param Zend_Form $form + * @param Zend_View_Interface $view + * @return string + */ + protected function _recurseForm(Zend_Form $form, Zend_View_Interface $view) + { + $content = ''; + + $custom = $form->getCustomMessages(); + if ($this->getShowCustomFormErrors() && count($custom)) { + $content .= $this->getMarkupListItemStart() + . $view->formErrors($custom, $this->getOptions()) + . $this->getMarkupListItemEnd(); + } + foreach ($form->getElementsAndSubFormsOrdered() as $subitem) { + if ($subitem instanceof Zend_Form_Element && !$this->getOnlyCustomFormErrors()) { + $messages = $subitem->getMessages(); + if (count($messages)) { + $subitem->setView($view); + $content .= $this->getMarkupListItemStart() + . $this->renderLabel($subitem, $view) + . $view->formErrors($messages, $this->getOptions()) + . $this->getMarkupListItemEnd(); + } + } else if ($subitem instanceof Zend_Form && !$this->ignoreSubForms()) { + $markup = $this->_recurseForm($subitem, $view); + + if (!empty($markup)) { + $content .= $this->getMarkupListStart() + . $markup + . $this->getMarkupListEnd(); + } + } + } + return $content; + } +} diff --git a/library/vendor/Zend/Form/Decorator/HtmlTag.php b/library/vendor/Zend/Form/Decorator/HtmlTag.php new file mode 100644 index 0000000..47b9e21 --- /dev/null +++ b/library/vendor/Zend/Form/Decorator/HtmlTag.php @@ -0,0 +1,253 @@ +_getEncoding(); + foreach ((array) $attribs as $key => $val) { + $key = htmlspecialchars($key, ENT_COMPAT, $enc); + if (is_array($val)) { + if (array_key_exists('callback', $val) + && is_callable($val['callback']) + ) { + $val = call_user_func($val['callback'], $this); + } else { + $val = implode(' ', $val); + } + } + $val = htmlspecialchars($val ?? '', ENT_COMPAT, $enc); + $xhtml .= " $key=\"$val\""; + } + return $xhtml; + } + + /** + * Normalize tag + * + * Ensures tag is alphanumeric characters only, and all lowercase. + * + * @param string $tag + * @return string + */ + public function normalizeTag($tag) + { + if (!isset($this->_tagFilter)) { + $this->_tagFilter = new Zend_Filter(); + $this->_tagFilter->addFilter(new Zend_Filter_Alnum()) + ->addFilter(new Zend_Filter_StringToLower()); + } + return $this->_tagFilter->filter($tag); + } + + /** + * Set tag to use + * + * @param string $tag + * @return Zend_Form_Decorator_HtmlTag + */ + public function setTag($tag) + { + $this->_tag = $this->normalizeTag($tag); + return $this; + } + + /** + * Get tag + * + * If no tag is registered, either via setTag() or as an option, uses 'div'. + * + * @return string + */ + public function getTag() + { + if (null === $this->_tag) { + if (null === ($tag = $this->getOption('tag'))) { + $this->setTag('div'); + } else { + $this->setTag($tag); + $this->removeOption('tag'); + } + } + + return $this->_tag; + } + + /** + * Get the formatted open tag + * + * @param string $tag + * @param array $attribs + * @return string + */ + protected function _getOpenTag($tag, array $attribs = null) + { + $html = '<' . $tag; + if (null !== $attribs) { + $html .= $this->_htmlAttribs($attribs); + } + $html .= '>'; + return $html; + } + + /** + * Get formatted closing tag + * + * @param string $tag + * @return string + */ + protected function _getCloseTag($tag) + { + return ''; + } + + /** + * Render content wrapped in an HTML tag + * + * @param string $content + * @return string + */ + public function render($content) + { + $tag = $this->getTag(); + $placement = $this->getPlacement(); + $noAttribs = $this->getOption('noAttribs'); + $openOnly = $this->getOption('openOnly'); + $closeOnly = $this->getOption('closeOnly'); + $this->removeOption('noAttribs'); + $this->removeOption('openOnly'); + $this->removeOption('closeOnly'); + + $attribs = null; + if (!$noAttribs) { + $attribs = $this->getOptions(); + } + + switch ($placement) { + case self::APPEND: + if ($closeOnly) { + return $content . $this->_getCloseTag($tag); + } + if ($openOnly) { + return $content . $this->_getOpenTag($tag, $attribs); + } + return $content + . $this->_getOpenTag($tag, $attribs) + . $this->_getCloseTag($tag); + case self::PREPEND: + if ($closeOnly) { + return $this->_getCloseTag($tag) . $content; + } + if ($openOnly) { + return $this->_getOpenTag($tag, $attribs) . $content; + } + return $this->_getOpenTag($tag, $attribs) + . $this->_getCloseTag($tag) + . $content; + default: + return (($openOnly || !$closeOnly) ? $this->_getOpenTag($tag, $attribs) : '') + . $content + . (($closeOnly || !$openOnly) ? $this->_getCloseTag($tag) : ''); + } + } + + /** + * Get encoding for use with htmlspecialchars() + * + * @return string + */ + protected function _getEncoding() + { + if (null !== $this->_encoding) { + return $this->_encoding; + } + + if (null === ($element = $this->getElement())) { + $this->_encoding = 'UTF-8'; + } elseif (null === ($view = $element->getView())) { + $this->_encoding = 'UTF-8'; + } elseif (!$view instanceof Zend_View_Abstract + && !method_exists($view, 'getEncoding') + ) { + $this->_encoding = 'UTF-8'; + } else { + $this->_encoding = $view->getEncoding(); + } + return $this->_encoding; + } +} diff --git a/library/vendor/Zend/Form/Decorator/Image.php b/library/vendor/Zend/Form/Decorator/Image.php new file mode 100644 index 0000000..4ec01c1 --- /dev/null +++ b/library/vendor/Zend/Form/Decorator/Image.php @@ -0,0 +1,152 @@ +_tag = (string) $tag; + return $this; + } + + /** + * Get HTML tag, if any, with which to surround label + * + * @return void + */ + public function getTag() + { + if (null === $this->_tag) { + $tag = $this->getOption('tag'); + if (null !== $tag) { + $this->removeOption('tag'); + $this->setTag($tag); + } + return $tag; + } + + return $this->_tag; + } + + /** + * Get attributes to pass to image helper + * + * @return array + */ + public function getAttribs() + { + $attribs = $this->getOptions(); + + if (null !== ($element = $this->getElement())) { + $attribs['alt'] = $element->getLabel(); + $attribs = array_merge($attribs, $element->getAttribs()); + } + + foreach ($this->_attribBlacklist as $key) { + if (array_key_exists($key, $attribs)) { + unset($attribs[$key]); + } + } + + return $attribs; + } + + /** + * Render a form image + * + * @param string $content + * @return string + */ + public function render($content) + { + $element = $this->getElement(); + $view = $element->getView(); + if (null === $view) { + return $content; + } + + $tag = $this->getTag(); + $placement = $this->getPlacement(); + $separator = $this->getSeparator(); + $name = $element->getFullyQualifiedName(); + $attribs = $this->getAttribs(); + $attribs['id'] = $element->getId(); + + $image = $view->formImage($name, $element->getImageValue(), $attribs); + + if (null !== $tag) { + $decorator = new Zend_Form_Decorator_HtmlTag(); + $decorator->setOptions(array('tag' => $tag)); + $image = $decorator->render($image); + } + + switch ($placement) { + case self::PREPEND: + return $image . $separator . $content; + case self::APPEND: + default: + return $content . $separator . $image; + } + } +} diff --git a/library/vendor/Zend/Form/Decorator/Interface.php b/library/vendor/Zend/Form/Decorator/Interface.php new file mode 100644 index 0000000..5cc1171 --- /dev/null +++ b/library/vendor/Zend/Form/Decorator/Interface.php @@ -0,0 +1,123 @@ +setOption('id', $id); + return $this; + } + + /** + * Retrieve element ID (used in 'for' attribute) + * + * If none set in decorator, looks first for element 'id' attribute, and + * defaults to element name. + * + * @return string + */ + public function getId() + { + $id = $this->getOption('id'); + if (null === $id) { + if (null !== ($element = $this->getElement())) { + $id = $element->getId(); + $this->setId($id); + } + } + + return $id; + } + + /** + * Set HTML tag with which to surround label + * + * @param string $tag + * @return Zend_Form_Decorator_Label + */ + public function setTag($tag) + { + if (empty($tag)) { + $this->_tag = null; + } else { + $this->_tag = (string) $tag; + } + + $this->removeOption('tag'); + + return $this; + } + + /** + * Get HTML tag, if any, with which to surround label + * + * @return string + */ + public function getTag() + { + if (null === $this->_tag) { + $tag = $this->getOption('tag'); + if (null !== $tag) { + $this->removeOption('tag'); + $this->setTag($tag); + } + return $tag; + } + + return $this->_tag; + } + + /** + * Set the class to apply to the HTML tag with which to surround label + * + * @param string $tagClass + * @return Zend_Form_Decorator_Label + */ + public function setTagClass($tagClass) + { + if (empty($tagClass)) { + $this->_tagClass = null; + } else { + $this->_tagClass = (string) $tagClass; + } + + $this->removeOption('tagClass'); + + return $this; + } + + /** + * Get the class to apply to the HTML tag, if any, with which to surround label + * + * @return void + */ + public function getTagClass() + { + if (null === $this->_tagClass) { + $tagClass = $this->getOption('tagClass'); + if (null !== $tagClass) { + $this->removeOption('tagClass'); + $this->setTagClass($tagClass); + } + } + + return $this->_tagClass; + } + + /** + * Get class with which to define label + * + * Appends either 'optional' or 'required' to class, depending on whether + * or not the element is required. + * + * @return string + */ + public function getClass() + { + $class = ''; + $element = $this->getElement(); + + $decoratorClass = $this->getOption('class'); + if (!empty($decoratorClass)) { + $class .= ' ' . $decoratorClass; + } + + $type = $element->isRequired() ? 'required' : 'optional'; + + if (!strstr($class, $type)) { + $class .= ' ' . $type; + $class = trim($class); + } + + return $class; + } + + /** + * Load an optional/required suffix/prefix key + * + * @param string $key + * @return void + */ + protected function _loadOptReqKey($key) + { + if (!isset($this->$key)) { + $value = $this->getOption($key); + $this->$key = (string) $value; + if (null !== $value) { + $this->removeOption($key); + } + } + } + + /** + * Overloading + * + * Currently overloads: + * + * - getOpt(ional)Prefix() + * - getOpt(ional)Suffix() + * - getReq(uired)Prefix() + * - getReq(uired)Suffix() + * - setOpt(ional)Prefix() + * - setOpt(ional)Suffix() + * - setReq(uired)Prefix() + * - setReq(uired)Suffix() + * + * @param string $method + * @param array $args + * @return mixed + * @throws Zend_Form_Exception for unsupported methods + */ + public function __call($method, $args) + { + $tail = substr($method, -6); + $head = substr($method, 0, 3); + if (in_array($head, array('get', 'set')) + && (('Prefix' == $tail) || ('Suffix' == $tail)) + ) { + $position = substr($method, -6); + $type = strtolower(substr($method, 3, 3)); + switch ($type) { + case 'req': + $key = 'required' . $position; + break; + case 'opt': + $key = 'optional' . $position; + break; + default: + throw new Zend_Form_Exception(sprintf('Invalid method "%s" called in Label decorator, and detected as type %s', $method, $type)); + } + + switch ($head) { + case 'set': + if (0 === count($args)) { + throw new Zend_Form_Exception(sprintf('Method "%s" requires at least one argument; none provided', $method)); + } + $value = array_shift($args); + $this->$key = $value; + return $this; + case 'get': + default: + if (null === ($element = $this->getElement())) { + $this->_loadOptReqKey($key); + } elseif (isset($element->$key)) { + $this->$key = (string) $element->$key; + } else { + $this->_loadOptReqKey($key); + } + return $this->$key; + } + } + + throw new Zend_Form_Exception(sprintf('Invalid method "%s" called in Label decorator', $method)); + } + + /** + * Get label to render + * + * @return string + */ + public function getLabel() + { + if (null === ($element = $this->getElement())) { + return ''; + } + + $label = $element->getLabel(); + $label = trim($label ?? ''); + + if (empty($label)) { + return ''; + } + + $optPrefix = $this->getOptPrefix(); + $optSuffix = $this->getOptSuffix(); + $reqPrefix = $this->getReqPrefix(); + $reqSuffix = $this->getReqSuffix(); + $separator = $this->getSeparator(); + + if (!empty($label)) { + if ($element->isRequired()) { + $label = $reqPrefix . $label . $reqSuffix; + } else { + $label = $optPrefix . $label . $optSuffix; + } + } + + return $label; + } + + /** + * Determine if label should append, prepend or implicit content + * + * @return string + */ + public function getPlacement() + { + $placement = $this->_placement; + if (null !== ($placementOpt = $this->getOption('placement'))) { + $placementOpt = strtoupper($placementOpt); + switch ($placementOpt) { + case self::APPEND: + case self::PREPEND: + case self::IMPLICIT: + case self::IMPLICIT_PREPEND: + case self::IMPLICIT_APPEND: + $placement = $this->_placement = $placementOpt; + break; + case false: + $placement = $this->_placement = null; + break; + default: + break; + } + $this->removeOption('placement'); + } + + return $placement; + } + + /** + * Render a label + * + * @param string $content + * @return string + */ + public function render($content) + { + $element = $this->getElement(); + $view = $element->getView(); + if (null === $view) { + return $content; + } + + $label = $this->getLabel(); + $separator = $this->getSeparator(); + $placement = $this->getPlacement(); + $tag = $this->getTag(); + $tagClass = $this->getTagClass(); + $id = $this->getId(); + $class = $this->getClass(); + $options = $this->getOptions(); + + + if (empty($label) && empty($tag)) { + return $content; + } + + if (!empty($label)) { + $options['class'] = $class; + $label = trim($label); + + switch ($placement) { + case self::IMPLICIT: + // Break was intentionally omitted + + case self::IMPLICIT_PREPEND: + $options['escape'] = false; + $options['disableFor'] = true; + + $label = $view->formLabel( + $element->getFullyQualifiedName(), + $label . $separator . $content, + $options + ); + break; + + case self::IMPLICIT_APPEND: + $options['escape'] = false; + $options['disableFor'] = true; + + $label = $view->formLabel( + $element->getFullyQualifiedName(), + $content . $separator . $label, + $options + ); + break; + + case self::APPEND: + // Break was intentionally omitted + + case self::PREPEND: + // Break was intentionally omitted + + default: + $label = $view->formLabel( + $element->getFullyQualifiedName(), + $label, + $options + ); + break; + } + } else { + $label = ' '; + } + + if (null !== $tag) { + $decorator = new Zend_Form_Decorator_HtmlTag(); + if (null !== $this->_tagClass) { + $decorator->setOptions(array('tag' => $tag, + 'id' => $id . '-label', + 'class' => $tagClass)); + } else { + $decorator->setOptions(array('tag' => $tag, + 'id' => $id . '-label')); + } + + $label = $decorator->render($label); + } + + switch ($placement) { + case self::APPEND: + return $content . $separator . $label; + + case self::PREPEND: + return $label . $separator . $content; + + case self::IMPLICIT: + // Break was intentionally omitted + + case self::IMPLICIT_PREPEND: + // Break was intentionally omitted + + case self::IMPLICIT_APPEND: + return $label; + } + } +} diff --git a/library/vendor/Zend/Form/Decorator/Marker/File/Interface.php b/library/vendor/Zend/Form/Decorator/Marker/File/Interface.php new file mode 100644 index 0000000..40a4fe7 --- /dev/null +++ b/library/vendor/Zend/Form/Decorator/Marker/File/Interface.php @@ -0,0 +1,33 @@ +getElement(); + if ((!$form instanceof Zend_Form) && (!$form instanceof Zend_Form_DisplayGroup)) { + return $content; + } + + $this->_recursivelyPrepareForm($form); + + return $content; + } + + protected function _recursivelyPrepareForm(Zend_Form $form) + { + $belongsTo = ($form instanceof Zend_Form) ? $form->getElementsBelongTo() : null; + $elementContent = ''; + $separator = $this->getSeparator(); + $translator = $form->getTranslator(); + $view = $form->getView(); + + foreach ($form as $item) { + $item->setView($view) + ->setTranslator($translator); + if ($item instanceof Zend_Form_Element) { + $item->setBelongsTo($belongsTo); + } elseif (!empty($belongsTo) && ($item instanceof Zend_Form)) { + if ($item->isArray()) { + $name = $this->mergeBelongsTo($belongsTo, $item->getElementsBelongTo()); + $item->setElementsBelongTo($name, true); + } else { + $item->setElementsBelongTo($belongsTo, true); + } + $this->_recursivelyPrepareForm($item); + } elseif (!empty($belongsTo) && ($item instanceof Zend_Form_DisplayGroup)) { + foreach ($item as $element) { + $element->setBelongsTo($belongsTo); + } + } + } + } +} diff --git a/library/vendor/Zend/Form/Decorator/Tooltip.php b/library/vendor/Zend/Form/Decorator/Tooltip.php new file mode 100644 index 0000000..2448b61 --- /dev/null +++ b/library/vendor/Zend/Form/Decorator/Tooltip.php @@ -0,0 +1,57 @@ +getElement()->getAttrib('title'))) { + if (null !== ($translator = $this->getElement()->getTranslator())) { + $title = $translator->translate($title); + } + } + + $this->getElement()->setAttrib('title', $title); + return $content; + } + +} diff --git a/library/vendor/Zend/Form/Decorator/ViewHelper.php b/library/vendor/Zend/Form/Decorator/ViewHelper.php new file mode 100644 index 0000000..a0f71af --- /dev/null +++ b/library/vendor/Zend/Form/Decorator/ViewHelper.php @@ -0,0 +1,266 @@ +_helper = (string) $helper; + return $this; + } + + /** + * Retrieve view helper for rendering element + * + * @return string + */ + public function getHelper() + { + if (null === $this->_helper) { + $options = $this->getOptions(); + if (isset($options['helper'])) { + $this->setHelper($options['helper']); + $this->removeOption('helper'); + } else { + $element = $this->getElement(); + if (null !== $element) { + if (null !== ($helper = $element->getAttrib('helper'))) { + $this->setHelper($helper); + } else { + $type = $element->getType(); + if ($pos = strrpos($type, '_')) { + $type = substr($type, $pos + 1); + } + $this->setHelper('form' . ucfirst($type)); + } + } + } + } + + return $this->_helper; + } + + /** + * Get name + * + * If element is a Zend_Form_Element, will attempt to namespace it if the + * element belongs to an array. + * + * @return string + */ + public function getName() + { + if (null === ($element = $this->getElement())) { + return ''; + } + + $name = $element->getName(); + + if (!$element instanceof Zend_Form_Element) { + return $name; + } + + if (null !== ($belongsTo = $element->getBelongsTo())) { + $name = $belongsTo . '[' + . $name + . ']'; + } + + if ($element->isArray()) { + $name .= '[]'; + } + + return $name; + } + + /** + * Retrieve element attributes + * + * Set id to element name and/or array item. + * + * @return array + */ + public function getElementAttribs() + { + if (null === ($element = $this->getElement())) { + return null; + } + + $attribs = $element->getAttribs(); + if (isset($attribs['helper'])) { + unset($attribs['helper']); + } + + if (method_exists($element, 'getSeparator')) { + if (null !== ($listsep = $element->getSeparator())) { + $attribs['listsep'] = $listsep; + } + } + + if (isset($attribs['id'])) { + return $attribs; + } + + $id = $element->getName(); + + if ($element instanceof Zend_Form_Element) { + if (null !== ($belongsTo = $element->getBelongsTo())) { + $belongsTo = preg_replace('/\[([^\]]+)\]/', '-$1', $belongsTo); + $id = $belongsTo . '-' . $id; + } + } + + $element->setAttrib('id', $id); + $attribs['id'] = $id; + + return $attribs; + } + + /** + * Get value + * + * If element type is one of the button types, returns the label. + * + * @param Zend_Form_Element $element + * @return string|null + */ + public function getValue($element) + { + if (!$element instanceof Zend_Form_Element) { + return null; + } + + foreach ($this->_buttonTypes as $type) { + if ($element instanceof $type) { + if (stristr($type, 'button')) { + $element->content = $element->getLabel(); + + return $element->getValue(); + } + return $element->getLabel(); + } + } + + return $element->getValue(); + } + + /** + * Render an element using a view helper + * + * Determine view helper from 'viewHelper' option, or, if none set, from + * the element type. Then call as + * helper($element->getName(), $element->getValue(), $element->getAttribs()) + * + * @param string $content + * @return string + * @throws Zend_Form_Decorator_Exception if element or view are not registered + */ + public function render($content) + { + $element = $this->getElement(); + + $view = $element->getView(); + if (null === $view) { + throw new Zend_Form_Decorator_Exception('ViewHelper decorator cannot render without a registered view object'); + } + + if (method_exists($element, 'getMultiOptions')) { + $element->getMultiOptions(); + } + + $helper = $this->getHelper(); + $separator = $this->getSeparator(); + $value = $this->getValue($element); + $attribs = $this->getElementAttribs(); + $name = $element->getFullyQualifiedName(); + $id = $element->getId(); + $attribs['id'] = $id; + + $helperObject = $view->getHelper($helper); + if (method_exists($helperObject, 'setTranslator')) { + $helperObject->setTranslator($element->getTranslator()); + } + + // Check list separator + if (isset($attribs['listsep']) + && in_array($helper, array('formMultiCheckbox', 'formRadio', 'formSelect')) + ) { + $listsep = $attribs['listsep']; + unset($attribs['listsep']); + + $elementContent = $view->$helper($name, $value, $attribs, $element->options, $listsep); + } else { + $elementContent = $view->$helper($name, $value, $attribs, $element->options); + } + + switch ($this->getPlacement()) { + case self::APPEND: + return $content . $separator . $elementContent; + case self::PREPEND: + return $elementContent . $separator . $content; + default: + return $elementContent; + } + } +} diff --git a/library/vendor/Zend/Form/Decorator/ViewScript.php b/library/vendor/Zend/Form/Decorator/ViewScript.php new file mode 100644 index 0000000..0a1a5a1 --- /dev/null +++ b/library/vendor/Zend/Form/Decorator/ViewScript.php @@ -0,0 +1,190 @@ + + * // in view script: + * echo $this->element->getLabel(); + * + * + * Any options other than separator, placement, viewScript, and viewModule are passed to + * the partial as local variables. + * + * @category Zend + * @package Zend_Form + * @subpackage Decorator + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +class Zend_Form_Decorator_ViewScript extends Zend_Form_Decorator_Abstract +{ + /** + * Default placement: append + * @var string + */ + protected $_placement = 'APPEND'; + + /** + * View script to render + * @var string + */ + protected $_viewScript; + + /** + * View script module + * @var string + */ + protected $_viewModule; + + /** + * Set view script + * + * @param string $script + * @return Zend_Form_Decorator_ViewScript + */ + public function setViewScript($script) + { + $this->_viewScript = (string) $script; + return $this; + } + + /** + * Get view script + * + * @return string|null + */ + public function getViewScript() + { + if (null === $this->_viewScript) { + if (null !== ($element = $this->getElement())) { + if (null !== ($viewScript = $element->getAttrib('viewScript'))) { + $this->setViewScript($viewScript); + return $viewScript; + } + } + + if (null !== ($viewScript = $this->getOption('viewScript'))) { + $this->setViewScript($viewScript) + ->removeOption('viewScript'); + } + } + + return $this->_viewScript; + } + + /** + * Set view script module + * + * @param string $module + * @return Zend_Form_Decorator_ViewScript + */ + public function setViewModule($viewModule) + { + $this->_viewModule = (string) $viewModule; + return $this; + } + + /** + * Get view script module + * + * @return string|null + */ + public function getViewModule() + { + if (null === $this->_viewModule) { + if (null !== ($element = $this->getElement())) { + if (null !== ($viewModule = $element->getAttrib('viewModule'))) { + $this->setViewModule($viewModule); + return $viewModule; + } + } + + if (null !== ($viewModule = $this->getOption('viewModule'))) { + $this->setViewModule($viewModule) + ->removeOption('viewModule'); + } + } + + return $this->_viewModule; + } + + /** + * Render a view script + * + * @param string $content + * @return string + */ + public function render($content) + { + $element = $this->getElement(); + $view = $element->getView(); + if (null === $view) { + return $content; + } + + $viewScript = $this->getViewScript(); + if (empty($viewScript)) { + throw new Zend_Form_Exception('No view script registered with ViewScript decorator'); + } + + $separator = $this->getSeparator(); + $placement = $this->getPlacement(); + + $vars = $this->getOptions(); + $vars['element'] = $element; + $vars['content'] = $content; + $vars['decorator'] = $this; + + $viewModule = $this->getViewModule(); + if (empty($viewModule)) { + $renderedContent = $view->partial($viewScript, $vars); + } else { + $renderedContent = $view->partial($viewScript, $viewModule, $vars); + } + + // Get placement again to see if it has changed + $placement = $this->getPlacement(); + + switch ($placement) { + case self::PREPEND: + return $renderedContent . $separator . $content; + case self::APPEND: + return $content . $separator . $renderedContent; + default: + return $renderedContent; + } + } +} diff --git a/library/vendor/Zend/Form/DisplayGroup.php b/library/vendor/Zend/Form/DisplayGroup.php new file mode 100644 index 0000000..73a4cde --- /dev/null +++ b/library/vendor/Zend/Form/DisplayGroup.php @@ -0,0 +1,1172 @@ +setName($name); + + $this->setPluginLoader($loader); + + if (is_array($options)) { + $this->setOptions($options); + } elseif ($options instanceof Zend_Config) { + $this->setConfig($options); + } + + // Extensions... + $this->init(); + + $this->loadDefaultDecorators(); + } + + /** + * Initialize object; used by extending classes + * + * @return void + */ + public function init() + { + } + + /** + * Set options + * + * @param array $options + * @return Zend_Form_DisplayGroup + */ + public function setOptions(array $options) + { + $forbidden = array( + 'Options', 'Config', 'PluginLoader', 'View', + 'Translator', 'Attrib' + ); + foreach ($options as $key => $value) { + $normalized = ucfirst($key); + + if (in_array($normalized, $forbidden)) { + continue; + } + + $method = 'set' . $normalized; + if (method_exists($this, $method)) { + $this->$method($value); + } else { + $this->setAttrib($key, $value); + } + } + return $this; + } + + /** + * Set options from config object + * + * @param Zend_Config $config + * @return Zend_Form_DisplayGroup + */ + public function setConfig(Zend_Config $config) + { + return $this->setOptions($config->toArray()); + } + + /** + * Set group attribute + * + * @param string $key + * @param mixed $value + * @return Zend_Form_DisplayGroup + */ + public function setAttrib($key, $value) + { + $key = (string) $key; + $this->_attribs[$key] = $value; + return $this; + } + + /** + * Add multiple form attributes at once + * + * @param array $attribs + * @return Zend_Form_DisplayGroup + */ + public function addAttribs(array $attribs) + { + foreach ($attribs as $key => $value) { + $this->setAttrib($key, $value); + } + return $this; + } + + /** + * Set multiple form attributes at once + * + * Overwrites any previously set attributes. + * + * @param array $attribs + * @return Zend_Form_DisplayGroup + */ + public function setAttribs(array $attribs) + { + $this->clearAttribs(); + return $this->addAttribs($attribs); + } + + /** + * Retrieve a single form attribute + * + * @param string $key + * @return mixed + */ + public function getAttrib($key) + { + $key = (string) $key; + if (!isset($this->_attribs[$key])) { + return null; + } + + return $this->_attribs[$key]; + } + + /** + * Retrieve all form attributes/metadata + * + * @return array + */ + public function getAttribs() + { + return $this->_attribs; + } + + /** + * Remove attribute + * + * @param string $key + * @return bool + */ + public function removeAttrib($key) + { + if (array_key_exists($key, $this->_attribs)) { + unset($this->_attribs[$key]); + return true; + } + + return false; + } + + /** + * Clear all form attributes + * + * @return Zend_Form + */ + public function clearAttribs() + { + $this->_attribs = array(); + return $this; + } + + /** + * Set form object to which the display group is attached + * + * @param Zend_Form $form + * @return Zend_Form_DisplayGroup + */ + public function setForm(Zend_Form $form) + { + $this->_form = $form; + + // Ensure any elements attached prior to setting the form are now + // removed from iteration by the form + foreach ($this->getElements() as $element) { + $form->removeFromIteration($element->getName()); + } + + return $this; + } + + /** + * Get form object to which the group is attached + * + * @return Zend_Form|null + */ + public function getForm() + { + return $this->_form; + } + + /** + * Filter a name to only allow valid variable characters + * + * @param string $value + * @return string + */ + public function filterName($value) + { + return preg_replace('/[^a-zA-Z0-9_\x7f-\xff]/', '', (string) $value); + } + + /** + * Set group name + * + * @param string $name + * @return Zend_Form_DisplayGroup + */ + public function setName($name) + { + $name = $this->filtername($name); + if (('0' !== $name) && empty($name)) { + throw new Zend_Form_Exception('Invalid name provided; must contain only valid variable characters and be non-empty'); + } + + $this->_name = $name; + return $this; + } + + /** + * Retrieve group name + * + * @return string + */ + public function getName() + { + return $this->_name; + } + + /** + * Get fully qualified name + * + * Places name as subitem of array and/or appends brackets. + * + * @return string + */ + public function getFullyQualifiedName() + { + return $this->getName(); + } + + /** + * Get element id + * + * @return string + */ + public function getId() + { + if (isset($this->id)) { + return $this->id; + } + + $id = $this->getFullyQualifiedName(); + + // Bail early if no array notation detected + if (!strstr($id, '[')) { + return $id; + } + + // Strip array notation + if ('[]' == substr($id, -2)) { + $id = substr($id, 0, strlen($id) - 2); + } + $id = str_replace('][', '-', $id); + $id = str_replace(array(']', '['), '-', $id); + $id = trim($id, '-'); + + return $id; + } + + /** + * Set group legend + * + * @param string $legend + * @return Zend_Form_DisplayGroup + */ + public function setLegend($legend) + { + return $this->setAttrib('legend', (string) $legend); + } + + /** + * Retrieve group legend + * + * @return string + */ + public function getLegend() + { + return $this->getAttrib('legend'); + } + + /** + * Set description + * + * @param string $value + * @return Zend_Form_DisplayGroup + */ + public function setDescription($value) + { + $this->_description = (string) $value; + return $this; + } + + /** + * Get description + * + * @return string + */ + public function getDescription() + { + return $this->_description; + } + + /** + * Set group order + * + * @param int $order + * @return Zend_Form_Element + */ + public function setOrder($order) + { + $this->_order = (int) $order; + return $this; + } + + /** + * Retrieve group order + * + * @return int + */ + public function getOrder() + { + return $this->_order; + } + + // Elements + + /** + * Add element to stack + * + * @param Zend_Form_Element $element + * @return Zend_Form_DisplayGroup + */ + public function addElement(Zend_Form_Element $element) + { + $this->_elements[$element->getName()] = $element; + $this->_groupUpdated = true; + + // Display group will now handle display of element + if (null !== ($form = $this->getForm())) { + $form->removeFromIteration($element->getName()); + } + + return $this; + } + + /** + * Add multiple elements at once + * + * @param array $elements + * @return Zend_Form_DisplayGroup + * @throws Zend_Form_Exception if any element is not a Zend_Form_Element + */ + public function addElements(array $elements) + { + foreach ($elements as $element) { + if (!$element instanceof Zend_Form_Element) { + throw new Zend_Form_Exception('elements passed via array to addElements() must be Zend_Form_Elements only'); + } + $this->addElement($element); + } + return $this; + } + + /** + * Set multiple elements at once (overwrites) + * + * @param array $elements + * @return Zend_Form_DisplayGroup + */ + public function setElements(array $elements) + { + $this->clearElements(); + return $this->addElements($elements); + } + + /** + * Retrieve element + * + * @param string $name + * @return Zend_Form_Element|null + */ + public function getElement($name) + { + $name = (string) $name; + if (isset($this->_elements[$name])) { + return $this->_elements[$name]; + } + + return null; + } + + /** + * Retrieve elements + * @return array + */ + public function getElements() + { + return $this->_elements; + } + + /** + * Remove a single element + * + * @param string $name + * @return boolean + */ + public function removeElement($name) + { + $name = (string) $name; + if (array_key_exists($name, $this->_elements)) { + unset($this->_elements[$name]); + $this->_groupUpdated = true; + return true; + } + + return false; + } + + /** + * Remove all elements + * + * @return Zend_Form_DisplayGroup + */ + public function clearElements() + { + $this->_elements = array(); + $this->_groupUpdated = true; + return $this; + } + + // Plugin loader (for decorators) + + /** + * Set plugin loader + * + * @param Zend_Loader_PluginLoader $loader + * @return Zend_Form_DisplayGroup + */ + public function setPluginLoader(Zend_Loader_PluginLoader $loader) + { + $this->_loader = $loader; + return $this; + } + + /** + * Retrieve plugin loader + * + * @return Zend_Loader_PluginLoader + */ + public function getPluginLoader() + { + return $this->_loader; + } + + /** + * Add a prefix path for the plugin loader + * + * @param string $prefix + * @param string $path + * @return Zend_Form_DisplayGroup + */ + public function addPrefixPath($prefix, $path) + { + $this->getPluginLoader()->addPrefixPath($prefix, $path); + return $this; + } + + /** + * Add several prefix paths at once + * + * @param array $spec + * @return Zend_Form_DisplayGroup + */ + public function addPrefixPaths(array $spec) + { + if (isset($spec['prefix']) && isset($spec['path'])) { + return $this->addPrefixPath($spec['prefix'], $spec['path']); + } + foreach ($spec as $prefix => $paths) { + if (is_numeric($prefix) && is_array($paths)) { + $prefix = null; + if (isset($paths['prefix']) && isset($paths['path'])) { + $this->addPrefixPath($paths['prefix'], $paths['path']); + } + } elseif (!is_numeric($prefix)) { + if (is_string($paths)) { + $this->addPrefixPath($prefix, $paths); + } elseif (is_array($paths)) { + foreach ($paths as $path) { + $this->addPrefixPath($prefix, $path); + } + } + } + } + return $this; + } + + // Decorators + + /** + * Set flag to disable loading default decorators + * + * @param bool $flag + * @return Zend_Form_Element + */ + public function setDisableLoadDefaultDecorators($flag) + { + $this->_disableLoadDefaultDecorators = (bool) $flag; + return $this; + } + + /** + * Should we load the default decorators? + * + * @return bool + */ + public function loadDefaultDecoratorsIsDisabled() + { + return $this->_disableLoadDefaultDecorators; + } + + /** + * Load default decorators + * + * @return Zend_Form_DisplayGroup + */ + public function loadDefaultDecorators() + { + if ($this->loadDefaultDecoratorsIsDisabled()) { + return $this; + } + + $decorators = $this->getDecorators(); + if (empty($decorators)) { + $this->addDecorator('FormElements') + ->addDecorator('HtmlTag', array('tag' => 'dl')) + ->addDecorator('Fieldset') + ->addDecorator('DtDdWrapper'); + } + return $this; + } + + /** + * Instantiate a decorator based on class name or class name fragment + * + * @param string $name + * @param null|array $options + * @return Zend_Form_Decorator_Interface + */ + protected function _getDecorator($name, $options = null) + { + $class = $this->getPluginLoader()->load($name); + if (null === $options) { + $decorator = new $class; + } else { + $decorator = new $class($options); + } + + return $decorator; + } + + /** + * Add a decorator for rendering the group + * + * @param string|Zend_Form_Decorator_Interface $decorator + * @param array|Zend_Config $options Options with which to initialize decorator + * @return Zend_Form_DisplayGroup + */ + public function addDecorator($decorator, $options = null) + { + if ($decorator instanceof Zend_Form_Decorator_Interface) { + $name = get_class($decorator); + } elseif (is_string($decorator)) { + $name = $decorator; + $decorator = array( + 'decorator' => $name, + 'options' => $options, + ); + } elseif (is_array($decorator)) { + foreach ($decorator as $name => $spec) { + break; + } + if (is_numeric($name)) { + throw new Zend_Form_Exception('Invalid alias provided to addDecorator; must be alphanumeric string'); + } + if (is_string($spec)) { + $decorator = array( + 'decorator' => $spec, + 'options' => $options, + ); + } elseif ($spec instanceof Zend_Form_Decorator_Interface) { + $decorator = $spec; + } + } else { + throw new Zend_Form_Exception('Invalid decorator provided to addDecorator; must be string or Zend_Form_Decorator_Interface'); + } + + $this->_decorators[$name] = $decorator; + + return $this; + } + + /** + * Add many decorators at once + * + * @param array $decorators + * @return Zend_Form_DisplayGroup + */ + public function addDecorators(array $decorators) + { + foreach ($decorators as $decoratorName => $decoratorInfo) { + if (is_string($decoratorInfo) || + $decoratorInfo instanceof Zend_Form_Decorator_Interface) { + if (!is_numeric($decoratorName)) { + $this->addDecorator(array($decoratorName => $decoratorInfo)); + } else { + $this->addDecorator($decoratorInfo); + } + } elseif (is_array($decoratorInfo)) { + $argc = count($decoratorInfo); + $options = array(); + if (isset($decoratorInfo['decorator'])) { + $decorator = $decoratorInfo['decorator']; + if (isset($decoratorInfo['options'])) { + $options = $decoratorInfo['options']; + } + $this->addDecorator($decorator, $options); + } else { + switch (true) { + case (0 == $argc): + break; + case (1 <= $argc): + $decorator = array_shift($decoratorInfo); + case (2 <= $argc): + $options = array_shift($decoratorInfo); + default: + $this->addDecorator($decorator, $options); + break; + } + } + } else { + throw new Zend_Form_Exception('Invalid decorator passed to addDecorators()'); + } + } + + return $this; + } + + /** + * Overwrite all decorators + * + * @param array $decorators + * @return Zend_Form_DisplayGroup + */ + public function setDecorators(array $decorators) + { + $this->clearDecorators(); + return $this->addDecorators($decorators); + } + + /** + * Retrieve a registered decorator + * + * @param string $name + * @return false|Zend_Form_Decorator_Abstract + */ + public function getDecorator($name) + { + if (!isset($this->_decorators[$name])) { + $len = strlen($name); + foreach ($this->_decorators as $localName => $decorator) { + if ($len > strlen($localName)) { + continue; + } + + if (0 === substr_compare($localName, $name, -$len, $len, true)) { + if (is_array($decorator)) { + return $this->_loadDecorator($decorator, $localName); + } + return $decorator; + } + } + return false; + } + + if (is_array($this->_decorators[$name])) { + return $this->_loadDecorator($this->_decorators[$name], $name); + } + + return $this->_decorators[$name]; + } + + /** + * Retrieve all decorators + * + * @return array + */ + public function getDecorators() + { + foreach ($this->_decorators as $key => $value) { + if (is_array($value)) { + $this->_loadDecorator($value, $key); + } + } + return $this->_decorators; + } + + /** + * Remove a single decorator + * + * @param string $name + * @return bool + */ + public function removeDecorator($name) + { + $decorator = $this->getDecorator($name); + if ($decorator) { + if (array_key_exists($name, $this->_decorators)) { + unset($this->_decorators[$name]); + } else { + $class = get_class($decorator); + unset($this->_decorators[$class]); + } + return true; + } + + return false; + } + + /** + * Clear all decorators + * + * @return Zend_Form_DisplayGroup + */ + public function clearDecorators() + { + $this->_decorators = array(); + return $this; + } + + /** + * Set view + * + * @param Zend_View_Interface $view + * @return Zend_Form_DisplayGroup + */ + public function setView(Zend_View_Interface $view = null) + { + $this->_view = $view; + return $this; + } + + /** + * Retrieve view + * + * @return Zend_View_Interface + */ + public function getView() + { + if (null === $this->_view) { + $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer'); + $this->setView($viewRenderer->view); + } + + return $this->_view; + } + + /** + * Render display group + * + * @return string + */ + public function render(Zend_View_Interface $view = null) + { + if (null !== $view) { + $this->setView($view); + } + $content = ''; + foreach ($this->getDecorators() as $decorator) { + $decorator->setElement($this); + $content = $decorator->render($content); + } + return $content; + } + + /** + * String representation of group + * + * @return string + */ + public function __toString() + { + try { + $return = $this->render(); + return $return; + } catch (Exception $e) { + trigger_error($e->getMessage(), E_USER_WARNING); + return ''; + } + } + + /** + * Set translator object + * + * @param Zend_Translate|Zend_Translate_Adapter|null $translator + * @return Zend_Form_DisplayGroup + */ + public function setTranslator($translator = null) + { + if ((null === $translator) || ($translator instanceof Zend_Translate_Adapter)) { + $this->_translator = $translator; + } elseif ($translator instanceof Zend_Translate) { + $this->_translator = $translator->getAdapter(); + } else { + throw new Zend_Form_Exception('Invalid translator specified'); + } + return $this; + } + + /** + * Retrieve translator object + * + * @return Zend_Translate_Adapter|null + */ + public function getTranslator() + { + if ($this->translatorIsDisabled()) { + return null; + } + + if (null === $this->_translator) { + return Zend_Form::getDefaultTranslator(); + } + + return $this->_translator; + } + + /** + * Does this display group have its own specific translator? + * + * @return bool + */ + public function hasTranslator() + { + return (bool) $this->getTranslator(); + } + + /** + * Indicate whether or not translation should be disabled + * + * @param bool $flag + * @return Zend_Form_DisplayGroup + */ + public function setDisableTranslator($flag) + { + $this->_translatorDisabled = (bool) $flag; + return $this; + } + + /** + * Is translation disabled? + * + * @return bool + */ + public function translatorIsDisabled() + { + return $this->_translatorDisabled; + } + + /** + * Overloading: allow rendering specific decorators + * + * Call renderDecoratorName() to render a specific decorator. + * + * @param string $method + * @param array $args + * @return string + * @throws Zend_Form_Exception for invalid decorator or invalid method call + */ + public function __call($method, $args) + { + if ('render' == substr($method, 0, 6)) { + $decoratorName = substr($method, 6); + if (false !== ($decorator = $this->getDecorator($decoratorName))) { + $decorator->setElement($this); + $seed = ''; + if (0 < count($args)) { + $seed = array_shift($args); + } + return $decorator->render($seed); + } + + throw new Zend_Form_Exception(sprintf('Decorator by name %s does not exist', $decoratorName)); + } + + throw new Zend_Form_Exception(sprintf('Method %s does not exist', $method)); + } + + // Interfaces: Iterator, Countable + + /** + * Current element + * + * @return Zend_Form_Element + */ + public function current(): Zend_Form_Element + { + $this->_sort(); + current($this->_elementOrder); + $key = key($this->_elementOrder); + return $this->getElement($key); + } + + /** + * Current element + * + * @return string + */ + public function key(): string + { + $this->_sort(); + return key($this->_elementOrder); + } + + /** + * Move pointer to next element + * + * @return void + */ + public function next(): void + { + $this->_sort(); + next($this->_elementOrder); + } + + /** + * Move pointer to beginning of element loop + * + * @return void + */ + public function rewind(): void + { + $this->_sort(); + reset($this->_elementOrder); + } + + /** + * Determine if current element/subform/display group is valid + * + * @return bool + */ + public function valid(): bool + { + $this->_sort(); + return (current($this->_elementOrder) !== false); + } + + /** + * Count of elements/subforms that are iterable + * + * @return int + */ + public function count(): int + { + return count($this->_elements); + } + + /** + * Sort items according to their order + * + * @return void + */ + protected function _sort() + { + if ($this->_groupUpdated || !is_array($this->_elementOrder)) { + $elementOrder = array(); + foreach ($this->getElements() as $key => $element) { + $elementOrder[$key] = $element->getOrder(); + } + + $items = array(); + $index = 0; + foreach ($elementOrder as $key => $order) { + if (null === $order) { + while (array_search($index, $elementOrder, true)) { + ++$index; + } + $items[$index] = $key; + ++$index; + } else { + $items[$order] = $key; + } + } + + $items = array_flip($items); + asort($items); + $this->_elementOrder = $items; + $this->_groupUpdated = false; + } + } + + /** + * Lazy-load a decorator + * + * @param array $decorator Decorator type and options + * @param mixed $name Decorator name or alias + * @return Zend_Form_Decorator_Interface + */ + protected function _loadDecorator(array $decorator, $name) + { + $sameName = false; + if ($name == $decorator['decorator']) { + $sameName = true; + } + + $instance = $this->_getDecorator($decorator['decorator'], $decorator['options']); + if ($sameName) { + $newName = get_class($instance); + $decoratorNames = array_keys($this->_decorators); + $order = array_flip($decoratorNames); + $order[$newName] = $order[$name]; + $decoratorsExchange = array(); + unset($order[$name]); + asort($order); + foreach ($order as $key => $index) { + if ($key == $newName) { + $decoratorsExchange[$key] = $instance; + continue; + } + $decoratorsExchange[$key] = $this->_decorators[$key]; + } + $this->_decorators = $decoratorsExchange; + } else { + $this->_decorators[$name] = $instance; + } + + return $instance; + } +} diff --git a/library/vendor/Zend/Form/Element.php b/library/vendor/Zend/Form/Element.php new file mode 100644 index 0000000..6e81ea6 --- /dev/null +++ b/library/vendor/Zend/Form/Element.php @@ -0,0 +1,2280 @@ +setName($spec); + } elseif (is_array($spec)) { + $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)) { + $this->setConfig($options); + } + + if (null === $this->getName()) { + throw new Zend_Form_Exception('Zend_Form_Element requires each element to have a name'); + } + + /** + * Extensions + */ + $this->init(); + + /** + * Register ViewHelper decorator by default + */ + $this->loadDefaultDecorators(); + } + + /** + * Initialize object; used by extending classes + * + * @return void + */ + public function init() + { + } + + /** + * Set flag to disable loading default decorators + * + * @param bool $flag + * @return Zend_Form_Element + */ + public function setDisableLoadDefaultDecorators($flag) + { + $this->_disableLoadDefaultDecorators = (bool) $flag; + return $this; + } + + /** + * Should we load the default decorators? + * + * @return bool + */ + public function loadDefaultDecoratorsIsDisabled() + { + return $this->_disableLoadDefaultDecorators; + } + + /** + * Load default decorators + * + * @return Zend_Form_Element + */ + public function loadDefaultDecorators() + { + if ($this->loadDefaultDecoratorsIsDisabled()) { + return $this; + } + + $decorators = $this->getDecorators(); + if (empty($decorators)) { + $this->addDecorator('ViewHelper') + ->addDecorator('Errors') + ->addDecorator('Description', array('tag' => 'p', 'class' => 'description')) + ->addDecorator('HtmlTag', array( + 'tag' => 'dd', + 'id' => array('callback' => array(get_class($this), 'resolveElementId')) + )) + ->addDecorator('Label', array('tag' => 'dt')); + } + return $this; + } + + /** + * Used to resolve and return an element ID + * + * Passed to the HtmlTag decorator as a callback in order to provide an ID. + * + * @param Zend_Form_Decorator_Interface $decorator + * @return string + */ + public static function resolveElementId(Zend_Form_Decorator_Interface $decorator) + { + return $decorator->getElement()->getId() . '-element'; + } + + /** + * Set object state from options array + * + * @param array $options + * @return Zend_Form_Element + */ + public function setOptions(array $options) + { + if (isset($options['prefixPath'])) { + $this->addPrefixPaths($options['prefixPath']); + unset($options['prefixPath']); + } + + if (isset($options['disableTranslator'])) { + $this->setDisableTranslator($options['disableTranslator']); + unset($options['disableTranslator']); + } + + unset($options['options']); + unset($options['config']); + + foreach ($options as $key => $value) { + $method = 'set' . ucfirst($key); + + if (in_array($method, array('setTranslator', 'setPluginLoader', 'setView'))) { + if (!is_object($value)) { + continue; + } + } + + if (method_exists($this, $method)) { + // Setter exists; use it + $this->$method($value); + } else { + // Assume it's metadata + $this->setAttrib($key, $value); + } + } + return $this; + } + + /** + * Set object state from Zend_Config object + * + * @param Zend_Config $config + * @return Zend_Form_Element + */ + public function setConfig(Zend_Config $config) + { + return $this->setOptions($config->toArray()); + } + + + // Localization: + + /** + * Set translator object for localization + * + * @param Zend_Translate|null $translator + * @return Zend_Form_Element + */ + public function setTranslator($translator = null) + { + if (null === $translator) { + $this->_translator = null; + } elseif ($translator instanceof Zend_Translate_Adapter) { + $this->_translator = $translator; + } elseif ($translator instanceof Zend_Translate) { + $this->_translator = $translator->getAdapter(); + } else { + throw new Zend_Form_Exception('Invalid translator specified'); + } + return $this; + } + + /** + * Retrieve localization translator object + * + * @return Zend_Translate_Adapter|null + */ + public function getTranslator() + { + if ($this->translatorIsDisabled()) { + return null; + } + + if (null === $this->_translator) { + return Zend_Form::getDefaultTranslator(); + } + return $this->_translator; + } + + /** + * Does this element have its own specific translator? + * + * @return bool + */ + public function hasTranslator() + { + return (bool)$this->_translator; + } + + /** + * Indicate whether or not translation should be disabled + * + * @param bool $flag + * @return Zend_Form_Element + */ + public function setDisableTranslator($flag) + { + $this->_translatorDisabled = (bool) $flag; + return $this; + } + + /** + * Is translation disabled? + * + * @return bool + */ + public function translatorIsDisabled() + { + return $this->_translatorDisabled; + } + + // Metadata + + /** + * Filter a name to only allow valid variable characters + * + * @param string $value + * @param bool $allowBrackets + * @return string + */ + public function filterName($value, $allowBrackets = false) + { + $charset = '^a-zA-Z0-9_\x7f-\xff'; + if ($allowBrackets) { + $charset .= '\[\]'; + } + return preg_replace('/[' . $charset . ']/', '', (string) $value); + } + + /** + * Set element name + * + * @param string $name + * @return Zend_Form_Element + */ + public function setName($name) + { + $name = $this->filterName($name); + if ('' === $name) { + throw new Zend_Form_Exception('Invalid name provided; must contain only valid variable characters and be non-empty'); + } + + $this->_name = $name; + return $this; + } + + /** + * Return element name + * + * @return string + */ + public function getName() + { + return $this->_name; + } + + /** + * Get fully qualified name + * + * Places name as subitem of array and/or appends brackets. + * + * @return string + */ + public function getFullyQualifiedName() + { + $name = $this->getName(); + + if (null !== ($belongsTo = $this->getBelongsTo())) { + $name = $belongsTo . '[' . $name . ']'; + } + + if ($this->isArray()) { + $name .= '[]'; + } + + return $name; + } + + /** + * Get element id + * + * @return string + */ + public function getId() + { + if (isset($this->id)) { + return $this->id; + } + + $id = $this->getFullyQualifiedName(); + + // Bail early if no array notation detected + if (!strstr($id, '[')) { + return $id; + } + + // Strip array notation + if ('[]' == substr($id, -2)) { + $id = substr($id, 0, strlen($id) - 2); + } + $id = str_replace('][', '-', $id); + $id = str_replace(array(']', '['), '-', $id); + $id = trim($id, '-'); + + return $id; + } + + /** + * Set element value + * + * @param mixed $value + * @return Zend_Form_Element + */ + public function setValue($value) + { + $this->_value = $value; + return $this; + } + + /** + * Filter a value + * + * @param string $value + * @param string $key + * @return void + */ + protected function _filterValue(&$value, &$key) + { + foreach ($this->getFilters() as $filter) { + $value = $filter->filter($value); + } + } + + /** + * Retrieve filtered element value + * + * @return mixed + */ + public function getValue() + { + $valueFiltered = $this->_value; + + if ($this->isArray() && is_array($valueFiltered)) { + array_walk_recursive($valueFiltered, function (&$val, $key) { + $this->_filterValue($val, $key); + }); + } else { + $this->_filterValue($valueFiltered, $valueFiltered); + } + + return $valueFiltered; + } + + /** + * Retrieve unfiltered element value + * + * @return mixed + */ + public function getUnfilteredValue() + { + return $this->_value; + } + + /** + * Set element label + * + * @param string $label + * @return Zend_Form_Element + */ + public function setLabel($label) + { + $this->_label = (string) $label; + return $this; + } + + /** + * Retrieve element label + * + * @return string + */ + public function getLabel() + { + $translator = $this->getTranslator(); + if (null !== $translator) { + return $translator->translate($this->_label); + } + + return $this->_label; + } + + /** + * Set element order + * + * @param int $order + * @return Zend_Form_Element + */ + public function setOrder($order) + { + $this->_order = (int) $order; + return $this; + } + + /** + * Retrieve element order + * + * @return int + */ + public function getOrder() + { + return $this->_order; + } + + /** + * Set required flag + * + * @param bool $flag Default value is true + * @return Zend_Form_Element + */ + public function setRequired($flag = true) + { + $this->_required = (bool) $flag; + return $this; + } + + /** + * Is the element required? + * + * @return bool + */ + public function isRequired() + { + return $this->_required; + } + + /** + * Set flag indicating whether a NotEmpty validator should be inserted when element is required + * + * @param bool $flag + * @return Zend_Form_Element + */ + public function setAutoInsertNotEmptyValidator($flag) + { + $this->_autoInsertNotEmptyValidator = (bool) $flag; + return $this; + } + + /** + * Get flag indicating whether a NotEmpty validator should be inserted when element is required + * + * @return bool + */ + public function autoInsertNotEmptyValidator() + { + return $this->_autoInsertNotEmptyValidator; + } + + /** + * Set element description + * + * @param string $description + * @return Zend_Form_Element + */ + public function setDescription($description) + { + $this->_description = (string) $description; + return $this; + } + + /** + * Retrieve element description + * + * @return string + */ + public function getDescription() + { + return $this->_description; + } + + /** + * Set 'allow empty' flag + * + * When the allow empty flag is enabled and the required flag is false, the + * element will validate with empty values. + * + * @param bool $flag + * @return Zend_Form_Element + */ + public function setAllowEmpty($flag) + { + $this->_allowEmpty = (bool) $flag; + return $this; + } + + /** + * Get 'allow empty' flag + * + * @return bool + */ + public function getAllowEmpty() + { + return $this->_allowEmpty; + } + + /** + * Set ignore flag (used when retrieving values at form level) + * + * @param bool $flag + * @return Zend_Form_Element + */ + public function setIgnore($flag) + { + $this->_ignore = (bool) $flag; + return $this; + } + + /** + * Get ignore flag (used when retrieving values at form level) + * + * @return bool + */ + public function getIgnore() + { + return $this->_ignore; + } + + /** + * Set flag indicating if element represents an array + * + * @param bool $flag + * @return Zend_Form_Element + */ + public function setIsArray($flag) + { + $this->_isArray = (bool) $flag; + return $this; + } + + /** + * Is the element representing an array? + * + * @return bool + */ + public function isArray() + { + return $this->_isArray; + } + + /** + * Set array to which element belongs + * + * @param string $array + * @return Zend_Form_Element + */ + public function setBelongsTo($array) + { + $array = $this->filterName($array, true); + if (!empty($array)) { + $this->_belongsTo = $array; + } + + return $this; + } + + /** + * Return array name to which element belongs + * + * @return string + */ + public function getBelongsTo() + { + return $this->_belongsTo; + } + + /** + * Return element type + * + * @return string + */ + public function getType() + { + if (null === $this->_type) { + $this->_type = get_class($this); + } + + return $this->_type; + } + + /** + * Set element attribute + * + * @param string $name + * @param mixed $value + * @return Zend_Form_Element + * @throws Zend_Form_Exception for invalid $name values + */ + public function setAttrib($name, $value) + { + $name = (string) $name; + if ('_' == $name[0]) { + throw new Zend_Form_Exception(sprintf('Invalid attribute "%s"; must not contain a leading underscore', $name)); + } + + if (null === $value) { + unset($this->$name); + } else { + $this->$name = $value; + } + + return $this; + } + + /** + * Set multiple attributes at once + * + * @param array $attribs + * @return Zend_Form_Element + */ + public function setAttribs(array $attribs) + { + foreach ($attribs as $key => $value) { + $this->setAttrib($key, $value); + } + + return $this; + } + + /** + * Retrieve element attribute + * + * @param string $name + * @return string + */ + public function getAttrib($name) + { + $name = (string) $name; + if (isset($this->$name)) { + return $this->$name; + } + + return null; + } + + /** + * 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; + } + + /** + * Use one error message for array elements with concatenated values + * + * @param boolean $concatJustValuesInErrorMessage + * @return Zend_Form_Element + */ + public function setConcatJustValuesInErrorMessage($concatJustValuesInErrorMessage) + { + $this->_concatJustValuesInErrorMessage = $concatJustValuesInErrorMessage; + return $this; + } + + /** + * Use one error message for array elements with concatenated values + * + * @return boolean + */ + public function getConcatJustValuesInErrorMessage() + { + return $this->_concatJustValuesInErrorMessage; + } + + /** + * Overloading: retrieve object property + * + * Prevents access to properties beginning with '_'. + * + * @param string $key + * @return mixed + */ + public function __get($key) + { + if ('_' == $key[0]) { + throw new Zend_Form_Exception(sprintf('Cannot retrieve value for protected/private property "%s"', $key)); + } + + if (!isset($this->$key)) { + return null; + } + + return $this->$key; + } + + /** + * Overloading: set object property + * + * @param string $key + * @param mixed $value + * @return voide + */ + public function __set($key, $value) + { + $this->setAttrib($key, $value); + } + + /** + * Overloading: allow rendering specific decorators + * + * Call renderDecoratorName() to render a specific decorator. + * + * @param string $method + * @param array $args + * @return string + * @throws Zend_Form_Exception for invalid decorator or invalid method call + */ + public function __call($method, $args) + { + if ('render' == substr($method, 0, 6)) { + $this->_isPartialRendering = true; + $this->render(); + $this->_isPartialRendering = false; + $decoratorName = substr($method, 6); + if (false !== ($decorator = $this->getDecorator($decoratorName))) { + $decorator->setElement($this); + $seed = ''; + if (0 < count($args)) { + $seed = array_shift($args); + } + return $decorator->render($seed); + } + + throw new Zend_Form_Element_Exception(sprintf('Decorator by name %s does not exist', $decoratorName)); + } + + throw new Zend_Form_Element_Exception(sprintf('Method %s does not exist', $method)); + } + + // Loaders + + /** + * Set plugin loader to use for validator or filter chain + * + * @param Zend_Loader_PluginLoader_Interface $loader + * @param string $type 'decorator', 'filter', or 'validate' + * @return Zend_Form_Element + * @throws Zend_Form_Exception on invalid type + */ + public function setPluginLoader(Zend_Loader_PluginLoader_Interface $loader, $type) + { + $type = strtoupper($type); + switch ($type) { + case self::DECORATOR: + case self::FILTER: + case self::VALIDATE: + $this->_loaders[$type] = $loader; + return $this; + default: + throw new Zend_Form_Exception(sprintf('Invalid type "%s" provided to setPluginLoader()', $type)); + } + } + + /** + * Retrieve plugin loader for validator or filter chain + * + * Instantiates with default rules if none available for that type. Use + * 'decorator', 'filter', or 'validate' for $type. + * + * @param string $type + * @return Zend_Loader_PluginLoader + * @throws Zend_Loader_Exception on invalid type. + */ + public function getPluginLoader($type) + { + $type = strtoupper($type); + switch ($type) { + case self::FILTER: + case self::VALIDATE: + $prefixSegment = ucfirst(strtolower($type)); + $pathSegment = $prefixSegment; + case self::DECORATOR: + if (!isset($prefixSegment)) { + $prefixSegment = 'Form_Decorator'; + $pathSegment = 'Form/Decorator'; + } + if (!isset($this->_loaders[$type])) { + $this->_loaders[$type] = new Zend_Loader_PluginLoader( + array('Zend_' . $prefixSegment . '_' => 'Zend/' . $pathSegment . '/') + ); + } + return $this->_loaders[$type]; + default: + throw new Zend_Form_Exception(sprintf('Invalid type "%s" provided to getPluginLoader()', $type)); + } + } + + /** + * Add prefix path for plugin loader + * + * 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 $prefix + * @param string $path + * @param string $type + * @return Zend_Form_Element + * @throws Zend_Form_Exception for invalid type + */ + public function addPrefixPath($prefix, $path, $type = null) + { + $type = strtoupper($type); + switch ($type) { + case self::DECORATOR: + case self::FILTER: + case self::VALIDATE: + $loader = $this->getPluginLoader($type); + $loader->addPrefixPath($prefix, $path); + return $this; + case null: + $nsSeparator = (false !== strpos($prefix, '\\'))?'\\':'_'; + $prefix = rtrim($prefix, $nsSeparator) . $nsSeparator; + $path = rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; + foreach (array(self::DECORATOR, self::FILTER, self::VALIDATE) as $type) { + $cType = ucfirst(strtolower($type)); + $loader = $this->getPluginLoader($type); + $loader->addPrefixPath($prefix . $cType, $path . $cType . DIRECTORY_SEPARATOR); + } + return $this; + default: + throw new Zend_Form_Exception(sprintf('Invalid type "%s" provided to getPluginLoader()', $type)); + } + } + + /** + * Add many prefix paths at once + * + * @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; + if (isset($paths['prefix']) && isset($paths['path'])) { + if (isset($paths['type'])) { + $type = $paths['type']; + } + $this->addPrefixPath($paths['prefix'], $paths['path'], $type); + } + } elseif (!is_numeric($type)) { + if (!isset($paths['prefix']) || !isset($paths['path'])) { + foreach ($paths as $prefix => $spec) { + if (is_array($spec)) { + foreach ($spec as $path) { + if (!is_string($path)) { + continue; + } + $this->addPrefixPath($prefix, $path, $type); + } + } elseif (is_string($spec)) { + $this->addPrefixPath($prefix, $spec, $type); + } + } + } else { + $this->addPrefixPath($paths['prefix'], $paths['path'], $type); + } + } + } + return $this; + } + + // Validation + + /** + * Add validator to validation chain + * + * Note: will overwrite existing validators if they are of the same class. + * + * @param string|Zend_Validate_Interface $validator + * @param bool $breakChainOnFailure + * @param array $options + * @return Zend_Form_Element + * @throws Zend_Form_Exception if invalid validator type + */ + public function addValidator($validator, $breakChainOnFailure = false, $options = array()) + { + if ($validator instanceof Zend_Validate_Interface) { + $name = get_class($validator); + + if (!isset($validator->zfBreakChainOnFailure)) { + $validator->zfBreakChainOnFailure = $breakChainOnFailure; + } + } elseif (is_string($validator)) { + $name = $validator; + $validator = array( + 'validator' => $validator, + 'breakChainOnFailure' => $breakChainOnFailure, + 'options' => $options, + ); + } else { + throw new Zend_Form_Exception('Invalid validator provided to addValidator; must be string or Zend_Validate_Interface'); + } + + + $this->_validators[$name] = $validator; + + return $this; + } + + /** + * Add multiple validators + * + * @param array $validators + * @return Zend_Form_Element + */ + public function addValidators(array $validators) + { + foreach ($validators as $validatorInfo) { + if (is_string($validatorInfo)) { + $this->addValidator($validatorInfo); + } elseif ($validatorInfo instanceof Zend_Validate_Interface) { + $this->addValidator($validatorInfo); + } elseif (is_array($validatorInfo)) { + $argc = count($validatorInfo); + $breakChainOnFailure = false; + $options = array(); + if (isset($validatorInfo['validator'])) { + $validator = $validatorInfo['validator']; + if (isset($validatorInfo['breakChainOnFailure'])) { + $breakChainOnFailure = $validatorInfo['breakChainOnFailure']; + } + if (isset($validatorInfo['options'])) { + $options = $validatorInfo['options']; + } + $this->addValidator($validator, $breakChainOnFailure, $options); + } else { + switch (true) { + case (0 == $argc): + break; + case (1 <= $argc): + $validator = array_shift($validatorInfo); + case (2 <= $argc): + $breakChainOnFailure = array_shift($validatorInfo); + case (3 <= $argc): + $options = array_shift($validatorInfo); + default: + $this->addValidator($validator, $breakChainOnFailure, $options); + break; + } + } + } else { + throw new Zend_Form_Exception('Invalid validator passed to addValidators()'); + } + } + + return $this; + } + + /** + * Set multiple validators, overwriting previous validators + * + * @param array $validators + * @return Zend_Form_Element + */ + public function setValidators(array $validators) + { + $this->clearValidators(); + return $this->addValidators($validators); + } + + /** + * Retrieve a single validator by name + * + * @param string $name + * @return Zend_Validate_Interface|false False if not found, validator otherwise + */ + public function getValidator($name) + { + if (!isset($this->_validators[$name])) { + $len = strlen($name); + foreach ($this->_validators as $localName => $validator) { + if ($len > strlen($localName)) { + continue; + } + if (0 === substr_compare($localName, $name, -$len, $len, true)) { + if (is_array($validator)) { + return $this->_loadValidator($validator); + } + return $validator; + } + } + return false; + } + + if (is_array($this->_validators[$name])) { + return $this->_loadValidator($this->_validators[$name]); + } + + return $this->_validators[$name]; + } + + /** + * Retrieve all validators + * + * @return array + */ + public function getValidators() + { + $validators = array(); + foreach ($this->_validators as $key => $value) { + if ($value instanceof Zend_Validate_Interface) { + $validators[$key] = $value; + continue; + } + $validator = $this->_loadValidator($value); + $validators[get_class($validator)] = $validator; + } + return $validators; + } + + /** + * Remove a single validator by name + * + * @param string $name + * @return bool + */ + public function removeValidator($name) + { + if (isset($this->_validators[$name])) { + unset($this->_validators[$name]); + } else { + $len = strlen($name); + foreach (array_keys($this->_validators) as $validator) { + if ($len > strlen($validator)) { + continue; + } + if (0 === substr_compare($validator, $name, -$len, $len, true)) { + unset($this->_validators[$validator]); + break; + } + } + } + + return $this; + } + + /** + * Clear all validators + * + * @return Zend_Form_Element + */ + public function clearValidators() + { + $this->_validators = array(); + return $this; + } + + /** + * 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 + * utilized. + * + * Note: The *filtered* value is validated. + * + * @param mixed $value + * @param mixed $context + * @return boolean + */ + public function isValid($value, $context = null) + { + $this->setValue($value); + $value = $this->getValue(); + + if ((('' === $value) || (null === $value)) + && !$this->isRequired() + && $this->getAllowEmpty() + ) { + return true; + } + + if ($this->isRequired() + && $this->autoInsertNotEmptyValidator() + && !$this->getValidator('NotEmpty')) + { + $validators = $this->getValidators(); + $notEmpty = array('validator' => 'NotEmpty', 'breakChainOnFailure' => true); + array_unshift($validators, $notEmpty); + $this->setValidators($validators); + } + + // Find the correct translator. Zend_Validate_Abstract::getDefaultTranslator() + // will get either the static translator attached to Zend_Validate_Abstract + // or the 'Zend_Translate' from Zend_Registry. + if (Zend_Validate_Abstract::hasDefaultTranslator() && + !Zend_Form::hasDefaultTranslator()) + { + $translator = Zend_Validate_Abstract::getDefaultTranslator(); + if ($this->hasTranslator()) { + // only pick up this element's translator if it was attached directly. + $translator = $this->getTranslator(); + } + } else { + $translator = $this->getTranslator(); + } + + $this->_messages = array(); + $this->_errors = array(); + $result = true; + $isArray = $this->isArray(); + foreach ($this->getValidators() as $key => $validator) { + if (method_exists($validator, 'setTranslator')) { + if (method_exists($validator, 'hasTranslator')) { + if (!$validator->hasTranslator()) { + $validator->setTranslator($translator); + } + } else { + $validator->setTranslator($translator); + } + } + + if (method_exists($validator, 'setDisableTranslator')) { + $validator->setDisableTranslator($this->translatorIsDisabled()); + } + + if ($isArray && is_array($value)) { + $messages = array(); + $errors = array(); + if (empty($value)) { + if ($this->isRequired() + || (!$this->isRequired() && !$this->getAllowEmpty()) + ) { + $value = ''; + } + } + foreach ((array)$value as $val) { + if (!$validator->isValid($val, $context)) { + $result = false; + if ($this->_hasErrorMessages()) { + $messages = $this->_getErrorMessages(); + $errors = $messages; + } else { + $messages = array_merge($messages, $validator->getMessages()); + $errors = array_merge($errors, $validator->getErrors()); + } + } + } + if ($result) { + continue; + } + } elseif ($validator->isValid($value, $context)) { + continue; + } else { + $result = false; + if ($this->_hasErrorMessages()) { + $messages = $this->_getErrorMessages(); + $errors = $messages; + } else { + $messages = $validator->getMessages(); + $errors = array_keys($messages); + } + } + + $result = false; + $this->_messages = array_merge($this->_messages, $messages); + $this->_errors = array_merge($this->_errors, $errors); + + if ($validator->zfBreakChainOnFailure) { + break; + } + } + + // If element manually flagged as invalid, return false + if ($this->_isErrorForced) { + return false; + } + + return $result; + } + + /** + * Add a custom error message to return in the event of failed validation + * + * @param string $message + * @return Zend_Form_Element + */ + public function addErrorMessage($message) + { + $this->_errorMessages[] = (string) $message; + return $this; + } + + /** + * Add multiple custom error messages to return in the event of failed validation + * + * @param array $messages + * @return Zend_Form_Element + */ + public function addErrorMessages(array $messages) + { + foreach ($messages as $message) { + $this->addErrorMessage($message); + } + return $this; + } + + /** + * Same as addErrorMessages(), but clears custom error message stack first + * + * @param array $messages + * @return Zend_Form_Element + */ + public function setErrorMessages(array $messages) + { + $this->clearErrorMessages(); + return $this->addErrorMessages($messages); + } + + /** + * Retrieve custom error messages + * + * @return array + */ + public function getErrorMessages() + { + return $this->_errorMessages; + } + + /** + * Clear custom error messages stack + * + * @return Zend_Form_Element + */ + public function clearErrorMessages() + { + $this->_errorMessages = array(); + return $this; + } + + /** + * Get errorMessageSeparator + * + * @return string + */ + public function getErrorMessageSeparator() + { + return $this->_errorMessageSeparator; + } + + /** + * Set errorMessageSeparator + * + * @param string $separator + * @return Zend_Form_Element + */ + public function setErrorMessageSeparator($separator) + { + $this->_errorMessageSeparator = $separator; + return $this; + } + + /** + * Mark the element as being in a failed validation state + * + * @return Zend_Form_Element + */ + public function markAsError() + { + $messages = $this->getMessages(); + $customMessages = $this->_getErrorMessages(); + $messages = $messages + $customMessages; + if (empty($messages)) { + $this->_isError = true; + } else { + $this->_messages = $messages; + } + $this->_isErrorForced = true; + return $this; + } + + /** + * Add an error message and mark element as failed validation + * + * @param string $message + * @return Zend_Form_Element + */ + public function addError($message) + { + $this->addErrorMessage($message); + $this->markAsError(); + return $this; + } + + /** + * Add multiple error messages and flag element as failed validation + * + * @param array $messages + * @return Zend_Form_Element + */ + public function addErrors(array $messages) + { + foreach ($messages as $message) { + $this->addError($message); + } + return $this; + } + + /** + * Overwrite any previously set error messages and flag as failed validation + * + * @param array $messages + * @return Zend_Form_Element + */ + public function setErrors(array $messages) + { + $this->clearErrorMessages(); + return $this->addErrors($messages); + } + + /** + * Are there errors registered? + * + * @return bool + */ + public function hasErrors() + { + return (!empty($this->_messages) || $this->_isError); + } + + /** + * Retrieve validator chain errors + * + * @return array + */ + public function getErrors() + { + return $this->_errors; + } + + /** + * Retrieve error messages + * + * @return array + */ + public function getMessages() + { + return $this->_messages; + } + + + // Filtering + + /** + * Add a filter to the element + * + * @param string|Zend_Filter_Interface $filter + * @return Zend_Form_Element + */ + public function addFilter($filter, $options = array()) + { + if ($filter instanceof Zend_Filter_Interface) { + $name = get_class($filter); + } elseif (is_string($filter)) { + $name = $filter; + $filter = array( + 'filter' => $filter, + 'options' => $options, + ); + $this->_filters[$name] = $filter; + } else { + throw new Zend_Form_Exception('Invalid filter provided to addFilter; must be string or Zend_Filter_Interface'); + } + + $this->_filters[$name] = $filter; + + return $this; + } + + /** + * Add filters to element + * + * @param array $filters + * @return Zend_Form_Element + */ + public function addFilters(array $filters) + { + foreach ($filters as $filterInfo) { + if (is_string($filterInfo)) { + $this->addFilter($filterInfo); + } elseif ($filterInfo instanceof Zend_Filter_Interface) { + $this->addFilter($filterInfo); + } elseif (is_array($filterInfo)) { + $argc = count($filterInfo); + $options = array(); + if (isset($filterInfo['filter'])) { + $filter = $filterInfo['filter']; + if (isset($filterInfo['options'])) { + $options = $filterInfo['options']; + } + $this->addFilter($filter, $options); + } else { + switch (true) { + case (0 == $argc): + break; + case (1 <= $argc): + $filter = array_shift($filterInfo); + case (2 <= $argc): + $options = array_shift($filterInfo); + default: + $this->addFilter($filter, $options); + break; + } + } + } else { + throw new Zend_Form_Exception('Invalid filter passed to addFilters()'); + } + } + + return $this; + } + + /** + * Add filters to element, overwriting any already existing + * + * @param array $filters + * @return Zend_Form_Element + */ + public function setFilters(array $filters) + { + $this->clearFilters(); + return $this->addFilters($filters); + } + + /** + * Retrieve a single filter by name + * + * @param string $name + * @return Zend_Filter_Interface + */ + public function getFilter($name) + { + if (!isset($this->_filters[$name])) { + $len = strlen($name); + foreach ($this->_filters as $localName => $filter) { + if ($len > strlen($localName)) { + continue; + } + + if (0 === substr_compare($localName, $name, -$len, $len, true)) { + if (is_array($filter)) { + return $this->_loadFilter($filter); + } + return $filter; + } + } + return false; + } + + if (is_array($this->_filters[$name])) { + return $this->_loadFilter($this->_filters[$name]); + } + + return $this->_filters[$name]; + } + + /** + * Get all filters + * + * @return array + */ + public function getFilters() + { + $filters = array(); + foreach ($this->_filters as $key => $value) { + if ($value instanceof Zend_Filter_Interface) { + $filters[$key] = $value; + continue; + } + $filter = $this->_loadFilter($value); + $filters[get_class($filter)] = $filter; + } + return $filters; + } + + /** + * Remove a filter by name + * + * @param string $name + * @return Zend_Form_Element + */ + public function removeFilter($name) + { + if (isset($this->_filters[$name])) { + unset($this->_filters[$name]); + } else { + $len = strlen($name); + foreach (array_keys($this->_filters) as $filter) { + if ($len > strlen($filter)) { + continue; + } + if (0 === substr_compare($filter, $name, -$len, $len, true)) { + unset($this->_filters[$filter]); + break; + } + } + } + + return $this; + } + + /** + * Clear all filters + * + * @return Zend_Form_Element + */ + public function clearFilters() + { + $this->_filters = array(); + return $this; + } + + // Rendering + + /** + * Set view object + * + * @param Zend_View_Interface $view + * @return Zend_Form_Element + */ + public function setView(Zend_View_Interface $view = null) + { + $this->_view = $view; + return $this; + } + + /** + * Retrieve view object + * + * Retrieves from ViewRenderer if none previously set. + * + * @return null|Zend_View_Interface + */ + public function getView() + { + if (null === $this->_view) { + $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer'); + $this->setView($viewRenderer->view); + } + return $this->_view; + } + + /** + * Instantiate a decorator based on class name or class name fragment + * + * @param string $name + * @param null|array $options + * @return Zend_Form_Decorator_Interface + */ + protected function _getDecorator($name, $options) + { + $class = $this->getPluginLoader(self::DECORATOR)->load($name); + if (null === $options) { + $decorator = new $class; + } else { + $decorator = new $class($options); + } + + return $decorator; + } + + /** + * Add a decorator for rendering the element + * + * @param string|Zend_Form_Decorator_Interface $decorator + * @param array|Zend_Config $options Options with which to initialize decorator + * @return Zend_Form_Element + */ + public function addDecorator($decorator, $options = null) + { + if ($decorator instanceof Zend_Form_Decorator_Interface) { + $name = get_class($decorator); + } elseif (is_string($decorator)) { + $name = $decorator; + $decorator = array( + 'decorator' => $name, + 'options' => $options, + ); + } elseif (is_array($decorator)) { + foreach ($decorator as $name => $spec) { + break; + } + if (is_numeric($name)) { + throw new Zend_Form_Exception('Invalid alias provided to addDecorator; must be alphanumeric string'); + } + if (is_string($spec)) { + $decorator = array( + 'decorator' => $spec, + 'options' => $options, + ); + } elseif ($spec instanceof Zend_Form_Decorator_Interface) { + $decorator = $spec; + } + } else { + throw new Zend_Form_Exception('Invalid decorator provided to addDecorator; must be string or Zend_Form_Decorator_Interface'); + } + + $this->_decorators[$name] = $decorator; + + return $this; + } + + /** + * Add many decorators at once + * + * @param array $decorators + * @return Zend_Form_Element + */ + public function addDecorators(array $decorators) + { + foreach ($decorators as $decoratorName => $decoratorInfo) { + if (is_string($decoratorInfo) || + $decoratorInfo instanceof Zend_Form_Decorator_Interface) { + if (!is_numeric($decoratorName)) { + $this->addDecorator(array($decoratorName => $decoratorInfo)); + } else { + $this->addDecorator($decoratorInfo); + } + } elseif (is_array($decoratorInfo)) { + $argc = count($decoratorInfo); + $options = array(); + if (isset($decoratorInfo['decorator'])) { + $decorator = $decoratorInfo['decorator']; + if (isset($decoratorInfo['options'])) { + $options = $decoratorInfo['options']; + } + $this->addDecorator($decorator, $options); + } else { + switch (true) { + case (0 == $argc): + break; + case (1 <= $argc): + $decorator = array_shift($decoratorInfo); + case (2 <= $argc): + $options = array_shift($decoratorInfo); + default: + $this->addDecorator($decorator, $options); + break; + } + } + } else { + throw new Zend_Form_Exception('Invalid decorator passed to addDecorators()'); + } + } + + return $this; + } + + /** + * Overwrite all decorators + * + * @param array $decorators + * @return Zend_Form_Element + */ + public function setDecorators(array $decorators) + { + $this->clearDecorators(); + return $this->addDecorators($decorators); + } + + /** + * Retrieve a registered decorator + * + * @param string $name + * @return false|Zend_Form_Decorator_Abstract + */ + public function getDecorator($name) + { + if (!isset($this->_decorators[$name])) { + $len = strlen($name); + foreach ($this->_decorators as $localName => $decorator) { + if ($len > strlen($localName)) { + continue; + } + + if (0 === substr_compare($localName, $name, -$len, $len, true)) { + if (is_array($decorator)) { + return $this->_loadDecorator($decorator, $localName); + } + return $decorator; + } + } + return false; + } + + if (is_array($this->_decorators[$name])) { + return $this->_loadDecorator($this->_decorators[$name], $name); + } + + return $this->_decorators[$name]; + } + + /** + * Retrieve all decorators + * + * @return array + */ + public function getDecorators() + { + foreach ($this->_decorators as $key => $value) { + if (is_array($value)) { + $this->_loadDecorator($value, $key); + } + } + return $this->_decorators; + } + + /** + * Remove a single decorator + * + * @param string $name + * @return Zend_Form_Element + */ + public function removeDecorator($name) + { + if (isset($this->_decorators[$name])) { + unset($this->_decorators[$name]); + } else { + $len = strlen($name); + foreach (array_keys($this->_decorators) as $decorator) { + if ($len > strlen($decorator)) { + continue; + } + if (0 === substr_compare($decorator, $name, -$len, $len, true)) { + unset($this->_decorators[$decorator]); + break; + } + } + } + + return $this; + } + + /** + * Clear all decorators + * + * @return Zend_Form_Element + */ + public function clearDecorators() + { + $this->_decorators = array(); + return $this; + } + + /** + * Render form element + * + * @param Zend_View_Interface $view + * @return string + */ + public function render(Zend_View_Interface $view = null) + { + if ($this->_isPartialRendering) { + return ''; + } + + if (null !== $view) { + $this->setView($view); + } + + $content = ''; + foreach ($this->getDecorators() as $decorator) { + $decorator->setElement($this); + $content = $decorator->render($content); + } + return $content; + } + + /** + * String representation of form element + * + * Proxies to {@link render()}. + * + * @return string + */ + public function __toString() + { + try { + $return = $this->render(); + return $return; + } catch (Exception $e) { + trigger_error($e->getMessage(), E_USER_WARNING); + return ''; + } + } + + /** + * Lazy-load a filter + * + * @param array $filter + * @return Zend_Filter_Interface + */ + protected function _loadFilter(array $filter) + { + $origName = $filter['filter']; + $name = $this->getPluginLoader(self::FILTER)->load($filter['filter']); + + if (array_key_exists($name, $this->_filters)) { + throw new Zend_Form_Exception(sprintf('Filter instance already exists for filter "%s"', $origName)); + } + + if (empty($filter['options'])) { + $instance = new $name; + } else { + $r = new ReflectionClass($name); + if ($r->hasMethod('__construct')) { + $instance = $r->newInstanceArgs(array_values((array) $filter['options'])); + } else { + $instance = $r->newInstance(); + } + } + + if ($origName != $name) { + $filterNames = array_keys($this->_filters); + $order = array_flip($filterNames); + $order[$name] = $order[$origName]; + $filtersExchange = array(); + unset($order[$origName]); + asort($order); + foreach ($order as $key => $index) { + if ($key == $name) { + $filtersExchange[$key] = $instance; + continue; + } + $filtersExchange[$key] = $this->_filters[$key]; + } + $this->_filters = $filtersExchange; + } else { + $this->_filters[$name] = $instance; + } + + return $instance; + } + + /** + * Lazy-load a validator + * + * @param array $validator Validator definition + * @return Zend_Validate_Interface + */ + protected function _loadValidator(array $validator) + { + $origName = $validator['validator']; + $name = $this->getPluginLoader(self::VALIDATE)->load($validator['validator']); + + if (array_key_exists($name, $this->_validators)) { + throw new Zend_Form_Exception(sprintf('Validator instance already exists for validator "%s"', $origName)); + } + + $messages = false; + if (isset($validator['options']) && array_key_exists('messages', (array)$validator['options'])) { + $messages = $validator['options']['messages']; + unset($validator['options']['messages']); + } + + if (empty($validator['options'])) { + $instance = new $name; + } else { + $r = new ReflectionClass($name); + if ($r->hasMethod('__construct')) { + $numeric = false; + if (is_array($validator['options'])) { + $keys = array_keys($validator['options']); + foreach($keys as $key) { + if (is_numeric($key)) { + $numeric = true; + break; + } + } + } + + if ($numeric) { + $instance = $r->newInstanceArgs(array_values((array) $validator['options'])); + } else { + $instance = $r->newInstance($validator['options']); + } + } else { + $instance = $r->newInstance(); + } + } + + if ($messages) { + if (is_array($messages)) { + $instance->setMessages($messages); + } elseif (is_string($messages)) { + $instance->setMessage($messages); + } + } + $instance->zfBreakChainOnFailure = $validator['breakChainOnFailure']; + + if ($origName != $name) { + $validatorNames = array_keys($this->_validators); + $order = array_flip($validatorNames); + $order[$name] = $order[$origName]; + $validatorsExchange = array(); + unset($order[$origName]); + asort($order); + foreach ($order as $key => $index) { + if ($key == $name) { + $validatorsExchange[$key] = $instance; + continue; + } + $validatorsExchange[$key] = $this->_validators[$key]; + } + $this->_validators = $validatorsExchange; + } else { + $this->_validators[$name] = $instance; + } + + return $instance; + } + + /** + * Lazy-load a decorator + * + * @param array $decorator Decorator type and options + * @param mixed $name Decorator name or alias + * @return Zend_Form_Decorator_Interface + */ + protected function _loadDecorator(array $decorator, $name) + { + $sameName = false; + if ($name == $decorator['decorator']) { + $sameName = true; + } + + $instance = $this->_getDecorator($decorator['decorator'], $decorator['options']); + if ($sameName) { + $newName = get_class($instance); + $decoratorNames = array_keys($this->_decorators); + $order = array_flip($decoratorNames); + $order[$newName] = $order[$name]; + $decoratorsExchange = array(); + unset($order[$name]); + asort($order); + foreach ($order as $key => $index) { + if ($key == $newName) { + $decoratorsExchange[$key] = $instance; + continue; + } + $decoratorsExchange[$key] = $this->_decorators[$key]; + } + $this->_decorators = $decoratorsExchange; + } else { + $this->_decorators[$name] = $instance; + } + + return $instance; + } + + /** + * Retrieve error messages and perform translation and value substitution + * + * @return array + */ + protected function _getErrorMessages() + { + $translator = $this->getTranslator(); + $messages = $this->getErrorMessages(); + $value = $this->getValue(); + 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 (count($aggregateMessages)) { + if ($this->_concatJustValuesInErrorMessage) { + $values = implode($this->getErrorMessageSeparator(), $value); + $messages[$key] = str_replace('%value%', $values, $message); + } else { + $messages[$key] = implode($this->getErrorMessageSeparator(), $aggregateMessages); + } + } + } else { + $messages[$key] = str_replace('%value%', $value, $message); + } + } + return $messages; + } + + /** + * Are there custom error messages registered? + * + * @return bool + */ + protected function _hasErrorMessages() + { + return !empty($this->_errorMessages); + } +} diff --git a/library/vendor/Zend/Form/Element/Button.php b/library/vendor/Zend/Form/Element/Button.php new file mode 100644 index 0000000..89de056 --- /dev/null +++ b/library/vendor/Zend/Form/Element/Button.php @@ -0,0 +1,55 @@ + '1', + 'uncheckedValue' => '0', + ); + + /** + * Value when checked + * @var string + */ + protected $_checkedValue = '1'; + + /** + * Value when not checked + * @var string + */ + protected $_uncheckedValue = '0'; + + /** + * Current value + * @var string 0 or 1 + */ + protected $_value = '0'; + + /** + * Set options + * + * Intercept checked and unchecked values and set them early; test stored + * value against checked and unchecked values after configuration. + * + * @param array $options + * @return Zend_Form_Element_Checkbox + */ + public function setOptions(array $options) + { + if (array_key_exists('checkedValue', $options)) { + $this->setCheckedValue($options['checkedValue']); + unset($options['checkedValue']); + } + if (array_key_exists('uncheckedValue', $options)) { + $this->setUncheckedValue($options['uncheckedValue']); + unset($options['uncheckedValue']); + } + parent::setOptions($options); + + $curValue = $this->getValue(); + $test = array($this->getCheckedValue(), $this->getUncheckedValue()); + if (!in_array($curValue, $test)) { + $this->setValue($curValue); + } + + return $this; + } + + /** + * Set value + * + * If value matches checked value, sets to that value, and sets the checked + * flag to true. + * + * Any other value causes the unchecked value to be set as the current + * value, and the checked flag to be set as false. + * + * + * @param mixed $value + * @return Zend_Form_Element_Checkbox + */ + public function setValue($value) + { + if ($value == $this->getCheckedValue()) { + parent::setValue($value); + $this->checked = true; + } else { + parent::setValue($this->getUncheckedValue()); + $this->checked = false; + } + return $this; + } + + /** + * Set checked value + * + * @param string $value + * @return Zend_Form_Element_Checkbox + */ + public function setCheckedValue($value) + { + $this->_checkedValue = (string) $value; + $this->options['checkedValue'] = $value; + return $this; + } + + /** + * Get value when checked + * + * @return string + */ + public function getCheckedValue() + { + return $this->_checkedValue; + } + + /** + * Set unchecked value + * + * @param string $value + * @return Zend_Form_Element_Checkbox + */ + public function setUncheckedValue($value) + { + $this->_uncheckedValue = (string) $value; + $this->options['uncheckedValue'] = $value; + return $this; + } + + /** + * Get value when not checked + * + * @return string + */ + public function getUncheckedValue() + { + return $this->_uncheckedValue; + } + + /** + * Set checked flag + * + * @param bool $flag + * @return Zend_Form_Element_Checkbox + */ + public function setChecked($flag) + { + $this->checked = (bool) $flag; + if ($this->checked) { + $this->setValue($this->getCheckedValue()); + } else { + $this->setValue($this->getUncheckedValue()); + } + return $this; + } + + /** + * Get checked flag + * + * @return bool + */ + public function isChecked() + { + return $this->checked; + } +} diff --git a/library/vendor/Zend/Form/Element/Exception.php b/library/vendor/Zend/Form/Element/Exception.php new file mode 100644 index 0000000..b39e053 --- /dev/null +++ b/library/vendor/Zend/Form/Element/Exception.php @@ -0,0 +1,36 @@ +loadDefaultDecoratorsIsDisabled()) { + return $this; + } + + parent::loadDefaultDecorators(); + + // This element needs the File decorator and not the ViewHelper decorator + if (false !== $this->getDecorator('ViewHelper')) { + $this->removeDecorator('ViewHelper'); + } + if (false === $this->getDecorator('File')) { + // Add File decorator to the beginning + $decorators = $this->getDecorators(); + array_unshift($decorators, 'File'); + $this->setDecorators($decorators); + } + + return $this; + } + + /** + * 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)) { + $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)) { + $nsSeparator = (false !== strpos($prefix, '\\'))?'\\':'_'; + $pluginPrefix = rtrim($prefix, $nsSeparator) . $nsSeparator . 'Transfer' . $nsSeparator . '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 + * @throws Zend_Form_Element_Exception + */ + 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 { + throw new Zend_Form_Element_Exception('Invalid adapter specified'); + } + + foreach (array('filter', 'validate') as $type) { + $loader = $this->getPluginLoader($type); + $this->_adapter->setPluginLoader($loader, $type); + } + + return $this; + } + + /** + * Get transfer adapter + * + * Lazy loads HTTP transfer adapter when no adapter registered. + * + * @return Zend_File_Transfer_Adapter_Abstract + */ + public function getTransferAdapter() + { + if (null === $this->_adapter) { + $this->setTransferAdapter('Http'); + } + return $this->_adapter; + } + + /** + * Add Validator; proxy to adapter + * + * @param string|Zend_Validate_Interface $validator + * @param bool $breakChainOnFailure + * @param mixed $options + * @return Zend_Form_Element_File + */ + public function addValidator($validator, $breakChainOnFailure = false, $options = array()) + { + $adapter = $this->getTransferAdapter(); + $adapter->addValidator($validator, $breakChainOnFailure, $options, $this->getName()); + $this->_validated = false; + + return $this; + } + + /** + * Add multiple validators at once; proxy to adapter + * + * @param array $validators + * @return Zend_Form_Element_File + */ + public function addValidators(array $validators) + { + $adapter = $this->getTransferAdapter(); + $adapter->addValidators($validators, $this->getName()); + $this->_validated = false; + + return $this; + } + + /** + * Add multiple validators at once, overwriting; proxy to adapter + * + * @param array $validators + * @return Zend_Form_Element_File + */ + public function setValidators(array $validators) + { + $adapter = $this->getTransferAdapter(); + $adapter->setValidators($validators, $this->getName()); + $this->_validated = false; + + return $this; + } + + /** + * Retrieve validator by name; proxy to adapter + * + * @param string $name + * @return Zend_Validate_Interface|null + */ + public function getValidator($name) + { + $adapter = $this->getTransferAdapter(); + return $adapter->getValidator($name); + } + + /** + * Retrieve all validators; proxy to adapter + * + * @return array + */ + public function getValidators() + { + $adapter = $this->getTransferAdapter(); + $validators = $adapter->getValidators($this->getName()); + if ($validators === null) { + $validators = array(); + } + + return $validators; + } + + /** + * Remove validator by name; proxy to adapter + * + * @param string $name + * @return Zend_Form_Element_File + */ + public function removeValidator($name) + { + $adapter = $this->getTransferAdapter(); + $adapter->removeValidator($name); + $this->_validated = false; + + return $this; + } + + /** + * Remove all validators; proxy to adapter + * + * @return Zend_Form_Element_File + */ + public function clearValidators() + { + $adapter = $this->getTransferAdapter(); + $adapter->clearValidators(); + $this->_validated = false; + + return $this; + } + + /** + * Add Filter; proxy to adapter + * + * @param string|array $filter Type of filter to add + * @param string|array $options Options to set for the filter + * @return Zend_Form_Element_File + */ + public function addFilter($filter, $options = null) + { + $adapter = $this->getTransferAdapter(); + $adapter->addFilter($filter, $options, $this->getName()); + + return $this; + } + + /** + * Add Multiple filters at once; proxy to adapter + * + * @param array $filters + * @return Zend_Form_Element_File + */ + public function addFilters(array $filters) + { + $adapter = $this->getTransferAdapter(); + $adapter->addFilters($filters, $this->getName()); + + return $this; + } + + /** + * Sets a filter for the class, erasing all previous set; proxy to adapter + * + * @param array $filters Filters to set + * @return Zend_Form_Element_File + */ + public function setFilters(array $filters) + { + $adapter = $this->getTransferAdapter(); + $adapter->setFilters($filters, $this->getName()); + + return $this; + } + + /** + * Retrieve individual filter; proxy to adapter + * + * @param string $name + * @return Zend_Filter_Interface|null + */ + public function getFilter($name) + { + $adapter = $this->getTransferAdapter(); + return $adapter->getFilter($name); + } + + /** + * Returns all set filters; proxy to adapter + * + * @return array List of set filters + */ + public function getFilters() + { + $adapter = $this->getTransferAdapter(); + $filters = $adapter->getFilters($this->getName()); + + if ($filters === null) { + $filters = array(); + } + return $filters; + } + + /** + * Remove an individual filter; proxy to adapter + * + * @param string $name + * @return Zend_Form_Element_File + */ + public function removeFilter($name) + { + $adapter = $this->getTransferAdapter(); + $adapter->removeFilter($name); + + return $this; + } + + /** + * Remove all filters; proxy to adapter + * + * @return Zend_Form_Element_File + */ + public function clearFilters() + { + $adapter = $this->getTransferAdapter(); + $adapter->clearFilters(); + + return $this; + } + + /** + * Validate upload + * + * @param string $value File, can be optional, give null to validate all files + * @param mixed $context + * @return bool + */ + public function isValid($value, $context = null) + { + if ($this->_validated) { + return true; + } + + $adapter = $this->getTransferAdapter(); + $translator = $this->getTranslator(); + if ($translator !== null) { + $adapter->setTranslator($translator); + } + + if (!$this->isRequired()) { + $adapter->setOptions(array('ignoreNoFile' => true), $this->getName()); + } else { + $adapter->setOptions(array('ignoreNoFile' => false), $this->getName()); + if ($this->autoInsertNotEmptyValidator() && !$this->getValidator('NotEmpty')) { + $this->addValidator('NotEmpty', true); + } + } + + if($adapter->isValid($this->getName())) { + $this->_validated = true; + return true; + } + + $this->_validated = false; + return false; + } + + /** + * Receive the uploaded file + * + * @return boolean + */ + public function receive() + { + if (!$this->_validated) { + if (!$this->isValid($this->getName())) { + return false; + } + } + + $adapter = $this->getTransferAdapter(); + if ($adapter->receive($this->getName())) { + return true; + } + + return false; + } + + /** + * Retrieve error codes; proxy to transfer adapter + * + * @return array + */ + public function getErrors() + { + return parent::getErrors() + $this->getTransferAdapter()->getErrors(); + } + + /** + * Are there errors registered? + * + * @return bool + */ + public function hasErrors() + { + return (parent::hasErrors() || $this->getTransferAdapter()->hasErrors()); + } + + /** + * Retrieve error messages; proxy to transfer adapter + * + * @return array + */ + public function getMessages() + { + return parent::getMessages() + $this->getTransferAdapter()->getMessages(); + } + + /** + * Set the upload destination + * + * @param string $path + * @return Zend_Form_Element_File + */ + public function setDestination($path) + { + $this->getTransferAdapter()->setDestination($path, $this->getName()); + return $this; + } + + /** + * Get the upload destination + * + * @return string + */ + public function getDestination() + { + return $this->getTransferAdapter()->getDestination($this->getName()); + } + + /** + * Get the final filename + * + * @param string $value (Optional) Element or file to return + * @param boolean $path (Optional) Return also the path, defaults to true + * @return string + */ + public function getFileName($value = null, $path = true) + { + if (empty($value)) { + $value = $this->getName(); + } + + return $this->getTransferAdapter()->getFileName($value, $path); + } + + /** + * Get internal file informations + * + * @param string $value (Optional) Element or file to return + * @return array + */ + public function getFileInfo($value = null) + { + if (empty($value)) { + $value = $this->getName(); + } + + return $this->getTransferAdapter()->getFileInfo($value); + } + + /** + * Set a multifile element + * + * @param integer $count Number of file elements + * @return Zend_Form_Element_File Provides fluent interface + */ + public function setMultiFile($count) + { + if ((integer) $count < 2) { + $this->setIsArray(false); + $this->_counter = 1; + } else { + $this->setIsArray(true); + $this->_counter = (integer) $count; + } + + return $this; + } + + /** + * Returns the multifile element number + * + * @return integer + */ + public function getMultiFile() + { + return $this->_counter; + } + + /** + * Sets the maximum file size of the form + * + * @return integer + */ + public function getMaxFileSize() + { + if (self::$_maxFileSize < 0) { + $ini = $this->_convertIniToInteger(trim(ini_get('post_max_size'))); + $max = $this->_convertIniToInteger(trim(ini_get('upload_max_filesize'))); + $min = max($ini, $max); + if ($ini > 0) { + $min = min($min, $ini); + } + + if ($max > 0) { + $min = min($min, $max); + } + + self::$_maxFileSize = $min; + } + + return self::$_maxFileSize; + } + + /** + * Sets the maximum file size of the form + * + * @param integer $size + * @return integer + */ + public function setMaxFileSize($size) + { + $ini = $this->_convertIniToInteger(trim(ini_get('post_max_size'))); + $max = $this->_convertIniToInteger(trim(ini_get('upload_max_filesize'))); + + if (($max > -1) && ($size > $max)) { + trigger_error("Your 'upload_max_filesize' config setting limits the maximum filesize to '$max'. You tried to set '$size'.", E_USER_NOTICE); + $size = $max; + } + + if (($ini > -1) && ($size > $ini)) { + trigger_error("Your 'post_max_size' config setting limits the maximum filesize to '$ini'. You tried to set '$size'.", E_USER_NOTICE); + $size = $ini; + } + + self::$_maxFileSize = $size; + return $this; + } + + /** + * Converts a ini setting to a integer value + * + * @param string $setting + * @return integer + */ + private function _convertIniToInteger($setting) + { + if (!is_numeric($setting)) { + $type = strtoupper(substr($setting, -1)); + $setting = (integer) substr($setting, 0, -1); + + switch ($type) { + case 'K' : + $setting *= 1024; + break; + + case 'M' : + $setting *= 1024 * 1024; + break; + + case 'G' : + $setting *= 1024 * 1024 * 1024; + break; + + default : + break; + } + } + + return (integer) $setting; + } + + /** + * Set if the file will be uploaded when getting the value + * This defaults to false which will force receive() when calling getValues() + * + * @param boolean $flag Sets if the file is handled as the elements value + * @return Zend_Form_Element_File + */ + public function setValueDisabled($flag) + { + $this->_valueDisabled = (bool) $flag; + return $this; + } + + /** + * Returns if the file will be uploaded when calling getValues() + * + * @return boolean Receive the file on calling getValues()? + */ + public function isValueDisabled() + { + return $this->_valueDisabled; + } + + /** + * Processes the file, returns null or the filename only + * For the complete path, use getFileName + * + * @return null|string + */ + public function getValue() + { + if ($this->_value !== null) { + return $this->_value; + } + + $content = $this->getTransferAdapter()->getFileName($this->getName()); + if (empty($content)) { + return null; + } + + if (!$this->isValid(null)) { + return null; + } + + if (!$this->_valueDisabled && !$this->receive()) { + return null; + } + + return $this->getFileName(null, false); + } + + /** + * Disallow setting the value + * + * @param mixed $value + * @return Zend_Form_Element_File + */ + public function setValue($value) + { + return $this; + } + + /** + * Set translator object for localization + * + * @param Zend_Translate|null $translator + * @return Zend_Form_Element_File + */ + public function setTranslator($translator = null) + { + $adapter = $this->getTransferAdapter(); + $adapter->setTranslator($translator); + parent::setTranslator($translator); + + return $this; + } + + /** + * Retrieve localization translator object + * + * @return Zend_Translate_Adapter|null + */ + public function getTranslator() + { + if ($this->translatorIsDisabled()) { + return null; + } + + $translator = $this->getTransferAdapter()->getTranslator(); + if (null === $translator) { + return Zend_Form::getDefaultTranslator(); + } + + return $translator; + } + + /** + * Indicate whether or not translation should be disabled + * + * @param bool $flag + * @return Zend_Form_Element_File + */ + public function setDisableTranslator($flag) + { + $adapter = $this->getTransferAdapter(); + $adapter->setDisableTranslator($flag); + $this->_translatorDisabled = (bool) $flag; + + return $this; + } + + /** + * Is translation disabled? + * + * @return bool + */ + public function translatorIsDisabled() + { + $adapter = $this->getTransferAdapter(); + return $adapter->translatorIsDisabled(); + } + + /** + * Was the file received? + * + * @return bool + */ + public function isReceived() + { + $adapter = $this->getTransferAdapter(); + return $adapter->isReceived($this->getName()); + } + + /** + * Was the file uploaded? + * + * @return bool + */ + public function isUploaded() + { + $adapter = $this->getTransferAdapter(); + return $adapter->isUploaded($this->getName()); + } + + /** + * Has the file been filtered? + * + * @return bool + */ + public function isFiltered() + { + $adapter = $this->getTransferAdapter(); + return $adapter->isFiltered($this->getName()); + } + + /** + * Returns the hash for this file element + * + * @param string $hash (Optional) Hash algorithm to use + * @return string|array Hashstring + */ + public function getHash($hash = 'crc32') + { + $adapter = $this->getTransferAdapter(); + return $adapter->getHash($hash, $this->getName()); + } + + /** + * Returns the filesize for this file element + * + * @return string|array Filesize + */ + public function getFileSize() + { + $adapter = $this->getTransferAdapter(); + return $adapter->getFileSize($this->getName()); + } + + /** + * Returns the mimetype for this file element + * + * @return string|array Mimetype + */ + public function getMimeType() + { + $adapter = $this->getTransferAdapter(); + return $adapter->getMimeType($this->getName()); + } + + /** + * Render form element + * Checks for decorator interface to prevent errors + * + * @param Zend_View_Interface $view + * @return string + * @throws Zend_Form_Element_Exception + */ + 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) { + 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; + } +} diff --git a/library/vendor/Zend/Form/Element/Hidden.php b/library/vendor/Zend/Form/Element/Hidden.php new file mode 100644 index 0000000..c512684 --- /dev/null +++ b/library/vendor/Zend/Form/Element/Hidden.php @@ -0,0 +1,41 @@ +loadDefaultDecoratorsIsDisabled()) { + return $this; + } + + $decorators = $this->getDecorators(); + if (empty($decorators)) { + $this->addDecorator('Tooltip') + ->addDecorator('Image') + ->addDecorator('Errors') + ->addDecorator('HtmlTag', array('tag' => 'dd')) + ->addDecorator('Label', array('tag' => 'dt')); + } + return $this; + } + + /** + * 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)); + } + +} diff --git a/library/vendor/Zend/Form/Element/Multi.php b/library/vendor/Zend/Form/Element/Multi.php new file mode 100644 index 0000000..3de2033 --- /dev/null +++ b/library/vendor/Zend/Form/Element/Multi.php @@ -0,0 +1,316 @@ +'. + * @var string + */ + protected $_separator = '
      '; + + /** + * Which values are translated already? + * @var array + */ + protected $_translated = array(); + + /** + * Retrieve separator + * + * @return mixed + */ + public function getSeparator() + { + return $this->_separator; + } + + /** + * Set separator + * + * @param mixed $separator + * @return self + */ + public function setSeparator($separator) + { + $this->_separator = $separator; + return $this; + } + + /** + * Retrieve options array + * + * @return array + */ + protected function _getMultiOptions() + { + if (null === $this->options || !is_array($this->options)) { + $this->options = array(); + } + + return $this->options; + } + + /** + * Add an option + * + * @param string $option + * @param string $value + * @return Zend_Form_Element_Multi + */ + public function addMultiOption($option, $value = '') + { + $option = (string) $option; + $this->_getMultiOptions(); + if (!$this->_translateOption($option, $value)) { + $this->options[$option] = $value; + } + + return $this; + } + + /** + * Add many options at once + * + * @param array $options + * @return Zend_Form_Element_Multi + */ + public function addMultiOptions(array $options) + { + foreach ($options as $option => $value) { + if (is_array($value) + && array_key_exists('key', $value) + && array_key_exists('value', $value) + ) { + $this->addMultiOption($value['key'], $value['value']); + } else { + $this->addMultiOption($option, $value); + } + } + return $this; + } + + /** + * Set all options at once (overwrites) + * + * @param array $options + * @return Zend_Form_Element_Multi + */ + public function setMultiOptions(array $options) + { + $this->clearMultiOptions(); + return $this->addMultiOptions($options); + } + + /** + * Retrieve single multi option + * + * @param string $option + * @return mixed + */ + public function getMultiOption($option) + { + $option = (string) $option; + $this->_getMultiOptions(); + if (isset($this->options[$option])) { + $this->_translateOption($option, $this->options[$option]); + return $this->options[$option]; + } + + return null; + } + + /** + * Retrieve options + * + * @return array + */ + public function getMultiOptions() + { + $this->_getMultiOptions(); + foreach ($this->options as $option => $value) { + $this->_translateOption($option, $value); + } + return $this->options; + } + + /** + * Remove a single multi option + * + * @param string $option + * @return bool + */ + public function removeMultiOption($option) + { + $option = (string) $option; + $this->_getMultiOptions(); + if (isset($this->options[$option])) { + unset($this->options[$option]); + if (isset($this->_translated[$option])) { + unset($this->_translated[$option]); + } + return true; + } + + return false; + } + + /** + * Clear all options + * + * @return Zend_Form_Element_Multi + */ + public function clearMultiOptions() + { + $this->options = array(); + $this->_translated = array(); + return $this; + } + + /** + * Set flag indicating whether or not to auto-register inArray validator + * + * @param bool $flag + * @return Zend_Form_Element_Multi + */ + public function setRegisterInArrayValidator($flag) + { + $this->_registerInArrayValidator = (bool) $flag; + return $this; + } + + /** + * Get status of auto-register inArray validator flag + * + * @return bool + */ + public function registerInArrayValidator() + { + return $this->_registerInArrayValidator; + } + + /** + * Is the value provided valid? + * + * Autoregisters InArray validator if necessary. + * + * @param string $value + * @param mixed $context + * @return bool + */ + public function isValid($value, $context = null) + { + if ($this->registerInArrayValidator()) { + if (!$this->getValidator('InArray')) { + $multiOptions = $this->getMultiOptions(); + $options = array(); + + foreach ($multiOptions as $opt_value => $opt_label) { + // optgroup instead of option label + if (is_array($opt_label)) { + $options = array_merge($options, array_keys($opt_label)); + } + else { + $options[] = $opt_value; + } + } + + $this->addValidator( + 'InArray', + true, + array($options) + ); + } + } + return parent::isValid($value, $context); + } + + /** + * Translate an option + * + * @param string $option + * @param string $value + * @return bool + */ + protected function _translateOption($option, $value) + { + if ($this->translatorIsDisabled()) { + return false; + } + + if (!isset($this->_translated[$option]) && !empty($value)) { + $this->options[$option] = $this->_translateValue($value); + if ($this->options[$option] === $value) { + return false; + } + $this->_translated[$option] = true; + return true; + } + + return false; + } + + /** + * Translate a multi option value + * + * @param string $value + * @return string + */ + protected function _translateValue($value) + { + if (is_array($value)) { + foreach ($value as $key => $val) { + $value[$key] = $this->_translateValue($val); + } + return $value; + } else { + if (null !== ($translator = $this->getTranslator())) { + return $translator->translate($value); + } + + return $value; + } + } +} diff --git a/library/vendor/Zend/Form/Element/MultiCheckbox.php b/library/vendor/Zend/Form/Element/MultiCheckbox.php new file mode 100644 index 0000000..24fe938 --- /dev/null +++ b/library/vendor/Zend/Form/Element/MultiCheckbox.php @@ -0,0 +1,72 @@ +loadDefaultDecoratorsIsDisabled()) { + return $this; + } + + parent::loadDefaultDecorators(); + + // Disable 'for' attribute + if (false !== $decorator = $this->getDecorator('label')) { + $decorator->setOption('disableFor', true); + } + + return $this; + } +} diff --git a/library/vendor/Zend/Form/Element/Multiselect.php b/library/vendor/Zend/Form/Element/Multiselect.php new file mode 100644 index 0000000..5e94d56 --- /dev/null +++ b/library/vendor/Zend/Form/Element/Multiselect.php @@ -0,0 +1,53 @@ +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); + } +} diff --git a/library/vendor/Zend/Form/Element/Radio.php b/library/vendor/Zend/Form/Element/Radio.php new file mode 100644 index 0000000..883a00d --- /dev/null +++ b/library/vendor/Zend/Form/Element/Radio.php @@ -0,0 +1,65 @@ +loadDefaultDecoratorsIsDisabled()) { + return $this; + } + parent::loadDefaultDecorators(); + + // Disable 'for' attribute + if (isset($this->_decorators['Label']) + && !isset($this->_decorators['Label']['options']['disableFor'])) + { + $this->_decorators['Label']['options']['disableFor'] = true; + } + + return $this; + } +} diff --git a/library/vendor/Zend/Form/Element/Reset.php b/library/vendor/Zend/Form/Element/Reset.php new file mode 100644 index 0000000..8a27805 --- /dev/null +++ b/library/vendor/Zend/Form/Element/Reset.php @@ -0,0 +1,41 @@ + $options); + } + + if (!isset($options['ignore'])) { + $options['ignore'] = true; + } + + parent::__construct($spec, $options); + } + + /** + * Return label + * + * If no label is present, returns the currently set name. + * + * If a translator is present, returns the translated label. + * + * @return string + */ + public function getLabel() + { + $value = parent::getLabel(); + + if (null === $value) { + $value = $this->getName(); + + if (null !== ($translator = $this->getTranslator())) { + return $translator->translate($value); + } + } + + return $value; + } + + /** + * Has this submit button been selected? + * + * @return bool + */ + public function isChecked() + { + $value = $this->getValue(); + + if (empty($value)) { + return false; + } + if ($value != $this->getLabel()) { + return false; + } + + return true; + } + + /** + * Default decorators + * + * Uses only 'Submit' and 'DtDdWrapper' decorators by default. + * + * @return Zend_Form_Element_Submit + */ + public function loadDefaultDecorators() + { + if ($this->loadDefaultDecoratorsIsDisabled()) { + return $this; + } + + $decorators = $this->getDecorators(); + if (empty($decorators)) { + $this->addDecorator('Tooltip') + ->addDecorator('ViewHelper') + ->addDecorator('DtDdWrapper'); + } + return $this; + } +} diff --git a/library/vendor/Zend/Form/Element/Text.php b/library/vendor/Zend/Form/Element/Text.php new file mode 100644 index 0000000..1a99b8e --- /dev/null +++ b/library/vendor/Zend/Form/Element/Text.php @@ -0,0 +1,41 @@ +loadDefaultDecoratorsIsDisabled()) { + return $this; + } + + $decorators = $this->getDecorators(); + if (empty($decorators)) { + $this->addDecorator('FormElements') + ->addDecorator('HtmlTag', array('tag' => 'dl')) + ->addDecorator('Fieldset') + ->addDecorator('DtDdWrapper'); + } + return $this; + } +} -- cgit v1.2.3