format for submission details
This commit is contained in:
commit
64a0f8a7d1
3468 changed files with 596569 additions and 0 deletions
33
www/analytics/libs/.htaccess
Normal file
33
www/analytics/libs/.htaccess
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<Files ~ "\.(php|php4|php5|inc|tpl|in|twig)$">
|
||||
<IfModule mod_access.c>
|
||||
Deny from all
|
||||
Require all denied
|
||||
</IfModule>
|
||||
<IfModule !mod_access_compat>
|
||||
<IfModule mod_authz_host.c>
|
||||
Deny from all
|
||||
Require all denied
|
||||
</IfModule>
|
||||
</IfModule>
|
||||
<IfModule mod_access_compat>
|
||||
Deny from all
|
||||
Require all denied
|
||||
</IfModule>
|
||||
</Files>
|
||||
<Files ~ "\.(test\.php|gif|ico|jpg|png|svg|js|css|swf)$">
|
||||
<IfModule mod_access.c>
|
||||
Allow from all
|
||||
Require all granted
|
||||
</IfModule>
|
||||
<IfModule !mod_access_compat>
|
||||
<IfModule mod_authz_host.c>
|
||||
Allow from all
|
||||
Require all granted
|
||||
</IfModule>
|
||||
</IfModule>
|
||||
<IfModule mod_access_compat>
|
||||
Allow from all
|
||||
Require all granted
|
||||
</IfModule>
|
||||
Satisfy any
|
||||
</Files>
|
||||
1993
www/analytics/libs/Archive_Tar/Tar.php
Executable file
1993
www/analytics/libs/Archive_Tar/Tar.php
Executable file
File diff suppressed because it is too large
Load diff
488
www/analytics/libs/HTML/Common2.php
Normal file
488
www/analytics/libs/HTML/Common2.php
Normal file
|
|
@ -0,0 +1,488 @@
|
|||
<?php
|
||||
/**
|
||||
* HTML_Common2: port of HTML_Common package to PHP5
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 2004-2009, Alexey Borzov <avb@php.net>
|
||||
*
|
||||
* 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_Common2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version CVS: $Id: Common2.php 295050 2010-02-14 05:01:19Z clockwerx $
|
||||
* @link http://pear.php.net/package/HTML_Common2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for HTML classes
|
||||
*
|
||||
* Implements methods for working with HTML attributes, parsing and generating
|
||||
* attribute strings. Port of HTML_Common class for PHP4 originally written by
|
||||
* Adam Daniel with contributions from numerous other developers.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_Common2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
abstract class HTML_Common2
|
||||
{
|
||||
/**
|
||||
* Associative array of attributes
|
||||
* @var array
|
||||
*/
|
||||
protected $attributes = array();
|
||||
|
||||
/**
|
||||
* List of attribites changes to which will be announced via onAttributeChange()
|
||||
* method rather than performed by HTML_Common2 class itself
|
||||
* @var array
|
||||
* @see onAttributeChange()
|
||||
*/
|
||||
protected $watchedAttributes = array();
|
||||
|
||||
/**
|
||||
* Indentation level of the element
|
||||
* @var int
|
||||
*/
|
||||
private $_indentLevel = 0;
|
||||
|
||||
/**
|
||||
* Comment associated with the element
|
||||
* @var string
|
||||
*/
|
||||
private $_comment = null;
|
||||
|
||||
/**
|
||||
* Global options for all elements generated by subclasses of HTML_Common2
|
||||
*
|
||||
* Preset options are
|
||||
* - 'charset': charset parameter used in htmlspecialchars() calls,
|
||||
* defaults to 'ISO-8859-1'
|
||||
* - 'indent': string used to indent HTML elements, defaults to "\11"
|
||||
* - 'linebreak': string used to indicate linebreak, defaults to "\12"
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $_options = array(
|
||||
'charset' => 'ISO-8859-1',
|
||||
'indent' => "\11",
|
||||
'linebreak' => "\12"
|
||||
);
|
||||
|
||||
/**
|
||||
* Sets global option(s)
|
||||
*
|
||||
* @param string|array Option name or array ('option name' => 'option value')
|
||||
* @param mixed Option value, if first argument is not an array
|
||||
*/
|
||||
public static function setOption($nameOrOptions, $value = null)
|
||||
{
|
||||
if (is_array($nameOrOptions)) {
|
||||
foreach ($nameOrOptions as $k => $v) {
|
||||
self::setOption($k, $v);
|
||||
}
|
||||
} else {
|
||||
$linebreaks = array('win' => "\15\12", 'unix' => "\12", 'mac' => "\15");
|
||||
if ('linebreak' == $nameOrOptions && isset($linebreaks[$value])) {
|
||||
$value = $linebreaks[$value];
|
||||
}
|
||||
self::$_options[$nameOrOptions] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns global option(s)
|
||||
*
|
||||
* @param string Option name
|
||||
* @return mixed Option value, null if option does not exist,
|
||||
* array of all options if $name is not given
|
||||
*/
|
||||
public static function getOption($name = null)
|
||||
{
|
||||
if (null === $name) {
|
||||
return self::$_options;
|
||||
} else {
|
||||
return isset(self::$_options[$name])? self::$_options[$name]: null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the HTML attributes given as string
|
||||
*
|
||||
* @param string HTML attribute string
|
||||
* @return array An associative aray of attributes
|
||||
*/
|
||||
protected static function parseAttributes($attrString)
|
||||
{
|
||||
$attributes = array();
|
||||
if (preg_match_all(
|
||||
"/(([A-Za-z_:]|[^\\x00-\\x7F])([A-Za-z0-9_:.-]|[^\\x00-\\x7F])*)" .
|
||||
"([ \\n\\t\\r]+)?(=([ \\n\\t\\r]+)?(\"[^\"]*\"|'[^']*'|[^ \\n\\t\\r]*))?/",
|
||||
$attrString,
|
||||
$regs
|
||||
)) {
|
||||
for ($i = 0; $i < count($regs[1]); $i++) {
|
||||
$name = trim($regs[1][$i]);
|
||||
$check = trim($regs[0][$i]);
|
||||
$value = trim($regs[7][$i]);
|
||||
if ($name == $check) {
|
||||
$attributes[strtolower($name)] = strtolower($name);
|
||||
} else {
|
||||
if (!empty($value) && ($value[0] == '\'' || $value[0] == '"')) {
|
||||
$value = substr($value, 1, -1);
|
||||
}
|
||||
$attributes[strtolower($name)] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a valid attribute array from either a string or an array
|
||||
*
|
||||
* @param mixed Array of attributes or HTML attribute string
|
||||
* @return array An associative aray of attributes
|
||||
*/
|
||||
protected static function prepareAttributes($attributes)
|
||||
{
|
||||
$prepared = array();
|
||||
if (is_string($attributes)) {
|
||||
return self::parseAttributes($attributes);
|
||||
|
||||
} elseif (is_array($attributes)) {
|
||||
foreach ($attributes as $key => $value) {
|
||||
if (is_int($key)) {
|
||||
$key = strtolower($value);
|
||||
$prepared[$key] = $key;
|
||||
} else {
|
||||
$prepared[strtolower($key)] = (string)$value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $prepared;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an attribute from an attribute array
|
||||
*
|
||||
* @param array Attribute array
|
||||
* @param string Name of attribute to remove
|
||||
*/
|
||||
protected static function removeAttributeArray(&$attributes, $name)
|
||||
{
|
||||
unset($attributes[strtolower($name)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates HTML attribute string from array
|
||||
*
|
||||
* @param array Attribute array
|
||||
* @return string Attribute string
|
||||
*/
|
||||
protected static function getAttributesString($attributes)
|
||||
{
|
||||
$str = '';
|
||||
if (is_array($attributes)) {
|
||||
$charset = self::getOption('charset');
|
||||
foreach ($attributes as $key => $value) {
|
||||
$str .= ' ' . $key . '="' . htmlspecialchars($value, ENT_QUOTES, $charset) . '"';
|
||||
}
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Class constructor, sets default attributes
|
||||
*
|
||||
* @param mixed Array of attribute 'name' => 'value' pairs or HTML attribute string
|
||||
*/
|
||||
public function __construct($attributes = null)
|
||||
{
|
||||
$this->mergeAttributes($attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the attribute
|
||||
*
|
||||
* @param string Attribute name
|
||||
* @param string Attribute value (will be set to $name if omitted)
|
||||
* @return HTML_Common2
|
||||
*/
|
||||
public function setAttribute($name, $value = null)
|
||||
{
|
||||
$name = strtolower($name);
|
||||
if (is_null($value)) {
|
||||
$value = $name;
|
||||
}
|
||||
if (in_array($name, $this->watchedAttributes)) {
|
||||
$this->onAttributeChange($name, $value);
|
||||
} else {
|
||||
$this->attributes[$name] = (string)$value;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of an attribute
|
||||
*
|
||||
* @param string Attribute name
|
||||
* @return string Attribute value, null if attribute does not exist
|
||||
*/
|
||||
public function getAttribute($name)
|
||||
{
|
||||
$name = strtolower($name);
|
||||
return isset($this->attributes[$name])? $this->attributes[$name]: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the attributes
|
||||
*
|
||||
* @param mixed Array of attribute 'name' => 'value' pairs or HTML attribute string
|
||||
* @return HTML_Common2
|
||||
*/
|
||||
public function setAttributes($attributes)
|
||||
{
|
||||
$attributes = self::prepareAttributes($attributes);
|
||||
$watched = array();
|
||||
foreach ($this->watchedAttributes as $watchedKey) {
|
||||
if (isset($attributes[$watchedKey])) {
|
||||
$this->setAttribute($watchedKey, $attributes[$watchedKey]);
|
||||
unset($attributes[$watchedKey]);
|
||||
} else {
|
||||
$this->removeAttribute($watchedKey);
|
||||
}
|
||||
if (isset($this->attributes[$watchedKey])) {
|
||||
$watched[$watchedKey] = $this->attributes[$watchedKey];
|
||||
}
|
||||
}
|
||||
$this->attributes = array_merge($watched, $attributes);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the attribute array or string
|
||||
*
|
||||
* @param bool Whether to return attributes as string
|
||||
* @return mixed Either an array or string of attributes
|
||||
*/
|
||||
public function getAttributes($asString = false)
|
||||
{
|
||||
if ($asString) {
|
||||
return self::getAttributesString($this->attributes);
|
||||
} else {
|
||||
return $this->attributes;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges the existing attributes with the new ones
|
||||
*
|
||||
* @param mixed Array of attribute 'name' => 'value' pairs or HTML attribute string
|
||||
* @return HTML_Common2
|
||||
*/
|
||||
public function mergeAttributes($attributes)
|
||||
{
|
||||
$attributes = self::prepareAttributes($attributes);
|
||||
foreach ($this->watchedAttributes as $watchedKey) {
|
||||
if (isset($attributes[$watchedKey])) {
|
||||
$this->onAttributeChange($watchedKey, $attributes[$watchedKey]);
|
||||
unset($attributes[$watchedKey]);
|
||||
}
|
||||
}
|
||||
$this->attributes = array_merge($this->attributes, $attributes);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an attribute
|
||||
*
|
||||
* @param string Name of attribute to remove
|
||||
* @return HTML_Common2
|
||||
*/
|
||||
public function removeAttribute($attribute)
|
||||
{
|
||||
if (in_array(strtolower($attribute), $this->watchedAttributes)) {
|
||||
$this->onAttributeChange(strtolower($attribute), null);
|
||||
} else {
|
||||
self::removeAttributeArray($this->attributes, $attribute);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the indentation level
|
||||
*
|
||||
* @param int
|
||||
* @return HTML_Common2
|
||||
*/
|
||||
public function setIndentLevel($level)
|
||||
{
|
||||
$level = intval($level);
|
||||
if (0 <= $level) {
|
||||
$this->_indentLevel = $level;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the indentation level
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getIndentLevel()
|
||||
{
|
||||
return $this->_indentLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the string to indent the element
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getIndent()
|
||||
{
|
||||
return str_repeat(self::getOption('indent'), $this->getIndentLevel());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the comment for the element
|
||||
*
|
||||
* @param string
|
||||
* @return HTML_Common2
|
||||
*/
|
||||
public function setComment($comment)
|
||||
{
|
||||
$this->_comment = $comment;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the comment associated with the element
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getComment()
|
||||
{
|
||||
return $this->_comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the element has given CSS class
|
||||
*
|
||||
* @param string Class name
|
||||
* @return bool
|
||||
*/
|
||||
public function hasClass($class)
|
||||
{
|
||||
$regex = '/(^|\s)' . preg_quote($class, '/') . '(\s|$)/';
|
||||
return (bool)preg_match($regex, $this->getAttribute('class'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the given CSS class(es) to the element
|
||||
*
|
||||
* @param string|array Class name, multiple class names separated by
|
||||
* whitespace, array of class names
|
||||
* @return HTML_Common2
|
||||
*/
|
||||
public function addClass($class)
|
||||
{
|
||||
if (!is_array($class)) {
|
||||
$class = preg_split('/\s+/', $class, null, PREG_SPLIT_NO_EMPTY);
|
||||
}
|
||||
$curClass = preg_split('/\s+/', $this->getAttribute('class'),
|
||||
null, PREG_SPLIT_NO_EMPTY);
|
||||
foreach ($class as $c) {
|
||||
if (!in_array($c, $curClass)) {
|
||||
$curClass[] = $c;
|
||||
}
|
||||
}
|
||||
$this->setAttribute('class', implode(' ', $curClass));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the given CSS class(es) from the element
|
||||
*
|
||||
* @param string|array Class name, multiple class names separated by
|
||||
* whitespace, array of class names
|
||||
* @return HTML_Common2
|
||||
*/
|
||||
public function removeClass($class)
|
||||
{
|
||||
if (!is_array($class)) {
|
||||
$class = preg_split('/\s+/', $class, null, PREG_SPLIT_NO_EMPTY);
|
||||
}
|
||||
$curClass = array_diff(
|
||||
preg_split('/\s+/', $this->getAttribute('class'),
|
||||
null, PREG_SPLIT_NO_EMPTY),
|
||||
$class
|
||||
);
|
||||
if (0 == count($curClass)) {
|
||||
$this->removeAttribute('class');
|
||||
} else {
|
||||
$this->setAttribute('class', implode(' ', $curClass));
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the HTML representation of the element
|
||||
*
|
||||
* This magic method allows using the instances of HTML_Common2 in string
|
||||
* contexts
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract public function __toString();
|
||||
|
||||
/**
|
||||
* Called if trying to change an attribute with name in $watchedAttributes
|
||||
*
|
||||
* This method is called for each attribute whose name is in the
|
||||
* $watchedAttributes array and which is being changed by setAttribute(),
|
||||
* setAttributes() or mergeAttributes() or removed via removeAttribute().
|
||||
* Note that the operation for the attribute is not carried on after calling
|
||||
* this method, it is the responsibility of this method to change or remove
|
||||
* (or not) the attribute.
|
||||
*
|
||||
* @param string Attribute name
|
||||
* @param string Attribute value, null if attribute is being removed
|
||||
*/
|
||||
protected function onAttributeChange($name, $value = null)
|
||||
{
|
||||
}
|
||||
}
|
||||
?>
|
||||
224
www/analytics/libs/HTML/QuickForm2.php
Normal file
224
www/analytics/libs/HTML/QuickForm2.php
Normal file
|
|
@ -0,0 +1,224 @@
|
|||
<?php
|
||||
/**
|
||||
* Class representing a HTML form
|
||||
*
|
||||
* 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: QuickForm2.php 299706 2010-05-24 18:32:37Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstract base class for QuickForm2 containers
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Container.php';
|
||||
|
||||
/**
|
||||
* Data source for HTML_QuickForm2 objects based on superglobal arrays
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/DataSource/SuperGlobal.php';
|
||||
|
||||
/**
|
||||
* Class representing a HTML form
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2 extends HTML_QuickForm2_Container
|
||||
{
|
||||
/**
|
||||
* Data sources providing values for form elements
|
||||
* @var array
|
||||
*/
|
||||
protected $datasources = array();
|
||||
|
||||
/**
|
||||
* We do not allow setting "method" and "id" other than through constructor
|
||||
* @var array
|
||||
*/
|
||||
protected $watchedAttributes = array('id', 'method');
|
||||
|
||||
/**
|
||||
* Class constructor, form's "id" and "method" attributes can only be set here
|
||||
*
|
||||
* @param string "id" attribute of <form> tag
|
||||
* @param string HTTP method used to submit the form
|
||||
* @param mixed Additional attributes (either a string or an array)
|
||||
* @param bool Whether to track if the form was submitted by adding
|
||||
* a special hidden field
|
||||
*/
|
||||
public function __construct($id, $method = 'post', $attributes = null, $trackSubmit = true)
|
||||
{
|
||||
$method = ('GET' == strtoupper($method))? 'get': 'post';
|
||||
if (empty($id)) {
|
||||
$id = self::generateId('');
|
||||
$trackSubmit = false;
|
||||
} else {
|
||||
self::storeId($id);
|
||||
}
|
||||
$this->attributes = array_merge(
|
||||
self::prepareAttributes($attributes),
|
||||
array('id' => (string)$id, 'method' => $method)
|
||||
);
|
||||
if (!isset($this->attributes['action'])) {
|
||||
$this->attributes['action'] = $_SERVER['PHP_SELF'];
|
||||
}
|
||||
if ($trackSubmit && isset($_REQUEST['_qf__' . $id]) ||
|
||||
!$trackSubmit && ('get' == $method && !empty($_GET) ||
|
||||
'post' == $method && (!empty($_POST) || !empty($_FILES))))
|
||||
{
|
||||
$this->addDataSource(new HTML_QuickForm2_DataSource_SuperGlobal(
|
||||
$method, get_magic_quotes_gpc()
|
||||
));
|
||||
}
|
||||
if ($trackSubmit) {
|
||||
$this->appendChild(HTML_QuickForm2_Factory::createElement(
|
||||
'hidden', '_qf__' . $id
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
protected function onAttributeChange($name, $value = null)
|
||||
{
|
||||
throw new HTML_QuickForm2_InvalidArgumentException(
|
||||
'Attribute \'' . $name . '\' is read-only'
|
||||
);
|
||||
}
|
||||
|
||||
protected function setContainer(HTML_QuickForm2_Container $container = null)
|
||||
{
|
||||
throw new HTML_QuickForm2_Exception('Form cannot be added to container');
|
||||
}
|
||||
|
||||
public function setId($id = null)
|
||||
{
|
||||
throw new HTML_QuickForm2_InvalidArgumentException(
|
||||
"Attribute 'id' is read-only"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds a new data source to the form
|
||||
*
|
||||
* @param HTML_QuickForm2_DataSource Data source
|
||||
*/
|
||||
public function addDataSource(HTML_QuickForm2_DataSource $datasource)
|
||||
{
|
||||
$this->datasources[] = $datasource;
|
||||
$this->updateValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces the list of form's data sources with a completely new one
|
||||
*
|
||||
* @param array A new data source list
|
||||
* @throws HTML_QuickForm2_InvalidArgumentException if given array
|
||||
* contains something that is not a valid data source
|
||||
*/
|
||||
public function setDataSources(array $datasources)
|
||||
{
|
||||
foreach ($datasources as $ds) {
|
||||
if (!$ds instanceof HTML_QuickForm2_DataSource) {
|
||||
throw new HTML_QuickForm2_InvalidArgumentException(
|
||||
'Array should contain only DataSource instances'
|
||||
);
|
||||
}
|
||||
}
|
||||
$this->datasources = $datasources;
|
||||
$this->updateValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of data sources attached to the form
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDataSources()
|
||||
{
|
||||
return $this->datasources;
|
||||
}
|
||||
|
||||
public function getType()
|
||||
{
|
||||
return 'form';
|
||||
}
|
||||
|
||||
public function setValue($value)
|
||||
{
|
||||
throw new HTML_QuickForm2_Exception('Not implemented');
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the server-side validation
|
||||
*
|
||||
* @return boolean Whether all form's elements are valid
|
||||
*/
|
||||
public function validate()
|
||||
{
|
||||
$isSubmitted = false;
|
||||
foreach ($this->datasources as $ds) {
|
||||
if ($ds instanceof HTML_QuickForm2_DataSource_Submit) {
|
||||
$isSubmitted = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $isSubmitted? parent::validate(): false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the form using the given renderer
|
||||
*
|
||||
* @param HTML_QuickForm2_Renderer Renderer instance
|
||||
* @return HTML_QuickForm2_Renderer
|
||||
*/
|
||||
public function render(HTML_QuickForm2_Renderer $renderer)
|
||||
{
|
||||
$renderer->startForm($this);
|
||||
$renderer->getJavascriptBuilder()->startForm($this);
|
||||
foreach ($this as $element) {
|
||||
$element->render($renderer);
|
||||
}
|
||||
$renderer->finishForm($this);
|
||||
return $renderer;
|
||||
}
|
||||
}
|
||||
?>
|
||||
487
www/analytics/libs/HTML/QuickForm2/Container.php
Normal file
487
www/analytics/libs/HTML/QuickForm2/Container.php
Normal file
|
|
@ -0,0 +1,487 @@
|
|||
<?php
|
||||
/**
|
||||
* Base class for simple HTML_QuickForm2 containers
|
||||
*
|
||||
* 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: Container.php 300722 2010-06-24 10:15:52Z mansion $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for all HTML_QuickForm2 elements
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Node.php';
|
||||
|
||||
/**
|
||||
* Abstract base class for simple QuickForm2 containers
|
||||
*
|
||||
* @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_Container extends HTML_QuickForm2_Node
|
||||
implements IteratorAggregate, Countable
|
||||
{
|
||||
/**
|
||||
* Array of elements contained in this container
|
||||
* @var array
|
||||
*/
|
||||
protected $elements = array();
|
||||
|
||||
|
||||
public function setName($name)
|
||||
{
|
||||
$this->attributes['name'] = (string)$name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function toggleFrozen($freeze = null)
|
||||
{
|
||||
if (null !== $freeze) {
|
||||
foreach ($this as $child) {
|
||||
$child->toggleFrozen($freeze);
|
||||
}
|
||||
}
|
||||
return parent::toggleFrozen($freeze);
|
||||
}
|
||||
|
||||
public function persistentFreeze($persistent = null)
|
||||
{
|
||||
if (null !== $persistent) {
|
||||
foreach ($this as $child) {
|
||||
$child->persistentFreeze($persistent);
|
||||
}
|
||||
}
|
||||
return parent::persistentFreeze($persistent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether container prepends its name to names of contained elements
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function prependsName()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the element's value
|
||||
*
|
||||
* The default implementation for Containers is to return an array with
|
||||
* contained elements' values. The array is indexed the same way $_GET and
|
||||
* $_POST arrays would be for these elements.
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
$values = array();
|
||||
foreach ($this as $child) {
|
||||
$value = $child->getValue();
|
||||
if (null !== $value) {
|
||||
if ($child instanceof HTML_QuickForm2_Container
|
||||
&& !$child->prependsName()
|
||||
) {
|
||||
$values = self::arrayMerge($values, $value);
|
||||
} else {
|
||||
$name = $child->getName();
|
||||
if (!strpos($name, '[')) {
|
||||
$values[$name] = $value;
|
||||
} else {
|
||||
$tokens = explode('[', str_replace(']', '', $name));
|
||||
$valueAry =& $values;
|
||||
do {
|
||||
$token = array_shift($tokens);
|
||||
if (!isset($valueAry[$token])) {
|
||||
$valueAry[$token] = array();
|
||||
}
|
||||
$valueAry =& $valueAry[$token];
|
||||
} while (count($tokens) > 1);
|
||||
$valueAry[$tokens[0]] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return empty($values)? null: $this->applyFilters($values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges two arrays
|
||||
*
|
||||
* Merges two arrays like the PHP function array_merge_recursive does,
|
||||
* the difference being that existing integer keys will not be renumbered.
|
||||
*
|
||||
* @param array
|
||||
* @param array
|
||||
* @return array resulting array
|
||||
*/
|
||||
protected static function arrayMerge($a, $b)
|
||||
{
|
||||
foreach ($b as $k => $v) {
|
||||
if (!is_array($v) || isset($a[$k]) && !is_array($a[$k])) {
|
||||
$a[$k] = $v;
|
||||
} else {
|
||||
$a[$k] = self::arrayMerge(isset($a[$k])? $a[$k]: array(), $v);
|
||||
}
|
||||
}
|
||||
return $a;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of this container's elements
|
||||
*
|
||||
* @return array Container elements
|
||||
*/
|
||||
public function getElements()
|
||||
{
|
||||
return $this->elements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends an element to the container
|
||||
*
|
||||
* If the element was previously added to the container or to another
|
||||
* container, it is first removed there.
|
||||
*
|
||||
* @param HTML_QuickForm2_Node Element to add
|
||||
* @return HTML_QuickForm2_Node Added element
|
||||
* @throws HTML_QuickForm2_InvalidArgumentException
|
||||
*/
|
||||
public function appendChild(HTML_QuickForm2_Node $element)
|
||||
{
|
||||
if ($this === $element->getContainer()) {
|
||||
$this->removeChild($element);
|
||||
}
|
||||
$element->setContainer($this);
|
||||
$this->elements[] = $element;
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends an element to the container (possibly creating it first)
|
||||
*
|
||||
* If the first parameter is an instance of HTML_QuickForm2_Node then all
|
||||
* other parameters are ignored and the method just calls {@link appendChild()}.
|
||||
* In the other case the element is first created via
|
||||
* {@link HTML_QuickForm2_Factory::createElement()} and then added via the
|
||||
* same method. This is a convenience method to reduce typing and ease
|
||||
* porting from HTML_QuickForm.
|
||||
*
|
||||
* @param string|HTML_QuickForm2_Node Either type name (treated
|
||||
* case-insensitively) or an element instance
|
||||
* @param mixed Element name
|
||||
* @param mixed Element attributes
|
||||
* @param array Element-specific data
|
||||
* @return HTML_QuickForm2_Node Added element
|
||||
* @throws HTML_QuickForm2_InvalidArgumentException
|
||||
* @throws HTML_QuickForm2_NotFoundException
|
||||
*/
|
||||
public function addElement($elementOrType, $name = null, $attributes = null,
|
||||
array $data = array())
|
||||
{
|
||||
if ($elementOrType instanceof HTML_QuickForm2_Node) {
|
||||
return $this->appendChild($elementOrType);
|
||||
} else {
|
||||
return $this->appendChild(HTML_QuickForm2_Factory::createElement(
|
||||
$elementOrType, $name, $attributes, $data
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the element from this container
|
||||
*
|
||||
* If the reference object is not given, the element will be appended.
|
||||
*
|
||||
* @param HTML_QuickForm2_Node Element to remove
|
||||
* @return HTML_QuickForm2_Node Removed object
|
||||
*/
|
||||
public function removeChild(HTML_QuickForm2_Node $element)
|
||||
{
|
||||
|
||||
if ($element->getContainer() !== $this) {
|
||||
throw new HTML_QuickForm2_NotFoundException(
|
||||
"Element with name '".$element->getName()."' was not found"
|
||||
);
|
||||
}
|
||||
foreach ($this as $key => $child){
|
||||
if ($child === $element) {
|
||||
unset($this->elements[$key]);
|
||||
$element->setContainer(null);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $element;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns an element if its id is found
|
||||
*
|
||||
* @param string Element id to find
|
||||
* @return HTML_QuickForm2_Node|null
|
||||
*/
|
||||
public function getElementById($id)
|
||||
{
|
||||
foreach ($this->getRecursiveIterator() as $element) {
|
||||
if ($id == $element->getId()) {
|
||||
return $element;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of elements which name corresponds to element
|
||||
*
|
||||
* @param string Elements name to find
|
||||
* @return array
|
||||
*/
|
||||
public function getElementsByName($name)
|
||||
{
|
||||
$found = array();
|
||||
foreach ($this->getRecursiveIterator() as $element) {
|
||||
if ($element->getName() == $name) {
|
||||
$found[] = $element;
|
||||
}
|
||||
}
|
||||
return $found;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts an element in the container
|
||||
*
|
||||
* If the reference object is not given, the element will be appended.
|
||||
*
|
||||
* @param HTML_QuickForm2_Node Element to insert
|
||||
* @param HTML_QuickForm2_Node Reference to insert before
|
||||
* @return HTML_QuickForm2_Node Inserted element
|
||||
*/
|
||||
public function insertBefore(HTML_QuickForm2_Node $element, HTML_QuickForm2_Node $reference = null)
|
||||
{
|
||||
if (null === $reference) {
|
||||
return $this->appendChild($element);
|
||||
}
|
||||
$offset = 0;
|
||||
foreach ($this as $child) {
|
||||
if ($child === $reference) {
|
||||
if ($this === $element->getContainer()) {
|
||||
$this->removeChild($element);
|
||||
}
|
||||
$element->setContainer($this);
|
||||
array_splice($this->elements, $offset, 0, array($element));
|
||||
return $element;
|
||||
}
|
||||
$offset++;
|
||||
}
|
||||
throw new HTML_QuickForm2_NotFoundException(
|
||||
"Reference element with name '".$reference->getName()."' was not found"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a recursive iterator for the container elements
|
||||
*
|
||||
* @return HTML_QuickForm2_ContainerIterator
|
||||
*/
|
||||
public function getIterator()
|
||||
{
|
||||
return new HTML_QuickForm2_ContainerIterator($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a recursive iterator iterator for the container elements
|
||||
*
|
||||
* @param int mode passed to RecursiveIteratorIterator
|
||||
* @return RecursiveIteratorIterator
|
||||
*/
|
||||
public function getRecursiveIterator($mode = RecursiveIteratorIterator::SELF_FIRST)
|
||||
{
|
||||
return new RecursiveIteratorIterator(
|
||||
new HTML_QuickForm2_ContainerIterator($this), $mode
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of elements in the container
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return count($this->elements);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the element needs to update its value from form's data sources
|
||||
*
|
||||
* The default behaviour is just to call the updateValue() methods of
|
||||
* contained elements, since default Container doesn't have any value itself
|
||||
*/
|
||||
public function updateValue()
|
||||
{
|
||||
foreach ($this as $child) {
|
||||
$child->updateValue();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Performs the server-side validation
|
||||
*
|
||||
* This method also calls validate() on all contained elements.
|
||||
*
|
||||
* @return boolean Whether the container and all contained elements are valid
|
||||
*/
|
||||
protected function validate()
|
||||
{
|
||||
$valid = parent::validate();
|
||||
foreach ($this as $child) {
|
||||
$valid = $child->validate() && $valid;
|
||||
}
|
||||
return $valid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends an element to the container, creating it first
|
||||
*
|
||||
* The element will be created via {@link HTML_QuickForm2_Factory::createElement()}
|
||||
* and then added via the {@link appendChild()} method.
|
||||
* The element type is deduced from the method name.
|
||||
* This is a convenience method to reduce typing.
|
||||
*
|
||||
* @param mixed Element name
|
||||
* @param mixed Element attributes
|
||||
* @param array Element-specific data
|
||||
* @return HTML_QuickForm2_Node Added element
|
||||
* @throws HTML_QuickForm2_InvalidArgumentException
|
||||
* @throws HTML_QuickForm2_NotFoundException
|
||||
*/
|
||||
public function __call($m, $a)
|
||||
{
|
||||
if (preg_match('/^(add)([a-zA-Z0-9_]+)$/', $m, $match)) {
|
||||
if ($match[1] == 'add') {
|
||||
$type = strtolower($match[2]);
|
||||
$name = isset($a[0]) ? $a[0] : null;
|
||||
$attr = isset($a[1]) ? $a[1] : null;
|
||||
$data = isset($a[2]) ? $a[2] : array();
|
||||
return $this->addElement($type, $name, $attr, $data);
|
||||
}
|
||||
}
|
||||
trigger_error("Fatal error: Call to undefined method ".get_class($this)."::".$m."()", E_USER_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the container using the given renderer
|
||||
*
|
||||
* @param HTML_QuickForm2_Renderer Renderer instance
|
||||
* @return HTML_QuickForm2_Renderer
|
||||
*/
|
||||
public function render(HTML_QuickForm2_Renderer $renderer)
|
||||
{
|
||||
foreach ($this->rules as $rule) {
|
||||
if ($rule[1] & HTML_QuickForm2_Rule::RUNAT_CLIENT) {
|
||||
$renderer->getJavascriptBuilder()->addRule($rule[0]);
|
||||
}
|
||||
}
|
||||
$renderer->startContainer($this);
|
||||
foreach ($this as $element) {
|
||||
$element->render($renderer);
|
||||
}
|
||||
$renderer->finishContainer($this);
|
||||
return $renderer;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
// require_once 'HTML/QuickForm2/Renderer.php';
|
||||
|
||||
return $this->render(HTML_QuickForm2_Renderer::factory('default'))->__toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Javascript code for getting the element's value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getJavascriptValue()
|
||||
{
|
||||
$args = array();
|
||||
foreach ($this as $child) {
|
||||
if ($child instanceof HTML_QuickForm2_Container) {
|
||||
$args[] = $child->getJavascriptValue();
|
||||
} else {
|
||||
$args[] = "'" . $child->getId() . "'";
|
||||
}
|
||||
}
|
||||
return 'qf.form.getContainerValue(' . implode(', ', $args) . ')';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements a recursive iterator for the container elements
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_ContainerIterator extends RecursiveArrayIterator implements RecursiveIterator
|
||||
{
|
||||
public function __construct(HTML_QuickForm2_Container $container)
|
||||
{
|
||||
parent::__construct($container->getElements());
|
||||
}
|
||||
|
||||
public function hasChildren()
|
||||
{
|
||||
return $this->current() instanceof HTML_QuickForm2_Container;
|
||||
}
|
||||
|
||||
public function getChildren()
|
||||
{
|
||||
return new HTML_QuickForm2_ContainerIterator($this->current());
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
92
www/analytics/libs/HTML/QuickForm2/Container/Fieldset.php
Normal file
92
www/analytics/libs/HTML/QuickForm2/Container/Fieldset.php
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
<?php
|
||||
/**
|
||||
* Base class for fieldsets
|
||||
*
|
||||
* 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: Fieldset.php 294052 2010-01-26 20:00:22Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for fieldsets
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Container.php';
|
||||
|
||||
/**
|
||||
* Concrete implementation of a container for fieldsets
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Container_Fieldset extends HTML_QuickForm2_Container
|
||||
{
|
||||
/**
|
||||
* Fieldsets don't have a 'name' attribute, so we only handle 'id'
|
||||
* @var array
|
||||
*/
|
||||
protected $watchedAttributes = array('id');
|
||||
|
||||
public function getType()
|
||||
{
|
||||
return 'fieldset';
|
||||
}
|
||||
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public function setName($name)
|
||||
{
|
||||
// Fieldsets do not have a name attribute
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
public function setValue($value)
|
||||
{
|
||||
throw new HTML_QuickForm2_Exception('Not implemented');
|
||||
}
|
||||
}
|
||||
?>
|
||||
328
www/analytics/libs/HTML/QuickForm2/Container/Group.php
Normal file
328
www/analytics/libs/HTML/QuickForm2/Container/Group.php
Normal file
|
|
@ -0,0 +1,328 @@
|
|||
<?php
|
||||
/**
|
||||
* Base class for HTML_QuickForm2 groups
|
||||
*
|
||||
* 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: Group.php 294057 2010-01-26 21:10:28Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for all HTML_QuickForm2 containers
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Container.php';
|
||||
|
||||
/**
|
||||
* Base class for QuickForm2 groups of elements
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Container_Group extends HTML_QuickForm2_Container
|
||||
{
|
||||
/**
|
||||
* Group name
|
||||
* If set, group name will be used as prefix for contained
|
||||
* element names, like groupname[elementname].
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Previous group name
|
||||
* Stores the previous group name when the group name is changed.
|
||||
* Used to restore children names if necessary.
|
||||
* @var string
|
||||
*/
|
||||
protected $previousName;
|
||||
|
||||
public function getType()
|
||||
{
|
||||
return 'group';
|
||||
}
|
||||
|
||||
protected function prependsName()
|
||||
{
|
||||
return strlen($this->name) > 0;
|
||||
}
|
||||
|
||||
public function getValue()
|
||||
{
|
||||
$value = parent::getValue();
|
||||
if (!$this->prependsName()) {
|
||||
return $value;
|
||||
|
||||
} elseif (!strpos($this->getName(), '[')) {
|
||||
return isset($value[$this->getName()])? $value[$this->getName()]: null;
|
||||
|
||||
} else {
|
||||
$tokens = explode('[', str_replace(']', '', $this->getName()));
|
||||
$valueAry =& $value;
|
||||
do {
|
||||
$token = array_shift($tokens);
|
||||
if (!isset($valueAry[$token])) {
|
||||
return null;
|
||||
}
|
||||
$valueAry =& $valueAry[$token];
|
||||
} while ($tokens);
|
||||
return $valueAry;
|
||||
}
|
||||
}
|
||||
|
||||
public function setValue($value)
|
||||
{
|
||||
// Prepare a mapper for element names as array
|
||||
|
||||
if ($this->prependsName()) {
|
||||
$prefix = explode('[', str_replace(']', '', $this->getName()));
|
||||
}
|
||||
|
||||
$elements = array();
|
||||
foreach ($this as $child) {
|
||||
$tokens = explode('[', str_replace(']', '', $child->getName()));
|
||||
if (!empty($prefix)) {
|
||||
$tokens = array_slice($tokens, count($prefix));
|
||||
}
|
||||
$elements[] = $tokens;
|
||||
}
|
||||
|
||||
// Iterate over values to find corresponding element
|
||||
|
||||
$index = 0;
|
||||
|
||||
foreach ($value as $k => $v) {
|
||||
$val = array($k => $v);
|
||||
$found = null;
|
||||
foreach ($elements as $i => $tokens) {
|
||||
do {
|
||||
$token = array_shift($tokens);
|
||||
$numeric = false;
|
||||
if ($token == "") {
|
||||
// Deal with numeric indexes in values
|
||||
$token = $index;
|
||||
$numeric = true;
|
||||
}
|
||||
if (isset($val[$token])) {
|
||||
// Found a value
|
||||
$val = $val[$token];
|
||||
$found = $val;
|
||||
if ($numeric) {
|
||||
$index += 1;
|
||||
}
|
||||
} else {
|
||||
// Not found, skip next iterations
|
||||
$found = null;
|
||||
break;
|
||||
}
|
||||
|
||||
} while (!empty($tokens));
|
||||
|
||||
if (!is_null($found)) {
|
||||
// Found a value corresponding to element name
|
||||
$child = $this->elements[$i];
|
||||
$child->setValue($val);
|
||||
unset($val);
|
||||
if (!($child instanceof HTML_QuickForm2_Container_Group)) {
|
||||
// Speed up next iterations
|
||||
unset($elements[$i]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setName($name)
|
||||
{
|
||||
$this->previousName = $this->name;
|
||||
$this->name = $name;
|
||||
foreach ($this as $child) {
|
||||
$this->renameChild($child);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function renameChild(HTML_QuickForm2_Node $element)
|
||||
{
|
||||
$tokens = explode('[', str_replace(']', '', $element->getName()));
|
||||
if ($this === $element->getContainer()) {
|
||||
// Child has already been renamed by its group before
|
||||
if (!is_null($this->previousName) &&
|
||||
$this->previousName !== '') {
|
||||
$gtokens = explode('[', str_replace(']', '', $this->previousName));
|
||||
$pos = array_search(end($gtokens), $tokens);
|
||||
if (!is_null($pos)) {
|
||||
$tokens = array_slice($tokens, $pos+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (is_null($this->name) || $this->name === '') {
|
||||
if (is_null($this->previousName) || $this->previousName === '') {
|
||||
return $element;
|
||||
} else {
|
||||
$elname = $tokens[0];
|
||||
unset($tokens[0]);
|
||||
foreach ($tokens as $v) {
|
||||
$elname .= '['.$v.']';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$elname = $this->getName().'['.implode('][', $tokens).']';
|
||||
}
|
||||
$element->setName($elname);
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends an element to the container
|
||||
*
|
||||
* If the element was previously added to the container or to another
|
||||
* container, it is first removed there.
|
||||
*
|
||||
* @param HTML_QuickForm2_Node Element to add
|
||||
* @return HTML_QuickForm2_Node Added element
|
||||
* @throws HTML_QuickForm2_InvalidArgumentException
|
||||
*/
|
||||
public function appendChild(HTML_QuickForm2_Node $element)
|
||||
{
|
||||
if (null !== ($container = $element->getContainer())) {
|
||||
$container->removeChild($element);
|
||||
}
|
||||
// Element can be renamed only after being removed from container
|
||||
$this->renameChild($element);
|
||||
|
||||
$element->setContainer($this);
|
||||
$this->elements[] = $element;
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the element from this container
|
||||
*
|
||||
* If the reference object is not given, the element will be appended.
|
||||
*
|
||||
* @param HTML_QuickForm2_Node Element to remove
|
||||
* @return HTML_QuickForm2_Node Removed object
|
||||
*/
|
||||
public function removeChild(HTML_QuickForm2_Node $element)
|
||||
{
|
||||
$element = parent::removeChild($element);
|
||||
if ($this->prependsName()) {
|
||||
$name = preg_replace('/^' . $this->getName() . '\[([^\]]*)\]/', '\1', $element->getName());
|
||||
$element->setName($name);
|
||||
}
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts an element in the container
|
||||
*
|
||||
* If the reference object is not given, the element will be appended.
|
||||
*
|
||||
* @param HTML_QuickForm2_Node Element to insert
|
||||
* @param HTML_QuickForm2_Node Reference to insert before
|
||||
* @return HTML_QuickForm2_Node Inserted element
|
||||
*/
|
||||
public function insertBefore(HTML_QuickForm2_Node $element, HTML_QuickForm2_Node $reference = null)
|
||||
{
|
||||
if (null === $reference) {
|
||||
return $this->appendChild($element);
|
||||
}
|
||||
return parent::insertBefore($this->renameChild($element), $reference);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets string(s) to separate grouped elements
|
||||
*
|
||||
* @param string|array Use a string for one separator, array for
|
||||
* alternating separators
|
||||
* @return HTML_QuickForm2_Container_Group
|
||||
*/
|
||||
public function setSeparator($separator)
|
||||
{
|
||||
$this->data['separator'] = $separator;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns string(s) to separate grouped elements
|
||||
*
|
||||
* @return string|array Separator, null if not set
|
||||
*/
|
||||
public function getSeparator()
|
||||
{
|
||||
return isset($this->data['separator'])? $this->data['separator']: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the group using the given renderer
|
||||
*
|
||||
* @param HTML_QuickForm2_Renderer Renderer instance
|
||||
* @return HTML_QuickForm2_Renderer
|
||||
*/
|
||||
public function render(HTML_QuickForm2_Renderer $renderer)
|
||||
{
|
||||
$renderer->startGroup($this);
|
||||
foreach ($this as $element) {
|
||||
$element->render($renderer);
|
||||
}
|
||||
$renderer->finishGroup($this);
|
||||
return $renderer;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
// require_once 'HTML/QuickForm2/Renderer.php';
|
||||
|
||||
return $this->render(
|
||||
HTML_QuickForm2_Renderer::factory('default')
|
||||
->setTemplateForId($this->getId(), '{content}')
|
||||
)->__toString();
|
||||
}
|
||||
}
|
||||
?>
|
||||
508
www/analytics/libs/HTML/QuickForm2/Controller.php
Normal file
508
www/analytics/libs/HTML/QuickForm2/Controller.php
Normal file
|
|
@ -0,0 +1,508 @@
|
|||
<?php
|
||||
/**
|
||||
* Class implementing the Page Controller pattern for multipage forms
|
||||
*
|
||||
* 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: Controller.php 295963 2010-03-08 14:33:43Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/** The class representing a page of a multipage form */
|
||||
// require_once 'HTML/QuickForm2/Controller/Page.php';
|
||||
|
||||
/** Object wrapping around session variable used to store controller data */
|
||||
// require_once 'HTML/QuickForm2/Controller/SessionContainer.php';
|
||||
|
||||
/** Class presenting the values stored in session by Controller as submitted ones */
|
||||
// require_once 'HTML/QuickForm2/DataSource/Session.php';
|
||||
|
||||
/**
|
||||
* Class implementing the Page Controller pattern for multipage forms
|
||||
*
|
||||
* This class keeps track of pages and (default) action handlers for the form,
|
||||
* it manages $_SESSION container for the form values, allows setting
|
||||
* DataSources for the form as a whole and getting its value.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Controller implements IteratorAggregate
|
||||
{
|
||||
/**
|
||||
* Key in $_REQUEST array that contains the ID of the Controller
|
||||
*/
|
||||
const KEY_ID = '_qfc_id';
|
||||
|
||||
/**
|
||||
* Key in $_SESSION array that contains the Controller data (needs ID substituted via sprintf())
|
||||
*/
|
||||
const KEY_CONTAINER = '_%s_container';
|
||||
|
||||
/**
|
||||
* Whether the form is a wizard
|
||||
* @var boolean
|
||||
*/
|
||||
protected $wizard = true;
|
||||
|
||||
/**
|
||||
* Whether Controller ID should be sent in GET and POST parameters
|
||||
* @var boolean
|
||||
*/
|
||||
protected $propagate = true;
|
||||
|
||||
/**
|
||||
* Controller ID
|
||||
* @var string
|
||||
*/
|
||||
protected $id = null;
|
||||
|
||||
/**
|
||||
* Contains the pages (instances of HTML_QuickForm2_Controller_Page) of the multipage form
|
||||
* @var array
|
||||
*/
|
||||
protected $pages = array();
|
||||
|
||||
/**
|
||||
* Contains the mapping of action names to handlers (objects implementing HTML_QuickForm2_Controller_Action)
|
||||
* @var array
|
||||
*/
|
||||
protected $handlers = array();
|
||||
|
||||
/**
|
||||
* The action extracted from HTTP request: array('page', 'action')
|
||||
* @var array
|
||||
*/
|
||||
protected $actionName = null;
|
||||
|
||||
/**
|
||||
* A wrapper around session variable used to store form data
|
||||
* @var HTML_QuickForm2_Controller_SessionContainer
|
||||
*/
|
||||
protected $sessionContainer = null;
|
||||
|
||||
/**
|
||||
* Finds a controller name in $_REQUEST
|
||||
*
|
||||
* @return string|null Returns nulle if either a KEY_ID is not present
|
||||
* in $_REQUEST or KEY_CONTAINER is not present in
|
||||
* $_SESSION
|
||||
*/
|
||||
public static function findControllerID()
|
||||
{
|
||||
if (empty($_REQUEST[self::KEY_ID])
|
||||
|| empty($_SESSION[sprintf(self::KEY_CONTAINER, $_REQUEST[self::KEY_ID])])
|
||||
) {
|
||||
return null;
|
||||
} else {
|
||||
return $_REQUEST[self::KEY_ID];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* Sets the form ID, whether to send this ID in POST and GET parameters,
|
||||
* wizard / non-wizard behaviour.
|
||||
*
|
||||
* Different forms should be given different IDs, as they are used to store
|
||||
* values in session. If $id is empty, the controller will try to find it
|
||||
* in $_REQUEST, throwing the exception if this fails.
|
||||
*
|
||||
* Wizard forms only allow going to the next page if all the previous ones
|
||||
* are valid.
|
||||
*
|
||||
* @param string Form ID
|
||||
* @param boolean Whether the form is a wizard
|
||||
* @param boolean Whether form's ID should be sent with GET and POST parameters
|
||||
* @throws HTML_QuickForm2_NotFoundException if ID is not given and cannot
|
||||
* be found in $_REQUEST, or session container is empty
|
||||
*/
|
||||
public function __construct($id = null, $wizard = true, $propagateId = false)
|
||||
{
|
||||
if (empty($id)) {
|
||||
$propagateId = true;
|
||||
$id = self::findControllerID();
|
||||
}
|
||||
if (empty($id)) {
|
||||
throw new HTML_QuickForm2_NotFoundException(
|
||||
'Controller ID not available in $_REQUEST or session ' .
|
||||
'container is empty, please provide ID to constructor'
|
||||
);
|
||||
}
|
||||
$this->id = $id;
|
||||
$this->wizard = (bool)$wizard;
|
||||
$this->propagate = (bool)$propagateId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the form is a wizard
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isWizard()
|
||||
{
|
||||
return $this->wizard;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the form ID
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether to send form id with GET and POST parameters
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function propagateId()
|
||||
{
|
||||
return $this->propagate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the session container with the controller data
|
||||
*
|
||||
* @return HTML_QuickForm2_Controller_SessionContainer
|
||||
*/
|
||||
public function getSessionContainer()
|
||||
{
|
||||
if (empty($this->sessionContainer)) {
|
||||
$this->sessionContainer = new HTML_QuickForm2_Controller_SessionContainer($this);
|
||||
}
|
||||
return $this->sessionContainer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the session variable containing the controller data
|
||||
*/
|
||||
public function destroySessionContainer()
|
||||
{
|
||||
unset($_SESSION[sprintf(self::KEY_CONTAINER, $this->id)]);
|
||||
$this->sessionContainer = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the name of the page and the action to perform with it from HTTP request data
|
||||
*
|
||||
* @return array first element is page name, second is action name
|
||||
*/
|
||||
public function getActionName()
|
||||
{
|
||||
if (is_array($this->actionName)) {
|
||||
return $this->actionName;
|
||||
}
|
||||
if (empty($this->pages)) {
|
||||
throw new HTML_QuickForm2_NotFoundException('No pages added to the form');
|
||||
}
|
||||
$names = array_map('preg_quote', array_keys($this->pages));
|
||||
$regex = '/^_qf_(' . implode('|', $names) . ')_(.+?)(_x)?$/';
|
||||
foreach (array_keys($_REQUEST) as $key) {
|
||||
if (preg_match($regex, $key, $matches)) {
|
||||
$this->actionName = array($matches[1], $matches[2]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!is_array($this->actionName)) {
|
||||
reset($this->pages);
|
||||
$this->actionName = array(key($this->pages), 'display');
|
||||
}
|
||||
return $this->actionName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the request
|
||||
*
|
||||
* This finds the page, the action to perform with it and passes the action
|
||||
* to the page's handle() method.
|
||||
*
|
||||
* @throws HTML_QuickForm2_Exception
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
list($page, $action) = $this->getActionName();
|
||||
return $this->pages[$page]->handle($action);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a handler for a specific action
|
||||
*
|
||||
* @param string action name
|
||||
* @param HTML_QuickForm2_Controller_Action the handler for the action
|
||||
*/
|
||||
public function addHandler($actionName, HTML_QuickForm2_Controller_Action $action)
|
||||
{
|
||||
$this->handlers[$actionName] = $action;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles an action
|
||||
*
|
||||
* This will be called if the page itself does not have a handler for a
|
||||
* specific action. The method also loads and uses default handlers for
|
||||
* common actions, if specific ones were not added.
|
||||
*
|
||||
* @param HTML_QuickForm2_Controller_Page form page
|
||||
* @param string action name
|
||||
* @throws HTML_QuickForm2_NotFoundException if handler for an action is missing
|
||||
*/
|
||||
public function handle(HTML_QuickForm2_Controller_Page $page, $actionName)
|
||||
{
|
||||
if (!isset($this->handlers[$actionName])
|
||||
&& in_array($actionName, array('next', 'back', 'submit', 'display', 'jump'))
|
||||
) {
|
||||
$className = 'HTML_QuickForm2_Controller_Action_' . ucfirst($actionName);
|
||||
if (!class_exists($className)) {
|
||||
HTML_QuickForm2_Loader::loadClass($className);
|
||||
}
|
||||
$this->addHandler($actionName, new $className());
|
||||
}
|
||||
if (isset($this->handlers[$actionName])) {
|
||||
return $this->handlers[$actionName]->perform($page, $actionName);
|
||||
} else {
|
||||
throw new HTML_QuickForm2_NotFoundException(
|
||||
"Unhandled action '{$actionName}' for page '{$page->getForm()->getId()}'"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new page to the form
|
||||
*
|
||||
* @param HTML_QuickForm2_Controller_Page
|
||||
*/
|
||||
public function addPage(HTML_QuickForm2_Controller_Page $page)
|
||||
{
|
||||
$pageId = $page->getForm()->getId();
|
||||
if (!empty($this->pages[$pageId])) {
|
||||
throw new HTML_QuickForm2_InvalidArgumentException(
|
||||
"Duplicate page ID '{$pageId}'"
|
||||
);
|
||||
}
|
||||
$page->setController($this);
|
||||
$this->pages[$pageId] = $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a page
|
||||
*
|
||||
* @param string Page ID
|
||||
* @return HTML_QuickForm2_Controller_Page
|
||||
* @throws HTML_QuickForm2_NotFoundException if there is no page with
|
||||
* the given ID
|
||||
*/
|
||||
public function getPage($pageId)
|
||||
{
|
||||
if (!empty($this->pages[$pageId])) {
|
||||
return $this->pages[$pageId];
|
||||
} else {
|
||||
throw new HTML_QuickForm2_NotFoundException(
|
||||
"Unknown page '{$pageId}'"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the page preceding the given one
|
||||
*
|
||||
* @param HTML_QuickForm2_Controller_Page
|
||||
* @return HTML_QuickForm2_Controller_Page|null
|
||||
*/
|
||||
public function previousPage(HTML_QuickForm2_Controller_Page $reference)
|
||||
{
|
||||
$previous = null;
|
||||
foreach ($this->pages as $page) {
|
||||
if ($page === $reference) {
|
||||
return $previous;
|
||||
}
|
||||
$previous = $page;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the page following the given one
|
||||
*
|
||||
* @param HTML_QuickForm2_Controller_Page
|
||||
* @return HTML_QuickForm2_Controller_Page|null
|
||||
*/
|
||||
public function nextPage(HTML_QuickForm2_Controller_Page $reference)
|
||||
{
|
||||
$previous = null;
|
||||
foreach ($this->pages as $page) {
|
||||
if ($previous === $reference) {
|
||||
return $page;
|
||||
}
|
||||
$previous = $page;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the pages of the controller are valid
|
||||
*
|
||||
* @param HTML_QuickForm2_Controller_Page If given, check only the pages
|
||||
* before (not including) that page
|
||||
* @return bool
|
||||
*/
|
||||
public function isValid(HTML_QuickForm2_Controller_Page $reference = null)
|
||||
{
|
||||
$container = $this->getSessionContainer();
|
||||
foreach ($this->pages as $id => $page) {
|
||||
if ($reference === $page) {
|
||||
return true;
|
||||
}
|
||||
if (!$container->getValidationStatus($id)) {
|
||||
// We should handle the possible situation when the user has never
|
||||
// seen a page of a non-modal multipage form
|
||||
if (!$this->isWizard()
|
||||
&& null === $container->getValidationStatus($id)
|
||||
) {
|
||||
// Empty Session datasource makes the form look submitted
|
||||
$page->getForm()->setDatasources(array_merge(
|
||||
$container->getDatasources(),
|
||||
array(new HTML_QuickForm2_DataSource_Session(array()))
|
||||
));
|
||||
// This will store the "submitted" values in session and
|
||||
// return validation status
|
||||
if ($page->storeValues()) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first page that failed validation
|
||||
*
|
||||
* @return HTML_QuickForm2_Controller_Page|null
|
||||
*/
|
||||
public function getFirstInvalidPage()
|
||||
{
|
||||
foreach ($this->pages as $id => $page) {
|
||||
if (!$this->getSessionContainer()->getValidationStatus($id)) {
|
||||
return $page;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new data source to the Controller
|
||||
*
|
||||
* Note that Controller data sources are stored in session, so your data source
|
||||
* implementation should properly handle its (un)serialization.
|
||||
*
|
||||
* @param HTML_QuickForm2_DataSource Data source
|
||||
*/
|
||||
public function addDataSource(HTML_QuickForm2_DataSource $datasource)
|
||||
{
|
||||
$this->getSessionContainer()->storeDatasources(
|
||||
array_merge($this->getSessionContainer()->getDatasources(),
|
||||
array($datasource))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the form's values
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
$values = array();
|
||||
foreach (array_keys($this->pages) as $id) {
|
||||
$pageValues = $this->getSessionContainer()->getValues($id);
|
||||
// skip elements representing actions
|
||||
foreach ($pageValues as $key => $value) {
|
||||
if (0 !== strpos($key, '_qf')) {
|
||||
if (isset($values[$key]) && is_array($value)) {
|
||||
$values[$key] = self::arrayMerge($values[$key], $value);
|
||||
} else {
|
||||
$values[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges two arrays
|
||||
*
|
||||
* Merges two arrays like the PHP function array_merge_recursive does,
|
||||
* the difference being that existing integer keys will not be renumbered.
|
||||
*
|
||||
* @param array
|
||||
* @param array
|
||||
* @return array resulting array
|
||||
*/
|
||||
protected static function arrayMerge($a, $b)
|
||||
{
|
||||
foreach ($b as $k => $v) {
|
||||
if (!is_array($v) || isset($a[$k]) && !is_array($a[$k])) {
|
||||
$a[$k] = $v;
|
||||
} else {
|
||||
$a[$k] = self::arrayMerge(isset($a[$k])? $a[$k]: array(), $v);
|
||||
}
|
||||
}
|
||||
return $a;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an Iterator for the form's pages
|
||||
*
|
||||
* @return ArrayIterator
|
||||
*/
|
||||
public function getIterator()
|
||||
{
|
||||
return new ArrayIterator($this->pages);
|
||||
}
|
||||
}
|
||||
?>
|
||||
68
www/analytics/libs/HTML/QuickForm2/Controller/Action.php
Normal file
68
www/analytics/libs/HTML/QuickForm2/Controller/Action.php
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
/**
|
||||
* Interface for Controller action handlers
|
||||
*
|
||||
* 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: Action.php 293335 2010-01-09 20:14:38Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Interface for Controller action handlers
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
interface HTML_QuickForm2_Controller_Action
|
||||
{
|
||||
/**
|
||||
* Performs the given action upon the given page
|
||||
*
|
||||
* @param HTML_QuickForm2_Controller_Page page of the multipage form
|
||||
* @param string action name, some action handlers
|
||||
* may perform different tasks depending
|
||||
* on this
|
||||
*/
|
||||
public function perform(HTML_QuickForm2_Controller_Page $page, $name);
|
||||
}
|
||||
?>
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
/**
|
||||
* Action handler for a 'back' button of wizard-type multipage form
|
||||
*
|
||||
* 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: Back.php 293411 2010-01-11 16:51:32Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/** Interface for Controller action handlers */
|
||||
// require_once 'HTML/QuickForm2/Controller/Action.php';
|
||||
|
||||
/**
|
||||
* Action handler for a 'back' button of wizard-type multipage form
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Controller_Action_Back
|
||||
implements HTML_QuickForm2_Controller_Action
|
||||
{
|
||||
public function perform(HTML_QuickForm2_Controller_Page $page, $name)
|
||||
{
|
||||
$page->storeValues(!$page->getController()->isWizard());
|
||||
|
||||
// go to the previous page if one is available
|
||||
// we don't check validation status here, 'jump' handler should
|
||||
if ($previous = $page->getController()->previousPage($page)) {
|
||||
return $previous->handle('jump');
|
||||
} else {
|
||||
return $page->handle('jump');
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
/**
|
||||
* Action handler for going to a specific page of a multipage form
|
||||
*
|
||||
* 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: Direct.php 293411 2010-01-11 16:51:32Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/** Interface for Controller action handlers */
|
||||
// require_once 'HTML/QuickForm2/Controller/Action.php';
|
||||
|
||||
/**
|
||||
* Action handler for going to a specific page of a multipage form
|
||||
*
|
||||
* When an instance of this class is added in addHandler(), action name
|
||||
* should be set to ID of a page you want to go to, not 'direct'
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Controller_Action_Direct
|
||||
implements HTML_QuickForm2_Controller_Action
|
||||
{
|
||||
public function perform(HTML_QuickForm2_Controller_Page $page, $name)
|
||||
{
|
||||
$page->storeValues();
|
||||
|
||||
return $page->getController()->getPage($name)->handle('jump');
|
||||
}
|
||||
}
|
||||
?>
|
||||
117
www/analytics/libs/HTML/QuickForm2/Controller/Action/Display.php
Normal file
117
www/analytics/libs/HTML/QuickForm2/Controller/Action/Display.php
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
<?php
|
||||
/**
|
||||
* Action handler for outputting the form
|
||||
*
|
||||
* 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: Display.php 294028 2010-01-25 23:09:11Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/** Interface for Controller action handlers */
|
||||
// require_once 'HTML/QuickForm2/Controller/Action.php';
|
||||
|
||||
/** Class presenting the values stored in session by Controller as submitted ones */
|
||||
// require_once 'HTML/QuickForm2/DataSource/Session.php';
|
||||
|
||||
/**
|
||||
* Action handler for outputting the form
|
||||
*
|
||||
* If you want to customize the form display, subclass this class and override
|
||||
* the renderForm() method, you don't need to change the perform() method.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Controller_Action_Display
|
||||
implements HTML_QuickForm2_Controller_Action
|
||||
{
|
||||
public function perform(HTML_QuickForm2_Controller_Page $page, $name)
|
||||
{
|
||||
$validate = false;
|
||||
$datasources = $page->getForm()->getDataSources();
|
||||
$container = $page->getController()->getSessionContainer();
|
||||
list(, $oldName) = $page->getController()->getActionName();
|
||||
// Check the original action name, we need to do additional processing
|
||||
// if it was 'display'
|
||||
if ('display' == $oldName) {
|
||||
// In case of wizard-type controller we should not allow access to
|
||||
// a page unless all previous pages are valid (see also bug #2323)
|
||||
if ($page->getController()->isWizard()
|
||||
&& !$page->getController()->isValid($page)
|
||||
) {
|
||||
return $page->getController()->getFirstInvalidPage()->handle('jump');
|
||||
}
|
||||
// If we have values in container then we should inject the Session
|
||||
// DataSource, if page was invalid previously we should later call
|
||||
// validate() to get the errors
|
||||
if (count($container->getValues($page->getForm()->getId()))) {
|
||||
array_unshift($datasources, new HTML_QuickForm2_DataSource_Session(
|
||||
$container->getValues($page->getForm()->getId())
|
||||
));
|
||||
$validate = false === $container->getValidationStatus($page->getForm()->getId());
|
||||
}
|
||||
}
|
||||
|
||||
// Add "defaults" datasources stored in session
|
||||
$page->getForm()->setDataSources(array_merge($datasources, $container->getDatasources()));
|
||||
$page->populateFormOnce();
|
||||
if ($validate) {
|
||||
$page->getForm()->validate();
|
||||
}
|
||||
return $this->renderForm($page->getForm());
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the form
|
||||
*
|
||||
* Default behaviour is to rely on form's __toString() magic method.
|
||||
* If you want to customize form appearance or use a different Renderer,
|
||||
* you should override this method.
|
||||
*
|
||||
* @param HTML_QuickForm2
|
||||
*/
|
||||
protected function renderForm(HTML_QuickForm2 $form)
|
||||
{
|
||||
echo $form;
|
||||
}
|
||||
}
|
||||
?>
|
||||
209
www/analytics/libs/HTML/QuickForm2/Controller/Action/Jump.php
Normal file
209
www/analytics/libs/HTML/QuickForm2/Controller/Action/Jump.php
Normal file
|
|
@ -0,0 +1,209 @@
|
|||
<?php
|
||||
/**
|
||||
* This handler performs an HTTP redirect to a specific page
|
||||
*
|
||||
* 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: Jump.php 294039 2010-01-26 12:29:46Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/** Interface for Controller action handlers */
|
||||
// require_once 'HTML/QuickForm2/Controller/Action.php';
|
||||
|
||||
/**
|
||||
* This handler performs an HTTP redirect to a specific page
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Controller_Action_Jump
|
||||
implements HTML_QuickForm2_Controller_Action
|
||||
{
|
||||
/**
|
||||
* Splits (part of) the URI into path and query components
|
||||
*
|
||||
* @param string String of the form 'foo?bar'
|
||||
* @return array Array of the form array('foo', '?bar)
|
||||
*/
|
||||
protected static function splitUri($uri)
|
||||
{
|
||||
if (false === ($qm = strpos($uri, '?'))) {
|
||||
return array($uri, '');
|
||||
} else {
|
||||
return array(substr($uri, 0, $qm), substr($uri, $qm));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the '..' and '.' segments from the path component
|
||||
*
|
||||
* @param string Path component of the URL, possibly with '.' and '..' segments
|
||||
* @return string Path component of the URL with '.' and '..' segments removed
|
||||
*/
|
||||
protected static function normalizePath($path)
|
||||
{
|
||||
$pathAry = explode('/', $path);
|
||||
$i = 1;
|
||||
|
||||
do {
|
||||
if ('.' == $pathAry[$i]) {
|
||||
if ($i < count($pathAry) - 1) {
|
||||
array_splice($pathAry, $i, 1);
|
||||
} else {
|
||||
$pathAry[$i] = '';
|
||||
$i++;
|
||||
}
|
||||
|
||||
} elseif ('..' == $pathAry[$i]) {
|
||||
if (1 == $i) {
|
||||
array_splice($pathAry, 1, 1);
|
||||
|
||||
} elseif ('..' != $pathAry[$i - 1]) {
|
||||
if ($i < count($pathAry) - 1) {
|
||||
array_splice($pathAry, $i - 1, 2);
|
||||
$i--;
|
||||
} else {
|
||||
array_splice($pathAry, $i - 1, 2, '');
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
$i++;
|
||||
}
|
||||
} while ($i < count($pathAry));
|
||||
|
||||
return implode('/', $pathAry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves relative URL using current page's URL as base
|
||||
*
|
||||
* The method follows procedure described in section 4 of RFC 1808 and
|
||||
* passes the examples provided in section 5 of said RFC. Values from
|
||||
* $_SERVER array are used for calculation of "current URL"
|
||||
*
|
||||
* @param string Relative URL, probably from form's action attribute
|
||||
* @return string Absolute URL
|
||||
*/
|
||||
protected static function resolveRelativeURL($url)
|
||||
{
|
||||
$https = !empty($_SERVER['HTTPS']) && ('off' != strtolower($_SERVER['HTTPS']));
|
||||
$scheme = ($https? 'https:': 'http:');
|
||||
if ('//' == substr($url, 0, 2)) {
|
||||
return $scheme . $url;
|
||||
|
||||
} else {
|
||||
$host = $scheme . '//' . $_SERVER['SERVER_NAME'] .
|
||||
(($https && 443 == $_SERVER['SERVER_PORT'] ||
|
||||
!$https && 80 == $_SERVER['SERVER_PORT'])? '': ':' . $_SERVER['SERVER_PORT']);
|
||||
if ('' == $url) {
|
||||
return $host . $_SERVER['REQUEST_URI'];
|
||||
|
||||
} elseif ('/' == $url[0]) {
|
||||
list($actPath, $actQuery) = self::splitUri($url);
|
||||
return $host . self::normalizePath($actPath) . $actQuery;
|
||||
|
||||
} else {
|
||||
list($basePath, $baseQuery) = self::splitUri($_SERVER['REQUEST_URI']);
|
||||
list($actPath, $actQuery) = self::splitUri($url);
|
||||
if ('' == $actPath) {
|
||||
return $host . $basePath . $actQuery;
|
||||
} else {
|
||||
$path = substr($basePath, 0, strrpos($basePath, '/') + 1) . $actPath;
|
||||
return $host . self::normalizePath($path) . $actQuery;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function perform(HTML_QuickForm2_Controller_Page $page, $name)
|
||||
{
|
||||
// we check whether *all* pages up to current are valid
|
||||
// if there is an invalid page we go to it, instead of the
|
||||
// requested one
|
||||
if ($page->getController()->isWizard()
|
||||
&& !$page->getController()->isValid($page)
|
||||
) {
|
||||
$page = $page->getController()->getFirstInvalidPage();
|
||||
}
|
||||
|
||||
// generate the URL for the page 'display' event and redirect to it
|
||||
$action = $page->getForm()->getAttribute('action');
|
||||
// Bug #13087: RFC 2616 requires an absolute URI in Location header
|
||||
if (!preg_match('@^([a-z][a-z0-9.+-]*):@i', $action)) {
|
||||
$action = self::resolveRelativeURL($action);
|
||||
}
|
||||
|
||||
if (!$page->getController()->propagateId()) {
|
||||
$controllerId = '';
|
||||
} else {
|
||||
$controllerId = '&' . HTML_QuickForm2_Controller::KEY_ID . '=' .
|
||||
$page->getController()->getId();
|
||||
}
|
||||
if (!defined('SID') || '' == SID || ini_get('session.use_only_cookies')) {
|
||||
$sessionId = '';
|
||||
} else {
|
||||
$sessionId = '&' . SID;
|
||||
}
|
||||
|
||||
return $this->doRedirect(
|
||||
$action . (false === strpos($action, '?')? '?': '&') .
|
||||
$page->getButtonName('display') . '=true' . $controllerId . $sessionId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Redirects to a given URL via Location: header and exits the script
|
||||
*
|
||||
* A separate method is mostly needed for creating mocks of this class
|
||||
* during testing.
|
||||
*
|
||||
* @param string URL to redirect to
|
||||
*/
|
||||
protected function doRedirect($url)
|
||||
{
|
||||
header('Location: ' . $url);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
<?php
|
||||
/**
|
||||
* Action handler for a 'next' button of wizard-type multipage form
|
||||
*
|
||||
* 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: Next.php 293411 2010-01-11 16:51:32Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/** Interface for Controller action handlers */
|
||||
// require_once 'HTML/QuickForm2/Controller/Action.php';
|
||||
|
||||
/**
|
||||
* Action handler for a 'next' button of wizard-type multipage form
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Controller_Action_Next
|
||||
implements HTML_QuickForm2_Controller_Action
|
||||
{
|
||||
public function perform(HTML_QuickForm2_Controller_Page $page, $name)
|
||||
{
|
||||
$valid = $page->storeValues();
|
||||
|
||||
// Wizard and page is invalid: don't go further
|
||||
if ($page->getController()->isWizard() && !$valid) {
|
||||
return $page->handle('display');
|
||||
}
|
||||
|
||||
// More pages?
|
||||
if (null !== ($next = $page->getController()->nextPage($page))) {
|
||||
return $next->handle('jump');
|
||||
|
||||
// Consider this a 'finish' button, if there is no explicit one
|
||||
} elseif($page->getController()->isWizard()) {
|
||||
if ($page->getController()->isValid()) {
|
||||
return $page->handle('process');
|
||||
} else {
|
||||
// redirect to the first invalid page
|
||||
return $page->getController()->getFirstInvalidPage()->handle('jump');
|
||||
}
|
||||
|
||||
} else {
|
||||
return $page->handle('display');
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
/**
|
||||
* Action handler for a 'submit' button
|
||||
*
|
||||
* 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: Submit.php 293411 2010-01-11 16:51:32Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/** Interface for Controller action handlers */
|
||||
// require_once 'HTML/QuickForm2/Controller/Action.php';
|
||||
|
||||
/**
|
||||
* Action handler for a 'submit' button
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Controller_Action_Submit
|
||||
implements HTML_QuickForm2_Controller_Action
|
||||
{
|
||||
public function perform(HTML_QuickForm2_Controller_Page $page, $name)
|
||||
{
|
||||
$valid = $page->storeValues();
|
||||
|
||||
// All pages are valid, process
|
||||
if ($page->getController()->isValid()) {
|
||||
return $page->handle('process');
|
||||
|
||||
// Current page is invalid, display it
|
||||
} elseif (!$valid) {
|
||||
return $page->handle('display');
|
||||
|
||||
// Some other page is invalid, redirect to it
|
||||
} else {
|
||||
return $page->getController()->getFirstInvalidPage()->handle('jump');
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
106
www/analytics/libs/HTML/QuickForm2/Controller/DefaultAction.php
Normal file
106
www/analytics/libs/HTML/QuickForm2/Controller/DefaultAction.php
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
<?php
|
||||
/**
|
||||
* A hidden button used to submit the form when the user presses Enter
|
||||
*
|
||||
* 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: DefaultAction.php 293465 2010-01-12 18:24:37Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/** Class for <input type="image" /> elements */
|
||||
// require_once 'HTML/QuickForm2/Element/InputImage.php';
|
||||
|
||||
/**
|
||||
* A hidden button used to submit the form when the user presses Enter
|
||||
*
|
||||
* This element is used by {@link HTML_QuickForm2_Controller_Page::setDefaultAction()}
|
||||
* to define the action that will take place if the user presses Enter on one
|
||||
* of the form elements instead of explicitly clicking one of the submit
|
||||
* buttons. Injecting a hidden <input type="image" /> element is about the
|
||||
* only cross-browser way to achieve this.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
* @link http://www.alanflavell.org.uk/www/formquestion.html
|
||||
* @link http://muffinresearch.co.uk/archives/2005/12/08/fun-with-multiple-submit-buttons/
|
||||
*/
|
||||
class HTML_QuickForm2_Controller_DefaultAction
|
||||
extends HTML_QuickForm2_Element_InputImage
|
||||
{
|
||||
protected $attributes = array('type' => 'image', 'id' => '_qf_default',
|
||||
'width' => '1', 'height' => '1');
|
||||
|
||||
/**
|
||||
* Disallow changing the 'id' attribute
|
||||
*
|
||||
* @param string Attribute name
|
||||
* @param string Attribute value, null if attribute is being removed
|
||||
*/
|
||||
protected function onAttributeChange($name, $value = null)
|
||||
{
|
||||
if ('id' == $name) {
|
||||
throw new HTML_QuickForm2_InvalidArgumentException(
|
||||
"Attribute 'id' is read-only"
|
||||
);
|
||||
}
|
||||
parent::onAttributeChange($name, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* This element is rendered using renderHidden() method
|
||||
*
|
||||
* renderHidden() is used to
|
||||
* - prevent using the standard element template as this button is
|
||||
* expected to be hidden
|
||||
* - render it above all other submit buttons since hidden elements
|
||||
* are usually at the top of the form
|
||||
*
|
||||
* @param HTML_QuickForm2_Renderer Renderer instance
|
||||
* @return HTML_QuickForm2_Renderer
|
||||
*/
|
||||
public function render(HTML_QuickForm2_Renderer $renderer)
|
||||
{
|
||||
$renderer->renderHidden($this);
|
||||
return $renderer;
|
||||
}
|
||||
}
|
||||
?>
|
||||
258
www/analytics/libs/HTML/QuickForm2/Controller/Page.php
Normal file
258
www/analytics/libs/HTML/QuickForm2/Controller/Page.php
Normal file
|
|
@ -0,0 +1,258 @@
|
|||
<?php
|
||||
/**
|
||||
* Class representing a page of a multipage form
|
||||
*
|
||||
* 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: Page.php 295963 2010-03-08 14:33:43Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class representing a page of a multipage form
|
||||
*
|
||||
* Unlike old HTML_QuickForm_Controller, this does not extend HTML_QuickForm2
|
||||
* but accepts an instance of that in the constructor. You need to create a
|
||||
* subclass of this class and implement its populateForm() method.
|
||||
*
|
||||
* @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_Controller_Page
|
||||
{
|
||||
/**
|
||||
* Button name template (needs form ID and action name substituted by sprintf())
|
||||
*/
|
||||
const KEY_NAME = '_qf_%s_%s';
|
||||
|
||||
/**
|
||||
* Whether populateForm() was already called
|
||||
* @var boolean
|
||||
*/
|
||||
private $_formPopulated = false;
|
||||
|
||||
/**
|
||||
* The form wrapped by this page
|
||||
* @var HTML_QuickForm2
|
||||
*/
|
||||
protected $form = null;
|
||||
|
||||
/**
|
||||
* Controller this page belongs to
|
||||
* @var HTML_QuickForm2_Controller
|
||||
*/
|
||||
protected $controller = null;
|
||||
|
||||
/**
|
||||
* Contains the mapping of action names to handlers (objects implementing HTML_QuickForm2_Controller_Action)
|
||||
* @var array
|
||||
*/
|
||||
protected $handlers = array();
|
||||
|
||||
/**
|
||||
* Class constructor, accepts the form to wrap around
|
||||
*
|
||||
* @param HTML_QuickForm2
|
||||
*/
|
||||
public function __construct(HTML_QuickForm2 $form)
|
||||
{
|
||||
$this->form = $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the form this page wraps around
|
||||
*
|
||||
* @return HTML_QuickForm2
|
||||
*/
|
||||
public function getForm()
|
||||
{
|
||||
return $this->form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the controller owning the page
|
||||
*
|
||||
* @param HTML_QuickForm2_Controller controller the page belongs to
|
||||
*/
|
||||
public function setController(HTML_QuickForm2_Controller $controller)
|
||||
{
|
||||
$this->controller = $controller;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the controller owning this page
|
||||
*
|
||||
* @return HTML_QuickForm2_Controller
|
||||
*/
|
||||
public function getController()
|
||||
{
|
||||
return $this->controller;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a handler for a specific action
|
||||
*
|
||||
* @param string action name
|
||||
* @param HTML_QuickForm2_Controller_Action the handler for the action
|
||||
*/
|
||||
public function addHandler($actionName, HTML_QuickForm2_Controller_Action $action)
|
||||
{
|
||||
$this->handlers[$actionName] = $action;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles an action
|
||||
*
|
||||
* If the page does not contain a handler for this action, controller's
|
||||
* handle() method will be called.
|
||||
*
|
||||
* @param string Name of the action
|
||||
* @throws HTML_QuickForm2_NotFoundException if handler for an action is missing
|
||||
*/
|
||||
public function handle($actionName)
|
||||
{
|
||||
if (isset($this->handlers[$actionName])) {
|
||||
return $this->handlers[$actionName]->perform($this, $actionName);
|
||||
} else {
|
||||
return $this->getController()->handle($this, $actionName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a name for a submit button that will invoke a specific action
|
||||
*
|
||||
* @param string Name of the action
|
||||
* @return string "name" attribute for a submit button
|
||||
*/
|
||||
public function getButtonName($actionName)
|
||||
{
|
||||
return sprintf(self::KEY_NAME, $this->getForm()->getId(), $actionName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default action invoked on page-form submit
|
||||
*
|
||||
* This is necessary as the user may just press Enter instead of
|
||||
* clicking one of the named submit buttons and then no action name will
|
||||
* be passed to the script.
|
||||
*
|
||||
* @param string Default action name
|
||||
* @param string Path to a 1x1 transparent GIF image
|
||||
* @return object Returns the image input used for default action
|
||||
*/
|
||||
public function setDefaultAction($actionName, $imageSrc = '')
|
||||
{
|
||||
// require_once 'HTML/QuickForm2/Controller/DefaultAction.php';
|
||||
|
||||
if (0 == count($this->form)) {
|
||||
$image = $this->form->appendChild(
|
||||
new HTML_QuickForm2_Controller_DefaultAction(
|
||||
$this->getButtonName($actionName), array('src' => $imageSrc)
|
||||
)
|
||||
);
|
||||
|
||||
// replace the existing DefaultAction
|
||||
} elseif ($image = $this->form->getElementById('_qf_default')) {
|
||||
$image->setName($this->getButtonName($actionName))
|
||||
->setAttribute('src', $imageSrc);
|
||||
|
||||
// Inject the element to the first position to improve chances that
|
||||
// it ends up on top in the output
|
||||
} else {
|
||||
$it = $this->form->getIterator();
|
||||
$it->rewind();
|
||||
$image = $this->form->insertBefore(
|
||||
new HTML_QuickForm2_Controller_DefaultAction(
|
||||
$this->getButtonName($actionName), array('src' => $imageSrc)
|
||||
),
|
||||
$it->current()
|
||||
);
|
||||
}
|
||||
return $image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper around populateForm() ensuring that it is only called once
|
||||
*/
|
||||
final public function populateFormOnce()
|
||||
{
|
||||
if (!$this->_formPopulated) {
|
||||
if (!empty($this->controller) && $this->controller->propagateId()) {
|
||||
$this->form->addElement(
|
||||
'hidden', HTML_QuickForm2_Controller::KEY_ID,
|
||||
array('id' => HTML_QuickForm2_Controller::KEY_ID)
|
||||
)->setValue($this->controller->getId());
|
||||
}
|
||||
$this->populateForm();
|
||||
$this->_formPopulated = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates the form with the elements
|
||||
*
|
||||
* The implementation of this method in your subclass of
|
||||
* HTML_QuickForm2_Controller_Page should contain all the necessary
|
||||
* addElement(), addRule() etc. calls. The method will only be called if
|
||||
* needed to prevent wasting resources on the forms that aren't going to
|
||||
* be seen by the user.
|
||||
*/
|
||||
abstract protected function populateForm();
|
||||
|
||||
/**
|
||||
* Stores the form values (and validation status) is session container
|
||||
*
|
||||
* @param bool Whether to store validation status
|
||||
*/
|
||||
public function storeValues($validate = true)
|
||||
{
|
||||
$this->populateFormOnce();
|
||||
$container = $this->getController()->getSessionContainer();
|
||||
$id = $this->form->getId();
|
||||
|
||||
$container->storeValues($id, (array)$this->form->getValue());
|
||||
if ($validate) {
|
||||
$container->storeValidationStatus($id, $this->form->validate());
|
||||
}
|
||||
return $container->getValidationStatus($id);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -0,0 +1,195 @@
|
|||
<?php
|
||||
/**
|
||||
* Object wrapping around session variable used to store controller data
|
||||
*
|
||||
* 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: SessionContainer.php 293868 2010-01-23 18:37:16Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Object wrapping around session variable used to store controller data
|
||||
*
|
||||
* Unlike old HTML_QuickForm_Controller, this does not extend HTML_QuickForm2
|
||||
* but accepts an instance of that in the constructor. You need to create a
|
||||
* subclass of this class and implement its populateForm() method.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Controller_SessionContainer
|
||||
{
|
||||
/**
|
||||
* A reference to a key in $_SESSION superglobal array
|
||||
* @var array
|
||||
*/
|
||||
protected $data;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* Initializes a variable in $_SESSION array, its name is based upon the
|
||||
* name of the Controller passed here
|
||||
*
|
||||
* @param HTML_QuickForm2_Controller
|
||||
*/
|
||||
public function __construct(HTML_QuickForm2_Controller $controller)
|
||||
{
|
||||
$name = sprintf(HTML_QuickForm2_Controller::KEY_CONTAINER,
|
||||
$controller->getId());
|
||||
if (empty($_SESSION[$name])) {
|
||||
$_SESSION[$name] = array(
|
||||
'datasources' => array(),
|
||||
'values' => array(),
|
||||
'valid' => array()
|
||||
);
|
||||
}
|
||||
$this->data =& $_SESSION[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores the page submit values
|
||||
*
|
||||
* @param string Page ID
|
||||
* @param array Page submit values
|
||||
*/
|
||||
public function storeValues($pageId, array $values)
|
||||
{
|
||||
$this->data['values'][$pageId] = $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the page values kept in session
|
||||
*
|
||||
* @param string Page ID
|
||||
* @return array
|
||||
*/
|
||||
public function getValues($pageId)
|
||||
{
|
||||
return array_key_exists($pageId, $this->data['values'])
|
||||
? $this->data['values'][$pageId]: array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores the page validation status
|
||||
*
|
||||
* @param string Page ID
|
||||
* @param bool Whether the page is valid
|
||||
*/
|
||||
public function storeValidationStatus($pageId, $status)
|
||||
{
|
||||
$this->data['valid'][$pageId] = (bool)$status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the page validation status kept in session
|
||||
*
|
||||
* @param string Page ID
|
||||
* @return bool
|
||||
*/
|
||||
public function getValidationStatus($pageId)
|
||||
{
|
||||
return array_key_exists($pageId, $this->data['valid'])
|
||||
? $this->data['valid'][$pageId]: null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores the controller data sources
|
||||
*
|
||||
* @param array A new data source list
|
||||
* @throws HTML_QuickForm2_InvalidArgumentException if given array
|
||||
* contains something that is not a valid data source
|
||||
*/
|
||||
public function storeDatasources(array $datasources)
|
||||
{
|
||||
foreach ($datasources as $ds) {
|
||||
if (!$ds instanceof HTML_QuickForm2_DataSource) {
|
||||
throw new HTML_QuickForm2_InvalidArgumentException(
|
||||
'Array should contain only DataSource instances'
|
||||
);
|
||||
}
|
||||
}
|
||||
$this->data['datasources'] = $datasources;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the controller data sources
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDatasources()
|
||||
{
|
||||
return $this->data['datasources'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores some user-supplied parameter alongside controller data
|
||||
*
|
||||
* It is sometimes useful to pass some additional user data between pages
|
||||
* of the form, thus this method. It will be removed with all the other
|
||||
* data by {@link HTML_QuickForm2_Controller::destroySessionContainer()}
|
||||
*
|
||||
* @param string Parameter name
|
||||
* @param string Parameter value
|
||||
*/
|
||||
public function storeOpaque($name, $value)
|
||||
{
|
||||
if (!array_key_exists('opaque', $this->data)) {
|
||||
$this->data['opaque'] = array();
|
||||
}
|
||||
$this->data['opaque'][$name] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a user-supplied parameter
|
||||
*
|
||||
* @param string Parameter name
|
||||
* @return mixed
|
||||
*/
|
||||
public function getOpaque($name)
|
||||
{
|
||||
return (array_key_exists('opaque', $this->data)
|
||||
&& array_key_exists($name, $this->data['opaque']))
|
||||
? $this->data['opaque'][$name]: null;
|
||||
}
|
||||
}
|
||||
67
www/analytics/libs/HTML/QuickForm2/DataSource.php
Normal file
67
www/analytics/libs/HTML/QuickForm2/DataSource.php
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
/**
|
||||
* Interface for data sources used by HTML_QuickForm2 objects
|
||||
*
|
||||
* 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: DataSource.php 300722 2010-06-24 10:15:52Z mansion $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Interface for data sources used by HTML_QuickForm2 objects
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
interface HTML_QuickForm2_DataSource
|
||||
{
|
||||
/**
|
||||
* Returns value for the element with the given name
|
||||
*
|
||||
* If data source doesn't have a requested value it should return null
|
||||
*
|
||||
* @param string Element's name
|
||||
* @return mixed Element's value
|
||||
*/
|
||||
public function getValue($name);
|
||||
}
|
||||
?>
|
||||
101
www/analytics/libs/HTML/QuickForm2/DataSource/Array.php
Normal file
101
www/analytics/libs/HTML/QuickForm2/DataSource/Array.php
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
<?php
|
||||
/**
|
||||
* Array-based data source for HTML_QuickForm2 objects
|
||||
*
|
||||
* 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: Array.php 294057 2010-01-26 21:10:28Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Interface for data sources used by HTML_QuickForm2 objects
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/DataSource.php';
|
||||
|
||||
/**
|
||||
* Array-based data source for HTML_QuickForm2 objects
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_DataSource_Array implements HTML_QuickForm2_DataSource
|
||||
{
|
||||
/**
|
||||
* Array containing elements' values
|
||||
* @var array
|
||||
*/
|
||||
protected $values;
|
||||
|
||||
/**
|
||||
* Class constructor, initializes the values array
|
||||
*
|
||||
* @param array Array containing the elements' values
|
||||
*/
|
||||
public function __construct($values = array())
|
||||
{
|
||||
$this->values = $values;
|
||||
}
|
||||
|
||||
public function getValue($name)
|
||||
{
|
||||
if (empty($this->values)) {
|
||||
return null;
|
||||
}
|
||||
if (strpos($name, '[')) {
|
||||
$tokens = explode('[', str_replace(']', '', $name));
|
||||
$value = $this->values;
|
||||
do {
|
||||
$token = array_shift($tokens);
|
||||
if (!isset($value[$token])) {
|
||||
return null;
|
||||
}
|
||||
$value = $value[$token];
|
||||
} while (!empty($tokens));
|
||||
return $value;
|
||||
} elseif (isset($this->values[$name])) {
|
||||
return $this->values[$name];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
78
www/analytics/libs/HTML/QuickForm2/DataSource/Session.php
Normal file
78
www/analytics/libs/HTML/QuickForm2/DataSource/Session.php
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
/**
|
||||
* Class presenting the values stored in session by Controller as submitted ones
|
||||
*
|
||||
* 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: Session.php 293411 2010-01-11 16:51:32Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/** Interface for data sources containing submitted values */
|
||||
// require_once 'HTML/QuickForm2/DataSource/Submit.php';
|
||||
|
||||
/** Array-based data source for HTML_QuickForm2 objects */
|
||||
// require_once 'HTML/QuickForm2/DataSource/Array.php';
|
||||
|
||||
/**
|
||||
* Class presenting the values stored in session by Controller as submitted ones
|
||||
*
|
||||
* This is a less hackish implementation of loadValues() method in old
|
||||
* HTML_QuickForm_Controller. The values need to be presented as submitted so
|
||||
* that elements like checkboxes and multiselects do not try to use default
|
||||
* values from subsequent datasources.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_DataSource_Session
|
||||
extends HTML_QuickForm2_DataSource_Array
|
||||
implements HTML_QuickForm2_DataSource_Submit
|
||||
{
|
||||
/**
|
||||
* File upload data is not stored in the session
|
||||
*/
|
||||
public function getUpload($name)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
?>
|
||||
76
www/analytics/libs/HTML/QuickForm2/DataSource/Submit.php
Normal file
76
www/analytics/libs/HTML/QuickForm2/DataSource/Submit.php
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
/**
|
||||
* Interface for data sources containing submitted values
|
||||
*
|
||||
* 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: Submit.php 300722 2010-06-24 10:15:52Z mansion $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Interface for data sources used by HTML_QuickForm2 objects
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/DataSource.php';
|
||||
|
||||
/**
|
||||
* Interface for data sources containing submitted values
|
||||
*
|
||||
* This interface provides method for getting information on uploaded files.
|
||||
* Additionally some elements will only consider getting their values from data
|
||||
* sources implementing this interface.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
interface HTML_QuickForm2_DataSource_Submit extends HTML_QuickForm2_DataSource
|
||||
{
|
||||
/**
|
||||
* Returns the information about uploaded file
|
||||
*
|
||||
* If data source doesn't such information it should return null
|
||||
*
|
||||
* @param string Name of file upload field
|
||||
* @return array|null Information on uploaded file, from $_FILES array
|
||||
*/
|
||||
public function getUpload($name);
|
||||
}
|
||||
?>
|
||||
170
www/analytics/libs/HTML/QuickForm2/DataSource/SuperGlobal.php
Normal file
170
www/analytics/libs/HTML/QuickForm2/DataSource/SuperGlobal.php
Normal file
|
|
@ -0,0 +1,170 @@
|
|||
<?php
|
||||
/**
|
||||
* Data source for HTML_QuickForm2 objects based on superglobal arrays
|
||||
*
|
||||
* 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: SuperGlobal.php 294057 2010-01-26 21:10:28Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Interface for data sources containing submitted values
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/DataSource/Submit.php';
|
||||
|
||||
/**
|
||||
* Array-based data source for HTML_QuickForm2 objects
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/DataSource/Array.php';
|
||||
|
||||
/**
|
||||
* Data source for HTML_QuickForm2 objects based on superglobal arrays
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_DataSource_SuperGlobal
|
||||
extends HTML_QuickForm2_DataSource_Array
|
||||
implements HTML_QuickForm2_DataSource_Submit
|
||||
{
|
||||
/**
|
||||
* Information on file uploads (from $_FILES)
|
||||
* @var array
|
||||
*/
|
||||
protected $files = array();
|
||||
|
||||
/**
|
||||
* Keys present in the $_FILES array
|
||||
* @var array
|
||||
*/
|
||||
private static $_fileKeys = array('name', 'type', 'size', 'tmp_name', 'error');
|
||||
|
||||
/**
|
||||
* Class constructor, intializes the internal arrays from superglobals
|
||||
*
|
||||
* @param string Request method (GET or POST)
|
||||
* @param bool Whether magic_quotes_gpc directive is on
|
||||
*/
|
||||
public function __construct($requestMethod = 'POST', $magicQuotesGPC = false)
|
||||
{
|
||||
if (!$magicQuotesGPC) {
|
||||
if ('GET' == strtoupper($requestMethod)) {
|
||||
$this->values = $_GET;
|
||||
} else {
|
||||
$this->values = $_POST;
|
||||
$this->files = $_FILES;
|
||||
}
|
||||
} else {
|
||||
if ('GET' == strtoupper($requestMethod)) {
|
||||
$this->values = $this->arrayMapRecursive('stripslashes', $_GET);
|
||||
} else {
|
||||
$this->values = $this->arrayMapRecursive('stripslashes', $_POST);
|
||||
foreach ($_FILES as $key1 => $val1) {
|
||||
foreach ($val1 as $key2 => $val2) {
|
||||
if ('name' == $key2) {
|
||||
$this->files[$key1][$key2] = $this->arrayMapRecursive(
|
||||
'stripslashes', $val2
|
||||
);
|
||||
} else {
|
||||
$this->files[$key1][$key2] = $val2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A recursive version of array_map() function
|
||||
*
|
||||
* @param callback Callback function to apply
|
||||
* @param mixed Input array
|
||||
* @return array with callback applied
|
||||
*/
|
||||
protected function arrayMapRecursive($callback, $arr)
|
||||
{
|
||||
if (!is_array($arr)) {
|
||||
return call_user_func($callback, $arr);
|
||||
}
|
||||
$mapped = array();
|
||||
foreach ($arr as $k => $v) {
|
||||
$mapped[$k] = is_array($v)?
|
||||
$this->arrayMapRecursive($callback, $v):
|
||||
call_user_func($callback, $v);
|
||||
}
|
||||
return $mapped;
|
||||
}
|
||||
|
||||
public function getUpload($name)
|
||||
{
|
||||
if (empty($this->files)) {
|
||||
return null;
|
||||
}
|
||||
if (false !== ($pos = strpos($name, '['))) {
|
||||
$tokens = explode('[', str_replace(']', '', $name));
|
||||
$base = array_shift($tokens);
|
||||
$value = array();
|
||||
if (!isset($this->files[$base]['name'])) {
|
||||
return null;
|
||||
}
|
||||
foreach (self::$_fileKeys as $key) {
|
||||
$value[$key] = $this->files[$base][$key];
|
||||
}
|
||||
|
||||
do {
|
||||
$token = array_shift($tokens);
|
||||
if (!isset($value['name'][$token])) {
|
||||
return null;
|
||||
}
|
||||
foreach (self::$_fileKeys as $key) {
|
||||
$value[$key] = $value[$key][$token];
|
||||
}
|
||||
} while (!empty($tokens));
|
||||
return $value;
|
||||
} elseif(isset($this->files[$name])) {
|
||||
return $this->files[$name];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
133
www/analytics/libs/HTML/QuickForm2/Element.php
Normal file
133
www/analytics/libs/HTML/QuickForm2/Element.php
Normal file
|
|
@ -0,0 +1,133 @@
|
|||
<?php
|
||||
/**
|
||||
* Base class for simple HTML_QuickForm2 elements (not Containers)
|
||||
*
|
||||
* 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: Element.php 299706 2010-05-24 18:32:37Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for all HTML_QuickForm2 elements
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Node.php';
|
||||
|
||||
/**
|
||||
* Abstract base class for simple QuickForm2 elements (not Containers)
|
||||
*
|
||||
* @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_Element extends HTML_QuickForm2_Node
|
||||
{
|
||||
public function setName($name)
|
||||
{
|
||||
$this->attributes['name'] = (string)$name;
|
||||
$this->updateValue();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates hidden form field containing the element's value
|
||||
*
|
||||
* This is used to pass the frozen element's value if 'persistent freeze'
|
||||
* feature is on
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getPersistentContent()
|
||||
{
|
||||
if (!$this->persistent || null === ($value = $this->getValue())) {
|
||||
return '';
|
||||
}
|
||||
return '<input type="hidden"' . self::getAttributesString(array(
|
||||
'name' => $this->getName(),
|
||||
'value' => $value,
|
||||
'id' => $this->getId()
|
||||
)) . ' />';
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the element needs to update its value from form's data sources
|
||||
*
|
||||
* The default behaviour is to go through the complete list of the data
|
||||
* sources until the non-null value is found.
|
||||
*/
|
||||
public function updateValue()
|
||||
{
|
||||
$name = $this->getName();
|
||||
foreach ($this->getDataSources() as $ds) {
|
||||
if (null !== ($value = $ds->getValue($name))) {
|
||||
$this->setValue($value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the element using the given renderer
|
||||
*
|
||||
* @param HTML_QuickForm2_Renderer Renderer instance
|
||||
* @return HTML_QuickForm2_Renderer
|
||||
*/
|
||||
public function render(HTML_QuickForm2_Renderer $renderer)
|
||||
{
|
||||
foreach ($this->rules as $rule) {
|
||||
if ($rule[1] & HTML_QuickForm2_Rule::RUNAT_CLIENT) {
|
||||
$renderer->getJavascriptBuilder()->addRule($rule[0]);
|
||||
}
|
||||
}
|
||||
$renderer->renderElement($this);
|
||||
return $renderer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Javascript code for getting the element's value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getJavascriptValue()
|
||||
{
|
||||
return "qf.form.getValue(document.getElementById('" . $this->getId() . "'))";
|
||||
}
|
||||
}
|
||||
?>
|
||||
161
www/analytics/libs/HTML/QuickForm2/Element/Button.php
Normal file
161
www/analytics/libs/HTML/QuickForm2/Element/Button.php
Normal file
|
|
@ -0,0 +1,161 @@
|
|||
<?php
|
||||
/**
|
||||
* Class for <button> 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>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SVN: $Id: Button.php 300722 2010-06-24 10:15:52Z mansion $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for simple HTML_QuickForm2 elements
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Element.php';
|
||||
|
||||
/**
|
||||
* Class for <button> elements
|
||||
*
|
||||
* Note that this element was named 'xbutton' in previous version of QuickForm,
|
||||
* the name 'button' being used for current 'inputbutton' element.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Element_Button extends HTML_QuickForm2_Element
|
||||
{
|
||||
/**
|
||||
* Contains options and data used for the element creation
|
||||
* - content: Content to be displayed between <button></button> tags
|
||||
* @var array
|
||||
*/
|
||||
protected $data = array('content' => '');
|
||||
|
||||
/**
|
||||
* Element's submit value
|
||||
* @var string
|
||||
*/
|
||||
protected $submitValue = null;
|
||||
|
||||
|
||||
public function getType()
|
||||
{
|
||||
return 'button';
|
||||
}
|
||||
|
||||
/**
|
||||
* Buttons can not be frozen
|
||||
*
|
||||
* @param bool Whether element should be frozen or editable. This
|
||||
* parameter is ignored in case of buttons
|
||||
* @return bool Always returns false
|
||||
*/
|
||||
public function toggleFrozen($freeze = null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the contents of the button element
|
||||
*
|
||||
* @param string Button content (HTML to add between <button></button> tags)
|
||||
* @return HTML_QuickForm2_Element_Button
|
||||
*/
|
||||
function setContent($content)
|
||||
{
|
||||
$this->data['content'] = $content;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Button's value cannot be set via this method
|
||||
*
|
||||
* @param mixed Element's value, this parameter is ignored
|
||||
* @return HTML_QuickForm2_Element_Button
|
||||
*/
|
||||
public function setValue($value)
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the element's value
|
||||
*
|
||||
* The value is only returned if the following is true
|
||||
* - button has 'type' attribute set to 'submit' (or no 'type' attribute)
|
||||
* - the form was submitted by clicking on this button
|
||||
*
|
||||
* This method returns the actual value submitted by the browser. Note that
|
||||
* different browsers submit different values!
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
if ((empty($this->attributes['type']) || 'submit' == $this->attributes['type']) &&
|
||||
!$this->getAttribute('disabled'))
|
||||
{
|
||||
return $this->applyFilters($this->submitValue);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return $this->getIndent() . '<button' . $this->getAttributes(true) .
|
||||
'>' . $this->data['content'] . '</button>';
|
||||
}
|
||||
|
||||
public function updateValue()
|
||||
{
|
||||
foreach ($this->getDataSources() as $ds) {
|
||||
if ($ds instanceof HTML_QuickForm2_DataSource_Submit &&
|
||||
null !== ($value = $ds->getValue($this->getName())))
|
||||
{
|
||||
$this->submitValue = $value;
|
||||
return;
|
||||
}
|
||||
}
|
||||
$this->submitValue = null;
|
||||
}
|
||||
}
|
||||
?>
|
||||
503
www/analytics/libs/HTML/QuickForm2/Element/Date.php
Normal file
503
www/analytics/libs/HTML/QuickForm2/Element/Date.php
Normal file
|
|
@ -0,0 +1,503 @@
|
|||
<?php
|
||||
/**
|
||||
* Date element
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 2006-2009, 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: Date.php 297453 2010-04-04 10:22:39Z mansion $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for HTML_QuickForm2 group of elements
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Container/Group.php';
|
||||
/**
|
||||
* Base class for HTML_QuickForm2 select element
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Element/Select.php';
|
||||
|
||||
/**
|
||||
* Class for a group of elements used to input dates (and times).
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Element_Date extends HTML_QuickForm2_Container_Group
|
||||
{
|
||||
public function getType()
|
||||
{
|
||||
return 'date';
|
||||
}
|
||||
|
||||
/**
|
||||
* Various options to control the element's display.
|
||||
* @var array
|
||||
*/
|
||||
protected $data = array(
|
||||
'language' => 'en',
|
||||
'format' => 'dMY',
|
||||
'minYear' => 2001,
|
||||
'maxYear' => 2010,
|
||||
'addEmptyOption' => false,
|
||||
'emptyOptionValue' => '',
|
||||
'emptyOptionText' => ' ',
|
||||
'optionIncrement' => array('i' => 1, 's' => 1)
|
||||
);
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* The following keys may appear in $data array:
|
||||
* - 'language': date language
|
||||
* - 'format': Format of the date, based on PHP's date() function.
|
||||
* The following characters are currently recognised in format string:
|
||||
* <pre>
|
||||
* D => Short names of days
|
||||
* l => Long names of days
|
||||
* d => Day numbers
|
||||
* M => Short names of months
|
||||
* F => Long names of months
|
||||
* m => Month numbers
|
||||
* Y => Four digit year
|
||||
* y => Two digit year
|
||||
* h => 12 hour format
|
||||
* H => 23 hour format
|
||||
* i => Minutes
|
||||
* s => Seconds
|
||||
* a => am/pm
|
||||
* A => AM/PM
|
||||
* </pre>
|
||||
* - 'minYear': Minimum year in year select
|
||||
* - 'maxYear': Maximum year in year select
|
||||
* - 'addEmptyOption': Should an empty option be added to the top of
|
||||
* each select box?
|
||||
* - 'emptyOptionValue': The value passed by the empty option.
|
||||
* - 'emptyOptionText': The text displayed for the empty option.
|
||||
* - 'optionIncrement': Step to increase the option values by (works for 'i' and 's')
|
||||
*
|
||||
* @param string Element name
|
||||
* @param mixed Attributes (either a string or an array)
|
||||
* @param array Element data (label, options and data used for element creation)
|
||||
*/
|
||||
public function __construct($name = null, $attributes = null, $data = null)
|
||||
{
|
||||
parent::__construct($name, $attributes, $data);
|
||||
|
||||
$locale =& $this->locale[$this->data['language']];
|
||||
$backslash = false;
|
||||
$separators = array();
|
||||
$separator = '';
|
||||
|
||||
for ($i = 0, $length = strlen($this->data['format']); $i < $length; $i++) {
|
||||
$sign = $this->data['format']{$i};
|
||||
if ($backslash) {
|
||||
$backslash = false;
|
||||
$separator .= $sign;
|
||||
} else {
|
||||
$loadSelect = true;
|
||||
switch ($sign) {
|
||||
case 'D':
|
||||
// Sunday is 0 like with 'w' in date()
|
||||
$options = $locale['weekdays_short'];
|
||||
break;
|
||||
case 'l':
|
||||
$options = $locale['weekdays_long'];
|
||||
break;
|
||||
case 'd':
|
||||
$options = $this->createOptionList(1, 31);
|
||||
break;
|
||||
case 'M':
|
||||
$options = $locale['months_short'];
|
||||
array_unshift($options , '');
|
||||
unset($options[0]);
|
||||
break;
|
||||
case 'm':
|
||||
$options = $this->createOptionList(1, 12);
|
||||
break;
|
||||
case 'F':
|
||||
$options = $locale['months_long'];
|
||||
array_unshift($options , '');
|
||||
unset($options[0]);
|
||||
break;
|
||||
case 'Y':
|
||||
$options = $this->createOptionList(
|
||||
$this->data['minYear'],
|
||||
$this->data['maxYear'],
|
||||
$this->data['minYear'] > $this->data['maxYear']? -1: 1
|
||||
);
|
||||
break;
|
||||
case 'y':
|
||||
$options = $this->createOptionList(
|
||||
$this->data['minYear'],
|
||||
$this->data['maxYear'],
|
||||
$this->data['minYear'] > $this->data['maxYear']? -1: 1
|
||||
);
|
||||
array_walk($options, create_function('&$v,$k','$v = substr($v,-2);'));
|
||||
break;
|
||||
case 'h':
|
||||
$options = $this->createOptionList(1, 12);
|
||||
break;
|
||||
case 'g':
|
||||
$options = $this->createOptionList(1, 12);
|
||||
array_walk($options, create_function('&$v,$k', '$v = intval($v);'));
|
||||
break;
|
||||
case 'H':
|
||||
$options = $this->createOptionList(0, 23);
|
||||
break;
|
||||
case 'i':
|
||||
$options = $this->createOptionList(0, 59, $this->data['optionIncrement']['i']);
|
||||
break;
|
||||
case 's':
|
||||
$options = $this->createOptionList(0, 59, $this->data['optionIncrement']['s']);
|
||||
break;
|
||||
case 'a':
|
||||
$options = array('am' => 'am', 'pm' => 'pm');
|
||||
break;
|
||||
case 'A':
|
||||
$options = array('AM' => 'AM', 'PM' => 'PM');
|
||||
break;
|
||||
case 'W':
|
||||
$options = $this->createOptionList(1, 53);
|
||||
break;
|
||||
case '\\':
|
||||
$backslash = true;
|
||||
$loadSelect = false;
|
||||
break;
|
||||
default:
|
||||
$separator .= (' ' == $sign? ' ': $sign);
|
||||
$loadSelect = false;
|
||||
}
|
||||
|
||||
if ($loadSelect) {
|
||||
if (0 < count($this)) {
|
||||
$separators[] = $separator;
|
||||
}
|
||||
$separator = '';
|
||||
// Should we add an empty option to the top of the select?
|
||||
if (!is_array($this->data['addEmptyOption']) && $this->data['addEmptyOption'] ||
|
||||
is_array($this->data['addEmptyOption']) && !empty($this->data['addEmptyOption'][$sign])) {
|
||||
|
||||
// Using '+' array operator to preserve the keys
|
||||
if (is_array($this->data['emptyOptionText']) && !empty($this->data['emptyOptionText'][$sign])) {
|
||||
$options = array($this->data['emptyOptionValue'] => $this->data['emptyOptionText'][$sign]) + $options;
|
||||
} else {
|
||||
$options = array($this->data['emptyOptionValue'] => $this->data['emptyOptionText']) + $options;
|
||||
}
|
||||
}
|
||||
$this->addSelect($sign, $this->getAttributes())->loadOptions($options);
|
||||
}
|
||||
}
|
||||
}
|
||||
$separators[] = $separator . ($backslash? '\\': '');
|
||||
$this->setSeparator($separators);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an option list containing the numbers from the start number to the end, inclusive
|
||||
*
|
||||
* @param int The start number
|
||||
* @param int The end number
|
||||
* @param int Increment by this value
|
||||
* @return array An array of numeric options.
|
||||
*/
|
||||
protected function createOptionList($start, $end, $step = 1)
|
||||
{
|
||||
for ($i = $start, $options = array(); $start > $end? $i >= $end: $i <= $end; $i += $step) {
|
||||
$options[$i] = sprintf('%02d', $i);
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trims leading zeros from the (numeric) string
|
||||
*
|
||||
* @param string A numeric string, possibly with leading zeros
|
||||
* @return string String with leading zeros removed
|
||||
*/
|
||||
protected function trimLeadingZeros($str)
|
||||
{
|
||||
if (0 == strcmp($str, $this->data['emptyOptionValue'])) {
|
||||
return $str;
|
||||
}
|
||||
$trimmed = ltrim($str, '0');
|
||||
return strlen($trimmed)? $trimmed: '0';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tries to convert the given value to a usable date before setting the
|
||||
* element value
|
||||
* @param int|string|array A timestamp, a string compatible with strtotime()
|
||||
* or an array that fits the element names
|
||||
*/
|
||||
public function setValue($value)
|
||||
{
|
||||
if (empty($value)) {
|
||||
$value = array();
|
||||
} elseif (is_scalar($value)) {
|
||||
if (!is_numeric($value)) {
|
||||
$value = strtotime($value);
|
||||
}
|
||||
// might be a unix epoch, then we fill all possible values
|
||||
$arr = explode('-', date('w-j-n-Y-g-G-i-s-a-A-W', (int)$value));
|
||||
$value = array(
|
||||
'D' => $arr[0],
|
||||
'l' => $arr[0],
|
||||
'd' => $arr[1],
|
||||
'M' => $arr[2],
|
||||
'm' => $arr[2],
|
||||
'F' => $arr[2],
|
||||
'Y' => $arr[3],
|
||||
'y' => $arr[3],
|
||||
'h' => $arr[4],
|
||||
'g' => $arr[4],
|
||||
'H' => $arr[5],
|
||||
'i' => $this->trimLeadingZeros($arr[6]),
|
||||
's' => $this->trimLeadingZeros($arr[7]),
|
||||
'a' => $arr[8],
|
||||
'A' => $arr[9],
|
||||
'W' => $this->trimLeadingZeros($arr[10])
|
||||
);
|
||||
} else {
|
||||
$value = array_map(array($this, 'trimLeadingZeros'), $value);
|
||||
}
|
||||
return parent::setValue($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the element needs to update its value from form's data sources
|
||||
*
|
||||
* Since the date element also accepts a timestamp as value, the default
|
||||
* group behavior is changed.
|
||||
*/
|
||||
public function updateValue()
|
||||
{
|
||||
$name = $this->getName();
|
||||
foreach ($this->getDataSources() as $ds) {
|
||||
if (null !== ($value = $ds->getValue($name))) {
|
||||
$this->setValue($value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
parent::updateValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Options in different languages
|
||||
*
|
||||
* Note to potential translators: to avoid encoding problems please send
|
||||
* your translations with "weird" letters encoded as HTML Unicode entities
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $locale = array(
|
||||
'en' => array (
|
||||
'weekdays_short'=> array ('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'),
|
||||
'weekdays_long' => array ('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'),
|
||||
'months_short' => array ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'),
|
||||
'months_long' => array ('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December')
|
||||
),
|
||||
'de' => array (
|
||||
'weekdays_short'=> array ('So', 'Mon', 'Di', 'Mi', 'Do', 'Fr', 'Sa'),
|
||||
'weekdays_long' => array ('Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'),
|
||||
'months_short' => array ('Jan', 'Feb', 'März', 'April', 'Mai', 'Juni', 'Juli', 'Aug', 'Sept', 'Okt', 'Nov', 'Dez'),
|
||||
'months_long' => array ('Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember')
|
||||
),
|
||||
'fr' => array (
|
||||
'weekdays_short'=> array ('Dim', 'Lun', 'Mar', 'Mer', 'Jeu', 'Ven', 'Sam'),
|
||||
'weekdays_long' => array ('Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'),
|
||||
'months_short' => array ('Jan', 'Fév', 'Mar', 'Avr', 'Mai', 'Juin', 'Juil', 'Août', 'Sep', 'Oct', 'Nov', 'Déc'),
|
||||
'months_long' => array ('Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre')
|
||||
),
|
||||
'hu' => array (
|
||||
'weekdays_short'=> array ('V', 'H', 'K', 'Sze', 'Cs', 'P', 'Szo'),
|
||||
'weekdays_long' => array ('vasárnap', 'hétfő', 'kedd', 'szerda', 'csütörtök', 'péntek', 'szombat'),
|
||||
'months_short' => array ('jan', 'feb', 'márc', 'ápr', 'máj', 'jún', 'júl', 'aug', 'szept', 'okt', 'nov', 'dec'),
|
||||
'months_long' => array ('január', 'február', 'március', 'április', 'május', 'június', 'július', 'augusztus', 'szeptember', 'október', 'november', 'december')
|
||||
),
|
||||
'pl' => array (
|
||||
'weekdays_short'=> array ('Nie', 'Pn', 'Wt', 'Śr', 'Czw', 'Pt', 'Sob'),
|
||||
'weekdays_long' => array ('Niedziela', 'Poniedziałek', 'Wtorek', 'Środa', 'Czwartek', 'Piątek', 'Sobota'),
|
||||
'months_short' => array ('Sty', 'Lut', 'Mar', 'Kwi', 'Maj', 'Cze', 'Lip', 'Sie', 'Wrz', 'Paź', 'Lis', 'Gru'),
|
||||
'months_long' => array ('Styczeń', 'Luty', 'Marzec', 'Kwiecień', 'Maj', 'Czerwiec', 'Lipiec', 'Sierpień', 'Wrzesień', 'Październik', 'Listopad', 'Grudzień')
|
||||
),
|
||||
'sl' => array (
|
||||
'weekdays_short'=> array ('Ned', 'Pon', 'Tor', 'Sre', 'Cet', 'Pet', 'Sob'),
|
||||
'weekdays_long' => array ('Nedelja', 'Ponedeljek', 'Torek', 'Sreda', 'Cetrtek', 'Petek', 'Sobota'),
|
||||
'months_short' => array ('Jan', 'Feb', 'Mar', 'Apr', 'Maj', 'Jun', 'Jul', 'Avg', 'Sep', 'Okt', 'Nov', 'Dec'),
|
||||
'months_long' => array ('Januar', 'Februar', 'Marec', 'April', 'Maj', 'Junij', 'Julij', 'Avgust', 'September', 'Oktober', 'November', 'December')
|
||||
),
|
||||
'ru' => array (
|
||||
'weekdays_short'=> array ('Вс', 'Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб'),
|
||||
'weekdays_long' => array ('Воскресенье', 'Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота'),
|
||||
'months_short' => array ('Янв', 'Фев', 'Мар', 'Апр', 'Май', 'Июн', 'Июл', 'Авг', 'Сен', 'Окт', 'Ноя', 'Дек'),
|
||||
'months_long' => array ('Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь')
|
||||
),
|
||||
'es' => array (
|
||||
'weekdays_short'=> array ('Dom', 'Lun', 'Mar', 'Mié', 'Jue', 'Vie', 'Sáb'),
|
||||
'weekdays_long' => array ('Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'),
|
||||
'months_short' => array ('Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic'),
|
||||
'months_long' => array ('Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre')
|
||||
),
|
||||
'da' => array (
|
||||
'weekdays_short'=> array ('Søn', 'Man', 'Tir', 'Ons', 'Tor', 'Fre', 'Lør'),
|
||||
'weekdays_long' => array ('Søndag', 'Mandag', 'Tirsdag', 'Onsdag', 'Torsdag', 'Fredag', 'Lørdag'),
|
||||
'months_short' => array ('Jan', 'Feb', 'Mar', 'Apr', 'Maj', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dec'),
|
||||
'months_long' => array ('Januar', 'Februar', 'Marts', 'April', 'Maj', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'December')
|
||||
),
|
||||
'is' => array (
|
||||
'weekdays_short'=> array ('Sun', 'Mán', 'Þri', 'Mið', 'Fim', 'Fös', 'Lau'),
|
||||
'weekdays_long' => array ('Sunnudagur', 'Mánudagur', 'Þriðjudagur', 'Miðvikudagur', 'Fimmtudagur', 'Föstudagur', 'Laugardagur'),
|
||||
'months_short' => array ('Jan', 'Feb', 'Mar', 'Apr', 'Maí', 'Jún', 'Júl', 'Ágú', 'Sep', 'Okt', 'Nóv', 'Des'),
|
||||
'months_long' => array ('Janúar', 'Febrúar', 'Mars', 'Apríl', 'Maí', 'Júní', 'Júlí', 'Ágúst', 'September', 'Október', 'Nóvember', 'Desember')
|
||||
),
|
||||
'it' => array (
|
||||
'weekdays_short'=> array ('Dom', 'Lun', 'Mar', 'Mer', 'Gio', 'Ven', 'Sab'),
|
||||
'weekdays_long' => array ('Domenica', 'Lunedì', 'Martedì', 'Mercoledì', 'Giovedì', 'Venerdì', 'Sabato'),
|
||||
'months_short' => array ('Gen', 'Feb', 'Mar', 'Apr', 'Mag', 'Giu', 'Lug', 'Ago', 'Set', 'Ott', 'Nov', 'Dic'),
|
||||
'months_long' => array ('Gennaio', 'Febbraio', 'Marzo', 'Aprile', 'Maggio', 'Giugno', 'Luglio', 'Agosto', 'Settembre', 'Ottobre', 'Novembre', 'Dicembre')
|
||||
),
|
||||
'sk' => array (
|
||||
'weekdays_short'=> array ('Ned', 'Pon', 'Uto', 'Str', 'Štv', 'Pia', 'Sob'),
|
||||
'weekdays_long' => array ('Nedeža', 'Pondelok', 'Utorok', 'Streda', 'Štvrtok', 'Piatok', 'Sobota'),
|
||||
'months_short' => array ('Jan', 'Feb', 'Mar', 'Apr', 'Máj', 'Jún', 'Júl', 'Aug', 'Sep', 'Okt', 'Nov', 'Dec'),
|
||||
'months_long' => array ('Január', 'Február', 'Marec', 'Apríl', 'Máj', 'Jún', 'Júl', 'August', 'September', 'Október', 'November', 'December')
|
||||
),
|
||||
'cs' => array (
|
||||
'weekdays_short'=> array ('Ne', 'Po', 'Út', 'St', 'Čt', 'Pá', 'So'),
|
||||
'weekdays_long' => array ('Neděle', 'Pondělí', 'Úterý', 'Středa', 'Čtvrtek', 'Pátek', 'Sobota'),
|
||||
'months_short' => array ('Led', 'Úno', 'Bře', 'Dub', 'Kvě', 'Čen', 'Čec', 'Srp', 'Zář', 'Říj', 'Lis', 'Pro'),
|
||||
'months_long' => array ('Leden', 'Únor', 'Březen', 'Duben', 'Květen', 'Červen', 'Červenec', 'Srpen', 'Září', 'Říjen', 'Listopad', 'Prosinec')
|
||||
),
|
||||
'hy' => array (
|
||||
'weekdays_short'=> array ('Կրկ', 'Երկ', 'Երք', 'Չրք', 'Հնգ', 'Ուր', 'Շբթ'),
|
||||
'weekdays_long' => array ('Կիրակի', 'Երկուշաբթի', 'Երեքշաբթի', 'Չորեքշաբթի', 'Հինգշաբթի', 'Ուրբաթ', 'Շաբաթ'),
|
||||
'months_short' => array ('Հնվ', 'Փտր', 'Մրտ', 'Ապր', 'Մյս', 'Հնս', 'Հլս', 'Օգս', 'Սպտ', 'Հկտ', 'Նյմ', 'Դկտ'),
|
||||
'months_long' => array ('Հունվար', 'Փետրվար', 'Մարտ', 'Ապրիլ', 'Մայիս', 'Հունիս', 'Հուլիս', 'Օգոստոս', 'Սեպտեմբեր', 'Հոկտեմբեր', 'Նոյեմբեր', 'Դեկտեմբեր')
|
||||
),
|
||||
'nl' => array (
|
||||
'weekdays_short'=> array ('Zo', 'Ma', 'Di', 'Wo', 'Do', 'Vr', 'Za'),
|
||||
'weekdays_long' => array ('Zondag', 'Maandag', 'Dinsdag', 'Woensdag', 'Donderdag', 'Vrijdag', 'Zaterdag'),
|
||||
'months_short' => array ('Jan', 'Feb', 'Mar', 'Apr', 'Mei', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dec'),
|
||||
'months_long' => array ('Januari', 'Februari', 'Maart', 'April', 'Mei', 'Juni', 'Juli', 'Augustus', 'September', 'Oktober', 'November', 'December')
|
||||
),
|
||||
'et' => array (
|
||||
'weekdays_short'=> array ('P', 'E', 'T', 'K', 'N', 'R', 'L'),
|
||||
'weekdays_long' => array ('Pühapäev', 'Esmaspäev', 'Teisipäev', 'Kolmapäev', 'Neljapäev', 'Reede', 'Laupäev'),
|
||||
'months_short' => array ('Jaan', 'Veebr', 'Märts', 'Aprill', 'Mai', 'Juuni', 'Juuli', 'Aug', 'Sept', 'Okt', 'Nov', 'Dets'),
|
||||
'months_long' => array ('Jaanuar', 'Veebruar', 'Märts', 'Aprill', 'Mai', 'Juuni', 'Juuli', 'August', 'September', 'Oktoober', 'November', 'Detsember')
|
||||
),
|
||||
'tr' => array (
|
||||
'weekdays_short'=> array ('Paz', 'Pzt', 'Sal', 'Çar', 'Per', 'Cum', 'Cts'),
|
||||
'weekdays_long' => array ('Pazar', 'Pazartesi', 'Salı', 'Çarşamba', 'Perşembe', 'Cuma', 'Cumartesi'),
|
||||
'months_short' => array ('Ock', 'Şbt', 'Mrt', 'Nsn', 'Mys', 'Hzrn', 'Tmmz', 'Ağst', 'Eyl', 'Ekm', 'Ksm', 'Arlk'),
|
||||
'months_long' => array ('Ocak', 'Şubat', 'Mart', 'Nisan', 'Mayıs', 'Haziran', 'Temmuz', 'Ağustos', 'Eylül', 'Ekim', 'Kasım', 'Aralık')
|
||||
),
|
||||
'no' => array (
|
||||
'weekdays_short'=> array ('Søn', 'Man', 'Tir', 'Ons', 'Tor', 'Fre', 'Lør'),
|
||||
'weekdays_long' => array ('Søndag', 'Mandag', 'Tirsdag', 'Onsdag', 'Torsdag', 'Fredag', 'Lørdag'),
|
||||
'months_short' => array ('Jan', 'Feb', 'Mar', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Des'),
|
||||
'months_long' => array ('Januar', 'Februar', 'Mars', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Desember')
|
||||
),
|
||||
'eo' => array (
|
||||
'weekdays_short'=> array ('Dim', 'Lun', 'Mar', 'Mer', 'Ĵaŭ', 'Ven', 'Sab'),
|
||||
'weekdays_long' => array ('Dimanĉo', 'Lundo', 'Mardo', 'Merkredo', 'Ĵaŭdo', 'Vendredo', 'Sabato'),
|
||||
'months_short' => array ('Jan', 'Feb', 'Mar', 'Apr', 'Maj', 'Jun', 'Jul', 'Aŭg', 'Sep', 'Okt', 'Nov', 'Dec'),
|
||||
'months_long' => array ('Januaro', 'Februaro', 'Marto', 'Aprilo', 'Majo', 'Junio', 'Julio', 'Aŭgusto', 'Septembro', 'Oktobro', 'Novembro', 'Decembro')
|
||||
),
|
||||
'ua' => array (
|
||||
'weekdays_short'=> array ('Ндл', 'Пнд', 'Втр', 'Срд', 'Чтв', 'Птн', 'Сбт'),
|
||||
'weekdays_long' => array ('Неділя', 'Понеділок', 'Вівторок', 'Середа', 'Четвер', 'П\'ятниця', 'Субота'),
|
||||
'months_short' => array ('Січ', 'Лют', 'Бер', 'Кві', 'Тра', 'Чер', 'Лип', 'Сер', 'Вер', 'Жов', 'Лис', 'Гру'),
|
||||
'months_long' => array ('Січень', 'Лютий', 'Березень', 'Квітень', 'Травень', 'Червень', 'Липень', 'Серпень', 'Вересень', 'Жовтень', 'Листопад', 'Грудень')
|
||||
),
|
||||
'ro' => array (
|
||||
'weekdays_short'=> array ('Dum', 'Lun', 'Mar', 'Mie', 'Joi', 'Vin', 'Sam'),
|
||||
'weekdays_long' => array ('Duminica', 'Luni', 'Marti', 'Miercuri', 'Joi', 'Vineri', 'Sambata'),
|
||||
'months_short' => array ('Ian', 'Feb', 'Mar', 'Apr', 'Mai', 'Iun', 'Iul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'),
|
||||
'months_long' => array ('Ianuarie', 'Februarie', 'Martie', 'Aprilie', 'Mai', 'Iunie', 'Iulie', 'August', 'Septembrie', 'Octombrie', 'Noiembrie', 'Decembrie')
|
||||
),
|
||||
'he' => array (
|
||||
'weekdays_short'=> array ('ראשון', 'שני', 'שלישי', 'רביעי', 'חמישי', 'שישי', 'שבת'),
|
||||
'weekdays_long' => array ('יום ראשון', 'יום שני', 'יום שלישי', 'יום רביעי', 'יום חמישי', 'יום שישי', 'שבת'),
|
||||
'months_short' => array ('ינואר', 'פברואר', 'מרץ', 'אפריל', 'מאי', 'יוני', 'יולי', 'אוגוסט', 'ספטמבר', 'אוקטובר', 'נובמבר', 'דצמבר'),
|
||||
'months_long' => array ('ינואר', 'פברואר', 'מרץ', 'אפריל', 'מאי', 'יוני', 'יולי', 'אוגוסט', 'ספטמבר', 'אוקטובר', 'נובמבר', 'דצמבר')
|
||||
),
|
||||
'sv' => array (
|
||||
'weekdays_short'=> array ('Sön', 'Mån', 'Tis', 'Ons', 'Tor', 'Fre', 'Lör'),
|
||||
'weekdays_long' => array ('Söndag', 'Måndag', 'Tisdag', 'Onsdag', 'Torsdag', 'Fredag', 'Lördag'),
|
||||
'months_short' => array ('Jan', 'Feb', 'Mar', 'Apr', 'Maj', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dec'),
|
||||
'months_long' => array ('Januari', 'Februari', 'Mars', 'April', 'Maj', 'Juni', 'Juli', 'Augusti', 'September', 'Oktober', 'November', 'December')
|
||||
),
|
||||
'pt' => array (
|
||||
'weekdays_short'=> array ('Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sáb'),
|
||||
'weekdays_long' => array ('Domingo', 'Segunda-feira', 'Terça-feira', 'Quarta-feira', 'Quinta-feira', 'Sexta-feira', 'Sábado'),
|
||||
'months_short' => array ('Jan', 'Fev', 'Mar', 'Abr', 'Mai', 'Jun', 'Jul', 'Ago', 'Set', 'Out', 'Nov', 'Dez'),
|
||||
'months_long' => array ('Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro')
|
||||
),
|
||||
'tw' => array (
|
||||
'weekdays_short'=> array ('週日','週一', '週二','週三', '週四','週五', '週六'),
|
||||
'weekdays_long' => array ('星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'),
|
||||
'months_short' => array ('一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'),
|
||||
'months_long' => array ('一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月')
|
||||
),
|
||||
'pt-br' => array (
|
||||
'weekdays_short'=> array ('Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sáb'),
|
||||
'weekdays_long' => array ('Domingo', 'Segunda', 'Terça', 'Quarta', 'Quinta', 'Sexta', 'Sábado'),
|
||||
'months_short' => array ('Jan', 'Fev', 'Mar', 'Abr', 'Mai', 'Jun', 'Jul', 'Ago', 'Set', 'Out', 'Nov', 'Dez'),
|
||||
'months_long' => array ('Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro')
|
||||
),
|
||||
'sr' => array (
|
||||
'weekdays_short'=> array ('Нед', 'Пон', 'Уто', 'Сре', 'Чет', 'Пет', 'Суб'),
|
||||
'weekdays_long' => array ('Недеља', 'Понедељак', 'Уторак', 'Среда', 'Четвртак', 'Петак', 'Субота'),
|
||||
'months_short' => array ('Јан', 'Феб', 'Мар', 'Апр', 'Мај', 'Јун', 'Јул', 'Авг', 'Сеп', 'Окт', 'Нов', 'Дец'),
|
||||
'months_long' => array ('Јануар', 'Фебруар', 'Март', 'Април', 'Мај', 'Јун', 'Јул', 'Август', 'Септембар', 'Октобар', 'Новембар', 'Децембар')
|
||||
),
|
||||
'el' => array (
|
||||
'weekdays_short'=> array ('Δευ', 'Τρί', 'Τετ', 'Πέμ', 'Παρ', 'Σάβ', 'Κυρ'),
|
||||
'weekdays_long' => array ('Δευτέρα', 'Τρίτη', 'Τετάρτη', 'Πέμπτη', 'Παρασκευή', 'Σάββατο', 'Κυριακή'),
|
||||
'months_short' => array ('Ιαν', 'Φεβ', 'Μάρ', 'Απρ', 'Μάϊ', 'Ioύν', 'Ιούλ', 'Αύγ', 'Σεπ', 'Οκτ', 'Νοέ', 'Δεκ'),
|
||||
'months_long' => array ('Ιανουάριος', 'Φεβρουάριος', 'Μάρτιος', 'Απρίλιος', 'Μάϊος', 'Ιούνιος', 'Ioύλιος', 'Αύγουστος', 'Σεπτέμβριος', 'Οκτώβριος', 'Νοέμβριος', 'Δεκέμβριος')
|
||||
)
|
||||
);
|
||||
}
|
||||
?>
|
||||
114
www/analytics/libs/HTML/QuickForm2/Element/Input.php
Normal file
114
www/analytics/libs/HTML/QuickForm2/Element/Input.php
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
<?php
|
||||
/**
|
||||
* Base class for <input> 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>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SVN: $Id: Input.php 300722 2010-06-24 10:15:52Z mansion $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for simple HTML_QuickForm2 elements (not Containers)
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Element.php';
|
||||
|
||||
/**
|
||||
* Base class for <input> elements
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Element_Input extends HTML_QuickForm2_Element
|
||||
{
|
||||
/**
|
||||
* 'type' attribute should not be changeable
|
||||
* @var array
|
||||
*/
|
||||
protected $watchedAttributes = array('id', 'name', 'type');
|
||||
|
||||
protected function onAttributeChange($name, $value = null)
|
||||
{
|
||||
if ('type' == $name) {
|
||||
throw new HTML_QuickForm2_InvalidArgumentException(
|
||||
"Attribute 'type' is read-only"
|
||||
);
|
||||
}
|
||||
parent::onAttributeChange($name, $value);
|
||||
}
|
||||
|
||||
public function getType()
|
||||
{
|
||||
return $this->attributes['type'];
|
||||
}
|
||||
|
||||
public function setValue($value)
|
||||
{
|
||||
$this->setAttribute('value', $value);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getValue()
|
||||
{
|
||||
return $this->getAttribute('disabled')? null: $this->applyFilters($this->getAttribute('value'));
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
if ($this->frozen) {
|
||||
return $this->getFrozenHtml();
|
||||
} else {
|
||||
return '<input' . $this->getAttributes(true) . ' />';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the field's value without HTML tags
|
||||
* @return string
|
||||
*/
|
||||
protected function getFrozenHtml()
|
||||
{
|
||||
$value = $this->getAttribute('value');
|
||||
return (('' != $value)? htmlspecialchars($value, ENT_QUOTES, self::getOption('charset')): ' ') .
|
||||
$this->getPersistentContent();
|
||||
}
|
||||
}
|
||||
?>
|
||||
99
www/analytics/libs/HTML/QuickForm2/Element/InputButton.php
Normal file
99
www/analytics/libs/HTML/QuickForm2/Element/InputButton.php
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
<?php
|
||||
/**
|
||||
* Class for <input type="button" /> 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>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SVN: $Id: InputButton.php 294057 2010-01-26 21:10:28Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for <input> elements
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Element/Input.php';
|
||||
|
||||
/**
|
||||
* Class for <input type="button" /> elements
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Element_InputButton extends HTML_QuickForm2_Element_Input
|
||||
{
|
||||
protected $attributes = array('type' => 'button');
|
||||
|
||||
/**
|
||||
* Buttons can not be frozen
|
||||
*
|
||||
* @param bool Whether element should be frozen or editable. This
|
||||
* parameter is ignored in case of buttons
|
||||
* @return bool Always returns false
|
||||
*/
|
||||
public function toggleFrozen($freeze = null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Button elements cannot have any submit values
|
||||
*
|
||||
* @param mixed Element's value, this parameter is ignored
|
||||
* @return HTML_QuickForm2_Element_InputButton
|
||||
*/
|
||||
public function setValue($value)
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Button elements cannot have any submit values
|
||||
*
|
||||
* This method always returns null
|
||||
*
|
||||
* return string|null
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
?>
|
||||
172
www/analytics/libs/HTML/QuickForm2/Element/InputCheckable.php
Normal file
172
www/analytics/libs/HTML/QuickForm2/Element/InputCheckable.php
Normal file
|
|
@ -0,0 +1,172 @@
|
|||
<?php
|
||||
/**
|
||||
* Base class for checkboxes and radios
|
||||
*
|
||||
* 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: InputCheckable.php 300722 2010-06-24 10:15:52Z mansion $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for <input> elements
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Element/Input.php';
|
||||
|
||||
/**
|
||||
* Base class for <input> elements having 'checked' attribute (checkboxes and radios)
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Element_InputCheckable extends HTML_QuickForm2_Element_Input
|
||||
{
|
||||
protected $persistent = true;
|
||||
|
||||
/**
|
||||
* HTML to represent the element in "frozen" state
|
||||
*
|
||||
* Array index "checked" contains HTML for element's "checked" state,
|
||||
* "unchecked" for not checked
|
||||
* @var array
|
||||
*/
|
||||
protected $frozenHtml = array(
|
||||
'checked' => 'On',
|
||||
'unchecked' => 'Off'
|
||||
);
|
||||
|
||||
/**
|
||||
* Contains options and data used for the element creation
|
||||
* - content: Label "glued" to a checkbox or radio
|
||||
* @var array
|
||||
*/
|
||||
protected $data = array('content' => '');
|
||||
|
||||
public function __construct($name = null, $attributes = null, $data = null)
|
||||
{
|
||||
parent::__construct($name, $attributes, $data);
|
||||
// "checked" attribute should be updated on changes to "value" attribute
|
||||
// see bug #15708
|
||||
$this->watchedAttributes[] = 'value';
|
||||
}
|
||||
|
||||
protected function onAttributeChange($name, $value = null)
|
||||
{
|
||||
if ('value' != $name) {
|
||||
return parent::onAttributeChange($name, $value);
|
||||
}
|
||||
if (null === $value) {
|
||||
unset($this->attributes['value'], $this->attributes['checked']);
|
||||
} else {
|
||||
$this->attributes['value'] = $value;
|
||||
$this->updateValue();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the label to be rendered glued to the element
|
||||
*
|
||||
* This label is returned by {@link __toString()} method with the element's
|
||||
* HTML. It is automatically wrapped into the <label> tag.
|
||||
*
|
||||
* @param string
|
||||
* @return HTML_QuickForm2_Element_InputCheckable
|
||||
*/
|
||||
public function setContent($content)
|
||||
{
|
||||
$this->data['content'] = $content;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the label that will be "glued" to element's HTML
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getContent()
|
||||
{
|
||||
return $this->data['content'];
|
||||
}
|
||||
|
||||
|
||||
public function setValue($value)
|
||||
{
|
||||
if ((string)$value == $this->getAttribute('value')) {
|
||||
return $this->setAttribute('checked');
|
||||
} else {
|
||||
return $this->removeAttribute('checked');
|
||||
}
|
||||
}
|
||||
|
||||
public function getValue()
|
||||
{
|
||||
if (!empty($this->attributes['checked']) && empty($this->attributes['disabled'])) {
|
||||
return $this->applyFilters($this->getAttribute('value'));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
if (0 == strlen($this->data['content'])) {
|
||||
$label = '';
|
||||
} elseif ($this->frozen) {
|
||||
$label = $this->data['content'];
|
||||
} else {
|
||||
$label = '<label for="' . htmlspecialchars(
|
||||
$this->getId(), ENT_QUOTES, self::getOption('charset')
|
||||
) . '">' . $this->data['content'] . '</label>';
|
||||
}
|
||||
return parent::__toString() . $label;
|
||||
}
|
||||
|
||||
public function getFrozenHtml()
|
||||
{
|
||||
if ($this->getAttribute('checked')) {
|
||||
return $this->frozenHtml['checked'] . $this->getPersistentContent();
|
||||
} else {
|
||||
return $this->frozenHtml['unchecked'];
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
99
www/analytics/libs/HTML/QuickForm2/Element/InputCheckbox.php
Normal file
99
www/analytics/libs/HTML/QuickForm2/Element/InputCheckbox.php
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
<?php
|
||||
/**
|
||||
* Class for <input type="checkbox" /> 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>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SVN: $Id: InputCheckbox.php 294057 2010-01-26 21:10:28Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for checkboxes and radios
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Element/InputCheckable.php';
|
||||
|
||||
/**
|
||||
* Class for <input type="checkbox" /> elements
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Element_InputCheckbox extends HTML_QuickForm2_Element_InputCheckable
|
||||
{
|
||||
protected $attributes = array('type' => 'checkbox');
|
||||
|
||||
protected $frozenHtml = array(
|
||||
'checked' => '<tt>[x]</tt>',
|
||||
'unchecked' => '<tt>[ ]</tt>'
|
||||
);
|
||||
|
||||
public function __construct($name = null, $attributes = null, array $data = array())
|
||||
{
|
||||
parent::__construct($name, $attributes, $data);
|
||||
if (!$this->getAttribute('value')) {
|
||||
$this->setAttribute('value', 1);
|
||||
}
|
||||
}
|
||||
|
||||
public function updateValue()
|
||||
{
|
||||
$name = $this->getName();
|
||||
if ('[]' == substr($name, -2)) {
|
||||
$name = substr($name, 0, -2);
|
||||
}
|
||||
foreach ($this->getDataSources() as $ds) {
|
||||
if (null !== ($value = $ds->getValue($name))
|
||||
|| $ds instanceof HTML_QuickForm2_DataSource_Submit
|
||||
) {
|
||||
if (!is_array($value)) {
|
||||
$this->setValue($value);
|
||||
} elseif (in_array($this->getAttribute('value'), array_map('strval', $value), true)) {
|
||||
$this->setAttribute('checked');
|
||||
} else {
|
||||
$this->removeAttribute('checked');
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
268
www/analytics/libs/HTML/QuickForm2/Element/InputFile.php
Normal file
268
www/analytics/libs/HTML/QuickForm2/Element/InputFile.php
Normal file
|
|
@ -0,0 +1,268 @@
|
|||
<?php
|
||||
/**
|
||||
* Class for <input type="file" /> 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>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SVN: $Id: InputFile.php 300722 2010-06-24 10:15:52Z mansion $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for <input> elements
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Element/Input.php';
|
||||
|
||||
/**
|
||||
* Class for <input type="file" /> elements
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Element_InputFile extends HTML_QuickForm2_Element_Input
|
||||
{
|
||||
/**
|
||||
* Default language for error messages
|
||||
*/
|
||||
const DEFAULT_LANGUAGE = 'en';
|
||||
|
||||
/**
|
||||
* Localized error messages for PHP's file upload errors
|
||||
* @var array
|
||||
*/
|
||||
protected $errorMessages = array(
|
||||
'en' => array(
|
||||
UPLOAD_ERR_INI_SIZE => 'The uploaded file exceeds size permitted by PHP configuration (%d bytes)',
|
||||
UPLOAD_ERR_FORM_SIZE => 'The uploaded file exceeds the MAX_FILE_SIZE directive in HTML form (%d bytes)',
|
||||
UPLOAD_ERR_PARTIAL => 'The file was only partially uploaded',
|
||||
UPLOAD_ERR_NO_TMP_DIR => 'Server error: temporary directory is missing',
|
||||
UPLOAD_ERR_CANT_WRITE => 'Server error: failed to write the file to disk',
|
||||
UPLOAD_ERR_EXTENSION => 'File upload was stopped by extension'
|
||||
),
|
||||
'fr' => array(
|
||||
UPLOAD_ERR_INI_SIZE => 'Le fichier envoyé excède la taille autorisée par la configuration de PHP (%d octets)',
|
||||
UPLOAD_ERR_FORM_SIZE => 'Le fichier envoyé excède la taille de MAX_FILE_SIZE spécifiée dans le formulaire HTML (%d octets)',
|
||||
UPLOAD_ERR_PARTIAL => 'Le fichier n\'a été que partiellement téléchargé',
|
||||
UPLOAD_ERR_NO_TMP_DIR => 'Erreur serveur: le répertoire temporaire est manquant',
|
||||
UPLOAD_ERR_CANT_WRITE => 'Erreur serveur: échec de l\'écriture du fichier sur le disque',
|
||||
UPLOAD_ERR_EXTENSION => 'L\'envoi de fichier est arrêté par l\'extension'
|
||||
),
|
||||
'ru' => array(
|
||||
UPLOAD_ERR_INI_SIZE => 'Размер загруженного файла превосходит максимально разрешённый настройками PHP (%d байт)',
|
||||
UPLOAD_ERR_FORM_SIZE => 'Размер загруженного файла превосходит директиву MAX_FILE_SIZE, указанную в форме (%d байт)',
|
||||
UPLOAD_ERR_PARTIAL => 'Файл был загружен не полностью',
|
||||
UPLOAD_ERR_NO_TMP_DIR => 'Ошибка на сервере: отсутствует каталог для временных файлов',
|
||||
UPLOAD_ERR_CANT_WRITE => 'Ошибка на сервере: не удалось записать файл на диск',
|
||||
UPLOAD_ERR_EXTENSION => 'Загрузка файла была остановлена расширением'
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Language to display error messages in
|
||||
* @var string
|
||||
*/
|
||||
protected $language;
|
||||
|
||||
/**
|
||||
* Information on uploaded file, from submit data source
|
||||
* @var array
|
||||
*/
|
||||
protected $value = null;
|
||||
|
||||
protected $attributes = array('type' => 'file');
|
||||
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* Possible keys in $data array are:
|
||||
* - 'language': language to display error messages in, it should either be
|
||||
* already available in the class or provided in 'errorMessages'
|
||||
* - 'errorMessages': an array of error messages with the following format
|
||||
* <pre>
|
||||
* 'language code 1' => array(
|
||||
* UPLOAD_ERR_... => 'message',
|
||||
* ...
|
||||
* UPLOAD_ERR_... => 'message'
|
||||
* ),
|
||||
* ...
|
||||
* 'language code N' => array(
|
||||
* ...
|
||||
* )
|
||||
* </pre>
|
||||
* Note that error messages for UPLOAD_ERR_INI_SIZE and UPLOAD_ERR_FORM_SIZE
|
||||
* may contain '%d' placeholders that will be automatically replaced by the
|
||||
* appropriate size limits. Note also that you don't need to provide messages
|
||||
* for every possible error code in the arrays, you may e.g. override just
|
||||
* one error message for a particular language.
|
||||
*
|
||||
* @param string Element name
|
||||
* @param mixed Attributes (either a string or an array)
|
||||
* @param array Data used to set up error messages for PHP's file
|
||||
* upload errors.
|
||||
*/
|
||||
public function __construct($name = null, $attributes = null, array $data = array())
|
||||
{
|
||||
if (isset($data['errorMessages'])) {
|
||||
// neither array_merge() nor array_merge_recursive will do
|
||||
foreach ($data['errorMessages'] as $lang => $ary) {
|
||||
foreach ($ary as $code => $message) {
|
||||
$this->errorMessages[$lang][$code] = $message;
|
||||
}
|
||||
}
|
||||
unset($data['errorMessages']);
|
||||
}
|
||||
if (!isset($data['language'])) {
|
||||
$this->language = self::DEFAULT_LANGUAGE;
|
||||
} else {
|
||||
$this->language = isset($this->errorMessages[$data['language']])?
|
||||
$data['language']: self::DEFAULT_LANGUAGE;
|
||||
unset($data['language']);
|
||||
}
|
||||
parent::__construct($name, $attributes, $data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* File upload elements cannot be frozen
|
||||
*
|
||||
* To properly "freeze" a file upload element one has to store the uploaded
|
||||
* file somewhere and store the file info in session. This is way outside
|
||||
* the scope of this class.
|
||||
*
|
||||
* @param bool Whether element should be frozen or editable. This
|
||||
* parameter is ignored in case of file uploads
|
||||
* @return bool Always returns false
|
||||
*/
|
||||
public function toggleFrozen($freeze = null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the information on uploaded file
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* File upload's value cannot be set here
|
||||
*
|
||||
* @param mixed Value for file element, this parameter is ignored
|
||||
* @return HTML_QuickForm2_Element_InputFile
|
||||
*/
|
||||
public function setValue($value)
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function updateValue()
|
||||
{
|
||||
foreach ($this->getDataSources() as $ds) {
|
||||
if ($ds instanceof HTML_QuickForm2_DataSource_Submit) {
|
||||
$value = $ds->getUpload($this->getName());
|
||||
if (null !== $value) {
|
||||
$this->value = $value;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->value = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the server-side validation
|
||||
*
|
||||
* Before the Rules added to the element kick in, the element checks the
|
||||
* error code added to the $_FILES array by PHP. If the code isn't
|
||||
* UPLOAD_ERR_OK or UPLOAD_ERR_NO_FILE then a built-in error message will be
|
||||
* displayed and no further validation will take place.
|
||||
*
|
||||
* @return boolean Whether the element is valid
|
||||
*/
|
||||
protected function validate()
|
||||
{
|
||||
if (strlen($this->error)) {
|
||||
return false;
|
||||
}
|
||||
if (isset($this->value['error']) &&
|
||||
!in_array($this->value['error'], array(UPLOAD_ERR_OK, UPLOAD_ERR_NO_FILE)))
|
||||
{
|
||||
if (isset($this->errorMessages[$this->language][$this->value['error']])) {
|
||||
$errorMessage = $this->errorMessages[$this->language][$this->value['error']];
|
||||
} else {
|
||||
$errorMessage = $this->errorMessages[self::DEFAULT_LANGUAGE][$this->value['error']];
|
||||
}
|
||||
if (UPLOAD_ERR_INI_SIZE == $this->value['error']) {
|
||||
$iniSize = ini_get('upload_max_filesize');
|
||||
$size = intval($iniSize);
|
||||
switch (strtoupper(substr($iniSize, -1))) {
|
||||
case 'G': $size *= 1024;
|
||||
case 'M': $size *= 1024;
|
||||
case 'K': $size *= 1024;
|
||||
}
|
||||
|
||||
} elseif (UPLOAD_ERR_FORM_SIZE == $this->value['error']) {
|
||||
foreach ($this->getDataSources() as $ds) {
|
||||
if ($ds instanceof HTML_QuickForm2_DataSource_Submit) {
|
||||
$size = intval($ds->getValue('MAX_FILE_SIZE'));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->error = isset($size)? sprintf($errorMessage, $size): $errorMessage;
|
||||
return false;
|
||||
}
|
||||
return parent::validate();
|
||||
}
|
||||
|
||||
public function addFilter($callback, array $options = null, $recursive = true)
|
||||
{
|
||||
throw new HTML_QuickForm2_Exception(
|
||||
'InputFile elements do not support filters'
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
||||
82
www/analytics/libs/HTML/QuickForm2/Element/InputHidden.php
Normal file
82
www/analytics/libs/HTML/QuickForm2/Element/InputHidden.php
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
/**
|
||||
* Class for <input type="hidden" /> 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>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SVN: $Id: InputHidden.php 294057 2010-01-26 21:10:28Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for <input> elements
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Element/Input.php';
|
||||
|
||||
/**
|
||||
* Class for <input type="hidden" /> elements
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Element_InputHidden extends HTML_QuickForm2_Element_Input
|
||||
{
|
||||
protected $attributes = array('type' => 'hidden');
|
||||
|
||||
/**
|
||||
* Hidden elements can not be frozen
|
||||
*
|
||||
* @param bool Whether element should be frozen or editable. This
|
||||
* parameter is ignored in case of hidden elements
|
||||
* @return bool Always returns false
|
||||
*/
|
||||
public function toggleFrozen($freeze = null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function render(HTML_QuickForm2_Renderer $renderer)
|
||||
{
|
||||
$renderer->renderHidden($this);
|
||||
return $renderer;
|
||||
}
|
||||
}
|
||||
?>
|
||||
162
www/analytics/libs/HTML/QuickForm2/Element/InputImage.php
Normal file
162
www/analytics/libs/HTML/QuickForm2/Element/InputImage.php
Normal file
|
|
@ -0,0 +1,162 @@
|
|||
<?php
|
||||
/**
|
||||
* Class for <input type="image" /> 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>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SVN: $Id: InputImage.php 300722 2010-06-24 10:15:52Z mansion $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for <input> elements
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Element/Input.php';
|
||||
|
||||
/**
|
||||
* Class for <input type="image" /> elements
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Element_InputImage extends HTML_QuickForm2_Element_Input
|
||||
{
|
||||
protected $attributes = array('type' => 'image');
|
||||
|
||||
/**
|
||||
* Coordinates of user click within the image, array contains keys 'x' and 'y'
|
||||
* @var array
|
||||
*/
|
||||
protected $coordinates = null;
|
||||
|
||||
/**
|
||||
* Image buttons can not be frozen
|
||||
*
|
||||
* @param bool Whether element should be frozen or editable. This
|
||||
* parameter is ignored in case of image elements
|
||||
* @return bool Always returns false
|
||||
*/
|
||||
public function toggleFrozen($freeze = null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Image button's value cannot be set via this method
|
||||
*
|
||||
* @param mixed Element's value, this parameter is ignored
|
||||
* @return HTML_QuickForm2_Element_InputImage
|
||||
*/
|
||||
public function setValue($value)
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the element's value
|
||||
*
|
||||
* The value is only returned if the form was actually submitted and this
|
||||
* image button was clicked. Returns null in all other cases.
|
||||
*
|
||||
* @return array|null An array with keys 'x' and 'y' containing the
|
||||
* coordinates of user click if the image was clicked,
|
||||
* null otherwise
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return $this->getAttribute('disabled')? null: $this->applyFilters($this->coordinates);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the HTML representation of the element
|
||||
*
|
||||
* The method changes the element's name to foo[bar][] if it was foo[bar]
|
||||
* originally. If it is not done, then one of the click coordinates will be
|
||||
* lost, see {@link http://bugs.php.net/bug.php?id=745}
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
if (false === strpos($this->attributes['name'], '[') ||
|
||||
'[]' == substr($this->attributes['name'], -2))
|
||||
{
|
||||
return parent::__toString();
|
||||
} else {
|
||||
$this->attributes['name'] .= '[]';
|
||||
$html = parent::__toString();
|
||||
$this->attributes['name'] = substr($this->attributes['name'], 0, -2);
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
|
||||
public function updateValue()
|
||||
{
|
||||
foreach ($this->getDataSources() as $ds) {
|
||||
if ($ds instanceof HTML_QuickForm2_DataSource_Submit) {
|
||||
$name = $this->getName();
|
||||
if (false === strpos($name, '[') &&
|
||||
null !== ($value = $ds->getValue($name . '_x')))
|
||||
{
|
||||
$this->coordinates = array(
|
||||
'x' => $value,
|
||||
'y' => $ds->getValue($name . '_y')
|
||||
);
|
||||
return;
|
||||
|
||||
} elseif (false !== strpos($name, '[')) {
|
||||
if ('[]' == substr($name, -2)) {
|
||||
$name = substr($name, 0, -2);
|
||||
}
|
||||
if (null !== ($value = $ds->getValue($name))) {
|
||||
$this->coordinates = array(
|
||||
'x' => $value[0],
|
||||
'y' => $value[1]
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->coordinates = null;
|
||||
}
|
||||
}
|
||||
?>
|
||||
71
www/analytics/libs/HTML/QuickForm2/Element/InputPassword.php
Normal file
71
www/analytics/libs/HTML/QuickForm2/Element/InputPassword.php
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
/**
|
||||
* Class for <input type="password" /> 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>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SVN: $Id: InputPassword.php 294057 2010-01-26 21:10:28Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for <input> elements
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Element/Input.php';
|
||||
|
||||
/**
|
||||
* Class for <input type="password" /> elements
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Element_InputPassword extends HTML_QuickForm2_Element_Input
|
||||
{
|
||||
protected $attributes = array('type' => 'password');
|
||||
|
||||
protected function getFrozenHtml()
|
||||
{
|
||||
$value = $this->getValue();
|
||||
return (('' != $value)? '********': ' ') .
|
||||
$this->getPersistentContent();
|
||||
}
|
||||
}
|
||||
?>
|
||||
69
www/analytics/libs/HTML/QuickForm2/Element/InputRadio.php
Normal file
69
www/analytics/libs/HTML/QuickForm2/Element/InputRadio.php
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
/**
|
||||
* Class for <input type="radio" /> 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>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SVN: $Id: InputRadio.php 294057 2010-01-26 21:10:28Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for checkboxes and radios
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Element/InputCheckable.php';
|
||||
|
||||
/**
|
||||
* Class for <input type="radio" /> elements
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Element_InputRadio extends HTML_QuickForm2_Element_InputCheckable
|
||||
{
|
||||
protected $attributes = array('type' => 'radio');
|
||||
|
||||
protected $frozenHtml = array(
|
||||
'checked' => '<tt>(x)</tt>',
|
||||
'unchecked' => '<tt>( )</tt>'
|
||||
);
|
||||
}
|
||||
?>
|
||||
99
www/analytics/libs/HTML/QuickForm2/Element/InputReset.php
Normal file
99
www/analytics/libs/HTML/QuickForm2/Element/InputReset.php
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
<?php
|
||||
/**
|
||||
* Class for <input type="reset" /> 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>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SVN: $Id: InputReset.php 294057 2010-01-26 21:10:28Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for <input> elements
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Element/Input.php';
|
||||
|
||||
/**
|
||||
* Class for <input type="reset" /> elements
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Element_InputReset extends HTML_QuickForm2_Element_Input
|
||||
{
|
||||
protected $attributes = array('type' => 'reset');
|
||||
|
||||
/**
|
||||
* Reset buttons can not be frozen
|
||||
*
|
||||
* @param bool Whether element should be frozen or editable. This
|
||||
* parameter is ignored in case of reset buttons
|
||||
* @return bool Always returns false
|
||||
*/
|
||||
public function toggleFrozen($freeze = null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset elements cannot have any submit values
|
||||
*
|
||||
* @param mixed Element's value, this parameter is ignored
|
||||
* @return HTML_QuickForm2_Element_InputReset
|
||||
*/
|
||||
public function setValue($value)
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset elements cannot have any submit values
|
||||
*
|
||||
* This method always returns null
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
?>
|
||||
120
www/analytics/libs/HTML/QuickForm2/Element/InputSubmit.php
Normal file
120
www/analytics/libs/HTML/QuickForm2/Element/InputSubmit.php
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
<?php
|
||||
/**
|
||||
* Class for <input type="submit" /> 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>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SVN: $Id: InputSubmit.php 300722 2010-06-24 10:15:52Z mansion $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for <input> elements
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Element/Input.php';
|
||||
|
||||
/**
|
||||
* Class for <input type="submit" /> elements
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Element_InputSubmit extends HTML_QuickForm2_Element_Input
|
||||
{
|
||||
protected $attributes = array('type' => 'submit');
|
||||
|
||||
/**
|
||||
* Element's submit value
|
||||
* @var string
|
||||
*/
|
||||
protected $submitValue = null;
|
||||
|
||||
|
||||
/**
|
||||
* Submit buttons can not be frozen
|
||||
*
|
||||
* @param bool Whether element should be frozen or editable. This
|
||||
* parameter is ignored in case of submit elements
|
||||
* @return bool Always returns false
|
||||
*/
|
||||
public function toggleFrozen($freeze = null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit's value cannot be set via this method
|
||||
*
|
||||
* @param mixed Element's value, this parameter is ignored
|
||||
* @return HTML_QuickForm2_Element_InputSubmit
|
||||
*/
|
||||
public function setValue($value)
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the element's value
|
||||
*
|
||||
* The value is only returned if the form was actually submitted and this
|
||||
* submit button was clicked. Returns null in all other cases
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return $this->getAttribute('disabled')? null: $this->applyFilters($this->submitValue);
|
||||
}
|
||||
|
||||
public function updateValue()
|
||||
{
|
||||
foreach ($this->getDataSources() as $ds) {
|
||||
if ($ds instanceof HTML_QuickForm2_DataSource_Submit &&
|
||||
null !== ($value = $ds->getValue($this->getName())))
|
||||
{
|
||||
$this->submitValue = $value;
|
||||
return;
|
||||
}
|
||||
}
|
||||
$this->submitValue = null;
|
||||
}
|
||||
}
|
||||
?>
|
||||
64
www/analytics/libs/HTML/QuickForm2/Element/InputText.php
Normal file
64
www/analytics/libs/HTML/QuickForm2/Element/InputText.php
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
/**
|
||||
* Class for <input type="text" /> 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>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SVN: $Id: InputText.php 294057 2010-01-26 21:10:28Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for <input> elements
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Element/Input.php';
|
||||
|
||||
/**
|
||||
* Class for <input type="text" /> elements
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Element_InputText extends HTML_QuickForm2_Element_Input
|
||||
{
|
||||
protected $attributes = array('type' => 'text');
|
||||
}
|
||||
?>
|
||||
575
www/analytics/libs/HTML/QuickForm2/Element/Select.php
Normal file
575
www/analytics/libs/HTML/QuickForm2/Element/Select.php
Normal file
|
|
@ -0,0 +1,575 @@
|
|||
<?php
|
||||
/**
|
||||
* Classes for <select> 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>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SVN: $Id: Select.php 300722 2010-06-24 10:15:52Z mansion $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for simple HTML_QuickForm2 elements
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Element.php';
|
||||
|
||||
|
||||
/**
|
||||
* Collection of <option>s and <optgroup>s
|
||||
*
|
||||
* This class handles the output of <option> tags. The class is not intended to
|
||||
* be used directly.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Element_Select_OptionContainer extends HTML_Common2
|
||||
implements IteratorAggregate, Countable
|
||||
{
|
||||
/**
|
||||
* List of options and optgroups in this container
|
||||
*
|
||||
* Options are stored as arrays (for performance reasons), optgroups as
|
||||
* instances of Optgroup class.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array();
|
||||
|
||||
/**
|
||||
* Reference to parent <select>'s values
|
||||
* @var array
|
||||
*/
|
||||
protected $values;
|
||||
|
||||
/**
|
||||
* Reference to parent <select>'s possible values
|
||||
* @var array
|
||||
*/
|
||||
protected $possibleValues;
|
||||
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param array Reference to values of parent <select> element
|
||||
* @param array Reference to possible values of parent <select> element
|
||||
*/
|
||||
public function __construct(&$values, &$possibleValues)
|
||||
{
|
||||
$this->values =& $values;
|
||||
$this->possibleValues =& $possibleValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new option
|
||||
*
|
||||
* Please note that if you pass 'selected' attribute in the $attributes
|
||||
* parameter then this option's value will be added to <select>'s values.
|
||||
*
|
||||
* @param string Option text
|
||||
* @param string 'value' attribute for <option> tag
|
||||
* @param mixed Additional attributes for <option> tag (either as a
|
||||
* string or as an associative array)
|
||||
*/
|
||||
public function addOption($text, $value, $attributes = null)
|
||||
{
|
||||
if (null === $attributes) {
|
||||
$attributes = array('value' => (string)$value);
|
||||
} else {
|
||||
$attributes = self::prepareAttributes($attributes);
|
||||
if (isset($attributes['selected'])) {
|
||||
// the 'selected' attribute will be set in __toString()
|
||||
unset($attributes['selected']);
|
||||
if (!in_array($value, $this->values)) {
|
||||
$this->values[] = $value;
|
||||
}
|
||||
}
|
||||
$attributes['value'] = (string)$value;
|
||||
}
|
||||
if (!isset($attributes['disabled'])) {
|
||||
$this->possibleValues[(string)$value] = true;
|
||||
}
|
||||
$this->options[] = array('text' => $text, 'attr' => $attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new optgroup
|
||||
*
|
||||
* @param string 'label' attribute for optgroup tag
|
||||
* @param mixed Additional attributes for <optgroup> tag (either as a
|
||||
* string or as an associative array)
|
||||
* @return HTML_QuickForm2_Element_Select_Optgroup
|
||||
*/
|
||||
public function addOptgroup($label, $attributes = null)
|
||||
{
|
||||
$optgroup = new HTML_QuickForm2_Element_Select_Optgroup(
|
||||
$this->values, $this->possibleValues,
|
||||
$label, $attributes
|
||||
);
|
||||
$this->options[] = $optgroup;
|
||||
return $optgroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of contained options
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOptions()
|
||||
{
|
||||
return $this->options;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
$indentLvl = $this->getIndentLevel();
|
||||
$indent = $this->getIndent() . self::getOption('indent');
|
||||
$linebreak = self::getOption('linebreak');
|
||||
$html = '';
|
||||
$strValues = array_map('strval', $this->values);
|
||||
foreach ($this->options as $option) {
|
||||
if (is_array($option)) {
|
||||
if (in_array($option['attr']['value'], $strValues, true)) {
|
||||
$option['attr']['selected'] = 'selected';
|
||||
}
|
||||
$html .= $indent . '<option' .
|
||||
self::getAttributesString($option['attr']) .
|
||||
'>' . $option['text'] . '</option>' . $linebreak;
|
||||
} elseif ($option instanceof HTML_QuickForm2_Element_Select_OptionContainer) {
|
||||
$option->setIndentLevel($indentLvl + 1);
|
||||
$html .= $option->__toString();
|
||||
}
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator over contained elements
|
||||
*
|
||||
* @return HTML_QuickForm2_Element_Select_OptionIterator
|
||||
*/
|
||||
public function getIterator()
|
||||
{
|
||||
return new HTML_QuickForm2_Element_Select_OptionIterator($this->options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a recursive iterator over contained elements
|
||||
*
|
||||
* @return RecursiveIteratorIterator
|
||||
*/
|
||||
public function getRecursiveIterator()
|
||||
{
|
||||
return new RecursiveIteratorIterator(
|
||||
new HTML_QuickForm2_Element_Select_OptionIterator($this->options),
|
||||
RecursiveIteratorIterator::SELF_FIRST
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of options in the container
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return count($this->options);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Class representing an <optgroup> tag
|
||||
*
|
||||
* Do not instantiate this class yourself, use
|
||||
* {@link HTML_QuickForm2_Element_Select::addOptgroup()} method
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Element_Select_Optgroup
|
||||
extends HTML_QuickForm2_Element_Select_OptionContainer
|
||||
{
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param array Reference to values of parent <select> element
|
||||
* @param array Reference to possible values of parent <select> element
|
||||
* @param string 'label' attribute for optgroup tag
|
||||
* @param mixed Additional attributes for <optgroup> tag (either as a
|
||||
* string or as an associative array)
|
||||
*/
|
||||
public function __construct(&$values, &$possibleValues, $label, $attributes = null)
|
||||
{
|
||||
parent::__construct($values, $possibleValues);
|
||||
$this->setAttributes($attributes);
|
||||
$this->attributes['label'] = (string)$label;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
$indent = $this->getIndent();
|
||||
$linebreak = self::getOption('linebreak');
|
||||
return $indent . '<optgroup' . $this->getAttributes(true) . '>' .
|
||||
$linebreak . parent::__toString() . $indent . '</optgroup>' . $linebreak;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements a recursive iterator for options arrays
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Element_Select_OptionIterator extends RecursiveArrayIterator
|
||||
implements RecursiveIterator
|
||||
{
|
||||
public function hasChildren()
|
||||
{
|
||||
return $this->current() instanceof HTML_QuickForm2_Element_Select_OptionContainer;
|
||||
}
|
||||
|
||||
public function getChildren()
|
||||
{
|
||||
return new HTML_QuickForm2_Element_Select_OptionIterator(
|
||||
$this->current()->getOptions()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Class representing a <select> element
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Element_Select extends HTML_QuickForm2_Element
|
||||
{
|
||||
protected $persistent = true;
|
||||
|
||||
/**
|
||||
* Values for the select element (i.e. values of the selected options)
|
||||
* @var array
|
||||
*/
|
||||
protected $values = array();
|
||||
|
||||
/**
|
||||
* Possible values for select elements
|
||||
*
|
||||
* A value is considered possible if it is present as a value attribute of
|
||||
* some option and that option is not disabled.
|
||||
* @var array
|
||||
*/
|
||||
protected $possibleValues = array();
|
||||
|
||||
|
||||
/**
|
||||
* Object containing options for the <select> element
|
||||
* @var HTML_QuickForm2_Element_Select_OptionContainer
|
||||
*/
|
||||
protected $optionContainer;
|
||||
|
||||
/**
|
||||
* Enable intrinsic validation by default
|
||||
* @var array
|
||||
*/
|
||||
protected $data = array('intrinsic_validation' => true);
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* Select element can understand the following keys in $data parameter:
|
||||
* - 'options': data to populate element's options with. Passed to
|
||||
* {@link loadOptions()} method.
|
||||
* - 'intrinsic_validation': setting this to false will disable
|
||||
* that validation, {@link getValue()} will then return all submit
|
||||
* values, not just those corresponding to options present in the
|
||||
* element. May be useful in AJAX scenarios.
|
||||
*
|
||||
* @param string Element name
|
||||
* @param mixed Attributes (either a string or an array)
|
||||
* @param array Additional element data
|
||||
* @throws HTML_QuickForm2_InvalidArgumentException if junk is given in $options
|
||||
*/
|
||||
public function __construct($name = null, $attributes = null, array $data = array())
|
||||
{
|
||||
$options = isset($data['options'])? $data['options']: array();
|
||||
unset($data['options']);
|
||||
parent::__construct($name, $attributes, $data);
|
||||
$this->loadOptions($options);
|
||||
}
|
||||
|
||||
public function getType()
|
||||
{
|
||||
return 'select';
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
if ($this->frozen) {
|
||||
return $this->getFrozenHtml();
|
||||
} else {
|
||||
if (empty($this->attributes['multiple'])) {
|
||||
$attrString = $this->getAttributes(true);
|
||||
} else {
|
||||
$this->attributes['name'] .= '[]';
|
||||
$attrString = $this->getAttributes(true);
|
||||
$this->attributes['name'] = substr($this->attributes['name'], 0, -2);
|
||||
}
|
||||
$indent = $this->getIndent();
|
||||
return $indent . '<select' . $attrString . '>' .
|
||||
self::getOption('linebreak') .
|
||||
$this->optionContainer->__toString() .
|
||||
$indent . '</select>';
|
||||
}
|
||||
}
|
||||
|
||||
protected function getFrozenHtml()
|
||||
{
|
||||
if (null === ($value = $this->getValue())) {
|
||||
return ' ';
|
||||
}
|
||||
$valueHash = is_array($value)? array_flip($value): array($value => true);
|
||||
$options = array();
|
||||
foreach ($this->optionContainer->getRecursiveIterator() as $child) {
|
||||
if (is_array($child) && isset($valueHash[$child['attr']['value']]) &&
|
||||
empty($child['attr']['disabled']))
|
||||
{
|
||||
$options[] = $child['text'];
|
||||
}
|
||||
}
|
||||
|
||||
$html = implode('<br />', $options);
|
||||
if ($this->persistent) {
|
||||
$name = $this->attributes['name'] .
|
||||
(empty($this->attributes['multiple'])? '': '[]');
|
||||
// Only use id attribute if doing single hidden input
|
||||
$idAttr = (1 == count($valueHash))? array('id' => $this->getId()): array();
|
||||
foreach ($valueHash as $key => $item) {
|
||||
$html .= '<input type="hidden"' . self::getAttributesString(array(
|
||||
'name' => $name,
|
||||
'value' => $key
|
||||
) + $idAttr) . ' />';
|
||||
}
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the <select> element
|
||||
*
|
||||
* Please note that the returned value may not necessarily be equal to that
|
||||
* passed to {@link setValue()}. It passes "intrinsic validation" confirming
|
||||
* that such value could possibly be submitted by this <select> element.
|
||||
* Specifically, this method will return null if the elements "disabled"
|
||||
* attribute is set, it will not return values if there are no options having
|
||||
* such a "value" attribute or if such options' "disabled" attribute is set.
|
||||
* It will also only return a scalar value for single selects, mimicking
|
||||
* the common browsers' behaviour.
|
||||
*
|
||||
* @return mixed "value" attribute of selected option in case of single
|
||||
* select, array of selected options' "value" attributes in
|
||||
* case of multiple selects, null if no options selected
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
if (!empty($this->attributes['disabled']) || 0 == count($this->values)
|
||||
|| ($this->data['intrinsic_validation']
|
||||
&& (0 == count($this->optionContainer) || 0 == count($this->possibleValues)))
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$values = array();
|
||||
foreach ($this->values as $value) {
|
||||
if (!$this->data['intrinsic_validation'] || !empty($this->possibleValues[$value])) {
|
||||
$values[] = $value;
|
||||
}
|
||||
}
|
||||
if (0 == count($values)) {
|
||||
return null;
|
||||
} elseif (!empty($this->attributes['multiple'])) {
|
||||
return $this->applyFilters($values);
|
||||
} elseif (1 == count($values)) {
|
||||
return $this->applyFilters($values[0]);
|
||||
} else {
|
||||
// The <select> is not multiple, but several options are to be
|
||||
// selected. At least IE and Mozilla select the last selected
|
||||
// option in this case, we should do the same
|
||||
foreach ($this->optionContainer->getRecursiveIterator() as $child) {
|
||||
if (is_array($child) && in_array($child['attr']['value'], $values)) {
|
||||
$lastValue = $child['attr']['value'];
|
||||
}
|
||||
}
|
||||
return $this->applyFilters($lastValue);
|
||||
}
|
||||
}
|
||||
|
||||
public function setValue($value)
|
||||
{
|
||||
if (is_array($value)) {
|
||||
$this->values = array_values($value);
|
||||
} else {
|
||||
$this->values = array($value);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads <option>s (and <optgroup>s) for select element
|
||||
*
|
||||
* The method expects a array of options and optgroups:
|
||||
* <pre>
|
||||
* array(
|
||||
* 'option value 1' => 'option text 1',
|
||||
* ...
|
||||
* 'option value N' => 'option text N',
|
||||
* 'optgroup label 1' => array(
|
||||
* 'option value' => 'option text',
|
||||
* ...
|
||||
* ),
|
||||
* ...
|
||||
* )
|
||||
* </pre>
|
||||
* If value is a scalar, then array key is treated as "value" attribute of
|
||||
* <option> and value as this <option>'s text. If value is an array, then
|
||||
* key is treated as a "label" attribute of <optgroup> and value as an
|
||||
* array of <option>s for this <optgroup>.
|
||||
*
|
||||
* If you need to specify additional attributes for <option> and <optgroup>
|
||||
* tags, then you need to use {@link addOption()} and {@link addOptgroup()}
|
||||
* methods instead of this one.
|
||||
*
|
||||
* @param array
|
||||
* @throws HTML_QuickForm2_InvalidArgumentException if junk is given in $options
|
||||
* @return HTML_QuickForm2_Element_Select
|
||||
*/
|
||||
public function loadOptions(array $options)
|
||||
{
|
||||
$this->possibleValues = array();
|
||||
$this->optionContainer = new HTML_QuickForm2_Element_Select_OptionContainer(
|
||||
$this->values, $this->possibleValues
|
||||
);
|
||||
$this->loadOptionsFromArray($this->optionContainer, $options);
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds options from given array into given container
|
||||
*
|
||||
* @param HTML_QuickForm2_Element_Select_OptionContainer options will be
|
||||
* added to this container
|
||||
* @param array options array
|
||||
*/
|
||||
protected function loadOptionsFromArray(
|
||||
HTML_QuickForm2_Element_Select_OptionContainer $container, $options
|
||||
)
|
||||
{
|
||||
foreach ($options as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$optgroup = $container->addOptgroup($key);
|
||||
$this->loadOptionsFromArray($optgroup, $value);
|
||||
} else {
|
||||
$container->addOption($value, $key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds a new option
|
||||
*
|
||||
* Please note that if you pass 'selected' attribute in the $attributes
|
||||
* parameter then this option's value will be added to <select>'s values.
|
||||
*
|
||||
* @param string Option text
|
||||
* @param string 'value' attribute for <option> tag
|
||||
* @param mixed Additional attributes for <option> tag (either as a
|
||||
* string or as an associative array)
|
||||
*/
|
||||
public function addOption($text, $value, $attributes = null)
|
||||
{
|
||||
return $this->optionContainer->addOption($text, $value, $attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new optgroup
|
||||
*
|
||||
* @param string 'label' attribute for optgroup tag
|
||||
* @param mixed Additional attributes for <optgroup> tag (either as a
|
||||
* string or as an associative array)
|
||||
* @return HTML_QuickForm2_Element_Select_Optgroup
|
||||
*/
|
||||
public function addOptgroup($label, $attributes = null)
|
||||
{
|
||||
return $this->optionContainer->addOptgroup($label, $attributes);
|
||||
}
|
||||
|
||||
public function updateValue()
|
||||
{
|
||||
if (!$this->getAttribute('multiple')) {
|
||||
parent::updateValue();
|
||||
} else {
|
||||
$name = $this->getName();
|
||||
foreach ($this->getDataSources() as $ds) {
|
||||
if (null !== ($value = $ds->getValue($name)) ||
|
||||
$ds instanceof HTML_QuickForm2_DataSource_Submit)
|
||||
{
|
||||
$this->setValue(null === $value? array(): $value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
153
www/analytics/libs/HTML/QuickForm2/Element/Static.php
Normal file
153
www/analytics/libs/HTML/QuickForm2/Element/Static.php
Normal file
|
|
@ -0,0 +1,153 @@
|
|||
<?php
|
||||
/**
|
||||
* Class for static elements that only contain text or markup
|
||||
*
|
||||
* 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: Static.php 299206 2010-05-10 10:21:10Z mansion $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for simple HTML_QuickForm2 elements (not Containers)
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Element.php';
|
||||
|
||||
/**
|
||||
* Class for static elements that only contain text or markup
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Element_Static extends HTML_QuickForm2_Element
|
||||
{
|
||||
|
||||
/**
|
||||
* Contains options and data used for the element creation
|
||||
* - content: Content of the static element
|
||||
* @var array
|
||||
*/
|
||||
protected $data = array('content' => '');
|
||||
|
||||
public function getType()
|
||||
{
|
||||
return 'static';
|
||||
}
|
||||
|
||||
/**
|
||||
* Static element can not be frozen
|
||||
*
|
||||
* @param bool Whether element should be frozen or editable. This
|
||||
* parameter is ignored in case of static elements
|
||||
* @return bool Always returns false
|
||||
*/
|
||||
public function toggleFrozen($freeze = null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the contents of the static element
|
||||
*
|
||||
* @param string Static content
|
||||
* @return HTML_QuickForm2_Element_Static
|
||||
*/
|
||||
function setContent($content)
|
||||
{
|
||||
$this->data['content'] = $content;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the contents of the static element
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function getContent()
|
||||
{
|
||||
return $this->data['content'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Static element's content can also be set via this method
|
||||
*
|
||||
* @param mixed Element's value, this parameter is ignored
|
||||
* @return HTML_QuickForm2_Element_Static
|
||||
*/
|
||||
public function setValue($value)
|
||||
{
|
||||
$this->setContent($value);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Static elements have no value
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return $this->getIndent() . $this->data['content'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the element needs to update its value from form's data sources
|
||||
*
|
||||
* Static elements content can be updated with default form values.
|
||||
*/
|
||||
public function updateValue()
|
||||
{
|
||||
foreach ($this->getDataSources() as $ds) {
|
||||
if (!$ds instanceof HTML_QuickForm2_DataSource_Submit &&
|
||||
null !== ($value = $ds->getValue($this->getName())))
|
||||
{
|
||||
$this->setContent($value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
110
www/analytics/libs/HTML/QuickForm2/Element/Textarea.php
Normal file
110
www/analytics/libs/HTML/QuickForm2/Element/Textarea.php
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
<?php
|
||||
/**
|
||||
* Class for <textarea> 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>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SVN: $Id: Textarea.php 300722 2010-06-24 10:15:52Z mansion $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for simple HTML_QuickForm2 elements
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Element.php';
|
||||
|
||||
/**
|
||||
* Class for <textarea> elements
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Element_Textarea extends HTML_QuickForm2_Element
|
||||
{
|
||||
protected $persistent = true;
|
||||
|
||||
/**
|
||||
* Value for textarea field
|
||||
* @var string
|
||||
*/
|
||||
protected $value = null;
|
||||
|
||||
public function getType()
|
||||
{
|
||||
return 'textarea';
|
||||
}
|
||||
|
||||
public function setValue($value)
|
||||
{
|
||||
$this->value = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getValue()
|
||||
{
|
||||
return empty($this->attributes['disabled'])? $this->applyFilters($this->value): null;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
if ($this->frozen) {
|
||||
return $this->getFrozenHtml();
|
||||
} else {
|
||||
return $this->getIndent() . '<textarea' . $this->getAttributes(true) .
|
||||
'>' . preg_replace("/(\r\n|\n|\r)/", '
', htmlspecialchars(
|
||||
$this->value, ENT_QUOTES, self::getOption('charset')
|
||||
)) . '</textarea>';
|
||||
}
|
||||
}
|
||||
|
||||
public function getFrozenHtml()
|
||||
{
|
||||
$value = htmlspecialchars($this->value, ENT_QUOTES, self::getOption('charset'));
|
||||
if ('off' == $this->getAttribute('wrap')) {
|
||||
$html = $this->getIndent() . '<pre>' . $value .
|
||||
'</pre>' . self::getOption('linebreak');
|
||||
} else {
|
||||
$html = nl2br($value) . self::getOption('linbebreak');
|
||||
}
|
||||
return $html . $this->getPersistentContent();
|
||||
}
|
||||
}
|
||||
?>
|
||||
109
www/analytics/libs/HTML/QuickForm2/Exception.php
Normal file
109
www/analytics/libs/HTML/QuickForm2/Exception.php
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
<?php
|
||||
/**
|
||||
* Exception classes 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: Exception.php 294057 2010-01-26 21:10:28Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for exceptions in PEAR
|
||||
*/
|
||||
// require_once 'PEAR/Exception.php';
|
||||
|
||||
/**
|
||||
* Base class for exceptions in HTML_QuickForm2 package
|
||||
*
|
||||
* Such a base class is required by the Exception RFC:
|
||||
* http://pear.php.net/pepr/pepr-proposal-show.php?id=132
|
||||
* It will rarely be thrown directly, its specialized subclasses will be
|
||||
* thrown most of the time.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Exception extends PEAR_Exception
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception that denotes some resource was not found
|
||||
*
|
||||
* One example is trying to instantiate a nonexistent class in Factory
|
||||
* <code>
|
||||
* try {
|
||||
* HTML_QuickForm2_Factory::registerElement('missing', 'NonExistent');
|
||||
* $el = HTML_QuickForm2_Factory::createElement('missing');
|
||||
* } catch (HTML_QuickForm2_NotFoundException $e) {
|
||||
* echo $e->getMessage();
|
||||
* }
|
||||
* </code>
|
||||
* This code fill output "Class 'NonExistent' does not exist and no file to load"
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_NotFoundException extends HTML_QuickForm2_Exception
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception that denotes invalid arguments were passed
|
||||
*
|
||||
* One example is trying to create an element of type which is unknown to Factory
|
||||
* <code>
|
||||
* try {
|
||||
* $el = HTML_QuickForm2_Factory::createElement('unknown');
|
||||
* } catch (HTML_QuickForm2_InvalidArgumentException $e) {
|
||||
* echo $e->getMessage();
|
||||
* }
|
||||
* </code>
|
||||
* This code will output "Element type 'unknown' is not known"
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_InvalidArgumentException extends HTML_QuickForm2_Exception
|
||||
{
|
||||
}
|
||||
?>
|
||||
233
www/analytics/libs/HTML/QuickForm2/Factory.php
Normal file
233
www/analytics/libs/HTML/QuickForm2/Factory.php
Normal file
|
|
@ -0,0 +1,233 @@
|
|||
<?php
|
||||
/**
|
||||
* Static Factory class for HTML_QuickForm2 package
|
||||
*
|
||||
* 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: Factory.php 299305 2010-05-12 20:15:28Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class with static methods for loading classes and files
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Loader.php';
|
||||
|
||||
/**
|
||||
* Static factory class
|
||||
*
|
||||
* The class handles instantiation of Element and Rule objects as well as
|
||||
* registering of new Element and Rule classes.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Factory
|
||||
{
|
||||
/**
|
||||
* List of element types known to Factory
|
||||
* @var array
|
||||
*/
|
||||
protected static $elementTypes = array(
|
||||
'button' => array('HTML_QuickForm2_Element_Button', null),
|
||||
'checkbox' => array('HTML_QuickForm2_Element_InputCheckbox', null),
|
||||
'date' => array('HTML_QuickForm2_Element_Date', null),
|
||||
'fieldset' => array('HTML_QuickForm2_Container_Fieldset', null),
|
||||
'group' => array('HTML_QuickForm2_Container_Group', null),
|
||||
'file' => array('HTML_QuickForm2_Element_InputFile', null),
|
||||
'hidden' => array('HTML_QuickForm2_Element_InputHidden', null),
|
||||
'image' => array('HTML_QuickForm2_Element_InputImage', null),
|
||||
'inputbutton' => array('HTML_QuickForm2_Element_InputButton', null),
|
||||
'password' => array('HTML_QuickForm2_Element_InputPassword', null),
|
||||
'radio' => array('HTML_QuickForm2_Element_InputRadio', null),
|
||||
'reset' => array('HTML_QuickForm2_Element_InputReset', null),
|
||||
'select' => array('HTML_QuickForm2_Element_Select', null),
|
||||
'submit' => array('HTML_QuickForm2_Element_InputSubmit', null),
|
||||
'text' => array('HTML_QuickForm2_Element_InputText', null),
|
||||
'textarea' => array('HTML_QuickForm2_Element_Textarea', null)
|
||||
);
|
||||
|
||||
/**
|
||||
* List of registered rules
|
||||
* @var array
|
||||
*/
|
||||
protected static $registeredRules = array(
|
||||
'nonempty' => array('HTML_QuickForm2_Rule_Nonempty', null),
|
||||
'empty' => array('HTML_QuickForm2_Rule_Empty', null),
|
||||
'required' => array('HTML_QuickForm2_Rule_Required', null),
|
||||
'compare' => array('HTML_QuickForm2_Rule_Compare', null),
|
||||
'eq' => array('HTML_QuickForm2_Rule_Compare', null,
|
||||
array('operator' => '===')),
|
||||
'neq' => array('HTML_QuickForm2_Rule_Compare', null,
|
||||
array('operator' => '!==')),
|
||||
'lt' => array('HTML_QuickForm2_Rule_Compare', null,
|
||||
array('operator' => '<')),
|
||||
'lte' => array('HTML_QuickForm2_Rule_Compare', null,
|
||||
array('operator' => '<=')),
|
||||
'gt' => array('HTML_QuickForm2_Rule_Compare', null,
|
||||
array('operator' => '>')),
|
||||
'gte' => array('HTML_QuickForm2_Rule_Compare', null,
|
||||
array('operator' => '>=')),
|
||||
'regex' => array('HTML_QuickForm2_Rule_Regex', null),
|
||||
'callback' => array('HTML_QuickForm2_Rule_Callback', null),
|
||||
'length' => array('HTML_QuickForm2_Rule_Length', null),
|
||||
'minlength' => array('HTML_QuickForm2_Rule_Length', null,
|
||||
array('max' => 0)),
|
||||
'maxlength' => array('HTML_QuickForm2_Rule_Length', null,
|
||||
array('min' => 0)),
|
||||
'maxfilesize' => array('HTML_QuickForm2_Rule_MaxFileSize', null),
|
||||
'mimetype' => array('HTML_QuickForm2_Rule_MimeType', null),
|
||||
'each' => array('HTML_QuickForm2_Rule_Each', null),
|
||||
'notcallback' => array('HTML_QuickForm2_Rule_NotCallback', null),
|
||||
'notregex' => array('HTML_QuickForm2_Rule_NotRegex', null)
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Registers a new element type
|
||||
*
|
||||
* @param string Type name (treated case-insensitively)
|
||||
* @param string Class name
|
||||
* @param string File containing the class, leave empty if class already loaded
|
||||
*/
|
||||
public static function registerElement($type, $className, $includeFile = null)
|
||||
{
|
||||
self::$elementTypes[strtolower($type)] = array($className, $includeFile);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether an element type is known to factory
|
||||
*
|
||||
* @param string Type name (treated case-insensitively)
|
||||
* @return bool
|
||||
*/
|
||||
public static function isElementRegistered($type)
|
||||
{
|
||||
return isset(self::$elementTypes[strtolower($type)]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new element object of the given type
|
||||
*
|
||||
* @param string Type name (treated case-insensitively)
|
||||
* @param mixed Element name (passed to element's constructor)
|
||||
* @param mixed Element attributes (passed to element's constructor)
|
||||
* @param array Element-specific data (passed to element's constructor)
|
||||
* @return HTML_QuickForm2_Node A created element
|
||||
* @throws HTML_QuickForm2_InvalidArgumentException If type name is unknown
|
||||
* @throws HTML_QuickForm2_NotFoundException If class for the element can
|
||||
* not be found and/or loaded from file
|
||||
*/
|
||||
public static function createElement($type, $name = null, $attributes = null,
|
||||
array $data = array())
|
||||
{
|
||||
$type = strtolower($type);
|
||||
if (!isset(self::$elementTypes[$type])) {
|
||||
throw new HTML_QuickForm2_InvalidArgumentException("Element type '$type' is not known");
|
||||
}
|
||||
list($className, $includeFile) = self::$elementTypes[$type];
|
||||
if (!class_exists($className)) {
|
||||
HTML_QuickForm2_Loader::loadClass($className, $includeFile);
|
||||
}
|
||||
return new $className($name, $attributes, $data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Registers a new rule type
|
||||
*
|
||||
* @param string Rule type name (treated case-insensitively)
|
||||
* @param string Class name
|
||||
* @param string File containing the class, leave empty if class already loaded
|
||||
* @param mixed Configuration data for rules of the given type
|
||||
*/
|
||||
public static function registerRule($type, $className, $includeFile = null,
|
||||
$config = null)
|
||||
{
|
||||
self::$registeredRules[strtolower($type)] = array($className, $includeFile, $config);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether a rule type is known to Factory
|
||||
*
|
||||
* @param string Rule type name (treated case-insensitively)
|
||||
* @return bool
|
||||
*/
|
||||
public static function isRuleRegistered($type)
|
||||
{
|
||||
return isset(self::$registeredRules[strtolower($type)]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new Rule of the given type
|
||||
*
|
||||
* @param string Rule type name (treated case-insensitively)
|
||||
* @param HTML_QuickForm2_Node Element to validate by the rule
|
||||
* @param string Message to display if validation fails
|
||||
* @param mixed Configuration data for the rule
|
||||
* @return HTML_QuickForm2_Rule A created Rule
|
||||
* @throws HTML_QuickForm2_InvalidArgumentException If rule type is unknown
|
||||
* @throws HTML_QuickForm2_NotFoundException If class for the rule
|
||||
* can't be found and/or loaded from file
|
||||
*/
|
||||
public static function createRule($type, HTML_QuickForm2_Node $owner,
|
||||
$message = '', $config = null)
|
||||
{
|
||||
$type = strtolower($type);
|
||||
if (!isset(self::$registeredRules[$type])) {
|
||||
throw new HTML_QuickForm2_InvalidArgumentException("Rule '$type' is not known");
|
||||
}
|
||||
list($className, $includeFile) = self::$registeredRules[$type];
|
||||
if (!class_exists($className)) {
|
||||
HTML_QuickForm2_Loader::loadClass($className, $includeFile);
|
||||
}
|
||||
if (isset(self::$registeredRules[$type][2])) {
|
||||
$config = call_user_func(array($className, 'mergeConfig'), $config,
|
||||
self::$registeredRules[$type][2]);
|
||||
}
|
||||
return new $className($owner, $message, $config);
|
||||
}
|
||||
}
|
||||
?>
|
||||
121
www/analytics/libs/HTML/QuickForm2/JavascriptBuilder.php
Normal file
121
www/analytics/libs/HTML/QuickForm2/JavascriptBuilder.php
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
<?php
|
||||
/**
|
||||
* Javascript aggregator and builder class
|
||||
*
|
||||
* 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: JavascriptBuilder.php 299480 2010-05-19 06:55:03Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Exception classes for HTML_QuickForm2
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Exception.php';
|
||||
require_once dirname(__FILE__) . '/Exception.php';
|
||||
|
||||
/**
|
||||
* Javascript aggregator and builder class
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_JavascriptBuilder
|
||||
{
|
||||
/**
|
||||
* Client-side rules
|
||||
* @var array
|
||||
*/
|
||||
protected $rules = array();
|
||||
|
||||
/**
|
||||
* Current form ID
|
||||
* @var string
|
||||
*/
|
||||
protected $formId = null;
|
||||
|
||||
/**
|
||||
* Sets the form currently being processed
|
||||
*
|
||||
* @param HTML_QuickForm2
|
||||
*/
|
||||
public function startForm(HTML_QuickForm2 $form)
|
||||
{
|
||||
$this->formId = $form->getId();
|
||||
$this->rules[$this->formId] = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the Rule javascript to the list of current form Rules
|
||||
*
|
||||
* @param HTML_QuickForm2_Rule
|
||||
*/
|
||||
public function addRule(HTML_QuickForm2_Rule $rule)
|
||||
{
|
||||
$this->rules[$this->formId][] = $rule->getJavascript();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns client-side validation code
|
||||
*
|
||||
* @todo This shouldn't probably be __toString() as we can't throw exceptions from that
|
||||
* @todo Of course we shouldn't put library files into each page, need some means to include them via <script> tags
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
$js = '';
|
||||
foreach ($this->rules as $formId => $rules) {
|
||||
if (!empty($rules)) {
|
||||
$js .= "new qf.validator(document.getElementById('{$formId}'), [\n" .
|
||||
implode(",\n", $rules) .
|
||||
"\n]);";
|
||||
}
|
||||
}
|
||||
if ('' != $js) {
|
||||
$js = "<script type=\"text/javascript\">\n//<![CDATA[\n" .
|
||||
file_get_contents('@data_dir@/HTML_QuickForm2/quickform.js') .
|
||||
"qf.events.contentReady(function() {\n{$js}\n});\n" .
|
||||
"//]]>\n</script>";
|
||||
}
|
||||
return $js;
|
||||
}
|
||||
}
|
||||
?>
|
||||
141
www/analytics/libs/HTML/QuickForm2/Loader.php
Normal file
141
www/analytics/libs/HTML/QuickForm2/Loader.php
Normal file
|
|
@ -0,0 +1,141 @@
|
|||
<?php
|
||||
/**
|
||||
* Class with static methods for loading classes and files
|
||||
*
|
||||
* 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: Loader.php 294057 2010-01-26 21:10:28Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Exception classes for HTML_QuickForm2
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Exception.php';
|
||||
require_once dirname(__FILE__) . '/Exception.php';
|
||||
|
||||
/**
|
||||
* Class with static methods for loading classes and files
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Loader
|
||||
{
|
||||
/**
|
||||
* Tries to load a given class
|
||||
*
|
||||
* If no $includeFile was provided, $className will be used with underscores
|
||||
* replaced with path separators and '.php' extension appended
|
||||
*
|
||||
* @param string Class name to load
|
||||
* @param string Name of the file (supposedly) containing the given class
|
||||
* @throws HTML_QuickForm2_NotFoundException If the file either can't be
|
||||
* loaded or doesn't contain the given class
|
||||
*/
|
||||
public static function loadClass($className, $includeFile = null)
|
||||
{
|
||||
if (class_exists($className, false) || interface_exists($className, false)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (empty($includeFile)) {
|
||||
$includeFile = str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
|
||||
}
|
||||
// Do not silence the errors with @, parse errors will not be seen
|
||||
include $includeFile;
|
||||
|
||||
// Still no class?
|
||||
if (!class_exists($className, false) && !interface_exists($className, false)) {
|
||||
if (!self::fileExists($includeFile)) {
|
||||
throw new HTML_QuickForm2_NotFoundException(
|
||||
"File '$includeFile' was not found"
|
||||
);
|
||||
} else {
|
||||
throw new HTML_QuickForm2_NotFoundException(
|
||||
"Class '$className' was not found within file '$includeFile'"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the file exists in the include path
|
||||
*
|
||||
* @param string file name
|
||||
* @return bool
|
||||
*/
|
||||
public static function fileExists($fileName)
|
||||
{
|
||||
$fp = @fopen($fileName, 'r', true);
|
||||
if (is_resource($fp)) {
|
||||
fclose($fp);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loading of HTML_QuickForm2_* classes suitable for SPL autoload mechanism
|
||||
*
|
||||
* This method will only try to load a class if its name starts with
|
||||
* HTML_QuickForm2. Register with the following:
|
||||
* <code>
|
||||
* spl_autoload_register(array('HTML_QuickForm2_Loader', 'autoload'));
|
||||
* </code>
|
||||
*
|
||||
* @param string Class name
|
||||
* @return bool Whether class loaded successfully
|
||||
*/
|
||||
public static function autoload($class)
|
||||
{
|
||||
if (0 !== strpos($class, 'HTML_QuickForm2')) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
@self::loadClass($class);
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
693
www/analytics/libs/HTML/QuickForm2/Node.php
Normal file
693
www/analytics/libs/HTML/QuickForm2/Node.php
Normal file
|
|
@ -0,0 +1,693 @@
|
|||
<?php
|
||||
/**
|
||||
* Base class for all HTML_QuickForm2 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>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SVN: $Id: Node.php 300747 2010-06-25 16:16:50Z mansion $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* HTML_Common2 - base class for HTML elements
|
||||
*/
|
||||
// require_once 'HTML/Common2.php';
|
||||
|
||||
// By default, we generate element IDs with numeric indexes appended even for
|
||||
// elements with unique names. If you want IDs to be equal to the element
|
||||
// names by default, set this configuration option to false.
|
||||
if (null === HTML_Common2::getOption('id_force_append_index')) {
|
||||
HTML_Common2::setOption('id_force_append_index', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception classes for HTML_QuickForm2
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Exception.php';
|
||||
require_once dirname(__FILE__) . '/Exception.php';
|
||||
|
||||
/**
|
||||
* Static factory class for QuickForm2 elements
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Factory.php';
|
||||
|
||||
/**
|
||||
* Base class for HTML_QuickForm2 rules
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Rule.php';
|
||||
|
||||
|
||||
/**
|
||||
* Abstract base class for all QuickForm2 Elements and Containers
|
||||
*
|
||||
* This class is mostly here to define the interface that should be implemented
|
||||
* by the subclasses. It also contains static methods handling generation
|
||||
* of unique ids for elements which do not have ids explicitly set.
|
||||
*
|
||||
* @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_Node extends HTML_Common2
|
||||
{
|
||||
/**
|
||||
* Array containing the parts of element ids
|
||||
* @var array
|
||||
*/
|
||||
protected static $ids = array();
|
||||
|
||||
/**
|
||||
* Element's "frozen" status
|
||||
* @var boolean
|
||||
*/
|
||||
protected $frozen = false;
|
||||
|
||||
/**
|
||||
* Whether element's value should persist when element is frozen
|
||||
* @var boolean
|
||||
*/
|
||||
protected $persistent = false;
|
||||
|
||||
/**
|
||||
* Element containing current
|
||||
* @var HTML_QuickForm2_Container
|
||||
*/
|
||||
protected $container = null;
|
||||
|
||||
/**
|
||||
* Contains options and data used for the element creation
|
||||
* @var array
|
||||
*/
|
||||
protected $data = array();
|
||||
|
||||
/**
|
||||
* Validation rules for element
|
||||
* @var array
|
||||
*/
|
||||
protected $rules = array();
|
||||
|
||||
/**
|
||||
* An array of callback filters for element
|
||||
* @var array
|
||||
*/
|
||||
protected $filters = array();
|
||||
|
||||
/**
|
||||
* Error message (usually set via Rule if validation fails)
|
||||
* @var string
|
||||
*/
|
||||
protected $error = null;
|
||||
|
||||
/**
|
||||
* Changing 'name' and 'id' attributes requires some special handling
|
||||
* @var array
|
||||
*/
|
||||
protected $watchedAttributes = array('id', 'name');
|
||||
|
||||
/**
|
||||
* Intercepts setting 'name' and 'id' attributes
|
||||
*
|
||||
* These attributes should always be present and thus trying to remove them
|
||||
* will result in an exception. Changing their values is delegated to
|
||||
* setName() and setId() methods, respectively
|
||||
*
|
||||
* @param string Attribute name
|
||||
* @param string Attribute value, null if attribute is being removed
|
||||
* @throws HTML_QuickForm2_InvalidArgumentException if trying to
|
||||
* remove a required attribute
|
||||
*/
|
||||
protected function onAttributeChange($name, $value = null)
|
||||
{
|
||||
if ('name' == $name) {
|
||||
if (null === $value) {
|
||||
throw new HTML_QuickForm2_InvalidArgumentException(
|
||||
"Required attribute 'name' can not be removed"
|
||||
);
|
||||
} else {
|
||||
$this->setName($value);
|
||||
}
|
||||
} elseif ('id' == $name) {
|
||||
if (null === $value) {
|
||||
throw new HTML_QuickForm2_InvalidArgumentException(
|
||||
"Required attribute 'id' can not be removed"
|
||||
);
|
||||
} else {
|
||||
$this->setId($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string Element name
|
||||
* @param mixed Attributes (either a string or an array)
|
||||
* @param array Element data (label, options and data used for element creation)
|
||||
*/
|
||||
public function __construct($name = null, $attributes = null, $data = null)
|
||||
{
|
||||
parent::__construct($attributes);
|
||||
$this->setName($name);
|
||||
// Autogenerating the id if not set on previous steps
|
||||
if ('' == $this->getId()) {
|
||||
$this->setId();
|
||||
}
|
||||
if (!empty($data)) {
|
||||
$this->data = array_merge($this->data, $data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates an id for the element
|
||||
*
|
||||
* Called when an element is created without explicitly given id
|
||||
*
|
||||
* @param string Element name
|
||||
* @return string The generated element id
|
||||
*/
|
||||
protected static function generateId($elementName)
|
||||
{
|
||||
$stop = !self::getOption('id_force_append_index');
|
||||
$tokens = strlen($elementName)
|
||||
? explode('[', str_replace(']', '', $elementName))
|
||||
: ($stop? array('qfauto', ''): array('qfauto'));
|
||||
$container =& self::$ids;
|
||||
$id = '';
|
||||
|
||||
do {
|
||||
$token = array_shift($tokens);
|
||||
// Handle the 'array[]' names
|
||||
if ('' === $token) {
|
||||
if (empty($container)) {
|
||||
$token = 0;
|
||||
} else {
|
||||
$keys = array_keys($container);
|
||||
$token = end($keys);
|
||||
while (isset($container[$token])) {
|
||||
$token++;
|
||||
}
|
||||
}
|
||||
}
|
||||
$id .= '-' . $token;
|
||||
if (!isset($container[$token])) {
|
||||
$container[$token] = array();
|
||||
// Handle duplicate names when not having mandatory indexes
|
||||
} elseif (empty($tokens) && $stop) {
|
||||
$tokens[] = '';
|
||||
}
|
||||
// Handle mandatory indexes
|
||||
if (empty($tokens) && !$stop) {
|
||||
$tokens[] = '';
|
||||
$stop = true;
|
||||
}
|
||||
$container =& $container[$token];
|
||||
} while (!empty($tokens));
|
||||
|
||||
return substr($id, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Stores the explicitly given id to prevent duplicate id generation
|
||||
*
|
||||
* @param string Element id
|
||||
*/
|
||||
protected static function storeId($id)
|
||||
{
|
||||
$tokens = explode('-', $id);
|
||||
$container =& self::$ids;
|
||||
|
||||
do {
|
||||
$token = array_shift($tokens);
|
||||
if (!isset($container[$token])) {
|
||||
$container[$token] = array();
|
||||
}
|
||||
$container =& $container[$token];
|
||||
} while (!empty($tokens));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the element options
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getData()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the element's type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract public function getType();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the element's name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return isset($this->attributes['name'])? $this->attributes['name']: null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the element's name
|
||||
*
|
||||
* @param string
|
||||
* @return HTML_QuickForm2_Node
|
||||
*/
|
||||
abstract public function setName($name);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the element's id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return isset($this->attributes['id'])? $this->attributes['id']: null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the elements id
|
||||
*
|
||||
* Please note that elements should always have an id in QuickForm2 and
|
||||
* therefore it will not be possible to remove the element's id or set it to
|
||||
* an empty value. If id is not explicitly given, it will be autogenerated.
|
||||
*
|
||||
* @param string Element's id, will be autogenerated if not given
|
||||
* @return HTML_QuickForm2_Node
|
||||
*/
|
||||
public function setId($id = null)
|
||||
{
|
||||
if (is_null($id)) {
|
||||
$id = self::generateId($this->getName());
|
||||
} else {
|
||||
self::storeId($id);
|
||||
}
|
||||
$this->attributes['id'] = (string)$id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the element's value
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function getValue();
|
||||
|
||||
|
||||
/**
|
||||
* Sets the element's value
|
||||
*
|
||||
* @param mixed
|
||||
* @return HTML_QuickForm2_Node
|
||||
*/
|
||||
abstract public function setValue($value);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the element's label(s)
|
||||
*
|
||||
* @return string|array
|
||||
*/
|
||||
public function getLabel()
|
||||
{
|
||||
if (isset($this->data['label'])) {
|
||||
return $this->data['label'];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the element's label(s)
|
||||
*
|
||||
* @param string|array Label for the element (may be an array of labels)
|
||||
* @return HTML_QuickForm2_Node
|
||||
*/
|
||||
public function setLabel($label)
|
||||
{
|
||||
$this->data['label'] = $label;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Changes the element's frozen status
|
||||
*
|
||||
* @param bool Whether the element should be frozen or editable. If
|
||||
* omitted, the method will not change the frozen status,
|
||||
* just return its current value
|
||||
* @return bool Old value of element's frozen status
|
||||
*/
|
||||
public function toggleFrozen($freeze = null)
|
||||
{
|
||||
$old = $this->frozen;
|
||||
if (null !== $freeze) {
|
||||
$this->frozen = (bool)$freeze;
|
||||
}
|
||||
return $old;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Changes the element's persistent freeze behaviour
|
||||
*
|
||||
* If persistent freeze is on, the element's value will be kept (and
|
||||
* submitted) in a hidden field when the element is frozen.
|
||||
*
|
||||
* @param bool New value for "persistent freeze". If omitted, the
|
||||
* method will not set anything, just return the current
|
||||
* value of the flag.
|
||||
* @return bool Old value of "persistent freeze" flag
|
||||
*/
|
||||
public function persistentFreeze($persistent = null)
|
||||
{
|
||||
$old = $this->persistent;
|
||||
if (null !== $persistent) {
|
||||
$this->persistent = (bool)$persistent;
|
||||
}
|
||||
return $old;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds the link to the element containing current
|
||||
*
|
||||
* @param HTML_QuickForm2_Container Element containing the current one,
|
||||
* null if the link should really be
|
||||
* removed (if removing from container)
|
||||
* @throws HTML_QuickForm2_InvalidArgumentException If trying to set a
|
||||
* child of an element as its container
|
||||
*/
|
||||
protected function setContainer(HTML_QuickForm2_Container $container = null)
|
||||
{
|
||||
if (null !== $container) {
|
||||
$check = $container;
|
||||
do {
|
||||
if ($this === $check) {
|
||||
throw new HTML_QuickForm2_InvalidArgumentException(
|
||||
'Cannot set an element or its child as its own container'
|
||||
);
|
||||
}
|
||||
} while ($check = $check->getContainer());
|
||||
if (null !== $this->container && $container !== $this->container) {
|
||||
$this->container->removeChild($this);
|
||||
}
|
||||
}
|
||||
$this->container = $container;
|
||||
if (null !== $container) {
|
||||
$this->updateValue();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the element containing current
|
||||
*
|
||||
* @return HTML_QuickForm2_Container|null
|
||||
*/
|
||||
public function getContainer()
|
||||
{
|
||||
return $this->container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the data sources for this element
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getDataSources()
|
||||
{
|
||||
if (empty($this->container)) {
|
||||
return array();
|
||||
} else {
|
||||
return $this->container->getDataSources();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the element needs to update its value from form's data sources
|
||||
*/
|
||||
abstract public function updateValue();
|
||||
|
||||
/**
|
||||
* Adds a validation rule
|
||||
*
|
||||
* @param HTML_QuickForm2_Rule|string Validation rule or rule type
|
||||
* @param string|int If first parameter is rule type, then
|
||||
* message to display if validation fails, otherwise constant showing
|
||||
* whether to perfom validation client-side and/or server-side
|
||||
* @param mixed Additional data for the rule
|
||||
* @param int Whether to perfom validation server-side
|
||||
* and/or client side. Combination of HTML_QuickForm2_Rule::RUNAT_* constants
|
||||
* @return HTML_QuickForm2_Rule The added rule
|
||||
* @throws HTML_QuickForm2_InvalidArgumentException if $rule is of a
|
||||
* wrong type or rule name isn't registered with Factory
|
||||
* @throws HTML_QuickForm2_NotFoundException if class for a given rule
|
||||
* name cannot be found
|
||||
* @todo Need some means to mark the Rules for running client-side
|
||||
*/
|
||||
public function addRule($rule, $messageOrRunAt = '', $options = null,
|
||||
$runAt = HTML_QuickForm2_Rule::RUNAT_SERVER)
|
||||
{
|
||||
if ($rule instanceof HTML_QuickForm2_Rule) {
|
||||
$rule->setOwner($this);
|
||||
$runAt = '' == $messageOrRunAt? HTML_QuickForm2_Rule::RUNAT_SERVER: $messageOrRunAt;
|
||||
} elseif (is_string($rule)) {
|
||||
$rule = HTML_QuickForm2_Factory::createRule($rule, $this, $messageOrRunAt, $options);
|
||||
} else {
|
||||
throw new HTML_QuickForm2_InvalidArgumentException(
|
||||
'addRule() expects either a rule type or ' .
|
||||
'a HTML_QuickForm2_Rule instance'
|
||||
);
|
||||
}
|
||||
|
||||
$this->rules[] = array($rule, $runAt);
|
||||
return $rule;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a validation rule
|
||||
*
|
||||
* The method will *not* throw an Exception if the rule wasn't added to the
|
||||
* element.
|
||||
*
|
||||
* @param HTML_QuickForm2_Rule Validation rule to remove
|
||||
* @return HTML_QuickForm2_Rule Removed rule
|
||||
*/
|
||||
public function removeRule(HTML_QuickForm2_Rule $rule)
|
||||
{
|
||||
foreach ($this->rules as $i => $r) {
|
||||
if ($r[0] === $rule) {
|
||||
unset($this->rules[$i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $rule;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a validation rule
|
||||
*
|
||||
* This method is mostly useful when when chaining several rules together
|
||||
* via {@link HTML_QuickForm2_Rule::and_()} and {@link HTML_QuickForm2_Rule::or_()}
|
||||
* methods:
|
||||
* <code>
|
||||
* $first->addRule('nonempty', 'Fill in either first or second field')
|
||||
* ->or_($second->createRule('nonempty'));
|
||||
* </code>
|
||||
*
|
||||
* @param string Rule type
|
||||
* @param string Message to display if validation fails
|
||||
* @param mixed Additional data for the rule
|
||||
* @return HTML_QuickForm2_Rule The created rule
|
||||
* @throws HTML_QuickForm2_InvalidArgumentException If rule type is unknown
|
||||
* @throws HTML_QuickForm2_NotFoundException If class for the rule
|
||||
* can't be found and/or loaded from file
|
||||
*/
|
||||
public function createRule($type, $message = '', $options = null)
|
||||
{
|
||||
return HTML_QuickForm2_Factory::createRule($type, $this, $message, $options);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether an element is required
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isRequired()
|
||||
{
|
||||
foreach ($this->rules as $rule) {
|
||||
if ($rule[0] instanceof HTML_QuickForm2_Rule_Required) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Performs the server-side validation
|
||||
*
|
||||
* @return boolean Whether the element is valid
|
||||
*/
|
||||
protected function validate()
|
||||
{
|
||||
foreach ($this->rules as $rule) {
|
||||
if (strlen($this->error)) {
|
||||
break;
|
||||
}
|
||||
if ($rule[1] & HTML_QuickForm2_Rule::RUNAT_SERVER) {
|
||||
$rule[0]->validate();
|
||||
}
|
||||
}
|
||||
return !strlen($this->error);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the error message to the element
|
||||
*
|
||||
* @param string
|
||||
* @return HTML_QuickForm2_Node
|
||||
*/
|
||||
public function setError($error = null)
|
||||
{
|
||||
$this->error = (string)$error;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the error message for the element
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getError()
|
||||
{
|
||||
return $this->error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Javascript code for getting the element's value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract public function getJavascriptValue();
|
||||
|
||||
/**
|
||||
* Adds a filter
|
||||
*
|
||||
* A filter is simply a PHP callback which will be applied to the element value
|
||||
* when getValue() is called. A filter is by default applied recursively :
|
||||
* if the value is an array, each elements it contains will
|
||||
* also be filtered, unless the recursive flag is set to false.
|
||||
*
|
||||
* @param callback The PHP callback used for filter
|
||||
* @param array Optional arguments for the callback. The first parameter
|
||||
* will always be the element value, then these options will
|
||||
* be used as parameters for the callback.
|
||||
* @param bool Whether to apply the filter recursively to contained elements
|
||||
* @return HTML_QuickForm2_Node The element
|
||||
* @throws HTML_QuickForm2_InvalidArgumentException If callback is incorrect
|
||||
*/
|
||||
public function addFilter($callback, array $options = null, $recursive = true)
|
||||
{
|
||||
if (!is_callable($callback, false, $callbackName)) {
|
||||
throw new HTML_QuickForm2_InvalidArgumentException(
|
||||
'Callback Filter requires a valid callback, \'' . $callbackName .
|
||||
'\' was given'
|
||||
);
|
||||
}
|
||||
$this->filters[] = array($callback, $options, 'recursive' => $recursive);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all element filters
|
||||
*/
|
||||
public function removeFilters()
|
||||
{
|
||||
$this->filters = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies element filters on element value
|
||||
* @param mixed Element value
|
||||
* @return mixed Filtered value
|
||||
*/
|
||||
protected function applyFilters($value)
|
||||
{
|
||||
foreach ($this->filters as $filter) {
|
||||
if (is_array($value) && !empty($filter['recursive'])) {
|
||||
array_walk_recursive($value,
|
||||
array('HTML_QuickForm2_Node', 'applyFilter'), $filter);
|
||||
} else {
|
||||
self::applyFilter($value, null, $filter);
|
||||
}
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
protected static function applyFilter(&$value, $key = null, $filter)
|
||||
{
|
||||
$callback = $filter[0];
|
||||
$options = $filter[1];
|
||||
if (!is_array($options)) {
|
||||
$options = array();
|
||||
}
|
||||
array_unshift($options, $value);
|
||||
$value = call_user_func_array($callback, $options);
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
367
www/analytics/libs/HTML/QuickForm2/Renderer.php
Normal file
367
www/analytics/libs/HTML/QuickForm2/Renderer.php
Normal file
|
|
@ -0,0 +1,367 @@
|
|||
<?php
|
||||
/**
|
||||
* Base class for HTML_QuickForm2 renderers
|
||||
*
|
||||
* 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: Renderer.php 299706 2010-05-24 18:32:37Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
use Piwik\Plugin;
|
||||
|
||||
/**
|
||||
* Class with static methods for loading classes and files
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Loader.php';
|
||||
|
||||
/**
|
||||
* Abstract base class for QuickForm2 renderers
|
||||
*
|
||||
* This class serves two main purposes:
|
||||
* <ul>
|
||||
* <li>Defines the API all renderers should implement (render*() methods);</li>
|
||||
* <li>Provides static methods for registering renderers and their plugins
|
||||
* and {@link factory()} method for creating renderer instances.</li>
|
||||
* </ul>
|
||||
*
|
||||
* Note that renderers should always be instantiated through factory(), in the
|
||||
* other case it will not be possible to add plugins.
|
||||
*
|
||||
* @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
|
||||
{
|
||||
/**
|
||||
* List of registered renderer types
|
||||
* @var array
|
||||
*/
|
||||
private static $_types = array(
|
||||
'default' => array('HTML_QuickForm2_Renderer_Default', null),
|
||||
'array' => array('HTML_QuickForm2_Renderer_Array', null)
|
||||
);
|
||||
|
||||
/**
|
||||
* List of registered renderer plugins
|
||||
* @var array
|
||||
*/
|
||||
private static $_pluginClasses = array(
|
||||
'default' => array(),
|
||||
'array' => array()
|
||||
);
|
||||
|
||||
/**
|
||||
* Renderer options
|
||||
* @var array
|
||||
* @see setOption()
|
||||
*/
|
||||
protected $options = array(
|
||||
'group_hiddens' => true,
|
||||
'required_note' => '<em>*</em> denotes required fields.',
|
||||
'errors_prefix' => 'Invalid information entered:',
|
||||
'errors_suffix' => 'Please correct these fields.',
|
||||
'group_errors' => false
|
||||
);
|
||||
|
||||
/**
|
||||
* Javascript builder object
|
||||
* @var HTML_QuickForm2_JavascriptBuilder
|
||||
*/
|
||||
protected $jsBuilder;
|
||||
|
||||
/**
|
||||
* Creates a new renderer instance of the given type
|
||||
*
|
||||
* A renderer is always wrapped by a Proxy, which handles calling its
|
||||
* "published" methods and methods of its plugins. Registered plugins are
|
||||
* added automagically to the existing renderer instances so that
|
||||
* <code>
|
||||
* $foo = HTML_QuickForm2_Renderer::factory('foo');
|
||||
* // Plugin implementing bar() method
|
||||
* HTML_QuickForm2_Renderer::registerPlugin('foo', 'Plugin_Foo_Bar');
|
||||
* $foo->bar();
|
||||
* </code>
|
||||
* will work.
|
||||
*
|
||||
* @param string Type name (treated case-insensitively)
|
||||
* @return HTML_QuickForm2_Renderer_Proxy A renderer instance of the given
|
||||
* type wrapped by a Proxy
|
||||
* @throws HTML_QuickForm2_InvalidArgumentException If type name is unknown
|
||||
* @throws HTML_QuickForm2_NotFoundException If class for the renderer can
|
||||
* not be found and/or loaded from file
|
||||
*/
|
||||
final public static function factory($type)
|
||||
{
|
||||
$type = strtolower($type);
|
||||
if (!isset(self::$_types[$type])) {
|
||||
throw new HTML_QuickForm2_InvalidArgumentException(
|
||||
"Renderer type '$type' is not known"
|
||||
);
|
||||
}
|
||||
|
||||
list ($className, $includeFile) = self::$_types[$type];
|
||||
if (!class_exists($className)) {
|
||||
HTML_QuickForm2_Loader::loadClass($className, $includeFile);
|
||||
}
|
||||
if (!class_exists('HTML_QuickForm2_Renderer_Proxy')) {
|
||||
HTML_QuickForm2_Loader::loadClass('HTML_QuickForm2_Renderer_Proxy');
|
||||
}
|
||||
return new HTML_QuickForm2_Renderer_Proxy(new $className, self::$_pluginClasses[$type]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a new renderer type
|
||||
*
|
||||
* @param string Type name (treated case-insensitively)
|
||||
* @param string Class name
|
||||
* @param string File containing the class, leave empty if class already loaded
|
||||
* @throws HTML_QuickForm2_InvalidArgumentException if type already registered
|
||||
*/
|
||||
final public static function register($type, $className, $includeFile = null)
|
||||
{
|
||||
$type = strtolower($type);
|
||||
if (!empty(self::$_types[$type])) {
|
||||
throw new HTML_QuickForm2_InvalidArgumentException(
|
||||
"Renderer type '$type' is already registered"
|
||||
);
|
||||
}
|
||||
self::$_types[$type] = array($className, $includeFile);
|
||||
if (empty(self::$_pluginClasses[$type])) {
|
||||
self::$_pluginClasses[$type] = array();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a plugin for a renderer type
|
||||
*
|
||||
* @param string Renderer type name (treated case-insensitively)
|
||||
* @param string Plugin class name
|
||||
* @param string File containing the plugin class, leave empty if class already loaded
|
||||
* @throws HTML_QuickForm2_InvalidArgumentException if plugin is already registered
|
||||
*/
|
||||
final public static function registerPlugin($type, $className, $includeFile = null)
|
||||
{
|
||||
$type = strtolower($type);
|
||||
// We don't check self::$_types, since a plugin may be registered
|
||||
// before renderer itself if it goes with some custom element
|
||||
if (empty(self::$_pluginClasses[$type])) {
|
||||
self::$_pluginClasses[$type] = array(array($className, $includeFile));
|
||||
} else {
|
||||
foreach (self::$_pluginClasses[$type] as $plugin) {
|
||||
if (0 == strcasecmp($plugin[0], $className)) {
|
||||
throw new HTML_QuickForm2_InvalidArgumentException(
|
||||
"Plugin '$className' for renderer type '$type' is already registered"
|
||||
);
|
||||
}
|
||||
}
|
||||
self::$_pluginClasses[$type][] = array($className, $includeFile);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Renderer instances should not be created directly, use {@link factory()}
|
||||
*/
|
||||
protected function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of "published" method names that should be callable through proxy
|
||||
*
|
||||
* Methods defined in HTML_QuickForm2_Renderer are proxied automatically,
|
||||
* only additional methods should be returned.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function exportMethods()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the option(s) affecting renderer behaviour
|
||||
*
|
||||
* The following options are available:
|
||||
* <ul>
|
||||
* <li>'group_hiddens' - whether to group hidden elements together or
|
||||
* render them where they were added (boolean)</li>
|
||||
* <li>'group_errors' - whether to group error messages or render them
|
||||
* alongside elements they apply to (boolean)</li>
|
||||
* <li>'errors_prefix' - leading message for grouped errors (string)</li>
|
||||
* <li>'errors_suffix' - trailing message for grouped errors (string)</li>
|
||||
* <li>'required_note' - note displayed if the form contains required
|
||||
* elements (string)</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param string|array option name or array ('option name' => 'option value')
|
||||
* @param mixed parameter value if $nameOrConfig is not an array
|
||||
* @return HTML_QuickForm2_Renderer
|
||||
* @throws HTML_QuickForm2_NotFoundException in case of unknown option
|
||||
*/
|
||||
public function setOption($nameOrOptions, $value = null)
|
||||
{
|
||||
if (is_array($nameOrOptions)) {
|
||||
foreach ($nameOrOptions as $name => $value) {
|
||||
$this->setOption($name, $value);
|
||||
}
|
||||
|
||||
} else {
|
||||
if (!array_key_exists($nameOrOptions, $this->options)) {
|
||||
throw new HTML_QuickForm2_NotFoundException(
|
||||
"Unknown option '{$nameOrOptions}'"
|
||||
);
|
||||
}
|
||||
$this->options[$nameOrOptions] = $value;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value(s) of the renderer option(s)
|
||||
*
|
||||
* @param string parameter name
|
||||
* @return mixed value of $name parameter, array of all configuration
|
||||
* parameters if $name is not given
|
||||
* @throws HTML_QuickForm2_NotFoundException in case of unknown option
|
||||
*/
|
||||
public function getOption($name = null)
|
||||
{
|
||||
if (null === $name) {
|
||||
return $this->options;
|
||||
} elseif (!array_key_exists($name, $this->options)) {
|
||||
throw new HTML_QuickForm2_NotFoundException(
|
||||
"Unknown option '{$name}'"
|
||||
);
|
||||
}
|
||||
return $this->options[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the javascript builder object
|
||||
*
|
||||
* @return HTML_QuickForm2_JavascriptBuilder
|
||||
*/
|
||||
public function getJavascriptBuilder()
|
||||
{
|
||||
if (empty($this->jsBuilder)) {
|
||||
if (!class_exists('HTML_QuickForm2_JavascriptBuilder')) {
|
||||
HTML_QuickForm2_Loader::loadClass('HTML_QuickForm2_JavascriptBuilder');
|
||||
}
|
||||
$this->jsBuilder = new HTML_QuickForm2_JavascriptBuilder();
|
||||
}
|
||||
return $this->jsBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the javascript builder object
|
||||
*
|
||||
* You may want to reuse the same builder object if outputting several
|
||||
* forms on one page.
|
||||
*
|
||||
* @param HTML_QuickForm2_JavascriptBuilder
|
||||
* @return HTML_QuickForm2_Renderer
|
||||
*/
|
||||
public function setJavascriptBuilder(HTML_QuickForm2_JavascriptBuilder $builder = null)
|
||||
{
|
||||
$this->jsBuilder = $builder;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a generic element
|
||||
*
|
||||
* @param HTML_QuickForm2_Node Element being rendered
|
||||
*/
|
||||
abstract public function renderElement(HTML_QuickForm2_Node $element);
|
||||
|
||||
/**
|
||||
* Renders a hidden element
|
||||
*
|
||||
* @param HTML_QuickForm2_Node Hidden element being rendered
|
||||
*/
|
||||
abstract public function renderHidden(HTML_QuickForm2_Node $element);
|
||||
|
||||
/**
|
||||
* Starts rendering a form, called before processing contained elements
|
||||
*
|
||||
* @param HTML_QuickForm2_Node Form being rendered
|
||||
*/
|
||||
abstract public function startForm(HTML_QuickForm2_Node $form);
|
||||
|
||||
/**
|
||||
* Finishes rendering a form, called after processing contained elements
|
||||
*
|
||||
* @param HTML_QuickForm2_Node Form being rendered
|
||||
*/
|
||||
abstract public function finishForm(HTML_QuickForm2_Node $form);
|
||||
|
||||
/**
|
||||
* Starts rendering a generic container, called before processing contained elements
|
||||
*
|
||||
* @param HTML_QuickForm2_Node Container being rendered
|
||||
*/
|
||||
abstract public function startContainer(HTML_QuickForm2_Node $container);
|
||||
|
||||
/**
|
||||
* Finishes rendering a generic container, called after processing contained elements
|
||||
*
|
||||
* @param HTML_QuickForm2_Node Container being rendered
|
||||
*/
|
||||
abstract public function finishContainer(HTML_QuickForm2_Node $container);
|
||||
|
||||
/**
|
||||
* Starts rendering a group, called before processing grouped elements
|
||||
*
|
||||
* @param HTML_QuickForm2_Node Group being rendered
|
||||
*/
|
||||
abstract public function startGroup(HTML_QuickForm2_Node $group);
|
||||
|
||||
/**
|
||||
* Finishes rendering a group, called after processing grouped elements
|
||||
*
|
||||
* @param HTML_QuickForm2_Node Group being rendered
|
||||
*/
|
||||
abstract public function finishGroup(HTML_QuickForm2_Node $group);
|
||||
}
|
||||
?>
|
||||
376
www/analytics/libs/HTML/QuickForm2/Renderer/Array.php
Normal file
376
www/analytics/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
www/analytics/libs/HTML/QuickForm2/Renderer/Default.php
Normal file
598
www/analytics/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
www/analytics/libs/HTML/QuickForm2/Renderer/Plugin.php
Normal file
69
www/analytics/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
www/analytics/libs/HTML/QuickForm2/Renderer/Proxy.php
Normal file
264
www/analytics/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
www/analytics/libs/HTML/QuickForm2/Renderer/Smarty.php
Normal file
292
www/analytics/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']];
|
||||
}
|
||||
}
|
||||
|
||||
/**#@-*/
|
||||
}
|
||||
333
www/analytics/libs/HTML/QuickForm2/Rule.php
Normal file
333
www/analytics/libs/HTML/QuickForm2/Rule.php
Normal file
|
|
@ -0,0 +1,333 @@
|
|||
<?php
|
||||
/**
|
||||
* Base class for HTML_QuickForm2 rules
|
||||
*
|
||||
* 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: Rule.php 299706 2010-05-24 18:32:37Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstract base class for HTML_QuickForm2 rules
|
||||
*
|
||||
* This class provides methods that allow chaining several rules together.
|
||||
* Its validate() method executes the whole rule chain starting from this rule.
|
||||
*
|
||||
* @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_Rule
|
||||
{
|
||||
/**
|
||||
* Constant showing that validation should be run server-side
|
||||
* @see HTML_QuickForm2_Node::addRule()
|
||||
*/
|
||||
const RUNAT_SERVER = 1;
|
||||
|
||||
/**
|
||||
* Constant showing that validation should be run client-side
|
||||
* @see HTML_QuickForm2_Node::addRule()
|
||||
*/
|
||||
const RUNAT_CLIENT = 2;
|
||||
|
||||
/**
|
||||
* An element whose value will be validated by this rule
|
||||
* @var HTML_QuickForm2_Node
|
||||
*/
|
||||
protected $owner;
|
||||
|
||||
/**
|
||||
* An error message to display if validation fails
|
||||
* @var string
|
||||
*/
|
||||
protected $message;
|
||||
|
||||
/**
|
||||
* Configuration data for the rule
|
||||
* @var mixed
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* Rules chained to this via "and" and "or" operators
|
||||
*
|
||||
* The contents can be described as "disjunctive normal form", where an outer
|
||||
* array represents a disjunction of conjunctive clauses represented by inner
|
||||
* arrays.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $chainedRules = array(array());
|
||||
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param HTML_QuickForm2_Node Element to validate
|
||||
* @param string Error message to display if validation fails
|
||||
* @param mixed Configuration data for the rule
|
||||
*/
|
||||
public function __construct(HTML_QuickForm2_Node $owner, $message = '', $config = null)
|
||||
{
|
||||
$this->setOwner($owner);
|
||||
$this->setMessage($message);
|
||||
$this->setConfig($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges local configuration with that provided for registerRule()
|
||||
*
|
||||
* Default behaviour is for global config to override local one, different
|
||||
* Rules may implement more complex merging behaviours.
|
||||
*
|
||||
* @param mixed Local configuration
|
||||
* @param mixed Global configuration, usually provided to {@link HTML_QuickForm2_Factory::registerRule()}
|
||||
* @return mixed Merged configuration
|
||||
*/
|
||||
public static function mergeConfig($localConfig, $globalConfig)
|
||||
{
|
||||
return is_null($globalConfig)? $localConfig: $globalConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets configuration data for the rule
|
||||
*
|
||||
* @param mixed Rule configuration data (specific for a Rule)
|
||||
* @return HTML_QuickForm2_Rule
|
||||
* @throws HTML_QuickForm2_InvalidArgumentException in case of invalid
|
||||
* configuration data
|
||||
*/
|
||||
public function setConfig($config)
|
||||
{
|
||||
$this->config = $config;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the rule's configuration data
|
||||
*
|
||||
* @return mixed Configuration data (specific for a Rule)
|
||||
*/
|
||||
public function getConfig()
|
||||
{
|
||||
return $this->config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the error message output by the rule
|
||||
*
|
||||
* @param string Error message to display if validation fails
|
||||
* @return HTML_QuickForm2_Rule
|
||||
*/
|
||||
public function setMessage($message)
|
||||
{
|
||||
$this->message = (string)$message;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the error message output by the rule
|
||||
*
|
||||
* @return string Error message
|
||||
*/
|
||||
public function getMessage()
|
||||
{
|
||||
return $this->message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the element that will be validated by this rule
|
||||
*
|
||||
* @param HTML_QuickForm2_Node Element to validate
|
||||
*/
|
||||
public function setOwner(HTML_QuickForm2_Node $owner)
|
||||
{
|
||||
if (null !== $this->owner) {
|
||||
$this->owner->removeRule($this);
|
||||
}
|
||||
$this->owner = $owner;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a rule to the chain with an "and" operator
|
||||
*
|
||||
* Evaluation is short-circuited, next rule will not be evaluated if the
|
||||
* previous one returns false. The method is named this way because "and" is
|
||||
* a reserved word in PHP.
|
||||
*
|
||||
* @param HTML_QuickForm2_Rule
|
||||
* @return HTML_QuickForm2_Rule first rule in the chain (i.e. $this)
|
||||
* @throws HTML_QuickForm2_InvalidArgumentException when trying to add
|
||||
* a "required" rule to the chain
|
||||
*/
|
||||
public function and_(HTML_QuickForm2_Rule $next)
|
||||
{
|
||||
if ($next instanceof HTML_QuickForm2_Rule_Required) {
|
||||
throw new HTML_QuickForm2_InvalidArgumentException(
|
||||
'and_(): Cannot add a "required" rule'
|
||||
);
|
||||
}
|
||||
$this->chainedRules[count($this->chainedRules) - 1][] = $next;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a rule to the chain with an "or" operator
|
||||
*
|
||||
* Evaluation is short-circuited, next rule will not be evaluated if the
|
||||
* previous one returns true. The method is named this way because "or" is
|
||||
* a reserved word in PHP.
|
||||
*
|
||||
* @param HTML_QuickForm2_Rule
|
||||
* @return HTML_QuickForm2_Rule first rule in the chain (i.e. $this)
|
||||
* @throws HTML_QuickForm2_InvalidArgumentException when trying to add
|
||||
* a "required" rule to the chain
|
||||
*/
|
||||
public function or_(HTML_QuickForm2_Rule $next)
|
||||
{
|
||||
if ($next instanceof HTML_QuickForm2_Rule_Required) {
|
||||
throw new HTML_QuickForm2_InvalidArgumentException(
|
||||
'or_(): Cannot add a "required" rule'
|
||||
);
|
||||
}
|
||||
$this->chainedRules[] = array($next);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs validation
|
||||
*
|
||||
* The whole rule chain is executed. Note that the side effect of this
|
||||
* method is setting the error message on element if validation fails
|
||||
*
|
||||
* @return boolean Whether the element is valid
|
||||
*/
|
||||
public function validate()
|
||||
{
|
||||
$globalValid = false;
|
||||
$localValid = $this->validateOwner();
|
||||
foreach ($this->chainedRules as $item) {
|
||||
foreach ($item as $multiplier) {
|
||||
if (!($localValid = $localValid && $multiplier->validate())) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($globalValid = $globalValid || $localValid) {
|
||||
break;
|
||||
}
|
||||
$localValid = true;
|
||||
}
|
||||
$globalValid or $this->setOwnerError();
|
||||
return $globalValid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the owner element
|
||||
*
|
||||
* @return bool Whether owner element is valid according to the rule
|
||||
*/
|
||||
abstract protected function validateOwner();
|
||||
|
||||
/**
|
||||
* Sets the error message on the owner element
|
||||
*/
|
||||
protected function setOwnerError()
|
||||
{
|
||||
if (strlen($this->getMessage()) && !$this->owner->getError()) {
|
||||
$this->owner->setError($this->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the client-side validation callback
|
||||
*
|
||||
* This essentially builds a Javascript version of validateOwner() method,
|
||||
* with element ID and Rule configuration hardcoded.
|
||||
*
|
||||
* @return string Javascript function to validate the element's value
|
||||
* @throws HTML_QuickForm2_Exception if Rule can only be run server-side
|
||||
*/
|
||||
protected function getJavascriptCallback()
|
||||
{
|
||||
throw new HTML_QuickForm2_Exception(
|
||||
get_class($this) . ' does not implement javascript validation'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the client-side representation of the Rule
|
||||
*
|
||||
* The Javascript object returned contains the following fields:
|
||||
* - callback: {@see getJavascriptCallback()}
|
||||
* - elementId: element ID to set error for if validation fails
|
||||
* - errorMessage: error message to set if validation fails
|
||||
* - chained: chained rules, array of arrays like in $chainedRules property
|
||||
*
|
||||
* @return string
|
||||
* @throws HTML_QuickForm2_Exception if Rule or its chained Rules can only
|
||||
* be run server-side
|
||||
*/
|
||||
public function getJavascript()
|
||||
{
|
||||
$js = "{\n\tcallback: " . $this->getJavascriptCallback() . ",\n" .
|
||||
"\telementId: '" . $this->owner->getId() . "',\n" .
|
||||
"\terrorMessage: '" . strtr($this->getMessage(), array(
|
||||
"\r" => '\r',
|
||||
"\n" => '\n',
|
||||
"\t" => '\t',
|
||||
"'" => "\\'",
|
||||
'"' => '\"',
|
||||
'\\' => '\\\\'
|
||||
)) . "',\n\tchained: [";
|
||||
$chained = array();
|
||||
foreach ($this->chainedRules as $item) {
|
||||
$multipliers = array();
|
||||
foreach ($item as $multiplier) {
|
||||
$multipliers[] = $multiplier->getJavascript();
|
||||
}
|
||||
$chained[] = '[' . implode(",\n", $multipliers) . ']';
|
||||
}
|
||||
$js .= implode(",\n", $chained) . "]\n}";
|
||||
return $js;
|
||||
}
|
||||
}
|
||||
?>
|
||||
172
www/analytics/libs/HTML/QuickForm2/Rule/Callback.php
Normal file
172
www/analytics/libs/HTML/QuickForm2/Rule/Callback.php
Normal file
|
|
@ -0,0 +1,172 @@
|
|||
<?php
|
||||
/**
|
||||
* Rule checking the value via a callback function (method)
|
||||
*
|
||||
* 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: Callback.php 294057 2010-01-26 21:10:28Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for HTML_QuickForm2 rules
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Rule.php';
|
||||
|
||||
/**
|
||||
* Rule checking the value via a callback function (method)
|
||||
*
|
||||
* The Rule needs a valid callback as a configuration parameter for its work, it
|
||||
* may also be given additional arguments to pass to the callback alongside the
|
||||
* element's value. See {@link mergeConfig()} for description of possible ways
|
||||
* to pass configuration parameters.
|
||||
*
|
||||
* The callback will be called with element's value as the first argument, if
|
||||
* additional arguments were provided they'll be passed as well. It is expected
|
||||
* to return false if the value is invalid and true if it is valid.
|
||||
*
|
||||
* Checking that the value is not empty:
|
||||
* <code>
|
||||
* $str->addRule('callback', 'The field should not be empty', 'strlen');
|
||||
* </code>
|
||||
* Checking that the value is in the given array:
|
||||
* <code>
|
||||
* $meta->addRule('callback', 'Unknown variable name',
|
||||
* array('callback' => 'in_array',
|
||||
* 'arguments' => array(array('foo', 'bar', 'baz'))));
|
||||
* </code>
|
||||
* The same, but with rule registering first:
|
||||
* <code>
|
||||
* HTML_QuickForm2_Factory::registerRule(
|
||||
* 'in_array', 'HTML_QuickForm2_Rule_Callback',
|
||||
* 'HTML/QuickForm2/Rule/Callback.php', 'in_array'
|
||||
* );
|
||||
* $meta->addRule('in_array', 'Unknown variable name', array(array('foo', 'bar', 'baz')));
|
||||
* </code>
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Rule_Callback extends HTML_QuickForm2_Rule
|
||||
{
|
||||
/**
|
||||
* Validates the owner element
|
||||
*
|
||||
* @return bool the value returned by a callback function
|
||||
*/
|
||||
protected function validateOwner()
|
||||
{
|
||||
$value = $this->owner->getValue();
|
||||
$config = $this->getConfig();
|
||||
return (bool)call_user_func_array(
|
||||
$config['callback'], array_merge(array($value), $config['arguments'])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges local configuration with that provided for registerRule()
|
||||
*
|
||||
* "Global" configuration may be passed to
|
||||
* {@link HTML_QuickForm2_Factory::registerRule()} in either of the
|
||||
* following formats
|
||||
* - callback
|
||||
* - array(['callback' => callback, ]['arguments' => array(...)])
|
||||
*
|
||||
* "Local" configuration may be passed to the constructor in either of
|
||||
* the following formats
|
||||
* - callback or arguments (interpretation depends on whether the global
|
||||
* configuration already contains the callback)
|
||||
* - array(['callback' => callback, ]['arguments' => array(...)])
|
||||
*
|
||||
* As usual, global config overrides local one. It is a good idea to use the
|
||||
* associative array format to prevent ambiguity.
|
||||
*
|
||||
* @param mixed Local configuration
|
||||
* @param mixed Global configuration
|
||||
* @return mixed Merged configuration
|
||||
*/
|
||||
public static function mergeConfig($localConfig, $globalConfig)
|
||||
{
|
||||
if (!isset($globalConfig)) {
|
||||
$config = $localConfig;
|
||||
|
||||
} else {
|
||||
if (!is_array($globalConfig) ||
|
||||
!isset($globalConfig['callback']) && !isset($globalConfig['arguments'])
|
||||
) {
|
||||
$config = array('callback' => $globalConfig);
|
||||
} else {
|
||||
$config = $globalConfig;
|
||||
}
|
||||
if (is_array($localConfig) && (isset($localConfig['callback'])
|
||||
|| isset($localConfig['arguments']))
|
||||
) {
|
||||
$config += $localConfig;
|
||||
} elseif(isset($localConfig)) {
|
||||
$config += array('callback' => $localConfig, 'arguments' => $localConfig);
|
||||
}
|
||||
}
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the callback to use for validation and its additional arguments
|
||||
*
|
||||
* @param callback|array Callback or array ('callback' => validation callback,
|
||||
* 'arguments' => additional arguments)
|
||||
* @return HTML_QuickForm2_Rule
|
||||
* @throws HTML_QuickForm2_InvalidArgumentException if callback is missing or invalid
|
||||
*/
|
||||
public function setConfig($config)
|
||||
{
|
||||
if (!is_array($config) || !isset($config['callback'])) {
|
||||
$config = array('callback' => $config);
|
||||
}
|
||||
if (!is_callable($config['callback'], false, $callbackName)) {
|
||||
throw new HTML_QuickForm2_InvalidArgumentException(
|
||||
'Callback Rule requires a valid callback, \'' . $callbackName .
|
||||
'\' was given'
|
||||
);
|
||||
}
|
||||
return parent::setConfig($config + array('arguments' => array()));
|
||||
}
|
||||
}
|
||||
?>
|
||||
231
www/analytics/libs/HTML/QuickForm2/Rule/Compare.php
Normal file
231
www/analytics/libs/HTML/QuickForm2/Rule/Compare.php
Normal file
|
|
@ -0,0 +1,231 @@
|
|||
<?php
|
||||
/**
|
||||
* Rule comparing the value of the field with some other value
|
||||
*
|
||||
* 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: Compare.php 299480 2010-05-19 06:55:03Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for HTML_QuickForm2 rules
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Rule.php';
|
||||
|
||||
/**
|
||||
* Rule comparing the value of the field with some other value
|
||||
*
|
||||
* The Rule needs two configuration parameters for its work
|
||||
* - comparison operator (defaults to equality)
|
||||
* - operand to compare with; this can be either a constant or another form
|
||||
* element (its value will be used)
|
||||
* See {@link mergeConfig()} for description of possible ways to pass
|
||||
* configuration parameters.
|
||||
*
|
||||
* Note that 'less than [or equal]' and 'greater than [or equal]' operators
|
||||
* compare the operands numerically, since this is considered as more useful
|
||||
* approach by the authors.
|
||||
*
|
||||
* For convenience, this Rule is already registered in the Factory with the
|
||||
* names 'eq', 'neq', 'lt', 'gt', 'lte', 'gte' corresponding to the relevant
|
||||
* operators:
|
||||
* <code>
|
||||
* $password->addRule('eq', 'Passwords do not match', $passwordRepeat);
|
||||
* $orderQty->addRule('lte', 'Should not order more than 10 of these', 10);
|
||||
* </code>
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Rule_Compare extends HTML_QuickForm2_Rule
|
||||
{
|
||||
/**
|
||||
* Possible comparison operators
|
||||
* @var array
|
||||
*/
|
||||
protected $operators = array('==', '!=', '===', '!==', '<', '<=', '>', '>=');
|
||||
|
||||
|
||||
/**
|
||||
* Validates the owner element
|
||||
*
|
||||
* @return bool whether (element_value operator operand) expression is true
|
||||
*/
|
||||
protected function validateOwner()
|
||||
{
|
||||
$value = $this->owner->getValue();
|
||||
$config = $this->getConfig();
|
||||
if (!in_array($config['operator'], array('===', '!=='))) {
|
||||
$compareFn = create_function(
|
||||
'$a, $b', 'return floatval($a) ' . $config['operator'] . ' floatval($b);'
|
||||
);
|
||||
} else {
|
||||
$compareFn = create_function(
|
||||
'$a, $b', 'return strval($a) ' . $config['operator'] . ' strval($b);'
|
||||
);
|
||||
}
|
||||
return $compareFn($value, $config['operand'] instanceof HTML_QuickForm2_Node
|
||||
? $config['operand']->getValue(): $config['operand']);
|
||||
}
|
||||
|
||||
protected function getJavascriptCallback()
|
||||
{
|
||||
$config = $this->getConfig();
|
||||
$operand1 = $this->owner->getJavascriptValue();
|
||||
$operand2 = $config['operand'] instanceof HTML_QuickForm2_Node
|
||||
? $config['operand']->getJavascriptValue()
|
||||
: "'" . strtr($config['operand'], array(
|
||||
"\r" => '\r',
|
||||
"\n" => '\n',
|
||||
"\t" => '\t',
|
||||
"'" => "\\'",
|
||||
'"' => '\"',
|
||||
'\\' => '\\\\'
|
||||
)) . "'";
|
||||
|
||||
if (!in_array($config['operator'], array('===', '!=='))) {
|
||||
$check = "Number({$operand1}) {$config['operator']} Number({$operand2})";
|
||||
} else {
|
||||
$check = "String({$operand1}) {$config['operator']} String({$operand2})";
|
||||
}
|
||||
|
||||
return "function () { return {$check}; }";
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges local configuration with that provided for registerRule()
|
||||
*
|
||||
* "Global" configuration may be passed to
|
||||
* {@link HTML_QuickForm2_Factory::registerRule()} in
|
||||
* either of the following formats
|
||||
* - operator
|
||||
* - array(operator[, operand])
|
||||
* - array(['operator' => operator, ]['operand' => operand])
|
||||
|
||||
* "Local" configuration may be passed to the constructor in either of
|
||||
* the following formats
|
||||
* - operand
|
||||
* - array([operator, ]operand)
|
||||
* - array(['operator' => operator, ]['operand' => operand])
|
||||
*
|
||||
* As usual, global configuration overrides local one.
|
||||
*
|
||||
* @param mixed Local configuration
|
||||
* @param mixed Global configuration
|
||||
* @return mixed Merged configuration
|
||||
*/
|
||||
public static function mergeConfig($localConfig, $globalConfig)
|
||||
{
|
||||
$config = null;
|
||||
if (0 < count($globalConfig)) {
|
||||
$config = self::toCanonicalForm($globalConfig, 'operator');
|
||||
}
|
||||
if (0 < count($localConfig)) {
|
||||
$config = (isset($config)? $config: array())
|
||||
+ self::toCanonicalForm($localConfig);
|
||||
}
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts configuration data to a canonical associative array form
|
||||
*
|
||||
* @param mixed Configuration data
|
||||
* @param string Array key to assign $config to if it is scalar
|
||||
* @return array Associative array that may contain 'operand' and 'operator' keys
|
||||
*/
|
||||
protected static function toCanonicalForm($config, $key = 'operand')
|
||||
{
|
||||
if (!is_array($config)) {
|
||||
return array($key => $config);
|
||||
|
||||
} elseif (array_key_exists('operator', $config)
|
||||
|| array_key_exists('operand', $config)
|
||||
) {
|
||||
return $config;
|
||||
|
||||
} elseif (1 == count($config)) {
|
||||
return array($key => end($config));
|
||||
|
||||
} else {
|
||||
return array('operator' => reset($config), 'operand' => end($config));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the comparison operator and operand to compare to
|
||||
*
|
||||
* $config can be either of the following
|
||||
* - operand
|
||||
* - array([operator, ]operand)
|
||||
* - array(['operator' => operator, ]['operand' => operand])
|
||||
* If operator is missing it will default to '==='
|
||||
*
|
||||
* @param mixed Configuration data
|
||||
* @return HTML_QuickForm2_Rule
|
||||
* @throws HTML_QuickForm2_InvalidArgumentException if a bogus comparison
|
||||
* operator is used for configuration, if an operand is missing
|
||||
*/
|
||||
public function setConfig($config)
|
||||
{
|
||||
if (0 == count($config)) {
|
||||
throw new HTML_QuickForm2_InvalidArgumentException(
|
||||
'Compare Rule requires an argument to compare with'
|
||||
);
|
||||
}
|
||||
$config = self::toCanonicalForm($config);
|
||||
|
||||
$config += array('operator' => '===');
|
||||
if (!in_array($config['operator'], $this->operators)) {
|
||||
throw new HTML_QuickForm2_InvalidArgumentException(
|
||||
'Compare Rule requires a valid comparison operator, ' .
|
||||
preg_replace('/\s+/', ' ', var_export($config['operator'], true)) . ' given'
|
||||
);
|
||||
}
|
||||
if (in_array($config['operator'], array('==', '!='))) {
|
||||
$config['operator'] .= '=';
|
||||
}
|
||||
|
||||
return parent::setConfig($config);
|
||||
}
|
||||
}
|
||||
?>
|
||||
137
www/analytics/libs/HTML/QuickForm2/Rule/Each.php
Normal file
137
www/analytics/libs/HTML/QuickForm2/Rule/Each.php
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
<?php
|
||||
/**
|
||||
* Validates all elements in a Container using a template Rule
|
||||
*
|
||||
* 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: Each.php 294057 2010-01-26 21:10:28Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for HTML_QuickForm2 rules
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Rule.php';
|
||||
|
||||
/**
|
||||
* Validates all elements in a Container using a template Rule
|
||||
*
|
||||
* This Rule needs one configuration parameter for its work: the template Rule
|
||||
* to use for actual validation. It can be passed either to
|
||||
* {@link HTML_QuickForm2_Rule::__construct() the Rule constructor} as local
|
||||
* configuration or to {@link HTML_QuickForm2_Factory::registerRule()} as
|
||||
* global one. As usual, global configuration overrides local.
|
||||
*
|
||||
* The container will be considered valid if all its elements are valid
|
||||
* according to a template Rule.
|
||||
*
|
||||
* <code>
|
||||
* $group->addRule('each', 'The fields should contain only letters',
|
||||
* $group->createRule('regex', '/^[a-z]+$/i'));
|
||||
* </code>
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Rule_Each extends HTML_QuickForm2_Rule
|
||||
{
|
||||
/**
|
||||
* Validates the owner's children using the template Rule
|
||||
*
|
||||
* @return bool Whether all children are valid according to a template Rule
|
||||
*/
|
||||
protected function validateOwner()
|
||||
{
|
||||
$rule = clone $this->getConfig();
|
||||
foreach ($this->owner->getRecursiveIterator(RecursiveIteratorIterator::LEAVES_ONLY) as $child) {
|
||||
$rule->setOwner($child);
|
||||
if (!$rule->validateOwner()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the template Rule to use for actual validation
|
||||
*
|
||||
* We do not allow using Required rules here, they are able to validate
|
||||
* containers themselves without the help of Each rule.
|
||||
*
|
||||
* @param HTML_QuickForm2_Rule Template Rule
|
||||
* @return HTML_QuickForm2_Rule
|
||||
* @throws HTML_QuickForm2_InvalidArgumentException if $config is either not
|
||||
* an instance of Rule or is an instance of Rule_Required
|
||||
*/
|
||||
public function setConfig($config)
|
||||
{
|
||||
if (!$config instanceof HTML_QuickForm2_Rule) {
|
||||
throw new HTML_QuickForm2_InvalidArgumentException(
|
||||
'Each Rule requires a template Rule to validate with, ' .
|
||||
preg_replace('/\s+/', ' ', var_export($config, true)) . ' given'
|
||||
);
|
||||
} elseif ($config instanceof HTML_QuickForm2_Rule_Required) {
|
||||
throw new HTML_QuickForm2_InvalidArgumentException(
|
||||
'Cannot use "required" Rule as a template'
|
||||
);
|
||||
}
|
||||
return parent::setConfig($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the element that will be validated by this rule
|
||||
*
|
||||
* @param HTML_QuickForm2_Container Container to validate
|
||||
* @throws HTML_QuickForm2_InvalidArgumentException if trying to use
|
||||
* this Rule on something that isn't a Container
|
||||
*/
|
||||
public function setOwner(HTML_QuickForm2_Node $owner)
|
||||
{
|
||||
if (!$owner instanceof HTML_QuickForm2_Container) {
|
||||
throw new HTML_QuickForm2_InvalidArgumentException(
|
||||
'Each Rule can only validate Containers, '.
|
||||
get_class($owner) . ' given'
|
||||
);
|
||||
}
|
||||
parent::setOwner($owner);
|
||||
}
|
||||
}
|
||||
?>
|
||||
89
www/analytics/libs/HTML/QuickForm2/Rule/Empty.php
Normal file
89
www/analytics/libs/HTML/QuickForm2/Rule/Empty.php
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
/**
|
||||
* Rule checking that the field is empty
|
||||
*
|
||||
* 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: Empty.php 299480 2010-05-19 06:55:03Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for HTML_QuickForm2 rules
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Rule.php';
|
||||
|
||||
/**
|
||||
* Rule checking that the field is empty
|
||||
*
|
||||
* Handles both simple form fields and file uploads, the latter are considered
|
||||
* valid iff no file upload was attempted.
|
||||
*
|
||||
* The rule doesn't make much sense if used separately, but can be very helpful
|
||||
* if chained:
|
||||
* <code>
|
||||
* $spamCheck->addRule('empty')
|
||||
* ->or_($email->createRule('nonempty', 'Supply a valid email if you want to receive our spam')
|
||||
* ->and_($email->createRule('email')));
|
||||
* </code>
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Rule_Empty extends HTML_QuickForm2_Rule
|
||||
{
|
||||
protected function validateOwner()
|
||||
{
|
||||
$value = $this->owner->getValue();
|
||||
if (!$this->owner instanceof HTML_QuickForm2_Element_InputFile) {
|
||||
return 0 == strlen($value);
|
||||
} else {
|
||||
return isset($value['error']) && UPLOAD_ERR_NO_FILE == $value['error'];
|
||||
}
|
||||
}
|
||||
|
||||
protected function getJavascriptCallback()
|
||||
{
|
||||
return "function() { return " . $this->owner->getJavascriptValue() . " == ''; }";
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
236
www/analytics/libs/HTML/QuickForm2/Rule/Length.php
Normal file
236
www/analytics/libs/HTML/QuickForm2/Rule/Length.php
Normal file
|
|
@ -0,0 +1,236 @@
|
|||
<?php
|
||||
/**
|
||||
* Rule checking the value's length
|
||||
*
|
||||
* 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: Length.php 299480 2010-05-19 06:55:03Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for HTML_QuickForm2 rules
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Rule.php';
|
||||
|
||||
/**
|
||||
* Rule checking the value's length
|
||||
*
|
||||
* The rule needs an "allowed length" parameter for its work, it can be either
|
||||
* - a scalar: the value will be valid if it is exactly this long
|
||||
* - an array: the value will be valid if its length is between the given values
|
||||
* (inclusive). If one of these evaluates to 0, then length will be compared
|
||||
* only with the remaining one.
|
||||
* See {@link mergeConfig()} for description of possible ways to pass
|
||||
* configuration parameters.
|
||||
*
|
||||
* The Rule considers empty fields as valid and doesn't try to compare their
|
||||
* lengths with provided limits.
|
||||
*
|
||||
* For convenience this Rule is also registered with the names 'minlength' and
|
||||
* 'maxlength' (having, respectively, 'max' and 'min' parameters set to 0):
|
||||
* <code>
|
||||
* $password->addRule('minlength', 'The password should be at least 6 characters long', 6);
|
||||
* $message->addRule('maxlength', 'Your message is too verbose', 1000);
|
||||
* </code>
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Rule_Length extends HTML_QuickForm2_Rule
|
||||
{
|
||||
/**
|
||||
* Validates the owner element
|
||||
*
|
||||
* @return bool whether length of the element's value is within allowed range
|
||||
*/
|
||||
protected function validateOwner()
|
||||
{
|
||||
if (0 == ($valueLength = strlen($this->owner->getValue()))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$allowedLength = $this->getConfig();
|
||||
if (is_scalar($allowedLength)) {
|
||||
return $valueLength == $allowedLength;
|
||||
} else {
|
||||
return (empty($allowedLength['min']) || $valueLength >= $allowedLength['min']) &&
|
||||
(empty($allowedLength['max']) || $valueLength <= $allowedLength['max']);
|
||||
}
|
||||
}
|
||||
|
||||
protected function getJavascriptCallback()
|
||||
{
|
||||
$allowedLength = $this->getConfig();
|
||||
if (is_scalar($allowedLength)) {
|
||||
$check = "length == {$allowedLength}";
|
||||
} else {
|
||||
$checks = array();
|
||||
if (!empty($allowedLength['min'])) {
|
||||
$checks[] = "length >= {$allowedLength['min']}";
|
||||
}
|
||||
if (!empty($allowedLength['max'])) {
|
||||
$checks[] = "length <= {$allowedLength['max']}";
|
||||
}
|
||||
$check = implode(' && ', $checks);
|
||||
}
|
||||
return "function() { var length = " . $this->owner->getJavascriptValue() .
|
||||
".length; if (0 == length) { return true; } else { return {$check}; } }";
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the 'min' and 'max' fields from one array to the other
|
||||
*
|
||||
* @param array Rule configuration, array with 'min' and 'max' keys
|
||||
* @param array Additional configuration, fields will be added to
|
||||
* $length if it doesn't contain such a key already
|
||||
* @return array
|
||||
*/
|
||||
protected static function mergeMinMaxLength($length, $config)
|
||||
{
|
||||
if (array_key_exists('min', $config) || array_key_exists('max', $config)) {
|
||||
if (!array_key_exists('min', $length) && array_key_exists('min', $config)) {
|
||||
$length['min'] = $config['min'];
|
||||
}
|
||||
if (!array_key_exists('max', $length) && array_key_exists('max', $config)) {
|
||||
$length['max'] = $config['max'];
|
||||
}
|
||||
} else {
|
||||
if (!array_key_exists('min', $length)) {
|
||||
$length['min'] = reset($config);
|
||||
}
|
||||
if (!array_key_exists('max', $length)) {
|
||||
$length['max'] = end($config);
|
||||
}
|
||||
}
|
||||
return $length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges length limits given on rule creation with those given to registerRule()
|
||||
*
|
||||
* "Global" length limits may be passed to
|
||||
* {@link HTML_QuickForm2_Factory::registerRule()} in either of the
|
||||
* following formats
|
||||
* - scalar (exact length)
|
||||
* - array(minlength, maxlength)
|
||||
* - array(['min' => minlength, ]['max' => maxlength])
|
||||
*
|
||||
* "Local" length limits may be passed to the constructor in either of
|
||||
* the following formats
|
||||
* - scalar (if global config is unset then it is treated as an exact
|
||||
* length, if 'min' or 'max' is in global config then it is treated
|
||||
* as 'max' or 'min', respectively)
|
||||
* - array(minlength, maxlength)
|
||||
* - array(['min' => minlength, ]['max' => maxlength])
|
||||
*
|
||||
* As usual, global configuration overrides local one.
|
||||
*
|
||||
* @param int|array Local length limits
|
||||
* @param int|array Global length limits, usually provided to {@link HTML_QuickForm2_Factory::registerRule()}
|
||||
* @return int|array Merged length limits
|
||||
*/
|
||||
public static function mergeConfig($localConfig, $globalConfig)
|
||||
{
|
||||
if (!isset($globalConfig)) {
|
||||
$length = $localConfig;
|
||||
|
||||
} elseif (!is_array($globalConfig)) {
|
||||
$length = $globalConfig;
|
||||
|
||||
} else {
|
||||
$length = self::mergeMinMaxLength(array(), $globalConfig);
|
||||
if (isset($localConfig)) {
|
||||
$length = self::mergeMinMaxLength(
|
||||
$length, is_array($localConfig)? $localConfig: array($localConfig)
|
||||
);
|
||||
}
|
||||
}
|
||||
return $length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the allowed length limits
|
||||
*
|
||||
* $config can be either of the following
|
||||
* - integer (rule checks for exact length)
|
||||
* - array(minlength, maxlength)
|
||||
* - array(['min' => minlength, ]['max' => maxlength])
|
||||
*
|
||||
* @param int|array Length limits
|
||||
* @return HTML_QuickForm2_Rule
|
||||
* @throws HTML_QuickForm2_InvalidArgumentException if bogus length limits
|
||||
* were provided
|
||||
*/
|
||||
public function setConfig($config)
|
||||
{
|
||||
if (is_array($config)) {
|
||||
$config = self::mergeMinMaxLength(array(), $config)
|
||||
+ array('min' => 0, 'max' => 0);
|
||||
}
|
||||
if (is_array($config) && ($config['min'] < 0 || $config['max'] < 0) ||
|
||||
!is_array($config) && $config < 0)
|
||||
{
|
||||
throw new HTML_QuickForm2_InvalidArgumentException(
|
||||
'Length Rule requires limits to be nonnegative, ' .
|
||||
preg_replace('/\s+/', ' ', var_export($config, true)) . ' given'
|
||||
);
|
||||
|
||||
} elseif (is_array($config) && $config['min'] == 0 && $config['max'] == 0 ||
|
||||
!is_array($config) && 0 == $config)
|
||||
{
|
||||
throw new HTML_QuickForm2_InvalidArgumentException(
|
||||
'Length Rule requires at least one non-zero limit, ' .
|
||||
preg_replace('/\s+/', ' ', var_export($config, true)) . ' given'
|
||||
);
|
||||
}
|
||||
|
||||
if (!empty($config['min']) && !empty($config['max'])) {
|
||||
if ($config['min'] > $config['max']) {
|
||||
list($config['min'], $config['max']) = array($config['max'], $config['min']);
|
||||
} elseif ($config['min'] == $config['max']) {
|
||||
$config = $config['min'];
|
||||
}
|
||||
}
|
||||
return parent::setConfig($config);
|
||||
}
|
||||
}
|
||||
?>
|
||||
124
www/analytics/libs/HTML/QuickForm2/Rule/MaxFileSize.php
Normal file
124
www/analytics/libs/HTML/QuickForm2/Rule/MaxFileSize.php
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
<?php
|
||||
/**
|
||||
* Rule checking that uploaded file size does not exceed the given limit
|
||||
*
|
||||
* 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: MaxFileSize.php 294057 2010-01-26 21:10:28Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for HTML_QuickForm2 rules
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Rule.php';
|
||||
|
||||
/**
|
||||
* Rule checking that uploaded file size does not exceed the given limit
|
||||
*
|
||||
* The Rule needs one configuration parameter for its work: the size limit.
|
||||
* This limit can be passed either to
|
||||
* {@link HTML_QuickForm2_Rule::__construct() the Rule constructor} as local
|
||||
* configuration or to {@link HTML_QuickForm2_Factory::registerRule()} as
|
||||
* global one. As usual, global configuration overrides local one.
|
||||
*
|
||||
* Note that if file upload failed due to upload_max_filesize php.ini setting
|
||||
* or MAX_FILE_SIZE form field, then this rule won't even be called, due to
|
||||
* File element's built-in validation setting the error message.
|
||||
*
|
||||
* The Rule considers missing file uploads (UPLOAD_ERR_NO_FILE) valid.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Rule_MaxFileSize extends HTML_QuickForm2_Rule
|
||||
{
|
||||
/**
|
||||
* Validates the owner element
|
||||
*
|
||||
* @return bool whether uploaded file's size is within given limit
|
||||
*/
|
||||
protected function validateOwner()
|
||||
{
|
||||
$value = $this->owner->getValue();
|
||||
if (!isset($value['error']) || UPLOAD_ERR_NO_FILE == $value['error']) {
|
||||
return true;
|
||||
}
|
||||
return ($this->getConfig() >= @filesize($value['tmp_name']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets maximum allowed file size
|
||||
*
|
||||
* @param int Maximum allowed size
|
||||
* @return HTML_QuickForm2_Rule
|
||||
* @throws HTML_QuickForm2_InvalidArgumentException if a bogus size limit was provided
|
||||
*/
|
||||
public function setConfig($config)
|
||||
{
|
||||
if (0 >= $config) {
|
||||
throw new HTML_QuickForm2_InvalidArgumentException(
|
||||
'MaxFileSize Rule requires a positive size limit, ' .
|
||||
preg_replace('/\s+/', ' ', var_export($config, true)) . ' given'
|
||||
);
|
||||
}
|
||||
return parent::setConfig($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the element that will be validated by this rule
|
||||
*
|
||||
* @param HTML_QuickForm2_Element_InputFile File upload field to validate
|
||||
* @throws HTML_QuickForm2_InvalidArgumentException if trying to use
|
||||
* this Rule on something that isn't a file upload field
|
||||
*/
|
||||
public function setOwner(HTML_QuickForm2_Node $owner)
|
||||
{
|
||||
if (!$owner instanceof HTML_QuickForm2_Element_InputFile) {
|
||||
throw new HTML_QuickForm2_InvalidArgumentException(
|
||||
'MaxFileSize Rule can only validate file upload fields, '.
|
||||
get_class($owner) . ' given'
|
||||
);
|
||||
}
|
||||
parent::setOwner($owner);
|
||||
}
|
||||
}
|
||||
?>
|
||||
122
www/analytics/libs/HTML/QuickForm2/Rule/MimeType.php
Normal file
122
www/analytics/libs/HTML/QuickForm2/Rule/MimeType.php
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
<?php
|
||||
/**
|
||||
* Rule checking that uploaded file is of the correct MIME type
|
||||
*
|
||||
* 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: MimeType.php 294057 2010-01-26 21:10:28Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for HTML_QuickForm2 rules
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Rule.php';
|
||||
|
||||
/**
|
||||
* Rule checking that uploaded file is of the correct MIME type
|
||||
*
|
||||
* The Rule needs one configuration parameter for its work: a string with a
|
||||
* desired MIME type or array of such strings. This parameter can be passed
|
||||
* either to {@link HTML_QuickForm2_Rule::__construct() the Rule constructor}
|
||||
* as local configuration or to {@link HTML_QuickForm2_Factory::registerRule()}
|
||||
* as global one. As usual, global configuration overrides local one.
|
||||
*
|
||||
* The Rule considers missing file uploads (UPLOAD_ERR_NO_FILE) valid.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Rule_MimeType extends HTML_QuickForm2_Rule
|
||||
{
|
||||
/**
|
||||
* Validates the owner element
|
||||
*
|
||||
* @return bool whether uploaded file's MIME type is correct
|
||||
*/
|
||||
protected function validateOwner()
|
||||
{
|
||||
$value = $this->owner->getValue();
|
||||
if (!isset($value['error']) || UPLOAD_ERR_NO_FILE == $value['error']) {
|
||||
return true;
|
||||
}
|
||||
$mime = $this->getConfig();
|
||||
return is_array($mime)? in_array($value['type'], $mime):
|
||||
$value['type'] == $mime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets allowed MIME type(s) for the uploaded file
|
||||
*
|
||||
* @param string|array Allowed MIME type or an array of types
|
||||
* @return HTML_QuickForm2_Rule
|
||||
* @throws HTML_QuickForm2_InvalidArgumentException if bogus configuration provided
|
||||
*/
|
||||
public function setConfig($config)
|
||||
{
|
||||
if (0 == count($config) || !is_string($config) && !is_array($config)) {
|
||||
throw new HTML_QuickForm2_InvalidArgumentException(
|
||||
'MimeType Rule requires MIME type(s), ' .
|
||||
preg_replace('/\s+/', ' ', var_export($config, true)) . ' given'
|
||||
);
|
||||
}
|
||||
return parent::setConfig($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the element that will be validated by this rule
|
||||
*
|
||||
* @param HTML_QuickForm2_Element_InputFile File upload field to validate
|
||||
* @throws HTML_QuickForm2_InvalidArgumentException if trying to use
|
||||
* this Rule on something that isn't a file upload field
|
||||
*/
|
||||
public function setOwner(HTML_QuickForm2_Node $owner)
|
||||
{
|
||||
if (!$owner instanceof HTML_QuickForm2_Element_InputFile) {
|
||||
throw new HTML_QuickForm2_InvalidArgumentException(
|
||||
'MimeType Rule can only validate file upload fields, '.
|
||||
get_class($owner) . ' given'
|
||||
);
|
||||
}
|
||||
parent::setOwner($owner);
|
||||
}
|
||||
}
|
||||
?>
|
||||
141
www/analytics/libs/HTML/QuickForm2/Rule/Nonempty.php
Normal file
141
www/analytics/libs/HTML/QuickForm2/Rule/Nonempty.php
Normal file
|
|
@ -0,0 +1,141 @@
|
|||
<?php
|
||||
/**
|
||||
* Rule checking that the field is not empty
|
||||
*
|
||||
* 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: Nonempty.php 299706 2010-05-24 18:32:37Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for HTML_QuickForm2 rules
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Rule.php';
|
||||
|
||||
/**
|
||||
* Rule checking that the field is not empty
|
||||
*
|
||||
* Handles simple form fields, file uploads and Containers.
|
||||
*
|
||||
* When validating <select multiple> fields and Containers it may use an
|
||||
* optional configuration parameter for minimum number of nonempty values,
|
||||
* defaulting to 1. It can be passed either to
|
||||
* {@link HTML_QuickForm2_Rule::__construct() the Rule constructor} as local
|
||||
* configuration or to {@link HTML_QuickForm2_Factory::registerRule()} as
|
||||
* global one. As usual, global configuration overrides local.
|
||||
*
|
||||
* <code>
|
||||
* // Required rule is 'nonempty' with a bit of special handling
|
||||
* $login->addRule('required', 'Please provide your login');
|
||||
* $multiSelect->addRule('required', 'Please select at least two options', 2);
|
||||
* </code>
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Rule_Nonempty extends HTML_QuickForm2_Rule
|
||||
{
|
||||
protected function validateOwner()
|
||||
{
|
||||
if ($this->owner instanceof HTML_QuickForm2_Container) {
|
||||
$nonempty = 0;
|
||||
foreach ($this->owner->getRecursiveIterator(RecursiveIteratorIterator::LEAVES_ONLY) as $child) {
|
||||
$rule = new self($child);
|
||||
if ($rule->validateOwner()) {
|
||||
$nonempty++;
|
||||
}
|
||||
}
|
||||
return $nonempty >= $this->getConfig();
|
||||
}
|
||||
|
||||
$value = $this->owner->getValue();
|
||||
if ($this->owner instanceof HTML_QuickForm2_Element_InputFile) {
|
||||
return isset($value['error']) && (UPLOAD_ERR_OK == $value['error']);
|
||||
} elseif (is_array($value)) {
|
||||
return count(array_filter($value, 'strlen')) >= $this->getConfig();
|
||||
} else {
|
||||
return (bool)strlen($value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets minimum number of nonempty values
|
||||
*
|
||||
* This is useful for multiple selects and Containers, will be ignored for
|
||||
* all other elements. Defaults to 1, thus multiple select will be
|
||||
* considered not empty if at least one option is selected, Container will
|
||||
* be considered not empty if at least one contained element is not empty.
|
||||
*
|
||||
* @param int Maximum allowed size
|
||||
* @return HTML_QuickForm2_Rule
|
||||
* @throws HTML_QuickForm2_InvalidArgumentException if a bogus size limit was provided
|
||||
*/
|
||||
public function setConfig($config)
|
||||
{
|
||||
if (is_null($config)) {
|
||||
$config = 1;
|
||||
} elseif (1 > intval($config)) {
|
||||
throw new HTML_QuickForm2_InvalidArgumentException(
|
||||
'Nonempty Rule accepts a positive count of nonempty values, ' .
|
||||
preg_replace('/\s+/', ' ', var_export($config, true)) . ' given'
|
||||
);
|
||||
}
|
||||
return parent::setConfig(intval($config));
|
||||
}
|
||||
|
||||
protected function getJavascriptCallback()
|
||||
{
|
||||
$js = "function() {var value = " . $this->owner->getJavascriptValue() . ";";
|
||||
if (!$this->owner instanceof HTML_QuickForm2_Container) {
|
||||
$js .= " if (!value instanceof Array) { return value != ''; } else { " .
|
||||
"var valid = 0; for (var i = 0; i < value.length; i++) { " .
|
||||
"if ('' != value[i]) { valid++; } } return valid >= " . $this->getConfig() . "; } }";
|
||||
} else {
|
||||
$js .= " var values = value.getValues(); var valid = 0; " .
|
||||
"for (var i = 0; i < values.length; i++) { " .
|
||||
"if ('' != values[i]) { valid++; } } return valid >= " . $this->getConfig() . "; }";
|
||||
}
|
||||
return $js;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
80
www/analytics/libs/HTML/QuickForm2/Rule/NotCallback.php
Normal file
80
www/analytics/libs/HTML/QuickForm2/Rule/NotCallback.php
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
/**
|
||||
* Rule checking the value via a callback function (method) with logical negation
|
||||
*
|
||||
* 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: NotCallback.php 299305 2010-05-12 20:15:28Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Rule checking the value via a callback function (method)
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Rule/Callback.php';
|
||||
|
||||
/**
|
||||
* Rule checking the value via a callback function (method) with logical negation
|
||||
*
|
||||
* The Rule accepts the same configuration parameters as the Callback Rule
|
||||
* does, but the callback is expected to return false if the element is valid
|
||||
* and true if it is invalid.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Rule_NotCallback extends HTML_QuickForm2_Rule_Callback
|
||||
{
|
||||
/**
|
||||
* Validates the owner element
|
||||
*
|
||||
* @return bool negated result of a callback function
|
||||
*/
|
||||
protected function validateOwner()
|
||||
{
|
||||
$value = $this->owner->getValue();
|
||||
$config = $this->getConfig();
|
||||
return !call_user_func_array(
|
||||
$config['callback'], array_merge(array($value), $config['arguments'])
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
||||
106
www/analytics/libs/HTML/QuickForm2/Rule/NotRegex.php
Normal file
106
www/analytics/libs/HTML/QuickForm2/Rule/NotRegex.php
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
<?php
|
||||
/**
|
||||
* Checks that the element's value does not match a regular expression
|
||||
*
|
||||
* 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: NotRegex.php 299480 2010-05-19 06:55:03Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Validates values using regular expressions
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Rule/Regex.php';
|
||||
|
||||
/**
|
||||
* Checks that the element's value does not match a regular expression
|
||||
*
|
||||
* The Rule behaves like Regex Rule, but it considers the element valid if its
|
||||
* value does not match the given regular expression.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Rule_NotRegex extends HTML_QuickForm2_Rule_Regex
|
||||
{
|
||||
/**
|
||||
* Validates the owner element
|
||||
*
|
||||
* @return bool whether element's value does not match given regular expression
|
||||
*/
|
||||
protected function validateOwner()
|
||||
{
|
||||
$value = $this->owner->getValue();
|
||||
if ($this->owner instanceof HTML_QuickForm2_Element_InputFile) {
|
||||
if (!isset($value['error']) || UPLOAD_ERR_NO_FILE == $value['error']) {
|
||||
return true;
|
||||
}
|
||||
$value = $value['name'];
|
||||
} elseif (!strlen($value)) {
|
||||
return true;
|
||||
}
|
||||
return !preg_match($this->getConfig() . 'D', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the client-side validation callback
|
||||
*
|
||||
* For this to work properly, slashes have to be used as regex delimiters.
|
||||
* The method takes care of transforming PHP unicode escapes in regexps to
|
||||
* JS unicode escapes if using 'u' modifier (see bug #12376)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getJavascriptCallback()
|
||||
{
|
||||
$regex = $this->getConfig();
|
||||
|
||||
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 "function() { var regex = {$regex}; var value = " . $this->owner->getJavascriptValue() .
|
||||
"; return value == '' || !regex.test(value); }";
|
||||
}
|
||||
}
|
||||
?>
|
||||
133
www/analytics/libs/HTML/QuickForm2/Rule/Regex.php
Normal file
133
www/analytics/libs/HTML/QuickForm2/Rule/Regex.php
Normal file
|
|
@ -0,0 +1,133 @@
|
|||
<?php
|
||||
/**
|
||||
* Validates values using regular expressions
|
||||
*
|
||||
* 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: Regex.php 299480 2010-05-19 06:55:03Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for HTML_QuickForm2 rules
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Rule.php';
|
||||
|
||||
/**
|
||||
* Validates values using regular expressions
|
||||
*
|
||||
* The Rule needs one configuration parameter for its work: a Perl-compatible
|
||||
* regular expression. This parameter can be passed either to
|
||||
* {@link HTML_QuickForm2_Rule::__construct() the Rule constructor} as local
|
||||
* configuration or to {@link HTML_QuickForm2_Factory::registerRule()}
|
||||
* as global one. As usual, global configuration overrides local one.
|
||||
*
|
||||
* The Rule can also validate file uploads, in this case the regular expression
|
||||
* is applied to upload's 'name' field.
|
||||
*
|
||||
* The Rule considers empty fields (file upload fields with UPLOAD_ERR_NO_FILE)
|
||||
* as valid and doesn't try to test them with the regular expression.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Rule_Regex extends HTML_QuickForm2_Rule
|
||||
{
|
||||
/**
|
||||
* Validates the owner element
|
||||
*
|
||||
* @return bool whether element's value matches given regular expression
|
||||
*/
|
||||
protected function validateOwner()
|
||||
{
|
||||
$value = $this->owner->getValue();
|
||||
if ($this->owner instanceof HTML_QuickForm2_Element_InputFile) {
|
||||
if (!isset($value['error']) || UPLOAD_ERR_NO_FILE == $value['error']) {
|
||||
return true;
|
||||
}
|
||||
$value = $value['name'];
|
||||
} elseif (!strlen($value)) {
|
||||
return true;
|
||||
}
|
||||
return preg_match($this->getConfig() . 'D', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the regular expression to validate with
|
||||
*
|
||||
* @param string Regular expression
|
||||
* @return HTML_QuickForm2_Rule
|
||||
* @throws HTML_QuickForm2_InvalidArgumentException if $config is not a string
|
||||
*/
|
||||
public function setConfig($config)
|
||||
{
|
||||
if (!is_string($config)) {
|
||||
throw new HTML_QuickForm2_InvalidArgumentException(
|
||||
'Regex Rule requires a regular expression, ' .
|
||||
preg_replace('/\s+/', ' ', var_export($config, true)) . ' given'
|
||||
);
|
||||
}
|
||||
return parent::setConfig($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the client-side validation callback
|
||||
*
|
||||
* For this to work properly, slashes have to be used as regex delimiters.
|
||||
* The method takes care of transforming PHP unicode escapes in regexps to
|
||||
* JS unicode escapes if using 'u' modifier (see bug #12376)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getJavascriptCallback()
|
||||
{
|
||||
$regex = $this->getConfig();
|
||||
|
||||
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 "function() { var regex = {$regex}; var value = " . $this->owner->getJavascriptValue() .
|
||||
"; return value == '' || regex.test(value); }";
|
||||
}
|
||||
}
|
||||
?>
|
||||
88
www/analytics/libs/HTML/QuickForm2/Rule/Required.php
Normal file
88
www/analytics/libs/HTML/QuickForm2/Rule/Required.php
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
<?php
|
||||
/**
|
||||
* Rule for required 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>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SVN: $Id: Required.php 294057 2010-01-26 21:10:28Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Rule checking that the form field is not empty
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Rule/Nonempty.php';
|
||||
|
||||
/**
|
||||
* Rule for required elements
|
||||
*
|
||||
* The main difference from "nonempty" Rule is that
|
||||
* - elements to which this Rule is attached will be considered required
|
||||
* ({@link HTML_QuickForm2_Node::isRequired()} will return true for them) and
|
||||
* marked accordingly when outputting the form
|
||||
* - this Rule can only be added directly to the element and other Rules can
|
||||
* only be added to it via and_() method
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Rule_Required extends HTML_QuickForm2_Rule_Nonempty
|
||||
{
|
||||
/**
|
||||
* Disallows adding a rule to the chain with an "or" operator
|
||||
*
|
||||
* Required rules are different from all others because they affect the
|
||||
* visual representation of an element ("* denotes required field").
|
||||
* Therefore we cannot allow chaining other rules to these via or_(), since
|
||||
* this will effectively mean that the field is not required anymore and the
|
||||
* visual difference is bogus.
|
||||
*
|
||||
* @param HTML_QuickForm2_Rule
|
||||
* @throws HTML_QuickForm2_Exception
|
||||
*/
|
||||
public function or_(HTML_QuickForm2_Rule $next)
|
||||
{
|
||||
throw new HTML_QuickForm2_Exception(
|
||||
'or_(): Cannot add a rule to "required" rule'
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
||||
749
www/analytics/libs/MaxMindGeoIP/geoip.inc
Executable file
749
www/analytics/libs/MaxMindGeoIP/geoip.inc
Executable file
|
|
@ -0,0 +1,749 @@
|
|||
<?php
|
||||
|
||||
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 2 -*- */
|
||||
/* geoip.inc
|
||||
*
|
||||
* Copyright (C) 2007 MaxMind LLC
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
define("GEOIP_COUNTRY_BEGIN", 16776960);
|
||||
define("GEOIP_STATE_BEGIN_REV0", 16700000);
|
||||
define("GEOIP_STATE_BEGIN_REV1", 16000000);
|
||||
define("GEOIP_STANDARD", 0);
|
||||
define("GEOIP_MEMORY_CACHE", 1);
|
||||
define("GEOIP_SHARED_MEMORY", 2);
|
||||
define("STRUCTURE_INFO_MAX_SIZE", 20);
|
||||
define("DATABASE_INFO_MAX_SIZE", 100);
|
||||
if (!defined('GEOIP_COUNTRY_EDITION')) {
|
||||
define("GEOIP_COUNTRY_EDITION", 106);
|
||||
}
|
||||
if (!defined("GEOIP_PROXY_EDITION")) {
|
||||
define("GEOIP_PROXY_EDITION", 8);
|
||||
}
|
||||
if (!defined("GEOIP_ASNUM_EDITION")) {
|
||||
define("GEOIP_ASNUM_EDITION", 9);
|
||||
}
|
||||
if (!defined("GEOIP_NETSPEED_EDITION")) {
|
||||
define("GEOIP_NETSPEED_EDITION", 10);
|
||||
}
|
||||
if (!defined("GEOIP_REGION_EDITION_REV0")) {
|
||||
define("GEOIP_REGION_EDITION_REV0", 112);
|
||||
}
|
||||
if (!defined("GEOIP_REGION_EDITION_REV1")) {
|
||||
define("GEOIP_REGION_EDITION_REV1", 3);
|
||||
}
|
||||
if (!defined("GEOIP_CITY_EDITION_REV0")) {
|
||||
define("GEOIP_CITY_EDITION_REV0", 111);
|
||||
}
|
||||
if (!defined("GEOIP_CITY_EDITION_REV1")) {
|
||||
define("GEOIP_CITY_EDITION_REV1", 2);
|
||||
}
|
||||
if (!defined("GEOIP_ORG_EDITION")) {
|
||||
define("GEOIP_ORG_EDITION", 110);
|
||||
}
|
||||
if (!defined("GEOIP_ISP_EDITION")) {
|
||||
define("GEOIP_ISP_EDITION", 4);
|
||||
}
|
||||
define("SEGMENT_RECORD_LENGTH", 3);
|
||||
define("STANDARD_RECORD_LENGTH", 3);
|
||||
define("ORG_RECORD_LENGTH", 4);
|
||||
define("MAX_RECORD_LENGTH", 4);
|
||||
define("MAX_ORG_RECORD_LENGTH", 300);
|
||||
define("GEOIP_SHM_KEY", 0x4f415401);
|
||||
define("US_OFFSET", 1);
|
||||
define("CANADA_OFFSET", 677);
|
||||
define("WORLD_OFFSET", 1353);
|
||||
define("FIPS_RANGE", 360);
|
||||
if (!defined("GEOIP_UNKNOWN_SPEED")) {
|
||||
define("GEOIP_UNKNOWN_SPEED", 0);
|
||||
}
|
||||
if (!defined("GEOIP_DIALUP_SPEED")) {
|
||||
define("GEOIP_DIALUP_SPEED", 1);
|
||||
}
|
||||
if (!defined("GEOIP_CABLEDSL_SPEED")) {
|
||||
define("GEOIP_CABLEDSL_SPEED", 2);
|
||||
}
|
||||
if (!defined("GEOIP_CORPORATE_SPEED")) {
|
||||
define("GEOIP_CORPORATE_SPEED", 3);
|
||||
}
|
||||
if (!defined("GEOIP_DOMAIN_EDITION")) {
|
||||
define("GEOIP_DOMAIN_EDITION", 11);
|
||||
}
|
||||
if (!defined("GEOIP_COUNTRY_EDITION_V6")) {
|
||||
define("GEOIP_COUNTRY_EDITION_V6", 12);
|
||||
}
|
||||
define("GEOIP_LOCATIONA_EDITION", 13);
|
||||
define("GEOIP_ACCURACYRADIUS_EDITION", 14);
|
||||
define("GEOIP_CITYCOMBINED_EDITION", 15);
|
||||
define("GEOIP_CITY_EDITION_REV1_V6", 30);
|
||||
define("GEOIP_CITY_EDITION_REV0_V6",31);
|
||||
define("GEOIP_NETSPEED_EDITION_REV1",32);
|
||||
define("GEOIP_NETSPEED_EDITION_REV1_V6",33);
|
||||
define("GEOIP_USERTYPE_EDITION",28);
|
||||
define("GEOIP_USERTYPE_EDITION_V6",29);
|
||||
define("GEOIP_ASNUM_EDITION_V6",21);
|
||||
define("GEOIP_ISP_EDITION_V6",22);
|
||||
define("GEOIP_ORG_EDITION_V6",23);
|
||||
define("GEOIP_DOMAIN_EDITION_V6",24);
|
||||
|
||||
define("CITYCOMBINED_FIXED_RECORD", 7 );
|
||||
|
||||
class GeoIP {
|
||||
var $flags;
|
||||
var $filehandle;
|
||||
var $memory_buffer;
|
||||
var $databaseType;
|
||||
var $databaseSegments;
|
||||
var $record_length;
|
||||
var $shmid;
|
||||
var $GEOIP_COUNTRY_CODE_TO_NUMBER = array(
|
||||
"" => 0, "AP" => 1, "EU" => 2, "AD" => 3, "AE" => 4, "AF" => 5,
|
||||
"AG" => 6, "AI" => 7, "AL" => 8, "AM" => 9, "CW" => 10, "AO" => 11,
|
||||
"AQ" => 12, "AR" => 13, "AS" => 14, "AT" => 15, "AU" => 16, "AW" => 17,
|
||||
"AZ" => 18, "BA" => 19, "BB" => 20, "BD" => 21, "BE" => 22, "BF" => 23,
|
||||
"BG" => 24, "BH" => 25, "BI" => 26, "BJ" => 27, "BM" => 28, "BN" => 29,
|
||||
"BO" => 30, "BR" => 31, "BS" => 32, "BT" => 33, "BV" => 34, "BW" => 35,
|
||||
"BY" => 36, "BZ" => 37, "CA" => 38, "CC" => 39, "CD" => 40, "CF" => 41,
|
||||
"CG" => 42, "CH" => 43, "CI" => 44, "CK" => 45, "CL" => 46, "CM" => 47,
|
||||
"CN" => 48, "CO" => 49, "CR" => 50, "CU" => 51, "CV" => 52, "CX" => 53,
|
||||
"CY" => 54, "CZ" => 55, "DE" => 56, "DJ" => 57, "DK" => 58, "DM" => 59,
|
||||
"DO" => 60, "DZ" => 61, "EC" => 62, "EE" => 63, "EG" => 64, "EH" => 65,
|
||||
"ER" => 66, "ES" => 67, "ET" => 68, "FI" => 69, "FJ" => 70, "FK" => 71,
|
||||
"FM" => 72, "FO" => 73, "FR" => 74, "SX" => 75, "GA" => 76, "GB" => 77,
|
||||
"GD" => 78, "GE" => 79, "GF" => 80, "GH" => 81, "GI" => 82, "GL" => 83,
|
||||
"GM" => 84, "GN" => 85, "GP" => 86, "GQ" => 87, "GR" => 88, "GS" => 89,
|
||||
"GT" => 90, "GU" => 91, "GW" => 92, "GY" => 93, "HK" => 94, "HM" => 95,
|
||||
"HN" => 96, "HR" => 97, "HT" => 98, "HU" => 99, "ID" => 100, "IE" => 101,
|
||||
"IL" => 102, "IN" => 103, "IO" => 104, "IQ" => 105, "IR" => 106, "IS" => 107,
|
||||
"IT" => 108, "JM" => 109, "JO" => 110, "JP" => 111, "KE" => 112, "KG" => 113,
|
||||
"KH" => 114, "KI" => 115, "KM" => 116, "KN" => 117, "KP" => 118, "KR" => 119,
|
||||
"KW" => 120, "KY" => 121, "KZ" => 122, "LA" => 123, "LB" => 124, "LC" => 125,
|
||||
"LI" => 126, "LK" => 127, "LR" => 128, "LS" => 129, "LT" => 130, "LU" => 131,
|
||||
"LV" => 132, "LY" => 133, "MA" => 134, "MC" => 135, "MD" => 136, "MG" => 137,
|
||||
"MH" => 138, "MK" => 139, "ML" => 140, "MM" => 141, "MN" => 142, "MO" => 143,
|
||||
"MP" => 144, "MQ" => 145, "MR" => 146, "MS" => 147, "MT" => 148, "MU" => 149,
|
||||
"MV" => 150, "MW" => 151, "MX" => 152, "MY" => 153, "MZ" => 154, "NA" => 155,
|
||||
"NC" => 156, "NE" => 157, "NF" => 158, "NG" => 159, "NI" => 160, "NL" => 161,
|
||||
"NO" => 162, "NP" => 163, "NR" => 164, "NU" => 165, "NZ" => 166, "OM" => 167,
|
||||
"PA" => 168, "PE" => 169, "PF" => 170, "PG" => 171, "PH" => 172, "PK" => 173,
|
||||
"PL" => 174, "PM" => 175, "PN" => 176, "PR" => 177, "PS" => 178, "PT" => 179,
|
||||
"PW" => 180, "PY" => 181, "QA" => 182, "RE" => 183, "RO" => 184, "RU" => 185,
|
||||
"RW" => 186, "SA" => 187, "SB" => 188, "SC" => 189, "SD" => 190, "SE" => 191,
|
||||
"SG" => 192, "SH" => 193, "SI" => 194, "SJ" => 195, "SK" => 196, "SL" => 197,
|
||||
"SM" => 198, "SN" => 199, "SO" => 200, "SR" => 201, "ST" => 202, "SV" => 203,
|
||||
"SY" => 204, "SZ" => 205, "TC" => 206, "TD" => 207, "TF" => 208, "TG" => 209,
|
||||
"TH" => 210, "TJ" => 211, "TK" => 212, "TM" => 213, "TN" => 214, "TO" => 215,
|
||||
"TL" => 216, "TR" => 217, "TT" => 218, "TV" => 219, "TW" => 220, "TZ" => 221,
|
||||
"UA" => 222, "UG" => 223, "UM" => 224, "US" => 225, "UY" => 226, "UZ" => 227,
|
||||
"VA" => 228, "VC" => 229, "VE" => 230, "VG" => 231, "VI" => 232, "VN" => 233,
|
||||
"VU" => 234, "WF" => 235, "WS" => 236, "YE" => 237, "YT" => 238, "RS" => 239,
|
||||
"ZA" => 240, "ZM" => 241, "ME" => 242, "ZW" => 243, "A1" => 244, "A2" => 245,
|
||||
"O1" => 246, "AX" => 247, "GG" => 248, "IM" => 249, "JE" => 250, "BL" => 251,
|
||||
"MF" => 252, "BQ" => 253,
|
||||
);
|
||||
var $GEOIP_COUNTRY_CODES = array(
|
||||
"","AP","EU","AD","AE","AF","AG","AI","AL","AM","CW",
|
||||
"AO","AQ","AR","AS","AT","AU","AW","AZ","BA","BB",
|
||||
"BD","BE","BF","BG","BH","BI","BJ","BM","BN","BO",
|
||||
"BR","BS","BT","BV","BW","BY","BZ","CA","CC","CD",
|
||||
"CF","CG","CH","CI","CK","CL","CM","CN","CO","CR",
|
||||
"CU","CV","CX","CY","CZ","DE","DJ","DK","DM","DO",
|
||||
"DZ","EC","EE","EG","EH","ER","ES","ET","FI","FJ",
|
||||
"FK","FM","FO","FR","SX","GA","GB","GD","GE","GF",
|
||||
"GH","GI","GL","GM","GN","GP","GQ","GR","GS","GT",
|
||||
"GU","GW","GY","HK","HM","HN","HR","HT","HU","ID",
|
||||
"IE","IL","IN","IO","IQ","IR","IS","IT","JM","JO",
|
||||
"JP","KE","KG","KH","KI","KM","KN","KP","KR","KW",
|
||||
"KY","KZ","LA","LB","LC","LI","LK","LR","LS","LT",
|
||||
"LU","LV","LY","MA","MC","MD","MG","MH","MK","ML",
|
||||
"MM","MN","MO","MP","MQ","MR","MS","MT","MU","MV",
|
||||
"MW","MX","MY","MZ","NA","NC","NE","NF","NG","NI",
|
||||
"NL","NO","NP","NR","NU","NZ","OM","PA","PE","PF",
|
||||
"PG","PH","PK","PL","PM","PN","PR","PS","PT","PW",
|
||||
"PY","QA","RE","RO","RU","RW","SA","SB","SC","SD",
|
||||
"SE","SG","SH","SI","SJ","SK","SL","SM","SN","SO",
|
||||
"SR","ST","SV","SY","SZ","TC","TD","TF","TG","TH",
|
||||
"TJ","TK","TM","TN","TO","TL","TR","TT","TV","TW",
|
||||
"TZ","UA","UG","UM","US","UY","UZ","VA","VC","VE",
|
||||
"VG","VI","VN","VU","WF","WS","YE","YT","RS","ZA",
|
||||
"ZM","ME","ZW","A1","A2","O1","AX","GG","IM","JE",
|
||||
"BL","MF", "BQ");
|
||||
var $GEOIP_COUNTRY_CODES3 = array(
|
||||
"","AP","EU","AND","ARE","AFG","ATG","AIA","ALB","ARM","CUW",
|
||||
"AGO","ATA","ARG","ASM","AUT","AUS","ABW","AZE","BIH","BRB",
|
||||
"BGD","BEL","BFA","BGR","BHR","BDI","BEN","BMU","BRN","BOL",
|
||||
"BRA","BHS","BTN","BVT","BWA","BLR","BLZ","CAN","CCK","COD",
|
||||
"CAF","COG","CHE","CIV","COK","CHL","CMR","CHN","COL","CRI",
|
||||
"CUB","CPV","CXR","CYP","CZE","DEU","DJI","DNK","DMA","DOM",
|
||||
"DZA","ECU","EST","EGY","ESH","ERI","ESP","ETH","FIN","FJI",
|
||||
"FLK","FSM","FRO","FRA","SXM","GAB","GBR","GRD","GEO","GUF",
|
||||
"GHA","GIB","GRL","GMB","GIN","GLP","GNQ","GRC","SGS","GTM",
|
||||
"GUM","GNB","GUY","HKG","HMD","HND","HRV","HTI","HUN","IDN",
|
||||
"IRL","ISR","IND","IOT","IRQ","IRN","ISL","ITA","JAM","JOR",
|
||||
"JPN","KEN","KGZ","KHM","KIR","COM","KNA","PRK","KOR","KWT",
|
||||
"CYM","KAZ","LAO","LBN","LCA","LIE","LKA","LBR","LSO","LTU",
|
||||
"LUX","LVA","LBY","MAR","MCO","MDA","MDG","MHL","MKD","MLI",
|
||||
"MMR","MNG","MAC","MNP","MTQ","MRT","MSR","MLT","MUS","MDV",
|
||||
"MWI","MEX","MYS","MOZ","NAM","NCL","NER","NFK","NGA","NIC",
|
||||
"NLD","NOR","NPL","NRU","NIU","NZL","OMN","PAN","PER","PYF",
|
||||
"PNG","PHL","PAK","POL","SPM","PCN","PRI","PSE","PRT","PLW",
|
||||
"PRY","QAT","REU","ROU","RUS","RWA","SAU","SLB","SYC","SDN",
|
||||
"SWE","SGP","SHN","SVN","SJM","SVK","SLE","SMR","SEN","SOM",
|
||||
"SUR","STP","SLV","SYR","SWZ","TCA","TCD","ATF","TGO","THA",
|
||||
"TJK","TKL","TKM","TUN","TON","TLS","TUR","TTO","TUV","TWN",
|
||||
"TZA","UKR","UGA","UMI","USA","URY","UZB","VAT","VCT","VEN",
|
||||
"VGB","VIR","VNM","VUT","WLF","WSM","YEM","MYT","SRB","ZAF",
|
||||
"ZMB","MNE","ZWE","A1","A2","O1","ALA","GGY","IMN","JEY",
|
||||
"BLM","MAF", "BES"
|
||||
);
|
||||
var $GEOIP_COUNTRY_NAMES = array(
|
||||
"","Asia/Pacific Region","Europe","Andorra","United Arab Emirates","Afghanistan","Antigua and Barbuda","Anguilla","Albania","Armenia","Curacao",
|
||||
"Angola","Antarctica","Argentina","American Samoa","Austria","Australia","Aruba","Azerbaijan","Bosnia and Herzegovina","Barbados",
|
||||
"Bangladesh","Belgium","Burkina Faso","Bulgaria","Bahrain","Burundi","Benin","Bermuda","Brunei Darussalam","Bolivia",
|
||||
"Brazil","Bahamas","Bhutan","Bouvet Island","Botswana","Belarus","Belize","Canada","Cocos (Keeling) Islands","Congo, The Democratic Republic of the",
|
||||
"Central African Republic","Congo","Switzerland","Cote D'Ivoire","Cook Islands","Chile","Cameroon","China","Colombia","Costa Rica",
|
||||
"Cuba","Cape Verde","Christmas Island","Cyprus","Czech Republic","Germany","Djibouti","Denmark","Dominica","Dominican Republic",
|
||||
"Algeria","Ecuador","Estonia","Egypt","Western Sahara","Eritrea","Spain","Ethiopia","Finland","Fiji",
|
||||
"Falkland Islands (Malvinas)","Micronesia, Federated States of","Faroe Islands","France","Sint Maarten (Dutch part)","Gabon","United Kingdom","Grenada","Georgia","French Guiana",
|
||||
"Ghana","Gibraltar","Greenland","Gambia","Guinea","Guadeloupe","Equatorial Guinea","Greece","South Georgia and the South Sandwich Islands","Guatemala",
|
||||
"Guam","Guinea-Bissau","Guyana","Hong Kong","Heard Island and McDonald Islands","Honduras","Croatia","Haiti","Hungary","Indonesia",
|
||||
"Ireland","Israel","India","British Indian Ocean Territory","Iraq","Iran, Islamic Republic of","Iceland","Italy","Jamaica","Jordan",
|
||||
"Japan","Kenya","Kyrgyzstan","Cambodia","Kiribati","Comoros","Saint Kitts and Nevis","Korea, Democratic People's Republic of","Korea, Republic of","Kuwait",
|
||||
"Cayman Islands","Kazakhstan","Lao People's Democratic Republic","Lebanon","Saint Lucia","Liechtenstein","Sri Lanka","Liberia","Lesotho","Lithuania",
|
||||
"Luxembourg","Latvia","Libya","Morocco","Monaco","Moldova, Republic of","Madagascar","Marshall Islands","Macedonia","Mali",
|
||||
"Myanmar","Mongolia","Macau","Northern Mariana Islands","Martinique","Mauritania","Montserrat","Malta","Mauritius","Maldives",
|
||||
"Malawi","Mexico","Malaysia","Mozambique","Namibia","New Caledonia","Niger","Norfolk Island","Nigeria","Nicaragua",
|
||||
"Netherlands","Norway","Nepal","Nauru","Niue","New Zealand","Oman","Panama","Peru","French Polynesia",
|
||||
"Papua New Guinea","Philippines","Pakistan","Poland","Saint Pierre and Miquelon","Pitcairn Islands","Puerto Rico","Palestinian Territory","Portugal","Palau",
|
||||
"Paraguay","Qatar","Reunion","Romania","Russian Federation","Rwanda","Saudi Arabia","Solomon Islands","Seychelles","Sudan",
|
||||
"Sweden","Singapore","Saint Helena","Slovenia","Svalbard and Jan Mayen","Slovakia","Sierra Leone","San Marino","Senegal","Somalia","Suriname",
|
||||
"Sao Tome and Principe","El Salvador","Syrian Arab Republic","Swaziland","Turks and Caicos Islands","Chad","French Southern Territories","Togo","Thailand",
|
||||
"Tajikistan","Tokelau","Turkmenistan","Tunisia","Tonga","Timor-Leste","Turkey","Trinidad and Tobago","Tuvalu","Taiwan",
|
||||
"Tanzania, United Republic of","Ukraine","Uganda","United States Minor Outlying Islands","United States","Uruguay","Uzbekistan","Holy See (Vatican City State)","Saint Vincent and the Grenadines","Venezuela",
|
||||
"Virgin Islands, British","Virgin Islands, U.S.","Vietnam","Vanuatu","Wallis and Futuna","Samoa","Yemen","Mayotte","Serbia","South Africa",
|
||||
"Zambia","Montenegro","Zimbabwe","Anonymous Proxy","Satellite Provider","Other","Aland Islands","Guernsey","Isle of Man","Jersey",
|
||||
"Saint Barthelemy","Saint Martin", "Bonaire, Saint Eustatius and Saba"
|
||||
);
|
||||
|
||||
var $GEOIP_CONTINENT_CODES = array(
|
||||
"--", "AS","EU","EU","AS","AS","NA","NA","EU","AS","NA",
|
||||
"AF","AN","SA","OC","EU","OC","NA","AS","EU","NA",
|
||||
"AS","EU","AF","EU","AS","AF","AF","NA","AS","SA",
|
||||
"SA","NA","AS","AN","AF","EU","NA","NA","AS","AF",
|
||||
"AF","AF","EU","AF","OC","SA","AF","AS","SA","NA",
|
||||
"NA","AF","AS","AS","EU","EU","AF","EU","NA","NA",
|
||||
"AF","SA","EU","AF","AF","AF","EU","AF","EU","OC",
|
||||
"SA","OC","EU","EU","NA","AF","EU","NA","AS","SA",
|
||||
"AF","EU","NA","AF","AF","NA","AF","EU","AN","NA",
|
||||
"OC","AF","SA","AS","AN","NA","EU","NA","EU","AS",
|
||||
"EU","AS","AS","AS","AS","AS","EU","EU","NA","AS",
|
||||
"AS","AF","AS","AS","OC","AF","NA","AS","AS","AS",
|
||||
"NA","AS","AS","AS","NA","EU","AS","AF","AF","EU",
|
||||
"EU","EU","AF","AF","EU","EU","AF","OC","EU","AF",
|
||||
"AS","AS","AS","OC","NA","AF","NA","EU","AF","AS",
|
||||
"AF","NA","AS","AF","AF","OC","AF","OC","AF","NA",
|
||||
"EU","EU","AS","OC","OC","OC","AS","NA","SA","OC",
|
||||
"OC","AS","AS","EU","NA","OC","NA","AS","EU","OC",
|
||||
"SA","AS","AF","EU","EU","AF","AS","OC","AF","AF",
|
||||
"EU","AS","AF","EU","EU","EU","AF","EU","AF","AF",
|
||||
"SA","AF","NA","AS","AF","NA","AF","AN","AF","AS",
|
||||
"AS","OC","AS","AF","OC","AS","EU","NA","OC","AS",
|
||||
"AF","EU","AF","OC","NA","SA","AS","EU","NA","SA",
|
||||
"NA","NA","AS","OC","OC","OC","AS","AF","EU","AF",
|
||||
"AF","EU","AF","--","--","--","EU","EU","EU","EU",
|
||||
"NA","NA","NA"
|
||||
);
|
||||
|
||||
}
|
||||
function geoip_load_shared_mem ($file) {
|
||||
|
||||
$fp = fopen($file, "rb");
|
||||
if (!$fp) {
|
||||
print "error opening $file: $php_errormsg\n";
|
||||
exit;
|
||||
}
|
||||
$s_array = fstat($fp);
|
||||
$size = $s_array['size'];
|
||||
if ($shmid = @shmop_open (GEOIP_SHM_KEY, "w", 0, 0)) {
|
||||
shmop_delete ($shmid);
|
||||
shmop_close ($shmid);
|
||||
}
|
||||
$shmid = shmop_open (GEOIP_SHM_KEY, "c", 0644, $size);
|
||||
shmop_write ($shmid, fread($fp, $size), 0);
|
||||
shmop_close ($shmid);
|
||||
}
|
||||
|
||||
function _setup_segments($gi){
|
||||
$gi->databaseType = GEOIP_COUNTRY_EDITION;
|
||||
$gi->record_length = STANDARD_RECORD_LENGTH;
|
||||
if ($gi->flags & GEOIP_SHARED_MEMORY) {
|
||||
$offset = @shmop_size ($gi->shmid) - 3;
|
||||
for ($i = 0; $i < STRUCTURE_INFO_MAX_SIZE; $i++) {
|
||||
$delim = @shmop_read ($gi->shmid, $offset, 3);
|
||||
$offset += 3;
|
||||
if ($delim == (chr(255).chr(255).chr(255))) {
|
||||
$gi->databaseType = ord(@shmop_read ($gi->shmid, $offset, 1));
|
||||
$offset++;
|
||||
|
||||
if ($gi->databaseType == GEOIP_REGION_EDITION_REV0){
|
||||
$gi->databaseSegments = GEOIP_STATE_BEGIN_REV0;
|
||||
} else if ($gi->databaseType == GEOIP_REGION_EDITION_REV1){
|
||||
$gi->databaseSegments = GEOIP_STATE_BEGIN_REV1;
|
||||
} else if (($gi->databaseType == GEOIP_CITY_EDITION_REV0)||
|
||||
($gi->databaseType == GEOIP_CITY_EDITION_REV1)
|
||||
|| ($gi->databaseType == GEOIP_ORG_EDITION)
|
||||
|| ($gi->databaseType == GEOIP_ORG_EDITION_V6)
|
||||
|| ($gi->databaseType == GEOIP_DOMAIN_EDITION)
|
||||
|| ($gi->databaseType == GEOIP_DOMAIN_EDITION_V6)
|
||||
|| ($gi->databaseType == GEOIP_ISP_EDITION)
|
||||
|| ($gi->databaseType == GEOIP_ISP_EDITION_V6)
|
||||
|| ($gi->databaseType == GEOIP_USERTYPE_EDITION)
|
||||
|| ($gi->databaseType == GEOIP_USERTYPE_EDITION_V6)
|
||||
|| ($gi->databaseType == GEOIP_LOCATIONA_EDITION)
|
||||
|| ($gi->databaseType == GEOIP_ACCURACYRADIUS_EDITION)
|
||||
|| ($gi->databaseType == GEOIP_CITY_EDITION_REV0_V6)
|
||||
|| ($gi->databaseType == GEOIP_CITY_EDITION_REV1_V6)
|
||||
|| ($gi->databaseType == GEOIP_NETSPEED_EDITION_REV1)
|
||||
|| ($gi->databaseType == GEOIP_NETSPEED_EDITION_REV1_V6)
|
||||
|| ($gi->databaseType == GEOIP_ASNUM_EDITION)
|
||||
|| ($gi->databaseType == GEOIP_ASNUM_EDITION_V6)){
|
||||
$gi->databaseSegments = 0;
|
||||
$buf = @shmop_read ($gi->shmid, $offset, SEGMENT_RECORD_LENGTH);
|
||||
for ($j = 0;$j < SEGMENT_RECORD_LENGTH;$j++){
|
||||
$gi->databaseSegments += (ord($buf[$j]) << ($j * 8));
|
||||
}
|
||||
if (($gi->databaseType == GEOIP_ORG_EDITION)
|
||||
|| ($gi->databaseType == GEOIP_ORG_EDITION_V6)
|
||||
|| ($gi->databaseType == GEOIP_DOMAIN_EDITION)
|
||||
|| ($gi->databaseType == GEOIP_DOMAIN_EDITION_V6)
|
||||
|| ($gi->databaseType == GEOIP_ISP_EDITION)
|
||||
|| ($gi->databaseType == GEOIP_ISP_EDITION_V6)) {
|
||||
$gi->record_length = ORG_RECORD_LENGTH;
|
||||
}
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
$offset -= 4;
|
||||
}
|
||||
}
|
||||
if (($gi->databaseType == GEOIP_COUNTRY_EDITION)||
|
||||
($gi->databaseType == GEOIP_COUNTRY_EDITION_V6)||
|
||||
($gi->databaseType == GEOIP_PROXY_EDITION)||
|
||||
($gi->databaseType == GEOIP_NETSPEED_EDITION)){
|
||||
$gi->databaseSegments = GEOIP_COUNTRY_BEGIN;
|
||||
}
|
||||
} else {
|
||||
$filepos = ftell($gi->filehandle);
|
||||
fseek($gi->filehandle, -3, SEEK_END);
|
||||
for ($i = 0; $i < STRUCTURE_INFO_MAX_SIZE; $i++) {
|
||||
$delim = fread($gi->filehandle,3);
|
||||
if ($delim == (chr(255).chr(255).chr(255))){
|
||||
$gi->databaseType = ord(fread($gi->filehandle,1));
|
||||
if ($gi->databaseType == GEOIP_REGION_EDITION_REV0){
|
||||
$gi->databaseSegments = GEOIP_STATE_BEGIN_REV0;
|
||||
}
|
||||
else if ($gi->databaseType == GEOIP_REGION_EDITION_REV1){
|
||||
$gi->databaseSegments = GEOIP_STATE_BEGIN_REV1;
|
||||
} else if (($gi->databaseType == GEOIP_CITY_EDITION_REV0)
|
||||
|| ($gi->databaseType == GEOIP_CITY_EDITION_REV1)
|
||||
|| ($gi->databaseType == GEOIP_CITY_EDITION_REV0_V6)
|
||||
|| ($gi->databaseType == GEOIP_CITY_EDITION_REV1_V6)
|
||||
|| ($gi->databaseType == GEOIP_ORG_EDITION)
|
||||
|| ($gi->databaseType == GEOIP_DOMAIN_EDITION)
|
||||
|| ($gi->databaseType == GEOIP_ISP_EDITION)
|
||||
|| ($gi->databaseType == GEOIP_ORG_EDITION_V6)
|
||||
|| ($gi->databaseType == GEOIP_DOMAIN_EDITION_V6)
|
||||
|| ($gi->databaseType == GEOIP_ISP_EDITION_V6)
|
||||
|| ($gi->databaseType == GEOIP_LOCATIONA_EDITION)
|
||||
|| ($gi->databaseType == GEOIP_ACCURACYRADIUS_EDITION)
|
||||
|| ($gi->databaseType == GEOIP_CITY_EDITION_REV0_V6)
|
||||
|| ($gi->databaseType == GEOIP_CITY_EDITION_REV1_V6)
|
||||
|| ($gi->databaseType == GEOIP_NETSPEED_EDITION_REV1)
|
||||
|| ($gi->databaseType == GEOIP_NETSPEED_EDITION_REV1_V6)
|
||||
|| ($gi->databaseType == GEOIP_USERTYPE_EDITION)
|
||||
|| ($gi->databaseType == GEOIP_USERTYPE_EDITION_V6)
|
||||
|| ($gi->databaseType == GEOIP_ASNUM_EDITION)
|
||||
|| ($gi->databaseType == GEOIP_ASNUM_EDITION_V6)){
|
||||
$gi->databaseSegments = 0;
|
||||
$buf = fread($gi->filehandle,SEGMENT_RECORD_LENGTH);
|
||||
for ($j = 0;$j < SEGMENT_RECORD_LENGTH;$j++){
|
||||
$gi->databaseSegments += (ord($buf[$j]) << ($j * 8));
|
||||
}
|
||||
if ( ( $gi->databaseType == GEOIP_ORG_EDITION )
|
||||
|| ( $gi->databaseType == GEOIP_DOMAIN_EDITION )
|
||||
|| ( $gi->databaseType == GEOIP_ISP_EDITION )
|
||||
|| ( $gi->databaseType == GEOIP_ORG_EDITION_V6 )
|
||||
|| ( $gi->databaseType == GEOIP_DOMAIN_EDITION_V6 )
|
||||
|| ( $gi->databaseType == GEOIP_ISP_EDITION_V6 )) {
|
||||
$gi->record_length = ORG_RECORD_LENGTH;
|
||||
}
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
fseek($gi->filehandle, -4, SEEK_CUR);
|
||||
}
|
||||
}
|
||||
if (($gi->databaseType == GEOIP_COUNTRY_EDITION)||
|
||||
($gi->databaseType == GEOIP_COUNTRY_EDITION_V6)||
|
||||
($gi->databaseType == GEOIP_PROXY_EDITION)||
|
||||
($gi->databaseType == GEOIP_NETSPEED_EDITION)){
|
||||
$gi->databaseSegments = GEOIP_COUNTRY_BEGIN;
|
||||
}
|
||||
fseek($gi->filehandle,$filepos,SEEK_SET);
|
||||
}
|
||||
return $gi;
|
||||
}
|
||||
|
||||
function geoip_open($filename, $flags) {
|
||||
$gi = new GeoIP;
|
||||
$gi->flags = $flags;
|
||||
if ($gi->flags & GEOIP_SHARED_MEMORY) {
|
||||
$gi->shmid = @shmop_open (GEOIP_SHM_KEY, "a", 0, 0);
|
||||
} else {
|
||||
$gi->filehandle = fopen($filename,"rb") or die( "Can not open $filename\n" );
|
||||
if ($gi->flags & GEOIP_MEMORY_CACHE) {
|
||||
$s_array = fstat($gi->filehandle);
|
||||
$gi->memory_buffer = fread($gi->filehandle, $s_array['size']);
|
||||
}
|
||||
}
|
||||
|
||||
$gi = _setup_segments($gi);
|
||||
return $gi;
|
||||
}
|
||||
|
||||
function geoip_close($gi) {
|
||||
if ($gi->flags & GEOIP_SHARED_MEMORY) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return fclose($gi->filehandle);
|
||||
}
|
||||
|
||||
function geoip_country_id_by_name_v6($gi, $name) {
|
||||
$rec = dns_get_record($name, DNS_AAAA);
|
||||
if ( !$rec ) {
|
||||
return false;
|
||||
}
|
||||
$addr = $rec[0]["ipv6"];
|
||||
if (!$addr || $addr == $name) {
|
||||
return false;
|
||||
}
|
||||
return geoip_country_id_by_addr_v6($gi, $addr);
|
||||
}
|
||||
|
||||
function geoip_country_id_by_name($gi, $name) {
|
||||
$addr = gethostbyname($name);
|
||||
if (!$addr || $addr == $name) {
|
||||
return false;
|
||||
}
|
||||
return geoip_country_id_by_addr($gi, $addr);
|
||||
}
|
||||
|
||||
function geoip_country_code_by_name_v6($gi, $name) {
|
||||
$country_id = geoip_country_id_by_name_v6($gi,$name);
|
||||
if ($country_id !== false) {
|
||||
return $gi->GEOIP_COUNTRY_CODES[$country_id];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!function_exists('geoip_country_code_by_name')) { // added for Piwik
|
||||
function geoip_country_code_by_name($gi, $name) {
|
||||
$country_id = geoip_country_id_by_name($gi,$name);
|
||||
if ($country_id !== false) {
|
||||
return $gi->GEOIP_COUNTRY_CODES[$country_id];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function geoip_country_name_by_name_v6($gi, $name) {
|
||||
$country_id = geoip_country_id_by_name_v6($gi,$name);
|
||||
if ($country_id !== false) {
|
||||
return $gi->GEOIP_COUNTRY_NAMES[$country_id];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!function_exists('geoip_country_name_by_name')) { // added for Piwik
|
||||
function geoip_country_name_by_name($gi, $name) {
|
||||
$country_id = geoip_country_id_by_name($gi,$name);
|
||||
if ($country_id !== false) {
|
||||
return $gi->GEOIP_COUNTRY_NAMES[$country_id];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function geoip_country_id_by_addr_v6($gi, $addr) {
|
||||
$ipnum = inet_pton($addr);
|
||||
return _geoip_seek_country_v6($gi, $ipnum) - GEOIP_COUNTRY_BEGIN;
|
||||
}
|
||||
|
||||
function geoip_country_id_by_addr($gi, $addr) {
|
||||
$ipnum = ip2long($addr);
|
||||
return _geoip_seek_country($gi, $ipnum) - GEOIP_COUNTRY_BEGIN;
|
||||
}
|
||||
|
||||
function geoip_country_code_by_addr_v6($gi, $addr) {
|
||||
$country_id = geoip_country_id_by_addr_v6($gi,$addr);
|
||||
if ($country_id !== false) {
|
||||
return $gi->GEOIP_COUNTRY_CODES[$country_id];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function geoip_country_code_by_addr($gi, $addr) {
|
||||
if ($gi->databaseType == GEOIP_CITY_EDITION_REV1) {
|
||||
$record = geoip_record_by_addr($gi,$addr);
|
||||
if ( $record !== false ) {
|
||||
return $record->country_code;
|
||||
}
|
||||
} else {
|
||||
$country_id = geoip_country_id_by_addr($gi,$addr);
|
||||
if ($country_id !== false) {
|
||||
return $gi->GEOIP_COUNTRY_CODES[$country_id];
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function geoip_country_name_by_addr_v6($gi, $addr) {
|
||||
$country_id = geoip_country_id_by_addr_v6($gi,$addr);
|
||||
if ($country_id !== false) {
|
||||
return $gi->GEOIP_COUNTRY_NAMES[$country_id];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function geoip_country_name_by_addr($gi, $addr) {
|
||||
if ($gi->databaseType == GEOIP_CITY_EDITION_REV1) {
|
||||
$record = geoip_record_by_addr($gi,$addr);
|
||||
return $record->country_name;
|
||||
} else {
|
||||
$country_id = geoip_country_id_by_addr($gi,$addr);
|
||||
if ($country_id !== false) {
|
||||
return $gi->GEOIP_COUNTRY_NAMES[$country_id];
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function _geoip_seek_country_v6($gi, $ipnum) {
|
||||
|
||||
# arrays from unpack start with offset 1
|
||||
# yet another php mystery. array_merge work around
|
||||
# this broken behaviour
|
||||
$v6vec = array_merge(unpack( "C16", $ipnum));
|
||||
|
||||
$offset = 0;
|
||||
for ($depth = 127; $depth >= 0; --$depth) {
|
||||
if ($gi->flags & GEOIP_MEMORY_CACHE) {
|
||||
// workaround php's broken substr, strpos, etc handling with
|
||||
// mbstring.func_overload and mbstring.internal_encoding
|
||||
$enc = mb_internal_encoding();
|
||||
mb_internal_encoding('ISO-8859-1');
|
||||
|
||||
$buf = substr($gi->memory_buffer,
|
||||
2 * $gi->record_length * $offset,
|
||||
2 * $gi->record_length);
|
||||
|
||||
mb_internal_encoding($enc);
|
||||
} elseif ($gi->flags & GEOIP_SHARED_MEMORY) {
|
||||
$buf = @shmop_read ($gi->shmid,
|
||||
2 * $gi->record_length * $offset,
|
||||
2 * $gi->record_length );
|
||||
} else {
|
||||
fseek($gi->filehandle, 2 * $gi->record_length * $offset, SEEK_SET) == 0
|
||||
or die("fseek failed");
|
||||
$buf = fread($gi->filehandle, 2 * $gi->record_length);
|
||||
}
|
||||
$x = array(0,0);
|
||||
for ($i = 0; $i < 2; ++$i) {
|
||||
for ($j = 0; $j < $gi->record_length; ++$j) {
|
||||
$x[$i] += ord($buf[$gi->record_length * $i + $j]) << ($j * 8);
|
||||
}
|
||||
}
|
||||
|
||||
$bnum = 127 - $depth;
|
||||
$idx = $bnum >> 3;
|
||||
$b_mask = 1 << ( $bnum & 7 ^ 7 );
|
||||
if (($v6vec[$idx] & $b_mask) > 0) {
|
||||
if ($x[1] >= $gi->databaseSegments) {
|
||||
return $x[1];
|
||||
}
|
||||
$offset = $x[1];
|
||||
} else {
|
||||
if ($x[0] >= $gi->databaseSegments) {
|
||||
return $x[0];
|
||||
}
|
||||
$offset = $x[0];
|
||||
}
|
||||
}
|
||||
trigger_error("error traversing database - perhaps it is corrupt?", E_USER_ERROR);
|
||||
return false;
|
||||
}
|
||||
|
||||
function _geoip_seek_country($gi, $ipnum) {
|
||||
$offset = 0;
|
||||
for ($depth = 31; $depth >= 0; --$depth) {
|
||||
if ($gi->flags & GEOIP_MEMORY_CACHE) {
|
||||
// workaround php's broken substr, strpos, etc handling with
|
||||
// mbstring.func_overload and mbstring.internal_encoding
|
||||
$enc = mb_internal_encoding();
|
||||
mb_internal_encoding('ISO-8859-1');
|
||||
|
||||
$buf = substr($gi->memory_buffer,
|
||||
2 * $gi->record_length * $offset,
|
||||
2 * $gi->record_length);
|
||||
|
||||
mb_internal_encoding($enc);
|
||||
} elseif ($gi->flags & GEOIP_SHARED_MEMORY) {
|
||||
$buf = @shmop_read ($gi->shmid,
|
||||
2 * $gi->record_length * $offset,
|
||||
2 * $gi->record_length );
|
||||
} else {
|
||||
fseek($gi->filehandle, 2 * $gi->record_length * $offset, SEEK_SET) == 0
|
||||
or die("fseek failed");
|
||||
$buf = fread($gi->filehandle, 2 * $gi->record_length);
|
||||
}
|
||||
$x = array(0,0);
|
||||
for ($i = 0; $i < 2; ++$i) {
|
||||
for ($j = 0; $j < $gi->record_length; ++$j) {
|
||||
$x[$i] += ord($buf[$gi->record_length * $i + $j]) << ($j * 8);
|
||||
}
|
||||
}
|
||||
if ($ipnum & (1 << $depth)) {
|
||||
if ($x[1] >= $gi->databaseSegments) {
|
||||
return $x[1];
|
||||
}
|
||||
$offset = $x[1];
|
||||
} else {
|
||||
if ($x[0] >= $gi->databaseSegments) {
|
||||
return $x[0];
|
||||
}
|
||||
$offset = $x[0];
|
||||
}
|
||||
}
|
||||
trigger_error("error traversing database - perhaps it is corrupt?", E_USER_ERROR);
|
||||
return false;
|
||||
}
|
||||
|
||||
function _common_get_org($gi, $seek_org){
|
||||
$record_pointer = $seek_org + (2 * $gi->record_length - 1) * $gi->databaseSegments;
|
||||
if ($gi->flags & GEOIP_SHARED_MEMORY) {
|
||||
$org_buf = @shmop_read ($gi->shmid, $record_pointer, MAX_ORG_RECORD_LENGTH);
|
||||
} else {
|
||||
fseek($gi->filehandle, $record_pointer, SEEK_SET);
|
||||
$org_buf = fread($gi->filehandle,MAX_ORG_RECORD_LENGTH);
|
||||
}
|
||||
// workaround php's broken substr, strpos, etc handling with
|
||||
// mbstring.func_overload and mbstring.internal_encoding
|
||||
$enc = mb_internal_encoding();
|
||||
mb_internal_encoding('ISO-8859-1');
|
||||
$org_buf = substr($org_buf, 0, strpos($org_buf, "\0"));
|
||||
mb_internal_encoding($enc);
|
||||
return $org_buf;
|
||||
}
|
||||
|
||||
function _get_org_v6($gi,$ipnum){
|
||||
$seek_org = _geoip_seek_country_v6($gi,$ipnum);
|
||||
if ($seek_org == $gi->databaseSegments) {
|
||||
return NULL;
|
||||
}
|
||||
return _common_get_org($gi, $seek_org);
|
||||
}
|
||||
|
||||
function _get_org($gi,$ipnum){
|
||||
$seek_org = _geoip_seek_country($gi,$ipnum);
|
||||
if ($seek_org == $gi->databaseSegments) {
|
||||
return NULL;
|
||||
}
|
||||
return _common_get_org($gi, $seek_org);
|
||||
}
|
||||
|
||||
|
||||
|
||||
function geoip_name_by_addr_v6 ($gi,$addr) {
|
||||
if ($addr == NULL) {
|
||||
return 0;
|
||||
}
|
||||
$ipnum = inet_pton($addr);
|
||||
return _get_org_v6($gi, $ipnum);
|
||||
}
|
||||
|
||||
function geoip_name_by_addr ($gi,$addr) {
|
||||
if ($addr == NULL) {
|
||||
return 0;
|
||||
}
|
||||
$ipnum = ip2long($addr);
|
||||
return _get_org($gi, $ipnum);
|
||||
}
|
||||
|
||||
function geoip_org_by_addr ($gi,$addr) {
|
||||
return geoip_name_by_addr($gi, $addr);
|
||||
}
|
||||
|
||||
function _get_region($gi,$ipnum){
|
||||
if ($gi->databaseType == GEOIP_REGION_EDITION_REV0){
|
||||
$seek_region = _geoip_seek_country($gi,$ipnum) - GEOIP_STATE_BEGIN_REV0;
|
||||
if ($seek_region >= 1000){
|
||||
$country_code = "US";
|
||||
$region = chr(($seek_region - 1000)/26 + 65) . chr(($seek_region - 1000)%26 + 65);
|
||||
} else {
|
||||
$country_code = $gi->GEOIP_COUNTRY_CODES[$seek_region];
|
||||
$region = "";
|
||||
}
|
||||
return array ($country_code,$region);
|
||||
} else if ($gi->databaseType == GEOIP_REGION_EDITION_REV1) {
|
||||
$seek_region = _geoip_seek_country($gi,$ipnum) - GEOIP_STATE_BEGIN_REV1;
|
||||
//print $seek_region;
|
||||
if ($seek_region < US_OFFSET){
|
||||
$country_code = "";
|
||||
$region = "";
|
||||
} else if ($seek_region < CANADA_OFFSET) {
|
||||
$country_code = "US";
|
||||
$region = chr(($seek_region - US_OFFSET)/26 + 65) . chr(($seek_region - US_OFFSET)%26 + 65);
|
||||
} else if ($seek_region < WORLD_OFFSET) {
|
||||
$country_code = "CA";
|
||||
$region = chr(($seek_region - CANADA_OFFSET)/26 + 65) . chr(($seek_region - CANADA_OFFSET)%26 + 65);
|
||||
} else {
|
||||
$country_code = $gi->GEOIP_COUNTRY_CODES[($seek_region - WORLD_OFFSET) / FIPS_RANGE];
|
||||
$region = "";
|
||||
}
|
||||
return array ($country_code,$region);
|
||||
}
|
||||
}
|
||||
|
||||
function geoip_region_by_addr ($gi,$addr) {
|
||||
if ($addr == NULL) {
|
||||
return 0;
|
||||
}
|
||||
$ipnum = ip2long($addr);
|
||||
return _get_region($gi, $ipnum);
|
||||
}
|
||||
|
||||
function getdnsattributes ($l,$ip){
|
||||
$r = new Net_DNS_Resolver();
|
||||
$r->nameservers = array("ws1.maxmind.com");
|
||||
$p = $r->search($l."." . $ip .".s.maxmind.com","TXT","IN");
|
||||
$str = is_object($p->answer[0])?$p->answer[0]->string():'';
|
||||
$str = substr( $str, 1, -1 );
|
||||
return $str;
|
||||
}
|
||||
|
||||
?>
|
||||
237
www/analytics/libs/MaxMindGeoIP/geoipcity.inc
Executable file
237
www/analytics/libs/MaxMindGeoIP/geoipcity.inc
Executable file
|
|
@ -0,0 +1,237 @@
|
|||
<?php
|
||||
|
||||
/* geoipcity.inc
|
||||
*
|
||||
* Copyright (C) 2004 Maxmind LLC
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/*
|
||||
* Changelog:
|
||||
*
|
||||
* 2005-01-13 Andrew Hill, Awarez Ltd. (http://www.awarez.net)
|
||||
* Formatted file according to PEAR library standards.
|
||||
* Changed inclusion of geoip.inc file to require_once, so that
|
||||
* this library can be used in the same script as geoip.inc.
|
||||
*/
|
||||
|
||||
define("FULL_RECORD_LENGTH",50);
|
||||
|
||||
require_once 'geoip.inc';
|
||||
require_once 'geoipregionvars.php';
|
||||
|
||||
class geoiprecord {
|
||||
var $country_code;
|
||||
var $country_code3;
|
||||
var $country_name;
|
||||
var $region;
|
||||
var $city;
|
||||
var $postal_code;
|
||||
var $latitude;
|
||||
var $longitude;
|
||||
var $area_code;
|
||||
var $dma_code; # metro and dma code are the same. use metro_code
|
||||
var $metro_code;
|
||||
var $continent_code;
|
||||
}
|
||||
|
||||
class geoipdnsrecord {
|
||||
var $country_code;
|
||||
var $country_code3;
|
||||
var $country_name;
|
||||
var $region;
|
||||
var $regionname;
|
||||
var $city;
|
||||
var $postal_code;
|
||||
var $latitude;
|
||||
var $longitude;
|
||||
var $areacode;
|
||||
var $dmacode;
|
||||
var $isp;
|
||||
var $org;
|
||||
var $metrocode;
|
||||
}
|
||||
|
||||
function getrecordwithdnsservice($str){
|
||||
$record = new geoipdnsrecord;
|
||||
$keyvalue = explode(";",$str);
|
||||
foreach ($keyvalue as $keyvalue2){
|
||||
list($key,$value) = explode("=",$keyvalue2);
|
||||
if ($key == "co"){
|
||||
$record->country_code = $value;
|
||||
}
|
||||
if ($key == "ci"){
|
||||
$record->city = $value;
|
||||
}
|
||||
if ($key == "re"){
|
||||
$record->region = $value;
|
||||
}
|
||||
if ($key == "ac"){
|
||||
$record->areacode = $value;
|
||||
}
|
||||
if ($key == "dm" || $key == "me" ){
|
||||
$record->dmacode = $value;
|
||||
$record->metrocode = $value;
|
||||
}
|
||||
if ($key == "is"){
|
||||
$record->isp = $value;
|
||||
}
|
||||
if ($key == "or"){
|
||||
$record->org = $value;
|
||||
}
|
||||
if ($key == "zi"){
|
||||
$record->postal_code = $value;
|
||||
}
|
||||
if ($key == "la"){
|
||||
$record->latitude = $value;
|
||||
}
|
||||
if ($key == "lo"){
|
||||
$record->longitude = $value;
|
||||
}
|
||||
}
|
||||
$number = $GLOBALS['GEOIP_COUNTRY_CODE_TO_NUMBER'][$record->country_code];
|
||||
$record->country_code3 = $GLOBALS['GEOIP_COUNTRY_CODES3'][$number];
|
||||
$record->country_name = $GLOBALS['GEOIP_COUNTRY_NAMES'][$number];
|
||||
if ($record->region != "") {
|
||||
if (($record->country_code == "US") || ($record->country_code == "CA")){
|
||||
$record->regionname = $GLOBALS['ISO'][$record->country_code][$record->region];
|
||||
} else {
|
||||
$record->regionname = $GLOBALS['FIPS'][$record->country_code][$record->region];
|
||||
}
|
||||
}
|
||||
return $record;
|
||||
}
|
||||
|
||||
|
||||
function _get_record_v6($gi,$ipnum){
|
||||
$seek_country = _geoip_seek_country_v6($gi,$ipnum);
|
||||
if ($seek_country == $gi->databaseSegments) {
|
||||
return NULL;
|
||||
}
|
||||
return _common_get_record($gi, $seek_country);
|
||||
}
|
||||
|
||||
function _common_get_record($gi, $seek_country){
|
||||
// workaround php's broken substr, strpos, etc handling with
|
||||
// mbstring.func_overload and mbstring.internal_encoding
|
||||
$enc = mb_internal_encoding();
|
||||
mb_internal_encoding('ISO-8859-1');
|
||||
|
||||
$record_pointer = $seek_country + (2 * $gi->record_length - 1) * $gi->databaseSegments;
|
||||
|
||||
if ($gi->flags & GEOIP_MEMORY_CACHE) {
|
||||
$record_buf = substr($gi->memory_buffer,$record_pointer,FULL_RECORD_LENGTH);
|
||||
} elseif ($gi->flags & GEOIP_SHARED_MEMORY){
|
||||
$record_buf = @shmop_read($gi->shmid,$record_pointer,FULL_RECORD_LENGTH);
|
||||
} else {
|
||||
fseek($gi->filehandle, $record_pointer, SEEK_SET);
|
||||
$record_buf = fread($gi->filehandle,FULL_RECORD_LENGTH);
|
||||
}
|
||||
$record = new geoiprecord;
|
||||
$record_buf_pos = 0;
|
||||
$char = ord(substr($record_buf,$record_buf_pos,1));
|
||||
$record->country_code = $gi->GEOIP_COUNTRY_CODES[$char];
|
||||
$record->country_code3 = $gi->GEOIP_COUNTRY_CODES3[$char];
|
||||
$record->country_name = $gi->GEOIP_COUNTRY_NAMES[$char];
|
||||
$record->continent_code = $gi->GEOIP_CONTINENT_CODES[$char];
|
||||
$record_buf_pos++;
|
||||
$str_length = 0;
|
||||
// Get region
|
||||
$char = ord(substr($record_buf,$record_buf_pos+$str_length,1));
|
||||
while ($char != 0){
|
||||
$str_length++;
|
||||
$char = ord(substr($record_buf,$record_buf_pos+$str_length,1));
|
||||
}
|
||||
if ($str_length > 0){
|
||||
$record->region = substr($record_buf,$record_buf_pos,$str_length);
|
||||
}
|
||||
$record_buf_pos += $str_length + 1;
|
||||
$str_length = 0;
|
||||
// Get city
|
||||
$char = ord(substr($record_buf,$record_buf_pos+$str_length,1));
|
||||
while ($char != 0){
|
||||
$str_length++;
|
||||
$char = ord(substr($record_buf,$record_buf_pos+$str_length,1));
|
||||
}
|
||||
if ($str_length > 0){
|
||||
$record->city = substr($record_buf,$record_buf_pos,$str_length);
|
||||
}
|
||||
$record_buf_pos += $str_length + 1;
|
||||
$str_length = 0;
|
||||
// Get postal code
|
||||
$char = ord(substr($record_buf,$record_buf_pos+$str_length,1));
|
||||
while ($char != 0){
|
||||
$str_length++;
|
||||
$char = ord(substr($record_buf,$record_buf_pos+$str_length,1));
|
||||
}
|
||||
if ($str_length > 0){
|
||||
$record->postal_code = substr($record_buf,$record_buf_pos,$str_length);
|
||||
}
|
||||
$record_buf_pos += $str_length + 1;
|
||||
$str_length = 0;
|
||||
// Get latitude and longitude
|
||||
$latitude = 0;
|
||||
$longitude = 0;
|
||||
for ($j = 0;$j < 3; ++$j){
|
||||
$char = ord(substr($record_buf,$record_buf_pos++,1));
|
||||
$latitude += ($char << ($j * 8));
|
||||
}
|
||||
$record->latitude = ($latitude/10000) - 180;
|
||||
for ($j = 0;$j < 3; ++$j){
|
||||
$char = ord(substr($record_buf,$record_buf_pos++,1));
|
||||
$longitude += ($char << ($j * 8));
|
||||
}
|
||||
$record->longitude = ($longitude/10000) - 180;
|
||||
if (GEOIP_CITY_EDITION_REV1 == $gi->databaseType){
|
||||
$metroarea_combo = 0;
|
||||
if ($record->country_code == "US"){
|
||||
for ($j = 0;$j < 3;++$j){
|
||||
$char = ord(substr($record_buf,$record_buf_pos++,1));
|
||||
$metroarea_combo += ($char << ($j * 8));
|
||||
}
|
||||
$record->metro_code = $record->dma_code = floor($metroarea_combo/1000);
|
||||
$record->area_code = $metroarea_combo%1000;
|
||||
}
|
||||
}
|
||||
mb_internal_encoding($enc);
|
||||
return $record;
|
||||
}
|
||||
|
||||
function GeoIP_record_by_addr_v6 ($gi,$addr){
|
||||
if ($addr == NULL){
|
||||
return 0;
|
||||
}
|
||||
$ipnum = inet_pton($addr);
|
||||
return _get_record_v6($gi, $ipnum);
|
||||
}
|
||||
|
||||
function _get_record($gi,$ipnum){
|
||||
$seek_country = _geoip_seek_country($gi,$ipnum);
|
||||
if ($seek_country == $gi->databaseSegments) {
|
||||
return NULL;
|
||||
}
|
||||
return _common_get_record($gi, $seek_country);
|
||||
}
|
||||
|
||||
function GeoIP_record_by_addr ($gi,$addr){
|
||||
if ($addr == NULL){
|
||||
return 0;
|
||||
}
|
||||
$ipnum = ip2long($addr);
|
||||
return _get_record($gi, $ipnum);
|
||||
}
|
||||
|
||||
?>
|
||||
4192
www/analytics/libs/MaxMindGeoIP/geoipregionvars.php
Executable file
4192
www/analytics/libs/MaxMindGeoIP/geoipregionvars.php
Executable file
File diff suppressed because it is too large
Load diff
1063
www/analytics/libs/PEAR.php
Normal file
1063
www/analytics/libs/PEAR.php
Normal file
File diff suppressed because it is too large
Load diff
389
www/analytics/libs/PEAR/Exception.php
Normal file
389
www/analytics/libs/PEAR/Exception.php
Normal file
|
|
@ -0,0 +1,389 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */
|
||||
/**
|
||||
* PEAR_Exception
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* @category pear
|
||||
* @package PEAR
|
||||
* @author Tomas V. V. Cox <cox@idecnet.com>
|
||||
* @author Hans Lellelid <hans@velum.net>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @author Greg Beaver <cellog@php.net>
|
||||
* @copyright 1997-2009 The Authors
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version CVS: $Id: Exception.php 296939 2010-03-27 16:24:43Z dufuz $
|
||||
* @link http://pear.php.net/package/PEAR
|
||||
* @since File available since Release 1.3.3
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Base PEAR_Exception Class
|
||||
*
|
||||
* 1) Features:
|
||||
*
|
||||
* - Nestable exceptions (throw new PEAR_Exception($msg, $prev_exception))
|
||||
* - Definable triggers, shot when exceptions occur
|
||||
* - Pretty and informative error messages
|
||||
* - Added more context info available (like class, method or cause)
|
||||
* - cause can be a PEAR_Exception or an array of mixed
|
||||
* PEAR_Exceptions/PEAR_ErrorStack warnings
|
||||
* - callbacks for specific exception classes and their children
|
||||
*
|
||||
* 2) Ideas:
|
||||
*
|
||||
* - Maybe a way to define a 'template' for the output
|
||||
*
|
||||
* 3) Inherited properties from PHP Exception Class:
|
||||
*
|
||||
* protected $message
|
||||
* protected $code
|
||||
* protected $line
|
||||
* protected $file
|
||||
* private $trace
|
||||
*
|
||||
* 4) Inherited methods from PHP Exception Class:
|
||||
*
|
||||
* __clone
|
||||
* __construct
|
||||
* getMessage
|
||||
* getCode
|
||||
* getFile
|
||||
* getLine
|
||||
* getTraceSafe
|
||||
* getTraceSafeAsString
|
||||
* __toString
|
||||
*
|
||||
* 5) Usage example
|
||||
*
|
||||
* <code>
|
||||
* require_once 'PEAR/Exception.php';
|
||||
*
|
||||
* class Test {
|
||||
* function foo() {
|
||||
* throw new PEAR_Exception('Error Message', ERROR_CODE);
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* function myLogger($pear_exception) {
|
||||
* echo $pear_exception->getMessage();
|
||||
* }
|
||||
* // each time a exception is thrown the 'myLogger' will be called
|
||||
* // (its use is completely optional)
|
||||
* PEAR_Exception::addObserver('myLogger');
|
||||
* $test = new Test;
|
||||
* try {
|
||||
* $test->foo();
|
||||
* } catch (PEAR_Exception $e) {
|
||||
* print $e;
|
||||
* }
|
||||
* </code>
|
||||
*
|
||||
* @category pear
|
||||
* @package PEAR
|
||||
* @author Tomas V.V.Cox <cox@idecnet.com>
|
||||
* @author Hans Lellelid <hans@velum.net>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @author Greg Beaver <cellog@php.net>
|
||||
* @copyright 1997-2009 The Authors
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version Release: 1.9.1
|
||||
* @link http://pear.php.net/package/PEAR
|
||||
* @since Class available since Release 1.3.3
|
||||
*
|
||||
*/
|
||||
class PEAR_Exception extends Exception
|
||||
{
|
||||
const OBSERVER_PRINT = -2;
|
||||
const OBSERVER_TRIGGER = -4;
|
||||
const OBSERVER_DIE = -8;
|
||||
protected $cause;
|
||||
private static $_observers = array();
|
||||
private static $_uniqueid = 0;
|
||||
private $_trace;
|
||||
|
||||
/**
|
||||
* Supported signatures:
|
||||
* - PEAR_Exception(string $message);
|
||||
* - PEAR_Exception(string $message, int $code);
|
||||
* - PEAR_Exception(string $message, Exception $cause);
|
||||
* - PEAR_Exception(string $message, Exception $cause, int $code);
|
||||
* - PEAR_Exception(string $message, PEAR_Error $cause);
|
||||
* - PEAR_Exception(string $message, PEAR_Error $cause, int $code);
|
||||
* - PEAR_Exception(string $message, array $causes);
|
||||
* - PEAR_Exception(string $message, array $causes, int $code);
|
||||
* @param string exception message
|
||||
* @param int|Exception|PEAR_Error|array|null exception cause
|
||||
* @param int|null exception code or null
|
||||
*/
|
||||
public function __construct($message, $p2 = null, $p3 = null)
|
||||
{
|
||||
if (is_int($p2)) {
|
||||
$code = $p2;
|
||||
$this->cause = null;
|
||||
} elseif (is_object($p2) || is_array($p2)) {
|
||||
// using is_object allows both Exception and PEAR_Error
|
||||
if (is_object($p2) && !($p2 instanceof Exception)) {
|
||||
if (!class_exists('PEAR_Error') || !($p2 instanceof PEAR_Error)) {
|
||||
throw new PEAR_Exception('exception cause must be Exception, ' .
|
||||
'array, or PEAR_Error');
|
||||
}
|
||||
}
|
||||
$code = $p3;
|
||||
if (is_array($p2) && isset($p2['message'])) {
|
||||
// fix potential problem of passing in a single warning
|
||||
$p2 = array($p2);
|
||||
}
|
||||
$this->cause = $p2;
|
||||
} else {
|
||||
$code = null;
|
||||
$this->cause = null;
|
||||
}
|
||||
parent::__construct($message, $code);
|
||||
$this->signal();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $callback - A valid php callback, see php func is_callable()
|
||||
* - A PEAR_Exception::OBSERVER_* constant
|
||||
* - An array(const PEAR_Exception::OBSERVER_*,
|
||||
* mixed $options)
|
||||
* @param string $label The name of the observer. Use this if you want
|
||||
* to remove it later with removeObserver()
|
||||
*/
|
||||
public static function addObserver($callback, $label = 'default')
|
||||
{
|
||||
self::$_observers[$label] = $callback;
|
||||
}
|
||||
|
||||
public static function removeObserver($label = 'default')
|
||||
{
|
||||
unset(self::$_observers[$label]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int unique identifier for an observer
|
||||
*/
|
||||
public static function getUniqueId()
|
||||
{
|
||||
return self::$_uniqueid++;
|
||||
}
|
||||
|
||||
private function signal()
|
||||
{
|
||||
foreach (self::$_observers as $func) {
|
||||
if (is_callable($func)) {
|
||||
call_user_func($func, $this);
|
||||
continue;
|
||||
}
|
||||
settype($func, 'array');
|
||||
switch ($func[0]) {
|
||||
case self::OBSERVER_PRINT :
|
||||
$f = (isset($func[1])) ? $func[1] : '%s';
|
||||
printf($f, $this->getMessage());
|
||||
break;
|
||||
case self::OBSERVER_TRIGGER :
|
||||
$f = (isset($func[1])) ? $func[1] : E_USER_NOTICE;
|
||||
trigger_error($this->getMessage(), $f);
|
||||
break;
|
||||
case self::OBSERVER_DIE :
|
||||
$f = (isset($func[1])) ? $func[1] : '%s';
|
||||
die(printf($f, $this->getMessage()));
|
||||
break;
|
||||
default:
|
||||
trigger_error('invalid observer type', E_USER_WARNING);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return specific error information that can be used for more detailed
|
||||
* error messages or translation.
|
||||
*
|
||||
* This method may be overridden in child exception classes in order
|
||||
* to add functionality not present in PEAR_Exception and is a placeholder
|
||||
* to define API
|
||||
*
|
||||
* The returned array must be an associative array of parameter => value like so:
|
||||
* <pre>
|
||||
* array('name' => $name, 'context' => array(...))
|
||||
* </pre>
|
||||
* @return array
|
||||
*/
|
||||
public function getErrorData()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the exception that caused this exception to be thrown
|
||||
* @access public
|
||||
* @return Exception|array The context of the exception
|
||||
*/
|
||||
public function getCause()
|
||||
{
|
||||
return $this->cause;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function must be public to call on caused exceptions
|
||||
* @param array
|
||||
*/
|
||||
public function getCauseMessage(&$causes)
|
||||
{
|
||||
$trace = $this->getTraceSafe();
|
||||
$cause = array('class' => get_class($this),
|
||||
'message' => $this->message,
|
||||
'file' => 'unknown',
|
||||
'line' => 'unknown');
|
||||
if (isset($trace[0])) {
|
||||
if (isset($trace[0]['file'])) {
|
||||
$cause['file'] = $trace[0]['file'];
|
||||
$cause['line'] = $trace[0]['line'];
|
||||
}
|
||||
}
|
||||
$causes[] = $cause;
|
||||
if ($this->cause instanceof PEAR_Exception) {
|
||||
$this->cause->getCauseMessage($causes);
|
||||
} elseif ($this->cause instanceof Exception) {
|
||||
$causes[] = array('class' => get_class($this->cause),
|
||||
'message' => $this->cause->getMessage(),
|
||||
'file' => $this->cause->getFile(),
|
||||
'line' => $this->cause->getLine());
|
||||
} elseif (class_exists('PEAR_Error') && $this->cause instanceof PEAR_Error) {
|
||||
$causes[] = array('class' => get_class($this->cause),
|
||||
'message' => $this->cause->getMessage(),
|
||||
'file' => 'unknown',
|
||||
'line' => 'unknown');
|
||||
} elseif (is_array($this->cause)) {
|
||||
foreach ($this->cause as $cause) {
|
||||
if ($cause instanceof PEAR_Exception) {
|
||||
$cause->getCauseMessage($causes);
|
||||
} elseif ($cause instanceof Exception) {
|
||||
$causes[] = array('class' => get_class($cause),
|
||||
'message' => $cause->getMessage(),
|
||||
'file' => $cause->getFile(),
|
||||
'line' => $cause->getLine());
|
||||
} elseif (class_exists('PEAR_Error') && $cause instanceof PEAR_Error) {
|
||||
$causes[] = array('class' => get_class($cause),
|
||||
'message' => $cause->getMessage(),
|
||||
'file' => 'unknown',
|
||||
'line' => 'unknown');
|
||||
} elseif (is_array($cause) && isset($cause['message'])) {
|
||||
// PEAR_ErrorStack warning
|
||||
$causes[] = array(
|
||||
'class' => $cause['package'],
|
||||
'message' => $cause['message'],
|
||||
'file' => isset($cause['context']['file']) ?
|
||||
$cause['context']['file'] :
|
||||
'unknown',
|
||||
'line' => isset($cause['context']['line']) ?
|
||||
$cause['context']['line'] :
|
||||
'unknown',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getTraceSafe()
|
||||
{
|
||||
if (!isset($this->_trace)) {
|
||||
$this->_trace = $this->getTrace();
|
||||
if (empty($this->_trace)) {
|
||||
$backtrace = debug_backtrace();
|
||||
$this->_trace = array($backtrace[count($backtrace)-1]);
|
||||
}
|
||||
}
|
||||
return $this->_trace;
|
||||
}
|
||||
|
||||
public function getErrorClass()
|
||||
{
|
||||
$trace = $this->getTraceSafe();
|
||||
return $trace[0]['class'];
|
||||
}
|
||||
|
||||
public function getErrorMethod()
|
||||
{
|
||||
$trace = $this->getTraceSafe();
|
||||
return $trace[0]['function'];
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
if (isset($_SERVER['REQUEST_URI'])) {
|
||||
return $this->toHtml();
|
||||
}
|
||||
return $this->toText();
|
||||
}
|
||||
|
||||
public function toHtml()
|
||||
{
|
||||
$trace = $this->getTraceSafe();
|
||||
$causes = array();
|
||||
$this->getCauseMessage($causes);
|
||||
$html = '<table style="border: 1px" cellspacing="0">' . "\n";
|
||||
foreach ($causes as $i => $cause) {
|
||||
$html .= '<tr><td colspan="3" style="background: #ff9999">'
|
||||
. str_repeat('-', $i) . ' <b>' . $cause['class'] . '</b>: '
|
||||
. htmlspecialchars($cause['message']) . ' in <b>' . $cause['file'] . '</b> '
|
||||
. 'on line <b>' . $cause['line'] . '</b>'
|
||||
. "</td></tr>\n";
|
||||
}
|
||||
$html .= '<tr><td colspan="3" style="background-color: #aaaaaa; text-align: center; font-weight: bold;">Exception trace</td></tr>' . "\n"
|
||||
. '<tr><td style="text-align: center; background: #cccccc; width:20px; font-weight: bold;">#</td>'
|
||||
. '<td style="text-align: center; background: #cccccc; font-weight: bold;">Function</td>'
|
||||
. '<td style="text-align: center; background: #cccccc; font-weight: bold;">Location</td></tr>' . "\n";
|
||||
|
||||
foreach ($trace as $k => $v) {
|
||||
$html .= '<tr><td style="text-align: center;">' . $k . '</td>'
|
||||
. '<td>';
|
||||
if (!empty($v['class'])) {
|
||||
$html .= $v['class'] . $v['type'];
|
||||
}
|
||||
$html .= $v['function'];
|
||||
$args = array();
|
||||
if (!empty($v['args'])) {
|
||||
foreach ($v['args'] as $arg) {
|
||||
if (is_null($arg)) $args[] = 'null';
|
||||
elseif (is_array($arg)) $args[] = 'Array';
|
||||
elseif (is_object($arg)) $args[] = 'Object('.get_class($arg).')';
|
||||
elseif (is_bool($arg)) $args[] = $arg ? 'true' : 'false';
|
||||
elseif (is_int($arg) || is_double($arg)) $args[] = $arg;
|
||||
else {
|
||||
$arg = (string)$arg;
|
||||
$str = htmlspecialchars(substr($arg, 0, 16));
|
||||
if (strlen($arg) > 16) $str .= '…';
|
||||
$args[] = "'" . $str . "'";
|
||||
}
|
||||
}
|
||||
}
|
||||
$html .= '(' . implode(', ',$args) . ')'
|
||||
. '</td>'
|
||||
. '<td>' . (isset($v['file']) ? $v['file'] : 'unknown')
|
||||
. ':' . (isset($v['line']) ? $v['line'] : 'unknown')
|
||||
. '</td></tr>' . "\n";
|
||||
}
|
||||
$html .= '<tr><td style="text-align: center;">' . ($k+1) . '</td>'
|
||||
. '<td>{main}</td>'
|
||||
. '<td> </td></tr>' . "\n"
|
||||
. '</table>';
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function toText()
|
||||
{
|
||||
$causes = array();
|
||||
$this->getCauseMessage($causes);
|
||||
$causeMsg = '';
|
||||
foreach ($causes as $i => $cause) {
|
||||
$causeMsg .= str_repeat(' ', $i) . $cause['class'] . ': '
|
||||
. $cause['message'] . ' in ' . $cause['file']
|
||||
. ' on line ' . $cause['line'] . "\n";
|
||||
}
|
||||
return $causeMsg . $this->getTraceAsString();
|
||||
}
|
||||
}
|
||||
7
www/analytics/libs/PEAR/FixPHP5PEARWarnings.php
Normal file
7
www/analytics/libs/PEAR/FixPHP5PEARWarnings.php
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
if ($skipmsg) {
|
||||
$a = new $ec($code, $mode, $options, $userinfo);
|
||||
} else {
|
||||
$a = new $ec($message, $code, $mode, $options, $userinfo);
|
||||
}
|
||||
?>
|
||||
27
www/analytics/libs/PEAR/LICENSE
Normal file
27
www/analytics/libs/PEAR/LICENSE
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
Copyright (c) 1997-2009,
|
||||
Stig Bakken <ssb@php.net>,
|
||||
Gregory Beaver <cellog@php.net>,
|
||||
Helgi Þormar Þorbjörnsson <helgi@php.net>,
|
||||
Tomas V.V.Cox <cox@idecnet.com>,
|
||||
Martin Jansen <mj@php.net>.
|
||||
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.
|
||||
|
||||
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.
|
||||
33
www/analytics/libs/PEAR5.php
Normal file
33
www/analytics/libs/PEAR5.php
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
/**
|
||||
* This is only meant for PHP 5 to get rid of certain strict warning
|
||||
* that doesn't get hidden since it's in the shutdown function
|
||||
*/
|
||||
class PEAR5
|
||||
{
|
||||
/**
|
||||
* If you have a class that's mostly/entirely static, and you need static
|
||||
* properties, you can use this method to simulate them. Eg. in your method(s)
|
||||
* do this: $myVar = &PEAR5::getStaticProperty('myclass', 'myVar');
|
||||
* You MUST use a reference, or they will not persist!
|
||||
*
|
||||
* @access public
|
||||
* @param string $class The calling classname, to prevent clashes
|
||||
* @param string $var The variable to retrieve.
|
||||
* @return mixed A reference to the variable. If not set it will be
|
||||
* auto initialised to NULL.
|
||||
*/
|
||||
static function &getStaticProperty($class, $var)
|
||||
{
|
||||
static $properties;
|
||||
if (!isset($properties[$class])) {
|
||||
$properties[$class] = array();
|
||||
}
|
||||
|
||||
if (!array_key_exists($var, $properties[$class])) {
|
||||
$properties[$class][$var] = null;
|
||||
}
|
||||
|
||||
return $properties[$class][$var];
|
||||
}
|
||||
}
|
||||
502
www/analytics/libs/PclZip/lgpl-2.1.txt
Normal file
502
www/analytics/libs/PclZip/lgpl-2.1.txt
Normal file
|
|
@ -0,0 +1,502 @@
|
|||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 2.1, February 1999
|
||||
|
||||
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
[This is the first released version of the Lesser GPL. It also counts
|
||||
as the successor of the GNU Library Public License, version 2, hence
|
||||
the version number 2.1.]
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
Licenses are intended to guarantee your freedom to share and change
|
||||
free software--to make sure the software is free for all its users.
|
||||
|
||||
This license, the Lesser General Public License, applies to some
|
||||
specially designated software packages--typically libraries--of the
|
||||
Free Software Foundation and other authors who decide to use it. You
|
||||
can use it too, but we suggest you first think carefully about whether
|
||||
this license or the ordinary General Public License is the better
|
||||
strategy to use in any particular case, based on the explanations below.
|
||||
|
||||
When we speak of free software, we are referring to freedom of use,
|
||||
not price. Our General Public Licenses are designed to make sure that
|
||||
you have the freedom to distribute copies of free software (and charge
|
||||
for this service if you wish); that you receive source code or can get
|
||||
it if you want it; that you can change the software and use pieces of
|
||||
it in new free programs; and that you are informed that you can do
|
||||
these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
distributors to deny you these rights or to ask you to surrender these
|
||||
rights. These restrictions translate to certain responsibilities for
|
||||
you if you distribute copies of the library or if you modify it.
|
||||
|
||||
For example, if you distribute copies of the library, whether gratis
|
||||
or for a fee, you must give the recipients all the rights that we gave
|
||||
you. You must make sure that they, too, receive or can get the source
|
||||
code. If you link other code with the library, you must provide
|
||||
complete object files to the recipients, so that they can relink them
|
||||
with the library after making changes to the library and recompiling
|
||||
it. And you must show them these terms so they know their rights.
|
||||
|
||||
We protect your rights with a two-step method: (1) we copyright the
|
||||
library, and (2) we offer you this license, which gives you legal
|
||||
permission to copy, distribute and/or modify the library.
|
||||
|
||||
To protect each distributor, we want to make it very clear that
|
||||
there is no warranty for the free library. Also, if the library is
|
||||
modified by someone else and passed on, the recipients should know
|
||||
that what they have is not the original version, so that the original
|
||||
author's reputation will not be affected by problems that might be
|
||||
introduced by others.
|
||||
|
||||
Finally, software patents pose a constant threat to the existence of
|
||||
any free program. We wish to make sure that a company cannot
|
||||
effectively restrict the users of a free program by obtaining a
|
||||
restrictive license from a patent holder. Therefore, we insist that
|
||||
any patent license obtained for a version of the library must be
|
||||
consistent with the full freedom of use specified in this license.
|
||||
|
||||
Most GNU software, including some libraries, is covered by the
|
||||
ordinary GNU General Public License. This license, the GNU Lesser
|
||||
General Public License, applies to certain designated libraries, and
|
||||
is quite different from the ordinary General Public License. We use
|
||||
this license for certain libraries in order to permit linking those
|
||||
libraries into non-free programs.
|
||||
|
||||
When a program is linked with a library, whether statically or using
|
||||
a shared library, the combination of the two is legally speaking a
|
||||
combined work, a derivative of the original library. The ordinary
|
||||
General Public License therefore permits such linking only if the
|
||||
entire combination fits its criteria of freedom. The Lesser General
|
||||
Public License permits more lax criteria for linking other code with
|
||||
the library.
|
||||
|
||||
We call this license the "Lesser" General Public License because it
|
||||
does Less to protect the user's freedom than the ordinary General
|
||||
Public License. It also provides other free software developers Less
|
||||
of an advantage over competing non-free programs. These disadvantages
|
||||
are the reason we use the ordinary General Public License for many
|
||||
libraries. However, the Lesser license provides advantages in certain
|
||||
special circumstances.
|
||||
|
||||
For example, on rare occasions, there may be a special need to
|
||||
encourage the widest possible use of a certain library, so that it becomes
|
||||
a de-facto standard. To achieve this, non-free programs must be
|
||||
allowed to use the library. A more frequent case is that a free
|
||||
library does the same job as widely used non-free libraries. In this
|
||||
case, there is little to gain by limiting the free library to free
|
||||
software only, so we use the Lesser General Public License.
|
||||
|
||||
In other cases, permission to use a particular library in non-free
|
||||
programs enables a greater number of people to use a large body of
|
||||
free software. For example, permission to use the GNU C Library in
|
||||
non-free programs enables many more people to use the whole GNU
|
||||
operating system, as well as its variant, the GNU/Linux operating
|
||||
system.
|
||||
|
||||
Although the Lesser General Public License is Less protective of the
|
||||
users' freedom, it does ensure that the user of a program that is
|
||||
linked with the Library has the freedom and the wherewithal to run
|
||||
that program using a modified version of the Library.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow. Pay close attention to the difference between a
|
||||
"work based on the library" and a "work that uses the library". The
|
||||
former contains code derived from the library, whereas the latter must
|
||||
be combined with the library in order to run.
|
||||
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License Agreement applies to any software library or other
|
||||
program which contains a notice placed by the copyright holder or
|
||||
other authorized party saying it may be distributed under the terms of
|
||||
this Lesser General Public License (also called "this License").
|
||||
Each licensee is addressed as "you".
|
||||
|
||||
A "library" means a collection of software functions and/or data
|
||||
prepared so as to be conveniently linked with application programs
|
||||
(which use some of those functions and data) to form executables.
|
||||
|
||||
The "Library", below, refers to any such software library or work
|
||||
which has been distributed under these terms. A "work based on the
|
||||
Library" means either the Library or any derivative work under
|
||||
copyright law: that is to say, a work containing the Library or a
|
||||
portion of it, either verbatim or with modifications and/or translated
|
||||
straightforwardly into another language. (Hereinafter, translation is
|
||||
included without limitation in the term "modification".)
|
||||
|
||||
"Source code" for a work means the preferred form of the work for
|
||||
making modifications to it. For a library, complete source code means
|
||||
all the source code for all modules it contains, plus any associated
|
||||
interface definition files, plus the scripts used to control compilation
|
||||
and installation of the library.
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running a program using the Library is not restricted, and output from
|
||||
such a program is covered only if its contents constitute a work based
|
||||
on the Library (independent of the use of the Library in a tool for
|
||||
writing it). Whether that is true depends on what the Library does
|
||||
and what the program that uses the Library does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Library's
|
||||
complete source code as you receive it, in any medium, provided that
|
||||
you conspicuously and appropriately publish on each copy an
|
||||
appropriate copyright notice and disclaimer of warranty; keep intact
|
||||
all the notices that refer to this License and to the absence of any
|
||||
warranty; and distribute a copy of this License along with the
|
||||
Library.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy,
|
||||
and you may at your option offer warranty protection in exchange for a
|
||||
fee.
|
||||
|
||||
2. You may modify your copy or copies of the Library or any portion
|
||||
of it, thus forming a work based on the Library, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) The modified work must itself be a software library.
|
||||
|
||||
b) You must cause the files modified to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
c) You must cause the whole of the work to be licensed at no
|
||||
charge to all third parties under the terms of this License.
|
||||
|
||||
d) If a facility in the modified Library refers to a function or a
|
||||
table of data to be supplied by an application program that uses
|
||||
the facility, other than as an argument passed when the facility
|
||||
is invoked, then you must make a good faith effort to ensure that,
|
||||
in the event an application does not supply such function or
|
||||
table, the facility still operates, and performs whatever part of
|
||||
its purpose remains meaningful.
|
||||
|
||||
(For example, a function in a library to compute square roots has
|
||||
a purpose that is entirely well-defined independent of the
|
||||
application. Therefore, Subsection 2d requires that any
|
||||
application-supplied function or table used by this function must
|
||||
be optional: if the application does not supply it, the square
|
||||
root function must still compute square roots.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Library,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Library, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote
|
||||
it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Library.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Library
|
||||
with the Library (or with a work based on the Library) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may opt to apply the terms of the ordinary GNU General Public
|
||||
License instead of this License to a given copy of the Library. To do
|
||||
this, you must alter all the notices that refer to this License, so
|
||||
that they refer to the ordinary GNU General Public License, version 2,
|
||||
instead of to this License. (If a newer version than version 2 of the
|
||||
ordinary GNU General Public License has appeared, then you can specify
|
||||
that version instead if you wish.) Do not make any other change in
|
||||
these notices.
|
||||
|
||||
Once this change is made in a given copy, it is irreversible for
|
||||
that copy, so the ordinary GNU General Public License applies to all
|
||||
subsequent copies and derivative works made from that copy.
|
||||
|
||||
This option is useful when you wish to copy part of the code of
|
||||
the Library into a program that is not a library.
|
||||
|
||||
4. You may copy and distribute the Library (or a portion or
|
||||
derivative of it, under Section 2) in object code or executable form
|
||||
under the terms of Sections 1 and 2 above provided that you accompany
|
||||
it with the complete corresponding machine-readable source code, which
|
||||
must be distributed under the terms of Sections 1 and 2 above on a
|
||||
medium customarily used for software interchange.
|
||||
|
||||
If distribution of object code is made by offering access to copy
|
||||
from a designated place, then offering equivalent access to copy the
|
||||
source code from the same place satisfies the requirement to
|
||||
distribute the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
5. A program that contains no derivative of any portion of the
|
||||
Library, but is designed to work with the Library by being compiled or
|
||||
linked with it, is called a "work that uses the Library". Such a
|
||||
work, in isolation, is not a derivative work of the Library, and
|
||||
therefore falls outside the scope of this License.
|
||||
|
||||
However, linking a "work that uses the Library" with the Library
|
||||
creates an executable that is a derivative of the Library (because it
|
||||
contains portions of the Library), rather than a "work that uses the
|
||||
library". The executable is therefore covered by this License.
|
||||
Section 6 states terms for distribution of such executables.
|
||||
|
||||
When a "work that uses the Library" uses material from a header file
|
||||
that is part of the Library, the object code for the work may be a
|
||||
derivative work of the Library even though the source code is not.
|
||||
Whether this is true is especially significant if the work can be
|
||||
linked without the Library, or if the work is itself a library. The
|
||||
threshold for this to be true is not precisely defined by law.
|
||||
|
||||
If such an object file uses only numerical parameters, data
|
||||
structure layouts and accessors, and small macros and small inline
|
||||
functions (ten lines or less in length), then the use of the object
|
||||
file is unrestricted, regardless of whether it is legally a derivative
|
||||
work. (Executables containing this object code plus portions of the
|
||||
Library will still fall under Section 6.)
|
||||
|
||||
Otherwise, if the work is a derivative of the Library, you may
|
||||
distribute the object code for the work under the terms of Section 6.
|
||||
Any executables containing that work also fall under Section 6,
|
||||
whether or not they are linked directly with the Library itself.
|
||||
|
||||
6. As an exception to the Sections above, you may also combine or
|
||||
link a "work that uses the Library" with the Library to produce a
|
||||
work containing portions of the Library, and distribute that work
|
||||
under terms of your choice, provided that the terms permit
|
||||
modification of the work for the customer's own use and reverse
|
||||
engineering for debugging such modifications.
|
||||
|
||||
You must give prominent notice with each copy of the work that the
|
||||
Library is used in it and that the Library and its use are covered by
|
||||
this License. You must supply a copy of this License. If the work
|
||||
during execution displays copyright notices, you must include the
|
||||
copyright notice for the Library among them, as well as a reference
|
||||
directing the user to the copy of this License. Also, you must do one
|
||||
of these things:
|
||||
|
||||
a) Accompany the work with the complete corresponding
|
||||
machine-readable source code for the Library including whatever
|
||||
changes were used in the work (which must be distributed under
|
||||
Sections 1 and 2 above); and, if the work is an executable linked
|
||||
with the Library, with the complete machine-readable "work that
|
||||
uses the Library", as object code and/or source code, so that the
|
||||
user can modify the Library and then relink to produce a modified
|
||||
executable containing the modified Library. (It is understood
|
||||
that the user who changes the contents of definitions files in the
|
||||
Library will not necessarily be able to recompile the application
|
||||
to use the modified definitions.)
|
||||
|
||||
b) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (1) uses at run time a
|
||||
copy of the library already present on the user's computer system,
|
||||
rather than copying library functions into the executable, and (2)
|
||||
will operate properly with a modified version of the library, if
|
||||
the user installs one, as long as the modified version is
|
||||
interface-compatible with the version that the work was made with.
|
||||
|
||||
c) Accompany the work with a written offer, valid for at
|
||||
least three years, to give the same user the materials
|
||||
specified in Subsection 6a, above, for a charge no more
|
||||
than the cost of performing this distribution.
|
||||
|
||||
d) If distribution of the work is made by offering access to copy
|
||||
from a designated place, offer equivalent access to copy the above
|
||||
specified materials from the same place.
|
||||
|
||||
e) Verify that the user has already received a copy of these
|
||||
materials or that you have already sent this user a copy.
|
||||
|
||||
For an executable, the required form of the "work that uses the
|
||||
Library" must include any data and utility programs needed for
|
||||
reproducing the executable from it. However, as a special exception,
|
||||
the materials to be distributed need not include anything that is
|
||||
normally distributed (in either source or binary form) with the major
|
||||
components (compiler, kernel, and so on) of the operating system on
|
||||
which the executable runs, unless that component itself accompanies
|
||||
the executable.
|
||||
|
||||
It may happen that this requirement contradicts the license
|
||||
restrictions of other proprietary libraries that do not normally
|
||||
accompany the operating system. Such a contradiction means you cannot
|
||||
use both them and the Library together in an executable that you
|
||||
distribute.
|
||||
|
||||
7. You may place library facilities that are a work based on the
|
||||
Library side-by-side in a single library together with other library
|
||||
facilities not covered by this License, and distribute such a combined
|
||||
library, provided that the separate distribution of the work based on
|
||||
the Library and of the other library facilities is otherwise
|
||||
permitted, and provided that you do these two things:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work
|
||||
based on the Library, uncombined with any other library
|
||||
facilities. This must be distributed under the terms of the
|
||||
Sections above.
|
||||
|
||||
b) Give prominent notice with the combined library of the fact
|
||||
that part of it is a work based on the Library, and explaining
|
||||
where to find the accompanying uncombined form of the same work.
|
||||
|
||||
8. You may not copy, modify, sublicense, link with, or distribute
|
||||
the Library except as expressly provided under this License. Any
|
||||
attempt otherwise to copy, modify, sublicense, link with, or
|
||||
distribute the Library is void, and will automatically terminate your
|
||||
rights under this License. However, parties who have received copies,
|
||||
or rights, from you under this License will not have their licenses
|
||||
terminated so long as such parties remain in full compliance.
|
||||
|
||||
9. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Library or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Library (or any work based on the
|
||||
Library), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Library or works based on it.
|
||||
|
||||
10. Each time you redistribute the Library (or any work based on the
|
||||
Library), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute, link with or modify the Library
|
||||
subject to these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties with
|
||||
this License.
|
||||
|
||||
11. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Library at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Library by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Library.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under any
|
||||
particular circumstance, the balance of the section is intended to apply,
|
||||
and the section as a whole is intended to apply in other circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
12. If the distribution and/or use of the Library is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Library under this License may add
|
||||
an explicit geographical distribution limitation excluding those countries,
|
||||
so that distribution is permitted only in or among countries not thus
|
||||
excluded. In such case, this License incorporates the limitation as if
|
||||
written in the body of this License.
|
||||
|
||||
13. The Free Software Foundation may publish revised and/or new
|
||||
versions of the Lesser General Public License from time to time.
|
||||
Such new versions will be similar in spirit to the present version,
|
||||
but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Library
|
||||
specifies a version number of this License which applies to it and
|
||||
"any later version", you have the option of following the terms and
|
||||
conditions either of that version or of any later version published by
|
||||
the Free Software Foundation. If the Library does not specify a
|
||||
license version number, you may choose any version ever published by
|
||||
the Free Software Foundation.
|
||||
|
||||
14. If you wish to incorporate parts of the Library into other free
|
||||
programs whose distribution conditions are incompatible with these,
|
||||
write to the author to ask for permission. For software which is
|
||||
copyrighted by the Free Software Foundation, write to the Free
|
||||
Software Foundation; we sometimes make exceptions for this. Our
|
||||
decision will be guided by the two goals of preserving the free status
|
||||
of all derivatives of our free software and of promoting the sharing
|
||||
and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
||||
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
|
||||
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
|
||||
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
||||
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
||||
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
||||
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
|
||||
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
|
||||
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
|
||||
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
|
||||
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
||||
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Libraries
|
||||
|
||||
If you develop a new library, and you want it to be of the greatest
|
||||
possible use to the public, we recommend making it free software that
|
||||
everyone can redistribute and change. You can do so by permitting
|
||||
redistribution under these terms (or, alternatively, under the terms of the
|
||||
ordinary General Public License).
|
||||
|
||||
To apply these terms, attach the following notices to the library. It is
|
||||
safest to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least the
|
||||
"copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the library's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the library, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the
|
||||
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1990
|
||||
Ty Coon, President of Vice
|
||||
|
||||
That's all there is to it!
|
||||
5694
www/analytics/libs/PclZip/pclzip.lib.php
Normal file
5694
www/analytics/libs/PclZip/pclzip.lib.php
Normal file
File diff suppressed because it is too large
Load diff
29
www/analytics/libs/PiwikTracker/LICENSE.txt
Normal file
29
www/analytics/libs/PiwikTracker/LICENSE.txt
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
Copyright 2010 Matthieu Aubry
|
||||
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.
|
||||
|
||||
* Neither the name of Matthieu Aubry nor the names of its contributors
|
||||
may 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.
|
||||
1537
www/analytics/libs/PiwikTracker/PiwikTracker.php
Normal file
1537
www/analytics/libs/PiwikTracker/PiwikTracker.php
Normal file
File diff suppressed because it is too large
Load diff
35
www/analytics/libs/README.md
Normal file
35
www/analytics/libs/README.md
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
## Piwik modifications to libs/
|
||||
|
||||
In general, bug fixes and improvements are reported upstream. Until these are
|
||||
included upstream, we maintain a list of bug fixes and local mods made to
|
||||
third-party libraries:
|
||||
|
||||
* HTML/Quickform2/
|
||||
- in r2626, php 5.1.6 incompatibility
|
||||
- in r3040, exception classes don't follow PEAR naming convention
|
||||
* pChart2.1.3/
|
||||
- the following unused files were removed:
|
||||
class/pBarcode39.class.php, class/pBarcode128.class.php,
|
||||
class/pBubble.class.php, class/pCache.class.php, class/pIndicator.class.php,
|
||||
class/pRadar.class.php, class/pScatter.class.php, class/pSplit.class.php,
|
||||
class/pSpring.class.php, class/pStock.class.php, class/pSurface.class.php,
|
||||
data/, examples/, fonts/, palettes/
|
||||
- The bug #4206 (GD with JIS-mapped Japanese Font Support) was fixed in this
|
||||
commit: https://github.com/piwik/piwik/commit/516c13d9b13ca3b908575eb809f7ad9d9397f0e1
|
||||
Changed files: class/pImage.class.php class/pDraw.class.php
|
||||
* PclZip/
|
||||
- in r1960, ignore touch() - utime failed warning
|
||||
* PEAR/, PEAR.php
|
||||
- in r2419, add static keyword to isError and raiseError as it throws notices
|
||||
in HTML_Quickform2
|
||||
- in r2422, is_a() is deprecated for php 5.0 to 5.2.x
|
||||
* sparkline/
|
||||
- in r1296, remove require_once
|
||||
- empty sparklines with floats, off-by-one errors, and locale conflict
|
||||
* tcpdf/
|
||||
- in 6f945465fe40021d579bc2b4b8876468da69b062 fixed a bug reported in the forums
|
||||
- in 566c63a52e31b2b2d3e1a83f8f63e74e8d661b21 fixed another couple bugs with fopen throwing warnings
|
||||
* Zend/
|
||||
- strip require_once (to support autoloading)
|
||||
- in r3694, fix ZF-10888 and ZF-10835
|
||||
- ZF-10871 - undefined variables when socket support disabled
|
||||
23
www/analytics/libs/UserAgentParser/README.md
Normal file
23
www/analytics/libs/UserAgentParser/README.md
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
# UserAgentParser
|
||||
|
||||
UserAgentParser is a php library to parse user agents,
|
||||
and extracts browser name & version and operating system.
|
||||
|
||||
UserAgentParser is NOT designed to parse bots user agent strings;
|
||||
UserAgentParser will only be accurate when parsing user agents
|
||||
coming from Javascript Enabled browsers!
|
||||
|
||||
UserAgentParser is designed for simplicity, to accurately detect the
|
||||
most used web browsers, and be regularly updated to detect new OS and browsers.
|
||||
|
||||
Potential limitations:
|
||||
|
||||
* it does NOT detect sub sub versions, ie. the "5" in 1.4.5; this is a design decision to simplify the version number
|
||||
* it does NOT detect search engine, bots, etc. user agents; it's designed to detect browsers with javascript enabled
|
||||
* it does NOT detect nested UA strings caused by some browser add-ons
|
||||
|
||||
Feature request:
|
||||
|
||||
* it could have the notion of operating system "types", ie "Windows". It currently only has "Windows XP", "Windows Vista", etc.
|
||||
|
||||
Feedback, patches: hello@piwik.org
|
||||
725
www/analytics/libs/UserAgentParser/UserAgentParser.php
Normal file
725
www/analytics/libs/UserAgentParser/UserAgentParser.php
Normal file
|
|
@ -0,0 +1,725 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright 2009, 2010 Matthieu Aubry & Piwik team
|
||||
* All rights reserved.
|
||||
*
|
||||
* @link https://github.com/piwik/piwik/tree/master/libs/UserAgentParser
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* * Neither the name of Matthieu Aubry nor the names of its contributors
|
||||
* may 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Example usage
|
||||
*
|
||||
* Browser info:
|
||||
* var_dump(UserAgentParser::getBrowser($_SERVER['HTTP_USER_AGENT']));
|
||||
*
|
||||
* Outputs:
|
||||
* array
|
||||
* 'id' => 'FF'
|
||||
* 'name' => 'Firefox'
|
||||
* 'short_name' => 'Firefox'
|
||||
* 'version' => '3.0'
|
||||
* 'major_number' => '3'
|
||||
* 'minor_number' => '0'
|
||||
*
|
||||
* Operating System info:
|
||||
* var_dump(UserAgentParser::getOperatingSystem($_SERVER['HTTP_USER_AGENT']));
|
||||
*
|
||||
* Outputs:
|
||||
* array
|
||||
* 'id' => 'WXP'
|
||||
* 'name' => 'Windows XP'
|
||||
* 'short_name' => 'Win XP'
|
||||
*
|
||||
*/
|
||||
class UserAgentParser
|
||||
{
|
||||
// browser regex => browser ID
|
||||
// if there are aliases, the common name should be last
|
||||
static protected $browsers = array(
|
||||
'abrowse' => 'AB',
|
||||
'amaya' => 'AM',
|
||||
'amigavoyager' => 'AV',
|
||||
'amiga-aweb' => 'AW',
|
||||
'arora' => 'AR',
|
||||
'beonex' => 'BE',
|
||||
|
||||
// BlackBerry smartphones and tablets
|
||||
'blackberry' => 'BB', // BlackBerry 6 and PlayBook adopted webkit
|
||||
'bb10' => 'B2', // BlackBerry 10
|
||||
'playbook' => 'BP',
|
||||
|
||||
'browsex' => 'BX',
|
||||
|
||||
// Camino (and earlier incarnation)
|
||||
'chimera' => 'CA',
|
||||
'camino' => 'CA',
|
||||
|
||||
'cheshire' => 'CS',
|
||||
|
||||
// Chrome, Chromium, and ChromePlus
|
||||
'crmo' => 'CH',
|
||||
'chrome' => 'CH',
|
||||
|
||||
// Chrome Frame
|
||||
'chromeframe' => 'CF',
|
||||
|
||||
'cometbird' => 'CO',
|
||||
'dillo' => 'DI',
|
||||
'elinks' => 'EL',
|
||||
'epiphany' => 'EP',
|
||||
'fennec' => 'FE',
|
||||
|
||||
// Dolfin (or Dolphin)
|
||||
'dolfin' => 'DF',
|
||||
|
||||
// Firefox (in its many incarnations and rebranded versions)
|
||||
'phoenix' => 'PX',
|
||||
'mozilla firebird' => 'FB',
|
||||
'firebird' => 'FB',
|
||||
'bonecho' => 'FF',
|
||||
'minefield' => 'FF',
|
||||
'namoroka' => 'FF',
|
||||
'shiretoko' => 'FF',
|
||||
'granparadiso' => 'FF',
|
||||
'iceweasel' => 'FF',
|
||||
'icecat' => 'FF',
|
||||
'firefox' => 'FF',
|
||||
|
||||
'thunderbird' => 'TB',
|
||||
|
||||
'flock' => 'FL',
|
||||
'fluid' => 'FD',
|
||||
'galeon' => 'GA',
|
||||
'google earth' => 'GE',
|
||||
'hana' => 'HA',
|
||||
'hotjava' => 'HJ',
|
||||
'ibrowse' => 'IB',
|
||||
'icab' => 'IC',
|
||||
|
||||
// IE (including shells: Acoo, AOL, Avant, Crazy Browser, Green Browser, KKMAN, Maxathon)
|
||||
'msie' => 'IE',
|
||||
'trident' => 'IE',
|
||||
'microsoft internet explorer' => 'IE',
|
||||
'internet explorer' => 'IE',
|
||||
|
||||
'iron' => 'IR',
|
||||
'kapiko' => 'KP',
|
||||
'kazehakase' => 'KZ',
|
||||
'k-meleon' => 'KM',
|
||||
'konqueror' => 'KO',
|
||||
'links' => 'LI',
|
||||
'lynx' => 'LX',
|
||||
'midori' => 'MI',
|
||||
|
||||
// SeaMonkey (formerly Mozilla Suite) (and rebranded versions)
|
||||
'mozilla' => 'MO',
|
||||
'gnuzilla' => 'SM',
|
||||
'iceape' => 'SM',
|
||||
'seamonkey' => 'SM',
|
||||
|
||||
// NCSA Mosaic (and incarnations)
|
||||
'mosaic' => 'MC',
|
||||
'ncsa mosaic' => 'MC',
|
||||
|
||||
// Netscape Navigator
|
||||
'navigator' => 'NS',
|
||||
'netscape6' => 'NS',
|
||||
'netscape' => 'NS',
|
||||
|
||||
'nx' => 'NF',
|
||||
'netfront' => 'NF',
|
||||
|
||||
'omniweb' => 'OW',
|
||||
|
||||
// Opera
|
||||
'nitro) opera' => 'OP',
|
||||
'opera' => 'OP',
|
||||
|
||||
'rekonq' => 'RK',
|
||||
|
||||
// Safari
|
||||
'safari' => 'SF',
|
||||
'applewebkit' => 'SF',
|
||||
|
||||
'titanium' => 'TI',
|
||||
|
||||
'webos' => 'WO',
|
||||
'webpro' => 'WP',
|
||||
);
|
||||
|
||||
// browser family (by layout engine)
|
||||
static protected $browserType = array(
|
||||
'ie' => array('IE'),
|
||||
'gecko' => array('NS', 'PX', 'FF', 'FB', 'CA', 'GA', 'KM', 'MO', 'SM', 'CO', 'FE', 'KP', 'KZ', 'TB'),
|
||||
'khtml' => array('KO'),
|
||||
'webkit' => array('SF', 'CH', 'OW', 'AR', 'EP', 'FL', 'WO', 'AB', 'IR', 'CS', 'FD', 'HA', 'MI', 'GE', 'DF', 'BB', 'BP', 'TI', 'CF', 'RK', 'B2', 'NF'),
|
||||
'opera' => array('OP'),
|
||||
);
|
||||
|
||||
// WebKit version numbers to Apple Safari version numbers (if Version/X.Y.Z not present)
|
||||
static protected $safariVersions = array(
|
||||
'536.25' => array('6', '0'),
|
||||
'534.48' => array('5', '1'),
|
||||
'533.16' => array('5', '0'),
|
||||
'533.4' => array('4', '1'),
|
||||
'526.11.2' => array('4', '0'),
|
||||
'525.26' => array('3', '2'),
|
||||
'525.13' => array('3', '1'),
|
||||
'522.11' => array('3', '0'),
|
||||
'412' => array('2', '0'),
|
||||
'312' => array('1', '3'),
|
||||
'125' => array('1', '2'),
|
||||
'100' => array('1', '1'),
|
||||
'85' => array('1', '0'),
|
||||
'73' => array('0', '9'),
|
||||
'48' => array('0', '8'),
|
||||
);
|
||||
|
||||
// OmniWeb build numbers to OmniWeb version numbers (if Version/X.Y.Z not present)
|
||||
static protected $omniWebVersions = array(
|
||||
'622.15' => array('5', '11'),
|
||||
'622.10' => array('5', '10'),
|
||||
'622.8' => array('5', '9'),
|
||||
'622.3' => array('5', '8'),
|
||||
'621' => array('5', '7'),
|
||||
'613' => array('5', '6'),
|
||||
'607' => array('5', '5'),
|
||||
'563.34' => array('5', '1'),
|
||||
'558.36' => array('5', '0'),
|
||||
'496' => array('4', '5'),
|
||||
);
|
||||
|
||||
// OS regex => OS ID
|
||||
static protected $operatingSystems = array(
|
||||
'Android' => 'AND',
|
||||
'Maemo' => 'MAE',
|
||||
'CrOS ' => 'LIN',
|
||||
'Linux' => 'LIN',
|
||||
|
||||
'Xbox' => 'XBX',
|
||||
|
||||
// workaround for vendors who changed the WinPhone 7 user agent
|
||||
'WP7' => 'WPH',
|
||||
|
||||
'CYGWIN_NT-6.2' => 'WI8',
|
||||
'Windows NT 6.2' => 'WI8',
|
||||
'Windows NT 6.3' => 'WI8',
|
||||
'Windows 8' => 'WI8',
|
||||
'CYGWIN_NT-6.1' => 'WI7',
|
||||
'Windows NT 6.1' => 'WI7',
|
||||
'Windows 7' => 'WI7',
|
||||
'CYGWIN_NT-6.0' => 'WVI',
|
||||
'Windows NT 6.0' => 'WVI',
|
||||
'Windows Vista' => 'WVI',
|
||||
'CYGWIN_NT-5.2' => 'WS3',
|
||||
'Windows NT 5.2' => 'WS3',
|
||||
'Windows Server 2003 / XP x64' => 'WS3',
|
||||
'CYGWIN_NT-5.1' => 'WXP',
|
||||
'Windows NT 5.1' => 'WXP',
|
||||
'Windows XP' => 'WXP',
|
||||
'CYGWIN_NT-5.0' => 'W2K',
|
||||
'Windows NT 5.0' => 'W2K',
|
||||
'Windows 2000' => 'W2K',
|
||||
'CYGWIN_NT-4.0' => 'WNT',
|
||||
'Windows NT 4.0' => 'WNT',
|
||||
'WinNT' => 'WNT',
|
||||
'Windows NT' => 'WNT',
|
||||
'CYGWIN_ME-4.90' => 'WME',
|
||||
'Win 9x 4.90' => 'WME',
|
||||
'Windows ME' => 'WME',
|
||||
'CYGWIN_98-4.10' => 'W98',
|
||||
'Win98' => 'W98',
|
||||
'Windows 98' => 'W98',
|
||||
'CYGWIN_95-4.0' => 'W95',
|
||||
'Win32' => 'W95',
|
||||
'Win95' => 'W95',
|
||||
'Windows 95' => 'W95',
|
||||
|
||||
// Windows Phone OS 7 and above
|
||||
'Windows Phone OS' => 'WPH',
|
||||
|
||||
// Windows Mobile 6.x and some later versions of Windows Mobile 5
|
||||
'IEMobile' => 'WMO', // fallback
|
||||
'Windows Mobile' => 'WMO',
|
||||
|
||||
// Windows CE, Pocket PC, and Windows Mobile 5 are indistinguishable without vendor/device specific detection
|
||||
'Windows CE' => 'WCE',
|
||||
|
||||
'iPod' => 'IPD',
|
||||
'iPad' => 'IPA',
|
||||
'iPhone' => 'IPH',
|
||||
// 'iOS' => 'IOS',
|
||||
'Darwin' => 'MAC',
|
||||
'Macintosh' => 'MAC',
|
||||
'Power Macintosh' => 'MAC',
|
||||
'Mac_PowerPC' => 'MAC',
|
||||
'Mac PPC' => 'MAC',
|
||||
'PPC' => 'MAC',
|
||||
'Mac PowerPC' => 'MAC',
|
||||
'Mac OS' => 'MAC',
|
||||
|
||||
'webOS' => 'WOS',
|
||||
'Palm webOS' => 'WOS',
|
||||
'PalmOS' => 'POS',
|
||||
'Palm OS' => 'POS',
|
||||
|
||||
'BB10' => 'BBX',
|
||||
'BlackBerry' => 'BLB',
|
||||
'RIM Tablet OS' => 'QNX',
|
||||
'QNX' => 'QNX',
|
||||
|
||||
'SymbOS' => 'SYM',
|
||||
'Symbian OS' => 'SYM',
|
||||
'SymbianOS' => 'SYM',
|
||||
|
||||
'bada' => 'SBA',
|
||||
|
||||
'SunOS' => 'SOS',
|
||||
'AIX' => 'AIX',
|
||||
'HP-UX' => 'HPX',
|
||||
'OpenVMS' => 'VMS',
|
||||
|
||||
'FreeBSD' => 'BSD',
|
||||
'NetBSD' => 'NBS',
|
||||
'OpenBSD' => 'OBS',
|
||||
'DragonFly' => 'DFB',
|
||||
'Syllable' => 'SYL',
|
||||
|
||||
'Nintendo WiiU' => 'WIU',
|
||||
'Nintendo Wii' => 'WII',
|
||||
'Nitro' => 'NDS',
|
||||
'Nintendo DSi' => 'DSI',
|
||||
'Nintendo DS' => 'NDS',
|
||||
'Nintendo 3DS' => '3DS',
|
||||
|
||||
'PlayStation Vita' => 'PSV',
|
||||
'PlayStation Portable' => 'PSP',
|
||||
'PlayStation 3' => 'PS3',
|
||||
|
||||
'IRIX' => 'IRI',
|
||||
'OSF1' => 'T64',
|
||||
'OS/2' => 'OS2',
|
||||
'BEOS' => 'BEO',
|
||||
'Amiga' => 'AMI',
|
||||
'AmigaOS' => 'AMI',
|
||||
);
|
||||
|
||||
// os family
|
||||
// NOTE: The keys in this array are used by plugins/UserSettings/functions.php . Any changes
|
||||
// made here should also be made in that file.
|
||||
static protected $osType = array(
|
||||
'Windows' => array('WI8', 'WI7', 'WVI', 'WS3', 'WXP', 'W2K', 'WNT', 'WME', 'W98', 'W95'),
|
||||
'Linux' => array('LIN'),
|
||||
'Mac' => array('MAC'),
|
||||
'iOS' => array('IPD', 'IPA', 'IPH'),
|
||||
'Android' => array('AND'),
|
||||
'Windows Mobile' => array('WPH', 'WMO', 'WCE'),
|
||||
'Gaming Console' => array('WII', 'WIU', 'PS3', 'XBX'),
|
||||
'Mobile Gaming Console' => array('PSP', 'PSV', 'NDS', 'DSI', '3DS'),
|
||||
'Unix' => array('SOS', 'AIX', 'HP-UX', 'BSD', 'NBS', 'OBS', 'DFB', 'SYL', 'IRI', 'T64'),
|
||||
'Other Mobile' => array('MAE', 'WOS', 'POS', 'BLB', 'QNX', 'SYM', 'SBA'),
|
||||
'Other' => array('VMS', 'OS2', 'BEOS', 'AMI')
|
||||
);
|
||||
|
||||
static protected $browserIdToName;
|
||||
static protected $browserIdToShortName;
|
||||
static protected $operatingSystemsIdToName;
|
||||
static protected $operatingSystemsIdToShortName;
|
||||
static private $init = false;
|
||||
|
||||
/**
|
||||
* Returns an array of the OS for the submitted user agent
|
||||
* 'id' => '',
|
||||
* 'name' => '',
|
||||
* 'short_name' => '',
|
||||
*
|
||||
* @param string $userAgent
|
||||
* @return string false if OS couldn't be identified, or 3 letters ID (eg. WXP)
|
||||
* @see UserAgentParser/OperatingSystems.php for the list of OS (also available in self::$operatingSystems)
|
||||
*/
|
||||
static public function getOperatingSystem($userAgent)
|
||||
{
|
||||
$userAgent = self::cleanupUserAgent($userAgent);
|
||||
self::init();
|
||||
$info = array(
|
||||
'id' => '',
|
||||
'name' => '',
|
||||
'short_name' => '',
|
||||
);
|
||||
foreach (self::$operatingSystems as $key => $value) {
|
||||
if (stristr($userAgent, $key) !== false) {
|
||||
$info['id'] = $value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (empty($info['id'])) {
|
||||
return false;
|
||||
}
|
||||
$info['name'] = self::getOperatingSystemNameFromId($info['id']);
|
||||
$info['short_name'] = self::getOperatingSystemShortNameFromId($info['id']);
|
||||
return $info;
|
||||
}
|
||||
|
||||
static protected function cleanupUserAgent($userAgent)
|
||||
{
|
||||
// in case value is URL encoded
|
||||
return urldecode($userAgent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the browser information array, given a user agent string.
|
||||
*
|
||||
* @param string $userAgent
|
||||
* @return array false if the browser is "unknown", or
|
||||
* array( 'id' => '', // 2 letters ID, eg. FF
|
||||
* 'name' => '', // 2 letters ID, eg. FF
|
||||
* 'short_name' => '', // 2 letters ID, eg. FF
|
||||
* 'major_number' => '', // 2 in firefox 2.0.12
|
||||
* 'minor_number' => '', // 0 in firefox 2.0.12
|
||||
* 'version' => '', // major_number.minor_number
|
||||
* );
|
||||
* @see self::$browsers for the list of OS
|
||||
*/
|
||||
static public function getBrowser($userAgent)
|
||||
{
|
||||
$userAgent = self::cleanupUserAgent($userAgent);
|
||||
|
||||
self::init();
|
||||
|
||||
$info = array(
|
||||
'id' => '',
|
||||
'name' => '',
|
||||
'short_name' => '',
|
||||
'major_number' => '',
|
||||
'minor_number' => '',
|
||||
'version' => '',
|
||||
);
|
||||
|
||||
$browsers = self::$browsers;
|
||||
|
||||
// derivative browsers often clone the base browser's useragent
|
||||
unset($browsers['firefox']);
|
||||
unset($browsers['mozilla']);
|
||||
unset($browsers['safari']);
|
||||
unset($browsers['applewebkit']);
|
||||
|
||||
$browsersPattern = str_replace(')', '\)', implode('|', array_keys($browsers)));
|
||||
|
||||
$results = array();
|
||||
|
||||
// Misbehaving IE add-ons
|
||||
$userAgent = preg_replace('/[; ]Mozilla\/[0-9.]+ \([^)]+\)/', '', $userAgent);
|
||||
|
||||
// Clean-up BlackBerry device UAs
|
||||
$userAgent = preg_replace('~^BlackBerry\d+/~', 'BlackBerry/', $userAgent);
|
||||
|
||||
if (preg_match_all("/($browsersPattern)[\/\sa-z(]*([0-9]+)([\.0-9a-z]+)?/i", $userAgent, $results)
|
||||
|| (strpos($userAgent, 'Shiira') === false && preg_match_all("/(firefox|thunderbird|safari)[\/\sa-z(]*([0-9]+)([\.0-9a-z]+)?/i", $userAgent, $results))
|
||||
|| preg_match_all("/(applewebkit)[\/\sa-z(]*([0-9]+)([\.0-9a-z]+)?/i", $userAgent, $results)
|
||||
|| preg_match_all("/^(mozilla)\/([0-9]+)([\.0-9a-z-]+)?(?: \[[a-z]{2}\])? (?:\([^)]*\))$/i", $userAgent, $results)
|
||||
|| preg_match_all("/^(mozilla)\/[0-9]+(?:[\.0-9a-z-]+)?\s\(.* rv:([0-9]+)([.0-9a-z]+)\) gecko(\/[0-9]{8}|$)(?:.*)/i", $userAgent, $results)
|
||||
|| (strpos($userAgent, 'Nintendo 3DS') !== false && preg_match_all("/^(mozilla).*version\/([0-9]+)([.0-9a-z]+)?/i", $userAgent, $results))
|
||||
) {
|
||||
// browser code (usually the first match)
|
||||
$count = 0;
|
||||
$info['id'] = self::$browsers[strtolower($results[1][0])];
|
||||
|
||||
// sometimes there's a better match at the end
|
||||
if (strpos($userAgent, 'chromeframe') !== false) {
|
||||
$count = count($results[0]) - 1;
|
||||
$info['id'] = 'CF';
|
||||
} elseif (($info['id'] == 'IE' || $info['id'] == 'LX') && (count($results[0]) > 1)) {
|
||||
$count = count($results[0]) - 1;
|
||||
$info['id'] = self::$browsers[strtolower($results[1][$count])];
|
||||
}
|
||||
|
||||
// Netscape fix
|
||||
if ($info['id'] == 'MO' && $count == 0) {
|
||||
if (stripos($userAgent, 'PlayStation') !== false) {
|
||||
return false;
|
||||
}
|
||||
if (strpos($userAgent, 'Nintendo 3DS') !== false) {
|
||||
$info['id'] = 'NF';
|
||||
} elseif (count($results) == 4) {
|
||||
$info['id'] = 'NS';
|
||||
}
|
||||
} // BlackBerry devices
|
||||
elseif (strpos($userAgent, 'BlackBerry') !== false) {
|
||||
$info['id'] = 'BB';
|
||||
} elseif (strpos($userAgent, 'RIM Tablet OS') !== false) {
|
||||
$info['id'] = 'BP';
|
||||
} elseif (strpos($userAgent, 'BB10') !== false) {
|
||||
$info['id'] = 'B2';
|
||||
} elseif (strpos($userAgent, 'Playstation Vita') !== false) {
|
||||
$info['id'] = 'NF';
|
||||
|
||||
if (preg_match_all("/(silk)[\/\sa-z(]*([0-9]+)([\.0-9a-z]+)?/i", $userAgent, $newResults)) {
|
||||
$results = $newResults;
|
||||
$count = count($results[0]) - 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Version/X.Y.Z override
|
||||
if (preg_match_all("/(version)[\/\sa-z(]*([0-9]+)([\.0-9a-z]+)?/i", $userAgent, $newResults)) {
|
||||
$results = $newResults;
|
||||
$count = count($results[0]) - 1;
|
||||
}
|
||||
|
||||
// major version number (1 in mozilla 1.7)
|
||||
$info['major_number'] = $results[2][$count];
|
||||
|
||||
// is an minor version number ? If not, 0
|
||||
$match = array();
|
||||
|
||||
preg_match('/([.\0-9]+)?([\.a-z0-9]+)?/i', $results[3][$count], $match);
|
||||
|
||||
if (isset($match[1])) {
|
||||
// find minor version number (7 in mozilla 1.7, 9 in firefox 0.9.3)
|
||||
$dot = strpos(substr($match[1], 1), '.');
|
||||
if ($dot !== false) {
|
||||
$info['minor_number'] = substr($match[1], 1, $dot);
|
||||
} else {
|
||||
$info['minor_number'] = substr($match[1], 1);
|
||||
}
|
||||
} else {
|
||||
$info['minor_number'] = '0';
|
||||
}
|
||||
$info['version'] = $info['major_number'] . '.' . $info['minor_number'];
|
||||
|
||||
// IE compatibility mode
|
||||
if ($info['id'] == 'IE'
|
||||
&& (strncmp($userAgent, 'Mozilla/4.0', 11) == 0 || strncmp($userAgent, 'Mozilla/5.0', 11) == 0)
|
||||
&& preg_match('~ Trident/([0-9]+)\.[0-9]+~', $userAgent, $tridentVersion)
|
||||
) {
|
||||
$info['major_number'] = $tridentVersion[1] + 4;
|
||||
$info['minor_number'] = '0';
|
||||
$info['version'] = $info['major_number'] . '.' . $info['minor_number'];
|
||||
}
|
||||
|
||||
// Safari fix
|
||||
if ($info['id'] == 'SF') {
|
||||
foreach (self::$safariVersions as $buildVersion => $productVersion) {
|
||||
if (version_compare($info['version'], $buildVersion) >= 0) {
|
||||
$info['major_number'] = $productVersion[0];
|
||||
$info['minor_number'] = $productVersion[1];
|
||||
$info['version'] = $info['major_number'] . '.' . $info['minor_number'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// OmniWeb fix
|
||||
if ($info['id'] == 'OW') {
|
||||
foreach (self::$omniWebVersions as $buildVersion => $productVersion) {
|
||||
if (version_compare($info['version'], $buildVersion) >= 0) {
|
||||
$info['major_number'] = $productVersion[0];
|
||||
$info['minor_number'] = $productVersion[1];
|
||||
$info['version'] = $info['major_number'] . '.' . $info['minor_number'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// SeaMonkey fix
|
||||
if ($info['id'] == 'MO' && $info['version'] == '1.9') {
|
||||
$info['id'] = 'SM';
|
||||
}
|
||||
|
||||
$info['name'] = self::getBrowserNameFromId($info['id']);
|
||||
$info['short_name'] = self::getBrowserShortNameFromId($info['id']);
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static protected function init()
|
||||
{
|
||||
if (self::$init) {
|
||||
return;
|
||||
}
|
||||
self::$init = true;
|
||||
|
||||
// init browser names and short names
|
||||
self::$browserIdToName = array_map('ucwords', array_flip(self::$browsers));
|
||||
self::$browserIdToName['AB'] = 'ABrowse';
|
||||
self::$browserIdToName['AV'] = 'AmigaVoyager';
|
||||
self::$browserIdToName['AW'] = 'Amiga AWeb';
|
||||
self::$browserIdToName['BB'] = 'BlackBerry';
|
||||
self::$browserIdToName['BP'] = 'PlayBook';
|
||||
self::$browserIdToName['B2'] = 'BlackBerry';
|
||||
self::$browserIdToName['BX'] = 'BrowseX';
|
||||
self::$browserIdToName['CF'] = 'Chrome Frame';
|
||||
self::$browserIdToName['CO'] = 'CometBird';
|
||||
self::$browserIdToName['EL'] = 'ELinks';
|
||||
self::$browserIdToName['FF'] = 'Firefox';
|
||||
self::$browserIdToName['HJ'] = 'HotJava';
|
||||
self::$browserIdToName['IB'] = 'IBrowse';
|
||||
self::$browserIdToName['IC'] = 'iCab';
|
||||
self::$browserIdToName['KM'] = 'K-Meleon';
|
||||
self::$browserIdToName['MC'] = 'NCSA Mosaic';
|
||||
self::$browserIdToName['NF'] = 'NetFront';
|
||||
self::$browserIdToName['OW'] = 'OmniWeb';
|
||||
self::$browserIdToName['SF'] = 'Safari';
|
||||
self::$browserIdToName['SM'] = 'SeaMonkey';
|
||||
self::$browserIdToName['WO'] = 'Palm webOS';
|
||||
self::$browserIdToName['WP'] = 'WebPro';
|
||||
|
||||
self::$browserIdToShortName = self::$browserIdToName;
|
||||
self::$browserIdToShortName['AW'] = 'AWeb';
|
||||
self::$browserIdToShortName['FB'] = 'Firebird';
|
||||
self::$browserIdToShortName['IE'] = 'IE';
|
||||
self::$browserIdToShortName['MC'] = 'Mosaic';
|
||||
self::$browserIdToShortName['BP'] = 'PlayBook';
|
||||
self::$browserIdToShortName['WO'] = 'webOS';
|
||||
|
||||
// init OS names and short names
|
||||
$operatingSystemsIdToName = array(
|
||||
'IPD' => 'iPod',
|
||||
'IPA' => 'iPad',
|
||||
'WME' => 'Windows Me',
|
||||
'BEO' => 'BeOS',
|
||||
'T64' => 'Tru64',
|
||||
'NDS' => 'Nintendo DS',
|
||||
'WIU' => 'Nintendo Wii U',
|
||||
'3DS' => 'Nintendo 3DS',
|
||||
|
||||
// These are for BC purposes only
|
||||
'W75' => 'WinPhone 7.5',
|
||||
'WP7' => 'WinPhone 7',
|
||||
'W65' => 'WinMo 6.5',
|
||||
'W61' => 'WinMo 6.1',
|
||||
|
||||
);
|
||||
self::$operatingSystemsIdToName = array_merge(array_flip(self::$operatingSystems), $operatingSystemsIdToName);
|
||||
$operatingSystemsIdToShortName = array(
|
||||
'PS3' => 'PS3',
|
||||
'PSP' => 'PSP',
|
||||
'WII' => 'Wii',
|
||||
'WIU' => 'Wii U',
|
||||
'NDS' => 'DS',
|
||||
'DSI' => 'DSi',
|
||||
'3DS' => '3DS',
|
||||
'PSV' => 'PS Vita',
|
||||
'WI8' => 'Win 8',
|
||||
'WI7' => 'Win 7',
|
||||
'WVI' => 'Win Vista',
|
||||
'WS3' => 'Win S2003',
|
||||
'WXP' => 'Win XP',
|
||||
'W98' => 'Win 98',
|
||||
'W2K' => 'Win 2000',
|
||||
'WNT' => 'Win NT',
|
||||
'WME' => 'Win Me',
|
||||
'W95' => 'Win 95',
|
||||
'WPH' => 'WinPhone',
|
||||
'WMO' => 'WinMo',
|
||||
'WCE' => 'Win CE',
|
||||
'WOS' => 'webOS',
|
||||
'UNK' => 'Unknown',
|
||||
);
|
||||
self::$operatingSystemsIdToShortName = array_merge(self::$operatingSystemsIdToName, $operatingSystemsIdToShortName);
|
||||
}
|
||||
|
||||
static public function getBrowserNameFromId($browserId)
|
||||
{
|
||||
self::init();
|
||||
if (isset(self::$browserIdToName[$browserId])) {
|
||||
return self::$browserIdToName[$browserId];
|
||||
}
|
||||
if(class_exists('DeviceDetector')) {
|
||||
if( !empty(DeviceDetector::$browsers[$browserId])) {
|
||||
return DeviceDetector::$browsers[$browserId];
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static public function getBrowserShortNameFromId($browserId)
|
||||
{
|
||||
self::init();
|
||||
if (isset(self::$browserIdToShortName[$browserId])) {
|
||||
return self::$browserIdToShortName[$browserId];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static public function getBrowserFamilyFromId($browserId)
|
||||
{
|
||||
self::init();
|
||||
$familyNameToUse = 'unknown';
|
||||
foreach (self::$browserType as $familyName => $aBrowsers) {
|
||||
if (in_array($browserId, $aBrowsers)) {
|
||||
$familyNameToUse = $familyName;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $familyNameToUse;
|
||||
}
|
||||
|
||||
static public function getOperatingSystemNameFromId($osId)
|
||||
{
|
||||
self::init();
|
||||
if (isset(self::$operatingSystemsIdToName[$osId])) {
|
||||
return self::$operatingSystemsIdToName[$osId];
|
||||
}
|
||||
|
||||
if(class_exists('DeviceDetector')) {
|
||||
return DeviceDetector::getOsNameFromId($osId);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static public function getOperatingSystemShortNameFromId($osId)
|
||||
{
|
||||
self::init();
|
||||
if (isset(self::$operatingSystemsIdToShortName[$osId])) {
|
||||
return self::$operatingSystemsIdToShortName[$osId];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static public function getOperatingSystemIdFromName($osName)
|
||||
{
|
||||
return isset(self::$operatingSystems[$osName]) ? self::$operatingSystems[$osName] : false;
|
||||
}
|
||||
|
||||
static public function getOperatingSystemFamilyFromId($osId)
|
||||
{
|
||||
self::init();
|
||||
foreach (self::$osType as $familyName => $aSystems) {
|
||||
if (in_array($osId, $aSystems)) {
|
||||
return $familyName;
|
||||
}
|
||||
}
|
||||
return 'unknown';
|
||||
}
|
||||
}
|
||||
56
www/analytics/libs/UserAgentParser/UserAgentParser.test.php
Normal file
56
www/analytics/libs/UserAgentParser/UserAgentParser.test.php
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
if (!isset($_GET['setUserAgent']) && !isset($_SERVER['HTTP_USER_AGENT'])) die;
|
||||
|
||||
require_once dirname(__FILE__) . '/UserAgentParser.php';
|
||||
echo "<h2>UserAgentParser php library test</h2>";
|
||||
$testUserAgent = array(
|
||||
'my user agent' => '',
|
||||
'ie8 on win7' => 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET CLR 3.0.04506; .NET CLR 3.5.21022; InfoPath.2; SLCC1; Zune 3.0)',
|
||||
'ie8 on vista (compatibility view)' => 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/4.0)',
|
||||
'ie8 on vista' => 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)',
|
||||
'chrome on winxp' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.19 (KHTML, like Gecko) Chrome/1.0.154.48 Safari/525.19',
|
||||
'IE6 on winxp' => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648)',
|
||||
'safari on winxp' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.19 (KHTML, like Gecko) Version/3.1.2 Safari/525.21',
|
||||
'FF3 on winxp' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6',
|
||||
'opera 9.63 on winxp' => 'Opera/9.63 (Windows NT 5.1; U; en) Presto/2.1.1',
|
||||
'Blackberry' => 'BlackBerry8700/4.1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1',
|
||||
'opera 9.30 on Nintendo Wii' => 'Opera/9.30 (Nintendo Wii; U; ; 2047-7; en)',
|
||||
'iphone' => 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 2_2 like Mac OS X; en-us) AppleWebKit/525.18.1 (KHTML, like Gecko) Version/3.1.1 Mobile/5G77 Safari/525.20',
|
||||
'iPod touch' => 'Mozilla/5.0 (iPod; U; CPU like Mac OS X; en) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/3A100a Safari/419.3',
|
||||
'iPod' => 'Mozilla/5.0 (iPod; U; CPU iPhone OS 2_2_1 like Mac OS X; en-us) AppleWebKit/525.18.1 (KHTML, like Gecko) Version/3.1.1 Mobile/5H11a Safari/525.20',
|
||||
'Android' => 'Mozilla/5.0 (Linux; U; Android 1.1; en-us; dream) AppleWebKit/525.10+ (KHTML, like Gecko) Version/3.0.4 Mobile Safari/523.12.2',
|
||||
'PalmOS' => 'Mozilla/5.0 [en] (PalmOS; U; WebPro/3.5; Palm-Zi72) ',
|
||||
'safari on mac os X' => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_5; en-us) AppleWebKit/527.3+ (KHTML, like Gecko) Version/3.1.2 Safari/525.20.1',
|
||||
'opera 9.64 on win ME' => 'Opera/9.64 (Windows ME; U; en) Presto/2.1.1',
|
||||
'opera 10.00 on XP' => 'Opera/9.80 (Windows NT 5.1; U; en) Presto/2.2.15 Version/10.00',
|
||||
'iron on win7' => 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/531.0 (KHTML, like Gecko) Iron/3.0.189.0 Safari/531.0',
|
||||
'firefox 3.6 alpha on vista' => 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2a2pre) Gecko/20090826 Namoroka/3.6a2pre',
|
||||
'firefox 3.5 alpha on win7' => 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1b4pre) Gecko/20090420 Shiretoko/3.5b4pre (.NET CLR 3.5.30729)',
|
||||
'firefox nightly build' => 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:2.0a1pre) Gecko/2008060602 Minefield/4.0a1pre',
|
||||
'thunderbird 14.0 with lightning 1.6' => 'Mozilla/5.0 (Windows NT 5.1; rv:14.0) Gecko/20120713 Thunderbird/14.0 Lightning/1.6',
|
||||
'Windows 8' => 'Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; Touch; rv:11.0) like Gecko',
|
||||
);
|
||||
echo "Test with another user agent: ";
|
||||
foreach ($testUserAgent as $name => $userAgent) {
|
||||
echo "<a href='?setUserAgent=" . urlencode($userAgent) . "'>$name</a>, ";
|
||||
}
|
||||
echo "<hr>";
|
||||
|
||||
if (isset($_GET['setUserAgent']) && !empty($_GET['setUserAgent'])) {
|
||||
echo "User Agent:";
|
||||
$userAgent = urldecode($_GET['setUserAgent']);
|
||||
} else {
|
||||
echo "Your user agent:";
|
||||
$userAgent = $_SERVER['HTTP_USER_AGENT'];
|
||||
}
|
||||
echo " <b>" . htmlentities($userAgent) . "</b><br><br>";
|
||||
|
||||
echo "Browser info:<pre>";
|
||||
var_dump(UserAgentParser::getBrowser($userAgent));
|
||||
echo "</pre>";
|
||||
|
||||
echo "Operating System info:<pre>";
|
||||
var_dump(UserAgentParser::getOperatingSystem($userAgent));
|
||||
echo "</pre>";
|
||||
|
||||
echo "<br><br><i>UserAgentParser doesn't detect your Operating System or Browser properly? <br>Please submit your user agent string and the expected result to hello at piwik.org. Patches are also welcome :-) Thanks!</i>";
|
||||
250
www/analytics/libs/Zend/Cache.php
Normal file
250
www/analytics/libs/Zend/Cache.php
Normal file
|
|
@ -0,0 +1,250 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Cache.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Cache
|
||||
{
|
||||
|
||||
/**
|
||||
* Standard frontends
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $standardFrontends = array('Core', 'Output', 'Class', 'File', 'Function', 'Page');
|
||||
|
||||
/**
|
||||
* Standard backends
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $standardBackends = array('File', 'Sqlite', 'Memcached', 'Libmemcached', 'Apc', 'ZendPlatform',
|
||||
'Xcache', 'TwoLevels', 'WinCache', 'ZendServer_Disk', 'ZendServer_ShMem');
|
||||
|
||||
/**
|
||||
* Standard backends which implement the ExtendedInterface
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $standardExtendedBackends = array('File', 'Apc', 'TwoLevels', 'Memcached', 'Libmemcached', 'Sqlite', 'WinCache');
|
||||
|
||||
/**
|
||||
* Only for backward compatibility (may be removed in next major release)
|
||||
*
|
||||
* @var array
|
||||
* @deprecated
|
||||
*/
|
||||
public static $availableFrontends = array('Core', 'Output', 'Class', 'File', 'Function', 'Page');
|
||||
|
||||
/**
|
||||
* Only for backward compatibility (may be removed in next major release)
|
||||
*
|
||||
* @var array
|
||||
* @deprecated
|
||||
*/
|
||||
public static $availableBackends = array('File', 'Sqlite', 'Memcached', 'Libmemcached', 'Apc', 'ZendPlatform', 'Xcache', 'WinCache', 'TwoLevels');
|
||||
|
||||
/**
|
||||
* Consts for clean() method
|
||||
*/
|
||||
const CLEANING_MODE_ALL = 'all';
|
||||
const CLEANING_MODE_OLD = 'old';
|
||||
const CLEANING_MODE_MATCHING_TAG = 'matchingTag';
|
||||
const CLEANING_MODE_NOT_MATCHING_TAG = 'notMatchingTag';
|
||||
const CLEANING_MODE_MATCHING_ANY_TAG = 'matchingAnyTag';
|
||||
|
||||
/**
|
||||
* Factory
|
||||
*
|
||||
* @param mixed $frontend frontend name (string) or Zend_Cache_Frontend_ object
|
||||
* @param mixed $backend backend name (string) or Zend_Cache_Backend_ object
|
||||
* @param array $frontendOptions associative array of options for the corresponding frontend constructor
|
||||
* @param array $backendOptions associative array of options for the corresponding backend constructor
|
||||
* @param boolean $customFrontendNaming if true, the frontend argument is used as a complete class name ; if false, the frontend argument is used as the end of "Zend_Cache_Frontend_[...]" class name
|
||||
* @param boolean $customBackendNaming if true, the backend argument is used as a complete class name ; if false, the backend argument is used as the end of "Zend_Cache_Backend_[...]" class name
|
||||
* @param boolean $autoload if true, there will no // require_once for backend and frontend (useful only for custom backends/frontends)
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return Zend_Cache_Core|Zend_Cache_Frontend
|
||||
*/
|
||||
public static function factory($frontend, $backend, $frontendOptions = array(), $backendOptions = array(), $customFrontendNaming = false, $customBackendNaming = false, $autoload = false)
|
||||
{
|
||||
if (is_string($backend)) {
|
||||
$backendObject = self::_makeBackend($backend, $backendOptions, $customBackendNaming, $autoload);
|
||||
} else {
|
||||
if ((is_object($backend)) && (in_array('Zend_Cache_Backend_Interface', class_implements($backend)))) {
|
||||
$backendObject = $backend;
|
||||
} else {
|
||||
self::throwException('backend must be a backend name (string) or an object which implements Zend_Cache_Backend_Interface');
|
||||
}
|
||||
}
|
||||
if (is_string($frontend)) {
|
||||
$frontendObject = self::_makeFrontend($frontend, $frontendOptions, $customFrontendNaming, $autoload);
|
||||
} else {
|
||||
if (is_object($frontend)) {
|
||||
$frontendObject = $frontend;
|
||||
} else {
|
||||
self::throwException('frontend must be a frontend name (string) or an object');
|
||||
}
|
||||
}
|
||||
$frontendObject->setBackend($backendObject);
|
||||
return $frontendObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Backend Constructor
|
||||
*
|
||||
* @param string $backend
|
||||
* @param array $backendOptions
|
||||
* @param boolean $customBackendNaming
|
||||
* @param boolean $autoload
|
||||
* @return Zend_Cache_Backend
|
||||
*/
|
||||
public static function _makeBackend($backend, $backendOptions, $customBackendNaming = false, $autoload = false)
|
||||
{
|
||||
if (!$customBackendNaming) {
|
||||
$backend = self::_normalizeName($backend);
|
||||
}
|
||||
if (in_array($backend, Zend_Cache::$standardBackends)) {
|
||||
// we use a standard backend
|
||||
$backendClass = 'Zend_Cache_Backend_' . $backend;
|
||||
// security controls are explicit
|
||||
// require_once str_replace('_', DIRECTORY_SEPARATOR, $backendClass) . '.php';
|
||||
} else {
|
||||
// we use a custom backend
|
||||
if (!preg_match('~^[\w]+$~D', $backend)) {
|
||||
Zend_Cache::throwException("Invalid backend name [$backend]");
|
||||
}
|
||||
if (!$customBackendNaming) {
|
||||
// we use this boolean to avoid an API break
|
||||
$backendClass = 'Zend_Cache_Backend_' . $backend;
|
||||
} else {
|
||||
$backendClass = $backend;
|
||||
}
|
||||
if (!$autoload) {
|
||||
$file = str_replace('_', DIRECTORY_SEPARATOR, $backendClass) . '.php';
|
||||
if (!(self::_isReadable($file))) {
|
||||
self::throwException("file $file not found in include_path");
|
||||
}
|
||||
// require_once $file;
|
||||
}
|
||||
}
|
||||
return new $backendClass($backendOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Frontend Constructor
|
||||
*
|
||||
* @param string $frontend
|
||||
* @param array $frontendOptions
|
||||
* @param boolean $customFrontendNaming
|
||||
* @param boolean $autoload
|
||||
* @return Zend_Cache_Core|Zend_Cache_Frontend
|
||||
*/
|
||||
public static function _makeFrontend($frontend, $frontendOptions = array(), $customFrontendNaming = false, $autoload = false)
|
||||
{
|
||||
if (!$customFrontendNaming) {
|
||||
$frontend = self::_normalizeName($frontend);
|
||||
}
|
||||
if (in_array($frontend, self::$standardFrontends)) {
|
||||
// we use a standard frontend
|
||||
// For perfs reasons, with frontend == 'Core', we can interact with the Core itself
|
||||
$frontendClass = 'Zend_Cache_' . ($frontend != 'Core' ? 'Frontend_' : '') . $frontend;
|
||||
// security controls are explicit
|
||||
// require_once str_replace('_', DIRECTORY_SEPARATOR, $frontendClass) . '.php';
|
||||
} else {
|
||||
// we use a custom frontend
|
||||
if (!preg_match('~^[\w]+$~D', $frontend)) {
|
||||
Zend_Cache::throwException("Invalid frontend name [$frontend]");
|
||||
}
|
||||
if (!$customFrontendNaming) {
|
||||
// we use this boolean to avoid an API break
|
||||
$frontendClass = 'Zend_Cache_Frontend_' . $frontend;
|
||||
} else {
|
||||
$frontendClass = $frontend;
|
||||
}
|
||||
if (!$autoload) {
|
||||
$file = str_replace('_', DIRECTORY_SEPARATOR, $frontendClass) . '.php';
|
||||
if (!(self::_isReadable($file))) {
|
||||
self::throwException("file $file not found in include_path");
|
||||
}
|
||||
// require_once $file;
|
||||
}
|
||||
}
|
||||
return new $frontendClass($frontendOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Throw an exception
|
||||
*
|
||||
* Note : for perf reasons, the "load" of Zend/Cache/Exception is dynamic
|
||||
* @param string $msg Message for the exception
|
||||
* @throws Zend_Cache_Exception
|
||||
*/
|
||||
public static function throwException($msg, Exception $e = null)
|
||||
{
|
||||
// For perfs reasons, we use this dynamic inclusion
|
||||
// require_once 'Zend/Cache/Exception.php';
|
||||
throw new Zend_Cache_Exception($msg, 0, $e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize frontend and backend names to allow multiple words TitleCased
|
||||
*
|
||||
* @param string $name Name to normalize
|
||||
* @return string
|
||||
*/
|
||||
protected static function _normalizeName($name)
|
||||
{
|
||||
$name = ucfirst(strtolower($name));
|
||||
$name = str_replace(array('-', '_', '.'), ' ', $name);
|
||||
$name = ucwords($name);
|
||||
$name = str_replace(' ', '', $name);
|
||||
if (stripos($name, 'ZendServer') === 0) {
|
||||
$name = 'ZendServer_' . substr($name, strlen('ZendServer'));
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns TRUE if the $filename is readable, or FALSE otherwise.
|
||||
* This function uses the PHP include_path, where PHP's is_readable()
|
||||
* does not.
|
||||
*
|
||||
* Note : this method comes from Zend_Loader (see #ZF-2891 for details)
|
||||
*
|
||||
* @param string $filename
|
||||
* @return boolean
|
||||
*/
|
||||
private static function _isReadable($filename)
|
||||
{
|
||||
if (!$fh = @fopen($filename, 'r', true)) {
|
||||
return false;
|
||||
}
|
||||
@fclose($fh);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
268
www/analytics/libs/Zend/Cache/Backend.php
Normal file
268
www/analytics/libs/Zend/Cache/Backend.php
Normal file
|
|
@ -0,0 +1,268 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Backend.php 23800 2011-03-10 20:52:08Z mabe $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Cache_Backend
|
||||
{
|
||||
/**
|
||||
* Frontend or Core directives
|
||||
*
|
||||
* =====> (int) lifetime :
|
||||
* - Cache lifetime (in seconds)
|
||||
* - If null, the cache is valid forever
|
||||
*
|
||||
* =====> (int) logging :
|
||||
* - if set to true, a logging is activated throw Zend_Log
|
||||
*
|
||||
* @var array directives
|
||||
*/
|
||||
protected $_directives = array(
|
||||
'lifetime' => 3600,
|
||||
'logging' => false,
|
||||
'logger' => null
|
||||
);
|
||||
|
||||
/**
|
||||
* Available options
|
||||
*
|
||||
* @var array available options
|
||||
*/
|
||||
protected $_options = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options Associative array of options
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $options = array())
|
||||
{
|
||||
while (list($name, $value) = each($options)) {
|
||||
$this->setOption($name, $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the frontend directives
|
||||
*
|
||||
* @param array $directives Assoc of directives
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function setDirectives($directives)
|
||||
{
|
||||
if (!is_array($directives)) Zend_Cache::throwException('Directives parameter must be an array');
|
||||
while (list($name, $value) = each($directives)) {
|
||||
if (!is_string($name)) {
|
||||
Zend_Cache::throwException("Incorrect option name : $name");
|
||||
}
|
||||
$name = strtolower($name);
|
||||
if (array_key_exists($name, $this->_directives)) {
|
||||
$this->_directives[$name] = $value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$this->_loggerSanity();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an option
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function setOption($name, $value)
|
||||
{
|
||||
if (!is_string($name)) {
|
||||
Zend_Cache::throwException("Incorrect option name : $name");
|
||||
}
|
||||
$name = strtolower($name);
|
||||
if (array_key_exists($name, $this->_options)) {
|
||||
$this->_options[$name] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the life time
|
||||
*
|
||||
* if $specificLifetime is not false, the given specific life time is used
|
||||
* else, the global lifetime is used
|
||||
*
|
||||
* @param int $specificLifetime
|
||||
* @return int Cache life time
|
||||
*/
|
||||
public function getLifetime($specificLifetime)
|
||||
{
|
||||
if ($specificLifetime === false) {
|
||||
return $this->_directives['lifetime'];
|
||||
}
|
||||
return $specificLifetime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the automatic cleaning is available for the backend
|
||||
*
|
||||
* DEPRECATED : use getCapabilities() instead
|
||||
*
|
||||
* @deprecated
|
||||
* @return boolean
|
||||
*/
|
||||
public function isAutomaticCleaningAvailable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine system TMP directory and detect if we have read access
|
||||
*
|
||||
* inspired from Zend_File_Transfer_Adapter_Abstract
|
||||
*
|
||||
* @return string
|
||||
* @throws Zend_Cache_Exception if unable to determine directory
|
||||
*/
|
||||
public function getTmpDir()
|
||||
{
|
||||
$tmpdir = array();
|
||||
foreach (array($_ENV, $_SERVER) as $tab) {
|
||||
foreach (array('TMPDIR', 'TEMP', 'TMP', 'windir', 'SystemRoot') as $key) {
|
||||
if (isset($tab[$key])) {
|
||||
if (($key == 'windir') or ($key == 'SystemRoot')) {
|
||||
$dir = realpath($tab[$key] . '\\temp');
|
||||
} else {
|
||||
$dir = realpath($tab[$key]);
|
||||
}
|
||||
if ($this->_isGoodTmpDir($dir)) {
|
||||
return $dir;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$upload = ini_get('upload_tmp_dir');
|
||||
if ($upload) {
|
||||
$dir = realpath($upload);
|
||||
if ($this->_isGoodTmpDir($dir)) {
|
||||
return $dir;
|
||||
}
|
||||
}
|
||||
if (function_exists('sys_get_temp_dir')) {
|
||||
$dir = sys_get_temp_dir();
|
||||
if ($this->_isGoodTmpDir($dir)) {
|
||||
return $dir;
|
||||
}
|
||||
}
|
||||
// Attemp to detect by creating a temporary file
|
||||
$tempFile = tempnam(md5(uniqid(rand(), TRUE)), '');
|
||||
if ($tempFile) {
|
||||
$dir = realpath(dirname($tempFile));
|
||||
unlink($tempFile);
|
||||
if ($this->_isGoodTmpDir($dir)) {
|
||||
return $dir;
|
||||
}
|
||||
}
|
||||
if ($this->_isGoodTmpDir('/tmp')) {
|
||||
return '/tmp';
|
||||
}
|
||||
if ($this->_isGoodTmpDir('\\temp')) {
|
||||
return '\\temp';
|
||||
}
|
||||
Zend_Cache::throwException('Could not determine temp directory, please specify a cache_dir manually');
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if the given temporary directory is readable and writable
|
||||
*
|
||||
* @param string $dir temporary directory
|
||||
* @return boolean true if the directory is ok
|
||||
*/
|
||||
protected function _isGoodTmpDir($dir)
|
||||
{
|
||||
if (is_readable($dir)) {
|
||||
if (is_writable($dir)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure if we enable logging that the Zend_Log class
|
||||
* is available.
|
||||
* Create a default log object if none is set.
|
||||
*
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
protected function _loggerSanity()
|
||||
{
|
||||
if (!isset($this->_directives['logging']) || !$this->_directives['logging']) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($this->_directives['logger'])) {
|
||||
if ($this->_directives['logger'] instanceof Zend_Log) {
|
||||
return;
|
||||
}
|
||||
Zend_Cache::throwException('Logger object is not an instance of Zend_Log class.');
|
||||
}
|
||||
|
||||
// Create a default logger to the standard output stream
|
||||
// require_once 'Zend/Log.php';
|
||||
// require_once 'Zend/Log/Writer/Stream.php';
|
||||
// require_once 'Zend/Log/Filter/Priority.php';
|
||||
$logger = new Zend_Log(new Zend_Log_Writer_Stream('php://output'));
|
||||
$logger->addFilter(new Zend_Log_Filter_Priority(Zend_Log::WARN, '<='));
|
||||
$this->_directives['logger'] = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message at the WARN (4) priority.
|
||||
*
|
||||
* @param string $message
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
protected function _log($message, $priority = 4)
|
||||
{
|
||||
if (!$this->_directives['logging']) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isset($this->_directives['logger'])) {
|
||||
Zend_Cache::throwException('Logging is enabled but logger is not set.');
|
||||
}
|
||||
$logger = $this->_directives['logger'];
|
||||
if (!$logger instanceof Zend_Log) {
|
||||
Zend_Cache::throwException('Logger object is not an instance of Zend_Log class.');
|
||||
}
|
||||
$logger->log($message, $priority);
|
||||
}
|
||||
}
|
||||
355
www/analytics/libs/Zend/Cache/Backend/Apc.php
Normal file
355
www/analytics/libs/Zend/Cache/Backend/Apc.php
Normal file
|
|
@ -0,0 +1,355 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Apc.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend_Interface
|
||||
*/
|
||||
// require_once 'Zend/Cache/Backend/ExtendedInterface.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend
|
||||
*/
|
||||
// require_once 'Zend/Cache/Backend.php';
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Cache_Backend_Apc extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface
|
||||
{
|
||||
/**
|
||||
* Log message
|
||||
*/
|
||||
const TAGS_UNSUPPORTED_BY_CLEAN_OF_APC_BACKEND = 'Zend_Cache_Backend_Apc::clean() : tags are unsupported by the Apc backend';
|
||||
const TAGS_UNSUPPORTED_BY_SAVE_OF_APC_BACKEND = 'Zend_Cache_Backend_Apc::save() : tags are unsupported by the Apc backend';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options associative array of options
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $options = array())
|
||||
{
|
||||
if (!extension_loaded('apc')) {
|
||||
Zend_Cache::throwException('The apc extension must be loaded for using this backend !');
|
||||
}
|
||||
parent::__construct($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available for the given id and (if yes) return it (false else)
|
||||
*
|
||||
* WARNING $doNotTestCacheValidity=true is unsupported by the Apc backend
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @param boolean $doNotTestCacheValidity if set to true, the cache validity won't be tested
|
||||
* @return string cached datas (or false)
|
||||
*/
|
||||
public function load($id, $doNotTestCacheValidity = false)
|
||||
{
|
||||
$tmp = apc_fetch($id);
|
||||
if (is_array($tmp)) {
|
||||
return $tmp[0];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available or not (for the given id)
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record
|
||||
*/
|
||||
public function test($id)
|
||||
{
|
||||
$tmp = apc_fetch($id);
|
||||
if (is_array($tmp)) {
|
||||
return $tmp[1];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save some string datas into a cache record
|
||||
*
|
||||
* Note : $data is always "string" (serialization is done by the
|
||||
* core not by the backend)
|
||||
*
|
||||
* @param string $data datas to cache
|
||||
* @param string $id cache id
|
||||
* @param array $tags array of strings, the cache record will be tagged by each string entry
|
||||
* @param int $specificLifetime if != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function save($data, $id, $tags = array(), $specificLifetime = false)
|
||||
{
|
||||
$lifetime = $this->getLifetime($specificLifetime);
|
||||
$result = apc_store($id, array($data, time(), $lifetime), $lifetime);
|
||||
if (count($tags) > 0) {
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_APC_BACKEND);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a cache record
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function remove($id)
|
||||
{
|
||||
return apc_delete($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean some cache records
|
||||
*
|
||||
* Available modes are :
|
||||
* 'all' (default) => remove all cache entries ($tags is not used)
|
||||
* 'old' => unsupported
|
||||
* 'matchingTag' => unsupported
|
||||
* 'notMatchingTag' => unsupported
|
||||
* 'matchingAnyTag' => unsupported
|
||||
*
|
||||
* @param string $mode clean mode
|
||||
* @param array $tags array of tags
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
||||
{
|
||||
switch ($mode) {
|
||||
case Zend_Cache::CLEANING_MODE_ALL:
|
||||
return apc_clear_cache('user');
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_OLD:
|
||||
$this->_log("Zend_Cache_Backend_Apc::clean() : CLEANING_MODE_OLD is unsupported by the Apc backend");
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
|
||||
case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
|
||||
case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_CLEAN_OF_APC_BACKEND);
|
||||
break;
|
||||
default:
|
||||
Zend_Cache::throwException('Invalid mode for clean() method');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the automatic cleaning is available for the backend
|
||||
*
|
||||
* DEPRECATED : use getCapabilities() instead
|
||||
*
|
||||
* @deprecated
|
||||
* @return boolean
|
||||
*/
|
||||
public function isAutomaticCleaningAvailable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the filling percentage of the backend storage
|
||||
*
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return int integer between 0 and 100
|
||||
*/
|
||||
public function getFillingPercentage()
|
||||
{
|
||||
$mem = apc_sma_info(true);
|
||||
$memSize = $mem['num_seg'] * $mem['seg_size'];
|
||||
$memAvailable= $mem['avail_mem'];
|
||||
$memUsed = $memSize - $memAvailable;
|
||||
if ($memSize == 0) {
|
||||
Zend_Cache::throwException('can\'t get apc memory size');
|
||||
}
|
||||
if ($memUsed > $memSize) {
|
||||
return 100;
|
||||
}
|
||||
return ((int) (100. * ($memUsed / $memSize)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored tags
|
||||
*
|
||||
* @return array array of stored tags (string)
|
||||
*/
|
||||
public function getTags()
|
||||
{
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_APC_BACKEND);
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which match given tags
|
||||
*
|
||||
* In case of multiple tags, a logical AND is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of matching cache ids (string)
|
||||
*/
|
||||
public function getIdsMatchingTags($tags = array())
|
||||
{
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_APC_BACKEND);
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which don't match given tags
|
||||
*
|
||||
* In case of multiple tags, a logical OR is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of not matching cache ids (string)
|
||||
*/
|
||||
public function getIdsNotMatchingTags($tags = array())
|
||||
{
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_APC_BACKEND);
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which match any given tags
|
||||
*
|
||||
* In case of multiple tags, a logical AND is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of any matching cache ids (string)
|
||||
*/
|
||||
public function getIdsMatchingAnyTags($tags = array())
|
||||
{
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_APC_BACKEND);
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids
|
||||
*
|
||||
* @return array array of stored cache ids (string)
|
||||
*/
|
||||
public function getIds()
|
||||
{
|
||||
$res = array();
|
||||
$array = apc_cache_info('user', false);
|
||||
$records = $array['cache_list'];
|
||||
foreach ($records as $record) {
|
||||
$res[] = $record['info'];
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of metadatas for the given cache id
|
||||
*
|
||||
* The array must include these keys :
|
||||
* - expire : the expire timestamp
|
||||
* - tags : a string array of tags
|
||||
* - mtime : timestamp of last modification time
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return array array of metadatas (false if the cache id is not found)
|
||||
*/
|
||||
public function getMetadatas($id)
|
||||
{
|
||||
$tmp = apc_fetch($id);
|
||||
if (is_array($tmp)) {
|
||||
$data = $tmp[0];
|
||||
$mtime = $tmp[1];
|
||||
if (!isset($tmp[2])) {
|
||||
// because this record is only with 1.7 release
|
||||
// if old cache records are still there...
|
||||
return false;
|
||||
}
|
||||
$lifetime = $tmp[2];
|
||||
return array(
|
||||
'expire' => $mtime + $lifetime,
|
||||
'tags' => array(),
|
||||
'mtime' => $mtime
|
||||
);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Give (if possible) an extra lifetime to the given cache id
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @param int $extraLifetime
|
||||
* @return boolean true if ok
|
||||
*/
|
||||
public function touch($id, $extraLifetime)
|
||||
{
|
||||
$tmp = apc_fetch($id);
|
||||
if (is_array($tmp)) {
|
||||
$data = $tmp[0];
|
||||
$mtime = $tmp[1];
|
||||
if (!isset($tmp[2])) {
|
||||
// because this record is only with 1.7 release
|
||||
// if old cache records are still there...
|
||||
return false;
|
||||
}
|
||||
$lifetime = $tmp[2];
|
||||
$newLifetime = $lifetime - (time() - $mtime) + $extraLifetime;
|
||||
if ($newLifetime <=0) {
|
||||
return false;
|
||||
}
|
||||
apc_store($id, array($data, time(), $newLifetime), $newLifetime);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an associative array of capabilities (booleans) of the backend
|
||||
*
|
||||
* The array must include these keys :
|
||||
* - automatic_cleaning (is automating cleaning necessary)
|
||||
* - tags (are tags supported)
|
||||
* - expired_read (is it possible to read expired cache records
|
||||
* (for doNotTestCacheValidity option for example))
|
||||
* - priority does the backend deal with priority when saving
|
||||
* - infinite_lifetime (is infinite lifetime can work with this backend)
|
||||
* - get_list (is it possible to get the list of cache ids and the complete list of tags)
|
||||
*
|
||||
* @return array associative of with capabilities
|
||||
*/
|
||||
public function getCapabilities()
|
||||
{
|
||||
return array(
|
||||
'automatic_cleaning' => false,
|
||||
'tags' => false,
|
||||
'expired_read' => false,
|
||||
'priority' => false,
|
||||
'infinite_lifetime' => false,
|
||||
'get_list' => true
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
250
www/analytics/libs/Zend/Cache/Backend/BlackHole.php
Normal file
250
www/analytics/libs/Zend/Cache/Backend/BlackHole.php
Normal file
|
|
@ -0,0 +1,250 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: BlackHole.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend_Interface
|
||||
*/
|
||||
// require_once 'Zend/Cache/Backend/ExtendedInterface.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend
|
||||
*/
|
||||
// require_once 'Zend/Cache/Backend.php';
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Cache_Backend_BlackHole
|
||||
extends Zend_Cache_Backend
|
||||
implements Zend_Cache_Backend_ExtendedInterface
|
||||
{
|
||||
/**
|
||||
* Test if a cache is available for the given id and (if yes) return it (false else)
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @param boolean $doNotTestCacheValidity if set to true, the cache validity won't be tested
|
||||
* @return string|false cached datas
|
||||
*/
|
||||
public function load($id, $doNotTestCacheValidity = false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available or not (for the given id)
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record
|
||||
*/
|
||||
public function test($id)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save some string datas into a cache record
|
||||
*
|
||||
* Note : $data is always "string" (serialization is done by the
|
||||
* core not by the backend)
|
||||
*
|
||||
* @param string $data Datas to cache
|
||||
* @param string $id Cache id
|
||||
* @param array $tags Array of strings, the cache record will be tagged by each string entry
|
||||
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function save($data, $id, $tags = array(), $specificLifetime = false)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a cache record
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function remove($id)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean some cache records
|
||||
*
|
||||
* Available modes are :
|
||||
* 'all' (default) => remove all cache entries ($tags is not used)
|
||||
* 'old' => remove too old cache entries ($tags is not used)
|
||||
* 'matchingTag' => remove cache entries matching all given tags
|
||||
* ($tags can be an array of strings or a single string)
|
||||
* 'notMatchingTag' => remove cache entries not matching one of the given tags
|
||||
* ($tags can be an array of strings or a single string)
|
||||
* 'matchingAnyTag' => remove cache entries matching any given tags
|
||||
* ($tags can be an array of strings or a single string)
|
||||
*
|
||||
* @param string $mode clean mode
|
||||
* @param tags array $tags array of tags
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids
|
||||
*
|
||||
* @return array array of stored cache ids (string)
|
||||
*/
|
||||
public function getIds()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored tags
|
||||
*
|
||||
* @return array array of stored tags (string)
|
||||
*/
|
||||
public function getTags()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which match given tags
|
||||
*
|
||||
* In case of multiple tags, a logical AND is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of matching cache ids (string)
|
||||
*/
|
||||
public function getIdsMatchingTags($tags = array())
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which don't match given tags
|
||||
*
|
||||
* In case of multiple tags, a logical OR is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of not matching cache ids (string)
|
||||
*/
|
||||
public function getIdsNotMatchingTags($tags = array())
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which match any given tags
|
||||
*
|
||||
* In case of multiple tags, a logical AND is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of any matching cache ids (string)
|
||||
*/
|
||||
public function getIdsMatchingAnyTags($tags = array())
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the filling percentage of the backend storage
|
||||
*
|
||||
* @return int integer between 0 and 100
|
||||
* @throws Zend_Cache_Exception
|
||||
*/
|
||||
public function getFillingPercentage()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of metadatas for the given cache id
|
||||
*
|
||||
* The array must include these keys :
|
||||
* - expire : the expire timestamp
|
||||
* - tags : a string array of tags
|
||||
* - mtime : timestamp of last modification time
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return array array of metadatas (false if the cache id is not found)
|
||||
*/
|
||||
public function getMetadatas($id)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Give (if possible) an extra lifetime to the given cache id
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @param int $extraLifetime
|
||||
* @return boolean true if ok
|
||||
*/
|
||||
public function touch($id, $extraLifetime)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an associative array of capabilities (booleans) of the backend
|
||||
*
|
||||
* The array must include these keys :
|
||||
* - automatic_cleaning (is automating cleaning necessary)
|
||||
* - tags (are tags supported)
|
||||
* - expired_read (is it possible to read expired cache records
|
||||
* (for doNotTestCacheValidity option for example))
|
||||
* - priority does the backend deal with priority when saving
|
||||
* - infinite_lifetime (is infinite lifetime can work with this backend)
|
||||
* - get_list (is it possible to get the list of cache ids and the complete list of tags)
|
||||
*
|
||||
* @return array associative of with capabilities
|
||||
*/
|
||||
public function getCapabilities()
|
||||
{
|
||||
return array(
|
||||
'automatic_cleaning' => true,
|
||||
'tags' => true,
|
||||
'expired_read' => true,
|
||||
'priority' => true,
|
||||
'infinite_lifetime' => true,
|
||||
'get_list' => true,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* PUBLIC METHOD FOR UNIT TESTING ONLY !
|
||||
*
|
||||
* Force a cache record to expire
|
||||
*
|
||||
* @param string $id cache id
|
||||
*/
|
||||
public function ___expire($id)
|
||||
{
|
||||
}
|
||||
}
|
||||
126
www/analytics/libs/Zend/Cache/Backend/ExtendedInterface.php
Normal file
126
www/analytics/libs/Zend/Cache/Backend/ExtendedInterface.php
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: ExtendedInterface.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend_Interface
|
||||
*/
|
||||
// require_once 'Zend/Cache/Backend/Interface.php';
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
interface Zend_Cache_Backend_ExtendedInterface extends Zend_Cache_Backend_Interface
|
||||
{
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids
|
||||
*
|
||||
* @return array array of stored cache ids (string)
|
||||
*/
|
||||
public function getIds();
|
||||
|
||||
/**
|
||||
* Return an array of stored tags
|
||||
*
|
||||
* @return array array of stored tags (string)
|
||||
*/
|
||||
public function getTags();
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which match given tags
|
||||
*
|
||||
* In case of multiple tags, a logical AND is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of matching cache ids (string)
|
||||
*/
|
||||
public function getIdsMatchingTags($tags = array());
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which don't match given tags
|
||||
*
|
||||
* In case of multiple tags, a logical OR is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of not matching cache ids (string)
|
||||
*/
|
||||
public function getIdsNotMatchingTags($tags = array());
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which match any given tags
|
||||
*
|
||||
* In case of multiple tags, a logical AND is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of any matching cache ids (string)
|
||||
*/
|
||||
public function getIdsMatchingAnyTags($tags = array());
|
||||
|
||||
/**
|
||||
* Return the filling percentage of the backend storage
|
||||
*
|
||||
* @return int integer between 0 and 100
|
||||
*/
|
||||
public function getFillingPercentage();
|
||||
|
||||
/**
|
||||
* Return an array of metadatas for the given cache id
|
||||
*
|
||||
* The array must include these keys :
|
||||
* - expire : the expire timestamp
|
||||
* - tags : a string array of tags
|
||||
* - mtime : timestamp of last modification time
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return array array of metadatas (false if the cache id is not found)
|
||||
*/
|
||||
public function getMetadatas($id);
|
||||
|
||||
/**
|
||||
* Give (if possible) an extra lifetime to the given cache id
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @param int $extraLifetime
|
||||
* @return boolean true if ok
|
||||
*/
|
||||
public function touch($id, $extraLifetime);
|
||||
|
||||
/**
|
||||
* Return an associative array of capabilities (booleans) of the backend
|
||||
*
|
||||
* The array must include these keys :
|
||||
* - automatic_cleaning (is automating cleaning necessary)
|
||||
* - tags (are tags supported)
|
||||
* - expired_read (is it possible to read expired cache records
|
||||
* (for doNotTestCacheValidity option for example))
|
||||
* - priority does the backend deal with priority when saving
|
||||
* - infinite_lifetime (is infinite lifetime can work with this backend)
|
||||
* - get_list (is it possible to get the list of cache ids and the complete list of tags)
|
||||
*
|
||||
* @return array associative of with capabilities
|
||||
*/
|
||||
public function getCapabilities();
|
||||
|
||||
}
|
||||
1007
www/analytics/libs/Zend/Cache/Backend/File.php
Normal file
1007
www/analytics/libs/Zend/Cache/Backend/File.php
Normal file
File diff suppressed because it is too large
Load diff
99
www/analytics/libs/Zend/Cache/Backend/Interface.php
Normal file
99
www/analytics/libs/Zend/Cache/Backend/Interface.php
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Interface.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
interface Zend_Cache_Backend_Interface
|
||||
{
|
||||
/**
|
||||
* Set the frontend directives
|
||||
*
|
||||
* @param array $directives assoc of directives
|
||||
*/
|
||||
public function setDirectives($directives);
|
||||
|
||||
/**
|
||||
* Test if a cache is available for the given id and (if yes) return it (false else)
|
||||
*
|
||||
* Note : return value is always "string" (unserialization is done by the core not by the backend)
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
|
||||
* @return string|false cached datas
|
||||
*/
|
||||
public function load($id, $doNotTestCacheValidity = false);
|
||||
|
||||
/**
|
||||
* Test if a cache is available or not (for the given id)
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return mixed|false (a cache is not available) or "last modified" timestamp (int) of the available cache record
|
||||
*/
|
||||
public function test($id);
|
||||
|
||||
/**
|
||||
* Save some string datas into a cache record
|
||||
*
|
||||
* Note : $data is always "string" (serialization is done by the
|
||||
* core not by the backend)
|
||||
*
|
||||
* @param string $data Datas to cache
|
||||
* @param string $id Cache id
|
||||
* @param array $tags Array of strings, the cache record will be tagged by each string entry
|
||||
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function save($data, $id, $tags = array(), $specificLifetime = false);
|
||||
|
||||
/**
|
||||
* Remove a cache record
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
public function remove($id);
|
||||
|
||||
/**
|
||||
* Clean some cache records
|
||||
*
|
||||
* Available modes are :
|
||||
* Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used)
|
||||
* Zend_Cache::CLEANING_MODE_OLD => remove too old cache entries ($tags is not used)
|
||||
* Zend_Cache::CLEANING_MODE_MATCHING_TAG => remove cache entries matching all given tags
|
||||
* ($tags can be an array of strings or a single string)
|
||||
* Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => remove cache entries not {matching one of the given tags}
|
||||
* ($tags can be an array of strings or a single string)
|
||||
* Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG => remove cache entries matching any given tags
|
||||
* ($tags can be an array of strings or a single string)
|
||||
*
|
||||
* @param string $mode Clean mode
|
||||
* @param array $tags Array of tags
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array());
|
||||
|
||||
}
|
||||
484
www/analytics/libs/Zend/Cache/Backend/Libmemcached.php
Normal file
484
www/analytics/libs/Zend/Cache/Backend/Libmemcached.php
Normal file
|
|
@ -0,0 +1,484 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Libmemcached.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend_Interface
|
||||
*/
|
||||
// require_once 'Zend/Cache/Backend/ExtendedInterface.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend
|
||||
*/
|
||||
// require_once 'Zend/Cache/Backend.php';
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Cache_Backend_Libmemcached extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface
|
||||
{
|
||||
/**
|
||||
* Default Server Values
|
||||
*/
|
||||
const DEFAULT_HOST = '127.0.0.1';
|
||||
const DEFAULT_PORT = 11211;
|
||||
const DEFAULT_WEIGHT = 1;
|
||||
|
||||
/**
|
||||
* Log message
|
||||
*/
|
||||
const TAGS_UNSUPPORTED_BY_CLEAN_OF_LIBMEMCACHED_BACKEND = 'Zend_Cache_Backend_Libmemcached::clean() : tags are unsupported by the Libmemcached backend';
|
||||
const TAGS_UNSUPPORTED_BY_SAVE_OF_LIBMEMCACHED_BACKEND = 'Zend_Cache_Backend_Libmemcached::save() : tags are unsupported by the Libmemcached backend';
|
||||
|
||||
/**
|
||||
* Available options
|
||||
*
|
||||
* =====> (array) servers :
|
||||
* an array of memcached server ; each memcached server is described by an associative array :
|
||||
* 'host' => (string) : the name of the memcached server
|
||||
* 'port' => (int) : the port of the memcached server
|
||||
* 'weight' => (int) : number of buckets to create for this server which in turn control its
|
||||
* probability of it being selected. The probability is relative to the total
|
||||
* weight of all servers.
|
||||
* =====> (array) client :
|
||||
* an array of memcached client options ; the memcached client is described by an associative array :
|
||||
* @see http://php.net/manual/memcached.constants.php
|
||||
* - The option name can be the name of the constant without the prefix 'OPT_'
|
||||
* or the integer value of this option constant
|
||||
*
|
||||
* @var array available options
|
||||
*/
|
||||
protected $_options = array(
|
||||
'servers' => array(array(
|
||||
'host' => self::DEFAULT_HOST,
|
||||
'port' => self::DEFAULT_PORT,
|
||||
'weight' => self::DEFAULT_WEIGHT,
|
||||
)),
|
||||
'client' => array()
|
||||
);
|
||||
|
||||
/**
|
||||
* Memcached object
|
||||
*
|
||||
* @var mixed memcached object
|
||||
*/
|
||||
protected $_memcache = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options associative array of options
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $options = array())
|
||||
{
|
||||
if (!extension_loaded('memcached')) {
|
||||
Zend_Cache::throwException('The memcached extension must be loaded for using this backend !');
|
||||
}
|
||||
|
||||
// override default client options
|
||||
$this->_options['client'] = array(
|
||||
Memcached::OPT_DISTRIBUTION => Memcached::DISTRIBUTION_CONSISTENT,
|
||||
Memcached::OPT_HASH => Memcached::HASH_MD5,
|
||||
Memcached::OPT_LIBKETAMA_COMPATIBLE => true,
|
||||
);
|
||||
|
||||
parent::__construct($options);
|
||||
|
||||
if (isset($this->_options['servers'])) {
|
||||
$value = $this->_options['servers'];
|
||||
if (isset($value['host'])) {
|
||||
// in this case, $value seems to be a simple associative array (one server only)
|
||||
$value = array(0 => $value); // let's transform it into a classical array of associative arrays
|
||||
}
|
||||
$this->setOption('servers', $value);
|
||||
}
|
||||
$this->_memcache = new Memcached;
|
||||
|
||||
// setup memcached client options
|
||||
foreach ($this->_options['client'] as $name => $value) {
|
||||
$optId = null;
|
||||
if (is_int($name)) {
|
||||
$optId = $name;
|
||||
} else {
|
||||
$optConst = 'Memcached::OPT_' . strtoupper($name);
|
||||
if (defined($optConst)) {
|
||||
$optId = constant($optConst);
|
||||
} else {
|
||||
$this->_log("Unknown memcached client option '{$name}' ({$optConst})");
|
||||
}
|
||||
}
|
||||
if ($optId) {
|
||||
if (!$this->_memcache->setOption($optId, $value)) {
|
||||
$this->_log("Setting memcached client option '{$optId}' failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// setup memcached servers
|
||||
$servers = array();
|
||||
foreach ($this->_options['servers'] as $server) {
|
||||
if (!array_key_exists('port', $server)) {
|
||||
$server['port'] = self::DEFAULT_PORT;
|
||||
}
|
||||
if (!array_key_exists('weight', $server)) {
|
||||
$server['weight'] = self::DEFAULT_WEIGHT;
|
||||
}
|
||||
|
||||
$servers[] = array($server['host'], $server['port'], $server['weight']);
|
||||
}
|
||||
$this->_memcache->addServers($servers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available for the given id and (if yes) return it (false else)
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
|
||||
* @return string|false cached datas
|
||||
*/
|
||||
public function load($id, $doNotTestCacheValidity = false)
|
||||
{
|
||||
$tmp = $this->_memcache->get($id);
|
||||
if (isset($tmp[0])) {
|
||||
return $tmp[0];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available or not (for the given id)
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @return int|false (a cache is not available) or "last modified" timestamp (int) of the available cache record
|
||||
*/
|
||||
public function test($id)
|
||||
{
|
||||
$tmp = $this->_memcache->get($id);
|
||||
if (isset($tmp[0], $tmp[1])) {
|
||||
return (int)$tmp[1];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save some string datas into a cache record
|
||||
*
|
||||
* Note : $data is always "string" (serialization is done by the
|
||||
* core not by the backend)
|
||||
*
|
||||
* @param string $data Datas to cache
|
||||
* @param string $id Cache id
|
||||
* @param array $tags Array of strings, the cache record will be tagged by each string entry
|
||||
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
public function save($data, $id, $tags = array(), $specificLifetime = false)
|
||||
{
|
||||
$lifetime = $this->getLifetime($specificLifetime);
|
||||
|
||||
// ZF-8856: using set because add needs a second request if item already exists
|
||||
$result = @$this->_memcache->set($id, array($data, time(), $lifetime), $lifetime);
|
||||
if ($result === false) {
|
||||
$rsCode = $this->_memcache->getResultCode();
|
||||
$rsMsg = $this->_memcache->getResultMessage();
|
||||
$this->_log("Memcached::set() failed: [{$rsCode}] {$rsMsg}");
|
||||
}
|
||||
|
||||
if (count($tags) > 0) {
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_LIBMEMCACHED_BACKEND);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a cache record
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
public function remove($id)
|
||||
{
|
||||
return $this->_memcache->delete($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean some cache records
|
||||
*
|
||||
* Available modes are :
|
||||
* 'all' (default) => remove all cache entries ($tags is not used)
|
||||
* 'old' => unsupported
|
||||
* 'matchingTag' => unsupported
|
||||
* 'notMatchingTag' => unsupported
|
||||
* 'matchingAnyTag' => unsupported
|
||||
*
|
||||
* @param string $mode Clean mode
|
||||
* @param array $tags Array of tags
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
||||
{
|
||||
switch ($mode) {
|
||||
case Zend_Cache::CLEANING_MODE_ALL:
|
||||
return $this->_memcache->flush();
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_OLD:
|
||||
$this->_log("Zend_Cache_Backend_Libmemcached::clean() : CLEANING_MODE_OLD is unsupported by the Libmemcached backend");
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
|
||||
case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
|
||||
case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_CLEAN_OF_LIBMEMCACHED_BACKEND);
|
||||
break;
|
||||
default:
|
||||
Zend_Cache::throwException('Invalid mode for clean() method');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the automatic cleaning is available for the backend
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isAutomaticCleaningAvailable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the frontend directives
|
||||
*
|
||||
* @param array $directives Assoc of directives
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function setDirectives($directives)
|
||||
{
|
||||
parent::setDirectives($directives);
|
||||
$lifetime = $this->getLifetime(false);
|
||||
if ($lifetime > 2592000) {
|
||||
// #ZF-3490 : For the memcached backend, there is a lifetime limit of 30 days (2592000 seconds)
|
||||
$this->_log('memcached backend has a limit of 30 days (2592000 seconds) for the lifetime');
|
||||
}
|
||||
if ($lifetime === null) {
|
||||
// #ZF-4614 : we tranform null to zero to get the maximal lifetime
|
||||
parent::setDirectives(array('lifetime' => 0));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids
|
||||
*
|
||||
* @return array array of stored cache ids (string)
|
||||
*/
|
||||
public function getIds()
|
||||
{
|
||||
$this->_log("Zend_Cache_Backend_Libmemcached::save() : getting the list of cache ids is unsupported by the Libmemcached backend");
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored tags
|
||||
*
|
||||
* @return array array of stored tags (string)
|
||||
*/
|
||||
public function getTags()
|
||||
{
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_LIBMEMCACHED_BACKEND);
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which match given tags
|
||||
*
|
||||
* In case of multiple tags, a logical AND is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of matching cache ids (string)
|
||||
*/
|
||||
public function getIdsMatchingTags($tags = array())
|
||||
{
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_LIBMEMCACHED_BACKEND);
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which don't match given tags
|
||||
*
|
||||
* In case of multiple tags, a logical OR is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of not matching cache ids (string)
|
||||
*/
|
||||
public function getIdsNotMatchingTags($tags = array())
|
||||
{
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_LIBMEMCACHED_BACKEND);
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which match any given tags
|
||||
*
|
||||
* In case of multiple tags, a logical AND is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of any matching cache ids (string)
|
||||
*/
|
||||
public function getIdsMatchingAnyTags($tags = array())
|
||||
{
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_LIBMEMCACHED_BACKEND);
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the filling percentage of the backend storage
|
||||
*
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return int integer between 0 and 100
|
||||
*/
|
||||
public function getFillingPercentage()
|
||||
{
|
||||
$mems = $this->_memcache->getStats();
|
||||
if ($mems === false) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$memSize = null;
|
||||
$memUsed = null;
|
||||
foreach ($mems as $key => $mem) {
|
||||
if ($mem === false) {
|
||||
$this->_log('can\'t get stat from ' . $key);
|
||||
continue;
|
||||
}
|
||||
|
||||
$eachSize = $mem['limit_maxbytes'];
|
||||
$eachUsed = $mem['bytes'];
|
||||
if ($eachUsed > $eachSize) {
|
||||
$eachUsed = $eachSize;
|
||||
}
|
||||
|
||||
$memSize += $eachSize;
|
||||
$memUsed += $eachUsed;
|
||||
}
|
||||
|
||||
if ($memSize === null || $memUsed === null) {
|
||||
Zend_Cache::throwException('Can\'t get filling percentage');
|
||||
}
|
||||
|
||||
return ((int) (100. * ($memUsed / $memSize)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of metadatas for the given cache id
|
||||
*
|
||||
* The array must include these keys :
|
||||
* - expire : the expire timestamp
|
||||
* - tags : a string array of tags
|
||||
* - mtime : timestamp of last modification time
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return array array of metadatas (false if the cache id is not found)
|
||||
*/
|
||||
public function getMetadatas($id)
|
||||
{
|
||||
$tmp = $this->_memcache->get($id);
|
||||
if (isset($tmp[0], $tmp[1], $tmp[2])) {
|
||||
$data = $tmp[0];
|
||||
$mtime = $tmp[1];
|
||||
$lifetime = $tmp[2];
|
||||
return array(
|
||||
'expire' => $mtime + $lifetime,
|
||||
'tags' => array(),
|
||||
'mtime' => $mtime
|
||||
);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Give (if possible) an extra lifetime to the given cache id
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @param int $extraLifetime
|
||||
* @return boolean true if ok
|
||||
*/
|
||||
public function touch($id, $extraLifetime)
|
||||
{
|
||||
$tmp = $this->_memcache->get($id);
|
||||
if (isset($tmp[0], $tmp[1], $tmp[2])) {
|
||||
$data = $tmp[0];
|
||||
$mtime = $tmp[1];
|
||||
$lifetime = $tmp[2];
|
||||
$newLifetime = $lifetime - (time() - $mtime) + $extraLifetime;
|
||||
if ($newLifetime <=0) {
|
||||
return false;
|
||||
}
|
||||
// #ZF-5702 : we try replace() first becase set() seems to be slower
|
||||
if (!($result = $this->_memcache->replace($id, array($data, time(), $newLifetime), $newLifetime))) {
|
||||
$result = $this->_memcache->set($id, array($data, time(), $newLifetime), $newLifetime);
|
||||
if ($result === false) {
|
||||
$rsCode = $this->_memcache->getResultCode();
|
||||
$rsMsg = $this->_memcache->getResultMessage();
|
||||
$this->_log("Memcached::set() failed: [{$rsCode}] {$rsMsg}");
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an associative array of capabilities (booleans) of the backend
|
||||
*
|
||||
* The array must include these keys :
|
||||
* - automatic_cleaning (is automating cleaning necessary)
|
||||
* - tags (are tags supported)
|
||||
* - expired_read (is it possible to read expired cache records
|
||||
* (for doNotTestCacheValidity option for example))
|
||||
* - priority does the backend deal with priority when saving
|
||||
* - infinite_lifetime (is infinite lifetime can work with this backend)
|
||||
* - get_list (is it possible to get the list of cache ids and the complete list of tags)
|
||||
*
|
||||
* @return array associative of with capabilities
|
||||
*/
|
||||
public function getCapabilities()
|
||||
{
|
||||
return array(
|
||||
'automatic_cleaning' => false,
|
||||
'tags' => false,
|
||||
'expired_read' => false,
|
||||
'priority' => false,
|
||||
'infinite_lifetime' => false,
|
||||
'get_list' => false
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
504
www/analytics/libs/Zend/Cache/Backend/Memcached.php
Normal file
504
www/analytics/libs/Zend/Cache/Backend/Memcached.php
Normal file
|
|
@ -0,0 +1,504 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Memcached.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend_Interface
|
||||
*/
|
||||
// require_once 'Zend/Cache/Backend/ExtendedInterface.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend
|
||||
*/
|
||||
// require_once 'Zend/Cache/Backend.php';
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Cache_Backend_Memcached extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface
|
||||
{
|
||||
/**
|
||||
* Default Values
|
||||
*/
|
||||
const DEFAULT_HOST = '127.0.0.1';
|
||||
const DEFAULT_PORT = 11211;
|
||||
const DEFAULT_PERSISTENT = true;
|
||||
const DEFAULT_WEIGHT = 1;
|
||||
const DEFAULT_TIMEOUT = 1;
|
||||
const DEFAULT_RETRY_INTERVAL = 15;
|
||||
const DEFAULT_STATUS = true;
|
||||
const DEFAULT_FAILURE_CALLBACK = null;
|
||||
|
||||
/**
|
||||
* Log message
|
||||
*/
|
||||
const TAGS_UNSUPPORTED_BY_CLEAN_OF_MEMCACHED_BACKEND = 'Zend_Cache_Backend_Memcached::clean() : tags are unsupported by the Memcached backend';
|
||||
const TAGS_UNSUPPORTED_BY_SAVE_OF_MEMCACHED_BACKEND = 'Zend_Cache_Backend_Memcached::save() : tags are unsupported by the Memcached backend';
|
||||
|
||||
/**
|
||||
* Available options
|
||||
*
|
||||
* =====> (array) servers :
|
||||
* an array of memcached server ; each memcached server is described by an associative array :
|
||||
* 'host' => (string) : the name of the memcached server
|
||||
* 'port' => (int) : the port of the memcached server
|
||||
* 'persistent' => (bool) : use or not persistent connections to this memcached server
|
||||
* 'weight' => (int) : number of buckets to create for this server which in turn control its
|
||||
* probability of it being selected. The probability is relative to the total
|
||||
* weight of all servers.
|
||||
* 'timeout' => (int) : value in seconds which will be used for connecting to the daemon. Think twice
|
||||
* before changing the default value of 1 second - you can lose all the
|
||||
* advantages of caching if your connection is too slow.
|
||||
* 'retry_interval' => (int) : controls how often a failed server will be retried, the default value
|
||||
* is 15 seconds. Setting this parameter to -1 disables automatic retry.
|
||||
* 'status' => (bool) : controls if the server should be flagged as online.
|
||||
* 'failure_callback' => (callback) : Allows the user to specify a callback function to run upon
|
||||
* encountering an error. The callback is run before failover
|
||||
* is attempted. The function takes two parameters, the hostname
|
||||
* and port of the failed server.
|
||||
*
|
||||
* =====> (boolean) compression :
|
||||
* true if you want to use on-the-fly compression
|
||||
*
|
||||
* =====> (boolean) compatibility :
|
||||
* true if you use old memcache server or extension
|
||||
*
|
||||
* @var array available options
|
||||
*/
|
||||
protected $_options = array(
|
||||
'servers' => array(array(
|
||||
'host' => self::DEFAULT_HOST,
|
||||
'port' => self::DEFAULT_PORT,
|
||||
'persistent' => self::DEFAULT_PERSISTENT,
|
||||
'weight' => self::DEFAULT_WEIGHT,
|
||||
'timeout' => self::DEFAULT_TIMEOUT,
|
||||
'retry_interval' => self::DEFAULT_RETRY_INTERVAL,
|
||||
'status' => self::DEFAULT_STATUS,
|
||||
'failure_callback' => self::DEFAULT_FAILURE_CALLBACK
|
||||
)),
|
||||
'compression' => false,
|
||||
'compatibility' => false,
|
||||
);
|
||||
|
||||
/**
|
||||
* Memcache object
|
||||
*
|
||||
* @var mixed memcache object
|
||||
*/
|
||||
protected $_memcache = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options associative array of options
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $options = array())
|
||||
{
|
||||
if (!extension_loaded('memcache')) {
|
||||
Zend_Cache::throwException('The memcache extension must be loaded for using this backend !');
|
||||
}
|
||||
parent::__construct($options);
|
||||
if (isset($this->_options['servers'])) {
|
||||
$value= $this->_options['servers'];
|
||||
if (isset($value['host'])) {
|
||||
// in this case, $value seems to be a simple associative array (one server only)
|
||||
$value = array(0 => $value); // let's transform it into a classical array of associative arrays
|
||||
}
|
||||
$this->setOption('servers', $value);
|
||||
}
|
||||
$this->_memcache = new Memcache;
|
||||
foreach ($this->_options['servers'] as $server) {
|
||||
if (!array_key_exists('port', $server)) {
|
||||
$server['port'] = self::DEFAULT_PORT;
|
||||
}
|
||||
if (!array_key_exists('persistent', $server)) {
|
||||
$server['persistent'] = self::DEFAULT_PERSISTENT;
|
||||
}
|
||||
if (!array_key_exists('weight', $server)) {
|
||||
$server['weight'] = self::DEFAULT_WEIGHT;
|
||||
}
|
||||
if (!array_key_exists('timeout', $server)) {
|
||||
$server['timeout'] = self::DEFAULT_TIMEOUT;
|
||||
}
|
||||
if (!array_key_exists('retry_interval', $server)) {
|
||||
$server['retry_interval'] = self::DEFAULT_RETRY_INTERVAL;
|
||||
}
|
||||
if (!array_key_exists('status', $server)) {
|
||||
$server['status'] = self::DEFAULT_STATUS;
|
||||
}
|
||||
if (!array_key_exists('failure_callback', $server)) {
|
||||
$server['failure_callback'] = self::DEFAULT_FAILURE_CALLBACK;
|
||||
}
|
||||
if ($this->_options['compatibility']) {
|
||||
// No status for compatibility mode (#ZF-5887)
|
||||
$this->_memcache->addServer($server['host'], $server['port'], $server['persistent'],
|
||||
$server['weight'], $server['timeout'],
|
||||
$server['retry_interval']);
|
||||
} else {
|
||||
$this->_memcache->addServer($server['host'], $server['port'], $server['persistent'],
|
||||
$server['weight'], $server['timeout'],
|
||||
$server['retry_interval'],
|
||||
$server['status'], $server['failure_callback']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available for the given id and (if yes) return it (false else)
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
|
||||
* @return string|false cached datas
|
||||
*/
|
||||
public function load($id, $doNotTestCacheValidity = false)
|
||||
{
|
||||
$tmp = $this->_memcache->get($id);
|
||||
if (is_array($tmp) && isset($tmp[0])) {
|
||||
return $tmp[0];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available or not (for the given id)
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @return mixed|false (a cache is not available) or "last modified" timestamp (int) of the available cache record
|
||||
*/
|
||||
public function test($id)
|
||||
{
|
||||
$tmp = $this->_memcache->get($id);
|
||||
if (is_array($tmp)) {
|
||||
return $tmp[1];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save some string datas into a cache record
|
||||
*
|
||||
* Note : $data is always "string" (serialization is done by the
|
||||
* core not by the backend)
|
||||
*
|
||||
* @param string $data Datas to cache
|
||||
* @param string $id Cache id
|
||||
* @param array $tags Array of strings, the cache record will be tagged by each string entry
|
||||
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
public function save($data, $id, $tags = array(), $specificLifetime = false)
|
||||
{
|
||||
$lifetime = $this->getLifetime($specificLifetime);
|
||||
if ($this->_options['compression']) {
|
||||
$flag = MEMCACHE_COMPRESSED;
|
||||
} else {
|
||||
$flag = 0;
|
||||
}
|
||||
|
||||
// ZF-8856: using set because add needs a second request if item already exists
|
||||
$result = @$this->_memcache->set($id, array($data, time(), $lifetime), $flag, $lifetime);
|
||||
|
||||
if (count($tags) > 0) {
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_MEMCACHED_BACKEND);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a cache record
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
public function remove($id)
|
||||
{
|
||||
return $this->_memcache->delete($id, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean some cache records
|
||||
*
|
||||
* Available modes are :
|
||||
* 'all' (default) => remove all cache entries ($tags is not used)
|
||||
* 'old' => unsupported
|
||||
* 'matchingTag' => unsupported
|
||||
* 'notMatchingTag' => unsupported
|
||||
* 'matchingAnyTag' => unsupported
|
||||
*
|
||||
* @param string $mode Clean mode
|
||||
* @param array $tags Array of tags
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
||||
{
|
||||
switch ($mode) {
|
||||
case Zend_Cache::CLEANING_MODE_ALL:
|
||||
return $this->_memcache->flush();
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_OLD:
|
||||
$this->_log("Zend_Cache_Backend_Memcached::clean() : CLEANING_MODE_OLD is unsupported by the Memcached backend");
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
|
||||
case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
|
||||
case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_CLEAN_OF_MEMCACHED_BACKEND);
|
||||
break;
|
||||
default:
|
||||
Zend_Cache::throwException('Invalid mode for clean() method');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the automatic cleaning is available for the backend
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isAutomaticCleaningAvailable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the frontend directives
|
||||
*
|
||||
* @param array $directives Assoc of directives
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function setDirectives($directives)
|
||||
{
|
||||
parent::setDirectives($directives);
|
||||
$lifetime = $this->getLifetime(false);
|
||||
if ($lifetime > 2592000) {
|
||||
// #ZF-3490 : For the memcached backend, there is a lifetime limit of 30 days (2592000 seconds)
|
||||
$this->_log('memcached backend has a limit of 30 days (2592000 seconds) for the lifetime');
|
||||
}
|
||||
if ($lifetime === null) {
|
||||
// #ZF-4614 : we tranform null to zero to get the maximal lifetime
|
||||
parent::setDirectives(array('lifetime' => 0));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids
|
||||
*
|
||||
* @return array array of stored cache ids (string)
|
||||
*/
|
||||
public function getIds()
|
||||
{
|
||||
$this->_log("Zend_Cache_Backend_Memcached::save() : getting the list of cache ids is unsupported by the Memcache backend");
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored tags
|
||||
*
|
||||
* @return array array of stored tags (string)
|
||||
*/
|
||||
public function getTags()
|
||||
{
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_MEMCACHED_BACKEND);
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which match given tags
|
||||
*
|
||||
* In case of multiple tags, a logical AND is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of matching cache ids (string)
|
||||
*/
|
||||
public function getIdsMatchingTags($tags = array())
|
||||
{
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_MEMCACHED_BACKEND);
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which don't match given tags
|
||||
*
|
||||
* In case of multiple tags, a logical OR is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of not matching cache ids (string)
|
||||
*/
|
||||
public function getIdsNotMatchingTags($tags = array())
|
||||
{
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_MEMCACHED_BACKEND);
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which match any given tags
|
||||
*
|
||||
* In case of multiple tags, a logical AND is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of any matching cache ids (string)
|
||||
*/
|
||||
public function getIdsMatchingAnyTags($tags = array())
|
||||
{
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_MEMCACHED_BACKEND);
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the filling percentage of the backend storage
|
||||
*
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return int integer between 0 and 100
|
||||
*/
|
||||
public function getFillingPercentage()
|
||||
{
|
||||
$mems = $this->_memcache->getExtendedStats();
|
||||
|
||||
$memSize = null;
|
||||
$memUsed = null;
|
||||
foreach ($mems as $key => $mem) {
|
||||
if ($mem === false) {
|
||||
$this->_log('can\'t get stat from ' . $key);
|
||||
continue;
|
||||
}
|
||||
|
||||
$eachSize = $mem['limit_maxbytes'];
|
||||
$eachUsed = $mem['bytes'];
|
||||
if ($eachUsed > $eachSize) {
|
||||
$eachUsed = $eachSize;
|
||||
}
|
||||
|
||||
$memSize += $eachSize;
|
||||
$memUsed += $eachUsed;
|
||||
}
|
||||
|
||||
if ($memSize === null || $memUsed === null) {
|
||||
Zend_Cache::throwException('Can\'t get filling percentage');
|
||||
}
|
||||
|
||||
return ((int) (100. * ($memUsed / $memSize)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of metadatas for the given cache id
|
||||
*
|
||||
* The array must include these keys :
|
||||
* - expire : the expire timestamp
|
||||
* - tags : a string array of tags
|
||||
* - mtime : timestamp of last modification time
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return array array of metadatas (false if the cache id is not found)
|
||||
*/
|
||||
public function getMetadatas($id)
|
||||
{
|
||||
$tmp = $this->_memcache->get($id);
|
||||
if (is_array($tmp)) {
|
||||
$data = $tmp[0];
|
||||
$mtime = $tmp[1];
|
||||
if (!isset($tmp[2])) {
|
||||
// because this record is only with 1.7 release
|
||||
// if old cache records are still there...
|
||||
return false;
|
||||
}
|
||||
$lifetime = $tmp[2];
|
||||
return array(
|
||||
'expire' => $mtime + $lifetime,
|
||||
'tags' => array(),
|
||||
'mtime' => $mtime
|
||||
);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Give (if possible) an extra lifetime to the given cache id
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @param int $extraLifetime
|
||||
* @return boolean true if ok
|
||||
*/
|
||||
public function touch($id, $extraLifetime)
|
||||
{
|
||||
if ($this->_options['compression']) {
|
||||
$flag = MEMCACHE_COMPRESSED;
|
||||
} else {
|
||||
$flag = 0;
|
||||
}
|
||||
$tmp = $this->_memcache->get($id);
|
||||
if (is_array($tmp)) {
|
||||
$data = $tmp[0];
|
||||
$mtime = $tmp[1];
|
||||
if (!isset($tmp[2])) {
|
||||
// because this record is only with 1.7 release
|
||||
// if old cache records are still there...
|
||||
return false;
|
||||
}
|
||||
$lifetime = $tmp[2];
|
||||
$newLifetime = $lifetime - (time() - $mtime) + $extraLifetime;
|
||||
if ($newLifetime <=0) {
|
||||
return false;
|
||||
}
|
||||
// #ZF-5702 : we try replace() first becase set() seems to be slower
|
||||
if (!($result = $this->_memcache->replace($id, array($data, time(), $newLifetime), $flag, $newLifetime))) {
|
||||
$result = $this->_memcache->set($id, array($data, time(), $newLifetime), $flag, $newLifetime);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an associative array of capabilities (booleans) of the backend
|
||||
*
|
||||
* The array must include these keys :
|
||||
* - automatic_cleaning (is automating cleaning necessary)
|
||||
* - tags (are tags supported)
|
||||
* - expired_read (is it possible to read expired cache records
|
||||
* (for doNotTestCacheValidity option for example))
|
||||
* - priority does the backend deal with priority when saving
|
||||
* - infinite_lifetime (is infinite lifetime can work with this backend)
|
||||
* - get_list (is it possible to get the list of cache ids and the complete list of tags)
|
||||
*
|
||||
* @return array associative of with capabilities
|
||||
*/
|
||||
public function getCapabilities()
|
||||
{
|
||||
return array(
|
||||
'automatic_cleaning' => false,
|
||||
'tags' => false,
|
||||
'expired_read' => false,
|
||||
'priority' => false,
|
||||
'infinite_lifetime' => false,
|
||||
'get_list' => false
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
678
www/analytics/libs/Zend/Cache/Backend/Sqlite.php
Normal file
678
www/analytics/libs/Zend/Cache/Backend/Sqlite.php
Normal file
|
|
@ -0,0 +1,678 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Sqlite.php 24348 2011-08-04 17:51:24Z mabe $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend_Interface
|
||||
*/
|
||||
// require_once 'Zend/Cache/Backend/ExtendedInterface.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend
|
||||
*/
|
||||
// require_once 'Zend/Cache/Backend.php';
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Cache_Backend_Sqlite extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface
|
||||
{
|
||||
/**
|
||||
* Available options
|
||||
*
|
||||
* =====> (string) cache_db_complete_path :
|
||||
* - the complete path (filename included) of the SQLITE database
|
||||
*
|
||||
* ====> (int) automatic_vacuum_factor :
|
||||
* - Disable / Tune the automatic vacuum process
|
||||
* - The automatic vacuum process defragment the database file (and make it smaller)
|
||||
* when a clean() or delete() is called
|
||||
* 0 => no automatic vacuum
|
||||
* 1 => systematic vacuum (when delete() or clean() methods are called)
|
||||
* x (integer) > 1 => automatic vacuum randomly 1 times on x clean() or delete()
|
||||
*
|
||||
* @var array Available options
|
||||
*/
|
||||
protected $_options = array(
|
||||
'cache_db_complete_path' => null,
|
||||
'automatic_vacuum_factor' => 10
|
||||
);
|
||||
|
||||
/**
|
||||
* DB ressource
|
||||
*
|
||||
* @var mixed $_db
|
||||
*/
|
||||
private $_db = null;
|
||||
|
||||
/**
|
||||
* Boolean to store if the structure has benn checked or not
|
||||
*
|
||||
* @var boolean $_structureChecked
|
||||
*/
|
||||
private $_structureChecked = false;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options Associative array of options
|
||||
* @throws Zend_cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $options = array())
|
||||
{
|
||||
parent::__construct($options);
|
||||
if ($this->_options['cache_db_complete_path'] === null) {
|
||||
Zend_Cache::throwException('cache_db_complete_path option has to set');
|
||||
}
|
||||
if (!extension_loaded('sqlite')) {
|
||||
Zend_Cache::throwException("Cannot use SQLite storage because the 'sqlite' extension is not loaded in the current PHP environment");
|
||||
}
|
||||
$this->_getConnection();
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
@sqlite_close($this->_getConnection());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available for the given id and (if yes) return it (false else)
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
|
||||
* @return string|false Cached datas
|
||||
*/
|
||||
public function load($id, $doNotTestCacheValidity = false)
|
||||
{
|
||||
$this->_checkAndBuildStructure();
|
||||
$sql = "SELECT content FROM cache WHERE id='$id'";
|
||||
if (!$doNotTestCacheValidity) {
|
||||
$sql = $sql . " AND (expire=0 OR expire>" . time() . ')';
|
||||
}
|
||||
$result = $this->_query($sql);
|
||||
$row = @sqlite_fetch_array($result);
|
||||
if ($row) {
|
||||
return $row['content'];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available or not (for the given id)
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @return mixed|false (a cache is not available) or "last modified" timestamp (int) of the available cache record
|
||||
*/
|
||||
public function test($id)
|
||||
{
|
||||
$this->_checkAndBuildStructure();
|
||||
$sql = "SELECT lastModified FROM cache WHERE id='$id' AND (expire=0 OR expire>" . time() . ')';
|
||||
$result = $this->_query($sql);
|
||||
$row = @sqlite_fetch_array($result);
|
||||
if ($row) {
|
||||
return ((int) $row['lastModified']);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save some string datas into a cache record
|
||||
*
|
||||
* Note : $data is always "string" (serialization is done by the
|
||||
* core not by the backend)
|
||||
*
|
||||
* @param string $data Datas to cache
|
||||
* @param string $id Cache id
|
||||
* @param array $tags Array of strings, the cache record will be tagged by each string entry
|
||||
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
public function save($data, $id, $tags = array(), $specificLifetime = false)
|
||||
{
|
||||
$this->_checkAndBuildStructure();
|
||||
$lifetime = $this->getLifetime($specificLifetime);
|
||||
$data = @sqlite_escape_string($data);
|
||||
$mktime = time();
|
||||
if ($lifetime === null) {
|
||||
$expire = 0;
|
||||
} else {
|
||||
$expire = $mktime + $lifetime;
|
||||
}
|
||||
$this->_query("DELETE FROM cache WHERE id='$id'");
|
||||
$sql = "INSERT INTO cache (id, content, lastModified, expire) VALUES ('$id', '$data', $mktime, $expire)";
|
||||
$res = $this->_query($sql);
|
||||
if (!$res) {
|
||||
$this->_log("Zend_Cache_Backend_Sqlite::save() : impossible to store the cache id=$id");
|
||||
return false;
|
||||
}
|
||||
$res = true;
|
||||
foreach ($tags as $tag) {
|
||||
$res = $this->_registerTag($id, $tag) && $res;
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a cache record
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
public function remove($id)
|
||||
{
|
||||
$this->_checkAndBuildStructure();
|
||||
$res = $this->_query("SELECT COUNT(*) AS nbr FROM cache WHERE id='$id'");
|
||||
$result1 = @sqlite_fetch_single($res);
|
||||
$result2 = $this->_query("DELETE FROM cache WHERE id='$id'");
|
||||
$result3 = $this->_query("DELETE FROM tag WHERE id='$id'");
|
||||
$this->_automaticVacuum();
|
||||
return ($result1 && $result2 && $result3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean some cache records
|
||||
*
|
||||
* Available modes are :
|
||||
* Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used)
|
||||
* Zend_Cache::CLEANING_MODE_OLD => remove too old cache entries ($tags is not used)
|
||||
* Zend_Cache::CLEANING_MODE_MATCHING_TAG => remove cache entries matching all given tags
|
||||
* ($tags can be an array of strings or a single string)
|
||||
* Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => remove cache entries not {matching one of the given tags}
|
||||
* ($tags can be an array of strings or a single string)
|
||||
* Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG => remove cache entries matching any given tags
|
||||
* ($tags can be an array of strings or a single string)
|
||||
*
|
||||
* @param string $mode Clean mode
|
||||
* @param array $tags Array of tags
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
||||
{
|
||||
$this->_checkAndBuildStructure();
|
||||
$return = $this->_clean($mode, $tags);
|
||||
$this->_automaticVacuum();
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids
|
||||
*
|
||||
* @return array array of stored cache ids (string)
|
||||
*/
|
||||
public function getIds()
|
||||
{
|
||||
$this->_checkAndBuildStructure();
|
||||
$res = $this->_query("SELECT id FROM cache WHERE (expire=0 OR expire>" . time() . ")");
|
||||
$result = array();
|
||||
while ($id = @sqlite_fetch_single($res)) {
|
||||
$result[] = $id;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored tags
|
||||
*
|
||||
* @return array array of stored tags (string)
|
||||
*/
|
||||
public function getTags()
|
||||
{
|
||||
$this->_checkAndBuildStructure();
|
||||
$res = $this->_query("SELECT DISTINCT(name) AS name FROM tag");
|
||||
$result = array();
|
||||
while ($id = @sqlite_fetch_single($res)) {
|
||||
$result[] = $id;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which match given tags
|
||||
*
|
||||
* In case of multiple tags, a logical AND is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of matching cache ids (string)
|
||||
*/
|
||||
public function getIdsMatchingTags($tags = array())
|
||||
{
|
||||
$first = true;
|
||||
$ids = array();
|
||||
foreach ($tags as $tag) {
|
||||
$res = $this->_query("SELECT DISTINCT(id) AS id FROM tag WHERE name='$tag'");
|
||||
if (!$res) {
|
||||
return array();
|
||||
}
|
||||
$rows = @sqlite_fetch_all($res, SQLITE_ASSOC);
|
||||
$ids2 = array();
|
||||
foreach ($rows as $row) {
|
||||
$ids2[] = $row['id'];
|
||||
}
|
||||
if ($first) {
|
||||
$ids = $ids2;
|
||||
$first = false;
|
||||
} else {
|
||||
$ids = array_intersect($ids, $ids2);
|
||||
}
|
||||
}
|
||||
$result = array();
|
||||
foreach ($ids as $id) {
|
||||
$result[] = $id;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which don't match given tags
|
||||
*
|
||||
* In case of multiple tags, a logical OR is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of not matching cache ids (string)
|
||||
*/
|
||||
public function getIdsNotMatchingTags($tags = array())
|
||||
{
|
||||
$res = $this->_query("SELECT id FROM cache");
|
||||
$rows = @sqlite_fetch_all($res, SQLITE_ASSOC);
|
||||
$result = array();
|
||||
foreach ($rows as $row) {
|
||||
$id = $row['id'];
|
||||
$matching = false;
|
||||
foreach ($tags as $tag) {
|
||||
$res = $this->_query("SELECT COUNT(*) AS nbr FROM tag WHERE name='$tag' AND id='$id'");
|
||||
if (!$res) {
|
||||
return array();
|
||||
}
|
||||
$nbr = (int) @sqlite_fetch_single($res);
|
||||
if ($nbr > 0) {
|
||||
$matching = true;
|
||||
}
|
||||
}
|
||||
if (!$matching) {
|
||||
$result[] = $id;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which match any given tags
|
||||
*
|
||||
* In case of multiple tags, a logical AND is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of any matching cache ids (string)
|
||||
*/
|
||||
public function getIdsMatchingAnyTags($tags = array())
|
||||
{
|
||||
$first = true;
|
||||
$ids = array();
|
||||
foreach ($tags as $tag) {
|
||||
$res = $this->_query("SELECT DISTINCT(id) AS id FROM tag WHERE name='$tag'");
|
||||
if (!$res) {
|
||||
return array();
|
||||
}
|
||||
$rows = @sqlite_fetch_all($res, SQLITE_ASSOC);
|
||||
$ids2 = array();
|
||||
foreach ($rows as $row) {
|
||||
$ids2[] = $row['id'];
|
||||
}
|
||||
if ($first) {
|
||||
$ids = $ids2;
|
||||
$first = false;
|
||||
} else {
|
||||
$ids = array_merge($ids, $ids2);
|
||||
}
|
||||
}
|
||||
$result = array();
|
||||
foreach ($ids as $id) {
|
||||
$result[] = $id;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the filling percentage of the backend storage
|
||||
*
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return int integer between 0 and 100
|
||||
*/
|
||||
public function getFillingPercentage()
|
||||
{
|
||||
$dir = dirname($this->_options['cache_db_complete_path']);
|
||||
$free = disk_free_space($dir);
|
||||
$total = disk_total_space($dir);
|
||||
if ($total == 0) {
|
||||
Zend_Cache::throwException('can\'t get disk_total_space');
|
||||
} else {
|
||||
if ($free >= $total) {
|
||||
return 100;
|
||||
}
|
||||
return ((int) (100. * ($total - $free) / $total));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of metadatas for the given cache id
|
||||
*
|
||||
* The array must include these keys :
|
||||
* - expire : the expire timestamp
|
||||
* - tags : a string array of tags
|
||||
* - mtime : timestamp of last modification time
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return array array of metadatas (false if the cache id is not found)
|
||||
*/
|
||||
public function getMetadatas($id)
|
||||
{
|
||||
$tags = array();
|
||||
$res = $this->_query("SELECT name FROM tag WHERE id='$id'");
|
||||
if ($res) {
|
||||
$rows = @sqlite_fetch_all($res, SQLITE_ASSOC);
|
||||
foreach ($rows as $row) {
|
||||
$tags[] = $row['name'];
|
||||
}
|
||||
}
|
||||
$this->_query('CREATE TABLE cache (id TEXT PRIMARY KEY, content BLOB, lastModified INTEGER, expire INTEGER)');
|
||||
$res = $this->_query("SELECT lastModified,expire FROM cache WHERE id='$id'");
|
||||
if (!$res) {
|
||||
return false;
|
||||
}
|
||||
$row = @sqlite_fetch_array($res, SQLITE_ASSOC);
|
||||
return array(
|
||||
'tags' => $tags,
|
||||
'mtime' => $row['lastModified'],
|
||||
'expire' => $row['expire']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Give (if possible) an extra lifetime to the given cache id
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @param int $extraLifetime
|
||||
* @return boolean true if ok
|
||||
*/
|
||||
public function touch($id, $extraLifetime)
|
||||
{
|
||||
$sql = "SELECT expire FROM cache WHERE id='$id' AND (expire=0 OR expire>" . time() . ')';
|
||||
$res = $this->_query($sql);
|
||||
if (!$res) {
|
||||
return false;
|
||||
}
|
||||
$expire = @sqlite_fetch_single($res);
|
||||
$newExpire = $expire + $extraLifetime;
|
||||
$res = $this->_query("UPDATE cache SET lastModified=" . time() . ", expire=$newExpire WHERE id='$id'");
|
||||
if ($res) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an associative array of capabilities (booleans) of the backend
|
||||
*
|
||||
* The array must include these keys :
|
||||
* - automatic_cleaning (is automating cleaning necessary)
|
||||
* - tags (are tags supported)
|
||||
* - expired_read (is it possible to read expired cache records
|
||||
* (for doNotTestCacheValidity option for example))
|
||||
* - priority does the backend deal with priority when saving
|
||||
* - infinite_lifetime (is infinite lifetime can work with this backend)
|
||||
* - get_list (is it possible to get the list of cache ids and the complete list of tags)
|
||||
*
|
||||
* @return array associative of with capabilities
|
||||
*/
|
||||
public function getCapabilities()
|
||||
{
|
||||
return array(
|
||||
'automatic_cleaning' => true,
|
||||
'tags' => true,
|
||||
'expired_read' => true,
|
||||
'priority' => false,
|
||||
'infinite_lifetime' => true,
|
||||
'get_list' => true
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* PUBLIC METHOD FOR UNIT TESTING ONLY !
|
||||
*
|
||||
* Force a cache record to expire
|
||||
*
|
||||
* @param string $id Cache id
|
||||
*/
|
||||
public function ___expire($id)
|
||||
{
|
||||
$time = time() - 1;
|
||||
$this->_query("UPDATE cache SET lastModified=$time, expire=$time WHERE id='$id'");
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the connection resource
|
||||
*
|
||||
* If we are not connected, the connection is made
|
||||
*
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return resource Connection resource
|
||||
*/
|
||||
private function _getConnection()
|
||||
{
|
||||
if (is_resource($this->_db)) {
|
||||
return $this->_db;
|
||||
} else {
|
||||
$this->_db = @sqlite_open($this->_options['cache_db_complete_path']);
|
||||
if (!(is_resource($this->_db))) {
|
||||
Zend_Cache::throwException("Impossible to open " . $this->_options['cache_db_complete_path'] . " cache DB file");
|
||||
}
|
||||
return $this->_db;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute an SQL query silently
|
||||
*
|
||||
* @param string $query SQL query
|
||||
* @return mixed|false query results
|
||||
*/
|
||||
private function _query($query)
|
||||
{
|
||||
$db = $this->_getConnection();
|
||||
if (is_resource($db)) {
|
||||
$res = @sqlite_query($db, $query);
|
||||
if ($res === false) {
|
||||
return false;
|
||||
} else {
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deal with the automatic vacuum process
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function _automaticVacuum()
|
||||
{
|
||||
if ($this->_options['automatic_vacuum_factor'] > 0) {
|
||||
$rand = rand(1, $this->_options['automatic_vacuum_factor']);
|
||||
if ($rand == 1) {
|
||||
$this->_query('VACUUM');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a cache id with the given tag
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @param string $tag Tag
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
private function _registerTag($id, $tag) {
|
||||
$res = $this->_query("DELETE FROM TAG WHERE name='$tag' AND id='$id'");
|
||||
$res = $this->_query("INSERT INTO tag (name, id) VALUES ('$tag', '$id')");
|
||||
if (!$res) {
|
||||
$this->_log("Zend_Cache_Backend_Sqlite::_registerTag() : impossible to register tag=$tag on id=$id");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the database structure
|
||||
*
|
||||
* @return false
|
||||
*/
|
||||
private function _buildStructure()
|
||||
{
|
||||
$this->_query('DROP INDEX tag_id_index');
|
||||
$this->_query('DROP INDEX tag_name_index');
|
||||
$this->_query('DROP INDEX cache_id_expire_index');
|
||||
$this->_query('DROP TABLE version');
|
||||
$this->_query('DROP TABLE cache');
|
||||
$this->_query('DROP TABLE tag');
|
||||
$this->_query('CREATE TABLE version (num INTEGER PRIMARY KEY)');
|
||||
$this->_query('CREATE TABLE cache (id TEXT PRIMARY KEY, content BLOB, lastModified INTEGER, expire INTEGER)');
|
||||
$this->_query('CREATE TABLE tag (name TEXT, id TEXT)');
|
||||
$this->_query('CREATE INDEX tag_id_index ON tag(id)');
|
||||
$this->_query('CREATE INDEX tag_name_index ON tag(name)');
|
||||
$this->_query('CREATE INDEX cache_id_expire_index ON cache(id, expire)');
|
||||
$this->_query('INSERT INTO version (num) VALUES (1)');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the database structure is ok (with the good version)
|
||||
*
|
||||
* @return boolean True if ok
|
||||
*/
|
||||
private function _checkStructureVersion()
|
||||
{
|
||||
$result = $this->_query("SELECT num FROM version");
|
||||
if (!$result) return false;
|
||||
$row = @sqlite_fetch_array($result);
|
||||
if (!$row) {
|
||||
return false;
|
||||
}
|
||||
if (((int) $row['num']) != 1) {
|
||||
// old cache structure
|
||||
$this->_log('Zend_Cache_Backend_Sqlite::_checkStructureVersion() : old cache structure version detected => the cache is going to be dropped');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean some cache records
|
||||
*
|
||||
* Available modes are :
|
||||
* Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used)
|
||||
* Zend_Cache::CLEANING_MODE_OLD => remove too old cache entries ($tags is not used)
|
||||
* Zend_Cache::CLEANING_MODE_MATCHING_TAG => remove cache entries matching all given tags
|
||||
* ($tags can be an array of strings or a single string)
|
||||
* Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => remove cache entries not {matching one of the given tags}
|
||||
* ($tags can be an array of strings or a single string)
|
||||
* Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG => remove cache entries matching any given tags
|
||||
* ($tags can be an array of strings or a single string)
|
||||
*
|
||||
* @param string $mode Clean mode
|
||||
* @param array $tags Array of tags
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
private function _clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
||||
{
|
||||
switch ($mode) {
|
||||
case Zend_Cache::CLEANING_MODE_ALL:
|
||||
$res1 = $this->_query('DELETE FROM cache');
|
||||
$res2 = $this->_query('DELETE FROM tag');
|
||||
return $res1 && $res2;
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_OLD:
|
||||
$mktime = time();
|
||||
$res1 = $this->_query("DELETE FROM tag WHERE id IN (SELECT id FROM cache WHERE expire>0 AND expire<=$mktime)");
|
||||
$res2 = $this->_query("DELETE FROM cache WHERE expire>0 AND expire<=$mktime");
|
||||
return $res1 && $res2;
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
|
||||
$ids = $this->getIdsMatchingTags($tags);
|
||||
$result = true;
|
||||
foreach ($ids as $id) {
|
||||
$result = $this->remove($id) && $result;
|
||||
}
|
||||
return $result;
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
|
||||
$ids = $this->getIdsNotMatchingTags($tags);
|
||||
$result = true;
|
||||
foreach ($ids as $id) {
|
||||
$result = $this->remove($id) && $result;
|
||||
}
|
||||
return $result;
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
|
||||
$ids = $this->getIdsMatchingAnyTags($tags);
|
||||
$result = true;
|
||||
foreach ($ids as $id) {
|
||||
$result = $this->remove($id) && $result;
|
||||
}
|
||||
return $result;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the database structure is ok (with the good version), if no : build it
|
||||
*
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return boolean True if ok
|
||||
*/
|
||||
private function _checkAndBuildStructure()
|
||||
{
|
||||
if (!($this->_structureChecked)) {
|
||||
if (!$this->_checkStructureVersion()) {
|
||||
$this->_buildStructure();
|
||||
if (!$this->_checkStructureVersion()) {
|
||||
Zend_Cache::throwException("Impossible to build cache structure in " . $this->_options['cache_db_complete_path']);
|
||||
}
|
||||
}
|
||||
$this->_structureChecked = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
564
www/analytics/libs/Zend/Cache/Backend/Static.php
Normal file
564
www/analytics/libs/Zend/Cache/Backend/Static.php
Normal file
|
|
@ -0,0 +1,564 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Static.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend_Interface
|
||||
*/
|
||||
// require_once 'Zend/Cache/Backend/Interface.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend
|
||||
*/
|
||||
// require_once 'Zend/Cache/Backend.php';
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Cache_Backend_Static
|
||||
extends Zend_Cache_Backend
|
||||
implements Zend_Cache_Backend_Interface
|
||||
{
|
||||
const INNER_CACHE_NAME = 'zend_cache_backend_static_tagcache';
|
||||
|
||||
/**
|
||||
* Static backend options
|
||||
* @var array
|
||||
*/
|
||||
protected $_options = array(
|
||||
'public_dir' => null,
|
||||
'sub_dir' => 'html',
|
||||
'file_extension' => '.html',
|
||||
'index_filename' => 'index',
|
||||
'file_locking' => true,
|
||||
'cache_file_umask' => 0600,
|
||||
'cache_directory_umask' => 0700,
|
||||
'debug_header' => false,
|
||||
'tag_cache' => null,
|
||||
'disable_caching' => false
|
||||
);
|
||||
|
||||
/**
|
||||
* Cache for handling tags
|
||||
* @var Zend_Cache_Core
|
||||
*/
|
||||
protected $_tagCache = null;
|
||||
|
||||
/**
|
||||
* Tagged items
|
||||
* @var array
|
||||
*/
|
||||
protected $_tagged = null;
|
||||
|
||||
/**
|
||||
* Interceptor child method to handle the case where an Inner
|
||||
* Cache object is being set since it's not supported by the
|
||||
* standard backend interface
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
* @return Zend_Cache_Backend_Static
|
||||
*/
|
||||
public function setOption($name, $value)
|
||||
{
|
||||
if ($name == 'tag_cache') {
|
||||
$this->setInnerCache($value);
|
||||
} else {
|
||||
parent::setOption($name, $value);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve any option via interception of the parent's statically held
|
||||
* options including the local option for a tag cache.
|
||||
*
|
||||
* @param string $name
|
||||
* @return mixed
|
||||
*/
|
||||
public function getOption($name)
|
||||
{
|
||||
if ($name == 'tag_cache') {
|
||||
return $this->getInnerCache();
|
||||
} else {
|
||||
if (in_array($name, $this->_options)) {
|
||||
return $this->_options[$name];
|
||||
}
|
||||
if ($name == 'lifetime') {
|
||||
return parent::getLifetime();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available for the given id and (if yes) return it (false else)
|
||||
*
|
||||
* Note : return value is always "string" (unserialization is done by the core not by the backend)
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
|
||||
* @return string|false cached datas
|
||||
*/
|
||||
public function load($id, $doNotTestCacheValidity = false)
|
||||
{
|
||||
if (($id = (string)$id) === '') {
|
||||
$id = $this->_detectId();
|
||||
} else {
|
||||
$id = $this->_decodeId($id);
|
||||
}
|
||||
if (!$this->_verifyPath($id)) {
|
||||
Zend_Cache::throwException('Invalid cache id: does not match expected public_dir path');
|
||||
}
|
||||
if ($doNotTestCacheValidity) {
|
||||
$this->_log("Zend_Cache_Backend_Static::load() : \$doNotTestCacheValidity=true is unsupported by the Static backend");
|
||||
}
|
||||
|
||||
$fileName = basename($id);
|
||||
if ($fileName === '') {
|
||||
$fileName = $this->_options['index_filename'];
|
||||
}
|
||||
$pathName = $this->_options['public_dir'] . dirname($id);
|
||||
$file = rtrim($pathName, '/') . '/' . $fileName . $this->_options['file_extension'];
|
||||
if (file_exists($file)) {
|
||||
$content = file_get_contents($file);
|
||||
return $content;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available or not (for the given id)
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return bool
|
||||
*/
|
||||
public function test($id)
|
||||
{
|
||||
$id = $this->_decodeId($id);
|
||||
if (!$this->_verifyPath($id)) {
|
||||
Zend_Cache::throwException('Invalid cache id: does not match expected public_dir path');
|
||||
}
|
||||
|
||||
$fileName = basename($id);
|
||||
if ($fileName === '') {
|
||||
$fileName = $this->_options['index_filename'];
|
||||
}
|
||||
if ($this->_tagged === null && $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME)) {
|
||||
$this->_tagged = $tagged;
|
||||
} elseif (!$this->_tagged) {
|
||||
return false;
|
||||
}
|
||||
$pathName = $this->_options['public_dir'] . dirname($id);
|
||||
|
||||
// Switch extension if needed
|
||||
if (isset($this->_tagged[$id])) {
|
||||
$extension = $this->_tagged[$id]['extension'];
|
||||
} else {
|
||||
$extension = $this->_options['file_extension'];
|
||||
}
|
||||
$file = $pathName . '/' . $fileName . $extension;
|
||||
if (file_exists($file)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save some string datas into a cache record
|
||||
*
|
||||
* Note : $data is always "string" (serialization is done by the
|
||||
* core not by the backend)
|
||||
*
|
||||
* @param string $data Datas to cache
|
||||
* @param string $id Cache id
|
||||
* @param array $tags Array of strings, the cache record will be tagged by each string entry
|
||||
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function save($data, $id, $tags = array(), $specificLifetime = false)
|
||||
{
|
||||
if ($this->_options['disable_caching']) {
|
||||
return true;
|
||||
}
|
||||
$extension = null;
|
||||
if ($this->_isSerialized($data)) {
|
||||
$data = unserialize($data);
|
||||
$extension = '.' . ltrim($data[1], '.');
|
||||
$data = $data[0];
|
||||
}
|
||||
|
||||
clearstatcache();
|
||||
if (($id = (string)$id) === '') {
|
||||
$id = $this->_detectId();
|
||||
} else {
|
||||
$id = $this->_decodeId($id);
|
||||
}
|
||||
|
||||
$fileName = basename($id);
|
||||
if ($fileName === '') {
|
||||
$fileName = $this->_options['index_filename'];
|
||||
}
|
||||
|
||||
$pathName = realpath($this->_options['public_dir']) . dirname($id);
|
||||
$this->_createDirectoriesFor($pathName);
|
||||
|
||||
if ($id === null || strlen($id) == 0) {
|
||||
$dataUnserialized = unserialize($data);
|
||||
$data = $dataUnserialized['data'];
|
||||
}
|
||||
$ext = $this->_options['file_extension'];
|
||||
if ($extension) $ext = $extension;
|
||||
$file = rtrim($pathName, '/') . '/' . $fileName . $ext;
|
||||
if ($this->_options['file_locking']) {
|
||||
$result = file_put_contents($file, $data, LOCK_EX);
|
||||
} else {
|
||||
$result = file_put_contents($file, $data);
|
||||
}
|
||||
@chmod($file, $this->_octdec($this->_options['cache_file_umask']));
|
||||
|
||||
if ($this->_tagged === null && $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME)) {
|
||||
$this->_tagged = $tagged;
|
||||
} elseif ($this->_tagged === null) {
|
||||
$this->_tagged = array();
|
||||
}
|
||||
if (!isset($this->_tagged[$id])) {
|
||||
$this->_tagged[$id] = array();
|
||||
}
|
||||
if (!isset($this->_tagged[$id]['tags'])) {
|
||||
$this->_tagged[$id]['tags'] = array();
|
||||
}
|
||||
$this->_tagged[$id]['tags'] = array_unique(array_merge($this->_tagged[$id]['tags'], $tags));
|
||||
$this->_tagged[$id]['extension'] = $ext;
|
||||
$this->getInnerCache()->save($this->_tagged, self::INNER_CACHE_NAME);
|
||||
return (bool) $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively create the directories needed to write the static file
|
||||
*/
|
||||
protected function _createDirectoriesFor($path)
|
||||
{
|
||||
if (!is_dir($path)) {
|
||||
$oldUmask = umask(0);
|
||||
if ( !@mkdir($path, $this->_octdec($this->_options['cache_directory_umask']), true)) {
|
||||
$lastErr = error_get_last();
|
||||
umask($oldUmask);
|
||||
Zend_Cache::throwException("Can't create directory: {$lastErr['message']}");
|
||||
}
|
||||
umask($oldUmask);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect serialization of data (cannot predict since this is the only way
|
||||
* to obey the interface yet pass in another parameter).
|
||||
*
|
||||
* In future, ZF 2.0, check if we can just avoid the interface restraints.
|
||||
*
|
||||
* This format is the only valid one possible for the class, so it's simple
|
||||
* to just run a regular expression for the starting serialized format.
|
||||
*/
|
||||
protected function _isSerialized($data)
|
||||
{
|
||||
return preg_match("/a:2:\{i:0;s:\d+:\"/", $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a cache record
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
public function remove($id)
|
||||
{
|
||||
if (!$this->_verifyPath($id)) {
|
||||
Zend_Cache::throwException('Invalid cache id: does not match expected public_dir path');
|
||||
}
|
||||
$fileName = basename($id);
|
||||
if ($this->_tagged === null && $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME)) {
|
||||
$this->_tagged = $tagged;
|
||||
} elseif (!$this->_tagged) {
|
||||
return false;
|
||||
}
|
||||
if (isset($this->_tagged[$id])) {
|
||||
$extension = $this->_tagged[$id]['extension'];
|
||||
} else {
|
||||
$extension = $this->_options['file_extension'];
|
||||
}
|
||||
if ($fileName === '') {
|
||||
$fileName = $this->_options['index_filename'];
|
||||
}
|
||||
$pathName = $this->_options['public_dir'] . dirname($id);
|
||||
$file = realpath($pathName) . '/' . $fileName . $extension;
|
||||
if (!file_exists($file)) {
|
||||
return false;
|
||||
}
|
||||
return unlink($file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a cache record recursively for the given directory matching a
|
||||
* REQUEST_URI based relative path (deletes the actual file matching this
|
||||
* in addition to the matching directory)
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
public function removeRecursively($id)
|
||||
{
|
||||
if (!$this->_verifyPath($id)) {
|
||||
Zend_Cache::throwException('Invalid cache id: does not match expected public_dir path');
|
||||
}
|
||||
$fileName = basename($id);
|
||||
if ($fileName === '') {
|
||||
$fileName = $this->_options['index_filename'];
|
||||
}
|
||||
$pathName = $this->_options['public_dir'] . dirname($id);
|
||||
$file = $pathName . '/' . $fileName . $this->_options['file_extension'];
|
||||
$directory = $pathName . '/' . $fileName;
|
||||
if (file_exists($directory)) {
|
||||
if (!is_writable($directory)) {
|
||||
return false;
|
||||
}
|
||||
if (is_dir($directory)) {
|
||||
foreach (new DirectoryIterator($directory) as $file) {
|
||||
if (true === $file->isFile()) {
|
||||
if (false === unlink($file->getPathName())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
rmdir($directory);
|
||||
}
|
||||
if (file_exists($file)) {
|
||||
if (!is_writable($file)) {
|
||||
return false;
|
||||
}
|
||||
return unlink($file);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean some cache records
|
||||
*
|
||||
* Available modes are :
|
||||
* Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used)
|
||||
* Zend_Cache::CLEANING_MODE_OLD => remove too old cache entries ($tags is not used)
|
||||
* Zend_Cache::CLEANING_MODE_MATCHING_TAG => remove cache entries matching all given tags
|
||||
* ($tags can be an array of strings or a single string)
|
||||
* Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => remove cache entries not {matching one of the given tags}
|
||||
* ($tags can be an array of strings or a single string)
|
||||
* Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG => remove cache entries matching any given tags
|
||||
* ($tags can be an array of strings or a single string)
|
||||
*
|
||||
* @param string $mode Clean mode
|
||||
* @param array $tags Array of tags
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
||||
{
|
||||
$result = false;
|
||||
switch ($mode) {
|
||||
case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
|
||||
case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
|
||||
if (empty($tags)) {
|
||||
throw new Zend_Exception('Cannot use tag matching modes as no tags were defined');
|
||||
}
|
||||
if ($this->_tagged === null && $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME)) {
|
||||
$this->_tagged = $tagged;
|
||||
} elseif (!$this->_tagged) {
|
||||
return true;
|
||||
}
|
||||
foreach ($tags as $tag) {
|
||||
$urls = array_keys($this->_tagged);
|
||||
foreach ($urls as $url) {
|
||||
if (isset($this->_tagged[$url]['tags']) && in_array($tag, $this->_tagged[$url]['tags'])) {
|
||||
$this->remove($url);
|
||||
unset($this->_tagged[$url]);
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->getInnerCache()->save($this->_tagged, self::INNER_CACHE_NAME);
|
||||
$result = true;
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_ALL:
|
||||
if ($this->_tagged === null) {
|
||||
$tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME);
|
||||
$this->_tagged = $tagged;
|
||||
}
|
||||
if ($this->_tagged === null || empty($this->_tagged)) {
|
||||
return true;
|
||||
}
|
||||
$urls = array_keys($this->_tagged);
|
||||
foreach ($urls as $url) {
|
||||
$this->remove($url);
|
||||
unset($this->_tagged[$url]);
|
||||
}
|
||||
$this->getInnerCache()->save($this->_tagged, self::INNER_CACHE_NAME);
|
||||
$result = true;
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_OLD:
|
||||
$this->_log("Zend_Cache_Backend_Static : Selected Cleaning Mode Currently Unsupported By This Backend");
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
|
||||
if (empty($tags)) {
|
||||
throw new Zend_Exception('Cannot use tag matching modes as no tags were defined');
|
||||
}
|
||||
if ($this->_tagged === null) {
|
||||
$tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME);
|
||||
$this->_tagged = $tagged;
|
||||
}
|
||||
if ($this->_tagged === null || empty($this->_tagged)) {
|
||||
return true;
|
||||
}
|
||||
$urls = array_keys($this->_tagged);
|
||||
foreach ($urls as $url) {
|
||||
$difference = array_diff($tags, $this->_tagged[$url]['tags']);
|
||||
if (count($tags) == count($difference)) {
|
||||
$this->remove($url);
|
||||
unset($this->_tagged[$url]);
|
||||
}
|
||||
}
|
||||
$this->getInnerCache()->save($this->_tagged, self::INNER_CACHE_NAME);
|
||||
$result = true;
|
||||
break;
|
||||
default:
|
||||
Zend_Cache::throwException('Invalid mode for clean() method');
|
||||
break;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an Inner Cache, used here primarily to store Tags associated
|
||||
* with caches created by this backend. Note: If Tags are lost, the cache
|
||||
* should be completely cleaned as the mapping of tags to caches will
|
||||
* have been irrevocably lost.
|
||||
*
|
||||
* @param Zend_Cache_Core
|
||||
* @return void
|
||||
*/
|
||||
public function setInnerCache(Zend_Cache_Core $cache)
|
||||
{
|
||||
$this->_tagCache = $cache;
|
||||
$this->_options['tag_cache'] = $cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Inner Cache if set
|
||||
*
|
||||
* @return Zend_Cache_Core
|
||||
*/
|
||||
public function getInnerCache()
|
||||
{
|
||||
if ($this->_tagCache === null) {
|
||||
Zend_Cache::throwException('An Inner Cache has not been set; use setInnerCache()');
|
||||
}
|
||||
return $this->_tagCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify path exists and is non-empty
|
||||
*
|
||||
* @param string $path
|
||||
* @return bool
|
||||
*/
|
||||
protected function _verifyPath($path)
|
||||
{
|
||||
$path = realpath($path);
|
||||
$base = realpath($this->_options['public_dir']);
|
||||
return strncmp($path, $base, strlen($base)) !== 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the page to save from the request
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _detectId()
|
||||
{
|
||||
return $_SERVER['REQUEST_URI'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate a cache id or a tag (security, reliable filenames, reserved prefixes...)
|
||||
*
|
||||
* Throw an exception if a problem is found
|
||||
*
|
||||
* @param string $string Cache id or tag
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
* @deprecated Not usable until perhaps ZF 2.0
|
||||
*/
|
||||
protected static function _validateIdOrTag($string)
|
||||
{
|
||||
if (!is_string($string)) {
|
||||
Zend_Cache::throwException('Invalid id or tag : must be a string');
|
||||
}
|
||||
|
||||
// Internal only checked in Frontend - not here!
|
||||
if (substr($string, 0, 9) == 'internal-') {
|
||||
return;
|
||||
}
|
||||
|
||||
// Validation assumes no query string, fragments or scheme included - only the path
|
||||
if (!preg_match(
|
||||
'/^(?:\/(?:(?:%[[:xdigit:]]{2}|[A-Za-z0-9-_.!~*\'()\[\]:@&=+$,;])*)?)+$/',
|
||||
$string
|
||||
)
|
||||
) {
|
||||
Zend_Cache::throwException("Invalid id or tag '$string' : must be a valid URL path");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect an octal string and return its octal value for file permission ops
|
||||
* otherwise return the non-string (assumed octal or decimal int already)
|
||||
*
|
||||
* @param string $val The potential octal in need of conversion
|
||||
* @return int
|
||||
*/
|
||||
protected function _octdec($val)
|
||||
{
|
||||
if (is_string($val) && decoct(octdec($val)) == $val) {
|
||||
return octdec($val);
|
||||
}
|
||||
return $val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode a request URI from the provided ID
|
||||
*
|
||||
* @param string $id
|
||||
* @return string
|
||||
*/
|
||||
protected function _decodeId($id)
|
||||
{
|
||||
return pack('H*', $id);
|
||||
}
|
||||
}
|
||||
413
www/analytics/libs/Zend/Cache/Backend/Test.php
Normal file
413
www/analytics/libs/Zend/Cache/Backend/Test.php
Normal file
|
|
@ -0,0 +1,413 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Test.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend_Interface
|
||||
*/
|
||||
// require_once 'Zend/Cache/Backend/ExtendedInterface.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend
|
||||
*/
|
||||
// require_once 'Zend/Cache/Backend.php';
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Cache_Backend_Test extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface
|
||||
{
|
||||
/**
|
||||
* Available options
|
||||
*
|
||||
* @var array available options
|
||||
*/
|
||||
protected $_options = array();
|
||||
|
||||
/**
|
||||
* Frontend or Core directives
|
||||
*
|
||||
* @var array directives
|
||||
*/
|
||||
protected $_directives = array();
|
||||
|
||||
/**
|
||||
* Array to log actions
|
||||
*
|
||||
* @var array $_log
|
||||
*/
|
||||
private $_log = array();
|
||||
|
||||
/**
|
||||
* Current index for log array
|
||||
*
|
||||
* @var int $_index
|
||||
*/
|
||||
private $_index = 0;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options associative array of options
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($options = array())
|
||||
{
|
||||
$this->_addLog('construct', array($options));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the frontend directives
|
||||
*
|
||||
* @param array $directives assoc of directives
|
||||
* @return void
|
||||
*/
|
||||
public function setDirectives($directives)
|
||||
{
|
||||
$this->_addLog('setDirectives', array($directives));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available for the given id and (if yes) return it (false else)
|
||||
*
|
||||
* For this test backend only, if $id == 'false', then the method will return false
|
||||
* if $id == 'serialized', the method will return a serialized array
|
||||
* ('foo' else)
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
|
||||
* @return string Cached datas (or false)
|
||||
*/
|
||||
public function load($id, $doNotTestCacheValidity = false)
|
||||
{
|
||||
$this->_addLog('get', array($id, $doNotTestCacheValidity));
|
||||
|
||||
if ( $id == 'false'
|
||||
|| $id == 'd8523b3ee441006261eeffa5c3d3a0a7'
|
||||
|| $id == 'e83249ea22178277d5befc2c5e2e9ace'
|
||||
|| $id == '40f649b94977c0a6e76902e2a0b43587'
|
||||
|| $id == '88161989b73a4cbfd0b701c446115a99'
|
||||
|| $id == '205fc79cba24f0f0018eb92c7c8b3ba4'
|
||||
|| $id == '170720e35f38150b811f68a937fb042d')
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ($id=='serialized') {
|
||||
return serialize(array('foo'));
|
||||
}
|
||||
if ($id=='serialized2') {
|
||||
return serialize(array('headers' => array(), 'data' => 'foo'));
|
||||
}
|
||||
if ( $id == '71769f39054f75894288e397df04e445' || $id == '615d222619fb20b527168340cebd0578'
|
||||
|| $id == '8a02d218a5165c467e7a5747cc6bd4b6' || $id == '648aca1366211d17cbf48e65dc570bee'
|
||||
|| $id == '4a923ef02d7f997ca14d56dfeae25ea7') {
|
||||
return serialize(array('foo', 'bar'));
|
||||
}
|
||||
return 'foo';
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available or not (for the given id)
|
||||
*
|
||||
* For this test backend only, if $id == 'false', then the method will return false
|
||||
* (123456 else)
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @return mixed|false false (a cache is not available) or "last modified" timestamp (int) of the available cache record
|
||||
*/
|
||||
public function test($id)
|
||||
{
|
||||
$this->_addLog('test', array($id));
|
||||
if ($id=='false') {
|
||||
return false;
|
||||
}
|
||||
if (($id=='3c439c922209e2cb0b54d6deffccd75a')) {
|
||||
return false;
|
||||
}
|
||||
return 123456;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save some string datas into a cache record
|
||||
*
|
||||
* For this test backend only, if $id == 'false', then the method will return false
|
||||
* (true else)
|
||||
*
|
||||
* @param string $data Datas to cache
|
||||
* @param string $id Cache id
|
||||
* @param array $tags Array of strings, the cache record will be tagged by each string entry
|
||||
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
public function save($data, $id, $tags = array(), $specificLifetime = false)
|
||||
{
|
||||
$this->_addLog('save', array($data, $id, $tags));
|
||||
if (substr($id,-5)=='false') {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a cache record
|
||||
*
|
||||
* For this test backend only, if $id == 'false', then the method will return false
|
||||
* (true else)
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
public function remove($id)
|
||||
{
|
||||
$this->_addLog('remove', array($id));
|
||||
if (substr($id,-5)=='false') {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean some cache records
|
||||
*
|
||||
* For this test backend only, if $mode == 'false', then the method will return false
|
||||
* (true else)
|
||||
*
|
||||
* Available modes are :
|
||||
* Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used)
|
||||
* Zend_Cache::CLEANING_MODE_OLD => remove too old cache entries ($tags is not used)
|
||||
* Zend_Cache::CLEANING_MODE_MATCHING_TAG => remove cache entries matching all given tags
|
||||
* ($tags can be an array of strings or a single string)
|
||||
* Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => remove cache entries not {matching one of the given tags}
|
||||
* ($tags can be an array of strings or a single string)
|
||||
*
|
||||
* @param string $mode Clean mode
|
||||
* @param array $tags Array of tags
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
||||
{
|
||||
$this->_addLog('clean', array($mode, $tags));
|
||||
if ($mode=='false') {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last log
|
||||
*
|
||||
* @return string The last log
|
||||
*/
|
||||
public function getLastLog()
|
||||
{
|
||||
return $this->_log[$this->_index - 1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the log index
|
||||
*
|
||||
* @return int Log index
|
||||
*/
|
||||
public function getLogIndex()
|
||||
{
|
||||
return $this->_index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the complete log array
|
||||
*
|
||||
* @return array Complete log array
|
||||
*/
|
||||
public function getAllLogs()
|
||||
{
|
||||
return $this->_log;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the automatic cleaning is available for the backend
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isAutomaticCleaningAvailable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids
|
||||
*
|
||||
* @return array array of stored cache ids (string)
|
||||
*/
|
||||
public function getIds()
|
||||
{
|
||||
return array(
|
||||
'prefix_id1', 'prefix_id2'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored tags
|
||||
*
|
||||
* @return array array of stored tags (string)
|
||||
*/
|
||||
public function getTags()
|
||||
{
|
||||
return array(
|
||||
'tag1', 'tag2'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which match given tags
|
||||
*
|
||||
* In case of multiple tags, a logical AND is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of matching cache ids (string)
|
||||
*/
|
||||
public function getIdsMatchingTags($tags = array())
|
||||
{
|
||||
if ($tags == array('tag1', 'tag2')) {
|
||||
return array('prefix_id1', 'prefix_id2');
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which don't match given tags
|
||||
*
|
||||
* In case of multiple tags, a logical OR is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of not matching cache ids (string)
|
||||
*/
|
||||
public function getIdsNotMatchingTags($tags = array())
|
||||
{
|
||||
if ($tags == array('tag3', 'tag4')) {
|
||||
return array('prefix_id3', 'prefix_id4');
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which match any given tags
|
||||
*
|
||||
* In case of multiple tags, a logical AND is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of any matching cache ids (string)
|
||||
*/
|
||||
public function getIdsMatchingAnyTags($tags = array())
|
||||
{
|
||||
if ($tags == array('tag5', 'tag6')) {
|
||||
return array('prefix_id5', 'prefix_id6');
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the filling percentage of the backend storage
|
||||
*
|
||||
* @return int integer between 0 and 100
|
||||
*/
|
||||
public function getFillingPercentage()
|
||||
{
|
||||
return 50;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of metadatas for the given cache id
|
||||
*
|
||||
* The array must include these keys :
|
||||
* - expire : the expire timestamp
|
||||
* - tags : a string array of tags
|
||||
* - mtime : timestamp of last modification time
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return array array of metadatas (false if the cache id is not found)
|
||||
*/
|
||||
public function getMetadatas($id)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Give (if possible) an extra lifetime to the given cache id
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @param int $extraLifetime
|
||||
* @return boolean true if ok
|
||||
*/
|
||||
public function touch($id, $extraLifetime)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an associative array of capabilities (booleans) of the backend
|
||||
*
|
||||
* The array must include these keys :
|
||||
* - automatic_cleaning (is automating cleaning necessary)
|
||||
* - tags (are tags supported)
|
||||
* - expired_read (is it possible to read expired cache records
|
||||
* (for doNotTestCacheValidity option for example))
|
||||
* - priority does the backend deal with priority when saving
|
||||
* - infinite_lifetime (is infinite lifetime can work with this backend)
|
||||
* - get_list (is it possible to get the list of cache ids and the complete list of tags)
|
||||
*
|
||||
* @return array associative of with capabilities
|
||||
*/
|
||||
public function getCapabilities()
|
||||
{
|
||||
return array(
|
||||
'automatic_cleaning' => true,
|
||||
'tags' => true,
|
||||
'expired_read' => false,
|
||||
'priority' => true,
|
||||
'infinite_lifetime' => true,
|
||||
'get_list' => true
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an event to the log array
|
||||
*
|
||||
* @param string $methodName MethodName
|
||||
* @param array $args Arguments
|
||||
* @return void
|
||||
*/
|
||||
private function _addLog($methodName, $args)
|
||||
{
|
||||
$this->_log[$this->_index] = array(
|
||||
'methodName' => $methodName,
|
||||
'args' => $args
|
||||
);
|
||||
$this->_index = $this->_index + 1;
|
||||
}
|
||||
|
||||
}
|
||||
536
www/analytics/libs/Zend/Cache/Backend/TwoLevels.php
Normal file
536
www/analytics/libs/Zend/Cache/Backend/TwoLevels.php
Normal file
|
|
@ -0,0 +1,536 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: TwoLevels.php 24254 2011-07-22 12:04:41Z mabe $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend_ExtendedInterface
|
||||
*/
|
||||
// require_once 'Zend/Cache/Backend/ExtendedInterface.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend
|
||||
*/
|
||||
// require_once 'Zend/Cache/Backend.php';
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
class Zend_Cache_Backend_TwoLevels extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface
|
||||
{
|
||||
/**
|
||||
* Available options
|
||||
*
|
||||
* =====> (string) slow_backend :
|
||||
* - Slow backend name
|
||||
* - Must implement the Zend_Cache_Backend_ExtendedInterface
|
||||
* - Should provide a big storage
|
||||
*
|
||||
* =====> (string) fast_backend :
|
||||
* - Flow backend name
|
||||
* - Must implement the Zend_Cache_Backend_ExtendedInterface
|
||||
* - Must be much faster than slow_backend
|
||||
*
|
||||
* =====> (array) slow_backend_options :
|
||||
* - Slow backend options (see corresponding backend)
|
||||
*
|
||||
* =====> (array) fast_backend_options :
|
||||
* - Fast backend options (see corresponding backend)
|
||||
*
|
||||
* =====> (int) stats_update_factor :
|
||||
* - Disable / Tune the computation of the fast backend filling percentage
|
||||
* - When saving a record into cache :
|
||||
* 1 => systematic computation of the fast backend filling percentage
|
||||
* x (integer) > 1 => computation of the fast backend filling percentage randomly 1 times on x cache write
|
||||
*
|
||||
* =====> (boolean) slow_backend_custom_naming :
|
||||
* =====> (boolean) fast_backend_custom_naming :
|
||||
* =====> (boolean) slow_backend_autoload :
|
||||
* =====> (boolean) fast_backend_autoload :
|
||||
* - See Zend_Cache::factory() method
|
||||
*
|
||||
* =====> (boolean) auto_refresh_fast_cache
|
||||
* - If true, auto refresh the fast cache when a cache record is hit
|
||||
*
|
||||
* @var array available options
|
||||
*/
|
||||
protected $_options = array(
|
||||
'slow_backend' => 'File',
|
||||
'fast_backend' => 'Apc',
|
||||
'slow_backend_options' => array(),
|
||||
'fast_backend_options' => array(),
|
||||
'stats_update_factor' => 10,
|
||||
'slow_backend_custom_naming' => false,
|
||||
'fast_backend_custom_naming' => false,
|
||||
'slow_backend_autoload' => false,
|
||||
'fast_backend_autoload' => false,
|
||||
'auto_refresh_fast_cache' => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Slow Backend
|
||||
*
|
||||
* @var Zend_Cache_Backend_ExtendedInterface
|
||||
*/
|
||||
protected $_slowBackend;
|
||||
|
||||
/**
|
||||
* Fast Backend
|
||||
*
|
||||
* @var Zend_Cache_Backend_ExtendedInterface
|
||||
*/
|
||||
protected $_fastBackend;
|
||||
|
||||
/**
|
||||
* Cache for the fast backend filling percentage
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_fastBackendFillingPercentage = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options Associative array of options
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $options = array())
|
||||
{
|
||||
parent::__construct($options);
|
||||
|
||||
if ($this->_options['slow_backend'] === null) {
|
||||
Zend_Cache::throwException('slow_backend option has to set');
|
||||
} elseif ($this->_options['slow_backend'] instanceof Zend_Cache_Backend_ExtendedInterface) {
|
||||
$this->_slowBackend = $this->_options['slow_backend'];
|
||||
} else {
|
||||
$this->_slowBackend = Zend_Cache::_makeBackend(
|
||||
$this->_options['slow_backend'],
|
||||
$this->_options['slow_backend_options'],
|
||||
$this->_options['slow_backend_custom_naming'],
|
||||
$this->_options['slow_backend_autoload']
|
||||
);
|
||||
if (!in_array('Zend_Cache_Backend_ExtendedInterface', class_implements($this->_slowBackend))) {
|
||||
Zend_Cache::throwException('slow_backend must implement the Zend_Cache_Backend_ExtendedInterface interface');
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->_options['fast_backend'] === null) {
|
||||
Zend_Cache::throwException('fast_backend option has to set');
|
||||
} elseif ($this->_options['fast_backend'] instanceof Zend_Cache_Backend_ExtendedInterface) {
|
||||
$this->_fastBackend = $this->_options['fast_backend'];
|
||||
} else {
|
||||
$this->_fastBackend = Zend_Cache::_makeBackend(
|
||||
$this->_options['fast_backend'],
|
||||
$this->_options['fast_backend_options'],
|
||||
$this->_options['fast_backend_custom_naming'],
|
||||
$this->_options['fast_backend_autoload']
|
||||
);
|
||||
if (!in_array('Zend_Cache_Backend_ExtendedInterface', class_implements($this->_fastBackend))) {
|
||||
Zend_Cache::throwException('fast_backend must implement the Zend_Cache_Backend_ExtendedInterface interface');
|
||||
}
|
||||
}
|
||||
|
||||
$this->_slowBackend->setDirectives($this->_directives);
|
||||
$this->_fastBackend->setDirectives($this->_directives);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available or not (for the given id)
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return mixed|false (a cache is not available) or "last modified" timestamp (int) of the available cache record
|
||||
*/
|
||||
public function test($id)
|
||||
{
|
||||
$fastTest = $this->_fastBackend->test($id);
|
||||
if ($fastTest) {
|
||||
return $fastTest;
|
||||
} else {
|
||||
return $this->_slowBackend->test($id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save some string datas into a cache record
|
||||
*
|
||||
* Note : $data is always "string" (serialization is done by the
|
||||
* core not by the backend)
|
||||
*
|
||||
* @param string $data Datas to cache
|
||||
* @param string $id Cache id
|
||||
* @param array $tags Array of strings, the cache record will be tagged by each string entry
|
||||
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||
* @param int $priority integer between 0 (very low priority) and 10 (maximum priority) used by some particular backends
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function save($data, $id, $tags = array(), $specificLifetime = false, $priority = 8)
|
||||
{
|
||||
$usage = $this->_getFastFillingPercentage('saving');
|
||||
$boolFast = true;
|
||||
$lifetime = $this->getLifetime($specificLifetime);
|
||||
$preparedData = $this->_prepareData($data, $lifetime, $priority);
|
||||
if (($priority > 0) && (10 * $priority >= $usage)) {
|
||||
$fastLifetime = $this->_getFastLifetime($lifetime, $priority);
|
||||
$boolFast = $this->_fastBackend->save($preparedData, $id, array(), $fastLifetime);
|
||||
$boolSlow = $this->_slowBackend->save($preparedData, $id, $tags, $lifetime);
|
||||
} else {
|
||||
$boolSlow = $this->_slowBackend->save($preparedData, $id, $tags, $lifetime);
|
||||
if ($boolSlow === true) {
|
||||
$boolFast = $this->_fastBackend->remove($id);
|
||||
if (!$boolFast && !$this->_fastBackend->test($id)) {
|
||||
// some backends return false on remove() even if the key never existed. (and it won't if fast is full)
|
||||
// all we care about is that the key doesn't exist now
|
||||
$boolFast = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ($boolFast && $boolSlow);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available for the given id and (if yes) return it (false else)
|
||||
*
|
||||
* Note : return value is always "string" (unserialization is done by the core not by the backend)
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
|
||||
* @return string|false cached datas
|
||||
*/
|
||||
public function load($id, $doNotTestCacheValidity = false)
|
||||
{
|
||||
$res = $this->_fastBackend->load($id, $doNotTestCacheValidity);
|
||||
if ($res === false) {
|
||||
$res = $this->_slowBackend->load($id, $doNotTestCacheValidity);
|
||||
if ($res === false) {
|
||||
// there is no cache at all for this id
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$array = unserialize($res);
|
||||
// maybe, we have to refresh the fast cache ?
|
||||
if ($this->_options['auto_refresh_fast_cache']) {
|
||||
if ($array['priority'] == 10) {
|
||||
// no need to refresh the fast cache with priority = 10
|
||||
return $array['data'];
|
||||
}
|
||||
$newFastLifetime = $this->_getFastLifetime($array['lifetime'], $array['priority'], time() - $array['expire']);
|
||||
// we have the time to refresh the fast cache
|
||||
$usage = $this->_getFastFillingPercentage('loading');
|
||||
if (($array['priority'] > 0) && (10 * $array['priority'] >= $usage)) {
|
||||
// we can refresh the fast cache
|
||||
$preparedData = $this->_prepareData($array['data'], $array['lifetime'], $array['priority']);
|
||||
$this->_fastBackend->save($preparedData, $id, array(), $newFastLifetime);
|
||||
}
|
||||
}
|
||||
return $array['data'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a cache record
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
public function remove($id)
|
||||
{
|
||||
$boolFast = $this->_fastBackend->remove($id);
|
||||
$boolSlow = $this->_slowBackend->remove($id);
|
||||
return $boolFast && $boolSlow;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean some cache records
|
||||
*
|
||||
* Available modes are :
|
||||
* Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used)
|
||||
* Zend_Cache::CLEANING_MODE_OLD => remove too old cache entries ($tags is not used)
|
||||
* Zend_Cache::CLEANING_MODE_MATCHING_TAG => remove cache entries matching all given tags
|
||||
* ($tags can be an array of strings or a single string)
|
||||
* Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => remove cache entries not {matching one of the given tags}
|
||||
* ($tags can be an array of strings or a single string)
|
||||
* Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG => remove cache entries matching any given tags
|
||||
* ($tags can be an array of strings or a single string)
|
||||
*
|
||||
* @param string $mode Clean mode
|
||||
* @param array $tags Array of tags
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
||||
{
|
||||
switch($mode) {
|
||||
case Zend_Cache::CLEANING_MODE_ALL:
|
||||
$boolFast = $this->_fastBackend->clean(Zend_Cache::CLEANING_MODE_ALL);
|
||||
$boolSlow = $this->_slowBackend->clean(Zend_Cache::CLEANING_MODE_ALL);
|
||||
return $boolFast && $boolSlow;
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_OLD:
|
||||
return $this->_slowBackend->clean(Zend_Cache::CLEANING_MODE_OLD);
|
||||
case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
|
||||
$ids = $this->_slowBackend->getIdsMatchingTags($tags);
|
||||
$res = true;
|
||||
foreach ($ids as $id) {
|
||||
$bool = $this->remove($id);
|
||||
$res = $res && $bool;
|
||||
}
|
||||
return $res;
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
|
||||
$ids = $this->_slowBackend->getIdsNotMatchingTags($tags);
|
||||
$res = true;
|
||||
foreach ($ids as $id) {
|
||||
$bool = $this->remove($id);
|
||||
$res = $res && $bool;
|
||||
}
|
||||
return $res;
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
|
||||
$ids = $this->_slowBackend->getIdsMatchingAnyTags($tags);
|
||||
$res = true;
|
||||
foreach ($ids as $id) {
|
||||
$bool = $this->remove($id);
|
||||
$res = $res && $bool;
|
||||
}
|
||||
return $res;
|
||||
break;
|
||||
default:
|
||||
Zend_Cache::throwException('Invalid mode for clean() method');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids
|
||||
*
|
||||
* @return array array of stored cache ids (string)
|
||||
*/
|
||||
public function getIds()
|
||||
{
|
||||
return $this->_slowBackend->getIds();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored tags
|
||||
*
|
||||
* @return array array of stored tags (string)
|
||||
*/
|
||||
public function getTags()
|
||||
{
|
||||
return $this->_slowBackend->getTags();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which match given tags
|
||||
*
|
||||
* In case of multiple tags, a logical AND is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of matching cache ids (string)
|
||||
*/
|
||||
public function getIdsMatchingTags($tags = array())
|
||||
{
|
||||
return $this->_slowBackend->getIdsMatchingTags($tags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which don't match given tags
|
||||
*
|
||||
* In case of multiple tags, a logical OR is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of not matching cache ids (string)
|
||||
*/
|
||||
public function getIdsNotMatchingTags($tags = array())
|
||||
{
|
||||
return $this->_slowBackend->getIdsNotMatchingTags($tags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which match any given tags
|
||||
*
|
||||
* In case of multiple tags, a logical AND is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of any matching cache ids (string)
|
||||
*/
|
||||
public function getIdsMatchingAnyTags($tags = array())
|
||||
{
|
||||
return $this->_slowBackend->getIdsMatchingAnyTags($tags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the filling percentage of the backend storage
|
||||
*
|
||||
* @return int integer between 0 and 100
|
||||
*/
|
||||
public function getFillingPercentage()
|
||||
{
|
||||
return $this->_slowBackend->getFillingPercentage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of metadatas for the given cache id
|
||||
*
|
||||
* The array must include these keys :
|
||||
* - expire : the expire timestamp
|
||||
* - tags : a string array of tags
|
||||
* - mtime : timestamp of last modification time
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return array array of metadatas (false if the cache id is not found)
|
||||
*/
|
||||
public function getMetadatas($id)
|
||||
{
|
||||
return $this->_slowBackend->getMetadatas($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Give (if possible) an extra lifetime to the given cache id
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @param int $extraLifetime
|
||||
* @return boolean true if ok
|
||||
*/
|
||||
public function touch($id, $extraLifetime)
|
||||
{
|
||||
return $this->_slowBackend->touch($id, $extraLifetime);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an associative array of capabilities (booleans) of the backend
|
||||
*
|
||||
* The array must include these keys :
|
||||
* - automatic_cleaning (is automating cleaning necessary)
|
||||
* - tags (are tags supported)
|
||||
* - expired_read (is it possible to read expired cache records
|
||||
* (for doNotTestCacheValidity option for example))
|
||||
* - priority does the backend deal with priority when saving
|
||||
* - infinite_lifetime (is infinite lifetime can work with this backend)
|
||||
* - get_list (is it possible to get the list of cache ids and the complete list of tags)
|
||||
*
|
||||
* @return array associative of with capabilities
|
||||
*/
|
||||
public function getCapabilities()
|
||||
{
|
||||
$slowBackendCapabilities = $this->_slowBackend->getCapabilities();
|
||||
return array(
|
||||
'automatic_cleaning' => $slowBackendCapabilities['automatic_cleaning'],
|
||||
'tags' => $slowBackendCapabilities['tags'],
|
||||
'expired_read' => $slowBackendCapabilities['expired_read'],
|
||||
'priority' => $slowBackendCapabilities['priority'],
|
||||
'infinite_lifetime' => $slowBackendCapabilities['infinite_lifetime'],
|
||||
'get_list' => $slowBackendCapabilities['get_list']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare a serialized array to store datas and metadatas informations
|
||||
*
|
||||
* @param string $data data to store
|
||||
* @param int $lifetime original lifetime
|
||||
* @param int $priority priority
|
||||
* @return string serialize array to store into cache
|
||||
*/
|
||||
private function _prepareData($data, $lifetime, $priority)
|
||||
{
|
||||
$lt = $lifetime;
|
||||
if ($lt === null) {
|
||||
$lt = 9999999999;
|
||||
}
|
||||
return serialize(array(
|
||||
'data' => $data,
|
||||
'lifetime' => $lifetime,
|
||||
'expire' => time() + $lt,
|
||||
'priority' => $priority
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute and return the lifetime for the fast backend
|
||||
*
|
||||
* @param int $lifetime original lifetime
|
||||
* @param int $priority priority
|
||||
* @param int $maxLifetime maximum lifetime
|
||||
* @return int lifetime for the fast backend
|
||||
*/
|
||||
private function _getFastLifetime($lifetime, $priority, $maxLifetime = null)
|
||||
{
|
||||
if ($lifetime <= 0) {
|
||||
// if no lifetime, we have an infinite lifetime
|
||||
// we need to use arbitrary lifetimes
|
||||
$fastLifetime = (int) (2592000 / (11 - $priority));
|
||||
} else {
|
||||
// prevent computed infinite lifetime (0) by ceil
|
||||
$fastLifetime = (int) ceil($lifetime / (11 - $priority));
|
||||
}
|
||||
|
||||
if ($maxLifetime >= 0 && $fastLifetime > $maxLifetime) {
|
||||
return $maxLifetime;
|
||||
}
|
||||
|
||||
return $fastLifetime;
|
||||
}
|
||||
|
||||
/**
|
||||
* PUBLIC METHOD FOR UNIT TESTING ONLY !
|
||||
*
|
||||
* Force a cache record to expire
|
||||
*
|
||||
* @param string $id cache id
|
||||
*/
|
||||
public function ___expire($id)
|
||||
{
|
||||
$this->_fastBackend->remove($id);
|
||||
$this->_slowBackend->___expire($id);
|
||||
}
|
||||
|
||||
private function _getFastFillingPercentage($mode)
|
||||
{
|
||||
|
||||
if ($mode == 'saving') {
|
||||
// mode saving
|
||||
if ($this->_fastBackendFillingPercentage === null) {
|
||||
$this->_fastBackendFillingPercentage = $this->_fastBackend->getFillingPercentage();
|
||||
} else {
|
||||
$rand = rand(1, $this->_options['stats_update_factor']);
|
||||
if ($rand == 1) {
|
||||
// we force a refresh
|
||||
$this->_fastBackendFillingPercentage = $this->_fastBackend->getFillingPercentage();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// mode loading
|
||||
// we compute the percentage only if it's not available in cache
|
||||
if ($this->_fastBackendFillingPercentage === null) {
|
||||
$this->_fastBackendFillingPercentage = $this->_fastBackend->getFillingPercentage();
|
||||
}
|
||||
}
|
||||
return $this->_fastBackendFillingPercentage;
|
||||
}
|
||||
|
||||
}
|
||||
349
www/analytics/libs/Zend/Cache/Backend/WinCache.php
Normal file
349
www/analytics/libs/Zend/Cache/Backend/WinCache.php
Normal file
|
|
@ -0,0 +1,349 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend_Interface
|
||||
*/
|
||||
// require_once 'Zend/Cache/Backend/ExtendedInterface.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend
|
||||
*/
|
||||
// require_once 'Zend/Cache/Backend.php';
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Cache_Backend_WinCache extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface
|
||||
{
|
||||
/**
|
||||
* Log message
|
||||
*/
|
||||
const TAGS_UNSUPPORTED_BY_CLEAN_OF_WINCACHE_BACKEND = 'Zend_Cache_Backend_WinCache::clean() : tags are unsupported by the WinCache backend';
|
||||
const TAGS_UNSUPPORTED_BY_SAVE_OF_WINCACHE_BACKEND = 'Zend_Cache_Backend_WinCache::save() : tags are unsupported by the WinCache backend';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options associative array of options
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $options = array())
|
||||
{
|
||||
if (!extension_loaded('wincache')) {
|
||||
Zend_Cache::throwException('The wincache extension must be loaded for using this backend !');
|
||||
}
|
||||
parent::__construct($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available for the given id and (if yes) return it (false else)
|
||||
*
|
||||
* WARNING $doNotTestCacheValidity=true is unsupported by the WinCache backend
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @param boolean $doNotTestCacheValidity if set to true, the cache validity won't be tested
|
||||
* @return string cached datas (or false)
|
||||
*/
|
||||
public function load($id, $doNotTestCacheValidity = false)
|
||||
{
|
||||
$tmp = wincache_ucache_get($id);
|
||||
if (is_array($tmp)) {
|
||||
return $tmp[0];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available or not (for the given id)
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record
|
||||
*/
|
||||
public function test($id)
|
||||
{
|
||||
$tmp = wincache_ucache_get($id);
|
||||
if (is_array($tmp)) {
|
||||
return $tmp[1];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save some string datas into a cache record
|
||||
*
|
||||
* Note : $data is always "string" (serialization is done by the
|
||||
* core not by the backend)
|
||||
*
|
||||
* @param string $data datas to cache
|
||||
* @param string $id cache id
|
||||
* @param array $tags array of strings, the cache record will be tagged by each string entry
|
||||
* @param int $specificLifetime if != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function save($data, $id, $tags = array(), $specificLifetime = false)
|
||||
{
|
||||
$lifetime = $this->getLifetime($specificLifetime);
|
||||
$result = wincache_ucache_set($id, array($data, time(), $lifetime), $lifetime);
|
||||
if (count($tags) > 0) {
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_WINCACHE_BACKEND);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a cache record
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function remove($id)
|
||||
{
|
||||
return wincache_ucache_delete($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean some cache records
|
||||
*
|
||||
* Available modes are :
|
||||
* 'all' (default) => remove all cache entries ($tags is not used)
|
||||
* 'old' => unsupported
|
||||
* 'matchingTag' => unsupported
|
||||
* 'notMatchingTag' => unsupported
|
||||
* 'matchingAnyTag' => unsupported
|
||||
*
|
||||
* @param string $mode clean mode
|
||||
* @param array $tags array of tags
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
||||
{
|
||||
switch ($mode) {
|
||||
case Zend_Cache::CLEANING_MODE_ALL:
|
||||
return wincache_ucache_clear();
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_OLD:
|
||||
$this->_log("Zend_Cache_Backend_WinCache::clean() : CLEANING_MODE_OLD is unsupported by the WinCache backend");
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
|
||||
case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
|
||||
case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_CLEAN_OF_WINCACHE_BACKEND);
|
||||
break;
|
||||
default:
|
||||
Zend_Cache::throwException('Invalid mode for clean() method');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the automatic cleaning is available for the backend
|
||||
*
|
||||
* DEPRECATED : use getCapabilities() instead
|
||||
*
|
||||
* @deprecated
|
||||
* @return boolean
|
||||
*/
|
||||
public function isAutomaticCleaningAvailable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the filling percentage of the backend storage
|
||||
*
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return int integer between 0 and 100
|
||||
*/
|
||||
public function getFillingPercentage()
|
||||
{
|
||||
$mem = wincache_ucache_meminfo();
|
||||
$memSize = $mem['memory_total'];
|
||||
$memUsed = $mem['memory_free'];
|
||||
if ($memSize == 0) {
|
||||
Zend_Cache::throwException('can\'t get WinCache memory size');
|
||||
}
|
||||
if ($memUsed > $memSize) {
|
||||
return 100;
|
||||
}
|
||||
return ((int) (100. * ($memUsed / $memSize)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored tags
|
||||
*
|
||||
* @return array array of stored tags (string)
|
||||
*/
|
||||
public function getTags()
|
||||
{
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_WINCACHE_BACKEND);
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which match given tags
|
||||
*
|
||||
* In case of multiple tags, a logical AND is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of matching cache ids (string)
|
||||
*/
|
||||
public function getIdsMatchingTags($tags = array())
|
||||
{
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_WINCACHE_BACKEND);
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which don't match given tags
|
||||
*
|
||||
* In case of multiple tags, a logical OR is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of not matching cache ids (string)
|
||||
*/
|
||||
public function getIdsNotMatchingTags($tags = array())
|
||||
{
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_WINCACHE_BACKEND);
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which match any given tags
|
||||
*
|
||||
* In case of multiple tags, a logical AND is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of any matching cache ids (string)
|
||||
*/
|
||||
public function getIdsMatchingAnyTags($tags = array())
|
||||
{
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_WINCACHE_BACKEND);
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids
|
||||
*
|
||||
* @return array array of stored cache ids (string)
|
||||
*/
|
||||
public function getIds()
|
||||
{
|
||||
$res = array();
|
||||
$array = wincache_ucache_info();
|
||||
$records = $array['ucache_entries'];
|
||||
foreach ($records as $record) {
|
||||
$res[] = $record['key_name'];
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of metadatas for the given cache id
|
||||
*
|
||||
* The array must include these keys :
|
||||
* - expire : the expire timestamp
|
||||
* - tags : a string array of tags
|
||||
* - mtime : timestamp of last modification time
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return array array of metadatas (false if the cache id is not found)
|
||||
*/
|
||||
public function getMetadatas($id)
|
||||
{
|
||||
$tmp = wincache_ucache_get($id);
|
||||
if (is_array($tmp)) {
|
||||
$data = $tmp[0];
|
||||
$mtime = $tmp[1];
|
||||
if (!isset($tmp[2])) {
|
||||
return false;
|
||||
}
|
||||
$lifetime = $tmp[2];
|
||||
return array(
|
||||
'expire' => $mtime + $lifetime,
|
||||
'tags' => array(),
|
||||
'mtime' => $mtime
|
||||
);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Give (if possible) an extra lifetime to the given cache id
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @param int $extraLifetime
|
||||
* @return boolean true if ok
|
||||
*/
|
||||
public function touch($id, $extraLifetime)
|
||||
{
|
||||
$tmp = wincache_ucache_get($id);
|
||||
if (is_array($tmp)) {
|
||||
$data = $tmp[0];
|
||||
$mtime = $tmp[1];
|
||||
if (!isset($tmp[2])) {
|
||||
return false;
|
||||
}
|
||||
$lifetime = $tmp[2];
|
||||
$newLifetime = $lifetime - (time() - $mtime) + $extraLifetime;
|
||||
if ($newLifetime <=0) {
|
||||
return false;
|
||||
}
|
||||
return wincache_ucache_set($id, array($data, time(), $newLifetime), $newLifetime);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an associative array of capabilities (booleans) of the backend
|
||||
*
|
||||
* The array must include these keys :
|
||||
* - automatic_cleaning (is automating cleaning necessary)
|
||||
* - tags (are tags supported)
|
||||
* - expired_read (is it possible to read expired cache records
|
||||
* (for doNotTestCacheValidity option for example))
|
||||
* - priority does the backend deal with priority when saving
|
||||
* - infinite_lifetime (is infinite lifetime can work with this backend)
|
||||
* - get_list (is it possible to get the list of cache ids and the complete list of tags)
|
||||
*
|
||||
* @return array associative of with capabilities
|
||||
*/
|
||||
public function getCapabilities()
|
||||
{
|
||||
return array(
|
||||
'automatic_cleaning' => false,
|
||||
'tags' => false,
|
||||
'expired_read' => false,
|
||||
'priority' => false,
|
||||
'infinite_lifetime' => false,
|
||||
'get_list' => true
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
221
www/analytics/libs/Zend/Cache/Backend/Xcache.php
Normal file
221
www/analytics/libs/Zend/Cache/Backend/Xcache.php
Normal file
|
|
@ -0,0 +1,221 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Xcache.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend_Interface
|
||||
*/
|
||||
// require_once 'Zend/Cache/Backend/Interface.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend
|
||||
*/
|
||||
// require_once 'Zend/Cache/Backend.php';
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Cache_Backend_Xcache extends Zend_Cache_Backend implements Zend_Cache_Backend_Interface
|
||||
{
|
||||
|
||||
/**
|
||||
* Log message
|
||||
*/
|
||||
const TAGS_UNSUPPORTED_BY_CLEAN_OF_XCACHE_BACKEND = 'Zend_Cache_Backend_Xcache::clean() : tags are unsupported by the Xcache backend';
|
||||
const TAGS_UNSUPPORTED_BY_SAVE_OF_XCACHE_BACKEND = 'Zend_Cache_Backend_Xcache::save() : tags are unsupported by the Xcache backend';
|
||||
|
||||
/**
|
||||
* Available options
|
||||
*
|
||||
* =====> (string) user :
|
||||
* xcache.admin.user (necessary for the clean() method)
|
||||
*
|
||||
* =====> (string) password :
|
||||
* xcache.admin.pass (clear, not MD5) (necessary for the clean() method)
|
||||
*
|
||||
* @var array available options
|
||||
*/
|
||||
protected $_options = array(
|
||||
'user' => null,
|
||||
'password' => null
|
||||
);
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options associative array of options
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $options = array())
|
||||
{
|
||||
if (!extension_loaded('xcache')) {
|
||||
Zend_Cache::throwException('The xcache extension must be loaded for using this backend !');
|
||||
}
|
||||
parent::__construct($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available for the given id and (if yes) return it (false else)
|
||||
*
|
||||
* WARNING $doNotTestCacheValidity=true is unsupported by the Xcache backend
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @param boolean $doNotTestCacheValidity if set to true, the cache validity won't be tested
|
||||
* @return string cached datas (or false)
|
||||
*/
|
||||
public function load($id, $doNotTestCacheValidity = false)
|
||||
{
|
||||
if ($doNotTestCacheValidity) {
|
||||
$this->_log("Zend_Cache_Backend_Xcache::load() : \$doNotTestCacheValidity=true is unsupported by the Xcache backend");
|
||||
}
|
||||
$tmp = xcache_get($id);
|
||||
if (is_array($tmp)) {
|
||||
return $tmp[0];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available or not (for the given id)
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record
|
||||
*/
|
||||
public function test($id)
|
||||
{
|
||||
if (xcache_isset($id)) {
|
||||
$tmp = xcache_get($id);
|
||||
if (is_array($tmp)) {
|
||||
return $tmp[1];
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save some string datas into a cache record
|
||||
*
|
||||
* Note : $data is always "string" (serialization is done by the
|
||||
* core not by the backend)
|
||||
*
|
||||
* @param string $data datas to cache
|
||||
* @param string $id cache id
|
||||
* @param array $tags array of strings, the cache record will be tagged by each string entry
|
||||
* @param int $specificLifetime if != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function save($data, $id, $tags = array(), $specificLifetime = false)
|
||||
{
|
||||
$lifetime = $this->getLifetime($specificLifetime);
|
||||
$result = xcache_set($id, array($data, time()), $lifetime);
|
||||
if (count($tags) > 0) {
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_XCACHE_BACKEND);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a cache record
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function remove($id)
|
||||
{
|
||||
return xcache_unset($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean some cache records
|
||||
*
|
||||
* Available modes are :
|
||||
* 'all' (default) => remove all cache entries ($tags is not used)
|
||||
* 'old' => unsupported
|
||||
* 'matchingTag' => unsupported
|
||||
* 'notMatchingTag' => unsupported
|
||||
* 'matchingAnyTag' => unsupported
|
||||
*
|
||||
* @param string $mode clean mode
|
||||
* @param array $tags array of tags
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
||||
{
|
||||
switch ($mode) {
|
||||
case Zend_Cache::CLEANING_MODE_ALL:
|
||||
// Necessary because xcache_clear_cache() need basic authentification
|
||||
$backup = array();
|
||||
if (isset($_SERVER['PHP_AUTH_USER'])) {
|
||||
$backup['PHP_AUTH_USER'] = $_SERVER['PHP_AUTH_USER'];
|
||||
}
|
||||
if (isset($_SERVER['PHP_AUTH_PW'])) {
|
||||
$backup['PHP_AUTH_PW'] = $_SERVER['PHP_AUTH_PW'];
|
||||
}
|
||||
if ($this->_options['user']) {
|
||||
$_SERVER['PHP_AUTH_USER'] = $this->_options['user'];
|
||||
}
|
||||
if ($this->_options['password']) {
|
||||
$_SERVER['PHP_AUTH_PW'] = $this->_options['password'];
|
||||
}
|
||||
|
||||
$cnt = xcache_count(XC_TYPE_VAR);
|
||||
for ($i=0; $i < $cnt; $i++) {
|
||||
xcache_clear_cache(XC_TYPE_VAR, $i);
|
||||
}
|
||||
|
||||
if (isset($backup['PHP_AUTH_USER'])) {
|
||||
$_SERVER['PHP_AUTH_USER'] = $backup['PHP_AUTH_USER'];
|
||||
$_SERVER['PHP_AUTH_PW'] = $backup['PHP_AUTH_PW'];
|
||||
}
|
||||
return true;
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_OLD:
|
||||
$this->_log("Zend_Cache_Backend_Xcache::clean() : CLEANING_MODE_OLD is unsupported by the Xcache backend");
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
|
||||
case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
|
||||
case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_CLEAN_OF_XCACHE_BACKEND);
|
||||
break;
|
||||
default:
|
||||
Zend_Cache::throwException('Invalid mode for clean() method');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the automatic cleaning is available for the backend
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isAutomaticCleaningAvailable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
317
www/analytics/libs/Zend/Cache/Backend/ZendPlatform.php
Normal file
317
www/analytics/libs/Zend/Cache/Backend/ZendPlatform.php
Normal file
|
|
@ -0,0 +1,317 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: ZendPlatform.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend_Interface
|
||||
*/
|
||||
// require_once 'Zend/Cache/Backend.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend_Interface
|
||||
*/
|
||||
// require_once 'Zend/Cache/Backend/Interface.php';
|
||||
|
||||
|
||||
/**
|
||||
* Impementation of Zend Cache Backend using the Zend Platform (Output Content Caching)
|
||||
*
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Cache_Backend_ZendPlatform extends Zend_Cache_Backend implements Zend_Cache_Backend_Interface
|
||||
{
|
||||
/**
|
||||
* internal ZP prefix
|
||||
*/
|
||||
const TAGS_PREFIX = "internal_ZPtag:";
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* Validate that the Zend Platform is loaded and licensed
|
||||
*
|
||||
* @param array $options Associative array of options
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $options = array())
|
||||
{
|
||||
if (!function_exists('accelerator_license_info')) {
|
||||
Zend_Cache::throwException('The Zend Platform extension must be loaded for using this backend !');
|
||||
}
|
||||
if (!function_exists('accelerator_get_configuration')) {
|
||||
$licenseInfo = accelerator_license_info();
|
||||
Zend_Cache::throwException('The Zend Platform extension is not loaded correctly: '.$licenseInfo['failure_reason']);
|
||||
}
|
||||
$accConf = accelerator_get_configuration();
|
||||
if (@!$accConf['output_cache_licensed']) {
|
||||
Zend_Cache::throwException('The Zend Platform extension does not have the proper license to use content caching features');
|
||||
}
|
||||
if (@!$accConf['output_cache_enabled']) {
|
||||
Zend_Cache::throwException('The Zend Platform content caching feature must be enabled for using this backend, set the \'zend_accelerator.output_cache_enabled\' directive to On !');
|
||||
}
|
||||
if (!is_writable($accConf['output_cache_dir'])) {
|
||||
Zend_Cache::throwException('The cache copies directory \''. ini_get('zend_accelerator.output_cache_dir') .'\' must be writable !');
|
||||
}
|
||||
parent:: __construct($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available for the given id and (if yes) return it (false else)
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
|
||||
* @return string Cached data (or false)
|
||||
*/
|
||||
public function load($id, $doNotTestCacheValidity = false)
|
||||
{
|
||||
// doNotTestCacheValidity implemented by giving zero lifetime to the cache
|
||||
if ($doNotTestCacheValidity) {
|
||||
$lifetime = 0;
|
||||
} else {
|
||||
$lifetime = $this->_directives['lifetime'];
|
||||
}
|
||||
$res = output_cache_get($id, $lifetime);
|
||||
if($res) {
|
||||
return $res[0];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test if a cache is available or not (for the given id)
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @return mixed|false false (a cache is not available) or "last modified" timestamp (int) of the available cache record
|
||||
*/
|
||||
public function test($id)
|
||||
{
|
||||
$result = output_cache_get($id, $this->_directives['lifetime']);
|
||||
if ($result) {
|
||||
return $result[1];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save some string datas into a cache record
|
||||
*
|
||||
* Note : $data is always "string" (serialization is done by the
|
||||
* core not by the backend)
|
||||
*
|
||||
* @param string $data Data to cache
|
||||
* @param string $id Cache id
|
||||
* @param array $tags Array of strings, the cache record will be tagged by each string entry
|
||||
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function save($data, $id, $tags = array(), $specificLifetime = false)
|
||||
{
|
||||
if (!($specificLifetime === false)) {
|
||||
$this->_log("Zend_Cache_Backend_ZendPlatform::save() : non false specifc lifetime is unsuported for this backend");
|
||||
}
|
||||
|
||||
$lifetime = $this->_directives['lifetime'];
|
||||
$result1 = output_cache_put($id, array($data, time()));
|
||||
$result2 = (count($tags) == 0);
|
||||
|
||||
foreach ($tags as $tag) {
|
||||
$tagid = self::TAGS_PREFIX.$tag;
|
||||
$old_tags = output_cache_get($tagid, $lifetime);
|
||||
if ($old_tags === false) {
|
||||
$old_tags = array();
|
||||
}
|
||||
$old_tags[$id] = $id;
|
||||
output_cache_remove_key($tagid);
|
||||
$result2 = output_cache_put($tagid, $old_tags);
|
||||
}
|
||||
|
||||
return $result1 && $result2;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove a cache record
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
public function remove($id)
|
||||
{
|
||||
return output_cache_remove_key($id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clean some cache records
|
||||
*
|
||||
* Available modes are :
|
||||
* Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used)
|
||||
* Zend_Cache::CLEANING_MODE_OLD => remove too old cache entries ($tags is not used)
|
||||
* This mode is not supported in this backend
|
||||
* Zend_Cache::CLEANING_MODE_MATCHING_TAG => remove cache entries matching all given tags
|
||||
* ($tags can be an array of strings or a single string)
|
||||
* Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => unsupported
|
||||
* Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG => remove cache entries matching any given tags
|
||||
* ($tags can be an array of strings or a single string)
|
||||
*
|
||||
* @param string $mode Clean mode
|
||||
* @param array $tags Array of tags
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
||||
{
|
||||
switch ($mode) {
|
||||
case Zend_Cache::CLEANING_MODE_ALL:
|
||||
case Zend_Cache::CLEANING_MODE_OLD:
|
||||
$cache_dir = ini_get('zend_accelerator.output_cache_dir');
|
||||
if (!$cache_dir) {
|
||||
return false;
|
||||
}
|
||||
$cache_dir .= '/.php_cache_api/';
|
||||
return $this->_clean($cache_dir, $mode);
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
|
||||
$idlist = null;
|
||||
foreach ($tags as $tag) {
|
||||
$next_idlist = output_cache_get(self::TAGS_PREFIX.$tag, $this->_directives['lifetime']);
|
||||
if ($idlist) {
|
||||
$idlist = array_intersect_assoc($idlist, $next_idlist);
|
||||
} else {
|
||||
$idlist = $next_idlist;
|
||||
}
|
||||
if (count($idlist) == 0) {
|
||||
// if ID list is already empty - we may skip checking other IDs
|
||||
$idlist = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($idlist) {
|
||||
foreach ($idlist as $id) {
|
||||
output_cache_remove_key($id);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
|
||||
$this->_log("Zend_Cache_Backend_ZendPlatform::clean() : CLEANING_MODE_NOT_MATCHING_TAG is not supported by the Zend Platform backend");
|
||||
return false;
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
|
||||
$idlist = null;
|
||||
foreach ($tags as $tag) {
|
||||
$next_idlist = output_cache_get(self::TAGS_PREFIX.$tag, $this->_directives['lifetime']);
|
||||
if ($idlist) {
|
||||
$idlist = array_merge_recursive($idlist, $next_idlist);
|
||||
} else {
|
||||
$idlist = $next_idlist;
|
||||
}
|
||||
if (count($idlist) == 0) {
|
||||
// if ID list is already empty - we may skip checking other IDs
|
||||
$idlist = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($idlist) {
|
||||
foreach ($idlist as $id) {
|
||||
output_cache_remove_key($id);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
break;
|
||||
default:
|
||||
Zend_Cache::throwException('Invalid mode for clean() method');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean a directory and recursivly go over it's subdirectories
|
||||
*
|
||||
* Remove all the cached files that need to be cleaned (according to mode and files mtime)
|
||||
*
|
||||
* @param string $dir Path of directory ot clean
|
||||
* @param string $mode The same parameter as in Zend_Cache_Backend_ZendPlatform::clean()
|
||||
* @return boolean True if ok
|
||||
*/
|
||||
private function _clean($dir, $mode)
|
||||
{
|
||||
$d = @dir($dir);
|
||||
if (!$d) {
|
||||
return false;
|
||||
}
|
||||
$result = true;
|
||||
while (false !== ($file = $d->read())) {
|
||||
if ($file == '.' || $file == '..') {
|
||||
continue;
|
||||
}
|
||||
$file = $d->path . $file;
|
||||
if (is_dir($file)) {
|
||||
$result = ($this->_clean($file .'/', $mode)) && ($result);
|
||||
} else {
|
||||
if ($mode == Zend_Cache::CLEANING_MODE_ALL) {
|
||||
$result = ($this->_remove($file)) && ($result);
|
||||
} else if ($mode == Zend_Cache::CLEANING_MODE_OLD) {
|
||||
// Files older than lifetime get deleted from cache
|
||||
if ($this->_directives['lifetime'] !== null) {
|
||||
if ((time() - @filemtime($file)) > $this->_directives['lifetime']) {
|
||||
$result = ($this->_remove($file)) && ($result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$d->close();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a file
|
||||
*
|
||||
* If we can't remove the file (because of locks or any problem), we will touch
|
||||
* the file to invalidate it
|
||||
*
|
||||
* @param string $file Complete file path
|
||||
* @return boolean True if ok
|
||||
*/
|
||||
private function _remove($file)
|
||||
{
|
||||
if (!@unlink($file)) {
|
||||
# If we can't remove the file (because of locks or any problem), we will touch
|
||||
# the file to invalidate it
|
||||
$this->_log("Zend_Cache_Backend_ZendPlatform::_remove() : we can't remove $file => we are going to try to invalidate it");
|
||||
if ($this->_directives['lifetime'] === null) {
|
||||
return false;
|
||||
}
|
||||
if (!file_exists($file)) {
|
||||
return false;
|
||||
}
|
||||
return @touch($file, time() - 2*abs($this->_directives['lifetime']));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
207
www/analytics/libs/Zend/Cache/Backend/ZendServer.php
Normal file
207
www/analytics/libs/Zend/Cache/Backend/ZendServer.php
Normal file
|
|
@ -0,0 +1,207 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: ZendServer.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
|
||||
/** @see Zend_Cache_Backend_Interface */
|
||||
// require_once 'Zend/Cache/Backend/Interface.php';
|
||||
|
||||
/** @see Zend_Cache_Backend */
|
||||
// require_once 'Zend/Cache/Backend.php';
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Cache_Backend_ZendServer extends Zend_Cache_Backend implements Zend_Cache_Backend_Interface
|
||||
{
|
||||
/**
|
||||
* Available options
|
||||
*
|
||||
* =====> (string) namespace :
|
||||
* Namespace to be used for chaching operations
|
||||
*
|
||||
* @var array available options
|
||||
*/
|
||||
protected $_options = array(
|
||||
'namespace' => 'zendframework'
|
||||
);
|
||||
|
||||
/**
|
||||
* Store data
|
||||
*
|
||||
* @param mixed $data Object to store
|
||||
* @param string $id Cache id
|
||||
* @param int $timeToLive Time to live in seconds
|
||||
* @throws Zend_Cache_Exception
|
||||
*/
|
||||
abstract protected function _store($data, $id, $timeToLive);
|
||||
|
||||
/**
|
||||
* Fetch data
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @throws Zend_Cache_Exception
|
||||
*/
|
||||
abstract protected function _fetch($id);
|
||||
|
||||
/**
|
||||
* Unset data
|
||||
*
|
||||
* @param string $id Cache id
|
||||
*/
|
||||
abstract protected function _unset($id);
|
||||
|
||||
/**
|
||||
* Clear cache
|
||||
*/
|
||||
abstract protected function _clear();
|
||||
|
||||
/**
|
||||
* Test if a cache is available for the given id and (if yes) return it (false else)
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @param boolean $doNotTestCacheValidity if set to true, the cache validity won't be tested
|
||||
* @return string cached datas (or false)
|
||||
*/
|
||||
public function load($id, $doNotTestCacheValidity = false)
|
||||
{
|
||||
$tmp = $this->_fetch($id);
|
||||
if ($tmp !== null) {
|
||||
return $tmp;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available or not (for the given id)
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record
|
||||
* @throws Zend_Cache_Exception
|
||||
*/
|
||||
public function test($id)
|
||||
{
|
||||
$tmp = $this->_fetch('internal-metadatas---' . $id);
|
||||
if ($tmp !== false) {
|
||||
if (!is_array($tmp) || !isset($tmp['mtime'])) {
|
||||
Zend_Cache::throwException('Cache metadata for \'' . $id . '\' id is corrupted' );
|
||||
}
|
||||
return $tmp['mtime'];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute & return the expire time
|
||||
*
|
||||
* @return int expire time (unix timestamp)
|
||||
*/
|
||||
private function _expireTime($lifetime)
|
||||
{
|
||||
if ($lifetime === null) {
|
||||
return 9999999999;
|
||||
}
|
||||
return time() + $lifetime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save some string datas into a cache record
|
||||
*
|
||||
* Note : $data is always "string" (serialization is done by the
|
||||
* core not by the backend)
|
||||
*
|
||||
* @param string $data datas to cache
|
||||
* @param string $id cache id
|
||||
* @param array $tags array of strings, the cache record will be tagged by each string entry
|
||||
* @param int $specificLifetime if != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function save($data, $id, $tags = array(), $specificLifetime = false)
|
||||
{
|
||||
$lifetime = $this->getLifetime($specificLifetime);
|
||||
$metadatas = array(
|
||||
'mtime' => time(),
|
||||
'expire' => $this->_expireTime($lifetime),
|
||||
);
|
||||
|
||||
if (count($tags) > 0) {
|
||||
$this->_log('Zend_Cache_Backend_ZendServer::save() : tags are unsupported by the ZendServer backends');
|
||||
}
|
||||
|
||||
return $this->_store($data, $id, $lifetime) &&
|
||||
$this->_store($metadatas, 'internal-metadatas---' . $id, $lifetime);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a cache record
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function remove($id)
|
||||
{
|
||||
$result1 = $this->_unset($id);
|
||||
$result2 = $this->_unset('internal-metadatas---' . $id);
|
||||
|
||||
return $result1 && $result2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean some cache records
|
||||
*
|
||||
* Available modes are :
|
||||
* 'all' (default) => remove all cache entries ($tags is not used)
|
||||
* 'old' => unsupported
|
||||
* 'matchingTag' => unsupported
|
||||
* 'notMatchingTag' => unsupported
|
||||
* 'matchingAnyTag' => unsupported
|
||||
*
|
||||
* @param string $mode clean mode
|
||||
* @param array $tags array of tags
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
||||
{
|
||||
switch ($mode) {
|
||||
case Zend_Cache::CLEANING_MODE_ALL:
|
||||
$this->_clear();
|
||||
return true;
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_OLD:
|
||||
$this->_log("Zend_Cache_Backend_ZendServer::clean() : CLEANING_MODE_OLD is unsupported by the Zend Server backends.");
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
|
||||
case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
|
||||
case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
|
||||
$this->_clear();
|
||||
$this->_log('Zend_Cache_Backend_ZendServer::clean() : tags are unsupported by the Zend Server backends.');
|
||||
break;
|
||||
default:
|
||||
Zend_Cache::throwException('Invalid mode for clean() method');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
100
www/analytics/libs/Zend/Cache/Backend/ZendServer/Disk.php
Normal file
100
www/analytics/libs/Zend/Cache/Backend/ZendServer/Disk.php
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Disk.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
|
||||
/** @see Zend_Cache_Backend_Interface */
|
||||
// require_once 'Zend/Cache/Backend/Interface.php';
|
||||
|
||||
/** @see Zend_Cache_Backend_ZendServer */
|
||||
// require_once 'Zend/Cache/Backend/ZendServer.php';
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Cache_Backend_ZendServer_Disk extends Zend_Cache_Backend_ZendServer implements Zend_Cache_Backend_Interface
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options associative array of options
|
||||
* @throws Zend_Cache_Exception
|
||||
*/
|
||||
public function __construct(array $options = array())
|
||||
{
|
||||
if (!function_exists('zend_disk_cache_store')) {
|
||||
Zend_Cache::throwException('Zend_Cache_ZendServer_Disk backend has to be used within Zend Server environment.');
|
||||
}
|
||||
parent::__construct($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store data
|
||||
*
|
||||
* @param mixed $data Object to store
|
||||
* @param string $id Cache id
|
||||
* @param int $timeToLive Time to live in seconds
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
protected function _store($data, $id, $timeToLive)
|
||||
{
|
||||
if (zend_disk_cache_store($this->_options['namespace'] . '::' . $id,
|
||||
$data,
|
||||
$timeToLive) === false) {
|
||||
$this->_log('Store operation failed.');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch data
|
||||
*
|
||||
* @param string $id Cache id
|
||||
*/
|
||||
protected function _fetch($id)
|
||||
{
|
||||
return zend_disk_cache_fetch($this->_options['namespace'] . '::' . $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unset data
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
protected function _unset($id)
|
||||
{
|
||||
return zend_disk_cache_delete($this->_options['namespace'] . '::' . $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear cache
|
||||
*/
|
||||
protected function _clear()
|
||||
{
|
||||
zend_disk_cache_clear($this->_options['namespace']);
|
||||
}
|
||||
}
|
||||
100
www/analytics/libs/Zend/Cache/Backend/ZendServer/ShMem.php
Normal file
100
www/analytics/libs/Zend/Cache/Backend/ZendServer/ShMem.php
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: ShMem.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
|
||||
/** @see Zend_Cache_Backend_Interface */
|
||||
// require_once 'Zend/Cache/Backend/Interface.php';
|
||||
|
||||
/** @see Zend_Cache_Backend_ZendServer */
|
||||
// require_once 'Zend/Cache/Backend/ZendServer.php';
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Cache_Backend_ZendServer_ShMem extends Zend_Cache_Backend_ZendServer implements Zend_Cache_Backend_Interface
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options associative array of options
|
||||
* @throws Zend_Cache_Exception
|
||||
*/
|
||||
public function __construct(array $options = array())
|
||||
{
|
||||
if (!function_exists('zend_shm_cache_store')) {
|
||||
Zend_Cache::throwException('Zend_Cache_ZendServer_ShMem backend has to be used within Zend Server environment.');
|
||||
}
|
||||
parent::__construct($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store data
|
||||
*
|
||||
* @param mixed $data Object to store
|
||||
* @param string $id Cache id
|
||||
* @param int $timeToLive Time to live in seconds
|
||||
*
|
||||
*/
|
||||
protected function _store($data, $id, $timeToLive)
|
||||
{
|
||||
if (zend_shm_cache_store($this->_options['namespace'] . '::' . $id,
|
||||
$data,
|
||||
$timeToLive) === false) {
|
||||
$this->_log('Store operation failed.');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch data
|
||||
*
|
||||
* @param string $id Cache id
|
||||
*/
|
||||
protected function _fetch($id)
|
||||
{
|
||||
return zend_shm_cache_fetch($this->_options['namespace'] . '::' . $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unset data
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
protected function _unset($id)
|
||||
{
|
||||
return zend_shm_cache_delete($this->_options['namespace'] . '::' . $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear cache
|
||||
*/
|
||||
protected function _clear()
|
||||
{
|
||||
zend_shm_cache_clear($this->_options['namespace']);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue