Index: branches/5.2.x/core/kernel/application.php =================================================================== diff -u -N -r14095 -r14184 --- branches/5.2.x/core/kernel/application.php (.../application.php) (revision 14095) +++ branches/5.2.x/core/kernel/application.php (.../application.php) (revision 14184) @@ -1,6 +1,6 @@ Factory = new kFactory(); $this->registerDefaultClasses(); $this->Phrases = new PhrasesCache(); - $this->memoryCache =& $this->Factory->makeClass('Cache'); - $this->EventManager =& $this->Factory->makeClass('EventManager'); + + $this->cacheManager =& $this->makeClass('kCacheManager'); + $this->cacheManager->InitCache(); + + $this->UrlManager =& $this->makeClass('kUrlManager'); + $this->EventManager =& $this->makeClass('EventManager'); $this->Factory->Storage['EventManager'] =& $this->EventManager; $this->RegisterDefaultBuildEvents(); @@ -360,7 +349,7 @@ $this->StoreVar('UserGroups', $user_groups, true); // true for optional } - $this->LoadStructureTemplateMapping(); + $this->UrlManager->LoadStructureTemplateMapping(); $this->HttpQuery->AfterInit(); $this->Session->ValidateExpired(); @@ -369,8 +358,7 @@ $this->Debugger->appendTimestamp('Processed HTTPQuery AfterInit'); } - $this->LoadCache(); - $this->InitConfig(); + $this->cacheManager->LoadApplicationCache(); $site_timezone = $this->ConfigValue('Config_Site_Time'); @@ -516,22 +504,6 @@ } kUtil::safeDefine('THEMES_PATH', $path); - - /*$theme_id = $this->GetVar('m_theme'); - if (!$theme_id) { - $theme_id = $this->GetDefaultThemeId(); - if (!$theme_id) { - if (!defined('IS_INSTALL')) $this->ApplicationDie('No Primary Theme Selected'); - } - } - $this->SetVar('m_theme', $theme_id); - $this->SetVar('theme.current_id', $theme_id ); // KOSTJA: this is to fool theme' getPassedId - $theme =& $this->recallObject('theme.current'); - if (!$theme->IsLoaded() || !$theme->GetDBField('Enabled')) { - if (!defined('IS_INSTALL')) $this->ApplicationDie('Unknown or disabled theme'); - } - - kUtil::safeDefine('THEMES_PATH', '/themes/'.$theme->GetDBField('Name'));*/ } function GetFrontThemePath($force=0) @@ -695,16 +667,18 @@ $this->registerClass('kTempTablesHandler', KERNEL_PATH . '/utility/temp_handler.php'); $this->registerClass('kEventManager', KERNEL_PATH . '/event_manager.php', 'EventManager', 'kiCacheable'); - $this->registerClass('kHookManager', KERNEL_PATH . '/managers/hook_manager.php', 'kHookManager', 'kiCacheable'); - $this->registerClass('kAgentManager', KERNEL_PATH . '/managers/agent_manager.php', 'kAgentManager', 'kiCacheable'); - $this->registerClass('kRequestManager', KERNEL_PATH . '/managers/request_manager.php', 'kRequestManager'); + $this->registerClass('kHookManager', KERNEL_PATH . '/managers/hook_manager.php', null, 'kiCacheable'); + $this->registerClass('kAgentManager', KERNEL_PATH . '/managers/agent_manager.php', null, 'kiCacheable'); + $this->registerClass('kRequestManager', KERNEL_PATH . '/managers/request_manager.php'); + $this->registerClass('kUrlManager', KERNEL_PATH . '/managers/url_manager.php'); + $this->registerClass('kCacheManager', KERNEL_PATH . '/managers/cache_manager.php', null, 'kiCacheable'); $this->registerClass('kUnitConfigReader', KERNEL_PATH . '/utility/unit_config_reader.php'); $this->registerClass('kArray', KERNEL_PATH . '/utility/params.php'); $this->registerClass('Params', KERNEL_PATH . '/utility/params.php'); $this->registerClass('Params', KERNEL_PATH . '/utility/params.php', 'kActions'); - $this->registerClass('kCache', KERNEL_PATH . '/utility/cache.php', 'Cache', 'Params'); + $this->registerClass('kCache', KERNEL_PATH . '/utility/cache.php', 'kCache', 'Params'); $this->registerClass('kHTTPQuery', KERNEL_PATH . '/utility/http_query.php', 'HTTPQuery', 'Params'); $this->registerClass('kHelper', KERNEL_PATH . '/kbase.php'); @@ -733,7 +707,7 @@ $this->registerClass('kEmailSendingHelper', KERNEL_PATH . '/utility/email_send.php', 'EmailSender', 'kHelper'); $this->registerClass('kSocket', KERNEL_PATH . '/utility/socket.php', 'Socket'); - if (file_exists(MODULES_PATH . '/in-commerce/units/currencies/currency_rates.php')) { + if ( file_exists(MODULES_PATH . '/in-commerce/units/currencies/currency_rates.php') ) { $this->registerClass('kCurrencyRates', MODULES_PATH . '/in-commerce/units/currencies/currency_rates.php'); } @@ -753,87 +727,22 @@ * @param int $category_id * @param string $name cache name = {filenames, category_designs, category_tree} * @return string + * @access public */ - function getCategoryCache($category_id, $name) + public function getCategoryCache($category_id, $name) { - $serial_name = '[%CIDSerial:' . $category_id . '%]'; - $cache_key = $name . $serial_name; - $ret = $this->getCache($cache_key); - - if ($ret === false) { - if (!$category_id) { - // don't query database for "Home" category (ID = 0), because it doesn't exist in database - return false; - } - - // this allows to save 2 sql queries for each category - $this->Conn->nextQueryCachable = true; - $sql = 'SELECT NamedParentPath, CachedTemplate, TreeLeft, TreeRight - FROM ' . TABLE_PREFIX . 'Category - WHERE CategoryId = ' . (int)$category_id; - $category_data = $this->Conn->GetRow($sql); - - if ($category_data !== false) { - // only direct links to category pages work (symlinks, container pages and so on won't work) - $this->setCache('filenames' . $serial_name, $category_data['NamedParentPath']); - $this->setCache('category_designs' . $serial_name, ltrim($category_data['CachedTemplate'], '/')); - $this->setCache('category_tree' . $serial_name, $category_data['TreeLeft'] . ';' . $category_data['TreeRight']); - } - } - - return $this->getCache($cache_key); + return $this->cacheManager->getCategoryCache($category_id, $name); } /** - * Returns item's filename that corresponds id passed. If possible, then get it from cache - * - * @param string $prefix - * @param int $id - * @param int $category_id - * @return string - */ - function getFilename($prefix, $id, $category_id = null) - { - if ($prefix == 'c') { - throw new Exception('Method "' . __FUNCTION__ . '" no longer work with "c" prefix. Please use "getCategoryCache" method instead'); - - return false; - } - - $category_id = isset($category_id) ? $category_id : $this->GetVar('m_cat_id'); - - $cache_key = 'filenames[%' . $this->incrementCacheSerial($prefix, $id, false) . '%]:' . (int)$category_id; - $filename = $this->getCache($cache_key); - - if ($filename === false) { - $this->Conn->nextQueryCachable = true; - $sql = 'SELECT ResourceId - FROM ' . $this->getUnitOption($prefix, 'TableName') . ' - WHERE ' . $this->getUnitOption($prefix, 'IDField') . ' = ' . $this->Conn->qstr($id); - $resource_id = $this->Conn->GetOne($sql); - - $this->Conn->nextQueryCachable = true; - $sql = 'SELECT Filename - FROM ' . TABLE_PREFIX . 'CategoryItems - WHERE (ItemResourceId = ' . $resource_id . ') AND (CategoryId = ' . (int)$category_id . ')'; - $filename = $this->Conn->GetOne($sql); - - if ($filename !== false) { - $this->setCache($cache_key, $filename); - } - } - - return $filename; - } - - /** * Returns caching type (none, memory, temporary) * * @return int + * @access public */ - function isCachingType($caching_type) + public function isCachingType($caching_type) { - return $this->memoryCache->getCachingType() == $caching_type; + return $this->cacheManager->isCachingType($caching_type); } /** @@ -842,30 +751,24 @@ * @param string $prefix * @param int $id ID (value of IDField) or ForeignKeyField:ID * @param bool $increment + * @access public */ - function incrementCacheSerial($prefix, $id = null, $increment = true) + public function incrementCacheSerial($prefix, $id = null, $increment = true) { - $pascal_case_prefix = implode('', array_map('ucfirst', explode('-', $prefix))); - $serial_name = $pascal_case_prefix . (isset($id) ? 'IDSerial:' . $id : 'Serial'); + return $this->cacheManager->incrementCacheSerial($prefix, $id, $increment); + } - if ($increment) { - if (defined('DEBUG_MODE') && DEBUG_MODE && $this->isDebugMode()) { - $this->Debugger->appendHTML('Incrementing serial: ' . $serial_name . '.'); - } - - $this->setCache($serial_name, (int)$this->getCache($serial_name) + 1); - - if (!defined('IS_INSTALL') || !IS_INSTALL) { - // delete cached mod-rewrite urls related to given prefix and id - $delete_clause = isset($id) ? $prefix . ':' . $id : $prefix; - - $sql = 'DELETE FROM ' . TABLE_PREFIX . 'CachedUrls - WHERE Prefixes LIKE ' . $this->Conn->qstr('%|' . $delete_clause . '|%'); - $this->Conn->Query($sql); - } - } - - return $serial_name; + /** + * Returns cached $key value from cache named $cache_name + * + * @param int $key key name from cache + * @param bool $store_locally store data locally after retrieved + * @return mixed + * @access public + */ + public function getCache($key, $store_locally = true) + { + return $this->cacheManager->getCache($key, $store_locally); } /** @@ -874,102 +777,68 @@ * @param int $key key name to add to cache * @param mixed $value value of chached record * @param int $expiration when value expires (0 - doesn't expire) + * @access public */ - function setCache($key, $value, $expiration = 0) + public function setCache($key, $value, $expiration = 0) { - return $this->memoryCache->setCache($key, $value, $expiration); + return $this->cacheManager->setCache($key, $value, $expiration); } /** - * Sets value to database cache + * Deletes key from cache * - * @param string $name - * @param mixed $value - * @param int $expiration + * @param string $key + * @access public */ - function setDBCache($name, $value, $expiration = false) + public function deleteCache($key) { - if ((int)$expiration <= 0) { - $expiration = -1; - } - - $fields_hash = Array ( - 'VarName' => $name, - 'Data' => &$value, - 'Cached' => adodb_mktime(), - 'LifeTime' => (int)$expiration, - ); - - $this->Conn->nextQueryCachable = true; - $this->Conn->doInsert($fields_hash, TABLE_PREFIX . 'Cache', 'REPLACE'); + $this->cacheManager->deleteCache($key); } /** - * Returns cached $key value from cache named $cache_name + * Reset's all memory cache at once * - * @param int $key key name from cache - * @param bool $store_locally store data locally after retrieved - * @return mixed + * @access public */ - function getCache($key, $store_locally = true) + public function resetCache() { - return $this->memoryCache->getCache($key, $store_locally); + $this->cacheManager->resetCache(); } /** * Returns value from database cache * * @param string $name key name * @return mixed + * @access public */ - function getDBCache($name) + public function getDBCache($name) { - $this->Conn->nextQueryCachable = true; - - $sql = 'SELECT Data, Cached, LifeTime - FROM ' . TABLE_PREFIX . 'Cache - WHERE VarName = ' . $this->Conn->qstr($name); - $data = $this->Conn->GetRow($sql); - - if ($data) { - $lifetime = (int)$data['LifeTime']; // in seconds - if (($lifetime > 0) && ($data['Cached'] + $lifetime < adodb_mktime())) { - // delete expired - $this->Conn->nextQueryCachable = true; - - $sql = 'DELETE FROM ' . TABLE_PREFIX . 'Cache - WHERE VarName = ' . $this->Conn->qstr($name); - $this->Conn->Query($sql); - - return false; - } - - return $data['Data']; - } - - return false; + return $this->cacheManager->getDBCache($name); } /** - * Deletes key from cache + * Sets value to database cache * - * @param string $key + * @param string $name + * @param mixed $value + * @param int $expiration + * @access public */ - function deleteCache($key) + public function setDBCache($name, $value, $expiration = false) { - $this->memoryCache->delete($key); + $this->cacheManager->setDBCache($name, $value, $expiration); } /** * Deletes key from database cache * * @param string $name + * @access public */ - function deleteDBCache($name) + public function deleteDBCache($name) { - $sql = 'DELETE FROM ' . TABLE_PREFIX . 'Cache - WHERE VarName = ' . $this->Conn->qstr($name); - $this->Conn->Query($sql); + $this->cacheManager->deleteDBCache($name); } /** @@ -1118,7 +987,7 @@ $this->Session->SaveData(); if (kUtil::constOn('DBG_CACHE')) { - $this->memoryCache->printStatistics(); + $this->cacheManager->printStatistics(); } $this->HTML = ob_get_clean() . $this->HTML . $this->Debugger->printReport(true); @@ -1143,7 +1012,7 @@ echo $this->HTML; } - $this->UpdateCache(); + $this->cacheManager->UpdateApplicationCache(); flush(); if (!$debug_mode) { @@ -1512,223 +1381,20 @@ } /** - * Returns index file, that could be passed as parameter to method, as parameter to tag and as constant or not passed at all - * - * @param string $prefix - * @param string $index_file - * @param Array $params - * @return string - */ - function getIndexFile($prefix, $index_file, &$params) - { - if (isset($params['index_file'])) { - $index_file = $params['index_file']; - unset($params['index_file']); - return $index_file; - } - - if (isset($index_file)) { - return $index_file; - } - - if (defined('INDEX_FILE')) { - return INDEX_FILE; - } - - $cut_prefix = trim(BASE_PATH, '/').'/'.trim($prefix, '/'); - return trim(preg_replace('/'.preg_quote($cut_prefix, '/').'(.*)/', '\\1', $_SERVER['PHP_SELF']), '/'); - } - - /** * Return href for template * * @access public * @param string $t Template path * @var string $prefix index.php prefix - could be blank, 'admin' */ - function HREF($t, $prefix = '', $params = null, $index_file = null) + public function HREF($t, $prefix = '', $params = null, $index_file = null) { - static $theme_id = null; + return $this->UrlManager->HREF($t, $prefix, $params, $index_file); + } - if (!isset($theme_id)) { - $theme_id = $this->GetVar('m_theme'); - } - - if (!$t) { - // when template not specified, use current - $t = $this->GetVar('t'); - } - - $t = preg_replace('/^Content\//i', '', $t); - - if (substr($t, -4) == '.tpl') { - // cut template extension (deprecated link format) - $t = substr($t, 0, strlen($t) - 4); - } - - if (substr($t, 0, 3) == 'id:') { - // link to structure page using it's id - $params['m_cat_id'] = substr($t, 3); - $t = $this->structureTemplateMapping[$t]; - } - - if (array_key_exists('use_section', $params)) { - $use_section = $params['use_section']; - unset($params['use_section']); - } - - if (isset($use_section) && $use_section && array_key_exists($t . ':' . $theme_id, $this->structureTemplateMapping)) { - // structure template corresponding to given physical template - $t = $this->structureTemplateMapping[$t . ':' . $theme_id]; - unset($params['use_section']); - } - - if (preg_match('/external:(.*)/', $t, $rets)) { - // external url - return $rets[1]; - } - - if ($this->isAdmin && $prefix == '') $prefix = ADMIN_DIRECTORY; - if ($this->isAdmin && $prefix == '_FRONT_END_') $prefix = ''; - - $index_file = $this->getIndexFile($prefix, $index_file, $params); - - if (isset($params['_auto_prefix_'])) { - unset($params['_auto_prefix_']); // this is parser-related param, do not need to pass it here - } - - $ssl = isset($params['__SSL__']) ? $params['__SSL__'] : null; - if ($ssl !== null) { - $session =& $this->recallObject('Session'); - /* @var $session Session */ - - $target_url = rtrim($this->BaseURL('', $ssl, false), '/'); - $cookie_url = trim($session->CookieDomain . $session->CookiePath, '/.'); - - // set session to GET_ONLY, to pass sid only if sid is REAL AND session is set - if (!preg_match('#' . preg_quote($cookie_url) . '#', $target_url) && $session->SessionSet) { - // when SSL<->NON-SSL redirect to different domain pass SID in url - $session->SetMode(Session::smGET_ONLY); - } - } - - if (isset($params['opener']) && $params['opener'] == 'u') { - $wid = $this->GetVar('m_wid'); - $stack_name = rtrim('opener_stack_'.$wid, '_'); - $opener_stack = $this->RecallVar($stack_name); - - if ($opener_stack && $opener_stack != serialize(Array())) { - $opener_stack = unserialize($opener_stack); - list($index_file, $env) = explode('|', $opener_stack[count($opener_stack) - 1]); - $ret = $this->BaseURL($prefix, $ssl).$index_file.'?'.ENV_VAR_NAME.'='.$env; - if ( getArrayValue($params,'escape') ) $ret = addslashes($ret); - - if (isset($params['m_opener']) && $params['m_opener'] == 'u') { - array_pop($opener_stack); - if (!$opener_stack) { - $this->RemoveVar($stack_name); - // remove popups last templates, because popup is closing now - $this->RemoveVar('last_template_'.$wid); - $this->RemoveVar('last_template_popup_'.$wid); - - // don't save popups last templates again :) - $this->SetVar('skip_last_template', 1); - } - else { - $this->StoreVar($stack_name, serialize($opener_stack)); - } - - /*// store window relations - $window_relations = $this->RecallVar('window_relations'); - $window_relations = $window_relations ? unserialize($window_relations) : Array (); - if (array_key_exists($wid, $window_relations)) { - unset($window_relations[$wid]); - $this->StoreVar('window_relations', serialize($window_relations)); - }*/ - } - return $ret; - } - else { - //define('DBG_REDIRECT', 1); - $t = $this->GetVar('t'); - } - } - - $pass = isset($params['pass']) ? $params['pass'] : ''; - - // pass events with url - $pass_events = false; - if( isset($params['pass_events']) ) - { - $pass_events = $params['pass_events']; - unset($params['pass_events']); - } - - $map_link = ''; - if( isset($params['anchor']) ) - { - $map_link = '#'.$params['anchor']; - unset($params['anchor']); - } - - if ( isset($params['no_amp']) ) - { - $params['__URLENCODE__'] = $params['no_amp']; - unset($params['no_amp']); - } - - $no_rewrite = false; - if( isset($params['__NO_REWRITE__']) ) - { - $no_rewrite = true; - unset($params['__NO_REWRITE__']); - } - - $force_rewrite = false; - if( isset($params['__MOD_REWRITE__']) ) - { - $force_rewrite = true; - unset($params['__MOD_REWRITE__']); - } - - $force_no_sid = false; - if( isset($params['__NO_SID__']) ) - { - $force_no_sid = true; - unset($params['__NO_SID__']); - } - - // append pass through variables to each link to be build - $params = array_merge($this->getPassThroughVariables($params), $params); - - if ($force_rewrite || ($this->RewriteURLs($ssl) && !$no_rewrite)) { - static $rewrite_listeners_done = false; - - if (!$rewrite_listeners_done) { - $mod_rewrite_helper =& $this->recallObject('ModRewriteHelper'); - /* @var $mod_rewrite_helper kModRewriteHelper */ - - $mod_rewrite_helper->initRewriteListeners(); - - $rewrite_listeners_done = true; - } - - $session =& $this->recallObject('Session'); - - if ($session->NeedQueryString() && !$force_no_sid) { - $params['sid'] = $this->GetSID(); - } - - $url = $this->BuildEnv_NEW($t, $params, $pass, $pass_events); - $ret = $this->BaseURL($prefix, $ssl).$url.$map_link; - } - else { - unset($params['pass_category']); // we don't need to pass it when mod_rewrite is off - $env = $this->BuildEnv($t, $params, $pass, $pass_events); - $ret = $this->BaseURL($prefix, $ssl).$index_file.'?'.$env.$map_link; - } - - return $ret; + function getPhysicalTemplate($template) + { + return $this->UrlManager->getPhysicalTemplate($template); } /** @@ -1739,359 +1405,12 @@ */ function getPassThroughVariables(&$params) { - static $cached_pass_through = null; - - if (isset($params['no_pass_through']) && $params['no_pass_through']) { - unset($params['no_pass_through']); - return Array(); - } - - // because pass through is not changed during script run, then we can cache it - if (is_null($cached_pass_through)) { - - $cached_pass_through = Array(); - $pass_through = $this->GetVar('pass_through'); - - if ($pass_through) { - // names of variables to pass to each link - $cached_pass_through['pass_through'] = $pass_through; - $pass_through = explode(',', $pass_through); - foreach ($pass_through as $pass_through_var) { - $cached_pass_through[$pass_through_var] = $this->GetVar($pass_through_var); - } - } - - } - - return $cached_pass_through; + return $this->UrlManager->getPassThroughVariables($params); } - - /** - * Returns sorted array of passed prefixes (to build url from) - * - * @param string $pass - * @return Array - */ - function getPassInfo($pass = 'all') - { - if (!$pass) $pass = 'all'; - $pass = trim( - preg_replace( - '/(?<=,|\\A)all(?=,|\\z)/', - trim($this->GetVar('passed'), ','), - trim($pass, ',') - ), - ','); - - if (!$pass) { - return Array(); - } - - $pass_info = array_unique( explode(',', $pass) ); // array( prefix[.special], prefix[.special] ... - - // we need to keep that sorting despite the sorting below, because this sorts prefixes with same priority by name - sort($pass_info, SORT_STRING); // to be prefix1,prefix1.special1,prefix1.special2,prefix3.specialX - - foreach ($pass_info as $prefix) { - list ($prefix_only, ) = explode('.', $prefix, 2); - $sorted[$prefix] = $this->getUnitOption($prefix_only, 'RewritePriority', 0); - } - - asort($sorted, SORT_NUMERIC); - $pass_info = array_keys($sorted); - - // ensure that "m" prefix is at the beginning - $main_index = array_search('m', $pass_info); - if ($main_index !== false) { - unset($pass_info[$main_index]); - array_unshift($pass_info, 'm'); - } - return $pass_info; - } - - function BuildEnv_NEW($t, $params, $pass='all', $pass_events = false) - { - if ($this->GetVar('admin') || (array_key_exists('admin', $params) && $params['admin'])) { - $params['admin'] = 1; - - if (!array_key_exists('editing_mode', $params)) { - $params['editing_mode'] = EDITING_MODE; - } - } - - $ret = ''; - $env = ''; - - $encode = false; - - if (isset($params['__URLENCODE__'])) { - $encode = $params['__URLENCODE__']; - unset($params['__URLENCODE__']); - } - - if (isset($params['__SSL__'])) { - unset($params['__SSL__']); - } - - $catalog_item_found = false; - $pass_info = $this->getPassInfo($pass); - - if ($pass_info) { - if ($pass_info[0] == 'm') { - array_shift($pass_info); - } - - $inject_parts = Array (); // url parts for beginning of url - $params['t'] = $t; // make template available for rewrite listeners - $params['pass_template'] = true; // by default we keep given template in resulting url - - if (!array_key_exists('pass_category', $params)) { - $params['pass_category'] = false; // by default we don't keep categories in url - } - - foreach ($pass_info as $pass_index => $pass_element) { - list ($prefix) = explode('.', $pass_element); - $catalog_item = $this->findModule('Var', $prefix) && $this->getUnitOption($prefix, 'CatalogItem'); - - if (array_key_exists($prefix, $this->RewriteListeners)) { - // if next prefix is same as current, but with special => exclude current prefix from url - $next_prefix = array_key_exists($pass_index + 1, $pass_info) ? $pass_info[$pass_index + 1] : false; - if ($next_prefix) { - $next_prefix = substr($next_prefix, 0, strlen($prefix) + 1); - if ($prefix . '.' == $next_prefix) { - continue; - } - } - - // rewrited url part - $url_part = $this->BuildModuleEnv_NEW($pass_element, $params, $pass_events); - - if (is_string($url_part) && $url_part) { - $ret .= $url_part . '/'; - - if ($catalog_item) { - // pass category later only for catalog items - $catalog_item_found = true; - } - } - elseif (is_array($url_part)) { - // rewrite listener want to insert something at the beginning of url too - if ($url_part[0]) { - $inject_parts[] = $url_part[0]; - } - - if ($url_part[1]) { - $ret .= $url_part[1] . '/'; - } - - if ($catalog_item) { - // pass category later only for catalog items - $catalog_item_found = true; - } - } elseif ($url_part === false) { - // rewrite listener decided not to rewrite given $pass_element - $env .= ':' . $this->BuildModuleEnv($pass_element, $params, $pass_events); - } - } - else { - $env .= ':' . $this->BuildModuleEnv($pass_element, $params, $pass_events); - } - } - - if ($catalog_item_found || preg_match('/c\.[-\d]*/', implode(',', $pass_info))) { - // "c" prefix is present -> keep category - $params['pass_category'] = true; - } - - $params['inject_parts'] = $inject_parts; - - $ret = $this->BuildModuleEnv_NEW('m', $params, $pass_events) . '/' . $ret; - $cat_processed = array_key_exists('category_processed', $params) && $params['category_processed']; - - // remove tempporary parameters used by listeners - unset($params['t'], $params['inject_parts'], $params['pass_template'], $params['pass_category'], $params['category_processed']); - - if (array_key_exists('url_ending', $params)) { - $ret = trim($ret, '/') . $params['url_ending']; - unset($params['url_ending']); - } - else { - $ret = trim($ret, '/') . MOD_REWRITE_URL_ENDING; - } - - if ($env) { - $params[ENV_VAR_NAME] = ltrim($env, ':'); - } - } - - unset($params['pass'], $params['opener'], $params['m_event']); - - if (array_key_exists('escape', $params) && $params['escape']) { - $ret = addslashes($ret); - unset($params['escape']); - } - - $ret = str_replace('%2F', '/', urlencode($ret)); - - $params_str = ''; - $join_string = $encode ? '&' : '&'; - - foreach ($params as $param => $value) { - $params_str .= $join_string . $param . '=' . $value; - } - - if ($params_str) { - $ret .= '?' . substr($params_str, strlen($join_string)); - } - - if ($encode) { - $ret = str_replace('\\', '%5C', $ret); - } - - return $ret; - } - - function BuildModuleEnv_NEW($prefix_special, &$params, $keep_events = false) - { - list ($prefix) = explode('.', $prefix_special); - - $url_parts = Array (); - $listener = $this->RewriteListeners[$prefix][0]; - - $ret = $listener[0]->$listener[1](REWRITE_MODE_BUILD, $prefix_special, $params, $url_parts, $keep_events); - - return $ret; - } - - /** - * Builds env part that corresponds prefix passed - * - * @param string $prefix_special item's prefix & [special] - * @param Array $params url params - * @param bool $pass_events - */ - function BuildModuleEnv($prefix_special, &$params, $pass_events = false) - { - list($prefix) = explode('.', $prefix_special); - $query_vars = $this->getUnitOption($prefix, 'QueryString'); - - //if pass events is off and event is not implicity passed - if( !$pass_events && !isset($params[$prefix_special.'_event']) ) { - $params[$prefix_special.'_event'] = ''; // remove event from url if requested - //otherwise it will use value from get_var - } - - if(!$query_vars) return ''; - - $tmp_string = Array(0 => $prefix_special); - foreach($query_vars as $index => $var_name) - { - //if value passed in params use it, otherwise use current from application - $var_name = $prefix_special.'_'.$var_name; - $tmp_string[$index] = isset( $params[$var_name] ) ? $params[$var_name] : $this->GetVar($var_name); - if ( isset($params[$var_name]) ) unset( $params[$var_name] ); - } - - $escaped = array(); - foreach ($tmp_string as $tmp_val) { - $escaped[] = str_replace(Array('-',':'), Array('\-','\:'), $tmp_val); - } - - $ret = implode('-', $escaped); - if ($this->getUnitOption($prefix, 'PortalStyleEnv') == true) - { - $ret = preg_replace('/^([a-zA-Z]+)-([0-9]+)-(.*)/','\\1\\2-\\3', $ret); - } - return $ret; - } - function BuildEnv($t, $params, $pass='all', $pass_events = false, $env_var = true) { - if ($this->GetVar('admin') || (array_key_exists('admin', $params) && $params['admin'])) { - $params['admin'] = 1; - - if (!array_key_exists('editing_mode', $params)) { - $params['editing_mode'] = EDITING_MODE; - } - } - - $session =& $this->recallObject('Session'); - $ssl = isset($params['__SSL__']) ? $params['__SSL__'] : 0; - $sid = $session->NeedQueryString() && !$this->RewriteURLs($ssl) ? $this->GetSID() : ''; -// if (getArrayValue($params,'admin') == 1) $sid = $this->GetSID(); - - $ret = ''; - if ($env_var) { - $ret = ENV_VAR_NAME.'='; - } - - $ret .= $sid . '-'; // SID-TEMPLATE - - $encode = false; - if (isset($params['__URLENCODE__'])) { - $encode = $params['__URLENCODE__']; - unset($params['__URLENCODE__']); - } - - if (isset($params['__SSL__'])) { - unset($params['__SSL__']); - } - - $env_string = ''; - $category_id = isset($params['m_cat_id']) ? $params['m_cat_id'] : $this->GetVar('m_cat_id'); - - $item_id = false; - $pass_info = $this->getPassInfo($pass); - if ($pass_info) { - if ($pass_info[0] == 'm') array_shift($pass_info); - foreach ($pass_info as $pass_element) { - list($prefix) = explode('.', $pass_element); - $require_rewrite = $this->findModule('Var', $prefix); - if ($require_rewrite) { - $item_id = isset($params[$pass_element.'_id']) ? $params[$pass_element.'_id'] : $this->GetVar($pass_element.'_id'); - } - $env_string .= ':'.$this->BuildModuleEnv($pass_element, $params, $pass_events); - } - } - - if (strtolower($t) == '__default__') { - if (is_numeric($item_id)) { - $mod_rw_helper =& $this->recallObject('ModRewriteHelper'); - /* @var $mod_rw_helper kModRewriteHelper */ - - $t = $mod_rw_helper->GetItemTemplate($category_id, $pass_element); // $pass_element should be the last processed element - // $t = $this->getCategoryCache($category_id, 'item_templates'); - } - elseif ($category_id) { - $t = strtolower(preg_replace('/^Content\//i', '', $this->getCategoryCache($category_id, 'filenames') )); - } - else { - $t = 'index'; - } - } - - $ret .= $t.':'.$this->BuildModuleEnv('m', $params, $pass_events).$env_string; - - unset($params['pass'], $params['opener'], $params['m_event']); - - if (array_key_exists('escape', $params) && $params['escape']) { - $ret = addslashes($ret); - unset($params['escape']); - } - - $join_string = $encode ? '&' : '&'; - $params_str = ''; - foreach ($params as $param => $value) - { - $params_str .= $join_string.$param.'='.$value; - } - $ret .= $params_str; - - if ($encode) { - $ret = str_replace('\\', '%5C', $ret); - } - return $ret; + return $this->UrlManager->BuildEnv($t, $params, $pass, $pass_events, $env_var); } function BaseURL($prefix = '', $ssl = null, $add_port = true) @@ -2283,125 +1602,17 @@ $this->Session->LoadPersistentVars(); } - function LoadCache() - { - // TODO: maybe language part isn't required, since same phrase from different languages have one ID now - $cache_key = $this->GetVar('t') . $this->GetVar('m_theme') . $this->GetVar('m_lang') . $this->isAdmin; - - $sql = 'SELECT PhraseList, ConfigVariables - FROM ' . TABLE_PREFIX . 'PhraseCache - WHERE Template = ' . $this->Conn->qstr( md5($cache_key) ); - $res = $this->Conn->GetRow($sql); - - if ($res) { - $this->Caches['PhraseList'] = $res['PhraseList'] ? explode(',', $res['PhraseList']) : Array (); - $config_ids = $res['ConfigVariables'] ? explode(',', $res['ConfigVariables']) : Array (); - - if (isset($this->Caches['ConfigVariables'])) { - $config_ids = array_diff($config_ids, $this->Caches['ConfigVariables']); - } - } - else { - $config_ids = Array (); - } - - $this->Phrases->Init('phrases'); - $this->Caches['ConfigVariables'] = $config_ids; - $this->ConfigCacheIds = $config_ids; - } - /** - * Loads template mapping for Front-End - * - */ - function LoadStructureTemplateMapping() - { - if (!$this->isAdmin) { - $category_helper =& $this->recallObject('CategoryHelper'); - /* @var $category_helper CategoryHelper */ - - $this->structureTemplateMapping = $category_helper->getTemplateMapping(); - } - } - - function UpdateCache() - { - $update = false; - //something changed - $update = $update || $this->Phrases->NeedsCacheUpdate(); - $update = $update || (count($this->ConfigCacheIds) && $this->ConfigCacheIds != $this->Caches['ConfigVariables']); - - if ($update) { - $cache_key = $this->GetVar('t').$this->GetVar('m_theme').$this->GetVar('m_lang').$this->isAdmin; - $query = sprintf("REPLACE %s (PhraseList, CacheDate, Template, ConfigVariables) - VALUES (%s, %s, %s, %s)", - TABLE_PREFIX.'PhraseCache', - $this->Conn->qstr(join(',', $this->Phrases->Ids)), - adodb_mktime(), - $this->Conn->qstr(md5($cache_key)), - $this->Conn->qstr(implode(',', array_unique($this->ConfigCacheIds)))); - $this->Conn->Query($query); - } - } - - function InitConfig() - { - if (isset($this->Caches['ConfigVariables']) && count($this->Caches['ConfigVariables']) > 0) { - $sql = 'SELECT VariableValue, VariableName - FROM ' . TABLE_PREFIX . 'ConfigurationValues - WHERE VariableId IN (' . implode(',', $this->Caches['ConfigVariables']) . ')'; - $this->ConfigHash = array_merge($this->ConfigHash, $this->Conn->GetCol($sql, 'VariableName')); - } - } - - /** * Returns configuration option value by name * * @param string $name * @return string */ function ConfigValue($name) { - if ($name == 'Smtp_AdminMailFrom') { - $res = $this->siteDomainField('AdminEmail'); - - if ($res) { - return $res; - } - } - - $res = array_key_exists($name, $this->ConfigHash) ? $this->ConfigHash[$name] : false; - if ($res !== false) { - return $res; - } - - if (defined('IS_INSTALL') && IS_INSTALL && !$this->TableFound('ConfigurationValues')) { - return false; - } - - $this->Conn->nextQueryCachable = true; - $sql = 'SELECT VariableId, VariableValue - FROM '.TABLE_PREFIX.'ConfigurationValues - WHERE VariableName = '.$this->Conn->qstr($name); - $res = $this->Conn->GetRow($sql); - - if ($res !== false) { - $this->ConfigHash[$name] = $res['VariableValue']; - $this->ConfigCacheIds[] = $res['VariableId']; - - return $res['VariableValue']; - } - - return false; + return $this->cacheManager->ConfigValue($name); } - function UpdateConfigCache() - { - if ($this->ConfigCacheIds) { - - } - } - /** * Allows to process any type of event * @@ -2498,7 +1709,7 @@ * @param Array $arguments * @return kBase */ - function &recallObject($name, $pseudo_class = null, $event_params = Array(), $arguments = Array ()) + public function &recallObject($name, $pseudo_class = null, $event_params = Array(), $arguments = Array ()) { $result =& $this->Factory->getObject($name, $pseudo_class, $event_params, $arguments); @@ -2537,7 +1748,7 @@ * @param string $name Object's name in the Storage * @author Kostja */ - function removeObject($name) + public function removeObject($name) { $this->Factory->DestroyObject($name); } @@ -2550,7 +1761,7 @@ * @return kBase * @access public */ - function &makeClass($pseudo_class, $arguments = Array ()) + public function &makeClass($pseudo_class, $arguments = Array ()) { $result =& $this->Factory->makeClass($pseudo_class, $arguments); @@ -2565,7 +1776,7 @@ * @author Alex * @access public */ - function isDebugMode($check_debugger = true) + public function isDebugMode($check_debugger = true) { $debug_mode = defined('DEBUG_MODE') && DEBUG_MODE; if ($check_debugger) { @@ -2608,13 +1819,9 @@ * @param mixed $default * @return string * @access public - * @author Alex */ - function getUnitOption($prefix, $option, $default = false) + public function getUnitOption($prefix, $option, $default = false) { - /*if (!isset($this->UnitConfigReader)) { - $this->UnitConfigReader =& $this->recallObject('kUnitConfigReader'); - }*/ return $this->UnitConfigReader->getUnitOption($prefix, $option, $default); } @@ -2624,12 +1831,10 @@ * @param string $prefix * @param string $name * @param string $value - * @author Alex * @access public */ - function setUnitOption($prefix, $option, $value) + public function setUnitOption($prefix, $option, $value) { -// $unit_config_reader =& $this->recallObject('kUnitConfigReader'); return $this->UnitConfigReader->setUnitOption($prefix,$option,$value); } @@ -2639,11 +1844,9 @@ * @param string $prefix * @return Array * @access public - * @author Alex */ - function getUnitOptions($prefix) + public function getUnitOptions($prefix) { -// $unit_config_reader =& $this->recallObject('kUnitConfigReader'); return $this->UnitConfigReader->getUnitOptions($prefix); } @@ -2653,11 +1856,8 @@ * @param string $prefix * @return bool */ - function prefixRegistred($prefix) + public function prefixRegistred($prefix) { - /*if (!isset($this->UnitConfigReader)) { - $this->UnitConfigReader =& $this->recallObject('kUnitConfigReader'); - }*/ return $this->UnitConfigReader->prefixRegistred($prefix); } @@ -2668,9 +1868,8 @@ * @param string $prefix_special * @return Array * @access public - * @author Alex */ - function processPrefix($prefix_special) + public function processPrefix($prefix_special) { return $this->Factory->processPrefix($prefix_special); } @@ -2688,7 +1887,6 @@ $this->EventManager->setEvent($prefix_special,$event_name); } - /** * SQL Error Handler * @@ -2976,6 +2174,8 @@ function CheckPermission($name, $type = 1, $cat_id = null) { $perm_helper =& $this->recallObject('PermissionsHelper'); + /* @var $perm_helper kPermissionsHelper */ + return $perm_helper->CheckPermission($name, $type, $cat_id); } @@ -3020,7 +2220,6 @@ function isModuleEnabled($module_name) { return $this->findModule('Name', $module_name) !== false; - } /** @@ -3288,6 +2487,11 @@ return $this->ModuleInfo['Core']['RootCat']; } + function DeleteUnitCache($include_sections = false) + { + $this->cacheManager->DeleteUnitCache($include_sections); + } + /** * Sets data from cache to object * @@ -3296,14 +2500,8 @@ */ public function setFromCache(&$data) { - $this->ConfigHash = $data['Application.ConfigHash']; - - $this->Caches['ConfigVariables'] = $data['Application.ConfigCacheIds']; // undefined attribute - $this->ConfigCacheIds = $data['Application.ConfigCacheIds']; - $this->ReplacementTemplates = $data['Application.ReplacementTemplates']; $this->RewriteListeners = $data['Application.RewriteListeners']; - $this->ModuleInfo = $data['Application.ModuleInfo']; } @@ -3316,17 +2514,10 @@ */ public function getToCache() { - return Array ( - 'Application.ConfigHash' => $this->ConfigHash, - - 'Application.Caches.ConfigVariables' => $this->Caches['ConfigVariables'], // undefined attribute - 'Application.ConfigCacheIds' => $this->ConfigCacheIds, - - 'Application.ReplacementTemplates' => $this->ReplacementTemplates, - 'Application.RewriteListeners' => $this->RewriteListeners, - - 'Application.ModuleInfo' => $this->ModuleInfo, - ); + return Array ( + 'Application.ReplacementTemplates' => $this->ReplacementTemplates, + 'Application.RewriteListeners' => $this->RewriteListeners, + 'Application.ModuleInfo' => $this->ModuleInfo, + ); } - } \ No newline at end of file