添加 Piwik 到代码库中。

+YUCHENG HU+

git-svn-id: https://svn.code.sf.net/p/hawebs/svn@446 a2543c7e-f6e9-4f8a-8bff-1ffc34733512
This commit is contained in:
YuCheng Hu
2010-07-10 02:16:49 +00:00
parent 3fc8e825f4
commit af01a5b640
73 changed files with 17443 additions and 0 deletions
File diff suppressed because it is too large Load Diff
+193
View File
@@ -0,0 +1,193 @@
<?php
// +-----------------------------------------------------------------------+
// | Copyright (c) 2005, Bertrand Mansion |
// | All rights reserved. |
// | |
// | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions |
// | are met: |
// | |
// | o Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. |
// | o 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.|
// | o 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. |
// | |
// +-----------------------------------------------------------------------+
// | Author: Bertrand Mansion <[email protected]> |
// | Stephan Schmidt <[email protected]> |
// +-----------------------------------------------------------------------+
//
// $Id: Notification.php 1230 2009-06-16 04:42:53Z vipsoft $
/**
* Default state of the notification
*/
define('EVENT_NOTIFICATION_STATE_DEFAULT', 0);
/**
* Notification has been cancelled
*/
define('EVENT_NOTIFICATION_STATE_CANCELLED', 1);
/**
* A Notification object
*
* The Notification object can be easily subclassed and serves as a container
* for the information about the notification. It holds an object which is
* usually a reference to the object that posted the notification,
* a notification name used to identify the notification and some user
* information which can be anything you need.
*
* @category Event
* @package Event_Dispatcher
* @author Bertrand Mansion <[email protected]>
* @author Stephan Schmidt <[email protected]>
* @copyright 1997-2005 The PHP Group
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version Release: @package_version@
* @link http://pear.php.net/package/Event_Dispatcher
*/
class Event_Notification
{
/**
* name of the notofication
* @var string
* @access private
*/
var $_notificationName;
/**
* object of interesed (the sender of the notification, in most cases)
* @var object
* @access private
*/
var $_notificationObject;
/**
* additional information about the notification
* @var mixed
* @access private
*/
var $_notificationInfo = array();
/**
* state of the notification
*
* This may be:
* - EVENT_NOTIFICATION_STATE_DEFAULT
* - EVENT_NOTIFICATION_STATE_CANCELLED
*
* @var integer
* @access private
*/
var $_notificationState = EVENT_NOTIFICATION_STATE_DEFAULT;
/**
* amount of observers that received this notification
* @var mixed
* @access private
*/
var $_notificationCount = 0;
/**
* Constructor
*
* @access public
* @param object The object of interest for the notification,
* usually is the posting object
* @param string Notification name
* @param array Free information array
*/
function Event_Notification(&$object, $name, $info = array())
{
$this->_notificationObject =& $object;
$this->_notificationName = $name;
$this->_notificationInfo = $info;
}
/**
* Returns the notification name
* @return string Notification name
*/
function getNotificationName()
{
return $this->_notificationName;
}
/**
* Returns the contained object
* @return object Contained object
*/
function &getNotificationObject()
{
return $this->_notificationObject;
}
/**
* Returns the user info array
* @return array user info
*/
function getNotificationInfo()
{
return $this->_notificationInfo;
}
/**
* Increase the internal count
*
* @access public
*/
function increaseNotificationCount()
{
++$this->_notificationCount;
}
/**
* Get the number of posted notifications
*
* @access public
* @return int
*/
function getNotificationCount()
{
return $this->_notificationCount;
}
/**
* Cancel the notification
*
* @access public
* @return void
*/
function cancelNotification()
{
$this->_notificationState = EVENT_NOTIFICATION_STATE_CANCELLED;
}
/**
* Checks whether the notification has been cancelled
*
* @access public
* @return boolean
*/
function isNotificationCancelled()
{
return ($this->_notificationState === EVENT_NOTIFICATION_STATE_CANCELLED);
}
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,158 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* An abstract base class for QuickForm renderers
*
* PHP versions 4 and 5
*
* LICENSE: This source file is subject to version 3.01 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_01.txt If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to [email protected] so we can mail you a copy immediately.
*
* @category HTML
* @package HTML_QuickForm
* @author Alexey Borzov <[email protected]>
* @copyright 2001-2009 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @version CVS: $Id: Renderer.php 1297 2009-07-08 04:58:45Z vipsoft $
* @link http://pear.php.net/package/HTML_QuickForm
*/
/**
* An abstract base class for QuickForm renderers
*
* The class implements a Visitor design pattern
*
* @category HTML
* @package HTML_QuickForm
* @author Alexey Borzov <[email protected]>
* @version Release: 3.2.11
* @since 3.0
* @abstract
*/
class HTML_QuickForm_Renderer
{
/**
* Constructor
*
* @access public
*/
function HTML_QuickForm_Renderer()
{
} // end constructor
/**
* Called when visiting a form, before processing any form elements
*
* @param HTML_QuickForm a form being visited
* @access public
* @return void
* @abstract
*/
function startForm(&$form)
{
return;
} // end func startForm
/**
* Called when visiting a form, after processing all form elements
*
* @param HTML_QuickForm a form being visited
* @access public
* @return void
* @abstract
*/
function finishForm(&$form)
{
return;
} // end func finishForm
/**
* Called when visiting a header element
*
* @param HTML_QuickForm_header a header element being visited
* @access public
* @return void
* @abstract
*/
function renderHeader(&$header)
{
return;
} // end func renderHeader
/**
* Called when visiting an element
*
* @param HTML_QuickForm_element form element being visited
* @param bool Whether an element is required
* @param string An error message associated with an element
* @access public
* @return void
* @abstract
*/
function renderElement(&$element, $required, $error)
{
return;
} // end func renderElement
/**
* Called when visiting a hidden element
*
* @param HTML_QuickForm_element a hidden element being visited
* @access public
* @return void
* @abstract
*/
function renderHidden(&$element)
{
return;
} // end func renderHidden
/**
* Called when visiting a raw HTML/text pseudo-element
*
* Only implemented in Default renderer. Usage of 'html' elements is
* discouraged, templates should be used instead.
*
* @param HTML_QuickForm_html a 'raw html' element being visited
* @access public
* @return void
* @abstract
*/
function renderHtml(&$data)
{
return;
} // end func renderHtml
/**
* Called when visiting a group, before processing any group elements
*
* @param HTML_QuickForm_group A group being visited
* @param bool Whether a group is required
* @param string An error message associated with a group
* @access public
* @return void
* @abstract
*/
function startGroup(&$group, $required, $error)
{
return;
} // end func startGroup
/**
* Called when visiting a group, after processing all group elements
*
* @param HTML_QuickForm_group A group being visited
* @access public
* @return void
* @abstract
*/
function finishGroup(&$group)
{
return;
} // end func finishGroup
} // end class HTML_QuickForm_Renderer
?>
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,294 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* QuickForm renderer for Flexy template engine, static version.
*
* PHP versions 4 and 5
*
* LICENSE: This source file is subject to version 3.01 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_01.txt If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to [email protected] so we can mail you a copy immediately.
*
* @category HTML
* @package HTML_QuickForm
* @author Ron McClain <[email protected]>
* @copyright 2001-2009 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @version CVS: $Id: ObjectFlexy.php 2118 2010-04-24 06:02:35Z vipsoft $
* @link http://pear.php.net/package/HTML_QuickForm
*/
/**
* A concrete renderer for HTML_QuickForm, makes an object from form contents
*/
require_once dirname(__FILE__) . '/Object.php';
/**
* QuickForm renderer for Flexy template engine, static version.
*
* A static renderer for HTML_Quickform. Makes a QuickFormFlexyObject
* from the form content suitable for use with a Flexy template
*
* Usage:
* <code>
* $form =& new HTML_QuickForm('form', 'POST');
* $template =& new HTML_Template_Flexy();
* $renderer =& new HTML_QuickForm_Renderer_ObjectFlexy(&$template);
* $renderer->setHtmlTemplate("html.html");
* $renderer->setLabelTemplate("label.html");
* $form->accept($renderer);
* $view = new StdClass;
* $view->form = $renderer->toObject();
* $template->compile("mytemplate.html");
* </code>
*
* Based on the code for HTML_QuickForm_Renderer_ArraySmarty
*
* @category HTML
* @package HTML_QuickForm
* @author Ron McClain <[email protected]>
* @version Release: 3.2.11
* @since 3.1.1
*/
class HTML_QuickForm_Renderer_ObjectFlexy extends HTML_QuickForm_Renderer_Object
{
/**#@+
* @access private
*/
/**
* HTML_Template_Flexy instance
* @var object $_flexy
*/
var $_flexy;
/**
* Current element index
* @var integer $_elementIdx
*/
var $_elementIdx;
/**
* The current element index inside a group
* @var integer $_groupElementIdx
*/
var $_groupElementIdx = 0;
/**
* Name of template file for form html
* @var string $_html
* @see setRequiredTemplate()
*/
var $_html = '';
/**
* Name of template file for form labels
* @var string $label
* @see setErrorTemplate()
*/
var $label = '';
/**
* Class of the element objects, so you can add your own
* element methods
* @var string $_elementType
*/
var $_elementType = 'QuickformFlexyElement';
/**#@-*/
/**
* Constructor
*
* @param HTML_Template_Flexy template object to use
* @public
*/
function HTML_QuickForm_Renderer_ObjectFlexy(&$flexy)
{
$this->HTML_QuickForm_Renderer_Object(true);
$this->_obj = new QuickformFlexyForm();
$this->_flexy =& $flexy;
} // end constructor
function renderHeader(&$header)
{
if($name = $header->getName()) {
$this->_obj->header->$name = $header->toHtml();
} else {
// $this->_obj->header[$this->_sectionCount] = $header->toHtml();
$tmp = $this->_obj->header;
$tmp[$this->_sectionCount] = $header->toHtml();
$this->_obj->header = $tmp;
}
$this->_currentSection = $this->_sectionCount++;
} // end func renderHeader
function startGroup(&$group, $required, $error)
{
parent::startGroup($group, $required, $error);
$this->_groupElementIdx = 1;
} //end func startGroup
/**
* Creates an object representing an element containing
* the key for storing this
*
* @access private
* @param HTML_QuickForm_element form element being rendered
* @param bool Whether an element is required
* @param string Error associated with the element
* @return object
*/
function _elementToObject(&$element, $required, $error)
{
$ret = parent::_elementToObject($element, $required, $error);
if($ret->type == 'group') {
$ret->html = $element->toHtml();
unset($ret->elements);
}
if(!empty($this->_label)) {
$this->_renderLabel($ret);
}
if(!empty($this->_html)) {
$this->_renderHtml($ret);
$ret->error = $error;
}
// Create an element key from the name
if (false !== ($pos = strpos($ret->name, '[')) || is_object($this->_currentGroup)) {
if (!$pos) {
$keys = '->{\'' . str_replace(array('\\', '\''), array('\\\\', '\\\''), $ret->name) . '\'}';
} else {
$keys = '->{\'' . str_replace(
array('\\', '\'', '[', ']'), array('\\\\', '\\\'', '\'}->{\'', ''),
$ret->name
) . '\'}';
}
// special handling for elements in native groups
if (is_object($this->_currentGroup)) {
// skip unnamed group items unless radios: no name -> no static access
// identification: have the same key string as the parent group
if ($this->_currentGroup->keys == $keys && 'radio' != $ret->type) {
return false;
}
// reduce string of keys by remove leading group keys
if (0 === strpos($keys, $this->_currentGroup->keys)) {
$keys = substr_replace($keys, '', 0, strlen($this->_currentGroup->keys));
}
}
} elseif (0 == strlen($ret->name)) {
$keys = '->{\'element_' . $this->_elementIdx . '\'}';
} else {
$keys = '->{\'' . str_replace(array('\\', '\''), array('\\\\', '\\\''), $ret->name) . '\'}';
}
// for radios: add extra key from value
if ('radio' == $ret->type && '[]' != substr($keys, -2)) {
$keys .= '->{\'' . str_replace(array('\\', '\''), array('\\\\', '\\\''), $ret->value) . '\'}';
}
$ret->keys = $keys;
$this->_elementIdx++;
return $ret;
}
/**
* Stores an object representation of an element in the
* QuickformFormObject instance
*
* @access private
* @param QuickformElement Object representation of an element
* @return void
*/
function _storeObject($elObj)
{
if ($elObj) {
$keys = $elObj->keys;
unset($elObj->keys);
if(is_object($this->_currentGroup) && ('group' != $elObj->type)) {
$code = '$this->_currentGroup' . $keys . ' = $elObj;';
} else {
$code = '$this->_obj' . $keys . ' = $elObj;';
}
eval($code);
}
}
/**
* Set the filename of the template to render html elements.
* In your template, {html} is replaced by the unmodified html.
* If the element is required, {required} will be true.
* Eg.
* <pre>
* {if:error}
* <font color="red" size="1">{error:h}</font><br />
* {end:}
* {html:h}
* </pre>
*
* @access public
* @param string Filename of template
* @return void
*/
function setHtmlTemplate($template)
{
$this->_html = $template;
}
/**
* Set the filename of the template to render form labels
* In your template, {label} is replaced by the unmodified label.
* {error} will be set to the error, if any. {required} will
* be true if this is a required field
* Eg.
* <pre>
* {if:required}
* <font color="orange" size="1">*</font>
* {end:}
* {label:h}
* </pre>
*
* @access public
* @param string Filename of template
* @return void
*/
function setLabelTemplate($template)
{
$this->_label = $template;
}
function _renderLabel(&$ret)
{
$this->_flexy->compile($this->_label);
$ret->label = $this->_flexy->bufferedOutputObject($ret);
}
function _renderHtml(&$ret)
{
$this->_flexy->compile($this->_html);
$ret->html = $this->_flexy->bufferedOutputObject($ret);
}
} // end class HTML_QuickForm_Renderer_ObjectFlexy
/**
* Adds nothing to QuickformForm, left for backwards compatibility
*
* @category HTML
* @package HTML_QuickForm
* @ignore
*/
class QuickformFlexyForm extends QuickformForm
{
}
/**
* Adds nothing to QuickformElement, left for backwards compatibility
*
* @category HTML
* @package HTML_QuickForm
* @ignore
*/
class QuickformFlexyElement extends QuickformElement
{
}
?>
@@ -0,0 +1,213 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* A renderer that makes it quick and easy to create customized forms.
*
* PHP versions 4 and 5
*
* LICENSE: This source file is subject to version 3.01 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_01.txt If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to [email protected] so we can mail you a copy immediately.
*
* @category HTML
* @package HTML_QuickForm
* @author Jason Rust <[email protected]>
* @copyright 2001-2009 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @version CVS: $Id: QuickHtml.php 2118 2010-04-24 06:02:35Z vipsoft $
* @link http://pear.php.net/package/HTML_QuickForm
*/
/**
* A concrete renderer for HTML_QuickForm, based on QuickForm 2.x built-in one
*/
require_once dirname(__FILE__) . '/Default.php';
/**
* A renderer that makes it quick and easy to create customized forms.
*
* This renderer has three main distinctives: an easy way to create
* custom-looking forms, the ability to separate the creation of form
* elements from their display, and being able to use QuickForm in
* widget-based template systems. See the online docs for more info.
* For a usage example see: docs/renderers/QuickHtml_example.php
*
* @category HTML
* @package HTML_QuickForm
* @author Jason Rust <[email protected]>
* @version Release: 3.2.11
* @since 3.1.1
*/
class HTML_QuickForm_Renderer_QuickHtml extends HTML_QuickForm_Renderer_Default {
// {{{ properties
/**
* The array of rendered elements
* @var array
*/
var $renderedElements = array();
// }}}
// {{{ constructor
/**
* Constructor
*
* @access public
* @return void
*/
function HTML_QuickForm_Renderer_QuickHtml()
{
$this->HTML_QuickForm_Renderer_Default();
// The default templates aren't used for this renderer
$this->clearAllTemplates();
} // end constructor
// }}}
// {{{ toHtml()
/**
* returns the HTML generated for the form
*
* @param string $data (optional) Any extra data to put before the end of the form
*
* @access public
* @return string
*/
function toHtml($data = '')
{
// Render any elements that haven't been rendered explicitly by elementToHtml()
foreach (array_keys($this->renderedElements) as $key) {
if (!$this->renderedElements[$key]['rendered']) {
$this->renderedElements[$key]['rendered'] = true;
$data .= $this->renderedElements[$key]['html'] . "\n";
}
}
// Insert the extra data and form elements at the end of the form
$this->_html = str_replace('</form>', $data . "\n</form>", $this->_html);
return $this->_html;
} // end func toHtml
// }}}
// {{{ elementToHtml()
/**
* Gets the html for an element and marks it as rendered.
*
* @param string $elementName The element name
* @param string $elementValue (optional) The value of the element. This is only useful
* for elements that have the same name (i.e. radio and checkbox), but
* different values
*
* @access public
* @return string The html for the QuickForm element
* @throws HTML_QuickForm_Error
*/
function elementToHtml($elementName, $elementValue = null)
{
$elementKey = null;
// Find the key for the element
foreach ($this->renderedElements as $key => $data) {
if ($data['name'] == $elementName &&
// See if the value must match as well
(is_null($elementValue) ||
$data['value'] == $elementValue)) {
$elementKey = $key;
break;
}
}
if (is_null($elementKey)) {
$msg = is_null($elementValue) ? "Element $elementName does not exist." :
"Element $elementName with value of $elementValue does not exist.";
return PEAR::raiseError(null, QUICKFORM_UNREGISTERED_ELEMENT, null, E_USER_WARNING, $msg, 'HTML_QuickForm_Error', true);
} else {
if ($this->renderedElements[$elementKey]['rendered']) {
$msg = is_null($elementValue) ? "Element $elementName has already been rendered." :
"Element $elementName with value of $elementValue has already been rendered.";
return PEAR::raiseError(null, QUICKFORM_ERROR, null, E_USER_WARNING, $msg, 'HTML_QuickForm_Error', true);
} else {
$this->renderedElements[$elementKey]['rendered'] = true;
return $this->renderedElements[$elementKey]['html'];
}
}
} // end func elementToHtml
// }}}
// {{{ renderElement()
/**
* Gets the html for an element and adds it to the array by calling
* parent::renderElement()
*
* @param HTML_QuickForm_element form element being visited
* @param bool Whether an element is required
* @param string An error message associated with an element
*
* @access public
* @return mixed HTML string of element if $immediateRender is set, else we just add the
* html to the global _html string
*/
function renderElement(&$element, $required, $error)
{
$this->_html = '';
parent::renderElement($element, $required, $error);
if (!$this->_inGroup) {
$this->renderedElements[] = array(
'name' => $element->getName(),
'value' => $element->getValue(),
'html' => $this->_html,
'rendered' => false);
}
$this->_html = '';
} // end func renderElement
// }}}
// {{{ renderHidden()
/**
* Gets the html for a hidden element and adds it to the array.
*
* @param HTML_QuickForm_element hidden form element being visited
* @access public
* @return void
*/
function renderHidden(&$element)
{
$this->renderedElements[] = array(
'name' => $element->getName(),
'value' => $element->getValue(),
'html' => $element->toHtml(),
'rendered' => false);
} // end func renderHidden
// }}}
// {{{ finishGroup()
/**
* Gets the html for the group element and adds it to the array by calling
* parent::finishGroup()
*
* @param HTML_QuickForm_group group being visited
* @access public
* @return void
*/
function finishGroup(&$group)
{
$this->_html = '';
parent::finishGroup($group);
$this->renderedElements[] = array(
'name' => $group->getName(),
'value' => $group->getValue(),
'html' => $this->_html,
'rendered' => false);
$this->_html = '';
} // end func finishGroup
// }}}
} // end class HTML_QuickForm_Renderer_QuickHtml
?>
@@ -0,0 +1,82 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Abstract base class for QuickForm validation rules
*
* PHP versions 4 and 5
*
* LICENSE: This source file is subject to version 3.01 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_01.txt If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to [email protected] so we can mail you a copy immediately.
*
* @category HTML
* @package HTML_QuickForm
* @author Bertrand Mansion <[email protected]>
* @copyright 2001-2009 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @version CVS: $Id: Rule.php 1297 2009-07-08 04:58:45Z vipsoft $
* @link http://pear.php.net/package/HTML_QuickForm
*/
/**
* Abstract base class for QuickForm validation rules
*
* @category HTML
* @package HTML_QuickForm
* @author Bertrand Mansion <[email protected]>
* @version Release: 3.2.11
* @since 3.2
* @abstract
*/
class HTML_QuickForm_Rule
{
/**
* Name of the rule to use in validate method
*
* This property is used in more global rules like Callback and Regex
* to determine which callback and which regex is to be used for validation
*
* @var string
* @access public
*/
var $name;
/**
* Validates a value
*
* @access public
* @abstract
*/
function validate($value)
{
return true;
}
/**
* Sets the rule name
*
* @param string rule name
* @access public
*/
function setName($ruleName)
{
$this->name = $ruleName;
}
/**
* Returns the javascript test (the test should return true if the value is INVALID)
*
* @param mixed Options for the rule
* @access public
* @return array first element is code to setup validation, second is the check itself
* @abstract
*/
function getValidationScript($options = null)
{
return array('', '');
}
}
?>
@@ -0,0 +1,124 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Validates values using callback functions or methods
*
* PHP versions 4 and 5
*
* LICENSE: This source file is subject to version 3.01 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_01.txt If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to [email protected] so we can mail you a copy immediately.
*
* @category HTML
* @package HTML_QuickForm
* @author Bertrand Mansion <[email protected]>
* @copyright 2001-2009 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @version CVS: $Id: Callback.php 2118 2010-04-24 06:02:35Z vipsoft $
* @link http://pear.php.net/package/HTML_QuickForm
*/
/**
* Abstract base class for QuickForm validation rules
*/
require_once dirname(__FILE__) . '/../Rule.php';
/**
* Validates values using callback functions or methods
*
* @category HTML
* @package HTML_QuickForm
* @author Bertrand Mansion <[email protected]>
* @version Release: 3.2.11
* @since 3.2
*/
class HTML_QuickForm_Rule_Callback extends HTML_QuickForm_Rule
{
/**
* Array of callbacks
*
* Array is in the format:
* $_data['rulename'] = array('functionname', 'classname');
* If the callback is not a method, then the class name is not set.
*
* @var array
* @access private
*/
var $_data = array();
/**
* Whether to use BC mode for specific rules
*
* Previous versions of QF passed element's name as a first parameter
* to validation functions, but not to validation methods. This behaviour
* is emulated if you are using 'function' as rule type when registering.
*
* @var array
* @access private
*/
var $_BCMode = array();
/**
* Validates a value using a callback
*
* @param string $value Value to be checked
* @param mixed $options Options for callback
* @access public
* @return boolean true if value is valid
*/
function validate($value, $options = null)
{
if (isset($this->_data[$this->name])) {
$callback = $this->_data[$this->name];
if (isset($callback[1])) {
return call_user_func(array($callback[1], $callback[0]), $value, $options);
} elseif ($this->_BCMode[$this->name]) {
return $callback[0]('', $value, $options);
} else {
return $callback[0]($value, $options);
}
} elseif (is_callable($options)) {
return call_user_func($options, $value);
} else {
return true;
}
} // end func validate
/**
* Adds new callbacks to the callbacks list
*
* @param string $name Name of rule
* @param string $callback Name of function or method
* @param string $class Name of class containing the method
* @param bool $BCMode Backwards compatibility mode
* @access public
*/
function addData($name, $callback, $class = null, $BCMode = false)
{
if (!empty($class)) {
$this->_data[$name] = array($callback, $class);
} else {
$this->_data[$name] = array($callback);
}
$this->_BCMode[$name] = $BCMode;
} // end func addData
function getValidationScript($options = null)
{
if (isset($this->_data[$this->name])) {
$callback = $this->_data[$this->name][0];
$params = ($this->_BCMode[$this->name]? "'', {jsVar}": '{jsVar}') .
(isset($options)? ", '{$options}'": '');
} else {
$callback = is_array($options)? $options[1]: $options;
$params = '{jsVar}';
}
return array('', "{jsVar} != '' && !{$callback}({$params})");
} // end func getValidationScript
} // end class HTML_QuickForm_Rule_Callback
?>
@@ -0,0 +1,105 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Rule to compare two form fields
*
* PHP versions 4 and 5
*
* LICENSE: This source file is subject to version 3.01 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_01.txt If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to [email protected] so we can mail you a copy immediately.
*
* @category HTML
* @package HTML_QuickForm
* @author Alexey Borzov <[email protected]>
* @copyright 2001-2009 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @version CVS: $Id: Compare.php 2118 2010-04-24 06:02:35Z vipsoft $
* @link http://pear.php.net/package/HTML_QuickForm
*/
/**
* Abstract base class for QuickForm validation rules
*/
require_once dirname(__FILE__) . '/../Rule.php';
/**
* Rule to compare two form fields
*
* The most common usage for this is to ensure that the password
* confirmation field matches the password field
*
* @category HTML
* @package HTML_QuickForm
* @author Alexey Borzov <[email protected]>
* @version Release: 3.2.11
* @since 3.2
*/
class HTML_QuickForm_Rule_Compare extends HTML_QuickForm_Rule
{
/**
* Possible operators to use
* @var array
* @access private
*/
var $_operators = array(
'eq' => '===',
'neq' => '!==',
'gt' => '>',
'gte' => '>=',
'lt' => '<',
'lte' => '<=',
'==' => '===',
'!=' => '!=='
);
/**
* Returns the operator to use for comparing the values
*
* @access private
* @param string operator name
* @return string operator to use for validation
*/
function _findOperator($name)
{
if (empty($name)) {
return '===';
} elseif (isset($this->_operators[$name])) {
return $this->_operators[$name];
} elseif (in_array($name, $this->_operators)) {
return $name;
} else {
return '===';
}
}
function validate($values, $operator = null)
{
$operator = $this->_findOperator($operator);
if ('===' != $operator && '!==' != $operator) {
$compareFn = create_function('$a, $b', 'return floatval($a) ' . $operator . ' floatval($b);');
} else {
$compareFn = create_function('$a, $b', 'return strval($a) ' . $operator . ' strval($b);');
}
return $compareFn($values[0], $values[1]);
}
function getValidationScript($operator = null)
{
$operator = $this->_findOperator($operator);
if ('===' != $operator && '!==' != $operator) {
$check = "!(Number({jsVar}[0]) {$operator} Number({jsVar}[1]))";
} else {
$check = "!(String({jsVar}[0]) {$operator} String({jsVar}[1]))";
}
return array('', "'' != {jsVar}[0] && {$check}");
}
}
?>
@@ -0,0 +1,73 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Email validation rule
*
* PHP versions 4 and 5
*
* LICENSE: This source file is subject to version 3.01 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_01.txt If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to [email protected] so we can mail you a copy immediately.
*
* @category HTML
* @package HTML_QuickForm
* @author Bertrand Mansion <[email protected]>
* @copyright 2001-2009 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @version CVS: $Id: Email.php 2118 2010-04-24 06:02:35Z vipsoft $
* @link http://pear.php.net/package/HTML_QuickForm
*/
/**
* Abstract base class for QuickForm validation rules
*/
require_once dirname(__FILE__) . '/../Rule.php';
/**
* Email validation rule
*
* @category HTML
* @package HTML_QuickForm
* @author Bertrand Mansion <[email protected]>
* @version Release: 3.2.11
* @since 3.2
*/
class HTML_QuickForm_Rule_Email extends HTML_QuickForm_Rule
{
var $regex = '/^((\"[^\"\f\n\r\t\v\b]+\")|([\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+(\.[\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+)*))@((\[(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))\])|(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))|((([A-Za-z0-9\-])+\.)+[A-Za-z\-]+))$/';
/**
* Validates an email address
*
* @param string $email Email address
* @param boolean $checkDomain True if dns check should be performed
* @access public
* @return boolean true if email is valid
*/
function validate($email, $checkDomain = false)
{
// Fix for bug #10799: add 'D' modifier to regex
if (preg_match($this->regex . 'D', $email)) {
if ($checkDomain && function_exists('checkdnsrr')) {
$tokens = explode('@', $email);
if (checkdnsrr($tokens[1], 'MX') || checkdnsrr($tokens[1], 'A')) {
return true;
}
return false;
}
return true;
}
return false;
} // end func validate
function getValidationScript($options = null)
{
return array(" var regex = " . $this->regex . ";\n", "{jsVar} != '' && !regex.test({jsVar})");
} // end func getValidationScript
} // end class HTML_QuickForm_Rule_Email
?>
@@ -0,0 +1,75 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Checks that the length of value is within range
*
* PHP versions 4 and 5
*
* LICENSE: This source file is subject to version 3.01 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_01.txt If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to [email protected] so we can mail you a copy immediately.
*
* @category HTML
* @package HTML_QuickForm
* @author Bertrand Mansion <[email protected]>
* @copyright 2001-2009 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @version CVS: $Id: Range.php 2118 2010-04-24 06:02:35Z vipsoft $
* @link http://pear.php.net/package/HTML_QuickForm
*/
/**
* Abstract base class for QuickForm validation rules
*/
require_once dirname(__FILE__) . '/../Rule.php';
/**
* Checks that the length of value is within range
*
* @category HTML
* @package HTML_QuickForm
* @author Bertrand Mansion <[email protected]>
* @version Release: 3.2.11
* @since 3.2
*/
class HTML_QuickForm_Rule_Range extends HTML_QuickForm_Rule
{
/**
* Validates a value using a range comparison
*
* @param string $value Value to be checked
* @param mixed $options Int for length, array for range
* @access public
* @return boolean true if value is valid
*/
function validate($value, $options)
{
$length = strlen($value);
switch ($this->name) {
case 'minlength': return ($length >= $options);
case 'maxlength': return ($length <= $options);
default: return ($length >= $options[0] && $length <= $options[1]);
}
} // end func validate
function getValidationScript($options = null)
{
switch ($this->name) {
case 'minlength':
$test = '{jsVar}.length < '.$options;
break;
case 'maxlength':
$test = '{jsVar}.length > '.$options;
break;
default:
$test = '({jsVar}.length < '.$options[0].' || {jsVar}.length > '.$options[1].')';
}
return array('', "{jsVar} != '' && {$test}");
} // end func getValidationScript
} // end class HTML_QuickForm_Rule_Range
?>
@@ -0,0 +1,107 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Validates values using regular expressions
*
* PHP versions 4 and 5
*
* LICENSE: This source file is subject to version 3.01 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_01.txt If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to [email protected] so we can mail you a copy immediately.
*
* @category HTML
* @package HTML_QuickForm
* @author Bertrand Mansion <[email protected]>
* @copyright 2001-2009 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @version CVS: $Id: Regex.php 2118 2010-04-24 06:02:35Z vipsoft $
* @link http://pear.php.net/package/HTML_QuickForm
*/
/**
* Abstract base class for QuickForm validation rules
*/
require_once dirname(__FILE__) . '/../Rule.php';
/**
* Validates values using regular expressions
*
* @category HTML
* @package HTML_QuickForm
* @author Bertrand Mansion <[email protected]>
* @version Release: 3.2.11
* @since 3.2
*/
class HTML_QuickForm_Rule_Regex extends HTML_QuickForm_Rule
{
/**
* Array of regular expressions
*
* Array is in the format:
* $_data['rulename'] = 'pattern';
*
* @var array
* @access private
*/
var $_data = array(
'lettersonly' => '/^[a-zA-Z]+$/',
'alphanumeric' => '/^[a-zA-Z0-9]+$/',
'numeric' => '/(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/',
'nopunctuation' => '/^[^().\/\*\^\?#!@$%+=,\"\'><~\[\]{}]+$/',
'nonzero' => '/^-?[1-9][0-9]*/'
);
/**
* Validates a value using a regular expression
*
* @param string $value Value to be checked
* @param string $regex Regular expression
* @access public
* @return boolean true if value is valid
*/
function validate($value, $regex = null)
{
// Fix for bug #10799: add 'D' modifier to regex
if (isset($this->_data[$this->name])) {
if (!preg_match($this->_data[$this->name] . 'D', $value)) {
return false;
}
} else {
if (!preg_match($regex . 'D', $value)) {
return false;
}
}
return true;
} // end func validate
/**
* Adds new regular expressions to the list
*
* @param string $name Name of rule
* @param string $pattern Regular expression pattern
* @access public
*/
function addData($name, $pattern)
{
$this->_data[$name] = $pattern;
} // end func addData
function getValidationScript($options = null)
{
$regex = isset($this->_data[$this->name]) ? $this->_data[$this->name] : $options;
// bug #12376, converting unicode escapes and stripping 'u' modifier
if ($pos = strpos($regex, 'u', strrpos($regex, '/'))) {
$regex = substr($regex, 0, $pos) . substr($regex, $pos + 1);
$regex = preg_replace('/(?<!\\\\)(?>\\\\\\\\)*\\\\x{([a-fA-F0-9]+)}/', '\\u$1', $regex);
}
return array(" var regex = " . $regex . ";\n", "{jsVar} != '' && !regex.test({jsVar})");
} // end func getValidationScript
} // end class HTML_QuickForm_Rule_Regex
?>
@@ -0,0 +1,63 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Required elements validation
*
* PHP versions 4 and 5
*
* LICENSE: This source file is subject to version 3.01 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_01.txt If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to [email protected] so we can mail you a copy immediately.
*
* @category HTML
* @package HTML_QuickForm
* @author Bertrand Mansion <[email protected]>
* @copyright 2001-2009 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @version CVS: $Id: Required.php 2118 2010-04-24 06:02:35Z vipsoft $
* @link http://pear.php.net/package/HTML_QuickForm
*/
/**
* Abstract base class for QuickForm validation rules
*/
require_once dirname(__FILE__) . '/../Rule.php';
/**
* Required elements validation
*
* @category HTML
* @package HTML_QuickForm
* @author Bertrand Mansion <[email protected]>
* @version Release: 3.2.11
* @since 3.2
*/
class HTML_QuickForm_Rule_Required extends HTML_QuickForm_Rule
{
/**
* Checks if an element is empty
*
* @param string $value Value to check
* @param mixed $options Not used yet
* @access public
* @return boolean true if value is not empty
*/
function validate($value, $options = null)
{
if ((string)$value == '') {
return false;
}
return true;
} // end func validate
function getValidationScript($options = null)
{
return array('', "{jsVar} == ''");
} // end func getValidationScript
} // end class HTML_QuickForm_Rule_Required
?>
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,286 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* HTML class for an advanced checkbox type field
*
* PHP versions 4 and 5
*
* LICENSE: This source file is subject to version 3.01 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_01.txt If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to [email protected] so we can mail you a copy immediately.
*
* @category HTML
* @package HTML_QuickForm
* @author Jason Rust <[email protected]>
* @author Alexey Borzov <[email protected]>
* @copyright 2001-2009 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @version CVS: $Id: advcheckbox.php 2118 2010-04-24 06:02:35Z vipsoft $
* @link http://pear.php.net/package/HTML_QuickForm
*/
/**
* HTML class for a checkbox type field
*/
require_once dirname(__FILE__) . '/checkbox.php';
/**
* HTML class for an advanced checkbox type field
*
* Basically this fixes a problem that HTML has had
* where checkboxes can only pass a single value (the
* value of the checkbox when checked). A value for when
* the checkbox is not checked cannot be passed, and
* furthermore the checkbox variable doesn't even exist if
* the checkbox was submitted unchecked.
*
* It works by prepending a hidden field with the same name and
* another "unchecked" value to the checbox. If the checkbox is
* checked, PHP overwrites the value of the hidden field with
* its value.
*
* @category HTML
* @package HTML_QuickForm
* @author Jason Rust <[email protected]>
* @author Alexey Borzov <[email protected]>
* @version Release: 3.2.11
* @since 2.0
*/
class HTML_QuickForm_advcheckbox extends HTML_QuickForm_checkbox
{
// {{{ properties
/**
* The values passed by the hidden elment
*
* @var array
* @access private
*/
var $_values = null;
/**
* The default value
*
* @var boolean
* @access private
*/
var $_currentValue = null;
// }}}
// {{{ constructor
/**
* Class constructor
*
* @param string $elementName (optional)Input field name attribute
* @param string $elementLabel (optional)Input field label
* @param string $text (optional)Text to put after the checkbox
* @param mixed $attributes (optional)Either a typical HTML attribute string
* or an associative array
* @param mixed $values (optional)Values to pass if checked or not checked
*
* @since 1.0
* @access public
* @return void
*/
function HTML_QuickForm_advcheckbox($elementName=null, $elementLabel=null, $text=null, $attributes=null, $values=null)
{
$this->HTML_QuickForm_checkbox($elementName, $elementLabel, $text, $attributes);
$this->setValues($values);
} //end constructor
// }}}
// {{{ getPrivateName()
/**
* Gets the private name for the element
*
* @param string $elementName The element name to make private
*
* @access public
* @return string
*
* @deprecated Deprecated since 3.2.6, both generated elements have the same name
*/
function getPrivateName($elementName)
{
return '__'.$elementName;
}
// }}}
// {{{ getOnclickJs()
/**
* Create the javascript for the onclick event which will
* set the value of the hidden field
*
* @param string $elementName The element name
*
* @access public
* @return string
*
* @deprecated Deprecated since 3.2.6, this element no longer uses any javascript
*/
function getOnclickJs($elementName)
{
$onclickJs = 'if (this.checked) { this.form[\''.$elementName.'\'].value=\''.addcslashes($this->_values[1], '\'').'\'; }';
$onclickJs .= 'else { this.form[\''.$elementName.'\'].value=\''.addcslashes($this->_values[0], '\'').'\'; }';
return $onclickJs;
}
// }}}
// {{{ setValues()
/**
* Sets the values used by the hidden element
*
* @param mixed $values The values, either a string or an array
*
* @access public
* @return void
*/
function setValues($values)
{
if (empty($values)) {
// give it default checkbox behavior
$this->_values = array('', 1);
} elseif (is_scalar($values)) {
// if it's string, then assume the value to
// be passed is for when the element is checked
$this->_values = array('', $values);
} else {
$this->_values = $values;
}
$this->updateAttributes(array('value' => $this->_values[1]));
$this->setChecked($this->_currentValue == $this->_values[1]);
}
// }}}
// {{{ setValue()
/**
* Sets the element's value
*
* @param mixed Element's value
* @access public
*/
function setValue($value)
{
$this->setChecked(isset($this->_values[1]) && $value == $this->_values[1]);
$this->_currentValue = $value;
}
// }}}
// {{{ getValue()
/**
* Returns the element's value
*
* @access public
* @return mixed
*/
function getValue()
{
if (is_array($this->_values)) {
return $this->_values[$this->getChecked()? 1: 0];
} else {
return null;
}
}
// }}}
// {{{ toHtml()
/**
* Returns the checkbox element in HTML
* and the additional hidden element in HTML
*
* @access public
* @return string
*/
function toHtml()
{
if ($this->_flagFrozen) {
return parent::toHtml();
} else {
return '<input' . $this->_getAttrString(array(
'type' => 'hidden',
'name' => $this->getName(),
'value' => $this->_values[0]
)) . ' />' . parent::toHtml();
}
} //end func toHtml
// }}}
// {{{ getFrozenHtml()
/**
* Unlike checkbox, this has to append a hidden input in both
* checked and non-checked states
*/
function getFrozenHtml()
{
return ($this->getChecked()? '<tt>[x]</tt>': '<tt>[ ]</tt>') .
$this->_getPersistantData();
}
// }}}
// {{{ onQuickFormEvent()
/**
* Called by HTML_QuickForm whenever form event is made on this element
*
* @param string $event Name of event
* @param mixed $arg event arguments
* @param object &$caller calling object
* @since 1.0
* @access public
* @return void
*/
function onQuickFormEvent($event, $arg, &$caller)
{
switch ($event) {
case 'updateValue':
// constant values override both default and submitted ones
// default values are overriden by submitted
$value = $this->_findValue($caller->_constantValues);
if (null === $value) {
$value = $this->_findValue($caller->_submitValues);
if (null === $value) {
$value = $this->_findValue($caller->_defaultValues);
}
}
if (null !== $value) {
$this->setValue($value);
}
break;
default:
parent::onQuickFormEvent($event, $arg, $caller);
}
return true;
} // end func onQuickFormLoad
// }}}
// {{{ exportValue()
/**
* This element has a value even if it is not checked, thus we override
* checkbox's behaviour here
*/
function exportValue(&$submitValues, $assoc)
{
$value = $this->_findValue($submitValues);
if (null === $value) {
$value = $this->getValue();
} elseif (is_array($this->_values) && ($value != $this->_values[0]) && ($value != $this->_values[1])) {
$value = null;
}
return $this->_prepareValue($value, $assoc);
}
// }}}
} //end class HTML_QuickForm_advcheckbox
?>
@@ -0,0 +1,258 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* HTML class for an autocomplete element
*
* PHP versions 4 and 5
*
* LICENSE: This source file is subject to version 3.01 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_01.txt If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to [email protected] so we can mail you a copy immediately.
*
* @category HTML
* @package HTML_QuickForm
* @author Matteo Di Giovinazzo <[email protected]>
* @copyright 2001-2009 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @version CVS: $Id: autocomplete.php 2118 2010-04-24 06:02:35Z vipsoft $
* @link http://pear.php.net/package/HTML_QuickForm
*/
/**
* HTML class for a text field
*/
require_once dirname(__FILE__) . '/text.php';
/**
* HTML class for an autocomplete element
*
* Creates an HTML input text element that
* at every keypressed javascript event checks in an array of options
* if there's a match and autocompletes the text in case of match.
*
* For the JavaScript code thanks to Martin Honnen and Nicholas C. Zakas
* See {@link http://www.faqts.com/knowledge_base/view.phtml/aid/13562} and
* {@link http://www.sitepoint.com/article/1220}
*
* Example:
* <code>
* $autocomplete =& $form->addElement('autocomplete', 'fruit', 'Favourite fruit:');
* $options = array("Apple", "Orange", "Pear", "Strawberry");
* $autocomplete->setOptions($options);
* </code>
*
* @category HTML
* @package HTML_QuickForm
* @author Matteo Di Giovinazzo <[email protected]>
* @version Release: 3.2.11
* @since 3.2
*/
class HTML_QuickForm_autocomplete extends HTML_QuickForm_text
{
// {{{ properties
/**
* Options for the autocomplete input text element
*
* @var array
* @access private
*/
var $_options = array();
/**
* "One-time" javascript (containing functions), see bug #4611
*
* @var string
* @access private
*/
var $_js = '';
// }}}
// {{{ constructor
/**
* Class constructor
*
* @param string $elementName (optional)Input field name attribute
* @param string $elementLabel (optional)Input field label in form
* @param array $options (optional)Autocomplete options
* @param mixed $attributes (optional)Either a typical HTML attribute string
* or an associative array. Date format is passed along the attributes.
* @access public
* @return void
*/
function HTML_QuickForm_autocomplete($elementName = null, $elementLabel = null, $options = null, $attributes = null)
{
$this->HTML_QuickForm_text($elementName, $elementLabel, $attributes);
$this->_persistantFreeze = true;
$this->_type = 'autocomplete';
if (isset($options)) {
$this->setOptions($options);
}
} //end constructor
// }}}
// {{{ setOptions()
/**
* Sets the options for the autocomplete input text element
*
* @param array $options Array of options for the autocomplete input text element
* @access public
* @return void
*/
function setOptions($options)
{
$this->_options = array_values($options);
} // end func setOptions
// }}}
// {{{ toHtml()
/**
* Returns Html for the autocomplete input text element
*
* @access public
* @return string
*/
function toHtml()
{
// prevent problems with grouped elements
$arrayName = str_replace(array('[', ']'), array('__', ''), $this->getName()) . '_values';
$this->updateAttributes(array(
'onkeypress' => 'return autocomplete(this, event, ' . $arrayName . ');'
));
if ($this->_flagFrozen) {
$js = '';
} else {
$js = "<script type=\"text/javascript\">\n//<![CDATA[\n";
if (!defined('HTML_QUICKFORM_AUTOCOMPLETE_EXISTS')) {
$this->_js .= <<<EOS
/* begin javascript for autocomplete */
function setSelectionRange(input, selectionStart, selectionEnd) {
if (input.setSelectionRange) {
input.setSelectionRange(selectionStart, selectionEnd);
}
else if (input.createTextRange) {
var range = input.createTextRange();
range.collapse(true);
range.moveEnd("character", selectionEnd);
range.moveStart("character", selectionStart);
range.select();
}
input.focus();
}
function setCaretToPosition(input, position) {
setSelectionRange(input, position, position);
}
function replaceSelection (input, replaceString) {
var len = replaceString.length;
if (input.setSelectionRange) {
var selectionStart = input.selectionStart;
var selectionEnd = input.selectionEnd;
input.value = input.value.substring(0, selectionStart) + replaceString + input.value.substring(selectionEnd);
input.selectionStart = selectionStart + len;
input.selectionEnd = selectionStart + len;
}
else if (document.selection) {
var range = document.selection.createRange();
var saved_range = range.duplicate();
if (range.parentElement() == input) {
range.text = replaceString;
range.moveEnd("character", saved_range.selectionStart + len);
range.moveStart("character", saved_range.selectionStart + len);
range.select();
}
}
input.focus();
}
function autocompleteMatch (text, values) {
for (var i = 0; i < values.length; i++) {
if (values[i].toUpperCase().indexOf(text.toUpperCase()) == 0) {
return values[i];
}
}
return null;
}
function autocomplete(textbox, event, values) {
if (textbox.setSelectionRange || textbox.createTextRange) {
switch (event.keyCode) {
case 38: // up arrow
case 40: // down arrow
case 37: // left arrow
case 39: // right arrow
case 33: // page up
case 34: // page down
case 36: // home
case 35: // end
case 13: // enter
case 9: // tab
case 27: // esc
case 16: // shift
case 17: // ctrl
case 18: // alt
case 20: // caps lock
case 8: // backspace
case 46: // delete
return true;
break;
default:
var c = String.fromCharCode(
(event.charCode == undefined) ? event.keyCode : event.charCode
);
replaceSelection(textbox, c);
sMatch = autocompleteMatch(textbox.value, values);
var len = textbox.value.length;
if (sMatch != null) {
textbox.value = sMatch;
setSelectionRange(textbox, len, textbox.value.length);
}
return false;
}
}
else {
return true;
}
}
/* end javascript for autocomplete */
EOS;
define('HTML_QUICKFORM_AUTOCOMPLETE_EXISTS', true);
}
$jsEscape = array(
"\r" => '\r',
"\n" => '\n',
"\t" => '\t',
"'" => "\\'",
'"' => '\"',
'\\' => '\\\\'
);
$js .= $this->_js;
$js .= 'var ' . $arrayName . " = new Array();\n";
for ($i = 0; $i < count($this->_options); $i++) {
$js .= $arrayName . '[' . $i . "] = '" . strtr($this->_options[$i], $jsEscape) . "';\n";
}
$js .= "//]]>\n</script>";
}
return $js . parent::toHtml();
}// end func toHtml
// }}}
} // end class HTML_QuickForm_autocomplete
?>
@@ -0,0 +1,80 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* HTML class for an <input type="button" /> elements
*
* PHP versions 4 and 5
*
* LICENSE: This source file is subject to version 3.01 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_01.txt If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to [email protected] so we can mail you a copy immediately.
*
* @category HTML
* @package HTML_QuickForm
* @author Adam Daniel <[email protected]>
* @author Bertrand Mansion <[email protected]>
* @copyright 2001-2009 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @version CVS: $Id: button.php 2118 2010-04-24 06:02:35Z vipsoft $
* @link http://pear.php.net/package/HTML_QuickForm
*/
/**
* Base class for <input /> form elements
*/
require_once dirname(__FILE__) . '/input.php';
/**
* HTML class for an <input type="button" /> elements
*
* @category HTML
* @package HTML_QuickForm
* @author Adam Daniel <[email protected]>
* @author Bertrand Mansion <[email protected]>
* @version Release: 3.2.11
* @since 1.0
*/
class HTML_QuickForm_button extends HTML_QuickForm_input
{
// {{{ constructor
/**
* Class constructor
*
* @param string $elementName (optional)Input field name attribute
* @param string $value (optional)Input field value
* @param mixed $attributes (optional)Either a typical HTML attribute string
* or an associative array
* @since 1.0
* @access public
* @return void
*/
function HTML_QuickForm_button($elementName=null, $value=null, $attributes=null)
{
HTML_QuickForm_input::HTML_QuickForm_input($elementName, null, $attributes);
$this->_persistantFreeze = false;
$this->setValue($value);
$this->setType('button');
} //end constructor
// }}}
// {{{ freeze()
/**
* Freeze the element so that only its value is returned
*
* @access public
* @return void
*/
function freeze()
{
return false;
} //end func freeze
// }}}
} //end class HTML_QuickForm_button
?>
@@ -0,0 +1,277 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* HTML class for a checkbox type field
*
* PHP versions 4 and 5
*
* LICENSE: This source file is subject to version 3.01 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_01.txt If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to [email protected] so we can mail you a copy immediately.
*
* @category HTML
* @package HTML_QuickForm
* @author Adam Daniel <[email protected]>
* @author Bertrand Mansion <[email protected]>
* @author Alexey Borzov <[email protected]>
* @copyright 2001-2009 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @version CVS: $Id: checkbox.php 2118 2010-04-24 06:02:35Z vipsoft $
* @link http://pear.php.net/package/HTML_QuickForm
*/
/**
* Base class for <input /> form elements
*/
require_once dirname(__FILE__) . '/input.php';
/**
* HTML class for a checkbox type field
*
* @category HTML
* @package HTML_QuickForm
* @author Adam Daniel <[email protected]>
* @author Bertrand Mansion <[email protected]>
* @author Alexey Borzov <[email protected]>
* @version Release: 3.2.11
* @since 1.0
*/
class HTML_QuickForm_checkbox extends HTML_QuickForm_input
{
// {{{ properties
/**
* Checkbox display text
* @var string
* @since 1.1
* @access private
*/
var $_text = '';
// }}}
// {{{ constructor
/**
* Class constructor
*
* @param string $elementName (optional)Input field name attribute
* @param string $elementLabel (optional)Input field value
* @param string $text (optional)Checkbox display text
* @param mixed $attributes (optional)Either a typical HTML attribute string
* or an associative array
* @since 1.0
* @access public
* @return void
*/
function HTML_QuickForm_checkbox($elementName=null, $elementLabel=null, $text='', $attributes=null)
{
HTML_QuickForm_input::HTML_QuickForm_input($elementName, $elementLabel, $attributes);
$this->_persistantFreeze = true;
$this->_text = $text;
$this->setType('checkbox');
$this->updateAttributes(array('value'=>1));
$this->_generateId();
} //end constructor
// }}}
// {{{ setChecked()
/**
* Sets whether a checkbox is checked
*
* @param bool $checked Whether the field is checked or not
* @since 1.0
* @access public
* @return void
*/
function setChecked($checked)
{
if (!$checked) {
$this->removeAttribute('checked');
} else {
$this->updateAttributes(array('checked'=>'checked'));
}
} //end func setChecked
// }}}
// {{{ getChecked()
/**
* Returns whether a checkbox is checked
*
* @since 1.0
* @access public
* @return bool
*/
function getChecked()
{
return (bool)$this->getAttribute('checked');
} //end func getChecked
// }}}
// {{{ toHtml()
/**
* Returns the checkbox element in HTML
*
* @since 1.0
* @access public
* @return string
*/
function toHtml()
{
if (0 == strlen($this->_text)) {
$label = '';
} elseif ($this->_flagFrozen) {
$label = $this->_text;
} else {
$label = '<label for="' . $this->getAttribute('id') . '">' . $this->_text . '</label>';
}
return HTML_QuickForm_input::toHtml() . $label;
} //end func toHtml
// }}}
// {{{ getFrozenHtml()
/**
* Returns the value of field without HTML tags
*
* @since 1.0
* @access public
* @return string
*/
function getFrozenHtml()
{
if ($this->getChecked()) {
return '<tt>[x]</tt>' .
$this->_getPersistantData();
} else {
return '<tt>[ ]</tt>';
}
} //end func getFrozenHtml
// }}}
// {{{ setText()
/**
* Sets the checkbox text
*
* @param string $text
* @since 1.1
* @access public
* @return void
*/
function setText($text)
{
$this->_text = $text;
} //end func setText
// }}}
// {{{ getText()
/**
* Returns the checkbox text
*
* @since 1.1
* @access public
* @return string
*/
function getText()
{
return $this->_text;
} //end func getText
// }}}
// {{{ setValue()
/**
* Sets the value of the form element
*
* @param string $value Default value of the form element
* @since 1.0
* @access public
* @return void
*/
function setValue($value)
{
return $this->setChecked($value);
} // end func setValue
// }}}
// {{{ getValue()
/**
* Returns the value of the form element
*
* @since 1.0
* @access public
* @return bool
*/
function getValue()
{
return $this->getChecked();
} // end func getValue
// }}}
// {{{ onQuickFormEvent()
/**
* Called by HTML_QuickForm whenever form event is made on this element
*
* @param string $event Name of event
* @param mixed $arg event arguments
* @param object &$caller calling object
* @since 1.0
* @access public
* @return void
*/
function onQuickFormEvent($event, $arg, &$caller)
{
switch ($event) {
case 'updateValue':
// constant values override both default and submitted ones
// default values are overriden by submitted
$value = $this->_findValue($caller->_constantValues);
if (null === $value) {
// if no boxes were checked, then there is no value in the array
// yet we don't want to display default value in this case
if ($caller->isSubmitted()) {
$value = $this->_findValue($caller->_submitValues);
} else {
$value = $this->_findValue($caller->_defaultValues);
}
}
if (null !== $value || $caller->isSubmitted()) {
$this->setChecked($value);
}
break;
case 'setGroupValue':
$this->setChecked($arg);
break;
default:
parent::onQuickFormEvent($event, $arg, $caller);
}
return true;
} // end func onQuickFormEvent
// }}}
// {{{ exportValue()
/**
* Return true if the checkbox is checked, null if it is not checked (getValue() returns false)
*/
function exportValue(&$submitValues, $assoc = false)
{
$value = $this->_findValue($submitValues);
if (null === $value) {
$value = $this->getChecked()? true: null;
}
return $this->_prepareValue($value, $assoc);
}
// }}}
} //end class HTML_QuickForm_checkbox
?>
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,74 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* A pseudo-element used for adding headers to form
*
* PHP versions 4 and 5
*
* LICENSE: This source file is subject to version 3.01 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_01.txt If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to [email protected] so we can mail you a copy immediately.
*
* @category HTML
* @package HTML_QuickForm
* @author Alexey Borzov <[email protected]>
* @copyright 2001-2009 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @version CVS: $Id: header.php 2118 2010-04-24 06:02:35Z vipsoft $
* @link http://pear.php.net/package/HTML_QuickForm
*/
/**
* HTML class for static data
*/
require_once dirname(__FILE__) . '/static.php';
/**
* A pseudo-element used for adding headers to form
*
* @category HTML
* @package HTML_QuickForm
* @author Alexey Borzov <[email protected]>
* @version Release: 3.2.11
* @since 3.0
*/
class HTML_QuickForm_header extends HTML_QuickForm_static
{
// {{{ constructor
/**
* Class constructor
*
* @param string $elementName Header name
* @param string $text Header text
* @access public
* @return void
*/
function HTML_QuickForm_header($elementName = null, $text = null)
{
$this->HTML_QuickForm_static($elementName, null, $text);
$this->_type = 'header';
}
// }}}
// {{{ accept()
/**
* Accepts a renderer
*
* @param HTML_QuickForm_Renderer renderer object
* @access public
* @return void
*/
function accept(&$renderer)
{
$renderer->renderHeader($this);
} // end func accept
// }}}
} //end class HTML_QuickForm_header
?>

Some files were not shown because too many files have changed in this diff Show More