updating PEAR sources
This commit is contained in:
parent
d4078e39e8
commit
fe942aa1b5
File diff suppressed because it is too large
Load Diff
|
@ -1,28 +1,40 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
|
||||
// | Lorenzo Alberton <l dot alberton at quipo dot it> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Calendar.php,v 1.3 2005/10/22 10:07:11 quipo Exp $
|
||||
//
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* @package Calendar
|
||||
* @version $Id: Calendar.php,v 1.3 2005/10/22 10:07:11 quipo Exp $
|
||||
* Contains the Calendar and Calendar_Engine_Factory classes
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "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 FREEBSD PROJECT 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 Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
||||
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @version CVS: $Id: Calendar.php,v 1.9 2008/11/15 21:21:42 quipo Exp $
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -52,14 +64,22 @@ define('CALENDAR_USE_MONTH_WEEKS', 3);
|
|||
* <b>Note:</b> this class must be modified to "register" alternative
|
||||
* Calendar_Engines. The engine used can be controlled with the constant
|
||||
* CALENDAR_ENGINE
|
||||
* @see Calendar_Engine_Interface
|
||||
* @package Calendar
|
||||
* @access protected
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
||||
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
* @see Calendar_Engine_Interface
|
||||
* @access protected
|
||||
*/
|
||||
class Calendar_Engine_Factory
|
||||
{
|
||||
/**
|
||||
* Returns an instance of the engine
|
||||
*
|
||||
* @return object instance of a calendar calculation engine
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -67,17 +87,17 @@ class Calendar_Engine_Factory
|
|||
{
|
||||
static $engine = false;
|
||||
switch (CALENDAR_ENGINE) {
|
||||
case 'PearDate':
|
||||
$class = 'Calendar_Engine_PearDate';
|
||||
break;
|
||||
case 'UnixTS':
|
||||
default:
|
||||
$class = 'Calendar_Engine_UnixTS';
|
||||
case 'PearDate':
|
||||
$class = 'Calendar_Engine_PearDate';
|
||||
break;
|
||||
case 'UnixTS':
|
||||
default:
|
||||
$class = 'Calendar_Engine_UnixTS';
|
||||
break;
|
||||
}
|
||||
if (!$engine) {
|
||||
if (!class_exists($class)) {
|
||||
require_once CALENDAR_ROOT.'Engine'.DIRECTORY_SEPARATOR.CALENDAR_ENGINE.'.php';
|
||||
include_once CALENDAR_ROOT.'Engine'.DIRECTORY_SEPARATOR.CALENDAR_ENGINE.'.php';
|
||||
}
|
||||
$engine = new $class;
|
||||
}
|
||||
|
@ -86,10 +106,16 @@ class Calendar_Engine_Factory
|
|||
}
|
||||
|
||||
/**
|
||||
* Base class for Calendar API. This class should not be instantiated
|
||||
* directly.
|
||||
* Base class for Calendar API. This class should not be instantiated directly.
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
||||
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
* @abstract
|
||||
* @package Calendar
|
||||
*/
|
||||
class Calendar
|
||||
{
|
||||
|
@ -113,7 +139,7 @@ class Calendar
|
|||
* @access private
|
||||
* @var int
|
||||
*/
|
||||
var $year;
|
||||
var $year;
|
||||
|
||||
/**
|
||||
* Month for this calendar object e.g. 9
|
||||
|
@ -167,12 +193,14 @@ class Calendar
|
|||
|
||||
/**
|
||||
* Constructs the Calendar
|
||||
* @param int year
|
||||
* @param int month
|
||||
* @param int day
|
||||
* @param int hour
|
||||
* @param int minute
|
||||
* @param int second
|
||||
*
|
||||
* @param int $y year
|
||||
* @param int $m month
|
||||
* @param int $d day
|
||||
* @param int $h hour
|
||||
* @param int $i minute
|
||||
* @param int $s second
|
||||
*
|
||||
* @access protected
|
||||
*/
|
||||
function Calendar($y = 2000, $m = 1, $d = 1, $h = 0, $i = 0, $s = 0)
|
||||
|
@ -181,7 +209,7 @@ class Calendar
|
|||
if (!isset($cE)) {
|
||||
$cE = & Calendar_Engine_Factory::getEngine();
|
||||
}
|
||||
$this->cE = & $cE;
|
||||
$this->cE = & $cE;
|
||||
$this->year = (int)$y;
|
||||
$this->month = (int)$m;
|
||||
$this->day = (int)$d;
|
||||
|
@ -193,7 +221,9 @@ class Calendar
|
|||
/**
|
||||
* Defines the calendar by a timestamp (Unix or ISO-8601), replacing values
|
||||
* passed to the constructor
|
||||
* @param int|string Unix or ISO-8601 timestamp
|
||||
*
|
||||
* @param int|string $ts Unix or ISO-8601 timestamp
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
|
@ -210,6 +240,7 @@ class Calendar
|
|||
/**
|
||||
* Returns a timestamp from the current date / time values. Format of
|
||||
* timestamp depends on Calendar_Engine implementation being used
|
||||
*
|
||||
* @return int|string timestamp
|
||||
* @access public
|
||||
*/
|
||||
|
@ -222,7 +253,9 @@ class Calendar
|
|||
|
||||
/**
|
||||
* Defines calendar object as selected (e.g. for today)
|
||||
* @param boolean state whether Calendar subclass
|
||||
*
|
||||
* @param boolean $state whether Calendar subclass
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
|
@ -233,6 +266,7 @@ class Calendar
|
|||
|
||||
/**
|
||||
* True if the calendar subclass object is selected (e.g. today)
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
|
@ -241,14 +275,26 @@ class Calendar
|
|||
return $this->selected;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the current Calendar object is today's date
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function isToday()
|
||||
{
|
||||
return $this->cE->isToday($this->getTimeStamp());
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjusts the date (helper method)
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function adjust()
|
||||
{
|
||||
$stamp = $this->getTimeStamp();
|
||||
$stamp = $this->getTimeStamp();
|
||||
$this->year = $this->cE->stampToYear($stamp);
|
||||
$this->month = $this->cE->stampToMonth($stamp);
|
||||
$this->day = $this->cE->stampToDay($stamp);
|
||||
|
@ -259,7 +305,9 @@ class Calendar
|
|||
|
||||
/**
|
||||
* Returns the date as an associative array (helper method)
|
||||
* @param mixed timestamp (leave empty for current timestamp)
|
||||
*
|
||||
* @param mixed $stamp timestamp (leave empty for current timestamp)
|
||||
*
|
||||
* @return array
|
||||
* @access public
|
||||
*/
|
||||
|
@ -280,59 +328,64 @@ class Calendar
|
|||
|
||||
/**
|
||||
* Returns the value as an associative array (helper method)
|
||||
* @param string type of date object that return value represents
|
||||
* @param string $format ['int' | 'array' | 'timestamp' | 'object']
|
||||
* @param mixed timestamp (depending on Calendar engine being used)
|
||||
* @param int integer default value (i.e. give me the answer quick)
|
||||
*
|
||||
* @param string $returnType type of date object that return value represents
|
||||
* @param string $format ['int' | 'array' | 'timestamp' | 'object']
|
||||
* @param mixed $stamp timestamp (depending on Calendar engine being used)
|
||||
* @param int $default default value (i.e. give me the answer quick)
|
||||
*
|
||||
* @return mixed
|
||||
* @access private
|
||||
*/
|
||||
function returnValue($returnType, $format, $stamp, $default)
|
||||
{
|
||||
switch (strtolower($format)) {
|
||||
case 'int':
|
||||
return $default;
|
||||
case 'array':
|
||||
return $this->toArray($stamp);
|
||||
break;
|
||||
case 'object':
|
||||
require_once CALENDAR_ROOT.'Factory.php';
|
||||
return Calendar_Factory::createByTimestamp($returnType,$stamp);
|
||||
break;
|
||||
case 'timestamp':
|
||||
default:
|
||||
return $stamp;
|
||||
break;
|
||||
case 'int':
|
||||
return $default;
|
||||
case 'array':
|
||||
return $this->toArray($stamp);
|
||||
break;
|
||||
case 'object':
|
||||
include_once CALENDAR_ROOT.'Factory.php';
|
||||
return Calendar_Factory::createByTimestamp($returnType, $stamp);
|
||||
break;
|
||||
case 'timestamp':
|
||||
default:
|
||||
return $stamp;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract method for building the children of a calendar object.
|
||||
* Implemented by Calendar subclasses
|
||||
* @param array containing Calendar objects to select (optional)
|
||||
*
|
||||
* @param array $sDates array containing Calendar objects to select (optional)
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
* @abstract
|
||||
*/
|
||||
function build($sDates = array())
|
||||
{
|
||||
require_once 'PEAR.php';
|
||||
PEAR::raiseError(
|
||||
'Calendar::build is abstract', null, PEAR_ERROR_TRIGGER,
|
||||
include_once 'PEAR.php';
|
||||
PEAR::raiseError('Calendar::build is abstract', null, PEAR_ERROR_TRIGGER,
|
||||
E_USER_NOTICE, 'Calendar::build()');
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract method for selected data objects called from build
|
||||
* @param array
|
||||
*
|
||||
* @param array $sDates array of Calendar objects to select
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
* @abstract
|
||||
*/
|
||||
function setSelection($sDates)
|
||||
{
|
||||
require_once 'PEAR.php';
|
||||
include_once 'PEAR.php';
|
||||
PEAR::raiseError(
|
||||
'Calendar::setSelection is abstract', null, PEAR_ERROR_TRIGGER,
|
||||
E_USER_NOTICE, 'Calendar::setSelection()');
|
||||
|
@ -344,6 +397,7 @@ class Calendar
|
|||
* (e.g. a minute from an hour object). On reaching the end of
|
||||
* the collection, returns false and resets the collection for
|
||||
* further iteratations.
|
||||
*
|
||||
* @return mixed either an object subclass of Calendar or false
|
||||
* @access public
|
||||
*/
|
||||
|
@ -360,6 +414,7 @@ class Calendar
|
|||
|
||||
/**
|
||||
* Fetches all child from the current collection of children
|
||||
*
|
||||
* @return array
|
||||
* @access public
|
||||
*/
|
||||
|
@ -369,8 +424,8 @@ class Calendar
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the number Calendar subclass objects stored in the internal
|
||||
* collection.
|
||||
* Get the number Calendar subclass objects stored in the internal collection
|
||||
*
|
||||
* @return int
|
||||
* @access public
|
||||
*/
|
||||
|
@ -381,8 +436,8 @@ class Calendar
|
|||
|
||||
/**
|
||||
* Determine whether this date is valid, with the bounds determined by
|
||||
* the Calendar_Engine. The call is passed on to
|
||||
* Calendar_Validator::isValid
|
||||
* the Calendar_Engine. The call is passed on to Calendar_Validator::isValid
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
|
@ -394,13 +449,14 @@ class Calendar
|
|||
|
||||
/**
|
||||
* Returns an instance of Calendar_Validator
|
||||
*
|
||||
* @return Calendar_Validator
|
||||
* @access public
|
||||
*/
|
||||
function & getValidator()
|
||||
{
|
||||
if (!isset($this->validator)) {
|
||||
require_once CALENDAR_ROOT.'Validator.php';
|
||||
include_once CALENDAR_ROOT.'Validator.php';
|
||||
$this->validator = & new Calendar_Validator($this);
|
||||
}
|
||||
return $this->validator;
|
||||
|
@ -409,6 +465,7 @@ class Calendar
|
|||
/**
|
||||
* Returns a reference to the current Calendar_Engine being used. Useful
|
||||
* for Calendar_Table_Helper and Calendar_Validator
|
||||
*
|
||||
* @return object implementing Calendar_Engine_Inteface
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -420,11 +477,13 @@ class Calendar
|
|||
/**
|
||||
* Set the CALENDAR_FIRST_DAY_OF_WEEK constant to the $firstDay value
|
||||
* if the constant is not set yet.
|
||||
*
|
||||
* @param integer $firstDay first day of the week (0=sunday, 1=monday, ...)
|
||||
*
|
||||
* @return integer
|
||||
* @throws E_USER_WARNING this method throws a WARNING if the
|
||||
* CALENDAR_FIRST_DAY_OF_WEEK constant is already defined and
|
||||
* the $firstDay parameter is set to a different value
|
||||
* @param integer $firstDay first day of the week (0=sunday, 1=monday, ...)
|
||||
* @return integer
|
||||
* @access protected
|
||||
*/
|
||||
function defineFirstDayOfWeek($firstDay = null)
|
||||
|
@ -450,7 +509,9 @@ class Calendar
|
|||
|
||||
/**
|
||||
* Returns the value for the previous year
|
||||
* @param string return value format ['int' | 'timestamp' | 'object' | 'array']
|
||||
*
|
||||
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
|
||||
*
|
||||
* @return int e.g. 2002 or timestamp
|
||||
* @access public
|
||||
*/
|
||||
|
@ -462,7 +523,9 @@ class Calendar
|
|||
|
||||
/**
|
||||
* Returns the value for this year
|
||||
* @param string return value format ['int' | 'timestamp' | 'object' | 'array']
|
||||
*
|
||||
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
|
||||
*
|
||||
* @return int e.g. 2003 or timestamp
|
||||
* @access public
|
||||
*/
|
||||
|
@ -474,7 +537,9 @@ class Calendar
|
|||
|
||||
/**
|
||||
* Returns the value for next year
|
||||
* @param string return value format ['int' | 'timestamp' | 'object' | 'array']
|
||||
*
|
||||
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
|
||||
*
|
||||
* @return int e.g. 2004 or timestamp
|
||||
* @access public
|
||||
*/
|
||||
|
@ -486,7 +551,9 @@ class Calendar
|
|||
|
||||
/**
|
||||
* Returns the value for the previous month
|
||||
* @param string return value format ['int' | 'timestamp' | 'object' | 'array']
|
||||
*
|
||||
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
|
||||
*
|
||||
* @return int e.g. 4 or Unix timestamp
|
||||
* @access public
|
||||
*/
|
||||
|
@ -498,7 +565,9 @@ class Calendar
|
|||
|
||||
/**
|
||||
* Returns the value for this month
|
||||
* @param string return value format ['int' | 'timestamp' | 'object' | 'array']
|
||||
*
|
||||
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
|
||||
*
|
||||
* @return int e.g. 5 or timestamp
|
||||
* @access public
|
||||
*/
|
||||
|
@ -510,7 +579,9 @@ class Calendar
|
|||
|
||||
/**
|
||||
* Returns the value for next month
|
||||
* @param string return value format ['int' | 'timestamp' | 'object' | 'array']
|
||||
*
|
||||
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
|
||||
*
|
||||
* @return int e.g. 6 or timestamp
|
||||
* @access public
|
||||
*/
|
||||
|
@ -522,7 +593,9 @@ class Calendar
|
|||
|
||||
/**
|
||||
* Returns the value for the previous day
|
||||
* @param string return value format ['int' | 'timestamp' | 'object' | 'array']
|
||||
*
|
||||
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
|
||||
*
|
||||
* @return int e.g. 10 or timestamp
|
||||
* @access public
|
||||
*/
|
||||
|
@ -535,7 +608,9 @@ class Calendar
|
|||
|
||||
/**
|
||||
* Returns the value for this day
|
||||
* @param string return value format ['int' | 'timestamp' | 'object' | 'array']
|
||||
*
|
||||
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
|
||||
*
|
||||
* @return int e.g. 11 or timestamp
|
||||
* @access public
|
||||
*/
|
||||
|
@ -548,7 +623,9 @@ class Calendar
|
|||
|
||||
/**
|
||||
* Returns the value for the next day
|
||||
* @param string return value format ['int' | 'timestamp' | 'object' | 'array']
|
||||
*
|
||||
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
|
||||
*
|
||||
* @return int e.g. 12 or timestamp
|
||||
* @access public
|
||||
*/
|
||||
|
@ -561,7 +638,9 @@ class Calendar
|
|||
|
||||
/**
|
||||
* Returns the value for the previous hour
|
||||
* @param string return value format ['int' | 'timestamp' | 'object' | 'array']
|
||||
*
|
||||
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
|
||||
*
|
||||
* @return int e.g. 13 or timestamp
|
||||
* @access public
|
||||
*/
|
||||
|
@ -574,7 +653,9 @@ class Calendar
|
|||
|
||||
/**
|
||||
* Returns the value for this hour
|
||||
* @param string return value format ['int' | 'timestamp' | 'object' | 'array']
|
||||
*
|
||||
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
|
||||
*
|
||||
* @return int e.g. 14 or timestamp
|
||||
* @access public
|
||||
*/
|
||||
|
@ -587,7 +668,9 @@ class Calendar
|
|||
|
||||
/**
|
||||
* Returns the value for the next hour
|
||||
* @param string return value format ['int' | 'timestamp' | 'object' | 'array']
|
||||
*
|
||||
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
|
||||
*
|
||||
* @return int e.g. 14 or timestamp
|
||||
* @access public
|
||||
*/
|
||||
|
@ -600,7 +683,9 @@ class Calendar
|
|||
|
||||
/**
|
||||
* Returns the value for the previous minute
|
||||
* @param string return value format ['int' | 'timestamp' | 'object' | 'array']
|
||||
*
|
||||
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
|
||||
*
|
||||
* @return int e.g. 23 or timestamp
|
||||
* @access public
|
||||
*/
|
||||
|
@ -614,7 +699,9 @@ class Calendar
|
|||
|
||||
/**
|
||||
* Returns the value for this minute
|
||||
* @param string return value format ['int' | 'timestamp' | 'object' | 'array']
|
||||
*
|
||||
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
|
||||
*
|
||||
* @return int e.g. 24 or timestamp
|
||||
* @access public
|
||||
*/
|
||||
|
@ -628,7 +715,9 @@ class Calendar
|
|||
|
||||
/**
|
||||
* Returns the value for the next minute
|
||||
* @param string return value format ['int' | 'timestamp' | 'object' | 'array']
|
||||
*
|
||||
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
|
||||
*
|
||||
* @return int e.g. 25 or timestamp
|
||||
* @access public
|
||||
*/
|
||||
|
@ -642,7 +731,9 @@ class Calendar
|
|||
|
||||
/**
|
||||
* Returns the value for the previous second
|
||||
* @param string return value format ['int' | 'timestamp' | 'object' | 'array']
|
||||
*
|
||||
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
|
||||
*
|
||||
* @return int e.g. 43 or timestamp
|
||||
* @access public
|
||||
*/
|
||||
|
@ -656,7 +747,9 @@ class Calendar
|
|||
|
||||
/**
|
||||
* Returns the value for this second
|
||||
* @param string return value format ['int' | 'timestamp' | 'object' | 'array']
|
||||
*
|
||||
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
|
||||
*
|
||||
* @return int e.g. 44 or timestamp
|
||||
* @access public
|
||||
*/
|
||||
|
@ -670,7 +763,9 @@ class Calendar
|
|||
|
||||
/**
|
||||
* Returns the value for the next second
|
||||
* @param string return value format ['int' | 'timestamp' | 'object' | 'array']
|
||||
*
|
||||
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
|
||||
*
|
||||
* @return int e.g. 45 or timestamp
|
||||
* @access public
|
||||
*/
|
||||
|
|
|
@ -1,27 +1,39 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Day.php,v 1.1 2004/05/24 22:25:42 quipo Exp $
|
||||
//
|
||||
|
||||
/**
|
||||
* @package Calendar
|
||||
* @version $Id: Day.php,v 1.1 2004/05/24 22:25:42 quipo Exp $
|
||||
* Contains the Calendar_Day class
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "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 FREEBSD PROJECT 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 Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @copyright 2003-2007 Harry Fuecks
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @version CVS: $Id: Day.php,v 1.5 2007/11/16 20:03:12 quipo Exp $
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -40,14 +52,20 @@ require_once CALENDAR_ROOT.'Calendar.php';
|
|||
/**
|
||||
* Represents a Day and builds Hours.
|
||||
* <code>
|
||||
* require_once 'Calendar'.DIRECTORY_SEPARATOR.'Day.php';
|
||||
* require_once 'Calendar/Day.php';
|
||||
* $Day = & new Calendar_Day(2003, 10, 21); // Oct 21st 2003
|
||||
* while ($Hour = & $Day->fetch()) {
|
||||
* echo $Hour->thisHour().'<br />';
|
||||
* }
|
||||
* </code>
|
||||
* @package Calendar
|
||||
* @access public
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @copyright 2003-2007 Harry Fuecks
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Day extends Calendar
|
||||
{
|
||||
|
@ -60,7 +78,7 @@ class Calendar_Day extends Calendar
|
|||
|
||||
/**
|
||||
* Marks the Day at the end of a week
|
||||
* @access private
|
||||
* @access private
|
||||
* @var boolean
|
||||
*/
|
||||
var $last = false;
|
||||
|
@ -75,9 +93,11 @@ class Calendar_Day extends Calendar
|
|||
|
||||
/**
|
||||
* Constructs Calendar_Day
|
||||
* @param int year e.g. 2003
|
||||
* @param int month e.g. 8
|
||||
* @param int day e.g. 15
|
||||
*
|
||||
* @param int $y year e.g. 2003
|
||||
* @param int $m month e.g. 8
|
||||
* @param int $d day e.g. 15
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function Calendar_Day($y, $m, $d)
|
||||
|
@ -87,17 +107,19 @@ class Calendar_Day extends Calendar
|
|||
|
||||
/**
|
||||
* Builds the Hours of the Day
|
||||
* @param array (optional) Caledar_Hour objects representing selected dates
|
||||
*
|
||||
* @param array $sDates (optional) Caledar_Hour objects representing selected dates
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function build($sDates = array())
|
||||
{
|
||||
require_once CALENDAR_ROOT.'Hour.php';
|
||||
include_once CALENDAR_ROOT.'Hour.php';
|
||||
|
||||
$hID = $this->cE->getHoursInDay($this->year, $this->month, $this->day);
|
||||
for ($i=0; $i < $hID; $i++) {
|
||||
$this->children[$i]=
|
||||
$this->children[$i] =
|
||||
new Calendar_Hour($this->year, $this->month, $this->day, $i);
|
||||
}
|
||||
if (count($sDates) > 0) {
|
||||
|
@ -108,7 +130,9 @@ class Calendar_Day extends Calendar
|
|||
|
||||
/**
|
||||
* Called from build()
|
||||
* @param array
|
||||
*
|
||||
* @param array $sDates dates to be selected
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
|
@ -131,11 +155,13 @@ class Calendar_Day extends Calendar
|
|||
/**
|
||||
* Defines Day object as first in a week
|
||||
* Only used by Calendar_Month_Weekdays::build()
|
||||
* @param boolean state
|
||||
*
|
||||
* @param boolean $state set this day as first in week
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function setFirst ($state = true)
|
||||
function setFirst($state = true)
|
||||
{
|
||||
$this->first = $state;
|
||||
}
|
||||
|
@ -143,7 +169,9 @@ class Calendar_Day extends Calendar
|
|||
/**
|
||||
* Defines Day object as last in a week
|
||||
* Used only following Calendar_Month_Weekdays::build()
|
||||
* @param boolean state
|
||||
*
|
||||
* @param boolean $state set this day as last in week
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
|
@ -155,16 +183,19 @@ class Calendar_Day extends Calendar
|
|||
/**
|
||||
* Returns true if Day object is first in a Week
|
||||
* Only relevant when Day is created by Calendar_Month_Weekdays::build()
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function isFirst() {
|
||||
function isFirst()
|
||||
{
|
||||
return $this->first;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if Day object is last in a Week
|
||||
* Only relevant when Day is created by Calendar_Month_Weekdays::build()
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
|
@ -176,7 +207,9 @@ class Calendar_Day extends Calendar
|
|||
/**
|
||||
* Defines Day object as empty
|
||||
* Only used by Calendar_Month_Weekdays::build()
|
||||
* @param boolean state
|
||||
*
|
||||
* @param boolean $state set this day as empty
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
|
@ -186,6 +219,8 @@ class Calendar_Day extends Calendar
|
|||
}
|
||||
|
||||
/**
|
||||
* Check if this day is empty
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
|
|
|
@ -1,28 +1,41 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Decorator.php,v 1.3 2005/10/22 10:29:46 quipo Exp $
|
||||
//
|
||||
|
||||
/**
|
||||
* @package Calendar
|
||||
* @version $Id: Decorator.php,v 1.3 2005/10/22 10:29:46 quipo Exp $
|
||||
* Contains the Calendar_Decorator class
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "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 FREEBSD PROJECT 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 Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @copyright 2003-2007 Harry Fuecks
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @version CVS: $Id: Decorator.php,v 1.9 2007/11/18 21:46:42 quipo Exp $
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
*/
|
||||
|
||||
/**
|
||||
* Decorates any calendar class.
|
||||
* Create a subclass of this class for your own "decoration".
|
||||
|
@ -40,8 +53,14 @@
|
|||
* $DayDecorator = & new DayDecorator($Day);
|
||||
* echo $DayDecorator->thisDay(); // Outputs "Sat"
|
||||
* </code>
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @copyright 2003-2007 Harry Fuecks
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
* @abstract
|
||||
* @package Calendar
|
||||
*/
|
||||
class Calendar_Decorator
|
||||
{
|
||||
|
@ -54,9 +73,10 @@ class Calendar_Decorator
|
|||
|
||||
/**
|
||||
* Constructs the Calendar_Decorator
|
||||
* @param object subclass to Calendar to decorate
|
||||
*
|
||||
* @param object &$calendar subclass to Calendar to decorate
|
||||
*/
|
||||
function Calendar_Decorator(& $calendar)
|
||||
function Calendar_Decorator(&$calendar)
|
||||
{
|
||||
$this->calendar = & $calendar;
|
||||
}
|
||||
|
@ -64,7 +84,9 @@ class Calendar_Decorator
|
|||
/**
|
||||
* Defines the calendar by a Unix timestamp, replacing values
|
||||
* passed to the constructor
|
||||
* @param int Unix timestamp
|
||||
*
|
||||
* @param int $ts Unix timestamp
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
|
@ -76,7 +98,8 @@ class Calendar_Decorator
|
|||
/**
|
||||
* Returns a timestamp from the current date / time values. Format of
|
||||
* timestamp depends on Calendar_Engine implementation being used
|
||||
* @return int timestamp
|
||||
*
|
||||
* @return int $ts timestamp
|
||||
* @access public
|
||||
*/
|
||||
function getTimestamp()
|
||||
|
@ -86,7 +109,9 @@ class Calendar_Decorator
|
|||
|
||||
/**
|
||||
* Defines calendar object as selected (e.g. for today)
|
||||
* @param boolean state whether Calendar subclass
|
||||
*
|
||||
* @param boolean $state whether Calendar subclass must be selected
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
|
@ -97,6 +122,7 @@ class Calendar_Decorator
|
|||
|
||||
/**
|
||||
* True if the calendar subclass object is selected (e.g. today)
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
|
@ -107,6 +133,7 @@ class Calendar_Decorator
|
|||
|
||||
/**
|
||||
* Adjusts the date (helper method)
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
|
@ -117,21 +144,25 @@ class Calendar_Decorator
|
|||
|
||||
/**
|
||||
* Returns the date as an associative array (helper method)
|
||||
* @param mixed timestamp (leave empty for current timestamp)
|
||||
*
|
||||
* @param mixed $stamp timestamp (leave empty for current timestamp)
|
||||
*
|
||||
* @return array
|
||||
* @access public
|
||||
*/
|
||||
function toArray($stamp=null)
|
||||
function toArray($stamp = null)
|
||||
{
|
||||
return $this->calendar->toArray($stamp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value as an associative array (helper method)
|
||||
* @param string type of date object that return value represents
|
||||
* @param string $format ['int' | 'array' | 'timestamp' | 'object']
|
||||
* @param mixed timestamp (depending on Calendar engine being used)
|
||||
* @param int integer default value (i.e. give me the answer quick)
|
||||
*
|
||||
* @param string $returnType type of date object that return value represents
|
||||
* @param string $format ['int'|'timestamp'|'object'|'array']
|
||||
* @param mixed $stamp timestamp (depending on Calendar engine being used)
|
||||
* @param integer $default default value (i.e. give me the answer quick)
|
||||
*
|
||||
* @return mixed
|
||||
* @access private
|
||||
*/
|
||||
|
@ -143,13 +174,15 @@ class Calendar_Decorator
|
|||
/**
|
||||
* Defines Day object as first in a week
|
||||
* Only used by Calendar_Month_Weekdays::build()
|
||||
* @param boolean state
|
||||
*
|
||||
* @param boolean $state whether it's first or not
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function setFirst ($state = true)
|
||||
function setFirst($state = true)
|
||||
{
|
||||
if ( method_exists($this->calendar,'setFirst') ) {
|
||||
if (method_exists($this->calendar, 'setFirst')) {
|
||||
$this->calendar->setFirst($state);
|
||||
}
|
||||
}
|
||||
|
@ -157,13 +190,15 @@ class Calendar_Decorator
|
|||
/**
|
||||
* Defines Day object as last in a week
|
||||
* Used only following Calendar_Month_Weekdays::build()
|
||||
* @param boolean state
|
||||
*
|
||||
* @param boolean $state whether it's last or not
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function setLast($state = true)
|
||||
{
|
||||
if ( method_exists($this->calendar,'setLast') ) {
|
||||
if (method_exists($this->calendar, 'setLast')) {
|
||||
$this->calendar->setLast($state);
|
||||
}
|
||||
}
|
||||
|
@ -171,11 +206,13 @@ class Calendar_Decorator
|
|||
/**
|
||||
* Returns true if Day object is first in a Week
|
||||
* Only relevant when Day is created by Calendar_Month_Weekdays::build()
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function isFirst() {
|
||||
if ( method_exists($this->calendar,'isFirst') ) {
|
||||
function isFirst()
|
||||
{
|
||||
if (method_exists($this->calendar, 'isFirst')) {
|
||||
return $this->calendar->isFirst();
|
||||
}
|
||||
}
|
||||
|
@ -183,12 +220,13 @@ class Calendar_Decorator
|
|||
/**
|
||||
* Returns true if Day object is last in a Week
|
||||
* Only relevant when Day is created by Calendar_Month_Weekdays::build()
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function isLast()
|
||||
{
|
||||
if ( method_exists($this->calendar,'isLast') ) {
|
||||
if (method_exists($this->calendar, 'isLast')) {
|
||||
return $this->calendar->isLast();
|
||||
}
|
||||
}
|
||||
|
@ -196,31 +234,37 @@ class Calendar_Decorator
|
|||
/**
|
||||
* Defines Day object as empty
|
||||
* Only used by Calendar_Month_Weekdays::build()
|
||||
* @param boolean state
|
||||
*
|
||||
* @param boolean $state whether it's empty or not
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function setEmpty ($state = true)
|
||||
{
|
||||
if ( method_exists($this->calendar,'setEmpty') ) {
|
||||
if (method_exists($this->calendar, 'setEmpty')) {
|
||||
$this->calendar->setEmpty($state);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the current object is empty
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function isEmpty()
|
||||
{
|
||||
if ( method_exists($this->calendar,'isEmpty') ) {
|
||||
if (method_exists($this->calendar, 'isEmpty')) {
|
||||
return $this->calendar->isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the children
|
||||
* @param array containing Calendar objects to select (optional)
|
||||
*
|
||||
* @param array $sDates array containing Calendar objects to select (optional)
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
* @abstract
|
||||
|
@ -235,6 +279,7 @@ class Calendar_Decorator
|
|||
* (e.g. a minute from an hour object). On reaching the end of
|
||||
* the collection, returns false and resets the collection for
|
||||
* further iteratations.
|
||||
*
|
||||
* @return mixed either an object subclass of Calendar or false
|
||||
* @access public
|
||||
*/
|
||||
|
@ -245,6 +290,7 @@ class Calendar_Decorator
|
|||
|
||||
/**
|
||||
* Fetches all child from the current collection of children
|
||||
*
|
||||
* @return array
|
||||
* @access public
|
||||
*/
|
||||
|
@ -254,8 +300,8 @@ class Calendar_Decorator
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the number Calendar subclass objects stored in the internal
|
||||
* collection.
|
||||
* Get the number Calendar subclass objects stored in the internal collection
|
||||
*
|
||||
* @return int
|
||||
* @access public
|
||||
*/
|
||||
|
@ -266,8 +312,8 @@ class Calendar_Decorator
|
|||
|
||||
/**
|
||||
* Determine whether this date is valid, with the bounds determined by
|
||||
* the Calendar_Engine. The call is passed on to
|
||||
* Calendar_Validator::isValid
|
||||
* the Calendar_Engine. The call is passed on to Calendar_Validator::isValid
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
|
@ -278,6 +324,7 @@ class Calendar_Decorator
|
|||
|
||||
/**
|
||||
* Returns an instance of Calendar_Validator
|
||||
*
|
||||
* @return Calendar_Validator
|
||||
* @access public
|
||||
*/
|
||||
|
@ -290,17 +337,21 @@ class Calendar_Decorator
|
|||
/**
|
||||
* Returns a reference to the current Calendar_Engine being used. Useful
|
||||
* for Calendar_Table_Helper and Calendar_Validator
|
||||
*
|
||||
* @return object implementing Calendar_Engine_Inteface
|
||||
* @access private
|
||||
*/
|
||||
function & getEngine()
|
||||
{
|
||||
return $this->calendar->getEngine();
|
||||
$engine = $this->calendar->getEngine();
|
||||
return $engine;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value for the previous year
|
||||
* @param string return value format ['int' | 'timestamp' | 'object' | 'array']
|
||||
*
|
||||
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
|
||||
*
|
||||
* @return int e.g. 2002 or timestamp
|
||||
* @access public
|
||||
*/
|
||||
|
@ -311,7 +362,9 @@ class Calendar_Decorator
|
|||
|
||||
/**
|
||||
* Returns the value for this year
|
||||
* @param string return value format ['int' | 'timestamp' | 'object' | 'array']
|
||||
*
|
||||
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
|
||||
*
|
||||
* @return int e.g. 2003 or timestamp
|
||||
* @access public
|
||||
*/
|
||||
|
@ -322,7 +375,9 @@ class Calendar_Decorator
|
|||
|
||||
/**
|
||||
* Returns the value for next year
|
||||
* @param string return value format ['int' | 'timestamp' | 'object' | 'array']
|
||||
*
|
||||
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
|
||||
*
|
||||
* @return int e.g. 2004 or timestamp
|
||||
* @access public
|
||||
*/
|
||||
|
@ -333,7 +388,9 @@ class Calendar_Decorator
|
|||
|
||||
/**
|
||||
* Returns the value for the previous month
|
||||
* @param string return value format ['int' | 'timestamp' | 'object' | 'array']
|
||||
*
|
||||
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
|
||||
*
|
||||
* @return int e.g. 4 or Unix timestamp
|
||||
* @access public
|
||||
*/
|
||||
|
@ -344,7 +401,9 @@ class Calendar_Decorator
|
|||
|
||||
/**
|
||||
* Returns the value for this month
|
||||
* @param string return value format ['int' | 'timestamp' | 'object' | 'array']
|
||||
*
|
||||
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
|
||||
*
|
||||
* @return int e.g. 5 or timestamp
|
||||
* @access public
|
||||
*/
|
||||
|
@ -355,7 +414,9 @@ class Calendar_Decorator
|
|||
|
||||
/**
|
||||
* Returns the value for next month
|
||||
* @param string return value format ['int' | 'timestamp' | 'object' | 'array']
|
||||
*
|
||||
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
|
||||
*
|
||||
* @return int e.g. 6 or timestamp
|
||||
* @access public
|
||||
*/
|
||||
|
@ -366,16 +427,18 @@ class Calendar_Decorator
|
|||
|
||||
/**
|
||||
* Returns the value for the previous week
|
||||
* @param string return value format ['int' | 'timestamp' | 'object' | 'array']
|
||||
*
|
||||
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
|
||||
*
|
||||
* @return int e.g. 4 or Unix timestamp
|
||||
* @access public
|
||||
*/
|
||||
function prevWeek($format = 'n_in_month')
|
||||
{
|
||||
if ( method_exists($this->calendar,'prevWeek') ) {
|
||||
if ( method_exists($this->calendar, 'prevWeek')) {
|
||||
return $this->calendar->prevWeek($format);
|
||||
} else {
|
||||
require_once 'PEAR.php';
|
||||
include_once 'PEAR.php';
|
||||
PEAR::raiseError(
|
||||
'Cannot call prevWeek on Calendar object of type: '.
|
||||
get_class($this->calendar), 133, PEAR_ERROR_TRIGGER,
|
||||
|
@ -386,16 +449,18 @@ class Calendar_Decorator
|
|||
|
||||
/**
|
||||
* Returns the value for this week
|
||||
* @param string return value format ['int' | 'timestamp' | 'object' | 'array']
|
||||
*
|
||||
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
|
||||
*
|
||||
* @return int e.g. 5 or timestamp
|
||||
* @access public
|
||||
*/
|
||||
function thisWeek($format = 'n_in_month')
|
||||
{
|
||||
if ( method_exists($this->calendar,'thisWeek') ) {
|
||||
if ( method_exists($this->calendar, 'thisWeek')) {
|
||||
return $this->calendar->thisWeek($format);
|
||||
} else {
|
||||
require_once 'PEAR.php';
|
||||
include_once 'PEAR.php';
|
||||
PEAR::raiseError(
|
||||
'Cannot call thisWeek on Calendar object of type: '.
|
||||
get_class($this->calendar), 133, PEAR_ERROR_TRIGGER,
|
||||
|
@ -406,16 +471,18 @@ class Calendar_Decorator
|
|||
|
||||
/**
|
||||
* Returns the value for next week
|
||||
* @param string return value format ['int' | 'timestamp' | 'object' | 'array']
|
||||
*
|
||||
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
|
||||
*
|
||||
* @return int e.g. 6 or timestamp
|
||||
* @access public
|
||||
*/
|
||||
function nextWeek($format = 'n_in_month')
|
||||
{
|
||||
if ( method_exists($this->calendar,'nextWeek') ) {
|
||||
if ( method_exists($this->calendar, 'nextWeek')) {
|
||||
return $this->calendar->nextWeek($format);
|
||||
} else {
|
||||
require_once 'PEAR.php';
|
||||
include_once 'PEAR.php';
|
||||
PEAR::raiseError(
|
||||
'Cannot call thisWeek on Calendar object of type: '.
|
||||
get_class($this->calendar), 133, PEAR_ERROR_TRIGGER,
|
||||
|
@ -426,17 +493,22 @@ class Calendar_Decorator
|
|||
|
||||
/**
|
||||
* Returns the value for the previous day
|
||||
* @param string return value format ['int' | 'timestamp' | 'object' | 'array']
|
||||
*
|
||||
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
|
||||
*
|
||||
* @return int e.g. 10 or timestamp
|
||||
* @access public
|
||||
*/
|
||||
function prevDay($format = 'int') {
|
||||
function prevDay($format = 'int')
|
||||
{
|
||||
return $this->calendar->prevDay($format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value for this day
|
||||
* @param string return value format ['int' | 'timestamp' | 'object' | 'array']
|
||||
*
|
||||
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
|
||||
*
|
||||
* @return int e.g. 11 or timestamp
|
||||
* @access public
|
||||
*/
|
||||
|
@ -447,7 +519,9 @@ class Calendar_Decorator
|
|||
|
||||
/**
|
||||
* Returns the value for the next day
|
||||
* @param string return value format ['int' | 'timestamp' | 'object' | 'array']
|
||||
*
|
||||
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
|
||||
*
|
||||
* @return int e.g. 12 or timestamp
|
||||
* @access public
|
||||
*/
|
||||
|
@ -458,7 +532,9 @@ class Calendar_Decorator
|
|||
|
||||
/**
|
||||
* Returns the value for the previous hour
|
||||
* @param string return value format ['int' | 'timestamp' | 'object' | 'array']
|
||||
*
|
||||
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
|
||||
*
|
||||
* @return int e.g. 13 or timestamp
|
||||
* @access public
|
||||
*/
|
||||
|
@ -469,7 +545,9 @@ class Calendar_Decorator
|
|||
|
||||
/**
|
||||
* Returns the value for this hour
|
||||
* @param string return value format ['int' | 'timestamp' | 'object' | 'array']
|
||||
*
|
||||
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
|
||||
*
|
||||
* @return int e.g. 14 or timestamp
|
||||
* @access public
|
||||
*/
|
||||
|
@ -480,7 +558,9 @@ class Calendar_Decorator
|
|||
|
||||
/**
|
||||
* Returns the value for the next hour
|
||||
* @param string return value format ['int' | 'timestamp' | 'object' | 'array']
|
||||
*
|
||||
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
|
||||
*
|
||||
* @return int e.g. 14 or timestamp
|
||||
* @access public
|
||||
*/
|
||||
|
@ -491,7 +571,9 @@ class Calendar_Decorator
|
|||
|
||||
/**
|
||||
* Returns the value for the previous minute
|
||||
* @param string return value format ['int' | 'timestamp' | 'object' | 'array']
|
||||
*
|
||||
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
|
||||
*
|
||||
* @return int e.g. 23 or timestamp
|
||||
* @access public
|
||||
*/
|
||||
|
@ -502,7 +584,9 @@ class Calendar_Decorator
|
|||
|
||||
/**
|
||||
* Returns the value for this minute
|
||||
* @param string return value format ['int' | 'timestamp' | 'object' | 'array']
|
||||
*
|
||||
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
|
||||
*
|
||||
* @return int e.g. 24 or timestamp
|
||||
* @access public
|
||||
*/
|
||||
|
@ -513,18 +597,22 @@ class Calendar_Decorator
|
|||
|
||||
/**
|
||||
* Returns the value for the next minute
|
||||
* @param string return value format ['int' | 'timestamp' | 'object' | 'array']
|
||||
*
|
||||
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
|
||||
*
|
||||
* @return int e.g. 25 or timestamp
|
||||
* @access public
|
||||
*/
|
||||
function nextMinute($format = 'int')
|
||||
function nextMinute($format = 'int')
|
||||
{
|
||||
return $this->calendar->nextMinute($format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value for the previous second
|
||||
* @param string return value format ['int' | 'timestamp' | 'object' | 'array']
|
||||
*
|
||||
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
|
||||
*
|
||||
* @return int e.g. 43 or timestamp
|
||||
* @access public
|
||||
*/
|
||||
|
@ -535,7 +623,9 @@ class Calendar_Decorator
|
|||
|
||||
/**
|
||||
* Returns the value for this second
|
||||
* @param string return value format ['int' | 'timestamp' | 'object' | 'array']
|
||||
*
|
||||
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
|
||||
*
|
||||
* @return int e.g. 44 or timestamp
|
||||
* @access public
|
||||
*/
|
||||
|
@ -546,7 +636,9 @@ class Calendar_Decorator
|
|||
|
||||
/**
|
||||
* Returns the value for the next second
|
||||
* @param string return value format ['int' | 'timestamp' | 'object' | 'array']
|
||||
*
|
||||
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
|
||||
*
|
||||
* @return int e.g. 45 or timestamp
|
||||
* @access public
|
||||
*/
|
||||
|
|
|
@ -1,28 +1,40 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
|
||||
// | Lorenzo Alberton <l dot alberton at quipo dot it> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Textual.php,v 1.3 2004/08/16 13:02:44 hfuecks Exp $
|
||||
//
|
||||
|
||||
/**
|
||||
* @package Calendar
|
||||
* @version $Id: Textual.php,v 1.3 2004/08/16 13:02:44 hfuecks Exp $
|
||||
* Contains the Calendar_Decorator_Wrapper class
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "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 FREEBSD PROJECT 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 Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
||||
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @version CVS: $Id: Textual.php,v 1.8 2007/11/24 11:04:24 quipo Exp $
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -48,14 +60,23 @@ require_once CALENDAR_ROOT.'Util'.DIRECTORY_SEPARATOR.'Textual.php';
|
|||
* days of the week.
|
||||
* <b>Note:</b> for performance you should prefer Calendar_Util_Textual unless you
|
||||
* have a specific need to use a decorator
|
||||
* @package Calendar
|
||||
* @access public
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
||||
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Decorator_Textual extends Calendar_Decorator
|
||||
{
|
||||
/**
|
||||
* Constructs Calendar_Decorator_Textual
|
||||
* @param object subclass of Calendar
|
||||
*
|
||||
* @param object &$Calendar subclass of Calendar
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function Calendar_Decorator_Textual(&$Calendar)
|
||||
|
@ -65,105 +86,123 @@ class Calendar_Decorator_Textual extends Calendar_Decorator
|
|||
|
||||
/**
|
||||
* Returns an array of 12 month names (first index = 1)
|
||||
* @param string (optional) format of returned months (one,two,short or long)
|
||||
*
|
||||
* @param string $format (optional) format of returned months (one|two|short|long)
|
||||
*
|
||||
* @return array
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function monthNames($format='long')
|
||||
function monthNames($format = 'long')
|
||||
{
|
||||
return Calendar_Util_Textual::monthNames($format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of 7 week day names (first index = 0)
|
||||
* @param string (optional) format of returned days (one,two,short or long)
|
||||
*
|
||||
* @param string $format (optional) format of returned days (one|two|short|long)
|
||||
*
|
||||
* @return array
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function weekdayNames($format='long')
|
||||
function weekdayNames($format = 'long')
|
||||
{
|
||||
return Calendar_Util_Textual::weekdayNames($format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns textual representation of the previous month of the decorated calendar object
|
||||
* @param string (optional) format of returned months (one,two,short or long)
|
||||
*
|
||||
* @param string $format (optional) format of returned months (one|two|short|long)
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function prevMonthName($format='long')
|
||||
function prevMonthName($format = 'long')
|
||||
{
|
||||
return Calendar_Util_Textual::prevMonthName($this->calendar,$format);
|
||||
return Calendar_Util_Textual::prevMonthName($this->calendar, $format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns textual representation of the month of the decorated calendar object
|
||||
* @param string (optional) format of returned months (one,two,short or long)
|
||||
*
|
||||
* @param string $format (optional) format of returned months (one|two|short|long)
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function thisMonthName($format='long')
|
||||
function thisMonthName($format = 'long')
|
||||
{
|
||||
return Calendar_Util_Textual::thisMonthName($this->calendar,$format);
|
||||
return Calendar_Util_Textual::thisMonthName($this->calendar, $format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns textual representation of the next month of the decorated calendar object
|
||||
* @param string (optional) format of returned months (one,two,short or long)
|
||||
*
|
||||
* @param string $format (optional) format of returned months (one|two|short|long)
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function nextMonthName($format='long')
|
||||
function nextMonthName($format = 'long')
|
||||
{
|
||||
return Calendar_Util_Textual::nextMonthName($this->calendar,$format);
|
||||
return Calendar_Util_Textual::nextMonthName($this->calendar, $format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns textual representation of the previous day of week of the decorated calendar object
|
||||
* @param string (optional) format of returned months (one,two,short or long)
|
||||
*
|
||||
* @param string $format (optional) format of returned months (one|two|short|long)
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function prevDayName($format='long')
|
||||
function prevDayName($format = 'long')
|
||||
{
|
||||
return Calendar_Util_Textual::prevDayName($this->calendar,$format);
|
||||
return Calendar_Util_Textual::prevDayName($this->calendar, $format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns textual representation of the day of week of the decorated calendar object
|
||||
* @param string (optional) format of returned months (one,two,short or long)
|
||||
*
|
||||
* @param string $format (optional) format of returned months (one|two|short|long)
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function thisDayName($format='long')
|
||||
function thisDayName($format = 'long')
|
||||
{
|
||||
return Calendar_Util_Textual::thisDayName($this->calendar,$format);
|
||||
return Calendar_Util_Textual::thisDayName($this->calendar, $format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns textual representation of the next day of week of the decorated calendar object
|
||||
* @param string (optional) format of returned months (one,two,short or long)
|
||||
*
|
||||
* @param string $format (optional) format of returned months (one|two|short|long)
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function nextDayName($format='long')
|
||||
function nextDayName($format = 'long')
|
||||
{
|
||||
return Calendar_Util_Textual::nextDayName($this->calendar,$format);
|
||||
return Calendar_Util_Textual::nextDayName($this->calendar, $format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the days of the week using the order defined in the decorated
|
||||
* calendar object. Only useful for Calendar_Month_Weekdays, Calendar_Month_Weeks
|
||||
* and Calendar_Week. Otherwise the returned array will begin on Sunday
|
||||
* @param string (optional) format of returned months (one,two,short or long)
|
||||
*
|
||||
* @param string $format (optional) format of returned months (one|two|short|long)
|
||||
*
|
||||
* @return array ordered array of week day names
|
||||
* @access public
|
||||
*/
|
||||
function orderedWeekdays($format='long')
|
||||
function orderedWeekdays($format = 'long')
|
||||
{
|
||||
return Calendar_Util_Textual::orderedWeekdays($this->calendar,$format);
|
||||
return Calendar_Util_Textual::orderedWeekdays($this->calendar, $format);
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -1,28 +1,40 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
|
||||
// | Lorenzo Alberton <l dot alberton at quipo dot it> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Uri.php,v 1.3 2004/08/16 09:04:20 hfuecks Exp $
|
||||
//
|
||||
|
||||
/**
|
||||
* @package Calendar
|
||||
* @version $Id: Uri.php,v 1.3 2004/08/16 09:04:20 hfuecks Exp $
|
||||
* Contains the Calendar_Decorator_Uri class
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "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 FREEBSD PROJECT 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 Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
||||
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @version CVS: $Id: Uri.php,v 1.8 2007/11/18 21:46:43 quipo Exp $
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -53,22 +65,31 @@ require_once CALENDAR_ROOT.'Util'.DIRECTORY_SEPARATOR.'Uri.php';
|
|||
* $Uri->setFragments('year', 'month', 'day');
|
||||
* echo $Uri->getPrev(); // Displays year=2003&month=10&day=22
|
||||
* </code>
|
||||
* @see Calendar_Util_Uri
|
||||
* @package Calendar
|
||||
* @access public
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
||||
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
* @see Calendar_Util_Uri
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Decorator_Uri extends Calendar_Decorator
|
||||
{
|
||||
|
||||
/**
|
||||
* @var Calendar_Util_Uri
|
||||
* @access private
|
||||
*/
|
||||
* @var Calendar_Util_Uri
|
||||
* @access private
|
||||
*/
|
||||
var $Uri;
|
||||
|
||||
/**
|
||||
* Constructs Calendar_Decorator_Uri
|
||||
* @param object subclass of Calendar
|
||||
*
|
||||
* @param object &$Calendar subclass of Calendar
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function Calendar_Decorator_Uri(&$Calendar)
|
||||
|
@ -78,22 +99,27 @@ class Calendar_Decorator_Uri extends Calendar_Decorator
|
|||
|
||||
/**
|
||||
* Sets the URI fragment names
|
||||
* @param string URI fragment for year
|
||||
* @param string (optional) URI fragment for month
|
||||
* @param string (optional) URI fragment for day
|
||||
* @param string (optional) URI fragment for hour
|
||||
* @param string (optional) URI fragment for minute
|
||||
* @param string (optional) URI fragment for second
|
||||
*
|
||||
* @param string $y URI fragment for year
|
||||
* @param string $m (optional) URI fragment for month
|
||||
* @param string $d (optional) URI fragment for day
|
||||
* @param string $h (optional) URI fragment for hour
|
||||
* @param string $i (optional) URI fragment for minute
|
||||
* @param string $s (optional) URI fragment for second
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function setFragments($y, $m=null, $d=null, $h=null, $i=null, $s=null) {
|
||||
function setFragments($y, $m = null, $d = null, $h = null, $i = null, $s = null)
|
||||
{
|
||||
$this->Uri = & new Calendar_Util_Uri($y, $m, $d, $h, $i, $s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the separator string between fragments
|
||||
* @param string separator e.g. /
|
||||
*
|
||||
* @param string $separator url fragment separator e.g. /
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
|
@ -103,20 +129,23 @@ class Calendar_Decorator_Uri extends Calendar_Decorator
|
|||
}
|
||||
|
||||
/**
|
||||
* Puts Uri decorator into "scalar mode" - URI variable names are not
|
||||
* returned
|
||||
* @param boolean (optional)
|
||||
* Puts Uri decorator into "scalar mode" - URI variable names are not returned
|
||||
*
|
||||
* @param boolean $state (optional)
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function setScalar($state=true)
|
||||
function setScalar($state = true)
|
||||
{
|
||||
$this->Uri->scalar = $state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the URI string for the previous calendar unit
|
||||
* @param string calendar unit to fetch uri for (year,month,week or day etc)
|
||||
*
|
||||
* @param string $method calendar unit to fetch uri for (year, month, week or day etc)
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
|
@ -127,7 +156,9 @@ class Calendar_Decorator_Uri extends Calendar_Decorator
|
|||
|
||||
/**
|
||||
* Gets the URI string for the current calendar unit
|
||||
* @param string calendar unit to fetch uri for (year,month,week or day etc)
|
||||
*
|
||||
* @param string $method calendar unit to fetch uri for (year,month,week or day etc)
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
|
@ -138,7 +169,9 @@ class Calendar_Decorator_Uri extends Calendar_Decorator
|
|||
|
||||
/**
|
||||
* Gets the URI string for the next calendar unit
|
||||
* @param string calendar unit to fetch uri for (year,month,week or day etc)
|
||||
*
|
||||
* @param string $method calendar unit to fetch uri for (year,month,week or day etc)
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
|
@ -146,6 +179,5 @@ class Calendar_Decorator_Uri extends Calendar_Decorator
|
|||
{
|
||||
return $this->Uri->next($this, $method);
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
|
@ -1,28 +1,40 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
|
||||
// | Lorenzo Alberton <l dot alberton at quipo dot it> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Weekday.php,v 1.3 2004/08/16 12:25:15 hfuecks Exp $
|
||||
//
|
||||
|
||||
/**
|
||||
* @package Calendar
|
||||
* @version $Id: Weekday.php,v 1.3 2004/08/16 12:25:15 hfuecks Exp $
|
||||
* Contains the Calendar_Decorator_Weekday class
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "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 FREEBSD PROJECT 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 Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
||||
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @version CVS: $Id: Weekday.php,v 1.8 2007/11/24 11:04:24 quipo Exp $
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -50,8 +62,15 @@ require_once CALENDAR_ROOT.'Day.php';
|
|||
* $Weekday->setFirstDay(0); // Set first day of week to Sunday (default Mon)
|
||||
* echo $Weekday->thisWeekDay(); // Displays 5 - fifth day of week relative to Sun
|
||||
* </code>
|
||||
* @package Calendar
|
||||
* @access public
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
||||
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Decorator_Weekday extends Calendar_Decorator
|
||||
{
|
||||
|
@ -64,84 +83,112 @@ class Calendar_Decorator_Weekday extends Calendar_Decorator
|
|||
|
||||
/**
|
||||
* Constructs Calendar_Decorator_Weekday
|
||||
* @param object subclass of Calendar
|
||||
*
|
||||
* @param object &$Calendar subclass of Calendar
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function Calendar_Decorator_Weekday(& $Calendar)
|
||||
function Calendar_Decorator_Weekday(&$Calendar)
|
||||
{
|
||||
parent::Calendar_Decorator($Calendar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the first day of the week (0 = Sunday, 1 = Monday (default) etc)
|
||||
* @param int first day of week
|
||||
*
|
||||
* @param int $firstDay first day of week
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function setFirstDay($firstDay) {
|
||||
function setFirstDay($firstDay)
|
||||
{
|
||||
$this->firstDay = (int)$firstDay;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the previous weekday
|
||||
* @param string (default = 'int') return value format
|
||||
* @return int numeric day of week or timestamp
|
||||
*
|
||||
* @param string $format (default = 'int') return value format
|
||||
*
|
||||
* @return int $format numeric day of week or timestamp
|
||||
* @access public
|
||||
*/
|
||||
function prevWeekDay($format = 'int')
|
||||
{
|
||||
$ts = $this->calendar->prevDay('timestamp');
|
||||
$Day = new Calendar_Day(2000,1,1);
|
||||
$ts = $this->calendar->prevDay('timestamp');
|
||||
$Day = new Calendar_Day(2000, 1, 1);
|
||||
$Day->setTimeStamp($ts);
|
||||
$day = $this->calendar->cE->getDayOfWeek($Day->thisYear(),$Day->thisMonth(),$Day->thisDay());
|
||||
$day = $this->calendar->cE->getDayOfWeek(
|
||||
$Day->thisYear(),
|
||||
$Day->thisMonth(),
|
||||
$Day->thisDay()
|
||||
);
|
||||
$day = $this->adjustWeekScale($day);
|
||||
return $this->returnValue('Day', $format, $ts, $day);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current weekday
|
||||
* @param string (default = 'int') return value format
|
||||
*
|
||||
* @param string $format (default = 'int') return value format
|
||||
*
|
||||
* @return int numeric day of week or timestamp
|
||||
* @access public
|
||||
*/
|
||||
function thisWeekDay($format = 'int')
|
||||
{
|
||||
$ts = $this->calendar->thisDay('timestamp');
|
||||
$day = $this->calendar->cE->getDayOfWeek($this->calendar->year,$this->calendar->month,$this->calendar->day);
|
||||
$ts = $this->calendar->thisDay('timestamp');
|
||||
$day = $this->calendar->cE->getDayOfWeek(
|
||||
$this->calendar->year,
|
||||
$this->calendar->month,
|
||||
$this->calendar->day
|
||||
);
|
||||
$day = $this->adjustWeekScale($day);
|
||||
return $this->returnValue('Day', $format, $ts, $day);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next weekday
|
||||
* @param string (default = 'int') return value format
|
||||
*
|
||||
* @param string $format (default = 'int') return value format
|
||||
*
|
||||
* @return int numeric day of week or timestamp
|
||||
* @access public
|
||||
*/
|
||||
function nextWeekDay($format = 'int')
|
||||
{
|
||||
$ts = $this->calendar->nextDay('timestamp');
|
||||
$Day = new Calendar_Day(2000,1,1);
|
||||
$ts = $this->calendar->nextDay('timestamp');
|
||||
$Day = new Calendar_Day(2000, 1, 1);
|
||||
$Day->setTimeStamp($ts);
|
||||
$day = $this->calendar->cE->getDayOfWeek($Day->thisYear(),$Day->thisMonth(),$Day->thisDay());
|
||||
$day = $this->calendar->cE->getDayOfWeek(
|
||||
$Day->thisYear(),
|
||||
$Day->thisMonth(),
|
||||
$Day->thisDay()
|
||||
);
|
||||
$day = $this->adjustWeekScale($day);
|
||||
return $this->returnValue('Day', $format, $ts, $day);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjusts the day of the week relative to the first day of the week
|
||||
* @param int day of week calendar from Calendar_Engine
|
||||
*
|
||||
* @param int $dayOfWeek day of week calendar from Calendar_Engine
|
||||
*
|
||||
* @return int day of week adjusted to first day
|
||||
* @access private
|
||||
*/
|
||||
function adjustWeekScale($dayOfWeek) {
|
||||
function adjustWeekScale($dayOfWeek)
|
||||
{
|
||||
$dayOfWeek = $dayOfWeek - $this->firstDay;
|
||||
if ( $dayOfWeek >= 0 ) {
|
||||
if ($dayOfWeek >= 0) {
|
||||
return $dayOfWeek;
|
||||
} else {
|
||||
return $this->calendar->cE->getDaysInWeek(
|
||||
$this->calendar->year,$this->calendar->month,$this->calendar->day
|
||||
) + $dayOfWeek;
|
||||
$this->calendar->year,
|
||||
$this->calendar->month,
|
||||
$this->calendar->day
|
||||
) + $dayOfWeek;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,28 +1,40 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
|
||||
// | Lorenzo Alberton <l dot alberton at quipo dot it> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Wrapper.php,v 1.2 2005/11/03 20:35:03 quipo Exp $
|
||||
//
|
||||
|
||||
/**
|
||||
* @package Calendar
|
||||
* @version $Id: Wrapper.php,v 1.2 2005/11/03 20:35:03 quipo Exp $
|
||||
* Contains the Calendar_Decorator_Wrapper class
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "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 FREEBSD PROJECT 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 Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
||||
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @version CVS: $Id: Wrapper.php,v 1.5 2007/10/31 18:27:03 quipo Exp $
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -40,14 +52,23 @@ require_once CALENDAR_ROOT.'Decorator.php';
|
|||
|
||||
/**
|
||||
* Decorator to help with wrapping built children in another decorator
|
||||
* @package Calendar
|
||||
* @access public
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
||||
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Decorator_Wrapper extends Calendar_Decorator
|
||||
{
|
||||
/**
|
||||
* Constructs Calendar_Decorator_Wrapper
|
||||
* @param object subclass of Calendar
|
||||
*
|
||||
* @param object &$Calendar subclass of Calendar
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function Calendar_Decorator_Wrapper(&$Calendar)
|
||||
|
@ -57,7 +78,9 @@ class Calendar_Decorator_Wrapper extends Calendar_Decorator
|
|||
|
||||
/**
|
||||
* Wraps objects returned from fetch in the named Decorator class
|
||||
* @param string name of Decorator class to wrap with
|
||||
*
|
||||
* @param string $decorator name of Decorator class to wrap with
|
||||
*
|
||||
* @return object instance of named decorator
|
||||
* @access public
|
||||
*/
|
||||
|
@ -74,7 +97,9 @@ class Calendar_Decorator_Wrapper extends Calendar_Decorator
|
|||
|
||||
/**
|
||||
* Wraps the returned calendar objects from fetchAll in the named decorator
|
||||
* @param string name of Decorator class to wrap with
|
||||
*
|
||||
* @param string $decorator name of Decorator class to wrap with
|
||||
*
|
||||
* @return array
|
||||
* @access public
|
||||
*/
|
||||
|
|
|
@ -1,32 +1,53 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Interface.php,v 1.5 2004/08/16 12:29:18 hfuecks Exp $
|
||||
//
|
||||
|
||||
/**
|
||||
* @package Calendar
|
||||
* @version $Id: Interface.php,v 1.5 2004/08/16 12:29:18 hfuecks Exp $
|
||||
* Contains the Calendar_Engine_Interface class (interface)
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "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 FREEBSD PROJECT 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 Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
||||
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @version CVS: $Id: Interface.php,v 1.10 2008/11/15 21:21:42 quipo Exp $
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
*/
|
||||
|
||||
/**
|
||||
* The methods the classes implementing the Calendar_Engine must implement.
|
||||
* Note this class is not used but simply to help development
|
||||
* @package Calendar
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
||||
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
* @access protected
|
||||
*/
|
||||
class Calendar_Engine_Interface
|
||||
|
@ -36,7 +57,9 @@ class Calendar_Engine_Interface
|
|||
* into human dates is only performed once per timestamp.
|
||||
* Typically called "internally" by methods like stampToYear.
|
||||
* Return value can vary, depending on the specific implementation
|
||||
* @param int timestamp (depending on implementation)
|
||||
*
|
||||
* @param int $stamp timestamp (depending on implementation)
|
||||
*
|
||||
* @return mixed
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -46,7 +69,9 @@ class Calendar_Engine_Interface
|
|||
|
||||
/**
|
||||
* Returns a numeric year given a timestamp
|
||||
* @param int timestamp (depending on implementation)
|
||||
*
|
||||
* @param int $stamp timestamp (depending on implementation)
|
||||
*
|
||||
* @return int year (e.g. 2003)
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -56,7 +81,9 @@ class Calendar_Engine_Interface
|
|||
|
||||
/**
|
||||
* Returns a numeric month given a timestamp
|
||||
* @param int timestamp (depending on implementation)
|
||||
*
|
||||
* @param int $stamp timestamp (depending on implementation)
|
||||
*
|
||||
* @return int month (e.g. 9)
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -66,7 +93,9 @@ class Calendar_Engine_Interface
|
|||
|
||||
/**
|
||||
* Returns a numeric day given a timestamp
|
||||
* @param int timestamp (depending on implementation)
|
||||
*
|
||||
* @param int $stamp timestamp (depending on implementation)
|
||||
*
|
||||
* @return int day (e.g. 15)
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -76,7 +105,9 @@ class Calendar_Engine_Interface
|
|||
|
||||
/**
|
||||
* Returns a numeric hour given a timestamp
|
||||
* @param int timestamp (depending on implementation)
|
||||
*
|
||||
* @param int $stamp timestamp (depending on implementation)
|
||||
*
|
||||
* @return int hour (e.g. 13)
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -86,7 +117,9 @@ class Calendar_Engine_Interface
|
|||
|
||||
/**
|
||||
* Returns a numeric minute given a timestamp
|
||||
* @param int timestamp (depending on implementation)
|
||||
*
|
||||
* @param int $stamp timestamp (depending on implementation)
|
||||
*
|
||||
* @return int minute (e.g. 34)
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -96,7 +129,9 @@ class Calendar_Engine_Interface
|
|||
|
||||
/**
|
||||
* Returns a numeric second given a timestamp
|
||||
* @param int timestamp (depending on implementation)
|
||||
*
|
||||
* @param int $stamp timestamp (depending on implementation)
|
||||
*
|
||||
* @return int second (e.g. 51)
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -105,25 +140,27 @@ class Calendar_Engine_Interface
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns a timestamp. Can be worth "caching" generated
|
||||
* timestamps in a static variable, identified by the
|
||||
* params this method accepts, to timestamp will only
|
||||
* be calculated once.
|
||||
* @param int year (e.g. 2003)
|
||||
* @param int month (e.g. 9)
|
||||
* @param int day (e.g. 13)
|
||||
* @param int hour (e.g. 13)
|
||||
* @param int minute (e.g. 34)
|
||||
* @param int second (e.g. 53)
|
||||
* Returns a timestamp. Can be worth "caching" generated timestamps in a
|
||||
* static variable, identified by the params this method accepts,
|
||||
* to timestamp will only be calculated once.
|
||||
*
|
||||
* @param int $y year (e.g. 2003)
|
||||
* @param int $m month (e.g. 9)
|
||||
* @param int $d day (e.g. 13)
|
||||
* @param int $h hour (e.g. 13)
|
||||
* @param int $i minute (e.g. 34)
|
||||
* @param int $s second (e.g. 53)
|
||||
*
|
||||
* @return int (depends on implementation)
|
||||
* @access protected
|
||||
*/
|
||||
function dateToStamp($y,$m,$d,$h,$i,$s)
|
||||
function dateToStamp($y, $m, $d, $h, $i, $s)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* The upper limit on years that the Calendar Engine can work with
|
||||
*
|
||||
* @return int (e.g. 2037)
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -133,6 +170,7 @@ class Calendar_Engine_Interface
|
|||
|
||||
/**
|
||||
* The lower limit on years that the Calendar Engine can work with
|
||||
*
|
||||
* @return int (e.g 1902)
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -142,7 +180,9 @@ class Calendar_Engine_Interface
|
|||
|
||||
/**
|
||||
* Returns the number of months in a year
|
||||
* @param int (optional) year to get months for
|
||||
*
|
||||
* @param int $y (optional) year to get months for
|
||||
*
|
||||
* @return int (e.g. 12)
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -152,8 +192,10 @@ class Calendar_Engine_Interface
|
|||
|
||||
/**
|
||||
* Returns the number of days in a month, given year and month
|
||||
* @param int year (e.g. 2003)
|
||||
* @param int month (e.g. 9)
|
||||
*
|
||||
* @param int $y year (e.g. 2003)
|
||||
* @param int $m month (e.g. 9)
|
||||
*
|
||||
* @return int days in month
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -164,8 +206,10 @@ class Calendar_Engine_Interface
|
|||
/**
|
||||
* Returns numeric representation of the day of the week in a month,
|
||||
* given year and month
|
||||
* @param int year (e.g. 2003)
|
||||
* @param int month (e.g. 9)
|
||||
*
|
||||
* @param int $y year (e.g. 2003)
|
||||
* @param int $m month (e.g. 9)
|
||||
*
|
||||
* @return int
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -175,21 +219,25 @@ class Calendar_Engine_Interface
|
|||
|
||||
/**
|
||||
* Returns the number of days in a week
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @param int day (4)
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
*
|
||||
* @return int (e.g. 7)
|
||||
* @access protected
|
||||
*/
|
||||
function getDaysInWeek($y=NULL, $m=NULL, $d=NULL)
|
||||
function getDaysInWeek($y=null, $m=null, $d=null)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of the week in the year (ISO-8601), given a date
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @param int day (4)
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
*
|
||||
* @return int week number
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -199,10 +247,12 @@ class Calendar_Engine_Interface
|
|||
|
||||
/**
|
||||
* Returns the number of the week in the month, given a date
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @param int day (4)
|
||||
* @param int first day of the week (default: 1 - monday)
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
* @param int $firstDay first day of the week (default: 1 - monday)
|
||||
*
|
||||
* @return int week number
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -212,9 +262,10 @@ class Calendar_Engine_Interface
|
|||
|
||||
/**
|
||||
* Returns the number of weeks in the month
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @param int first day of the week (default: 1 - monday)
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
*
|
||||
* @return int weeks number
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -224,9 +275,11 @@ class Calendar_Engine_Interface
|
|||
|
||||
/**
|
||||
* Returns the number of the day of the week (0=sunday, 1=monday...)
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @param int day (4)
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
*
|
||||
* @return int weekday number
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -236,33 +289,41 @@ class Calendar_Engine_Interface
|
|||
|
||||
/**
|
||||
* Returns the numeric values of the days of the week.
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @param int day (4)
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
*
|
||||
* @return array list of numeric values of days in week, beginning 0
|
||||
* @access protected
|
||||
*/
|
||||
function getWeekDays($y=NULL, $m=NULL, $d=NULL)
|
||||
function getWeekDays($y=null, $m=null, $d=null)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default first day of the week as an integer. Must be a
|
||||
* member of the array returned from getWeekDays
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @param int day (4)
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
*
|
||||
* @return int (e.g. 1 for Monday)
|
||||
* @see getWeekDays
|
||||
* @access protected
|
||||
*/
|
||||
function getFirstDayOfWeek($y=NULL, $m=NULL, $d=NULL)
|
||||
function getFirstDayOfWeek($y=null, $m=null, $d=null)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of hours in a day<br>
|
||||
* @param int (optional) day to get hours for
|
||||
* Returns the number of hours in a day
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
*
|
||||
* @return int (e.g. 24)
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -272,7 +333,12 @@ class Calendar_Engine_Interface
|
|||
|
||||
/**
|
||||
* Returns the number of minutes in an hour
|
||||
* @param int (optional) hour to get minutes for
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
* @param int $h hour
|
||||
*
|
||||
* @return int
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -282,12 +348,30 @@ class Calendar_Engine_Interface
|
|||
|
||||
/**
|
||||
* Returns the number of seconds in a minutes
|
||||
* @param int (optional) minute to get seconds for
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
* @param int $h hour
|
||||
* @param int $i minute
|
||||
*
|
||||
* @return int
|
||||
* @access protected
|
||||
*/
|
||||
function getSecondsInMinute($y=null,$m=null,$d=null,$h=null,$i=null)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given day is the current day
|
||||
*
|
||||
* @param int timestamp (depending on implementation)
|
||||
*
|
||||
* @return boolean
|
||||
* @access protected
|
||||
*/
|
||||
function isToday($stamp)
|
||||
{
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -1,28 +1,41 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Lorenzo Alberton <l dot alberton at quipo dot it> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: PearDate.php,v 1.8 2004/08/20 20:00:55 quipo Exp $
|
||||
//
|
||||
|
||||
/**
|
||||
* @package Calendar
|
||||
* @version $Id: PearDate.php,v 1.8 2004/08/20 20:00:55 quipo Exp $
|
||||
* Contains the Calendar_Engine_PearDate class
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "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 FREEBSD PROJECT 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 Date and Time
|
||||
* @package Calendar
|
||||
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
||||
* @copyright 2003-2007 Lorenzo Alberton
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @version CVS: $Id: PearDate.php,v 1.14 2008/11/15 21:41:38 quipo Exp $
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
*/
|
||||
|
||||
/**
|
||||
* Load PEAR::Date class
|
||||
*/
|
||||
|
@ -31,7 +44,13 @@ require_once 'Date.php';
|
|||
/**
|
||||
* Performs calendar calculations based on the PEAR::Date class
|
||||
* Timestamps are in the ISO-8601 format (YYYY-MM-DD HH:MM:SS)
|
||||
* @package Calendar
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
||||
* @copyright 2003-2007 Lorenzo Alberton
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
* @access protected
|
||||
*/
|
||||
class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
|
||||
|
@ -40,7 +59,9 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
|
|||
* Makes sure a given timestamp is only ever parsed once
|
||||
* Uses a static variable to prevent date() being used twice
|
||||
* for a date which is already known
|
||||
* @param mixed Any timestamp format recognized by Pear::Date
|
||||
*
|
||||
* @param mixed $stamp Any timestamp format recognized by Pear::Date
|
||||
*
|
||||
* @return object Pear::Date object
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -55,7 +76,9 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
|
|||
|
||||
/**
|
||||
* Returns a numeric year given a iso-8601 datetime
|
||||
* @param string iso-8601 datetime (YYYY-MM-DD HH:MM:SS)
|
||||
*
|
||||
* @param string $stamp iso-8601 datetime (YYYY-MM-DD HH:MM:SS)
|
||||
*
|
||||
* @return int year (e.g. 2003)
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -67,7 +90,9 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
|
|||
|
||||
/**
|
||||
* Returns a numeric month given a iso-8601 datetime
|
||||
* @param string iso-8601 datetime (YYYY-MM-DD HH:MM:SS)
|
||||
*
|
||||
* @param string $stamp iso-8601 datetime (YYYY-MM-DD HH:MM:SS)
|
||||
*
|
||||
* @return int month (e.g. 9)
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -79,7 +104,9 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
|
|||
|
||||
/**
|
||||
* Returns a numeric day given a iso-8601 datetime
|
||||
* @param string iso-8601 datetime (YYYY-MM-DD HH:MM:SS)
|
||||
*
|
||||
* @param string $stamp iso-8601 datetime (YYYY-MM-DD HH:MM:SS)
|
||||
*
|
||||
* @return int day (e.g. 15)
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -91,7 +118,9 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
|
|||
|
||||
/**
|
||||
* Returns a numeric hour given a iso-8601 datetime
|
||||
* @param string iso-8601 datetime (YYYY-MM-DD HH:MM:SS)
|
||||
*
|
||||
* @param string $stamp iso-8601 datetime (YYYY-MM-DD HH:MM:SS)
|
||||
*
|
||||
* @return int hour (e.g. 13)
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -103,7 +132,9 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
|
|||
|
||||
/**
|
||||
* Returns a numeric minute given a iso-8601 datetime
|
||||
* @param string iso-8601 datetime (YYYY-MM-DD HH:MM:SS)
|
||||
*
|
||||
* @param string $stamp iso-8601 datetime (YYYY-MM-DD HH:MM:SS)
|
||||
*
|
||||
* @return int minute (e.g. 34)
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -115,7 +146,9 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
|
|||
|
||||
/**
|
||||
* Returns a numeric second given a iso-8601 datetime
|
||||
* @param string iso-8601 datetime (YYYY-MM-DD HH:MM:SS)
|
||||
*
|
||||
* @param string $stamp iso-8601 datetime (YYYY-MM-DD HH:MM:SS)
|
||||
*
|
||||
* @return int second (e.g. 51)
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -127,12 +160,14 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
|
|||
|
||||
/**
|
||||
* Returns a iso-8601 datetime
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @param int day (13)
|
||||
* @param int hour (13)
|
||||
* @param int minute (34)
|
||||
* @param int second (53)
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (13)
|
||||
* @param int $h hour (13)
|
||||
* @param int $i minute (34)
|
||||
* @param int $s second (53)
|
||||
*
|
||||
* @return string iso-8601 datetime
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -150,12 +185,15 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
|
|||
|
||||
/**
|
||||
* Set the correct date values (useful for math operations on dates)
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @param int day (13)
|
||||
* @param int hour (13)
|
||||
* @param int minute (34)
|
||||
* @param int second (53)
|
||||
*
|
||||
* @param int &$y year (2003)
|
||||
* @param int &$m month (9)
|
||||
* @param int &$d day (13)
|
||||
* @param int &$h hour (13)
|
||||
* @param int &$i minute (34)
|
||||
* @param int &$s second (53)
|
||||
*
|
||||
* @return void
|
||||
* @access protected
|
||||
*/
|
||||
function adjustDate(&$y, &$m, &$d, &$h, &$i, &$s)
|
||||
|
@ -209,6 +247,7 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
|
|||
|
||||
/**
|
||||
* The upper limit on years that the Calendar Engine can work with
|
||||
*
|
||||
* @return int 9999
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -219,6 +258,7 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
|
|||
|
||||
/**
|
||||
* The lower limit on years that the Calendar Engine can work with
|
||||
*
|
||||
* @return int 0
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -229,6 +269,9 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
|
|||
|
||||
/**
|
||||
* Returns the number of months in a year
|
||||
*
|
||||
* @param int $y year
|
||||
*
|
||||
* @return int (12)
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -239,8 +282,10 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
|
|||
|
||||
/**
|
||||
* Returns the number of days in a month, given year and month
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
*
|
||||
* @return int days in month
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -252,8 +297,10 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
|
|||
/**
|
||||
* Returns numeric representation of the day of the week in a month,
|
||||
* given year and month
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
*
|
||||
* @return int from 0 to 7
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -264,36 +311,44 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
|
|||
|
||||
/**
|
||||
* Returns the number of days in a week
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @param int day (4)
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
*
|
||||
* @return int (7)
|
||||
* @access protected
|
||||
*/
|
||||
function getDaysInWeek($y=NULL, $m=NULL, $d=NULL)
|
||||
function getDaysInWeek($y=null, $m=null, $d=null)
|
||||
{
|
||||
return 7;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of the week in the year (ISO-8601), given a date
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @param int day (4)
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
*
|
||||
* @return int week number
|
||||
* @access protected
|
||||
*/
|
||||
function getWeekNInYear($y, $m, $d)
|
||||
{
|
||||
return Date_Calc::weekOfYear($d, $m, $y); //beware, Date_Calc doesn't follow ISO-8601 standard!
|
||||
//return Date_Calc::weekOfYear($d, $m, $y); //beware, Date_Calc doesn't follow ISO-8601 standard!
|
||||
list($nYear, $nWeek) = Date_Calc::weekOfYear4th($d, $m, $y);
|
||||
return $nWeek;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of the week in the month, given a date
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @param int day (4)
|
||||
* @param int first day of the week (default: monday)
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
* @param int $firstDay first day of the week (default: monday)
|
||||
*
|
||||
* @return int week number
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -311,9 +366,11 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
|
|||
|
||||
/**
|
||||
* Returns the number of weeks in the month
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @param int first day of the week (default: monday)
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $firstDay first day of the week (default: monday)
|
||||
*
|
||||
* @return int weeks number
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -337,9 +394,11 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
|
|||
|
||||
/**
|
||||
* Returns the number of the day of the week (0=sunday, 1=monday...)
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @param int day (4)
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
*
|
||||
* @return int weekday number
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -350,32 +409,41 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
|
|||
|
||||
/**
|
||||
* Returns a list of integer days of the week beginning 0
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @param int day (4)
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
*
|
||||
* @return array (0, 1, 2, 3, 4, 5, 6) 1 = Monday
|
||||
* @access protected
|
||||
*/
|
||||
function getWeekDays($y=NULL, $m=NULL, $d=NULL)
|
||||
function getWeekDays($y=null, $m=null, $d=null)
|
||||
{
|
||||
return array(0, 1, 2, 3, 4, 5, 6);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default first day of the week
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @param int day (4)
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
*
|
||||
* @return int (default 1 = Monday)
|
||||
* @access protected
|
||||
*/
|
||||
function getFirstDayOfWeek($y=NULL, $m=NULL, $d=NULL)
|
||||
function getFirstDayOfWeek($y=null, $m=null, $d=null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of hours in a day
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
*
|
||||
* @return int (24)
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -386,6 +454,12 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
|
|||
|
||||
/**
|
||||
* Returns the number of minutes in an hour
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
* @param int $h hour
|
||||
*
|
||||
* @return int (60)
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -396,6 +470,13 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
|
|||
|
||||
/**
|
||||
* Returns the number of seconds in a minutes
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
* @param int $h hour
|
||||
* @param int $i minute
|
||||
*
|
||||
* @return int (60)
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -403,5 +484,26 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
|
|||
{
|
||||
return 60;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given day is the current day
|
||||
*
|
||||
* @param mixed $stamp Any timestamp format recognized by Pear::Date
|
||||
*
|
||||
* @return boolean
|
||||
* @access protected
|
||||
*/
|
||||
function isToday($stamp)
|
||||
{
|
||||
static $today = null;
|
||||
if (is_null($today)) {
|
||||
$today = new Date();
|
||||
}
|
||||
$date = Calendar_Engine_PearDate::stampCollection($stamp);
|
||||
return ( $date->day == $today->getDay()
|
||||
&& $date->month == $today->getMonth()
|
||||
&& $date->year == $today->getYear()
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -1,33 +1,52 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: UnixTS.php,v 1.9 2004/08/20 20:00:55 quipo Exp $
|
||||
//
|
||||
|
||||
/**
|
||||
* @package Calendar
|
||||
* @version $Id: UnixTS.php,v 1.9 2004/08/20 20:00:55 quipo Exp $
|
||||
* Contains the Calendar_Engine_UnixTS class
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "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 FREEBSD PROJECT 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 Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @copyright 2003-2007 Harry Fuecks
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @version CVS: $Id: UnixTS.php,v 1.14 2008/11/15 21:21:42 quipo Exp $
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
*/
|
||||
|
||||
/**
|
||||
* Performs calendar calculations based on the PHP date() function and
|
||||
* Unix timestamps (using PHP's mktime() function).
|
||||
* @package Calendar
|
||||
* @access protected
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @copyright 2003-2007 Harry Fuecks
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
* @access protected
|
||||
*/
|
||||
class Calendar_Engine_UnixTS /* implements Calendar_Engine_Interface */
|
||||
{
|
||||
|
@ -48,7 +67,9 @@ class Calendar_Engine_UnixTS /* implements Calendar_Engine_Interface */
|
|||
* </pre>
|
||||
* Uses a static variable to prevent date() being used twice
|
||||
* for a date which is already known
|
||||
* @param int Unix timestamp
|
||||
*
|
||||
* @param int $stamp Unix timestamp
|
||||
*
|
||||
* @return array
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -56,7 +77,7 @@ class Calendar_Engine_UnixTS /* implements Calendar_Engine_Interface */
|
|||
{
|
||||
static $stamps = array();
|
||||
if ( !isset($stamps[$stamp]) ) {
|
||||
$date = @date('Y n j H i s t W w',$stamp);
|
||||
$date = @date('Y n j H i s t W w', $stamp);
|
||||
$stamps[$stamp] = sscanf($date, "%d %d %d %d %d %d %d %d %d");
|
||||
}
|
||||
return $stamps[$stamp];
|
||||
|
@ -64,7 +85,9 @@ class Calendar_Engine_UnixTS /* implements Calendar_Engine_Interface */
|
|||
|
||||
/**
|
||||
* Returns a numeric year given a timestamp
|
||||
* @param int Unix timestamp
|
||||
*
|
||||
* @param int $stamp Unix timestamp
|
||||
*
|
||||
* @return int year (e.g. 2003)
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -76,7 +99,9 @@ class Calendar_Engine_UnixTS /* implements Calendar_Engine_Interface */
|
|||
|
||||
/**
|
||||
* Returns a numeric month given a timestamp
|
||||
* @param int Unix timestamp
|
||||
*
|
||||
* @param int $stamp Unix timestamp
|
||||
*
|
||||
* @return int month (e.g. 9)
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -88,7 +113,9 @@ class Calendar_Engine_UnixTS /* implements Calendar_Engine_Interface */
|
|||
|
||||
/**
|
||||
* Returns a numeric day given a timestamp
|
||||
* @param int Unix timestamp
|
||||
*
|
||||
* @param int $stamp Unix timestamp
|
||||
*
|
||||
* @return int day (e.g. 15)
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -100,7 +127,9 @@ class Calendar_Engine_UnixTS /* implements Calendar_Engine_Interface */
|
|||
|
||||
/**
|
||||
* Returns a numeric hour given a timestamp
|
||||
* @param int Unix timestamp
|
||||
*
|
||||
* @param int $stamp Unix timestamp
|
||||
*
|
||||
* @return int hour (e.g. 13)
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -112,7 +141,9 @@ class Calendar_Engine_UnixTS /* implements Calendar_Engine_Interface */
|
|||
|
||||
/**
|
||||
* Returns a numeric minute given a timestamp
|
||||
* @param int Unix timestamp
|
||||
*
|
||||
* @param int $stamp Unix timestamp
|
||||
*
|
||||
* @return int minute (e.g. 34)
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -124,7 +155,9 @@ class Calendar_Engine_UnixTS /* implements Calendar_Engine_Interface */
|
|||
|
||||
/**
|
||||
* Returns a numeric second given a timestamp
|
||||
* @param int Unix timestamp
|
||||
*
|
||||
* @param int $stamp Unix timestamp
|
||||
*
|
||||
* @return int second (e.g. 51)
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -136,19 +169,21 @@ class Calendar_Engine_UnixTS /* implements Calendar_Engine_Interface */
|
|||
|
||||
/**
|
||||
* Returns a timestamp
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @param int day (13)
|
||||
* @param int hour (13)
|
||||
* @param int minute (34)
|
||||
* @param int second (53)
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (13)
|
||||
* @param int $h hour (13)
|
||||
* @param int $i minute (34)
|
||||
* @param int $s second (53)
|
||||
*
|
||||
* @return int Unix timestamp
|
||||
* @access protected
|
||||
*/
|
||||
function dateToStamp($y, $m, $d, $h=0, $i=0, $s=0)
|
||||
{
|
||||
static $dates = array();
|
||||
if ( !isset($dates[$y][$m][$d][$h][$i][$s]) ) {
|
||||
if (!isset($dates[$y][$m][$d][$h][$i][$s])) {
|
||||
$dates[$y][$m][$d][$h][$i][$s] = @mktime($h, $i, $s, $m, $d, $y);
|
||||
}
|
||||
return $dates[$y][$m][$d][$h][$i][$s];
|
||||
|
@ -156,6 +191,7 @@ class Calendar_Engine_UnixTS /* implements Calendar_Engine_Interface */
|
|||
|
||||
/**
|
||||
* The upper limit on years that the Calendar Engine can work with
|
||||
*
|
||||
* @return int (2037)
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -166,6 +202,7 @@ class Calendar_Engine_UnixTS /* implements Calendar_Engine_Interface */
|
|||
|
||||
/**
|
||||
* The lower limit on years that the Calendar Engine can work with
|
||||
*
|
||||
* @return int (1970 if it's Windows and 1902 for all other OSs)
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -176,8 +213,11 @@ class Calendar_Engine_UnixTS /* implements Calendar_Engine_Interface */
|
|||
|
||||
/**
|
||||
* Returns the number of months in a year
|
||||
*
|
||||
* @param int $y year
|
||||
*
|
||||
* @return int (12)
|
||||
* @access protected
|
||||
* @access protected
|
||||
*/
|
||||
function getMonthsInYear($y=null)
|
||||
{
|
||||
|
@ -186,73 +226,83 @@ class Calendar_Engine_UnixTS /* implements Calendar_Engine_Interface */
|
|||
|
||||
/**
|
||||
* Returns the number of days in a month, given year and month
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
*
|
||||
* @return int days in month
|
||||
* @access protected
|
||||
*/
|
||||
function getDaysInMonth($y, $m)
|
||||
{
|
||||
$stamp = Calendar_Engine_UnixTS::dateToStamp($y,$m,1);
|
||||
$date = Calendar_Engine_UnixTS::stampCollection($stamp);
|
||||
$stamp = Calendar_Engine_UnixTS::dateToStamp($y, $m, 1);
|
||||
$date = Calendar_Engine_UnixTS::stampCollection($stamp);
|
||||
return $date[6];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns numeric representation of the day of the week in a month,
|
||||
* given year and month
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
*
|
||||
* @return int from 0 to 6
|
||||
* @access protected
|
||||
*/
|
||||
function getFirstDayInMonth($y, $m)
|
||||
{
|
||||
$stamp = Calendar_Engine_UnixTS::dateToStamp($y,$m,1);
|
||||
$date = Calendar_Engine_UnixTS::stampCollection($stamp);
|
||||
$stamp = Calendar_Engine_UnixTS::dateToStamp($y, $m, 1);
|
||||
$date = Calendar_Engine_UnixTS::stampCollection($stamp);
|
||||
return $date[8];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of days in a week
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @param int day (4)
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
*
|
||||
* @return int (7)
|
||||
* @access protected
|
||||
*/
|
||||
function getDaysInWeek($y=NULL, $m=NULL, $d=NULL)
|
||||
function getDaysInWeek($y=null, $m=null, $d=null)
|
||||
{
|
||||
return 7;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of the week in the year (ISO-8601), given a date
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @param int day (4)
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
*
|
||||
* @return int week number
|
||||
* @access protected
|
||||
*/
|
||||
function getWeekNInYear($y, $m, $d)
|
||||
{
|
||||
$stamp = Calendar_Engine_UnixTS::dateToStamp($y,$m,$d);
|
||||
$date = Calendar_Engine_UnixTS::stampCollection($stamp);
|
||||
$stamp = Calendar_Engine_UnixTS::dateToStamp($y, $m, $d);
|
||||
$date = Calendar_Engine_UnixTS::stampCollection($stamp);
|
||||
return $date[7];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of the week in the month, given a date
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @param int day (4)
|
||||
* @param int first day of the week (default: monday)
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
* @param int $firstDay first day of the week (default: monday)
|
||||
*
|
||||
* @return int week number
|
||||
* @access protected
|
||||
*/
|
||||
function getWeekNInMonth($y, $m, $d, $firstDay=1)
|
||||
{
|
||||
$weekEnd = ($firstDay == 0) ? $this->getDaysInWeek()-1 : $firstDay-1;
|
||||
$weekEnd = (0 == $firstDay) ? $this->getDaysInWeek()-1 : $firstDay-1;
|
||||
$end_of_week = 1;
|
||||
while (@date('w', @mktime(0, 0, 0, $m, $end_of_week, $y)) != $weekEnd) {
|
||||
++$end_of_week; //find first weekend of the month
|
||||
|
@ -267,13 +317,15 @@ class Calendar_Engine_UnixTS /* implements Calendar_Engine_Interface */
|
|||
|
||||
/**
|
||||
* Returns the number of weeks in the month
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @param int first day of the week (default: monday)
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $firstDay first day of the week (default: monday)
|
||||
*
|
||||
* @return int weeks number
|
||||
* @access protected
|
||||
*/
|
||||
function getWeeksInMonth($y, $m, $firstDay=1)
|
||||
function getWeeksInMonth($y, $m, $firstDay = 1)
|
||||
{
|
||||
$FDOM = $this->getFirstDayInMonth($y, $m);
|
||||
if ($FDOM == 0) {
|
||||
|
@ -293,73 +345,119 @@ class Calendar_Engine_UnixTS /* implements Calendar_Engine_Interface */
|
|||
|
||||
/**
|
||||
* Returns the number of the day of the week (0=sunday, 1=monday...)
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @param int day (4)
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
*
|
||||
* @return int weekday number
|
||||
* @access protected
|
||||
*/
|
||||
function getDayOfWeek($y, $m, $d)
|
||||
{
|
||||
$stamp = Calendar_Engine_UnixTS::dateToStamp($y,$m,$d);
|
||||
$stamp = Calendar_Engine_UnixTS::dateToStamp($y, $m, $d);
|
||||
$date = Calendar_Engine_UnixTS::stampCollection($stamp);
|
||||
return $date[8];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of integer days of the week beginning 0
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @param int day (4)
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
*
|
||||
* @return array (0,1,2,3,4,5,6) 1 = Monday
|
||||
* @access protected
|
||||
*/
|
||||
function getWeekDays($y=NULL, $m=NULL, $d=NULL)
|
||||
function getWeekDays($y=null, $m=null, $d=null)
|
||||
{
|
||||
return array(0, 1, 2, 3, 4, 5, 6);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default first day of the week
|
||||
* @param int year (2003)
|
||||
* @param int month (9)
|
||||
* @param int day (4)
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
*
|
||||
* @return int (default 1 = Monday)
|
||||
* @access protected
|
||||
*/
|
||||
function getFirstDayOfWeek($y=NULL, $m=NULL, $d=NULL)
|
||||
function getFirstDayOfWeek($y=null, $m=null, $d=null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of hours in a day
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
*
|
||||
* @return int (24)
|
||||
* @access protected
|
||||
*/
|
||||
function getHoursInDay($y=null,$m=null,$d=null)
|
||||
function getHoursInDay($y=null, $m=null, $d=null)
|
||||
{
|
||||
return 24;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of minutes in an hour
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
* @param int $h hour
|
||||
*
|
||||
* @return int (60)
|
||||
* @access protected
|
||||
*/
|
||||
function getMinutesInHour($y=null,$m=null,$d=null,$h=null)
|
||||
function getMinutesInHour($y=null, $m=null, $d=null, $h=null)
|
||||
{
|
||||
return 60;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of seconds in a minutes
|
||||
*
|
||||
* @param int $y year (2003)
|
||||
* @param int $m month (9)
|
||||
* @param int $d day (4)
|
||||
* @param int $h hour
|
||||
* @param int $i minute
|
||||
*
|
||||
* @return int (60)
|
||||
* @access protected
|
||||
*/
|
||||
function getSecondsInMinute($y=null,$m=null,$d=null,$h=null,$i=null)
|
||||
function getSecondsInMinute($y=null, $m=null, $d=null, $h=null, $i=null)
|
||||
{
|
||||
return 60;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given day is the current day
|
||||
*
|
||||
* @param mixed $stamp Any timestamp format recognized by Pear::Date
|
||||
*
|
||||
* @return boolean
|
||||
* @access protected
|
||||
*/
|
||||
function isToday($stamp)
|
||||
{
|
||||
static $today = null;
|
||||
if (is_null($today)) {
|
||||
$today_date = @date('Y n j');
|
||||
$today = sscanf($today_date, '%d %d %d');
|
||||
}
|
||||
$date = Calendar_Engine_UnixTS::stampCollection($stamp);
|
||||
return ( $date[2] == $today[2]
|
||||
&& $date[1] == $today[1]
|
||||
&& $date[0] == $today[0]
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -1,28 +1,40 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
|
||||
// | Lorenzo Alberton <l dot alberton at quipo dot it> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Factory.php,v 1.3 2005/10/22 10:08:47 quipo Exp $
|
||||
//
|
||||
|
||||
/**
|
||||
* @package Calendar
|
||||
* @version $Id: Factory.php,v 1.3 2005/10/22 10:08:47 quipo Exp $
|
||||
* Contains the Calendar_Factory class
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "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 FREEBSD PROJECT 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 Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
||||
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @version CVS: $Id: Factory.php,v 1.8 2007/11/18 21:46:42 quipo Exp $
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -52,20 +64,29 @@ require_once CALENDAR_ROOT.'Calendar.php';
|
|||
* It defaults to building Calendar_Month objects.<br>
|
||||
* Use the constract CALENDAR_FIRST_DAY_OF_WEEK to control the first day of the week
|
||||
* for Month or Week objects (e.g. 0 = Sunday, 6 = Saturday)
|
||||
* @package Calendar
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
||||
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
* @access protected
|
||||
*/
|
||||
class Calendar_Factory
|
||||
{
|
||||
/**
|
||||
* Creates a calendar object given the type and units
|
||||
* @param string class of calendar object to create
|
||||
* @param int year
|
||||
* @param int month
|
||||
* @param int day
|
||||
* @param int hour
|
||||
* @param int minute
|
||||
* @param int second
|
||||
*
|
||||
* @param string $type class of calendar object to create
|
||||
* @param int $y year
|
||||
* @param int $m month
|
||||
* @param int $d day
|
||||
* @param int $h hour
|
||||
* @param int $i minute
|
||||
* @param int $s second
|
||||
*
|
||||
* @return object subclass of Calendar
|
||||
* @access public
|
||||
* @static
|
||||
|
@ -74,70 +95,72 @@ class Calendar_Factory
|
|||
{
|
||||
$firstDay = defined('CALENDAR_FIRST_DAY_OF_WEEK') ? CALENDAR_FIRST_DAY_OF_WEEK : 1;
|
||||
switch ($type) {
|
||||
case 'Day':
|
||||
require_once CALENDAR_ROOT.'Day.php';
|
||||
return new Calendar_Day($y,$m,$d);
|
||||
case 'Month':
|
||||
// Set default state for which month type to build
|
||||
if (!defined('CALENDAR_MONTH_STATE')) {
|
||||
define('CALENDAR_MONTH_STATE', CALENDAR_USE_MONTH);
|
||||
}
|
||||
switch (CALENDAR_MONTH_STATE) {
|
||||
case CALENDAR_USE_MONTH_WEEKDAYS:
|
||||
require_once CALENDAR_ROOT.'Month/Weekdays.php';
|
||||
$class = 'Calendar_Month_Weekdays';
|
||||
break;
|
||||
case CALENDAR_USE_MONTH_WEEKS:
|
||||
require_once CALENDAR_ROOT.'Month/Weeks.php';
|
||||
$class = 'Calendar_Month_Weeks';
|
||||
break;
|
||||
case CALENDAR_USE_MONTH:
|
||||
default:
|
||||
require_once CALENDAR_ROOT.'Month.php';
|
||||
$class = 'Calendar_Month';
|
||||
break;
|
||||
}
|
||||
return new $class($y, $m, $firstDay);
|
||||
case 'Week':
|
||||
require_once CALENDAR_ROOT.'Week.php';
|
||||
return new Calendar_Week($y, $m, $d, $firstDay);
|
||||
case 'Hour':
|
||||
require_once CALENDAR_ROOT.'Hour.php';
|
||||
return new Calendar_Hour($y, $m, $d, $h);
|
||||
case 'Minute':
|
||||
require_once CALENDAR_ROOT.'Minute.php';
|
||||
return new Calendar_Minute($y, $m, $d, $h, $i);
|
||||
case 'Second':
|
||||
require_once CALENDAR_ROOT.'Second.php';
|
||||
return new Calendar_Second($y,$m,$d,$h,$i,$s);
|
||||
case 'Year':
|
||||
require_once CALENDAR_ROOT.'Year.php';
|
||||
return new Calendar_Year($y);
|
||||
case 'Day':
|
||||
include_once CALENDAR_ROOT.'Day.php';
|
||||
return new Calendar_Day($y, $m, $d);
|
||||
case 'Month':
|
||||
// Set default state for which month type to build
|
||||
if (!defined('CALENDAR_MONTH_STATE')) {
|
||||
define('CALENDAR_MONTH_STATE', CALENDAR_USE_MONTH);
|
||||
}
|
||||
switch (CALENDAR_MONTH_STATE) {
|
||||
case CALENDAR_USE_MONTH_WEEKDAYS:
|
||||
include_once CALENDAR_ROOT.'Month/Weekdays.php';
|
||||
$class = 'Calendar_Month_Weekdays';
|
||||
break;
|
||||
case CALENDAR_USE_MONTH_WEEKS:
|
||||
include_once CALENDAR_ROOT.'Month/Weeks.php';
|
||||
$class = 'Calendar_Month_Weeks';
|
||||
break;
|
||||
case CALENDAR_USE_MONTH:
|
||||
default:
|
||||
require_once 'PEAR.php';
|
||||
PEAR::raiseError(
|
||||
'Calendar_Factory::create() unrecognised type: '.$type, null, PEAR_ERROR_TRIGGER,
|
||||
E_USER_NOTICE, 'Calendar_Factory::create()');
|
||||
return false;
|
||||
include_once CALENDAR_ROOT.'Month.php';
|
||||
$class = 'Calendar_Month';
|
||||
break;
|
||||
}
|
||||
return new $class($y, $m, $firstDay);
|
||||
case 'Week':
|
||||
include_once CALENDAR_ROOT.'Week.php';
|
||||
return new Calendar_Week($y, $m, $d, $firstDay);
|
||||
case 'Hour':
|
||||
include_once CALENDAR_ROOT.'Hour.php';
|
||||
return new Calendar_Hour($y, $m, $d, $h);
|
||||
case 'Minute':
|
||||
include_once CALENDAR_ROOT.'Minute.php';
|
||||
return new Calendar_Minute($y, $m, $d, $h, $i);
|
||||
case 'Second':
|
||||
include_once CALENDAR_ROOT.'Second.php';
|
||||
return new Calendar_Second($y, $m, $d, $h, $i, $s);
|
||||
case 'Year':
|
||||
include_once CALENDAR_ROOT.'Year.php';
|
||||
return new Calendar_Year($y);
|
||||
default:
|
||||
include_once 'PEAR.php';
|
||||
PEAR::raiseError('Calendar_Factory::create() unrecognised type: '.$type,
|
||||
null, PEAR_ERROR_TRIGGER, E_USER_NOTICE, 'Calendar_Factory::create()');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance of a calendar object, given a type and timestamp
|
||||
* @param string type of object to create
|
||||
* @param mixed timestamp (depending on Calendar engine being used)
|
||||
*
|
||||
* @param string $type type of object to create
|
||||
* @param mixed $stamp timestamp (depending on Calendar engine being used)
|
||||
*
|
||||
* @return object subclass of Calendar
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function & createByTimestamp($type, $stamp)
|
||||
{
|
||||
$cE = & Calendar_Engine_Factory::getEngine();
|
||||
$y = $cE->stampToYear($stamp);
|
||||
$m = $cE->stampToMonth($stamp);
|
||||
$d = $cE->stampToDay($stamp);
|
||||
$h = $cE->stampToHour($stamp);
|
||||
$i = $cE->stampToMinute($stamp);
|
||||
$s = $cE->stampToSecond($stamp);
|
||||
$cE = & Calendar_Engine_Factory::getEngine();
|
||||
$y = $cE->stampToYear($stamp);
|
||||
$m = $cE->stampToMonth($stamp);
|
||||
$d = $cE->stampToDay($stamp);
|
||||
$h = $cE->stampToHour($stamp);
|
||||
$i = $cE->stampToMinute($stamp);
|
||||
$s = $cE->stampToSecond($stamp);
|
||||
$cal = Calendar_Factory::create($type, $y, $m, $d, $h, $i, $s);
|
||||
return $cal;
|
||||
}
|
||||
|
|
|
@ -1,27 +1,39 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Hour.php,v 1.1 2004/05/24 22:25:42 quipo Exp $
|
||||
//
|
||||
|
||||
/**
|
||||
* @package Calendar
|
||||
* @version $Id: Hour.php,v 1.1 2004/05/24 22:25:42 quipo Exp $
|
||||
* Contains the Calendar_Hour class
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "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 FREEBSD PROJECT 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 Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @copyright 2003-2007 Harry Fuecks
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @version CVS: $Id: Hour.php,v 1.6 2007/11/24 11:04:24 quipo Exp $
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -47,17 +59,25 @@ require_once CALENDAR_ROOT.'Calendar.php';
|
|||
* echo $Minute->thisMinute().'<br />';
|
||||
* }
|
||||
* </code>
|
||||
* @package Calendar
|
||||
* @access public
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @copyright 2003-2007 Harry Fuecks
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Hour extends Calendar
|
||||
{
|
||||
/**
|
||||
* Constructs Calendar_Hour
|
||||
* @param int year e.g. 2003
|
||||
* @param int month e.g. 5
|
||||
* @param int day e.g. 11
|
||||
* @param int hour e.g. 13
|
||||
*
|
||||
* @param int $y year e.g. 2003
|
||||
* @param int $m month e.g. 5
|
||||
* @param int $d day e.g. 11
|
||||
* @param int $h hour e.g. 13
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function Calendar_Hour($y, $m, $d, $h)
|
||||
|
@ -65,19 +85,21 @@ class Calendar_Hour extends Calendar
|
|||
Calendar::Calendar($y, $m, $d, $h);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Builds the Minutes in the Hour
|
||||
* @param array (optional) Calendar_Minute objects representing selected dates
|
||||
*
|
||||
* @param array $sDates (optional) Calendar_Minute objects representing selected dates
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function build($sDates=array())
|
||||
function build($sDates = array())
|
||||
{
|
||||
require_once CALENDAR_ROOT.'Minute.php';
|
||||
include_once CALENDAR_ROOT.'Minute.php';
|
||||
$mIH = $this->cE->getMinutesInHour($this->year, $this->month, $this->day,
|
||||
$this->hour);
|
||||
for ($i=0; $i < $mIH; $i++) {
|
||||
$this->children[$i]=
|
||||
$this->children[$i] =
|
||||
new Calendar_Minute($this->year, $this->month, $this->day,
|
||||
$this->hour, $i);
|
||||
}
|
||||
|
@ -89,7 +111,9 @@ class Calendar_Hour extends Calendar
|
|||
|
||||
/**
|
||||
* Called from build()
|
||||
* @param array
|
||||
*
|
||||
* @param array $sDates Calendar_Minute objects representing selected dates
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
|
|
|
@ -1,27 +1,39 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Minute.php,v 1.1 2004/05/24 22:25:42 quipo Exp $
|
||||
//
|
||||
|
||||
/**
|
||||
* @package Calendar
|
||||
* @version $Id: Minute.php,v 1.1 2004/05/24 22:25:42 quipo Exp $
|
||||
* Contains the Calendar_Minute class
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "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 FREEBSD PROJECT 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 Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @copyright 2003-2007 Harry Fuecks
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @version CVS: $Id: Minute.php,v 1.5 2007/11/16 20:03:12 quipo Exp $
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -47,18 +59,26 @@ require_once CALENDAR_ROOT.'Calendar.php';
|
|||
* echo $Second->thisSecond().'<br />';
|
||||
* }
|
||||
* </code>
|
||||
* @package Calendar
|
||||
* @access public
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @copyright 2003-2007 Harry Fuecks
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Minute extends Calendar
|
||||
{
|
||||
/**
|
||||
* Constructs Minute
|
||||
* @param int year e.g. 2003
|
||||
* @param int month e.g. 5
|
||||
* @param int day e.g. 11
|
||||
* @param int hour e.g. 13
|
||||
* @param int minute e.g. 31
|
||||
*
|
||||
* @param int $y year e.g. 2003
|
||||
* @param int $m month e.g. 5
|
||||
* @param int $d day e.g. 11
|
||||
* @param int $h hour e.g. 13
|
||||
* @param int $i minute e.g. 31
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function Calendar_Minute($y, $m, $d, $h, $i)
|
||||
|
@ -68,13 +88,15 @@ class Calendar_Minute extends Calendar
|
|||
|
||||
/**
|
||||
* Builds the Calendar_Second objects
|
||||
* @param array (optional) Calendar_Second objects representing selected dates
|
||||
*
|
||||
* @param array $sDates (optional) Calendar_Second objects representing selected dates
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function build($sDates=array())
|
||||
function build($sDates = array())
|
||||
{
|
||||
require_once CALENDAR_ROOT.'Second.php';
|
||||
include_once CALENDAR_ROOT.'Second.php';
|
||||
$sIM = $this->cE->getSecondsInMinute($this->year, $this->month,
|
||||
$this->day, $this->hour, $this->minute);
|
||||
for ($i=0; $i < $sIM; $i++) {
|
||||
|
@ -89,7 +111,9 @@ class Calendar_Minute extends Calendar
|
|||
|
||||
/**
|
||||
* Called from build()
|
||||
* @param array
|
||||
*
|
||||
* @param array $sDates Calendar_Second objects representing selected dates
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
|
|
|
@ -1,27 +1,39 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Month.php,v 1.3 2005/10/22 10:10:26 quipo Exp $
|
||||
//
|
||||
|
||||
/**
|
||||
* @package Calendar
|
||||
* @version $Id: Month.php,v 1.3 2005/10/22 10:10:26 quipo Exp $
|
||||
* Contains the Calendar_Month class
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "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 FREEBSD PROJECT 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 Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @copyright 2003-2007 Harry Fuecks
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @version CVS: $Id: Month.php,v 1.7 2007/11/16 20:03:12 quipo Exp $
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -47,16 +59,24 @@ require_once CALENDAR_ROOT.'Calendar.php';
|
|||
* echo $Day->thisDay().'<br />';
|
||||
* }
|
||||
* </code>
|
||||
* @package Calendar
|
||||
* @access public
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @copyright 2003-2007 Harry Fuecks
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Month extends Calendar
|
||||
{
|
||||
/**
|
||||
* Constructs Calendar_Month
|
||||
* @param int $y year e.g. 2003
|
||||
* @param int $m month e.g. 5
|
||||
*
|
||||
* @param int $y year e.g. 2003
|
||||
* @param int $m month e.g. 5
|
||||
* @param int $firstDay first day of the week [optional]
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function Calendar_Month($y, $m, $firstDay=null)
|
||||
|
@ -68,13 +88,15 @@ class Calendar_Month extends Calendar
|
|||
/**
|
||||
* Builds Day objects for this Month. Creates as many Calendar_Day objects
|
||||
* as there are days in the month
|
||||
* @param array (optional) Calendar_Day objects representing selected dates
|
||||
*
|
||||
* @param array $sDates (optional) Calendar_Day objects representing selected dates
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function build($sDates=array())
|
||||
function build($sDates = array())
|
||||
{
|
||||
require_once CALENDAR_ROOT.'Day.php';
|
||||
include_once CALENDAR_ROOT.'Day.php';
|
||||
$daysInMonth = $this->cE->getDaysInMonth($this->year, $this->month);
|
||||
for ($i=1; $i<=$daysInMonth; $i++) {
|
||||
$this->children[$i] = new Calendar_Day($this->year, $this->month, $i);
|
||||
|
@ -87,7 +109,9 @@ class Calendar_Month extends Calendar
|
|||
|
||||
/**
|
||||
* Called from build()
|
||||
* @param array
|
||||
*
|
||||
* @param array $sDates Calendar_Day objects representing selected dates
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
|
|
|
@ -1,27 +1,39 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Weekdays.php,v 1.4 2005/10/22 10:28:49 quipo Exp $
|
||||
//
|
||||
|
||||
/**
|
||||
* @package Calendar
|
||||
* @version $Id: Weekdays.php,v 1.4 2005/10/22 10:28:49 quipo Exp $
|
||||
* Contains the Calendar_Month_Weekdays class
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "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 FREEBSD PROJECT 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 Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @copyright 2003-2007 Harry Fuecks
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @version CVS: $Id: Weekdays.php,v 1.8 2007/11/16 20:04:45 quipo Exp $
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -62,8 +74,14 @@ require_once CALENDAR_ROOT.'Month.php';
|
|||
* }
|
||||
* }
|
||||
* </code>
|
||||
* @package Calendar
|
||||
* @access public
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @copyright 2003-2007 Harry Fuecks
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Month_Weekdays extends Calendar_Month
|
||||
{
|
||||
|
@ -83,9 +101,11 @@ class Calendar_Month_Weekdays extends Calendar_Month
|
|||
|
||||
/**
|
||||
* Constructs Calendar_Month_Weekdays
|
||||
* @param int year e.g. 2003
|
||||
* @param int month e.g. 5
|
||||
* @param int (optional) first day of week (e.g. 0 for Sunday, 2 for Tuesday etc.)
|
||||
*
|
||||
* @param int $y year e.g. 2003
|
||||
* @param int $m month e.g. 5
|
||||
* @param int $firstDay (optional) first day of week (e.g. 0 for Sunday, 2 for Tuesday etc.)
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function Calendar_Month_Weekdays($y, $m, $firstDay=null)
|
||||
|
@ -97,16 +117,18 @@ class Calendar_Month_Weekdays extends Calendar_Month
|
|||
* Builds Day objects in tabular form, to allow display of calendar month
|
||||
* with empty cells if the first day of the week does not fall on the first
|
||||
* day of the month.
|
||||
*
|
||||
* @param array $sDates (optional) Calendar_Day objects representing selected dates
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
* @see Calendar_Day::isEmpty()
|
||||
* @see Calendar_Day_Base::isFirst()
|
||||
* @see Calendar_Day_Base::isLast()
|
||||
* @param array (optional) Calendar_Day objects representing selected dates
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function build($sDates=array())
|
||||
function build($sDates = array())
|
||||
{
|
||||
require_once CALENDAR_ROOT.'Table/Helper.php';
|
||||
include_once CALENDAR_ROOT.'Table/Helper.php';
|
||||
$this->tableHelper = & new Calendar_Table_Helper($this, $this->firstDay);
|
||||
Calendar_Month::build($sDates);
|
||||
$this->buildEmptyDaysBefore();
|
||||
|
@ -118,6 +140,7 @@ class Calendar_Month_Weekdays extends Calendar_Month
|
|||
|
||||
/**
|
||||
* Prepends empty days before the real days in the month
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
|
@ -138,12 +161,13 @@ class Calendar_Month_Weekdays extends Calendar_Month
|
|||
|
||||
/**
|
||||
* Shifts the array of children forward, if necessary
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function shiftDays()
|
||||
{
|
||||
if (isset ($this->children[0])) {
|
||||
if (isset($this->children[0])) {
|
||||
array_unshift($this->children, null);
|
||||
unset($this->children[0]);
|
||||
}
|
||||
|
@ -151,14 +175,15 @@ class Calendar_Month_Weekdays extends Calendar_Month
|
|||
|
||||
/**
|
||||
* Appends empty days after the real days in the month
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function buildEmptyDaysAfter()
|
||||
{
|
||||
$eAfter = $this->tableHelper->getEmptyDaysAfter();
|
||||
$sDOM = $this->tableHelper->getNumTableDaysInMonth();
|
||||
for ($i = 1; $i <= $sDOM-$eAfter; $i++) {
|
||||
$sDOM = $this->tableHelper->getNumTableDaysInMonth();
|
||||
for ($i=1; $i <= $sDOM-$eAfter; $i++) {
|
||||
$Day = new Calendar_Day($this->year, $this->month+1, $i);
|
||||
$Day->setEmpty();
|
||||
$Day->adjust();
|
||||
|
@ -169,12 +194,13 @@ class Calendar_Month_Weekdays extends Calendar_Month
|
|||
/**
|
||||
* Sets the "markers" for the beginning and of a of week, in the
|
||||
* built Calendar_Day children
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function setWeekMarkers()
|
||||
{
|
||||
$dIW = $this->cE->getDaysInWeek(
|
||||
$dIW = $this->cE->getDaysInWeek(
|
||||
$this->thisYear(),
|
||||
$this->thisMonth(),
|
||||
$this->thisDay()
|
||||
|
|
|
@ -1,28 +1,40 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
|
||||
// | Lorenzo Alberton <l dot alberton at quipo dot it> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Weeks.php,v 1.3 2005/10/22 10:28:49 quipo Exp $
|
||||
//
|
||||
|
||||
/**
|
||||
* @package Calendar
|
||||
* @version $Id: Weeks.php,v 1.3 2005/10/22 10:28:49 quipo Exp $
|
||||
* Contains the Calendar_Month_Weeks class
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "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 FREEBSD PROJECT 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 Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
||||
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @version CVS: $Id: Weeks.php,v 1.7 2007/11/16 20:04:45 quipo Exp $
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -53,8 +65,15 @@ require_once CALENDAR_ROOT.'Month.php';
|
|||
* echo $Week->thisWeek().'<br />';
|
||||
* }
|
||||
* </code>
|
||||
* @package Calendar
|
||||
* @access public
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
||||
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Month_Weeks extends Calendar_Month
|
||||
{
|
||||
|
@ -74,9 +93,11 @@ class Calendar_Month_Weeks extends Calendar_Month
|
|||
|
||||
/**
|
||||
* Constructs Calendar_Month_Weeks
|
||||
* @param int year e.g. 2003
|
||||
* @param int month e.g. 5
|
||||
* @param int (optional) first day of week (e.g. 0 for Sunday, 2 for Tuesday etc.)
|
||||
*
|
||||
* @param int $y year e.g. 2003
|
||||
* @param int $m month e.g. 5
|
||||
* @param int $firstDay (optional) first day of week (e.g. 0 for Sunday, 2 for Tuesday etc.)
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function Calendar_Month_Weeks($y, $m, $firstDay=null)
|
||||
|
@ -87,21 +108,25 @@ class Calendar_Month_Weeks extends Calendar_Month
|
|||
/**
|
||||
* Builds Calendar_Week objects for the Month. Note that Calendar_Week
|
||||
* builds Calendar_Day object in tabular form (with Calendar_Day->empty)
|
||||
* @param array (optional) Calendar_Week objects representing selected dates
|
||||
*
|
||||
* @param array $sDates (optional) Calendar_Week objects representing selected dates
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function build($sDates=array())
|
||||
function build($sDates = array())
|
||||
{
|
||||
require_once CALENDAR_ROOT.'Table/Helper.php';
|
||||
include_once CALENDAR_ROOT.'Table/Helper.php';
|
||||
$this->tableHelper = & new Calendar_Table_Helper($this, $this->firstDay);
|
||||
require_once CALENDAR_ROOT.'Week.php';
|
||||
include_once CALENDAR_ROOT.'Week.php';
|
||||
$numWeeks = $this->tableHelper->getNumWeeks();
|
||||
for ($i=1, $d=1; $i<=$numWeeks; $i++,
|
||||
$d+=$this->cE->getDaysInWeek(
|
||||
$this->thisYear(),
|
||||
$this->thisMonth(),
|
||||
$this->thisDay()) ) {
|
||||
$this->thisDay()
|
||||
)
|
||||
) {
|
||||
$this->children[$i] = new Calendar_Week(
|
||||
$this->year, $this->month, $d, $this->tableHelper->getFirstDay());
|
||||
}
|
||||
|
@ -118,7 +143,9 @@ class Calendar_Month_Weeks extends Calendar_Month
|
|||
|
||||
/**
|
||||
* Called from build()
|
||||
* @param array
|
||||
*
|
||||
* @param array $sDates Calendar_Week objects representing selected dates
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
|
|
|
@ -1,27 +1,39 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Second.php,v 1.1 2004/05/24 22:25:42 quipo Exp $
|
||||
//
|
||||
|
||||
/**
|
||||
* @package Calendar
|
||||
* @version $Id: Second.php,v 1.1 2004/05/24 22:25:42 quipo Exp $
|
||||
* Contains the Calendar_Second class
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "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 FREEBSD PROJECT 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 Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @copyright 2003-2007 Harry Fuecks
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @version CVS: $Id: Second.php,v 1.4 2007/10/31 18:26:41 quipo Exp $
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -41,18 +53,26 @@ require_once CALENDAR_ROOT.'Calendar.php';
|
|||
* Represents a Second<br />
|
||||
* <b>Note:</b> Seconds do not build other objects
|
||||
* so related methods are overridden to return NULL
|
||||
* @package Calendar
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @copyright 2003-2007 Harry Fuecks
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Second extends Calendar
|
||||
{
|
||||
/**
|
||||
* Constructs Second
|
||||
* @param int year e.g. 2003
|
||||
* @param int month e.g. 5
|
||||
* @param int day e.g. 11
|
||||
* @param int hour e.g. 13
|
||||
* @param int minute e.g. 31
|
||||
* @param int second e.g. 45
|
||||
*
|
||||
* @param int $y year e.g. 2003
|
||||
* @param int $m month e.g. 5
|
||||
* @param int $d day e.g. 11
|
||||
* @param int $h hour e.g. 13
|
||||
* @param int $i minute e.g. 31
|
||||
* @param int $s second e.g. 45
|
||||
*/
|
||||
function Calendar_Second($y, $m, $d, $h, $i, $s)
|
||||
{
|
||||
|
@ -61,6 +81,7 @@ class Calendar_Second extends Calendar
|
|||
|
||||
/**
|
||||
* Overwrite build
|
||||
*
|
||||
* @return NULL
|
||||
*/
|
||||
function build()
|
||||
|
@ -70,6 +91,7 @@ class Calendar_Second extends Calendar
|
|||
|
||||
/**
|
||||
* Overwrite fetch
|
||||
*
|
||||
* @return NULL
|
||||
*/
|
||||
function fetch()
|
||||
|
@ -79,6 +101,7 @@ class Calendar_Second extends Calendar
|
|||
|
||||
/**
|
||||
* Overwrite fetchAll
|
||||
*
|
||||
* @return NULL
|
||||
*/
|
||||
function fetchAll()
|
||||
|
@ -88,6 +111,7 @@ class Calendar_Second extends Calendar
|
|||
|
||||
/**
|
||||
* Overwrite size
|
||||
*
|
||||
* @return NULL
|
||||
*/
|
||||
function size()
|
||||
|
|
|
@ -1,34 +1,52 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Helper.php,v 1.5 2005/10/22 09:51:53 quipo Exp $
|
||||
//
|
||||
|
||||
/**
|
||||
* @package Calendar
|
||||
* @version $Id: Helper.php,v 1.5 2005/10/22 09:51:53 quipo Exp $
|
||||
* Contains the Calendar_Decorator_Wrapper class
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "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 FREEBSD PROJECT 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 Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @copyright 2003-2007 Harry Fuecks
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @version CVS: $Id: Helper.php,v 1.9 2007/11/16 20:05:05 quipo Exp $
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
*/
|
||||
|
||||
/**
|
||||
* Used by Calendar_Month_Weekdays, Calendar_Month_Weeks and Calendar_Week to
|
||||
* help with building the calendar in tabular form
|
||||
* @package Calendar
|
||||
* @access protected
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @copyright 2003-2007 Harry Fuecks
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Table_Helper
|
||||
{
|
||||
|
@ -90,8 +108,10 @@ class Calendar_Table_Helper
|
|||
|
||||
/**
|
||||
* Constructs Calendar_Table_Helper
|
||||
* @param object Calendar_Month_Weekdays, Calendar_Month_Weeks, Calendar_Week
|
||||
* @param int (optional) first day of the week e.g. 1 for Monday
|
||||
*
|
||||
* @param object &$calendar Calendar_Month_Weekdays, Calendar_Month_Weeks, Calendar_Week
|
||||
* @param int $firstDay (optional) first day of the week e.g. 1 for Monday
|
||||
*
|
||||
* @access protected
|
||||
*/
|
||||
function Calendar_Table_Helper(& $calendar, $firstDay=null)
|
||||
|
@ -112,6 +132,7 @@ class Calendar_Table_Helper
|
|||
|
||||
/**
|
||||
* Constructs $this->daysOfWeek based on $this->firstDay
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
|
@ -140,6 +161,7 @@ class Calendar_Table_Helper
|
|||
|
||||
/**
|
||||
* Constructs $this->daysOfMonth
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
|
@ -174,9 +196,10 @@ class Calendar_Table_Helper
|
|||
|
||||
/**
|
||||
* Returns the first day of the month
|
||||
* @see Calendar_Engine_Interface::getFirstDayOfWeek()
|
||||
*
|
||||
* @return int
|
||||
* @access protected
|
||||
* @see Calendar_Engine_Interface::getFirstDayOfWeek()
|
||||
*/
|
||||
function getFirstDay()
|
||||
{
|
||||
|
@ -185,6 +208,7 @@ class Calendar_Table_Helper
|
|||
|
||||
/**
|
||||
* Returns the order array of days in a week
|
||||
*
|
||||
* @return int
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -195,6 +219,7 @@ class Calendar_Table_Helper
|
|||
|
||||
/**
|
||||
* Returns the number of tabular weeks in a month
|
||||
*
|
||||
* @return int
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -205,6 +230,7 @@ class Calendar_Table_Helper
|
|||
|
||||
/**
|
||||
* Returns the number of real days + empty days
|
||||
*
|
||||
* @return int
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -215,6 +241,7 @@ class Calendar_Table_Helper
|
|||
|
||||
/**
|
||||
* Returns the number of empty days before the real days begin
|
||||
*
|
||||
* @return int
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -225,6 +252,7 @@ class Calendar_Table_Helper
|
|||
|
||||
/**
|
||||
* Returns the index of the last real day in the month
|
||||
*
|
||||
* @todo Potential performance optimization with static
|
||||
* @return int
|
||||
* @access protected
|
||||
|
@ -232,17 +260,18 @@ class Calendar_Table_Helper
|
|||
function getEmptyDaysAfter()
|
||||
{
|
||||
// Causes bug when displaying more than one month
|
||||
// static $index;
|
||||
// if (!isset($index)) {
|
||||
//static $index;
|
||||
//if (!isset($index)) {
|
||||
$index = $this->getEmptyDaysBefore() + $this->cE->getDaysInMonth(
|
||||
$this->calendar->thisYear(), $this->calendar->thisMonth());
|
||||
// }
|
||||
//}
|
||||
return $index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of the last real day in the month, relative to the
|
||||
* beginning of the tabular week it is part of
|
||||
*
|
||||
* @return int
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -254,11 +283,18 @@ class Calendar_Table_Helper
|
|||
$this->calendar->thisYear(),
|
||||
$this->calendar->thisMonth(),
|
||||
$this->calendar->thisDay()
|
||||
) * ($this->numWeeks-1) );
|
||||
) * ($this->numWeeks-1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the timestamp of the first day of the current week
|
||||
*
|
||||
* @param int $y year
|
||||
* @param int $m month
|
||||
* @param int $d day
|
||||
* @param int $firstDay first day of the week (default 1 = Monday)
|
||||
*
|
||||
* @return int timestamp
|
||||
*/
|
||||
function getWeekStart($y, $m, $d, $firstDay=1)
|
||||
{
|
||||
|
|
|
@ -1,28 +1,45 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
|
||||
// | Lorenzo Alberton <l dot alberton at quipo dot it> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Textual.php,v 1.2 2004/08/16 13:13:09 hfuecks Exp $
|
||||
//
|
||||
|
||||
/**
|
||||
* Contains the Calendar_Util_Textual class
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "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 FREEBSD PROJECT 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 Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
||||
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @version CVS: $Id: Textual.php,v 1.8 2007/11/28 19:42:01 quipo Exp $
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
*/
|
||||
|
||||
/**
|
||||
* @package Calendar
|
||||
* @version $Id: Textual.php,v 1.2 2004/08/16 13:13:09 hfuecks Exp $
|
||||
* @version $Id: Textual.php,v 1.8 2007/11/28 19:42:01 quipo Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -41,23 +58,37 @@ require_once CALENDAR_ROOT.'Decorator.php';
|
|||
/**
|
||||
* Static utlities to help with fetching textual representations of months and
|
||||
* days of the week.
|
||||
* @package Calendar
|
||||
* @access public
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
||||
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Util_Textual
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns an array of 12 month names (first index = 1)
|
||||
* @param string (optional) format of returned months (one,two,short or long)
|
||||
*
|
||||
* @param string $format (optional) format of returned months (one|two|short|long)
|
||||
*
|
||||
* @return array
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function monthNames($format='long')
|
||||
function monthNames($format = 'long')
|
||||
{
|
||||
$formats = array('one'=>'%b', 'two'=>'%b', 'short'=>'%b', 'long'=>'%B');
|
||||
if (!array_key_exists($format,$formats)) {
|
||||
$formats = array(
|
||||
'one' => '%b',
|
||||
'two' => '%b',
|
||||
'short' => '%b',
|
||||
'long' => '%B',
|
||||
);
|
||||
if (!array_key_exists($format, $formats)) {
|
||||
$format = 'long';
|
||||
}
|
||||
$months = array();
|
||||
|
@ -65,11 +96,11 @@ class Calendar_Util_Textual
|
|||
$stamp = mktime(0, 0, 0, $i, 1, 2003);
|
||||
$month = strftime($formats[$format], $stamp);
|
||||
switch($format) {
|
||||
case 'one':
|
||||
$month = substr($month, 0, 1);
|
||||
case 'one':
|
||||
$month = substr($month, 0, 1);
|
||||
break;
|
||||
case 'two':
|
||||
$month = substr($month, 0, 2);
|
||||
case 'two':
|
||||
$month = substr($month, 0, 2);
|
||||
break;
|
||||
}
|
||||
$months[$i] = $month;
|
||||
|
@ -79,15 +110,22 @@ class Calendar_Util_Textual
|
|||
|
||||
/**
|
||||
* Returns an array of 7 week day names (first index = 0)
|
||||
* @param string (optional) format of returned days (one,two,short or long)
|
||||
*
|
||||
* @param string $format (optional) format of returned days (one,two,short or long)
|
||||
*
|
||||
* @return array
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function weekdayNames($format='long')
|
||||
function weekdayNames($format = 'long')
|
||||
{
|
||||
$formats = array('one'=>'%a', 'two'=>'%a', 'short'=>'%a', 'long'=>'%A');
|
||||
if (!array_key_exists($format,$formats)) {
|
||||
$formats = array(
|
||||
'one' => '%a',
|
||||
'two' => '%a',
|
||||
'short' => '%a',
|
||||
'long' => '%A',
|
||||
);
|
||||
if (!array_key_exists($format, $formats)) {
|
||||
$format = 'long';
|
||||
}
|
||||
$days = array();
|
||||
|
@ -95,11 +133,11 @@ class Calendar_Util_Textual
|
|||
$stamp = mktime(0, 0, 0, 11, $i+2, 2003);
|
||||
$day = strftime($formats[$format], $stamp);
|
||||
switch($format) {
|
||||
case 'one':
|
||||
$day = substr($day, 0, 1);
|
||||
case 'one':
|
||||
$day = substr($day, 0, 1);
|
||||
break;
|
||||
case 'two':
|
||||
$day = substr($day, 0, 2);
|
||||
case 'two':
|
||||
$day = substr($day, 0, 2);
|
||||
break;
|
||||
}
|
||||
$days[$i] = $day;
|
||||
|
@ -109,13 +147,15 @@ class Calendar_Util_Textual
|
|||
|
||||
/**
|
||||
* Returns textual representation of the previous month of the decorated calendar object
|
||||
* @param object subclass of Calendar e.g. Calendar_Month
|
||||
* @param string (optional) format of returned months (one,two,short or long)
|
||||
*
|
||||
* @param object $Calendar subclass of Calendar e.g. Calendar_Month
|
||||
* @param string $format (optional) format of returned months (one,two,short or long)
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function prevMonthName($Calendar, $format='long')
|
||||
function prevMonthName($Calendar, $format = 'long')
|
||||
{
|
||||
$months = Calendar_Util_Textual::monthNames($format);
|
||||
return $months[$Calendar->prevMonth()];
|
||||
|
@ -123,13 +163,15 @@ class Calendar_Util_Textual
|
|||
|
||||
/**
|
||||
* Returns textual representation of the month of the decorated calendar object
|
||||
* @param object subclass of Calendar e.g. Calendar_Month
|
||||
* @param string (optional) format of returned months (one,two,short or long)
|
||||
*
|
||||
* @param object $Calendar subclass of Calendar e.g. Calendar_Month
|
||||
* @param string $format (optional) format of returned months (one,two,short or long)
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function thisMonthName($Calendar, $format='long')
|
||||
function thisMonthName($Calendar, $format = 'long')
|
||||
{
|
||||
$months = Calendar_Util_Textual::monthNames($format);
|
||||
return $months[$Calendar->thisMonth()];
|
||||
|
@ -137,13 +179,15 @@ class Calendar_Util_Textual
|
|||
|
||||
/**
|
||||
* Returns textual representation of the next month of the decorated calendar object
|
||||
* @param object subclass of Calendar e.g. Calendar_Month
|
||||
* @param string (optional) format of returned months (one,two,short or long)
|
||||
*
|
||||
* @param object $Calendar subclass of Calendar e.g. Calendar_Month
|
||||
* @param string $format (optional) format of returned months (one,two,short or long)
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function nextMonthName($Calendar, $format='long')
|
||||
function nextMonthName($Calendar, $format = 'long')
|
||||
{
|
||||
$months = Calendar_Util_Textual::monthNames($format);
|
||||
return $months[$Calendar->nextMonth()];
|
||||
|
@ -152,18 +196,20 @@ class Calendar_Util_Textual
|
|||
/**
|
||||
* Returns textual representation of the previous day of week of the decorated calendar object
|
||||
* <b>Note:</b> Requires PEAR::Date
|
||||
* @param object subclass of Calendar e.g. Calendar_Month
|
||||
* @param string (optional) format of returned months (one,two,short or long)
|
||||
*
|
||||
* @param object $Calendar subclass of Calendar e.g. Calendar_Month
|
||||
* @param string $format (optional) format of returned months (one,two,short or long)
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function prevDayName($Calendar, $format='long')
|
||||
function prevDayName($Calendar, $format = 'long')
|
||||
{
|
||||
$days = Calendar_Util_Textual::weekdayNames($format);
|
||||
$stamp = $Calendar->prevDay('timestamp');
|
||||
$cE = $Calendar->getEngine();
|
||||
require_once 'Date/Calc.php';
|
||||
include_once 'Date/Calc.php';
|
||||
$day = Date_Calc::dayOfWeek($cE->stampToDay($stamp),
|
||||
$cE->stampToMonth($stamp), $cE->stampToYear($stamp));
|
||||
return $days[$day];
|
||||
|
@ -172,8 +218,10 @@ class Calendar_Util_Textual
|
|||
/**
|
||||
* Returns textual representation of the day of week of the decorated calendar object
|
||||
* <b>Note:</b> Requires PEAR::Date
|
||||
* @param object subclass of Calendar e.g. Calendar_Month
|
||||
* @param string (optional) format of returned months (one,two,short or long)
|
||||
*
|
||||
* @param object $Calendar subclass of Calendar e.g. Calendar_Month
|
||||
* @param string $format (optional) format of returned months (one,two,short or long)
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
* @static
|
||||
|
@ -181,15 +229,17 @@ class Calendar_Util_Textual
|
|||
function thisDayName($Calendar, $format='long')
|
||||
{
|
||||
$days = Calendar_Util_Textual::weekdayNames($format);
|
||||
require_once 'Date/Calc.php';
|
||||
include_once 'Date/Calc.php';
|
||||
$day = Date_Calc::dayOfWeek($Calendar->thisDay(), $Calendar->thisMonth(), $Calendar->thisYear());
|
||||
return $days[$day];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns textual representation of the next day of week of the decorated calendar object
|
||||
* @param object subclass of Calendar e.g. Calendar_Month
|
||||
* @param string (optional) format of returned months (one,two,short or long)
|
||||
*
|
||||
* @param object $Calendar subclass of Calendar e.g. Calendar_Month
|
||||
* @param string $format (optional) format of returned months (one,two,short or long)
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
* @static
|
||||
|
@ -199,7 +249,7 @@ class Calendar_Util_Textual
|
|||
$days = Calendar_Util_Textual::weekdayNames($format);
|
||||
$stamp = $Calendar->nextDay('timestamp');
|
||||
$cE = $Calendar->getEngine();
|
||||
require_once 'Date/Calc.php';
|
||||
include_once 'Date/Calc.php';
|
||||
$day = Date_Calc::dayOfWeek($cE->stampToDay($stamp),
|
||||
$cE->stampToMonth($stamp), $cE->stampToYear($stamp));
|
||||
return $days[$day];
|
||||
|
@ -209,21 +259,36 @@ class Calendar_Util_Textual
|
|||
* Returns the days of the week using the order defined in the decorated
|
||||
* calendar object. Only useful for Calendar_Month_Weekdays, Calendar_Month_Weeks
|
||||
* and Calendar_Week. Otherwise the returned array will begin on Sunday
|
||||
* @param object subclass of Calendar e.g. Calendar_Month
|
||||
* @param string (optional) format of returned months (one,two,short or long)
|
||||
*
|
||||
* @param object $Calendar subclass of Calendar e.g. Calendar_Month
|
||||
* @param string $format (optional) format of returned months (one,two,short or long)
|
||||
*
|
||||
* @return array ordered array of week day names
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function orderedWeekdays($Calendar, $format='long')
|
||||
function orderedWeekdays($Calendar, $format = 'long')
|
||||
{
|
||||
$days = Calendar_Util_Textual::weekdayNames($format);
|
||||
|
||||
// Not so good - need methods to access this information perhaps...
|
||||
if (isset($Calendar->tableHelper)) {
|
||||
$ordereddays = $Calendar->tableHelper->daysOfWeek;
|
||||
$ordereddays = $Calendar->tableHelper->getDaysOfWeek();
|
||||
} else {
|
||||
$ordereddays = array(0, 1, 2, 3, 4, 5, 6);
|
||||
//default: start from Sunday
|
||||
$firstDay = 0;
|
||||
//check if defined / set
|
||||
if (defined('CALENDAR_FIRST_DAY_OF_WEEK')) {
|
||||
$firstDay = CALENDAR_FIRST_DAY_OF_WEEK;
|
||||
} elseif(isset($Calendar->firstDay)) {
|
||||
$firstDay = $Calendar->firstDay;
|
||||
}
|
||||
$ordereddays = array();
|
||||
for ($i = $firstDay; $i < 7; $i++) {
|
||||
$ordereddays[] = $i;
|
||||
}
|
||||
for ($i = 0; $i < $firstDay; $i++) {
|
||||
$ordereddays[] = $i;
|
||||
}
|
||||
}
|
||||
|
||||
$ordereddays = array_flip($ordereddays);
|
||||
|
|
|
@ -1,28 +1,40 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
|
||||
// | Lorenzo Alberton <l dot alberton at quipo dot it> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Uri.php,v 1.1 2004/08/16 09:03:55 hfuecks Exp $
|
||||
//
|
||||
|
||||
/**
|
||||
* @package Calendar
|
||||
* @version $Id: Uri.php,v 1.1 2004/08/16 09:03:55 hfuecks Exp $
|
||||
* Contains the Calendar_Util_Uri class
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "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 FREEBSD PROJECT 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 Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
||||
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @version CVS: $Id: Uri.php,v 1.7 2007/11/18 22:22:42 quipo Exp $
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -37,8 +49,15 @@
|
|||
* echo $Uri->prev($Day,'month'); // Displays 2003/10
|
||||
* echo $Uri->prev($Day,'day'); // Displays 2003/10/22
|
||||
* </code>
|
||||
* @package Calendar
|
||||
* @access public
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
||||
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Util_Uri
|
||||
{
|
||||
|
@ -69,12 +88,14 @@ class Calendar_Util_Uri
|
|||
/**
|
||||
* Constructs Calendar_Decorator_Uri
|
||||
* The term "fragment" means <i>name</i> of a calendar GET variables in the URL
|
||||
* @param string URI fragment for year
|
||||
* @param string (optional) URI fragment for month
|
||||
* @param string (optional) URI fragment for day
|
||||
* @param string (optional) URI fragment for hour
|
||||
* @param string (optional) URI fragment for minute
|
||||
* @param string (optional) URI fragment for second
|
||||
*
|
||||
* @param string $y URI fragment for year
|
||||
* @param string $m (optional) URI fragment for month
|
||||
* @param string $d (optional) URI fragment for day
|
||||
* @param string $h (optional) URI fragment for hour
|
||||
* @param string $i (optional) URI fragment for minute
|
||||
* @param string $s (optional) URI fragment for second
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function Calendar_Util_Uri($y, $m=null, $d=null, $h=null, $i=null, $s=null)
|
||||
|
@ -84,16 +105,19 @@ class Calendar_Util_Uri
|
|||
|
||||
/**
|
||||
* Sets the URI fragment names
|
||||
* @param string URI fragment for year
|
||||
* @param string (optional) URI fragment for month
|
||||
* @param string (optional) URI fragment for day
|
||||
* @param string (optional) URI fragment for hour
|
||||
* @param string (optional) URI fragment for minute
|
||||
* @param string (optional) URI fragment for second
|
||||
*
|
||||
* @param string $y URI fragment for year
|
||||
* @param string $m (optional) URI fragment for month
|
||||
* @param string $d (optional) URI fragment for day
|
||||
* @param string $h (optional) URI fragment for hour
|
||||
* @param string $i (optional) URI fragment for minute
|
||||
* @param string $s (optional) URI fragment for second
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function setFragments($y, $m=null, $d=null, $h=null, $i=null, $s=null) {
|
||||
function setFragments($y, $m=null, $d=null, $h=null, $i=null, $s=null)
|
||||
{
|
||||
if (!is_null($y)) $this->uris['Year'] = $y;
|
||||
if (!is_null($m)) $this->uris['Month'] = $m;
|
||||
if (!is_null($d)) $this->uris['Day'] = $d;
|
||||
|
@ -104,8 +128,10 @@ class Calendar_Util_Uri
|
|||
|
||||
/**
|
||||
* Gets the URI string for the previous calendar unit
|
||||
* @param object subclassed from Calendar e.g. Calendar_Month
|
||||
* @param string calendar unit ( must be year, month, week, day, hour, minute or second)
|
||||
*
|
||||
* @param object $Calendar subclassed from Calendar e.g. Calendar_Month
|
||||
* @param string $unit calendar unit (year|month|week|day|hour|minute|second)
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
|
@ -118,22 +144,26 @@ class Calendar_Util_Uri
|
|||
|
||||
/**
|
||||
* Gets the URI string for the current calendar unit
|
||||
* @param object subclassed from Calendar e.g. Calendar_Month
|
||||
* @param string calendar unit ( must be year, month, week, day, hour, minute or second)
|
||||
*
|
||||
* @param object $Calendar subclassed from Calendar e.g. Calendar_Month
|
||||
* @param string $unit calendar unit (year|month|week|day|hour|minute|second)
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function this($Calendar, $unit)
|
||||
{
|
||||
$method = 'this'.$unit;
|
||||
$method = 'this'.$unit;
|
||||
$stamp = $Calendar->{$method}('timestamp');
|
||||
return $this->buildUriString($Calendar, $method, $stamp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the URI string for the next calendar unit
|
||||
* @param object subclassed from Calendar e.g. Calendar_Month
|
||||
* @param string calendar unit ( must be year, month, week, day, hour, minute or second)
|
||||
*
|
||||
* @param object $Calendar subclassed from Calendar e.g. Calendar_Month
|
||||
* @param string $unit calendar unit (year|month|week|day|hour|minute|second)
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
|
@ -146,8 +176,11 @@ class Calendar_Util_Uri
|
|||
|
||||
/**
|
||||
* Build the URI string
|
||||
* @param string method substring
|
||||
* @param int timestamp
|
||||
*
|
||||
* @param object $Calendar subclassed from Calendar e.g. Calendar_Month
|
||||
* @param string $method method substring
|
||||
* @param int $stamp timestamp
|
||||
*
|
||||
* @return string build uri string
|
||||
* @access private
|
||||
*/
|
||||
|
@ -159,7 +192,9 @@ class Calendar_Util_Uri
|
|||
foreach ($this->uris as $unit => $uri) {
|
||||
$call = 'stampTo'.$unit;
|
||||
$uriString .= $separator;
|
||||
if (!$this->scalar) $uriString .= $uri.'=';
|
||||
if (!$this->scalar) {
|
||||
$uriString .= $uri.'=';
|
||||
}
|
||||
$uriString .= $cE->{$call}($stamp);
|
||||
$separator = $this->separator;
|
||||
}
|
||||
|
|
|
@ -1,27 +1,39 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Validator.php,v 1.1 2004/05/24 22:25:42 quipo Exp $
|
||||
//
|
||||
|
||||
/**
|
||||
* @package Calendar
|
||||
* @version $Id: Validator.php,v 1.1 2004/05/24 22:25:42 quipo Exp $
|
||||
* Contains the Calendar_Validator class
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "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 FREEBSD PROJECT 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 Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @copyright 2003-2007 Harry Fuecks
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @version CVS: $Id: Validator.php,v 1.6 2007/11/28 19:42:33 quipo Exp $
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -37,9 +49,15 @@ if (!defined('CALENDAR_VALUE_TOOLARGE')) {
|
|||
/**
|
||||
* Used to validate any given Calendar date object. Instances of this class
|
||||
* can be obtained from any data object using the getValidator method
|
||||
* @see Calendar::getValidator()
|
||||
* @package Calendar
|
||||
* @access public
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @copyright 2003-2007 Harry Fuecks
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
* @see Calendar::getValidator()
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Validator
|
||||
{
|
||||
|
@ -66,17 +84,20 @@ class Calendar_Validator
|
|||
|
||||
/**
|
||||
* Constructs Calendar_Validator
|
||||
* @param object subclass of Calendar
|
||||
*
|
||||
* @param object &$calendar subclass of Calendar
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function Calendar_Validator(& $calendar)
|
||||
function Calendar_Validator(&$calendar)
|
||||
{
|
||||
$this->calendar = & $calendar;
|
||||
$this->cE = & $calendar->getEngine();
|
||||
$this->cE = & $calendar->getEngine();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls all the other isValidXXX() methods in the validator
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
|
@ -84,7 +105,7 @@ class Calendar_Validator
|
|||
{
|
||||
$checks = array('isValidYear', 'isValidMonth', 'isValidDay',
|
||||
'isValidHour', 'isValidMinute', 'isValidSecond');
|
||||
$valid = true;
|
||||
$valid = true;
|
||||
foreach ($checks as $check) {
|
||||
if (!$this->{$check}()) {
|
||||
$valid = false;
|
||||
|
@ -95,15 +116,16 @@ class Calendar_Validator
|
|||
|
||||
/**
|
||||
* Check whether this is a valid year
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function isValidYear()
|
||||
{
|
||||
$y = $this->calendar->thisYear();
|
||||
$y = $this->calendar->thisYear();
|
||||
$min = $this->cE->getMinYears();
|
||||
if ($min > $y) {
|
||||
$this->errors[] = new Calendar_Validation_Error(
|
||||
$this->errors[] = new Calendar_Validation_Error(
|
||||
'Year', $y, CALENDAR_VALUE_TOOSMALL.$min);
|
||||
return false;
|
||||
}
|
||||
|
@ -118,12 +140,13 @@ class Calendar_Validator
|
|||
|
||||
/**
|
||||
* Check whether this is a valid month
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function isValidMonth()
|
||||
{
|
||||
$m = $this->calendar->thisMonth();
|
||||
$m = $this->calendar->thisMonth();
|
||||
$min = 1;
|
||||
if ($min > $m) {
|
||||
$this->errors[] = new Calendar_Validation_Error(
|
||||
|
@ -141,12 +164,13 @@ class Calendar_Validator
|
|||
|
||||
/**
|
||||
* Check whether this is a valid day
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function isValidDay()
|
||||
{
|
||||
$d = $this->calendar->thisDay();
|
||||
$d = $this->calendar->thisDay();
|
||||
$min = 1;
|
||||
if ($min > $d) {
|
||||
$this->errors[] = new Calendar_Validation_Error(
|
||||
|
@ -154,7 +178,9 @@ class Calendar_Validator
|
|||
return false;
|
||||
}
|
||||
$max = $this->cE->getDaysInMonth(
|
||||
$this->calendar->thisYear(), $this->calendar->thisMonth());
|
||||
$this->calendar->thisYear(),
|
||||
$this->calendar->thisMonth()
|
||||
);
|
||||
if ($d > $max) {
|
||||
$this->errors[] = new Calendar_Validation_Error(
|
||||
'Day', $d, CALENDAR_VALUE_TOOLARGE.$max);
|
||||
|
@ -165,12 +191,13 @@ class Calendar_Validator
|
|||
|
||||
/**
|
||||
* Check whether this is a valid hour
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function isValidHour()
|
||||
{
|
||||
$h = $this->calendar->thisHour();
|
||||
$h = $this->calendar->thisHour();
|
||||
$min = 0;
|
||||
if ($min > $h) {
|
||||
$this->errors[] = new Calendar_Validation_Error(
|
||||
|
@ -188,12 +215,13 @@ class Calendar_Validator
|
|||
|
||||
/**
|
||||
* Check whether this is a valid minute
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function isValidMinute()
|
||||
{
|
||||
$i = $this->calendar->thisMinute();
|
||||
$i = $this->calendar->thisMinute();
|
||||
$min = 0;
|
||||
if ($min > $i) {
|
||||
$this->errors[] = new Calendar_Validation_Error(
|
||||
|
@ -211,12 +239,13 @@ class Calendar_Validator
|
|||
|
||||
/**
|
||||
* Check whether this is a valid second
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function isValidSecond()
|
||||
{
|
||||
$s = $this->calendar->thisSecond();
|
||||
$s = $this->calendar->thisSecond();
|
||||
$min = 0;
|
||||
if ($min > $s) {
|
||||
$this->errors[] = new Calendar_Validation_Error(
|
||||
|
@ -234,12 +263,13 @@ class Calendar_Validator
|
|||
|
||||
/**
|
||||
* Iterates over any validation errors
|
||||
*
|
||||
* @return mixed either Calendar_Validation_Error or false
|
||||
* @access public
|
||||
*/
|
||||
function fetch()
|
||||
{
|
||||
$error = each ($this->errors);
|
||||
$error = each($this->errors);
|
||||
if ($error) {
|
||||
return $error['value'];
|
||||
} else {
|
||||
|
@ -251,9 +281,15 @@ class Calendar_Validator
|
|||
|
||||
/**
|
||||
* For Validation Error messages
|
||||
* @see Calendar::fetch()
|
||||
* @package Calendar
|
||||
* @access public
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @copyright 2003-2007 Harry Fuecks
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
* @see Calendar::fetch()
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Validation_Error
|
||||
{
|
||||
|
@ -280,12 +316,14 @@ class Calendar_Validation_Error
|
|||
|
||||
/**
|
||||
* Constructs Calendar_Validation_Error
|
||||
* @param string Date unit (e.g. month,hour,second)
|
||||
* @param int Value of unit which failed test
|
||||
* @param string Validation error message
|
||||
*
|
||||
* @param string $unit Date unit (e.g. month,hour,second)
|
||||
* @param int $value Value of unit which failed test
|
||||
* @param string $message Validation error message
|
||||
*
|
||||
* @access protected
|
||||
*/
|
||||
function Calendar_Validation_Error($unit,$value,$message)
|
||||
function Calendar_Validation_Error($unit, $value, $message)
|
||||
{
|
||||
$this->unit = $unit;
|
||||
$this->value = $value;
|
||||
|
@ -294,6 +332,7 @@ class Calendar_Validation_Error
|
|||
|
||||
/**
|
||||
* Returns the Date unit
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
|
@ -304,6 +343,7 @@ class Calendar_Validation_Error
|
|||
|
||||
/**
|
||||
* Returns the value of the unit
|
||||
*
|
||||
* @return int
|
||||
* @access public
|
||||
*/
|
||||
|
@ -314,6 +354,7 @@ class Calendar_Validation_Error
|
|||
|
||||
/**
|
||||
* Returns the validation error message
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
|
@ -324,6 +365,7 @@ class Calendar_Validation_Error
|
|||
|
||||
/**
|
||||
* Returns a string containing the unit, value and error message
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
|
|
|
@ -1,28 +1,40 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
|
||||
// | Lorenzo Alberton <l dot alberton at quipo dot it> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Week.php,v 1.7 2005/10/22 10:26:49 quipo Exp $
|
||||
//
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* @package Calendar
|
||||
* @version $Id: Week.php,v 1.7 2005/10/22 10:26:49 quipo Exp $
|
||||
* Contains the Calendar_Week class
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "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 FREEBSD PROJECT 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 Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
||||
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @version CVS: $Id: Week.php,v 1.14 2007/11/18 21:46:42 quipo Exp $
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -41,7 +53,7 @@ require_once CALENDAR_ROOT.'Calendar.php';
|
|||
/**
|
||||
* Represents a Week and builds Days in tabular format<br>
|
||||
* <code>
|
||||
* require_once 'Calendar'.DIRECTORY_SEPARATOR.'Week.php';
|
||||
* require_once 'Calendar/Week.php';
|
||||
* $Week = & new Calendar_Week(2003, 10, 1); Oct 2003, 1st tabular week
|
||||
* echo '<tr>';
|
||||
* while ($Day = & $Week->fetch()) {
|
||||
|
@ -53,8 +65,14 @@ require_once CALENDAR_ROOT.'Calendar.php';
|
|||
* }
|
||||
* echo '</tr>';
|
||||
* </code>
|
||||
* @package Calendar
|
||||
* @access public
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
||||
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
*/
|
||||
class Calendar_Week extends Calendar
|
||||
{
|
||||
|
@ -109,33 +127,49 @@ class Calendar_Week extends Calendar
|
|||
|
||||
/**
|
||||
* Constructs Week
|
||||
* @param int year e.g. 2003
|
||||
* @param int month e.g. 5
|
||||
* @param int a day of the desired week
|
||||
* @param int (optional) first day of week (e.g. 0 for Sunday, 2 for Tuesday etc.)
|
||||
*
|
||||
* @param int $y year e.g. 2003
|
||||
* @param int $m month e.g. 5
|
||||
* @param int $d a day of the desired week
|
||||
* @param int $firstDay (optional) first day of week (e.g. 0 for Sunday, 2 for Tuesday etc.)
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function Calendar_Week($y, $m, $d, $firstDay=null)
|
||||
function Calendar_Week($y, $m, $d, $firstDay = null)
|
||||
{
|
||||
require_once CALENDAR_ROOT.'Table/Helper.php';
|
||||
include_once CALENDAR_ROOT.'Table/Helper.php';
|
||||
Calendar::Calendar($y, $m, $d);
|
||||
$this->firstDay = $this->defineFirstDayOfWeek($firstDay);
|
||||
$this->firstDay = $this->defineFirstDayOfWeek($firstDay);
|
||||
$this->tableHelper = & new Calendar_Table_Helper($this, $this->firstDay);
|
||||
$this->thisWeek = $this->tableHelper->getWeekStart($y, $m, $d, $this->firstDay);
|
||||
$this->prevWeek = $this->tableHelper->getWeekStart($y, $m, $d - $this->cE->getDaysInWeek(
|
||||
$this->thisYear(),
|
||||
$this->thisMonth(),
|
||||
$this->thisDay()), $this->firstDay);
|
||||
$this->nextWeek = $this->tableHelper->getWeekStart($y, $m, $d + $this->cE->getDaysInWeek(
|
||||
$this->thisYear(),
|
||||
$this->thisMonth(),
|
||||
$this->thisDay()), $this->firstDay);
|
||||
$this->thisWeek = $this->tableHelper->getWeekStart($y, $m, $d, $this->firstDay);
|
||||
$this->prevWeek = $this->tableHelper->getWeekStart(
|
||||
$y,
|
||||
$m,
|
||||
$d - $this->cE->getDaysInWeek(
|
||||
$this->thisYear(),
|
||||
$this->thisMonth(),
|
||||
$this->thisDay()
|
||||
),
|
||||
$this->firstDay
|
||||
);
|
||||
$this->nextWeek = $this->tableHelper->getWeekStart(
|
||||
$y,
|
||||
$m,
|
||||
$d + $this->cE->getDaysInWeek(
|
||||
$this->thisYear(),
|
||||
$this->thisMonth(),
|
||||
$this->thisDay()
|
||||
),
|
||||
$this->firstDay
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the calendar by a timestamp (Unix or ISO-8601), replacing values
|
||||
* passed to the constructor
|
||||
* @param int|string Unix or ISO-8601 timestamp
|
||||
*
|
||||
* @param int|string $ts Unix or ISO-8601 timestamp
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
|
@ -146,28 +180,38 @@ class Calendar_Week extends Calendar
|
|||
$this->year, $this->month, $this->day, $this->firstDay
|
||||
);
|
||||
$this->prevWeek = $this->tableHelper->getWeekStart(
|
||||
$this->year, $this->month, $this->day - $this->cE->getDaysInWeek(
|
||||
$this->year,
|
||||
$this->month,
|
||||
$this->day - $this->cE->getDaysInWeek(
|
||||
$this->thisYear(),
|
||||
$this->thisMonth(),
|
||||
$this->thisDay()), $this->firstDay
|
||||
$this->thisDay()
|
||||
),
|
||||
$this->firstDay
|
||||
);
|
||||
$this->nextWeek = $this->tableHelper->getWeekStart(
|
||||
$this->year, $this->month, $this->day + $this->cE->getDaysInWeek(
|
||||
$this->year,
|
||||
$this->month,
|
||||
$this->day + $this->cE->getDaysInWeek(
|
||||
$this->thisYear(),
|
||||
$this->thisMonth(),
|
||||
$this->thisDay()), $this->firstDay
|
||||
$this->thisDay()
|
||||
),
|
||||
$this->firstDay
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds Calendar_Day objects for this Week
|
||||
* @param array (optional) Calendar_Day objects representing selected dates
|
||||
*
|
||||
* @param array $sDates (optional) Calendar_Day objects representing selected dates
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function build($sDates = array())
|
||||
{
|
||||
require_once CALENDAR_ROOT.'Day.php';
|
||||
include_once CALENDAR_ROOT.'Day.php';
|
||||
$year = $this->cE->stampToYear($this->thisWeek);
|
||||
$month = $this->cE->stampToMonth($this->thisWeek);
|
||||
$day = $this->cE->stampToDay($this->thisWeek);
|
||||
|
@ -180,9 +224,10 @@ class Calendar_Week extends Calendar
|
|||
for ($i=1; $i <= $end; $i++) {
|
||||
$stamp = $this->cE->dateToStamp($year, $month, $day++);
|
||||
$this->children[$i] = new Calendar_Day(
|
||||
$this->cE->stampToYear($stamp),
|
||||
$this->cE->stampToMonth($stamp),
|
||||
$this->cE->stampToDay($stamp));
|
||||
$this->cE->stampToYear($stamp),
|
||||
$this->cE->stampToMonth($stamp),
|
||||
$this->cE->stampToDay($stamp)
|
||||
);
|
||||
}
|
||||
|
||||
//set empty days (@see Calendar_Month_Weeks::build())
|
||||
|
@ -206,28 +251,36 @@ class Calendar_Week extends Calendar
|
|||
}
|
||||
|
||||
/**
|
||||
* @param boolean
|
||||
* Set as first week of the month
|
||||
*
|
||||
* @param boolean $state whether it's first or not
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function setFirst($state=true)
|
||||
function setFirst($state = true)
|
||||
{
|
||||
$this->firstWeek = $state;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param boolean
|
||||
* Set as last week of the month
|
||||
*
|
||||
* @param boolean $state whether it's lasst or not
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function setLast($state=true)
|
||||
function setLast($state = true)
|
||||
{
|
||||
$this->lastWeek = $state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called from build()
|
||||
* @param array
|
||||
*
|
||||
* @param array $sDates Calendar_Day objects representing selected dates
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
|
@ -247,37 +300,63 @@ class Calendar_Week extends Calendar
|
|||
reset($this->children);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value for this year
|
||||
*
|
||||
* When a on the first/last week of the year, the year of the week is
|
||||
* calculated according to ISO-8601
|
||||
*
|
||||
* @param string $format return value format ['int' | 'timestamp' | 'object' | 'array']
|
||||
*
|
||||
* @return int e.g. 2003 or timestamp
|
||||
* @access public
|
||||
*/
|
||||
function thisYear($format = 'int')
|
||||
{
|
||||
$tmp_cal = new Calendar();
|
||||
$tmp_cal->setTimestamp($this->thisWeek);
|
||||
$first_dow = $tmp_cal->thisDay('array');
|
||||
$days_in_week = $tmp_cal->cE->getDaysInWeek($tmp_cal->year, $tmp_cal->month, $tmp_cal->day);
|
||||
$tmp_cal->day += $days_in_week;
|
||||
$last_dow = $tmp_cal->thisDay('array');
|
||||
|
||||
if ($first_dow['year'] == $last_dow['year']) {
|
||||
return $first_dow['year'];
|
||||
}
|
||||
|
||||
if ($last_dow['day'] > floor($days_in_week / 2)) {
|
||||
return $last_dow['year'];
|
||||
}
|
||||
return $first_dow['year'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the previous week, according to the requested format
|
||||
*
|
||||
* @param string $format ['timestamp' | 'n_in_month' | 'n_in_year' | 'array']
|
||||
*
|
||||
* @return mixed
|
||||
* @access public
|
||||
*/
|
||||
function prevWeek($format = 'n_in_month')
|
||||
{
|
||||
switch (strtolower($format)) {
|
||||
case 'int':
|
||||
case 'n_in_month':
|
||||
return ($this->firstWeek) ? null : $this->thisWeek('n_in_month') -1;
|
||||
break;
|
||||
case 'n_in_year':
|
||||
return $this->cE->getWeekNInYear(
|
||||
$this->cE->stampToYear($this->prevWeek),
|
||||
$this->cE->stampToMonth($this->prevWeek),
|
||||
$this->cE->stampToDay($this->prevWeek));
|
||||
break;
|
||||
case 'array':
|
||||
return $this->toArray($this->prevWeek);
|
||||
break;
|
||||
case 'object':
|
||||
require_once CALENDAR_ROOT.'Factory.php';
|
||||
return Calendar_Factory::createByTimestamp('Week', $this->prevWeek);
|
||||
break;
|
||||
case 'timestamp':
|
||||
default:
|
||||
return $this->prevWeek;
|
||||
break;
|
||||
case 'int':
|
||||
case 'n_in_month':
|
||||
return ($this->firstWeek) ? null : $this->thisWeek('n_in_month') -1;
|
||||
case 'n_in_year':
|
||||
return $this->cE->getWeekNInYear(
|
||||
$this->cE->stampToYear($this->prevWeek),
|
||||
$this->cE->stampToMonth($this->prevWeek),
|
||||
$this->cE->stampToDay($this->prevWeek));
|
||||
case 'array':
|
||||
return $this->toArray($this->prevWeek);
|
||||
case 'object':
|
||||
include_once CALENDAR_ROOT.'Factory.php';
|
||||
return Calendar_Factory::createByTimestamp('Week', $this->prevWeek);
|
||||
case 'timestamp':
|
||||
default:
|
||||
return $this->prevWeek;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -285,46 +364,42 @@ class Calendar_Week extends Calendar
|
|||
* Gets the value of the current week, according to the requested format
|
||||
*
|
||||
* @param string $format ['timestamp' | 'n_in_month' | 'n_in_year' | 'array']
|
||||
*
|
||||
* @return mixed
|
||||
* @access public
|
||||
*/
|
||||
function thisWeek($format = 'n_in_month')
|
||||
{
|
||||
switch (strtolower($format)) {
|
||||
case 'int':
|
||||
case 'n_in_month':
|
||||
if ($this->firstWeek) {
|
||||
return 1;
|
||||
}
|
||||
if ($this->lastWeek) {
|
||||
return $this->cE->getWeeksInMonth(
|
||||
$this->thisYear(),
|
||||
$this->thisMonth(),
|
||||
$this->firstDay);
|
||||
}
|
||||
return $this->cE->getWeekNInMonth(
|
||||
case 'int':
|
||||
case 'n_in_month':
|
||||
if ($this->firstWeek) {
|
||||
return 1;
|
||||
}
|
||||
if ($this->lastWeek) {
|
||||
return $this->cE->getWeeksInMonth(
|
||||
$this->thisYear(),
|
||||
$this->thisMonth(),
|
||||
$this->thisDay(),
|
||||
$this->firstDay);
|
||||
break;
|
||||
case 'n_in_year':
|
||||
return $this->cE->getWeekNInYear(
|
||||
$this->cE->stampToYear($this->thisWeek),
|
||||
$this->cE->stampToMonth($this->thisWeek),
|
||||
$this->cE->stampToDay($this->thisWeek));
|
||||
break;
|
||||
case 'array':
|
||||
return $this->toArray($this->thisWeek);
|
||||
break;
|
||||
case 'object':
|
||||
require_once CALENDAR_ROOT.'Factory.php';
|
||||
return Calendar_Factory::createByTimestamp('Week', $this->thisWeek);
|
||||
break;
|
||||
case 'timestamp':
|
||||
default:
|
||||
return $this->thisWeek;
|
||||
break;
|
||||
}
|
||||
return $this->cE->getWeekNInMonth(
|
||||
$this->thisYear(),
|
||||
$this->thisMonth(),
|
||||
$this->thisDay(),
|
||||
$this->firstDay);
|
||||
case 'n_in_year':
|
||||
return $this->cE->getWeekNInYear(
|
||||
$this->cE->stampToYear($this->thisWeek),
|
||||
$this->cE->stampToMonth($this->thisWeek),
|
||||
$this->cE->stampToDay($this->thisWeek));
|
||||
case 'array':
|
||||
return $this->toArray($this->thisWeek);
|
||||
case 'object':
|
||||
include_once CALENDAR_ROOT.'Factory.php';
|
||||
return Calendar_Factory::createByTimestamp('Week', $this->thisWeek);
|
||||
case 'timestamp':
|
||||
default:
|
||||
return $this->thisWeek;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -332,39 +407,36 @@ class Calendar_Week extends Calendar
|
|||
* Gets the value of the following week, according to the requested format
|
||||
*
|
||||
* @param string $format ['timestamp' | 'n_in_month' | 'n_in_year' | 'array']
|
||||
*
|
||||
* @return mixed
|
||||
* @access public
|
||||
*/
|
||||
function nextWeek($format = 'n_in_month')
|
||||
{
|
||||
switch (strtolower($format)) {
|
||||
case 'int':
|
||||
case 'n_in_month':
|
||||
return ($this->lastWeek) ? null : $this->thisWeek('n_in_month') +1;
|
||||
break;
|
||||
case 'n_in_year':
|
||||
return $this->cE->getWeekNInYear(
|
||||
$this->cE->stampToYear($this->nextWeek),
|
||||
$this->cE->stampToMonth($this->nextWeek),
|
||||
$this->cE->stampToDay($this->nextWeek));
|
||||
break;
|
||||
case 'array':
|
||||
return $this->toArray($this->nextWeek);
|
||||
break;
|
||||
case 'object':
|
||||
require_once CALENDAR_ROOT.'Factory.php';
|
||||
return Calendar_Factory::createByTimestamp('Week', $this->nextWeek);
|
||||
break;
|
||||
case 'timestamp':
|
||||
default:
|
||||
return $this->nextWeek;
|
||||
break;
|
||||
case 'int':
|
||||
case 'n_in_month':
|
||||
return ($this->lastWeek) ? null : $this->thisWeek('n_in_month') +1;
|
||||
case 'n_in_year':
|
||||
return $this->cE->getWeekNInYear(
|
||||
$this->cE->stampToYear($this->nextWeek),
|
||||
$this->cE->stampToMonth($this->nextWeek),
|
||||
$this->cE->stampToDay($this->nextWeek));
|
||||
case 'array':
|
||||
return $this->toArray($this->nextWeek);
|
||||
case 'object':
|
||||
include_once CALENDAR_ROOT.'Factory.php';
|
||||
return Calendar_Factory::createByTimestamp('Week', $this->nextWeek);
|
||||
case 'timestamp':
|
||||
default:
|
||||
return $this->nextWeek;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the instance of Calendar_Table_Helper.
|
||||
* Called from Calendar_Validator::isValidWeek
|
||||
*
|
||||
* @return Calendar_Table_Helper
|
||||
* @access protected
|
||||
*/
|
||||
|
@ -375,6 +447,7 @@ class Calendar_Week extends Calendar
|
|||
|
||||
/**
|
||||
* Makes sure theres a value for $this->day
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
|
|
|
@ -1,27 +1,39 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Year.php,v 1.4 2005/10/22 10:25:39 quipo Exp $
|
||||
//
|
||||
|
||||
/**
|
||||
* @package Calendar
|
||||
* @version $Id: Year.php,v 1.4 2005/10/22 10:25:39 quipo Exp $
|
||||
* Contains the Calendar_Minute class
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "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 FREEBSD PROJECT 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 Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @copyright 2003-2007 Harry Fuecks
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @version CVS: $Id: Year.php,v 1.9 2007/11/18 21:46:42 quipo Exp $
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -47,14 +59,22 @@ require_once CALENDAR_ROOT.'Calendar.php';
|
|||
* echo $Month->thisMonth().'<br />';
|
||||
* }
|
||||
* </code>
|
||||
* @package Calendar
|
||||
* @access public
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Calendar
|
||||
* @author Harry Fuecks <hfuecks@phppatterns.com>
|
||||
* @copyright 2003-2007 Harry Fuecks
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @link http://pear.php.net/package/Calendar
|
||||
* @access public
|
||||
*/
|
||||
class Calendar_Year extends Calendar
|
||||
{
|
||||
/**
|
||||
* Constructs Calendar_Year
|
||||
* @param int year e.g. 2003
|
||||
*
|
||||
* @param int $y year e.g. 2003
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function Calendar_Year($y)
|
||||
|
@ -73,16 +93,20 @@ class Calendar_Year extends Calendar
|
|||
* // define ('CALENDAR_MONTH_STATE',CALENDAR_USE_MONTH); // Use Calendar_Month
|
||||
* </code>
|
||||
* It defaults to building Calendar_Month objects.
|
||||
* @param array (optional) array of Calendar_Month objects representing selected dates
|
||||
* @param int (optional) first day of week (e.g. 0 for Sunday, 2 for Tuesday etc.)
|
||||
*
|
||||
* @param array $sDates (optional) array of Calendar_Month objects
|
||||
* representing selected dates
|
||||
* @param int $firstDay (optional) first day of week
|
||||
* (e.g. 0 for Sunday, 2 for Tuesday etc.)
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function build($sDates = array(), $firstDay = null)
|
||||
{
|
||||
require_once CALENDAR_ROOT.'Factory.php';
|
||||
include_once CALENDAR_ROOT.'Factory.php';
|
||||
$this->firstDay = $this->defineFirstDayOfWeek($firstDay);
|
||||
$monthsInYear = $this->cE->getMonthsInYear($this->thisYear());
|
||||
$monthsInYear = $this->cE->getMonthsInYear($this->thisYear());
|
||||
for ($i=1; $i <= $monthsInYear; $i++) {
|
||||
$this->children[$i] = Calendar_Factory::create('Month', $this->year, $i);
|
||||
}
|
||||
|
@ -94,11 +118,14 @@ class Calendar_Year extends Calendar
|
|||
|
||||
/**
|
||||
* Called from build()
|
||||
* @param array
|
||||
*
|
||||
* @param array $sDates array of Calendar_Month objects representing selected dates
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function setSelection($sDates) {
|
||||
function setSelection($sDates)
|
||||
{
|
||||
foreach ($sDates as $sDate) {
|
||||
if ($this->year == $sDate->thisYear()) {
|
||||
$key = $sDate->thisMonth();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
// $Id: calendar_test.php,v 1.1 2004/05/24 22:25:43 quipo Exp $
|
||||
// $Id: calendar_test.php,v 1.2 2008/11/15 21:21:42 quipo Exp $
|
||||
|
||||
require_once('simple_include.php');
|
||||
require_once('calendar_include.php');
|
||||
|
@ -111,5 +111,14 @@ class TestOfCalendar extends UnitTestCase {
|
|||
$stamp = mktime(13,32,43,10,25,2003);
|
||||
$this->assertEqual($stamp,$this->cal->getTimeStamp());
|
||||
}
|
||||
function testIsToday() {
|
||||
$stamp = mktime();
|
||||
$this->cal->setTimestamp($stamp);
|
||||
$this->assertTrue($this->cal->isToday());
|
||||
|
||||
$stamp += 1000000000;
|
||||
$this->cal->setTimestamp($stamp);
|
||||
$this->assertFalse($this->cal->isToday());
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
// $Id: decorator_textual_test.php,v 1.1 2004/05/24 22:25:43 quipo Exp $
|
||||
// $Id: decorator_textual_test.php,v 1.2 2008/11/15 21:21:42 quipo Exp $
|
||||
|
||||
require_once('simple_include.php');
|
||||
require_once('calendar_include.php');
|
||||
|
@ -160,6 +160,11 @@ class TestOfDecoratorTextual extends TestOfDecorator {
|
|||
5=>'Fri',
|
||||
6=>'Sat',
|
||||
);
|
||||
$nShifts = CALENDAR_FIRST_DAY_OF_WEEK;
|
||||
while ($nShifts-- > 0) {
|
||||
$day = array_shift($weekdayNames);
|
||||
array_push($weekdayNames, $day);
|
||||
}
|
||||
$Textual = new Calendar_Decorator_Textual($this->mockcal);
|
||||
$this->assertEqual($weekdayNames,$Textual->orderedWeekdays('short'));
|
||||
}
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
<?php
|
||||
// $Id: month_weekdays_test.php,v 1.1 2004/05/24 22:25:43 quipo Exp $
|
||||
// $Id: month_weekdays_test.php,v 1.3 2008/11/15 21:21:42 quipo Exp $
|
||||
|
||||
require_once('simple_include.php');
|
||||
require_once('calendar_include.php');
|
||||
require_once 'simple_include.php';
|
||||
require_once 'calendar_include.php';
|
||||
|
||||
require_once('./calendar_test.php');
|
||||
require_once './calendar_test.php';
|
||||
|
||||
class TestOfMonthWeekdays extends TestOfCalendar {
|
||||
function TestOfMonthWeekdays() {
|
||||
$this->UnitTestCase('Test of Month Weekdays');
|
||||
}
|
||||
function setUp() {
|
||||
$this->cal = new Calendar_Month_Weekdays(2003,10);
|
||||
$this->cal = new Calendar_Month_Weekdays(2003, 10);
|
||||
}
|
||||
function testPrevDay () {
|
||||
$this->assertEqual(30,$this->cal->prevDay());
|
||||
|
@ -28,41 +28,41 @@ class TestOfMonthWeekdays extends TestOfCalendar {
|
|||
$this->cal->prevDay('array'));
|
||||
}
|
||||
function testThisDay () {
|
||||
$this->assertEqual(1,$this->cal->thisDay());
|
||||
$this->assertEqual(1, $this->cal->thisDay());
|
||||
}
|
||||
function testNextDay () {
|
||||
$this->assertEqual(2,$this->cal->nextDay());
|
||||
$this->assertEqual(2, $this->cal->nextDay());
|
||||
}
|
||||
function testPrevHour () {
|
||||
$this->assertEqual(23,$this->cal->prevHour());
|
||||
$this->assertEqual(23, $this->cal->prevHour());
|
||||
}
|
||||
function testThisHour () {
|
||||
$this->assertEqual(0,$this->cal->thisHour());
|
||||
$this->assertEqual(0, $this->cal->thisHour());
|
||||
}
|
||||
function testNextHour () {
|
||||
$this->assertEqual(1,$this->cal->nextHour());
|
||||
$this->assertEqual(1, $this->cal->nextHour());
|
||||
}
|
||||
function testPrevMinute () {
|
||||
$this->assertEqual(59,$this->cal->prevMinute());
|
||||
$this->assertEqual(59, $this->cal->prevMinute());
|
||||
}
|
||||
function testThisMinute () {
|
||||
$this->assertEqual(0,$this->cal->thisMinute());
|
||||
$this->assertEqual(0, $this->cal->thisMinute());
|
||||
}
|
||||
function testNextMinute () {
|
||||
$this->assertEqual(1,$this->cal->nextMinute());
|
||||
$this->assertEqual(1, $this->cal->nextMinute());
|
||||
}
|
||||
function testPrevSecond () {
|
||||
$this->assertEqual(59,$this->cal->prevSecond());
|
||||
$this->assertEqual(59, $this->cal->prevSecond());
|
||||
}
|
||||
function testThisSecond () {
|
||||
$this->assertEqual(0,$this->cal->thisSecond());
|
||||
$this->assertEqual(0, $this->cal->thisSecond());
|
||||
}
|
||||
function testNextSecond () {
|
||||
$this->assertEqual(1,$this->cal->nextSecond());
|
||||
$this->assertEqual(1, $this->cal->nextSecond());
|
||||
}
|
||||
function testGetTimeStamp() {
|
||||
$stamp = mktime(0,0,0,10,1,2003);
|
||||
$this->assertEqual($stamp,$this->cal->getTimeStamp());
|
||||
$stamp = mktime(0, 0, 0, 10, 1, 2003);
|
||||
$this->assertEqual($stamp, $this->cal->getTimeStamp());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -72,51 +72,57 @@ class TestOfMonthWeekdaysBuild extends TestOfMonthWeekdays {
|
|||
}
|
||||
function testSize() {
|
||||
$this->cal->build();
|
||||
$this->assertEqual(35,$this->cal->size());
|
||||
$this->assertEqual(35, $this->cal->size());
|
||||
}
|
||||
function testFetch() {
|
||||
$this->cal->build();
|
||||
$i=0;
|
||||
while ( $Child = $this->cal->fetch() ) {
|
||||
while ($Child = $this->cal->fetch()) {
|
||||
$i++;
|
||||
}
|
||||
$this->assertEqual(35,$i);
|
||||
$this->assertEqual(35, $i);
|
||||
}
|
||||
function testFetchAll() {
|
||||
$this->cal->build();
|
||||
$children = array();
|
||||
$i = 1;
|
||||
while ( $Child = $this->cal->fetch() ) {
|
||||
$children[$i]=$Child;
|
||||
while ($Child = $this->cal->fetch()) {
|
||||
$children[$i] = $Child;
|
||||
$i++;
|
||||
}
|
||||
$this->assertEqual($children,$this->cal->fetchAll());
|
||||
}
|
||||
function testSelection() {
|
||||
require_once(CALENDAR_ROOT . 'Day.php');
|
||||
$selection = array(new Calendar_Day(2003,10,25));
|
||||
include_once CALENDAR_ROOT . 'Day.php';
|
||||
$selection = array(new Calendar_Day(2003, 10, 25));
|
||||
$this->cal->build($selection);
|
||||
$daysInPrevMonth = (0 == CALENDAR_FIRST_DAY_OF_WEEK) ? 3 : 2;
|
||||
$end = 25 + $daysInPrevMonth;
|
||||
$i = 1;
|
||||
while ( $Child = $this->cal->fetch() ) {
|
||||
if ( $i == 27 )
|
||||
while ($Child = $this->cal->fetch()) {
|
||||
if ($i == $end) {
|
||||
break;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
$this->assertTrue($Child->isSelected());
|
||||
$this->assertEqual(25, $Child->day);
|
||||
}
|
||||
function testEmptyCount() {
|
||||
$this->cal->build();
|
||||
$empty = 0;
|
||||
while ( $Child = $this->cal->fetch() ) {
|
||||
if ( $Child->isEmpty() )
|
||||
while ($Child = $this->cal->fetch()) {
|
||||
if ($Child->isEmpty()) {
|
||||
$empty++;
|
||||
}
|
||||
}
|
||||
$this->assertEqual(4,$empty);
|
||||
$this->assertEqual(4, $empty);
|
||||
}
|
||||
function testEmptyDaysBefore_AfterAdjust() {
|
||||
$this->cal = new Calendar_Month_Weekdays(2004,0);
|
||||
$this->cal = new Calendar_Month_Weekdays(2004, 0);
|
||||
$this->cal->build();
|
||||
$this->assertEqual(0,$this->cal->tableHelper->getEmptyDaysBefore());
|
||||
$expected = (CALENDAR_FIRST_DAY_OF_WEEK == 0) ? 1 : 0;
|
||||
$this->assertEqual($expected, $this->cal->tableHelper->getEmptyDaysBefore());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -124,7 +130,7 @@ if (!defined('TEST_RUNNING')) {
|
|||
define('TEST_RUNNING', true);
|
||||
$test = &new TestOfMonthWeekdays();
|
||||
$test->run(new HtmlReporter());
|
||||
$test = &new TestOfMonthWeekdaysBuild();
|
||||
$test = &new TestOfMonthWeekdaysBuild();
|
||||
$test->run(new HtmlReporter());
|
||||
}
|
||||
?>
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
// $Id: month_weeks_test.php,v 1.1 2004/05/24 22:25:43 quipo Exp $
|
||||
// $Id: month_weeks_test.php,v 1.3 2008/11/15 21:21:42 quipo Exp $
|
||||
|
||||
require_once('simple_include.php');
|
||||
require_once('calendar_include.php');
|
||||
|
@ -11,10 +11,10 @@ class TestOfMonthWeeks extends TestOfCalendar {
|
|||
$this->UnitTestCase('Test of Month Weeks');
|
||||
}
|
||||
function setUp() {
|
||||
$this->cal = new Calendar_Month_Weeks(2003,10);
|
||||
$this->cal = new Calendar_Month_Weeks(2003, 10);
|
||||
}
|
||||
function testPrevDay () {
|
||||
$this->assertEqual(30,$this->cal->prevDay());
|
||||
$this->assertEqual(30, $this->cal->prevDay());
|
||||
}
|
||||
function testPrevDay_Array () {
|
||||
$this->assertEqual(
|
||||
|
@ -28,37 +28,37 @@ class TestOfMonthWeeks extends TestOfCalendar {
|
|||
$this->cal->prevDay('array'));
|
||||
}
|
||||
function testThisDay () {
|
||||
$this->assertEqual(1,$this->cal->thisDay());
|
||||
$this->assertEqual(1, $this->cal->thisDay());
|
||||
}
|
||||
function testNextDay () {
|
||||
$this->assertEqual(2,$this->cal->nextDay());
|
||||
$this->assertEqual(2, $this->cal->nextDay());
|
||||
}
|
||||
function testPrevHour () {
|
||||
$this->assertEqual(23,$this->cal->prevHour());
|
||||
$this->assertEqual(23, $this->cal->prevHour());
|
||||
}
|
||||
function testThisHour () {
|
||||
$this->assertEqual(0,$this->cal->thisHour());
|
||||
$this->assertEqual(0, $this->cal->thisHour());
|
||||
}
|
||||
function testNextHour () {
|
||||
$this->assertEqual(1,$this->cal->nextHour());
|
||||
$this->assertEqual(1, $this->cal->nextHour());
|
||||
}
|
||||
function testPrevMinute () {
|
||||
$this->assertEqual(59,$this->cal->prevMinute());
|
||||
$this->assertEqual(59, $this->cal->prevMinute());
|
||||
}
|
||||
function testThisMinute () {
|
||||
$this->assertEqual(0,$this->cal->thisMinute());
|
||||
$this->assertEqual(0, $this->cal->thisMinute());
|
||||
}
|
||||
function testNextMinute () {
|
||||
$this->assertEqual(1,$this->cal->nextMinute());
|
||||
$this->assertEqual(1, $this->cal->nextMinute());
|
||||
}
|
||||
function testPrevSecond () {
|
||||
$this->assertEqual(59,$this->cal->prevSecond());
|
||||
$this->assertEqual(59, $this->cal->prevSecond());
|
||||
}
|
||||
function testThisSecond () {
|
||||
$this->assertEqual(0,$this->cal->thisSecond());
|
||||
$this->assertEqual(0, $this->cal->thisSecond());
|
||||
}
|
||||
function testNextSecond () {
|
||||
$this->assertEqual(1,$this->cal->nextSecond());
|
||||
$this->assertEqual(1, $this->cal->nextSecond());
|
||||
}
|
||||
function testGetTimeStamp() {
|
||||
$stamp = mktime(0,0,0,10,1,2003);
|
||||
|
@ -78,7 +78,7 @@ class TestOfMonthWeeksBuild extends TestOfMonthWeeks {
|
|||
function testFetch() {
|
||||
$this->cal->build();
|
||||
$i=0;
|
||||
while ( $Child = $this->cal->fetch() ) {
|
||||
while ($Child = $this->cal->fetch()) {
|
||||
$i++;
|
||||
}
|
||||
$this->assertEqual(5,$i);
|
||||
|
@ -96,22 +96,26 @@ class TestOfMonthWeeksBuild extends TestOfMonthWeeks {
|
|||
}
|
||||
*/
|
||||
function testSelection() {
|
||||
require_once(CALENDAR_ROOT . 'Week.php');
|
||||
include_once CALENDAR_ROOT . 'Week.php';
|
||||
$selection = array(new Calendar_Week(2003, 10, 12));
|
||||
$this->cal->build($selection);
|
||||
$i = 1;
|
||||
$expected = (CALENDAR_FIRST_DAY_OF_WEEK == 0) ? 3 : 2;
|
||||
while ($Child = $this->cal->fetch()) {
|
||||
if ($i == 2) {
|
||||
break; //12-10-2003 is the 2nd day of the week
|
||||
if ($i == $expected) {
|
||||
//12-10-2003 is in the 2nd week of the month if firstDay is Monday,
|
||||
//in the 3rd if firstDay is Sunday
|
||||
break;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
$this->assertTrue($Child->isSelected());
|
||||
}
|
||||
function testEmptyDaysBefore_AfterAdjust() {
|
||||
$this->cal = new Calendar_Month_Weeks(2004,0);
|
||||
$this->cal = new Calendar_Month_Weeks(2004, 0);
|
||||
$this->cal->build();
|
||||
$this->assertEqual(0,$this->cal->tableHelper->getEmptyDaysBefore());
|
||||
$expected = (CALENDAR_FIRST_DAY_OF_WEEK == 0) ? 1 : 0;
|
||||
$this->assertEqual($expected, $this->cal->tableHelper->getEmptyDaysBefore());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
// $Id: peardate_engine_test.php,v 1.2 2004/08/16 11:36:51 hfuecks Exp $
|
||||
// $Id: peardate_engine_test.php,v 1.3 2008/11/15 21:21:42 quipo Exp $
|
||||
|
||||
require_once('simple_include.php');
|
||||
require_once('calendar_include.php');
|
||||
|
@ -114,6 +114,12 @@ class TestOfPearDateEngine extends UnitTestCase {
|
|||
|
||||
$this->assertEqual($this->engine->getDayOfWeek($y, $m, $d), 3);
|
||||
}
|
||||
function testIsToday() {
|
||||
$stamp = date('Y-m-d H:i:s');
|
||||
$this->assertTrue($this->engine->isToday($stamp));
|
||||
$stamp = date('Y-m-d H:i:s', time() + 1000000000);
|
||||
$this->assertFalse($this->engine->isToday($stamp));
|
||||
}
|
||||
}
|
||||
|
||||
if (!defined('TEST_RUNNING')) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
// $Id: unixts_engine_test.php,v 1.2 2004/08/16 11:36:51 hfuecks Exp $
|
||||
// $Id: unixts_engine_test.php,v 1.3 2008/11/15 21:21:42 quipo Exp $
|
||||
|
||||
require_once('simple_include.php');
|
||||
require_once('calendar_include.php');
|
||||
|
@ -94,6 +94,12 @@ class TestOfUnixTsEngine extends UnitTestCase {
|
|||
$stamp = mktime(13,30,45,10,15,2003);
|
||||
$this->assertEqual($this->engine->stampToYear($stamp),2003);
|
||||
}
|
||||
function testIsToday() {
|
||||
$stamp = mktime();
|
||||
$this->assertTrue($this->engine->isToday($stamp));
|
||||
$stamp += 1000000000;
|
||||
$this->assertFalse($this->engine->isToday($stamp));
|
||||
}
|
||||
}
|
||||
|
||||
if (!defined('TEST_RUNNING')) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
// $Id: util_textual_test.php,v 1.1 2004/08/16 12:56:10 hfuecks Exp $
|
||||
// $Id: util_textual_test.php,v 1.2 2008/11/15 21:21:42 quipo Exp $
|
||||
|
||||
require_once('simple_include.php');
|
||||
require_once('calendar_include.php');
|
||||
|
@ -178,6 +178,11 @@ class TestOfUtilTextual extends UnitTestCase {
|
|||
5=>'Fri',
|
||||
6=>'Sat',
|
||||
);
|
||||
$nShifts = CALENDAR_FIRST_DAY_OF_WEEK;
|
||||
while ($nShifts-- > 0) {
|
||||
$day = array_shift($weekdayNames);
|
||||
array_push($weekdayNames, $day);
|
||||
}
|
||||
$this->assertEqual($weekdayNames,Calendar_Util_Textual::orderedWeekdays($this->mockcal,'short'));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
// $Id: week_test.php,v 1.4 2005/10/20 18:56:21 quipo Exp $
|
||||
// $Id: week_test.php,v 1.5 2006/10/20 14:03:58 quipo Exp $
|
||||
define('CALENDAR_FIRST_DAY_OF_WEEK', 1); //force firstDay = monday
|
||||
|
||||
require_once('simple_include.php');
|
||||
|
@ -15,6 +15,41 @@ class TestOfWeek extends TestOfCalendar {
|
|||
$this->cal = Calendar_Factory::create('Week', 2003, 10, 9);
|
||||
//print_r($this->cal);
|
||||
}
|
||||
function testThisYear () {
|
||||
$this->assertEqual(2003, $this->cal->thisYear());
|
||||
|
||||
$stamp = mktime(0,0,0,1,1,2003);
|
||||
$this->cal->setTimestamp($stamp);
|
||||
$this->assertEqual(2003, $this->cal->thisYear());
|
||||
|
||||
$stamp = mktime(0,0,0,12,31,2003);
|
||||
$this->cal->setTimestamp($stamp);
|
||||
$this->assertEqual(2004, $this->cal->thisYear());
|
||||
|
||||
$stamp = mktime(0,0,0,1,1,2005);
|
||||
$this->cal->setTimestamp($stamp);
|
||||
$this->assertEqual(2004, $this->cal->thisYear());
|
||||
|
||||
$stamp = mktime(0,0,0,12,31,2004);
|
||||
$this->cal->setTimestamp($stamp);
|
||||
$this->assertEqual(2004, $this->cal->thisYear());
|
||||
|
||||
$stamp = mktime(0,0,0,1,1,2005);
|
||||
$this->cal->setTimestamp($stamp);
|
||||
$this->assertEqual(2004, $this->cal->thisYear());
|
||||
|
||||
$stamp = mktime(0,0,0,12,31,2005);
|
||||
$this->cal->setTimestamp($stamp);
|
||||
$this->assertEqual(2005, $this->cal->thisYear());
|
||||
|
||||
$stamp = mktime(0,0,0,1,1,2006);
|
||||
$this->cal->setTimestamp($stamp);
|
||||
$this->assertEqual(2005, $this->cal->thisYear());
|
||||
|
||||
$stamp = mktime(0,0,0,12,31,2006);
|
||||
$this->cal->setTimestamp($stamp);
|
||||
$this->assertEqual(2006, $this->cal->thisYear());
|
||||
}
|
||||
function testPrevDay () {
|
||||
$this->assertEqual(8, $this->cal->prevDay());
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// | PHP Version 5 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// | Copyright (c) 1997-2004 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 3.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
|
@ -16,7 +16,7 @@
|
|||
// | Author: Andrei Zmievski <andrei@php.net> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Getopt.php,v 1.21.4.7 2003/12/05 21:57:01 andrei Exp $
|
||||
// $Id: Getopt.php,v 1.4 2007/06/12 14:58:56 cellog Exp $
|
||||
|
||||
require_once 'PEAR.php';
|
||||
|
||||
|
@ -127,6 +127,10 @@ class Console_Getopt {
|
|||
$error = Console_Getopt::_parseLongOption(substr($arg, 2), $long_options, $opts, $args);
|
||||
if (PEAR::isError($error))
|
||||
return $error;
|
||||
} elseif ($arg == '-') {
|
||||
// - is stdin
|
||||
$non_opts = array_merge($non_opts, array_slice($args, $i));
|
||||
break;
|
||||
} else {
|
||||
$error = Console_Getopt::_parseShortOption(substr($arg, 1), $short_options, $opts, $args);
|
||||
if (PEAR::isError($error))
|
||||
|
@ -167,10 +171,14 @@ class Console_Getopt {
|
|||
if ($i + 1 < strlen($arg)) {
|
||||
$opts[] = array($opt, substr($arg, $i + 1));
|
||||
break;
|
||||
} else if (list(, $opt_arg) = each($args))
|
||||
} else if (list(, $opt_arg) = each($args)) {
|
||||
/* Else use the next argument. */;
|
||||
else
|
||||
if (Console_Getopt::_isShortOpt($opt_arg) || Console_Getopt::_isLongOpt($opt_arg)) {
|
||||
return PEAR::raiseError("Console_Getopt: option requires an argument -- $opt");
|
||||
}
|
||||
} else {
|
||||
return PEAR::raiseError("Console_Getopt: option requires an argument -- $opt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -178,30 +186,58 @@ class Console_Getopt {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @access private
|
||||
*
|
||||
*/
|
||||
function _isShortOpt($arg)
|
||||
{
|
||||
return strlen($arg) == 2 && $arg[0] == '-' && preg_match('/[a-zA-Z]/', $arg[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @access private
|
||||
*
|
||||
*/
|
||||
function _isLongOpt($arg)
|
||||
{
|
||||
return strlen($arg) > 2 && $arg[0] == '-' && $arg[1] == '-' &&
|
||||
preg_match('/[a-zA-Z]+$/', substr($arg, 2));
|
||||
}
|
||||
|
||||
/**
|
||||
* @access private
|
||||
*
|
||||
*/
|
||||
function _parseLongOption($arg, $long_options, &$opts, &$args)
|
||||
{
|
||||
@list($opt, $opt_arg) = explode('=', $arg);
|
||||
@list($opt, $opt_arg) = explode('=', $arg, 2);
|
||||
$opt_len = strlen($opt);
|
||||
|
||||
for ($i = 0; $i < count($long_options); $i++) {
|
||||
$long_opt = $long_options[$i];
|
||||
$opt_start = substr($long_opt, 0, $opt_len);
|
||||
$long_opt_name = str_replace('=', '', $long_opt);
|
||||
|
||||
/* Option doesn't match. Go on to the next one. */
|
||||
if ($opt_start != $opt)
|
||||
if ($long_opt_name != $opt) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$opt_rest = substr($long_opt, $opt_len);
|
||||
|
||||
/* Check that the options uniquely matches one of the allowed
|
||||
options. */
|
||||
if ($i + 1 < count($long_options)) {
|
||||
$next_option_rest = substr($long_options[$i + 1], $opt_len);
|
||||
} else {
|
||||
$next_option_rest = '';
|
||||
}
|
||||
if ($opt_rest != '' && $opt{0} != '=' &&
|
||||
$i + 1 < count($long_options) &&
|
||||
$opt == substr($long_options[$i+1], 0, $opt_len)) {
|
||||
$opt == substr($long_options[$i+1], 0, $opt_len) &&
|
||||
$next_option_rest != '' &&
|
||||
$next_option_rest{0} != '=') {
|
||||
return PEAR::raiseError("Console_Getopt: option --$opt is ambiguous");
|
||||
}
|
||||
|
||||
|
@ -212,6 +248,9 @@ class Console_Getopt {
|
|||
if (!strlen($opt_arg) && !(list(, $opt_arg) = each($args))) {
|
||||
return PEAR::raiseError("Console_Getopt: option --$opt requires an argument");
|
||||
}
|
||||
if (Console_Getopt::_isShortOpt($opt_arg) || Console_Getopt::_isLongOpt($opt_arg)) {
|
||||
return PEAR::raiseError("Console_Getopt: option requires an argument --$opt");
|
||||
}
|
||||
}
|
||||
} else if ($opt_arg) {
|
||||
return PEAR::raiseError("Console_Getopt: option --$opt doesn't allow an argument");
|
||||
|
|
|
@ -18,9 +18,9 @@
|
|||
* @author Stig Bakken <ssb@php.net>
|
||||
* @author Tomas V.V.Cox <cox@idecnet.com>
|
||||
* @author Daniel Convissor <danielc@php.net>
|
||||
* @copyright 1997-2005 The PHP Group
|
||||
* @copyright 1997-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id: DB.php,v 1.86 2007/01/22 01:17:48 aharvey Exp $
|
||||
* @version CVS: $Id: DB.php,v 1.88 2007/08/12 05:27:25 aharvey Exp $
|
||||
* @link http://pear.php.net/package/DB
|
||||
*/
|
||||
|
||||
|
@ -424,9 +424,9 @@ define('DB_PORTABILITY_ALL', 63);
|
|||
* @author Stig Bakken <ssb@php.net>
|
||||
* @author Tomas V.V.Cox <cox@idecnet.com>
|
||||
* @author Daniel Convissor <danielc@php.net>
|
||||
* @copyright 1997-2005 The PHP Group
|
||||
* @copyright 1997-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version Release: 1.7.9
|
||||
* @version Release: 1.7.13
|
||||
* @link http://pear.php.net/package/DB
|
||||
*/
|
||||
class DB
|
||||
|
@ -467,7 +467,7 @@ class DB
|
|||
return $tmp;
|
||||
}
|
||||
|
||||
@$obj =& new $classname;
|
||||
@$obj = new $classname;
|
||||
|
||||
foreach ($options as $option => $value) {
|
||||
$test = $obj->setOption($option, $value);
|
||||
|
@ -544,7 +544,7 @@ class DB
|
|||
return $tmp;
|
||||
}
|
||||
|
||||
@$obj =& new $classname;
|
||||
@$obj = new $classname;
|
||||
|
||||
foreach ($options as $option => $value) {
|
||||
$test = $obj->setOption($option, $value);
|
||||
|
@ -576,7 +576,7 @@ class DB
|
|||
*/
|
||||
function apiVersion()
|
||||
{
|
||||
return '1.7.9';
|
||||
return '1.7.13';
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
@ -938,9 +938,9 @@ class DB
|
|||
* @category Database
|
||||
* @package DB
|
||||
* @author Stig Bakken <ssb@php.net>
|
||||
* @copyright 1997-2005 The PHP Group
|
||||
* @copyright 1997-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version Release: 1.7.9
|
||||
* @version Release: 1.7.13
|
||||
* @link http://pear.php.net/package/DB
|
||||
*/
|
||||
class DB_Error extends PEAR_Error
|
||||
|
@ -985,9 +985,9 @@ class DB_Error extends PEAR_Error
|
|||
* @category Database
|
||||
* @package DB
|
||||
* @author Stig Bakken <ssb@php.net>
|
||||
* @copyright 1997-2005 The PHP Group
|
||||
* @copyright 1997-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version Release: 1.7.9
|
||||
* @version Release: 1.7.13
|
||||
* @link http://pear.php.net/package/DB
|
||||
*/
|
||||
class DB_result
|
||||
|
@ -1199,7 +1199,7 @@ class DB_result
|
|||
if ($object_class == 'stdClass') {
|
||||
$arr = (object) $arr;
|
||||
} else {
|
||||
$arr = &new $object_class($arr);
|
||||
$arr = new $object_class($arr);
|
||||
}
|
||||
}
|
||||
return $arr;
|
||||
|
@ -1450,9 +1450,9 @@ class DB_result
|
|||
* @category Database
|
||||
* @package DB
|
||||
* @author Stig Bakken <ssb@php.net>
|
||||
* @copyright 1997-2005 The PHP Group
|
||||
* @copyright 1997-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version Release: 1.7.9
|
||||
* @version Release: 1.7.13
|
||||
* @link http://pear.php.net/package/DB
|
||||
* @see DB_common::setFetchMode()
|
||||
*/
|
||||
|
|
|
@ -18,9 +18,9 @@
|
|||
* @author Stig Bakken <ssb@php.net>
|
||||
* @author Tomas V.V. Cox <cox@idecnet.com>
|
||||
* @author Daniel Convissor <danielc@php.net>
|
||||
* @copyright 1997-2005 The PHP Group
|
||||
* @copyright 1997-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id: common.php,v 1.140 2007/01/12 02:41:07 aharvey Exp $
|
||||
* @version CVS: $Id: common.php,v 1.143 2007/09/21 13:40:41 aharvey Exp $
|
||||
* @link http://pear.php.net/package/DB
|
||||
*/
|
||||
|
||||
|
@ -40,9 +40,9 @@ require_once 'PEAR.php';
|
|||
* @author Stig Bakken <ssb@php.net>
|
||||
* @author Tomas V.V. Cox <cox@idecnet.com>
|
||||
* @author Daniel Convissor <danielc@php.net>
|
||||
* @copyright 1997-2005 The PHP Group
|
||||
* @copyright 1997-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version Release: 1.7.9
|
||||
* @version Release: 1.7.13
|
||||
* @link http://pear.php.net/package/DB
|
||||
*/
|
||||
class DB_common extends PEAR
|
||||
|
@ -891,7 +891,7 @@ class DB_common extends PEAR
|
|||
if (DB::isError($sth)) {
|
||||
return $sth;
|
||||
}
|
||||
$ret =& $this->execute($sth, array_values($fields_values));
|
||||
$ret = $this->execute($sth, array_values($fields_values));
|
||||
$this->freePrepared($sth);
|
||||
return $ret;
|
||||
|
||||
|
@ -985,7 +985,7 @@ class DB_common extends PEAR
|
|||
* "'it''s good'",
|
||||
* 'filename.txt'
|
||||
* );
|
||||
* $res =& $db->execute($sth, $data);
|
||||
* $res = $db->execute($sth, $data);
|
||||
* </code>
|
||||
*
|
||||
* @param resource $stmt a DB statement resource returned from prepare()
|
||||
|
@ -1014,7 +1014,7 @@ class DB_common extends PEAR
|
|||
if ($result === DB_OK || DB::isError($result)) {
|
||||
return $result;
|
||||
} else {
|
||||
$tmp =& new DB_result($this, $result);
|
||||
$tmp = new DB_result($this, $result);
|
||||
return $tmp;
|
||||
}
|
||||
}
|
||||
|
@ -1095,7 +1095,7 @@ class DB_common extends PEAR
|
|||
function executeMultiple($stmt, $data)
|
||||
{
|
||||
foreach ($data as $value) {
|
||||
$res =& $this->execute($stmt, $value);
|
||||
$res = $this->execute($stmt, $value);
|
||||
if (DB::isError($res)) {
|
||||
return $res;
|
||||
}
|
||||
|
@ -1208,7 +1208,7 @@ class DB_common extends PEAR
|
|||
if (DB::isError($sth)) {
|
||||
return $sth;
|
||||
}
|
||||
$ret =& $this->execute($sth, $params);
|
||||
$ret = $this->execute($sth, $params);
|
||||
$this->freePrepared($sth, false);
|
||||
return $ret;
|
||||
} else {
|
||||
|
@ -1217,7 +1217,7 @@ class DB_common extends PEAR
|
|||
if ($result === DB_OK || DB::isError($result)) {
|
||||
return $result;
|
||||
} else {
|
||||
$tmp =& new DB_result($this, $result);
|
||||
$tmp = new DB_result($this, $result);
|
||||
return $tmp;
|
||||
}
|
||||
}
|
||||
|
@ -1248,7 +1248,7 @@ class DB_common extends PEAR
|
|||
if (DB::isError($query)){
|
||||
return $query;
|
||||
}
|
||||
$result =& $this->query($query, $params);
|
||||
$result = $this->query($query, $params);
|
||||
if (is_a($result, 'DB_result')) {
|
||||
$result->setOption('limit_from', $from);
|
||||
$result->setOption('limit_count', $count);
|
||||
|
@ -1283,10 +1283,10 @@ class DB_common extends PEAR
|
|||
if (DB::isError($sth)) {
|
||||
return $sth;
|
||||
}
|
||||
$res =& $this->execute($sth, $params);
|
||||
$res = $this->execute($sth, $params);
|
||||
$this->freePrepared($sth);
|
||||
} else {
|
||||
$res =& $this->query($query);
|
||||
$res = $this->query($query);
|
||||
}
|
||||
|
||||
if (DB::isError($res)) {
|
||||
|
@ -1347,10 +1347,10 @@ class DB_common extends PEAR
|
|||
if (DB::isError($sth)) {
|
||||
return $sth;
|
||||
}
|
||||
$res =& $this->execute($sth, $params);
|
||||
$res = $this->execute($sth, $params);
|
||||
$this->freePrepared($sth);
|
||||
} else {
|
||||
$res =& $this->query($query);
|
||||
$res = $this->query($query);
|
||||
}
|
||||
|
||||
if (DB::isError($res)) {
|
||||
|
@ -1398,10 +1398,10 @@ class DB_common extends PEAR
|
|||
return $sth;
|
||||
}
|
||||
|
||||
$res =& $this->execute($sth, $params);
|
||||
$res = $this->execute($sth, $params);
|
||||
$this->freePrepared($sth);
|
||||
} else {
|
||||
$res =& $this->query($query);
|
||||
$res = $this->query($query);
|
||||
}
|
||||
|
||||
if (DB::isError($res)) {
|
||||
|
@ -1414,7 +1414,7 @@ class DB_common extends PEAR
|
|||
$ret = array();
|
||||
} else {
|
||||
if (!array_key_exists($col, $row)) {
|
||||
$ret =& $this->raiseError(DB_ERROR_NOSUCHFIELD);
|
||||
$ret = $this->raiseError(DB_ERROR_NOSUCHFIELD);
|
||||
} else {
|
||||
$ret = array($row[$col]);
|
||||
while (is_array($row = $res->fetchRow($fetchmode))) {
|
||||
|
@ -1530,10 +1530,10 @@ class DB_common extends PEAR
|
|||
return $sth;
|
||||
}
|
||||
|
||||
$res =& $this->execute($sth, $params);
|
||||
$res = $this->execute($sth, $params);
|
||||
$this->freePrepared($sth);
|
||||
} else {
|
||||
$res =& $this->query($query);
|
||||
$res = $this->query($query);
|
||||
}
|
||||
|
||||
if (DB::isError($res)) {
|
||||
|
@ -1545,7 +1545,7 @@ class DB_common extends PEAR
|
|||
$cols = $res->numCols();
|
||||
|
||||
if ($cols < 2) {
|
||||
$tmp =& $this->raiseError(DB_ERROR_TRUNCATED);
|
||||
$tmp = $this->raiseError(DB_ERROR_TRUNCATED);
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
|
@ -1657,10 +1657,10 @@ class DB_common extends PEAR
|
|||
return $sth;
|
||||
}
|
||||
|
||||
$res =& $this->execute($sth, $params);
|
||||
$res = $this->execute($sth, $params);
|
||||
$this->freePrepared($sth);
|
||||
} else {
|
||||
$res =& $this->query($query);
|
||||
$res = $this->query($query);
|
||||
}
|
||||
|
||||
if ($res === DB_OK || DB::isError($res)) {
|
||||
|
@ -1681,7 +1681,7 @@ class DB_common extends PEAR
|
|||
$res->free();
|
||||
|
||||
if (DB::isError($row)) {
|
||||
$tmp =& $this->raiseError($row);
|
||||
$tmp = $this->raiseError($row);
|
||||
return $tmp;
|
||||
}
|
||||
return $results;
|
||||
|
|
|
@ -18,9 +18,9 @@
|
|||
* @package DB
|
||||
* @author Tomas V.V. Cox <cox@idecnet.com>
|
||||
* @author Daniel Convissor <danielc@php.net>
|
||||
* @copyright 1997-2005 The PHP Group
|
||||
* @copyright 1997-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id: dbase.php,v 1.42 2007/01/11 07:43:09 aharvey Exp $
|
||||
* @version CVS: $Id: dbase.php,v 1.45 2007/09/21 13:40:41 aharvey Exp $
|
||||
* @link http://pear.php.net/package/DB
|
||||
*/
|
||||
|
||||
|
@ -39,9 +39,9 @@ require_once 'DB/common.php';
|
|||
* @package DB
|
||||
* @author Tomas V.V. Cox <cox@idecnet.com>
|
||||
* @author Daniel Convissor <danielc@php.net>
|
||||
* @copyright 1997-2005 The PHP Group
|
||||
* @copyright 1997-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version Release: 1.7.9
|
||||
* @version Release: 1.7.13
|
||||
* @link http://pear.php.net/package/DB
|
||||
*/
|
||||
class DB_dbase extends DB_common
|
||||
|
@ -188,7 +188,7 @@ class DB_dbase extends DB_common
|
|||
* 'portability' => DB_PORTABILITY_ALL,
|
||||
* );
|
||||
*
|
||||
* $db =& DB::connect($dsn, $options);
|
||||
* $db = DB::connect($dsn, $options);
|
||||
* if (PEAR::isError($db)) {
|
||||
* die($db->getMessage());
|
||||
* }
|
||||
|
@ -273,7 +273,7 @@ class DB_dbase extends DB_common
|
|||
{
|
||||
// emulate result resources
|
||||
$this->res_row[(int)$this->result] = 0;
|
||||
$tmp =& new DB_result($this, $this->result++);
|
||||
$tmp = new DB_result($this, $this->result++);
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,9 +18,9 @@
|
|||
* @package DB
|
||||
* @author Frank M. Kromann <frank@frontbase.com>
|
||||
* @author Daniel Convissor <danielc@php.net>
|
||||
* @copyright 1997-2005 The PHP Group
|
||||
* @copyright 1997-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id: fbsql.php,v 1.86 2007/01/12 03:11:17 aharvey Exp $
|
||||
* @version CVS: $Id: fbsql.php,v 1.88 2007/07/06 05:19:21 aharvey Exp $
|
||||
* @link http://pear.php.net/package/DB
|
||||
*/
|
||||
|
||||
|
@ -39,9 +39,9 @@ require_once 'DB/common.php';
|
|||
* @package DB
|
||||
* @author Frank M. Kromann <frank@frontbase.com>
|
||||
* @author Daniel Convissor <danielc@php.net>
|
||||
* @copyright 1997-2005 The PHP Group
|
||||
* @copyright 1997-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version Release: 1.7.9
|
||||
* @version Release: 1.7.13
|
||||
* @link http://pear.php.net/package/DB
|
||||
* @since Class functional since Release 1.7.0
|
||||
*/
|
||||
|
@ -353,7 +353,7 @@ class DB_fbsql extends DB_common
|
|||
*/
|
||||
function commit()
|
||||
{
|
||||
@fbsql_commit();
|
||||
@fbsql_commit($this->connection);
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
@ -366,7 +366,7 @@ class DB_fbsql extends DB_common
|
|||
*/
|
||||
function rollback()
|
||||
{
|
||||
@fbsql_rollback();
|
||||
@fbsql_rollback($this->connection);
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
|
|
@ -21,9 +21,9 @@
|
|||
* @package DB
|
||||
* @author Sterling Hughes <sterling@php.net>
|
||||
* @author Daniel Convissor <danielc@php.net>
|
||||
* @copyright 1997-2005 The PHP Group
|
||||
* @copyright 1997-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id: ibase.php,v 1.113 2007/01/12 03:11:17 aharvey Exp $
|
||||
* @version CVS: $Id: ibase.php,v 1.116 2007/09/21 13:40:41 aharvey Exp $
|
||||
* @link http://pear.php.net/package/DB
|
||||
*/
|
||||
|
||||
|
@ -47,9 +47,9 @@ require_once 'DB/common.php';
|
|||
* @package DB
|
||||
* @author Sterling Hughes <sterling@php.net>
|
||||
* @author Daniel Convissor <danielc@php.net>
|
||||
* @copyright 1997-2005 The PHP Group
|
||||
* @copyright 1997-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version Release: 1.7.9
|
||||
* @version Release: 1.7.13
|
||||
* @link http://pear.php.net/package/DB
|
||||
* @since Class became stable in Release 1.7.0
|
||||
*/
|
||||
|
@ -553,9 +553,9 @@ class DB_ibase extends DB_common
|
|||
$data = (array)$data;
|
||||
$this->last_parameters = $data;
|
||||
|
||||
$types =& $this->prepare_types[(int)$stmt];
|
||||
$types = $this->prepare_types[(int)$stmt];
|
||||
if (count($types) != count($data)) {
|
||||
$tmp =& $this->raiseError(DB_ERROR_MISMATCH);
|
||||
$tmp = $this->raiseError(DB_ERROR_MISMATCH);
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
|
@ -574,7 +574,7 @@ class DB_ibase extends DB_common
|
|||
} elseif ($types[$i] == DB_PARAM_OPAQUE) {
|
||||
$fp = @fopen($data[$key], 'rb');
|
||||
if (!$fp) {
|
||||
$tmp =& $this->raiseError(DB_ERROR_ACCESS_VIOLATION);
|
||||
$tmp = $this->raiseError(DB_ERROR_ACCESS_VIOLATION);
|
||||
return $tmp;
|
||||
}
|
||||
$data[$key] = fread($fp, filesize($data[$key]));
|
||||
|
@ -587,7 +587,7 @@ class DB_ibase extends DB_common
|
|||
|
||||
$res = call_user_func_array('ibase_execute', $data);
|
||||
if (!$res) {
|
||||
$tmp =& $this->ibaseRaiseError();
|
||||
$tmp = $this->ibaseRaiseError();
|
||||
return $tmp;
|
||||
}
|
||||
/* XXX need this?
|
||||
|
@ -601,7 +601,7 @@ class DB_ibase extends DB_common
|
|||
$tmp = DB_OK;
|
||||
} else {
|
||||
$this->_last_query_manip = false;
|
||||
$tmp =& new DB_result($this, $res);
|
||||
$tmp = new DB_result($this, $res);
|
||||
}
|
||||
return $tmp;
|
||||
}
|
||||
|
@ -707,7 +707,7 @@ class DB_ibase extends DB_common
|
|||
$repeat = 0;
|
||||
do {
|
||||
$this->pushErrorHandling(PEAR_ERROR_RETURN);
|
||||
$result =& $this->query("SELECT GEN_ID(${sqn}, 1) "
|
||||
$result = $this->query("SELECT GEN_ID(${sqn}, 1) "
|
||||
. 'FROM RDB$GENERATORS '
|
||||
. "WHERE RDB\$GENERATOR_NAME='${sqn}'");
|
||||
$this->popErrorHandling();
|
||||
|
@ -865,7 +865,7 @@ class DB_ibase extends DB_common
|
|||
if ($errno === null) {
|
||||
$errno = $this->errorCode($this->errorNative());
|
||||
}
|
||||
$tmp =& $this->raiseError($errno, null, null, null, @ibase_errmsg());
|
||||
$tmp = $this->raiseError($errno, null, null, null, @ibase_errmsg());
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,9 +18,9 @@
|
|||
* @package DB
|
||||
* @author Tomas V.V.Cox <cox@idecnet.com>
|
||||
* @author Daniel Convissor <danielc@php.net>
|
||||
* @copyright 1997-2005 The PHP Group
|
||||
* @copyright 1997-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id: ifx.php,v 1.74 2007/01/12 03:11:17 aharvey Exp $
|
||||
* @version CVS: $Id: ifx.php,v 1.75 2007/07/06 05:19:21 aharvey Exp $
|
||||
* @link http://pear.php.net/package/DB
|
||||
*/
|
||||
|
||||
|
@ -46,9 +46,9 @@ require_once 'DB/common.php';
|
|||
* @package DB
|
||||
* @author Tomas V.V.Cox <cox@idecnet.com>
|
||||
* @author Daniel Convissor <danielc@php.net>
|
||||
* @copyright 1997-2005 The PHP Group
|
||||
* @copyright 1997-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version Release: 1.7.9
|
||||
* @version Release: 1.7.13
|
||||
* @link http://pear.php.net/package/DB
|
||||
*/
|
||||
class DB_ifx extends DB_common
|
||||
|
|
|
@ -21,9 +21,9 @@
|
|||
* @category Database
|
||||
* @package DB
|
||||
* @author Daniel Convissor <danielc@php.net>
|
||||
* @copyright 1997-2005 The PHP Group
|
||||
* @copyright 1997-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id: msql.php,v 1.62 2007/01/12 03:11:17 aharvey Exp $
|
||||
* @version CVS: $Id: msql.php,v 1.64 2007/09/21 13:40:41 aharvey Exp $
|
||||
* @link http://pear.php.net/package/DB
|
||||
*/
|
||||
|
||||
|
@ -45,9 +45,9 @@ require_once 'DB/common.php';
|
|||
* @category Database
|
||||
* @package DB
|
||||
* @author Daniel Convissor <danielc@php.net>
|
||||
* @copyright 1997-2005 The PHP Group
|
||||
* @copyright 1997-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version Release: 1.7.9
|
||||
* @version Release: 1.7.13
|
||||
* @link http://pear.php.net/package/DB
|
||||
* @since Class not functional until Release 1.7.0
|
||||
*/
|
||||
|
@ -153,7 +153,7 @@ class DB_msql extends DB_common
|
|||
* 'portability' => DB_PORTABILITY_ALL,
|
||||
* );
|
||||
*
|
||||
* $db =& DB::connect($dsn, $options);
|
||||
* $db = DB::connect($dsn, $options);
|
||||
* if (PEAR::isError($db)) {
|
||||
* die($db->getMessage());
|
||||
* }
|
||||
|
@ -443,7 +443,7 @@ class DB_msql extends DB_common
|
|||
$repeat = false;
|
||||
do {
|
||||
$this->pushErrorHandling(PEAR_ERROR_RETURN);
|
||||
$result =& $this->query("SELECT _seq FROM ${seqname}");
|
||||
$result = $this->query("SELECT _seq FROM ${seqname}");
|
||||
$this->popErrorHandling();
|
||||
if ($ondemand && DB::isError($result) &&
|
||||
$result->getCode() == DB_ERROR_NOSUCHTABLE) {
|
||||
|
|
|
@ -18,9 +18,9 @@
|
|||
* @package DB
|
||||
* @author Sterling Hughes <sterling@php.net>
|
||||
* @author Daniel Convissor <danielc@php.net>
|
||||
* @copyright 1997-2005 The PHP Group
|
||||
* @copyright 1997-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id: mssql.php,v 1.90 2007/01/12 05:16:22 aharvey Exp $
|
||||
* @version CVS: $Id: mssql.php,v 1.92 2007/09/21 13:40:41 aharvey Exp $
|
||||
* @link http://pear.php.net/package/DB
|
||||
*/
|
||||
|
||||
|
@ -47,9 +47,9 @@ require_once 'DB/common.php';
|
|||
* @package DB
|
||||
* @author Sterling Hughes <sterling@php.net>
|
||||
* @author Daniel Convissor <danielc@php.net>
|
||||
* @copyright 1997-2005 The PHP Group
|
||||
* @copyright 1997-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version Release: 1.7.9
|
||||
* @version Release: 1.7.13
|
||||
* @link http://pear.php.net/package/DB
|
||||
*/
|
||||
class DB_mssql extends DB_common
|
||||
|
@ -566,14 +566,14 @@ class DB_mssql extends DB_common
|
|||
return $this->raiseError($result);
|
||||
}
|
||||
} elseif (!DB::isError($result)) {
|
||||
$result =& $this->query("SELECT IDENT_CURRENT('$seqname')");
|
||||
$result = $this->query("SELECT IDENT_CURRENT('$seqname')");
|
||||
if (DB::isError($result)) {
|
||||
/* Fallback code for MS SQL Server 7.0, which doesn't have
|
||||
* IDENT_CURRENT. This is *not* safe for concurrent
|
||||
* requests, and really, if you're using it, you're in a
|
||||
* world of hurt. Nevertheless, it's here to ensure BC. See
|
||||
* bug #181 for the gory details.*/
|
||||
$result =& $this->query("SELECT @@IDENTITY FROM $seqname");
|
||||
$result = $this->query("SELECT @@IDENTITY FROM $seqname");
|
||||
}
|
||||
$repeat = 0;
|
||||
} else {
|
||||
|
|
|
@ -18,9 +18,9 @@
|
|||
* @package DB
|
||||
* @author Stig Bakken <ssb@php.net>
|
||||
* @author Daniel Convissor <danielc@php.net>
|
||||
* @copyright 1997-2005 The PHP Group
|
||||
* @copyright 1997-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id: mysql.php,v 1.124 2007/01/12 03:11:17 aharvey Exp $
|
||||
* @version CVS: $Id: mysql.php,v 1.126 2007/09/21 13:32:52 aharvey Exp $
|
||||
* @link http://pear.php.net/package/DB
|
||||
*/
|
||||
|
||||
|
@ -39,9 +39,9 @@ require_once 'DB/common.php';
|
|||
* @package DB
|
||||
* @author Stig Bakken <ssb@php.net>
|
||||
* @author Daniel Convissor <danielc@php.net>
|
||||
* @copyright 1997-2005 The PHP Group
|
||||
* @copyright 1997-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version Release: 1.7.9
|
||||
* @version Release: 1.7.13
|
||||
* @link http://pear.php.net/package/DB
|
||||
*/
|
||||
class DB_mysql extends DB_common
|
||||
|
@ -932,6 +932,13 @@ class DB_mysql extends DB_common
|
|||
function tableInfo($result, $mode = null)
|
||||
{
|
||||
if (is_string($result)) {
|
||||
// Fix for bug #11580.
|
||||
if ($this->_db) {
|
||||
if (!@mysql_select_db($this->_db, $this->connection)) {
|
||||
return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Probably received a table name.
|
||||
* Create a result resource identifier.
|
||||
|
|
|
@ -17,9 +17,9 @@
|
|||
* @category Database
|
||||
* @package DB
|
||||
* @author Daniel Convissor <danielc@php.net>
|
||||
* @copyright 1997-2005 The PHP Group
|
||||
* @copyright 1997-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id: mysqli.php,v 1.78 2007/01/12 03:11:17 aharvey Exp $
|
||||
* @version CVS: $Id: mysqli.php,v 1.82 2007/09/21 13:40:41 aharvey Exp $
|
||||
* @link http://pear.php.net/package/DB
|
||||
*/
|
||||
|
||||
|
@ -41,9 +41,9 @@ require_once 'DB/common.php';
|
|||
* @category Database
|
||||
* @package DB
|
||||
* @author Daniel Convissor <danielc@php.net>
|
||||
* @copyright 1997-2005 The PHP Group
|
||||
* @copyright 1997-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version Release: 1.7.9
|
||||
* @version Release: 1.7.13
|
||||
* @link http://pear.php.net/package/DB
|
||||
* @since Class functional since Release 1.6.3
|
||||
*/
|
||||
|
@ -190,7 +190,6 @@ class DB_mysqli extends DB_common
|
|||
*/
|
||||
var $mysqli_types = array(
|
||||
MYSQLI_TYPE_DECIMAL => 'decimal',
|
||||
246 => 'decimal',
|
||||
MYSQLI_TYPE_TINY => 'tinyint',
|
||||
MYSQLI_TYPE_SHORT => 'int',
|
||||
MYSQLI_TYPE_LONG => 'int',
|
||||
|
@ -214,6 +213,10 @@ class DB_mysqli extends DB_common
|
|||
MYSQLI_TYPE_VAR_STRING => 'varchar',
|
||||
MYSQLI_TYPE_STRING => 'char',
|
||||
MYSQLI_TYPE_GEOMETRY => 'geometry',
|
||||
/* These constants are conditionally compiled in ext/mysqli, so we'll
|
||||
* define them by number rather than constant. */
|
||||
16 => 'bit',
|
||||
246 => 'decimal',
|
||||
);
|
||||
|
||||
|
||||
|
@ -268,7 +271,7 @@ class DB_mysqli extends DB_common
|
|||
* 'ssl' => true,
|
||||
* );
|
||||
*
|
||||
* $db =& DB::connect($dsn, $options);
|
||||
* $db = DB::connect($dsn, $options);
|
||||
* if (PEAR::isError($db)) {
|
||||
* die($db->getMessage());
|
||||
* }
|
||||
|
@ -959,6 +962,13 @@ class DB_mysqli extends DB_common
|
|||
function tableInfo($result, $mode = null)
|
||||
{
|
||||
if (is_string($result)) {
|
||||
// Fix for bug #11580.
|
||||
if ($this->_db) {
|
||||
if (!@mysqli_select_db($this->connection, $this->_db)) {
|
||||
return $this->mysqliRaiseError(DB_ERROR_NODBSELECTED);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Probably received a table name.
|
||||
* Create a result resource identifier.
|
||||
|
|
|
@ -18,9 +18,9 @@
|
|||
* @package DB
|
||||
* @author James L. Pine <jlp@valinux.com>
|
||||
* @author Daniel Convissor <danielc@php.net>
|
||||
* @copyright 1997-2005 The PHP Group
|
||||
* @copyright 1997-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id: oci8.php,v 1.111 2007/01/12 03:11:17 aharvey Exp $
|
||||
* @version CVS: $Id: oci8.php,v 1.115 2007/09/21 13:40:41 aharvey Exp $
|
||||
* @link http://pear.php.net/package/DB
|
||||
*/
|
||||
|
||||
|
@ -45,9 +45,9 @@ require_once 'DB/common.php';
|
|||
* @package DB
|
||||
* @author James L. Pine <jlp@valinux.com>
|
||||
* @author Daniel Convissor <danielc@php.net>
|
||||
* @copyright 1997-2005 The PHP Group
|
||||
* @copyright 1997-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version Release: 1.7.9
|
||||
* @version Release: 1.7.13
|
||||
* @link http://pear.php.net/package/DB
|
||||
*/
|
||||
class DB_oci8 extends DB_common
|
||||
|
@ -487,7 +487,7 @@ class DB_oci8 extends DB_common
|
|||
$save_query = $this->last_query;
|
||||
$save_stmt = $this->last_stmt;
|
||||
|
||||
$count =& $this->query($countquery);
|
||||
$count = $this->query($countquery);
|
||||
|
||||
// Restore the last query and statement.
|
||||
$this->last_query = $save_query;
|
||||
|
@ -633,9 +633,9 @@ class DB_oci8 extends DB_common
|
|||
$this->last_query = $this->_prepared_queries[(int)$stmt];
|
||||
$this->_data = $data;
|
||||
|
||||
$types =& $this->prepare_types[(int)$stmt];
|
||||
$types = $this->prepare_types[(int)$stmt];
|
||||
if (count($types) != count($data)) {
|
||||
$tmp =& $this->raiseError(DB_ERROR_MISMATCH);
|
||||
$tmp = $this->raiseError(DB_ERROR_MISMATCH);
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
|
@ -654,7 +654,7 @@ class DB_oci8 extends DB_common
|
|||
} elseif ($types[$i] == DB_PARAM_OPAQUE) {
|
||||
$fp = @fopen($data[$key], 'rb');
|
||||
if (!$fp) {
|
||||
$tmp =& $this->raiseError(DB_ERROR_ACCESS_VIOLATION);
|
||||
$tmp = $this->raiseError(DB_ERROR_ACCESS_VIOLATION);
|
||||
return $tmp;
|
||||
}
|
||||
$data[$key] = fread($fp, filesize($data[$key]));
|
||||
|
@ -690,7 +690,7 @@ class DB_oci8 extends DB_common
|
|||
} else {
|
||||
$this->_last_query_manip = false;
|
||||
@ocisetprefetch($stmt, $this->options['result_buffering']);
|
||||
$tmp =& new DB_result($this, $stmt);
|
||||
$tmp = new DB_result($this, $stmt);
|
||||
}
|
||||
return $tmp;
|
||||
}
|
||||
|
@ -818,7 +818,7 @@ class DB_oci8 extends DB_common
|
|||
if (count($params)) {
|
||||
$result = $this->prepare("SELECT * FROM ($query) "
|
||||
. 'WHERE NULL = NULL');
|
||||
$tmp =& $this->execute($result, $params);
|
||||
$tmp = $this->execute($result, $params);
|
||||
} else {
|
||||
$q_fields = "SELECT * FROM ($query) WHERE NULL = NULL";
|
||||
|
||||
|
@ -878,7 +878,7 @@ class DB_oci8 extends DB_common
|
|||
$repeat = 0;
|
||||
do {
|
||||
$this->expectError(DB_ERROR_NOSUCHTABLE);
|
||||
$result =& $this->query("SELECT ${seqname}.nextval FROM dual");
|
||||
$result = $this->query("SELECT ${seqname}.nextval FROM dual");
|
||||
$this->popExpect();
|
||||
if ($ondemand && DB::isError($result) &&
|
||||
$result->getCode() == DB_ERROR_NOSUCHTABLE) {
|
||||
|
@ -1119,6 +1119,8 @@ class DB_oci8 extends DB_common
|
|||
return 'SELECT table_name FROM user_tables';
|
||||
case 'synonyms':
|
||||
return 'SELECT synonym_name FROM user_synonyms';
|
||||
case 'views':
|
||||
return 'SELECT view_name FROM user_views';
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -18,9 +18,9 @@
|
|||
* @package DB
|
||||
* @author Stig Bakken <ssb@php.net>
|
||||
* @author Daniel Convissor <danielc@php.net>
|
||||
* @copyright 1997-2005 The PHP Group
|
||||
* @copyright 1997-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id: odbc.php,v 1.80 2007/01/12 03:11:17 aharvey Exp $
|
||||
* @version CVS: $Id: odbc.php,v 1.81 2007/07/06 05:19:21 aharvey Exp $
|
||||
* @link http://pear.php.net/package/DB
|
||||
*/
|
||||
|
||||
|
@ -42,9 +42,9 @@ require_once 'DB/common.php';
|
|||
* @package DB
|
||||
* @author Stig Bakken <ssb@php.net>
|
||||
* @author Daniel Convissor <danielc@php.net>
|
||||
* @copyright 1997-2005 The PHP Group
|
||||
* @copyright 1997-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version Release: 1.7.9
|
||||
* @version Release: 1.7.13
|
||||
* @link http://pear.php.net/package/DB
|
||||
*/
|
||||
class DB_odbc extends DB_common
|
||||
|
|
|
@ -19,9 +19,9 @@
|
|||
* @author Rui Hirokawa <hirokawa@php.net>
|
||||
* @author Stig Bakken <ssb@php.net>
|
||||
* @author Daniel Convissor <danielc@php.net>
|
||||
* @copyright 1997-2005 The PHP Group
|
||||
* @copyright 1997-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id: pgsql.php,v 1.134 2007/01/12 05:45:09 aharvey Exp $
|
||||
* @version CVS: $Id: pgsql.php,v 1.138 2007/09/21 13:40:41 aharvey Exp $
|
||||
* @link http://pear.php.net/package/DB
|
||||
*/
|
||||
|
||||
|
@ -41,9 +41,9 @@ require_once 'DB/common.php';
|
|||
* @author Rui Hirokawa <hirokawa@php.net>
|
||||
* @author Stig Bakken <ssb@php.net>
|
||||
* @author Daniel Convissor <danielc@php.net>
|
||||
* @copyright 1997-2005 The PHP Group
|
||||
* @copyright 1997-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version Release: 1.7.9
|
||||
* @version Release: 1.7.13
|
||||
* @link http://pear.php.net/package/DB
|
||||
*/
|
||||
class DB_pgsql extends DB_common
|
||||
|
@ -193,7 +193,7 @@ class DB_pgsql extends DB_common
|
|||
* 'portability' => DB_PORTABILITY_ALL,
|
||||
* );
|
||||
*
|
||||
* $db =& DB::connect($dsn, $options);
|
||||
* $db = DB::connect($dsn, $options);
|
||||
* if (PEAR::isError($db)) {
|
||||
* die($db->getMessage());
|
||||
* }
|
||||
|
@ -512,7 +512,17 @@ class DB_pgsql extends DB_common
|
|||
function escapeSimple($str)
|
||||
{
|
||||
if (function_exists('pg_escape_string')) {
|
||||
return pg_escape_string($str);
|
||||
/* This fixes an undocumented BC break in PHP 5.2.0 which changed
|
||||
* the prototype of pg_escape_string. I'm not thrilled about having
|
||||
* to sniff the PHP version, quite frankly, but it's the only way
|
||||
* to deal with the problem. Revision 1.331.2.13.2.10 on
|
||||
* php-src/ext/pgsql/pgsql.c (PHP_5_2 branch) is to blame, for the
|
||||
* record. */
|
||||
if (version_compare(PHP_VERSION, '5.2.0', '>=')) {
|
||||
return pg_escape_string($this->connection, $str);
|
||||
} else {
|
||||
return pg_escape_string($str);
|
||||
}
|
||||
} else {
|
||||
return str_replace("'", "''", str_replace('\\', '\\\\', $str));
|
||||
}
|
||||
|
@ -666,7 +676,7 @@ class DB_pgsql extends DB_common
|
|||
$repeat = false;
|
||||
do {
|
||||
$this->pushErrorHandling(PEAR_ERROR_RETURN);
|
||||
$result =& $this->query("SELECT NEXTVAL('${seqname}')");
|
||||
$result = $this->query("SELECT NEXTVAL('${seqname}')");
|
||||
$this->popErrorHandling();
|
||||
if ($ondemand && DB::isError($result) &&
|
||||
$result->getCode() == DB_ERROR_NOSUCHTABLE) {
|
||||
|
@ -1072,6 +1082,9 @@ class DB_pgsql extends DB_common
|
|||
. ' FROM pg_catalog.pg_tables'
|
||||
. ' WHERE schemaname NOT IN'
|
||||
. " ('pg_catalog', 'information_schema', 'pg_toast')";
|
||||
case 'schema.views':
|
||||
return "SELECT schemaname || '.' || viewname from pg_views WHERE schemaname"
|
||||
. " NOT IN ('information_schema', 'pg_catalog')";
|
||||
case 'views':
|
||||
// Table cols: viewname | viewowner | definition
|
||||
return 'SELECT viewname from pg_views WHERE schemaname'
|
||||
|
|
|
@ -19,9 +19,9 @@
|
|||
* @author Urs Gehrig <urs@circle.ch>
|
||||
* @author Mika Tuupola <tuupola@appelsiini.net>
|
||||
* @author Daniel Convissor <danielc@php.net>
|
||||
* @copyright 1997-2005 The PHP Group
|
||||
* @copyright 1997-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0 3.0
|
||||
* @version CVS: $Id: sqlite.php,v 1.114 2007/01/12 02:41:07 aharvey Exp $
|
||||
* @version CVS: $Id: sqlite.php,v 1.117 2007/09/21 14:23:28 aharvey Exp $
|
||||
* @link http://pear.php.net/package/DB
|
||||
*/
|
||||
|
||||
|
@ -45,9 +45,9 @@ require_once 'DB/common.php';
|
|||
* @author Urs Gehrig <urs@circle.ch>
|
||||
* @author Mika Tuupola <tuupola@appelsiini.net>
|
||||
* @author Daniel Convissor <danielc@php.net>
|
||||
* @copyright 1997-2005 The PHP Group
|
||||
* @copyright 1997-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0 3.0
|
||||
* @version Release: 1.7.9
|
||||
* @version Release: 1.7.13
|
||||
* @link http://pear.php.net/package/DB
|
||||
*/
|
||||
class DB_sqlite extends DB_common
|
||||
|
@ -182,7 +182,7 @@ class DB_sqlite extends DB_common
|
|||
* 'portability' => DB_PORTABILITY_ALL,
|
||||
* );
|
||||
*
|
||||
* $db =& DB::connect($dsn, $options);
|
||||
* $db = DB::connect($dsn, $options);
|
||||
* if (PEAR::isError($db)) {
|
||||
* die($db->getMessage());
|
||||
* }
|
||||
|
@ -359,6 +359,16 @@ class DB_sqlite extends DB_common
|
|||
if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) {
|
||||
$arr = array_change_key_case($arr, CASE_LOWER);
|
||||
}
|
||||
|
||||
/* Remove extraneous " characters from the fields in the result.
|
||||
* Fixes bug #11716. */
|
||||
if (is_array($arr) && count($arr) > 0) {
|
||||
$strippedArr = array();
|
||||
foreach ($arr as $field => $value) {
|
||||
$strippedArr[trim($field, '"')] = $value;
|
||||
}
|
||||
$arr = $strippedArr;
|
||||
}
|
||||
} else {
|
||||
$arr = @sqlite_fetch_array($result, SQLITE_NUM);
|
||||
}
|
||||
|
|
|
@ -16,9 +16,9 @@
|
|||
* @category Database
|
||||
* @package DB
|
||||
* @author Stig Bakken <stig@php.net>
|
||||
* @copyright 1997-2005 The PHP Group
|
||||
* @copyright 1997-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id: storage.php,v 1.22 2005/07/10 13:38:51 danielc Exp $
|
||||
* @version CVS: $Id: storage.php,v 1.24 2007/08/12 05:27:25 aharvey Exp $
|
||||
* @link http://pear.php.net/package/DB
|
||||
*/
|
||||
|
||||
|
@ -36,9 +36,9 @@ require_once 'DB.php';
|
|||
* @category Database
|
||||
* @package DB
|
||||
* @author Stig Bakken <stig@php.net>
|
||||
* @copyright 1997-2005 The PHP Group
|
||||
* @copyright 1997-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version Release: 1.7.9
|
||||
* @version Release: 1.7.13
|
||||
* @link http://pear.php.net/package/DB
|
||||
*/
|
||||
class DB_storage extends PEAR
|
||||
|
@ -293,7 +293,7 @@ class DB_storage extends PEAR
|
|||
function &create($table, &$data)
|
||||
{
|
||||
$classname = strtolower(get_class($this));
|
||||
$obj =& new $classname($table);
|
||||
$obj = new $classname($table);
|
||||
foreach ($data as $name => $value) {
|
||||
$obj->_properties[$name] = true;
|
||||
$obj->$name = &$value;
|
||||
|
|
|
@ -19,9 +19,9 @@
|
|||
* @author Sterling Hughes <sterling@php.net>
|
||||
* @author Antônio Carlos Venâncio Júnior <floripa@php.net>
|
||||
* @author Daniel Convissor <danielc@php.net>
|
||||
* @copyright 1997-2005 The PHP Group
|
||||
* @copyright 1997-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id: sybase.php,v 1.85 2007/02/06 07:35:07 aharvey Exp $
|
||||
* @version CVS: $Id: sybase.php,v 1.87 2007/09/21 13:40:42 aharvey Exp $
|
||||
* @link http://pear.php.net/package/DB
|
||||
*/
|
||||
|
||||
|
@ -44,9 +44,9 @@ require_once 'DB/common.php';
|
|||
* @author Sterling Hughes <sterling@php.net>
|
||||
* @author Antônio Carlos Venâncio Júnior <floripa@php.net>
|
||||
* @author Daniel Convissor <danielc@php.net>
|
||||
* @copyright 1997-2005 The PHP Group
|
||||
* @copyright 1997-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version Release: 1.7.9
|
||||
* @version Release: 1.7.13
|
||||
* @link http://pear.php.net/package/DB
|
||||
*/
|
||||
class DB_sybase extends DB_common
|
||||
|
@ -479,7 +479,7 @@ class DB_sybase extends DB_common
|
|||
return $this->raiseError($result);
|
||||
}
|
||||
} elseif (!DB::isError($result)) {
|
||||
$result =& $this->query("SELECT @@IDENTITY FROM $seqname");
|
||||
$result = $this->query("SELECT @@IDENTITY FROM $seqname");
|
||||
$repeat = 0;
|
||||
} else {
|
||||
$repeat = false;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -16,7 +16,7 @@
|
|||
// | Author: Sterling Hughes <sterling@php.net> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Find.php,v 1.26 2006/02/11 16:28:40 techtonik Exp $
|
||||
// $Id: Find.php,v 1.27 2006/06/30 14:06:16 techtonik Exp $
|
||||
//
|
||||
|
||||
require_once 'PEAR.php';
|
||||
|
@ -30,7 +30,7 @@ define('FILE_FIND_VERSION', '@package_version@');
|
|||
* Commonly needed functions searching directory trees
|
||||
*
|
||||
* @access public
|
||||
* @version $Id: Find.php,v 1.26 2006/02/11 16:28:40 techtonik Exp $
|
||||
* @version $Id: Find.php,v 1.27 2006/06/30 14:06:16 techtonik Exp $
|
||||
* @package File
|
||||
* @author Sterling Hughes <sterling@php.net>
|
||||
*/
|
||||
|
@ -42,6 +42,12 @@ class File_Find
|
|||
*/
|
||||
var $_dirs = array();
|
||||
|
||||
/**
|
||||
* directory separator
|
||||
* @var string
|
||||
*/
|
||||
var $dirsep = "/";
|
||||
|
||||
/**
|
||||
* found files
|
||||
* @var array
|
||||
|
@ -55,8 +61,7 @@ class File_Find
|
|||
var $directories = array();
|
||||
|
||||
/**
|
||||
* Search the current directory to find matches for the
|
||||
* the specified pattern.
|
||||
* Search specified directory to find matches for specified pattern
|
||||
*
|
||||
* @param string $pattern a string containing the pattern to search
|
||||
* the directory for.
|
||||
|
@ -80,7 +85,7 @@ class File_Find
|
|||
$dh = @opendir($dirpath);
|
||||
|
||||
if (!$dh) {
|
||||
$pe = PEAR::raiseError("Cannot open directory");
|
||||
$pe = PEAR::raiseError("Cannot open directory $dirpath");
|
||||
return $pe;
|
||||
}
|
||||
|
||||
|
@ -132,16 +137,14 @@ class File_Find
|
|||
$this->files = array();
|
||||
$this->directories = array();
|
||||
|
||||
/* consistency rules - strip out trailing slashes */
|
||||
/* strip out trailing slashes */
|
||||
$directory = preg_replace('![\\\\/]+$!', '', $directory);
|
||||
/* use only native system directory delimiters */
|
||||
$directory = preg_replace("![\\\\/]+!", DIRECTORY_SEPARATOR, $directory);
|
||||
|
||||
$this->_dirs = array($directory);
|
||||
|
||||
while (count($this->_dirs)) {
|
||||
$dir = array_pop($this->_dirs);
|
||||
File_Find::_build($dir);
|
||||
File_Find::_build($dir, $this->dirsep);
|
||||
array_push($this->directories, $dir);
|
||||
}
|
||||
|
||||
|
@ -181,7 +184,8 @@ class File_Find
|
|||
|
||||
$count++;
|
||||
|
||||
$directory .= DIRECTORY_SEPARATOR;
|
||||
/* strip trailing slashes */
|
||||
$directory = preg_replace('![\\\\/]+$!', '', $directory);
|
||||
|
||||
if (is_readable($directory)) {
|
||||
$dh = opendir($directory);
|
||||
|
@ -194,9 +198,7 @@ class File_Find
|
|||
}
|
||||
|
||||
while (list($key, $val) = each($retval)) {
|
||||
$path = $directory . $val;
|
||||
$path = str_replace(DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR,
|
||||
DIRECTORY_SEPARATOR, $path);
|
||||
$path = $directory . "/" . $val;
|
||||
|
||||
if (!is_array($val) && is_dir($path)) {
|
||||
unset($retval[$key]);
|
||||
|
@ -287,9 +289,10 @@ class File_Find
|
|||
* File_Find::maptree()
|
||||
*
|
||||
* @param string $directory name of the directory to read
|
||||
* @param string $separator directory separator
|
||||
* @return void
|
||||
*/
|
||||
function _build($directory)
|
||||
function _build($directory, $separator = "/")
|
||||
{
|
||||
|
||||
$dh = @opendir($directory);
|
||||
|
@ -302,9 +305,7 @@ class File_Find
|
|||
while (false !== ($entry = @readdir($dh))) {
|
||||
if ($entry != '.' && $entry != '..') {
|
||||
|
||||
$entry = $directory.DIRECTORY_SEPARATOR.$entry;
|
||||
$entry = str_replace(DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR,
|
||||
DIRECTORY_SEPARATOR, $entry);
|
||||
$entry = $directory.$separator.$entry;
|
||||
|
||||
if (is_dir($entry)) {
|
||||
array_push($this->_dirs, $entry);
|
||||
|
@ -343,7 +344,7 @@ class File_Find
|
|||
|
||||
/**
|
||||
* Package method to match via 'shell' pattern. Provided in global
|
||||
* scope, because they should be called like 'preg_match' and 'eregi'
|
||||
* scope, because it should be called like 'preg_match' and 'eregi'
|
||||
* and can be easily copied into other packages
|
||||
*
|
||||
* @author techtonik <techtonik@php.net>
|
||||
|
|
|
@ -1,457 +1,482 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* File::Util
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.0 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category File
|
||||
* @package File
|
||||
* @author Michael Wallner <mike@php.net>
|
||||
* @copyright 2004-2005 Michael Wallner
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id: Util.php,v 1.21 2005/08/09 07:52:13 mike Exp $
|
||||
* @link http://pear.php.net/package/File
|
||||
*/
|
||||
|
||||
/**#@+
|
||||
* Sorting Constants
|
||||
*/
|
||||
define('FILE_SORT_NONE', 0);
|
||||
define('FILE_SORT_REVERSE', 1);
|
||||
define('FILE_SORT_NAME', 2);
|
||||
define('FILE_SORT_SIZE', 4);
|
||||
define('FILE_SORT_DATE', 8);
|
||||
define('FILE_SORT_RANDOM', 16);
|
||||
/**#@-*/
|
||||
|
||||
/**#@+
|
||||
* Listing Constants
|
||||
*/
|
||||
define('FILE_LIST_FILES', 1);
|
||||
define('FILE_LIST_DIRS', 2);
|
||||
define('FILE_LIST_DOTS', 4);
|
||||
define('FILE_LIST_ALL', FILE_LIST_FILES | FILE_LIST_DIRS | FILE_LIST_DOTS);
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
define('FILE_WIN32', defined('OS_WINDOWS') ? OS_WINDOWS : !strncasecmp(PHP_OS, 'win', 3));
|
||||
|
||||
/**
|
||||
* File_Util
|
||||
*
|
||||
* File and directory utility functions.
|
||||
*
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
class File_Util
|
||||
{
|
||||
/**
|
||||
* Returns a string path built from the array $pathParts. Where a join
|
||||
* occurs multiple separators are removed. Joins using the optional
|
||||
* separator, defaulting to the PHP DIRECTORY_SEPARATOR constant.
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @param array $parts Array containing the parts to be joined
|
||||
* @param string $separator The directory seperator
|
||||
*/
|
||||
function buildPath($parts, $separator = DIRECTORY_SEPARATOR)
|
||||
{
|
||||
$qs = '/^'. preg_quote($separator, '/') .'+$/';
|
||||
for ($i = 0, $c = count($parts); $i < $c; $i++) {
|
||||
if (!strlen($parts[$i]) || preg_match($qs, $parts[$i])) {
|
||||
unset($parts[$i]);
|
||||
} elseif (0 == $i) {
|
||||
$parts[$i] = rtrim($parts[$i], $separator);
|
||||
} elseif ($c - 1 == $i) {
|
||||
$parts[$i] = ltrim($parts[$i], $separator);
|
||||
} else {
|
||||
$parts[$i] = trim($parts[$i], $separator);
|
||||
}
|
||||
}
|
||||
return implode($separator, $parts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a path without leading / or C:\. If this is not
|
||||
* present the path is returned as is.
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @param string $path The path to be processed
|
||||
* @return string The processed path or the path as is
|
||||
*/
|
||||
function skipRoot($path)
|
||||
{
|
||||
if (File_Util::isAbsolute($path)) {
|
||||
if (FILE_WIN32) {
|
||||
return substr($path, $path{3} == '\\' ? 4 : 3);
|
||||
}
|
||||
return ltrim($path, '/');
|
||||
}
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the temp directory according to either the TMP, TMPDIR, or
|
||||
* TEMP env variables. If these are not set it will also check for the
|
||||
* existence of /tmp, %WINDIR%\temp
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @return string The system tmp directory
|
||||
*/
|
||||
function tmpDir()
|
||||
{
|
||||
if (FILE_WIN32) {
|
||||
if (isset($_ENV['TEMP'])) {
|
||||
return $_ENV['TEMP'];
|
||||
}
|
||||
if (isset($_ENV['TMP'])) {
|
||||
return $_ENV['TMP'];
|
||||
}
|
||||
if (isset($_ENV['windir'])) {
|
||||
return $_ENV['windir'] . '\\temp';
|
||||
}
|
||||
if (isset($_ENV['SystemRoot'])) {
|
||||
return $_ENV['SystemRoot'] . '\\temp';
|
||||
}
|
||||
if (isset($_SERVER['TEMP'])) {
|
||||
return $_SERVER['TEMP'];
|
||||
}
|
||||
if (isset($_SERVER['TMP'])) {
|
||||
return $_SERVER['TMP'];
|
||||
}
|
||||
if (isset($_SERVER['windir'])) {
|
||||
return $_SERVER['windir'] . '\\temp';
|
||||
}
|
||||
if (isset($_SERVER['SystemRoot'])) {
|
||||
return $_SERVER['SystemRoot'] . '\\temp';
|
||||
}
|
||||
return '\temp';
|
||||
}
|
||||
if (isset($_ENV['TMPDIR'])) {
|
||||
return $_ENV['TMPDIR'];
|
||||
}
|
||||
if (isset($_SERVER['TMPDIR'])) {
|
||||
return $_SERVER['TMPDIR'];
|
||||
}
|
||||
return '/tmp';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a temporary filename using tempnam() and File::tmpDir().
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @param string $dirname Optional directory name for the tmp file
|
||||
* @return string Filename and path of the tmp file
|
||||
*/
|
||||
function tmpFile($dirname = null)
|
||||
{
|
||||
if (!isset($dirname)) {
|
||||
$dirname = File_Util::tmpDir();
|
||||
}
|
||||
return tempnam($dirname, 'temp.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns boolean based on whether given path is absolute or not.
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @param string $path Given path
|
||||
* @return boolean True if the path is absolute, false if it is not
|
||||
*/
|
||||
function isAbsolute($path)
|
||||
{
|
||||
if (preg_match('/(?:\/|\\\)\.\.(?=\/|$)/', $path)) {
|
||||
return false;
|
||||
}
|
||||
if (FILE_WIN32) {
|
||||
return preg_match('/^[a-zA-Z]:(\\\|\/)/', $path);
|
||||
}
|
||||
return ($path{0} == '/') || ($path{0} == '~');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get path relative to another path
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @return string
|
||||
* @param string $path
|
||||
* @param string $root
|
||||
* @param string $separator
|
||||
*/
|
||||
function relativePath($path, $root, $separator = DIRECTORY_SEPARATOR)
|
||||
{
|
||||
$path = File_Util::realpath($path, $separator);
|
||||
$root = File_Util::realpath($root, $separator);
|
||||
$dirs = explode($separator, $path);
|
||||
$comp = explode($separator, $root);
|
||||
|
||||
if (FILE_WIN32) {
|
||||
if (strcasecmp($dirs[0], $comp[0])) {
|
||||
return $path;
|
||||
}
|
||||
unset($dirs[0], $comp[0]);
|
||||
}
|
||||
|
||||
foreach ($comp as $i => $part) {
|
||||
if (isset($dirs[$i]) && $part == $dirs[$i]) {
|
||||
unset($dirs[$i], $comp[$i]);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return str_repeat('..' . $separator, count($comp)) . implode($separator, $dirs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get real path (works with non-existant paths)
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @return string
|
||||
* @param string $path
|
||||
* @param string $separator
|
||||
*/
|
||||
function realPath($path, $separator = DIRECTORY_SEPARATOR)
|
||||
{
|
||||
if (!strlen($path)) {
|
||||
return $separator;
|
||||
}
|
||||
|
||||
$drive = '';
|
||||
if (FILE_WIN32) {
|
||||
$path = preg_replace('/[\\\\\/]/', $separator, $path);
|
||||
if (preg_match('/([a-zA-Z]\:)(.*)/', $path, $matches)) {
|
||||
$drive = $matches[1];
|
||||
$path = $matches[2];
|
||||
} else {
|
||||
$cwd = getcwd();
|
||||
$drive = substr($cwd, 0, 2);
|
||||
if ($path{0} !== $separator{0}) {
|
||||
$path = substr($cwd, 3) . $separator . $path;
|
||||
}
|
||||
}
|
||||
} elseif ($path{0} !== $separator) {
|
||||
$path = getcwd() . $separator . $path;
|
||||
}
|
||||
|
||||
$dirStack = array();
|
||||
foreach (explode($separator, $path) as $dir) {
|
||||
if (strlen($dir) && $dir !== '.') {
|
||||
if ($dir == '..') {
|
||||
array_pop($dirStack);
|
||||
} else {
|
||||
$dirStack[] = $dir;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $drive . $separator . implode($separator, $dirStack);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether path is in root path
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @return bool
|
||||
* @param string $path
|
||||
* @param string $root
|
||||
*/
|
||||
function pathInRoot($path, $root)
|
||||
{
|
||||
static $realPaths = array();
|
||||
|
||||
if (!isset($realPaths[$root])) {
|
||||
$realPaths[$root] = File_Util::realPath($root);
|
||||
}
|
||||
|
||||
return false !== strstr(File_Util::realPath($path), $realPaths[$root]);
|
||||
}
|
||||
|
||||
/**
|
||||
* List Directory
|
||||
*
|
||||
* The final argument, $cb, is a callback that either evaluates to true or
|
||||
* false and performs a filter operation, or it can also modify the
|
||||
* directory/file names returned. To achieve the latter effect use as
|
||||
* follows:
|
||||
*
|
||||
* <code>
|
||||
* <?php
|
||||
* function uc(&$filename) {
|
||||
* $filename = strtoupper($filename);
|
||||
* return true;
|
||||
* }
|
||||
* $entries = File_Util::listDir('.', FILE_LIST_ALL, FILE_SORT_NONE, 'uc');
|
||||
* foreach ($entries as $e) {
|
||||
* echo $e->name, "\n";
|
||||
* }
|
||||
* ?>
|
||||
* </code>
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @return array
|
||||
* @param string $path
|
||||
* @param int $list
|
||||
* @param int $sort
|
||||
* @param mixed $cb
|
||||
*/
|
||||
function listDir($path, $list = FILE_LIST_ALL, $sort = FILE_SORT_NONE, $cb = null)
|
||||
{
|
||||
if (!strlen($path) || !is_dir($path)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$entries = array();
|
||||
for ($dir = dir($path); false !== $entry = $dir->read(); ) {
|
||||
if ($list & FILE_LIST_DOTS || $entry{0} !== '.') {
|
||||
$isRef = ($entry === '.' || $entry === '..');
|
||||
$isDir = $isRef || is_dir($path .'/'. $entry);
|
||||
if ( ((!$isDir && $list & FILE_LIST_FILES) ||
|
||||
($isDir && $list & FILE_LIST_DIRS)) &&
|
||||
(!is_callable($cb) ||
|
||||
call_user_func_array($cb, array(&$entry)))) {
|
||||
$entries[] = (object) array(
|
||||
'name' => $entry,
|
||||
'size' => $isDir ? null : filesize($path .'/'. $entry),
|
||||
'date' => filemtime($path .'/'. $entry),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
$dir->close();
|
||||
|
||||
if ($sort) {
|
||||
$entries = File_Util::sortFiles($entries, $sort);
|
||||
}
|
||||
|
||||
return $entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort Files
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @return array
|
||||
* @param array $files
|
||||
* @param int $sort
|
||||
*/
|
||||
function sortFiles($files, $sort)
|
||||
{
|
||||
if (!$files) {
|
||||
return array();
|
||||
}
|
||||
|
||||
if (!$sort) {
|
||||
return $files;
|
||||
}
|
||||
|
||||
if ($sort === 1) {
|
||||
return array_reverse($files);
|
||||
}
|
||||
|
||||
if ($sort & FILE_SORT_RANDOM) {
|
||||
shuffle($files);
|
||||
return $files;
|
||||
}
|
||||
|
||||
$names = array();
|
||||
$sizes = array();
|
||||
$dates = array();
|
||||
|
||||
if ($sort & FILE_SORT_NAME) {
|
||||
$r = &$names;
|
||||
} elseif ($sort & FILE_SORT_DATE) {
|
||||
$r = &$dates;
|
||||
} elseif ($sort & FILE_SORT_SIZE) {
|
||||
$r = &$sizes;
|
||||
} else {
|
||||
asort($files, SORT_REGULAR);
|
||||
return $files;
|
||||
}
|
||||
|
||||
$sortFlags = array(
|
||||
FILE_SORT_NAME => SORT_STRING,
|
||||
FILE_SORT_DATE => SORT_NUMERIC,
|
||||
FILE_SORT_SIZE => SORT_NUMERIC,
|
||||
);
|
||||
|
||||
foreach ($files as $file) {
|
||||
$names[] = $file->name;
|
||||
$sizes[] = $file->size;
|
||||
$dates[] = $file->date;
|
||||
}
|
||||
|
||||
if ($sort & FILE_SORT_REVERSE) {
|
||||
arsort($r, $sortFlags[$sort & ~1]);
|
||||
} else {
|
||||
asort($r, $sortFlags[$sort]);
|
||||
}
|
||||
|
||||
$result = array();
|
||||
foreach ($r as $i => $f) {
|
||||
$result[] = $files[$i];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Switch File Extension
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @return string|array
|
||||
* @param string|array $filename
|
||||
* @param string $to new file extension
|
||||
* @param string $from change only files with this extension
|
||||
* @param bool $reverse change only files not having $from extension
|
||||
*/
|
||||
function switchExt($filename, $to, $from = null, $reverse = false)
|
||||
{
|
||||
if (is_array($filename)) {
|
||||
foreach ($filename as $key => $file) {
|
||||
$filename[$key] = File_Util::switchExt($file, $to, $from);
|
||||
}
|
||||
return $filename;
|
||||
}
|
||||
|
||||
if ($len = strlen($from)) {
|
||||
$ext = substr($filename, -$len - 1);
|
||||
$cfn = FILE_WIN32 ? 'strcasecmp' : 'strcmp';
|
||||
if (!$reverse == $cfn($ext, '.'. $from)) {
|
||||
return $filename;
|
||||
}
|
||||
return substr($filename, 0, -$len - 1) .'.'. $to;
|
||||
}
|
||||
|
||||
if ($pos = strpos($filename, '.')) {
|
||||
return substr($filename, 0, $pos) .'.'. $to;
|
||||
}
|
||||
|
||||
return $filename .'.'. $to;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* File::Util
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.0 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category File
|
||||
* @package File
|
||||
* @author Michael Wallner <mike@php.net>
|
||||
* @copyright 2004-2005 Michael Wallner
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id: Util.php,v 1.25 2007/02/20 14:19:08 mike Exp $
|
||||
* @link http://pear.php.net/package/File
|
||||
*/
|
||||
|
||||
/**#@+
|
||||
* Sorting Constants
|
||||
*/
|
||||
define('FILE_SORT_NONE', 0);
|
||||
define('FILE_SORT_REVERSE', 1);
|
||||
define('FILE_SORT_NAME', 2);
|
||||
define('FILE_SORT_SIZE', 4);
|
||||
define('FILE_SORT_DATE', 8);
|
||||
define('FILE_SORT_RANDOM', 16);
|
||||
/**#@-*/
|
||||
|
||||
/**#@+
|
||||
* Listing Constants
|
||||
*/
|
||||
define('FILE_LIST_FILES', 1);
|
||||
define('FILE_LIST_DIRS', 2);
|
||||
define('FILE_LIST_DOTS', 4);
|
||||
define('FILE_LIST_ALL', FILE_LIST_FILES | FILE_LIST_DIRS | FILE_LIST_DOTS);
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
define('FILE_WIN32', defined('OS_WINDOWS') ? OS_WINDOWS : !strncasecmp(PHP_OS, 'win', 3));
|
||||
|
||||
/**
|
||||
* File_Util
|
||||
*
|
||||
* File and directory utility functions.
|
||||
*
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
class File_Util
|
||||
{
|
||||
/**
|
||||
* Returns a string path built from the array $pathParts. Where a join
|
||||
* occurs multiple separators are removed. Joins using the optional
|
||||
* separator, defaulting to the PHP DIRECTORY_SEPARATOR constant.
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @param array $parts Array containing the parts to be joined
|
||||
* @param string $separator The directory seperator
|
||||
*/
|
||||
function buildPath($parts, $separator = DIRECTORY_SEPARATOR)
|
||||
{
|
||||
$qs = '/^'. preg_quote($separator, '/') .'+$/';
|
||||
for ($i = 0, $c = count($parts); $i < $c; $i++) {
|
||||
if (!strlen($parts[$i]) || preg_match($qs, $parts[$i])) {
|
||||
unset($parts[$i]);
|
||||
} elseif (0 == $i) {
|
||||
$parts[$i] = rtrim($parts[$i], $separator);
|
||||
} elseif ($c - 1 == $i) {
|
||||
$parts[$i] = ltrim($parts[$i], $separator);
|
||||
} else {
|
||||
$parts[$i] = trim($parts[$i], $separator);
|
||||
}
|
||||
}
|
||||
return implode($separator, $parts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a path without leading / or C:\. If this is not
|
||||
* present the path is returned as is.
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @param string $path The path to be processed
|
||||
* @return string The processed path or the path as is
|
||||
*/
|
||||
function skipRoot($path)
|
||||
{
|
||||
if (File_Util::isAbsolute($path)) {
|
||||
if (FILE_WIN32) {
|
||||
return substr($path, $path{3} == '\\' ? 4 : 3);
|
||||
}
|
||||
return ltrim($path, '/');
|
||||
}
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the temp directory according to either the TMP, TMPDIR, or
|
||||
* TEMP env variables. If these are not set it will also check for the
|
||||
* existence of /tmp, %WINDIR%\temp
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @return string The system tmp directory
|
||||
*/
|
||||
function tmpDir()
|
||||
{
|
||||
if (FILE_WIN32) {
|
||||
if (isset($_ENV['TEMP'])) {
|
||||
return $_ENV['TEMP'];
|
||||
}
|
||||
if (isset($_ENV['TMP'])) {
|
||||
return $_ENV['TMP'];
|
||||
}
|
||||
if (isset($_ENV['windir'])) {
|
||||
return $_ENV['windir'] . '\\temp';
|
||||
}
|
||||
if (isset($_ENV['SystemRoot'])) {
|
||||
return $_ENV['SystemRoot'] . '\\temp';
|
||||
}
|
||||
if (isset($_SERVER['TEMP'])) {
|
||||
return $_SERVER['TEMP'];
|
||||
}
|
||||
if (isset($_SERVER['TMP'])) {
|
||||
return $_SERVER['TMP'];
|
||||
}
|
||||
if (isset($_SERVER['windir'])) {
|
||||
return $_SERVER['windir'] . '\\temp';
|
||||
}
|
||||
if (isset($_SERVER['SystemRoot'])) {
|
||||
return $_SERVER['SystemRoot'] . '\\temp';
|
||||
}
|
||||
return '\temp';
|
||||
}
|
||||
if (isset($_ENV['TMPDIR'])) {
|
||||
return $_ENV['TMPDIR'];
|
||||
}
|
||||
if (isset($_SERVER['TMPDIR'])) {
|
||||
return $_SERVER['TMPDIR'];
|
||||
}
|
||||
return '/tmp';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a temporary filename using tempnam() and File::tmpDir().
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @param string $dirname Optional directory name for the tmp file
|
||||
* @return string Filename and path of the tmp file
|
||||
*/
|
||||
function tmpFile($dirname = null)
|
||||
{
|
||||
if (!isset($dirname)) {
|
||||
$dirname = File_Util::tmpDir();
|
||||
}
|
||||
return tempnam($dirname, 'temp.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns boolean based on whether given path is absolute or not.
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @param string $path Given path
|
||||
* @return boolean True if the path is absolute, false if it is not
|
||||
*/
|
||||
function isAbsolute($path)
|
||||
{
|
||||
if (preg_match('/(?:\/|\\\)\.\.(?=\/|$)/', $path)) {
|
||||
return false;
|
||||
}
|
||||
if (FILE_WIN32) {
|
||||
return preg_match('/^[a-zA-Z]:(\\\|\/)/', $path);
|
||||
}
|
||||
return ($path{0} == '/') || ($path{0} == '~');
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for a file's existence, taking the current include path
|
||||
* into consideration
|
||||
*
|
||||
* This method can be called statically
|
||||
* (e.g., File_Util::isIncludable('config.php'))
|
||||
*
|
||||
* @param string $file
|
||||
* @param string $sep the directory separator (optional)
|
||||
* @return string the includable path
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function isIncludable($file, $sep = DIRECTORY_SEPARATOR)
|
||||
{
|
||||
foreach ((array) explode(PATH_SEPARATOR, ini_get('include_path')) as $path) {
|
||||
if (file_exists($path .= $sep . $file)) {
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
if (file_exists($file)) {
|
||||
return $file;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get path relative to another path
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @return string
|
||||
* @param string $path
|
||||
* @param string $root
|
||||
* @param string $separator
|
||||
*/
|
||||
function relativePath($path, $root, $separator = DIRECTORY_SEPARATOR)
|
||||
{
|
||||
$path = File_Util::realpath($path, $separator);
|
||||
$root = File_Util::realpath($root, $separator);
|
||||
$dirs = explode($separator, $path);
|
||||
$comp = explode($separator, $root);
|
||||
|
||||
if (FILE_WIN32) {
|
||||
if (strcasecmp($dirs[0], $comp[0])) {
|
||||
return $path;
|
||||
}
|
||||
unset($dirs[0], $comp[0]);
|
||||
}
|
||||
|
||||
foreach ($comp as $i => $part) {
|
||||
if (isset($dirs[$i]) && $part == $dirs[$i]) {
|
||||
unset($dirs[$i], $comp[$i]);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return str_repeat('..' . $separator, count($comp)) . implode($separator, $dirs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get real path (works with non-existant paths)
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @return string
|
||||
* @param string $path
|
||||
* @param string $separator
|
||||
*/
|
||||
function realPath($path, $separator = DIRECTORY_SEPARATOR)
|
||||
{
|
||||
if (!strlen($path)) {
|
||||
return $separator;
|
||||
}
|
||||
|
||||
$drive = '';
|
||||
if (FILE_WIN32) {
|
||||
$path = preg_replace('/[\\\\\/]/', $separator, $path);
|
||||
if (preg_match('/([a-zA-Z]\:)(.*)/', $path, $matches)) {
|
||||
$drive = $matches[1];
|
||||
$path = $matches[2];
|
||||
} else {
|
||||
$cwd = getcwd();
|
||||
$drive = substr($cwd, 0, 2);
|
||||
if ($path{0} !== $separator{0}) {
|
||||
$path = substr($cwd, 3) . $separator . $path;
|
||||
}
|
||||
}
|
||||
} elseif ($path{0} !== $separator) {
|
||||
$path = getcwd() . $separator . $path;
|
||||
}
|
||||
|
||||
$dirStack = array();
|
||||
foreach (explode($separator, $path) as $dir) {
|
||||
if (strlen($dir) && $dir !== '.') {
|
||||
if ($dir == '..') {
|
||||
array_pop($dirStack);
|
||||
} else {
|
||||
$dirStack[] = $dir;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $drive . $separator . implode($separator, $dirStack);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether path is in root path
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @return bool
|
||||
* @param string $path
|
||||
* @param string $root
|
||||
*/
|
||||
function pathInRoot($path, $root)
|
||||
{
|
||||
static $realPaths = array();
|
||||
|
||||
if (!isset($realPaths[$root])) {
|
||||
$realPaths[$root] = File_Util::realPath($root);
|
||||
}
|
||||
|
||||
return false !== strstr(File_Util::realPath($path), $realPaths[$root]);
|
||||
}
|
||||
|
||||
/**
|
||||
* List Directory
|
||||
*
|
||||
* The final argument, $cb, is a callback that either evaluates to true or
|
||||
* false and performs a filter operation, or it can also modify the
|
||||
* directory/file names returned. To achieve the latter effect use as
|
||||
* follows:
|
||||
*
|
||||
* <code>
|
||||
* <?php
|
||||
* function uc(&$filename) {
|
||||
* $filename = strtoupper($filename);
|
||||
* return true;
|
||||
* }
|
||||
* $entries = File_Util::listDir('.', FILE_LIST_ALL, FILE_SORT_NONE, 'uc');
|
||||
* foreach ($entries as $e) {
|
||||
* echo $e->name, "\n";
|
||||
* }
|
||||
* ?>
|
||||
* </code>
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @return array
|
||||
* @param string $path
|
||||
* @param int $list
|
||||
* @param int $sort
|
||||
* @param mixed $cb
|
||||
*/
|
||||
function listDir($path, $list = FILE_LIST_ALL, $sort = FILE_SORT_NONE, $cb = null)
|
||||
{
|
||||
if (!strlen($path) || !is_dir($path)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$entries = array();
|
||||
for ($dir = dir($path); false !== $entry = $dir->read(); ) {
|
||||
if ($list & FILE_LIST_DOTS || $entry{0} !== '.') {
|
||||
$isRef = ($entry === '.' || $entry === '..');
|
||||
$isDir = $isRef || is_dir($path .'/'. $entry);
|
||||
if ( ((!$isDir && $list & FILE_LIST_FILES) ||
|
||||
($isDir && $list & FILE_LIST_DIRS)) &&
|
||||
(!is_callable($cb) ||
|
||||
call_user_func_array($cb, array(&$entry)))) {
|
||||
$entries[] = (object) array(
|
||||
'name' => $entry,
|
||||
'size' => $isDir ? null : filesize($path .'/'. $entry),
|
||||
'date' => filemtime($path .'/'. $entry),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
$dir->close();
|
||||
|
||||
if ($sort) {
|
||||
$entries = File_Util::sortFiles($entries, $sort);
|
||||
}
|
||||
|
||||
return $entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort Files
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @return array
|
||||
* @param array $files
|
||||
* @param int $sort
|
||||
*/
|
||||
function sortFiles($files, $sort)
|
||||
{
|
||||
if (!$files) {
|
||||
return array();
|
||||
}
|
||||
|
||||
if (!$sort) {
|
||||
return $files;
|
||||
}
|
||||
|
||||
if ($sort === 1) {
|
||||
return array_reverse($files);
|
||||
}
|
||||
|
||||
if ($sort & FILE_SORT_RANDOM) {
|
||||
shuffle($files);
|
||||
return $files;
|
||||
}
|
||||
|
||||
$names = array();
|
||||
$sizes = array();
|
||||
$dates = array();
|
||||
|
||||
if ($sort & FILE_SORT_NAME) {
|
||||
$r = &$names;
|
||||
} elseif ($sort & FILE_SORT_DATE) {
|
||||
$r = &$dates;
|
||||
} elseif ($sort & FILE_SORT_SIZE) {
|
||||
$r = &$sizes;
|
||||
} else {
|
||||
asort($files, SORT_REGULAR);
|
||||
return $files;
|
||||
}
|
||||
|
||||
$sortFlags = array(
|
||||
FILE_SORT_NAME => SORT_STRING,
|
||||
FILE_SORT_DATE => SORT_NUMERIC,
|
||||
FILE_SORT_SIZE => SORT_NUMERIC,
|
||||
);
|
||||
|
||||
foreach ($files as $file) {
|
||||
$names[] = $file->name;
|
||||
$sizes[] = $file->size;
|
||||
$dates[] = $file->date;
|
||||
}
|
||||
|
||||
if ($sort & FILE_SORT_REVERSE) {
|
||||
arsort($r, $sortFlags[$sort & ~1]);
|
||||
} else {
|
||||
asort($r, $sortFlags[$sort]);
|
||||
}
|
||||
|
||||
$result = array();
|
||||
foreach ($r as $i => $f) {
|
||||
$result[] = $files[$i];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Switch File Extension
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @return string|array
|
||||
* @param string|array $filename
|
||||
* @param string $to new file extension
|
||||
* @param string $from change only files with this extension
|
||||
* @param bool $reverse change only files not having $from extension
|
||||
*/
|
||||
function switchExt($filename, $to, $from = null, $reverse = false)
|
||||
{
|
||||
if (is_array($filename)) {
|
||||
foreach ($filename as $key => $file) {
|
||||
$filename[$key] = File_Util::switchExt($file, $to, $from);
|
||||
}
|
||||
return $filename;
|
||||
}
|
||||
|
||||
if ($len = strlen($from)) {
|
||||
$ext = substr($filename, -$len - 1);
|
||||
$cfn = FILE_WIN32 ? 'strcasecmp' : 'strcmp';
|
||||
if (!$reverse == $cfn($ext, '.'. $from)) {
|
||||
return $filename;
|
||||
}
|
||||
return substr($filename, 0, -$len - 1) .'.'. $to;
|
||||
}
|
||||
|
||||
if ($pos = strpos($filename, '.')) {
|
||||
return substr($filename, 0, $pos) .'.'. $to;
|
||||
}
|
||||
|
||||
return $filename .'.'. $to;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -1,470 +1,465 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Adam Daniel <adaniel1@eesus.jnj.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Common.php,v 1.13 2006/10/08 14:10:46 avb Exp $
|
||||
|
||||
/**
|
||||
* Base class for all HTML classes
|
||||
*
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @category HTML
|
||||
* @package HTML_Common
|
||||
* @version 1.2.3
|
||||
* @abstract
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for all HTML classes
|
||||
*
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @version 1.7
|
||||
* @since PHP 4.0.3pl1
|
||||
* @abstract
|
||||
*/
|
||||
class HTML_Common {
|
||||
|
||||
/**
|
||||
* Associative array of table attributes
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_attributes = array();
|
||||
|
||||
/**
|
||||
* Tab offset of the table
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $_tabOffset = 0;
|
||||
|
||||
/**
|
||||
* Tab string
|
||||
* @var string
|
||||
* @since 1.7
|
||||
* @access private
|
||||
*/
|
||||
var $_tab = "\11";
|
||||
|
||||
/**
|
||||
* Contains the line end string
|
||||
* @var string
|
||||
* @since 1.7
|
||||
* @access private
|
||||
*/
|
||||
var $_lineEnd = "\12";
|
||||
|
||||
/**
|
||||
* HTML comment on the object
|
||||
* @var string
|
||||
* @since 1.5
|
||||
* @access private
|
||||
*/
|
||||
var $_comment = '';
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
* @param mixed $attributes Associative array of table tag attributes
|
||||
* or HTML attributes name="value" pairs
|
||||
* @param int $tabOffset Indent offset in tabs
|
||||
* @access public
|
||||
*/
|
||||
function HTML_Common($attributes = null, $tabOffset = 0)
|
||||
{
|
||||
$this->setAttributes($attributes);
|
||||
$this->setTabOffset($tabOffset);
|
||||
} // end constructor
|
||||
|
||||
/**
|
||||
* Returns the current API version
|
||||
* @access public
|
||||
* @returns double
|
||||
*/
|
||||
function apiVersion()
|
||||
{
|
||||
return 1.7;
|
||||
} // end func apiVersion
|
||||
|
||||
/**
|
||||
* Returns the lineEnd
|
||||
*
|
||||
* @since 1.7
|
||||
* @access private
|
||||
* @return string
|
||||
*/
|
||||
function _getLineEnd()
|
||||
{
|
||||
return $this->_lineEnd;
|
||||
} // end func getLineEnd
|
||||
|
||||
/**
|
||||
* Returns a string containing the unit for indenting HTML
|
||||
*
|
||||
* @since 1.7
|
||||
* @access private
|
||||
* @return string
|
||||
*/
|
||||
function _getTab()
|
||||
{
|
||||
return $this->_tab;
|
||||
} // end func _getTab
|
||||
|
||||
/**
|
||||
* Returns a string containing the offset for the whole HTML code
|
||||
*
|
||||
* @return string
|
||||
* @access private
|
||||
*/
|
||||
function _getTabs()
|
||||
{
|
||||
return str_repeat($this->_getTab(), $this->_tabOffset);
|
||||
} // end func _getTabs
|
||||
|
||||
/**
|
||||
* Returns an HTML formatted attribute string
|
||||
* @param array $attributes
|
||||
* @return string
|
||||
* @access private
|
||||
*/
|
||||
function _getAttrString($attributes)
|
||||
{
|
||||
$strAttr = '';
|
||||
|
||||
if (is_array($attributes)) {
|
||||
$charset = HTML_Common::charset();
|
||||
foreach ($attributes as $key => $value) {
|
||||
$strAttr .= ' ' . $key . '="' . htmlspecialchars($value, ENT_COMPAT, $charset) . '"';
|
||||
}
|
||||
}
|
||||
return $strAttr;
|
||||
} // end func _getAttrString
|
||||
|
||||
/**
|
||||
* Returns a valid atrributes array from either a string or array
|
||||
* @param mixed $attributes Either a typical HTML attribute string or an associative array
|
||||
* @access private
|
||||
* @return array
|
||||
*/
|
||||
function _parseAttributes($attributes)
|
||||
{
|
||||
if (is_array($attributes)) {
|
||||
$ret = array();
|
||||
foreach ($attributes as $key => $value) {
|
||||
if (is_int($key)) {
|
||||
$key = $value = strtolower($value);
|
||||
} else {
|
||||
$key = strtolower($key);
|
||||
}
|
||||
$ret[$key] = $value;
|
||||
}
|
||||
return $ret;
|
||||
|
||||
} elseif (is_string($attributes)) {
|
||||
$preg = "/(([A-Za-z_:]|[^\\x00-\\x7F])([A-Za-z0-9_:.-]|[^\\x00-\\x7F])*)" .
|
||||
"([ \\n\\t\\r]+)?(=([ \\n\\t\\r]+)?(\"[^\"]*\"|'[^']*'|[^ \\n\\t\\r]*))?/";
|
||||
if (preg_match_all($preg, $attributes, $regs)) {
|
||||
for ($counter=0; $counter<count($regs[1]); $counter++) {
|
||||
$name = $regs[1][$counter];
|
||||
$check = $regs[0][$counter];
|
||||
$value = $regs[7][$counter];
|
||||
if (trim($name) == trim($check)) {
|
||||
$arrAttr[strtolower(trim($name))] = strtolower(trim($name));
|
||||
} else {
|
||||
if (substr($value, 0, 1) == "\"" || substr($value, 0, 1) == "'") {
|
||||
$value = substr($value, 1, -1);
|
||||
}
|
||||
$arrAttr[strtolower(trim($name))] = trim($value);
|
||||
}
|
||||
}
|
||||
return $arrAttr;
|
||||
}
|
||||
}
|
||||
} // end func _parseAttributes
|
||||
|
||||
/**
|
||||
* Returns the array key for the given non-name-value pair attribute
|
||||
*
|
||||
* @param string $attr Attribute
|
||||
* @param array $attributes Array of attribute
|
||||
* @since 1.0
|
||||
* @access private
|
||||
* @return bool
|
||||
*/
|
||||
function _getAttrKey($attr, $attributes)
|
||||
{
|
||||
if (isset($attributes[strtolower($attr)])) {
|
||||
return true;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} //end func _getAttrKey
|
||||
|
||||
/**
|
||||
* Updates the attributes in $attr1 with the values in $attr2 without changing the other existing attributes
|
||||
* @param array $attr1 Original attributes array
|
||||
* @param array $attr2 New attributes array
|
||||
* @access private
|
||||
*/
|
||||
function _updateAttrArray(&$attr1, $attr2)
|
||||
{
|
||||
if (!is_array($attr2)) {
|
||||
return false;
|
||||
}
|
||||
foreach ($attr2 as $key => $value) {
|
||||
$attr1[$key] = $value;
|
||||
}
|
||||
} // end func _updateAtrrArray
|
||||
|
||||
/**
|
||||
* Removes the given attribute from the given array
|
||||
*
|
||||
* @param string $attr Attribute name
|
||||
* @param array $attributes Attribute array
|
||||
* @since 1.4
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
function _removeAttr($attr, &$attributes)
|
||||
{
|
||||
$attr = strtolower($attr);
|
||||
if (isset($attributes[$attr])) {
|
||||
unset($attributes[$attr]);
|
||||
}
|
||||
} //end func _removeAttr
|
||||
|
||||
/**
|
||||
* Returns the value of the given attribute
|
||||
*
|
||||
* @param string $attr Attribute name
|
||||
* @since 1.5
|
||||
* @access public
|
||||
* @return string|null returns null if an attribute does not exist
|
||||
*/
|
||||
function getAttribute($attr)
|
||||
{
|
||||
$attr = strtolower($attr);
|
||||
if (isset($this->_attributes[$attr])) {
|
||||
return $this->_attributes[$attr];
|
||||
}
|
||||
return null;
|
||||
} //end func getAttribute
|
||||
|
||||
/**
|
||||
* Sets the value of the attribute
|
||||
*
|
||||
* @param string Attribute name
|
||||
* @param string Attribute value (will be set to $name if omitted)
|
||||
* @access public
|
||||
*/
|
||||
function setAttribute($name, $value = null)
|
||||
{
|
||||
$name = strtolower($name);
|
||||
if (is_null($value)) {
|
||||
$value = $name;
|
||||
}
|
||||
$this->_attributes[$name] = $value;
|
||||
} // end func setAttribute
|
||||
|
||||
/**
|
||||
* Sets the HTML attributes
|
||||
* @param mixed $attributes Either a typical HTML attribute string or an associative array
|
||||
* @access public
|
||||
*/
|
||||
function setAttributes($attributes)
|
||||
{
|
||||
$this->_attributes = $this->_parseAttributes($attributes);
|
||||
} // end func setAttributes
|
||||
|
||||
/**
|
||||
* Returns the assoc array (default) or string of attributes
|
||||
*
|
||||
* @param bool Whether to return the attributes as string
|
||||
* @since 1.6
|
||||
* @access public
|
||||
* @return mixed attributes
|
||||
*/
|
||||
function getAttributes($asString = false)
|
||||
{
|
||||
if ($asString) {
|
||||
return $this->_getAttrString($this->_attributes);
|
||||
} else {
|
||||
return $this->_attributes;
|
||||
}
|
||||
} //end func getAttributes
|
||||
|
||||
/**
|
||||
* Updates the passed attributes without changing the other existing attributes
|
||||
* @param mixed $attributes Either a typical HTML attribute string or an associative array
|
||||
* @access public
|
||||
*/
|
||||
function updateAttributes($attributes)
|
||||
{
|
||||
$this->_updateAttrArray($this->_attributes, $this->_parseAttributes($attributes));
|
||||
} // end func updateAttributes
|
||||
|
||||
/**
|
||||
* Removes an attribute
|
||||
*
|
||||
* @param string $attr Attribute name
|
||||
* @since 1.4
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function removeAttribute($attr)
|
||||
{
|
||||
$this->_removeAttr($attr, $this->_attributes);
|
||||
} //end func removeAttribute
|
||||
|
||||
/**
|
||||
* Sets the line end style to Windows, Mac, Unix or a custom string.
|
||||
*
|
||||
* @param string $style "win", "mac", "unix" or custom string.
|
||||
* @since 1.7
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setLineEnd($style)
|
||||
{
|
||||
switch ($style) {
|
||||
case 'win':
|
||||
$this->_lineEnd = "\15\12";
|
||||
break;
|
||||
case 'unix':
|
||||
$this->_lineEnd = "\12";
|
||||
break;
|
||||
case 'mac':
|
||||
$this->_lineEnd = "\15";
|
||||
break;
|
||||
default:
|
||||
$this->_lineEnd = $style;
|
||||
}
|
||||
} // end func setLineEnd
|
||||
|
||||
/**
|
||||
* Sets the tab offset
|
||||
*
|
||||
* @param int $offset
|
||||
* @access public
|
||||
*/
|
||||
function setTabOffset($offset)
|
||||
{
|
||||
$this->_tabOffset = $offset;
|
||||
} // end func setTabOffset
|
||||
|
||||
/**
|
||||
* Returns the tabOffset
|
||||
*
|
||||
* @since 1.5
|
||||
* @access public
|
||||
* @return int
|
||||
*/
|
||||
function getTabOffset()
|
||||
{
|
||||
return $this->_tabOffset;
|
||||
} //end func getTabOffset
|
||||
|
||||
/**
|
||||
* Sets the string used to indent HTML
|
||||
*
|
||||
* @since 1.7
|
||||
* @param string $string String used to indent ("\11", "\t", ' ', etc.).
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setTab($string)
|
||||
{
|
||||
$this->_tab = $string;
|
||||
} // end func setTab
|
||||
|
||||
/**
|
||||
* Sets the HTML comment to be displayed at the beginning of the HTML string
|
||||
*
|
||||
* @param string
|
||||
* @since 1.4
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setComment($comment)
|
||||
{
|
||||
$this->_comment = $comment;
|
||||
} // end func setHtmlComment
|
||||
|
||||
/**
|
||||
* Returns the HTML comment
|
||||
*
|
||||
* @since 1.5
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getComment()
|
||||
{
|
||||
return $this->_comment;
|
||||
} //end func getComment
|
||||
|
||||
/**
|
||||
* Abstract method. Must be extended to return the objects HTML
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
* @abstract
|
||||
*/
|
||||
function toHtml()
|
||||
{
|
||||
return '';
|
||||
} // end func toHtml
|
||||
|
||||
/**
|
||||
* Displays the HTML to the screen
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function display()
|
||||
{
|
||||
print $this->toHtml();
|
||||
} // end func display
|
||||
|
||||
/**
|
||||
* Sets the charset to use by htmlspecialchars() function
|
||||
*
|
||||
* Since this parameter is expected to be global, the function is designed
|
||||
* to be called statically:
|
||||
* <code>
|
||||
* HTML_Common::charset('utf-8');
|
||||
* </code>
|
||||
* or
|
||||
* <code>
|
||||
* $charset = HTML_Common::charset();
|
||||
* </code>
|
||||
*
|
||||
* @param string New charset to use. Omit if just getting the
|
||||
* current value. Consult the htmlspecialchars() docs
|
||||
* for a list of supported character sets.
|
||||
* @return string Current charset
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function charset($newCharset = null)
|
||||
{
|
||||
static $charset = 'ISO-8859-1';
|
||||
|
||||
if (!is_null($newCharset)) {
|
||||
$charset = $newCharset;
|
||||
}
|
||||
return $charset;
|
||||
} // end func charset
|
||||
} // end class HTML_Common
|
||||
?>
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Base class for all HTML classes
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_Common
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: Common.php,v 1.15 2009/04/03 15:26:22 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_Common/
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for all HTML classes
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_Common
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @version Release: 1.2.5
|
||||
* @abstract
|
||||
*/
|
||||
class HTML_Common
|
||||
{
|
||||
/**
|
||||
* Associative array of attributes
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_attributes = array();
|
||||
|
||||
/**
|
||||
* Tab offset of the tag
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $_tabOffset = 0;
|
||||
|
||||
/**
|
||||
* Tab string
|
||||
* @var string
|
||||
* @since 1.7
|
||||
* @access private
|
||||
*/
|
||||
var $_tab = "\11";
|
||||
|
||||
/**
|
||||
* Contains the line end string
|
||||
* @var string
|
||||
* @since 1.7
|
||||
* @access private
|
||||
*/
|
||||
var $_lineEnd = "\12";
|
||||
|
||||
/**
|
||||
* HTML comment on the object
|
||||
* @var string
|
||||
* @since 1.5
|
||||
* @access private
|
||||
*/
|
||||
var $_comment = '';
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
* @param mixed $attributes Associative array of table tag attributes
|
||||
* or HTML attributes name="value" pairs
|
||||
* @param int $tabOffset Indent offset in tabs
|
||||
* @access public
|
||||
*/
|
||||
function HTML_Common($attributes = null, $tabOffset = 0)
|
||||
{
|
||||
$this->setAttributes($attributes);
|
||||
$this->setTabOffset($tabOffset);
|
||||
} // end constructor
|
||||
|
||||
/**
|
||||
* Returns the current API version
|
||||
* @access public
|
||||
* @returns double
|
||||
*/
|
||||
function apiVersion()
|
||||
{
|
||||
return 1.7;
|
||||
} // end func apiVersion
|
||||
|
||||
/**
|
||||
* Returns the lineEnd
|
||||
*
|
||||
* @since 1.7
|
||||
* @access private
|
||||
* @return string
|
||||
*/
|
||||
function _getLineEnd()
|
||||
{
|
||||
return $this->_lineEnd;
|
||||
} // end func getLineEnd
|
||||
|
||||
/**
|
||||
* Returns a string containing the unit for indenting HTML
|
||||
*
|
||||
* @since 1.7
|
||||
* @access private
|
||||
* @return string
|
||||
*/
|
||||
function _getTab()
|
||||
{
|
||||
return $this->_tab;
|
||||
} // end func _getTab
|
||||
|
||||
/**
|
||||
* Returns a string containing the offset for the whole HTML code
|
||||
*
|
||||
* @return string
|
||||
* @access private
|
||||
*/
|
||||
function _getTabs()
|
||||
{
|
||||
return str_repeat($this->_getTab(), $this->_tabOffset);
|
||||
} // end func _getTabs
|
||||
|
||||
/**
|
||||
* Returns an HTML formatted attribute string
|
||||
* @param array $attributes
|
||||
* @return string
|
||||
* @access private
|
||||
*/
|
||||
function _getAttrString($attributes)
|
||||
{
|
||||
$strAttr = '';
|
||||
|
||||
if (is_array($attributes)) {
|
||||
$charset = HTML_Common::charset();
|
||||
foreach ($attributes as $key => $value) {
|
||||
$strAttr .= ' ' . $key . '="' . htmlspecialchars($value, ENT_COMPAT, $charset) . '"';
|
||||
}
|
||||
}
|
||||
return $strAttr;
|
||||
} // end func _getAttrString
|
||||
|
||||
/**
|
||||
* Returns a valid atrributes array from either a string or array
|
||||
* @param mixed $attributes Either a typical HTML attribute string or an associative array
|
||||
* @access private
|
||||
* @return array
|
||||
*/
|
||||
function _parseAttributes($attributes)
|
||||
{
|
||||
if (is_array($attributes)) {
|
||||
$ret = array();
|
||||
foreach ($attributes as $key => $value) {
|
||||
if (is_int($key)) {
|
||||
$key = $value = strtolower($value);
|
||||
} else {
|
||||
$key = strtolower($key);
|
||||
}
|
||||
$ret[$key] = $value;
|
||||
}
|
||||
return $ret;
|
||||
|
||||
} elseif (is_string($attributes)) {
|
||||
$preg = "/(([A-Za-z_:]|[^\\x00-\\x7F])([A-Za-z0-9_:.-]|[^\\x00-\\x7F])*)" .
|
||||
"([ \\n\\t\\r]+)?(=([ \\n\\t\\r]+)?(\"[^\"]*\"|'[^']*'|[^ \\n\\t\\r]*))?/";
|
||||
if (preg_match_all($preg, $attributes, $regs)) {
|
||||
for ($counter=0; $counter<count($regs[1]); $counter++) {
|
||||
$name = $regs[1][$counter];
|
||||
$check = $regs[0][$counter];
|
||||
$value = $regs[7][$counter];
|
||||
if (trim($name) == trim($check)) {
|
||||
$arrAttr[strtolower(trim($name))] = strtolower(trim($name));
|
||||
} else {
|
||||
if (substr($value, 0, 1) == "\"" || substr($value, 0, 1) == "'") {
|
||||
$arrAttr[strtolower(trim($name))] = substr($value, 1, -1);
|
||||
} else {
|
||||
$arrAttr[strtolower(trim($name))] = trim($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $arrAttr;
|
||||
}
|
||||
}
|
||||
} // end func _parseAttributes
|
||||
|
||||
/**
|
||||
* Returns the array key for the given non-name-value pair attribute
|
||||
*
|
||||
* @param string $attr Attribute
|
||||
* @param array $attributes Array of attribute
|
||||
* @since 1.0
|
||||
* @access private
|
||||
* @return bool
|
||||
*/
|
||||
function _getAttrKey($attr, $attributes)
|
||||
{
|
||||
if (isset($attributes[strtolower($attr)])) {
|
||||
return true;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} //end func _getAttrKey
|
||||
|
||||
/**
|
||||
* Updates the attributes in $attr1 with the values in $attr2 without changing the other existing attributes
|
||||
* @param array $attr1 Original attributes array
|
||||
* @param array $attr2 New attributes array
|
||||
* @access private
|
||||
*/
|
||||
function _updateAttrArray(&$attr1, $attr2)
|
||||
{
|
||||
if (!is_array($attr2)) {
|
||||
return false;
|
||||
}
|
||||
foreach ($attr2 as $key => $value) {
|
||||
$attr1[$key] = $value;
|
||||
}
|
||||
} // end func _updateAtrrArray
|
||||
|
||||
/**
|
||||
* Removes the given attribute from the given array
|
||||
*
|
||||
* @param string $attr Attribute name
|
||||
* @param array $attributes Attribute array
|
||||
* @since 1.4
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
function _removeAttr($attr, &$attributes)
|
||||
{
|
||||
$attr = strtolower($attr);
|
||||
if (isset($attributes[$attr])) {
|
||||
unset($attributes[$attr]);
|
||||
}
|
||||
} //end func _removeAttr
|
||||
|
||||
/**
|
||||
* Returns the value of the given attribute
|
||||
*
|
||||
* @param string $attr Attribute name
|
||||
* @since 1.5
|
||||
* @access public
|
||||
* @return string|null returns null if an attribute does not exist
|
||||
*/
|
||||
function getAttribute($attr)
|
||||
{
|
||||
$attr = strtolower($attr);
|
||||
if (isset($this->_attributes[$attr])) {
|
||||
return $this->_attributes[$attr];
|
||||
}
|
||||
return null;
|
||||
} //end func getAttribute
|
||||
|
||||
/**
|
||||
* Sets the value of the attribute
|
||||
*
|
||||
* @param string Attribute name
|
||||
* @param string Attribute value (will be set to $name if omitted)
|
||||
* @access public
|
||||
*/
|
||||
function setAttribute($name, $value = null)
|
||||
{
|
||||
$name = strtolower($name);
|
||||
if (is_null($value)) {
|
||||
$value = $name;
|
||||
}
|
||||
$this->_attributes[$name] = $value;
|
||||
} // end func setAttribute
|
||||
|
||||
/**
|
||||
* Sets the HTML attributes
|
||||
* @param mixed $attributes Either a typical HTML attribute string or an associative array
|
||||
* @access public
|
||||
*/
|
||||
function setAttributes($attributes)
|
||||
{
|
||||
$this->_attributes = $this->_parseAttributes($attributes);
|
||||
} // end func setAttributes
|
||||
|
||||
/**
|
||||
* Returns the assoc array (default) or string of attributes
|
||||
*
|
||||
* @param bool Whether to return the attributes as string
|
||||
* @since 1.6
|
||||
* @access public
|
||||
* @return mixed attributes
|
||||
*/
|
||||
function getAttributes($asString = false)
|
||||
{
|
||||
if ($asString) {
|
||||
return $this->_getAttrString($this->_attributes);
|
||||
} else {
|
||||
return $this->_attributes;
|
||||
}
|
||||
} //end func getAttributes
|
||||
|
||||
/**
|
||||
* Updates the passed attributes without changing the other existing attributes
|
||||
* @param mixed $attributes Either a typical HTML attribute string or an associative array
|
||||
* @access public
|
||||
*/
|
||||
function updateAttributes($attributes)
|
||||
{
|
||||
$this->_updateAttrArray($this->_attributes, $this->_parseAttributes($attributes));
|
||||
} // end func updateAttributes
|
||||
|
||||
/**
|
||||
* Removes an attribute
|
||||
*
|
||||
* @param string $attr Attribute name
|
||||
* @since 1.4
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function removeAttribute($attr)
|
||||
{
|
||||
$this->_removeAttr($attr, $this->_attributes);
|
||||
} //end func removeAttribute
|
||||
|
||||
/**
|
||||
* Sets the line end style to Windows, Mac, Unix or a custom string.
|
||||
*
|
||||
* @param string $style "win", "mac", "unix" or custom string.
|
||||
* @since 1.7
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setLineEnd($style)
|
||||
{
|
||||
switch ($style) {
|
||||
case 'win':
|
||||
$this->_lineEnd = "\15\12";
|
||||
break;
|
||||
case 'unix':
|
||||
$this->_lineEnd = "\12";
|
||||
break;
|
||||
case 'mac':
|
||||
$this->_lineEnd = "\15";
|
||||
break;
|
||||
default:
|
||||
$this->_lineEnd = $style;
|
||||
}
|
||||
} // end func setLineEnd
|
||||
|
||||
/**
|
||||
* Sets the tab offset
|
||||
*
|
||||
* @param int $offset
|
||||
* @access public
|
||||
*/
|
||||
function setTabOffset($offset)
|
||||
{
|
||||
$this->_tabOffset = $offset;
|
||||
} // end func setTabOffset
|
||||
|
||||
/**
|
||||
* Returns the tabOffset
|
||||
*
|
||||
* @since 1.5
|
||||
* @access public
|
||||
* @return int
|
||||
*/
|
||||
function getTabOffset()
|
||||
{
|
||||
return $this->_tabOffset;
|
||||
} //end func getTabOffset
|
||||
|
||||
/**
|
||||
* Sets the string used to indent HTML
|
||||
*
|
||||
* @since 1.7
|
||||
* @param string $string String used to indent ("\11", "\t", ' ', etc.).
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setTab($string)
|
||||
{
|
||||
$this->_tab = $string;
|
||||
} // end func setTab
|
||||
|
||||
/**
|
||||
* Sets the HTML comment to be displayed at the beginning of the HTML string
|
||||
*
|
||||
* @param string
|
||||
* @since 1.4
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setComment($comment)
|
||||
{
|
||||
$this->_comment = $comment;
|
||||
} // end func setHtmlComment
|
||||
|
||||
/**
|
||||
* Returns the HTML comment
|
||||
*
|
||||
* @since 1.5
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getComment()
|
||||
{
|
||||
return $this->_comment;
|
||||
} //end func getComment
|
||||
|
||||
/**
|
||||
* Abstract method. Must be extended to return the objects HTML
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
* @abstract
|
||||
*/
|
||||
function toHtml()
|
||||
{
|
||||
return '';
|
||||
} // end func toHtml
|
||||
|
||||
/**
|
||||
* Displays the HTML to the screen
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function display()
|
||||
{
|
||||
print $this->toHtml();
|
||||
} // end func display
|
||||
|
||||
/**
|
||||
* Sets the charset to use by htmlspecialchars() function
|
||||
*
|
||||
* Since this parameter is expected to be global, the function is designed
|
||||
* to be called statically:
|
||||
* <code>
|
||||
* HTML_Common::charset('utf-8');
|
||||
* </code>
|
||||
* or
|
||||
* <code>
|
||||
* $charset = HTML_Common::charset();
|
||||
* </code>
|
||||
*
|
||||
* @param string New charset to use. Omit if just getting the
|
||||
* current value. Consult the htmlspecialchars() docs
|
||||
* for a list of supported character sets.
|
||||
* @return string Current charset
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function charset($newCharset = null)
|
||||
{
|
||||
static $charset = 'ISO-8859-1';
|
||||
|
||||
if (!is_null($newCharset)) {
|
||||
$charset = $newCharset;
|
||||
}
|
||||
return $charset;
|
||||
} // end func charset
|
||||
} // end class HTML_Common
|
||||
?>
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,150 +1,158 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4.0 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Alexey Borzov <borz_off@cs.msu.su> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Renderer.php,v 1.1 2003/03/08 17:02:07 mansion Exp $
|
||||
|
||||
/**
|
||||
* An abstract base class for QuickForm renderers
|
||||
*
|
||||
* The class implements a Visitor design pattern
|
||||
*
|
||||
* @abstract
|
||||
* @author Alexey Borzov <borz_off@cs.msu.su>
|
||||
*/
|
||||
class HTML_QuickForm_Renderer
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function HTML_QuickForm_Renderer()
|
||||
{
|
||||
} // end constructor
|
||||
|
||||
/**
|
||||
* Called when visiting a form, before processing any form elements
|
||||
*
|
||||
* @param object An HTML_QuickForm object being visited
|
||||
* @access public
|
||||
* @return void
|
||||
* @abstract
|
||||
*/
|
||||
function startForm(&$form)
|
||||
{
|
||||
return;
|
||||
} // end func startForm
|
||||
|
||||
/**
|
||||
* Called when visiting a form, after processing all form elements
|
||||
*
|
||||
* @param object An HTML_QuickForm object being visited
|
||||
* @access public
|
||||
* @return void
|
||||
* @abstract
|
||||
*/
|
||||
function finishForm(&$form)
|
||||
{
|
||||
return;
|
||||
} // end func finishForm
|
||||
|
||||
/**
|
||||
* Called when visiting a header element
|
||||
*
|
||||
* @param object An HTML_QuickForm_header element being visited
|
||||
* @access public
|
||||
* @return void
|
||||
* @abstract
|
||||
*/
|
||||
function renderHeader(&$header)
|
||||
{
|
||||
return;
|
||||
} // end func renderHeader
|
||||
|
||||
/**
|
||||
* Called when visiting an element
|
||||
*
|
||||
* @param object An HTML_QuickForm_element object being visited
|
||||
* @param bool Whether an element is required
|
||||
* @param string An error message associated with an element
|
||||
* @access public
|
||||
* @return void
|
||||
* @abstract
|
||||
*/
|
||||
function renderElement(&$element, $required, $error)
|
||||
{
|
||||
return;
|
||||
} // end func renderElement
|
||||
|
||||
/**
|
||||
* Called when visiting a hidden element
|
||||
*
|
||||
* @param object An HTML_QuickForm_hidden object being visited
|
||||
* @access public
|
||||
* @return void
|
||||
* @abstract
|
||||
*/
|
||||
function renderHidden(&$element)
|
||||
{
|
||||
return;
|
||||
} // end func renderHidden
|
||||
|
||||
/**
|
||||
* Called when visiting a raw HTML/text pseudo-element
|
||||
*
|
||||
* Seems that this should not be used when using a template-based renderer
|
||||
*
|
||||
* @param object An HTML_QuickForm_html element being visited
|
||||
* @access public
|
||||
* @return void
|
||||
* @abstract
|
||||
*/
|
||||
function renderHtml(&$data)
|
||||
{
|
||||
return;
|
||||
} // end func renderHtml
|
||||
|
||||
/**
|
||||
* Called when visiting a group, before processing any group elements
|
||||
*
|
||||
* @param object An HTML_QuickForm_group object being visited
|
||||
* @param bool Whether a group is required
|
||||
* @param string An error message associated with a group
|
||||
* @access public
|
||||
* @return void
|
||||
* @abstract
|
||||
*/
|
||||
function startGroup(&$group, $required, $error)
|
||||
{
|
||||
return;
|
||||
} // end func startGroup
|
||||
|
||||
/**
|
||||
* Called when visiting a group, after processing all group elements
|
||||
*
|
||||
* @param object An HTML_QuickForm_group object being visited
|
||||
* @access public
|
||||
* @return void
|
||||
* @abstract
|
||||
*/
|
||||
function finishGroup(&$group)
|
||||
{
|
||||
return;
|
||||
} // end func finishGroup
|
||||
} // end class HTML_QuickForm_Renderer
|
||||
?>
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* An abstract base class for QuickForm renderers
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id$
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* An abstract base class for QuickForm renderers
|
||||
*
|
||||
* The class implements a Visitor design pattern
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @version Release: 3.2.11
|
||||
* @since 3.0
|
||||
* @abstract
|
||||
*/
|
||||
class HTML_QuickForm_Renderer
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function HTML_QuickForm_Renderer()
|
||||
{
|
||||
} // end constructor
|
||||
|
||||
/**
|
||||
* Called when visiting a form, before processing any form elements
|
||||
*
|
||||
* @param HTML_QuickForm a form being visited
|
||||
* @access public
|
||||
* @return void
|
||||
* @abstract
|
||||
*/
|
||||
function startForm(&$form)
|
||||
{
|
||||
return;
|
||||
} // end func startForm
|
||||
|
||||
/**
|
||||
* Called when visiting a form, after processing all form elements
|
||||
*
|
||||
* @param HTML_QuickForm a form being visited
|
||||
* @access public
|
||||
* @return void
|
||||
* @abstract
|
||||
*/
|
||||
function finishForm(&$form)
|
||||
{
|
||||
return;
|
||||
} // end func finishForm
|
||||
|
||||
/**
|
||||
* Called when visiting a header element
|
||||
*
|
||||
* @param HTML_QuickForm_header a header element being visited
|
||||
* @access public
|
||||
* @return void
|
||||
* @abstract
|
||||
*/
|
||||
function renderHeader(&$header)
|
||||
{
|
||||
return;
|
||||
} // end func renderHeader
|
||||
|
||||
/**
|
||||
* Called when visiting an element
|
||||
*
|
||||
* @param HTML_QuickForm_element form element being visited
|
||||
* @param bool Whether an element is required
|
||||
* @param string An error message associated with an element
|
||||
* @access public
|
||||
* @return void
|
||||
* @abstract
|
||||
*/
|
||||
function renderElement(&$element, $required, $error)
|
||||
{
|
||||
return;
|
||||
} // end func renderElement
|
||||
|
||||
/**
|
||||
* Called when visiting a hidden element
|
||||
*
|
||||
* @param HTML_QuickForm_element a hidden element being visited
|
||||
* @access public
|
||||
* @return void
|
||||
* @abstract
|
||||
*/
|
||||
function renderHidden(&$element)
|
||||
{
|
||||
return;
|
||||
} // end func renderHidden
|
||||
|
||||
/**
|
||||
* Called when visiting a raw HTML/text pseudo-element
|
||||
*
|
||||
* Only implemented in Default renderer. Usage of 'html' elements is
|
||||
* discouraged, templates should be used instead.
|
||||
*
|
||||
* @param HTML_QuickForm_html a 'raw html' element being visited
|
||||
* @access public
|
||||
* @return void
|
||||
* @abstract
|
||||
*/
|
||||
function renderHtml(&$data)
|
||||
{
|
||||
return;
|
||||
} // end func renderHtml
|
||||
|
||||
/**
|
||||
* Called when visiting a group, before processing any group elements
|
||||
*
|
||||
* @param HTML_QuickForm_group A group being visited
|
||||
* @param bool Whether a group is required
|
||||
* @param string An error message associated with a group
|
||||
* @access public
|
||||
* @return void
|
||||
* @abstract
|
||||
*/
|
||||
function startGroup(&$group, $required, $error)
|
||||
{
|
||||
return;
|
||||
} // end func startGroup
|
||||
|
||||
/**
|
||||
* Called when visiting a group, after processing all group elements
|
||||
*
|
||||
* @param HTML_QuickForm_group A group being visited
|
||||
* @access public
|
||||
* @return void
|
||||
* @abstract
|
||||
*/
|
||||
function finishGroup(&$group)
|
||||
{
|
||||
return;
|
||||
} // end func finishGroup
|
||||
} // end class HTML_QuickForm_Renderer
|
||||
?>
|
||||
|
|
|
@ -1,319 +1,340 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4.0 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Alexey Borzov <borz_off@cs.msu.su> |
|
||||
// | Adam Daniel <adaniel1@eesus.jnj.com> |
|
||||
// | Bertrand Mansion <bmansion@mamasam.com> |
|
||||
// | Thomas Schulz <ths@4bconsult.de> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Array.php,v 1.9 2004/10/15 20:00:48 ths Exp $
|
||||
|
||||
require_once 'HTML/QuickForm/Renderer.php';
|
||||
|
||||
/**
|
||||
* A concrete renderer for HTML_QuickForm, makes an array of form contents
|
||||
*
|
||||
* Based on old toArray() code.
|
||||
*
|
||||
* The form array structure is the following:
|
||||
* array(
|
||||
* 'frozen' => 'whether the form is frozen',
|
||||
* 'javascript' => 'javascript for client-side validation',
|
||||
* 'attributes' => 'attributes for <form> tag',
|
||||
* 'requirednote => 'note about the required elements',
|
||||
* // if we set the option to collect hidden elements
|
||||
* 'hidden' => 'collected html of all hidden elements',
|
||||
* // if there were some validation errors:
|
||||
* 'errors' => array(
|
||||
* '1st element name' => 'Error for the 1st element',
|
||||
* ...
|
||||
* 'nth element name' => 'Error for the nth element'
|
||||
* ),
|
||||
* // if there are no headers in the form:
|
||||
* 'elements' => array(
|
||||
* element_1,
|
||||
* ...
|
||||
* element_N
|
||||
* )
|
||||
* // if there are headers in the form:
|
||||
* 'sections' => array(
|
||||
* array(
|
||||
* 'header' => 'Header text for the first header',
|
||||
* 'name' => 'Header name for the first header',
|
||||
* 'elements' => array(
|
||||
* element_1,
|
||||
* ...
|
||||
* element_K1
|
||||
* )
|
||||
* ),
|
||||
* ...
|
||||
* array(
|
||||
* 'header' => 'Header text for the Mth header',
|
||||
* 'name' => 'Header name for the Mth header',
|
||||
* 'elements' => array(
|
||||
* element_1,
|
||||
* ...
|
||||
* element_KM
|
||||
* )
|
||||
* )
|
||||
* )
|
||||
* );
|
||||
*
|
||||
* where element_i is an array of the form:
|
||||
* array(
|
||||
* 'name' => 'element name',
|
||||
* 'value' => 'element value',
|
||||
* 'type' => 'type of the element',
|
||||
* 'frozen' => 'whether element is frozen',
|
||||
* 'label' => 'label for the element',
|
||||
* 'required' => 'whether element is required',
|
||||
* 'error' => 'error associated with the element',
|
||||
* 'style' => 'some information about element style (e.g. for Smarty)',
|
||||
* // if element is not a group
|
||||
* 'html' => 'HTML for the element'
|
||||
* // if element is a group
|
||||
* 'separator' => 'separator for group elements',
|
||||
* 'elements' => array(
|
||||
* element_1,
|
||||
* ...
|
||||
* element_N
|
||||
* )
|
||||
* );
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
class HTML_QuickForm_Renderer_Array extends HTML_QuickForm_Renderer
|
||||
{
|
||||
/**
|
||||
* An array being generated
|
||||
* @var array
|
||||
*/
|
||||
var $_ary;
|
||||
|
||||
/**
|
||||
* Number of sections in the form (i.e. number of headers in it)
|
||||
* @var integer
|
||||
*/
|
||||
var $_sectionCount;
|
||||
|
||||
/**
|
||||
* Current section number
|
||||
* @var integer
|
||||
*/
|
||||
var $_currentSection;
|
||||
|
||||
/**
|
||||
* Array representing current group
|
||||
* @var array
|
||||
*/
|
||||
var $_currentGroup = null;
|
||||
|
||||
/**
|
||||
* Additional style information for different elements
|
||||
* @var array
|
||||
*/
|
||||
var $_elementStyles = array();
|
||||
|
||||
/**
|
||||
* true: collect all hidden elements into string; false: process them as usual form elements
|
||||
* @var bool
|
||||
*/
|
||||
var $_collectHidden = false;
|
||||
|
||||
/**
|
||||
* true: render an array of labels to many labels, $key 0 named 'label', the rest "label_$key"
|
||||
* false: leave labels as defined
|
||||
* @var bool
|
||||
*/
|
||||
var $staticLabels = false;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param bool true: collect all hidden elements into string; false: process them as usual form elements
|
||||
* @param bool true: render an array of labels to many labels, $key 0 to 'label' and the oterh to "label_$key"
|
||||
* @access public
|
||||
*/
|
||||
function HTML_QuickForm_Renderer_Array($collectHidden = false, $staticLabels = false)
|
||||
{
|
||||
$this->HTML_QuickForm_Renderer();
|
||||
$this->_collectHidden = $collectHidden;
|
||||
$this->_staticLabels = $staticLabels;
|
||||
} // end constructor
|
||||
|
||||
|
||||
/**
|
||||
* Returns the resultant array
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
function toArray()
|
||||
{
|
||||
return $this->_ary;
|
||||
}
|
||||
|
||||
|
||||
function startForm(&$form)
|
||||
{
|
||||
$this->_ary = array(
|
||||
'frozen' => $form->isFrozen(),
|
||||
'javascript' => $form->getValidationScript(),
|
||||
'attributes' => $form->getAttributes(true),
|
||||
'requirednote' => $form->getRequiredNote(),
|
||||
'errors' => array()
|
||||
);
|
||||
if ($this->_collectHidden) {
|
||||
$this->_ary['hidden'] = '';
|
||||
}
|
||||
$this->_elementIdx = 1;
|
||||
$this->_currentSection = null;
|
||||
$this->_sectionCount = 0;
|
||||
} // end func startForm
|
||||
|
||||
|
||||
function renderHeader(&$header)
|
||||
{
|
||||
$this->_ary['sections'][$this->_sectionCount] = array(
|
||||
'header' => $header->toHtml(),
|
||||
'name' => $header->getName()
|
||||
);
|
||||
$this->_currentSection = $this->_sectionCount++;
|
||||
} // end func renderHeader
|
||||
|
||||
|
||||
function renderElement(&$element, $required, $error)
|
||||
{
|
||||
$elAry = $this->_elementToArray($element, $required, $error);
|
||||
if (!empty($error)) {
|
||||
$this->_ary['errors'][$elAry['name']] = $error;
|
||||
}
|
||||
$this->_storeArray($elAry);
|
||||
} // end func renderElement
|
||||
|
||||
|
||||
function renderHidden(&$element)
|
||||
{
|
||||
if ($this->_collectHidden) {
|
||||
$this->_ary['hidden'] .= $element->toHtml() . "\n";
|
||||
} else {
|
||||
$this->renderElement($element, false, null);
|
||||
}
|
||||
} // end func renderHidden
|
||||
|
||||
|
||||
function startGroup(&$group, $required, $error)
|
||||
{
|
||||
$this->_currentGroup = $this->_elementToArray($group, $required, $error);
|
||||
if (!empty($error)) {
|
||||
$this->_ary['errors'][$this->_currentGroup['name']] = $error;
|
||||
}
|
||||
} // end func startGroup
|
||||
|
||||
|
||||
function finishGroup(&$group)
|
||||
{
|
||||
$this->_storeArray($this->_currentGroup);
|
||||
$this->_currentGroup = null;
|
||||
} // end func finishGroup
|
||||
|
||||
|
||||
/**
|
||||
* Creates an array representing an element
|
||||
*
|
||||
* @access private
|
||||
* @param object An HTML_QuickForm_element object
|
||||
* @param bool Whether an element is required
|
||||
* @param string Error associated with the element
|
||||
* @return array
|
||||
*/
|
||||
function _elementToArray(&$element, $required, $error)
|
||||
{
|
||||
$ret = array(
|
||||
'name' => $element->getName(),
|
||||
'value' => $element->getValue(),
|
||||
'type' => $element->getType(),
|
||||
'frozen' => $element->isFrozen(),
|
||||
'required' => $required,
|
||||
'error' => $error
|
||||
);
|
||||
// render label(s)
|
||||
$labels = $element->getLabel();
|
||||
if (is_array($labels) && $this->_staticLabels) {
|
||||
foreach($labels as $key => $label) {
|
||||
$key = is_int($key)? $key + 1: $key;
|
||||
if (1 === $key) {
|
||||
$ret['label'] = $label;
|
||||
} else {
|
||||
$ret['label_' . $key] = $label;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$ret['label'] = $labels;
|
||||
}
|
||||
|
||||
// set the style for the element
|
||||
if (isset($this->_elementStyles[$ret['name']])) {
|
||||
$ret['style'] = $this->_elementStyles[$ret['name']];
|
||||
}
|
||||
if ('group' == $ret['type']) {
|
||||
$ret['separator'] = $element->_separator;
|
||||
$ret['elements'] = array();
|
||||
} else {
|
||||
$ret['html'] = $element->toHtml();
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Stores an array representation of an element in the form array
|
||||
*
|
||||
* @access private
|
||||
* @param array Array representation of an element
|
||||
* @return void
|
||||
*/
|
||||
function _storeArray($elAry)
|
||||
{
|
||||
// where should we put this element...
|
||||
if (is_array($this->_currentGroup) && ('group' != $elAry['type'])) {
|
||||
$this->_currentGroup['elements'][] = $elAry;
|
||||
} elseif (isset($this->_currentSection)) {
|
||||
$this->_ary['sections'][$this->_currentSection]['elements'][] = $elAry;
|
||||
} else {
|
||||
$this->_ary['elements'][] = $elAry;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets a style to use for element rendering
|
||||
*
|
||||
* @param mixed element name or array ('element name' => 'style name')
|
||||
* @param string style name if $elementName is not an array
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setElementStyle($elementName, $styleName = null)
|
||||
{
|
||||
if (is_array($elementName)) {
|
||||
$this->_elementStyles = array_merge($this->_elementStyles, $elementName);
|
||||
} else {
|
||||
$this->_elementStyles[$elementName] = $styleName;
|
||||
}
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* A concrete renderer for HTML_QuickForm, makes an array of form contents
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @author Thomas Schulz <ths@4bconsult.de>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: Array.php,v 1.11 2009/04/04 21:34:04 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* An abstract base class for QuickForm renderers
|
||||
*/
|
||||
require_once 'HTML/QuickForm/Renderer.php';
|
||||
|
||||
/**
|
||||
* A concrete renderer for HTML_QuickForm, makes an array of form contents
|
||||
*
|
||||
* Based on old HTML_QuickForm::toArray() code.
|
||||
*
|
||||
* The form array structure is the following:
|
||||
* <pre>
|
||||
* array(
|
||||
* 'frozen' => 'whether the form is frozen',
|
||||
* 'javascript' => 'javascript for client-side validation',
|
||||
* 'attributes' => 'attributes for <form> tag',
|
||||
* 'requirednote => 'note about the required elements',
|
||||
* // if we set the option to collect hidden elements
|
||||
* 'hidden' => 'collected html of all hidden elements',
|
||||
* // if there were some validation errors:
|
||||
* 'errors' => array(
|
||||
* '1st element name' => 'Error for the 1st element',
|
||||
* ...
|
||||
* 'nth element name' => 'Error for the nth element'
|
||||
* ),
|
||||
* // if there are no headers in the form:
|
||||
* 'elements' => array(
|
||||
* element_1,
|
||||
* ...
|
||||
* element_N
|
||||
* )
|
||||
* // if there are headers in the form:
|
||||
* 'sections' => array(
|
||||
* array(
|
||||
* 'header' => 'Header text for the first header',
|
||||
* 'name' => 'Header name for the first header',
|
||||
* 'elements' => array(
|
||||
* element_1,
|
||||
* ...
|
||||
* element_K1
|
||||
* )
|
||||
* ),
|
||||
* ...
|
||||
* array(
|
||||
* 'header' => 'Header text for the Mth header',
|
||||
* 'name' => 'Header name for the Mth header',
|
||||
* 'elements' => array(
|
||||
* element_1,
|
||||
* ...
|
||||
* element_KM
|
||||
* )
|
||||
* )
|
||||
* )
|
||||
* );
|
||||
* </pre>
|
||||
*
|
||||
* where element_i is an array of the form:
|
||||
* <pre>
|
||||
* array(
|
||||
* 'name' => 'element name',
|
||||
* 'value' => 'element value',
|
||||
* 'type' => 'type of the element',
|
||||
* 'frozen' => 'whether element is frozen',
|
||||
* 'label' => 'label for the element',
|
||||
* 'required' => 'whether element is required',
|
||||
* 'error' => 'error associated with the element',
|
||||
* 'style' => 'some information about element style (e.g. for Smarty)',
|
||||
* // if element is not a group
|
||||
* 'html' => 'HTML for the element'
|
||||
* // if element is a group
|
||||
* 'separator' => 'separator for group elements',
|
||||
* 'elements' => array(
|
||||
* element_1,
|
||||
* ...
|
||||
* element_N
|
||||
* )
|
||||
* );
|
||||
* </pre>
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @author Thomas Schulz <ths@4bconsult.de>
|
||||
* @version Release: 3.2.11
|
||||
* @since 3.0
|
||||
*/
|
||||
class HTML_QuickForm_Renderer_Array extends HTML_QuickForm_Renderer
|
||||
{
|
||||
/**#@+
|
||||
* @access private
|
||||
*/
|
||||
/**
|
||||
* An array being generated
|
||||
* @var array
|
||||
*/
|
||||
var $_ary;
|
||||
|
||||
/**
|
||||
* Number of sections in the form (i.e. number of headers in it)
|
||||
* @var integer
|
||||
*/
|
||||
var $_sectionCount;
|
||||
|
||||
/**
|
||||
* Current section number
|
||||
* @var integer
|
||||
*/
|
||||
var $_currentSection;
|
||||
|
||||
/**
|
||||
* Array representing current group
|
||||
* @var array
|
||||
*/
|
||||
var $_currentGroup = null;
|
||||
|
||||
/**
|
||||
* Additional style information for different elements
|
||||
* @var array
|
||||
*/
|
||||
var $_elementStyles = array();
|
||||
|
||||
/**
|
||||
* true: collect all hidden elements into string; false: process them as usual form elements
|
||||
* @var bool
|
||||
*/
|
||||
var $_collectHidden = false;
|
||||
|
||||
/**
|
||||
* true: render an array of labels to many labels, $key 0 named 'label', the rest "label_$key"
|
||||
* false: leave labels as defined
|
||||
* @var bool
|
||||
*/
|
||||
var $_staticLabels = false;
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param bool true: collect all hidden elements into string; false: process them as usual form elements
|
||||
* @param bool true: render an array of labels to many labels, $key 0 to 'label' and the oterh to "label_$key"
|
||||
* @access public
|
||||
*/
|
||||
function HTML_QuickForm_Renderer_Array($collectHidden = false, $staticLabels = false)
|
||||
{
|
||||
$this->HTML_QuickForm_Renderer();
|
||||
$this->_collectHidden = $collectHidden;
|
||||
$this->_staticLabels = $staticLabels;
|
||||
} // end constructor
|
||||
|
||||
|
||||
/**
|
||||
* Returns the resultant array
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
function toArray()
|
||||
{
|
||||
return $this->_ary;
|
||||
}
|
||||
|
||||
|
||||
function startForm(&$form)
|
||||
{
|
||||
$this->_ary = array(
|
||||
'frozen' => $form->isFrozen(),
|
||||
'javascript' => $form->getValidationScript(),
|
||||
'attributes' => $form->getAttributes(true),
|
||||
'requirednote' => $form->getRequiredNote(),
|
||||
'errors' => array()
|
||||
);
|
||||
if ($this->_collectHidden) {
|
||||
$this->_ary['hidden'] = '';
|
||||
}
|
||||
$this->_elementIdx = 1;
|
||||
$this->_currentSection = null;
|
||||
$this->_sectionCount = 0;
|
||||
} // end func startForm
|
||||
|
||||
|
||||
function renderHeader(&$header)
|
||||
{
|
||||
$this->_ary['sections'][$this->_sectionCount] = array(
|
||||
'header' => $header->toHtml(),
|
||||
'name' => $header->getName()
|
||||
);
|
||||
$this->_currentSection = $this->_sectionCount++;
|
||||
} // end func renderHeader
|
||||
|
||||
|
||||
function renderElement(&$element, $required, $error)
|
||||
{
|
||||
$elAry = $this->_elementToArray($element, $required, $error);
|
||||
if (!empty($error)) {
|
||||
$this->_ary['errors'][$elAry['name']] = $error;
|
||||
}
|
||||
$this->_storeArray($elAry);
|
||||
} // end func renderElement
|
||||
|
||||
|
||||
function renderHidden(&$element)
|
||||
{
|
||||
if ($this->_collectHidden) {
|
||||
$this->_ary['hidden'] .= $element->toHtml() . "\n";
|
||||
} else {
|
||||
$this->renderElement($element, false, null);
|
||||
}
|
||||
} // end func renderHidden
|
||||
|
||||
|
||||
function startGroup(&$group, $required, $error)
|
||||
{
|
||||
$this->_currentGroup = $this->_elementToArray($group, $required, $error);
|
||||
if (!empty($error)) {
|
||||
$this->_ary['errors'][$this->_currentGroup['name']] = $error;
|
||||
}
|
||||
} // end func startGroup
|
||||
|
||||
|
||||
function finishGroup(&$group)
|
||||
{
|
||||
$this->_storeArray($this->_currentGroup);
|
||||
$this->_currentGroup = null;
|
||||
} // end func finishGroup
|
||||
|
||||
|
||||
/**
|
||||
* Creates an array representing an element
|
||||
*
|
||||
* @access private
|
||||
* @param HTML_QuickForm_element element being processed
|
||||
* @param bool Whether an element is required
|
||||
* @param string Error associated with the element
|
||||
* @return array
|
||||
*/
|
||||
function _elementToArray(&$element, $required, $error)
|
||||
{
|
||||
$ret = array(
|
||||
'name' => $element->getName(),
|
||||
'value' => $element->getValue(),
|
||||
'type' => $element->getType(),
|
||||
'frozen' => $element->isFrozen(),
|
||||
'required' => $required,
|
||||
'error' => $error
|
||||
);
|
||||
// render label(s)
|
||||
$labels = $element->getLabel();
|
||||
if (is_array($labels) && $this->_staticLabels) {
|
||||
foreach($labels as $key => $label) {
|
||||
$key = is_int($key)? $key + 1: $key;
|
||||
if (1 === $key) {
|
||||
$ret['label'] = $label;
|
||||
} else {
|
||||
$ret['label_' . $key] = $label;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$ret['label'] = $labels;
|
||||
}
|
||||
|
||||
// set the style for the element
|
||||
if (isset($this->_elementStyles[$ret['name']])) {
|
||||
$ret['style'] = $this->_elementStyles[$ret['name']];
|
||||
}
|
||||
if ('group' == $ret['type']) {
|
||||
$ret['separator'] = $element->_separator;
|
||||
$ret['elements'] = array();
|
||||
} else {
|
||||
$ret['html'] = $element->toHtml();
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Stores an array representation of an element in the form array
|
||||
*
|
||||
* @access private
|
||||
* @param array Array representation of an element
|
||||
* @return void
|
||||
*/
|
||||
function _storeArray($elAry)
|
||||
{
|
||||
// where should we put this element...
|
||||
if (is_array($this->_currentGroup) && ('group' != $elAry['type'])) {
|
||||
$this->_currentGroup['elements'][] = $elAry;
|
||||
} elseif (isset($this->_currentSection)) {
|
||||
$this->_ary['sections'][$this->_currentSection]['elements'][] = $elAry;
|
||||
} else {
|
||||
$this->_ary['elements'][] = $elAry;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets a style to use for element rendering
|
||||
*
|
||||
* @param mixed element name or array ('element name' => 'style name')
|
||||
* @param string style name if $elementName is not an array
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setElementStyle($elementName, $styleName = null)
|
||||
{
|
||||
if (is_array($elementName)) {
|
||||
$this->_elementStyles = array_merge($this->_elementStyles, $elementName);
|
||||
} else {
|
||||
$this->_elementStyles[$elementName] = $styleName;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -1,381 +1,403 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4.0 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Alexey Borzov <borz_off@cs.msu.su> |
|
||||
// | Bertrand Mansion <bmansion@mamasam.com> |
|
||||
// | Thomas Schulz <ths@4bconsult.de> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: ArraySmarty.php,v 1.11 2006/10/07 20:12:17 avb Exp $
|
||||
|
||||
require_once 'HTML/QuickForm/Renderer/Array.php';
|
||||
|
||||
/**
|
||||
* A static renderer for HTML_QuickForm, makes an array of form content
|
||||
* useful for an Smarty template
|
||||
*
|
||||
* Based on old toArray() code and ITStatic renderer.
|
||||
*
|
||||
* The form array structure is the following:
|
||||
* Array (
|
||||
* [frozen] => whether the complete form is frozen'
|
||||
* [javascript] => javascript for client-side validation
|
||||
* [attributes] => attributes for <form> tag
|
||||
* [hidden] => html of all hidden elements
|
||||
* [requirednote] => note about the required elements
|
||||
* [errors] => Array
|
||||
* (
|
||||
* [1st_element_name] => Error for the 1st element
|
||||
* ...
|
||||
* [nth_element_name] => Error for the nth element
|
||||
* )
|
||||
*
|
||||
* [header] => Array
|
||||
* (
|
||||
* [1st_header_name] => Header text for the 1st header
|
||||
* ...
|
||||
* [nth_header_name] => Header text for the nth header
|
||||
* )
|
||||
*
|
||||
* [1st_element_name] => Array for the 1st element
|
||||
* ...
|
||||
* [nth_element_name] => Array for the nth element
|
||||
*
|
||||
* // where an element array has the form:
|
||||
* (
|
||||
* [name] => element name
|
||||
* [value] => element value,
|
||||
* [type] => type of the element
|
||||
* [frozen] => whether element is frozen
|
||||
* [label] => label for the element
|
||||
* [required] => whether element is required
|
||||
* // if element is not a group:
|
||||
* [html] => HTML for the element
|
||||
* // if element is a group:
|
||||
* [separator] => separator for group elements
|
||||
* [1st_gitem_name] => Array for the 1st element in group
|
||||
* ...
|
||||
* [nth_gitem_name] => Array for the nth element in group
|
||||
* )
|
||||
* )
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
class HTML_QuickForm_Renderer_ArraySmarty extends HTML_QuickForm_Renderer_Array
|
||||
{
|
||||
/**
|
||||
* The Smarty template engine instance
|
||||
* @var object
|
||||
*/
|
||||
var $_tpl = null;
|
||||
|
||||
/**
|
||||
* Current element index
|
||||
* @var integer
|
||||
*/
|
||||
var $_elementIdx = 0;
|
||||
|
||||
/**
|
||||
* The current element index inside a group
|
||||
* @var integer
|
||||
*/
|
||||
var $_groupElementIdx = 0;
|
||||
|
||||
/**
|
||||
* How to handle the required tag for required fields
|
||||
* @var string
|
||||
* @see setRequiredTemplate()
|
||||
*/
|
||||
var $_required = '';
|
||||
|
||||
/**
|
||||
* How to handle error messages in form validation
|
||||
* @var string
|
||||
* @see setErrorTemplate()
|
||||
*/
|
||||
var $_error = '';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param object reference to the Smarty template engine instance
|
||||
* @param bool true: render an array of labels to many labels, $key 0 to 'label' and the oterh to "label_$key"
|
||||
* @access public
|
||||
*/
|
||||
function HTML_QuickForm_Renderer_ArraySmarty(&$tpl, $staticLabels = false)
|
||||
{
|
||||
$this->HTML_QuickForm_Renderer_Array(true, $staticLabels);
|
||||
$this->_tpl =& $tpl;
|
||||
} // end constructor
|
||||
|
||||
/**
|
||||
* Called when visiting a header element
|
||||
*
|
||||
* @param object An HTML_QuickForm_header element being visited
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function renderHeader(&$header)
|
||||
{
|
||||
if ($name = $header->getName()) {
|
||||
$this->_ary['header'][$name] = $header->toHtml();
|
||||
} else {
|
||||
$this->_ary['header'][$this->_sectionCount] = $header->toHtml();
|
||||
}
|
||||
$this->_currentSection = $this->_sectionCount++;
|
||||
} // end func renderHeader
|
||||
|
||||
/**
|
||||
* Called when visiting a group, before processing any group elements
|
||||
*
|
||||
* @param object An HTML_QuickForm_group object being visited
|
||||
* @param bool Whether a group is required
|
||||
* @param string An error message associated with a group
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function startGroup(&$group, $required, $error)
|
||||
{
|
||||
parent::startGroup($group, $required, $error);
|
||||
$this->_groupElementIdx = 1;
|
||||
} // end func startGroup
|
||||
|
||||
/**
|
||||
* Creates an array representing an element containing
|
||||
* the key for storing this
|
||||
*
|
||||
* @access private
|
||||
* @param object An HTML_QuickForm_element object
|
||||
* @param bool Whether an element is required
|
||||
* @param string Error associated with the element
|
||||
* @return array
|
||||
*/
|
||||
function _elementToArray(&$element, $required, $error)
|
||||
{
|
||||
$ret = parent::_elementToArray($element, $required, $error);
|
||||
|
||||
if ('group' == $ret['type']) {
|
||||
$ret['html'] = $element->toHtml();
|
||||
// we don't need the elements, see the array structure
|
||||
unset($ret['elements']);
|
||||
}
|
||||
if (($required || $error) && !empty($this->_required)){
|
||||
$this->_renderRequired($ret['label'], $ret['html'], $required, $error);
|
||||
}
|
||||
if ($error && !empty($this->_error)) {
|
||||
$this->_renderError($ret['label'], $ret['html'], $error);
|
||||
$ret['error'] = $error;
|
||||
}
|
||||
// create keys for elements grouped by native group or name
|
||||
if (strstr($ret['name'], '[') or $this->_currentGroup) {
|
||||
// Fix for bug #8123: escape backslashes and quotes to prevent errors
|
||||
// in eval(). The code below seems to handle the case where element
|
||||
// name has unbalanced square brackets. Dunno whether we really
|
||||
// need this after the fix for #8123, but I'm wary of making big
|
||||
// changes to this code.
|
||||
preg_match('/([^]]*)\\[([^]]*)\\]/', $ret['name'], $matches);
|
||||
if (isset($matches[1])) {
|
||||
$sKeysSub = substr_replace($ret['name'], '', 0, strlen($matches[1]));
|
||||
$sKeysSub = str_replace(
|
||||
array('\\', '\'', '[' , ']', '[\'\']'),
|
||||
array('\\\\', '\\\'', '[\'', '\']', '[]' ),
|
||||
$sKeysSub
|
||||
);
|
||||
$sKeys = '[\'' . str_replace(array('\\', '\''), array('\\\\', '\\\''), $matches[1]) . '\']' . $sKeysSub;
|
||||
} else {
|
||||
$sKeys = '[\'' . str_replace(array('\\', '\''), array('\\\\', '\\\''), $ret['name']) . '\']';
|
||||
}
|
||||
// special handling for elements in native groups
|
||||
if ($this->_currentGroup) {
|
||||
// skip unnamed group items unless radios: no name -> no static access
|
||||
// identification: have the same key string as the parent group
|
||||
if ($this->_currentGroup['keys'] == $sKeys and 'radio' != $ret['type']) {
|
||||
return false;
|
||||
}
|
||||
// reduce string of keys by remove leading group keys
|
||||
if (0 === strpos($sKeys, $this->_currentGroup['keys'])) {
|
||||
$sKeys = substr_replace($sKeys, '', 0, strlen($this->_currentGroup['keys']));
|
||||
}
|
||||
}
|
||||
// element without a name
|
||||
} elseif ($ret['name'] == '') {
|
||||
$sKeys = '[\'element_' . $this->_elementIdx . '\']';
|
||||
// other elements
|
||||
} else {
|
||||
$sKeys = '[\'' . str_replace(array('\\', '\''), array('\\\\', '\\\''), $ret['name']) . '\']';
|
||||
}
|
||||
// for radios: add extra key from value
|
||||
if ('radio' == $ret['type'] and substr($sKeys, -2) != '[]') {
|
||||
$sKeys .= '[\'' . str_replace(array('\\', '\''), array('\\\\', '\\\''), $ret['value']) . '\']';
|
||||
}
|
||||
$this->_elementIdx++;
|
||||
$ret['keys'] = $sKeys;
|
||||
return $ret;
|
||||
} // end func _elementToArray
|
||||
|
||||
/**
|
||||
* Stores an array representation of an element in the form array
|
||||
*
|
||||
* @access private
|
||||
* @param array Array representation of an element
|
||||
* @return void
|
||||
*/
|
||||
function _storeArray($elAry)
|
||||
{
|
||||
if ($elAry) {
|
||||
$sKeys = $elAry['keys'];
|
||||
unset($elAry['keys']);
|
||||
// where should we put this element...
|
||||
if (is_array($this->_currentGroup) && ('group' != $elAry['type'])) {
|
||||
$toEval = '$this->_currentGroup' . $sKeys . ' = $elAry;';
|
||||
} else {
|
||||
$toEval = '$this->_ary' . $sKeys . ' = $elAry;';
|
||||
}
|
||||
eval($toEval);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when an element is required
|
||||
*
|
||||
* This method will add the required tag to the element label and/or the element html
|
||||
* such as defined with the method setRequiredTemplate.
|
||||
*
|
||||
* @param string The element label
|
||||
* @param string The element html rendering
|
||||
* @param boolean The element required
|
||||
* @param string The element error
|
||||
* @see setRequiredTemplate()
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
function _renderRequired(&$label, &$html, &$required, &$error)
|
||||
{
|
||||
$this->_tpl->assign(array(
|
||||
'label' => $label,
|
||||
'html' => $html,
|
||||
'required' => $required,
|
||||
'error' => $error
|
||||
));
|
||||
if (!empty($label) && strpos($this->_required, $this->_tpl->left_delimiter . '$label') !== false) {
|
||||
$label = $this->_tplFetch($this->_required);
|
||||
}
|
||||
if (!empty($html) && strpos($this->_required, $this->_tpl->left_delimiter . '$html') !== false) {
|
||||
$html = $this->_tplFetch($this->_required);
|
||||
}
|
||||
$this->_tpl->clear_assign(array('label', 'html', 'required'));
|
||||
} // end func _renderRequired
|
||||
|
||||
/**
|
||||
* Called when an element has a validation error
|
||||
*
|
||||
* This method will add the error message to the element label or the element html
|
||||
* such as defined with the method setErrorTemplate. If the error placeholder is not found
|
||||
* in the template, the error will be displayed in the form error block.
|
||||
*
|
||||
* @param string The element label
|
||||
* @param string The element html rendering
|
||||
* @param string The element error
|
||||
* @see setErrorTemplate()
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
function _renderError(&$label, &$html, &$error)
|
||||
{
|
||||
$this->_tpl->assign(array('label' => '', 'html' => '', 'error' => $error));
|
||||
$error = $this->_tplFetch($this->_error);
|
||||
$this->_tpl->assign(array('label' => $label, 'html' => $html));
|
||||
|
||||
if (!empty($label) && strpos($this->_error, $this->_tpl->left_delimiter . '$label') !== false) {
|
||||
$label = $this->_tplFetch($this->_error);
|
||||
} elseif (!empty($html) && strpos($this->_error, $this->_tpl->left_delimiter . '$html') !== false) {
|
||||
$html = $this->_tplFetch($this->_error);
|
||||
}
|
||||
$this->_tpl->clear_assign(array('label', 'html', 'error'));
|
||||
} // end func _renderError
|
||||
|
||||
/**
|
||||
* Process an template sourced in a string with Smarty
|
||||
*
|
||||
* Smarty has no core function to render a template given as a string.
|
||||
* So we use the smarty eval plugin function to do this.
|
||||
*
|
||||
* @param string The template source
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
function _tplFetch($tplSource)
|
||||
{
|
||||
if (!function_exists('smarty_function_eval')) {
|
||||
require SMARTY_DIR . '/plugins/function.eval.php';
|
||||
}
|
||||
return smarty_function_eval(array('var' => $tplSource), $this->_tpl);
|
||||
}// end func _tplFetch
|
||||
|
||||
/**
|
||||
* Sets the way required elements are rendered
|
||||
*
|
||||
* You can use {$label} or {$html} placeholders to let the renderer know where
|
||||
* where the element label or the element html are positionned according to the
|
||||
* required tag. They will be replaced accordingly with the right value. You
|
||||
* can use the full smarty syntax here, especially a custom modifier for I18N.
|
||||
* For example:
|
||||
* {if $required}<span style="color: red;">*</span>{/if}{$label|translate}
|
||||
* will put a red star in front of the label if the element is required and
|
||||
* translate the label.
|
||||
*
|
||||
*
|
||||
* @param string The required element template
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setRequiredTemplate($template)
|
||||
{
|
||||
$this->_required = $template;
|
||||
} // end func setRequiredTemplate
|
||||
|
||||
/**
|
||||
* Sets the way elements with validation errors are rendered
|
||||
*
|
||||
* You can use {$label} or {$html} placeholders to let the renderer know where
|
||||
* where the element label or the element html are positionned according to the
|
||||
* error message. They will be replaced accordingly with the right value.
|
||||
* The error message will replace the {$error} placeholder.
|
||||
* For example:
|
||||
* {if $error}<span style="color: red;">{$error}</span>{/if}<br />{$html}
|
||||
* will put the error message in red on top of the element html.
|
||||
*
|
||||
* If you want all error messages to be output in the main error block, use
|
||||
* the {$form.errors} part of the rendered array that collects all raw error
|
||||
* messages.
|
||||
*
|
||||
* If you want to place all error messages manually, do not specify {$html}
|
||||
* nor {$label}.
|
||||
*
|
||||
* Groups can have special layouts. With this kind of groups, you have to
|
||||
* place the formated error message manually. In this case, use {$form.group.error}
|
||||
* where you want the formated error message to appear in the form.
|
||||
*
|
||||
* @param string The element error template
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setErrorTemplate($template)
|
||||
{
|
||||
$this->_error = $template;
|
||||
} // end func setErrorTemplate
|
||||
}
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* A static renderer for HTML_QuickForm, makes an array of form content
|
||||
* useful for a Smarty template
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @author Thomas Schulz <ths@4bconsult.de>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: ArraySmarty.php,v 1.14 2009/04/06 12:02:08 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* A concrete renderer for HTML_QuickForm, makes an array of form contents
|
||||
*/
|
||||
require_once 'HTML/QuickForm/Renderer/Array.php';
|
||||
|
||||
/**
|
||||
* A static renderer for HTML_QuickForm, makes an array of form content
|
||||
* useful for a Smarty template
|
||||
*
|
||||
* Based on old HTML_QuickForm::toArray() code and ITStatic renderer.
|
||||
*
|
||||
* The form array structure is the following:
|
||||
* <pre>
|
||||
* Array (
|
||||
* [frozen] => whether the complete form is frozen'
|
||||
* [javascript] => javascript for client-side validation
|
||||
* [attributes] => attributes for <form> tag
|
||||
* [hidden] => html of all hidden elements
|
||||
* [requirednote] => note about the required elements
|
||||
* [errors] => Array
|
||||
* (
|
||||
* [1st_element_name] => Error for the 1st element
|
||||
* ...
|
||||
* [nth_element_name] => Error for the nth element
|
||||
* )
|
||||
*
|
||||
* [header] => Array
|
||||
* (
|
||||
* [1st_header_name] => Header text for the 1st header
|
||||
* ...
|
||||
* [nth_header_name] => Header text for the nth header
|
||||
* )
|
||||
*
|
||||
* [1st_element_name] => Array for the 1st element
|
||||
* ...
|
||||
* [nth_element_name] => Array for the nth element
|
||||
* </pre>
|
||||
*
|
||||
* where an element array has the form:
|
||||
* <pre>
|
||||
* (
|
||||
* [name] => element name
|
||||
* [value] => element value,
|
||||
* [type] => type of the element
|
||||
* [frozen] => whether element is frozen
|
||||
* [label] => label for the element
|
||||
* [required] => whether element is required
|
||||
* // if element is not a group:
|
||||
* [html] => HTML for the element
|
||||
* // if element is a group:
|
||||
* [separator] => separator for group elements
|
||||
* [1st_gitem_name] => Array for the 1st element in group
|
||||
* ...
|
||||
* [nth_gitem_name] => Array for the nth element in group
|
||||
* )
|
||||
* )
|
||||
* </pre>
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @author Thomas Schulz <ths@4bconsult.de>
|
||||
* @version Release: 3.2.11
|
||||
* @since 3.0
|
||||
*/
|
||||
class HTML_QuickForm_Renderer_ArraySmarty extends HTML_QuickForm_Renderer_Array
|
||||
{
|
||||
/**#@+
|
||||
* @access private
|
||||
*/
|
||||
/**
|
||||
* The Smarty template engine instance
|
||||
* @var object
|
||||
*/
|
||||
var $_tpl = null;
|
||||
|
||||
/**
|
||||
* Current element index
|
||||
* @var integer
|
||||
*/
|
||||
var $_elementIdx = 0;
|
||||
|
||||
/**
|
||||
* The current element index inside a group
|
||||
* @var integer
|
||||
*/
|
||||
var $_groupElementIdx = 0;
|
||||
|
||||
/**
|
||||
* How to handle the required tag for required fields
|
||||
* @var string
|
||||
* @see setRequiredTemplate()
|
||||
*/
|
||||
var $_required = '';
|
||||
|
||||
/**
|
||||
* How to handle error messages in form validation
|
||||
* @var string
|
||||
* @see setErrorTemplate()
|
||||
*/
|
||||
var $_error = '';
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Smarty reference to the Smarty template engine instance
|
||||
* @param bool true: render an array of labels to many labels, $key 0 to 'label' and the oterh to "label_$key"
|
||||
* @param bool true: collect all hidden elements into string; false: process them as usual form elements
|
||||
* @access public
|
||||
*/
|
||||
function HTML_QuickForm_Renderer_ArraySmarty(&$tpl, $staticLabels = false, $collectHidden = true)
|
||||
{
|
||||
$this->HTML_QuickForm_Renderer_Array($collectHidden, $staticLabels);
|
||||
$this->_tpl =& $tpl;
|
||||
} // end constructor
|
||||
|
||||
/**
|
||||
* Called when visiting a header element
|
||||
*
|
||||
* @param HTML_QuickForm_header header element being visited
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function renderHeader(&$header)
|
||||
{
|
||||
if ($name = $header->getName()) {
|
||||
$this->_ary['header'][$name] = $header->toHtml();
|
||||
} else {
|
||||
$this->_ary['header'][$this->_sectionCount] = $header->toHtml();
|
||||
}
|
||||
$this->_currentSection = $this->_sectionCount++;
|
||||
} // end func renderHeader
|
||||
|
||||
/**
|
||||
* Called when visiting a group, before processing any group elements
|
||||
*
|
||||
* @param HTML_QuickForm_group group being visited
|
||||
* @param bool Whether a group is required
|
||||
* @param string An error message associated with a group
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function startGroup(&$group, $required, $error)
|
||||
{
|
||||
parent::startGroup($group, $required, $error);
|
||||
$this->_groupElementIdx = 1;
|
||||
} // end func startGroup
|
||||
|
||||
/**
|
||||
* Creates an array representing an element containing
|
||||
* the key for storing this
|
||||
*
|
||||
* @access private
|
||||
* @param HTML_QuickForm_element form element being visited
|
||||
* @param bool Whether an element is required
|
||||
* @param string Error associated with the element
|
||||
* @return array
|
||||
*/
|
||||
function _elementToArray(&$element, $required, $error)
|
||||
{
|
||||
$ret = parent::_elementToArray($element, $required, $error);
|
||||
|
||||
if ('group' == $ret['type']) {
|
||||
$ret['html'] = $element->toHtml();
|
||||
// we don't need the elements, see the array structure
|
||||
unset($ret['elements']);
|
||||
}
|
||||
if (($required || $error) && !empty($this->_required)){
|
||||
$this->_renderRequired($ret['label'], $ret['html'], $required, $error);
|
||||
}
|
||||
if ($error && !empty($this->_error)) {
|
||||
$this->_renderError($ret['label'], $ret['html'], $error);
|
||||
$ret['error'] = $error;
|
||||
}
|
||||
// create keys for elements grouped by native group or name
|
||||
if (strstr($ret['name'], '[') or $this->_currentGroup) {
|
||||
// Fix for bug #8123: escape backslashes and quotes to prevent errors
|
||||
// in eval(). The code below seems to handle the case where element
|
||||
// name has unbalanced square brackets. Dunno whether we really
|
||||
// need this after the fix for #8123, but I'm wary of making big
|
||||
// changes to this code.
|
||||
preg_match('/([^]]*)\\[([^]]*)\\]/', $ret['name'], $matches);
|
||||
if (isset($matches[1])) {
|
||||
$sKeysSub = substr_replace($ret['name'], '', 0, strlen($matches[1]));
|
||||
$sKeysSub = str_replace(
|
||||
array('\\', '\'', '[' , ']', '[\'\']'),
|
||||
array('\\\\', '\\\'', '[\'', '\']', '[]' ),
|
||||
$sKeysSub
|
||||
);
|
||||
$sKeys = '[\'' . str_replace(array('\\', '\''), array('\\\\', '\\\''), $matches[1]) . '\']' . $sKeysSub;
|
||||
} else {
|
||||
$sKeys = '[\'' . str_replace(array('\\', '\''), array('\\\\', '\\\''), $ret['name']) . '\']';
|
||||
}
|
||||
// special handling for elements in native groups
|
||||
if ($this->_currentGroup) {
|
||||
// skip unnamed group items unless radios: no name -> no static access
|
||||
// identification: have the same key string as the parent group
|
||||
if ($this->_currentGroup['keys'] == $sKeys and 'radio' != $ret['type']) {
|
||||
return false;
|
||||
}
|
||||
// reduce string of keys by remove leading group keys
|
||||
if (0 === strpos($sKeys, $this->_currentGroup['keys'])) {
|
||||
$sKeys = substr_replace($sKeys, '', 0, strlen($this->_currentGroup['keys']));
|
||||
}
|
||||
}
|
||||
// element without a name
|
||||
} elseif ($ret['name'] == '') {
|
||||
$sKeys = '[\'element_' . $this->_elementIdx . '\']';
|
||||
// other elements
|
||||
} else {
|
||||
$sKeys = '[\'' . str_replace(array('\\', '\''), array('\\\\', '\\\''), $ret['name']) . '\']';
|
||||
}
|
||||
// for radios: add extra key from value
|
||||
if ('radio' == $ret['type'] and substr($sKeys, -2) != '[]') {
|
||||
$sKeys .= '[\'' . str_replace(array('\\', '\''), array('\\\\', '\\\''), $ret['value']) . '\']';
|
||||
}
|
||||
$this->_elementIdx++;
|
||||
$ret['keys'] = $sKeys;
|
||||
return $ret;
|
||||
} // end func _elementToArray
|
||||
|
||||
/**
|
||||
* Stores an array representation of an element in the form array
|
||||
*
|
||||
* @access private
|
||||
* @param array Array representation of an element
|
||||
* @return void
|
||||
*/
|
||||
function _storeArray($elAry)
|
||||
{
|
||||
if ($elAry) {
|
||||
$sKeys = $elAry['keys'];
|
||||
unset($elAry['keys']);
|
||||
// where should we put this element...
|
||||
if (is_array($this->_currentGroup) && ('group' != $elAry['type'])) {
|
||||
$toEval = '$this->_currentGroup' . $sKeys . ' = $elAry;';
|
||||
} else {
|
||||
$toEval = '$this->_ary' . $sKeys . ' = $elAry;';
|
||||
}
|
||||
eval($toEval);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when an element is required
|
||||
*
|
||||
* This method will add the required tag to the element label and/or the element html
|
||||
* such as defined with the method setRequiredTemplate.
|
||||
*
|
||||
* @param string The element label
|
||||
* @param string The element html rendering
|
||||
* @param boolean The element required
|
||||
* @param string The element error
|
||||
* @see setRequiredTemplate()
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
function _renderRequired(&$label, &$html, &$required, &$error)
|
||||
{
|
||||
$this->_tpl->assign(array(
|
||||
'label' => $label,
|
||||
'html' => $html,
|
||||
'required' => $required,
|
||||
'error' => $error
|
||||
));
|
||||
if (!empty($label) && strpos($this->_required, $this->_tpl->left_delimiter . '$label') !== false) {
|
||||
$label = $this->_tplFetch($this->_required);
|
||||
}
|
||||
if (!empty($html) && strpos($this->_required, $this->_tpl->left_delimiter . '$html') !== false) {
|
||||
$html = $this->_tplFetch($this->_required);
|
||||
}
|
||||
$this->_tpl->clear_assign(array('label', 'html', 'required'));
|
||||
} // end func _renderRequired
|
||||
|
||||
/**
|
||||
* Called when an element has a validation error
|
||||
*
|
||||
* This method will add the error message to the element label or the element html
|
||||
* such as defined with the method setErrorTemplate. If the error placeholder is not found
|
||||
* in the template, the error will be displayed in the form error block.
|
||||
*
|
||||
* @param string The element label
|
||||
* @param string The element html rendering
|
||||
* @param string The element error
|
||||
* @see setErrorTemplate()
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
function _renderError(&$label, &$html, &$error)
|
||||
{
|
||||
$this->_tpl->assign(array('label' => '', 'html' => '', 'error' => $error));
|
||||
$error = $this->_tplFetch($this->_error);
|
||||
$this->_tpl->assign(array('label' => $label, 'html' => $html));
|
||||
|
||||
if (!empty($label) && strpos($this->_error, $this->_tpl->left_delimiter . '$label') !== false) {
|
||||
$label = $this->_tplFetch($this->_error);
|
||||
} elseif (!empty($html) && strpos($this->_error, $this->_tpl->left_delimiter . '$html') !== false) {
|
||||
$html = $this->_tplFetch($this->_error);
|
||||
}
|
||||
$this->_tpl->clear_assign(array('label', 'html', 'error'));
|
||||
} // end func _renderError
|
||||
|
||||
/**
|
||||
* Process an template sourced in a string with Smarty
|
||||
*
|
||||
* Smarty has no core function to render a template given as a string.
|
||||
* So we use the smarty eval plugin function to do this.
|
||||
*
|
||||
* @param string The template source
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
function _tplFetch($tplSource)
|
||||
{
|
||||
if (!function_exists('smarty_function_eval')) {
|
||||
require SMARTY_DIR . '/plugins/function.eval.php';
|
||||
}
|
||||
return smarty_function_eval(array('var' => $tplSource), $this->_tpl);
|
||||
}// end func _tplFetch
|
||||
|
||||
/**
|
||||
* Sets the way required elements are rendered
|
||||
*
|
||||
* You can use {$label} or {$html} placeholders to let the renderer know where
|
||||
* where the element label or the element html are positionned according to the
|
||||
* required tag. They will be replaced accordingly with the right value. You
|
||||
* can use the full smarty syntax here, especially a custom modifier for I18N.
|
||||
* For example:
|
||||
* {if $required}<span style="color: red;">*</span>{/if}{$label|translate}
|
||||
* will put a red star in front of the label if the element is required and
|
||||
* translate the label.
|
||||
*
|
||||
*
|
||||
* @param string The required element template
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setRequiredTemplate($template)
|
||||
{
|
||||
$this->_required = $template;
|
||||
} // end func setRequiredTemplate
|
||||
|
||||
/**
|
||||
* Sets the way elements with validation errors are rendered
|
||||
*
|
||||
* You can use {$label} or {$html} placeholders to let the renderer know where
|
||||
* where the element label or the element html are positionned according to the
|
||||
* error message. They will be replaced accordingly with the right value.
|
||||
* The error message will replace the {$error} placeholder.
|
||||
* For example:
|
||||
* {if $error}<span style="color: red;">{$error}</span>{/if}<br />{$html}
|
||||
* will put the error message in red on top of the element html.
|
||||
*
|
||||
* If you want all error messages to be output in the main error block, use
|
||||
* the {$form.errors} part of the rendered array that collects all raw error
|
||||
* messages.
|
||||
*
|
||||
* If you want to place all error messages manually, do not specify {$html}
|
||||
* nor {$label}.
|
||||
*
|
||||
* Groups can have special layouts. With this kind of groups, you have to
|
||||
* place the formated error message manually. In this case, use {$form.group.error}
|
||||
* where you want the formated error message to appear in the form.
|
||||
*
|
||||
* @param string The element error template
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setErrorTemplate($template)
|
||||
{
|
||||
$this->_error = $template;
|
||||
} // end func setErrorTemplate
|
||||
}
|
||||
?>
|
|
@ -1,32 +1,43 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4.0 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Alexey Borzov <borz_off@cs.msu.su> |
|
||||
// | Adam Daniel <adaniel1@eesus.jnj.com> |
|
||||
// | Bertrand Mansion <bmansion@mamasam.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id$
|
||||
|
||||
require_once('HTML/QuickForm/Renderer.php');
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* A concrete renderer for HTML_QuickForm,
|
||||
* based on QuickForm 2.x built-in one
|
||||
* A concrete renderer for HTML_QuickForm, based on QuickForm 2.x built-in one
|
||||
*
|
||||
* @access public
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id$
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* An abstract base class for QuickForm renderers
|
||||
*/
|
||||
require_once 'HTML/QuickForm/Renderer.php';
|
||||
|
||||
/**
|
||||
* A concrete renderer for HTML_QuickForm, based on QuickForm 2.x built-in one
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 3.0
|
||||
*/
|
||||
class HTML_QuickForm_Renderer_Default extends HTML_QuickForm_Renderer
|
||||
{
|
||||
|
@ -162,7 +173,7 @@ class HTML_QuickForm_Renderer_Default extends HTML_QuickForm_Renderer
|
|||
/**
|
||||
* Called when visiting a form, before processing any form elements
|
||||
*
|
||||
* @param object An HTML_QuickForm object being visited
|
||||
* @param HTML_QuickForm form object being visited
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -176,7 +187,7 @@ class HTML_QuickForm_Renderer_Default extends HTML_QuickForm_Renderer
|
|||
* Called when visiting a form, after processing all form elements
|
||||
* Adds required note, form attributes, validation javascript and form content.
|
||||
*
|
||||
* @param object An HTML_QuickForm object being visited
|
||||
* @param HTML_QuickForm form object being visited
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -204,7 +215,7 @@ class HTML_QuickForm_Renderer_Default extends HTML_QuickForm_Renderer
|
|||
/**
|
||||
* Called when visiting a header element
|
||||
*
|
||||
* @param object An HTML_QuickForm_header element being visited
|
||||
* @param HTML_QuickForm_header header element being visited
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -245,14 +256,14 @@ class HTML_QuickForm_Renderer_Default extends HTML_QuickForm_Renderer
|
|||
$html = str_replace('<!-- BEGIN required -->', '', $html);
|
||||
$html = str_replace('<!-- END required -->', '', $html);
|
||||
} else {
|
||||
$html = preg_replace("/([ \t\n\r]*)?<!-- BEGIN required -->(\s|\S)*<!-- END required -->([ \t\n\r]*)?/iU", '', $html);
|
||||
$html = preg_replace("/([ \t\n\r]*)?<!-- BEGIN required -->.*<!-- END required -->([ \t\n\r]*)?/isU", '', $html);
|
||||
}
|
||||
if (isset($error)) {
|
||||
$html = str_replace('{error}', $error, $html);
|
||||
$html = str_replace('<!-- BEGIN error -->', '', $html);
|
||||
$html = str_replace('<!-- END error -->', '', $html);
|
||||
} else {
|
||||
$html = preg_replace("/([ \t\n\r]*)?<!-- BEGIN error -->(\s|\S)*<!-- END error -->([ \t\n\r]*)?/iU", '', $html);
|
||||
$html = preg_replace("/([ \t\n\r]*)?<!-- BEGIN error -->.*<!-- END error -->([ \t\n\r]*)?/isU", '', $html);
|
||||
}
|
||||
if (is_array($label)) {
|
||||
foreach($label as $key => $text) {
|
||||
|
@ -263,7 +274,7 @@ class HTML_QuickForm_Renderer_Default extends HTML_QuickForm_Renderer
|
|||
}
|
||||
}
|
||||
if (strpos($html, '{label_')) {
|
||||
$html = preg_replace('/\s*<!-- BEGIN label_(\S+) -->.*<!-- END label_\1 -->\s*/i', '', $html);
|
||||
$html = preg_replace('/\s*<!-- BEGIN label_(\S+) -->.*<!-- END label_\1 -->\s*/is', '', $html);
|
||||
}
|
||||
return $html;
|
||||
} // end func _prepareTemplate
|
||||
|
@ -272,9 +283,9 @@ class HTML_QuickForm_Renderer_Default extends HTML_QuickForm_Renderer
|
|||
* Renders an element Html
|
||||
* Called when visiting an element
|
||||
*
|
||||
* @param object An HTML_QuickForm_element object being visited
|
||||
* @param bool Whether an element is required
|
||||
* @param string An error message associated with an element
|
||||
* @param HTML_QuickForm_element form element being visited
|
||||
* @param bool Whether an element is required
|
||||
* @param string An error message associated with an element
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -290,7 +301,7 @@ class HTML_QuickForm_Renderer_Default extends HTML_QuickForm_Renderer
|
|||
$html = str_replace('<!-- BEGIN required -->', '', $html);
|
||||
$html = str_replace('<!-- END required -->', '', $html);
|
||||
} else {
|
||||
$html = preg_replace("/([ \t\n\r]*)?<!-- BEGIN required -->(\s|\S)*<!-- END required -->([ \t\n\r]*)?/iU", '', $html);
|
||||
$html = preg_replace("/([ \t\n\r]*)?<!-- BEGIN required -->.*<!-- END required -->([ \t\n\r]*)?/isU", '', $html);
|
||||
}
|
||||
$this->_groupElements[] = str_replace('{element}', $element->toHtml(), $html);
|
||||
|
||||
|
@ -303,7 +314,7 @@ class HTML_QuickForm_Renderer_Default extends HTML_QuickForm_Renderer
|
|||
* Renders an hidden element
|
||||
* Called when visiting a hidden element
|
||||
*
|
||||
* @param object An HTML_QuickForm_hidden object being visited
|
||||
* @param HTML_QuickForm_element form element being visited
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -315,7 +326,7 @@ class HTML_QuickForm_Renderer_Default extends HTML_QuickForm_Renderer
|
|||
/**
|
||||
* Called when visiting a raw HTML/text pseudo-element
|
||||
*
|
||||
* @param object An HTML_QuickForm_html element being visited
|
||||
* @param HTML_QuickForm_html element being visited
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -327,7 +338,7 @@ class HTML_QuickForm_Renderer_Default extends HTML_QuickForm_Renderer
|
|||
/**
|
||||
* Called when visiting a group, before processing any group elements
|
||||
*
|
||||
* @param object An HTML_QuickForm_group object being visited
|
||||
* @param HTML_QuickForm_group group being visited
|
||||
* @param bool Whether a group is required
|
||||
* @param string An error message associated with a group
|
||||
* @access public
|
||||
|
@ -346,7 +357,7 @@ class HTML_QuickForm_Renderer_Default extends HTML_QuickForm_Renderer
|
|||
/**
|
||||
* Called when visiting a group, after processing all group elements
|
||||
*
|
||||
* @param object An HTML_QuickForm_group object being visited
|
||||
* @param HTML_QuickForm_group group being visited
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
|
|
@ -1,287 +1,300 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4.0 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Alexey Borzov <borz_off@cs.msu.su> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: ITDynamic.php,v 1.5 2004/10/15 13:04:36 avb Exp $
|
||||
|
||||
require_once 'HTML/QuickForm/Renderer.php';
|
||||
|
||||
/**
|
||||
* A concrete renderer for HTML_QuickForm, using Integrated Templates.
|
||||
*
|
||||
* This is a "dynamic" renderer, which means that concrete form look
|
||||
* is defined at runtime. This also means that you can define
|
||||
* <b>one</b> template file for <b>all</b> your forms. That template
|
||||
* should contain a block for every element 'look' appearing in your
|
||||
* forms and also some special blocks (consult the examples). If a
|
||||
* special block is not set for an element, the renderer falls back to
|
||||
* a default one.
|
||||
*
|
||||
* @author Alexey Borzov <borz_off@cs.msu.su>
|
||||
* @access public
|
||||
*/
|
||||
class HTML_QuickForm_Renderer_ITDynamic extends HTML_QuickForm_Renderer
|
||||
{
|
||||
/**
|
||||
* A template class (HTML_Template_ITX or HTML_Template_Sigma) instance
|
||||
* @var object
|
||||
*/
|
||||
var $_tpl = null;
|
||||
|
||||
/**
|
||||
* The errors that were not shown near concrete fields go here
|
||||
* @var array
|
||||
*/
|
||||
var $_errors = array();
|
||||
|
||||
/**
|
||||
* Show the block with required note?
|
||||
* @var bool
|
||||
*/
|
||||
var $_showRequired = false;
|
||||
|
||||
/**
|
||||
* A separator for group elements
|
||||
* @var mixed
|
||||
*/
|
||||
var $_groupSeparator = null;
|
||||
|
||||
/**
|
||||
* The current element index inside a group
|
||||
* @var integer
|
||||
*/
|
||||
var $_groupElementIdx = 0;
|
||||
|
||||
/**
|
||||
* Blocks to use for different elements
|
||||
* @var array
|
||||
*/
|
||||
var $_elementBlocks = array();
|
||||
|
||||
/**
|
||||
* Block to use for headers
|
||||
* @var string
|
||||
*/
|
||||
var $_headerBlock = null;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param object An HTML_Template_ITX/HTML_Template_Sigma object to use
|
||||
*/
|
||||
function HTML_QuickForm_Renderer_ITDynamic(&$tpl)
|
||||
{
|
||||
$this->HTML_QuickForm_Renderer();
|
||||
$this->_tpl =& $tpl;
|
||||
$this->_tpl->setCurrentBlock('qf_main_loop');
|
||||
}
|
||||
|
||||
|
||||
function finishForm(&$form)
|
||||
{
|
||||
// display errors above form
|
||||
if (!empty($this->_errors) && $this->_tpl->blockExists('qf_error_loop')) {
|
||||
foreach ($this->_errors as $error) {
|
||||
$this->_tpl->setVariable('qf_error', $error);
|
||||
$this->_tpl->parse('qf_error_loop');
|
||||
}
|
||||
}
|
||||
// show required note
|
||||
if ($this->_showRequired) {
|
||||
$this->_tpl->setVariable('qf_required_note', $form->getRequiredNote());
|
||||
}
|
||||
// assign form attributes
|
||||
$this->_tpl->setVariable('qf_attributes', $form->getAttributes(true));
|
||||
// assign javascript validation rules
|
||||
$this->_tpl->setVariable('qf_javascript', $form->getValidationScript());
|
||||
}
|
||||
|
||||
|
||||
function renderHeader(&$header)
|
||||
{
|
||||
$blockName = $this->_matchBlock($header);
|
||||
if ('qf_header' == $blockName && isset($this->_headerBlock)) {
|
||||
$blockName = $this->_headerBlock;
|
||||
}
|
||||
$this->_tpl->setVariable('qf_header', $header->toHtml());
|
||||
$this->_tpl->parse($blockName);
|
||||
$this->_tpl->parse('qf_main_loop');
|
||||
}
|
||||
|
||||
|
||||
function renderElement(&$element, $required, $error)
|
||||
{
|
||||
$blockName = $this->_matchBlock($element);
|
||||
// are we inside a group?
|
||||
if ('qf_main_loop' != $this->_tpl->currentBlock) {
|
||||
if (0 != $this->_groupElementIdx && $this->_tpl->placeholderExists('qf_separator', $blockName)) {
|
||||
if (is_array($this->_groupSeparator)) {
|
||||
$this->_tpl->setVariable('qf_separator', $this->_groupSeparator[($this->_groupElementIdx - 1) % count($this->_groupSeparator)]);
|
||||
} else {
|
||||
$this->_tpl->setVariable('qf_separator', (string)$this->_groupSeparator);
|
||||
}
|
||||
}
|
||||
$this->_groupElementIdx++;
|
||||
|
||||
} elseif(!empty($error)) {
|
||||
// show the error message or keep it for later use
|
||||
if ($this->_tpl->blockExists($blockName . '_error')) {
|
||||
$this->_tpl->setVariable('qf_error', $error);
|
||||
} else {
|
||||
$this->_errors[] = $error;
|
||||
}
|
||||
}
|
||||
// show an '*' near the required element
|
||||
if ($required) {
|
||||
$this->_showRequired = true;
|
||||
if ($this->_tpl->blockExists($blockName . '_required')) {
|
||||
$this->_tpl->touchBlock($blockName . '_required');
|
||||
}
|
||||
}
|
||||
// Prepare multiple labels
|
||||
$labels = $element->getLabel();
|
||||
if (is_array($labels)) {
|
||||
$mainLabel = array_shift($labels);
|
||||
} else {
|
||||
$mainLabel = $labels;
|
||||
}
|
||||
// render the element itself with its main label
|
||||
$this->_tpl->setVariable('qf_element', $element->toHtml());
|
||||
if ($this->_tpl->placeholderExists('qf_label', $blockName)) {
|
||||
$this->_tpl->setVariable('qf_label', $mainLabel);
|
||||
}
|
||||
// render extra labels, if any
|
||||
if (is_array($labels)) {
|
||||
foreach($labels as $key => $label) {
|
||||
$key = is_int($key)? $key + 2: $key;
|
||||
if ($this->_tpl->blockExists($blockName . '_label_' . $key)) {
|
||||
$this->_tpl->setVariable('qf_label_' . $key, $label);
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->_tpl->parse($blockName);
|
||||
$this->_tpl->parseCurrentBlock();
|
||||
}
|
||||
|
||||
|
||||
function renderHidden(&$element)
|
||||
{
|
||||
$this->_tpl->setVariable('qf_hidden', $element->toHtml());
|
||||
$this->_tpl->parse('qf_hidden_loop');
|
||||
}
|
||||
|
||||
|
||||
function startGroup(&$group, $required, $error)
|
||||
{
|
||||
$blockName = $this->_matchBlock($group);
|
||||
$this->_tpl->setCurrentBlock($blockName . '_loop');
|
||||
$this->_groupElementIdx = 0;
|
||||
$this->_groupSeparator = is_null($group->_separator)? ' ': $group->_separator;
|
||||
// show an '*' near the required element
|
||||
if ($required) {
|
||||
$this->_showRequired = true;
|
||||
if ($this->_tpl->blockExists($blockName . '_required')) {
|
||||
$this->_tpl->touchBlock($blockName . '_required');
|
||||
}
|
||||
}
|
||||
// show the error message or keep it for later use
|
||||
if (!empty($error)) {
|
||||
if ($this->_tpl->blockExists($blockName . '_error')) {
|
||||
$this->_tpl->setVariable('qf_error', $error);
|
||||
} else {
|
||||
$this->_errors[] = $error;
|
||||
}
|
||||
}
|
||||
$this->_tpl->setVariable('qf_group_label', $group->getLabel());
|
||||
}
|
||||
|
||||
|
||||
function finishGroup(&$group)
|
||||
{
|
||||
$this->_tpl->parse($this->_matchBlock($group));
|
||||
$this->_tpl->setCurrentBlock('qf_main_loop');
|
||||
$this->_tpl->parseCurrentBlock();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the name of a block to use for element rendering
|
||||
*
|
||||
* If a name was not explicitly set via setElementBlock(), it tries
|
||||
* the names '{prefix}_{element type}' and '{prefix}_{element}', where
|
||||
* prefix is either 'qf' or the name of the current group's block
|
||||
*
|
||||
* @param object An HTML_QuickForm_element object
|
||||
* @access private
|
||||
* @return string block name
|
||||
*/
|
||||
function _matchBlock(&$element)
|
||||
{
|
||||
$name = $element->getName();
|
||||
$type = $element->getType();
|
||||
if (isset($this->_elementBlocks[$name]) && $this->_tpl->blockExists($this->_elementBlocks[$name])) {
|
||||
if (('group' == $type) || ($this->_elementBlocks[$name] . '_loop' != $this->_tpl->currentBlock)) {
|
||||
return $this->_elementBlocks[$name];
|
||||
}
|
||||
}
|
||||
if ('group' != $type && 'qf_main_loop' != $this->_tpl->currentBlock) {
|
||||
$prefix = substr($this->_tpl->currentBlock, 0, -5); // omit '_loop' postfix
|
||||
} else {
|
||||
$prefix = 'qf';
|
||||
}
|
||||
if ($this->_tpl->blockExists($prefix . '_' . $type)) {
|
||||
return $prefix . '_' . $type;
|
||||
} elseif ($this->_tpl->blockExists($prefix . '_' . $name)) {
|
||||
return $prefix . '_' . $name;
|
||||
} else {
|
||||
return $prefix . '_element';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the block to use for element rendering
|
||||
*
|
||||
* @param mixed element name or array ('element name' => 'block name')
|
||||
* @param string block name if $elementName is not an array
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setElementBlock($elementName, $blockName = null)
|
||||
{
|
||||
if (is_array($elementName)) {
|
||||
$this->_elementBlocks = array_merge($this->_elementBlocks, $elementName);
|
||||
} else {
|
||||
$this->_elementBlocks[$elementName] = $blockName;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the name of a block to use for header rendering
|
||||
*
|
||||
* @param string block name
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setHeaderBlock($blockName)
|
||||
{
|
||||
$this->_headerBlock = $blockName;
|
||||
}
|
||||
}
|
||||
?>
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* A concrete renderer for HTML_QuickForm, using Integrated Templates.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: ITDynamic.php,v 1.7 2009/04/04 21:34:04 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* An abstract base class for QuickForm renderers
|
||||
*/
|
||||
require_once 'HTML/QuickForm/Renderer.php';
|
||||
|
||||
/**
|
||||
* A concrete renderer for HTML_QuickForm, using Integrated Templates.
|
||||
*
|
||||
* This is a "dynamic" renderer, which means that concrete form look
|
||||
* is defined at runtime. This also means that you can define
|
||||
* <b>one</b> template file for <b>all</b> your forms. That template
|
||||
* should contain a block for every element 'look' appearing in your
|
||||
* forms and also some special blocks (consult the examples). If a
|
||||
* special block is not set for an element, the renderer falls back to
|
||||
* a default one.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @version Release: 3.2.11
|
||||
* @since 3.0
|
||||
*/
|
||||
class HTML_QuickForm_Renderer_ITDynamic extends HTML_QuickForm_Renderer
|
||||
{
|
||||
/**#@+
|
||||
* @access private
|
||||
*/
|
||||
/**
|
||||
* A template class (HTML_Template_ITX or HTML_Template_Sigma) instance
|
||||
* @var HTML_Template_ITX|HTML_Template_Sigma
|
||||
*/
|
||||
var $_tpl = null;
|
||||
|
||||
/**
|
||||
* The errors that were not shown near concrete fields go here
|
||||
* @var array
|
||||
*/
|
||||
var $_errors = array();
|
||||
|
||||
/**
|
||||
* Show the block with required note?
|
||||
* @var bool
|
||||
*/
|
||||
var $_showRequired = false;
|
||||
|
||||
/**
|
||||
* A separator for group elements
|
||||
* @var mixed
|
||||
*/
|
||||
var $_groupSeparator = null;
|
||||
|
||||
/**
|
||||
* The current element index inside a group
|
||||
* @var integer
|
||||
*/
|
||||
var $_groupElementIdx = 0;
|
||||
|
||||
/**
|
||||
* Blocks to use for different elements
|
||||
* @var array
|
||||
*/
|
||||
var $_elementBlocks = array();
|
||||
|
||||
/**
|
||||
* Block to use for headers
|
||||
* @var string
|
||||
*/
|
||||
var $_headerBlock = null;
|
||||
/**#@-*/
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param HTML_Template_ITX|HTML_Template_Sigma Template object to use
|
||||
*/
|
||||
function HTML_QuickForm_Renderer_ITDynamic(&$tpl)
|
||||
{
|
||||
$this->HTML_QuickForm_Renderer();
|
||||
$this->_tpl =& $tpl;
|
||||
$this->_tpl->setCurrentBlock('qf_main_loop');
|
||||
}
|
||||
|
||||
|
||||
function finishForm(&$form)
|
||||
{
|
||||
// display errors above form
|
||||
if (!empty($this->_errors) && $this->_tpl->blockExists('qf_error_loop')) {
|
||||
foreach ($this->_errors as $error) {
|
||||
$this->_tpl->setVariable('qf_error', $error);
|
||||
$this->_tpl->parse('qf_error_loop');
|
||||
}
|
||||
}
|
||||
// show required note
|
||||
if ($this->_showRequired) {
|
||||
$this->_tpl->setVariable('qf_required_note', $form->getRequiredNote());
|
||||
}
|
||||
// assign form attributes
|
||||
$this->_tpl->setVariable('qf_attributes', $form->getAttributes(true));
|
||||
// assign javascript validation rules
|
||||
$this->_tpl->setVariable('qf_javascript', $form->getValidationScript());
|
||||
}
|
||||
|
||||
|
||||
function renderHeader(&$header)
|
||||
{
|
||||
$blockName = $this->_matchBlock($header);
|
||||
if ('qf_header' == $blockName && isset($this->_headerBlock)) {
|
||||
$blockName = $this->_headerBlock;
|
||||
}
|
||||
$this->_tpl->setVariable('qf_header', $header->toHtml());
|
||||
$this->_tpl->parse($blockName);
|
||||
$this->_tpl->parse('qf_main_loop');
|
||||
}
|
||||
|
||||
|
||||
function renderElement(&$element, $required, $error)
|
||||
{
|
||||
$blockName = $this->_matchBlock($element);
|
||||
// are we inside a group?
|
||||
if ('qf_main_loop' != $this->_tpl->currentBlock) {
|
||||
if (0 != $this->_groupElementIdx && $this->_tpl->placeholderExists('qf_separator', $blockName)) {
|
||||
if (is_array($this->_groupSeparator)) {
|
||||
$this->_tpl->setVariable('qf_separator', $this->_groupSeparator[($this->_groupElementIdx - 1) % count($this->_groupSeparator)]);
|
||||
} else {
|
||||
$this->_tpl->setVariable('qf_separator', (string)$this->_groupSeparator);
|
||||
}
|
||||
}
|
||||
$this->_groupElementIdx++;
|
||||
|
||||
} elseif(!empty($error)) {
|
||||
// show the error message or keep it for later use
|
||||
if ($this->_tpl->blockExists($blockName . '_error')) {
|
||||
$this->_tpl->setVariable('qf_error', $error);
|
||||
} else {
|
||||
$this->_errors[] = $error;
|
||||
}
|
||||
}
|
||||
// show an '*' near the required element
|
||||
if ($required) {
|
||||
$this->_showRequired = true;
|
||||
if ($this->_tpl->blockExists($blockName . '_required')) {
|
||||
$this->_tpl->touchBlock($blockName . '_required');
|
||||
}
|
||||
}
|
||||
// Prepare multiple labels
|
||||
$labels = $element->getLabel();
|
||||
if (is_array($labels)) {
|
||||
$mainLabel = array_shift($labels);
|
||||
} else {
|
||||
$mainLabel = $labels;
|
||||
}
|
||||
// render the element itself with its main label
|
||||
$this->_tpl->setVariable('qf_element', $element->toHtml());
|
||||
if ($this->_tpl->placeholderExists('qf_label', $blockName)) {
|
||||
$this->_tpl->setVariable('qf_label', $mainLabel);
|
||||
}
|
||||
// render extra labels, if any
|
||||
if (is_array($labels)) {
|
||||
foreach($labels as $key => $label) {
|
||||
$key = is_int($key)? $key + 2: $key;
|
||||
if ($this->_tpl->blockExists($blockName . '_label_' . $key)) {
|
||||
$this->_tpl->setVariable('qf_label_' . $key, $label);
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->_tpl->parse($blockName);
|
||||
$this->_tpl->parseCurrentBlock();
|
||||
}
|
||||
|
||||
|
||||
function renderHidden(&$element)
|
||||
{
|
||||
$this->_tpl->setVariable('qf_hidden', $element->toHtml());
|
||||
$this->_tpl->parse('qf_hidden_loop');
|
||||
}
|
||||
|
||||
|
||||
function startGroup(&$group, $required, $error)
|
||||
{
|
||||
$blockName = $this->_matchBlock($group);
|
||||
$this->_tpl->setCurrentBlock($blockName . '_loop');
|
||||
$this->_groupElementIdx = 0;
|
||||
$this->_groupSeparator = is_null($group->_separator)? ' ': $group->_separator;
|
||||
// show an '*' near the required element
|
||||
if ($required) {
|
||||
$this->_showRequired = true;
|
||||
if ($this->_tpl->blockExists($blockName . '_required')) {
|
||||
$this->_tpl->touchBlock($blockName . '_required');
|
||||
}
|
||||
}
|
||||
// show the error message or keep it for later use
|
||||
if (!empty($error)) {
|
||||
if ($this->_tpl->blockExists($blockName . '_error')) {
|
||||
$this->_tpl->setVariable('qf_error', $error);
|
||||
} else {
|
||||
$this->_errors[] = $error;
|
||||
}
|
||||
}
|
||||
$this->_tpl->setVariable('qf_group_label', $group->getLabel());
|
||||
}
|
||||
|
||||
|
||||
function finishGroup(&$group)
|
||||
{
|
||||
$this->_tpl->parse($this->_matchBlock($group));
|
||||
$this->_tpl->setCurrentBlock('qf_main_loop');
|
||||
$this->_tpl->parseCurrentBlock();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the name of a block to use for element rendering
|
||||
*
|
||||
* If a name was not explicitly set via setElementBlock(), it tries
|
||||
* the names '{prefix}_{element type}' and '{prefix}_{element}', where
|
||||
* prefix is either 'qf' or the name of the current group's block
|
||||
*
|
||||
* @param HTML_QuickForm_element form element being rendered
|
||||
* @access private
|
||||
* @return string block name
|
||||
*/
|
||||
function _matchBlock(&$element)
|
||||
{
|
||||
$name = $element->getName();
|
||||
$type = $element->getType();
|
||||
if (isset($this->_elementBlocks[$name]) && $this->_tpl->blockExists($this->_elementBlocks[$name])) {
|
||||
if (('group' == $type) || ($this->_elementBlocks[$name] . '_loop' != $this->_tpl->currentBlock)) {
|
||||
return $this->_elementBlocks[$name];
|
||||
}
|
||||
}
|
||||
if ('group' != $type && 'qf_main_loop' != $this->_tpl->currentBlock) {
|
||||
$prefix = substr($this->_tpl->currentBlock, 0, -5); // omit '_loop' postfix
|
||||
} else {
|
||||
$prefix = 'qf';
|
||||
}
|
||||
if ($this->_tpl->blockExists($prefix . '_' . $type)) {
|
||||
return $prefix . '_' . $type;
|
||||
} elseif ($this->_tpl->blockExists($prefix . '_' . $name)) {
|
||||
return $prefix . '_' . $name;
|
||||
} else {
|
||||
return $prefix . '_element';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the block to use for element rendering
|
||||
*
|
||||
* @param mixed element name or array ('element name' => 'block name')
|
||||
* @param string block name if $elementName is not an array
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setElementBlock($elementName, $blockName = null)
|
||||
{
|
||||
if (is_array($elementName)) {
|
||||
$this->_elementBlocks = array_merge($this->_elementBlocks, $elementName);
|
||||
} else {
|
||||
$this->_elementBlocks[$elementName] = $blockName;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the name of a block to use for header rendering
|
||||
*
|
||||
* @param string block name
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setHeaderBlock($blockName)
|
||||
{
|
||||
$this->_headerBlock = $blockName;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -1,490 +1,504 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4.0 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Bertrand Mansion <bmansion@mamasam.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: ITStatic.php,v 1.7 2004/06/28 14:20:22 avb Exp $
|
||||
|
||||
require_once('HTML/QuickForm/Renderer.php');
|
||||
|
||||
/**
|
||||
* A static renderer for HTML_QuickForm compatible
|
||||
* with HTML_Template_IT and HTML_Template_Sigma.
|
||||
*
|
||||
* As opposed to the dynamic renderer, this renderer needs
|
||||
* every elements and labels in the form to be specified by
|
||||
* placeholders at the position you want them to be displayed.
|
||||
*
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @access public
|
||||
*/
|
||||
class HTML_QuickForm_Renderer_ITStatic extends HTML_QuickForm_Renderer
|
||||
{
|
||||
/**
|
||||
* An HTML_Template_IT or some other API compatible Template instance
|
||||
* @var object
|
||||
*/
|
||||
var $_tpl = null;
|
||||
|
||||
/**
|
||||
* Rendered form name
|
||||
* @var string
|
||||
*/
|
||||
var $_formName = 'form';
|
||||
|
||||
/**
|
||||
* The errors that were not shown near concrete fields go here
|
||||
* @var array
|
||||
*/
|
||||
var $_errors = array();
|
||||
|
||||
/**
|
||||
* Show the block with required note?
|
||||
* @var bool
|
||||
*/
|
||||
var $_showRequired = false;
|
||||
|
||||
/**
|
||||
* Which group are we currently parsing ?
|
||||
* @var string
|
||||
*/
|
||||
var $_inGroup;
|
||||
|
||||
/**
|
||||
* Index of the element in its group
|
||||
* @var int
|
||||
*/
|
||||
var $_elementIndex = 0;
|
||||
|
||||
/**
|
||||
* If elements have been added with the same name
|
||||
* @var array
|
||||
*/
|
||||
var $_duplicateElements = array();
|
||||
|
||||
/**
|
||||
* How to handle the required tag for required fields
|
||||
* @var string
|
||||
*/
|
||||
var $_required = '{label}<font size="1" color="red">*</font>';
|
||||
|
||||
/**
|
||||
* How to handle error messages in form validation
|
||||
* @var string
|
||||
*/
|
||||
var $_error = '<font color="red">{error}</font><br />{html}';
|
||||
|
||||
/**
|
||||
* Collected HTML for hidden elements, if needed
|
||||
* @var string
|
||||
*/
|
||||
var $_hidden = '';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param object An HTML_Template_IT or other compatible Template object to use
|
||||
*/
|
||||
function HTML_QuickForm_Renderer_ITStatic(&$tpl)
|
||||
{
|
||||
$this->HTML_QuickForm_Renderer();
|
||||
$this->_tpl =& $tpl;
|
||||
} // end constructor
|
||||
|
||||
/**
|
||||
* Called when visiting a form, before processing any form elements
|
||||
*
|
||||
* @param object An HTML_QuickForm object being visited
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function startForm(&$form)
|
||||
{
|
||||
$this->_formName = $form->getAttribute('id');
|
||||
|
||||
if (count($form->_duplicateIndex) > 0) {
|
||||
// Take care of duplicate elements
|
||||
foreach ($form->_duplicateIndex as $elementName => $indexes) {
|
||||
$this->_duplicateElements[$elementName] = 0;
|
||||
}
|
||||
}
|
||||
} // end func startForm
|
||||
|
||||
/**
|
||||
* Called when visiting a form, after processing all form elements
|
||||
*
|
||||
* @param object An HTML_QuickForm object being visited
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function finishForm(&$form)
|
||||
{
|
||||
// display errors above form
|
||||
if (!empty($this->_errors) && $this->_tpl->blockExists($this->_formName.'_error_loop')) {
|
||||
foreach ($this->_errors as $error) {
|
||||
$this->_tpl->setVariable($this->_formName.'_error', $error);
|
||||
$this->_tpl->parse($this->_formName.'_error_loop');
|
||||
}
|
||||
}
|
||||
// show required note
|
||||
if ($this->_showRequired) {
|
||||
$this->_tpl->setVariable($this->_formName.'_required_note', $form->getRequiredNote());
|
||||
}
|
||||
// add hidden elements, if collected
|
||||
if (!empty($this->_hidden)) {
|
||||
$this->_tpl->setVariable($this->_formName . '_hidden', $this->_hidden);
|
||||
}
|
||||
// assign form attributes
|
||||
$this->_tpl->setVariable($this->_formName.'_attributes', $form->getAttributes(true));
|
||||
// assign javascript validation rules
|
||||
$this->_tpl->setVariable($this->_formName.'_javascript', $form->getValidationScript());
|
||||
} // end func finishForm
|
||||
|
||||
/**
|
||||
* Called when visiting a header element
|
||||
*
|
||||
* @param object An HTML_QuickForm_header element being visited
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function renderHeader(&$header)
|
||||
{
|
||||
$name = $header->getName();
|
||||
$varName = $this->_formName.'_header';
|
||||
|
||||
// Find placeHolder
|
||||
if (!empty($name) && $this->_tpl->placeHolderExists($this->_formName.'_header_'.$name)) {
|
||||
$varName = $this->_formName.'_header_'.$name;
|
||||
}
|
||||
$this->_tpl->setVariable($varName, $header->toHtml());
|
||||
} // end func renderHeader
|
||||
|
||||
/**
|
||||
* Called when visiting an element
|
||||
*
|
||||
* @param object An HTML_QuickForm_element object being visited
|
||||
* @param bool Whether an element is required
|
||||
* @param string An error message associated with an element
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function renderElement(&$element, $required, $error)
|
||||
{
|
||||
$name = $element->getName();
|
||||
|
||||
// are we inside a group?
|
||||
if (!empty($this->_inGroup)) {
|
||||
$varName = $this->_formName.'_'.str_replace(array('[', ']'), '_', $name);
|
||||
if (substr($varName, -2) == '__') {
|
||||
// element name is of type : group[]
|
||||
$varName = $this->_inGroup.'_'.$this->_elementIndex.'_';
|
||||
$this->_elementIndex++;
|
||||
}
|
||||
if ($varName != $this->_inGroup) {
|
||||
$varName .= '_' == substr($varName, -1)? '': '_';
|
||||
// element name is of type : group[name]
|
||||
$label = $element->getLabel();
|
||||
$html = $element->toHtml();
|
||||
|
||||
if ($required && !$element->isFrozen()) {
|
||||
$this->_renderRequired($label, $html);
|
||||
$this->_showRequired = true;
|
||||
}
|
||||
if (!empty($label)) {
|
||||
if (is_array($label)) {
|
||||
foreach ($label as $key => $value) {
|
||||
$this->_tpl->setVariable($varName.'label_'.$key, $value);
|
||||
}
|
||||
} else {
|
||||
$this->_tpl->setVariable($varName.'label', $label);
|
||||
}
|
||||
}
|
||||
$this->_tpl->setVariable($varName.'html', $html);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
$name = str_replace(array('[', ']'), array('_', ''), $name);
|
||||
|
||||
if (isset($this->_duplicateElements[$name])) {
|
||||
// Element is a duplicate
|
||||
$varName = $this->_formName.'_'.$name.'_'.$this->_duplicateElements[$name];
|
||||
$this->_duplicateElements[$name]++;
|
||||
} else {
|
||||
$varName = $this->_formName.'_'.$name;
|
||||
}
|
||||
|
||||
$label = $element->getLabel();
|
||||
$html = $element->toHtml();
|
||||
|
||||
if ($required) {
|
||||
$this->_showRequired = true;
|
||||
$this->_renderRequired($label, $html);
|
||||
}
|
||||
if (!empty($error)) {
|
||||
$this->_renderError($label, $html, $error);
|
||||
}
|
||||
if (is_array($label)) {
|
||||
foreach ($label as $key => $value) {
|
||||
$this->_tpl->setVariable($varName.'_label_'.$key, $value);
|
||||
}
|
||||
} else {
|
||||
$this->_tpl->setVariable($varName.'_label', $label);
|
||||
}
|
||||
$this->_tpl->setVariable($varName.'_html', $html);
|
||||
}
|
||||
} // end func renderElement
|
||||
|
||||
/**
|
||||
* Called when visiting a hidden element
|
||||
*
|
||||
* @param object An HTML_QuickForm_hidden object being visited
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function renderHidden(&$element)
|
||||
{
|
||||
if ($this->_tpl->placeholderExists($this->_formName . '_hidden')) {
|
||||
$this->_hidden .= $element->toHtml();
|
||||
} else {
|
||||
$name = $element->getName();
|
||||
$name = str_replace(array('[', ']'), array('_', ''), $name);
|
||||
$this->_tpl->setVariable($this->_formName.'_'.$name.'_html', $element->toHtml());
|
||||
}
|
||||
} // end func renderHidden
|
||||
|
||||
/**
|
||||
* Called when visiting a group, before processing any group elements
|
||||
*
|
||||
* @param object An HTML_QuickForm_group object being visited
|
||||
* @param bool Whether a group is required
|
||||
* @param string An error message associated with a group
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function startGroup(&$group, $required, $error)
|
||||
{
|
||||
$name = $group->getName();
|
||||
$varName = $this->_formName.'_'.$name;
|
||||
|
||||
$this->_elementIndex = 0;
|
||||
|
||||
$html = $this->_tpl->placeholderExists($varName.'_html') ? $group->toHtml() : '';
|
||||
$label = $group->getLabel();
|
||||
|
||||
if ($required) {
|
||||
$this->_renderRequired($label, $html);
|
||||
}
|
||||
if (!empty($error)) {
|
||||
$this->_renderError($label, $html, $error);
|
||||
}
|
||||
if (!empty($html)) {
|
||||
$this->_tpl->setVariable($varName.'_html', $html);
|
||||
} else {
|
||||
// Uses error blocks to set the special groups layout error
|
||||
// <!-- BEGIN form_group_error -->{form_group_error}<!-- END form_group_error -->
|
||||
if (!empty($error)) {
|
||||
if ($this->_tpl->placeholderExists($varName.'_error')) {
|
||||
if ($this->_tpl->blockExists($this->_formName . '_error_block')) {
|
||||
$this->_tpl->setVariable($this->_formName . '_error', $error);
|
||||
$error = $this->_getTplBlock($this->_formName . '_error_block');
|
||||
} elseif (strpos($this->_error, '{html}') !== false || strpos($this->_error, '{label}') !== false) {
|
||||
$error = str_replace('{error}', $error, $this->_error);
|
||||
}
|
||||
}
|
||||
$this->_tpl->setVariable($varName . '_error', $error);
|
||||
array_pop($this->_errors);
|
||||
}
|
||||
}
|
||||
if (is_array($label)) {
|
||||
foreach ($label as $key => $value) {
|
||||
$this->_tpl->setVariable($varName.'_label_'.$key, $value);
|
||||
}
|
||||
} else {
|
||||
$this->_tpl->setVariable($varName.'_label', $label);
|
||||
}
|
||||
$this->_inGroup = $varName;
|
||||
} // end func startGroup
|
||||
|
||||
/**
|
||||
* Called when visiting a group, after processing all group elements
|
||||
*
|
||||
* @param object An HTML_QuickForm_group object being visited
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function finishGroup(&$group)
|
||||
{
|
||||
$this->_inGroup = '';
|
||||
} // end func finishGroup
|
||||
|
||||
/**
|
||||
* Sets the way required elements are rendered
|
||||
*
|
||||
* You can use {label} or {html} placeholders to let the renderer know where
|
||||
* where the element label or the element html are positionned according to the
|
||||
* required tag. They will be replaced accordingly with the right value.
|
||||
* For example:
|
||||
* <font color="red">*</font>{label}
|
||||
* will put a red star in front of the label if the element is required.
|
||||
*
|
||||
* @param string The required element template
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setRequiredTemplate($template)
|
||||
{
|
||||
$this->_required = $template;
|
||||
} // end func setRequiredTemplate
|
||||
|
||||
/**
|
||||
* Sets the way elements with validation errors are rendered
|
||||
*
|
||||
* You can use {label} or {html} placeholders to let the renderer know where
|
||||
* where the element label or the element html are positionned according to the
|
||||
* error message. They will be replaced accordingly with the right value.
|
||||
* The error message will replace the {error} place holder.
|
||||
* For example:
|
||||
* <font color="red">{error}</font><br />{html}
|
||||
* will put the error message in red on top of the element html.
|
||||
*
|
||||
* If you want all error messages to be output in the main error block, do not specify
|
||||
* {html} nor {label}.
|
||||
*
|
||||
* Groups can have special layouts. With this kind of groups, the renderer will need
|
||||
* to know where to place the error message. In this case, use error blocks like:
|
||||
* <!-- BEGIN form_group_error -->{form_group_error}<!-- END form_group_error -->
|
||||
* where you want the error message to appear in the form.
|
||||
*
|
||||
* @param string The element error template
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setErrorTemplate($template)
|
||||
{
|
||||
$this->_error = $template;
|
||||
} // end func setErrorTemplate
|
||||
|
||||
/**
|
||||
* Called when an element is required
|
||||
*
|
||||
* This method will add the required tag to the element label and/or the element html
|
||||
* such as defined with the method setRequiredTemplate
|
||||
*
|
||||
* @param string The element label
|
||||
* @param string The element html rendering
|
||||
* @see setRequiredTemplate()
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
function _renderRequired(&$label, &$html)
|
||||
{
|
||||
if ($this->_tpl->blockExists($tplBlock = $this->_formName . '_required_block')) {
|
||||
if (!empty($label) && $this->_tpl->placeholderExists($this->_formName . '_label', $tplBlock)) {
|
||||
$this->_tpl->setVariable($this->_formName . '_label', is_array($label)? $label[0]: $label);
|
||||
if (is_array($label)) {
|
||||
$label[0] = $this->_getTplBlock($tplBlock);
|
||||
} else {
|
||||
$label = $this->_getTplBlock($tplBlock);
|
||||
}
|
||||
}
|
||||
if (!empty($html) && $this->_tpl->placeholderExists($this->_formName . '_html', $tplBlock)) {
|
||||
$this->_tpl->setVariable($this->_formName . '_html', $html);
|
||||
$html = $this->_getTplBlock($tplBlock);
|
||||
}
|
||||
} else {
|
||||
if (!empty($label) && strpos($this->_required, '{label}') !== false) {
|
||||
if (is_array($label)) {
|
||||
$label[0] = str_replace('{label}', $label[0], $this->_required);
|
||||
} else {
|
||||
$label = str_replace('{label}', $label, $this->_required);
|
||||
}
|
||||
}
|
||||
if (!empty($html) && strpos($this->_required, '{html}') !== false) {
|
||||
$html = str_replace('{html}', $html, $this->_required);
|
||||
}
|
||||
}
|
||||
} // end func _renderRequired
|
||||
|
||||
/**
|
||||
* Called when an element has a validation error
|
||||
*
|
||||
* This method will add the error message to the element label or the element html
|
||||
* such as defined with the method setErrorTemplate. If the error placeholder is not found
|
||||
* in the template, the error will be displayed in the form error block.
|
||||
*
|
||||
* @param string The element label
|
||||
* @param string The element html rendering
|
||||
* @param string The element error
|
||||
* @see setErrorTemplate()
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
function _renderError(&$label, &$html, $error)
|
||||
{
|
||||
if ($this->_tpl->blockExists($tplBlock = $this->_formName . '_error_block')) {
|
||||
$this->_tpl->setVariable($this->_formName . '_error', $error);
|
||||
if (!empty($label) && $this->_tpl->placeholderExists($this->_formName . '_label', $tplBlock)) {
|
||||
$this->_tpl->setVariable($this->_formName . '_label', is_array($label)? $label[0]: $label);
|
||||
if (is_array($label)) {
|
||||
$label[0] = $this->_getTplBlock($tplBlock);
|
||||
} else {
|
||||
$label = $this->_getTplBlock($tplBlock);
|
||||
}
|
||||
} elseif (!empty($html) && $this->_tpl->placeholderExists($this->_formName . '_html', $tplBlock)) {
|
||||
$this->_tpl->setVariable($this->_formName . '_html', $html);
|
||||
$html = $this->_getTplBlock($tplBlock);
|
||||
}
|
||||
// clean up after ourselves
|
||||
$this->_tpl->setVariable($this->_formName . '_error', null);
|
||||
} elseif (!empty($label) && strpos($this->_error, '{label}') !== false) {
|
||||
if (is_array($label)) {
|
||||
$label[0] = str_replace(array('{label}', '{error}'), array($label[0], $error), $this->_error);
|
||||
} else {
|
||||
$label = str_replace(array('{label}', '{error}'), array($label, $error), $this->_error);
|
||||
}
|
||||
} elseif (!empty($html) && strpos($this->_error, '{html}') !== false) {
|
||||
$html = str_replace(array('{html}', '{error}'), array($html, $error), $this->_error);
|
||||
} else {
|
||||
$this->_errors[] = $error;
|
||||
}
|
||||
}// end func _renderError
|
||||
|
||||
|
||||
/**
|
||||
* Returns the block's contents
|
||||
*
|
||||
* The method is needed because ITX and Sigma implement clearing
|
||||
* the block contents on get() a bit differently
|
||||
*
|
||||
* @param string Block name
|
||||
* @return string Block contents
|
||||
*/
|
||||
function _getTplBlock($block)
|
||||
{
|
||||
$this->_tpl->parse($block);
|
||||
if (is_a($this->_tpl, 'html_template_sigma')) {
|
||||
$ret = $this->_tpl->get($block, true);
|
||||
} else {
|
||||
$oldClear = $this->_tpl->clearCache;
|
||||
$this->_tpl->clearCache = true;
|
||||
$ret = $this->_tpl->get($block);
|
||||
$this->_tpl->clearCache = $oldClear;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
} // end class HTML_QuickForm_Renderer_ITStatic
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* A static renderer for HTML_QuickForm compatible
|
||||
* with HTML_Template_IT and HTML_Template_Sigma.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: ITStatic.php,v 1.9 2009/04/04 21:34:04 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* An abstract base class for QuickForm renderers
|
||||
*/
|
||||
require_once 'HTML/QuickForm/Renderer.php';
|
||||
|
||||
/**
|
||||
* A static renderer for HTML_QuickForm compatible
|
||||
* with HTML_Template_IT and HTML_Template_Sigma.
|
||||
*
|
||||
* As opposed to the dynamic renderer, this renderer needs
|
||||
* every elements and labels in the form to be specified by
|
||||
* placeholders at the position you want them to be displayed.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 3.0
|
||||
*/
|
||||
class HTML_QuickForm_Renderer_ITStatic extends HTML_QuickForm_Renderer
|
||||
{
|
||||
/**#@+
|
||||
* @access private
|
||||
*/
|
||||
/**
|
||||
* An HTML_Template_IT or some other API compatible Template instance
|
||||
* @var object
|
||||
*/
|
||||
var $_tpl = null;
|
||||
|
||||
/**
|
||||
* Rendered form name
|
||||
* @var string
|
||||
*/
|
||||
var $_formName = 'form';
|
||||
|
||||
/**
|
||||
* The errors that were not shown near concrete fields go here
|
||||
* @var array
|
||||
*/
|
||||
var $_errors = array();
|
||||
|
||||
/**
|
||||
* Show the block with required note?
|
||||
* @var bool
|
||||
*/
|
||||
var $_showRequired = false;
|
||||
|
||||
/**
|
||||
* Which group are we currently parsing ?
|
||||
* @var string
|
||||
*/
|
||||
var $_inGroup;
|
||||
|
||||
/**
|
||||
* Index of the element in its group
|
||||
* @var int
|
||||
*/
|
||||
var $_elementIndex = 0;
|
||||
|
||||
/**
|
||||
* If elements have been added with the same name
|
||||
* @var array
|
||||
*/
|
||||
var $_duplicateElements = array();
|
||||
|
||||
/**
|
||||
* How to handle the required tag for required fields
|
||||
* @var string
|
||||
*/
|
||||
var $_required = '{label}<font size="1" color="red">*</font>';
|
||||
|
||||
/**
|
||||
* How to handle error messages in form validation
|
||||
* @var string
|
||||
*/
|
||||
var $_error = '<font color="red">{error}</font><br />{html}';
|
||||
|
||||
/**
|
||||
* Collected HTML for hidden elements, if needed
|
||||
* @var string
|
||||
*/
|
||||
var $_hidden = '';
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param HTML_Template_IT|HTML_Template_Sigma Template object to use
|
||||
*/
|
||||
function HTML_QuickForm_Renderer_ITStatic(&$tpl)
|
||||
{
|
||||
$this->HTML_QuickForm_Renderer();
|
||||
$this->_tpl =& $tpl;
|
||||
} // end constructor
|
||||
|
||||
/**
|
||||
* Called when visiting a form, before processing any form elements
|
||||
*
|
||||
* @param HTML_QuickForm form object being visited
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function startForm(&$form)
|
||||
{
|
||||
$this->_formName = $form->getAttribute('id');
|
||||
|
||||
if (count($form->_duplicateIndex) > 0) {
|
||||
// Take care of duplicate elements
|
||||
foreach ($form->_duplicateIndex as $elementName => $indexes) {
|
||||
$this->_duplicateElements[$elementName] = 0;
|
||||
}
|
||||
}
|
||||
} // end func startForm
|
||||
|
||||
/**
|
||||
* Called when visiting a form, after processing all form elements
|
||||
*
|
||||
* @param HTML_QuickForm form object being visited
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function finishForm(&$form)
|
||||
{
|
||||
// display errors above form
|
||||
if (!empty($this->_errors) && $this->_tpl->blockExists($this->_formName.'_error_loop')) {
|
||||
foreach ($this->_errors as $error) {
|
||||
$this->_tpl->setVariable($this->_formName.'_error', $error);
|
||||
$this->_tpl->parse($this->_formName.'_error_loop');
|
||||
}
|
||||
}
|
||||
// show required note
|
||||
if ($this->_showRequired) {
|
||||
$this->_tpl->setVariable($this->_formName.'_required_note', $form->getRequiredNote());
|
||||
}
|
||||
// add hidden elements, if collected
|
||||
if (!empty($this->_hidden)) {
|
||||
$this->_tpl->setVariable($this->_formName . '_hidden', $this->_hidden);
|
||||
}
|
||||
// assign form attributes
|
||||
$this->_tpl->setVariable($this->_formName.'_attributes', $form->getAttributes(true));
|
||||
// assign javascript validation rules
|
||||
$this->_tpl->setVariable($this->_formName.'_javascript', $form->getValidationScript());
|
||||
} // end func finishForm
|
||||
|
||||
/**
|
||||
* Called when visiting a header element
|
||||
*
|
||||
* @param HTML_QuickForm_header header element being visited
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function renderHeader(&$header)
|
||||
{
|
||||
$name = $header->getName();
|
||||
$varName = $this->_formName.'_header';
|
||||
|
||||
// Find placeHolder
|
||||
if (!empty($name) && $this->_tpl->placeHolderExists($this->_formName.'_header_'.$name)) {
|
||||
$varName = $this->_formName.'_header_'.$name;
|
||||
}
|
||||
$this->_tpl->setVariable($varName, $header->toHtml());
|
||||
} // end func renderHeader
|
||||
|
||||
/**
|
||||
* Called when visiting an element
|
||||
*
|
||||
* @param HTML_QuickForm_element form element being visited
|
||||
* @param bool Whether an element is required
|
||||
* @param string An error message associated with an element
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function renderElement(&$element, $required, $error)
|
||||
{
|
||||
$name = $element->getName();
|
||||
|
||||
// are we inside a group?
|
||||
if (!empty($this->_inGroup)) {
|
||||
$varName = $this->_formName.'_'.str_replace(array('[', ']'), '_', $name);
|
||||
if (substr($varName, -2) == '__') {
|
||||
// element name is of type : group[]
|
||||
$varName = $this->_inGroup.'_'.$this->_elementIndex.'_';
|
||||
$this->_elementIndex++;
|
||||
}
|
||||
if ($varName != $this->_inGroup) {
|
||||
$varName .= '_' == substr($varName, -1)? '': '_';
|
||||
// element name is of type : group[name]
|
||||
$label = $element->getLabel();
|
||||
$html = $element->toHtml();
|
||||
|
||||
if ($required && !$element->isFrozen()) {
|
||||
$this->_renderRequired($label, $html);
|
||||
$this->_showRequired = true;
|
||||
}
|
||||
if (!empty($label)) {
|
||||
if (is_array($label)) {
|
||||
foreach ($label as $key => $value) {
|
||||
$this->_tpl->setVariable($varName.'label_'.$key, $value);
|
||||
}
|
||||
} else {
|
||||
$this->_tpl->setVariable($varName.'label', $label);
|
||||
}
|
||||
}
|
||||
$this->_tpl->setVariable($varName.'html', $html);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
$name = str_replace(array('[', ']'), array('_', ''), $name);
|
||||
|
||||
if (isset($this->_duplicateElements[$name])) {
|
||||
// Element is a duplicate
|
||||
$varName = $this->_formName.'_'.$name.'_'.$this->_duplicateElements[$name];
|
||||
$this->_duplicateElements[$name]++;
|
||||
} else {
|
||||
$varName = $this->_formName.'_'.$name;
|
||||
}
|
||||
|
||||
$label = $element->getLabel();
|
||||
$html = $element->toHtml();
|
||||
|
||||
if ($required) {
|
||||
$this->_showRequired = true;
|
||||
$this->_renderRequired($label, $html);
|
||||
}
|
||||
if (!empty($error)) {
|
||||
$this->_renderError($label, $html, $error);
|
||||
}
|
||||
if (is_array($label)) {
|
||||
foreach ($label as $key => $value) {
|
||||
$this->_tpl->setVariable($varName.'_label_'.$key, $value);
|
||||
}
|
||||
} else {
|
||||
$this->_tpl->setVariable($varName.'_label', $label);
|
||||
}
|
||||
$this->_tpl->setVariable($varName.'_html', $html);
|
||||
}
|
||||
} // end func renderElement
|
||||
|
||||
/**
|
||||
* Called when visiting a hidden element
|
||||
*
|
||||
* @param HTML_QuickForm_element hidden element being visited
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function renderHidden(&$element)
|
||||
{
|
||||
if ($this->_tpl->placeholderExists($this->_formName . '_hidden')) {
|
||||
$this->_hidden .= $element->toHtml();
|
||||
} else {
|
||||
$name = $element->getName();
|
||||
$name = str_replace(array('[', ']'), array('_', ''), $name);
|
||||
$this->_tpl->setVariable($this->_formName.'_'.$name.'_html', $element->toHtml());
|
||||
}
|
||||
} // end func renderHidden
|
||||
|
||||
/**
|
||||
* Called when visiting a group, before processing any group elements
|
||||
*
|
||||
* @param HTML_QuickForm_group group being visited
|
||||
* @param bool Whether a group is required
|
||||
* @param string An error message associated with a group
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function startGroup(&$group, $required, $error)
|
||||
{
|
||||
$name = $group->getName();
|
||||
$varName = $this->_formName.'_'.$name;
|
||||
|
||||
$this->_elementIndex = 0;
|
||||
|
||||
$html = $this->_tpl->placeholderExists($varName.'_html') ? $group->toHtml() : '';
|
||||
$label = $group->getLabel();
|
||||
|
||||
if ($required) {
|
||||
$this->_renderRequired($label, $html);
|
||||
}
|
||||
if (!empty($error)) {
|
||||
$this->_renderError($label, $html, $error);
|
||||
}
|
||||
if (!empty($html)) {
|
||||
$this->_tpl->setVariable($varName.'_html', $html);
|
||||
} else {
|
||||
// Uses error blocks to set the special groups layout error
|
||||
// <!-- BEGIN form_group_error -->{form_group_error}<!-- END form_group_error -->
|
||||
if (!empty($error)) {
|
||||
if ($this->_tpl->placeholderExists($varName.'_error')) {
|
||||
if ($this->_tpl->blockExists($this->_formName . '_error_block')) {
|
||||
$this->_tpl->setVariable($this->_formName . '_error', $error);
|
||||
$error = $this->_getTplBlock($this->_formName . '_error_block');
|
||||
} elseif (strpos($this->_error, '{html}') !== false || strpos($this->_error, '{label}') !== false) {
|
||||
$error = str_replace('{error}', $error, $this->_error);
|
||||
}
|
||||
}
|
||||
$this->_tpl->setVariable($varName . '_error', $error);
|
||||
array_pop($this->_errors);
|
||||
}
|
||||
}
|
||||
if (is_array($label)) {
|
||||
foreach ($label as $key => $value) {
|
||||
$this->_tpl->setVariable($varName.'_label_'.$key, $value);
|
||||
}
|
||||
} else {
|
||||
$this->_tpl->setVariable($varName.'_label', $label);
|
||||
}
|
||||
$this->_inGroup = $varName;
|
||||
} // end func startGroup
|
||||
|
||||
/**
|
||||
* Called when visiting a group, after processing all group elements
|
||||
*
|
||||
* @param HTML_QuickForm_group group being visited
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function finishGroup(&$group)
|
||||
{
|
||||
$this->_inGroup = '';
|
||||
} // end func finishGroup
|
||||
|
||||
/**
|
||||
* Sets the way required elements are rendered
|
||||
*
|
||||
* You can use {label} or {html} placeholders to let the renderer know where
|
||||
* where the element label or the element html are positionned according to the
|
||||
* required tag. They will be replaced accordingly with the right value.
|
||||
* For example:
|
||||
* <font color="red">*</font>{label}
|
||||
* will put a red star in front of the label if the element is required.
|
||||
*
|
||||
* @param string The required element template
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setRequiredTemplate($template)
|
||||
{
|
||||
$this->_required = $template;
|
||||
} // end func setRequiredTemplate
|
||||
|
||||
/**
|
||||
* Sets the way elements with validation errors are rendered
|
||||
*
|
||||
* You can use {label} or {html} placeholders to let the renderer know where
|
||||
* where the element label or the element html are positionned according to the
|
||||
* error message. They will be replaced accordingly with the right value.
|
||||
* The error message will replace the {error} place holder.
|
||||
* For example:
|
||||
* <font color="red">{error}</font><br />{html}
|
||||
* will put the error message in red on top of the element html.
|
||||
*
|
||||
* If you want all error messages to be output in the main error block, do not specify
|
||||
* {html} nor {label}.
|
||||
*
|
||||
* Groups can have special layouts. With this kind of groups, the renderer will need
|
||||
* to know where to place the error message. In this case, use error blocks like:
|
||||
* <!-- BEGIN form_group_error -->{form_group_error}<!-- END form_group_error -->
|
||||
* where you want the error message to appear in the form.
|
||||
*
|
||||
* @param string The element error template
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setErrorTemplate($template)
|
||||
{
|
||||
$this->_error = $template;
|
||||
} // end func setErrorTemplate
|
||||
|
||||
/**
|
||||
* Called when an element is required
|
||||
*
|
||||
* This method will add the required tag to the element label and/or the element html
|
||||
* such as defined with the method setRequiredTemplate
|
||||
*
|
||||
* @param string The element label
|
||||
* @param string The element html rendering
|
||||
* @see setRequiredTemplate()
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
function _renderRequired(&$label, &$html)
|
||||
{
|
||||
if ($this->_tpl->blockExists($tplBlock = $this->_formName . '_required_block')) {
|
||||
if (!empty($label) && $this->_tpl->placeholderExists($this->_formName . '_label', $tplBlock)) {
|
||||
$this->_tpl->setVariable($this->_formName . '_label', is_array($label)? $label[0]: $label);
|
||||
if (is_array($label)) {
|
||||
$label[0] = $this->_getTplBlock($tplBlock);
|
||||
} else {
|
||||
$label = $this->_getTplBlock($tplBlock);
|
||||
}
|
||||
}
|
||||
if (!empty($html) && $this->_tpl->placeholderExists($this->_formName . '_html', $tplBlock)) {
|
||||
$this->_tpl->setVariable($this->_formName . '_html', $html);
|
||||
$html = $this->_getTplBlock($tplBlock);
|
||||
}
|
||||
} else {
|
||||
if (!empty($label) && strpos($this->_required, '{label}') !== false) {
|
||||
if (is_array($label)) {
|
||||
$label[0] = str_replace('{label}', $label[0], $this->_required);
|
||||
} else {
|
||||
$label = str_replace('{label}', $label, $this->_required);
|
||||
}
|
||||
}
|
||||
if (!empty($html) && strpos($this->_required, '{html}') !== false) {
|
||||
$html = str_replace('{html}', $html, $this->_required);
|
||||
}
|
||||
}
|
||||
} // end func _renderRequired
|
||||
|
||||
/**
|
||||
* Called when an element has a validation error
|
||||
*
|
||||
* This method will add the error message to the element label or the element html
|
||||
* such as defined with the method setErrorTemplate. If the error placeholder is not found
|
||||
* in the template, the error will be displayed in the form error block.
|
||||
*
|
||||
* @param string The element label
|
||||
* @param string The element html rendering
|
||||
* @param string The element error
|
||||
* @see setErrorTemplate()
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
function _renderError(&$label, &$html, $error)
|
||||
{
|
||||
if ($this->_tpl->blockExists($tplBlock = $this->_formName . '_error_block')) {
|
||||
$this->_tpl->setVariable($this->_formName . '_error', $error);
|
||||
if (!empty($label) && $this->_tpl->placeholderExists($this->_formName . '_label', $tplBlock)) {
|
||||
$this->_tpl->setVariable($this->_formName . '_label', is_array($label)? $label[0]: $label);
|
||||
if (is_array($label)) {
|
||||
$label[0] = $this->_getTplBlock($tplBlock);
|
||||
} else {
|
||||
$label = $this->_getTplBlock($tplBlock);
|
||||
}
|
||||
} elseif (!empty($html) && $this->_tpl->placeholderExists($this->_formName . '_html', $tplBlock)) {
|
||||
$this->_tpl->setVariable($this->_formName . '_html', $html);
|
||||
$html = $this->_getTplBlock($tplBlock);
|
||||
}
|
||||
// clean up after ourselves
|
||||
$this->_tpl->setVariable($this->_formName . '_error', null);
|
||||
} elseif (!empty($label) && strpos($this->_error, '{label}') !== false) {
|
||||
if (is_array($label)) {
|
||||
$label[0] = str_replace(array('{label}', '{error}'), array($label[0], $error), $this->_error);
|
||||
} else {
|
||||
$label = str_replace(array('{label}', '{error}'), array($label, $error), $this->_error);
|
||||
}
|
||||
} elseif (!empty($html) && strpos($this->_error, '{html}') !== false) {
|
||||
$html = str_replace(array('{html}', '{error}'), array($html, $error), $this->_error);
|
||||
} else {
|
||||
$this->_errors[] = $error;
|
||||
}
|
||||
}// end func _renderError
|
||||
|
||||
|
||||
/**
|
||||
* Returns the block's contents
|
||||
*
|
||||
* The method is needed because ITX and Sigma implement clearing
|
||||
* the block contents on get() a bit differently
|
||||
*
|
||||
* @param string Block name
|
||||
* @return string Block contents
|
||||
*/
|
||||
function _getTplBlock($block)
|
||||
{
|
||||
$this->_tpl->parse($block);
|
||||
if (is_a($this->_tpl, 'html_template_sigma')) {
|
||||
$ret = $this->_tpl->get($block, true);
|
||||
} else {
|
||||
$oldClear = $this->_tpl->clearCache;
|
||||
$this->_tpl->clearCache = true;
|
||||
$ret = $this->_tpl->get($block);
|
||||
$this->_tpl->clearCache = $oldClear;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
} // end class HTML_QuickForm_Renderer_ITStatic
|
||||
?>
|
|
@ -1,432 +1,461 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4.0 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Ron McClain <ron@humaniq.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Object.php,v 1.4 2005/06/17 20:00:57 avb Exp $
|
||||
|
||||
require_once('HTML/QuickForm/Renderer.php');
|
||||
|
||||
/**
|
||||
* A concrete renderer for HTML_QuickForm, makes an object from form contents
|
||||
*
|
||||
* Based on HTML_Quickform_Renderer_Array code
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
class HTML_QuickForm_Renderer_Object extends HTML_QuickForm_Renderer
|
||||
{
|
||||
/**
|
||||
* The object being generated
|
||||
* @var object $_obj
|
||||
*/
|
||||
var $_obj= null;
|
||||
|
||||
/**
|
||||
* Number of sections in the form (i.e. number of headers in it)
|
||||
* @var integer $_sectionCount
|
||||
*/
|
||||
var $_sectionCount;
|
||||
|
||||
/**
|
||||
* Current section number
|
||||
* @var integer $_currentSection
|
||||
*/
|
||||
var $_currentSection;
|
||||
|
||||
/**
|
||||
* Object representing current group
|
||||
* @var object $_currentGroup
|
||||
*/
|
||||
var $_currentGroup = null;
|
||||
|
||||
/**
|
||||
* Class of Element Objects
|
||||
* @var object $_elementType
|
||||
*/
|
||||
var $_elementType = 'QuickFormElement';
|
||||
|
||||
/**
|
||||
* Additional style information for different elements
|
||||
* @var array $_elementStyles
|
||||
*/
|
||||
var $_elementStyles = array();
|
||||
|
||||
/**
|
||||
* true: collect all hidden elements into string; false: process them as usual form elements
|
||||
* @var bool $_collectHidden
|
||||
*/
|
||||
var $_collectHidden = false;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param collecthidden bool true: collect all hidden elements
|
||||
* @access public
|
||||
*/
|
||||
function HTML_QuickForm_Renderer_Object($collecthidden = false)
|
||||
{
|
||||
$this->HTML_QuickForm_Renderer();
|
||||
$this->_collectHidden = $collecthidden;
|
||||
$this->_obj = new QuickformForm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the rendered Object
|
||||
* @access public
|
||||
*/
|
||||
function toObject()
|
||||
{
|
||||
return $this->_obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the class of the form elements. Defaults to QuickformElement.
|
||||
* @param type string Name of element class
|
||||
* @access public
|
||||
*/
|
||||
function setElementType($type)
|
||||
{
|
||||
$this->_elementType = $type;
|
||||
}
|
||||
|
||||
function startForm(&$form)
|
||||
{
|
||||
$this->_obj->frozen = $form->isFrozen();
|
||||
$this->_obj->javascript = $form->getValidationScript();
|
||||
$this->_obj->attributes = $form->getAttributes(true);
|
||||
$this->_obj->requirednote = $form->getRequiredNote();
|
||||
$this->_obj->errors = new StdClass;
|
||||
|
||||
if($this->_collectHidden) {
|
||||
$this->_obj->hidden = '';
|
||||
}
|
||||
$this->_elementIdx = 1;
|
||||
$this->_currentSection = null;
|
||||
$this->_sectionCount = 0;
|
||||
} // end func startForm
|
||||
|
||||
function renderHeader(&$header)
|
||||
{
|
||||
$hobj = new StdClass;
|
||||
$hobj->header = $header->toHtml();
|
||||
$this->_obj->sections[$this->_sectionCount] = $hobj;
|
||||
$this->_currentSection = $this->_sectionCount++;
|
||||
}
|
||||
|
||||
function renderElement(&$element, $required, $error)
|
||||
{
|
||||
$elObj = $this->_elementToObject($element, $required, $error);
|
||||
if(!empty($error)) {
|
||||
$name = $elObj->name;
|
||||
$this->_obj->errors->$name = $error;
|
||||
}
|
||||
$this->_storeObject($elObj);
|
||||
} // end func renderElement
|
||||
|
||||
function renderHidden(&$element)
|
||||
{
|
||||
if($this->_collectHidden) {
|
||||
$this->_obj->hidden .= $element->toHtml() . "\n";
|
||||
} else {
|
||||
$this->renderElement($element, false, null);
|
||||
}
|
||||
} //end func renderHidden
|
||||
|
||||
function startGroup(&$group, $required, $error)
|
||||
{
|
||||
$this->_currentGroup = $this->_elementToObject($group, $required, $error);
|
||||
if(!empty($error)) {
|
||||
$name = $this->_currentGroup->name;
|
||||
$this->_obj->errors->$name = $error;
|
||||
}
|
||||
} // end func startGroup
|
||||
|
||||
function finishGroup(&$group)
|
||||
{
|
||||
$this->_storeObject($this->_currentGroup);
|
||||
$this->_currentGroup = null;
|
||||
} // end func finishGroup
|
||||
|
||||
/**
|
||||
* Creates an object representing an element
|
||||
*
|
||||
* @access private
|
||||
* @param element object An HTML_QuickForm_element object
|
||||
* @param required bool Whether an element is required
|
||||
* @param error string Error associated with the element
|
||||
* @return object
|
||||
*/
|
||||
function _elementToObject(&$element, $required, $error)
|
||||
{
|
||||
if($this->_elementType) {
|
||||
$ret = new $this->_elementType;
|
||||
}
|
||||
$ret->name = $element->getName();
|
||||
$ret->value = $element->getValue();
|
||||
$ret->type = $element->getType();
|
||||
$ret->frozen = $element->isFrozen();
|
||||
$labels = $element->getLabel();
|
||||
if (is_array($labels)) {
|
||||
$ret->label = array_shift($labels);
|
||||
foreach ($labels as $key => $label) {
|
||||
$key = is_int($key)? $key + 2: $key;
|
||||
$ret->{'label_' . $key} = $label;
|
||||
}
|
||||
} else {
|
||||
$ret->label = $labels;
|
||||
}
|
||||
$ret->required = $required;
|
||||
$ret->error = $error;
|
||||
|
||||
if(isset($this->_elementStyles[$ret->name])) {
|
||||
$ret->style = $this->_elementStyles[$ret->name];
|
||||
$ret->styleTemplate = "styles/". $ret->style .".html";
|
||||
}
|
||||
if($ret->type == 'group') {
|
||||
$ret->separator = $element->_separator;
|
||||
$ret->elements = array();
|
||||
} else {
|
||||
$ret->html = $element->toHtml();
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores an object representation of an element in the form array
|
||||
*
|
||||
* @access private
|
||||
* @param elObj object Object representation of an element
|
||||
* @return void
|
||||
*/
|
||||
function _storeObject($elObj)
|
||||
{
|
||||
$name = $elObj->name;
|
||||
if(is_object($this->_currentGroup) && $elObj->type != 'group') {
|
||||
$this->_currentGroup->elements[] = $elObj;
|
||||
} elseif (isset($this->_currentSection)) {
|
||||
$this->_obj->sections[$this->_currentSection]->elements[] = $elObj;
|
||||
} else {
|
||||
$this->_obj->elements[] = $elObj;
|
||||
}
|
||||
}
|
||||
|
||||
function setElementStyle($elementName, $styleName = null)
|
||||
{
|
||||
if(is_array($elementName)) {
|
||||
$this->_elementStyles = array_merge($this->_elementStyles, $elementName);
|
||||
} else {
|
||||
$this->_elementStyles[$elementName] = $styleName;
|
||||
}
|
||||
}
|
||||
|
||||
} // end class HTML_QuickForm_Renderer_Object
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Convenience class for the form object passed to outputObject()
|
||||
*
|
||||
* Eg.
|
||||
* {form.outputJavaScript():h}
|
||||
* {form.outputHeader():h}
|
||||
* <table>
|
||||
* <tr>
|
||||
* <td>{form.name.label:h}</td><td>{form.name.html:h}</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
* </form>
|
||||
*/
|
||||
class QuickformForm
|
||||
{
|
||||
/**
|
||||
* Whether the form has been frozen
|
||||
* @var boolean $frozen
|
||||
*/
|
||||
var $frozen;
|
||||
|
||||
/**
|
||||
* Javascript for client-side validation
|
||||
* @var string $javascript
|
||||
*/
|
||||
var $javascript;
|
||||
|
||||
/**
|
||||
* Attributes for form tag
|
||||
* @var string $attributes
|
||||
*/
|
||||
var $attributes;
|
||||
|
||||
/**
|
||||
* Note about required elements
|
||||
* @var string $requirednote
|
||||
*/
|
||||
var $requirednote;
|
||||
|
||||
/**
|
||||
* Collected html of all hidden variables
|
||||
* @var string $hidden
|
||||
*/
|
||||
var $hidden;
|
||||
|
||||
/**
|
||||
* Set if there were validation errors.
|
||||
* StdClass object with element names for keys and their
|
||||
* error messages as values
|
||||
* @var object $errors
|
||||
*/
|
||||
var $errors;
|
||||
|
||||
/**
|
||||
* Array of QuickformElementObject elements. If there are headers in the form
|
||||
* this will be empty and the elements will be in the
|
||||
* separate sections
|
||||
* @var array $elements
|
||||
*/
|
||||
var $elements;
|
||||
|
||||
/**
|
||||
* Array of sections contained in the document
|
||||
* @var array $sections
|
||||
*/
|
||||
var $sections;
|
||||
|
||||
/**
|
||||
* Output <form> header
|
||||
* {form.outputHeader():h}
|
||||
* @return string <form attributes>
|
||||
*/
|
||||
function outputHeader()
|
||||
{
|
||||
return "<form " . $this->attributes . ">\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Output form javascript
|
||||
* {form.outputJavaScript():h}
|
||||
* @return string Javascript
|
||||
*/
|
||||
function outputJavaScript()
|
||||
{
|
||||
return $this->javascript;
|
||||
}
|
||||
} // end class QuickformForm
|
||||
|
||||
|
||||
/**
|
||||
* Convenience class describing a form element.
|
||||
* The properties defined here will be available from
|
||||
* your flexy templates by referencing
|
||||
* {form.zip.label:h}, {form.zip.html:h}, etc.
|
||||
*/
|
||||
class QuickformElement
|
||||
{
|
||||
/**
|
||||
* Element name
|
||||
* @var string $name
|
||||
*/
|
||||
var $name;
|
||||
|
||||
/**
|
||||
* Element value
|
||||
* @var mixed $value
|
||||
*/
|
||||
var $value;
|
||||
|
||||
/**
|
||||
* Type of element
|
||||
* @var string $type
|
||||
*/
|
||||
var $type;
|
||||
|
||||
/**
|
||||
* Whether the element is frozen
|
||||
* @var boolean $frozen
|
||||
*/
|
||||
var $frozen;
|
||||
|
||||
/**
|
||||
* Label for the element
|
||||
* @var string $label
|
||||
*/
|
||||
var $label;
|
||||
|
||||
/**
|
||||
* Whether element is required
|
||||
* @var boolean $required
|
||||
*/
|
||||
var $required;
|
||||
|
||||
/**
|
||||
* Error associated with the element
|
||||
* @var string $error
|
||||
*/
|
||||
var $error;
|
||||
|
||||
/**
|
||||
* Some information about element style
|
||||
* @var string $style
|
||||
*/
|
||||
var $style;
|
||||
|
||||
/**
|
||||
* HTML for the element
|
||||
* @var string $html
|
||||
*/
|
||||
var $html;
|
||||
|
||||
/**
|
||||
* If element is a group, the group separator
|
||||
* @var mixed $separator
|
||||
*/
|
||||
var $separator;
|
||||
|
||||
/**
|
||||
* If element is a group, an array of subelements
|
||||
* @var array $elements
|
||||
*/
|
||||
var $elements;
|
||||
|
||||
function isType($type)
|
||||
{
|
||||
return ($this->type == $type);
|
||||
}
|
||||
|
||||
function notFrozen()
|
||||
{
|
||||
return !$this->frozen;
|
||||
}
|
||||
|
||||
function isButton()
|
||||
{
|
||||
return ($this->type == "submit" || $this->type == "reset");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* XXX: why does it use Flexy when all other stuff here does not depend on it?
|
||||
*/
|
||||
function outputStyle()
|
||||
{
|
||||
ob_start();
|
||||
HTML_Template_Flexy::staticQuickTemplate('styles/' . $this->style . '.html', $this);
|
||||
$ret = ob_get_contents();
|
||||
ob_end_clean();
|
||||
return $ret;
|
||||
}
|
||||
} // end class QuickformElement
|
||||
?>
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* A concrete renderer for HTML_QuickForm, makes an object from form contents
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Ron McClain <ron@humaniq.com>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: Object.php,v 1.6 2009/04/04 21:34:04 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* An abstract base class for QuickForm renderers
|
||||
*/
|
||||
require_once 'HTML/QuickForm/Renderer.php';
|
||||
|
||||
/**
|
||||
* A concrete renderer for HTML_QuickForm, makes an object from form contents
|
||||
*
|
||||
* Based on HTML_Quickform_Renderer_Array code
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Ron McClain <ron@humaniq.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 3.1.1
|
||||
*/
|
||||
class HTML_QuickForm_Renderer_Object extends HTML_QuickForm_Renderer
|
||||
{
|
||||
/**#@+
|
||||
* @access private
|
||||
*/
|
||||
/**
|
||||
* The object being generated
|
||||
* @var QuickformForm
|
||||
*/
|
||||
var $_obj= null;
|
||||
|
||||
/**
|
||||
* Number of sections in the form (i.e. number of headers in it)
|
||||
* @var integer $_sectionCount
|
||||
*/
|
||||
var $_sectionCount;
|
||||
|
||||
/**
|
||||
* Current section number
|
||||
* @var integer $_currentSection
|
||||
*/
|
||||
var $_currentSection;
|
||||
|
||||
/**
|
||||
* Object representing current group
|
||||
* @var object $_currentGroup
|
||||
*/
|
||||
var $_currentGroup = null;
|
||||
|
||||
/**
|
||||
* Class of Element Objects
|
||||
* @var object $_elementType
|
||||
*/
|
||||
var $_elementType = 'QuickFormElement';
|
||||
|
||||
/**
|
||||
* Additional style information for different elements
|
||||
* @var array $_elementStyles
|
||||
*/
|
||||
var $_elementStyles = array();
|
||||
|
||||
/**
|
||||
* true: collect all hidden elements into string; false: process them as usual form elements
|
||||
* @var bool $_collectHidden
|
||||
*/
|
||||
var $_collectHidden = false;
|
||||
/**#@-*/
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param bool true: collect all hidden elements
|
||||
* @access public
|
||||
*/
|
||||
function HTML_QuickForm_Renderer_Object($collecthidden = false)
|
||||
{
|
||||
$this->HTML_QuickForm_Renderer();
|
||||
$this->_collectHidden = $collecthidden;
|
||||
$this->_obj = new QuickformForm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the rendered Object
|
||||
* @access public
|
||||
*/
|
||||
function toObject()
|
||||
{
|
||||
return $this->_obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the class of the form elements. Defaults to QuickformElement.
|
||||
* @param string Name of element class
|
||||
* @access public
|
||||
*/
|
||||
function setElementType($type)
|
||||
{
|
||||
$this->_elementType = $type;
|
||||
}
|
||||
|
||||
function startForm(&$form)
|
||||
{
|
||||
$this->_obj->frozen = $form->isFrozen();
|
||||
$this->_obj->javascript = $form->getValidationScript();
|
||||
$this->_obj->attributes = $form->getAttributes(true);
|
||||
$this->_obj->requirednote = $form->getRequiredNote();
|
||||
$this->_obj->errors = new StdClass;
|
||||
|
||||
if($this->_collectHidden) {
|
||||
$this->_obj->hidden = '';
|
||||
}
|
||||
$this->_elementIdx = 1;
|
||||
$this->_currentSection = null;
|
||||
$this->_sectionCount = 0;
|
||||
} // end func startForm
|
||||
|
||||
function renderHeader(&$header)
|
||||
{
|
||||
$hobj = new StdClass;
|
||||
$hobj->header = $header->toHtml();
|
||||
$this->_obj->sections[$this->_sectionCount] = $hobj;
|
||||
$this->_currentSection = $this->_sectionCount++;
|
||||
}
|
||||
|
||||
function renderElement(&$element, $required, $error)
|
||||
{
|
||||
$elObj = $this->_elementToObject($element, $required, $error);
|
||||
if(!empty($error)) {
|
||||
$name = $elObj->name;
|
||||
$this->_obj->errors->$name = $error;
|
||||
}
|
||||
$this->_storeObject($elObj);
|
||||
} // end func renderElement
|
||||
|
||||
function renderHidden(&$element)
|
||||
{
|
||||
if($this->_collectHidden) {
|
||||
$this->_obj->hidden .= $element->toHtml() . "\n";
|
||||
} else {
|
||||
$this->renderElement($element, false, null);
|
||||
}
|
||||
} //end func renderHidden
|
||||
|
||||
function startGroup(&$group, $required, $error)
|
||||
{
|
||||
$this->_currentGroup = $this->_elementToObject($group, $required, $error);
|
||||
if(!empty($error)) {
|
||||
$name = $this->_currentGroup->name;
|
||||
$this->_obj->errors->$name = $error;
|
||||
}
|
||||
} // end func startGroup
|
||||
|
||||
function finishGroup(&$group)
|
||||
{
|
||||
$this->_storeObject($this->_currentGroup);
|
||||
$this->_currentGroup = null;
|
||||
} // end func finishGroup
|
||||
|
||||
/**
|
||||
* Creates an object representing an element
|
||||
*
|
||||
* @access private
|
||||
* @param HTML_QuickForm_element form element being rendered
|
||||
* @param required bool Whether an element is required
|
||||
* @param error string Error associated with the element
|
||||
* @return object
|
||||
*/
|
||||
function _elementToObject(&$element, $required, $error)
|
||||
{
|
||||
if($this->_elementType) {
|
||||
$ret = new $this->_elementType;
|
||||
}
|
||||
$ret->name = $element->getName();
|
||||
$ret->value = $element->getValue();
|
||||
$ret->type = $element->getType();
|
||||
$ret->frozen = $element->isFrozen();
|
||||
$labels = $element->getLabel();
|
||||
if (is_array($labels)) {
|
||||
$ret->label = array_shift($labels);
|
||||
foreach ($labels as $key => $label) {
|
||||
$key = is_int($key)? $key + 2: $key;
|
||||
$ret->{'label_' . $key} = $label;
|
||||
}
|
||||
} else {
|
||||
$ret->label = $labels;
|
||||
}
|
||||
$ret->required = $required;
|
||||
$ret->error = $error;
|
||||
|
||||
if(isset($this->_elementStyles[$ret->name])) {
|
||||
$ret->style = $this->_elementStyles[$ret->name];
|
||||
$ret->styleTemplate = "styles/". $ret->style .".html";
|
||||
}
|
||||
if($ret->type == 'group') {
|
||||
$ret->separator = $element->_separator;
|
||||
$ret->elements = array();
|
||||
} else {
|
||||
$ret->html = $element->toHtml();
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores an object representation of an element in the form array
|
||||
*
|
||||
* @access private
|
||||
* @param QuickformElement Object representation of an element
|
||||
* @return void
|
||||
*/
|
||||
function _storeObject($elObj)
|
||||
{
|
||||
$name = $elObj->name;
|
||||
if(is_object($this->_currentGroup) && $elObj->type != 'group') {
|
||||
$this->_currentGroup->elements[] = $elObj;
|
||||
} elseif (isset($this->_currentSection)) {
|
||||
$this->_obj->sections[$this->_currentSection]->elements[] = $elObj;
|
||||
} else {
|
||||
$this->_obj->elements[] = $elObj;
|
||||
}
|
||||
}
|
||||
|
||||
function setElementStyle($elementName, $styleName = null)
|
||||
{
|
||||
if(is_array($elementName)) {
|
||||
$this->_elementStyles = array_merge($this->_elementStyles, $elementName);
|
||||
} else {
|
||||
$this->_elementStyles[$elementName] = $styleName;
|
||||
}
|
||||
}
|
||||
|
||||
} // end class HTML_QuickForm_Renderer_Object
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Convenience class for the form object passed to outputObject()
|
||||
*
|
||||
* Eg.
|
||||
* <pre>
|
||||
* {form.outputJavaScript():h}
|
||||
* {form.outputHeader():h}
|
||||
* <table>
|
||||
* <tr>
|
||||
* <td>{form.name.label:h}</td><td>{form.name.html:h}</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
* </form>
|
||||
* </pre>
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Ron McClain <ron@humaniq.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 3.1.1
|
||||
*/
|
||||
class QuickformForm
|
||||
{
|
||||
/**
|
||||
* Whether the form has been frozen
|
||||
* @var boolean $frozen
|
||||
*/
|
||||
var $frozen;
|
||||
|
||||
/**
|
||||
* Javascript for client-side validation
|
||||
* @var string $javascript
|
||||
*/
|
||||
var $javascript;
|
||||
|
||||
/**
|
||||
* Attributes for form tag
|
||||
* @var string $attributes
|
||||
*/
|
||||
var $attributes;
|
||||
|
||||
/**
|
||||
* Note about required elements
|
||||
* @var string $requirednote
|
||||
*/
|
||||
var $requirednote;
|
||||
|
||||
/**
|
||||
* Collected html of all hidden variables
|
||||
* @var string $hidden
|
||||
*/
|
||||
var $hidden;
|
||||
|
||||
/**
|
||||
* Set if there were validation errors.
|
||||
* StdClass object with element names for keys and their
|
||||
* error messages as values
|
||||
* @var object $errors
|
||||
*/
|
||||
var $errors;
|
||||
|
||||
/**
|
||||
* Array of QuickformElementObject elements. If there are headers in the form
|
||||
* this will be empty and the elements will be in the
|
||||
* separate sections
|
||||
* @var array $elements
|
||||
*/
|
||||
var $elements;
|
||||
|
||||
/**
|
||||
* Array of sections contained in the document
|
||||
* @var array $sections
|
||||
*/
|
||||
var $sections;
|
||||
|
||||
/**
|
||||
* Output <form> header
|
||||
* {form.outputHeader():h}
|
||||
* @return string <form attributes>
|
||||
*/
|
||||
function outputHeader()
|
||||
{
|
||||
return "<form " . $this->attributes . ">\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Output form javascript
|
||||
* {form.outputJavaScript():h}
|
||||
* @return string Javascript
|
||||
*/
|
||||
function outputJavaScript()
|
||||
{
|
||||
return $this->javascript;
|
||||
}
|
||||
} // end class QuickformForm
|
||||
|
||||
|
||||
/**
|
||||
* Convenience class describing a form element.
|
||||
*
|
||||
* The properties defined here will be available from
|
||||
* your flexy templates by referencing
|
||||
* {form.zip.label:h}, {form.zip.html:h}, etc.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Ron McClain <ron@humaniq.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 3.1.1
|
||||
*/
|
||||
class QuickformElement
|
||||
{
|
||||
/**
|
||||
* Element name
|
||||
* @var string $name
|
||||
*/
|
||||
var $name;
|
||||
|
||||
/**
|
||||
* Element value
|
||||
* @var mixed $value
|
||||
*/
|
||||
var $value;
|
||||
|
||||
/**
|
||||
* Type of element
|
||||
* @var string $type
|
||||
*/
|
||||
var $type;
|
||||
|
||||
/**
|
||||
* Whether the element is frozen
|
||||
* @var boolean $frozen
|
||||
*/
|
||||
var $frozen;
|
||||
|
||||
/**
|
||||
* Label for the element
|
||||
* @var string $label
|
||||
*/
|
||||
var $label;
|
||||
|
||||
/**
|
||||
* Whether element is required
|
||||
* @var boolean $required
|
||||
*/
|
||||
var $required;
|
||||
|
||||
/**
|
||||
* Error associated with the element
|
||||
* @var string $error
|
||||
*/
|
||||
var $error;
|
||||
|
||||
/**
|
||||
* Some information about element style
|
||||
* @var string $style
|
||||
*/
|
||||
var $style;
|
||||
|
||||
/**
|
||||
* HTML for the element
|
||||
* @var string $html
|
||||
*/
|
||||
var $html;
|
||||
|
||||
/**
|
||||
* If element is a group, the group separator
|
||||
* @var mixed $separator
|
||||
*/
|
||||
var $separator;
|
||||
|
||||
/**
|
||||
* If element is a group, an array of subelements
|
||||
* @var array $elements
|
||||
*/
|
||||
var $elements;
|
||||
|
||||
function isType($type)
|
||||
{
|
||||
return ($this->type == $type);
|
||||
}
|
||||
|
||||
function notFrozen()
|
||||
{
|
||||
return !$this->frozen;
|
||||
}
|
||||
|
||||
function isButton()
|
||||
{
|
||||
return ($this->type == "submit" || $this->type == "reset");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* XXX: why does it use Flexy when all other stuff here does not depend on it?
|
||||
*/
|
||||
function outputStyle()
|
||||
{
|
||||
ob_start();
|
||||
HTML_Template_Flexy::staticQuickTemplate('styles/' . $this->style . '.html', $this);
|
||||
$ret = ob_get_contents();
|
||||
ob_end_clean();
|
||||
return $ret;
|
||||
}
|
||||
} // end class QuickformElement
|
||||
?>
|
||||
|
|
|
@ -1,264 +1,291 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4.0 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Ron McClain <ron@humaniq.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: ObjectFlexy.php,v 1.8 2006/10/07 20:12:17 avb Exp $
|
||||
|
||||
require_once("HTML/QuickForm/Renderer/Object.php");
|
||||
|
||||
/**
|
||||
* QuickForm renderer for Flexy template engine, static version.
|
||||
*
|
||||
* A static renderer for HTML_Quickform. Makes a QuickFormFlexyObject
|
||||
* from the form content suitable for use with a Flexy template
|
||||
*
|
||||
* Usage:
|
||||
* $form =& new HTML_QuickForm('form', 'POST');
|
||||
* $template =& new HTML_Template_Flexy();
|
||||
* $renderer =& new HTML_QuickForm_Renderer_ObjectFlexy(&$template);
|
||||
* $renderer->setHtmlTemplate("html.html");
|
||||
* $renderer->setLabelTemplate("label.html");
|
||||
* $form->accept($renderer);
|
||||
* $view = new StdClass;
|
||||
* $view->form = $renderer->toObject();
|
||||
* $template->compile("mytemplate.html");
|
||||
*
|
||||
* Based on the code for HTML_QuickForm_Renderer_ArraySmarty
|
||||
*
|
||||
* @see QuickFormFlexyObject
|
||||
* @access public
|
||||
*/
|
||||
class HTML_QuickForm_Renderer_ObjectFlexy extends HTML_QuickForm_Renderer_Object
|
||||
{
|
||||
/**
|
||||
* HTML_Template_Flexy instance
|
||||
* @var object $_flexy
|
||||
*/
|
||||
var $_flexy;
|
||||
|
||||
/**
|
||||
* Current element index
|
||||
* @var integer $_elementIdx
|
||||
*/
|
||||
var $_elementIdx;
|
||||
|
||||
/**
|
||||
* The current element index inside a group
|
||||
* @var integer $_groupElementIdx
|
||||
*/
|
||||
var $_groupElementIdx = 0;
|
||||
|
||||
/**
|
||||
* Name of template file for form html
|
||||
* @var string $_html
|
||||
* @see setRequiredTemplate()
|
||||
*/
|
||||
var $_html = '';
|
||||
|
||||
/**
|
||||
* Name of template file for form labels
|
||||
* @var string $label
|
||||
* @see setErrorTemplate()
|
||||
*/
|
||||
var $label = '';
|
||||
|
||||
/**
|
||||
* Class of the element objects, so you can add your own
|
||||
* element methods
|
||||
* @var string $_elementType
|
||||
*/
|
||||
var $_elementType = 'QuickformFlexyElement';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param $flexy object HTML_Template_Flexy instance
|
||||
* @public
|
||||
*/
|
||||
function HTML_QuickForm_Renderer_ObjectFlexy(&$flexy)
|
||||
{
|
||||
$this->HTML_QuickForm_Renderer_Object(true);
|
||||
$this->_obj = new QuickformFlexyForm();
|
||||
$this->_flexy =& $flexy;
|
||||
} // end constructor
|
||||
|
||||
function renderHeader(&$header)
|
||||
{
|
||||
if($name = $header->getName()) {
|
||||
$this->_obj->header->$name = $header->toHtml();
|
||||
} else {
|
||||
$this->_obj->header[$this->_sectionCount] = $header->toHtml();
|
||||
}
|
||||
$this->_currentSection = $this->_sectionCount++;
|
||||
} // end func renderHeader
|
||||
|
||||
function startGroup(&$group, $required, $error)
|
||||
{
|
||||
parent::startGroup($group, $required, $error);
|
||||
$this->_groupElementIdx = 1;
|
||||
} //end func startGroup
|
||||
|
||||
/**
|
||||
* Creates an object representing an element containing
|
||||
* the key for storing this
|
||||
*
|
||||
* @access private
|
||||
* @param element object An HTML_QuickForm_element object
|
||||
* @param required bool Whether an element is required
|
||||
* @param error string Error associated with the element
|
||||
* @return object
|
||||
*/
|
||||
function _elementToObject(&$element, $required, $error)
|
||||
{
|
||||
$ret = parent::_elementToObject($element, $required, $error);
|
||||
if($ret->type == 'group') {
|
||||
$ret->html = $element->toHtml();
|
||||
unset($ret->elements);
|
||||
}
|
||||
if(!empty($this->_label)) {
|
||||
$this->_renderLabel($ret);
|
||||
}
|
||||
|
||||
if(!empty($this->_html)) {
|
||||
$this->_renderHtml($ret);
|
||||
$ret->error = $error;
|
||||
}
|
||||
|
||||
// Create an element key from the name
|
||||
if (false !== ($pos = strpos($ret->name, '[')) || is_object($this->_currentGroup)) {
|
||||
if (!$pos) {
|
||||
$keys = '->{\'' . str_replace(array('\\', '\''), array('\\\\', '\\\''), $ret->name) . '\'}';
|
||||
} else {
|
||||
$keys = '->{\'' . str_replace(
|
||||
array('\\', '\'', '[', ']'), array('\\\\', '\\\'', '\'}->{\'', ''),
|
||||
$ret->name
|
||||
) . '\'}';
|
||||
}
|
||||
// special handling for elements in native groups
|
||||
if (is_object($this->_currentGroup)) {
|
||||
// skip unnamed group items unless radios: no name -> no static access
|
||||
// identification: have the same key string as the parent group
|
||||
if ($this->_currentGroup->keys == $keys && 'radio' != $ret->type) {
|
||||
return false;
|
||||
}
|
||||
// reduce string of keys by remove leading group keys
|
||||
if (0 === strpos($keys, $this->_currentGroup->keys)) {
|
||||
$keys = substr_replace($keys, '', 0, strlen($this->_currentGroup->keys));
|
||||
}
|
||||
}
|
||||
} elseif (0 == strlen($ret->name)) {
|
||||
$keys = '->{\'element_' . $this->_elementIdx . '\'}';
|
||||
} else {
|
||||
$keys = '->{\'' . str_replace(array('\\', '\''), array('\\\\', '\\\''), $ret->name) . '\'}';
|
||||
}
|
||||
// for radios: add extra key from value
|
||||
if ('radio' == $ret->type && '[]' != substr($keys, -2)) {
|
||||
$keys .= '->{\'' . str_replace(array('\\', '\''), array('\\\\', '\\\''), $ret->value) . '\'}';
|
||||
}
|
||||
$ret->keys = $keys;
|
||||
$this->_elementIdx++;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores an object representation of an element in the
|
||||
* QuickformFormObject instance
|
||||
*
|
||||
* @access private
|
||||
* @param elObj object Object representation of an element
|
||||
* @return void
|
||||
*/
|
||||
function _storeObject($elObj)
|
||||
{
|
||||
if ($elObj) {
|
||||
$keys = $elObj->keys;
|
||||
unset($elObj->keys);
|
||||
if(is_object($this->_currentGroup) && ('group' != $elObj->type)) {
|
||||
$code = '$this->_currentGroup' . $keys . ' = $elObj;';
|
||||
} else {
|
||||
$code = '$this->_obj' . $keys . ' = $elObj;';
|
||||
}
|
||||
eval($code);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the filename of the template to render html elements.
|
||||
* In your template, {html} is replaced by the unmodified html.
|
||||
* If the element is required, {required} will be true.
|
||||
* Eg.
|
||||
* {if:error}
|
||||
* <font color="red" size="1">{error:h}</font><br />
|
||||
* {end:}
|
||||
* {html:h}
|
||||
*
|
||||
* @access public
|
||||
* @param template string Filename of template
|
||||
* @return void
|
||||
*/
|
||||
function setHtmlTemplate($template)
|
||||
{
|
||||
$this->_html = $template;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the filename of the template to render form labels
|
||||
* In your template, {label} is replaced by the unmodified label.
|
||||
* {error} will be set to the error, if any. {required} will
|
||||
* be true if this is a required field
|
||||
* Eg.
|
||||
* {if:required}
|
||||
* <font color="orange" size="1">*</font>
|
||||
* {end:}
|
||||
* {label:h}
|
||||
*
|
||||
* @access public
|
||||
* @param template string Filename of template
|
||||
* @return void
|
||||
*/
|
||||
function setLabelTemplate($template)
|
||||
{
|
||||
$this->_label = $template;
|
||||
}
|
||||
|
||||
function _renderLabel(&$ret)
|
||||
{
|
||||
$this->_flexy->compile($this->_label);
|
||||
$ret->label = $this->_flexy->bufferedOutputObject($ret);
|
||||
}
|
||||
|
||||
function _renderHtml(&$ret)
|
||||
{
|
||||
$this->_flexy->compile($this->_html);
|
||||
$ret->html = $this->_flexy->bufferedOutputObject($ret);
|
||||
}
|
||||
} // end class HTML_QuickForm_Renderer_ObjectFlexy
|
||||
|
||||
/**
|
||||
* Adds nothing to QuickformForm, left for backwards compatibility
|
||||
*/
|
||||
class QuickformFlexyForm extends QuickformForm
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds nothing to QuickformElement, left for backwards compatibility
|
||||
*/
|
||||
class QuickformFlexyElement extends QuickformElement
|
||||
{
|
||||
}
|
||||
?>
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* QuickForm renderer for Flexy template engine, static version.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Ron McClain <ron@humaniq.com>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: ObjectFlexy.php,v 1.10 2009/04/04 21:34:04 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* A concrete renderer for HTML_QuickForm, makes an object from form contents
|
||||
*/
|
||||
require_once 'HTML/QuickForm/Renderer/Object.php';
|
||||
|
||||
/**
|
||||
* QuickForm renderer for Flexy template engine, static version.
|
||||
*
|
||||
* A static renderer for HTML_Quickform. Makes a QuickFormFlexyObject
|
||||
* from the form content suitable for use with a Flexy template
|
||||
*
|
||||
* Usage:
|
||||
* <code>
|
||||
* $form =& new HTML_QuickForm('form', 'POST');
|
||||
* $template =& new HTML_Template_Flexy();
|
||||
* $renderer =& new HTML_QuickForm_Renderer_ObjectFlexy(&$template);
|
||||
* $renderer->setHtmlTemplate("html.html");
|
||||
* $renderer->setLabelTemplate("label.html");
|
||||
* $form->accept($renderer);
|
||||
* $view = new StdClass;
|
||||
* $view->form = $renderer->toObject();
|
||||
* $template->compile("mytemplate.html");
|
||||
* </code>
|
||||
*
|
||||
* Based on the code for HTML_QuickForm_Renderer_ArraySmarty
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Ron McClain <ron@humaniq.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 3.1.1
|
||||
*/
|
||||
class HTML_QuickForm_Renderer_ObjectFlexy extends HTML_QuickForm_Renderer_Object
|
||||
{
|
||||
/**#@+
|
||||
* @access private
|
||||
*/
|
||||
/**
|
||||
* HTML_Template_Flexy instance
|
||||
* @var object $_flexy
|
||||
*/
|
||||
var $_flexy;
|
||||
|
||||
/**
|
||||
* Current element index
|
||||
* @var integer $_elementIdx
|
||||
*/
|
||||
var $_elementIdx;
|
||||
|
||||
/**
|
||||
* The current element index inside a group
|
||||
* @var integer $_groupElementIdx
|
||||
*/
|
||||
var $_groupElementIdx = 0;
|
||||
|
||||
/**
|
||||
* Name of template file for form html
|
||||
* @var string $_html
|
||||
* @see setRequiredTemplate()
|
||||
*/
|
||||
var $_html = '';
|
||||
|
||||
/**
|
||||
* Name of template file for form labels
|
||||
* @var string $label
|
||||
* @see setErrorTemplate()
|
||||
*/
|
||||
var $label = '';
|
||||
|
||||
/**
|
||||
* Class of the element objects, so you can add your own
|
||||
* element methods
|
||||
* @var string $_elementType
|
||||
*/
|
||||
var $_elementType = 'QuickformFlexyElement';
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param HTML_Template_Flexy template object to use
|
||||
* @public
|
||||
*/
|
||||
function HTML_QuickForm_Renderer_ObjectFlexy(&$flexy)
|
||||
{
|
||||
$this->HTML_QuickForm_Renderer_Object(true);
|
||||
$this->_obj = new QuickformFlexyForm();
|
||||
$this->_flexy =& $flexy;
|
||||
} // end constructor
|
||||
|
||||
function renderHeader(&$header)
|
||||
{
|
||||
if($name = $header->getName()) {
|
||||
$this->_obj->header->$name = $header->toHtml();
|
||||
} else {
|
||||
$this->_obj->header[$this->_sectionCount] = $header->toHtml();
|
||||
}
|
||||
$this->_currentSection = $this->_sectionCount++;
|
||||
} // end func renderHeader
|
||||
|
||||
function startGroup(&$group, $required, $error)
|
||||
{
|
||||
parent::startGroup($group, $required, $error);
|
||||
$this->_groupElementIdx = 1;
|
||||
} //end func startGroup
|
||||
|
||||
/**
|
||||
* Creates an object representing an element containing
|
||||
* the key for storing this
|
||||
*
|
||||
* @access private
|
||||
* @param HTML_QuickForm_element form element being rendered
|
||||
* @param bool Whether an element is required
|
||||
* @param string Error associated with the element
|
||||
* @return object
|
||||
*/
|
||||
function _elementToObject(&$element, $required, $error)
|
||||
{
|
||||
$ret = parent::_elementToObject($element, $required, $error);
|
||||
if($ret->type == 'group') {
|
||||
$ret->html = $element->toHtml();
|
||||
unset($ret->elements);
|
||||
}
|
||||
if(!empty($this->_label)) {
|
||||
$this->_renderLabel($ret);
|
||||
}
|
||||
|
||||
if(!empty($this->_html)) {
|
||||
$this->_renderHtml($ret);
|
||||
$ret->error = $error;
|
||||
}
|
||||
|
||||
// Create an element key from the name
|
||||
if (false !== ($pos = strpos($ret->name, '[')) || is_object($this->_currentGroup)) {
|
||||
if (!$pos) {
|
||||
$keys = '->{\'' . str_replace(array('\\', '\''), array('\\\\', '\\\''), $ret->name) . '\'}';
|
||||
} else {
|
||||
$keys = '->{\'' . str_replace(
|
||||
array('\\', '\'', '[', ']'), array('\\\\', '\\\'', '\'}->{\'', ''),
|
||||
$ret->name
|
||||
) . '\'}';
|
||||
}
|
||||
// special handling for elements in native groups
|
||||
if (is_object($this->_currentGroup)) {
|
||||
// skip unnamed group items unless radios: no name -> no static access
|
||||
// identification: have the same key string as the parent group
|
||||
if ($this->_currentGroup->keys == $keys && 'radio' != $ret->type) {
|
||||
return false;
|
||||
}
|
||||
// reduce string of keys by remove leading group keys
|
||||
if (0 === strpos($keys, $this->_currentGroup->keys)) {
|
||||
$keys = substr_replace($keys, '', 0, strlen($this->_currentGroup->keys));
|
||||
}
|
||||
}
|
||||
} elseif (0 == strlen($ret->name)) {
|
||||
$keys = '->{\'element_' . $this->_elementIdx . '\'}';
|
||||
} else {
|
||||
$keys = '->{\'' . str_replace(array('\\', '\''), array('\\\\', '\\\''), $ret->name) . '\'}';
|
||||
}
|
||||
// for radios: add extra key from value
|
||||
if ('radio' == $ret->type && '[]' != substr($keys, -2)) {
|
||||
$keys .= '->{\'' . str_replace(array('\\', '\''), array('\\\\', '\\\''), $ret->value) . '\'}';
|
||||
}
|
||||
$ret->keys = $keys;
|
||||
$this->_elementIdx++;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores an object representation of an element in the
|
||||
* QuickformFormObject instance
|
||||
*
|
||||
* @access private
|
||||
* @param QuickformElement Object representation of an element
|
||||
* @return void
|
||||
*/
|
||||
function _storeObject($elObj)
|
||||
{
|
||||
if ($elObj) {
|
||||
$keys = $elObj->keys;
|
||||
unset($elObj->keys);
|
||||
if(is_object($this->_currentGroup) && ('group' != $elObj->type)) {
|
||||
$code = '$this->_currentGroup' . $keys . ' = $elObj;';
|
||||
} else {
|
||||
$code = '$this->_obj' . $keys . ' = $elObj;';
|
||||
}
|
||||
eval($code);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the filename of the template to render html elements.
|
||||
* In your template, {html} is replaced by the unmodified html.
|
||||
* If the element is required, {required} will be true.
|
||||
* Eg.
|
||||
* <pre>
|
||||
* {if:error}
|
||||
* <font color="red" size="1">{error:h}</font><br />
|
||||
* {end:}
|
||||
* {html:h}
|
||||
* </pre>
|
||||
*
|
||||
* @access public
|
||||
* @param string Filename of template
|
||||
* @return void
|
||||
*/
|
||||
function setHtmlTemplate($template)
|
||||
{
|
||||
$this->_html = $template;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the filename of the template to render form labels
|
||||
* In your template, {label} is replaced by the unmodified label.
|
||||
* {error} will be set to the error, if any. {required} will
|
||||
* be true if this is a required field
|
||||
* Eg.
|
||||
* <pre>
|
||||
* {if:required}
|
||||
* <font color="orange" size="1">*</font>
|
||||
* {end:}
|
||||
* {label:h}
|
||||
* </pre>
|
||||
*
|
||||
* @access public
|
||||
* @param string Filename of template
|
||||
* @return void
|
||||
*/
|
||||
function setLabelTemplate($template)
|
||||
{
|
||||
$this->_label = $template;
|
||||
}
|
||||
|
||||
function _renderLabel(&$ret)
|
||||
{
|
||||
$this->_flexy->compile($this->_label);
|
||||
$ret->label = $this->_flexy->bufferedOutputObject($ret);
|
||||
}
|
||||
|
||||
function _renderHtml(&$ret)
|
||||
{
|
||||
$this->_flexy->compile($this->_html);
|
||||
$ret->html = $this->_flexy->bufferedOutputObject($ret);
|
||||
}
|
||||
} // end class HTML_QuickForm_Renderer_ObjectFlexy
|
||||
|
||||
/**
|
||||
* Adds nothing to QuickformForm, left for backwards compatibility
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @ignore
|
||||
*/
|
||||
class QuickformFlexyForm extends QuickformForm
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds nothing to QuickformElement, left for backwards compatibility
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @ignore
|
||||
*/
|
||||
class QuickformFlexyElement extends QuickformElement
|
||||
{
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -1,203 +1,213 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4.0 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Jason Rust <jrust@rustyparts.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: QuickHtml.php,v 1.1 2003/08/25 16:41:02 jrust Exp $
|
||||
|
||||
require_once('HTML/QuickForm/Renderer/Default.php');
|
||||
|
||||
/**
|
||||
* A renderer that makes it quick and easy to create customized forms.
|
||||
*
|
||||
* This renderer has three main distinctives: an easy way to create
|
||||
* custom-looking forms, the ability to separate the creation of form
|
||||
* elements from their display, and being able to use QuickForm in
|
||||
* widget-based template systems. See the online docs for more info.
|
||||
* For a usage example see: docs/renderers/QuickHtml_example.php
|
||||
*
|
||||
* @access public
|
||||
* @package QuickForm
|
||||
*/
|
||||
class HTML_QuickForm_Renderer_QuickHtml extends HTML_QuickForm_Renderer_Default {
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* The array of rendered elements
|
||||
* @var array
|
||||
*/
|
||||
var $renderedElements = array();
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function HTML_QuickForm_Renderer_QuickHtml()
|
||||
{
|
||||
$this->HTML_QuickForm_Renderer_Default();
|
||||
// The default templates aren't used for this renderer
|
||||
$this->clearAllTemplates();
|
||||
} // end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ toHtml()
|
||||
|
||||
/**
|
||||
* returns the HTML generated for the form
|
||||
*
|
||||
* @param string $data (optional) Any extra data to put before the end of the form
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function toHtml($data = '')
|
||||
{
|
||||
// Render any elements that haven't been rendered explicitly by elementToHtml()
|
||||
foreach (array_keys($this->renderedElements) as $key) {
|
||||
if (!$this->renderedElements[$key]['rendered']) {
|
||||
$this->renderedElements[$key]['rendered'] = true;
|
||||
$data .= $this->renderedElements[$key]['html'] . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
// Insert the extra data and form elements at the end of the form
|
||||
$this->_html = str_replace('</form>', $data . "\n</form>", $this->_html);
|
||||
return $this->_html;
|
||||
} // end func toHtml
|
||||
|
||||
// }}}
|
||||
// {{{ elementToHtml()
|
||||
|
||||
/**
|
||||
* Gets the html for an element and marks it as rendered.
|
||||
*
|
||||
* @param string $elementName The element name
|
||||
* @param string $elementValue (optional) The value of the element. This is only useful
|
||||
* for elements that have the same name (i.e. radio and checkbox), but
|
||||
* different values
|
||||
*
|
||||
* @access public
|
||||
* @return string The html for the QuickForm element
|
||||
*/
|
||||
function elementToHtml($elementName, $elementValue = null)
|
||||
{
|
||||
$elementKey = null;
|
||||
// Find the key for the element
|
||||
foreach ($this->renderedElements as $key => $data) {
|
||||
if ($data['name'] == $elementName &&
|
||||
// See if the value must match as well
|
||||
(is_null($elementValue) ||
|
||||
$data['value'] == $elementValue)) {
|
||||
$elementKey = $key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_null($elementKey)) {
|
||||
$msg = is_null($elementValue) ? "Element $elementName does not exist." :
|
||||
"Element $elementName with value of $elementValue does not exist.";
|
||||
return PEAR::raiseError(null, QUICKFORM_UNREGISTERED_ELEMENT, null, E_USER_WARNING, $msg, 'HTML_QuickForm_Error', true);
|
||||
} else {
|
||||
if ($this->renderedElements[$elementKey]['rendered']) {
|
||||
$msg = is_null($elementValue) ? "Element $elementName has already been rendered." :
|
||||
"Element $elementName with value of $elementValue has already been rendered.";
|
||||
return PEAR::raiseError(null, QUICKFORM_ERROR, null, E_USER_WARNING, $msg, 'HTML_QuickForm_Error', true);
|
||||
} else {
|
||||
$this->renderedElements[$elementKey]['rendered'] = true;
|
||||
return $this->renderedElements[$elementKey]['html'];
|
||||
}
|
||||
}
|
||||
} // end func elementToHtml
|
||||
|
||||
// }}}
|
||||
// {{{ renderElement()
|
||||
|
||||
/**
|
||||
* Gets the html for an element and adds it to the array by calling
|
||||
* parent::renderElement()
|
||||
*
|
||||
* @param object An HTML_QuickForm_element object
|
||||
* @param bool Whether an element is required
|
||||
* @param string An error message associated with an element
|
||||
*
|
||||
* @access public
|
||||
* @return mixed HTML string of element if $immediateRender is set, else we just add the
|
||||
* html to the global _html string
|
||||
*/
|
||||
function renderElement(&$element, $required, $error)
|
||||
{
|
||||
$this->_html = '';
|
||||
parent::renderElement($element, $required, $error);
|
||||
if (!$this->_inGroup) {
|
||||
$this->renderedElements[] = array(
|
||||
'name' => $element->getName(),
|
||||
'value' => $element->getValue(),
|
||||
'html' => $this->_html,
|
||||
'rendered' => false);
|
||||
}
|
||||
$this->_html = '';
|
||||
} // end func renderElement
|
||||
|
||||
// }}}
|
||||
// {{{ renderHidden()
|
||||
|
||||
/**
|
||||
* Gets the html for a hidden element and adds it to the array.
|
||||
*
|
||||
* @param object An HTML_QuickForm_hidden object being visited
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function renderHidden(&$element)
|
||||
{
|
||||
$this->renderedElements[] = array(
|
||||
'name' => $element->getName(),
|
||||
'value' => $element->getValue(),
|
||||
'html' => $element->toHtml(),
|
||||
'rendered' => false);
|
||||
} // end func renderHidden
|
||||
|
||||
// }}}
|
||||
// {{{ finishGroup()
|
||||
|
||||
/**
|
||||
* Gets the html for the group element and adds it to the array by calling
|
||||
* parent::finishGroup()
|
||||
*
|
||||
* @param object An HTML_QuickForm_group object being visited
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function finishGroup(&$group)
|
||||
{
|
||||
$this->_html = '';
|
||||
parent::finishGroup($group);
|
||||
$this->renderedElements[] = array(
|
||||
'name' => $group->getName(),
|
||||
'value' => $group->getValue(),
|
||||
'html' => $this->_html,
|
||||
'rendered' => false);
|
||||
$this->_html = '';
|
||||
} // end func finishGroup
|
||||
|
||||
// }}}
|
||||
} // end class HTML_QuickForm_Renderer_QuickHtml
|
||||
?>
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* A renderer that makes it quick and easy to create customized forms.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Jason Rust <jrust@rustyparts.com>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: QuickHtml.php,v 1.3 2009/04/04 21:34:04 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* A concrete renderer for HTML_QuickForm, based on QuickForm 2.x built-in one
|
||||
*/
|
||||
require_once 'HTML/QuickForm/Renderer/Default.php';
|
||||
|
||||
/**
|
||||
* A renderer that makes it quick and easy to create customized forms.
|
||||
*
|
||||
* This renderer has three main distinctives: an easy way to create
|
||||
* custom-looking forms, the ability to separate the creation of form
|
||||
* elements from their display, and being able to use QuickForm in
|
||||
* widget-based template systems. See the online docs for more info.
|
||||
* For a usage example see: docs/renderers/QuickHtml_example.php
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Jason Rust <jrust@rustyparts.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 3.1.1
|
||||
*/
|
||||
class HTML_QuickForm_Renderer_QuickHtml extends HTML_QuickForm_Renderer_Default {
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* The array of rendered elements
|
||||
* @var array
|
||||
*/
|
||||
var $renderedElements = array();
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function HTML_QuickForm_Renderer_QuickHtml()
|
||||
{
|
||||
$this->HTML_QuickForm_Renderer_Default();
|
||||
// The default templates aren't used for this renderer
|
||||
$this->clearAllTemplates();
|
||||
} // end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ toHtml()
|
||||
|
||||
/**
|
||||
* returns the HTML generated for the form
|
||||
*
|
||||
* @param string $data (optional) Any extra data to put before the end of the form
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function toHtml($data = '')
|
||||
{
|
||||
// Render any elements that haven't been rendered explicitly by elementToHtml()
|
||||
foreach (array_keys($this->renderedElements) as $key) {
|
||||
if (!$this->renderedElements[$key]['rendered']) {
|
||||
$this->renderedElements[$key]['rendered'] = true;
|
||||
$data .= $this->renderedElements[$key]['html'] . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
// Insert the extra data and form elements at the end of the form
|
||||
$this->_html = str_replace('</form>', $data . "\n</form>", $this->_html);
|
||||
return $this->_html;
|
||||
} // end func toHtml
|
||||
|
||||
// }}}
|
||||
// {{{ elementToHtml()
|
||||
|
||||
/**
|
||||
* Gets the html for an element and marks it as rendered.
|
||||
*
|
||||
* @param string $elementName The element name
|
||||
* @param string $elementValue (optional) The value of the element. This is only useful
|
||||
* for elements that have the same name (i.e. radio and checkbox), but
|
||||
* different values
|
||||
*
|
||||
* @access public
|
||||
* @return string The html for the QuickForm element
|
||||
* @throws HTML_QuickForm_Error
|
||||
*/
|
||||
function elementToHtml($elementName, $elementValue = null)
|
||||
{
|
||||
$elementKey = null;
|
||||
// Find the key for the element
|
||||
foreach ($this->renderedElements as $key => $data) {
|
||||
if ($data['name'] == $elementName &&
|
||||
// See if the value must match as well
|
||||
(is_null($elementValue) ||
|
||||
$data['value'] == $elementValue)) {
|
||||
$elementKey = $key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_null($elementKey)) {
|
||||
$msg = is_null($elementValue) ? "Element $elementName does not exist." :
|
||||
"Element $elementName with value of $elementValue does not exist.";
|
||||
return PEAR::raiseError(null, QUICKFORM_UNREGISTERED_ELEMENT, null, E_USER_WARNING, $msg, 'HTML_QuickForm_Error', true);
|
||||
} else {
|
||||
if ($this->renderedElements[$elementKey]['rendered']) {
|
||||
$msg = is_null($elementValue) ? "Element $elementName has already been rendered." :
|
||||
"Element $elementName with value of $elementValue has already been rendered.";
|
||||
return PEAR::raiseError(null, QUICKFORM_ERROR, null, E_USER_WARNING, $msg, 'HTML_QuickForm_Error', true);
|
||||
} else {
|
||||
$this->renderedElements[$elementKey]['rendered'] = true;
|
||||
return $this->renderedElements[$elementKey]['html'];
|
||||
}
|
||||
}
|
||||
} // end func elementToHtml
|
||||
|
||||
// }}}
|
||||
// {{{ renderElement()
|
||||
|
||||
/**
|
||||
* Gets the html for an element and adds it to the array by calling
|
||||
* parent::renderElement()
|
||||
*
|
||||
* @param HTML_QuickForm_element form element being visited
|
||||
* @param bool Whether an element is required
|
||||
* @param string An error message associated with an element
|
||||
*
|
||||
* @access public
|
||||
* @return mixed HTML string of element if $immediateRender is set, else we just add the
|
||||
* html to the global _html string
|
||||
*/
|
||||
function renderElement(&$element, $required, $error)
|
||||
{
|
||||
$this->_html = '';
|
||||
parent::renderElement($element, $required, $error);
|
||||
if (!$this->_inGroup) {
|
||||
$this->renderedElements[] = array(
|
||||
'name' => $element->getName(),
|
||||
'value' => $element->getValue(),
|
||||
'html' => $this->_html,
|
||||
'rendered' => false);
|
||||
}
|
||||
$this->_html = '';
|
||||
} // end func renderElement
|
||||
|
||||
// }}}
|
||||
// {{{ renderHidden()
|
||||
|
||||
/**
|
||||
* Gets the html for a hidden element and adds it to the array.
|
||||
*
|
||||
* @param HTML_QuickForm_element hidden form element being visited
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function renderHidden(&$element)
|
||||
{
|
||||
$this->renderedElements[] = array(
|
||||
'name' => $element->getName(),
|
||||
'value' => $element->getValue(),
|
||||
'html' => $element->toHtml(),
|
||||
'rendered' => false);
|
||||
} // end func renderHidden
|
||||
|
||||
// }}}
|
||||
// {{{ finishGroup()
|
||||
|
||||
/**
|
||||
* Gets the html for the group element and adds it to the array by calling
|
||||
* parent::finishGroup()
|
||||
*
|
||||
* @param HTML_QuickForm_group group being visited
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function finishGroup(&$group)
|
||||
{
|
||||
$this->_html = '';
|
||||
parent::finishGroup($group);
|
||||
$this->renderedElements[] = array(
|
||||
'name' => $group->getName(),
|
||||
'value' => $group->getValue(),
|
||||
'html' => $this->_html,
|
||||
'rendered' => false);
|
||||
$this->_html = '';
|
||||
} // end func finishGroup
|
||||
|
||||
// }}}
|
||||
} // end class HTML_QuickForm_Renderer_QuickHtml
|
||||
?>
|
||||
|
|
|
@ -1,67 +1,82 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4.0 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Bertrand Mansion <bmansion@mamasam.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Rule.php,v 1.2 2003/11/03 16:08:22 avb Exp $
|
||||
|
||||
class HTML_QuickForm_Rule
|
||||
{
|
||||
/**
|
||||
* Name of the rule to use in validate method
|
||||
*
|
||||
* This property is used in more global rules like Callback and Regex
|
||||
* to determine which callback and which regex is to be used for validation
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $name;
|
||||
|
||||
/**
|
||||
* Validates a value
|
||||
*
|
||||
* @access public
|
||||
* @abstract
|
||||
*/
|
||||
function validate($value)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the rule name
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function setName($ruleName)
|
||||
{
|
||||
$this->name = $ruleName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the javascript test (the test should return true if the value is INVALID)
|
||||
*
|
||||
* @param mixed Options for the rule
|
||||
* @access public
|
||||
* @return array first element is code to setup validation, second is the check itself
|
||||
*/
|
||||
function getValidationScript($options = null)
|
||||
{
|
||||
return array('', '');
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Abstract base class for QuickForm validation rules
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: Rule.php,v 1.4 2009/04/04 21:34:02 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstract base class for QuickForm validation rules
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 3.2
|
||||
* @abstract
|
||||
*/
|
||||
class HTML_QuickForm_Rule
|
||||
{
|
||||
/**
|
||||
* Name of the rule to use in validate method
|
||||
*
|
||||
* This property is used in more global rules like Callback and Regex
|
||||
* to determine which callback and which regex is to be used for validation
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $name;
|
||||
|
||||
/**
|
||||
* Validates a value
|
||||
*
|
||||
* @access public
|
||||
* @abstract
|
||||
*/
|
||||
function validate($value)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the rule name
|
||||
*
|
||||
* @param string rule name
|
||||
* @access public
|
||||
*/
|
||||
function setName($ruleName)
|
||||
{
|
||||
$this->name = $ruleName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the javascript test (the test should return true if the value is INVALID)
|
||||
*
|
||||
* @param mixed Options for the rule
|
||||
* @access public
|
||||
* @return array first element is code to setup validation, second is the check itself
|
||||
* @abstract
|
||||
*/
|
||||
function getValidationScript($options = null)
|
||||
{
|
||||
return array('', '');
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -1,113 +1,124 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4.0 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Bertrand Mansion <bmansion@mamasam.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Callback.php,v 1.7 2003/11/11 12:41:13 avb Exp $
|
||||
|
||||
require_once('HTML/QuickForm/Rule.php');
|
||||
|
||||
/**
|
||||
* Validates values using callback functions or methods
|
||||
* @version 1.0
|
||||
*/
|
||||
class HTML_QuickForm_Rule_Callback extends HTML_QuickForm_Rule
|
||||
{
|
||||
/**
|
||||
* Array of callbacks
|
||||
*
|
||||
* Array is in the format:
|
||||
* $_data['rulename'] = array('functionname', 'classname');
|
||||
* If the callback is not a method, then the class name is not set.
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_data = array();
|
||||
|
||||
/**
|
||||
* Whether to use BC mode for specific rules
|
||||
*
|
||||
* Previous versions of QF passed element's name as a first parameter
|
||||
* to validation functions, but not to validation methods. This behaviour
|
||||
* is emulated if you are using 'function' as rule type when registering.
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_BCMode = array();
|
||||
|
||||
/**
|
||||
* Validates a value using a callback
|
||||
*
|
||||
* @param string $value Value to be checked
|
||||
* @param mixed $options Options for callback
|
||||
* @access public
|
||||
* @return boolean true if value is valid
|
||||
*/
|
||||
function validate($value, $options = null)
|
||||
{
|
||||
if (isset($this->_data[$this->name])) {
|
||||
$callback = $this->_data[$this->name];
|
||||
if (isset($callback[1])) {
|
||||
return call_user_func(array($callback[1], $callback[0]), $value, $options);
|
||||
} elseif ($this->_BCMode[$this->name]) {
|
||||
return $callback[0]('', $value, $options);
|
||||
} else {
|
||||
return $callback[0]($value, $options);
|
||||
}
|
||||
} elseif (is_callable($options)) {
|
||||
return call_user_func($options, $value);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} // end func validate
|
||||
|
||||
/**
|
||||
* Adds new callbacks to the callbacks list
|
||||
*
|
||||
* @param string $name Name of rule
|
||||
* @param string $callback Name of function or method
|
||||
* @param string $class Name of class containing the method
|
||||
* @param bool $BCMode Backwards compatibility mode
|
||||
* @access public
|
||||
*/
|
||||
function addData($name, $callback, $class = null, $BCMode = false)
|
||||
{
|
||||
if (!empty($class)) {
|
||||
$this->_data[$name] = array($callback, $class);
|
||||
} else {
|
||||
$this->_data[$name] = array($callback);
|
||||
}
|
||||
$this->_BCMode[$name] = $BCMode;
|
||||
} // end func addData
|
||||
|
||||
|
||||
function getValidationScript($options = null)
|
||||
{
|
||||
if (isset($this->_data[$this->name])) {
|
||||
$callback = $this->_data[$this->name][0];
|
||||
$params = ($this->_BCMode[$this->name]? "'', {jsVar}": '{jsVar}') .
|
||||
(isset($options)? ", '{$options}'": '');
|
||||
} else {
|
||||
$callback = is_array($options)? $options[1]: $options;
|
||||
$params = '{jsVar}';
|
||||
}
|
||||
return array('', "{jsVar} != '' && !{$callback}({$params})");
|
||||
} // end func getValidationScript
|
||||
|
||||
} // end class HTML_QuickForm_Rule_Callback
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Validates values using callback functions or methods
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: Callback.php,v 1.9 2009/04/04 21:34:04 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstract base class for QuickForm validation rules
|
||||
*/
|
||||
require_once 'HTML/QuickForm/Rule.php';
|
||||
|
||||
/**
|
||||
* Validates values using callback functions or methods
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 3.2
|
||||
*/
|
||||
class HTML_QuickForm_Rule_Callback extends HTML_QuickForm_Rule
|
||||
{
|
||||
/**
|
||||
* Array of callbacks
|
||||
*
|
||||
* Array is in the format:
|
||||
* $_data['rulename'] = array('functionname', 'classname');
|
||||
* If the callback is not a method, then the class name is not set.
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_data = array();
|
||||
|
||||
/**
|
||||
* Whether to use BC mode for specific rules
|
||||
*
|
||||
* Previous versions of QF passed element's name as a first parameter
|
||||
* to validation functions, but not to validation methods. This behaviour
|
||||
* is emulated if you are using 'function' as rule type when registering.
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_BCMode = array();
|
||||
|
||||
/**
|
||||
* Validates a value using a callback
|
||||
*
|
||||
* @param string $value Value to be checked
|
||||
* @param mixed $options Options for callback
|
||||
* @access public
|
||||
* @return boolean true if value is valid
|
||||
*/
|
||||
function validate($value, $options = null)
|
||||
{
|
||||
if (isset($this->_data[$this->name])) {
|
||||
$callback = $this->_data[$this->name];
|
||||
if (isset($callback[1])) {
|
||||
return call_user_func(array($callback[1], $callback[0]), $value, $options);
|
||||
} elseif ($this->_BCMode[$this->name]) {
|
||||
return $callback[0]('', $value, $options);
|
||||
} else {
|
||||
return $callback[0]($value, $options);
|
||||
}
|
||||
} elseif (is_callable($options)) {
|
||||
return call_user_func($options, $value);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} // end func validate
|
||||
|
||||
/**
|
||||
* Adds new callbacks to the callbacks list
|
||||
*
|
||||
* @param string $name Name of rule
|
||||
* @param string $callback Name of function or method
|
||||
* @param string $class Name of class containing the method
|
||||
* @param bool $BCMode Backwards compatibility mode
|
||||
* @access public
|
||||
*/
|
||||
function addData($name, $callback, $class = null, $BCMode = false)
|
||||
{
|
||||
if (!empty($class)) {
|
||||
$this->_data[$name] = array($callback, $class);
|
||||
} else {
|
||||
$this->_data[$name] = array($callback);
|
||||
}
|
||||
$this->_BCMode[$name] = $BCMode;
|
||||
} // end func addData
|
||||
|
||||
|
||||
function getValidationScript($options = null)
|
||||
{
|
||||
if (isset($this->_data[$this->name])) {
|
||||
$callback = $this->_data[$this->name][0];
|
||||
$params = ($this->_BCMode[$this->name]? "'', {jsVar}": '{jsVar}') .
|
||||
(isset($options)? ", '{$options}'": '');
|
||||
} else {
|
||||
$callback = is_array($options)? $options[1]: $options;
|
||||
$params = '{jsVar}';
|
||||
}
|
||||
return array('', "{jsVar} != '' && !{$callback}({$params})");
|
||||
} // end func getValidationScript
|
||||
|
||||
} // end class HTML_QuickForm_Rule_Callback
|
||||
?>
|
|
@ -1,95 +1,105 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4.0 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Alexey Borzov <avb@php.net> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Compare.php,v 1.3 2003/11/03 16:08:24 avb Exp $
|
||||
|
||||
require_once 'HTML/QuickForm/Rule.php';
|
||||
|
||||
/**
|
||||
* Rule to compare two form fields
|
||||
*
|
||||
* The most common usage for this is to ensure that the password
|
||||
* confirmation field matches the password field
|
||||
*
|
||||
* @access public
|
||||
* @package HTML_QuickForm
|
||||
* @version $Revision: 1.3 $
|
||||
*/
|
||||
class HTML_QuickForm_Rule_Compare extends HTML_QuickForm_Rule
|
||||
{
|
||||
/**
|
||||
* Possible operators to use
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_operators = array(
|
||||
'eq' => '==',
|
||||
'neq' => '!=',
|
||||
'gt' => '>',
|
||||
'gte' => '>=',
|
||||
'lt' => '<',
|
||||
'lte' => '<='
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the operator to use for comparing the values
|
||||
*
|
||||
* @access private
|
||||
* @param string operator name
|
||||
* @return string operator to use for validation
|
||||
*/
|
||||
function _findOperator($name)
|
||||
{
|
||||
if (empty($name)) {
|
||||
return '==';
|
||||
} elseif (isset($this->_operators[$name])) {
|
||||
return $this->_operators[$name];
|
||||
} elseif (in_array($name, $this->_operators)) {
|
||||
return $name;
|
||||
} else {
|
||||
return '==';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function validate($values, $operator = null)
|
||||
{
|
||||
$operator = $this->_findOperator($operator);
|
||||
if ('==' != $operator && '!=' != $operator) {
|
||||
$compareFn = create_function('$a, $b', 'return floatval($a) ' . $operator . ' floatval($b);');
|
||||
} else {
|
||||
$compareFn = create_function('$a, $b', 'return $a ' . $operator . ' $b;');
|
||||
}
|
||||
|
||||
return $compareFn($values[0], $values[1]);
|
||||
}
|
||||
|
||||
|
||||
function getValidationScript($operator = null)
|
||||
{
|
||||
$operator = $this->_findOperator($operator);
|
||||
if ('==' != $operator && '!=' != $operator) {
|
||||
$check = "!(Number({jsVar}[0]) {$operator} Number({jsVar}[1]))";
|
||||
} else {
|
||||
$check = "!({jsVar}[0] {$operator} {jsVar}[1])";
|
||||
}
|
||||
return array('', "'' != {jsVar}[0] && {$check}");
|
||||
}
|
||||
}
|
||||
?>
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Rule to compare two form fields
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: Compare.php,v 1.7 2009/04/04 21:34:04 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstract base class for QuickForm validation rules
|
||||
*/
|
||||
require_once 'HTML/QuickForm/Rule.php';
|
||||
|
||||
/**
|
||||
* Rule to compare two form fields
|
||||
*
|
||||
* The most common usage for this is to ensure that the password
|
||||
* confirmation field matches the password field
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @version Release: 3.2.11
|
||||
* @since 3.2
|
||||
*/
|
||||
class HTML_QuickForm_Rule_Compare extends HTML_QuickForm_Rule
|
||||
{
|
||||
/**
|
||||
* Possible operators to use
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_operators = array(
|
||||
'eq' => '===',
|
||||
'neq' => '!==',
|
||||
'gt' => '>',
|
||||
'gte' => '>=',
|
||||
'lt' => '<',
|
||||
'lte' => '<=',
|
||||
'==' => '===',
|
||||
'!=' => '!=='
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the operator to use for comparing the values
|
||||
*
|
||||
* @access private
|
||||
* @param string operator name
|
||||
* @return string operator to use for validation
|
||||
*/
|
||||
function _findOperator($name)
|
||||
{
|
||||
if (empty($name)) {
|
||||
return '===';
|
||||
} elseif (isset($this->_operators[$name])) {
|
||||
return $this->_operators[$name];
|
||||
} elseif (in_array($name, $this->_operators)) {
|
||||
return $name;
|
||||
} else {
|
||||
return '===';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function validate($values, $operator = null)
|
||||
{
|
||||
$operator = $this->_findOperator($operator);
|
||||
if ('===' != $operator && '!==' != $operator) {
|
||||
$compareFn = create_function('$a, $b', 'return floatval($a) ' . $operator . ' floatval($b);');
|
||||
} else {
|
||||
$compareFn = create_function('$a, $b', 'return strval($a) ' . $operator . ' strval($b);');
|
||||
}
|
||||
|
||||
return $compareFn($values[0], $values[1]);
|
||||
}
|
||||
|
||||
|
||||
function getValidationScript($operator = null)
|
||||
{
|
||||
$operator = $this->_findOperator($operator);
|
||||
if ('===' != $operator && '!==' != $operator) {
|
||||
$check = "!(Number({jsVar}[0]) {$operator} Number({jsVar}[1]))";
|
||||
} else {
|
||||
$check = "!(String({jsVar}[0]) {$operator} String({jsVar}[1]))";
|
||||
}
|
||||
return array('', "'' != {jsVar}[0] && {$check}");
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -1,61 +1,73 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4.0 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Bertrand Mansion <bmansion@mamasam.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Email.php,v 1.4 2003/12/18 14:21:57 mansion Exp $
|
||||
|
||||
require_once('HTML/QuickForm/Rule.php');
|
||||
|
||||
/**
|
||||
* Email validation rule
|
||||
* @version 1.0
|
||||
*/
|
||||
class HTML_QuickForm_Rule_Email extends HTML_QuickForm_Rule
|
||||
{
|
||||
var $regex = '/^((\"[^\"\f\n\r\t\v\b]+\")|([\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+(\.[\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+)*))@((\[(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))\])|(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))|((([A-Za-z0-9\-])+\.)+[A-Za-z\-]+))$/';
|
||||
|
||||
/**
|
||||
* Validates an email address
|
||||
*
|
||||
* @param string $email Email address
|
||||
* @param boolean $checkDomain True if dns check should be performed
|
||||
* @access public
|
||||
* @return boolean true if email is valid
|
||||
*/
|
||||
function validate($email, $checkDomain = false)
|
||||
{
|
||||
if (preg_match($this->regex, $email)) {
|
||||
if ($checkDomain && function_exists('checkdnsrr')) {
|
||||
$tokens = explode('@', $email);
|
||||
if (checkdnsrr($tokens[1], 'MX') || checkdnsrr($tokens[1], 'A')) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} // end func validate
|
||||
|
||||
|
||||
function getValidationScript($options = null)
|
||||
{
|
||||
return array(" var regex = " . $this->regex . ";\n", "{jsVar} != '' && !regex.test({jsVar})");
|
||||
} // end func getValidationScript
|
||||
|
||||
} // end class HTML_QuickForm_Rule_Email
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Email validation rule
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: Email.php,v 1.7 2009/04/04 21:34:04 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstract base class for QuickForm validation rules
|
||||
*/
|
||||
require_once 'HTML/QuickForm/Rule.php';
|
||||
|
||||
/**
|
||||
* Email validation rule
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 3.2
|
||||
*/
|
||||
class HTML_QuickForm_Rule_Email extends HTML_QuickForm_Rule
|
||||
{
|
||||
var $regex = '/^((\"[^\"\f\n\r\t\v\b]+\")|([\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+(\.[\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+)*))@((\[(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))\])|(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))|((([A-Za-z0-9\-])+\.)+[A-Za-z\-]+))$/';
|
||||
|
||||
/**
|
||||
* Validates an email address
|
||||
*
|
||||
* @param string $email Email address
|
||||
* @param boolean $checkDomain True if dns check should be performed
|
||||
* @access public
|
||||
* @return boolean true if email is valid
|
||||
*/
|
||||
function validate($email, $checkDomain = false)
|
||||
{
|
||||
// Fix for bug #10799: add 'D' modifier to regex
|
||||
if (preg_match($this->regex . 'D', $email)) {
|
||||
if ($checkDomain && function_exists('checkdnsrr')) {
|
||||
$tokens = explode('@', $email);
|
||||
if (checkdnsrr($tokens[1], 'MX') || checkdnsrr($tokens[1], 'A')) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} // end func validate
|
||||
|
||||
|
||||
function getValidationScript($options = null)
|
||||
{
|
||||
return array(" var regex = " . $this->regex . ";\n", "{jsVar} != '' && !regex.test({jsVar})");
|
||||
} // end func getValidationScript
|
||||
|
||||
} // end class HTML_QuickForm_Rule_Email
|
||||
?>
|
|
@ -1,64 +1,75 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4.0 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Bertrand Mansion <bmansion@mamasam.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Range.php,v 1.6 2003/11/03 16:08:24 avb Exp $
|
||||
|
||||
require_once('HTML/QuickForm/Rule.php');
|
||||
|
||||
/**
|
||||
* Validates values using range comparison
|
||||
* @version 1.0
|
||||
*/
|
||||
class HTML_QuickForm_Rule_Range extends HTML_QuickForm_Rule
|
||||
{
|
||||
/**
|
||||
* Validates a value using a range comparison
|
||||
*
|
||||
* @param string $value Value to be checked
|
||||
* @param mixed $options Int for length, array for range
|
||||
* @access public
|
||||
* @return boolean true if value is valid
|
||||
*/
|
||||
function validate($value, $options)
|
||||
{
|
||||
$length = strlen($value);
|
||||
switch ($this->name) {
|
||||
case 'minlength': return ($length >= $options);
|
||||
case 'maxlength': return ($length <= $options);
|
||||
default: return ($length >= $options[0] && $length <= $options[1]);
|
||||
}
|
||||
} // end func validate
|
||||
|
||||
|
||||
function getValidationScript($options = null)
|
||||
{
|
||||
switch ($this->name) {
|
||||
case 'minlength':
|
||||
$test = '{jsVar}.length < '.$options;
|
||||
break;
|
||||
case 'maxlength':
|
||||
$test = '{jsVar}.length > '.$options;
|
||||
break;
|
||||
default:
|
||||
$test = '({jsVar}.length < '.$options[0].' || {jsVar}.length > '.$options[1].')';
|
||||
}
|
||||
return array('', "{jsVar} != '' && {$test}");
|
||||
} // end func getValidationScript
|
||||
|
||||
} // end class HTML_QuickForm_Rule_Range
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Checks that the length of value is within range
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: Range.php,v 1.8 2009/04/04 21:34:04 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstract base class for QuickForm validation rules
|
||||
*/
|
||||
require_once 'HTML/QuickForm/Rule.php';
|
||||
|
||||
/**
|
||||
* Checks that the length of value is within range
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 3.2
|
||||
*/
|
||||
class HTML_QuickForm_Rule_Range extends HTML_QuickForm_Rule
|
||||
{
|
||||
/**
|
||||
* Validates a value using a range comparison
|
||||
*
|
||||
* @param string $value Value to be checked
|
||||
* @param mixed $options Int for length, array for range
|
||||
* @access public
|
||||
* @return boolean true if value is valid
|
||||
*/
|
||||
function validate($value, $options)
|
||||
{
|
||||
$length = strlen($value);
|
||||
switch ($this->name) {
|
||||
case 'minlength': return ($length >= $options);
|
||||
case 'maxlength': return ($length <= $options);
|
||||
default: return ($length >= $options[0] && $length <= $options[1]);
|
||||
}
|
||||
} // end func validate
|
||||
|
||||
|
||||
function getValidationScript($options = null)
|
||||
{
|
||||
switch ($this->name) {
|
||||
case 'minlength':
|
||||
$test = '{jsVar}.length < '.$options;
|
||||
break;
|
||||
case 'maxlength':
|
||||
$test = '{jsVar}.length > '.$options;
|
||||
break;
|
||||
default:
|
||||
$test = '({jsVar}.length < '.$options[0].' || {jsVar}.length > '.$options[1].')';
|
||||
}
|
||||
return array('', "{jsVar} != '' && {$test}");
|
||||
} // end func getValidationScript
|
||||
|
||||
} // end class HTML_QuickForm_Rule_Range
|
||||
?>
|
|
@ -1,89 +1,107 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4.0 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Bertrand Mansion <bmansion@mamasam.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Regex.php,v 1.3 2003/11/03 16:08:24 avb Exp $
|
||||
|
||||
require_once('HTML/QuickForm/Rule.php');
|
||||
|
||||
/**
|
||||
* Validates values using regular expressions
|
||||
* @version 1.0
|
||||
*/
|
||||
class HTML_QuickForm_Rule_Regex extends HTML_QuickForm_Rule
|
||||
{
|
||||
/**
|
||||
* Array of regular expressions
|
||||
*
|
||||
* Array is in the format:
|
||||
* $_data['rulename'] = 'pattern';
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_data = array(
|
||||
'lettersonly' => '/^[a-zA-Z]+$/',
|
||||
'alphanumeric' => '/^[a-zA-Z0-9]+$/',
|
||||
'numeric' => '/(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/',
|
||||
'nopunctuation' => '/^[^().\/\*\^\?#!@$%+=,\"\'><~\[\]{}]+$/',
|
||||
'nonzero' => '/^-?[1-9][0-9]*/'
|
||||
);
|
||||
|
||||
/**
|
||||
* Validates a value using a regular expression
|
||||
*
|
||||
* @param string $value Value to be checked
|
||||
* @param string $regex Regular expression
|
||||
* @access public
|
||||
* @return boolean true if value is valid
|
||||
*/
|
||||
function validate($value, $regex = null)
|
||||
{
|
||||
if (isset($this->_data[$this->name])) {
|
||||
if (!preg_match($this->_data[$this->name], $value)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!preg_match($regex, $value)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} // end func validate
|
||||
|
||||
/**
|
||||
* Adds new regular expressions to the list
|
||||
*
|
||||
* @param string $name Name of rule
|
||||
* @param string $pattern Regular expression pattern
|
||||
* @access public
|
||||
*/
|
||||
function addData($name, $pattern)
|
||||
{
|
||||
$this->_data[$name] = $pattern;
|
||||
} // end func addData
|
||||
|
||||
|
||||
function getValidationScript($options = null)
|
||||
{
|
||||
$regex = isset($this->_data[$this->name]) ? $this->_data[$this->name] : $options;
|
||||
|
||||
return array(" var regex = " . $regex . ";\n", "{jsVar} != '' && !regex.test({jsVar})");
|
||||
} // end func getValidationScript
|
||||
|
||||
} // end class HTML_QuickForm_Rule_Regex
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Validates values using regular expressions
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: Regex.php,v 1.6 2009/04/04 21:34:04 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstract base class for QuickForm validation rules
|
||||
*/
|
||||
require_once 'HTML/QuickForm/Rule.php';
|
||||
|
||||
/**
|
||||
* Validates values using regular expressions
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 3.2
|
||||
*/
|
||||
class HTML_QuickForm_Rule_Regex extends HTML_QuickForm_Rule
|
||||
{
|
||||
/**
|
||||
* Array of regular expressions
|
||||
*
|
||||
* Array is in the format:
|
||||
* $_data['rulename'] = 'pattern';
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_data = array(
|
||||
'lettersonly' => '/^[a-zA-Z]+$/',
|
||||
'alphanumeric' => '/^[a-zA-Z0-9]+$/',
|
||||
'numeric' => '/(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/',
|
||||
'nopunctuation' => '/^[^().\/\*\^\?#!@$%+=,\"\'><~\[\]{}]+$/',
|
||||
'nonzero' => '/^-?[1-9][0-9]*/'
|
||||
);
|
||||
|
||||
/**
|
||||
* Validates a value using a regular expression
|
||||
*
|
||||
* @param string $value Value to be checked
|
||||
* @param string $regex Regular expression
|
||||
* @access public
|
||||
* @return boolean true if value is valid
|
||||
*/
|
||||
function validate($value, $regex = null)
|
||||
{
|
||||
// Fix for bug #10799: add 'D' modifier to regex
|
||||
if (isset($this->_data[$this->name])) {
|
||||
if (!preg_match($this->_data[$this->name] . 'D', $value)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!preg_match($regex . 'D', $value)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} // end func validate
|
||||
|
||||
/**
|
||||
* Adds new regular expressions to the list
|
||||
*
|
||||
* @param string $name Name of rule
|
||||
* @param string $pattern Regular expression pattern
|
||||
* @access public
|
||||
*/
|
||||
function addData($name, $pattern)
|
||||
{
|
||||
$this->_data[$name] = $pattern;
|
||||
} // end func addData
|
||||
|
||||
|
||||
function getValidationScript($options = null)
|
||||
{
|
||||
$regex = isset($this->_data[$this->name]) ? $this->_data[$this->name] : $options;
|
||||
|
||||
// bug #12376, converting unicode escapes and stripping 'u' modifier
|
||||
if ($pos = strpos($regex, 'u', strrpos($regex, '/'))) {
|
||||
$regex = substr($regex, 0, $pos) . substr($regex, $pos + 1);
|
||||
$regex = preg_replace('/(?<!\\\\)(?>\\\\\\\\)*\\\\x{([a-fA-F0-9]+)}/', '\\u$1', $regex);
|
||||
}
|
||||
|
||||
return array(" var regex = " . $regex . ";\n", "{jsVar} != '' && !regex.test({jsVar})");
|
||||
} // end func getValidationScript
|
||||
|
||||
} // end class HTML_QuickForm_Rule_Regex
|
||||
?>
|
|
@ -1,52 +1,63 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4.0 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Bertrand Mansion <bmansion@mamasam.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Required.php,v 1.4 2005/06/18 20:58:33 avb Exp $
|
||||
|
||||
require_once('HTML/QuickForm/Rule.php');
|
||||
|
||||
/**
|
||||
* Required elements validation
|
||||
* @version 1.0
|
||||
*/
|
||||
class HTML_QuickForm_Rule_Required extends HTML_QuickForm_Rule
|
||||
{
|
||||
/**
|
||||
* Checks if an element is empty
|
||||
*
|
||||
* @param string $value Value to check
|
||||
* @param mixed $options Not used yet
|
||||
* @access public
|
||||
* @return boolean true if value is not empty
|
||||
*/
|
||||
function validate($value, $options = null)
|
||||
{
|
||||
if ((string)$value == '') {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} // end func validate
|
||||
|
||||
|
||||
function getValidationScript($options = null)
|
||||
{
|
||||
return array('', "{jsVar} == ''");
|
||||
} // end func getValidationScript
|
||||
|
||||
} // end class HTML_QuickForm_Rule_Required
|
||||
?>
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Required elements validation
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: Required.php,v 1.6 2009/04/04 21:34:04 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstract base class for QuickForm validation rules
|
||||
*/
|
||||
require_once 'HTML/QuickForm/Rule.php';
|
||||
|
||||
/**
|
||||
* Required elements validation
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 3.2
|
||||
*/
|
||||
class HTML_QuickForm_Rule_Required extends HTML_QuickForm_Rule
|
||||
{
|
||||
/**
|
||||
* Checks if an element is empty
|
||||
*
|
||||
* @param string $value Value to check
|
||||
* @param mixed $options Not used yet
|
||||
* @access public
|
||||
* @return boolean true if value is not empty
|
||||
*/
|
||||
function validate($value, $options = null)
|
||||
{
|
||||
if ((string)$value == '') {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} // end func validate
|
||||
|
||||
|
||||
function getValidationScript($options = null)
|
||||
{
|
||||
return array('', "{jsVar} == ''");
|
||||
} // end func getValidationScript
|
||||
|
||||
} // end class HTML_QuickForm_Rule_Required
|
||||
?>
|
||||
|
|
|
@ -1,336 +1,349 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4.0 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Adam Daniel <adaniel1@eesus.jnj.com> |
|
||||
// | Alexey Borzov <borz_off@cs.msu.su> |
|
||||
// | Bertrand Mansion <bmansion@mamasam.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: RuleRegistry.php,v 1.17 2006/06/20 22:09:15 avb Exp $
|
||||
|
||||
/**
|
||||
* Registers rule objects and uses them for validation
|
||||
*
|
||||
*/
|
||||
class HTML_QuickForm_RuleRegistry
|
||||
{
|
||||
/**
|
||||
* Array containing references to used rules
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_rules = array();
|
||||
|
||||
|
||||
/**
|
||||
* Returns a singleton of HTML_QuickForm_RuleRegistry
|
||||
*
|
||||
* Usually, only one RuleRegistry object is needed, this is the reason
|
||||
* why it is recommended to use this method to get the validation object.
|
||||
*
|
||||
* @access public
|
||||
* @static
|
||||
* @return object Reference to the HTML_QuickForm_RuleRegistry singleton
|
||||
*/
|
||||
function &singleton()
|
||||
{
|
||||
static $obj;
|
||||
if (!isset($obj)) {
|
||||
$obj = new HTML_QuickForm_RuleRegistry();
|
||||
}
|
||||
return $obj;
|
||||
} // end func singleton
|
||||
|
||||
/**
|
||||
* Registers a new validation rule
|
||||
*
|
||||
* In order to use a custom rule in your form, you need to register it
|
||||
* first. For regular expressions, one can directly use the 'regex' type
|
||||
* rule in addRule(), this is faster than registering the rule.
|
||||
*
|
||||
* Functions and methods can be registered. Use the 'function' type.
|
||||
* When registering a method, specify the class name as second parameter.
|
||||
*
|
||||
* You can also register an HTML_QuickForm_Rule subclass with its own
|
||||
* validate() method.
|
||||
*
|
||||
* @param string $ruleName Name of validation rule
|
||||
* @param string $type Either: 'regex', 'function' or null
|
||||
* @param string $data1 Name of function, regular expression or
|
||||
* HTML_QuickForm_Rule object class name
|
||||
* @param string $data2 Object parent of above function or HTML_QuickForm_Rule file path
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function registerRule($ruleName, $type, $data1, $data2 = null)
|
||||
{
|
||||
$type = strtolower($type);
|
||||
if ($type == 'regex') {
|
||||
// Regular expression
|
||||
$rule =& $this->getRule('regex');
|
||||
$rule->addData($ruleName, $data1);
|
||||
$GLOBALS['_HTML_QuickForm_registered_rules'][$ruleName] = $GLOBALS['_HTML_QuickForm_registered_rules']['regex'];
|
||||
|
||||
} elseif ($type == 'function' || $type == 'callback') {
|
||||
// Callback function
|
||||
$rule =& $this->getRule('callback');
|
||||
$rule->addData($ruleName, $data1, $data2, 'function' == $type);
|
||||
$GLOBALS['_HTML_QuickForm_registered_rules'][$ruleName] = $GLOBALS['_HTML_QuickForm_registered_rules']['callback'];
|
||||
|
||||
} elseif (is_object($data1)) {
|
||||
// An instance of HTML_QuickForm_Rule
|
||||
$this->_rules[strtolower(get_class($data1))] = $data1;
|
||||
$GLOBALS['_HTML_QuickForm_registered_rules'][$ruleName] = array(strtolower(get_class($data1)), null);
|
||||
|
||||
} else {
|
||||
// Rule class name
|
||||
$GLOBALS['_HTML_QuickForm_registered_rules'][$ruleName] = array(strtolower($data1), $data2);
|
||||
}
|
||||
} // end func registerRule
|
||||
|
||||
/**
|
||||
* Returns a reference to the requested rule object
|
||||
*
|
||||
* @param string $ruleName Name of the requested rule
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
function &getRule($ruleName)
|
||||
{
|
||||
list($class, $path) = $GLOBALS['_HTML_QuickForm_registered_rules'][$ruleName];
|
||||
|
||||
if (!isset($this->_rules[$class])) {
|
||||
if (!empty($path)) {
|
||||
include_once($path);
|
||||
}
|
||||
$this->_rules[$class] =& new $class();
|
||||
}
|
||||
$this->_rules[$class]->setName($ruleName);
|
||||
return $this->_rules[$class];
|
||||
} // end func getRule
|
||||
|
||||
/**
|
||||
* Performs validation on the given values
|
||||
*
|
||||
* @param string $ruleName Name of the rule to be used
|
||||
* @param mixed $values Can be a scalar or an array of values
|
||||
* to be validated
|
||||
* @param mixed $options Options used by the rule
|
||||
* @param mixed $multiple Whether to validate an array of values altogether
|
||||
* @access public
|
||||
* @return mixed true if no error found, int of valid values (when an array of values is given) or false if error
|
||||
*/
|
||||
function validate($ruleName, $values, $options = null, $multiple = false)
|
||||
{
|
||||
$rule =& $this->getRule($ruleName);
|
||||
|
||||
if (is_array($values) && !$multiple) {
|
||||
$result = 0;
|
||||
foreach ($values as $value) {
|
||||
if ($rule->validate($value, $options) === true) {
|
||||
$result++;
|
||||
}
|
||||
}
|
||||
return ($result == 0) ? false : $result;
|
||||
} else {
|
||||
return $rule->validate($values, $options);
|
||||
}
|
||||
} // end func validate
|
||||
|
||||
/**
|
||||
* Returns the validation test in javascript code
|
||||
*
|
||||
* @param mixed Element(s) the rule applies to
|
||||
* @param string Element name, in case $element is not array
|
||||
* @param array Rule data
|
||||
* @access public
|
||||
* @return string JavaScript for the rule
|
||||
*/
|
||||
function getValidationScript(&$element, $elementName, $ruleData)
|
||||
{
|
||||
$reset = (isset($ruleData['reset'])) ? $ruleData['reset'] : false;
|
||||
$rule =& $this->getRule($ruleData['type']);
|
||||
if (!is_array($element)) {
|
||||
list($jsValue, $jsReset) = $this->_getJsValue($element, $elementName, $reset, null);
|
||||
} else {
|
||||
$jsValue = " value = new Array();\n";
|
||||
$jsReset = '';
|
||||
for ($i = 0; $i < count($element); $i++) {
|
||||
list($tmp_value, $tmp_reset) = $this->_getJsValue($element[$i], $element[$i]->getName(), $reset, $i);
|
||||
$jsValue .= "\n" . $tmp_value;
|
||||
$jsReset .= $tmp_reset;
|
||||
}
|
||||
}
|
||||
$jsField = isset($ruleData['group'])? $ruleData['group']: $elementName;
|
||||
list ($jsPrefix, $jsCheck) = $rule->getValidationScript($ruleData['format']);
|
||||
if (!isset($ruleData['howmany'])) {
|
||||
$js = $jsValue . "\n" . $jsPrefix .
|
||||
" if (" . str_replace('{jsVar}', 'value', $jsCheck) . " && !errFlag['{$jsField}']) {\n" .
|
||||
" errFlag['{$jsField}'] = true;\n" .
|
||||
" _qfMsg = _qfMsg + '\\n - {$ruleData['message']}';\n" .
|
||||
$jsReset .
|
||||
" }\n";
|
||||
} else {
|
||||
$js = $jsValue . "\n" . $jsPrefix .
|
||||
" var res = 0;\n" .
|
||||
" for (var i = 0; i < value.length; i++) {\n" .
|
||||
" if (!(" . str_replace('{jsVar}', 'value[i]', $jsCheck) . ")) {\n" .
|
||||
" res++;\n" .
|
||||
" }\n" .
|
||||
" }\n" .
|
||||
" if (res < {$ruleData['howmany']} && !errFlag['{$jsField}']) {\n" .
|
||||
" errFlag['{$jsField}'] = true;\n" .
|
||||
" _qfMsg = _qfMsg + '\\n - {$ruleData['message']}';\n" .
|
||||
$jsReset .
|
||||
" }\n";
|
||||
}
|
||||
return $js;
|
||||
} // end func getValidationScript
|
||||
|
||||
|
||||
/**
|
||||
* Returns JavaScript to get and to reset the element's value
|
||||
*
|
||||
* @access private
|
||||
* @param object HTML_QuickForm_element element being processed
|
||||
* @param string element's name
|
||||
* @param bool whether to generate JavaScript to reset the value
|
||||
* @param integer value's index in the array (only used for multielement rules)
|
||||
* @return array first item is value javascript, second is reset
|
||||
*/
|
||||
function _getJsValue(&$element, $elementName, $reset = false, $index = null)
|
||||
{
|
||||
$jsIndex = isset($index)? '[' . $index . ']': '';
|
||||
$tmp_reset = $reset? " var field = frm.elements['$elementName'];\n": '';
|
||||
if (is_a($element, 'html_quickform_group')) {
|
||||
$value = " _qfGroups['{$elementName}'] = {";
|
||||
$elements =& $element->getElements();
|
||||
for ($i = 0, $count = count($elements); $i < $count; $i++) {
|
||||
$append = ($elements[$i]->getType() == 'select' && $elements[$i]->getMultiple())? '[]': '';
|
||||
$value .= "'" . $element->getElementName($i) . $append . "': true" .
|
||||
($i < $count - 1? ', ': '');
|
||||
}
|
||||
$value .=
|
||||
"};\n" .
|
||||
" value{$jsIndex} = new Array();\n" .
|
||||
" var valueIdx = 0;\n" .
|
||||
" for (var i = 0; i < frm.elements.length; i++) {\n" .
|
||||
" var _element = frm.elements[i];\n" .
|
||||
" if (_element.name in _qfGroups['{$elementName}']) {\n" .
|
||||
" switch (_element.type) {\n" .
|
||||
" case 'checkbox':\n" .
|
||||
" case 'radio':\n" .
|
||||
" if (_element.checked) {\n" .
|
||||
" value{$jsIndex}[valueIdx++] = _element.value;\n" .
|
||||
" }\n" .
|
||||
" break;\n" .
|
||||
" case 'select-one':\n" .
|
||||
" if (-1 != _element.selectedIndex) {\n" .
|
||||
" value{$jsIndex}[valueIdx++] = _element.options[_element.selectedIndex].value;\n" .
|
||||
" }\n" .
|
||||
" break;\n" .
|
||||
" case 'select-multiple':\n" .
|
||||
" var tmpVal = new Array();\n" .
|
||||
" var tmpIdx = 0;\n" .
|
||||
" for (var j = 0; j < _element.options.length; j++) {\n" .
|
||||
" if (_element.options[j].selected) {\n" .
|
||||
" tmpVal[tmpIdx++] = _element.options[j].value;\n" .
|
||||
" }\n" .
|
||||
" }\n" .
|
||||
" if (tmpIdx > 0) {\n" .
|
||||
" value{$jsIndex}[valueIdx++] = tmpVal;\n" .
|
||||
" }\n" .
|
||||
" break;\n" .
|
||||
" default:\n" .
|
||||
" value{$jsIndex}[valueIdx++] = _element.value;\n" .
|
||||
" }\n" .
|
||||
" }\n" .
|
||||
" }\n";
|
||||
if ($reset) {
|
||||
$tmp_reset =
|
||||
" for (var i = 0; i < frm.elements.length; i++) {\n" .
|
||||
" var _element = frm.elements[i];\n" .
|
||||
" if (_element.name in _qfGroups['{$elementName}']) {\n" .
|
||||
" switch (_element.type) {\n" .
|
||||
" case 'checkbox':\n" .
|
||||
" case 'radio':\n" .
|
||||
" _element.checked = _element.defaultChecked;\n" .
|
||||
" break;\n" .
|
||||
" case 'select-one':\n" .
|
||||
" case 'select-multiple':\n" .
|
||||
" for (var j = 0; j < _element.options.length; j++) {\n" .
|
||||
" _element.options[j].selected = _element.options[j].defaultSelected;\n" .
|
||||
" }\n" .
|
||||
" break;\n" .
|
||||
" default:\n" .
|
||||
" _element.value = _element.defaultValue;\n" .
|
||||
" }\n" .
|
||||
" }\n" .
|
||||
" }\n";
|
||||
}
|
||||
|
||||
} elseif ($element->getType() == 'select') {
|
||||
if ($element->getMultiple()) {
|
||||
$elementName .= '[]';
|
||||
$value =
|
||||
" value{$jsIndex} = new Array();\n" .
|
||||
" var valueIdx = 0;\n" .
|
||||
" for (var i = 0; i < frm.elements['{$elementName}'].options.length; i++) {\n" .
|
||||
" if (frm.elements['{$elementName}'].options[i].selected) {\n" .
|
||||
" value{$jsIndex}[valueIdx++] = frm.elements['{$elementName}'].options[i].value;\n" .
|
||||
" }\n" .
|
||||
" }\n";
|
||||
} else {
|
||||
$value = " value{$jsIndex} = frm.elements['{$elementName}'].selectedIndex == -1? '': frm.elements['{$elementName}'].options[frm.elements['{$elementName}'].selectedIndex].value;\n";
|
||||
}
|
||||
if ($reset) {
|
||||
$tmp_reset .=
|
||||
" for (var i = 0; i < field.options.length; i++) {\n" .
|
||||
" field.options[i].selected = field.options[i].defaultSelected;\n" .
|
||||
" }\n";
|
||||
}
|
||||
|
||||
} elseif ($element->getType() == 'checkbox') {
|
||||
if (is_a($element, 'html_quickform_advcheckbox')) {
|
||||
$value = " value{$jsIndex} = frm.elements['$elementName'][1].checked? frm.elements['$elementName'][1].value: frm.elements['$elementName'][0].value;\n";
|
||||
$tmp_reset .= $reset ? " field[1].checked = field[1].defaultChecked;\n" : '';
|
||||
} else {
|
||||
$value = " value{$jsIndex} = frm.elements['$elementName'].checked? '1': '';\n";
|
||||
$tmp_reset .= $reset ? " field.checked = field.defaultChecked;\n" : '';
|
||||
}
|
||||
|
||||
} elseif ($element->getType() == 'radio') {
|
||||
$value = " value{$jsIndex} = '';\n" .
|
||||
// Fix for bug #5644
|
||||
" var els = 'length' in frm.elements['$elementName']? frm.elements['$elementName']: [ frm.elements['$elementName'] ];\n" .
|
||||
" for (var i = 0; i < els.length; i++) {\n" .
|
||||
" if (els[i].checked) {\n" .
|
||||
" value{$jsIndex} = els[i].value;\n" .
|
||||
" }\n" .
|
||||
" }";
|
||||
if ($reset) {
|
||||
$tmp_reset .= " for (var i = 0; i < field.length; i++) {\n" .
|
||||
" field[i].checked = field[i].defaultChecked;\n" .
|
||||
" }";
|
||||
}
|
||||
|
||||
} else {
|
||||
$value = " value{$jsIndex} = frm.elements['$elementName'].value;";
|
||||
$tmp_reset .= ($reset) ? " field.value = field.defaultValue;\n" : '';
|
||||
}
|
||||
return array($value, $tmp_reset);
|
||||
}
|
||||
} // end class HTML_QuickForm_RuleRegistry
|
||||
?>
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Registers rule objects and uses them for validation
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: RuleRegistry.php,v 1.19 2009/04/04 21:34:02 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Registers rule objects and uses them for validation
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @version Release: 3.2.11
|
||||
* @since 3.2
|
||||
*/
|
||||
class HTML_QuickForm_RuleRegistry
|
||||
{
|
||||
/**
|
||||
* Array containing references to used rules
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_rules = array();
|
||||
|
||||
|
||||
/**
|
||||
* Returns a singleton of HTML_QuickForm_RuleRegistry
|
||||
*
|
||||
* Usually, only one RuleRegistry object is needed, this is the reason
|
||||
* why it is recommended to use this method to get the validation object.
|
||||
*
|
||||
* @access public
|
||||
* @static
|
||||
* @return HTML_QuickForm_RuleRegistry
|
||||
*/
|
||||
function &singleton()
|
||||
{
|
||||
static $obj;
|
||||
if (!isset($obj)) {
|
||||
$obj = new HTML_QuickForm_RuleRegistry();
|
||||
}
|
||||
return $obj;
|
||||
} // end func singleton
|
||||
|
||||
/**
|
||||
* Registers a new validation rule
|
||||
*
|
||||
* In order to use a custom rule in your form, you need to register it
|
||||
* first. For regular expressions, one can directly use the 'regex' type
|
||||
* rule in addRule(), this is faster than registering the rule.
|
||||
*
|
||||
* Functions and methods can be registered. Use the 'function' type.
|
||||
* When registering a method, specify the class name as second parameter.
|
||||
*
|
||||
* You can also register an HTML_QuickForm_Rule subclass with its own
|
||||
* validate() method.
|
||||
*
|
||||
* @param string $ruleName Name of validation rule
|
||||
* @param string $type Either: 'regex', 'function' or null
|
||||
* @param string $data1 Name of function, regular expression or
|
||||
* HTML_QuickForm_Rule object class name
|
||||
* @param string $data2 Object parent of above function or HTML_QuickForm_Rule file path
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function registerRule($ruleName, $type, $data1, $data2 = null)
|
||||
{
|
||||
$type = strtolower($type);
|
||||
if ($type == 'regex') {
|
||||
// Regular expression
|
||||
$rule =& $this->getRule('regex');
|
||||
$rule->addData($ruleName, $data1);
|
||||
$GLOBALS['_HTML_QuickForm_registered_rules'][$ruleName] = $GLOBALS['_HTML_QuickForm_registered_rules']['regex'];
|
||||
|
||||
} elseif ($type == 'function' || $type == 'callback') {
|
||||
// Callback function
|
||||
$rule =& $this->getRule('callback');
|
||||
$rule->addData($ruleName, $data1, $data2, 'function' == $type);
|
||||
$GLOBALS['_HTML_QuickForm_registered_rules'][$ruleName] = $GLOBALS['_HTML_QuickForm_registered_rules']['callback'];
|
||||
|
||||
} elseif (is_object($data1)) {
|
||||
// An instance of HTML_QuickForm_Rule
|
||||
$this->_rules[strtolower(get_class($data1))] = $data1;
|
||||
$GLOBALS['_HTML_QuickForm_registered_rules'][$ruleName] = array(strtolower(get_class($data1)), null);
|
||||
|
||||
} else {
|
||||
// Rule class name
|
||||
$GLOBALS['_HTML_QuickForm_registered_rules'][$ruleName] = array(strtolower($data1), $data2);
|
||||
}
|
||||
} // end func registerRule
|
||||
|
||||
/**
|
||||
* Returns a reference to the requested rule object
|
||||
*
|
||||
* @param string $ruleName Name of the requested rule
|
||||
* @access public
|
||||
* @return HTML_QuickForm_Rule
|
||||
*/
|
||||
function &getRule($ruleName)
|
||||
{
|
||||
list($class, $path) = $GLOBALS['_HTML_QuickForm_registered_rules'][$ruleName];
|
||||
|
||||
if (!isset($this->_rules[$class])) {
|
||||
if (!empty($path)) {
|
||||
include_once($path);
|
||||
}
|
||||
$this->_rules[$class] =& new $class();
|
||||
}
|
||||
$this->_rules[$class]->setName($ruleName);
|
||||
return $this->_rules[$class];
|
||||
} // end func getRule
|
||||
|
||||
/**
|
||||
* Performs validation on the given values
|
||||
*
|
||||
* @param string $ruleName Name of the rule to be used
|
||||
* @param mixed $values Can be a scalar or an array of values
|
||||
* to be validated
|
||||
* @param mixed $options Options used by the rule
|
||||
* @param mixed $multiple Whether to validate an array of values altogether
|
||||
* @access public
|
||||
* @return mixed true if no error found, int of valid values (when an array of values is given) or false if error
|
||||
*/
|
||||
function validate($ruleName, $values, $options = null, $multiple = false)
|
||||
{
|
||||
$rule =& $this->getRule($ruleName);
|
||||
|
||||
if (is_array($values) && !$multiple) {
|
||||
$result = 0;
|
||||
foreach ($values as $value) {
|
||||
if ($rule->validate($value, $options) === true) {
|
||||
$result++;
|
||||
}
|
||||
}
|
||||
return ($result == 0) ? false : $result;
|
||||
} else {
|
||||
return $rule->validate($values, $options);
|
||||
}
|
||||
} // end func validate
|
||||
|
||||
/**
|
||||
* Returns the validation test in javascript code
|
||||
*
|
||||
* @param array|HTML_QuickForm_element Element(s) the rule applies to
|
||||
* @param string Element name, in case $element is
|
||||
* not an array
|
||||
* @param array Rule data
|
||||
* @access public
|
||||
* @return string JavaScript for the rule
|
||||
*/
|
||||
function getValidationScript(&$element, $elementName, $ruleData)
|
||||
{
|
||||
$reset = (isset($ruleData['reset'])) ? $ruleData['reset'] : false;
|
||||
$rule =& $this->getRule($ruleData['type']);
|
||||
if (!is_array($element)) {
|
||||
list($jsValue, $jsReset) = $this->_getJsValue($element, $elementName, $reset, null);
|
||||
} else {
|
||||
$jsValue = " value = new Array();\n";
|
||||
$jsReset = '';
|
||||
for ($i = 0; $i < count($element); $i++) {
|
||||
list($tmp_value, $tmp_reset) = $this->_getJsValue($element[$i], $element[$i]->getName(), $reset, $i);
|
||||
$jsValue .= "\n" . $tmp_value;
|
||||
$jsReset .= $tmp_reset;
|
||||
}
|
||||
}
|
||||
$jsField = isset($ruleData['group'])? $ruleData['group']: $elementName;
|
||||
list ($jsPrefix, $jsCheck) = $rule->getValidationScript($ruleData['format']);
|
||||
if (!isset($ruleData['howmany'])) {
|
||||
$js = $jsValue . "\n" . $jsPrefix .
|
||||
" if (" . str_replace('{jsVar}', 'value', $jsCheck) . " && !errFlag['{$jsField}']) {\n" .
|
||||
" errFlag['{$jsField}'] = true;\n" .
|
||||
" _qfMsg = _qfMsg + '\\n - {$ruleData['message']}';\n" .
|
||||
$jsReset .
|
||||
" }\n";
|
||||
} else {
|
||||
$js = $jsValue . "\n" . $jsPrefix .
|
||||
" var res = 0;\n" .
|
||||
" for (var i = 0; i < value.length; i++) {\n" .
|
||||
" if (!(" . str_replace('{jsVar}', 'value[i]', $jsCheck) . ")) {\n" .
|
||||
" res++;\n" .
|
||||
" }\n" .
|
||||
" }\n" .
|
||||
" if (res < {$ruleData['howmany']} && !errFlag['{$jsField}']) {\n" .
|
||||
" errFlag['{$jsField}'] = true;\n" .
|
||||
" _qfMsg = _qfMsg + '\\n - {$ruleData['message']}';\n" .
|
||||
$jsReset .
|
||||
" }\n";
|
||||
}
|
||||
return $js;
|
||||
} // end func getValidationScript
|
||||
|
||||
|
||||
/**
|
||||
* Returns JavaScript to get and to reset the element's value
|
||||
*
|
||||
* @access private
|
||||
* @param HTML_QuickForm_element element being processed
|
||||
* @param string element's name
|
||||
* @param bool whether to generate JavaScript to reset
|
||||
* the value
|
||||
* @param integer value's index in the array (only used for
|
||||
* multielement rules)
|
||||
* @return array first item is value javascript, second is reset
|
||||
*/
|
||||
function _getJsValue(&$element, $elementName, $reset = false, $index = null)
|
||||
{
|
||||
$jsIndex = isset($index)? '[' . $index . ']': '';
|
||||
$tmp_reset = $reset? " var field = frm.elements['$elementName'];\n": '';
|
||||
if (is_a($element, 'html_quickform_group')) {
|
||||
$value = " _qfGroups['{$elementName}'] = {";
|
||||
$elements =& $element->getElements();
|
||||
for ($i = 0, $count = count($elements); $i < $count; $i++) {
|
||||
$append = ($elements[$i]->getType() == 'select' && $elements[$i]->getMultiple())? '[]': '';
|
||||
$value .= "'" . $element->getElementName($i) . $append . "': true" .
|
||||
($i < $count - 1? ', ': '');
|
||||
}
|
||||
$value .=
|
||||
"};\n" .
|
||||
" value{$jsIndex} = new Array();\n" .
|
||||
" var valueIdx = 0;\n" .
|
||||
" for (var i = 0; i < frm.elements.length; i++) {\n" .
|
||||
" var _element = frm.elements[i];\n" .
|
||||
" if (_element.name in _qfGroups['{$elementName}']) {\n" .
|
||||
" switch (_element.type) {\n" .
|
||||
" case 'checkbox':\n" .
|
||||
" case 'radio':\n" .
|
||||
" if (_element.checked) {\n" .
|
||||
" value{$jsIndex}[valueIdx++] = _element.value;\n" .
|
||||
" }\n" .
|
||||
" break;\n" .
|
||||
" case 'select-one':\n" .
|
||||
" if (-1 != _element.selectedIndex) {\n" .
|
||||
" value{$jsIndex}[valueIdx++] = _element.options[_element.selectedIndex].value;\n" .
|
||||
" }\n" .
|
||||
" break;\n" .
|
||||
" case 'select-multiple':\n" .
|
||||
" var tmpVal = new Array();\n" .
|
||||
" var tmpIdx = 0;\n" .
|
||||
" for (var j = 0; j < _element.options.length; j++) {\n" .
|
||||
" if (_element.options[j].selected) {\n" .
|
||||
" tmpVal[tmpIdx++] = _element.options[j].value;\n" .
|
||||
" }\n" .
|
||||
" }\n" .
|
||||
" if (tmpIdx > 0) {\n" .
|
||||
" value{$jsIndex}[valueIdx++] = tmpVal;\n" .
|
||||
" }\n" .
|
||||
" break;\n" .
|
||||
" default:\n" .
|
||||
" value{$jsIndex}[valueIdx++] = _element.value;\n" .
|
||||
" }\n" .
|
||||
" }\n" .
|
||||
" }\n";
|
||||
if ($reset) {
|
||||
$tmp_reset =
|
||||
" for (var i = 0; i < frm.elements.length; i++) {\n" .
|
||||
" var _element = frm.elements[i];\n" .
|
||||
" if (_element.name in _qfGroups['{$elementName}']) {\n" .
|
||||
" switch (_element.type) {\n" .
|
||||
" case 'checkbox':\n" .
|
||||
" case 'radio':\n" .
|
||||
" _element.checked = _element.defaultChecked;\n" .
|
||||
" break;\n" .
|
||||
" case 'select-one':\n" .
|
||||
" case 'select-multiple':\n" .
|
||||
" for (var j = 0; j < _element.options.length; j++) {\n" .
|
||||
" _element.options[j].selected = _element.options[j].defaultSelected;\n" .
|
||||
" }\n" .
|
||||
" break;\n" .
|
||||
" default:\n" .
|
||||
" _element.value = _element.defaultValue;\n" .
|
||||
" }\n" .
|
||||
" }\n" .
|
||||
" }\n";
|
||||
}
|
||||
|
||||
} elseif ($element->getType() == 'select') {
|
||||
if ($element->getMultiple()) {
|
||||
$elementName .= '[]';
|
||||
$value =
|
||||
" value{$jsIndex} = new Array();\n" .
|
||||
" var valueIdx = 0;\n" .
|
||||
" for (var i = 0; i < frm.elements['{$elementName}'].options.length; i++) {\n" .
|
||||
" if (frm.elements['{$elementName}'].options[i].selected) {\n" .
|
||||
" value{$jsIndex}[valueIdx++] = frm.elements['{$elementName}'].options[i].value;\n" .
|
||||
" }\n" .
|
||||
" }\n";
|
||||
} else {
|
||||
$value = " value{$jsIndex} = frm.elements['{$elementName}'].selectedIndex == -1? '': frm.elements['{$elementName}'].options[frm.elements['{$elementName}'].selectedIndex].value;\n";
|
||||
}
|
||||
if ($reset) {
|
||||
$tmp_reset .=
|
||||
" for (var i = 0; i < field.options.length; i++) {\n" .
|
||||
" field.options[i].selected = field.options[i].defaultSelected;\n" .
|
||||
" }\n";
|
||||
}
|
||||
|
||||
} elseif ($element->getType() == 'checkbox') {
|
||||
if (is_a($element, 'html_quickform_advcheckbox')) {
|
||||
$value = " value{$jsIndex} = frm.elements['$elementName'][1].checked? frm.elements['$elementName'][1].value: frm.elements['$elementName'][0].value;\n";
|
||||
$tmp_reset .= $reset ? " field[1].checked = field[1].defaultChecked;\n" : '';
|
||||
} else {
|
||||
$value = " value{$jsIndex} = frm.elements['$elementName'].checked? '1': '';\n";
|
||||
$tmp_reset .= $reset ? " field.checked = field.defaultChecked;\n" : '';
|
||||
}
|
||||
|
||||
} elseif ($element->getType() == 'radio') {
|
||||
$value = " value{$jsIndex} = '';\n" .
|
||||
// Fix for bug #5644
|
||||
" var els = 'length' in frm.elements['$elementName']? frm.elements['$elementName']: [ frm.elements['$elementName'] ];\n" .
|
||||
" for (var i = 0; i < els.length; i++) {\n" .
|
||||
" if (els[i].checked) {\n" .
|
||||
" value{$jsIndex} = els[i].value;\n" .
|
||||
" }\n" .
|
||||
" }";
|
||||
if ($reset) {
|
||||
$tmp_reset .= " for (var i = 0; i < field.length; i++) {\n" .
|
||||
" field[i].checked = field[i].defaultChecked;\n" .
|
||||
" }";
|
||||
}
|
||||
|
||||
} else {
|
||||
$value = " value{$jsIndex} = frm.elements['$elementName'].value;";
|
||||
$tmp_reset .= ($reset) ? " field.value = field.defaultValue;\n" : '';
|
||||
}
|
||||
return array($value, $tmp_reset);
|
||||
}
|
||||
} // end class HTML_QuickForm_RuleRegistry
|
||||
?>
|
||||
|
|
|
@ -1,277 +1,286 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4.0 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Adam Daniel <adaniel1@eesus.jnj.com> |
|
||||
// | Bertrand Mansion <bmansion@mamasam.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: advcheckbox.php,v 1.16 2006/06/20 16:33:06 avb Exp $
|
||||
|
||||
require_once('HTML/QuickForm/checkbox.php');
|
||||
|
||||
/**
|
||||
* HTML class for an advanced checkbox type field
|
||||
*
|
||||
* Basically this fixes a problem that HTML has had
|
||||
* where checkboxes can only pass a single value (the
|
||||
* value of the checkbox when checked). A value for when
|
||||
* the checkbox is not checked cannot be passed, and
|
||||
* furthermore the checkbox variable doesn't even exist if
|
||||
* the checkbox was submitted unchecked.
|
||||
*
|
||||
* It works by prepending a hidden field with the same name and
|
||||
* another "unchecked" value to the checbox. If the checkbox is
|
||||
* checked, PHP overwrites the value of the hidden field with
|
||||
* its value.
|
||||
*
|
||||
* @author Jason Rust <jrust@php.net>
|
||||
* @since 2.0
|
||||
* @access public
|
||||
*/
|
||||
class HTML_QuickForm_advcheckbox extends HTML_QuickForm_checkbox
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* The values passed by the hidden elment
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_values = null;
|
||||
|
||||
/**
|
||||
* The default value
|
||||
*
|
||||
* @var boolean
|
||||
* @access private
|
||||
*/
|
||||
var $_currentValue = null;
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $elementName (optional)Input field name attribute
|
||||
* @param string $elementLabel (optional)Input field label
|
||||
* @param string $text (optional)Text to put after the checkbox
|
||||
* @param mixed $attributes (optional)Either a typical HTML attribute string
|
||||
* or an associative array
|
||||
* @param mixed $values (optional)Values to pass if checked or not checked
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function HTML_QuickForm_advcheckbox($elementName=null, $elementLabel=null, $text=null, $attributes=null, $values=null)
|
||||
{
|
||||
$this->HTML_QuickForm_checkbox($elementName, $elementLabel, $text, $attributes);
|
||||
$this->setValues($values);
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ getPrivateName()
|
||||
|
||||
/**
|
||||
* Gets the private name for the element
|
||||
*
|
||||
* @param string $elementName The element name to make private
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*
|
||||
* @deprecated Deprecated since 3.2.6, both generated elements have the same name
|
||||
*/
|
||||
function getPrivateName($elementName)
|
||||
{
|
||||
return '__'.$elementName;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getOnclickJs()
|
||||
|
||||
/**
|
||||
* Create the javascript for the onclick event which will
|
||||
* set the value of the hidden field
|
||||
*
|
||||
* @param string $elementName The element name
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*
|
||||
* @deprecated Deprecated since 3.2.6, this element no longer uses any javascript
|
||||
*/
|
||||
function getOnclickJs($elementName)
|
||||
{
|
||||
$onclickJs = 'if (this.checked) { this.form[\''.$elementName.'\'].value=\''.addcslashes($this->_values[1], '\'').'\'; }';
|
||||
$onclickJs .= 'else { this.form[\''.$elementName.'\'].value=\''.addcslashes($this->_values[0], '\'').'\'; }';
|
||||
return $onclickJs;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ setValues()
|
||||
|
||||
/**
|
||||
* Sets the values used by the hidden element
|
||||
*
|
||||
* @param mixed $values The values, either a string or an array
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setValues($values)
|
||||
{
|
||||
if (empty($values)) {
|
||||
// give it default checkbox behavior
|
||||
$this->_values = array('', 1);
|
||||
} elseif (is_scalar($values)) {
|
||||
// if it's string, then assume the value to
|
||||
// be passed is for when the element is checked
|
||||
$this->_values = array('', $values);
|
||||
} else {
|
||||
$this->_values = $values;
|
||||
}
|
||||
$this->updateAttributes(array('value' => $this->_values[1]));
|
||||
$this->setChecked($this->_currentValue == $this->_values[1]);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ setValue()
|
||||
|
||||
/**
|
||||
* Sets the element's value
|
||||
*
|
||||
* @param mixed Element's value
|
||||
* @access public
|
||||
*/
|
||||
function setValue($value)
|
||||
{
|
||||
$this->setChecked(isset($this->_values[1]) && $value == $this->_values[1]);
|
||||
$this->_currentValue = $value;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getValue()
|
||||
|
||||
/**
|
||||
* Returns the element's value
|
||||
*
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
function getValue()
|
||||
{
|
||||
if (is_array($this->_values)) {
|
||||
return $this->_values[$this->getChecked()? 1: 0];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ toHtml()
|
||||
|
||||
/**
|
||||
* Returns the checkbox element in HTML
|
||||
* and the additional hidden element in HTML
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function toHtml()
|
||||
{
|
||||
if ($this->_flagFrozen) {
|
||||
return parent::toHtml();
|
||||
} else {
|
||||
return '<input' . $this->_getAttrString(array(
|
||||
'type' => 'hidden',
|
||||
'name' => $this->getName(),
|
||||
'value' => $this->_values[0]
|
||||
)) . ' />' . parent::toHtml();
|
||||
|
||||
}
|
||||
} //end func toHtml
|
||||
|
||||
// }}}
|
||||
// {{{ getFrozenHtml()
|
||||
|
||||
/**
|
||||
* Unlike checkbox, this has to append a hidden input in both
|
||||
* checked and non-checked states
|
||||
*/
|
||||
function getFrozenHtml()
|
||||
{
|
||||
return ($this->getChecked()? '<tt>[x]</tt>': '<tt>[ ]</tt>') .
|
||||
$this->_getPersistantData();
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ onQuickFormEvent()
|
||||
|
||||
/**
|
||||
* Called by HTML_QuickForm whenever form event is made on this element
|
||||
*
|
||||
* @param string $event Name of event
|
||||
* @param mixed $arg event arguments
|
||||
* @param object $caller calling object
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function onQuickFormEvent($event, $arg, &$caller)
|
||||
{
|
||||
switch ($event) {
|
||||
case 'updateValue':
|
||||
// constant values override both default and submitted ones
|
||||
// default values are overriden by submitted
|
||||
$value = $this->_findValue($caller->_constantValues);
|
||||
if (null === $value) {
|
||||
$value = $this->_findValue($caller->_submitValues);
|
||||
if (null === $value) {
|
||||
$value = $this->_findValue($caller->_defaultValues);
|
||||
}
|
||||
}
|
||||
if (null !== $value) {
|
||||
$this->setValue($value);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parent::onQuickFormEvent($event, $arg, $caller);
|
||||
}
|
||||
return true;
|
||||
} // end func onQuickFormLoad
|
||||
|
||||
// }}}
|
||||
// {{{ exportValue()
|
||||
|
||||
/**
|
||||
* This element has a value even if it is not checked, thus we override
|
||||
* checkbox's behaviour here
|
||||
*/
|
||||
function exportValue(&$submitValues, $assoc)
|
||||
{
|
||||
$value = $this->_findValue($submitValues);
|
||||
if (null === $value) {
|
||||
$value = $this->getValue();
|
||||
} elseif (is_array($this->_values) && ($value != $this->_values[0]) && ($value != $this->_values[1])) {
|
||||
$value = null;
|
||||
}
|
||||
return $this->_prepareValue($value, $assoc);
|
||||
}
|
||||
// }}}
|
||||
} //end class HTML_QuickForm_advcheckbox
|
||||
?>
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* HTML class for an advanced checkbox type field
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Jason Rust <jrust@php.net>
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: advcheckbox.php,v 1.18 2009/04/04 21:34:02 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* HTML class for a checkbox type field
|
||||
*/
|
||||
require_once 'HTML/QuickForm/checkbox.php';
|
||||
|
||||
/**
|
||||
* HTML class for an advanced checkbox type field
|
||||
*
|
||||
* Basically this fixes a problem that HTML has had
|
||||
* where checkboxes can only pass a single value (the
|
||||
* value of the checkbox when checked). A value for when
|
||||
* the checkbox is not checked cannot be passed, and
|
||||
* furthermore the checkbox variable doesn't even exist if
|
||||
* the checkbox was submitted unchecked.
|
||||
*
|
||||
* It works by prepending a hidden field with the same name and
|
||||
* another "unchecked" value to the checbox. If the checkbox is
|
||||
* checked, PHP overwrites the value of the hidden field with
|
||||
* its value.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Jason Rust <jrust@php.net>
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @version Release: 3.2.11
|
||||
* @since 2.0
|
||||
*/
|
||||
class HTML_QuickForm_advcheckbox extends HTML_QuickForm_checkbox
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* The values passed by the hidden elment
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_values = null;
|
||||
|
||||
/**
|
||||
* The default value
|
||||
*
|
||||
* @var boolean
|
||||
* @access private
|
||||
*/
|
||||
var $_currentValue = null;
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $elementName (optional)Input field name attribute
|
||||
* @param string $elementLabel (optional)Input field label
|
||||
* @param string $text (optional)Text to put after the checkbox
|
||||
* @param mixed $attributes (optional)Either a typical HTML attribute string
|
||||
* or an associative array
|
||||
* @param mixed $values (optional)Values to pass if checked or not checked
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function HTML_QuickForm_advcheckbox($elementName=null, $elementLabel=null, $text=null, $attributes=null, $values=null)
|
||||
{
|
||||
$this->HTML_QuickForm_checkbox($elementName, $elementLabel, $text, $attributes);
|
||||
$this->setValues($values);
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ getPrivateName()
|
||||
|
||||
/**
|
||||
* Gets the private name for the element
|
||||
*
|
||||
* @param string $elementName The element name to make private
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*
|
||||
* @deprecated Deprecated since 3.2.6, both generated elements have the same name
|
||||
*/
|
||||
function getPrivateName($elementName)
|
||||
{
|
||||
return '__'.$elementName;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getOnclickJs()
|
||||
|
||||
/**
|
||||
* Create the javascript for the onclick event which will
|
||||
* set the value of the hidden field
|
||||
*
|
||||
* @param string $elementName The element name
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*
|
||||
* @deprecated Deprecated since 3.2.6, this element no longer uses any javascript
|
||||
*/
|
||||
function getOnclickJs($elementName)
|
||||
{
|
||||
$onclickJs = 'if (this.checked) { this.form[\''.$elementName.'\'].value=\''.addcslashes($this->_values[1], '\'').'\'; }';
|
||||
$onclickJs .= 'else { this.form[\''.$elementName.'\'].value=\''.addcslashes($this->_values[0], '\'').'\'; }';
|
||||
return $onclickJs;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ setValues()
|
||||
|
||||
/**
|
||||
* Sets the values used by the hidden element
|
||||
*
|
||||
* @param mixed $values The values, either a string or an array
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setValues($values)
|
||||
{
|
||||
if (empty($values)) {
|
||||
// give it default checkbox behavior
|
||||
$this->_values = array('', 1);
|
||||
} elseif (is_scalar($values)) {
|
||||
// if it's string, then assume the value to
|
||||
// be passed is for when the element is checked
|
||||
$this->_values = array('', $values);
|
||||
} else {
|
||||
$this->_values = $values;
|
||||
}
|
||||
$this->updateAttributes(array('value' => $this->_values[1]));
|
||||
$this->setChecked($this->_currentValue == $this->_values[1]);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ setValue()
|
||||
|
||||
/**
|
||||
* Sets the element's value
|
||||
*
|
||||
* @param mixed Element's value
|
||||
* @access public
|
||||
*/
|
||||
function setValue($value)
|
||||
{
|
||||
$this->setChecked(isset($this->_values[1]) && $value == $this->_values[1]);
|
||||
$this->_currentValue = $value;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getValue()
|
||||
|
||||
/**
|
||||
* Returns the element's value
|
||||
*
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
function getValue()
|
||||
{
|
||||
if (is_array($this->_values)) {
|
||||
return $this->_values[$this->getChecked()? 1: 0];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ toHtml()
|
||||
|
||||
/**
|
||||
* Returns the checkbox element in HTML
|
||||
* and the additional hidden element in HTML
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function toHtml()
|
||||
{
|
||||
if ($this->_flagFrozen) {
|
||||
return parent::toHtml();
|
||||
} else {
|
||||
return '<input' . $this->_getAttrString(array(
|
||||
'type' => 'hidden',
|
||||
'name' => $this->getName(),
|
||||
'value' => $this->_values[0]
|
||||
)) . ' />' . parent::toHtml();
|
||||
|
||||
}
|
||||
} //end func toHtml
|
||||
|
||||
// }}}
|
||||
// {{{ getFrozenHtml()
|
||||
|
||||
/**
|
||||
* Unlike checkbox, this has to append a hidden input in both
|
||||
* checked and non-checked states
|
||||
*/
|
||||
function getFrozenHtml()
|
||||
{
|
||||
return ($this->getChecked()? '<tt>[x]</tt>': '<tt>[ ]</tt>') .
|
||||
$this->_getPersistantData();
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ onQuickFormEvent()
|
||||
|
||||
/**
|
||||
* Called by HTML_QuickForm whenever form event is made on this element
|
||||
*
|
||||
* @param string $event Name of event
|
||||
* @param mixed $arg event arguments
|
||||
* @param object &$caller calling object
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function onQuickFormEvent($event, $arg, &$caller)
|
||||
{
|
||||
switch ($event) {
|
||||
case 'updateValue':
|
||||
// constant values override both default and submitted ones
|
||||
// default values are overriden by submitted
|
||||
$value = $this->_findValue($caller->_constantValues);
|
||||
if (null === $value) {
|
||||
$value = $this->_findValue($caller->_submitValues);
|
||||
if (null === $value) {
|
||||
$value = $this->_findValue($caller->_defaultValues);
|
||||
}
|
||||
}
|
||||
if (null !== $value) {
|
||||
$this->setValue($value);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parent::onQuickFormEvent($event, $arg, $caller);
|
||||
}
|
||||
return true;
|
||||
} // end func onQuickFormLoad
|
||||
|
||||
// }}}
|
||||
// {{{ exportValue()
|
||||
|
||||
/**
|
||||
* This element has a value even if it is not checked, thus we override
|
||||
* checkbox's behaviour here
|
||||
*/
|
||||
function exportValue(&$submitValues, $assoc)
|
||||
{
|
||||
$value = $this->_findValue($submitValues);
|
||||
if (null === $value) {
|
||||
$value = $this->getValue();
|
||||
} elseif (is_array($this->_values) && ($value != $this->_values[0]) && ($value != $this->_values[1])) {
|
||||
$value = null;
|
||||
}
|
||||
return $this->_prepareValue($value, $assoc);
|
||||
}
|
||||
// }}}
|
||||
} //end class HTML_QuickForm_advcheckbox
|
||||
?>
|
||||
|
|
|
@ -1,249 +1,258 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Matteo Di Giovinazzo <matteodg@infinito.it> |
|
||||
// | |
|
||||
// | For the JavaScript code thanks to Martin Honnen and |
|
||||
// | Nicholas C. Zakas |
|
||||
// | See: |
|
||||
// | http://www.faqts.com/knowledge_base/view.phtml/aid/13562 |
|
||||
// | and |
|
||||
// | http://www.sitepoint.com/article/1220 |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: autocomplete.php,v 1.6 2005/08/05 16:33:56 avb Exp $
|
||||
|
||||
|
||||
require_once("HTML/QuickForm/text.php");
|
||||
|
||||
|
||||
/**
|
||||
* Class to dynamically create an HTML input text element that
|
||||
* at every keypressed javascript event, check in an array of options
|
||||
* if there's a match and autocomplete the text in case of match.
|
||||
*
|
||||
* Ex:
|
||||
* $autocomplete =& $form->addElement('autocomplete', 'fruit', 'Favourite fruit:');
|
||||
* $options = array("Apple", "Orange", "Pear", "Strawberry");
|
||||
* $autocomplete->setOptions($options);
|
||||
*
|
||||
* @author Matteo Di Giovinazzo <matteodg@infinito.it>
|
||||
*/
|
||||
class HTML_QuickForm_autocomplete extends HTML_QuickForm_text
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* Options for the autocomplete input text element
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_options = array();
|
||||
|
||||
/**
|
||||
* "One-time" javascript (containing functions), see bug #4611
|
||||
*
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_js = '';
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $elementName (optional)Input field name attribute
|
||||
* @param string $elementLabel (optional)Input field label in form
|
||||
* @param array $options (optional)Autocomplete options
|
||||
* @param mixed $attributes (optional)Either a typical HTML attribute string
|
||||
* or an associative array. Date format is passed along the attributes.
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function HTML_QuickForm_autocomplete($elementName = null, $elementLabel = null, $options = null, $attributes = null)
|
||||
{
|
||||
$this->HTML_QuickForm_text($elementName, $elementLabel, $attributes);
|
||||
$this->_persistantFreeze = true;
|
||||
$this->_type = 'autocomplete';
|
||||
if (isset($options)) {
|
||||
$this->setOptions($options);
|
||||
}
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ setOptions()
|
||||
|
||||
/**
|
||||
* Sets the options for the autocomplete input text element
|
||||
*
|
||||
* @param array $options Array of options for the autocomplete input text element
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setOptions($options)
|
||||
{
|
||||
$this->_options = array_values($options);
|
||||
} // end func setOptions
|
||||
|
||||
// }}}
|
||||
// {{{ toHtml()
|
||||
|
||||
/**
|
||||
* Returns Html for the autocomplete input text element
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function toHtml()
|
||||
{
|
||||
// prevent problems with grouped elements
|
||||
$arrayName = str_replace(array('[', ']'), array('__', ''), $this->getName()) . '_values';
|
||||
|
||||
$this->updateAttributes(array(
|
||||
'onkeypress' => 'return autocomplete(this, event, ' . $arrayName . ');'
|
||||
));
|
||||
if ($this->_flagFrozen) {
|
||||
$js = '';
|
||||
} else {
|
||||
$js = "<script type=\"text/javascript\">\n//<![CDATA[\n";
|
||||
if (!defined('HTML_QUICKFORM_AUTOCOMPLETE_EXISTS')) {
|
||||
$this->_js .= <<<EOS
|
||||
|
||||
/* begin javascript for autocomplete */
|
||||
function setSelectionRange(input, selectionStart, selectionEnd) {
|
||||
if (input.setSelectionRange) {
|
||||
input.setSelectionRange(selectionStart, selectionEnd);
|
||||
}
|
||||
else if (input.createTextRange) {
|
||||
var range = input.createTextRange();
|
||||
range.collapse(true);
|
||||
range.moveEnd("character", selectionEnd);
|
||||
range.moveStart("character", selectionStart);
|
||||
range.select();
|
||||
}
|
||||
input.focus();
|
||||
}
|
||||
|
||||
function setCaretToPosition(input, position) {
|
||||
setSelectionRange(input, position, position);
|
||||
}
|
||||
|
||||
function replaceSelection (input, replaceString) {
|
||||
var len = replaceString.length;
|
||||
if (input.setSelectionRange) {
|
||||
var selectionStart = input.selectionStart;
|
||||
var selectionEnd = input.selectionEnd;
|
||||
|
||||
input.value = input.value.substring(0, selectionStart) + replaceString + input.value.substring(selectionEnd);
|
||||
input.selectionStart = selectionStart + len;
|
||||
input.selectionEnd = selectionStart + len;
|
||||
}
|
||||
else if (document.selection) {
|
||||
var range = document.selection.createRange();
|
||||
var saved_range = range.duplicate();
|
||||
|
||||
if (range.parentElement() == input) {
|
||||
range.text = replaceString;
|
||||
range.moveEnd("character", saved_range.selectionStart + len);
|
||||
range.moveStart("character", saved_range.selectionStart + len);
|
||||
range.select();
|
||||
}
|
||||
}
|
||||
input.focus();
|
||||
}
|
||||
|
||||
|
||||
function autocompleteMatch (text, values) {
|
||||
for (var i = 0; i < values.length; i++) {
|
||||
if (values[i].toUpperCase().indexOf(text.toUpperCase()) == 0) {
|
||||
return values[i];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function autocomplete(textbox, event, values) {
|
||||
if (textbox.setSelectionRange || textbox.createTextRange) {
|
||||
switch (event.keyCode) {
|
||||
case 38: // up arrow
|
||||
case 40: // down arrow
|
||||
case 37: // left arrow
|
||||
case 39: // right arrow
|
||||
case 33: // page up
|
||||
case 34: // page down
|
||||
case 36: // home
|
||||
case 35: // end
|
||||
case 13: // enter
|
||||
case 9: // tab
|
||||
case 27: // esc
|
||||
case 16: // shift
|
||||
case 17: // ctrl
|
||||
case 18: // alt
|
||||
case 20: // caps lock
|
||||
case 8: // backspace
|
||||
case 46: // delete
|
||||
return true;
|
||||
break;
|
||||
|
||||
default:
|
||||
var c = String.fromCharCode(
|
||||
(event.charCode == undefined) ? event.keyCode : event.charCode
|
||||
);
|
||||
replaceSelection(textbox, c);
|
||||
sMatch = autocompleteMatch(textbox.value, values);
|
||||
var len = textbox.value.length;
|
||||
|
||||
if (sMatch != null) {
|
||||
textbox.value = sMatch;
|
||||
setSelectionRange(textbox, len, textbox.value.length);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
/* end javascript for autocomplete */
|
||||
|
||||
EOS;
|
||||
define('HTML_QUICKFORM_AUTOCOMPLETE_EXISTS', true);
|
||||
}
|
||||
$jsEscape = array(
|
||||
"\r" => '\r',
|
||||
"\n" => '\n',
|
||||
"\t" => '\t',
|
||||
"'" => "\\'",
|
||||
'"' => '\"',
|
||||
'\\' => '\\\\'
|
||||
);
|
||||
|
||||
$js .= $this->_js;
|
||||
$js .= 'var ' . $arrayName . " = new Array();\n";
|
||||
for ($i = 0; $i < count($this->_options); $i++) {
|
||||
$js .= $arrayName . '[' . $i . "] = '" . strtr($this->_options[$i], $jsEscape) . "';\n";
|
||||
}
|
||||
$js .= "//]]>\n</script>";
|
||||
}
|
||||
return $js . parent::toHtml();
|
||||
}// end func toHtml
|
||||
|
||||
// }}}
|
||||
} // end class HTML_QuickForm_autocomplete
|
||||
?>
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* HTML class for an autocomplete element
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Matteo Di Giovinazzo <matteodg@infinito.it>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: autocomplete.php,v 1.8 2009/04/04 21:34:02 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* HTML class for a text field
|
||||
*/
|
||||
require_once 'HTML/QuickForm/text.php';
|
||||
|
||||
/**
|
||||
* HTML class for an autocomplete element
|
||||
*
|
||||
* Creates an HTML input text element that
|
||||
* at every keypressed javascript event checks in an array of options
|
||||
* if there's a match and autocompletes the text in case of match.
|
||||
*
|
||||
* For the JavaScript code thanks to Martin Honnen and Nicholas C. Zakas
|
||||
* See {@link http://www.faqts.com/knowledge_base/view.phtml/aid/13562} and
|
||||
* {@link http://www.sitepoint.com/article/1220}
|
||||
*
|
||||
* Example:
|
||||
* <code>
|
||||
* $autocomplete =& $form->addElement('autocomplete', 'fruit', 'Favourite fruit:');
|
||||
* $options = array("Apple", "Orange", "Pear", "Strawberry");
|
||||
* $autocomplete->setOptions($options);
|
||||
* </code>
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Matteo Di Giovinazzo <matteodg@infinito.it>
|
||||
* @version Release: 3.2.11
|
||||
* @since 3.2
|
||||
*/
|
||||
class HTML_QuickForm_autocomplete extends HTML_QuickForm_text
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* Options for the autocomplete input text element
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_options = array();
|
||||
|
||||
/**
|
||||
* "One-time" javascript (containing functions), see bug #4611
|
||||
*
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_js = '';
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $elementName (optional)Input field name attribute
|
||||
* @param string $elementLabel (optional)Input field label in form
|
||||
* @param array $options (optional)Autocomplete options
|
||||
* @param mixed $attributes (optional)Either a typical HTML attribute string
|
||||
* or an associative array. Date format is passed along the attributes.
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function HTML_QuickForm_autocomplete($elementName = null, $elementLabel = null, $options = null, $attributes = null)
|
||||
{
|
||||
$this->HTML_QuickForm_text($elementName, $elementLabel, $attributes);
|
||||
$this->_persistantFreeze = true;
|
||||
$this->_type = 'autocomplete';
|
||||
if (isset($options)) {
|
||||
$this->setOptions($options);
|
||||
}
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ setOptions()
|
||||
|
||||
/**
|
||||
* Sets the options for the autocomplete input text element
|
||||
*
|
||||
* @param array $options Array of options for the autocomplete input text element
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setOptions($options)
|
||||
{
|
||||
$this->_options = array_values($options);
|
||||
} // end func setOptions
|
||||
|
||||
// }}}
|
||||
// {{{ toHtml()
|
||||
|
||||
/**
|
||||
* Returns Html for the autocomplete input text element
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function toHtml()
|
||||
{
|
||||
// prevent problems with grouped elements
|
||||
$arrayName = str_replace(array('[', ']'), array('__', ''), $this->getName()) . '_values';
|
||||
|
||||
$this->updateAttributes(array(
|
||||
'onkeypress' => 'return autocomplete(this, event, ' . $arrayName . ');'
|
||||
));
|
||||
if ($this->_flagFrozen) {
|
||||
$js = '';
|
||||
} else {
|
||||
$js = "<script type=\"text/javascript\">\n//<![CDATA[\n";
|
||||
if (!defined('HTML_QUICKFORM_AUTOCOMPLETE_EXISTS')) {
|
||||
$this->_js .= <<<EOS
|
||||
|
||||
/* begin javascript for autocomplete */
|
||||
function setSelectionRange(input, selectionStart, selectionEnd) {
|
||||
if (input.setSelectionRange) {
|
||||
input.setSelectionRange(selectionStart, selectionEnd);
|
||||
}
|
||||
else if (input.createTextRange) {
|
||||
var range = input.createTextRange();
|
||||
range.collapse(true);
|
||||
range.moveEnd("character", selectionEnd);
|
||||
range.moveStart("character", selectionStart);
|
||||
range.select();
|
||||
}
|
||||
input.focus();
|
||||
}
|
||||
|
||||
function setCaretToPosition(input, position) {
|
||||
setSelectionRange(input, position, position);
|
||||
}
|
||||
|
||||
function replaceSelection (input, replaceString) {
|
||||
var len = replaceString.length;
|
||||
if (input.setSelectionRange) {
|
||||
var selectionStart = input.selectionStart;
|
||||
var selectionEnd = input.selectionEnd;
|
||||
|
||||
input.value = input.value.substring(0, selectionStart) + replaceString + input.value.substring(selectionEnd);
|
||||
input.selectionStart = selectionStart + len;
|
||||
input.selectionEnd = selectionStart + len;
|
||||
}
|
||||
else if (document.selection) {
|
||||
var range = document.selection.createRange();
|
||||
var saved_range = range.duplicate();
|
||||
|
||||
if (range.parentElement() == input) {
|
||||
range.text = replaceString;
|
||||
range.moveEnd("character", saved_range.selectionStart + len);
|
||||
range.moveStart("character", saved_range.selectionStart + len);
|
||||
range.select();
|
||||
}
|
||||
}
|
||||
input.focus();
|
||||
}
|
||||
|
||||
|
||||
function autocompleteMatch (text, values) {
|
||||
for (var i = 0; i < values.length; i++) {
|
||||
if (values[i].toUpperCase().indexOf(text.toUpperCase()) == 0) {
|
||||
return values[i];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function autocomplete(textbox, event, values) {
|
||||
if (textbox.setSelectionRange || textbox.createTextRange) {
|
||||
switch (event.keyCode) {
|
||||
case 38: // up arrow
|
||||
case 40: // down arrow
|
||||
case 37: // left arrow
|
||||
case 39: // right arrow
|
||||
case 33: // page up
|
||||
case 34: // page down
|
||||
case 36: // home
|
||||
case 35: // end
|
||||
case 13: // enter
|
||||
case 9: // tab
|
||||
case 27: // esc
|
||||
case 16: // shift
|
||||
case 17: // ctrl
|
||||
case 18: // alt
|
||||
case 20: // caps lock
|
||||
case 8: // backspace
|
||||
case 46: // delete
|
||||
return true;
|
||||
break;
|
||||
|
||||
default:
|
||||
var c = String.fromCharCode(
|
||||
(event.charCode == undefined) ? event.keyCode : event.charCode
|
||||
);
|
||||
replaceSelection(textbox, c);
|
||||
sMatch = autocompleteMatch(textbox.value, values);
|
||||
var len = textbox.value.length;
|
||||
|
||||
if (sMatch != null) {
|
||||
textbox.value = sMatch;
|
||||
setSelectionRange(textbox, len, textbox.value.length);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
/* end javascript for autocomplete */
|
||||
|
||||
EOS;
|
||||
define('HTML_QUICKFORM_AUTOCOMPLETE_EXISTS', true);
|
||||
}
|
||||
$jsEscape = array(
|
||||
"\r" => '\r',
|
||||
"\n" => '\n',
|
||||
"\t" => '\t',
|
||||
"'" => "\\'",
|
||||
'"' => '\"',
|
||||
'\\' => '\\\\'
|
||||
);
|
||||
|
||||
$js .= $this->_js;
|
||||
$js .= 'var ' . $arrayName . " = new Array();\n";
|
||||
for ($i = 0; $i < count($this->_options); $i++) {
|
||||
$js .= $arrayName . '[' . $i . "] = '" . strtr($this->_options[$i], $jsEscape) . "';\n";
|
||||
}
|
||||
$js .= "//]]>\n</script>";
|
||||
}
|
||||
return $js . parent::toHtml();
|
||||
}// end func toHtml
|
||||
|
||||
// }}}
|
||||
} // end class HTML_QuickForm_autocomplete
|
||||
?>
|
||||
|
|
|
@ -1,73 +1,80 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4.0 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Adam Daniel <adaniel1@eesus.jnj.com> |
|
||||
// | Bertrand Mansion <bmansion@mamasam.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: button.php,v 1.4 2003/06/18 19:36:20 avb Exp $
|
||||
|
||||
require_once("HTML/QuickForm/input.php");
|
||||
|
||||
/**
|
||||
* HTML class for a button type element
|
||||
*
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version 1.1
|
||||
* @since PHP4.04pl1
|
||||
* @access public
|
||||
*/
|
||||
class HTML_QuickForm_button extends HTML_QuickForm_input
|
||||
{
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $elementName (optional)Input field name attribute
|
||||
* @param string $value (optional)Input field value
|
||||
* @param mixed $attributes (optional)Either a typical HTML attribute string
|
||||
* or an associative array
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function HTML_QuickForm_button($elementName=null, $value=null, $attributes=null)
|
||||
{
|
||||
HTML_QuickForm_input::HTML_QuickForm_input($elementName, null, $attributes);
|
||||
$this->_persistantFreeze = false;
|
||||
$this->setValue($value);
|
||||
$this->setType('button');
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ freeze()
|
||||
|
||||
/**
|
||||
* Freeze the element so that only its value is returned
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function freeze()
|
||||
{
|
||||
return false;
|
||||
} //end func freeze
|
||||
|
||||
// }}}
|
||||
|
||||
} //end class HTML_QuickForm_button
|
||||
?>
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* HTML class for an <input type="button" /> elements
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: button.php,v 1.6 2009/04/04 21:34:02 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for <input /> form elements
|
||||
*/
|
||||
require_once 'HTML/QuickForm/input.php';
|
||||
|
||||
/**
|
||||
* HTML class for an <input type="button" /> elements
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 1.0
|
||||
*/
|
||||
class HTML_QuickForm_button extends HTML_QuickForm_input
|
||||
{
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $elementName (optional)Input field name attribute
|
||||
* @param string $value (optional)Input field value
|
||||
* @param mixed $attributes (optional)Either a typical HTML attribute string
|
||||
* or an associative array
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function HTML_QuickForm_button($elementName=null, $value=null, $attributes=null)
|
||||
{
|
||||
HTML_QuickForm_input::HTML_QuickForm_input($elementName, null, $attributes);
|
||||
$this->_persistantFreeze = false;
|
||||
$this->setValue($value);
|
||||
$this->setType('button');
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ freeze()
|
||||
|
||||
/**
|
||||
* Freeze the element so that only its value is returned
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function freeze()
|
||||
{
|
||||
return false;
|
||||
} //end func freeze
|
||||
|
||||
// }}}
|
||||
|
||||
} //end class HTML_QuickForm_button
|
||||
?>
|
||||
|
|
|
@ -1,268 +1,277 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4.0 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Adam Daniel <adaniel1@eesus.jnj.com> |
|
||||
// | Bertrand Mansion <bmansion@mamasam.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: checkbox.php,v 1.20 2005/07/22 17:30:51 avb Exp $
|
||||
|
||||
require_once("HTML/QuickForm/input.php");
|
||||
|
||||
/**
|
||||
* HTML class for a checkbox type field
|
||||
*
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version 1.1
|
||||
* @since PHP4.04pl1
|
||||
* @access public
|
||||
*/
|
||||
class HTML_QuickForm_checkbox extends HTML_QuickForm_input
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* Checkbox display text
|
||||
* @var string
|
||||
* @since 1.1
|
||||
* @access private
|
||||
*/
|
||||
var $_text = '';
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $elementName (optional)Input field name attribute
|
||||
* @param string $elementLabel (optional)Input field value
|
||||
* @param string $text (optional)Checkbox display text
|
||||
* @param mixed $attributes (optional)Either a typical HTML attribute string
|
||||
* or an associative array
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function HTML_QuickForm_checkbox($elementName=null, $elementLabel=null, $text='', $attributes=null)
|
||||
{
|
||||
HTML_QuickForm_input::HTML_QuickForm_input($elementName, $elementLabel, $attributes);
|
||||
$this->_persistantFreeze = true;
|
||||
$this->_text = $text;
|
||||
$this->setType('checkbox');
|
||||
$this->updateAttributes(array('value'=>1));
|
||||
$this->_generateId();
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ setChecked()
|
||||
|
||||
/**
|
||||
* Sets whether a checkbox is checked
|
||||
*
|
||||
* @param bool $checked Whether the field is checked or not
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setChecked($checked)
|
||||
{
|
||||
if (!$checked) {
|
||||
$this->removeAttribute('checked');
|
||||
} else {
|
||||
$this->updateAttributes(array('checked'=>'checked'));
|
||||
}
|
||||
} //end func setChecked
|
||||
|
||||
// }}}
|
||||
// {{{ getChecked()
|
||||
|
||||
/**
|
||||
* Returns whether a checkbox is checked
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
function getChecked()
|
||||
{
|
||||
return (bool)$this->getAttribute('checked');
|
||||
} //end func getChecked
|
||||
|
||||
// }}}
|
||||
// {{{ toHtml()
|
||||
|
||||
/**
|
||||
* Returns the checkbox element in HTML
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function toHtml()
|
||||
{
|
||||
if (0 == strlen($this->_text)) {
|
||||
$label = '';
|
||||
} elseif ($this->_flagFrozen) {
|
||||
$label = $this->_text;
|
||||
} else {
|
||||
$label = '<label for="' . $this->getAttribute('id') . '">' . $this->_text . '</label>';
|
||||
}
|
||||
return HTML_QuickForm_input::toHtml() . $label;
|
||||
} //end func toHtml
|
||||
|
||||
// }}}
|
||||
// {{{ getFrozenHtml()
|
||||
|
||||
/**
|
||||
* Returns the value of field without HTML tags
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getFrozenHtml()
|
||||
{
|
||||
if ($this->getChecked()) {
|
||||
return '<tt>[x]</tt>' .
|
||||
$this->_getPersistantData();
|
||||
} else {
|
||||
return '<tt>[ ]</tt>';
|
||||
}
|
||||
} //end func getFrozenHtml
|
||||
|
||||
// }}}
|
||||
// {{{ setText()
|
||||
|
||||
/**
|
||||
* Sets the checkbox text
|
||||
*
|
||||
* @param string $text
|
||||
* @since 1.1
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setText($text)
|
||||
{
|
||||
$this->_text = $text;
|
||||
} //end func setText
|
||||
|
||||
// }}}
|
||||
// {{{ getText()
|
||||
|
||||
/**
|
||||
* Returns the checkbox text
|
||||
*
|
||||
* @since 1.1
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getText()
|
||||
{
|
||||
return $this->_text;
|
||||
} //end func getText
|
||||
|
||||
// }}}
|
||||
// {{{ setValue()
|
||||
|
||||
/**
|
||||
* Sets the value of the form element
|
||||
*
|
||||
* @param string $value Default value of the form element
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setValue($value)
|
||||
{
|
||||
return $this->setChecked($value);
|
||||
} // end func setValue
|
||||
|
||||
// }}}
|
||||
// {{{ getValue()
|
||||
|
||||
/**
|
||||
* Returns the value of the form element
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
function getValue()
|
||||
{
|
||||
return $this->getChecked();
|
||||
} // end func getValue
|
||||
|
||||
// }}}
|
||||
// {{{ onQuickFormEvent()
|
||||
|
||||
/**
|
||||
* Called by HTML_QuickForm whenever form event is made on this element
|
||||
*
|
||||
* @param string $event Name of event
|
||||
* @param mixed $arg event arguments
|
||||
* @param object $caller calling object
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function onQuickFormEvent($event, $arg, &$caller)
|
||||
{
|
||||
switch ($event) {
|
||||
case 'updateValue':
|
||||
// constant values override both default and submitted ones
|
||||
// default values are overriden by submitted
|
||||
$value = $this->_findValue($caller->_constantValues);
|
||||
if (null === $value) {
|
||||
// if no boxes were checked, then there is no value in the array
|
||||
// yet we don't want to display default value in this case
|
||||
if ($caller->isSubmitted()) {
|
||||
$value = $this->_findValue($caller->_submitValues);
|
||||
} else {
|
||||
$value = $this->_findValue($caller->_defaultValues);
|
||||
}
|
||||
}
|
||||
if (null !== $value) {
|
||||
$this->setChecked($value);
|
||||
}
|
||||
break;
|
||||
case 'setGroupValue':
|
||||
$this->setChecked($arg);
|
||||
break;
|
||||
default:
|
||||
parent::onQuickFormEvent($event, $arg, $caller);
|
||||
}
|
||||
return true;
|
||||
} // end func onQuickFormEvent
|
||||
|
||||
// }}}
|
||||
// {{{ exportValue()
|
||||
|
||||
/**
|
||||
* Return true if the checkbox is checked, null if it is not checked (getValue() returns false)
|
||||
*/
|
||||
function exportValue(&$submitValues, $assoc = false)
|
||||
{
|
||||
$value = $this->_findValue($submitValues);
|
||||
if (null === $value) {
|
||||
$value = $this->getChecked()? true: null;
|
||||
}
|
||||
return $this->_prepareValue($value, $assoc);
|
||||
}
|
||||
|
||||
// }}}
|
||||
} //end class HTML_QuickForm_checkbox
|
||||
?>
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* HTML class for a checkbox type field
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: checkbox.php,v 1.23 2009/04/04 21:34:02 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for <input /> form elements
|
||||
*/
|
||||
require_once 'HTML/QuickForm/input.php';
|
||||
|
||||
/**
|
||||
* HTML class for a checkbox type field
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @version Release: 3.2.11
|
||||
* @since 1.0
|
||||
*/
|
||||
class HTML_QuickForm_checkbox extends HTML_QuickForm_input
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* Checkbox display text
|
||||
* @var string
|
||||
* @since 1.1
|
||||
* @access private
|
||||
*/
|
||||
var $_text = '';
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $elementName (optional)Input field name attribute
|
||||
* @param string $elementLabel (optional)Input field value
|
||||
* @param string $text (optional)Checkbox display text
|
||||
* @param mixed $attributes (optional)Either a typical HTML attribute string
|
||||
* or an associative array
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function HTML_QuickForm_checkbox($elementName=null, $elementLabel=null, $text='', $attributes=null)
|
||||
{
|
||||
HTML_QuickForm_input::HTML_QuickForm_input($elementName, $elementLabel, $attributes);
|
||||
$this->_persistantFreeze = true;
|
||||
$this->_text = $text;
|
||||
$this->setType('checkbox');
|
||||
$this->updateAttributes(array('value'=>1));
|
||||
$this->_generateId();
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ setChecked()
|
||||
|
||||
/**
|
||||
* Sets whether a checkbox is checked
|
||||
*
|
||||
* @param bool $checked Whether the field is checked or not
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setChecked($checked)
|
||||
{
|
||||
if (!$checked) {
|
||||
$this->removeAttribute('checked');
|
||||
} else {
|
||||
$this->updateAttributes(array('checked'=>'checked'));
|
||||
}
|
||||
} //end func setChecked
|
||||
|
||||
// }}}
|
||||
// {{{ getChecked()
|
||||
|
||||
/**
|
||||
* Returns whether a checkbox is checked
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
function getChecked()
|
||||
{
|
||||
return (bool)$this->getAttribute('checked');
|
||||
} //end func getChecked
|
||||
|
||||
// }}}
|
||||
// {{{ toHtml()
|
||||
|
||||
/**
|
||||
* Returns the checkbox element in HTML
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function toHtml()
|
||||
{
|
||||
if (0 == strlen($this->_text)) {
|
||||
$label = '';
|
||||
} elseif ($this->_flagFrozen) {
|
||||
$label = $this->_text;
|
||||
} else {
|
||||
$label = '<label for="' . $this->getAttribute('id') . '">' . $this->_text . '</label>';
|
||||
}
|
||||
return HTML_QuickForm_input::toHtml() . $label;
|
||||
} //end func toHtml
|
||||
|
||||
// }}}
|
||||
// {{{ getFrozenHtml()
|
||||
|
||||
/**
|
||||
* Returns the value of field without HTML tags
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getFrozenHtml()
|
||||
{
|
||||
if ($this->getChecked()) {
|
||||
return '<tt>[x]</tt>' .
|
||||
$this->_getPersistantData();
|
||||
} else {
|
||||
return '<tt>[ ]</tt>';
|
||||
}
|
||||
} //end func getFrozenHtml
|
||||
|
||||
// }}}
|
||||
// {{{ setText()
|
||||
|
||||
/**
|
||||
* Sets the checkbox text
|
||||
*
|
||||
* @param string $text
|
||||
* @since 1.1
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setText($text)
|
||||
{
|
||||
$this->_text = $text;
|
||||
} //end func setText
|
||||
|
||||
// }}}
|
||||
// {{{ getText()
|
||||
|
||||
/**
|
||||
* Returns the checkbox text
|
||||
*
|
||||
* @since 1.1
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getText()
|
||||
{
|
||||
return $this->_text;
|
||||
} //end func getText
|
||||
|
||||
// }}}
|
||||
// {{{ setValue()
|
||||
|
||||
/**
|
||||
* Sets the value of the form element
|
||||
*
|
||||
* @param string $value Default value of the form element
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setValue($value)
|
||||
{
|
||||
return $this->setChecked($value);
|
||||
} // end func setValue
|
||||
|
||||
// }}}
|
||||
// {{{ getValue()
|
||||
|
||||
/**
|
||||
* Returns the value of the form element
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
function getValue()
|
||||
{
|
||||
return $this->getChecked();
|
||||
} // end func getValue
|
||||
|
||||
// }}}
|
||||
// {{{ onQuickFormEvent()
|
||||
|
||||
/**
|
||||
* Called by HTML_QuickForm whenever form event is made on this element
|
||||
*
|
||||
* @param string $event Name of event
|
||||
* @param mixed $arg event arguments
|
||||
* @param object &$caller calling object
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function onQuickFormEvent($event, $arg, &$caller)
|
||||
{
|
||||
switch ($event) {
|
||||
case 'updateValue':
|
||||
// constant values override both default and submitted ones
|
||||
// default values are overriden by submitted
|
||||
$value = $this->_findValue($caller->_constantValues);
|
||||
if (null === $value) {
|
||||
// if no boxes were checked, then there is no value in the array
|
||||
// yet we don't want to display default value in this case
|
||||
if ($caller->isSubmitted()) {
|
||||
$value = $this->_findValue($caller->_submitValues);
|
||||
} else {
|
||||
$value = $this->_findValue($caller->_defaultValues);
|
||||
}
|
||||
}
|
||||
if (null !== $value || $caller->isSubmitted()) {
|
||||
$this->setChecked($value);
|
||||
}
|
||||
break;
|
||||
case 'setGroupValue':
|
||||
$this->setChecked($arg);
|
||||
break;
|
||||
default:
|
||||
parent::onQuickFormEvent($event, $arg, $caller);
|
||||
}
|
||||
return true;
|
||||
} // end func onQuickFormEvent
|
||||
|
||||
// }}}
|
||||
// {{{ exportValue()
|
||||
|
||||
/**
|
||||
* Return true if the checkbox is checked, null if it is not checked (getValue() returns false)
|
||||
*/
|
||||
function exportValue(&$submitValues, $assoc = false)
|
||||
{
|
||||
$value = $this->_findValue($submitValues);
|
||||
if (null === $value) {
|
||||
$value = $this->getChecked()? true: null;
|
||||
}
|
||||
return $this->_prepareValue($value, $assoc);
|
||||
}
|
||||
|
||||
// }}}
|
||||
} //end class HTML_QuickForm_checkbox
|
||||
?>
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,485 +1,494 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4.0 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Adam Daniel <adaniel1@eesus.jnj.com> |
|
||||
// | Bertrand Mansion <bmansion@mamasam.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: element.php,v 1.34 2006/10/07 20:12:17 avb Exp $
|
||||
|
||||
require_once('HTML/Common.php');
|
||||
|
||||
/**
|
||||
* Base class for form elements
|
||||
*
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version 1.3
|
||||
* @since PHP4.04pl1
|
||||
* @access public
|
||||
* @abstract
|
||||
*/
|
||||
class HTML_QuickForm_element extends HTML_Common
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* Label of the field
|
||||
* @var string
|
||||
* @since 1.3
|
||||
* @access private
|
||||
*/
|
||||
var $_label = '';
|
||||
|
||||
/**
|
||||
* Form element type
|
||||
* @var string
|
||||
* @since 1.0
|
||||
* @access private
|
||||
*/
|
||||
var $_type = '';
|
||||
|
||||
/**
|
||||
* Flag to tell if element is frozen
|
||||
* @var boolean
|
||||
* @since 1.0
|
||||
* @access private
|
||||
*/
|
||||
var $_flagFrozen = false;
|
||||
|
||||
/**
|
||||
* Does the element support persistant data when frozen
|
||||
* @var boolean
|
||||
* @since 1.3
|
||||
* @access private
|
||||
*/
|
||||
var $_persistantFreeze = false;
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string Name of the element
|
||||
* @param mixed Label(s) for the element
|
||||
* @param mixed Associative array of tag attributes or HTML attributes name="value" pairs
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function HTML_QuickForm_element($elementName=null, $elementLabel=null, $attributes=null)
|
||||
{
|
||||
HTML_Common::HTML_Common($attributes);
|
||||
if (isset($elementName)) {
|
||||
$this->setName($elementName);
|
||||
}
|
||||
if (isset($elementLabel)) {
|
||||
$this->setLabel($elementLabel);
|
||||
}
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ apiVersion()
|
||||
|
||||
/**
|
||||
* Returns the current API version
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return float
|
||||
*/
|
||||
function apiVersion()
|
||||
{
|
||||
return 2.0;
|
||||
} // end func apiVersion
|
||||
|
||||
// }}}
|
||||
// {{{ getType()
|
||||
|
||||
/**
|
||||
* Returns element type
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getType()
|
||||
{
|
||||
return $this->_type;
|
||||
} // end func getType
|
||||
|
||||
// }}}
|
||||
// {{{ setName()
|
||||
|
||||
/**
|
||||
* Sets the input field name
|
||||
*
|
||||
* @param string $name Input field name attribute
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setName($name)
|
||||
{
|
||||
// interface method
|
||||
} //end func setName
|
||||
|
||||
// }}}
|
||||
// {{{ getName()
|
||||
|
||||
/**
|
||||
* Returns the element name
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getName()
|
||||
{
|
||||
// interface method
|
||||
} //end func getName
|
||||
|
||||
// }}}
|
||||
// {{{ setValue()
|
||||
|
||||
/**
|
||||
* Sets the value of the form element
|
||||
*
|
||||
* @param string $value Default value of the form element
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setValue($value)
|
||||
{
|
||||
// interface
|
||||
} // end func setValue
|
||||
|
||||
// }}}
|
||||
// {{{ getValue()
|
||||
|
||||
/**
|
||||
* Returns the value of the form element
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
function getValue()
|
||||
{
|
||||
// interface
|
||||
return null;
|
||||
} // end func getValue
|
||||
|
||||
// }}}
|
||||
// {{{ freeze()
|
||||
|
||||
/**
|
||||
* Freeze the element so that only its value is returned
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function freeze()
|
||||
{
|
||||
$this->_flagFrozen = true;
|
||||
} //end func freeze
|
||||
|
||||
// }}}
|
||||
// {{{ unfreeze()
|
||||
|
||||
/**
|
||||
* Unfreezes the element so that it becomes editable
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @since 3.2.4
|
||||
*/
|
||||
function unfreeze()
|
||||
{
|
||||
$this->_flagFrozen = false;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getFrozenHtml()
|
||||
|
||||
/**
|
||||
* Returns the value of field without HTML tags
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getFrozenHtml()
|
||||
{
|
||||
$value = $this->getValue();
|
||||
return ('' != $value? htmlspecialchars($value): ' ') .
|
||||
$this->_getPersistantData();
|
||||
} //end func getFrozenHtml
|
||||
|
||||
// }}}
|
||||
// {{{ _getPersistantData()
|
||||
|
||||
/**
|
||||
* Used by getFrozenHtml() to pass the element's value if _persistantFreeze is on
|
||||
*
|
||||
* @access private
|
||||
* @return string
|
||||
*/
|
||||
function _getPersistantData()
|
||||
{
|
||||
if (!$this->_persistantFreeze) {
|
||||
return '';
|
||||
} else {
|
||||
$id = $this->getAttribute('id');
|
||||
return '<input' . $this->_getAttrString(array(
|
||||
'type' => 'hidden',
|
||||
'name' => $this->getName(),
|
||||
'value' => $this->getValue()
|
||||
) + (isset($id)? array('id' => $id): array())) . ' />';
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ isFrozen()
|
||||
|
||||
/**
|
||||
* Returns whether or not the element is frozen
|
||||
*
|
||||
* @since 1.3
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
function isFrozen()
|
||||
{
|
||||
return $this->_flagFrozen;
|
||||
} // end func isFrozen
|
||||
|
||||
// }}}
|
||||
// {{{ setPersistantFreeze()
|
||||
|
||||
/**
|
||||
* Sets wether an element value should be kept in an hidden field
|
||||
* when the element is frozen or not
|
||||
*
|
||||
* @param bool $persistant True if persistant value
|
||||
* @since 2.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setPersistantFreeze($persistant=false)
|
||||
{
|
||||
$this->_persistantFreeze = $persistant;
|
||||
} //end func setPersistantFreeze
|
||||
|
||||
// }}}
|
||||
// {{{ setLabel()
|
||||
|
||||
/**
|
||||
* Sets display text for the element
|
||||
*
|
||||
* @param string $label Display text for the element
|
||||
* @since 1.3
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setLabel($label)
|
||||
{
|
||||
$this->_label = $label;
|
||||
} //end func setLabel
|
||||
|
||||
// }}}
|
||||
// {{{ getLabel()
|
||||
|
||||
/**
|
||||
* Returns display text for the element
|
||||
*
|
||||
* @since 1.3
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getLabel()
|
||||
{
|
||||
return $this->_label;
|
||||
} //end func getLabel
|
||||
|
||||
// }}}
|
||||
// {{{ _findValue()
|
||||
|
||||
/**
|
||||
* Tries to find the element value from the values array
|
||||
*
|
||||
* @since 2.7
|
||||
* @access private
|
||||
* @return mixed
|
||||
*/
|
||||
function _findValue(&$values)
|
||||
{
|
||||
if (empty($values)) {
|
||||
return null;
|
||||
}
|
||||
$elementName = $this->getName();
|
||||
if (isset($values[$elementName])) {
|
||||
return $values[$elementName];
|
||||
} elseif (strpos($elementName, '[')) {
|
||||
$myVar = "['" . str_replace(
|
||||
array('\\', '\'', ']', '['), array('\\\\', '\\\'', '', "']['"),
|
||||
$elementName
|
||||
) . "']";
|
||||
return eval("return (isset(\$values$myVar)) ? \$values$myVar : null;");
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} //end func _findValue
|
||||
|
||||
// }}}
|
||||
// {{{ onQuickFormEvent()
|
||||
|
||||
/**
|
||||
* Called by HTML_QuickForm whenever form event is made on this element
|
||||
*
|
||||
* @param string $event Name of event
|
||||
* @param mixed $arg event arguments
|
||||
* @param object $caller calling object
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function onQuickFormEvent($event, $arg, &$caller)
|
||||
{
|
||||
switch ($event) {
|
||||
case 'createElement':
|
||||
$className = get_class($this);
|
||||
$this->$className($arg[0], $arg[1], $arg[2], $arg[3], $arg[4]);
|
||||
break;
|
||||
case 'addElement':
|
||||
$this->onQuickFormEvent('createElement', $arg, $caller);
|
||||
$this->onQuickFormEvent('updateValue', null, $caller);
|
||||
break;
|
||||
case 'updateValue':
|
||||
// constant values override both default and submitted ones
|
||||
// default values are overriden by submitted
|
||||
$value = $this->_findValue($caller->_constantValues);
|
||||
if (null === $value) {
|
||||
$value = $this->_findValue($caller->_submitValues);
|
||||
if (null === $value) {
|
||||
$value = $this->_findValue($caller->_defaultValues);
|
||||
}
|
||||
}
|
||||
if (null !== $value) {
|
||||
$this->setValue($value);
|
||||
}
|
||||
break;
|
||||
case 'setGroupValue':
|
||||
$this->setValue($arg);
|
||||
}
|
||||
return true;
|
||||
} // end func onQuickFormEvent
|
||||
|
||||
// }}}
|
||||
// {{{ accept()
|
||||
|
||||
/**
|
||||
* Accepts a renderer
|
||||
*
|
||||
* @param object An HTML_QuickForm_Renderer object
|
||||
* @param bool Whether an element is required
|
||||
* @param string An error message associated with an element
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function accept(&$renderer, $required=false, $error=null)
|
||||
{
|
||||
$renderer->renderElement($this, $required, $error);
|
||||
} // end func accept
|
||||
|
||||
// }}}
|
||||
// {{{ _generateId()
|
||||
|
||||
/**
|
||||
* Automatically generates and assigns an 'id' attribute for the element.
|
||||
*
|
||||
* Currently used to ensure that labels work on radio buttons and
|
||||
* checkboxes. Per idea of Alexander Radivanovich.
|
||||
*
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
function _generateId()
|
||||
{
|
||||
static $idx = 1;
|
||||
|
||||
if (!$this->getAttribute('id')) {
|
||||
$this->updateAttributes(array('id' => 'qf_' . substr(md5(microtime() . $idx++), 0, 6)));
|
||||
}
|
||||
} // end func _generateId
|
||||
|
||||
// }}}
|
||||
// {{{ exportValue()
|
||||
|
||||
/**
|
||||
* Returns a 'safe' element's value
|
||||
*
|
||||
* @param array array of submitted values to search
|
||||
* @param bool whether to return the value as associative array
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
function exportValue(&$submitValues, $assoc = false)
|
||||
{
|
||||
$value = $this->_findValue($submitValues);
|
||||
if (null === $value) {
|
||||
$value = $this->getValue();
|
||||
}
|
||||
return $this->_prepareValue($value, $assoc);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ _prepareValue()
|
||||
|
||||
/**
|
||||
* Used by exportValue() to prepare the value for returning
|
||||
*
|
||||
* @param mixed the value found in exportValue()
|
||||
* @param bool whether to return the value as associative array
|
||||
* @access private
|
||||
* @return mixed
|
||||
*/
|
||||
function _prepareValue($value, $assoc)
|
||||
{
|
||||
if (null === $value) {
|
||||
return null;
|
||||
} elseif (!$assoc) {
|
||||
return $value;
|
||||
} else {
|
||||
$name = $this->getName();
|
||||
if (!strpos($name, '[')) {
|
||||
return array($name => $value);
|
||||
} else {
|
||||
$valueAry = array();
|
||||
$myIndex = "['" . str_replace(
|
||||
array('\\', '\'', ']', '['), array('\\\\', '\\\'', '', "']['"),
|
||||
$name
|
||||
) . "']";
|
||||
eval("\$valueAry$myIndex = \$value;");
|
||||
return $valueAry;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
} // end class HTML_QuickForm_element
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Base class for form elements
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: element.php,v 1.37 2009/04/04 21:34:02 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for all HTML classes
|
||||
*/
|
||||
require_once 'HTML/Common.php';
|
||||
|
||||
/**
|
||||
* Base class for form elements
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @version Release: 3.2.11
|
||||
* @since 1.0
|
||||
* @abstract
|
||||
*/
|
||||
class HTML_QuickForm_element extends HTML_Common
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* Label of the field
|
||||
* @var string
|
||||
* @since 1.3
|
||||
* @access private
|
||||
*/
|
||||
var $_label = '';
|
||||
|
||||
/**
|
||||
* Form element type
|
||||
* @var string
|
||||
* @since 1.0
|
||||
* @access private
|
||||
*/
|
||||
var $_type = '';
|
||||
|
||||
/**
|
||||
* Flag to tell if element is frozen
|
||||
* @var boolean
|
||||
* @since 1.0
|
||||
* @access private
|
||||
*/
|
||||
var $_flagFrozen = false;
|
||||
|
||||
/**
|
||||
* Does the element support persistant data when frozen
|
||||
* @var boolean
|
||||
* @since 1.3
|
||||
* @access private
|
||||
*/
|
||||
var $_persistantFreeze = false;
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string Name of the element
|
||||
* @param mixed Label(s) for the element
|
||||
* @param mixed Associative array of tag attributes or HTML attributes name="value" pairs
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function HTML_QuickForm_element($elementName=null, $elementLabel=null, $attributes=null)
|
||||
{
|
||||
HTML_Common::HTML_Common($attributes);
|
||||
if (isset($elementName)) {
|
||||
$this->setName($elementName);
|
||||
}
|
||||
if (isset($elementLabel)) {
|
||||
$this->setLabel($elementLabel);
|
||||
}
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ apiVersion()
|
||||
|
||||
/**
|
||||
* Returns the current API version
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return float
|
||||
*/
|
||||
function apiVersion()
|
||||
{
|
||||
return 3.2;
|
||||
} // end func apiVersion
|
||||
|
||||
// }}}
|
||||
// {{{ getType()
|
||||
|
||||
/**
|
||||
* Returns element type
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getType()
|
||||
{
|
||||
return $this->_type;
|
||||
} // end func getType
|
||||
|
||||
// }}}
|
||||
// {{{ setName()
|
||||
|
||||
/**
|
||||
* Sets the input field name
|
||||
*
|
||||
* @param string $name Input field name attribute
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setName($name)
|
||||
{
|
||||
// interface method
|
||||
} //end func setName
|
||||
|
||||
// }}}
|
||||
// {{{ getName()
|
||||
|
||||
/**
|
||||
* Returns the element name
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getName()
|
||||
{
|
||||
// interface method
|
||||
} //end func getName
|
||||
|
||||
// }}}
|
||||
// {{{ setValue()
|
||||
|
||||
/**
|
||||
* Sets the value of the form element
|
||||
*
|
||||
* @param string $value Default value of the form element
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setValue($value)
|
||||
{
|
||||
// interface
|
||||
} // end func setValue
|
||||
|
||||
// }}}
|
||||
// {{{ getValue()
|
||||
|
||||
/**
|
||||
* Returns the value of the form element
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
function getValue()
|
||||
{
|
||||
// interface
|
||||
return null;
|
||||
} // end func getValue
|
||||
|
||||
// }}}
|
||||
// {{{ freeze()
|
||||
|
||||
/**
|
||||
* Freeze the element so that only its value is returned
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function freeze()
|
||||
{
|
||||
$this->_flagFrozen = true;
|
||||
} //end func freeze
|
||||
|
||||
// }}}
|
||||
// {{{ unfreeze()
|
||||
|
||||
/**
|
||||
* Unfreezes the element so that it becomes editable
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @since 3.2.4
|
||||
*/
|
||||
function unfreeze()
|
||||
{
|
||||
$this->_flagFrozen = false;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getFrozenHtml()
|
||||
|
||||
/**
|
||||
* Returns the value of field without HTML tags
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getFrozenHtml()
|
||||
{
|
||||
$value = $this->getValue();
|
||||
return (strlen($value)? htmlspecialchars($value): ' ') .
|
||||
$this->_getPersistantData();
|
||||
} //end func getFrozenHtml
|
||||
|
||||
// }}}
|
||||
// {{{ _getPersistantData()
|
||||
|
||||
/**
|
||||
* Used by getFrozenHtml() to pass the element's value if _persistantFreeze is on
|
||||
*
|
||||
* @access private
|
||||
* @return string
|
||||
*/
|
||||
function _getPersistantData()
|
||||
{
|
||||
if (!$this->_persistantFreeze) {
|
||||
return '';
|
||||
} else {
|
||||
$id = $this->getAttribute('id');
|
||||
return '<input' . $this->_getAttrString(array(
|
||||
'type' => 'hidden',
|
||||
'name' => $this->getName(),
|
||||
'value' => $this->getValue()
|
||||
) + (isset($id)? array('id' => $id): array())) . ' />';
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ isFrozen()
|
||||
|
||||
/**
|
||||
* Returns whether or not the element is frozen
|
||||
*
|
||||
* @since 1.3
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
function isFrozen()
|
||||
{
|
||||
return $this->_flagFrozen;
|
||||
} // end func isFrozen
|
||||
|
||||
// }}}
|
||||
// {{{ setPersistantFreeze()
|
||||
|
||||
/**
|
||||
* Sets wether an element value should be kept in an hidden field
|
||||
* when the element is frozen or not
|
||||
*
|
||||
* @param bool $persistant True if persistant value
|
||||
* @since 2.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setPersistantFreeze($persistant=false)
|
||||
{
|
||||
$this->_persistantFreeze = $persistant;
|
||||
} //end func setPersistantFreeze
|
||||
|
||||
// }}}
|
||||
// {{{ setLabel()
|
||||
|
||||
/**
|
||||
* Sets display text for the element
|
||||
*
|
||||
* @param string $label Display text for the element
|
||||
* @since 1.3
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setLabel($label)
|
||||
{
|
||||
$this->_label = $label;
|
||||
} //end func setLabel
|
||||
|
||||
// }}}
|
||||
// {{{ getLabel()
|
||||
|
||||
/**
|
||||
* Returns display text for the element
|
||||
*
|
||||
* @since 1.3
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getLabel()
|
||||
{
|
||||
return $this->_label;
|
||||
} //end func getLabel
|
||||
|
||||
// }}}
|
||||
// {{{ _findValue()
|
||||
|
||||
/**
|
||||
* Tries to find the element value from the values array
|
||||
*
|
||||
* @since 2.7
|
||||
* @access private
|
||||
* @return mixed
|
||||
*/
|
||||
function _findValue(&$values)
|
||||
{
|
||||
if (empty($values)) {
|
||||
return null;
|
||||
}
|
||||
$elementName = $this->getName();
|
||||
if (isset($values[$elementName])) {
|
||||
return $values[$elementName];
|
||||
} elseif (strpos($elementName, '[')) {
|
||||
$myVar = "['" . str_replace(
|
||||
array('\\', '\'', ']', '['), array('\\\\', '\\\'', '', "']['"),
|
||||
$elementName
|
||||
) . "']";
|
||||
return eval("return (isset(\$values$myVar)) ? \$values$myVar : null;");
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} //end func _findValue
|
||||
|
||||
// }}}
|
||||
// {{{ onQuickFormEvent()
|
||||
|
||||
/**
|
||||
* Called by HTML_QuickForm whenever form event is made on this element
|
||||
*
|
||||
* @param string $event Name of event
|
||||
* @param mixed $arg event arguments
|
||||
* @param object &$caller calling object
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function onQuickFormEvent($event, $arg, &$caller)
|
||||
{
|
||||
switch ($event) {
|
||||
case 'createElement':
|
||||
$className = get_class($this);
|
||||
$this->$className($arg[0], $arg[1], $arg[2], $arg[3], $arg[4]);
|
||||
break;
|
||||
case 'addElement':
|
||||
$this->onQuickFormEvent('createElement', $arg, $caller);
|
||||
$this->onQuickFormEvent('updateValue', null, $caller);
|
||||
break;
|
||||
case 'updateValue':
|
||||
// constant values override both default and submitted ones
|
||||
// default values are overriden by submitted
|
||||
$value = $this->_findValue($caller->_constantValues);
|
||||
if (null === $value) {
|
||||
$value = $this->_findValue($caller->_submitValues);
|
||||
if (null === $value) {
|
||||
$value = $this->_findValue($caller->_defaultValues);
|
||||
}
|
||||
}
|
||||
if (null !== $value) {
|
||||
$this->setValue($value);
|
||||
}
|
||||
break;
|
||||
case 'setGroupValue':
|
||||
$this->setValue($arg);
|
||||
}
|
||||
return true;
|
||||
} // end func onQuickFormEvent
|
||||
|
||||
// }}}
|
||||
// {{{ accept()
|
||||
|
||||
/**
|
||||
* Accepts a renderer
|
||||
*
|
||||
* @param HTML_QuickForm_Renderer renderer object
|
||||
* @param bool Whether an element is required
|
||||
* @param string An error message associated with an element
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function accept(&$renderer, $required=false, $error=null)
|
||||
{
|
||||
$renderer->renderElement($this, $required, $error);
|
||||
} // end func accept
|
||||
|
||||
// }}}
|
||||
// {{{ _generateId()
|
||||
|
||||
/**
|
||||
* Automatically generates and assigns an 'id' attribute for the element.
|
||||
*
|
||||
* Currently used to ensure that labels work on radio buttons and
|
||||
* checkboxes. Per idea of Alexander Radivanovich.
|
||||
*
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
function _generateId()
|
||||
{
|
||||
static $idx = 1;
|
||||
|
||||
if (!$this->getAttribute('id')) {
|
||||
$this->updateAttributes(array('id' => 'qf_' . substr(md5(microtime() . $idx++), 0, 6)));
|
||||
}
|
||||
} // end func _generateId
|
||||
|
||||
// }}}
|
||||
// {{{ exportValue()
|
||||
|
||||
/**
|
||||
* Returns a 'safe' element's value
|
||||
*
|
||||
* @param array array of submitted values to search
|
||||
* @param bool whether to return the value as associative array
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
function exportValue(&$submitValues, $assoc = false)
|
||||
{
|
||||
$value = $this->_findValue($submitValues);
|
||||
if (null === $value) {
|
||||
$value = $this->getValue();
|
||||
}
|
||||
return $this->_prepareValue($value, $assoc);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ _prepareValue()
|
||||
|
||||
/**
|
||||
* Used by exportValue() to prepare the value for returning
|
||||
*
|
||||
* @param mixed the value found in exportValue()
|
||||
* @param bool whether to return the value as associative array
|
||||
* @access private
|
||||
* @return mixed
|
||||
*/
|
||||
function _prepareValue($value, $assoc)
|
||||
{
|
||||
if (null === $value) {
|
||||
return null;
|
||||
} elseif (!$assoc) {
|
||||
return $value;
|
||||
} else {
|
||||
$name = $this->getName();
|
||||
if (!strpos($name, '[')) {
|
||||
return array($name => $value);
|
||||
} else {
|
||||
$valueAry = array();
|
||||
$myIndex = "['" . str_replace(
|
||||
array('\\', '\'', ']', '['), array('\\\\', '\\\'', '', "']['"),
|
||||
$name
|
||||
) . "']";
|
||||
eval("\$valueAry$myIndex = \$value;");
|
||||
return $valueAry;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
} // end class HTML_QuickForm_element
|
||||
?>
|
|
@ -1,349 +1,358 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4.0 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Adam Daniel <adaniel1@eesus.jnj.com> |
|
||||
// | Bertrand Mansion <bmansion@mamasam.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: file.php,v 1.22 2006/10/07 20:12:17 avb Exp $
|
||||
|
||||
require_once("HTML/QuickForm/input.php");
|
||||
|
||||
// register file-related rules
|
||||
if (class_exists('HTML_QuickForm')) {
|
||||
HTML_QuickForm::registerRule('uploadedfile', 'callback', '_ruleIsUploadedFile', 'HTML_QuickForm_file');
|
||||
HTML_QuickForm::registerRule('maxfilesize', 'callback', '_ruleCheckMaxFileSize', 'HTML_QuickForm_file');
|
||||
HTML_QuickForm::registerRule('mimetype', 'callback', '_ruleCheckMimeType', 'HTML_QuickForm_file');
|
||||
HTML_QuickForm::registerRule('filename', 'callback', '_ruleCheckFileName', 'HTML_QuickForm_file');
|
||||
}
|
||||
|
||||
/**
|
||||
* HTML class for a file type element
|
||||
*
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version 1.0
|
||||
* @since PHP4.04pl1
|
||||
* @access public
|
||||
*/
|
||||
class HTML_QuickForm_file extends HTML_QuickForm_input
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* Uploaded file data, from $_FILES
|
||||
* @var array
|
||||
*/
|
||||
var $_value = null;
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string Input field name attribute
|
||||
* @param string Input field label
|
||||
* @param mixed (optional)Either a typical HTML attribute string
|
||||
* or an associative array
|
||||
* @since 1.0
|
||||
* @access public
|
||||
*/
|
||||
function HTML_QuickForm_file($elementName=null, $elementLabel=null, $attributes=null)
|
||||
{
|
||||
HTML_QuickForm_input::HTML_QuickForm_input($elementName, $elementLabel, $attributes);
|
||||
$this->setType('file');
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ setSize()
|
||||
|
||||
/**
|
||||
* Sets size of file element
|
||||
*
|
||||
* @param int Size of file element
|
||||
* @since 1.0
|
||||
* @access public
|
||||
*/
|
||||
function setSize($size)
|
||||
{
|
||||
$this->updateAttributes(array('size' => $size));
|
||||
} //end func setSize
|
||||
|
||||
// }}}
|
||||
// {{{ getSize()
|
||||
|
||||
/**
|
||||
* Returns size of file element
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return int
|
||||
*/
|
||||
function getSize()
|
||||
{
|
||||
return $this->getAttribute('size');
|
||||
} //end func getSize
|
||||
|
||||
// }}}
|
||||
// {{{ freeze()
|
||||
|
||||
/**
|
||||
* Freeze the element so that only its value is returned
|
||||
*
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
function freeze()
|
||||
{
|
||||
return false;
|
||||
} //end func freeze
|
||||
|
||||
// }}}
|
||||
// {{{ setValue()
|
||||
|
||||
/**
|
||||
* Sets value for file element.
|
||||
*
|
||||
* Actually this does nothing. The function is defined here to override
|
||||
* HTML_Quickform_input's behaviour of setting the 'value' attribute. As
|
||||
* no sane user-agent uses <input type="file">'s value for anything
|
||||
* (because of security implications) we implement file's value as a
|
||||
* read-only property with a special meaning.
|
||||
*
|
||||
* @param mixed Value for file element
|
||||
* @since 3.0
|
||||
* @access public
|
||||
*/
|
||||
function setValue($value)
|
||||
{
|
||||
return null;
|
||||
} //end func setValue
|
||||
|
||||
// }}}
|
||||
// {{{ getValue()
|
||||
|
||||
/**
|
||||
* Returns information about the uploaded file
|
||||
*
|
||||
* @since 3.0
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
function getValue()
|
||||
{
|
||||
return $this->_value;
|
||||
} // end func getValue
|
||||
|
||||
// }}}
|
||||
// {{{ onQuickFormEvent()
|
||||
|
||||
/**
|
||||
* Called by HTML_QuickForm whenever form event is made on this element
|
||||
*
|
||||
* @param string Name of event
|
||||
* @param mixed event arguments
|
||||
* @param object calling object
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
function onQuickFormEvent($event, $arg, &$caller)
|
||||
{
|
||||
switch ($event) {
|
||||
case 'updateValue':
|
||||
if ($caller->getAttribute('method') == 'get') {
|
||||
return PEAR::raiseError('Cannot add a file upload field to a GET method form');
|
||||
}
|
||||
$this->_value = $this->_findValue();
|
||||
$caller->updateAttributes(array('enctype' => 'multipart/form-data'));
|
||||
$caller->setMaxFileSize();
|
||||
break;
|
||||
case 'addElement':
|
||||
$this->onQuickFormEvent('createElement', $arg, $caller);
|
||||
return $this->onQuickFormEvent('updateValue', null, $caller);
|
||||
break;
|
||||
case 'createElement':
|
||||
$className = get_class($this);
|
||||
$this->$className($arg[0], $arg[1], $arg[2]);
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
} // end func onQuickFormEvent
|
||||
|
||||
// }}}
|
||||
// {{{ moveUploadedFile()
|
||||
|
||||
/**
|
||||
* Moves an uploaded file into the destination
|
||||
*
|
||||
* @param string Destination directory path
|
||||
* @param string New file name
|
||||
* @access public
|
||||
* @return bool Whether the file was moved successfully
|
||||
*/
|
||||
function moveUploadedFile($dest, $fileName = '')
|
||||
{
|
||||
if ($dest != '' && substr($dest, -1) != '/') {
|
||||
$dest .= '/';
|
||||
}
|
||||
$fileName = ($fileName != '') ? $fileName : basename($this->_value['name']);
|
||||
return move_uploaded_file($this->_value['tmp_name'], $dest . $fileName);
|
||||
} // end func moveUploadedFile
|
||||
|
||||
// }}}
|
||||
// {{{ isUploadedFile()
|
||||
|
||||
/**
|
||||
* Checks if the element contains an uploaded file
|
||||
*
|
||||
* @access public
|
||||
* @return bool true if file has been uploaded, false otherwise
|
||||
*/
|
||||
function isUploadedFile()
|
||||
{
|
||||
return $this->_ruleIsUploadedFile($this->_value);
|
||||
} // end func isUploadedFile
|
||||
|
||||
// }}}
|
||||
// {{{ _ruleIsUploadedFile()
|
||||
|
||||
/**
|
||||
* Checks if the given element contains an uploaded file
|
||||
*
|
||||
* @param array Uploaded file info (from $_FILES)
|
||||
* @access private
|
||||
* @return bool true if file has been uploaded, false otherwise
|
||||
*/
|
||||
function _ruleIsUploadedFile($elementValue)
|
||||
{
|
||||
if ((isset($elementValue['error']) && $elementValue['error'] == 0) ||
|
||||
(!empty($elementValue['tmp_name']) && $elementValue['tmp_name'] != 'none')) {
|
||||
return is_uploaded_file($elementValue['tmp_name']);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} // end func _ruleIsUploadedFile
|
||||
|
||||
// }}}
|
||||
// {{{ _ruleCheckMaxFileSize()
|
||||
|
||||
/**
|
||||
* Checks that the file does not exceed the max file size
|
||||
*
|
||||
* @param array Uploaded file info (from $_FILES)
|
||||
* @param int Max file size
|
||||
* @access private
|
||||
* @return bool true if filesize is lower than maxsize, false otherwise
|
||||
*/
|
||||
function _ruleCheckMaxFileSize($elementValue, $maxSize)
|
||||
{
|
||||
if (!empty($elementValue['error']) &&
|
||||
(UPLOAD_ERR_FORM_SIZE == $elementValue['error'] || UPLOAD_ERR_INI_SIZE == $elementValue['error'])) {
|
||||
return false;
|
||||
}
|
||||
if (!HTML_QuickForm_file::_ruleIsUploadedFile($elementValue)) {
|
||||
return true;
|
||||
}
|
||||
return ($maxSize >= @filesize($elementValue['tmp_name']));
|
||||
} // end func _ruleCheckMaxFileSize
|
||||
|
||||
// }}}
|
||||
// {{{ _ruleCheckMimeType()
|
||||
|
||||
/**
|
||||
* Checks if the given element contains an uploaded file of the right mime type
|
||||
*
|
||||
* @param array Uploaded file info (from $_FILES)
|
||||
* @param mixed Mime Type (can be an array of allowed types)
|
||||
* @access private
|
||||
* @return bool true if mimetype is correct, false otherwise
|
||||
*/
|
||||
function _ruleCheckMimeType($elementValue, $mimeType)
|
||||
{
|
||||
if (!HTML_QuickForm_file::_ruleIsUploadedFile($elementValue)) {
|
||||
return true;
|
||||
}
|
||||
if (is_array($mimeType)) {
|
||||
return in_array($elementValue['type'], $mimeType);
|
||||
}
|
||||
return $elementValue['type'] == $mimeType;
|
||||
} // end func _ruleCheckMimeType
|
||||
|
||||
// }}}
|
||||
// {{{ _ruleCheckFileName()
|
||||
|
||||
/**
|
||||
* Checks if the given element contains an uploaded file of the filename regex
|
||||
*
|
||||
* @param array Uploaded file info (from $_FILES)
|
||||
* @param string Regular expression
|
||||
* @access private
|
||||
* @return bool true if name matches regex, false otherwise
|
||||
*/
|
||||
function _ruleCheckFileName($elementValue, $regex)
|
||||
{
|
||||
if (!HTML_QuickForm_file::_ruleIsUploadedFile($elementValue)) {
|
||||
return true;
|
||||
}
|
||||
return preg_match($regex, $elementValue['name']);
|
||||
} // end func _ruleCheckFileName
|
||||
|
||||
// }}}
|
||||
// {{{ _findValue()
|
||||
|
||||
/**
|
||||
* Tries to find the element value from the values array
|
||||
*
|
||||
* Needs to be redefined here as $_FILES is populated differently from
|
||||
* other arrays when element name is of the form foo[bar]
|
||||
*
|
||||
* @access private
|
||||
* @return mixed
|
||||
*/
|
||||
function _findValue()
|
||||
{
|
||||
if (empty($_FILES)) {
|
||||
return null;
|
||||
}
|
||||
$elementName = $this->getName();
|
||||
if (isset($_FILES[$elementName])) {
|
||||
return $_FILES[$elementName];
|
||||
} elseif (false !== ($pos = strpos($elementName, '['))) {
|
||||
$base = str_replace(
|
||||
array('\\', '\''), array('\\\\', '\\\''),
|
||||
substr($elementName, 0, $pos)
|
||||
);
|
||||
$idx = "['" . str_replace(
|
||||
array('\\', '\'', ']', '['), array('\\\\', '\\\'', '', "']['"),
|
||||
substr($elementName, $pos + 1, -1)
|
||||
) . "']";
|
||||
$props = array('name', 'type', 'size', 'tmp_name', 'error');
|
||||
$code = "if (!isset(\$_FILES['{$base}']['name']{$idx})) {\n" .
|
||||
" return null;\n" .
|
||||
"} else {\n" .
|
||||
" \$value = array();\n";
|
||||
foreach ($props as $prop) {
|
||||
$code .= " \$value['{$prop}'] = \$_FILES['{$base}']['{$prop}']{$idx};\n";
|
||||
}
|
||||
return eval($code . " return \$value;\n}\n");
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
} // end class HTML_QuickForm_file
|
||||
?>
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* HTML class for a file upload field
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: file.php,v 1.25 2009/04/04 21:34:02 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for <input /> form elements
|
||||
*/
|
||||
require_once 'HTML/QuickForm/input.php';
|
||||
|
||||
// register file-related rules
|
||||
if (class_exists('HTML_QuickForm')) {
|
||||
HTML_QuickForm::registerRule('uploadedfile', 'callback', '_ruleIsUploadedFile', 'HTML_QuickForm_file');
|
||||
HTML_QuickForm::registerRule('maxfilesize', 'callback', '_ruleCheckMaxFileSize', 'HTML_QuickForm_file');
|
||||
HTML_QuickForm::registerRule('mimetype', 'callback', '_ruleCheckMimeType', 'HTML_QuickForm_file');
|
||||
HTML_QuickForm::registerRule('filename', 'callback', '_ruleCheckFileName', 'HTML_QuickForm_file');
|
||||
}
|
||||
|
||||
/**
|
||||
* HTML class for a file upload field
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @version Release: 3.2.11
|
||||
* @since 1.0
|
||||
*/
|
||||
class HTML_QuickForm_file extends HTML_QuickForm_input
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* Uploaded file data, from $_FILES
|
||||
* @var array
|
||||
*/
|
||||
var $_value = null;
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string Input field name attribute
|
||||
* @param string Input field label
|
||||
* @param mixed (optional)Either a typical HTML attribute string
|
||||
* or an associative array
|
||||
* @since 1.0
|
||||
* @access public
|
||||
*/
|
||||
function HTML_QuickForm_file($elementName=null, $elementLabel=null, $attributes=null)
|
||||
{
|
||||
HTML_QuickForm_input::HTML_QuickForm_input($elementName, $elementLabel, $attributes);
|
||||
$this->setType('file');
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ setSize()
|
||||
|
||||
/**
|
||||
* Sets size of file element
|
||||
*
|
||||
* @param int Size of file element
|
||||
* @since 1.0
|
||||
* @access public
|
||||
*/
|
||||
function setSize($size)
|
||||
{
|
||||
$this->updateAttributes(array('size' => $size));
|
||||
} //end func setSize
|
||||
|
||||
// }}}
|
||||
// {{{ getSize()
|
||||
|
||||
/**
|
||||
* Returns size of file element
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return int
|
||||
*/
|
||||
function getSize()
|
||||
{
|
||||
return $this->getAttribute('size');
|
||||
} //end func getSize
|
||||
|
||||
// }}}
|
||||
// {{{ freeze()
|
||||
|
||||
/**
|
||||
* Freeze the element so that only its value is returned
|
||||
*
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
function freeze()
|
||||
{
|
||||
return false;
|
||||
} //end func freeze
|
||||
|
||||
// }}}
|
||||
// {{{ setValue()
|
||||
|
||||
/**
|
||||
* Sets value for file element.
|
||||
*
|
||||
* Actually this does nothing. The function is defined here to override
|
||||
* HTML_Quickform_input's behaviour of setting the 'value' attribute. As
|
||||
* no sane user-agent uses <input type="file">'s value for anything
|
||||
* (because of security implications) we implement file's value as a
|
||||
* read-only property with a special meaning.
|
||||
*
|
||||
* @param mixed Value for file element
|
||||
* @since 3.0
|
||||
* @access public
|
||||
*/
|
||||
function setValue($value)
|
||||
{
|
||||
return null;
|
||||
} //end func setValue
|
||||
|
||||
// }}}
|
||||
// {{{ getValue()
|
||||
|
||||
/**
|
||||
* Returns information about the uploaded file
|
||||
*
|
||||
* @since 3.0
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
function getValue()
|
||||
{
|
||||
return $this->_value;
|
||||
} // end func getValue
|
||||
|
||||
// }}}
|
||||
// {{{ onQuickFormEvent()
|
||||
|
||||
/**
|
||||
* Called by HTML_QuickForm whenever form event is made on this element
|
||||
*
|
||||
* @param string Name of event
|
||||
* @param mixed event arguments
|
||||
* @param object calling object
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
function onQuickFormEvent($event, $arg, &$caller)
|
||||
{
|
||||
switch ($event) {
|
||||
case 'updateValue':
|
||||
if ($caller->getAttribute('method') == 'get') {
|
||||
return PEAR::raiseError('Cannot add a file upload field to a GET method form');
|
||||
}
|
||||
$this->_value = $this->_findValue();
|
||||
$caller->updateAttributes(array('enctype' => 'multipart/form-data'));
|
||||
$caller->setMaxFileSize();
|
||||
break;
|
||||
case 'addElement':
|
||||
$this->onQuickFormEvent('createElement', $arg, $caller);
|
||||
return $this->onQuickFormEvent('updateValue', null, $caller);
|
||||
break;
|
||||
case 'createElement':
|
||||
$className = get_class($this);
|
||||
$this->$className($arg[0], $arg[1], $arg[2]);
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
} // end func onQuickFormEvent
|
||||
|
||||
// }}}
|
||||
// {{{ moveUploadedFile()
|
||||
|
||||
/**
|
||||
* Moves an uploaded file into the destination
|
||||
*
|
||||
* @param string Destination directory path
|
||||
* @param string New file name
|
||||
* @access public
|
||||
* @return bool Whether the file was moved successfully
|
||||
*/
|
||||
function moveUploadedFile($dest, $fileName = '')
|
||||
{
|
||||
if ($dest != '' && substr($dest, -1) != '/') {
|
||||
$dest .= '/';
|
||||
}
|
||||
$fileName = ($fileName != '') ? $fileName : basename($this->_value['name']);
|
||||
return move_uploaded_file($this->_value['tmp_name'], $dest . $fileName);
|
||||
} // end func moveUploadedFile
|
||||
|
||||
// }}}
|
||||
// {{{ isUploadedFile()
|
||||
|
||||
/**
|
||||
* Checks if the element contains an uploaded file
|
||||
*
|
||||
* @access public
|
||||
* @return bool true if file has been uploaded, false otherwise
|
||||
*/
|
||||
function isUploadedFile()
|
||||
{
|
||||
return $this->_ruleIsUploadedFile($this->_value);
|
||||
} // end func isUploadedFile
|
||||
|
||||
// }}}
|
||||
// {{{ _ruleIsUploadedFile()
|
||||
|
||||
/**
|
||||
* Checks if the given element contains an uploaded file
|
||||
*
|
||||
* @param array Uploaded file info (from $_FILES)
|
||||
* @access private
|
||||
* @return bool true if file has been uploaded, false otherwise
|
||||
*/
|
||||
function _ruleIsUploadedFile($elementValue)
|
||||
{
|
||||
if ((isset($elementValue['error']) && $elementValue['error'] == 0) ||
|
||||
(!empty($elementValue['tmp_name']) && $elementValue['tmp_name'] != 'none')) {
|
||||
return is_uploaded_file($elementValue['tmp_name']);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} // end func _ruleIsUploadedFile
|
||||
|
||||
// }}}
|
||||
// {{{ _ruleCheckMaxFileSize()
|
||||
|
||||
/**
|
||||
* Checks that the file does not exceed the max file size
|
||||
*
|
||||
* @param array Uploaded file info (from $_FILES)
|
||||
* @param int Max file size
|
||||
* @access private
|
||||
* @return bool true if filesize is lower than maxsize, false otherwise
|
||||
*/
|
||||
function _ruleCheckMaxFileSize($elementValue, $maxSize)
|
||||
{
|
||||
if (!empty($elementValue['error']) &&
|
||||
(UPLOAD_ERR_FORM_SIZE == $elementValue['error'] || UPLOAD_ERR_INI_SIZE == $elementValue['error'])) {
|
||||
return false;
|
||||
}
|
||||
if (!HTML_QuickForm_file::_ruleIsUploadedFile($elementValue)) {
|
||||
return true;
|
||||
}
|
||||
return ($maxSize >= @filesize($elementValue['tmp_name']));
|
||||
} // end func _ruleCheckMaxFileSize
|
||||
|
||||
// }}}
|
||||
// {{{ _ruleCheckMimeType()
|
||||
|
||||
/**
|
||||
* Checks if the given element contains an uploaded file of the right mime type
|
||||
*
|
||||
* @param array Uploaded file info (from $_FILES)
|
||||
* @param mixed Mime Type (can be an array of allowed types)
|
||||
* @access private
|
||||
* @return bool true if mimetype is correct, false otherwise
|
||||
*/
|
||||
function _ruleCheckMimeType($elementValue, $mimeType)
|
||||
{
|
||||
if (!HTML_QuickForm_file::_ruleIsUploadedFile($elementValue)) {
|
||||
return true;
|
||||
}
|
||||
if (is_array($mimeType)) {
|
||||
return in_array($elementValue['type'], $mimeType);
|
||||
}
|
||||
return $elementValue['type'] == $mimeType;
|
||||
} // end func _ruleCheckMimeType
|
||||
|
||||
// }}}
|
||||
// {{{ _ruleCheckFileName()
|
||||
|
||||
/**
|
||||
* Checks if the given element contains an uploaded file of the filename regex
|
||||
*
|
||||
* @param array Uploaded file info (from $_FILES)
|
||||
* @param string Regular expression
|
||||
* @access private
|
||||
* @return bool true if name matches regex, false otherwise
|
||||
*/
|
||||
function _ruleCheckFileName($elementValue, $regex)
|
||||
{
|
||||
if (!HTML_QuickForm_file::_ruleIsUploadedFile($elementValue)) {
|
||||
return true;
|
||||
}
|
||||
return (bool)preg_match($regex, $elementValue['name']);
|
||||
} // end func _ruleCheckFileName
|
||||
|
||||
// }}}
|
||||
// {{{ _findValue()
|
||||
|
||||
/**
|
||||
* Tries to find the element value from the values array
|
||||
*
|
||||
* Needs to be redefined here as $_FILES is populated differently from
|
||||
* other arrays when element name is of the form foo[bar]
|
||||
*
|
||||
* @access private
|
||||
* @return mixed
|
||||
*/
|
||||
function _findValue()
|
||||
{
|
||||
if (empty($_FILES)) {
|
||||
return null;
|
||||
}
|
||||
$elementName = $this->getName();
|
||||
if (isset($_FILES[$elementName])) {
|
||||
return $_FILES[$elementName];
|
||||
} elseif (false !== ($pos = strpos($elementName, '['))) {
|
||||
$base = str_replace(
|
||||
array('\\', '\''), array('\\\\', '\\\''),
|
||||
substr($elementName, 0, $pos)
|
||||
);
|
||||
$idx = "['" . str_replace(
|
||||
array('\\', '\'', ']', '['), array('\\\\', '\\\'', '', "']['"),
|
||||
substr($elementName, $pos + 1, -1)
|
||||
) . "']";
|
||||
$props = array('name', 'type', 'size', 'tmp_name', 'error');
|
||||
$code = "if (!isset(\$_FILES['{$base}']['name']{$idx})) {\n" .
|
||||
" return null;\n" .
|
||||
"} else {\n" .
|
||||
" \$value = array();\n";
|
||||
foreach ($props as $prop) {
|
||||
$code .= " \$value['{$prop}'] = \$_FILES['{$base}']['{$prop}']{$idx};\n";
|
||||
}
|
||||
return eval($code . " return \$value;\n}\n");
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
} // end class HTML_QuickForm_file
|
||||
?>
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,65 +1,74 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4.0 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Alexey Borzov <borz_off@cs.msu.su> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: header.php,v 1.1 2003/03/12 11:16:33 avb Exp $
|
||||
|
||||
require_once 'HTML/QuickForm/static.php';
|
||||
|
||||
/**
|
||||
* A pseudo-element used for adding headers to form
|
||||
*
|
||||
* @author Alexey Borzov <borz_off@cs.msu.su>
|
||||
* @access public
|
||||
*/
|
||||
class HTML_QuickForm_header extends HTML_QuickForm_static
|
||||
{
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $elementName Header name
|
||||
* @param string $text Header text
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function HTML_QuickForm_header($elementName = null, $text = null)
|
||||
{
|
||||
$this->HTML_QuickForm_static($elementName, null, $text);
|
||||
$this->_type = 'header';
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ accept()
|
||||
|
||||
/**
|
||||
* Accepts a renderer
|
||||
*
|
||||
* @param object An HTML_QuickForm_Renderer object
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function accept(&$renderer)
|
||||
{
|
||||
$renderer->renderHeader($this);
|
||||
} // end func accept
|
||||
|
||||
// }}}
|
||||
|
||||
} //end class HTML_QuickForm_header
|
||||
?>
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* A pseudo-element used for adding headers to form
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: header.php,v 1.3 2009/04/04 21:34:03 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* HTML class for static data
|
||||
*/
|
||||
require_once 'HTML/QuickForm/static.php';
|
||||
|
||||
/**
|
||||
* A pseudo-element used for adding headers to form
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @version Release: 3.2.11
|
||||
* @since 3.0
|
||||
*/
|
||||
class HTML_QuickForm_header extends HTML_QuickForm_static
|
||||
{
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $elementName Header name
|
||||
* @param string $text Header text
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function HTML_QuickForm_header($elementName = null, $text = null)
|
||||
{
|
||||
$this->HTML_QuickForm_static($elementName, null, $text);
|
||||
$this->_type = 'header';
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ accept()
|
||||
|
||||
/**
|
||||
* Accepts a renderer
|
||||
*
|
||||
* @param HTML_QuickForm_Renderer renderer object
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function accept(&$renderer)
|
||||
{
|
||||
$renderer->renderHeader($this);
|
||||
} // end func accept
|
||||
|
||||
// }}}
|
||||
|
||||
} //end class HTML_QuickForm_header
|
||||
?>
|
||||
|
|
|
@ -1,87 +1,94 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4.0 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Adam Daniel <adaniel1@eesus.jnj.com> |
|
||||
// | Bertrand Mansion <bmansion@mamasam.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: hidden.php,v 1.10 2003/06/18 19:36:20 avb Exp $
|
||||
|
||||
require_once("HTML/QuickForm/input.php");
|
||||
|
||||
/**
|
||||
* HTML class for a hidden type element
|
||||
*
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version 1.0
|
||||
* @since PHP4.04pl1
|
||||
* @access public
|
||||
*/
|
||||
class HTML_QuickForm_hidden extends HTML_QuickForm_input
|
||||
{
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $elementName (optional)Input field name attribute
|
||||
* @param string $value (optional)Input field value
|
||||
* @param mixed $attributes (optional)Either a typical HTML attribute string
|
||||
* or an associative array
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function HTML_QuickForm_hidden($elementName=null, $value='', $attributes=null)
|
||||
{
|
||||
HTML_QuickForm_input::HTML_QuickForm_input($elementName, null, $attributes);
|
||||
$this->setType('hidden');
|
||||
$this->setValue($value);
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ freeze()
|
||||
|
||||
/**
|
||||
* Freeze the element so that only its value is returned
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function freeze()
|
||||
{
|
||||
return false;
|
||||
} //end func freeze
|
||||
|
||||
// }}}
|
||||
// {{{ accept()
|
||||
|
||||
/**
|
||||
* Accepts a renderer
|
||||
*
|
||||
* @param object An HTML_QuickForm_Renderer object
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function accept(&$renderer)
|
||||
{
|
||||
$renderer->renderHidden($this);
|
||||
} // end func accept
|
||||
|
||||
// }}}
|
||||
|
||||
} //end class HTML_QuickForm_hidden
|
||||
?>
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* HTML class for a hidden type element
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: hidden.php,v 1.12 2009/04/04 21:34:03 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for <input /> form elements
|
||||
*/
|
||||
require_once 'HTML/QuickForm/input.php';
|
||||
|
||||
/**
|
||||
* HTML class for a hidden type element
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 1.0
|
||||
*/
|
||||
class HTML_QuickForm_hidden extends HTML_QuickForm_input
|
||||
{
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $elementName (optional)Input field name attribute
|
||||
* @param string $value (optional)Input field value
|
||||
* @param mixed $attributes (optional)Either a typical HTML attribute string
|
||||
* or an associative array
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function HTML_QuickForm_hidden($elementName=null, $value='', $attributes=null)
|
||||
{
|
||||
HTML_QuickForm_input::HTML_QuickForm_input($elementName, null, $attributes);
|
||||
$this->setType('hidden');
|
||||
$this->setValue($value);
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ freeze()
|
||||
|
||||
/**
|
||||
* Freeze the element so that only its value is returned
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function freeze()
|
||||
{
|
||||
return false;
|
||||
} //end func freeze
|
||||
|
||||
// }}}
|
||||
// {{{ accept()
|
||||
|
||||
/**
|
||||
* Accepts a renderer
|
||||
*
|
||||
* @param HTML_QuickForm_Renderer renderer object
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function accept(&$renderer)
|
||||
{
|
||||
$renderer->renderHidden($this);
|
||||
} // end func accept
|
||||
|
||||
// }}}
|
||||
|
||||
} //end class HTML_QuickForm_hidden
|
||||
?>
|
||||
|
|
|
@ -1,111 +1,118 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4.0 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Adam Daniel <adaniel1@eesus.jnj.com> |
|
||||
// | Bertrand Mansion <bmansion@mamasam.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: hiddenselect.php,v 1.5 2006/10/07 21:18:41 avb Exp $
|
||||
|
||||
require_once('HTML/QuickForm/select.php');
|
||||
|
||||
/**
|
||||
* This class takes the same arguments as a select element, but instead
|
||||
* of creating a select ring it creates hidden elements for all values
|
||||
* already selected with setDefault or setConstant. This is useful if
|
||||
* you have a select ring that you don't want visible, but you need all
|
||||
* selected values to be passed.
|
||||
*
|
||||
* @author Isaac Shepard <ishepard@bsiweb.com>
|
||||
*
|
||||
* @version 1.0
|
||||
* @since 2.1
|
||||
* @access public
|
||||
*/
|
||||
class HTML_QuickForm_hiddenselect extends HTML_QuickForm_select
|
||||
{
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string Select name attribute
|
||||
* @param mixed Label(s) for the select (not used)
|
||||
* @param mixed Data to be used to populate options
|
||||
* @param mixed Either a typical HTML attribute string or an associative array (not used)
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function HTML_QuickForm_hiddenselect($elementName=null, $elementLabel=null, $options=null, $attributes=null)
|
||||
{
|
||||
HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
|
||||
$this->_persistantFreeze = true;
|
||||
$this->_type = 'hiddenselect';
|
||||
if (isset($options)) {
|
||||
$this->load($options);
|
||||
}
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ toHtml()
|
||||
|
||||
/**
|
||||
* Returns the SELECT in HTML
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
* @throws
|
||||
*/
|
||||
function toHtml()
|
||||
{
|
||||
if (empty($this->_values)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$tabs = $this->_getTabs();
|
||||
$name = $this->getPrivateName();
|
||||
$strHtml = '';
|
||||
|
||||
foreach ($this->_values as $key => $val) {
|
||||
for ($i = 0, $optCount = count($this->_options); $i < $optCount; $i++) {
|
||||
if ($val == $this->_options[$i]['attr']['value']) {
|
||||
$strHtml .= $tabs . '<input' . $this->_getAttrString(array(
|
||||
'type' => 'hidden',
|
||||
'name' => $name,
|
||||
'value' => $val
|
||||
)) . " />\n" ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $strHtml;
|
||||
} //end func toHtml
|
||||
|
||||
// }}}
|
||||
// {{{ accept()
|
||||
|
||||
/**
|
||||
* This is essentially a hidden element and should be rendered as one
|
||||
*/
|
||||
function accept(&$renderer)
|
||||
{
|
||||
$renderer->renderHidden($this);
|
||||
}
|
||||
|
||||
// }}}
|
||||
} //end class HTML_QuickForm_hiddenselect
|
||||
?>
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Hidden select pseudo-element
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Isaac Shepard <ishepard@bsiweb.com>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: hiddenselect.php,v 1.7 2009/04/04 21:34:03 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class for <select></select> elements
|
||||
*/
|
||||
require_once 'HTML/QuickForm/select.php';
|
||||
|
||||
/**
|
||||
* Hidden select pseudo-element
|
||||
*
|
||||
* This class takes the same arguments as a select element, but instead
|
||||
* of creating a select ring it creates hidden elements for all values
|
||||
* already selected with setDefault or setConstant. This is useful if
|
||||
* you have a select ring that you don't want visible, but you need all
|
||||
* selected values to be passed.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Isaac Shepard <ishepard@bsiweb.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 2.1
|
||||
*/
|
||||
class HTML_QuickForm_hiddenselect extends HTML_QuickForm_select
|
||||
{
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string Select name attribute
|
||||
* @param mixed Label(s) for the select (not used)
|
||||
* @param mixed Data to be used to populate options
|
||||
* @param mixed Either a typical HTML attribute string or an associative array (not used)
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function HTML_QuickForm_hiddenselect($elementName=null, $elementLabel=null, $options=null, $attributes=null)
|
||||
{
|
||||
HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
|
||||
$this->_persistantFreeze = true;
|
||||
$this->_type = 'hiddenselect';
|
||||
if (isset($options)) {
|
||||
$this->load($options);
|
||||
}
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ toHtml()
|
||||
|
||||
/**
|
||||
* Returns the SELECT in HTML
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
* @throws
|
||||
*/
|
||||
function toHtml()
|
||||
{
|
||||
if (empty($this->_values)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$tabs = $this->_getTabs();
|
||||
$name = $this->getPrivateName();
|
||||
$strHtml = '';
|
||||
|
||||
foreach ($this->_values as $key => $val) {
|
||||
for ($i = 0, $optCount = count($this->_options); $i < $optCount; $i++) {
|
||||
if ($val == $this->_options[$i]['attr']['value']) {
|
||||
$strHtml .= $tabs . '<input' . $this->_getAttrString(array(
|
||||
'type' => 'hidden',
|
||||
'name' => $name,
|
||||
'value' => $val
|
||||
)) . " />\n" ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $strHtml;
|
||||
} //end func toHtml
|
||||
|
||||
// }}}
|
||||
// {{{ accept()
|
||||
|
||||
/**
|
||||
* This is essentially a hidden element and should be rendered as one
|
||||
*/
|
||||
function accept(&$renderer)
|
||||
{
|
||||
$renderer->renderHidden($this);
|
||||
}
|
||||
|
||||
// }}}
|
||||
} //end class HTML_QuickForm_hiddenselect
|
||||
?>
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,67 +1,77 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4.0 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Alexey Borzov <borz_off@cs.msu.su> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: html.php,v 1.1 2003/03/12 11:16:33 avb Exp $
|
||||
|
||||
require_once 'HTML/QuickForm/static.php';
|
||||
|
||||
/**
|
||||
* A pseudo-element used for adding raw HTML to form
|
||||
*
|
||||
* Intended for use with the default renderer only, template-based
|
||||
* ones may (and probably will) completely ignore this
|
||||
*
|
||||
* @author Alexey Borzov <borz_off@cs.msu.su>
|
||||
* @access public
|
||||
*/
|
||||
class HTML_QuickForm_html extends HTML_QuickForm_static
|
||||
{
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $text raw HTML to add
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function HTML_QuickForm_html($text = null)
|
||||
{
|
||||
$this->HTML_QuickForm_static(null, null, $text);
|
||||
$this->_type = 'html';
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ accept()
|
||||
|
||||
/**
|
||||
* Accepts a renderer
|
||||
*
|
||||
* @param object An HTML_QuickForm_Renderer object
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function accept(&$renderer)
|
||||
{
|
||||
$renderer->renderHtml($this);
|
||||
} // end func accept
|
||||
|
||||
// }}}
|
||||
|
||||
} //end class HTML_QuickForm_header
|
||||
?>
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* A pseudo-element used for adding raw HTML to form
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: html.php,v 1.3 2009/04/04 21:34:03 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* HTML class for static data
|
||||
*/
|
||||
require_once 'HTML/QuickForm/static.php';
|
||||
|
||||
/**
|
||||
* A pseudo-element used for adding raw HTML to form
|
||||
*
|
||||
* Intended for use with the default renderer only, template-based
|
||||
* ones may (and probably will) completely ignore this
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @version Release: 3.2.11
|
||||
* @since 3.0
|
||||
* @deprecated Please use the templates rather than add raw HTML via this element
|
||||
*/
|
||||
class HTML_QuickForm_html extends HTML_QuickForm_static
|
||||
{
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $text raw HTML to add
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function HTML_QuickForm_html($text = null)
|
||||
{
|
||||
$this->HTML_QuickForm_static(null, null, $text);
|
||||
$this->_type = 'html';
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ accept()
|
||||
|
||||
/**
|
||||
* Accepts a renderer
|
||||
*
|
||||
* @param HTML_QuickForm_Renderer renderer object (only works with Default renderer!)
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function accept(&$renderer)
|
||||
{
|
||||
$renderer->renderHtml($this);
|
||||
} // end func accept
|
||||
|
||||
// }}}
|
||||
|
||||
} //end class HTML_QuickForm_html
|
||||
?>
|
||||
|
|
|
@ -1,119 +1,127 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4.0 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Adam Daniel <adaniel1@eesus.jnj.com> |
|
||||
// | Bertrand Mansion <bmansion@mamasam.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: image.php,v 1.4 2003/06/18 19:36:20 avb Exp $
|
||||
require_once("HTML/QuickForm/input.php");
|
||||
|
||||
/**
|
||||
* HTML class for a image type element
|
||||
*
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version 1.0
|
||||
* @since PHP4.04pl1
|
||||
* @access public
|
||||
*/
|
||||
class HTML_QuickForm_image extends HTML_QuickForm_input
|
||||
{
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $elementName (optional)Element name attribute
|
||||
* @param string $src (optional)Image source
|
||||
* @param mixed $attributes (optional)Either a typical HTML attribute string
|
||||
* or an associative array
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function HTML_QuickForm_image($elementName=null, $src='', $attributes=null)
|
||||
{
|
||||
HTML_QuickForm_input::HTML_QuickForm_input($elementName, null, $attributes);
|
||||
$this->setType('image');
|
||||
$this->setSource($src);
|
||||
} // end class constructor
|
||||
|
||||
// }}}
|
||||
// {{{ setSource()
|
||||
|
||||
/**
|
||||
* Sets source for image element
|
||||
*
|
||||
* @param string $src source for image element
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setSource($src)
|
||||
{
|
||||
$this->updateAttributes(array('src' => $src));
|
||||
} // end func setSource
|
||||
|
||||
// }}}
|
||||
// {{{ setBorder()
|
||||
|
||||
/**
|
||||
* Sets border size for image element
|
||||
*
|
||||
* @param string $border border for image element
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setBorder($border)
|
||||
{
|
||||
$this->updateAttributes(array('border' => $border));
|
||||
} // end func setBorder
|
||||
|
||||
// }}}
|
||||
// {{{ setAlign()
|
||||
|
||||
/**
|
||||
* Sets alignment for image element
|
||||
*
|
||||
* @param string $align alignment for image element
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setAlign($align)
|
||||
{
|
||||
$this->updateAttributes(array('align' => $align));
|
||||
} // end func setAlign
|
||||
|
||||
// }}}
|
||||
// {{{ freeze()
|
||||
|
||||
/**
|
||||
* Freeze the element so that only its value is returned
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function freeze()
|
||||
{
|
||||
return false;
|
||||
} //end func freeze
|
||||
|
||||
// }}}
|
||||
|
||||
} // end class HTML_QuickForm_image
|
||||
?>
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* HTML class for an <input type="image" /> element
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: image.php,v 1.6 2009/04/04 21:34:03 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for <input /> form elements
|
||||
*/
|
||||
require_once 'HTML/QuickForm/input.php';
|
||||
|
||||
/**
|
||||
* HTML class for an <input type="image" /> element
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 1.0
|
||||
*/
|
||||
class HTML_QuickForm_image extends HTML_QuickForm_input
|
||||
{
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $elementName (optional)Element name attribute
|
||||
* @param string $src (optional)Image source
|
||||
* @param mixed $attributes (optional)Either a typical HTML attribute string
|
||||
* or an associative array
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function HTML_QuickForm_image($elementName=null, $src='', $attributes=null)
|
||||
{
|
||||
HTML_QuickForm_input::HTML_QuickForm_input($elementName, null, $attributes);
|
||||
$this->setType('image');
|
||||
$this->setSource($src);
|
||||
} // end class constructor
|
||||
|
||||
// }}}
|
||||
// {{{ setSource()
|
||||
|
||||
/**
|
||||
* Sets source for image element
|
||||
*
|
||||
* @param string $src source for image element
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setSource($src)
|
||||
{
|
||||
$this->updateAttributes(array('src' => $src));
|
||||
} // end func setSource
|
||||
|
||||
// }}}
|
||||
// {{{ setBorder()
|
||||
|
||||
/**
|
||||
* Sets border size for image element
|
||||
*
|
||||
* @param string $border border for image element
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setBorder($border)
|
||||
{
|
||||
$this->updateAttributes(array('border' => $border));
|
||||
} // end func setBorder
|
||||
|
||||
// }}}
|
||||
// {{{ setAlign()
|
||||
|
||||
/**
|
||||
* Sets alignment for image element
|
||||
*
|
||||
* @param string $align alignment for image element
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setAlign($align)
|
||||
{
|
||||
$this->updateAttributes(array('align' => $align));
|
||||
} // end func setAlign
|
||||
|
||||
// }}}
|
||||
// {{{ freeze()
|
||||
|
||||
/**
|
||||
* Freeze the element so that only its value is returned
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function freeze()
|
||||
{
|
||||
return false;
|
||||
} //end func freeze
|
||||
|
||||
// }}}
|
||||
|
||||
} // end class HTML_QuickForm_image
|
||||
?>
|
||||
|
|
|
@ -1,202 +1,209 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4.0 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Adam Daniel <adaniel1@eesus.jnj.com> |
|
||||
// | Bertrand Mansion <bmansion@mamasam.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: input.php,v 1.8 2003/06/18 19:36:20 avb Exp $
|
||||
|
||||
require_once("HTML/QuickForm/element.php");
|
||||
|
||||
/**
|
||||
* Base class for input form elements
|
||||
*
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version 1.0
|
||||
* @since PHP4.04pl1
|
||||
* @access public
|
||||
* @abstract
|
||||
*/
|
||||
class HTML_QuickForm_input extends HTML_QuickForm_element
|
||||
{
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string Input field name attribute
|
||||
* @param mixed Label(s) for the input field
|
||||
* @param mixed Either a typical HTML attribute string or an associative array
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function HTML_QuickForm_input($elementName=null, $elementLabel=null, $attributes=null)
|
||||
{
|
||||
$this->HTML_QuickForm_element($elementName, $elementLabel, $attributes);
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ setType()
|
||||
|
||||
/**
|
||||
* Sets the element type
|
||||
*
|
||||
* @param string $type Element type
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setType($type)
|
||||
{
|
||||
$this->_type = $type;
|
||||
$this->updateAttributes(array('type'=>$type));
|
||||
} // end func setType
|
||||
|
||||
// }}}
|
||||
// {{{ setName()
|
||||
|
||||
/**
|
||||
* Sets the input field name
|
||||
*
|
||||
* @param string $name Input field name attribute
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setName($name)
|
||||
{
|
||||
$this->updateAttributes(array('name'=>$name));
|
||||
} //end func setName
|
||||
|
||||
// }}}
|
||||
// {{{ getName()
|
||||
|
||||
/**
|
||||
* Returns the element name
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getName()
|
||||
{
|
||||
return $this->getAttribute('name');
|
||||
} //end func getName
|
||||
|
||||
// }}}
|
||||
// {{{ setValue()
|
||||
|
||||
/**
|
||||
* Sets the value of the form element
|
||||
*
|
||||
* @param string $value Default value of the form element
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setValue($value)
|
||||
{
|
||||
$this->updateAttributes(array('value'=>$value));
|
||||
} // end func setValue
|
||||
|
||||
// }}}
|
||||
// {{{ getValue()
|
||||
|
||||
/**
|
||||
* Returns the value of the form element
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getValue()
|
||||
{
|
||||
return $this->getAttribute('value');
|
||||
} // end func getValue
|
||||
|
||||
// }}}
|
||||
// {{{ toHtml()
|
||||
|
||||
/**
|
||||
* Returns the input field in HTML
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function toHtml()
|
||||
{
|
||||
if ($this->_flagFrozen) {
|
||||
return $this->getFrozenHtml();
|
||||
} else {
|
||||
return $this->_getTabs() . '<input' . $this->_getAttrString($this->_attributes) . ' />';
|
||||
}
|
||||
} //end func toHtml
|
||||
|
||||
// }}}
|
||||
// {{{ onQuickFormEvent()
|
||||
|
||||
/**
|
||||
* Called by HTML_QuickForm whenever form event is made on this element
|
||||
*
|
||||
* @param string $event Name of event
|
||||
* @param mixed $arg event arguments
|
||||
* @param object $caller calling object
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws
|
||||
*/
|
||||
function onQuickFormEvent($event, $arg, &$caller)
|
||||
{
|
||||
// do not use submit values for button-type elements
|
||||
$type = $this->getType();
|
||||
if (('updateValue' != $event) ||
|
||||
('submit' != $type && 'reset' != $type && 'image' != $type && 'button' != $type)) {
|
||||
parent::onQuickFormEvent($event, $arg, $caller);
|
||||
} else {
|
||||
$value = $this->_findValue($caller->_constantValues);
|
||||
if (null === $value) {
|
||||
$value = $this->_findValue($caller->_defaultValues);
|
||||
}
|
||||
if (null !== $value) {
|
||||
$this->setValue($value);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} // end func onQuickFormEvent
|
||||
|
||||
// }}}
|
||||
// {{{ exportValue()
|
||||
|
||||
/**
|
||||
* We don't need values from button-type elements (except submit) and files
|
||||
*/
|
||||
function exportValue(&$submitValues, $assoc = false)
|
||||
{
|
||||
$type = $this->getType();
|
||||
if ('reset' == $type || 'image' == $type || 'button' == $type || 'file' == $type) {
|
||||
return null;
|
||||
} else {
|
||||
return parent::exportValue($submitValues, $assoc);
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
} // end class HTML_QuickForm_element
|
||||
?>
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Base class for <input /> form elements
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: input.php,v 1.10 2009/04/04 21:34:03 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for form elements
|
||||
*/
|
||||
require_once 'HTML/QuickForm/element.php';
|
||||
|
||||
/**
|
||||
* Base class for <input /> form elements
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 1.0
|
||||
* @abstract
|
||||
*/
|
||||
class HTML_QuickForm_input extends HTML_QuickForm_element
|
||||
{
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string Input field name attribute
|
||||
* @param mixed Label(s) for the input field
|
||||
* @param mixed Either a typical HTML attribute string or an associative array
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function HTML_QuickForm_input($elementName=null, $elementLabel=null, $attributes=null)
|
||||
{
|
||||
$this->HTML_QuickForm_element($elementName, $elementLabel, $attributes);
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ setType()
|
||||
|
||||
/**
|
||||
* Sets the element type
|
||||
*
|
||||
* @param string $type Element type
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setType($type)
|
||||
{
|
||||
$this->_type = $type;
|
||||
$this->updateAttributes(array('type'=>$type));
|
||||
} // end func setType
|
||||
|
||||
// }}}
|
||||
// {{{ setName()
|
||||
|
||||
/**
|
||||
* Sets the input field name
|
||||
*
|
||||
* @param string $name Input field name attribute
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setName($name)
|
||||
{
|
||||
$this->updateAttributes(array('name'=>$name));
|
||||
} //end func setName
|
||||
|
||||
// }}}
|
||||
// {{{ getName()
|
||||
|
||||
/**
|
||||
* Returns the element name
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getName()
|
||||
{
|
||||
return $this->getAttribute('name');
|
||||
} //end func getName
|
||||
|
||||
// }}}
|
||||
// {{{ setValue()
|
||||
|
||||
/**
|
||||
* Sets the value of the form element
|
||||
*
|
||||
* @param string $value Default value of the form element
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setValue($value)
|
||||
{
|
||||
$this->updateAttributes(array('value'=>$value));
|
||||
} // end func setValue
|
||||
|
||||
// }}}
|
||||
// {{{ getValue()
|
||||
|
||||
/**
|
||||
* Returns the value of the form element
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getValue()
|
||||
{
|
||||
return $this->getAttribute('value');
|
||||
} // end func getValue
|
||||
|
||||
// }}}
|
||||
// {{{ toHtml()
|
||||
|
||||
/**
|
||||
* Returns the input field in HTML
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function toHtml()
|
||||
{
|
||||
if ($this->_flagFrozen) {
|
||||
return $this->getFrozenHtml();
|
||||
} else {
|
||||
return $this->_getTabs() . '<input' . $this->_getAttrString($this->_attributes) . ' />';
|
||||
}
|
||||
} //end func toHtml
|
||||
|
||||
// }}}
|
||||
// {{{ onQuickFormEvent()
|
||||
|
||||
/**
|
||||
* Called by HTML_QuickForm whenever form event is made on this element
|
||||
*
|
||||
* @param string $event Name of event
|
||||
* @param mixed $arg event arguments
|
||||
* @param object &$caller calling object
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws
|
||||
*/
|
||||
function onQuickFormEvent($event, $arg, &$caller)
|
||||
{
|
||||
// do not use submit values for button-type elements
|
||||
$type = $this->getType();
|
||||
if (('updateValue' != $event) ||
|
||||
('submit' != $type && 'reset' != $type && 'image' != $type && 'button' != $type)) {
|
||||
parent::onQuickFormEvent($event, $arg, $caller);
|
||||
} else {
|
||||
$value = $this->_findValue($caller->_constantValues);
|
||||
if (null === $value) {
|
||||
$value = $this->_findValue($caller->_defaultValues);
|
||||
}
|
||||
if (null !== $value) {
|
||||
$this->setValue($value);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} // end func onQuickFormEvent
|
||||
|
||||
// }}}
|
||||
// {{{ exportValue()
|
||||
|
||||
/**
|
||||
* We don't need values from button-type elements (except submit) and files
|
||||
*/
|
||||
function exportValue(&$submitValues, $assoc = false)
|
||||
{
|
||||
$type = $this->getType();
|
||||
if ('reset' == $type || 'image' == $type || 'button' == $type || 'file' == $type) {
|
||||
return null;
|
||||
} else {
|
||||
return parent::exportValue($submitValues, $assoc);
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
} // end class HTML_QuickForm_element
|
||||
?>
|
||||
|
|
|
@ -1,192 +1,200 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4.0 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Adam Daniel <adaniel1@eesus.jnj.com> |
|
||||
// | Bertrand Mansion <bmansion@mamasam.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
|
||||
require_once 'HTML/QuickForm/static.php';
|
||||
|
||||
/**
|
||||
* HTML class for a link type field
|
||||
*
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version 1.0
|
||||
* @since PHP4.04pl1
|
||||
* @access public
|
||||
*/
|
||||
class HTML_QuickForm_link extends HTML_QuickForm_static
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* Link display text
|
||||
* @var string
|
||||
* @since 1.0
|
||||
* @access private
|
||||
*/
|
||||
var $_text = "";
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $elementLabel (optional)Link label
|
||||
* @param string $href (optional)Link href
|
||||
* @param string $text (optional)Link display text
|
||||
* @param mixed $attributes (optional)Either a typical HTML attribute string
|
||||
* or an associative array
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws
|
||||
*/
|
||||
function HTML_QuickForm_link($elementName=null, $elementLabel=null, $href=null, $text=null, $attributes=null)
|
||||
{
|
||||
HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
|
||||
$this->_persistantFreeze = false;
|
||||
$this->_type = 'link';
|
||||
$this->setHref($href);
|
||||
$this->_text = $text;
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ setName()
|
||||
|
||||
/**
|
||||
* Sets the input field name
|
||||
*
|
||||
* @param string $name Input field name attribute
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws
|
||||
*/
|
||||
function setName($name)
|
||||
{
|
||||
$this->updateAttributes(array('name'=>$name));
|
||||
} //end func setName
|
||||
|
||||
// }}}
|
||||
// {{{ getName()
|
||||
|
||||
/**
|
||||
* Returns the element name
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
* @throws
|
||||
*/
|
||||
function getName()
|
||||
{
|
||||
return $this->getAttribute('name');
|
||||
} //end func getName
|
||||
|
||||
// }}}
|
||||
// {{{ setValue()
|
||||
|
||||
/**
|
||||
* Sets value for textarea element
|
||||
*
|
||||
* @param string $value Value for password element
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws
|
||||
*/
|
||||
function setValue($value)
|
||||
{
|
||||
return;
|
||||
} //end func setValue
|
||||
|
||||
// }}}
|
||||
// {{{ getValue()
|
||||
|
||||
/**
|
||||
* Returns the value of the form element
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws
|
||||
*/
|
||||
function getValue()
|
||||
{
|
||||
return;
|
||||
} // end func getValue
|
||||
|
||||
|
||||
// }}}
|
||||
// {{{ setHref()
|
||||
|
||||
/**
|
||||
* Sets the links href
|
||||
*
|
||||
* @param string $href
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws
|
||||
*/
|
||||
function setHref($href)
|
||||
{
|
||||
$this->updateAttributes(array('href'=>$href));
|
||||
} // end func setHref
|
||||
|
||||
// }}}
|
||||
// {{{ toHtml()
|
||||
|
||||
/**
|
||||
* Returns the textarea element in HTML
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
* @throws
|
||||
*/
|
||||
function toHtml()
|
||||
{
|
||||
$tabs = $this->_getTabs();
|
||||
$html = "$tabs<a".$this->_getAttrString($this->_attributes).">";
|
||||
$html .= $this->_text;
|
||||
$html .= "</a>";
|
||||
return $html;
|
||||
} //end func toHtml
|
||||
|
||||
// }}}
|
||||
// {{{ getFrozenHtml()
|
||||
|
||||
/**
|
||||
* Returns the value of field without HTML tags (in this case, value is changed to a mask)
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
* @throws
|
||||
*/
|
||||
function getFrozenHtml()
|
||||
{
|
||||
return;
|
||||
} //end func getFrozenHtml
|
||||
|
||||
// }}}
|
||||
|
||||
} //end class HTML_QuickForm_textarea
|
||||
?>
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* HTML class for a link type field
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: link.php,v 1.4 2009/04/04 21:34:04 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* HTML class for static data
|
||||
*/
|
||||
require_once 'HTML/QuickForm/static.php';
|
||||
|
||||
/**
|
||||
* HTML class for a link type field
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 2.0
|
||||
*/
|
||||
class HTML_QuickForm_link extends HTML_QuickForm_static
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* Link display text
|
||||
* @var string
|
||||
* @since 1.0
|
||||
* @access private
|
||||
*/
|
||||
var $_text = "";
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $elementLabel (optional)Link label
|
||||
* @param string $href (optional)Link href
|
||||
* @param string $text (optional)Link display text
|
||||
* @param mixed $attributes (optional)Either a typical HTML attribute string
|
||||
* or an associative array
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws
|
||||
*/
|
||||
function HTML_QuickForm_link($elementName=null, $elementLabel=null, $href=null, $text=null, $attributes=null)
|
||||
{
|
||||
HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
|
||||
$this->_persistantFreeze = false;
|
||||
$this->_type = 'link';
|
||||
$this->setHref($href);
|
||||
$this->_text = $text;
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ setName()
|
||||
|
||||
/**
|
||||
* Sets the input field name
|
||||
*
|
||||
* @param string $name Input field name attribute
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws
|
||||
*/
|
||||
function setName($name)
|
||||
{
|
||||
$this->updateAttributes(array('name'=>$name));
|
||||
} //end func setName
|
||||
|
||||
// }}}
|
||||
// {{{ getName()
|
||||
|
||||
/**
|
||||
* Returns the element name
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
* @throws
|
||||
*/
|
||||
function getName()
|
||||
{
|
||||
return $this->getAttribute('name');
|
||||
} //end func getName
|
||||
|
||||
// }}}
|
||||
// {{{ setValue()
|
||||
|
||||
/**
|
||||
* Sets value for textarea element
|
||||
*
|
||||
* @param string $value Value for password element
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws
|
||||
*/
|
||||
function setValue($value)
|
||||
{
|
||||
return;
|
||||
} //end func setValue
|
||||
|
||||
// }}}
|
||||
// {{{ getValue()
|
||||
|
||||
/**
|
||||
* Returns the value of the form element
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws
|
||||
*/
|
||||
function getValue()
|
||||
{
|
||||
return;
|
||||
} // end func getValue
|
||||
|
||||
|
||||
// }}}
|
||||
// {{{ setHref()
|
||||
|
||||
/**
|
||||
* Sets the links href
|
||||
*
|
||||
* @param string $href
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws
|
||||
*/
|
||||
function setHref($href)
|
||||
{
|
||||
$this->updateAttributes(array('href'=>$href));
|
||||
} // end func setHref
|
||||
|
||||
// }}}
|
||||
// {{{ toHtml()
|
||||
|
||||
/**
|
||||
* Returns the textarea element in HTML
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
* @throws
|
||||
*/
|
||||
function toHtml()
|
||||
{
|
||||
$tabs = $this->_getTabs();
|
||||
$html = "$tabs<a".$this->_getAttrString($this->_attributes).">";
|
||||
$html .= $this->_text;
|
||||
$html .= "</a>";
|
||||
return $html;
|
||||
} //end func toHtml
|
||||
|
||||
// }}}
|
||||
// {{{ getFrozenHtml()
|
||||
|
||||
/**
|
||||
* Returns the value of field without HTML tags (in this case, value is changed to a mask)
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
* @throws
|
||||
*/
|
||||
function getFrozenHtml()
|
||||
{
|
||||
return;
|
||||
} //end func getFrozenHtml
|
||||
|
||||
// }}}
|
||||
|
||||
} //end class HTML_QuickForm_textarea
|
||||
?>
|
||||
|
|
|
@ -1,108 +1,115 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4.0 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Adam Daniel <adaniel1@eesus.jnj.com> |
|
||||
// | Bertrand Mansion <bmansion@mamasam.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: password.php,v 1.6 2004/02/28 22:10:16 avb Exp $
|
||||
|
||||
require_once("HTML/QuickForm/input.php");
|
||||
|
||||
/**
|
||||
* HTML class for a password type field
|
||||
*
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version 1.1
|
||||
* @since PHP4.04pl1
|
||||
* @access public
|
||||
*/
|
||||
class HTML_QuickForm_password extends HTML_QuickForm_input
|
||||
{
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $elementName (optional)Input field name attribute
|
||||
* @param string $elementLabel (optional)Input field label
|
||||
* @param mixed $attributes (optional)Either a typical HTML attribute string
|
||||
* or an associative array
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws
|
||||
*/
|
||||
function HTML_QuickForm_password($elementName=null, $elementLabel=null, $attributes=null)
|
||||
{
|
||||
HTML_QuickForm_input::HTML_QuickForm_input($elementName, $elementLabel, $attributes);
|
||||
$this->setType('password');
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ setSize()
|
||||
|
||||
/**
|
||||
* Sets size of password element
|
||||
*
|
||||
* @param string $size Size of password field
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setSize($size)
|
||||
{
|
||||
$this->updateAttributes(array('size'=>$size));
|
||||
} //end func setSize
|
||||
|
||||
// }}}
|
||||
// {{{ setMaxlength()
|
||||
|
||||
/**
|
||||
* Sets maxlength of password element
|
||||
*
|
||||
* @param string $maxlength Maximum length of password field
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setMaxlength($maxlength)
|
||||
{
|
||||
$this->updateAttributes(array('maxlength'=>$maxlength));
|
||||
} //end func setMaxlength
|
||||
|
||||
// }}}
|
||||
// {{{ getFrozenHtml()
|
||||
|
||||
/**
|
||||
* Returns the value of field without HTML tags (in this case, value is changed to a mask)
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
* @throws
|
||||
*/
|
||||
function getFrozenHtml()
|
||||
{
|
||||
$value = $this->getValue();
|
||||
return ('' != $value? '**********': ' ') .
|
||||
$this->_getPersistantData();
|
||||
} //end func getFrozenHtml
|
||||
|
||||
// }}}
|
||||
|
||||
} //end class HTML_QuickForm_password
|
||||
?>
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* HTML class for a password type field
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: password.php,v 1.8 2009/04/04 21:34:04 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for <input /> form elements
|
||||
*/
|
||||
require_once 'HTML/QuickForm/input.php';
|
||||
|
||||
/**
|
||||
* HTML class for a password type field
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 1.0
|
||||
*/
|
||||
class HTML_QuickForm_password extends HTML_QuickForm_input
|
||||
{
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $elementName (optional)Input field name attribute
|
||||
* @param string $elementLabel (optional)Input field label
|
||||
* @param mixed $attributes (optional)Either a typical HTML attribute string
|
||||
* or an associative array
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws
|
||||
*/
|
||||
function HTML_QuickForm_password($elementName=null, $elementLabel=null, $attributes=null)
|
||||
{
|
||||
HTML_QuickForm_input::HTML_QuickForm_input($elementName, $elementLabel, $attributes);
|
||||
$this->setType('password');
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ setSize()
|
||||
|
||||
/**
|
||||
* Sets size of password element
|
||||
*
|
||||
* @param string $size Size of password field
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setSize($size)
|
||||
{
|
||||
$this->updateAttributes(array('size'=>$size));
|
||||
} //end func setSize
|
||||
|
||||
// }}}
|
||||
// {{{ setMaxlength()
|
||||
|
||||
/**
|
||||
* Sets maxlength of password element
|
||||
*
|
||||
* @param string $maxlength Maximum length of password field
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setMaxlength($maxlength)
|
||||
{
|
||||
$this->updateAttributes(array('maxlength'=>$maxlength));
|
||||
} //end func setMaxlength
|
||||
|
||||
// }}}
|
||||
// {{{ getFrozenHtml()
|
||||
|
||||
/**
|
||||
* Returns the value of field without HTML tags (in this case, value is changed to a mask)
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
* @throws
|
||||
*/
|
||||
function getFrozenHtml()
|
||||
{
|
||||
$value = $this->getValue();
|
||||
return ('' != $value? '**********': ' ') .
|
||||
$this->_getPersistantData();
|
||||
} //end func getFrozenHtml
|
||||
|
||||
// }}}
|
||||
|
||||
} //end class HTML_QuickForm_password
|
||||
?>
|
||||
|
|
|
@ -1,244 +1,251 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4.0 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Adam Daniel <adaniel1@eesus.jnj.com> |
|
||||
// | Bertrand Mansion <bmansion@mamasam.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: radio.php,v 1.18 2006/10/07 15:18:16 avb Exp $
|
||||
|
||||
require_once('HTML/QuickForm/input.php');
|
||||
|
||||
/**
|
||||
* HTML class for a radio type element
|
||||
*
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version 1.1
|
||||
* @since PHP4.04pl1
|
||||
* @access public
|
||||
*/
|
||||
class HTML_QuickForm_radio extends HTML_QuickForm_input
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* Radio display text
|
||||
* @var string
|
||||
* @since 1.1
|
||||
* @access private
|
||||
*/
|
||||
var $_text = '';
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string Input field name attribute
|
||||
* @param mixed Label(s) for a field
|
||||
* @param string Text to display near the radio
|
||||
* @param string Input field value
|
||||
* @param mixed Either a typical HTML attribute string or an associative array
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function HTML_QuickForm_radio($elementName=null, $elementLabel=null, $text=null, $value=null, $attributes=null)
|
||||
{
|
||||
$this->HTML_QuickForm_element($elementName, $elementLabel, $attributes);
|
||||
if (isset($value)) {
|
||||
$this->setValue($value);
|
||||
}
|
||||
$this->_persistantFreeze = true;
|
||||
$this->setType('radio');
|
||||
$this->_text = $text;
|
||||
$this->_generateId();
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ setChecked()
|
||||
|
||||
/**
|
||||
* Sets whether radio button is checked
|
||||
*
|
||||
* @param bool $checked Whether the field is checked or not
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setChecked($checked)
|
||||
{
|
||||
if (!$checked) {
|
||||
$this->removeAttribute('checked');
|
||||
} else {
|
||||
$this->updateAttributes(array('checked'=>'checked'));
|
||||
}
|
||||
} //end func setChecked
|
||||
|
||||
// }}}
|
||||
// {{{ getChecked()
|
||||
|
||||
/**
|
||||
* Returns whether radio button is checked
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getChecked()
|
||||
{
|
||||
return $this->getAttribute('checked');
|
||||
} //end func getChecked
|
||||
|
||||
// }}}
|
||||
// {{{ toHtml()
|
||||
|
||||
/**
|
||||
* Returns the radio element in HTML
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function toHtml()
|
||||
{
|
||||
if (0 == strlen($this->_text)) {
|
||||
$label = '';
|
||||
} elseif ($this->_flagFrozen) {
|
||||
$label = $this->_text;
|
||||
} else {
|
||||
$label = '<label for="' . $this->getAttribute('id') . '">' . $this->_text . '</label>';
|
||||
}
|
||||
return HTML_QuickForm_input::toHtml() . $label;
|
||||
} //end func toHtml
|
||||
|
||||
// }}}
|
||||
// {{{ getFrozenHtml()
|
||||
|
||||
/**
|
||||
* Returns the value of field without HTML tags
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getFrozenHtml()
|
||||
{
|
||||
if ($this->getChecked()) {
|
||||
return '<tt>(x)</tt>' .
|
||||
$this->_getPersistantData();
|
||||
} else {
|
||||
return '<tt>( )</tt>';
|
||||
}
|
||||
} //end func getFrozenHtml
|
||||
|
||||
// }}}
|
||||
// {{{ setText()
|
||||
|
||||
/**
|
||||
* Sets the radio text
|
||||
*
|
||||
* @param string $text Text to display near the radio button
|
||||
* @since 1.1
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setText($text)
|
||||
{
|
||||
$this->_text = $text;
|
||||
} //end func setText
|
||||
|
||||
// }}}
|
||||
// {{{ getText()
|
||||
|
||||
/**
|
||||
* Returns the radio text
|
||||
*
|
||||
* @since 1.1
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getText()
|
||||
{
|
||||
return $this->_text;
|
||||
} //end func getText
|
||||
|
||||
// }}}
|
||||
// {{{ onQuickFormEvent()
|
||||
|
||||
/**
|
||||
* Called by HTML_QuickForm whenever form event is made on this element
|
||||
*
|
||||
* @param string $event Name of event
|
||||
* @param mixed $arg event arguments
|
||||
* @param object $caller calling object
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function onQuickFormEvent($event, $arg, &$caller)
|
||||
{
|
||||
switch ($event) {
|
||||
case 'updateValue':
|
||||
// constant values override both default and submitted ones
|
||||
// default values are overriden by submitted
|
||||
$value = $this->_findValue($caller->_constantValues);
|
||||
if (null === $value) {
|
||||
$value = $this->_findValue($caller->_submitValues);
|
||||
if (null === $value) {
|
||||
$value = $this->_findValue($caller->_defaultValues);
|
||||
}
|
||||
}
|
||||
if (!is_null($value) && $value == $this->getValue()) {
|
||||
$this->setChecked(true);
|
||||
} else {
|
||||
$this->setChecked(false);
|
||||
}
|
||||
break;
|
||||
case 'setGroupValue':
|
||||
if ($arg == $this->getValue()) {
|
||||
$this->setChecked(true);
|
||||
} else {
|
||||
$this->setChecked(false);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parent::onQuickFormEvent($event, $arg, $caller);
|
||||
}
|
||||
return true;
|
||||
} // end func onQuickFormLoad
|
||||
|
||||
// }}}
|
||||
// {{{ exportValue()
|
||||
|
||||
/**
|
||||
* Returns the value attribute if the radio is checked, null if it is not
|
||||
*/
|
||||
function exportValue(&$submitValues, $assoc = false)
|
||||
{
|
||||
$value = $this->_findValue($submitValues);
|
||||
if (null === $value) {
|
||||
$value = $this->getChecked()? $this->getValue(): null;
|
||||
} elseif ($value != $this->getValue()) {
|
||||
$value = null;
|
||||
}
|
||||
return $this->_prepareValue($value, $assoc);
|
||||
}
|
||||
|
||||
// }}}
|
||||
} //end class HTML_QuickForm_radio
|
||||
?>
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* HTML class for a radio type element
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: radio.php,v 1.20 2009/04/04 21:34:04 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for <input /> form elements
|
||||
*/
|
||||
require_once 'HTML/QuickForm/input.php';
|
||||
|
||||
/**
|
||||
* HTML class for a radio type element
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 1.0
|
||||
*/
|
||||
class HTML_QuickForm_radio extends HTML_QuickForm_input
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* Radio display text
|
||||
* @var string
|
||||
* @since 1.1
|
||||
* @access private
|
||||
*/
|
||||
var $_text = '';
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string Input field name attribute
|
||||
* @param mixed Label(s) for a field
|
||||
* @param string Text to display near the radio
|
||||
* @param string Input field value
|
||||
* @param mixed Either a typical HTML attribute string or an associative array
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function HTML_QuickForm_radio($elementName=null, $elementLabel=null, $text=null, $value=null, $attributes=null)
|
||||
{
|
||||
$this->HTML_QuickForm_element($elementName, $elementLabel, $attributes);
|
||||
if (isset($value)) {
|
||||
$this->setValue($value);
|
||||
}
|
||||
$this->_persistantFreeze = true;
|
||||
$this->setType('radio');
|
||||
$this->_text = $text;
|
||||
$this->_generateId();
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ setChecked()
|
||||
|
||||
/**
|
||||
* Sets whether radio button is checked
|
||||
*
|
||||
* @param bool $checked Whether the field is checked or not
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setChecked($checked)
|
||||
{
|
||||
if (!$checked) {
|
||||
$this->removeAttribute('checked');
|
||||
} else {
|
||||
$this->updateAttributes(array('checked'=>'checked'));
|
||||
}
|
||||
} //end func setChecked
|
||||
|
||||
// }}}
|
||||
// {{{ getChecked()
|
||||
|
||||
/**
|
||||
* Returns whether radio button is checked
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getChecked()
|
||||
{
|
||||
return $this->getAttribute('checked');
|
||||
} //end func getChecked
|
||||
|
||||
// }}}
|
||||
// {{{ toHtml()
|
||||
|
||||
/**
|
||||
* Returns the radio element in HTML
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function toHtml()
|
||||
{
|
||||
if (0 == strlen($this->_text)) {
|
||||
$label = '';
|
||||
} elseif ($this->_flagFrozen) {
|
||||
$label = $this->_text;
|
||||
} else {
|
||||
$label = '<label for="' . $this->getAttribute('id') . '">' . $this->_text . '</label>';
|
||||
}
|
||||
return HTML_QuickForm_input::toHtml() . $label;
|
||||
} //end func toHtml
|
||||
|
||||
// }}}
|
||||
// {{{ getFrozenHtml()
|
||||
|
||||
/**
|
||||
* Returns the value of field without HTML tags
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getFrozenHtml()
|
||||
{
|
||||
if ($this->getChecked()) {
|
||||
return '<tt>(x)</tt>' .
|
||||
$this->_getPersistantData();
|
||||
} else {
|
||||
return '<tt>( )</tt>';
|
||||
}
|
||||
} //end func getFrozenHtml
|
||||
|
||||
// }}}
|
||||
// {{{ setText()
|
||||
|
||||
/**
|
||||
* Sets the radio text
|
||||
*
|
||||
* @param string $text Text to display near the radio button
|
||||
* @since 1.1
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setText($text)
|
||||
{
|
||||
$this->_text = $text;
|
||||
} //end func setText
|
||||
|
||||
// }}}
|
||||
// {{{ getText()
|
||||
|
||||
/**
|
||||
* Returns the radio text
|
||||
*
|
||||
* @since 1.1
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getText()
|
||||
{
|
||||
return $this->_text;
|
||||
} //end func getText
|
||||
|
||||
// }}}
|
||||
// {{{ onQuickFormEvent()
|
||||
|
||||
/**
|
||||
* Called by HTML_QuickForm whenever form event is made on this element
|
||||
*
|
||||
* @param string $event Name of event
|
||||
* @param mixed $arg event arguments
|
||||
* @param object &$caller calling object
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function onQuickFormEvent($event, $arg, &$caller)
|
||||
{
|
||||
switch ($event) {
|
||||
case 'updateValue':
|
||||
// constant values override both default and submitted ones
|
||||
// default values are overriden by submitted
|
||||
$value = $this->_findValue($caller->_constantValues);
|
||||
if (null === $value) {
|
||||
$value = $this->_findValue($caller->_submitValues);
|
||||
if (null === $value) {
|
||||
$value = $this->_findValue($caller->_defaultValues);
|
||||
}
|
||||
}
|
||||
if (!is_null($value) && $value == $this->getValue()) {
|
||||
$this->setChecked(true);
|
||||
} else {
|
||||
$this->setChecked(false);
|
||||
}
|
||||
break;
|
||||
case 'setGroupValue':
|
||||
if ($arg == $this->getValue()) {
|
||||
$this->setChecked(true);
|
||||
} else {
|
||||
$this->setChecked(false);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parent::onQuickFormEvent($event, $arg, $caller);
|
||||
}
|
||||
return true;
|
||||
} // end func onQuickFormLoad
|
||||
|
||||
// }}}
|
||||
// {{{ exportValue()
|
||||
|
||||
/**
|
||||
* Returns the value attribute if the radio is checked, null if it is not
|
||||
*/
|
||||
function exportValue(&$submitValues, $assoc = false)
|
||||
{
|
||||
$value = $this->_findValue($submitValues);
|
||||
if (null === $value) {
|
||||
$value = $this->getChecked()? $this->getValue(): null;
|
||||
} elseif ($value != $this->getValue()) {
|
||||
$value = null;
|
||||
}
|
||||
return $this->_prepareValue($value, $assoc);
|
||||
}
|
||||
|
||||
// }}}
|
||||
} //end class HTML_QuickForm_radio
|
||||
?>
|
||||
|
|
|
@ -1,72 +1,79 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4.0 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Adam Daniel <adaniel1@eesus.jnj.com> |
|
||||
// | Bertrand Mansion <bmansion@mamasam.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: reset.php,v 1.4 2003/06/18 19:36:20 avb Exp $
|
||||
|
||||
require_once("HTML/QuickForm/input.php");
|
||||
|
||||
/**
|
||||
* HTML class for a reset type element
|
||||
*
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version 1.1
|
||||
* @since PHP4.04pl1
|
||||
* @access public
|
||||
*/
|
||||
class HTML_QuickForm_reset extends HTML_QuickForm_input
|
||||
{
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $elementName (optional)Input field name attribute
|
||||
* @param string $value (optional)Input field value
|
||||
* @param mixed $attributes (optional)Either a typical HTML attribute string
|
||||
* or an associative array
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function HTML_QuickForm_reset($elementName=null, $value=null, $attributes=null)
|
||||
{
|
||||
HTML_QuickForm_input::HTML_QuickForm_input($elementName, null, $attributes);
|
||||
$this->setValue($value);
|
||||
$this->setType('reset');
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ freeze()
|
||||
|
||||
/**
|
||||
* Freeze the element so that only its value is returned
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function freeze()
|
||||
{
|
||||
return false;
|
||||
} //end func freeze
|
||||
|
||||
// }}}
|
||||
|
||||
} //end class HTML_QuickForm_reset
|
||||
?>
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* HTML class for a reset type element
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: reset.php,v 1.6 2009/04/04 21:34:04 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for <input /> form elements
|
||||
*/
|
||||
require_once 'HTML/QuickForm/input.php';
|
||||
|
||||
/**
|
||||
* HTML class for a reset type element
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 1.0
|
||||
*/
|
||||
class HTML_QuickForm_reset extends HTML_QuickForm_input
|
||||
{
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $elementName (optional)Input field name attribute
|
||||
* @param string $value (optional)Input field value
|
||||
* @param mixed $attributes (optional)Either a typical HTML attribute string
|
||||
* or an associative array
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function HTML_QuickForm_reset($elementName=null, $value=null, $attributes=null)
|
||||
{
|
||||
HTML_QuickForm_input::HTML_QuickForm_input($elementName, null, $attributes);
|
||||
$this->setValue($value);
|
||||
$this->setType('reset');
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ freeze()
|
||||
|
||||
/**
|
||||
* Freeze the element so that only its value is returned
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function freeze()
|
||||
{
|
||||
return false;
|
||||
} //end func freeze
|
||||
|
||||
// }}}
|
||||
|
||||
} //end class HTML_QuickForm_reset
|
||||
?>
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,193 +1,201 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4.0 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Adam Daniel <adaniel1@eesus.jnj.com> |
|
||||
// | Bertrand Mansion <bmansion@mamasam.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: static.php,v 1.6 2003/06/16 13:06:26 avb Exp $
|
||||
|
||||
require_once("HTML/QuickForm/element.php");
|
||||
|
||||
/**
|
||||
* HTML class for static data
|
||||
*
|
||||
* @author Wojciech Gdela <eltehaem@poczta.onet.pl>
|
||||
* @access public
|
||||
*/
|
||||
class HTML_QuickForm_static extends HTML_QuickForm_element {
|
||||
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* Display text
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_text = null;
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $elementLabel (optional)Label
|
||||
* @param string $text (optional)Display text
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function HTML_QuickForm_static($elementName=null, $elementLabel=null, $text=null)
|
||||
{
|
||||
HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel);
|
||||
$this->_persistantFreeze = false;
|
||||
$this->_type = 'static';
|
||||
$this->_text = $text;
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ setName()
|
||||
|
||||
/**
|
||||
* Sets the element name
|
||||
*
|
||||
* @param string $name Element name
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setName($name)
|
||||
{
|
||||
$this->updateAttributes(array('name'=>$name));
|
||||
} //end func setName
|
||||
|
||||
// }}}
|
||||
// {{{ getName()
|
||||
|
||||
/**
|
||||
* Returns the element name
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getName()
|
||||
{
|
||||
return $this->getAttribute('name');
|
||||
} //end func getName
|
||||
|
||||
// }}}
|
||||
// {{{ setText()
|
||||
|
||||
/**
|
||||
* Sets the text
|
||||
*
|
||||
* @param string $text
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setText($text)
|
||||
{
|
||||
$this->_text = $text;
|
||||
} // end func setText
|
||||
|
||||
// }}}
|
||||
// {{{ setValue()
|
||||
|
||||
/**
|
||||
* Sets the text (uses the standard setValue call to emulate a form element.
|
||||
*
|
||||
* @param string $text
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setValue($text)
|
||||
{
|
||||
$this->setText($text);
|
||||
} // end func setValue
|
||||
|
||||
// }}}
|
||||
// {{{ toHtml()
|
||||
|
||||
/**
|
||||
* Returns the static text element in HTML
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function toHtml()
|
||||
{
|
||||
return $this->_getTabs() . $this->_text;
|
||||
} //end func toHtml
|
||||
|
||||
// }}}
|
||||
// {{{ getFrozenHtml()
|
||||
|
||||
/**
|
||||
* Returns the value of field without HTML tags
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getFrozenHtml()
|
||||
{
|
||||
return $this->toHtml();
|
||||
} //end func getFrozenHtml
|
||||
|
||||
// }}}
|
||||
// {{{ onQuickFormEvent()
|
||||
|
||||
/**
|
||||
* Called by HTML_QuickForm whenever form event is made on this element
|
||||
*
|
||||
* @param string $event Name of event
|
||||
* @param mixed $arg event arguments
|
||||
* @param object $caller calling object
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws
|
||||
*/
|
||||
function onQuickFormEvent($event, $arg, &$caller)
|
||||
{
|
||||
switch ($event) {
|
||||
case 'updateValue':
|
||||
// do NOT use submitted values for static elements
|
||||
$value = $this->_findValue($caller->_constantValues);
|
||||
if (null === $value) {
|
||||
$value = $this->_findValue($caller->_defaultValues);
|
||||
}
|
||||
if (null !== $value) {
|
||||
$this->setValue($value);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parent::onQuickFormEvent($event, $arg, $caller);
|
||||
}
|
||||
return true;
|
||||
} // end func onQuickFormEvent
|
||||
|
||||
// }}}
|
||||
// {{{ exportValue()
|
||||
|
||||
/**
|
||||
* We override this here because we don't want any values from static elements
|
||||
*/
|
||||
function exportValue(&$submitValues, $assoc = false)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// }}}
|
||||
} //end class HTML_QuickForm_static
|
||||
?>
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* HTML class for static data
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Wojciech Gdela <eltehaem@poczta.onet.pl>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: static.php,v 1.8 2009/04/04 21:34:04 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for form elements
|
||||
*/
|
||||
require_once 'HTML/QuickForm/element.php';
|
||||
|
||||
/**
|
||||
* HTML class for static data
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Wojciech Gdela <eltehaem@poczta.onet.pl>
|
||||
* @version Release: 3.2.11
|
||||
* @since 2.7
|
||||
*/
|
||||
class HTML_QuickForm_static extends HTML_QuickForm_element {
|
||||
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* Display text
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_text = null;
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $elementLabel (optional)Label
|
||||
* @param string $text (optional)Display text
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function HTML_QuickForm_static($elementName=null, $elementLabel=null, $text=null)
|
||||
{
|
||||
HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel);
|
||||
$this->_persistantFreeze = false;
|
||||
$this->_type = 'static';
|
||||
$this->_text = $text;
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ setName()
|
||||
|
||||
/**
|
||||
* Sets the element name
|
||||
*
|
||||
* @param string $name Element name
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setName($name)
|
||||
{
|
||||
$this->updateAttributes(array('name'=>$name));
|
||||
} //end func setName
|
||||
|
||||
// }}}
|
||||
// {{{ getName()
|
||||
|
||||
/**
|
||||
* Returns the element name
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getName()
|
||||
{
|
||||
return $this->getAttribute('name');
|
||||
} //end func getName
|
||||
|
||||
// }}}
|
||||
// {{{ setText()
|
||||
|
||||
/**
|
||||
* Sets the text
|
||||
*
|
||||
* @param string $text
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setText($text)
|
||||
{
|
||||
$this->_text = $text;
|
||||
} // end func setText
|
||||
|
||||
// }}}
|
||||
// {{{ setValue()
|
||||
|
||||
/**
|
||||
* Sets the text (uses the standard setValue call to emulate a form element.
|
||||
*
|
||||
* @param string $text
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setValue($text)
|
||||
{
|
||||
$this->setText($text);
|
||||
} // end func setValue
|
||||
|
||||
// }}}
|
||||
// {{{ toHtml()
|
||||
|
||||
/**
|
||||
* Returns the static text element in HTML
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function toHtml()
|
||||
{
|
||||
return $this->_getTabs() . $this->_text;
|
||||
} //end func toHtml
|
||||
|
||||
// }}}
|
||||
// {{{ getFrozenHtml()
|
||||
|
||||
/**
|
||||
* Returns the value of field without HTML tags
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getFrozenHtml()
|
||||
{
|
||||
return $this->toHtml();
|
||||
} //end func getFrozenHtml
|
||||
|
||||
// }}}
|
||||
// {{{ onQuickFormEvent()
|
||||
|
||||
/**
|
||||
* Called by HTML_QuickForm whenever form event is made on this element
|
||||
*
|
||||
* @param string $event Name of event
|
||||
* @param mixed $arg event arguments
|
||||
* @param object &$caller calling object
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws
|
||||
*/
|
||||
function onQuickFormEvent($event, $arg, &$caller)
|
||||
{
|
||||
switch ($event) {
|
||||
case 'updateValue':
|
||||
// do NOT use submitted values for static elements
|
||||
$value = $this->_findValue($caller->_constantValues);
|
||||
if (null === $value) {
|
||||
$value = $this->_findValue($caller->_defaultValues);
|
||||
}
|
||||
if (null !== $value) {
|
||||
$this->setValue($value);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parent::onQuickFormEvent($event, $arg, $caller);
|
||||
}
|
||||
return true;
|
||||
} // end func onQuickFormEvent
|
||||
|
||||
// }}}
|
||||
// {{{ exportValue()
|
||||
|
||||
/**
|
||||
* We override this here because we don't want any values from static elements
|
||||
*/
|
||||
function exportValue(&$submitValues, $assoc = false)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// }}}
|
||||
} //end class HTML_QuickForm_static
|
||||
?>
|
||||
|
|
|
@ -1,82 +1,89 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4.0 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Adam Daniel <adaniel1@eesus.jnj.com> |
|
||||
// | Bertrand Mansion <bmansion@mamasam.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: submit.php,v 1.4 2003/06/18 19:36:20 avb Exp $
|
||||
|
||||
require_once("HTML/QuickForm/input.php");
|
||||
|
||||
/**
|
||||
* HTML class for a submit type element
|
||||
*
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version 1.0
|
||||
* @since PHP4.04pl1
|
||||
* @access public
|
||||
*/
|
||||
class HTML_QuickForm_submit extends HTML_QuickForm_input
|
||||
{
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string Input field name attribute
|
||||
* @param string Input field value
|
||||
* @param mixed Either a typical HTML attribute string or an associative array
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function HTML_QuickForm_submit($elementName=null, $value=null, $attributes=null)
|
||||
{
|
||||
HTML_QuickForm_input::HTML_QuickForm_input($elementName, null, $attributes);
|
||||
$this->setValue($value);
|
||||
$this->setType('submit');
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ freeze()
|
||||
|
||||
/**
|
||||
* Freeze the element so that only its value is returned
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function freeze()
|
||||
{
|
||||
return false;
|
||||
} //end func freeze
|
||||
|
||||
// }}}
|
||||
// {{{ exportValue()
|
||||
|
||||
/**
|
||||
* Only return the value if it is found within $submitValues (i.e. if
|
||||
* this particular submit button was clicked)
|
||||
*/
|
||||
function exportValue(&$submitValues, $assoc = false)
|
||||
{
|
||||
return $this->_prepareValue($this->_findValue($submitValues), $assoc);
|
||||
}
|
||||
|
||||
// }}}
|
||||
} //end class HTML_QuickForm_submit
|
||||
?>
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* HTML class for a submit type element
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: submit.php,v 1.6 2009/04/04 21:34:04 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for <input /> form elements
|
||||
*/
|
||||
require_once 'HTML/QuickForm/input.php';
|
||||
|
||||
/**
|
||||
* HTML class for a submit type element
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 1.0
|
||||
*/
|
||||
class HTML_QuickForm_submit extends HTML_QuickForm_input
|
||||
{
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string Input field name attribute
|
||||
* @param string Input field value
|
||||
* @param mixed Either a typical HTML attribute string or an associative array
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function HTML_QuickForm_submit($elementName=null, $value=null, $attributes=null)
|
||||
{
|
||||
HTML_QuickForm_input::HTML_QuickForm_input($elementName, null, $attributes);
|
||||
$this->setValue($value);
|
||||
$this->setType('submit');
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ freeze()
|
||||
|
||||
/**
|
||||
* Freeze the element so that only its value is returned
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function freeze()
|
||||
{
|
||||
return false;
|
||||
} //end func freeze
|
||||
|
||||
// }}}
|
||||
// {{{ exportValue()
|
||||
|
||||
/**
|
||||
* Only return the value if it is found within $submitValues (i.e. if
|
||||
* this particular submit button was clicked)
|
||||
*/
|
||||
function exportValue(&$submitValues, $assoc = false)
|
||||
{
|
||||
return $this->_prepareValue($this->_findValue($submitValues), $assoc);
|
||||
}
|
||||
|
||||
// }}}
|
||||
} //end class HTML_QuickForm_submit
|
||||
?>
|
||||
|
|
|
@ -1,91 +1,98 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4.0 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Adam Daniel <adaniel1@eesus.jnj.com> |
|
||||
// | Bertrand Mansion <bmansion@mamasam.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: text.php,v 1.5 2003/06/18 19:36:20 avb Exp $
|
||||
|
||||
require_once("HTML/QuickForm/input.php");
|
||||
|
||||
/**
|
||||
* HTML class for a text field
|
||||
*
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version 1.0
|
||||
* @since PHP4.04pl1
|
||||
* @access public
|
||||
*/
|
||||
class HTML_QuickForm_text extends HTML_QuickForm_input
|
||||
{
|
||||
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $elementName (optional)Input field name attribute
|
||||
* @param string $elementLabel (optional)Input field label
|
||||
* @param mixed $attributes (optional)Either a typical HTML attribute string
|
||||
* or an associative array
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function HTML_QuickForm_text($elementName=null, $elementLabel=null, $attributes=null)
|
||||
{
|
||||
HTML_QuickForm_input::HTML_QuickForm_input($elementName, $elementLabel, $attributes);
|
||||
$this->_persistantFreeze = true;
|
||||
$this->setType('text');
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ setSize()
|
||||
|
||||
/**
|
||||
* Sets size of text field
|
||||
*
|
||||
* @param string $size Size of text field
|
||||
* @since 1.3
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setSize($size)
|
||||
{
|
||||
$this->updateAttributes(array('size'=>$size));
|
||||
} //end func setSize
|
||||
|
||||
// }}}
|
||||
// {{{ setMaxlength()
|
||||
|
||||
/**
|
||||
* Sets maxlength of text field
|
||||
*
|
||||
* @param string $maxlength Maximum length of text field
|
||||
* @since 1.3
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setMaxlength($maxlength)
|
||||
{
|
||||
$this->updateAttributes(array('maxlength'=>$maxlength));
|
||||
} //end func setMaxlength
|
||||
|
||||
// }}}
|
||||
|
||||
} //end class HTML_QuickForm_text
|
||||
?>
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* HTML class for a text field
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: text.php,v 1.7 2009/04/04 21:34:04 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for <input /> form elements
|
||||
*/
|
||||
require_once 'HTML/QuickForm/input.php';
|
||||
|
||||
/**
|
||||
* HTML class for a text field
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 1.0
|
||||
*/
|
||||
class HTML_QuickForm_text extends HTML_QuickForm_input
|
||||
{
|
||||
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $elementName (optional)Input field name attribute
|
||||
* @param string $elementLabel (optional)Input field label
|
||||
* @param mixed $attributes (optional)Either a typical HTML attribute string
|
||||
* or an associative array
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function HTML_QuickForm_text($elementName=null, $elementLabel=null, $attributes=null)
|
||||
{
|
||||
HTML_QuickForm_input::HTML_QuickForm_input($elementName, $elementLabel, $attributes);
|
||||
$this->_persistantFreeze = true;
|
||||
$this->setType('text');
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ setSize()
|
||||
|
||||
/**
|
||||
* Sets size of text field
|
||||
*
|
||||
* @param string $size Size of text field
|
||||
* @since 1.3
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setSize($size)
|
||||
{
|
||||
$this->updateAttributes(array('size'=>$size));
|
||||
} //end func setSize
|
||||
|
||||
// }}}
|
||||
// {{{ setMaxlength()
|
||||
|
||||
/**
|
||||
* Sets maxlength of text field
|
||||
*
|
||||
* @param string $maxlength Maximum length of text field
|
||||
* @since 1.3
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setMaxlength($maxlength)
|
||||
{
|
||||
$this->updateAttributes(array('maxlength'=>$maxlength));
|
||||
} //end func setMaxlength
|
||||
|
||||
// }}}
|
||||
|
||||
} //end class HTML_QuickForm_text
|
||||
?>
|
||||
|
|
|
@ -1,222 +1,229 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4.0 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Adam Daniel <adaniel1@eesus.jnj.com> |
|
||||
// | Bertrand Mansion <bmansion@mamasam.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: textarea.php,v 1.11 2004/02/28 22:10:16 avb Exp $
|
||||
|
||||
require_once("HTML/QuickForm/element.php");
|
||||
|
||||
/**
|
||||
* HTML class for a textarea type field
|
||||
*
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version 1.0
|
||||
* @since PHP4.04pl1
|
||||
* @access public
|
||||
*/
|
||||
class HTML_QuickForm_textarea extends HTML_QuickForm_element
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* Field value
|
||||
* @var string
|
||||
* @since 1.0
|
||||
* @access private
|
||||
*/
|
||||
var $_value = null;
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string Input field name attribute
|
||||
* @param mixed Label(s) for a field
|
||||
* @param mixed Either a typical HTML attribute string or an associative array
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function HTML_QuickForm_textarea($elementName=null, $elementLabel=null, $attributes=null)
|
||||
{
|
||||
HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
|
||||
$this->_persistantFreeze = true;
|
||||
$this->_type = 'textarea';
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ setName()
|
||||
|
||||
/**
|
||||
* Sets the input field name
|
||||
*
|
||||
* @param string $name Input field name attribute
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setName($name)
|
||||
{
|
||||
$this->updateAttributes(array('name'=>$name));
|
||||
} //end func setName
|
||||
|
||||
// }}}
|
||||
// {{{ getName()
|
||||
|
||||
/**
|
||||
* Returns the element name
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getName()
|
||||
{
|
||||
return $this->getAttribute('name');
|
||||
} //end func getName
|
||||
|
||||
// }}}
|
||||
// {{{ setValue()
|
||||
|
||||
/**
|
||||
* Sets value for textarea element
|
||||
*
|
||||
* @param string $value Value for textarea element
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setValue($value)
|
||||
{
|
||||
$this->_value = $value;
|
||||
} //end func setValue
|
||||
|
||||
// }}}
|
||||
// {{{ getValue()
|
||||
|
||||
/**
|
||||
* Returns the value of the form element
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getValue()
|
||||
{
|
||||
return $this->_value;
|
||||
} // end func getValue
|
||||
|
||||
// }}}
|
||||
// {{{ setWrap()
|
||||
|
||||
/**
|
||||
* Sets wrap type for textarea element
|
||||
*
|
||||
* @param string $wrap Wrap type
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setWrap($wrap)
|
||||
{
|
||||
$this->updateAttributes(array('wrap' => $wrap));
|
||||
} //end func setWrap
|
||||
|
||||
// }}}
|
||||
// {{{ setRows()
|
||||
|
||||
/**
|
||||
* Sets height in rows for textarea element
|
||||
*
|
||||
* @param string $rows Height expressed in rows
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setRows($rows)
|
||||
{
|
||||
$this->updateAttributes(array('rows' => $rows));
|
||||
} //end func setRows
|
||||
|
||||
// }}}
|
||||
// {{{ setCols()
|
||||
|
||||
/**
|
||||
* Sets width in cols for textarea element
|
||||
*
|
||||
* @param string $cols Width expressed in cols
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setCols($cols)
|
||||
{
|
||||
$this->updateAttributes(array('cols' => $cols));
|
||||
} //end func setCols
|
||||
|
||||
// }}}
|
||||
// {{{ toHtml()
|
||||
|
||||
/**
|
||||
* Returns the textarea element in HTML
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function toHtml()
|
||||
{
|
||||
if ($this->_flagFrozen) {
|
||||
return $this->getFrozenHtml();
|
||||
} else {
|
||||
return $this->_getTabs() .
|
||||
'<textarea' . $this->_getAttrString($this->_attributes) . '>' .
|
||||
// because we wrap the form later we don't want the text indented
|
||||
preg_replace("/(\r\n|\n|\r)/", '
', htmlspecialchars($this->_value)) .
|
||||
'</textarea>';
|
||||
}
|
||||
} //end func toHtml
|
||||
|
||||
// }}}
|
||||
// {{{ getFrozenHtml()
|
||||
|
||||
/**
|
||||
* Returns the value of field without HTML tags (in this case, value is changed to a mask)
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getFrozenHtml()
|
||||
{
|
||||
$value = htmlspecialchars($this->getValue());
|
||||
if ($this->getAttribute('wrap') == 'off') {
|
||||
$html = $this->_getTabs() . '<pre>' . $value."</pre>\n";
|
||||
} else {
|
||||
$html = nl2br($value)."\n";
|
||||
}
|
||||
return $html . $this->_getPersistantData();
|
||||
} //end func getFrozenHtml
|
||||
|
||||
// }}}
|
||||
|
||||
} //end class HTML_QuickForm_textarea
|
||||
?>
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* HTML class for a textarea type field
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: textarea.php,v 1.13 2009/04/04 21:34:04 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for form elements
|
||||
*/
|
||||
require_once 'HTML/QuickForm/element.php';
|
||||
|
||||
/**
|
||||
* HTML class for a textarea type field
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 1.0
|
||||
*/
|
||||
class HTML_QuickForm_textarea extends HTML_QuickForm_element
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* Field value
|
||||
* @var string
|
||||
* @since 1.0
|
||||
* @access private
|
||||
*/
|
||||
var $_value = null;
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string Input field name attribute
|
||||
* @param mixed Label(s) for a field
|
||||
* @param mixed Either a typical HTML attribute string or an associative array
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function HTML_QuickForm_textarea($elementName=null, $elementLabel=null, $attributes=null)
|
||||
{
|
||||
HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
|
||||
$this->_persistantFreeze = true;
|
||||
$this->_type = 'textarea';
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ setName()
|
||||
|
||||
/**
|
||||
* Sets the input field name
|
||||
*
|
||||
* @param string $name Input field name attribute
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setName($name)
|
||||
{
|
||||
$this->updateAttributes(array('name'=>$name));
|
||||
} //end func setName
|
||||
|
||||
// }}}
|
||||
// {{{ getName()
|
||||
|
||||
/**
|
||||
* Returns the element name
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getName()
|
||||
{
|
||||
return $this->getAttribute('name');
|
||||
} //end func getName
|
||||
|
||||
// }}}
|
||||
// {{{ setValue()
|
||||
|
||||
/**
|
||||
* Sets value for textarea element
|
||||
*
|
||||
* @param string $value Value for textarea element
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setValue($value)
|
||||
{
|
||||
$this->_value = $value;
|
||||
} //end func setValue
|
||||
|
||||
// }}}
|
||||
// {{{ getValue()
|
||||
|
||||
/**
|
||||
* Returns the value of the form element
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getValue()
|
||||
{
|
||||
return $this->_value;
|
||||
} // end func getValue
|
||||
|
||||
// }}}
|
||||
// {{{ setWrap()
|
||||
|
||||
/**
|
||||
* Sets wrap type for textarea element
|
||||
*
|
||||
* @param string $wrap Wrap type
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setWrap($wrap)
|
||||
{
|
||||
$this->updateAttributes(array('wrap' => $wrap));
|
||||
} //end func setWrap
|
||||
|
||||
// }}}
|
||||
// {{{ setRows()
|
||||
|
||||
/**
|
||||
* Sets height in rows for textarea element
|
||||
*
|
||||
* @param string $rows Height expressed in rows
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setRows($rows)
|
||||
{
|
||||
$this->updateAttributes(array('rows' => $rows));
|
||||
} //end func setRows
|
||||
|
||||
// }}}
|
||||
// {{{ setCols()
|
||||
|
||||
/**
|
||||
* Sets width in cols for textarea element
|
||||
*
|
||||
* @param string $cols Width expressed in cols
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setCols($cols)
|
||||
{
|
||||
$this->updateAttributes(array('cols' => $cols));
|
||||
} //end func setCols
|
||||
|
||||
// }}}
|
||||
// {{{ toHtml()
|
||||
|
||||
/**
|
||||
* Returns the textarea element in HTML
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function toHtml()
|
||||
{
|
||||
if ($this->_flagFrozen) {
|
||||
return $this->getFrozenHtml();
|
||||
} else {
|
||||
return $this->_getTabs() .
|
||||
'<textarea' . $this->_getAttrString($this->_attributes) . '>' .
|
||||
// because we wrap the form later we don't want the text indented
|
||||
preg_replace("/(\r\n|\n|\r)/", '
', htmlspecialchars($this->_value)) .
|
||||
'</textarea>';
|
||||
}
|
||||
} //end func toHtml
|
||||
|
||||
// }}}
|
||||
// {{{ getFrozenHtml()
|
||||
|
||||
/**
|
||||
* Returns the value of field without HTML tags (in this case, value is changed to a mask)
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getFrozenHtml()
|
||||
{
|
||||
$value = htmlspecialchars($this->getValue());
|
||||
if ($this->getAttribute('wrap') == 'off') {
|
||||
$html = $this->_getTabs() . '<pre>' . $value."</pre>\n";
|
||||
} else {
|
||||
$html = nl2br($value)."\n";
|
||||
}
|
||||
return $html . $this->_getPersistantData();
|
||||
} //end func getFrozenHtml
|
||||
|
||||
// }}}
|
||||
|
||||
} //end class HTML_QuickForm_textarea
|
||||
?>
|
||||
|
|
|
@ -1,145 +1,153 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Alexey Borzov <avb@php.net> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: xbutton.php,v 1.1 2004/05/18 09:46:46 avb Exp $
|
||||
|
||||
require_once 'HTML/QuickForm/element.php';
|
||||
|
||||
/**
|
||||
* Class for HTML 4.0 <button> element
|
||||
*
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @since 3.2.3
|
||||
* @access public
|
||||
*/
|
||||
class HTML_QuickForm_xbutton extends HTML_QuickForm_element
|
||||
{
|
||||
/**
|
||||
* Contents of the <button> tag
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_content;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string Button name
|
||||
* @param string Button content (HTML to add between <button></button> tags)
|
||||
* @param mixed Either a typical HTML attribute string or an associative array
|
||||
* @access public
|
||||
*/
|
||||
function HTML_QuickForm_xbutton($elementName = null, $elementContent = null, $attributes = null)
|
||||
{
|
||||
$this->HTML_QuickForm_element($elementName, null, $attributes);
|
||||
$this->setContent($elementContent);
|
||||
$this->setPersistantFreeze(false);
|
||||
$this->_type = 'xbutton';
|
||||
}
|
||||
|
||||
|
||||
function toHtml()
|
||||
{
|
||||
return '<button' . $this->getAttributes(true) . '>' . $this->_content . '</button>';
|
||||
}
|
||||
|
||||
|
||||
function getFrozenHtml()
|
||||
{
|
||||
return $this->toHtml();
|
||||
}
|
||||
|
||||
|
||||
function freeze()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
function setName($name)
|
||||
{
|
||||
$this->updateAttributes(array(
|
||||
'name' => $name
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
function getName()
|
||||
{
|
||||
return $this->getAttribute('name');
|
||||
}
|
||||
|
||||
|
||||
function setValue($value)
|
||||
{
|
||||
$this->updateAttributes(array(
|
||||
'value' => $value
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
function getValue()
|
||||
{
|
||||
return $this->getAttribute('value');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the contents of the button element
|
||||
*
|
||||
* @param string Button content (HTML to add between <button></button> tags)
|
||||
*/
|
||||
function setContent($content)
|
||||
{
|
||||
$this->_content = $content;
|
||||
}
|
||||
|
||||
|
||||
function onQuickFormEvent($event, $arg, &$caller)
|
||||
{
|
||||
if ('updateValue' != $event) {
|
||||
return parent::onQuickFormEvent($event, $arg, $caller);
|
||||
} else {
|
||||
$value = $this->_findValue($caller->_constantValues);
|
||||
if (null === $value) {
|
||||
$value = $this->_findValue($caller->_defaultValues);
|
||||
}
|
||||
if (null !== $value) {
|
||||
$this->setValue($value);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a 'safe' element's value
|
||||
*
|
||||
* The value is only returned if the button's type is "submit" and if this
|
||||
* particlular button was clicked
|
||||
*/
|
||||
function exportValue(&$submitValues, $assoc = false)
|
||||
{
|
||||
if ('submit' == $this->getAttribute('type')) {
|
||||
return $this->_prepareValue($this->_findValue($submitValues), $assoc);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Class for HTML 4.0 <button> element
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: xbutton.php,v 1.3 2009/04/04 21:34:04 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for form elements
|
||||
*/
|
||||
require_once 'HTML/QuickForm/element.php';
|
||||
|
||||
/**
|
||||
* Class for HTML 4.0 <button> element
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @version Release: 3.2.11
|
||||
* @since 3.2.3
|
||||
*/
|
||||
class HTML_QuickForm_xbutton extends HTML_QuickForm_element
|
||||
{
|
||||
/**
|
||||
* Contents of the <button> tag
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_content;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string Button name
|
||||
* @param string Button content (HTML to add between <button></button> tags)
|
||||
* @param mixed Either a typical HTML attribute string or an associative array
|
||||
* @access public
|
||||
*/
|
||||
function HTML_QuickForm_xbutton($elementName = null, $elementContent = null, $attributes = null)
|
||||
{
|
||||
$this->HTML_QuickForm_element($elementName, null, $attributes);
|
||||
$this->setContent($elementContent);
|
||||
$this->setPersistantFreeze(false);
|
||||
$this->_type = 'xbutton';
|
||||
}
|
||||
|
||||
|
||||
function toHtml()
|
||||
{
|
||||
return '<button' . $this->getAttributes(true) . '>' . $this->_content . '</button>';
|
||||
}
|
||||
|
||||
|
||||
function getFrozenHtml()
|
||||
{
|
||||
return $this->toHtml();
|
||||
}
|
||||
|
||||
|
||||
function freeze()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
function setName($name)
|
||||
{
|
||||
$this->updateAttributes(array(
|
||||
'name' => $name
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
function getName()
|
||||
{
|
||||
return $this->getAttribute('name');
|
||||
}
|
||||
|
||||
|
||||
function setValue($value)
|
||||
{
|
||||
$this->updateAttributes(array(
|
||||
'value' => $value
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
function getValue()
|
||||
{
|
||||
return $this->getAttribute('value');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the contents of the button element
|
||||
*
|
||||
* @param string Button content (HTML to add between <button></button> tags)
|
||||
*/
|
||||
function setContent($content)
|
||||
{
|
||||
$this->_content = $content;
|
||||
}
|
||||
|
||||
|
||||
function onQuickFormEvent($event, $arg, &$caller)
|
||||
{
|
||||
if ('updateValue' != $event) {
|
||||
return parent::onQuickFormEvent($event, $arg, $caller);
|
||||
} else {
|
||||
$value = $this->_findValue($caller->_constantValues);
|
||||
if (null === $value) {
|
||||
$value = $this->_findValue($caller->_defaultValues);
|
||||
}
|
||||
if (null !== $value) {
|
||||
$this->setValue($value);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a 'safe' element's value
|
||||
*
|
||||
* The value is only returned if the button's type is "submit" and if this
|
||||
* particlular button was clicked
|
||||
*/
|
||||
function exportValue(&$submitValues, $assoc = false)
|
||||
{
|
||||
if ('submit' == $this->getAttribute('type')) {
|
||||
return $this->_prepareValue($this->_findValue($submitValues), $assoc);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -4,19 +4,13 @@
|
|||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.0 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category pear
|
||||
* @package PEAR
|
||||
* @author Stig Bakken <ssb@php.net>
|
||||
* @author Gregory Beaver <cellog@php.net>
|
||||
* @copyright 1997-2005 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id: Guess.php,v 1.20.2.1 2006/06/16 11:41:16 pajoye Exp $
|
||||
* @copyright 1997-2009 The Authors
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version CVS: $Id: Guess.php 278521 2009-04-09 22:24:12Z dufuz $
|
||||
* @link http://pear.php.net/package/PEAR
|
||||
* @since File available since PEAR 0.1
|
||||
*/
|
||||
|
@ -74,7 +68,7 @@
|
|||
// Darwin home-eden.local 7.5.0 Darwin Kernel Version 7.5.0: Thu Aug 5 19:26:16 PDT 2004; root:xnu/xnu-517.7.21.obj~3/RELEASE_PPC Power Macintosh
|
||||
//
|
||||
// Mac OS X early versions
|
||||
//
|
||||
//
|
||||
|
||||
// }}}
|
||||
|
||||
|
@ -91,9 +85,9 @@
|
|||
* @package PEAR
|
||||
* @author Stig Bakken <ssb@php.net>
|
||||
* @author Gregory Beaver <cellog@php.net>
|
||||
* @copyright 1997-2005 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version Release: 1.4.11
|
||||
* @copyright 1997-2009 The Authors
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version Release: 1.9.0
|
||||
* @link http://pear.php.net/package/PEAR
|
||||
* @since Class available since Release 0.1
|
||||
*/
|
||||
|
@ -128,16 +122,16 @@ class OS_Guess
|
|||
if ($uname === null) {
|
||||
$uname = php_uname();
|
||||
}
|
||||
$parts = split('[[:space:]]+', trim($uname));
|
||||
$parts = preg_split('/\s+/', trim($uname));
|
||||
$n = count($parts);
|
||||
|
||||
$release = $machine = $cpu = '';
|
||||
$sysname = $parts[0];
|
||||
$release = $machine = $cpu = '';
|
||||
$sysname = $parts[0];
|
||||
$nodename = $parts[1];
|
||||
$cpu = $parts[$n-1];
|
||||
$cpu = $parts[$n-1];
|
||||
$extra = '';
|
||||
if ($cpu == 'unknown') {
|
||||
$cpu = $parts[$n-2];
|
||||
$cpu = $parts[$n - 2];
|
||||
}
|
||||
|
||||
switch ($sysname) {
|
||||
|
@ -158,7 +152,7 @@ class OS_Guess
|
|||
case 'Linux' :
|
||||
$extra = $this->_detectGlibcVersion();
|
||||
// use only the first two digits from the kernel version
|
||||
$release = ereg_replace('^([[:digit:]]+\.[[:digit:]]+).*', '\1', $parts[2]);
|
||||
$release = preg_replace('/^([0-9]+\.[0-9]+).*/', '\1', $parts[2]);
|
||||
break;
|
||||
case 'Mac' :
|
||||
$sysname = 'darwin';
|
||||
|
@ -176,14 +170,13 @@ class OS_Guess
|
|||
$cpu = 'powerpc';
|
||||
}
|
||||
}
|
||||
$release = ereg_replace('^([[:digit:]]+\.[[:digit:]]+).*', '\1', $parts[2]);
|
||||
$release = preg_replace('/^([0-9]+\.[0-9]+).*/', '\1', $parts[2]);
|
||||
break;
|
||||
default:
|
||||
$release = ereg_replace('-.*', '', $parts[2]);
|
||||
$release = preg_replace('/-.*/', '', $parts[2]);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (isset($sysmap[$sysname])) {
|
||||
$sysname = $sysmap[$sysname];
|
||||
} else {
|
||||
|
@ -201,12 +194,13 @@ class OS_Guess
|
|||
if ($glibc !== false) {
|
||||
return $glibc; // no need to run this multiple times
|
||||
}
|
||||
$major = $minor = 0;
|
||||
include_once "System.php";
|
||||
if (!@file_exists('/usr/bin/cpp') || !@is_executable('/usr/bin/cpp')) {
|
||||
// Use glibc's <features.h> header file to
|
||||
// get major and minor version number:
|
||||
if (@file_exists('/usr/include/features.h') &&
|
||||
@is_readable('/usr/include/features.h')) {
|
||||
// Use glibc's <features.h> header file to
|
||||
// get major and minor version number:
|
||||
if (@file_exists('/usr/include/features.h') &&
|
||||
@is_readable('/usr/include/features.h')) {
|
||||
if (!@file_exists('/usr/bin/cpp') || !@is_executable('/usr/bin/cpp')) {
|
||||
$features_file = fopen('/usr/include/features.h', 'rb');
|
||||
while (!feof($features_file)) {
|
||||
$line = fgets($features_file, 8192);
|
||||
|
@ -222,6 +216,7 @@ class OS_Guess
|
|||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (strpos($line, '__GLIBC_MINOR__')) {
|
||||
// got the minor version number
|
||||
// #define __GLIBC_MINOR__ version
|
||||
|
@ -238,34 +233,37 @@ class OS_Guess
|
|||
return $glibc = '';
|
||||
}
|
||||
return $glibc = 'glibc' . trim($glibc_major) . "." . trim($glibc_minor) ;
|
||||
} // no cpp
|
||||
|
||||
$tmpfile = System::mktemp("glibctest");
|
||||
$fp = fopen($tmpfile, "w");
|
||||
fwrite($fp, "#include <features.h>\n__GLIBC__ __GLIBC_MINOR__\n");
|
||||
fclose($fp);
|
||||
$cpp = popen("/usr/bin/cpp $tmpfile", "r");
|
||||
while ($line = fgets($cpp, 1024)) {
|
||||
if ($line{0} == '#' || trim($line) == '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (list($major, $minor) = explode(' ', trim($line))) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $glibc = '';
|
||||
}
|
||||
$tmpfile = System::mktemp("glibctest");
|
||||
$fp = fopen($tmpfile, "w");
|
||||
fwrite($fp, "#include <features.h>\n__GLIBC__ __GLIBC_MINOR__\n");
|
||||
fclose($fp);
|
||||
$cpp = popen("/usr/bin/cpp $tmpfile", "r");
|
||||
$major = $minor = 0;
|
||||
while ($line = fgets($cpp, 1024)) {
|
||||
if ($line{0} == '#' || trim($line) == '') {
|
||||
continue;
|
||||
}
|
||||
if (list($major, $minor) = explode(' ', trim($line))) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
pclose($cpp);
|
||||
unlink($tmpfile);
|
||||
if (!($major && $minor) && is_link('/lib/libc.so.6')) {
|
||||
pclose($cpp);
|
||||
unlink($tmpfile);
|
||||
} // features.h
|
||||
|
||||
if (!($major && $minor) && @is_link('/lib/libc.so.6')) {
|
||||
// Let's try reading the libc.so.6 symlink
|
||||
if (ereg('^libc-([.*])\.so$', basename(readlink('/lib/libc.so.6')), $matches)) {
|
||||
list($major, $minor) = explode('.', $matches);
|
||||
if (preg_match('/^libc-(.*)\.so$/', basename(readlink('/lib/libc.so.6')), $matches)) {
|
||||
list($major, $minor) = explode('.', $matches[1]);
|
||||
}
|
||||
}
|
||||
|
||||
if (!($major && $minor)) {
|
||||
return $glibc = '';
|
||||
}
|
||||
|
||||
return $glibc = "glibc{$major}.{$minor}";
|
||||
}
|
||||
|
||||
|
@ -304,11 +302,7 @@ class OS_Guess
|
|||
|
||||
function matchSignature($match)
|
||||
{
|
||||
if (is_array($match)) {
|
||||
$fragments = $match;
|
||||
} else {
|
||||
$fragments = explode('-', $match);
|
||||
}
|
||||
$fragments = is_array($match) ? $match : explode('-', $match);
|
||||
$n = count($fragments);
|
||||
$matches = 0;
|
||||
if ($n > 0) {
|
||||
|
@ -329,8 +323,8 @@ class OS_Guess
|
|||
function _matchFragment($fragment, $value)
|
||||
{
|
||||
if (strcspn($fragment, '*?') < strlen($fragment)) {
|
||||
$reg = '^' . str_replace(array('*', '?', '/'), array('.*', '.', '\\/'), $fragment) . '$';
|
||||
return eregi($reg, $value);
|
||||
$reg = '/^' . str_replace(array('*', '?', '/'), array('.*', '.', '\\/'), $fragment) . '\\z/';
|
||||
return preg_match($reg, $value);
|
||||
}
|
||||
return ($fragment == '*' || !strcasecmp($fragment, $value));
|
||||
}
|
||||
|
@ -341,5 +335,4 @@ class OS_Guess
|
|||
* indent-tabs-mode: nil
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
*/
|
||||
?>
|
||||
*/
|
|
@ -6,21 +6,15 @@
|
|||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.0 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category pear
|
||||
* @package PEAR
|
||||
* @author Sterling Hughes <sterling@php.net>
|
||||
* @author Stig Bakken <ssb@php.net>
|
||||
* @author Tomas V.V.Cox <cox@idecnet.com>
|
||||
* @author Greg Beaver <cellog@php.net>
|
||||
* @copyright 1997-2006 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id: PEAR.php,v 1.98 2006/01/23 05:38:05 cellog Exp $
|
||||
* @copyright 1997-2009 The Authors
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version CVS: $Id: PEAR.php 286670 2009-08-02 14:16:06Z dufuz $
|
||||
* @link http://pear.php.net/package/PEAR
|
||||
* @since File available since Release 0.1
|
||||
*/
|
||||
|
@ -52,15 +46,6 @@ if (substr(PHP_OS, 0, 3) == 'WIN') {
|
|||
define('PEAR_OS', 'Unix'); // blatant assumption
|
||||
}
|
||||
|
||||
// instant backwards compatibility
|
||||
if (!defined('PATH_SEPARATOR')) {
|
||||
if (OS_WINDOWS) {
|
||||
define('PATH_SEPARATOR', ';');
|
||||
} else {
|
||||
define('PATH_SEPARATOR', ':');
|
||||
}
|
||||
}
|
||||
|
||||
$GLOBALS['_PEAR_default_error_mode'] = PEAR_ERROR_RETURN;
|
||||
$GLOBALS['_PEAR_default_error_options'] = E_USER_NOTICE;
|
||||
$GLOBALS['_PEAR_destructor_object_list'] = array();
|
||||
|
@ -92,8 +77,8 @@ $GLOBALS['_PEAR_error_handler_stack'] = array();
|
|||
* @author Tomas V.V. Cox <cox@idecnet.com>
|
||||
* @author Greg Beaver <cellog@php.net>
|
||||
* @copyright 1997-2006 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version Release: 1.4.11
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version Release: 1.9.0
|
||||
* @link http://pear.php.net/package/PEAR
|
||||
* @see PEAR_Error
|
||||
* @since Class available since PHP 4.0.2
|
||||
|
@ -230,6 +215,14 @@ class PEAR
|
|||
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];
|
||||
}
|
||||
|
||||
|
@ -272,16 +265,17 @@ class PEAR
|
|||
*/
|
||||
function isError($data, $code = null)
|
||||
{
|
||||
if (is_a($data, 'PEAR_Error')) {
|
||||
if (is_null($code)) {
|
||||
return true;
|
||||
} elseif (is_string($code)) {
|
||||
return $data->getMessage() == $code;
|
||||
} else {
|
||||
return $data->getCode() == $code;
|
||||
}
|
||||
if (!is_a($data, 'PEAR_Error')) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
|
||||
if (is_null($code)) {
|
||||
return true;
|
||||
} elseif (is_string($code)) {
|
||||
return $data->getMessage() == $code;
|
||||
}
|
||||
|
||||
return $data->getCode() == $code;
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
@ -449,7 +443,6 @@ class PEAR
|
|||
function delExpect($error_code)
|
||||
{
|
||||
$deleted = false;
|
||||
|
||||
if ((is_array($error_code) && (0 != count($error_code)))) {
|
||||
// $error_code is a non-empty array here;
|
||||
// we walk through it trying to unset all
|
||||
|
@ -469,10 +462,10 @@ class PEAR
|
|||
} else {
|
||||
return PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME
|
||||
}
|
||||
} else {
|
||||
// $error_code is empty
|
||||
return PEAR::raiseError("The expected error you submitted is empty"); // IMPROVE ME
|
||||
}
|
||||
|
||||
// $error_code is empty
|
||||
return PEAR::raiseError("The expected error you submitted is empty"); // IMPROVE ME
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
@ -539,6 +532,7 @@ class PEAR
|
|||
$mode = PEAR_ERROR_RETURN;
|
||||
}
|
||||
}
|
||||
|
||||
// No mode given, try global ones
|
||||
if ($mode === null) {
|
||||
// Class error handler
|
||||
|
@ -559,13 +553,20 @@ class PEAR
|
|||
} else {
|
||||
$ec = 'PEAR_Error';
|
||||
}
|
||||
if ($skipmsg) {
|
||||
$a = &new $ec($code, $mode, $options, $userinfo);
|
||||
return $a;
|
||||
} else {
|
||||
$a = &new $ec($message, $code, $mode, $options, $userinfo);
|
||||
|
||||
if (intval(PHP_VERSION) < 5) {
|
||||
// little non-eval hack to fix bug #12147
|
||||
include 'PEAR/FixPHP5PEARWarnings.php';
|
||||
return $a;
|
||||
}
|
||||
|
||||
if ($skipmsg) {
|
||||
$a = new $ec($code, $mode, $options, $userinfo);
|
||||
} else {
|
||||
$a = new $ec($message, $code, $mode, $options, $userinfo);
|
||||
}
|
||||
|
||||
return $a;
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
@ -585,10 +586,10 @@ class PEAR
|
|||
if (isset($this) && is_a($this, 'PEAR')) {
|
||||
$a = &$this->raiseError($message, $code, null, null, $userinfo);
|
||||
return $a;
|
||||
} else {
|
||||
$a = &PEAR::raiseError($message, $code, null, null, $userinfo);
|
||||
return $a;
|
||||
}
|
||||
|
||||
$a = &PEAR::raiseError($message, $code, null, null, $userinfo);
|
||||
return $a;
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
@ -739,6 +740,7 @@ class PEAR
|
|||
if ((ini_get('enable_dl') != 1) || (ini_get('safe_mode') == 1)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (OS_WINDOWS) {
|
||||
$suffix = '.dll';
|
||||
} elseif (PHP_OS == 'HP-UX') {
|
||||
|
@ -750,14 +752,20 @@ class PEAR
|
|||
} else {
|
||||
$suffix = '.so';
|
||||
}
|
||||
|
||||
return @dl('php_'.$ext.$suffix) || @dl($ext.$suffix);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// }}}
|
||||
}
|
||||
|
||||
if (PEAR_ZE2) {
|
||||
include_once 'PEAR5.php';
|
||||
}
|
||||
|
||||
// {{{ _PEAR_call_destructors()
|
||||
|
||||
function _PEAR_call_destructors()
|
||||
|
@ -767,9 +775,16 @@ function _PEAR_call_destructors()
|
|||
sizeof($_PEAR_destructor_object_list))
|
||||
{
|
||||
reset($_PEAR_destructor_object_list);
|
||||
if (@PEAR::getStaticProperty('PEAR', 'destructlifo')) {
|
||||
if (PEAR_ZE2) {
|
||||
$destructLifoExists = PEAR5::getStaticProperty('PEAR', 'destructlifo');
|
||||
} else {
|
||||
$destructLifoExists = PEAR::getStaticProperty('PEAR', 'destructlifo');
|
||||
}
|
||||
|
||||
if ($destructLifoExists) {
|
||||
$_PEAR_destructor_object_list = array_reverse($_PEAR_destructor_object_list);
|
||||
}
|
||||
|
||||
while (list($k, $objref) = each($_PEAR_destructor_object_list)) {
|
||||
$classname = get_class($objref);
|
||||
while ($classname) {
|
||||
|
@ -788,7 +803,7 @@ function _PEAR_call_destructors()
|
|||
}
|
||||
|
||||
// Now call the shutdown functions
|
||||
if (is_array($GLOBALS['_PEAR_shutdown_funcs']) AND !empty($GLOBALS['_PEAR_shutdown_funcs'])) {
|
||||
if (isset($GLOBALS['_PEAR_shutdown_funcs']) AND is_array($GLOBALS['_PEAR_shutdown_funcs']) AND !empty($GLOBALS['_PEAR_shutdown_funcs'])) {
|
||||
foreach ($GLOBALS['_PEAR_shutdown_funcs'] as $value) {
|
||||
call_user_func_array($value[0], $value[1]);
|
||||
}
|
||||
|
@ -807,8 +822,8 @@ function _PEAR_call_destructors()
|
|||
* @author Tomas V.V. Cox <cox@idecnet.com>
|
||||
* @author Gregory Beaver <cellog@php.net>
|
||||
* @copyright 1997-2006 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version Release: 1.4.11
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version Release: 1.9.0
|
||||
* @link http://pear.php.net/manual/en/core.pear.pear-error.php
|
||||
* @see PEAR::raiseError(), PEAR::throwError()
|
||||
* @since Class available since PHP 4.0.2
|
||||
|
@ -858,11 +873,20 @@ class PEAR_Error
|
|||
$this->code = $code;
|
||||
$this->mode = $mode;
|
||||
$this->userinfo = $userinfo;
|
||||
if (function_exists("debug_backtrace")) {
|
||||
if (@!PEAR::getStaticProperty('PEAR_Error', 'skiptrace')) {
|
||||
$this->backtrace = debug_backtrace();
|
||||
|
||||
if (PEAR_ZE2) {
|
||||
$skiptrace = PEAR5::getStaticProperty('PEAR_Error', 'skiptrace');
|
||||
} else {
|
||||
$skiptrace = PEAR::getStaticProperty('PEAR_Error', 'skiptrace');
|
||||
}
|
||||
|
||||
if (!$skiptrace) {
|
||||
$this->backtrace = debug_backtrace();
|
||||
if (isset($this->backtrace[0]) && isset($this->backtrace[0]['object'])) {
|
||||
unset($this->backtrace[0]['object']);
|
||||
}
|
||||
}
|
||||
|
||||
if ($mode & PEAR_ERROR_CALLBACK) {
|
||||
$this->level = E_USER_NOTICE;
|
||||
$this->callback = $options;
|
||||
|
@ -870,20 +894,25 @@ class PEAR_Error
|
|||
if ($options === null) {
|
||||
$options = E_USER_NOTICE;
|
||||
}
|
||||
|
||||
$this->level = $options;
|
||||
$this->callback = null;
|
||||
}
|
||||
|
||||
if ($this->mode & PEAR_ERROR_PRINT) {
|
||||
if (is_null($options) || is_int($options)) {
|
||||
$format = "%s";
|
||||
} else {
|
||||
$format = $options;
|
||||
}
|
||||
|
||||
printf($format, $this->getMessage());
|
||||
}
|
||||
|
||||
if ($this->mode & PEAR_ERROR_TRIGGER) {
|
||||
trigger_error($this->getMessage(), $this->level);
|
||||
}
|
||||
|
||||
if ($this->mode & PEAR_ERROR_DIE) {
|
||||
$msg = $this->getMessage();
|
||||
if (is_null($options) || is_int($options)) {
|
||||
|
@ -896,11 +925,13 @@ class PEAR_Error
|
|||
}
|
||||
die(sprintf($format, $msg));
|
||||
}
|
||||
|
||||
if ($this->mode & PEAR_ERROR_CALLBACK) {
|
||||
if (is_callable($this->callback)) {
|
||||
call_user_func($this->callback, $this);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->mode & PEAR_ERROR_EXCEPTION) {
|
||||
trigger_error("PEAR_ERROR_EXCEPTION is obsolete, use class PEAR_Exception for exceptions", E_USER_WARNING);
|
||||
eval('$e = new Exception($this->message, $this->code);throw($e);');
|
||||
|
@ -1039,6 +1070,12 @@ class PEAR_Error
|
|||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ toString()
|
||||
function __toString()
|
||||
{
|
||||
return $this->getMessage();
|
||||
}
|
||||
// }}}
|
||||
// {{{ toString()
|
||||
|
||||
|
@ -1098,4 +1135,3 @@ class PEAR_Error
|
|||
* c-basic-offset: 4
|
||||
* End:
|
||||
*/
|
||||
?>
|
||||
|
|
|
@ -3,19 +3,14 @@
|
|||
* Class auto-loader
|
||||
*
|
||||
* PHP versions 4
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.0 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
|
||||
*
|
||||
* @category pear
|
||||
* @package PEAR
|
||||
* @author Stig Bakken <ssb@php.net>
|
||||
* @copyright 1997-2006 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id: Autoloader.php,v 1.13 2006/01/06 04:47:36 cellog Exp $
|
||||
* @copyright 1997-2009 The Authors
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version CVS: $Id: Autoloader.php 276383 2009-02-24 23:39:37Z dufuz $
|
||||
* @link http://pear.php.net/manual/en/core.ppm.php#core.ppm.pear-autoloader
|
||||
* @since File available since Release 0.1
|
||||
* @deprecated File deprecated in Release 1.4.0a1
|
||||
|
@ -48,9 +43,9 @@ require_once "PEAR.php";
|
|||
* @category pear
|
||||
* @package PEAR
|
||||
* @author Stig Bakken <ssb@php.net>
|
||||
* @copyright 1997-2006 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version Release: 1.4.11
|
||||
* @copyright 1997-2009 The Authors
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version Release: 1.9.0
|
||||
* @link http://pear.php.net/manual/en/core.ppm.php#core.ppm.pear-autoloader
|
||||
* @since File available since Release 0.1
|
||||
* @deprecated File deprecated in Release 1.4.0a1
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue