diff --git a/conlite/classes/cApi/class.action.php b/conlite/classes/cApi/class.action.php index e7284aa..46674bb 100644 --- a/conlite/classes/cApi/class.action.php +++ b/conlite/classes/cApi/class.action.php @@ -50,7 +50,7 @@ class cApiActionCollection extends ItemCollection { * @return cApiAction */ public function create($area, $name, $code = "", $location = "", $relevant = 1) { - $item = parent::create(); + $item = parent::createNewItem(); if (is_string($area)) { $c = new cApiArea(); diff --git a/conlite/classes/cApi/class.upload.php b/conlite/classes/cApi/class.upload.php index d8314d0..3661d5b 100644 --- a/conlite/classes/cApi/class.upload.php +++ b/conlite/classes/cApi/class.upload.php @@ -54,7 +54,7 @@ class cApiUploadCollection extends ItemCollection { public function create($dir, $file) { global $client, $cfg, $auth; - $item = parent::create(); + $item = parent::createNewItem(); $item->set("idclient", $client); $item->set("filename", $file, false); diff --git a/conlite/classes/class.communications.php b/conlite/classes/class.communications.php index 957e66f..dc0feda 100644 --- a/conlite/classes/class.communications.php +++ b/conlite/classes/class.communications.php @@ -60,7 +60,7 @@ class CommunicationCollection extends ItemCollection public function create() { global $auth, $client; - $item = parent::create(); + $item = parent::createNewItem(); $client = Contenido_Security::toInteger($client); diff --git a/conlite/classes/class.dbfs.php b/conlite/classes/class.dbfs.php index 3cf46f9..8e2d442 100644 --- a/conlite/classes/class.dbfs.php +++ b/conlite/classes/class.dbfs.php @@ -236,7 +236,7 @@ class DBFSCollection extends ItemCollection } if ($dir && !$this->dir_exists($dir) || $file != ".") { - $item = parent::create(); + $item = parent::createNewItem(); $item->set("idclient", $client); $item->set("dirname", $dir); $item->set("filename", $file); diff --git a/conlite/classes/class.frontend.groups.php b/conlite/classes/class.frontend.groups.php index 7bb56ca..8946241 100644 --- a/conlite/classes/class.frontend.groups.php +++ b/conlite/classes/class.frontend.groups.php @@ -77,7 +77,7 @@ class FrontendGroupCollection extends ItemCollection $groupname = $groupname. md5(rand()); } - $item = parent::create(); + $item = parent::createNewItem(); $item->set("idclient", $client); $item->set("groupname", $groupname); @@ -170,7 +170,7 @@ class FrontendGroupMemberCollection extends ItemCollection return false; } - $item = parent::create(); + $item = parent::createNewItem(); $item->set("idfrontenduser", $idfrontenduser); $item->set("idfrontendgroup", $idfrontendgroup); diff --git a/conlite/classes/class.frontend.permissions.php b/conlite/classes/class.frontend.permissions.php index 76faa32..a77c7a8 100644 --- a/conlite/classes/class.frontend.permissions.php +++ b/conlite/classes/class.frontend.permissions.php @@ -74,7 +74,7 @@ class FrontendPermissionCollection extends ItemCollection $item = null; if (!$this->checkPerm($group, $plugin, $action, $mitem)) { - $item = parent::create(); + $item = parent::createNewItem(); $item->set("idlang", $lang); $item->set("idfrontendgroup", $group); $item->set("plugin", $plugin); diff --git a/conlite/classes/class.frontend.users.php b/conlite/classes/class.frontend.users.php index 9f63479..cb3748b 100644 --- a/conlite/classes/class.frontend.users.php +++ b/conlite/classes/class.frontend.users.php @@ -94,7 +94,7 @@ class FrontendUserCollection extends ItemCollection return $this->create($username."_".substr(md5(rand()),0,10), $password); } - $item = parent::create(); + $item = parent::createNewItem(); $item->set("idclient", $client); $item->set("username", $username); $item->set("password", $password); diff --git a/conlite/classes/class.genericdb.php b/conlite/classes/class.genericdb.php index 04986d5..d9788c8 100644 --- a/conlite/classes/class.genericdb.php +++ b/conlite/classes/class.genericdb.php @@ -38,6 +38,10 @@ if (file_exists($driver_filename)) { include_once($driver_filename); } +// load all genericdb classes +cInclude("classes", "genericdb/class.item.base.abstract.php"); +cInclude("classes", "genericdb/class.item.cache.php"); + /** * Class Contenido_ItemException. @@ -48,401 +52,10 @@ if (file_exists($driver_filename)) { class Contenido_ItemException extends Exception {} -/** - * Class Contenido_ItemCache. - * - * Implements features to cache entries, usually result sets of Item classes. - * Contains a list of self instances, where each instance contains cached Items - * fore one specific table. - * - * @author Murat Purc - * @version 0.1.2 - * @copyright four for business AG - */ -class Contenido_ItemCache -{ - /** - * List of self instances (Contenido_ItemCache) - * @var array - */ - protected static $_oInstances = array(); - /** - * Assoziative cache array - * @var array - */ - protected $_aItemsCache = array(); - - /** - * Table name for current instance - * @var string - */ - protected $_sTable = ''; - - /** - * Max number of items to cache - * @var int - */ - protected $_iMaxItemsToCache = 10; - - /** - * Enable caching - * @var bool - */ - protected $_bEnable = false; - - protected $_iFrame; - - /** - * Contructor of Contenido_ItemCache - * @param string $sTable Table name - * @param array $aOptions Options array as follows: - * - $aOptions['max_items_to_cache'] = (int) Number of items to cache - * - $aOptions['enable'] = (bool) Flag to enable caching - */ - protected function __construct($sTable, array $aOptions = array()) - { - $this->_sTable = $sTable; - if (isset($aOptions['max_items_to_cache']) && (int) $aOptions['max_items_to_cache'] > 0) { - $this->_iMaxItemsToCache = (int) $aOptions['max_items_to_cache']; - } - if (isset($aOptions['enable']) && is_bool($aOptions['enable'])) { - $this->_bEnable = (bool) $aOptions['enable']; - } - - if(isset($_GET['frame']) && is_numeric($_GET['frame'])) { - $this->_iFrame = (int) $_GET['frame']; - } else { - $this->_bEnable = false; - } - } - - /** - * Prevent cloning - */ - protected function __clone() - { - } - - /** - * Returns item cache instance, creates it, if not done before. - * Works as a singleton for one specific table. - * - * @param string $sTable Table name - * @param array $aOptions Options array as follows: - * - $aOptions['max_items_to_cache'] = (int) Number of items to cache - * - $aOptions['enable'] = (bool) Flag to enable caching - */ - public static function getInstance($sTable, array $aOptions = array()) - { - if (!isset(self::$_oInstances[$sTable])) { - self::$_oInstances[$sTable] = new self($sTable, $aOptions); - } - return self::$_oInstances[$sTable]; - } - - /** - * Returns items cache list. - * - * @return array - */ - public function getItemsCache() - { - return $this->_aItemsCache[$this->_iFrame]; - } - - /** - * Returns existing entry from cache by it's id. - * - * @param mixed $mId - * @return array|null - */ - public function getItem($mId) - { - if (!$this->_bEnable) { - return null; - } - - if (isset($this->_aItemsCache[$this->_iFrame][$mId])) { - return $this->_aItemsCache[$this->_iFrame][$mId]; - } else { - return null; - } - } - - /** - * Returns existing entry from cache by matching propery value. - * - * @param mixed $mProperty - * @param mixed $mValue - * @return array|null - */ - public function getItemByProperty($mProperty, $mValue) - { - if (!$this->_bEnable) { - return null; - } - - // loop thru all cached entries and try to find a entry by it's property - if(is_array($this->_aItemsCache[$this->_iFrame]) - && count($this->_aItemsCache[$this->_iFrame]) > 0) { - foreach ($this->_aItemsCache[$this->_iFrame] as $id => $aEntry) { - if (isset($aEntry[$mProperty]) && $aEntry[$mProperty] == $mValue) { - return $aEntry; - } - } - } - return null; - } - - /** - * Returns existing entry from cache by matching properties and their values. - * - * @param array $aProperties Assoziative key value pairs - * @return array|null - */ - public function getItemByProperties(array $aProperties) - { - if (!$this->_bEnable) { - return null; - } - - // loop thru all cached entries and try to find a entry by it's property - foreach ($this->_aItemsCache as $id => $aEntry) { - $mFound = null; - foreach ($aProperties as $key => $value) { - if (isset($aEntry[$key]) && $aEntry[$key] == $value) { - if (null === $mFound) { - $mFound = true; - } - } else { - $mFound = false; - break; - } - if (true === $mFound) { - return $aEntry; - } - } - } - return null; - } - - /** - * Adds passed item data to internal cache - * - * @param mixed $mId - * @param array $aData Usually the recordset - * @return void - */ - public function addItem($mId, array $aData) - { - if (!$this->_bEnable) { - return null; - } - - if(isset($this->_aItemsCache[$this->_iFrame])) { - $aTmpItemsArray = $this->_aItemsCache[$this->_iFrame]; - - if ($this->_iMaxItemsToCache == count($aTmpItemsArray)) { - // we have reached the maximum number of cached items, remove first entry - $firstEntryKey = array_shift($aTmpItemsArray); - if(is_array($firstEntryKey)) return null; - unset($this->_aItemsCache[$this->_iFrame][$firstEntryKey]); - } - } - - // add entry - $this->_aItemsCache[$this->_iFrame][$mId] = $aData; - } - - /** - * Removes existing cache entry by it's key - * - * @param mixed $mId - * @return void - */ - public function removeItem($mId) - { - if (!$this->_bEnable) { - return null; - } - - // remove entry - if (isset($this->_aItemsCache[$this->_iFrame][$mId])){ - unset($this->_aItemsCache[$this->_iFrame][$mId]); - } - } -} - - -/** - * Class Contenido_ItemBaseAbstract. - * Base class with common features for database based items and item collections. - * - * @author Murat Purc - * @version 0.2 - * @copyright four for business AG - */ -abstract class Contenido_ItemBaseAbstract -{ - /** - * Database instance, contains the database object - * @var DB_ConLite - */ - protected $db; - - /** - * Second DB instance, is required for some additional queries without - * losing an current existing query result. - * @var DB_ConLite - */ - protected $secondDb; - - /** - * Property collection instance - * @var PropertyCollection - */ - protected $properties; - - /** - * Item cache instance - * @var Contenido_ItemCache - */ - protected static $_oCache; - - /** - * GenericDB settings, see $cfg['sql'] - * @var array - */ - protected $_settings; - - /** - * Storage of the source table to use for the information - * @var string - */ - protected $table; - - /** - * Storage of the primary key - * @var string - * @todo remove access from public - */ - public $primaryKey; - - /** - * Checks for the virginity of created objects. If true, the object - * is virgin and no operations on it except load-Functions are allowed. - * @todo remove access from public - * @var bool - */ - public $virgin; - - /** - * Lifetime of results/created objects? - * FIXME Not used at the moment! - * @var int - */ - protected $lifetime; - - /** - * Storage of the last occured error - * @var string - */ - protected $lasterror = ''; - - /** - * Cache the result items - * FIXME seems to not used, remove it! - * @var array - */ - protected $cache; - - /** - * Classname of current instance - * @var string - */ - protected $_className; /** - * Sets some common properties - * - * @param string $sTable Name of table - * @param string $sPrimaryKey Primary key of table - * @param string $sClassName Name of parent class - * @param int $iLifetime Lifetime of the object in seconds (NOT USED!) - * @throws Contenido_ItemException If table name or primary key is not set - */ - protected function __construct($sTable, $sPrimaryKey, $sClassName, $iLifetime = 10) - { - global $cfg; - - $this->db = new DB_ConLite(); - - if ($sTable == '') { - $sMsg = "$sClassName: No table specified. Inherited classes *need* to set a table"; - throw new Contenido_ItemException($sMsg); - } elseif ($sPrimaryKey == '') { - $sMsg = "No primary key specified. Inherited classes *need* to set a primary key"; - throw new Contenido_ItemException($sMsg); - } - - $this->_settings = $cfg['sql']; - - // instanciate caching - $aCacheOpt = (isset($this->_settings['cache'])) ? $this->_settings['cache'] : array(); - self::$_oCache = Contenido_ItemCache::getInstance($sTable, $aCacheOpt); - - $this->table = $sTable; - $this->primaryKey = $sPrimaryKey; - $this->virgin = true; - $this->lifetime = $iLifetime; - $this->_className = $sClassName; - } - - - /** - * Escape string for using in SQL-Statement. - * - * @param string $sString The string to escape - * @return string Escaped string - */ - public function escape($sString) - { - return $this->db->escape($sString); - } - - /** - * Returns the second database instance, usable to run additional statements - * without losing current query results. - * - * @return DB_ConLite - */ - protected function _getSecondDBInstance() - { - if (!isset($this->secondDb) || !($this->secondDb instanceof DB_ConLite)) { - $this->secondDb = new DB_ConLite(); - } - return $this->secondDb; - } - - /** - * Returns properties instance, instantiates it if not done before. - * - * @return PropertyCollection - */ - protected function _getPropertiesCollectionInstance() - { - // Runtime on-demand allocation of the properties object - if (!isset($this->properties) || !($this->properties instanceof PropertyCollection)) { - $this->properties = new PropertyCollection(); - } - return $this->properties; - } -} - - -/** * Class ItemCollection * Abstract class for database based item collections. * @@ -451,7 +64,7 @@ abstract class Contenido_ItemBaseAbstract * @version 0.2 * @copyright four for business 2003 */ -abstract class ItemCollection extends Contenido_ItemBaseAbstract +abstract class ItemCollection extends cItemBaseAbstract { /** * Storage of all result items @@ -1537,7 +1150,7 @@ abstract class ItemCollection extends Contenido_ItemBaseAbstract * @param string $primaryKeyValue Optional parameter for direct input of primary key value * @return Item The newly created object */ - public function create() + public function createNewItem($aData = NULL) { /* @var $oDb DB_ConLite */ $oDb = $this->_getSecondDBInstance(); $iNextId = $oDb->nextid($this->table); @@ -1696,7 +1309,7 @@ abstract class ItemCollection extends Contenido_ItemBaseAbstract * @version 0.3 * @copyright four for business 2003 */ -abstract class Item extends Contenido_ItemBaseAbstract +abstract class Item extends cItemBaseAbstract { /** * Storage of the source table to use for the user informations diff --git a/conlite/classes/class.inuse.php b/conlite/classes/class.inuse.php index 7c7366f..13cdf76 100644 --- a/conlite/classes/class.inuse.php +++ b/conlite/classes/class.inuse.php @@ -69,7 +69,7 @@ class InUseCollection extends ItemCollection $this->select("type = '".$type."' AND objectid = '".$objectid."'"); if (!$this->next()) { - $newitem = parent::create(); + $newitem = parent::createNewItem(); $newitem->set("type", $type); $newitem->set("objectid", $objectid); $newitem->set("session", $session); diff --git a/conlite/classes/class.note.php b/conlite/classes/class.note.php index 123784f..1a49b80 100644 --- a/conlite/classes/class.note.php +++ b/conlite/classes/class.note.php @@ -82,7 +82,7 @@ class NoteCollection extends CommunicationCollection */ public function create($itemtype, $itemid, $idlang, $message, $category = "") { - $item = parent::create(); + $item = parent::createNewItem(); $item->set("subject", "Note Item"); $item->set("message", $message); diff --git a/conlite/classes/class.properties.php b/conlite/classes/class.properties.php index a8a7584..70bf767 100644 --- a/conlite/classes/class.properties.php +++ b/conlite/classes/class.properties.php @@ -122,7 +122,7 @@ class PropertyCollection extends ItemCollection { global $cfg, $auth; - $item = parent::create(); + $item = parent::createNewItem(); if (!$bInternally) { $itemtype = Contenido_Security::escapeDB($itemtype, null); @@ -459,7 +459,7 @@ class PropertyItem extends Item * @param string $value * @param bool $safe Flag to run filter on passed value */ - public function setField($field, $value, $safe) + public function setField($field, $value, $safe = true) { if (array_key_exists($field, $this->maximumLength)) { if (strlen($value) > $this->maximumLength[$field]) { diff --git a/conlite/classes/class.todo.php b/conlite/classes/class.todo.php index 402641f..b5215a8 100644 --- a/conlite/classes/class.todo.php +++ b/conlite/classes/class.todo.php @@ -63,7 +63,7 @@ class TODOCollection extends CommunicationCollection /** * Creates a new communication item */ - public function create($itemtype, $itemid, $reminderdate, $subject, $content, $notimail, $notibackend, $recipient) + public function createItem($itemtype, $itemid, $reminderdate, $subject, $content, $notimail, $notibackend, $recipient) { $item = parent::create(); diff --git a/conlite/classes/contenido/class.area.php b/conlite/classes/contenido/class.area.php index 8750fd5..54b733e 100644 --- a/conlite/classes/contenido/class.area.php +++ b/conlite/classes/contenido/class.area.php @@ -70,7 +70,7 @@ class cApiArea extends Item public function create($name, $parentid = 0, $relevant = 1, $online = 1) { - $item = parent::create(); + $item = parent::createNewItem(); $item->set("name", $name); $item->set("relevant", $relevant); diff --git a/conlite/classes/contenido/class.container.php b/conlite/classes/contenido/class.container.php index c56a293..fdaa88b 100644 --- a/conlite/classes/contenido/class.container.php +++ b/conlite/classes/contenido/class.container.php @@ -64,7 +64,7 @@ class cApiContainerCollection extends ItemCollection public function create($idtpl, $number, $module) { - $item = parent::create(); + $item = parent::createNewItem(); $item->set("idtpl", $idtpl); $item->set("number", $number); $item->set("module", $module); diff --git a/conlite/classes/contenido/class.containerconfig.php b/conlite/classes/contenido/class.containerconfig.php index cbf5707..6f7ff36 100644 --- a/conlite/classes/contenido/class.containerconfig.php +++ b/conlite/classes/contenido/class.containerconfig.php @@ -45,7 +45,7 @@ class cApiContainerConfigurationCollection extends ItemCollection public function create($idtplcfg, $number, $container) { - $item = parent::create(); + $item = parent::createNewItem(); $item->set("idtplcfg", $idtplcfg); $item->set("number", $number); $item->set("container", $container); diff --git a/conlite/classes/contenido/class.file.php b/conlite/classes/contenido/class.file.php index 0def169..c51e8d3 100644 --- a/conlite/classes/contenido/class.file.php +++ b/conlite/classes/contenido/class.file.php @@ -45,7 +45,7 @@ class cApiFileCollection extends ItemCollection public function create($area, $filename, $filetype = "main") { - $item = parent::create(); + $item = parent::createNewItem(); if (is_string($area)) { $c = new cApiArea(); diff --git a/conlite/classes/contenido/class.framefile.php b/conlite/classes/contenido/class.framefile.php index 9823b33..08d6661 100644 --- a/conlite/classes/contenido/class.framefile.php +++ b/conlite/classes/contenido/class.framefile.php @@ -45,7 +45,7 @@ class cApiFrameFileCollection extends ItemCollection public function create($area, $idframe, $idfile) { - $item = parent::create(); + $item = parent::createNewItem(); if (is_string($area)) { $c = new cApiArea(); diff --git a/conlite/classes/contenido/class.layout.php b/conlite/classes/contenido/class.layout.php index c90eedf..1167c4a 100644 --- a/conlite/classes/contenido/class.layout.php +++ b/conlite/classes/contenido/class.layout.php @@ -41,7 +41,7 @@ class cApiLayoutCollection extends ItemCollection { public function create($title) { global $client; - $item = parent::create(); + $item = parent::createNewItem(); $item->set("name", $title); $item->set("idclient", $client); $item->store(); diff --git a/conlite/classes/contenido/class.module.php b/conlite/classes/contenido/class.module.php index 93eddda..4742a0d 100644 --- a/conlite/classes/contenido/class.module.php +++ b/conlite/classes/contenido/class.module.php @@ -48,7 +48,7 @@ class cApiModuleCollection extends ItemCollection { */ public function create($name) { global $auth, $client; - $item = parent::create(); + $item = parent::createNewItem(); $item->set("idclient", $client); $item->set("name", $name); @@ -147,13 +147,12 @@ class cApiModule extends Item { } } - $oClient = cApiClient::getInstance($client); - if ($oClient->isLoaded()) { + $oClient = new cApiClient($client); $aClientProp = $oClient->getPropertiesByType('modfileedit'); if (count($aClientProp) > 0) { $this->_aModFileEditConf = array_merge($this->_aModFileEditConf, $aClientProp); } - } + if ($mId !== false) { $this->loadByPrimaryKey($mId); } @@ -889,7 +888,7 @@ class cApiModule extends Item { if ($this->_aModFileEditConf['use'] !== true) { return false; } - return $this->_setFieldFromFile('output', $this->_sModAlias . "_output.php"); + return $this->_setFieldFromFile('output', $this->_sModAlias."_output.php"); } /** @@ -903,7 +902,7 @@ class cApiModule extends Item { if ($this->_aModFileEditConf['use'] !== true) { return false; } - return $this->_setFieldFromFile('input', $this->_sModAlias . "_input.php"); + return $this->_setFieldFromFile('input', $this->_sModAlias."_input.php"); } private function _displayNoteFromFile($bIsOldPath = FALSE) { @@ -1076,7 +1075,7 @@ class cApiModuleTranslationCollection extends ItemCollection { } return $item; } else { - $item = parent::create(); + $item = parent::createNewItem(); $item->set("idmod", $idmod); $item->set("idlang", $idlang); $item->set("original", $original); diff --git a/conlite/classes/contenido/class.templateconfig.php b/conlite/classes/contenido/class.templateconfig.php index 2f59ecf..88824fe 100644 --- a/conlite/classes/contenido/class.templateconfig.php +++ b/conlite/classes/contenido/class.templateconfig.php @@ -61,7 +61,7 @@ class cApiTemplateConfigurationCollection extends ItemCollection { global $auth; - $item = parent::create(); + $item = parent::createNewItem(); $item->set("idtpl", $idtpl); $item->set("author", $auth->auth['uname']); $item->set("status", 0); diff --git a/conlite/classes/contenido/class.user.php b/conlite/classes/contenido/class.user.php index 3cc372a..b81879e 100644 --- a/conlite/classes/contenido/class.user.php +++ b/conlite/classes/contenido/class.user.php @@ -54,7 +54,7 @@ class cApiUserCollection extends ItemCollection if ($this->next()) { return false; } else { - $item = parent::create(); + $item = parent::createNewItem(); $item->set("user_id", $md5user); $item->set("username", $username); $item->store(); diff --git a/conlite/classes/drivers/class.gdb.driver.php b/conlite/classes/drivers/class.gdb.driver.php index 3084f6f..75dd7fa 100644 --- a/conlite/classes/drivers/class.gdb.driver.php +++ b/conlite/classes/drivers/class.gdb.driver.php @@ -31,33 +31,31 @@ if(!defined('CON_FRAMEWORK')) { die('Illegal call'); } -class gdbDriver -{ +class gdbDriver { + var $_sEncoding; - var $_oItemClassInstance; - function gdbDriver () - {} + function gdbDriver() { - function setEncoding ($sEncoding) - { + } + + function setEncoding($sEncoding) { $this->_sEncoding = $sEncoding; } - function setItemClassInstance ($oInstance) - { + function setItemClassInstance($oInstance) { $this->_oItemClassInstance = $oInstance; } - function buildJoinQuery ($destinationTable, $destinationClass, $destinationPrimaryKey, $sourceClass, $primaryKey) - { + function buildJoinQuery($destinationTable, $destinationClass, $destinationPrimaryKey, $sourceClass, $primaryKey) { } - function buildOperator ($sField, $sOperator, $sRestriction) - { + function buildOperator($sField, $sOperator, $sRestriction) { + } + } ?> diff --git a/conlite/classes/genericdb/class.item.base.abstract.php b/conlite/classes/genericdb/class.item.base.abstract.php new file mode 100644 index 0000000..cf5aead --- /dev/null +++ b/conlite/classes/genericdb/class.item.base.abstract.php @@ -0,0 +1,162 @@ +db = new DB_ConLite(); + + if ($sTable == '') { + $sMsg = "$sClassName: No table specified. Inherited classes *need* to set a table"; + throw new Contenido_ItemException($sMsg); + } elseif ($sPrimaryKey == '') { + $sMsg = "No primary key specified. Inherited classes *need* to set a primary key"; + throw new Contenido_ItemException($sMsg); + } + + $this->_settings = $cfg['sql']; + + // instanciate caching + $aCacheOpt = (isset($this->_settings['cache'])) ? $this->_settings['cache'] : array(); + self::$_oCache = cItemCache::getInstance($sTable, $aCacheOpt); + + $this->table = $sTable; + $this->primaryKey = $sPrimaryKey; + $this->virgin = true; + $this->lifetime = $iLifetime; + $this->_className = $sClassName; + } + + /** + * Escape string for using in SQL-Statement. + * + * @param string $sString The string to escape + * @return string Escaped string + */ + public function escape($sString) { + return $this->db->escape($sString); + } + + /** + * Returns the second database instance, usable to run additional statements + * without losing current query results. + * + * @return DB_ConLite + */ + protected function _getSecondDBInstance() { + if (!isset($this->secondDb) || !($this->secondDb instanceof DB_ConLite)) { + $this->secondDb = new DB_ConLite(); + } + return $this->secondDb; + } + + /** + * Returns properties instance, instantiates it if not done before. + * + * @return PropertyCollection + */ + protected function _getPropertiesCollectionInstance() { + // Runtime on-demand allocation of the properties object + if (!isset($this->properties) || !($this->properties instanceof PropertyCollection)) { + $this->properties = new PropertyCollection(); + } + return $this->properties; + } + +} + +?> \ No newline at end of file diff --git a/conlite/classes/genericdb/class.item.cache.php b/conlite/classes/genericdb/class.item.cache.php new file mode 100644 index 0000000..b6ea912 --- /dev/null +++ b/conlite/classes/genericdb/class.item.cache.php @@ -0,0 +1,214 @@ +_sTable = $sTable; + if (isset($aOptions['max_items_to_cache']) && (int) $aOptions['max_items_to_cache'] > 0) { + $this->_iMaxItemsToCache = (int) $aOptions['max_items_to_cache']; + } + if (isset($aOptions['enable']) && is_bool($aOptions['enable'])) { + $this->_bEnable = (bool) $aOptions['enable']; + } + + if (isset($_GET['frame']) && is_numeric($_GET['frame'])) { + $this->_iFrame = (int) $_GET['frame']; + } else { + $this->_bEnable = false; + } + } + + /** + * Prevent cloning + */ + protected function __clone() { + + } + + /** + * Returns item cache instance, creates it, if not done before. + * Works as a singleton for one specific table. + * + * @param string $sTable Table name + * @param array $aOptions Options array as follows: + * - $aOptions['max_items_to_cache'] = (int) Number of items to cache + * - $aOptions['enable'] = (bool) Flag to enable caching + */ + public static function getInstance($sTable, array $aOptions = array()) { + if (!isset(self::$_oInstances[$sTable])) { + self::$_oInstances[$sTable] = new self($sTable, $aOptions); + } + return self::$_oInstances[$sTable]; + } + + /** + * Returns items cache list. + * + * @return array + */ + public function getItemsCache() { + return $this->_aItemsCache[$this->_iFrame]; + } + + /** + * Returns existing entry from cache by it's id. + * + * @param mixed $mId + * @return array|null + */ + public function getItem($mId) { + if (!$this->_bEnable) { + return null; + } + + if (isset($this->_aItemsCache[$this->_iFrame][$mId])) { + return $this->_aItemsCache[$this->_iFrame][$mId]; + } else { + return null; + } + } + + /** + * Returns existing entry from cache by matching propery value. + * + * @param mixed $mProperty + * @param mixed $mValue + * @return array|null + */ + public function getItemByProperty($mProperty, $mValue) { + if (!$this->_bEnable) { + return null; + } + + // loop thru all cached entries and try to find a entry by it's property + if (is_array($this->_aItemsCache[$this->_iFrame]) && count($this->_aItemsCache[$this->_iFrame]) > 0) { + foreach ($this->_aItemsCache[$this->_iFrame] as $id => $aEntry) { + if (isset($aEntry[$mProperty]) && $aEntry[$mProperty] == $mValue) { + return $aEntry; + } + } + } + return null; + } + + /** + * Returns existing entry from cache by matching properties and their values. + * + * @param array $aProperties Assoziative key value pairs + * @return array|null + */ + public function getItemByProperties(array $aProperties) { + if (!$this->_bEnable) { + return null; + } + + // loop thru all cached entries and try to find a entry by it's property + foreach ($this->_aItemsCache as $id => $aEntry) { + $mFound = null; + foreach ($aProperties as $key => $value) { + if (isset($aEntry[$key]) && $aEntry[$key] == $value) { + if (null === $mFound) { + $mFound = true; + } + } else { + $mFound = false; + break; + } + if (true === $mFound) { + return $aEntry; + } + } + } + return null; + } + + /** + * Adds passed item data to internal cache + * + * @param mixed $mId + * @param array $aData Usually the recordset + * @return void + */ + public function addItem($mId, array $aData) { + if (!$this->_bEnable) { + return null; + } + + if (isset($this->_aItemsCache[$this->_iFrame])) { + $aTmpItemsArray = $this->_aItemsCache[$this->_iFrame]; + + if ($this->_iMaxItemsToCache == count($aTmpItemsArray)) { + // we have reached the maximum number of cached items, remove first entry + $firstEntryKey = array_shift($aTmpItemsArray); + if (is_array($firstEntryKey)) + return null; + unset($this->_aItemsCache[$this->_iFrame][$firstEntryKey]); + } + } + + // add entry + $this->_aItemsCache[$this->_iFrame][$mId] = $aData; + } + + /** + * Removes existing cache entry by it's key + * + * @param mixed $mId + * @return void + */ + public function removeItem($mId) { + if (!$this->_bEnable) { + return null; + } + + // remove entry + if (isset($this->_aItemsCache[$this->_iFrame][$mId])) { + unset($this->_aItemsCache[$this->_iFrame][$mId]); + } + } + +} diff --git a/conlite/includes/include.todo.popup.php b/conlite/includes/include.todo.popup.php index 0a121ff..1a4ad2a 100644 --- a/conlite/includes/include.todo.popup.php +++ b/conlite/includes/include.todo.popup.php @@ -45,7 +45,7 @@ if ($action == "todo_save_item") if (is_array($userassignment)) { foreach ($userassignment as $key => $value) { - $item = $todo->create($itemtype, $itemid, strtotime($reminderdate), $subject, $message, $notiemail, $notibackend, $auth->auth["uid"]); + $item = $todo->createItem($itemtype, $itemid, strtotime($reminderdate), $subject, $message, $notiemail, $notibackend, $auth->auth["uid"]); $item->set("recipient", $value); $item->setProperty("todo", "enddate", $enddate); $item->store(); diff --git a/conlite/plugins/newsletter/classes/class.newsletter.groups.php b/conlite/plugins/newsletter/classes/class.newsletter.groups.php index 928dd5d..2d4fa94 100644 --- a/conlite/plugins/newsletter/classes/class.newsletter.groups.php +++ b/conlite/plugins/newsletter/classes/class.newsletter.groups.php @@ -82,7 +82,7 @@ class RecipientGroupCollection extends ItemCollection $groupname = $groupname . md5(rand()); } - $item = parent::create(); + $item = parent::createNewItem(); $item->set("idclient", $client); $item->set("idlang", $lang); diff --git a/conlite/plugins/newsletter/classes/class.newsletter.jobs.php b/conlite/plugins/newsletter/classes/class.newsletter.jobs.php index 8e2aa31..439cd7b 100644 --- a/conlite/plugins/newsletter/classes/class.newsletter.jobs.php +++ b/conlite/plugins/newsletter/classes/class.newsletter.jobs.php @@ -74,7 +74,7 @@ class cNewsletterJobCollection extends ItemCollection $client = Contenido_Security::toInteger($client); $sName = Contenido_Security::escapeDB($sName, null); - $oItem = parent::create(); + $oItem = parent::createNewItem(); $oItem->set("idnews", $iIDNews); $oItem->set("idclient", $client); diff --git a/conlite/plugins/newsletter/classes/class.newsletter.logs.php b/conlite/plugins/newsletter/classes/class.newsletter.logs.php index fc6dbfe..79210e8 100644 --- a/conlite/plugins/newsletter/classes/class.newsletter.logs.php +++ b/conlite/plugins/newsletter/classes/class.newsletter.logs.php @@ -84,7 +84,7 @@ class cNewsletterLogCollection extends ItemCollection $oRecipient = new Recipient; if ($oRecipient->loadByPrimaryKey($idnewsrcp)) { - $oItem = parent::create(); + $oItem = parent::createNewItem(); $oItem->set("idnewsjob", $idnewsjob); $oItem->set("idnewsrcp", $idnewsrcp); diff --git a/conlite/plugins/newsletter/classes/class.newsletter.php b/conlite/plugins/newsletter/classes/class.newsletter.php index ec251b0..0e5b643 100644 --- a/conlite/plugins/newsletter/classes/class.newsletter.php +++ b/conlite/plugins/newsletter/classes/class.newsletter.php @@ -80,7 +80,7 @@ class NewsletterCollection extends ItemCollection return $this->create($sName."_".substr(md5(rand()), 0, 10)); } - $oItem = parent::create(); + $oItem = parent::createNewItem(); $oItem->set("idclient", $client); $oItem->set("idlang", $lang); $oItem->set("name", $sName); @@ -108,7 +108,7 @@ class NewsletterCollection extends ItemCollection $oBaseItem = new Newsletter(); $oBaseItem->loadByPrimaryKey($iItemID); - $oItem = parent::create(); + $oItem = parent::createNewItem(); $oItem->set("name", $oBaseItem->get("name")."_".substr(md5(rand()), 0, 10)); $iIDArt = 0; diff --git a/conlite/plugins/newsletter/classes/class.newsletter.recipients.php b/conlite/plugins/newsletter/classes/class.newsletter.recipients.php index 3b87973..59ecc6f 100644 --- a/conlite/plugins/newsletter/classes/class.newsletter.recipients.php +++ b/conlite/plugins/newsletter/classes/class.newsletter.recipients.php @@ -82,7 +82,7 @@ class RecipientCollection extends ItemCollection if ($this->next()) { return $this->create($sEMail."_".substr(md5(rand()),0,10), $sName, 0, $sJoinID, $iMessageType); // 0: Deactivate 'confirmed' } - $oItem = parent::create(); + $oItem = parent::createNewItem(); $oItem->set("idclient", $client); $oItem->set("idlang", $lang); $oItem->set("name", $sName); diff --git a/conlite/plugins/workflow/classes/class.workflow.php b/conlite/plugins/workflow/classes/class.workflow.php index 4617d27..fb618c8 100644 --- a/conlite/plugins/workflow/classes/class.workflow.php +++ b/conlite/plugins/workflow/classes/class.workflow.php @@ -66,7 +66,7 @@ class Workflows extends ItemCollection { function create () { global $auth, $client, $lang; - $newitem = parent::create(); + $newitem = parent::createNewItem(); $newitem->setField("created", date("Y-m-d H-i-s")); $newitem->setField("idauthor", $auth->auth["uid"]); $newitem->setField("idclient", $client); diff --git a/conlite/plugins/workflow/classes/class.workflowactions.php b/conlite/plugins/workflow/classes/class.workflowactions.php index acdcb04..991589b 100644 --- a/conlite/plugins/workflow/classes/class.workflowactions.php +++ b/conlite/plugins/workflow/classes/class.workflowactions.php @@ -87,7 +87,7 @@ class WorkflowActions extends ItemCollection { $this->select("idworkflowitem = '".Contenido_Security::escapeDB($idworkflowitem, NULL)."' AND action = '".Contenido_Security::escapeDB($action, NULL)."'"); if (!$this->next()) { - $newitem = parent::create(); + $newitem = parent::createNewItem(); $newitem->setField("idworkflowitem",$idworkflowitem); $newitem->setField("action",$action); $newitem->store(); diff --git a/conlite/plugins/workflow/classes/class.workflowallocation.php b/conlite/plugins/workflow/classes/class.workflowallocation.php index a834395..773514b 100644 --- a/conlite/plugins/workflow/classes/class.workflowallocation.php +++ b/conlite/plugins/workflow/classes/class.workflowallocation.php @@ -126,7 +126,7 @@ class WorkflowAllocations extends ItemCollection { $this->lasterror = i18n("Workflow doesn't exist", "workflow"); return false; } - $newitem = parent::create(); + $newitem = parent::createNewItem(); if (!$newitem->setWorkflow($idworkflow)) { $this->lasterror = $newitem->lasterror; diff --git a/conlite/plugins/workflow/classes/class.workflowartallocation.php b/conlite/plugins/workflow/classes/class.workflowartallocation.php index 0ac9236..425a2cf 100644 --- a/conlite/plugins/workflow/classes/class.workflowartallocation.php +++ b/conlite/plugins/workflow/classes/class.workflowartallocation.php @@ -81,7 +81,7 @@ class WorkflowArtAllocations extends ItemCollection { return false; } - $newitem = parent::create(); + $newitem = parent::createNewItem(); $newitem->setField("idartlang",$idartlang); $newitem->store(); diff --git a/conlite/plugins/workflow/classes/class.workflowitems.php b/conlite/plugins/workflow/classes/class.workflowitems.php index 17f4235..d06d345 100644 --- a/conlite/plugins/workflow/classes/class.workflowitems.php +++ b/conlite/plugins/workflow/classes/class.workflowitems.php @@ -181,7 +181,7 @@ class WorkflowItems extends ItemCollection { $lastPos = $item->getField("position") + 1; } - $newItem = parent::create(); + $newItem = parent::createNewItem(); if ($newItem->init($idworkflow, $lastPos) === false) { $this->delete($newItem->getField("idworkflowitem")); @@ -278,7 +278,7 @@ class WorkflowItem extends Item { } } - parent::setField($field, $value); + parent::setField($field, $value, $bSafe); } /** diff --git a/conlite/plugins/workflow/classes/class.workflowtasks.php b/conlite/plugins/workflow/classes/class.workflowtasks.php index 36a421c..c336c73 100644 --- a/conlite/plugins/workflow/classes/class.workflowtasks.php +++ b/conlite/plugins/workflow/classes/class.workflowtasks.php @@ -60,7 +60,7 @@ class WorkflowTasks extends ItemCollection { function create () { - $newitem = parent::create(); + $newitem = parent::createNewItem(); return ($newitem); } diff --git a/conlite/plugins/workflow/classes/class.workflowusersequence.php b/conlite/plugins/workflow/classes/class.workflowusersequence.php index b6cdb48..6224850 100644 --- a/conlite/plugins/workflow/classes/class.workflowusersequence.php +++ b/conlite/plugins/workflow/classes/class.workflowusersequence.php @@ -103,7 +103,7 @@ class WorkflowUserSequences extends ItemCollection { function create ($idworkflowitem) { global $auth, $client, $idworkflow; - $newitem = parent::create(); + $newitem = parent::createNewItem(); $workflowitems = new WorkflowItems; if (!$workflowitems->exists($idworkflowitem)) @@ -198,7 +198,7 @@ class WorkflowUserSequence extends Item { * @param string $field Field to set * @param string $valie Value to set */ - function setField($field, $value) + function setField($field, $value, $bSafe = true) { global $cfg; @@ -235,7 +235,7 @@ class WorkflowUserSequence extends Item { } - parent::setField($field, $value); + parent::setField($field, $value, $bSafe); if ($idusersquence) { WorkflowUserSequences::updateArtAllocation(0); } diff --git a/pear/XML/RSS.php b/pear/XML/RSS.php index bc0a8ec..9255a5f 100644 --- a/pear/XML/RSS.php +++ b/pear/XML/RSS.php @@ -1,5 +1,4 @@