PDF rausgenommen
This commit is contained in:
376
msd2/tracking/piwik/libs/HTML/QuickForm2/Renderer/Array.php
Normal file
376
msd2/tracking/piwik/libs/HTML/QuickForm2/Renderer/Array.php
Normal file
@ -0,0 +1,376 @@
|
||||
<?php
|
||||
/**
|
||||
* A renderer for HTML_QuickForm2 building an array of form elements
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 2006-2010, Alexey Borzov <avb@php.net>,
|
||||
* Bertrand Mansion <golgote@mamasam.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * The names of the authors may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @author Thomas Schulz <ths@4bconsult.de>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SVN: $Id: Array.php 294052 2010-01-26 20:00:22Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstract base class for QuickForm2 renderers
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Renderer.php';
|
||||
|
||||
/**
|
||||
* A renderer for HTML_QuickForm2 building an array of form elements
|
||||
*
|
||||
* Based on Array renderer from HTML_QuickForm 3.x package
|
||||
*
|
||||
* The form array structure is the following:
|
||||
* <pre>
|
||||
* array(
|
||||
* 'id' => form's "id" attribute (string),
|
||||
* 'frozen' => whether the form is frozen (bool),
|
||||
* 'attributes' => attributes for <form> tag (string),
|
||||
* // if form contains required elements:
|
||||
* 'required_note' => note about the required elements (string),
|
||||
* // if 'group_hiddens' option is true:
|
||||
* 'hidden' => array with html of hidden elements (array),
|
||||
* // if 'group_errors' option is true:
|
||||
* 'errors' => array(
|
||||
* '1st element id' => 'Error for the 1st element',
|
||||
* ...
|
||||
* 'nth element id' => 'Error for the nth element'
|
||||
* ),
|
||||
* 'elements' => array(
|
||||
* element_1,
|
||||
* ...
|
||||
* element_N
|
||||
* )
|
||||
* );
|
||||
* </pre>
|
||||
* Where element_i is an array of the form
|
||||
* <pre>
|
||||
* array(
|
||||
* 'id' => element id (string),
|
||||
* 'type' => type of the element (string),
|
||||
* 'frozen' => whether element is frozen (bool),
|
||||
* // if element has a label:
|
||||
* 'label' => 'label for the element',
|
||||
* // note that if 'static_labels' option is true and element's label is an
|
||||
* // array then there will be several 'label_*' keys corresponding to
|
||||
* // labels' array keys
|
||||
* 'required' => whether element is required (bool),
|
||||
* // if a validation error is present and 'group_errors' option is false:
|
||||
* 'error' => error associated with the element (string),
|
||||
* // if some style was associated with an element:
|
||||
* 'style' => 'some information about element style (e.g. for Smarty)',
|
||||
*
|
||||
* // if element is not a Container
|
||||
* 'value' => element value (mixed),
|
||||
* 'html' => HTML for the element (string),
|
||||
*
|
||||
* // if element is a Container
|
||||
* 'attributes' => container attributes (string)
|
||||
* // only for groups, if separator is set:
|
||||
* 'separator' => separator for group elements (mixed),
|
||||
* 'elements' => array(
|
||||
* element_1,
|
||||
* ...
|
||||
* element_N
|
||||
* )
|
||||
* );
|
||||
* </pre>
|
||||
*
|
||||
* While almost everything in this class is defined as public, its properties
|
||||
* and those methods that are not published (i.e. not in array returned by
|
||||
* exportMethods()) will be available to renderer plugins only.
|
||||
*
|
||||
* The following methods are published:
|
||||
* - {@link reset()}
|
||||
* - {@link toArray()}
|
||||
* - {@link setStyleForId()}
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @author Thomas Schulz <ths@4bconsult.de>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Renderer_Array extends HTML_QuickForm2_Renderer
|
||||
{
|
||||
/**
|
||||
* An array being generated
|
||||
* @var array
|
||||
*/
|
||||
public $array = array();
|
||||
|
||||
/**
|
||||
* Array with references to 'elements' fields of currently processed containers
|
||||
* @var unknown_type
|
||||
*/
|
||||
public $containers = array();
|
||||
|
||||
/**
|
||||
* Whether the form contains required elements
|
||||
* @var bool
|
||||
*/
|
||||
public $hasRequired = false;
|
||||
|
||||
/**
|
||||
* Additional style information for elements
|
||||
* @var array
|
||||
*/
|
||||
public $styles = array();
|
||||
|
||||
/**
|
||||
* Constructor, adds a new 'static_labels' option
|
||||
*/
|
||||
protected function __construct()
|
||||
{
|
||||
$this->options['static_labels'] = false;
|
||||
}
|
||||
|
||||
public function exportMethods()
|
||||
{
|
||||
return array(
|
||||
'reset',
|
||||
'toArray',
|
||||
'setStyleForId'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the accumulated data
|
||||
*
|
||||
* This method is called automatically by startForm() method, but should
|
||||
* be called manually before calling other rendering methods separately.
|
||||
*
|
||||
* @return HTML_QuickForm2_Renderer_Array
|
||||
*/
|
||||
public function reset()
|
||||
{
|
||||
$this->array = array();
|
||||
$this->containers = array();
|
||||
$this->hasRequired = false;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the resultant array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
return $this->array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an array with fields that are common to all elements
|
||||
*
|
||||
* @param HTML_QuickForm2_Node Element being rendered
|
||||
* @return array
|
||||
*/
|
||||
public function buildCommonFields(HTML_QuickForm2_Node $element)
|
||||
{
|
||||
$ary = array(
|
||||
'id' => $element->getId(),
|
||||
'frozen' => $element->toggleFrozen()
|
||||
);
|
||||
if ($labels = $element->getLabel()) {
|
||||
if (!is_array($labels) || !$this->options['static_labels']) {
|
||||
$ary['label'] = $labels;
|
||||
} else {
|
||||
foreach ($labels as $key => $label) {
|
||||
$key = is_int($key)? $key + 1: $key;
|
||||
if (1 === $key) {
|
||||
$ary['label'] = $label;
|
||||
} else {
|
||||
$ary['label_' . $key] = $label;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (($error = $element->getError()) && $this->options['group_errors']) {
|
||||
$this->array['errors'][$ary['id']] = $error;
|
||||
} elseif ($error) {
|
||||
$ary['error'] = $error;
|
||||
}
|
||||
if (isset($this->styles[$ary['id']])) {
|
||||
$ary['style'] = $this->styles[$ary['id']];
|
||||
}
|
||||
if (!$element instanceof HTML_QuickForm2_Container) {
|
||||
$ary['html'] = $element->__toString();
|
||||
} else {
|
||||
$ary['elements'] = array();
|
||||
$ary['attributes'] = $element->getAttributes(true);
|
||||
}
|
||||
return $ary;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores an array representing "scalar" element in the form array
|
||||
*
|
||||
* @param array
|
||||
*/
|
||||
public function pushScalar(array $element)
|
||||
{
|
||||
if (!empty($element['required'])) {
|
||||
$this->hasRequired = true;
|
||||
}
|
||||
if (empty($this->containers)) {
|
||||
$this->array += $element;
|
||||
} else {
|
||||
$this->containers[count($this->containers) - 1][] = $element;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores an array representing a Container in the form array
|
||||
*
|
||||
* @param array
|
||||
*/
|
||||
public function pushContainer(array $container)
|
||||
{
|
||||
if (!empty($container['required'])) {
|
||||
$this->hasRequired = true;
|
||||
}
|
||||
if (empty($this->containers)) {
|
||||
$this->array += $container;
|
||||
$this->containers = array(&$this->array['elements']);
|
||||
} else {
|
||||
$cntIndex = count($this->containers) - 1;
|
||||
$myIndex = count($this->containers[$cntIndex]);
|
||||
$this->containers[$cntIndex][$myIndex] = $container;
|
||||
$this->containers[$cntIndex + 1] =& $this->containers[$cntIndex][$myIndex]['elements'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a style for element rendering
|
||||
*
|
||||
* "Style" is some information that is opaque to Array Renderer but may be
|
||||
* of use to e.g. template engine that receives the resultant array.
|
||||
*
|
||||
* @param string|array Element id or array ('element id' => 'style')
|
||||
* @param sting Element style if $idOrStyles is not an array
|
||||
* @return HTML_QuickForm2_Renderer_Array
|
||||
*/
|
||||
public function setStyleForId($idOrStyles, $style = null)
|
||||
{
|
||||
if (is_array($idOrStyles)) {
|
||||
$this->styles = array_merge($this->styles, $idOrStyles);
|
||||
} else {
|
||||
$this->styles[$idOrStyles] = $style;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**#@+
|
||||
* Implementations of abstract methods from {@link HTML_QuickForm2_Renderer}
|
||||
*/
|
||||
public function renderElement(HTML_QuickForm2_Node $element)
|
||||
{
|
||||
$ary = $this->buildCommonFields($element) + array(
|
||||
'value' => $element->getValue(),
|
||||
'type' => $element->getType(),
|
||||
'required' => $element->isRequired(),
|
||||
);
|
||||
$this->pushScalar($ary);
|
||||
}
|
||||
|
||||
public function renderHidden(HTML_QuickForm2_Node $element)
|
||||
{
|
||||
if ($this->options['group_hiddens']) {
|
||||
$this->array['hidden'][] = $element->__toString();
|
||||
} else {
|
||||
$this->renderElement($element);
|
||||
}
|
||||
}
|
||||
|
||||
public function startForm(HTML_QuickForm2_Node $form)
|
||||
{
|
||||
$this->reset();
|
||||
|
||||
$this->array = $this->buildCommonFields($form);
|
||||
if ($this->options['group_errors']) {
|
||||
$this->array['errors'] = array();
|
||||
}
|
||||
if ($this->options['group_hiddens']) {
|
||||
$this->array['hidden'] = array();
|
||||
}
|
||||
$this->containers = array(&$this->array['elements']);
|
||||
}
|
||||
|
||||
public function finishForm(HTML_QuickForm2_Node $form)
|
||||
{
|
||||
$this->finishContainer($form);
|
||||
if ($this->hasRequired) {
|
||||
$this->array['required_note'] = $this->options['required_note'];
|
||||
}
|
||||
}
|
||||
|
||||
public function startContainer(HTML_QuickForm2_Node $container)
|
||||
{
|
||||
$ary = $this->buildCommonFields($container) + array(
|
||||
'required' => $container->isRequired(),
|
||||
'type' => $container->getType()
|
||||
);
|
||||
$this->pushContainer($ary);
|
||||
}
|
||||
|
||||
public function finishContainer(HTML_QuickForm2_Node $container)
|
||||
{
|
||||
array_pop($this->containers);
|
||||
}
|
||||
|
||||
public function startGroup(HTML_QuickForm2_Node $group)
|
||||
{
|
||||
$ary = $this->buildCommonFields($group) + array(
|
||||
'required' => $group->isRequired(),
|
||||
'type' => $group->getType()
|
||||
);
|
||||
if ($separator = $group->getSeparator()) {
|
||||
$ary['separator'] = $separator;
|
||||
}
|
||||
$this->pushContainer($ary);
|
||||
}
|
||||
|
||||
public function finishGroup(HTML_QuickForm2_Node $group)
|
||||
{
|
||||
$this->finishContainer($group);
|
||||
}
|
||||
/**#@-*/
|
||||
}
|
||||
?>
|
598
msd2/tracking/piwik/libs/HTML/QuickForm2/Renderer/Default.php
Normal file
598
msd2/tracking/piwik/libs/HTML/QuickForm2/Renderer/Default.php
Normal file
@ -0,0 +1,598 @@
|
||||
<?php
|
||||
/**
|
||||
* Default renderer for HTML_QuickForm2
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 2006-2010, Alexey Borzov <avb@php.net>,
|
||||
* Bertrand Mansion <golgote@mamasam.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * The names of the authors may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SVN: $Id: Default.php 299706 2010-05-24 18:32:37Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstract base class for QuickForm2 renderers
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Renderer.php';
|
||||
|
||||
/**
|
||||
* Default renderer for QuickForm2
|
||||
*
|
||||
* Mostly a direct port of Default renderer from QuickForm 3.x package.
|
||||
*
|
||||
* While almost everything in this class is defined as public, its properties
|
||||
* and those methods that are not published (i.e. not in array returned by
|
||||
* exportMethods()) will be available to renderer plugins only.
|
||||
*
|
||||
* The following methods are published:
|
||||
* - {@link reset()}
|
||||
* - {@link setTemplateForClass()}
|
||||
* - {@link setTemplateForId()}
|
||||
* - {@link setErrorTemplate()}
|
||||
* - {@link setElementTemplateForGroupClass()}
|
||||
* - {@link setElementTemplateForGroupId()}
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Renderer_Default extends HTML_QuickForm2_Renderer
|
||||
{
|
||||
/**
|
||||
* Whether the form contains required elements
|
||||
* @var bool
|
||||
*/
|
||||
public $hasRequired = false;
|
||||
|
||||
/**
|
||||
* HTML generated for the form
|
||||
* @var array
|
||||
*/
|
||||
public $html = array(array());
|
||||
|
||||
/**
|
||||
* HTML for hidden elements if 'group_hiddens' option is on
|
||||
* @var string
|
||||
*/
|
||||
public $hiddenHtml = '';
|
||||
|
||||
/**
|
||||
* Array of validation errors if 'group_errors' option is on
|
||||
* @var array
|
||||
*/
|
||||
public $errors = array();
|
||||
|
||||
/**
|
||||
* Default templates for elements of the given class
|
||||
* @var array
|
||||
*/
|
||||
public $templatesForClass = array(
|
||||
'html_quickform2_element_inputhidden' => '<div style="display: none;">{element}</div>',
|
||||
'html_quickform2' => '<div class="quickform">{errors}<form{attributes}>{hidden}{content}</form><qf:reqnote><div class="reqnote">{reqnote}</div></qf:reqnote></div>',
|
||||
'html_quickform2_container_fieldset' => '<fieldset{attributes}><qf:label><legend id="{id}-legend">{label}</legend></qf:label>{content}</fieldset>',
|
||||
'special:error' => array(
|
||||
'prefix' => '<div class="errors"><qf:message><p>{message}</p></qf:message><ul><li>',
|
||||
'separator' => '</li><li>',
|
||||
'suffix' => '</li></ul><qf:message><p>{message}</p></qf:message></div>'
|
||||
),
|
||||
'html_quickform2_element' => '<div class="row"><label for="{id}" class="element"><qf:required><span class="required">* </span></qf:required>{label}</label><div class="element<qf:error> error</qf:error>"><qf:error><span class="error">{error}</span><br /></qf:error>{element}</div></div>',
|
||||
'html_quickform2_container_group' => '<div class="row"><label class="element"><qf:required><span class="required">* </span></qf:required>{label}</label><div class="element group<qf:error> error</qf:error>"><qf:error><span class="error">{error}</span><br /></qf:error>{content}</div></div>'
|
||||
);
|
||||
|
||||
/**
|
||||
* Custom templates for elements with the given IDs
|
||||
* @var array
|
||||
*/
|
||||
public $templatesForId = array();
|
||||
|
||||
/**
|
||||
* Default templates for elements in groups of the given classes
|
||||
*
|
||||
* Array has the form ('group class' => ('element class' => 'template', ...), ...)
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $elementTemplatesForGroupClass = array(
|
||||
'html_quickform2_container' => array(
|
||||
'html_quickform2_element' => '{element}',
|
||||
'html_quickform2_container_fieldset' => '<fieldset{attributes}><qf:label><legend id="{id}-legend">{label}</legend></qf:label>{content}</fieldset>'
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Custom templates for grouped elements in the given group IDs
|
||||
*
|
||||
* Array has the form ('group id' => ('element class' => 'template', ...), ...)
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $elementTemplatesForGroupId = array();
|
||||
|
||||
/**
|
||||
* Array containing IDs of the groups being rendered
|
||||
* @var array
|
||||
*/
|
||||
public $groupId = array();
|
||||
|
||||
public function exportMethods()
|
||||
{
|
||||
return array(
|
||||
'reset',
|
||||
'setTemplateForClass',
|
||||
'setTemplateForId',
|
||||
'setErrorTemplate',
|
||||
'setGroupedTemplateForClass',
|
||||
'setElementTemplateForGroupClass',
|
||||
'setElementTemplateForGroupId'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets template for form elements that are instances of the given class
|
||||
*
|
||||
* When searching for a template to use, renderer will check for templates
|
||||
* set for element's class and its parent classes, until found. Thus a more
|
||||
* specific template will override a more generic one.
|
||||
*
|
||||
* @param string Class name
|
||||
* @param mixed Template to use for elements of that class
|
||||
* @return HTML_QuickForm2_Renderer_Default
|
||||
*/
|
||||
public function setTemplateForClass($className, $template)
|
||||
{
|
||||
$this->templatesForClass[strtolower($className)] = $template;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets template for form element with the given id
|
||||
*
|
||||
* If a template is set for an element via this method, it will be used.
|
||||
* In the other case a generic template set by {@link setTemplateForClass()}
|
||||
* or {@link setGroupedTemplateForClass()} will be used.
|
||||
*
|
||||
* @param string Element's id
|
||||
* @param mixed Template to use for rendering of that element
|
||||
* @return HTML_QuickForm2_Renderer_Default
|
||||
*/
|
||||
public function setTemplateForId($id, $template)
|
||||
{
|
||||
$this->templatesForId[$id] = $template;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets template for rendering validation errors
|
||||
*
|
||||
* This template will be used if 'group_errors' option is set to true.
|
||||
* The template array should contain 'prefix', 'suffix' and 'separator'
|
||||
* keys.
|
||||
*
|
||||
* @param array Template for validation errors
|
||||
* @return HTML_QuickForm2_Renderer_Default
|
||||
*/
|
||||
public function setErrorTemplate(array $template)
|
||||
{
|
||||
return $this->setTemplateForClass('special:error', $template);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets grouped elements templates using group class
|
||||
*
|
||||
* Templates set via {@link setTemplateForClass()} will not be used for
|
||||
* grouped form elements. When searching for a template to use, the renderer
|
||||
* will first consider template set for a specific group id, then the
|
||||
* group templates set by group class.
|
||||
*
|
||||
* @param string Group class name
|
||||
* @param string Element class name
|
||||
* @param mixed Template
|
||||
* @return HTML_QuickForm2_Renderer_Default
|
||||
*/
|
||||
public function setElementTemplateForGroupClass($groupClass, $elementClass, $template)
|
||||
{
|
||||
$this->elementTemplatesForGroupClass[strtolower($groupClass)][strtolower($elementClass)] = $template;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets grouped elements templates using group id
|
||||
*
|
||||
* Templates set via {@link setTemplateForClass()} will not be used for
|
||||
* grouped form elements. When searching for a template to use, the renderer
|
||||
* will first consider template set for a specific group id, then the
|
||||
* group templates set by group class.
|
||||
*
|
||||
* @param string Group id
|
||||
* @param string Element class name
|
||||
* @param mixed Template
|
||||
* @return HTML_QuickForm2_Renderer_Default
|
||||
*/
|
||||
public function setElementTemplateForGroupId($groupId, $elementClass, $template)
|
||||
{
|
||||
$this->elementTemplatesForGroupId[$groupId][strtolower($elementClass)] = $template;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the accumulated data
|
||||
*
|
||||
* This method is called automatically by startForm() method, but should
|
||||
* be called manually before calling other rendering methods separately.
|
||||
*
|
||||
* @return HTML_QuickForm2_Renderer_Default
|
||||
*/
|
||||
public function reset()
|
||||
{
|
||||
$this->html = array(array());
|
||||
$this->hiddenHtml = '';
|
||||
$this->errors = array();
|
||||
$this->hasRequired = false;
|
||||
$this->groupId = array();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns generated HTML
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return (isset($this->html[0][0])? $this->html[0][0]: '') .
|
||||
$this->hiddenHtml;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a generic element
|
||||
*
|
||||
* @param HTML_QuickForm2_Node Element being rendered
|
||||
*/
|
||||
public function renderElement(HTML_QuickForm2_Node $element)
|
||||
{
|
||||
$elTpl = $this->prepareTemplate($this->findTemplate($element), $element);
|
||||
$this->html[count($this->html) - 1][] = str_replace(array('{element}', '{id}'),
|
||||
array($element, $element->getId()), $elTpl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a hidden element
|
||||
*
|
||||
* @param HTML_QuickForm2_Node Hidden element being rendered
|
||||
*/
|
||||
public function renderHidden(HTML_QuickForm2_Node $element)
|
||||
{
|
||||
if ($this->options['group_hiddens']) {
|
||||
$this->hiddenHtml .= $element->__toString();
|
||||
} else {
|
||||
$this->html[count($this->html) - 1][] = str_replace('{element}', $element,
|
||||
$this->findTemplate($element));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts rendering a generic container, called before processing contained elements
|
||||
*
|
||||
* @param HTML_QuickForm2_Node Container being rendered
|
||||
*/
|
||||
public function startContainer(HTML_QuickForm2_Node $container)
|
||||
{
|
||||
$this->html[] = array();
|
||||
$this->groupId[] = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finishes rendering a generic container, called after processing contained elements
|
||||
*
|
||||
* @param HTML_QuickForm2_Node Container being rendered
|
||||
*/
|
||||
public function finishContainer(HTML_QuickForm2_Node $container)
|
||||
{
|
||||
array_pop($this->groupId);
|
||||
|
||||
$cTpl = str_replace(
|
||||
array('{attributes}', '{id}'),
|
||||
array($container->getAttributes(true), $container->getId()),
|
||||
$this->prepareTemplate($this->findTemplate($container, '{content}'), $container)
|
||||
);
|
||||
$cHtml = array_pop($this->html);
|
||||
$break = HTML_Common2::getOption('linebreak');
|
||||
$indent = str_repeat(HTML_Common2::getOption('indent'), count($this->html));
|
||||
$this->html[count($this->html) - 1][] = str_replace(
|
||||
'{content}', $break . $indent . implode($break . $indent, $cHtml), $cTpl
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts rendering a group, called before processing grouped elements
|
||||
*
|
||||
* @param HTML_QuickForm2_Node Group being rendered
|
||||
*/
|
||||
public function startGroup(HTML_QuickForm2_Node $group)
|
||||
{
|
||||
$this->html[] = array();
|
||||
$this->groupId[] = $group->getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Finishes rendering a group, called after processing grouped elements
|
||||
*
|
||||
* @param HTML_QuickForm2_Node Group being rendered
|
||||
*/
|
||||
public function finishGroup(HTML_QuickForm2_Node $group)
|
||||
{
|
||||
$gTpl = str_replace(
|
||||
array('{attributes}', '{id}'),
|
||||
array($group->getAttributes(true), array_pop($this->groupId)),
|
||||
$this->prepareTemplate($this->findTemplate($group, '{content}'), $group)
|
||||
);
|
||||
|
||||
$separator = $group->getSeparator();
|
||||
$elements = array_pop($this->html);
|
||||
if (!is_array($separator)) {
|
||||
$content = implode((string)$separator, $elements);
|
||||
} else {
|
||||
$content = '';
|
||||
$cSeparator = count($separator);
|
||||
for ($i = 0, $count = count($elements); $i < $count; $i++) {
|
||||
$content .= (0 == $i? '': $separator[($i - 1) % $cSeparator]) .
|
||||
$elements[$i];
|
||||
}
|
||||
}
|
||||
|
||||
$this->html[count($this->html) - 1][] = str_replace('{content}', $content, $gTpl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts rendering a form, called before processing contained elements
|
||||
*
|
||||
* @param HTML_QuickForm2_Node Form being rendered
|
||||
*/
|
||||
public function startForm(HTML_QuickForm2_Node $form)
|
||||
{
|
||||
$this->reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Finishes rendering a form, called after processing contained elements
|
||||
*
|
||||
* @param HTML_QuickForm2_Node Form being rendered
|
||||
*/
|
||||
public function finishForm(HTML_QuickForm2_Node $form)
|
||||
{
|
||||
$formTpl = str_replace(
|
||||
array('{attributes}', '{hidden}', '{errors}'),
|
||||
array($form->getAttributes(true), $this->hiddenHtml,
|
||||
$this->outputGroupedErrors()),
|
||||
$this->findTemplate($form, '{content}')
|
||||
);
|
||||
$this->hiddenHtml = '';
|
||||
|
||||
// required note
|
||||
if (!$this->hasRequired || $form->toggleFrozen() ||
|
||||
empty($this->options['required_note']))
|
||||
{
|
||||
$formTpl = preg_replace('!<qf:reqnote>.*</qf:reqnote>!isU', '', $formTpl);
|
||||
} else {
|
||||
$formTpl = str_replace(
|
||||
array('<qf:reqnote>', '</qf:reqnote>', '{reqnote}'),
|
||||
array('', '', $this->options['required_note']),
|
||||
$formTpl
|
||||
);
|
||||
}
|
||||
|
||||
$break = HTML_Common2::getOption('linebreak');
|
||||
$script = $this->getJavascriptBuilder()->__toString();
|
||||
$this->html[0] = array((empty($script)? '': $script . $break) . str_replace(
|
||||
'{content}', $break . implode($break, $this->html[0]), $formTpl
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a error list if 'group_errors' option is true
|
||||
*
|
||||
* @return string HTML with a list of all validation errors
|
||||
*/
|
||||
public function outputGroupedErrors()
|
||||
{
|
||||
if (empty($this->errors)) {
|
||||
return '';
|
||||
}
|
||||
if (!empty($this->options['errors_prefix'])) {
|
||||
$errorHtml = str_replace(array('<qf:message>', '</qf:message>', '{message}'),
|
||||
array('', '', $this->options['errors_prefix']),
|
||||
$this->templatesForClass['special:error']['prefix']);
|
||||
} else {
|
||||
$errorHtml = preg_replace('!<qf:message>.*</qf:message>!isU', '',
|
||||
$this->templatesForClass['special:error']['prefix']);
|
||||
}
|
||||
$errorHtml .= implode($this->templatesForClass['special:error']['separator'], $this->errors);
|
||||
if (!empty($this->options['errors_suffix'])) {
|
||||
$errorHtml .= str_replace(array('<qf:message>', '</qf:message>', '{message}'),
|
||||
array('', '', $this->options['errors_suffix']),
|
||||
$this->templatesForClass['special:error']['suffix']);
|
||||
} else {
|
||||
$errorHtml .= preg_replace('!<qf:message>.*</qf:message>!isU', '',
|
||||
$this->templatesForClass['special:error']['suffix']);
|
||||
}
|
||||
return $errorHtml;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a proper template for the element
|
||||
*
|
||||
* Templates are scanned in a predefined order. First, if a template was
|
||||
* set for a specific element by id, it is returned, no matter if the
|
||||
* element belongs to a group. If the element does not belong to a group,
|
||||
* we try to match a template using the element class.
|
||||
* But, if the element belongs to a group, templates are first looked up
|
||||
* using the containing group id, then using the containing group class.
|
||||
* When no template is found, the provided default template is returned.
|
||||
*
|
||||
* @param HTML_QuickForm2_Node Element being rendered
|
||||
* @param string Default template to use if not found
|
||||
* @return string Template
|
||||
*/
|
||||
public function findTemplate(HTML_QuickForm2_Node $element, $default = '{element}')
|
||||
{
|
||||
if (!empty($this->templatesForId[$element->getId()])) {
|
||||
return $this->templatesForId[$element->getId()];
|
||||
}
|
||||
$class = strtolower(get_class($element));
|
||||
$groupId = end($this->groupId);
|
||||
$elementClasses = array();
|
||||
do {
|
||||
if (empty($groupId) && !empty($this->templatesForClass[$class])) {
|
||||
return $this->templatesForClass[$class];
|
||||
}
|
||||
$elementClasses[$class] = true;
|
||||
} while ($class = strtolower(get_parent_class($class)));
|
||||
|
||||
if (!empty($groupId)) {
|
||||
if (!empty($this->elementTemplatesForGroupId[$groupId])) {
|
||||
while (list($elClass) = each($elementClasses)) {
|
||||
if (!empty($this->elementTemplatesForGroupId[$groupId][$elClass])) {
|
||||
return $this->elementTemplatesForGroupId[$groupId][$elClass];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$group = $element->getContainer();
|
||||
$grClass = strtolower(get_class($group));
|
||||
do {
|
||||
if (!empty($this->elementTemplatesForGroupClass[$grClass])) {
|
||||
reset($elementClasses);
|
||||
while (list($elClass) = each($elementClasses)) {
|
||||
if (!empty($this->elementTemplatesForGroupClass[$grClass][$elClass])) {
|
||||
return $this->elementTemplatesForGroupClass[$grClass][$elClass];
|
||||
}
|
||||
}
|
||||
}
|
||||
} while ($grClass = strtolower(get_parent_class($grClass)));
|
||||
}
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the element's template, adding label(s), required note and error message
|
||||
*
|
||||
* @param string Element template
|
||||
* @param HTML_QuickForm2_Node Element being rendered
|
||||
* @return string Template with some substitutions done
|
||||
*/
|
||||
public function prepareTemplate($elTpl, HTML_QuickForm2_Node $element)
|
||||
{
|
||||
// if element is required
|
||||
$elTpl = $this->markRequired($elTpl, $element->isRequired());
|
||||
$elTpl = $this->outputError($elTpl, $element->getError());
|
||||
return $this->outputLabel($elTpl, $element->getLabel());
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks element required or removes "required" block
|
||||
*
|
||||
* @param string Element template
|
||||
* @param bool Whether element is required
|
||||
* @return string Template with processed "required" block
|
||||
*/
|
||||
public function markRequired($elTpl, $required)
|
||||
{
|
||||
if ($required) {
|
||||
$this->hasRequired = true;
|
||||
$elTpl = str_replace(array('<qf:required>', '</qf:required>'),
|
||||
array('', ''), $elTpl);
|
||||
} else {
|
||||
$elTpl = preg_replace('!<qf:required>.*</qf:required>!isU', '', $elTpl);
|
||||
}
|
||||
return $elTpl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs element error, removes empty error blocks
|
||||
*
|
||||
* @param string Element template
|
||||
* @param string Validation error for the element
|
||||
* @return string Template with error substitutions done
|
||||
*/
|
||||
public function outputError($elTpl, $error)
|
||||
{
|
||||
if ($error && !$this->options['group_errors']) {
|
||||
$elTpl = str_replace(array('<qf:error>', '</qf:error>', '{error}'),
|
||||
array('', '', $error), $elTpl);
|
||||
} else {
|
||||
if ($error && $this->options['group_errors']) {
|
||||
$this->errors[] = $error;
|
||||
}
|
||||
$elTpl = preg_replace('!<qf:error>.*</qf:error>!isU', '', $elTpl);
|
||||
}
|
||||
return $elTpl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs element's label(s), removes empty label blocks
|
||||
*
|
||||
* @param string Element template
|
||||
* @param mixed Element label(s)
|
||||
* @return string Template with label substitutions done
|
||||
*/
|
||||
public function outputLabel($elTpl, $label)
|
||||
{
|
||||
$mainLabel = is_array($label)? array_shift($label): $label;
|
||||
$elTpl = str_replace('{label}', $mainLabel, $elTpl);
|
||||
if (false !== strpos($elTpl, '<qf:label>')) {
|
||||
if ($mainLabel) {
|
||||
$elTpl = str_replace(array('<qf:label>', '</qf:label>'), array('', ''), $elTpl);
|
||||
} else {
|
||||
$elTpl = preg_replace('!<qf:label>.*</qf:label>!isU', '', $elTpl);
|
||||
}
|
||||
}
|
||||
if (is_array($label)) {
|
||||
foreach($label as $key => $text) {
|
||||
$key = is_int($key)? $key + 2: $key;
|
||||
$elTpl = str_replace(array('<qf:label_' . $key . '>', '</qf:label_' . $key . '>', '{label_' . $key . '}'),
|
||||
array('', '', $text), $elTpl);
|
||||
}
|
||||
}
|
||||
if (strpos($elTpl, '{label_')) {
|
||||
$elTpl = preg_replace('!<qf:label_([^>]+)>.*</qf:label_\1>!isU', '', $elTpl);
|
||||
}
|
||||
return $elTpl;
|
||||
}
|
||||
}
|
||||
?>
|
69
msd2/tracking/piwik/libs/HTML/QuickForm2/Renderer/Plugin.php
Normal file
69
msd2/tracking/piwik/libs/HTML/QuickForm2/Renderer/Plugin.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
* Abstract base class for HTML_QuickForm2_Renderer plugin classes
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 2006-2010, Alexey Borzov <avb@php.net>,
|
||||
* Bertrand Mansion <golgote@mamasam.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * The names of the authors may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SVN: $Id: Plugin.php 294057 2010-01-26 21:10:28Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstract base class for HTML_QuickForm2_Renderer plugin classes
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
abstract class HTML_QuickForm2_Renderer_Plugin
|
||||
{
|
||||
protected $renderer;
|
||||
|
||||
/**
|
||||
* Sets the base renderer this plugin is enhancing
|
||||
*
|
||||
* @param HTML_QuickForm2_Renderer base renderer
|
||||
*/
|
||||
public function setRenderer(HTML_QuickForm2_Renderer $renderer)
|
||||
{
|
||||
$this->renderer = $renderer;
|
||||
}
|
||||
}
|
||||
?>
|
264
msd2/tracking/piwik/libs/HTML/QuickForm2/Renderer/Proxy.php
Normal file
264
msd2/tracking/piwik/libs/HTML/QuickForm2/Renderer/Proxy.php
Normal file
@ -0,0 +1,264 @@
|
||||
<?php
|
||||
/**
|
||||
* Proxy class for HTML_QuickForm2 renderers and their plugins
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 2006-2010, Alexey Borzov <avb@php.net>,
|
||||
* Bertrand Mansion <golgote@mamasam.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * The names of the authors may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SVN: $Id: Proxy.php 299706 2010-05-24 18:32:37Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstract base class for QuickForm2 renderers
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Renderer.php';
|
||||
|
||||
/**
|
||||
* Proxy class for HTML_QuickForm2 renderers and their plugins
|
||||
*
|
||||
* This class serves two purposes:
|
||||
* <ol>
|
||||
* <li>Aggregates renderer and its plugins. From user's point of view
|
||||
* renderer plugins simply add new methods to renderer instances.</li>
|
||||
* <li>Restricts access to renderer properties and methods. Those are defined
|
||||
* as 'public' to allow easy access from plugins, but only methods
|
||||
* with names explicitly returned by Renderer::exportMethods() are
|
||||
* available to the outside world.</li>
|
||||
* </ol>
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Renderer_Proxy extends HTML_QuickForm2_Renderer
|
||||
{
|
||||
/**
|
||||
* Renderer instance
|
||||
* @var HTML_QuickForm2_Renderer
|
||||
*/
|
||||
private $_renderer;
|
||||
|
||||
/**
|
||||
* Additional renderer methods to proxy via __call(), as returned by exportMethods()
|
||||
* @var array
|
||||
*/
|
||||
private $_rendererMethods = array();
|
||||
|
||||
/**
|
||||
* Reference to a list of registered renderer plugins for that renderer type
|
||||
* @var array
|
||||
*/
|
||||
private $_pluginClasses;
|
||||
|
||||
/**
|
||||
* Plugins for this renderer
|
||||
* @var array
|
||||
*/
|
||||
private $_plugins = array();
|
||||
|
||||
/**
|
||||
* Plugin methods to call via __call() magic method
|
||||
*
|
||||
* Array has the form ('lowercase method name' => 'index in _plugins array')
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_pluginMethods = array();
|
||||
|
||||
/**
|
||||
* Constructor, sets proxied renderer and its plugins
|
||||
*
|
||||
* @param HTML_QuickForm2_Renderer Renderer instance to proxy
|
||||
* @param array Plugins registered for that renderer type
|
||||
*/
|
||||
protected function __construct(HTML_QuickForm2_Renderer $renderer, array &$pluginClasses)
|
||||
{
|
||||
foreach ($renderer->exportMethods() as $method) {
|
||||
$this->_rendererMethods[strtolower($method)] = true;
|
||||
}
|
||||
$this->_renderer = $renderer;
|
||||
$this->_pluginClasses = &$pluginClasses;
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic function; call an imported method of a renderer or its plugin
|
||||
*
|
||||
* @param string method name
|
||||
* @param array method arguments
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($name, $arguments)
|
||||
{
|
||||
$lower = strtolower($name);
|
||||
if (isset($this->_rendererMethods[$lower])) {
|
||||
// support fluent interfaces
|
||||
$ret = call_user_func_array(array($this->_renderer, $name), $arguments);
|
||||
return $ret === $this->_renderer? $this: $ret;
|
||||
}
|
||||
// any additional plugins since last __call()?
|
||||
for ($i = count($this->_plugins); $i < count($this->_pluginClasses); $i++) {
|
||||
list($className, $includeFile) = $this->_pluginClasses[$i];
|
||||
if (!class_exists($className)) {
|
||||
HTML_QuickForm2_Loader::loadClass($className, $includeFile);
|
||||
}
|
||||
$this->addPlugin($i, new $className);
|
||||
}
|
||||
if (isset($this->_pluginMethods[$lower])) {
|
||||
return call_user_func_array(
|
||||
array($this->_plugins[$this->_pluginMethods[$lower]], $name),
|
||||
$arguments
|
||||
);
|
||||
}
|
||||
trigger_error("Fatal error: Call to undefined method " .
|
||||
get_class($this->_renderer) . "::" . $name . "()", E_USER_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a plugin for the current renderer instance
|
||||
*
|
||||
* Plugin's methods are imported and can be later called as this object's own
|
||||
*
|
||||
* @param HTML_QuickForm2_Renderer_Plugin a plugin instance
|
||||
* @throws HTML_QuickForm2_InvalidArgumentException if a plugin has already
|
||||
* imported name
|
||||
*/
|
||||
protected function addPlugin($index, HTML_QuickForm2_Renderer_Plugin $plugin)
|
||||
{
|
||||
$methods = array();
|
||||
$reflection = new ReflectionObject($plugin);
|
||||
foreach ($reflection->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
|
||||
$lower = strtolower($method->getName());
|
||||
if ('HTML_QuickForm2_Renderer_Plugin' == $method->getDeclaringClass()->getName()) {
|
||||
continue;
|
||||
} elseif (isset($this->_rendererMethods[$lower])
|
||||
|| isset($this->_pluginMethods[$lower])
|
||||
) {
|
||||
throw new HTML_QuickForm2_InvalidArgumentException(
|
||||
'Duplicate method name: name ' . $method->getName() . ' in plugin ' .
|
||||
get_class($plugin) . ' already taken by ' .
|
||||
(isset($this->_rendererMethods[$lower])?
|
||||
get_class($this->_renderer):
|
||||
get_class($this->_plugins[$this->_pluginMethods[$lower]])
|
||||
)
|
||||
);
|
||||
}
|
||||
$methods[$lower] = $index;
|
||||
}
|
||||
$plugin->setRenderer($this->_renderer);
|
||||
$this->_plugins[$index] = $plugin;
|
||||
$this->_pluginMethods += $methods;
|
||||
}
|
||||
|
||||
/**#@+
|
||||
* Proxies for methods defined in {@link HTML_QuickForm2_Renderer}
|
||||
*/
|
||||
public function setOption($nameOrOptions, $value = null)
|
||||
{
|
||||
$this->_renderer->setOption($nameOrOptions, $value);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getOption($name = null)
|
||||
{
|
||||
return $this->_renderer->getOption($name);
|
||||
}
|
||||
|
||||
public function getJavascriptBuilder()
|
||||
{
|
||||
return $this->_renderer->getJavascriptBuilder();
|
||||
}
|
||||
|
||||
public function setJavascriptBuilder(HTML_QuickForm2_JavascriptBuilder $builder = null)
|
||||
{
|
||||
$this->_renderer->setJavascriptBuilder($builder);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function renderElement(HTML_QuickForm2_Node $element)
|
||||
{
|
||||
$this->_renderer->renderElement($element);
|
||||
}
|
||||
|
||||
public function renderHidden(HTML_QuickForm2_Node $element)
|
||||
{
|
||||
$this->_renderer->renderHidden($element);
|
||||
}
|
||||
|
||||
public function startForm(HTML_QuickForm2_Node $form)
|
||||
{
|
||||
$this->_renderer->startForm($form);
|
||||
}
|
||||
|
||||
public function finishForm(HTML_QuickForm2_Node $form)
|
||||
{
|
||||
$this->_renderer->finishForm($form);
|
||||
}
|
||||
|
||||
public function startContainer(HTML_QuickForm2_Node $container)
|
||||
{
|
||||
$this->_renderer->startContainer($container);
|
||||
}
|
||||
|
||||
public function finishContainer(HTML_QuickForm2_Node $container)
|
||||
{
|
||||
$this->_renderer->finishContainer($container);
|
||||
}
|
||||
|
||||
public function startGroup(HTML_QuickForm2_Node $group)
|
||||
{
|
||||
$this->_renderer->startGroup($group);
|
||||
}
|
||||
|
||||
public function finishGroup(HTML_QuickForm2_Node $group)
|
||||
{
|
||||
$this->_renderer->finishGroup($group);
|
||||
}
|
||||
/**#@-*/
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
if (method_exists($this->_renderer, '__toString')) {
|
||||
return $this->_renderer->__toString();
|
||||
}
|
||||
trigger_error("Fatal error: Object of class " . get_class($this->_renderer) .
|
||||
" could not be converted to string", E_USER_ERROR);
|
||||
}
|
||||
}
|
||||
?>
|
292
msd2/tracking/piwik/libs/HTML/QuickForm2/Renderer/Smarty.php
Normal file
292
msd2/tracking/piwik/libs/HTML/QuickForm2/Renderer/Smarty.php
Normal file
@ -0,0 +1,292 @@
|
||||
<?php
|
||||
/**
|
||||
* A renderer for HTML_QuickForm2 suitable for using with the Smarty template engine.
|
||||
* See: http://www.smarty.net/
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 2009, Alain D D Williams <addw@phcomp.co.uk>
|
||||
* Based on the QuickForm2 Array renderer.
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * The names of the authors may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alain D D Williams <addw@phcomp.co.uk>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SCCS: %W% %G% %U%
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* This generates an array, bring in the array renderer and extend it a bit:
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Renderer/Array.php';
|
||||
|
||||
/**
|
||||
* A renderer for HTML_QuickForm2 building an array of form elements
|
||||
*
|
||||
* Based on Array renderer from HTML_QuickForm 3.x package
|
||||
*
|
||||
* The form array structure is the following:
|
||||
* <pre>
|
||||
* array(
|
||||
* 'id' => form's "id" attribute (string),
|
||||
* 'frozen' => whether the form is frozen (bool),
|
||||
* 'attributes' => attributes for <form> tag (string),
|
||||
* // if form contains required elements:
|
||||
* 'required_note' => note about the required elements (string),
|
||||
* 'requirednote' => note about the required elements (string),
|
||||
* NB: no '_' in the middle
|
||||
* In old_compat this is a span style="font-size:80%;"
|
||||
* with the '*' also color:#ff0000;
|
||||
* Not old_compat it is in a div class="reqnote"
|
||||
* // if 'group_hiddens' option is true:
|
||||
* 'hidden' => array with html of hidden elements (array),
|
||||
* // if 'group_errors' option is true:
|
||||
* 'errors' => array(
|
||||
* '1st element id' => 'Error for the 1st element',
|
||||
* ...
|
||||
* 'nth element id' => 'Error for the nth element'
|
||||
* ),
|
||||
* 'elements' => array(
|
||||
* element_1,
|
||||
* ...
|
||||
* element_N
|
||||
* )
|
||||
* '1st_elements_name' => array for the 1st element,
|
||||
* ... references into 'elements' above
|
||||
* 'nth_elements_name' => array for the nth element,
|
||||
* )
|
||||
* );
|
||||
* </pre>
|
||||
* Where element_i is an array of the form
|
||||
* <pre>
|
||||
* array(
|
||||
* 'id' => element id (string),
|
||||
* 'name' => element name (string),
|
||||
* 'type' => type of the element (string),
|
||||
* 'frozen' => whether element is frozen (bool),
|
||||
* // if element has a label:
|
||||
* 'label' => 'label for the element',
|
||||
* // note that if 'static_labels' option is true and element's label is an
|
||||
* // array then there will be several 'label_*' keys corresponding to
|
||||
* // labels' array keys
|
||||
* 'required' => whether element is required (bool),
|
||||
* // if a validation error is present and 'group_errors' option is false:
|
||||
* 'error' => error associated with the element (string),
|
||||
* // if some style was associated with an element:
|
||||
* 'style' => 'some information about element style (e.g. for Smarty)',
|
||||
*
|
||||
* // if element is not a Container
|
||||
* 'value' => element value (mixed),
|
||||
* 'html' => HTML for the element (string),
|
||||
*
|
||||
* // if element is a Container
|
||||
* 'attributes' => container attributes (string)
|
||||
* // only for groups, if separator is set:
|
||||
* 'separator' => separator for group elements (mixed),
|
||||
* 'elements' => array(
|
||||
* element_1,
|
||||
* ...
|
||||
* element_N
|
||||
* )
|
||||
*
|
||||
* If the type is 'radio' an element (type = 'radio') is created for each choice that the user has,
|
||||
* keyed by the 'id' value. An 'element' will be created having an array with one element key '0'.
|
||||
* The 'id' above will be set to the value in 'name'.
|
||||
* The 'type' of each element will be 'radio'
|
||||
* );
|
||||
* </pre>
|
||||
*
|
||||
* The following additional options are available:
|
||||
* <ul>
|
||||
* <li>'old_compat' - generate something compatible with an old renderer</li>
|
||||
* <li>'key_id' - the key to elements is the field's 'id' rather than 'name'</li>
|
||||
* </ul>
|
||||
*
|
||||
* While almost everything in this class is defined as public, its properties
|
||||
* and those methods that are not published (i.e. not in array returned by
|
||||
* exportMethods()) will be available to renderer plugins only.
|
||||
*
|
||||
* The following methods are published:
|
||||
* - {@link reset()}
|
||||
* - {@link toArray()}
|
||||
* - {@link setStyleForId()}
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alain D D Williams <addw@phcomp.co.uk>
|
||||
* @version Release: SCCS: %W% %G% %U%
|
||||
*/
|
||||
class HTML_QuickForm2_Renderer_Smarty extends HTML_QuickForm2_Renderer_Array
|
||||
{
|
||||
/**
|
||||
* Constructor, adds new options
|
||||
*/
|
||||
protected function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->options += array(
|
||||
'old_compat' => false,
|
||||
'key_id' => false,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an array with fields that are common to all elements
|
||||
*
|
||||
* @param HTML_QuickForm2_Node Element being rendered
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function buildCommonFields(HTML_QuickForm2_Node $element)
|
||||
{
|
||||
$keyn = $this->options['key_id'] ? 'id' : 'name';
|
||||
|
||||
$ary = array(
|
||||
'id' => $element->getId(),
|
||||
'frozen' => $element->toggleFrozen(),
|
||||
'name' => $element->getName(),
|
||||
);
|
||||
|
||||
// Key that we use for putting into arrays so that smarty can extract them.
|
||||
// Note that the name may be empty.
|
||||
$key_val = $ary[$keyn];
|
||||
if($key_val == '')
|
||||
$key_val = $ary['id'];
|
||||
|
||||
if ($labels = $element->getLabel()) {
|
||||
if (!is_array($labels) || !$this->options['static_labels']) {
|
||||
$ary['label'] = $labels;
|
||||
} else {
|
||||
foreach ($labels as $key => $label) {
|
||||
$key = is_int($key)? $key + 1: $key;
|
||||
if (1 === $key) {
|
||||
$ary['label'] = $label;
|
||||
} else {
|
||||
$ary['label_' . $key] = $label;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Smarty: group_errors under 'name' or 'id' depending on key_id option:
|
||||
if (($error = $element->getError()) && $this->options['group_errors']) {
|
||||
$this->array['errors'][$key_val] = $error;
|
||||
} elseif ($error) {
|
||||
$ary['error'] = $error;
|
||||
}
|
||||
if (isset($this->styles[$key_val])) {
|
||||
$ary['style'] = $this->styles[$key_val];
|
||||
}
|
||||
if (!$element instanceof HTML_QuickForm2_Container) {
|
||||
$ary['html'] = $element->__toString();
|
||||
} else {
|
||||
$ary['elements'] = array();
|
||||
$ary['attributes'] = $element->getAttributes(true);
|
||||
}
|
||||
return $ary;
|
||||
}
|
||||
|
||||
public function startForm(HTML_QuickForm2_Node $form)
|
||||
{
|
||||
if($this->options['old_compat'])
|
||||
$this->options['group_hiddens'] = true;
|
||||
|
||||
parent::startForm($form);
|
||||
}
|
||||
|
||||
public function finishForm(HTML_QuickForm2_Node $form)
|
||||
{
|
||||
parent::finishForm($form);
|
||||
|
||||
if ($this->hasRequired) {
|
||||
|
||||
// Create element 'requirednote' - note no '_'
|
||||
if($this->options['old_compat']) {
|
||||
// Old QuickForm had the requirednote styled & a different name:
|
||||
$this->array['requirednote'] = preg_replace('|<em>([^<]+)</em>(.*)|',
|
||||
'<span style="font-size:80%; color:#ff0000;">$1</span><span style="font-size:80%;">$2</span>',
|
||||
$this->options['required_note']);
|
||||
} else {
|
||||
$this->array['requirednote'] = '<div class="reqnote">'. $this->options['required_note'] . '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
// Create top level elements keyed by form field 'name' or 'id'
|
||||
if(isset($this->array['elements']['0']))
|
||||
$this->linkToLevelAbove($this->array, $this->array['elements']);
|
||||
|
||||
// For compat: it is expected that 'hidden' is a string, not an array:
|
||||
if($this->options['old_compat'] && isset($this->array['hidden']) && is_array($this->array['hidden']))
|
||||
$this->array['hidden'] = join(' ', $this->array['hidden']);
|
||||
}
|
||||
|
||||
// Look through the elements (numerically indexed) array, make fields
|
||||
// members of the level above. This is so that they can be easily accessed by smarty templates.
|
||||
// If we find a group, recurse down. Used for smarty only.
|
||||
// Key is 'name' or 'id'.
|
||||
private function linkToLevelAbove(&$top, $elements, $inGroup = false)
|
||||
{
|
||||
$key = $this->options['key_id'] ? 'id' : 'name';
|
||||
|
||||
foreach($elements as &$elem) {
|
||||
$top_key = $elem[$key];
|
||||
|
||||
// If in a group, convert something like inGrp[F4grp][F4_1] to F4_1
|
||||
// Don't do if key_id as the value is a straight id.
|
||||
if( !$this->options['key_id'] && $inGroup && $top_key != '') {
|
||||
if(!(preg_match("/\[?([\w_]+)\]?$/i", $top_key, $match)))
|
||||
throw new HTML_QuickForm2_InvalidArgumentException(
|
||||
"linkToLevelAbove can't obtain the name from '$top_key'");
|
||||
$top_key = $match[1];
|
||||
}
|
||||
|
||||
// Radio buttons: several elements with the same name, make an array
|
||||
if(isset($elem['type']) && $elem['type'] == 'radio') {
|
||||
if( ! isset($top[$top_key]))
|
||||
$top[$top_key] = array('id' => $top_key, 'type' => 'radio', 'elements' => array(0));
|
||||
$top[$top_key][$elem['id']] = &$elem;
|
||||
} else // Normal field, just link into the level above.
|
||||
if( ! isset($top[$top_key]))
|
||||
$top[$top_key] = &$elem; // Link into the level above
|
||||
|
||||
// If we have a group link its fields up to this level:
|
||||
if(isset($elem['elements']['0']))
|
||||
$this->linkToLevelAbove($elem, $elem['elements'], true);
|
||||
|
||||
// Link errors to the top level:
|
||||
if(isset($elem['error']) && isset($this->array[$elem['error']]))
|
||||
$this->array['errors'][$top_key] = $this->array[$elem['error']];
|
||||
}
|
||||
}
|
||||
|
||||
/**#@-*/
|
||||
}
|
Reference in New Issue
Block a user