|
From: <be...@us...> - 2013-07-10 11:23:03
|
Revision: 11824
http://sourceforge.net/p/xoops/svn/11824
Author: beckmi
Date: 2013-07-10 11:23:00 +0000 (Wed, 10 Jul 2013)
Log Message:
-----------
Adjustments for PHP 5.4, and adding index.html files
Modified Paths:
--------------
XoopsModules/extgallery/trunk/modules/extgallery/class/ExtgalleryPersistableObjectHandler.php
XoopsModules/extgallery/trunk/modules/extgallery/class/pear/PEAR.php
XoopsModules/extgallery/trunk/modules/extgallery/xoops_version.php
Added Paths:
-----------
XoopsModules/extgallery/trunk/modules/extgallery/batch/index.html
XoopsModules/extgallery/trunk/modules/extgallery/fonts/index.html
XoopsModules/extgallery/trunk/modules/extgallery/include/applet/conf/index.html
XoopsModules/extgallery/trunk/modules/extgallery/include/applet/images/index.html
XoopsModules/extgallery/trunk/modules/extgallery/include/applet/wjhk/jupload2/context/index.html
Added: XoopsModules/extgallery/trunk/modules/extgallery/batch/index.html
===================================================================
--- XoopsModules/extgallery/trunk/modules/extgallery/batch/index.html (rev 0)
+++ XoopsModules/extgallery/trunk/modules/extgallery/batch/index.html 2013-07-10 11:23:00 UTC (rev 11824)
@@ -0,0 +1 @@
+<script>history.go(-1);</script>
\ No newline at end of file
Modified: XoopsModules/extgallery/trunk/modules/extgallery/class/ExtgalleryPersistableObjectHandler.php
===================================================================
--- XoopsModules/extgallery/trunk/modules/extgallery/class/ExtgalleryPersistableObjectHandler.php 2013-07-10 06:36:20 UTC (rev 11823)
+++ XoopsModules/extgallery/trunk/modules/extgallery/class/ExtgalleryPersistableObjectHandler.php 2013-07-10 11:23:00 UTC (rev 11824)
@@ -1,650 +1,650 @@
-<?php
-/**
- * ExtGallery Class Manager
- *
- * You may not change or alter any portion of this comment or credits
- * of supporting developers from this source code or any supporting source code
- * which is considered copyrighted (c) material of the original comment or credit authors.
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * @copyright The XOOPS Project http://sourceforge.net/projects/xoops/
- * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
- * @author Zoullou (http://www.zoullou.net)
- * @package ExtGallery
- * @version $Id$
- */
-
-
-/**
-* Persistable Object Handler class.
-* This class is responsible for providing data access mechanisms to the data source
-* of derived class objects.
-*
-* @author Jan Keller Pedersen <mit...@xo...> - IDG Danmark A/S <www.idg.dk>
-* @copyright copyright (c) 2000-2004 XOOPS.org
-* @package Kernel
-*/
-
-class ExtgalleryPersistableObjectHandler extends XoopsObjectHandler {
-
- /**#@+
- * Information about the class, the handler is managing
- *
- * @var string
- */
- var $table;
- var $keyName;
- var $className;
- var $identifierName;
- /**#@-*/
-
- /**
- * Constructor - called from child classes
- * @param object $db {@link XoopsDatabase} object
- * @param string $tablename Name of database table
- * @param string $classname Name of Class, this handler is managing
- * @param string $keyname Name of the property, holding the key
- *
- * @return void
- */
- function ExtgalleryPersistableObjectHandler(&$db, $tablename, $classname, $keyname, $idenfierName = false) {
- $this->XoopsObjectHandler($db);
- $this->table = $db->prefix($tablename);
- $this->keyName = $keyname;
- $this->className = $classname;
- if ($idenfierName != false) {
- $this->identifierName = $idenfierName;
- }
- }
-
- /**
- * create a new user
- *
- * @param bool $isNew Flag the new objects as "new"?
- *
- * @return object
- */
- /* function &create($isNew = true) {
- //DNPROSSI - 5.3.0 Assigning the return value of new by reference is deprecated PHP 5.3
- //Kept for backward compatability
- if (version_compare(PHP_VERSION, '5.3.0', '<'))
- {
- $obj =& new $this->className();
- }
- else
- {
- $obj = new $this->className();
- }
- if ($isNew === true) {
- $obj->setNew();
- }
- return $obj;
- } */
-
- function &create($isNew = true)
- {
- $obj = new $this->className();
- if ($isNew === true) {
- $obj->setNew();
- }
- return $obj;
- }
-
- /**
- * retrieve an object
- *
- * @param mixed $id ID of the object - or array of ids for joint keys. Joint keys MUST be given in the same order as in the constructor
- * @param bool $as_object whether to return an object or an array
- * @return mixed reference to the object, FALSE if failed
- */
- function &get($id, $as_object = true) {
- if (is_array($this->keyName)) {
- $criteria = new CriteriaCompo();
- for ($i = 0; $i < count($this->keyName); $i++) {
- $criteria->add(new Criteria($this->keyName[$i], intval($id[$i])));
- }
- } else {
- $criteria = new Criteria($this->keyName, intval($id));
- }
- $criteria->setLimit(1);
- $obj_array = $this->getObjects($criteria, false, $as_object);
- if (count($obj_array) != 1) {
- return $this->create();
- }
- return $obj_array[0];
- }
-
- /**
- * retrieve objects from the database
- *
- * @param object $criteria {@link CriteriaElement} conditions to be met
- * @param bool $id_as_key use the ID as key for the array?
- * @param bool $as_object return an array of objects?
- *
- * @return array
- */
- function &getObjects($criteria = null, $id_as_key = false, $as_object = true)
- {
- $ret = array();
- $limit = $start = 0;
- $sql = 'SELECT * FROM '.$this->table;
- if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
- $sql .= ' '.$criteria->renderWhere();
- if ($criteria->getSort() != '') {
- $sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder();
- }
- $limit = $criteria->getLimit();
- $start = $criteria->getStart();
- }
- $result = $this->db->query($sql, $limit, $start);
- if (!$result) {
- return $ret;
- }
-
- $ret = $this->convertResultSet($result, $id_as_key, $as_object);
- return $ret;
- }
-
- /**
- * Convert a database resultset to a returnable array
- *
- * @param object $result database resultset
- * @param bool $id_as_key - should NOT be used with joint keys
- * @param bool $as_object
- *
- * @return array
- */
- function convertResultSet($result, $id_as_key = false, $as_object = true) {
- $ret = array();
- while ($myrow = $this->db->fetchArray($result)) {
- $obj =& $this->create(false);
- $obj->assignVars($myrow);
- if (!$id_as_key) {
- if ($as_object) {
- $ret[] =& $obj;
- }
- else {
- $row = array();
- $vars = $obj->getVars();
- foreach (array_keys($vars) as $i) {
- $row[$i] = $obj->getVar($i);
- }
- $ret[] = $row;
- }
- } else {
- if ($as_object) {
- $ret[$myrow[$this->keyName]] =& $obj;
- }
- else {
- $row = array();
- $vars = $obj->getVars();
- foreach (array_keys($vars) as $i) {
- $row[$i] = $obj->getVar($i);
- }
- $ret[$myrow[$this->keyName]] = $row;
- }
- }
- unset($obj);
- }
-
- return $ret;
- }
-
- /**
- * Retrieve a list of objects as arrays - DON'T USE WITH JOINT KEYS
- *
- * @param object $criteria {@link CriteriaElement} conditions to be met
- * @param int $limit Max number of objects to fetch
- * @param int $start Which record to start at
- *
- * @return array
- */
- function getList($criteria = null, $limit = 0, $start = 0) {
- $ret = array();
- if ($criteria == null) {
- $criteria = new CriteriaCompo();
- }
-
- if ($criteria->getSort() == '') {
- $criteria->setSort($this->identifierName);
- }
-
- $sql = 'SELECT '.$this->keyName;
- if(!empty($this->identifierName)){
- $sql .= ', '.$this->identifierName;
- }
- $sql .= ' FROM '.$this->table;
- if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
- $sql .= ' '.$criteria->renderWhere();
- if ($criteria->getSort() != '') {
- $sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder();
- }
- $limit = $criteria->getLimit();
- $start = $criteria->getStart();
- }
- $result = $this->db->query($sql, $limit, $start);
- if (!$result) {
- return $ret;
- }
-
- $myts =& MyTextSanitizer::getInstance();
- while ($myrow = $this->db->fetchArray($result)) {
- //identifiers should be textboxes, so sanitize them like that
- $ret[$myrow[$this->keyName]] = empty($this->identifierName)?1:$myts->htmlSpecialChars($myrow[$this->identifierName]);
- }
- return $ret;
- }
-
- /**
-
- * count objects matching a condition
- *
- * @param object $criteria {@link CriteriaElement} to match
- * @return int count of objects
- */
- function getCount($criteria = null)
- {
- $field = "";
- $groupby = false;
- if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
- if ($criteria->groupby != "") {
- $groupby = true;
- $field = $criteria->groupby.", "; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used
- }
- }
- $sql = 'SELECT '.$field.'COUNT(*) FROM '.$this->table;
- if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
- $sql .= ' '.$criteria->renderWhere();
- if ($criteria->groupby != "") {
- $sql .= $criteria->getGroupby();
- }
- }
- $result = $this->db->query($sql);
- if (!$result) {
- return 0;
- }
- if ($groupby == false) {
- list($count) = $this->db->fetchRow($result);
- return $count;
- }
- else {
- $ret = array();
- while (list($id, $count) = $this->db->fetchRow($result)) {
- $ret[$id] = $count;
- }
- return $ret;
- }
- }
-
- /**
- * delete an object from the database
- *
- * @param mixed $id id of the object to delete
- * @param bool $force
- * @return bool FALSE if failed.
- */
- function delete($id, $force = false)
- {
- if (is_array($this->keyName)) {
- $clause = array();
- for ($i = 0; $i < count($this->keyName); $i++) {
- $clause[] = $this->keyName[$i]." = ".$id[$i];
- }
- $whereclause = implode(" AND ", $clause);
- }
- else {
- $whereclause = $this->keyName." = ".$id;
- }
- $sql = "DELETE FROM ".$this->table." WHERE ".$whereclause;
- if (false != $force) {
- $result = $this->db->queryF($sql);
- } else {
- $result = $this->db->query($sql);
- }
- if (!$result) {
- return false;
- }
- return true;
- }
-
- /**
- * insert a new object in the database
- *
- * @param object $obj reference to the object
- * @param bool $force whether to force the query execution despite security settings
- * @param bool $checkObject check if the object is dirty and clean the attributes
- * @return bool FALSE if failed, TRUE if already present and unchanged or successful
- */
-
- function insert(&$obj, $force = false, $checkObject = true)
- {
- if ($checkObject != false) {
- if (!is_object($obj)) {
- var_dump($obj);
- return false;
- }
- /**
- * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5
- */
- if (!is_a($obj, $this->className)) {
- $obj->setErrors(get_class($obj)." Differs from ".$this->className);
- return false;
- }
- }
- if (!$obj->cleanVars()) {
- return false;
- }
-
- foreach ($obj->cleanVars as $k => $v) {
- if ($obj->vars[$k]['data_type'] == XOBJ_DTYPE_INT) {
- $cleanvars[$k] = intval($v);
- } elseif ( is_array( $v ) ) {
- $cleanvars[ $k ] = $this->db->quoteString( implode( ',', $v ) );
- } else {
- $cleanvars[$k] = $this->db->quoteString($v);
- }
- }
- if ($obj->isNew()) {
- if (!is_array($this->keyName)) {
- if ($cleanvars[$this->keyName] < 1) {
- $cleanvars[$this->keyName] = $this->db->genId($this->table.'_'.$this->keyName.'_seq');
- }
- }
- $sql = "INSERT INTO ".$this->table." (".implode(',', array_keys($cleanvars)).") VALUES (".implode(',', array_values($cleanvars)) .")";
- } else {
- $sql = "UPDATE ".$this->table." SET";
- foreach ($cleanvars as $key => $value) {
- if ((!is_array($this->keyName) && $key == $this->keyName) || (is_array($this->keyName) && in_array($key, $this->keyName))) {
- continue;
- }
- if (isset($notfirst) ) {
- $sql .= ",";
- }
- $sql .= " ".$key." = ".$value;
- $notfirst = true;
- }
- if (is_array($this->keyName)) {
- $whereclause = "";
- for ($i = 0; $i < count($this->keyName); $i++) {
- if ($i > 0) {
- $whereclause .= " AND ";
- }
- $whereclause .= $this->keyName[$i]." = ".$obj->getVar($this->keyName[$i]);
- }
- }
- else {
- $whereclause = $this->keyName." = ".$obj->getVar($this->keyName);
- }
- $sql .= " WHERE ".$whereclause;
- }
- if (false != $force) {
- $result = $this->db->queryF($sql);
- } else {
- $result = $this->db->query($sql);
- }
- if (!$result) {
- return false;
- }
- if ($obj->isNew() && !is_array($this->keyName)) {
- $obj->assignVar($this->keyName, $this->db->getInsertId());
- }
- return true;
- }
-
- /**
- * Change a value for objects with a certain criteria
- *
- * @param string $fieldname Name of the field
- * @param string $fieldvalue Value to write
- * @param object $criteria {@link CriteriaElement}
- *
- * @return bool
- **/
- function updateAll($fieldname, $fieldvalue, $criteria = null, $force = false)
- {
- $set_clause = $fieldname . ' = ';
- if ( is_numeric( $fieldvalue ) ) {
- $set_clause .= $fieldvalue;
- } elseif ( is_array( $fieldvalue ) ) {
- $set_clause .= $this->db->quoteString( implode( ',', $fieldvalue ) );
- } else {
- $set_clause .= $this->db->quoteString( $fieldvalue );
- }
- $sql = 'UPDATE '.$this->table.' SET '.$set_clause;
- if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
- $sql .= ' '.$criteria->renderWhere();
- }
- if (false != $force) {
- $result = $this->db->queryF($sql);
- } else {
- $result = $this->db->query($sql);
- }
- if (!$result) {
- return false;
- }
- return true;
- }
-
- function updateFieldValue($fieldname, $fieldvalue, $criteria = null, $force = true)
- {
- $sql = 'UPDATE '.$this->table.' SET '.$fieldname.' = '.$fieldvalue;
- if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
- $sql .= ' '.$criteria->renderWhere();
- }
- if (false != $force) {
- $result = $this->db->queryF($sql);
- } else {
- $result = $this->db->query($sql);
- }
- if (!$result) {
- return false;
- }
- return true;
- }
-
- /**
- * delete all objects meeting the conditions
- *
- * @param object $criteria {@link CriteriaElement} with conditions to meet
- * @return bool
- */
-
- function deleteAll($criteria = null)
- {
- if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
- $sql = 'DELETE FROM '.$this->table;
- $sql .= ' '.$criteria->renderWhere();
- if (!$this->db->query($sql)) {
- return false;
- }
- $rows = $this->db->getAffectedRows();
- return $rows > 0 ? $rows : true;
- }
- return false;
- }
-
- function _toObject($data) {
- if(is_array($data)) {
- $ret = array();
- foreach($data as $v) {
- $object = new $this->className();
- $object->assignVars($v);
- $ret[] = $object;
- }
- return $ret;
- } else {
- $object = new $this->className();
- $object->assignVars($v);
- return $object;
- }
- }
-
- function objectToArray($objects, $externalKeys = array(), $format = 's') {
- static $cache;
-
- $ret = array();
- if(is_array($objects)) {
- $i = 0;
- foreach($objects as $object) {
- $vars = $object->getVars();
- foreach ($vars as $k => $v) {
- $ret[$i][$k] = $object->getVar($k,$format);
- }
- foreach($externalKeys as $key) {
- // Replace external key by corresponding object
- $externalKey = $object->getExternalKey($key);
- if($ret[$i][$key] != 0) {
- // Retriving data if isn't cached
- if(!isset($cached[$externalKey['keyName']][$ret[$i][$key]])) {
- if($externalKey['core']) {
- $handler = xoops_gethandler($externalKey['className']);
- } else {
- $handler = xoops_getmodulehandler($externalKey['className'], 'extgallery');
- }
- $cached[$externalKey['keyName']][$ret[$i][$key]] = $this->objectToArrayWithoutExternalKey($handler->$externalKey['getMethodeName']($ret[$i][$key]),$format);
- }
- $ret[$i][$externalKey['keyName']] = $cached[$externalKey['keyName']][$ret[$i][$key]];
- }
- unset($ret[$i][$key]);
- }
- $i++;
- }
- } else {
- $vars = $objects->getVars();
- foreach ($vars as $k => $v) {
- $ret[$k] = $objects->getVar($k,$format);
- }
- foreach($externalKeys as $key) {
- // Replace external key by corresponding object
- $externalKey = $objects->getExternalKey($key);
- if($ret[$key] != 0) {
- // Retriving data if isn't cached
- if(!isset($cached[$externalKey['keyName']][$ret[$key]])) {
- if($externalKey['core']) {
- $handler = xoops_gethandler($externalKey['className']);
- } else {
- $handler = xoops_getmodulehandler($externalKey['className'], 'extgallery');
- }
- $cached[$externalKey['keyName']][$ret[$key]] = $this->objectToArrayWithoutExternalKey($handler->$externalKey['getMethodeName']($ret[$key]),$format);
- }
- $ret[$externalKey['keyName']] = $cached[$externalKey['keyName']][$ret[$key]];
- }
- unset($ret[$key]);
- }
- }
- return $ret;
- }
-
- function objectToArrayWithoutExternalKey($object,$format = 's') {
- $ret = array();
- if($object != null) {
- $vars = $object->getVars();
- foreach ($vars as $k => $v) {
- $ret[$k] = $object->getVar($k,$format);
- }
- }
- return $ret;
- }
-
- function updateCounter($fieldname,$criteria,$op='+') {
- $sql = 'UPDATE '.$this->table.' SET '.$fieldname.' = '.$fieldname.$op.'1';
- $sql .= ' '.$criteria->renderWhere();
- $result = $this->db->queryF($sql);
- if (!$result) {
- return false;
- }
- return true;
- }
-
- function getSum($criteria = null,$sum = '*')
- {
- $field = "";
- $groupby = false;
- if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
- if ($criteria->groupby != "") {
- $groupby = true;
- $field = $criteria->groupby.", "; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used
- }
- }
- $sql = 'SELECT '.$field."SUM($sum) FROM ".$this->table;
- if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
- $sql .= ' '.$criteria->renderWhere();
- if ($criteria->groupby != "") {
- $sql .= $criteria->getGroupby();
- }
- }
- $result = $this->db->query($sql);
- if (!$result) {
- return 0;
- }
- if ($groupby == false) {
- list($sum) = $this->db->fetchRow($result);
- return $sum;
- }
- else {
- $ret = array();
- while (list($id, $sum) = $this->db->fetchRow($result)) {
- $ret[$id] = $sum;
- }
- return $ret;
- }
- }
-
- function getMax($criteria = null,$max = '*')
- {
- $field = "";
- $groupby = false;
- if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
- if ($criteria->groupby != "") {
- $groupby = true;
- $field = $criteria->groupby.", "; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used
- }
- }
- $sql = 'SELECT '.$field."MAX($max) FROM ".$this->table;
- if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
- $sql .= ' '.$criteria->renderWhere();
- if ($criteria->groupby != "") {
- $sql .= $criteria->getGroupby();
- }
- }
- $result = $this->db->query($sql);
- if (!$result) {
- return 0;
- }
- if ($groupby == false) {
- list($max) = $this->db->fetchRow($result);
- return $max;
- } else {
- $ret = array();
- while (list($id, $max) = $this->db->fetchRow($result)) {
- $ret[$id] = $max;
- }
- return $ret;
- }
- }
-
- function getAvg($criteria = null,$avg = '*')
- {
- $field = "";
-
- $sql = 'SELECT '.$field."AVG($avg) FROM ".$this->table;
- if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
- $sql .= ' '.$criteria->renderWhere();
- }
- $result = $this->db->query($sql);
- if (!$result) {
- return 0;
- }
- list($sum) = $this->db->fetchRow($result);
- return $sum;
- }
-
- function getInsertId() {
- return $this->db->getInsertId();
- }
-
-}
-
+<?php
+/**
+ * ExtGallery Class Manager
+ *
+ * You may not change or alter any portion of this comment or credits
+ * of supporting developers from this source code or any supporting source code
+ * which is considered copyrighted (c) material of the original comment or credit authors.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * @copyright The XOOPS Project http://sourceforge.net/projects/xoops/
+ * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
+ * @author Zoullou (http://www.zoullou.net)
+ * @package ExtGallery
+ * @version $Id$
+ */
+
+
+/**
+* Persistable Object Handler class.
+* This class is responsible for providing data access mechanisms to the data source
+* of derived class objects.
+*
+* @author Jan Keller Pedersen <mit...@xo...> - IDG Danmark A/S <www.idg.dk>
+* @copyright copyright (c) 2000-2004 XOOPS.org
+* @package Kernel
+*/
+
+class ExtgalleryPersistableObjectHandler extends XoopsObjectHandler {
+
+ /**#@+
+ * Information about the class, the handler is managing
+ *
+ * @var string
+ */
+ var $table;
+ var $keyName;
+ var $className;
+ var $identifierName;
+ /**#@-*/
+
+ /**
+ * Constructor - called from child classes
+ * @param object $db {@link XoopsDatabase} object
+ * @param string $tablename Name of database table
+ * @param string $classname Name of Class, this handler is managing
+ * @param string $keyname Name of the property, holding the key
+ *
+ * @return void
+ */
+ function ExtgalleryPersistableObjectHandler(&$db, $tablename, $classname, $keyname, $idenfierName = false) {
+ $this->XoopsObjectHandler($db);
+ $this->table = $db->prefix($tablename);
+ $this->keyName = $keyname;
+ $this->className = $classname;
+ if ($idenfierName != false) {
+ $this->identifierName = $idenfierName;
+ }
+ }
+
+ /**
+ * create a new user
+ *
+ * @param bool $isNew Flag the new objects as "new"?
+ *
+ * @return object
+ */
+ /* function &create($isNew = true) {
+ //DNPROSSI - 5.3.0 Assigning the return value of new by reference is deprecated PHP 5.3
+ //Kept for backward compatability
+ if (version_compare(PHP_VERSION, '5.3.0', '<'))
+ {
+ $obj = new $this->className();
+ }
+ else
+ {
+ $obj = new $this->className();
+ }
+ if ($isNew === true) {
+ $obj->setNew();
+ }
+ return $obj;
+ } */
+
+ function &create($isNew = true)
+ {
+ $obj = new $this->className();
+ if ($isNew === true) {
+ $obj->setNew();
+ }
+ return $obj;
+ }
+
+ /**
+ * retrieve an object
+ *
+ * @param mixed $id ID of the object - or array of ids for joint keys. Joint keys MUST be given in the same order as in the constructor
+ * @param bool $as_object whether to return an object or an array
+ * @return mixed reference to the object, FALSE if failed
+ */
+ function &get($id, $as_object = true) {
+ if (is_array($this->keyName)) {
+ $criteria = new CriteriaCompo();
+ for ($i = 0; $i < count($this->keyName); $i++) {
+ $criteria->add(new Criteria($this->keyName[$i], intval($id[$i])));
+ }
+ } else {
+ $criteria = new Criteria($this->keyName, intval($id));
+ }
+ $criteria->setLimit(1);
+ $obj_array = $this->getObjects($criteria, false, $as_object);
+ if (count($obj_array) != 1) {
+ return $this->create();
+ }
+ return $obj_array[0];
+ }
+
+ /**
+ * retrieve objects from the database
+ *
+ * @param object $criteria {@link CriteriaElement} conditions to be met
+ * @param bool $id_as_key use the ID as key for the array?
+ * @param bool $as_object return an array of objects?
+ *
+ * @return array
+ */
+ function &getObjects($criteria = null, $id_as_key = false, $as_object = true)
+ {
+ $ret = array();
+ $limit = $start = 0;
+ $sql = 'SELECT * FROM '.$this->table;
+ if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
+ $sql .= ' '.$criteria->renderWhere();
+ if ($criteria->getSort() != '') {
+ $sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder();
+ }
+ $limit = $criteria->getLimit();
+ $start = $criteria->getStart();
+ }
+ $result = $this->db->query($sql, $limit, $start);
+ if (!$result) {
+ return $ret;
+ }
+
+ $ret = $this->convertResultSet($result, $id_as_key, $as_object);
+ return $ret;
+ }
+
+ /**
+ * Convert a database resultset to a returnable array
+ *
+ * @param object $result database resultset
+ * @param bool $id_as_key - should NOT be used with joint keys
+ * @param bool $as_object
+ *
+ * @return array
+ */
+ function convertResultSet($result, $id_as_key = false, $as_object = true) {
+ $ret = array();
+ while ($myrow = $this->db->fetchArray($result)) {
+ $obj =& $this->create(false);
+ $obj->assignVars($myrow);
+ if (!$id_as_key) {
+ if ($as_object) {
+ $ret[] =& $obj;
+ }
+ else {
+ $row = array();
+ $vars = $obj->getVars();
+ foreach (array_keys($vars) as $i) {
+ $row[$i] = $obj->getVar($i);
+ }
+ $ret[] = $row;
+ }
+ } else {
+ if ($as_object) {
+ $ret[$myrow[$this->keyName]] =& $obj;
+ }
+ else {
+ $row = array();
+ $vars = $obj->getVars();
+ foreach (array_keys($vars) as $i) {
+ $row[$i] = $obj->getVar($i);
+ }
+ $ret[$myrow[$this->keyName]] = $row;
+ }
+ }
+ unset($obj);
+ }
+
+ return $ret;
+ }
+
+ /**
+ * Retrieve a list of objects as arrays - DON'T USE WITH JOINT KEYS
+ *
+ * @param object $criteria {@link CriteriaElement} conditions to be met
+ * @param int $limit Max number of objects to fetch
+ * @param int $start Which record to start at
+ *
+ * @return array
+ */
+ function getList($criteria = null, $limit = 0, $start = 0) {
+ $ret = array();
+ if ($criteria == null) {
+ $criteria = new CriteriaCompo();
+ }
+
+ if ($criteria->getSort() == '') {
+ $criteria->setSort($this->identifierName);
+ }
+
+ $sql = 'SELECT '.$this->keyName;
+ if(!empty($this->identifierName)){
+ $sql .= ', '.$this->identifierName;
+ }
+ $sql .= ' FROM '.$this->table;
+ if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
+ $sql .= ' '.$criteria->renderWhere();
+ if ($criteria->getSort() != '') {
+ $sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder();
+ }
+ $limit = $criteria->getLimit();
+ $start = $criteria->getStart();
+ }
+ $result = $this->db->query($sql, $limit, $start);
+ if (!$result) {
+ return $ret;
+ }
+
+ $myts =& MyTextSanitizer::getInstance();
+ while ($myrow = $this->db->fetchArray($result)) {
+ //identifiers should be textboxes, so sanitize them like that
+ $ret[$myrow[$this->keyName]] = empty($this->identifierName)?1:$myts->htmlSpecialChars($myrow[$this->identifierName]);
+ }
+ return $ret;
+ }
+
+ /**
+
+ * count objects matching a condition
+ *
+ * @param object $criteria {@link CriteriaElement} to match
+ * @return int count of objects
+ */
+ function getCount($criteria = null)
+ {
+ $field = "";
+ $groupby = false;
+ if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
+ if ($criteria->groupby != "") {
+ $groupby = true;
+ $field = $criteria->groupby.", "; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used
+ }
+ }
+ $sql = 'SELECT '.$field.'COUNT(*) FROM '.$this->table;
+ if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
+ $sql .= ' '.$criteria->renderWhere();
+ if ($criteria->groupby != "") {
+ $sql .= $criteria->getGroupby();
+ }
+ }
+ $result = $this->db->query($sql);
+ if (!$result) {
+ return 0;
+ }
+ if ($groupby == false) {
+ list($count) = $this->db->fetchRow($result);
+ return $count;
+ }
+ else {
+ $ret = array();
+ while (list($id, $count) = $this->db->fetchRow($result)) {
+ $ret[$id] = $count;
+ }
+ return $ret;
+ }
+ }
+
+ /**
+ * delete an object from the database
+ *
+ * @param mixed $id id of the object to delete
+ * @param bool $force
+ * @return bool FALSE if failed.
+ */
+ function delete($id, $force = false)
+ {
+ if (is_array($this->keyName)) {
+ $clause = array();
+ for ($i = 0; $i < count($this->keyName); $i++) {
+ $clause[] = $this->keyName[$i]." = ".$id[$i];
+ }
+ $whereclause = implode(" AND ", $clause);
+ }
+ else {
+ $whereclause = $this->keyName." = ".$id;
+ }
+ $sql = "DELETE FROM ".$this->table." WHERE ".$whereclause;
+ if (false != $force) {
+ $result = $this->db->queryF($sql);
+ } else {
+ $result = $this->db->query($sql);
+ }
+ if (!$result) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * insert a new object in the database
+ *
+ * @param object $obj reference to the object
+ * @param bool $force whether to force the query execution despite security settings
+ * @param bool $checkObject check if the object is dirty and clean the attributes
+ * @return bool FALSE if failed, TRUE if already present and unchanged or successful
+ */
+
+ function insert(&$obj, $force = false, $checkObject = true)
+ {
+ if ($checkObject != false) {
+ if (!is_object($obj)) {
+ var_dump($obj);
+ return false;
+ }
+ /**
+ * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5
+ */
+ if (!is_a($obj, $this->className)) {
+ $obj->setErrors(get_class($obj)." Differs from ".$this->className);
+ return false;
+ }
+ }
+ if (!$obj->cleanVars()) {
+ return false;
+ }
+
+ foreach ($obj->cleanVars as $k => $v) {
+ if ($obj->vars[$k]['data_type'] == XOBJ_DTYPE_INT) {
+ $cleanvars[$k] = intval($v);
+ } elseif ( is_array( $v ) ) {
+ $cleanvars[ $k ] = $this->db->quoteString( implode( ',', $v ) );
+ } else {
+ $cleanvars[$k] = $this->db->quoteString($v);
+ }
+ }
+ if ($obj->isNew()) {
+ if (!is_array($this->keyName)) {
+ if ($cleanvars[$this->keyName] < 1) {
+ $cleanvars[$this->keyName] = $this->db->genId($this->table.'_'.$this->keyName.'_seq');
+ }
+ }
+ $sql = "INSERT INTO ".$this->table." (".implode(',', array_keys($cleanvars)).") VALUES (".implode(',', array_values($cleanvars)) .")";
+ } else {
+ $sql = "UPDATE ".$this->table." SET";
+ foreach ($cleanvars as $key => $value) {
+ if ((!is_array($this->keyName) && $key == $this->keyName) || (is_array($this->keyName) && in_array($key, $this->keyName))) {
+ continue;
+ }
+ if (isset($notfirst) ) {
+ $sql .= ",";
+ }
+ $sql .= " ".$key." = ".$value;
+ $notfirst = true;
+ }
+ if (is_array($this->keyName)) {
+ $whereclause = "";
+ for ($i = 0; $i < count($this->keyName); $i++) {
+ if ($i > 0) {
+ $whereclause .= " AND ";
+ }
+ $whereclause .= $this->keyName[$i]." = ".$obj->getVar($this->keyName[$i]);
+ }
+ }
+ else {
+ $whereclause = $this->keyName." = ".$obj->getVar($this->keyName);
+ }
+ $sql .= " WHERE ".$whereclause;
+ }
+ if (false != $force) {
+ $result = $this->db->queryF($sql);
+ } else {
+ $result = $this->db->query($sql);
+ }
+ if (!$result) {
+ return false;
+ }
+ if ($obj->isNew() && !is_array($this->keyName)) {
+ $obj->assignVar($this->keyName, $this->db->getInsertId());
+ }
+ return true;
+ }
+
+ /**
+ * Change a value for objects with a certain criteria
+ *
+ * @param string $fieldname Name of the field
+ * @param string $fieldvalue Value to write
+ * @param object $criteria {@link CriteriaElement}
+ *
+ * @return bool
+ **/
+ function updateAll($fieldname, $fieldvalue, $criteria = null, $force = false)
+ {
+ $set_clause = $fieldname . ' = ';
+ if ( is_numeric( $fieldvalue ) ) {
+ $set_clause .= $fieldvalue;
+ } elseif ( is_array( $fieldvalue ) ) {
+ $set_clause .= $this->db->quoteString( implode( ',', $fieldvalue ) );
+ } else {
+ $set_clause .= $this->db->quoteString( $fieldvalue );
+ }
+ $sql = 'UPDATE '.$this->table.' SET '.$set_clause;
+ if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
+ $sql .= ' '.$criteria->renderWhere();
+ }
+ if (false != $force) {
+ $result = $this->db->queryF($sql);
+ } else {
+ $result = $this->db->query($sql);
+ }
+ if (!$result) {
+ return false;
+ }
+ return true;
+ }
+
+ function updateFieldValue($fieldname, $fieldvalue, $criteria = null, $force = true)
+ {
+ $sql = 'UPDATE '.$this->table.' SET '.$fieldname.' = '.$fieldvalue;
+ if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
+ $sql .= ' '.$criteria->renderWhere();
+ }
+ if (false != $force) {
+ $result = $this->db->queryF($sql);
+ } else {
+ $result = $this->db->query($sql);
+ }
+ if (!$result) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * delete all objects meeting the conditions
+ *
+ * @param object $criteria {@link CriteriaElement} with conditions to meet
+ * @return bool
+ */
+
+ function deleteAll($criteria = null)
+ {
+ if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
+ $sql = 'DELETE FROM '.$this->table;
+ $sql .= ' '.$criteria->renderWhere();
+ if (!$this->db->query($sql)) {
+ return false;
+ }
+ $rows = $this->db->getAffectedRows();
+ return $rows > 0 ? $rows : true;
+ }
+ return false;
+ }
+
+ function _toObject($data) {
+ if(is_array($data)) {
+ $ret = array();
+ foreach($data as $v) {
+ $object = new $this->className();
+ $object->assignVars($v);
+ $ret[] = $object;
+ }
+ return $ret;
+ } else {
+ $object = new $this->className();
+ $object->assignVars($v);
+ return $object;
+ }
+ }
+
+ function objectToArray($objects, $externalKeys = array(), $format = 's') {
+ static $cache;
+
+ $ret = array();
+ if(is_array($objects)) {
+ $i = 0;
+ foreach($objects as $object) {
+ $vars = $object->getVars();
+ foreach ($vars as $k => $v) {
+ $ret[$i][$k] = $object->getVar($k,$format);
+ }
+ foreach($externalKeys as $key) {
+ // Replace external key by corresponding object
+ $externalKey = $object->getExternalKey($key);
+ if($ret[$i][$key] != 0) {
+ // Retriving data if isn't cached
+ if(!isset($cached[$externalKey['keyName']][$ret[$i][$key]])) {
+ if($externalKey['core']) {
+ $handler = xoops_gethandler($externalKey['className']);
+ } else {
+ $handler = xoops_getmodulehandler($externalKey['className'], 'extgallery');
+ }
+ $cached[$externalKey['keyName']][$ret[$i][$key]] = $this->objectToArrayWithoutExternalKey($handler->$externalKey['getMethodeName']($ret[$i][$key]),$format);
+ }
+ $ret[$i][$externalKey['keyName']] = $cached[$externalKey['keyName']][$ret[$i][$key]];
+ }
+ unset($ret[$i][$key]);
+ }
+ $i++;
+ }
+ } else {
+ $vars = $objects->getVars();
+ foreach ($vars as $k => $v) {
+ $ret[$k] = $objects->getVar($k,$format);
+ }
+ foreach($externalKeys as $key) {
+ // Replace external key by corresponding object
+ $externalKey = $objects->getExternalKey($key);
+ if($ret[$key] != 0) {
+ // Retriving data if isn't cached
+ if(!isset($cached[$externalKey['keyName']][$ret[$key]])) {
+ if($externalKey['core']) {
+ $handler = xoops_gethandler($externalKey['className']);
+ } else {
+ $handler = xoops_getmodulehandler($externalKey['className'], 'extgallery');
+ }
+ $cached[$externalKey['keyName']][$ret[$key]] = $this->objectToArrayWithoutExternalKey($handler->$externalKey['getMethodeName']($ret[$key]),$format);
+ }
+ $ret[$externalKey['keyName']] = $cached[$externalKey['keyName']][$ret[$key]];
+ }
+ unset($ret[$key]);
+ }
+ }
+ return $ret;
+ }
+
+ function objectToArrayWithoutExternalKey($object,$format = 's') {
+ $ret = array();
+ if($object != null) {
+ $vars = $object->getVars();
+ foreach ($vars as $k => $v) {
+ $ret[$k] = $object->getVar($k,$format);
+ }
+ }
+ return $ret;
+ }
+
+ function updateCounter($fieldname,$criteria,$op='+') {
+ $sql = 'UPDATE '.$this->table.' SET '.$fieldname.' = '.$fieldname.$op.'1';
+ $sql .= ' '.$criteria->renderWhere();
+ $result = $this->db->queryF($sql);
+ if (!$result) {
+ return false;
+ }
+ return true;
+ }
+
+ function getSum($criteria = null,$sum = '*')
+ {
+ $field = "";
+ $groupby = false;
+ if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
+ if ($criteria->groupby != "") {
+ $groupby = true;
+ $field = $criteria->groupby.", "; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used
+ }
+ }
+ $sql = 'SELECT '.$field."SUM($sum) FROM ".$this->table;
+ if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
+ $sql .= ' '.$criteria->renderWhere();
+ if ($criteria->groupby != "") {
+ $sql .= $criteria->getGroupby();
+ }
+ }
+ $result = $this->db->query($sql);
+ if (!$result) {
+ return 0;
+ }
+ if ($groupby == false) {
+ list($sum) = $this->db->fetchRow($result);
+ return $sum;
+ }
+ else {
+ $ret = array();
+ while (list($id, $sum) = $this->db->fetchRow($result)) {
+ $ret[$id] = $sum;
+ }
+ return $ret;
+ }
+ }
+
+ function getMax($criteria = null,$max = '*')
+ {
+ $field = "";
+ $groupby = false;
+ if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
+ if ($criteria->groupby != "") {
+ $groupby = true;
+ $field = $criteria->groupby.", "; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used
+ }
+ }
+ $sql = 'SELECT '.$field."MAX($max) FROM ".$this->table;
+ if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
+ $sql .= ' '.$criteria->renderWhere();
+ if ($criteria->groupby != "") {
+ $sql .= $criteria->getGroupby();
+ }
+ }
+ $result = $this->db->query($sql);
+ if (!$result) {
+ return 0;
+ }
+ if ($groupby == false) {
+ list($max) = $this->db->fetchRow($result);
+ return $max;
+ } else {
+ $ret = array();
+ while (list($id, $max) = $this->db->fetchRow($result)) {
+ $ret[$id] = $max;
+ }
+ return $ret;
+ }
+ }
+
+ function getAvg($criteria = null,$avg = '*')
+ {
+ $field = "";
+
+ $sql = 'SELECT '.$field."AVG($avg) FROM ".$this->table;
+ if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
+ $sql .= ' '.$criteria->renderWhere();
+ }
+ $result = $this->db->query($sql);
+ if (!$result) {
+ return 0;
+ }
+ list($sum) = $this->db->fetchRow($result);
+ return $sum;
+ }
+
+ function getInsertId() {
+ return $this->db->getInsertId();
+ }
+
+}
+
?>
\ No newline at end of file
Modified: XoopsModules/extgallery/trunk/modules/extgallery/class/pear/PEAR.php
===================================================================
--- XoopsModules/extgallery/trunk/modules/extgallery/class/pear/PEAR.php 2013-07-10 06:36:20 UTC (rev 11823)
+++ XoopsModules/extgallery/trunk/modules/extgallery/class/pear/PEAR.php 2013-07-10 11:23:00 UTC (rev 11824)
@@ -1,1071 +1,1071 @@
-<?php
-/**
- * PEAR, the PHP Extension and Application Repository
- *
- * PEAR class and PEAR_Error class
- *
- * PHP versions 4 and 5
- *
- * @category pear
- * @package PEAR
- * @author Sterling Hughes <ste...@ph...>
- * @author Stig Bakken <ss...@ph...>
- * @author Tomas V.V.Cox <co...@id...>
- * @author Greg Beaver <ce...@ph...>
- * @copyright 1997-2010 The Authors
- * @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id$
- * @link http://pear.php.net/package/PEAR
- * @since File available since Release 0.1
- */
-
-/**#@+
- * ERROR constants
- */
-define('PEAR_ERROR_RETURN', 1);
-define('PEAR_ERROR_PRINT', 2);
-define('PEAR_ERROR_TRIGGER', 4);
-define('PEAR_ERROR_DIE', 8);
-define('PEAR_ERROR_CALLBACK', 16);
-/**
- * WARNING: obsolete
- * @deprecated
- */
-define('PEAR_ERROR_EXCEPTION', 32);
-/**#@-*/
-define('PEAR_ZE2', (function_exists('version_compare') &&
- version_compare(zend_version(), "2-dev", "ge")));
-
-if (substr(PHP_OS, 0, 3) == 'WIN') {
- define('OS_WINDOWS', true);
- define('OS_UNIX', false);
- define('PEAR_OS', 'Windows');
-} else {
- define('OS_WINDOWS', false);
- define('OS_UNIX', true);
- define('PEAR_OS', 'Unix'); // blatant assumption
-}
-
-$GLOBALS['_PEAR_default_error_mode'] = PEAR_ERROR_RETURN;
-$GLOBALS['_PEAR_default_error_options'] = E_USER_NOTICE;
-$GLOBALS['_PEAR_destructor_object_list'] = array();
-$GLOBALS['_PEAR_shutdown_funcs'] = array();
-$GLOBALS['_PEAR_error_handler_stack'] = array();
-
-@ini_set('track_errors', true);
-
-/**
- * Base class for other PEAR classes. Provides rudimentary
- * emulation of destructors.
- *
- * If you want a destructor in your class, inherit PEAR and make a
- * destructor method called _yourclassname (same name as the
- * constructor, but with a "_" prefix). Also, in your constructor you
- * have to call the PEAR constructor: $this->PEAR();.
- * The destructor method will be called without parameters. Note that
- * at in some SAPI implementations (such as Apache), any output during
- * the request shutdown (in which destructors are called) seems to be
- * discarded. If you need to get any debug information from your
- * destructor, use error_log(), syslog() or something similar.
- *
- * IMPORTANT! To use the emulated destructors you need to create the
- * objects by reference: $obj =& new PEAR_child;
- *
- * @category pear
- * @package PEAR
- * @author Stig Bakken <ss...@ph...>
- * @author Tomas V.V. Cox <co...@id...>
- * @author Greg Beaver <ce...@ph...>
- * @copyright 1997-2006 The PHP Group
- * @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.4
- * @link http://pear.php.net/package/PEAR
- * @see PEAR_Error
- * @since Class available since PHP 4.0.2
- * @link http://pear.php.net/manual/en/core.pear.php#core.pear.pear
- */
-
- if (!class_exists('PEAR')) {
-class PEAR
-{
- /**
- * Whether to enable internal debug messages.
- *
- * @var bool
- * @access private
- */
- var $_debug = false;
-
- /**
- * Default error mode for this object.
- *
- * @var int
- * @access private
- */
- var $_default_error_mode = null;
-
- /**
- * Default error options used for this object when error mode
- * is PEAR_ERROR_TRIGGER.
- *
- * @var int
- * @access private
- */
- var $_default_error_options = null;
-
- /**
- * Default error handler (callback) for this object, if error mode is
- * PEAR_ERROR_CALLBACK.
- *
- * @var string
- * @access private
- */
- var $_default_error_handler = '';
-
- /**
- * Which class to use for error objects.
- *
- * @var string
- * @access private
- */
- var $_error_class = 'PEAR_Error';
-
- /**
- * An array of expected errors.
- *
- * @var array
- * @access private
- */
- var $_expected_errors = array();
-
- /**
- * Constructor. Registers this object in
- * $_PEAR_destructor_object_list for destructor emulation if a
- * destructor object exists.
- *
- * @param string $error_class (optional) which class to use for
- * error objects, defaults to PEAR_Error.
- * @access public
- * @return void
- */
- function PEAR($error_class = null)
- {
- $classname = strtolower(get_class($this));
- if ($this->_debug) {
- print "PEAR constructor called, class=$classname\n";
- }
-
- if ($error_class !== null) {
- $this->_error_class = $error_class;
- }
-
- while ($classname && strcasecmp($classname, "pear")) {
- $destructor = "_$classname";
- if (method_exists($this, $destructor)) {
- global $_PEAR_destructor_object_list;
- $_PEAR_destructor_object_list[] = &$this;
- if (!isset($GLOBALS['_PEAR_SHUTDOWN_REGISTERED'])) {
- register_shutdown_function("_PEAR_call_destructors");
- $GLOBALS['_PEAR_SHUTDOWN_REGISTERED'] = true;
- }
- break;
- } else {
- $classname = get_parent_class($classname);
- }
- }
- }
-
- /**
- * Destructor (the emulated type of...). Does nothing right now,
- * but is included for forward compatibility, so subclass
- * destructors should always call it.
- *
- * See the note in the class desciption about output from
- * destructors.
- *
- * @access public
- * @return void
- */
- function _PEAR() {
- if ($this->_debug) {
- printf("PEAR destructor called, class=%s\n", strtolower(get_class($this)));
- }
- }
-
- /**
- * If you have a class that's mostly/entirely static, and you need static
- * properties, you can use this method to simulate them. Eg. in your method(s)
- * do this: $myVar = &PEAR::getStaticProperty('myclass', 'myVar');
- * You MUST use a reference, or they will not persist!
- *
- * @access public
- * @param string $class The calling classname, to prevent clashes
- * @param string $var The variable to retrieve.
- * @return mixed A reference to the variable. If not set it will be
- * auto initialised to NULL.
- */
- 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];
- }
-
- /**
- * Use this function to register a shutdown method for static
- * classes.
- *
- * @access public
- * @param mixed $func The function name (or array of class/method) to call
- * @param mixed $args The arguments to pass to the function
- * @return void
- */
- function registerShutdownFunc($func, $args = array())
- {
- // if we are called statically, there is a potential
- // that no shutdown func is registered. Bug #6445
- if (!isset($GLOBALS['_PEAR_SHUTDOWN_REGISTERED'])) {
- register_shutdown_function("_PEAR_call_destructors");
- $GLOBALS['_PEAR_SHUTDOWN_REGISTERED'] = true;
- }
- $GLOBALS['_PEAR_shutdown_funcs'][] = array($func, $args);
- }
-
- /**
- * Tell whether a value is a PEAR error.
- *
- * @param mixed $data the value to test
- * @param int $code if $data is an error object, return true
- * only if $code is a string and
- * $obj->getMessage() == $code or
- * $code is an integer and $obj->getCode() == $code
- * @access public
- * @return bool true if parameter is an error
- */
- function isError($data, $code = null)
- {
- if (!is_a($data, 'PEAR_Error')) {
- return false;
- }
-
- if (is_null($code)) {
- return true;
- } elseif (is_string($code)) {
- return $data->getMessage() == $code;
- }
-
- return $data->getCode() == $code;
- }
-
- /**
- * Sets how errors generated by this object should be handled.
- * Can be invoked both in objects and statically. If called
- * statically, setErrorHandling sets the default behaviour for all
- * PEAR objects. If called in an object, setErrorHandling sets
- * the default behaviour for that object.
- *
- * @param int $mode
- * One of PEAR_ERROR_RETURN, PEAR_ERROR_PRINT,
- * PEAR_ERROR_TRIGGER, PEAR_ERROR_DIE,
- * PEAR_ERROR_CALLBACK or PEAR_ERROR_EXCEPTION.
- *
- * @param mixed $options
- * When $mode is PEAR_ERROR_TRIGGER, this is the error level (one
- * of E_USER_NOTICE, E_USER_WARNING or E_USER_ERROR).
- *
- * When $mode is PEAR_ERROR_CALLBACK, this parameter is expected
- * to be the callback function or method. A callback
- * function is a string with the name of the function, a
- * callback method is an array of two elements: the element
- * at index 0 is the object, and the element at index 1 is
- * the name of the method to call in the object.
- *
- * When $mode is PEAR_ERROR_PRINT or PEAR_ERROR_DIE, this is
- * a printf format string used when printing the error
- * message.
- *
- * @access public
- * @return void
- * @see PEAR_ERROR_RETURN
- * @see PEAR_ERROR_PRINT
- * @see PEAR_ERROR_TRIGGER
- * @see PEAR_ERROR_DIE
- * @see PEAR_ERROR_CALLBACK
- * @see PEAR_ERROR_EXCEPTION
- *
- * @since PHP 4.0.5
- */
- function setErrorHandling($mode = null, $options = null)
- {
- if (isset($this) && is_a($this, 'PEAR')) {
- $setmode = &$this->_default_error_mode;
- $setoptions = &$this->_default_error_options;
- } else {
- $setmode = &$GLOBALS['_PEAR_default_error_mode'];
- $setoptions = &$GLOBALS['_PEAR_default_error_options'];
- }
-
- switch ($mode) {
- case PEAR_ERROR_EXCEPTION:
- case PEAR_ERROR_RETURN:
- case PEAR_ERROR_PRINT:
- case PEAR_ERROR_TRIGGER:
- case PEAR_ERROR_DIE:
- case null:
- $setmode = $mode;
- $setoptions = $options;
- break;
-
- case PEAR_ERROR_CALLBACK:
- $setmode = $mode;
- // class/object method callback
- if (is_callable($options)) {
- $setoptions = $options;
- } else {
- trigger_error("invalid error callback", E_USER_WARNING);
- }
- break;
-
- default:
- trigger_error("invalid error mode", E_USER_WARNING);
- break;
- }
- }
-
- /**
- * This method is used to tell which errors you expect to get.
- * Expected errors are always returned with error mode
- * PEAR_ERROR_RETURN. Expected error codes are stored in a stack,
- * and this method pushes a new element onto it. The list of
- * expected errors are in effect until they are popped off the
- * stack with the popExpect() method.
- *
- * Note that this method can not be called statically
- *
- * @param mixed $code a single error code or an array of error codes to expect
- *
- * @return int the new depth of the "expected errors" stack
- * @access public
- */
- function expectError($code = '*')
- {
- if (is_array($code)) {
- array_push($this->_expected_errors, $code);
- } else {
- array_push($this->_expected_errors, array($code));
- }
- return count($this->_expected_errors);
- }
-
- /**
- * This method pops one element off the expected error codes
- * stack.
- *
- * @return array the list of error codes that were popped
- */
- function popExpect()
- {
- return array_pop($this->_expected_errors);
- }
-
- /**
- * This method checks unsets an error code if available
- *
- * @param mixed error code
- * @return bool true if the error code was unset, false otherwise
- * @access private
- * @since PHP 4.3.0
- */
- function _checkDelExpect($error_code)
- {
- $deleted = false;
- foreach ($this->_expected_errors as $key => $error_array) {
- if (in_array($error_code, $error_array)) {
- unset($this->_expected_errors[$key][array_search($error_code, $error_array)]);
- $deleted = true;
- }
-
- // clean up empty arrays
- if (0 == count($this->_expected_errors[$key])) {
- unset($this->_expected_errors[$key]);
- }
- }
-
- return $deleted;
- }
-
- /**
- * This method deletes all occurences of the specified element from
- * the expected error codes stack.
- *
- * @param mixed $error_code error code that should be deleted
- * @return mixed list of error codes that were deleted or error
- * @access public
- * @since PHP 4.3.0
- */
- 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 values
- foreach ($error_code as $key => $error) {
- $deleted = $this->_checkDelExpect($error) ? true : false;
- }
-
- return $deleted ? true : PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME
- } elseif (!empty($error_code)) {
- // $error_code comes alone, trying to unset it
- if ($this->_checkDelExpect($error_code)) {
- return true;
- }
-
- return PEAR::raiseError("The expected error you submitted does not exist"); ...
[truncated message content] |