Overview

Packages

  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Datatype
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationMain
    • NavigationTop
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • cApiPathresolveCacheHelper
  • cArray
  • cArticleCollector
  • cDirHandler
  • cFileHandler
  • cHTMLInputSelectElement
  • cIterator
  • cString
  • UI_Config_Table
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * This file contains the path resolve cache collection and item class and its helper.
  4:  *
  5:  * @package          Core
  6:  * @subpackage       GenericDB_Model
  7:  * @version          SVN Revision $Rev:$
  8:  *
  9:  * @author           Murat Purc <murat@purc.de>
 10:  * @copyright        four for business AG <www.4fb.de>
 11:  * @license          http://www.contenido.org/license/LIZENZ.txt
 12:  * @link             http://www.4fb.de
 13:  * @link             http://www.contenido.org
 14:  */
 15: 
 16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 17: 
 18: /**
 19:  * Pathresolve cache static helper class
 20:  *
 21:  * @package Core
 22:  * @subpackage Util
 23:  */
 24: class cApiPathresolveCacheHelper {
 25: 
 26:     /**
 27:      * Flag to state state about created heap table.
 28:      *
 29:      * @var bool
 30:      */
 31:     protected static $_tableCreated = false;
 32: 
 33:     /**
 34:      * Checks configuration of heap table creation, it's existance and creates
 35:      * it if needed.
 36:      *
 37:      * @param array $cfg Global CONTENIDO config array
 38:      */
 39:     public static function setup($cfg) {
 40:         if (true === $cfg['pathresolve_heapcache'] && false === self::$_tableCreated) {
 41:             $db = cRegistry::getDb();
 42:             $tableName = $cfg['sql']['sqlprefix'] . '_pathresolve_cache';
 43: 
 44:             $sql = "SHOW TABLES LIKE '" . $db->escape($tableName) . "'";
 45:             $db->query($sql);
 46: 
 47:             if (!$db->nextRecord()) {
 48:                 // Important: This is really a hack! Don't use
 49:                 // pathresolve_heapcache if you are
 50:                 // not sure what it does.
 51:                 // @TODO: pls insert to this create table statetment MAX_ROWS.
 52:                 $sql = 'CREATE TABLE `' . $db->escape($tableName) . '` (
 53:                            `idpathresolvecache` INT(10) NOT NULL AUTO_INCREMENT,
 54:                            `path` VARCHAR(255) NOT NULL,
 55:                            `idcat` INT(10) NOT NULL,
 56:                            `idlang` INT(10) NOT NULL,
 57:                            `lastcached` INT(10) NOT NULL,
 58:                             PRIMARY KEY (`idpathresolvecache`)
 59:                         ) ENGINE = HEAP;';
 60:                 $db->query($sql);
 61:             }
 62:             self::$_tableCreated = true;
 63:         }
 64:     }
 65: 
 66: }
 67: 
 68: /**
 69:  * Pathresolve cache collection
 70:  *
 71:  * @package Core
 72:  * @subpackage GenericDB_Model
 73:  */
 74: class cApiPathresolveCacheCollection extends ItemCollection {
 75: 
 76:     /**
 77:      * Constructor
 78:      */
 79:     public function __construct() {
 80:         global $cfg;
 81:         cApiPathresolveCacheHelper::setup($cfg['sql']['sqlprefix'] . '_pathresolve_cache');
 82:         parent::__construct($cfg['sql']['sqlprefix'] . '_pathresolve_cache', 'idpathresolvecache');
 83:         $this->_setItemClass('cApiPathresolveCache');
 84:     }
 85: 
 86:     /**
 87:      * Creates a pathresolve cache entry.
 88:      *
 89:      * @param string $path
 90:      * @param int $idcat
 91:      * @param int $idlang
 92:      * @param string $lastcached
 93:      * @return cApiPathresolveCache
 94:      */
 95:     public function create($path, $idcat, $idlang, $lastcached = '') {
 96:         $oItem = parent::createNewItem();
 97: 
 98:         if (empty($lastcached)) {
 99:             $lastcached = time();
100:         }
101: 
102:         $oItem->set('path', $this->db->escape($path), false);
103:         $oItem->set('idcat', (int) $idcat, false);
104:         $oItem->set('idlang', (int) $idlang, false);
105:         $oItem->set('lastcached', $this->escape($lastcached), false);
106:         $oItem->store();
107: 
108:         return $oItem;
109:     }
110: 
111:     /**
112:      * Returns a last cached entry by path and language.
113:      *
114:      * @param string $path
115:      * @param int $idlang
116:      * @return cApiPathresolveCache|null
117:      */
118:     public function fetchLatestByPathAndLanguage($path, $idlang) {
119:         $this->select("path LIKE '" . $this->db->escape($path) . "' AND idlang=" . (int) $idlang, '', 'lastcached DESC', '1');
120:         return $this->next();
121:     }
122: 
123:     /**
124:      * Deletes entry by category and language.
125:      *
126:      * @param int $idcat
127:      * @param int $idlang
128:      */
129:     public function deleteByCategoryAndLanguage($idcat, $idlang) {
130:         $this->select('idcat=' . (int) $idcat . ' AND idlang=' . (int) $idlang);
131:         while (($oCode = $this->next()) !== false) {
132:             $this->delete($oCode->get('idpathresolvecache'));
133:         }
134:     }
135: 
136: }
137: 
138: /**
139:  * Pathresolve cache item
140:  *
141:  * @package Core
142:  * @subpackage GenericDB_Model
143:  */
144: class cApiPathresolveCache extends Item {
145: 
146:     /**
147:      * Constructor Function
148:      *
149:      * @param mixed $mId Specifies the ID of item to load
150:      */
151:     public function __construct($mId = false) {
152:         global $cfg;
153:         cApiPathresolveCacheHelper::setup($cfg['sql']['sqlprefix'] . '_pathresolve_cache');
154:         parent::__construct($cfg['sql']['sqlprefix'] . '_pathresolve_cache', 'idpathresolvecache');
155:         $this->setFilters(array(), array());
156:         if ($mId !== false) {
157:             $this->loadByPrimaryKey($mId);
158:         }
159:     }
160: 
161:     /**
162:      * Checks if item's cache time has expired.
163:      *
164:      * @throws cException If item has not been loaded before
165:      * @return bool
166:      */
167:     public function isCacheTimeExpired() {
168:         global $cfg;
169:         if (!$this->isLoaded()) {
170:             throw new cException('Item not loaded!');
171:         }
172:         $cacheTime = (isset($cfg['pathresolve_heapcache_time']))? $cfg['pathresolve_heapcache_time'] : 60 * 60 * 24;
173:         return ($this->get('lastcached') + $cacheTime < time());
174:     }
175: 
176: }
177: 
CMS CONTENIDO 4.9.0 API documentation generated by ApiGen 2.8.0