Index: trunk/core/kernel/application.php =================================================================== diff -u -r4674 -r4758 --- trunk/core/kernel/application.php (.../application.php) (revision 4674) +++ trunk/core/kernel/application.php (.../application.php) (revision 4758) @@ -63,6 +63,14 @@ var $ConfigHash = Array(); /** + * Ids of config variables used in current run (for caching) + * + * @var Array + * @access private + */ + var $ConfigCacheIds = array(); + + /** * Reference to debugger * * @var Debugger @@ -90,15 +98,47 @@ * @var kDBConnection */ var $Conn = null; - + /** * Maintains list of user-defined error handlers * * @var Array */ var $errorHandlers = Array(); + + // performance needs: /** + * Holds a refererence to httpquery + * + * @var kHttpQuery + */ + var $HttpQuery = null; + + /** + * Holds a reference to UnitConfigReader + * + * @var kUnitConfigReader + */ + var $UnitConfigReader = null; + + /** + * Holds a reference to Session + * + * @var kSession + */ + var $Session = null; + + /** + * Holds a ref to kEventManager + * + * @var kEventManager + */ + var $EventManager = null; + + var $Application = null; + + /** * Returns kApplication instance anywhere in the script. * * This method should be used to get single kApplication object instance anywhere in the @@ -128,6 +168,7 @@ safeDefine('APPLICATION_CLASS', 'kApplication'); $class = APPLICATION_CLASS; $instance = new $class(); + $instance->Application =& $instance; } return $instance; } @@ -138,22 +179,32 @@ * @param string $field * @param mixed $value * @param string field value to returns, if not specified, then return all fields + * @param string field to return + * @param string field case-insensitive compare * @return Array */ - function findModule($field, $value, $return_field = null) + function findModule($field, $value, $return_field = null, $ci=false) { $found = false; foreach ($this->ModuleInfo as $module_name => $module_info) { - if ($module_info[$field] == $value) { - $found = true; - break; + if ($ci) { + if (strtolower($module_info[$field]) == strtolower($value)) { + $found = true; + break; + } } + else { + if ($module_info[$field] == $value) { + $found = true; + break; + } + } } - + if ($found) { return isset($return_field) ? $module_info[$return_field] : $module_info; } - + return false; } @@ -170,17 +221,15 @@ { if($this->InitDone) return false; - if( $this->isDebugMode() && dbg_ConstOn('DBG_PROFILE_MEMORY') ) + if( defined('DEBUG_MODE') && $this->isDebugMode() && dbg_ConstOn('DBG_PROFILE_MEMORY') ) { $this->Debugger->appendMemoryUsage('Application before Init:'); } - if( !$this->isDebugMode() && !constOn('DBG_ZEND_PRESENT') ) { error_reporting(0); ini_set('display_errors', 0); } - if( !constOn('DBG_ZEND_PRESENT') ) { $error_handler = set_error_handler( Array(&$this,'handleError') ); @@ -190,31 +239,44 @@ $this->Conn = new kDBConnection(SQL_TYPE, Array(&$this, 'handleSQLError') ); $this->Conn->Connect(SQL_SERVER, SQL_USER, SQL_PASS, SQL_DB); $this->Conn->debugMode = $this->isDebugMode(); - - $this->ConfigHash = $this->Conn->GetCol('SELECT VariableValue, VariableName FROM '.TABLE_PREFIX.'ConfigurationValues', 'VariableName'); + $this->Factory = new kFactory(); + $this->registerDefaultClasses(); + $this->Phrases = new PhrasesCache(); + $this->EventManager =& $this->Factory->makeClass('EventManager'); + $this->Factory->Storage['EventManager'] =& $this->EventManager; + $this->RegisterDefaultBuildEvents(); + $this->SetDefaultConstants(); + + $this->UnitConfigReader =& $this->recallObject('kUnitConfigReader'); + $this->UnitConfigReader->scanModules(MODULES_PATH); + $this->registerModuleConstants(); + + // extracted out of SetDefaultConstants because it uses ConfigValue which is read only in UnitConfigReader (optimization) + $this->SetAdminDirectory(); + $rewrite_on = $this->ConfigValue('UseModRewrite'); // admin=1 - when front is browsed using admin session $admin_on = getArrayValue($_REQUEST, 'admin') || $this->IsAdmin(); define('MOD_REWRITE', $rewrite_on && !$admin_on ? 1 : 0); - $this->Factory = new kFactory(); - - $this->registerDefaultClasses(); - $this->refreshModuleInfo(); - $this->SetDefaultConstants(); - - // 1. to read configs before doing any recallObject - $config_reader =& $this->recallObject('kUnitConfigReader'); + $this->HttpQuery =& $this->recallObject('HTTPQuery'); + $this->Session =& $this->recallObject('Session'); + $this->HttpQuery->AfterInit(); + + $this->LoadCache(); + $this->InitConfig(); + // Module items are recalled during url parsing & PhrasesCache is needed already there, // because it's used in their build events. That's why phrases cache initialization is // called from kHTTPQuery in case when mod_rewrite is used if (!$this->RewriteURLs()) { $this->Phrases = new PhrasesCache(); - $this->Phrases->Init('phrases'); } - + + $this->Phrases->Init('phrases'); + if(!$this->RecallVar('UserGroups')) { $session =& $this->recallObject('Session'); $user_groups = trim($session->GetField('GroupList'), ','); @@ -229,6 +291,8 @@ $language =& $this->recallObject( 'lang.current', null, Array('live_table' => true) ); + $this->HandleEvent( new kEvent('visits:OnRegisterVisit') ); + $this->ValidateLogin(); if($this->isDebugMode()) { @@ -246,30 +310,35 @@ FROM '.TABLE_PREFIX.'Modules WHERE '.$modules_helper->getWhereClause().' ORDER BY LoadOrder'; - + $this->ModuleInfo = $this->Conn->Query($sql, 'Name'); + $this->registerModuleConstants(); } - + /** * Checks if passed language id if valid and sets it to primary otherwise * */ function VerifyLanguageId() { $language_id = $this->GetVar('m_lang'); - if ($language_id) { - $table = $this->getUnitOption('lang', 'TableName'); - $id_field = $this->getUnitOption('lang', 'IDField'); - $sql = 'SELECT '.$id_field.' - FROM '.$table.' - WHERE Enabled = 1'; - $language_ids = $this->Conn->GetCol($sql); + if (!$language_id) { + $language_id = $this->GetDefaultLanguageId(); + if (!$language_id) { + if (!$this->Application->IsAdmin()) { + die ('No Primary Language Selected'); + } + else { + $language_id = 1; + } + } } - - if (!$language_id || !in_array($language_id, $language_ids)) { - $this->SetVar('m_lang', $this->GetDefaultLanguageId() ); + $this->SetVar('lang.current_id', $language_id ); + $this->SetVar('m_lang', $language_id ); + $lang =& $this->recallObject('lang.current'); + if ( !$lang->IsLoaded() || (!$this->Application->IsAdmin() && !$lang->GetDBField('Enabled')) ) { + die ('Unknown or disabled language'); } - $this->SetVar('lang.current_id', $this->GetVar('m_lang') ); } /** @@ -278,20 +347,21 @@ */ function VerifyThemeId() { + if ($this->Application->IsAdmin()) return; + $theme_id = $this->GetVar('m_theme'); - if ($theme_id) { - $table = $this->getUnitOption('theme', 'TableName'); - $id_field = $this->getUnitOption('theme', 'IDField'); - $sql = 'SELECT '.$id_field.' - FROM '.$table.' - WHERE Enabled = 1'; - $theme_ids = $this->Conn->GetCol($sql); + if (!$theme_id) { + $theme_id = $this->GetDefaultThemeId(); + if (!$theme_id) { + die('No Primary Theme Selected'); + } } - - if (!$theme_id || !in_array($theme_id, $theme_ids)) { - $this->SetVar('m_theme', $this->GetDefaultThemeId() ); + $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')) { + die('Unknown or disabled theme'); } - $this->SetVar('theme.current_id', $this->GetVar('m_theme') ); } function GetDefaultLanguageId() @@ -350,6 +420,11 @@ */ function RegisterDefaultClasses() { + + $this->registerClass('kTempTablesHandler', KERNEL_PATH.'/utility/temp_handler.php'); + $this->registerClass('kEventManager', KERNEL_PATH.'/event_manager.php', 'EventManager'); + $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'); @@ -359,12 +434,11 @@ $this->registerClass('Session', KERNEL_PATH.'/session/session.php'); $this->registerClass('SessionStorage', KERNEL_PATH.'/session/session.php'); - $this->registerClass('kEventManager', KERNEL_PATH.'/event_manager.php', 'EventManager'); - $this->registerClass('kUnitConfigReader', KERNEL_PATH.'/utility/unit_config_reader.php'); + $this->registerClass('Params', KERNEL_PATH.'/utility/params.php', 'kActions'); - $this->registerClass('kFormatter', KERNEL_PATH.'/utility/formatters.php'); + /*$this->registerClass('kFormatter', KERNEL_PATH.'/utility/formatters.php'); $this->registerClass('kOptionsFormatter', KERNEL_PATH.'/utility/formatters.php'); $this->registerClass('kUploadFormatter', KERNEL_PATH.'/utility/formatters.php'); $this->registerClass('kPictureFormatter', KERNEL_PATH.'/utility/formatters.php'); @@ -375,26 +449,22 @@ $this->registerClass('kCCDateFormatter', KERNEL_PATH.'/utility/formatters.php'); $this->registerClass('kUnitFormatter', KERNEL_PATH.'/utility/formatters.php'); $this->registerClass('kFilesizeFormatter', KERNEL_PATH.'/utility/formatters.php'); - $this->registerClass('kSerializedFormatter', KERNEL_PATH.'/utility/formatters.php'); + $this->registerClass('kSerializedFormatter', KERNEL_PATH.'/utility/formatters.php');*/ - $this->registerClass('kTempTablesHandler', KERNEL_PATH.'/utility/temp_handler.php'); - $event_manager =& $this->recallObject('EventManager'); - $event_manager->registerBuildEvent('kTempTablesHandler', 'OnTempHandlerBuild'); - - $this->registerClass('TemplatesCache', KERNEL_PATH.'/parser/template.php'); - $this->registerClass('Template', KERNEL_PATH.'/parser/template.php'); - $this->registerClass('TemplateParser', KERNEL_PATH.'/parser/template_parser.php'); - - $this->registerClass('kMainTagProcessor', KERNEL_PATH.'/processors/main_processor.php','m_TagProcessor'); - $this->registerClass('kMultipleFilter', KERNEL_PATH.'/utility/filters.php'); $this->registerClass('kDBList', KERNEL_PATH.'/db/dblist.php'); $this->registerClass('kDBItem', KERNEL_PATH.'/db/dbitem.php'); $this->registerClass('kDBEventHandler', KERNEL_PATH.'/db/db_event_handler.php'); - $this->registerClass('kDBTagProcessor', KERNEL_PATH.'/db/db_tag_processor.php'); $this->registerClass('kTagProcessor', KERNEL_PATH.'/processors/tag_processor.php'); + $this->registerClass('kMainTagProcessor', KERNEL_PATH.'/processors/main_processor.php','m_TagProcessor', 'kTagProcessor'); + $this->registerClass('kDBTagProcessor', KERNEL_PATH.'/db/db_tag_processor.php', null, 'kTagProcessor'); + + $this->registerClass('TemplatesCache', KERNEL_PATH.'/parser/template.php'); + $this->registerClass('Template', KERNEL_PATH.'/parser/template.php'); + $this->registerClass('TemplateParser', KERNEL_PATH.'/parser/template_parser.php',null, 'kDBTagProcessor'); + $this->registerClass('kEmailMessage', KERNEL_PATH.'/utility/email.php'); $this->registerClass('kSmtpClient', KERNEL_PATH.'/utility/smtp_client.php'); @@ -405,6 +475,12 @@ $this->registerClass('FCKeditor', FULL_PATH.'/admin/editor/cmseditor/fckeditor.php'); // need this? } + function RegisterDefaultBuildEvents() + { + $event_manager =& $this->recallObject('EventManager'); + $event_manager->registerBuildEvent('kTempTablesHandler', 'OnTempHandlerBuild'); + } + /** * Returns item's filename that corresponds id passed. If possible, then get it from cache * @@ -418,13 +494,13 @@ if ($filename === false) { $table = $this->getUnitOption($prefix, 'TableName'); $id_field = $this->getUnitOption($prefix, 'IDField'); - + if ($prefix == 'c') { if(!$id) { $this->setCache('filenames', $prefix.'_'.$id, ''); return ''; } - + // this allows to save 2 sql queries for each category $sql = 'SELECT NamedParentPath, CachedCategoryTemplate, CachedItemTemplate FROM '.$table.' @@ -444,8 +520,8 @@ } return $filename; } - - + + /** * Adds new value to cache $cache_name and identified by key $key * @@ -458,7 +534,7 @@ $cache =& $this->recallObject('Cache'); $cache->setCache($cache_name, $key, $value); } - + /** * Returns cached $key value from cache named $cache_name * @@ -480,12 +556,13 @@ function SetDefaultConstants() { safeDefine('SERVER_NAME', $_SERVER['HTTP_HOST']); + } + function SetAdminDirectory() + { $admin_dir = $this->ConfigValue('AdminDirectory'); if(!$admin_dir) $admin_dir = 'admin'; safeDefine('ADMIN_DIR', $admin_dir); - - $this->registerModuleConstants(); } /** @@ -541,14 +618,14 @@ // for permission checking in events & templates $this->LinkVar('module'); // for common configuration templates $this->LinkVar('section'); // for common configuration templates - + if ($this->GetVar('m_opener') == 'p') { $this->LinkVar('main_prefix'); // window prefix, that opened selector $this->LinkVar('dst_field'); // field to set value choosed in selector $this->LinkVar('return_template'); // template to go, when something was coosen from popup (from finalizePopup) } } - + if (!$this->RequestProcessed) $this->ProcessRequest(); $this->InitParser(); @@ -606,15 +683,15 @@ //eval("?".">".$this->HTML); echo $this->HTML; - $this->Phrases->UpdateCache(); + $this->UpdateCache(); flush(); - + if ($this->isDebugMode() && dbg_ConstOn('DBG_CACHE')) { $cache =& $this->recallObject('Cache'); $cache->printStatistics(); } - + $event_manager =& $this->recallObject('EventManager'); $event_manager->RunRegularEvents(reAFTER); @@ -661,8 +738,8 @@ */ function GetVar($name, $default = false) { - $http_query =& $this->recallObject('HTTPQuery'); - return $http_query->Get($name, $default); +// $http_query =& $this->recallObject('HTTPQuery'); + return isset($this->HttpQuery->_Params[$name]) ? $this->HttpQuery->_Params[$name] : $default; } /** @@ -673,8 +750,7 @@ */ function GetVars() { - $http_query =& $this->recallObject('HTTPQuery'); - return $http_query->GetParams(); + return $this->HttpQuery->GetParams(); } /** @@ -692,42 +768,39 @@ */ function SetVar($var,$val) { - $http_query =& $this->recallObject('HTTPQuery'); - $http_query->Set($var,$val); +// $http_query =& $this->recallObject('HTTPQuery'); + return $this->HttpQuery->Set($var,$val); } /** - * Deletes Session variable + * Deletes kHTTPQuery variable * * @param string $var + * @todo think about method name */ - function RemoveVar($var) + function DeleteVar($var) { - $session =& $this->recallObject('Session'); - return $session->RemoveVar($var); + return $this->HttpQuery->Remove($var); } /** - * Restores Session variable to it's db version + * Deletes Session variable * * @param string $var */ - function RestoreVar($var) + function RemoveVar($var) { - $session =& $this->recallObject('Session'); - return $session->RestoreVar($var); + return $this->Session->RemoveVar($var); } - + /** - * Deletes kHTTPQuery variable + * Restores Session variable to it's db version * * @param string $var - * @todo think about method name */ - function DeleteVar($var) + function RestoreVar($var) { - $http_query =& $this->recallObject('HTTPQuery'); - return $http_query->Remove($var); + return $this->Session->RestoreVar($var); } /** @@ -743,8 +816,7 @@ */ function RecallVar($var,$default=false) { - $session =& $this->recallObject('Session'); - return $session->RecallVar($var,$default); + return $this->Session->RecallVar($var,$default); } /** @@ -759,13 +831,13 @@ function StoreVar($var, $val) { $session =& $this->recallObject('Session'); - $session->StoreVar($var, $val); + $this->Session->StoreVar($var, $val); } function StoreVarDefault($var, $val) { $session =& $this->recallObject('Session'); - $session->StoreVarDefault($var, $val); + $this->Session->StoreVarDefault($var, $val); } /** @@ -871,19 +943,19 @@ 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 * @@ -909,9 +981,9 @@ if ( $this->IsAdmin() && $prefix == '') $prefix = '/admin'; if ( $this->IsAdmin() && $prefix == '_FRONT_END_') $prefix = ''; - + $index_file = $this->getIndexFile($prefix, $index_file, $params); - + $ssl = isset($params['__SSL__']) ? $params['__SSL__'] : null; if ($ssl !== null) { $session =& $this->recallObject('Session'); @@ -987,7 +1059,7 @@ return $ret; } - + /** * Returns sorted array of passed prefixes (to build url from) * @@ -997,14 +1069,14 @@ function getPassInfo($pass = 'all') { $pass = str_replace('all', trim($this->GetVar('passed'), ','), $pass); - + if (!$pass) { return Array(); } - + $pass_info = array_unique( explode(',', $pass) ); // array( prefix[.special], prefix[.special] ... sort($pass_info, SORT_STRING); // to be prefix1,prefix1.special1,prefix1.special2,prefix3.specialX - + // ensure that "m" prefix is at the beginning $main_index = array_search('m', $pass_info); if ($main_index !== false) { @@ -1013,7 +1085,7 @@ } return $pass_info; } - + function BuildEnv_NEW($t, $params, $pass = 'all', $pass_events = false) { // $session =& $this->recallObject('Session'); @@ -1059,7 +1131,7 @@ } } $ret = $this->BuildModuleEnv_NEW('m', $params, $pass_events).$ret; - + $ret = trim($ret, '/').'.html'; if($env) $params[ENV_VAR_NAME] = ltrim($env, ':'); } @@ -1087,21 +1159,21 @@ return $ret; } - + function BuildModuleEnv_NEW($prefix_special, &$params, $pass_events = false) { $event_params = Array('pass_events' => $pass_events, 'url_params' => $params); $event = new kEvent($prefix_special.':BuildEnv', $event_params); $this->HandleEvent($event); $params = $event->getEventParam('url_params'); // save back unprocessed parameters - + $ret = ''; if ($event->getEventParam('env_string')) { $ret = trim( $event->getEventParam('env_string'), '/'); } return $ret; } - + /** * Builds env part that corresponds prefix passed * @@ -1155,7 +1227,7 @@ if ($env_var) { $ret = ENV_VAR_NAME.'='; } - + $ret .= $sid.(constOn('INPORTAL_ENV') ? '-' : ':'); $encode = false; @@ -1170,7 +1242,7 @@ $env_string = ''; $category_id = isset($params['m_cat_id']) ? $params['m_cat_id'] : $this->GetVar('m_cat_id'); - + $item_id = 0; $pass_info = $this->getPassInfo($pass); if ($pass_info) { @@ -1184,7 +1256,7 @@ $env_string .= ':'.$this->BuildModuleEnv($pass_element, $params, $pass_events); } } - + if (strtolower($t) == '__default__') { // to put category & item templates into cache $filename = $this->getFilename('c', $category_id); @@ -1198,9 +1270,9 @@ $t = 'index'; } } - + $ret .= $t.':'.$this->BuildModuleEnv('m', $params, $pass_events).$env_string; - + unset($params['pass']); unset($params['opener']); unset($params['m_event']); @@ -1336,18 +1408,66 @@ if (!$user_id && $user_id != -1) $user_id = -2; $this->SetVar('u_id', $user_id); $this->StoreVar('user_id', $user_id); - + if ($this->GetVar('expired') == 1) { $user =& $this->recallObject('u'); $user->SetError('ValidateLogin', 'session_expired', 'la_text_sess_expired'); } - + if (($user_id != -2) && constOn('DBG_REQUREST_LOG') ) { $http_query =& $this->recallObject('HTTPQuery'); $http_query->writeRequestLog(DBG_REQUREST_LOG); } } + function LoadCache() { + $cache_key = $this->GetVar('t').$this->GetVar('m_theme').$this->GetVar('m_lang').$this->IsAdmin(); + $query = sprintf("SELECT PhraseList, ConfigVariables FROM %s WHERE Template = %s", + TABLE_PREFIX.'PhraseCache', + $this->Conn->Qstr(md5($cache_key))); + $res = $this->Conn->GetRow($query); + + if ($res) { + $this->Caches['PhraseList'] = $res['PhraseList'] ? explode(',', $res['PhraseList']) : array(); + + $config_ids = $res['ConfigVariables'] ? explode(',', $res['ConfigVariables']) : array(); + $config_ids = array_diff($config_ids, $this->Caches['ConfigVariables']); + } + else { + $config_ids = array(); + } + $this->Caches['ConfigVariables'] = $config_ids; + $this->ConfigCacheIds = $config_ids; + } + + 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) { + $this->ConfigHash = array_merge($this->ConfigHash, $this->Conn->GetCol( + 'SELECT VariableValue, VariableName FROM '.TABLE_PREFIX.'ConfigurationValues + WHERE VariableId IN ('.implode(',', $this->Caches['ConfigVariables']).')', 'VariableName')); + } + } + /** * Returns configuration option value by name * @@ -1356,9 +1476,25 @@ */ function ConfigValue($name) { - return getArrayValue($this->ConfigHash, $name); + $res = isset($this->ConfigHash[$name]) ? $this->ConfigHash[$name] : false; + if ($res !== false) return $res; + + $res = $this->Conn->GetRow('SELECT VariableId, VariableValue FROM '.TABLE_PREFIX.'ConfigurationValues WHERE VariableName = '.$this->Conn->qstr($name)); + if ($res) { + $this->ConfigHash[$name] = $res['VariableValue']; + $this->ConfigCacheIds[] = $res['VariableId']; + return $res['VariableValue']; + } + return false; } + function UpdateConfigCache() + { + if ($this->ConfigCacheIds) { + + } + } + /** * Allows to process any type of event * @@ -1371,8 +1507,12 @@ if ( isset($params) ) { $event = new kEvent( $params, $specificParams ); } - $event_manager =& $this->recallObject('EventManager'); - $event_manager->HandleEvent($event); + + if (!isset($this->EventManager)) { + $this->EventManager =& $this->recallObject('EventManager'); + } + + $this->EventManager->HandleEvent($event); } /** @@ -1448,8 +1588,24 @@ */ function &recallObject($name,$pseudo_class=null,$event_params=Array()) { + $result =& $this->Factory->getObject($name, $pseudo_class, $event_params); + return $result; + } + + /** + * Returns object using Variable number of params, + * all params starting with 4th are passed to object consturctor + * + * @param string $name + * @param string $pseudo_class + * @param Array $event_params + * @return Object + * @author Alex + */ + function &recallObjectP($name,$pseudo_class=null,$event_params=Array()) + { $func_args = func_get_args(); - $result =& ref_call_user_func_array( Array(&$this->Factory, 'getObject'), $func_args ); + $result =& ref_call_user_func_array( Array(&$this->Factory, 'getObjectP'), $func_args ); return $result; } @@ -1464,7 +1620,7 @@ $result =& $this->recallObject($prefix.'_TagProcessor'); return $result; } - + /** * Checks if object with prefix passes was already created in factory * @@ -1516,7 +1672,7 @@ */ function isDebugMode($check_debugger = true) { - $debug_mode = constOn('DEBUG_MODE'); + $debug_mode = defined('DEBUG_MODE') && DEBUG_MODE; if($check_debugger) { $debug_mode = $debug_mode && is_object($this->Debugger); @@ -1547,12 +1703,12 @@ // we want to create https link from http mode // we want to create https link from https mode // conditions: ($ssl || PROTOCOL == 'https://') && $this->ConfigValue('UseModRewriteWithSSL') - + // case #2,#3: // we want to create http link from https mode // we want to create http link from http mode // conditions: !$ssl && (PROTOCOL == 'https://' || PROTOCOL == 'http://') - + $allow_rewriting = (!$ssl && (PROTOCOL == 'https://' || PROTOCOL == 'http://')) // always allow mod_rewrite for http || // or allow rewriting for redirect TO httpS or when already in httpS @@ -1573,8 +1729,10 @@ */ function getUnitOption($prefix, $option, $default = false) { - $unit_config_reader =& $this->recallObject('kUnitConfigReader'); - return $unit_config_reader->getUnitOption($prefix, $option, $default); + /*if (!isset($this->UnitConfigReader)) { + $this->UnitConfigReader =& $this->recallObject('kUnitConfigReader'); + }*/ + return $this->UnitConfigReader->getUnitOption($prefix, $option, $default); } /** @@ -1588,8 +1746,8 @@ */ function setUnitOption($prefix, $option, $value) { - $unit_config_reader =& $this->recallObject('kUnitConfigReader'); - return $unit_config_reader->setUnitOption($prefix,$option,$value); +// $unit_config_reader =& $this->recallObject('kUnitConfigReader'); + return $this->UnitConfigReader->setUnitOption($prefix,$option,$value); } /** @@ -1602,8 +1760,8 @@ */ function getUnitOptions($prefix) { - $unit_config_reader =& $this->recallObject('kUnitConfigReader'); - return $unit_config_reader->getUnitOptions($prefix); +// $unit_config_reader =& $this->recallObject('kUnitConfigReader'); + return $this->UnitConfigReader->getUnitOptions($prefix); } /** @@ -1614,8 +1772,10 @@ */ function prefixRegistred($prefix) { - $unit_config_reader =& $this->recallObject('kUnitConfigReader'); - return $unit_config_reader->prefixRegistred($prefix); + /*if (!isset($this->UnitConfigReader)) { + $this->UnitConfigReader =& $this->recallObject('kUnitConfigReader'); + }*/ + return $this->UnitConfigReader->prefixRegistred($prefix); } /** @@ -1790,7 +1950,7 @@ { $user =& $this->recallObject('u'); $user_id = $user->GetID(); - + $ret = $user_id > 0; if ($this->IsAdmin() && ($user_id == -1)) { $ret = true; @@ -1810,18 +1970,18 @@ { if ($this->GetVar('u_id') == -1) { // "root" is allowed anywhere - return $name == 'SYSTEM_ACCESS.READONLY' ? 0 : 1; - } - - if ($type == 1) { - // "system" permission are always checked per "Home" category (ID = 0) - $cat_id = 0; - } - + return $name == 'SYSTEM_ACCESS.READONLY' ? 0 : 1; + } + + if ($type == 1) { + // "system" permission are always checked per "Home" category (ID = 0) + $cat_id = 0; + } + if (!isset($cat_id)) { $cat_id = $this->GetVar('m_cat_id'); } - + if ($cat_id == 0) { $cat_hierarchy = Array(0); } @@ -1874,7 +2034,7 @@ { return $this->InitDone && (count($this->ModuleInfo) > 0); } - + /** * Allows to determine if module is installed & enabled * @@ -1884,15 +2044,55 @@ function isModuleEnabled($module_name) { return $this->findModule('Name', $module_name); - + } - + function reportError($class, $method) { $this->Debugger->appendTrace(); trigger_error('depricated method '.$class.'->'.$method.'(...)', E_USER_ERROR); } + + /** + * Get temp table name + * + * @param string $table + * @return string + */ + function GetTempName($table) + { + return TABLE_PREFIX.'ses_'.$this->GetSID().'_edit_'.$table; + } + + function GetTempTablePrefix() + { + return TABLE_PREFIX.'ses_'.$this->GetSID().'_edit_'; + } + + function IsTempTable($table) + { + return strpos($table, TABLE_PREFIX.'ses_'.$this->GetSID().'_edit_') !== false; + } + + /** + * Return live table name based on temp table name + * + * @param string $temp_table + * @return string + */ + function GetLiveName($temp_table) + { + if( preg_match('/'.TABLE_PREFIX.'ses_'.$this->GetSID().'_edit_(.*)/',$temp_table,$rets) ) + { + return $rets[1]; + } + else + { + return $temp_table; + } + } + } ?> \ No newline at end of file