Index: branches/5.1.x/core/kernel/application.php =================================================================== diff -u -r12127 -r12657 --- branches/5.1.x/core/kernel/application.php (.../application.php) (revision 12127) +++ branches/5.1.x/core/kernel/application.php (.../application.php) (revision 12657) @@ -1,6 +1,6 @@ +* This class is a Facade for any other class which needs to deal with Kernel4 framework.
* The class incapsulates the main run-cycle of the script, provide access to all other objects in the framework.
*
-* The class is a singleton, which means that there could be only one instance of KernelApplication in the script.
-* This could be guranteed by NOT calling the class constuctor directly, but rather calling KernelApplication::Instance() method, +* The class is a singleton, which means that there could be only one instance of kApplication in the script.
+* This could be guranteed by NOT calling the class constuctor directly, but rather calling kApplication::Instance() method, * which returns an instance of the application. The method gurantees that it will return exactly the same instance for any call.
* See singleton pattern by GOF. * @package kernel4 */ +defined('FULL_PATH') or die('restricted access!'); + class kApplication { /** @@ -41,15 +43,7 @@ */ var $Parser; - /** - * New Parser (Experimental) - * - * @var NParser - */ - var $NParser; - - /** * Holds parser output buffer * @access private * @var string @@ -98,6 +92,13 @@ var $ReplacementTemplates = Array (); /** + * Mod-Rewrite listeners used during url building and parsing + * + * @var Array + */ + var $RewriteListeners = Array (); + + /** * Reference to debugger * * @var Debugger @@ -185,7 +186,7 @@ /** * Holds current NParser tag while parsing, can be used in error messages to display template file and line * - * @var unknown_type + * @var _BlockTag */ var $CurrentNTag = null; @@ -284,7 +285,7 @@ ob_start(); // collect any output from method (other then tags) into buffer } - if(defined('DEBUG_MODE') && $this->isDebugMode() && constOn('DBG_PROFILE_MEMORY')) { + if (defined('DEBUG_MODE') && $this->isDebugMode() && constOn('DBG_PROFILE_MEMORY')) { $this->Debugger->appendMemoryUsage('Application before Init:'); } if (!$this->isDebugMode() && !constOn('DBG_ZEND_PRESENT')) { @@ -311,15 +312,15 @@ $this->RegisterDefaultBuildEvents(); $this->SetDefaultConstants(); - if( defined('DEBUG_MODE') && $this->isDebugMode() ) { + if (defined('DEBUG_MODE') && $this->isDebugMode()) { $this->Debugger->appendTimestamp('Before UnitConfigReader'); } $this->UnitConfigReader =& $this->recallObject('kUnitConfigReader'); $this->UnitConfigReader->scanModules(MODULES_PATH); $this->registerModuleConstants(); - if( defined('DEBUG_MODE') && $this->isDebugMode() ) { + if (defined('DEBUG_MODE') && $this->isDebugMode()) { $this->Debugger->appendTimestamp('After UnitConfigReader'); } @@ -330,13 +331,13 @@ $this->HttpQuery =& $this->recallObject('HTTPQuery'); - if( defined('DEBUG_MODE') && $this->isDebugMode() ) { + if (defined('DEBUG_MODE') && $this->isDebugMode()) { $this->Debugger->appendTimestamp('Processed HTTPQuery initial'); } $this->Session =& $this->recallObject('Session'); - if( defined('DEBUG_MODE') && $this->isDebugMode() ) { + if (defined('DEBUG_MODE') && $this->isDebugMode()) { $this->Debugger->appendTimestamp('Processed Session'); } @@ -347,14 +348,14 @@ } $this->Session->SetField('GroupList', $user_groups); - $this->StoreVar('UserGroups', $user_groups); + $this->StoreVar('UserGroups', $user_groups, true); // true for optional } $this->HttpQuery->AfterInit(); $this->Session->ValidateExpired(); - if( defined('DEBUG_MODE') && $this->isDebugMode() ) { + if (defined('DEBUG_MODE') && $this->isDebugMode()) { $this->Debugger->appendTimestamp('Processed HTTPQuery AfterInit'); } @@ -363,17 +364,16 @@ $this->Phrases->Init('phrases'); - if( defined('DEBUG_MODE') && $this->isDebugMode() ) { + if (defined('DEBUG_MODE') && $this->isDebugMode()) { $this->Debugger->appendTimestamp('Loaded cache and phrases'); } $this->UnitConfigReader->AfterConfigRead(); - if( defined('DEBUG_MODE') && $this->isDebugMode() ) { + if (defined('DEBUG_MODE') && $this->isDebugMode()) { $this->Debugger->appendTimestamp('Processed AfterConfigRead'); } - /*// 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 @@ -382,7 +382,9 @@ }*/ if ($this->GetVar('m_cat_id') === false) $this->SetVar('m_cat_id', 0); - if( !$this->RecallVar('curr_iso') ) $this->StoreVar('curr_iso', $this->GetPrimaryCurrency() ); + if (!$this->RecallVar('curr_iso')) { + $this->StoreVar('curr_iso', $this->GetPrimaryCurrency(), true); // true for optional + } $this->SetVar('visits_id', $this->RecallVar('visit_id') ); @@ -394,7 +396,7 @@ $this->ValidateLogin(); - if( defined('DEBUG_MODE') && $this->isDebugMode() ) { + if (defined('DEBUG_MODE') && $this->isDebugMode()) { $this->Debugger->profileFinish('kernel4_startup'); } @@ -600,65 +602,48 @@ */ 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('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'); - $this->registerClass('kHelper', KERNEL_PATH.'/kbase.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('kHTTPQuery', KERNEL_PATH . '/utility/http_query.php', 'HTTPQuery', 'Params'); - $this->registerClass('kCache', KERNEL_PATH.'/utility/cache.php', 'Cache', Array('Params')); - $this->registerClass('kHTTPQuery', KERNEL_PATH.'/utility/http_query.php', 'HTTPQuery', Array('Params') ); + $this->registerClass('kHelper', KERNEL_PATH . '/kbase.php'); + $this->registerClass('kMultipleFilter', KERNEL_PATH . '/utility/filters.php'); - $this->registerClass('Session', KERNEL_PATH.'/session/session.php'); - $this->registerClass('SessionStorage', KERNEL_PATH.'/session/session.php'); + $this->registerClass('Session', KERNEL_PATH . '/session/session.php'); + $this->registerClass('SessionStorage', KERNEL_PATH . '/session/session.php'); + $this->registerClass('InpSession', KERNEL_PATH . '/session/inp_session.php', 'Session'); + $this->registerClass('InpSessionStorage', KERNEL_PATH . '/session/inp_session.php', 'SessionStorage'); + $this->registerClass('kTagProcessor', KERNEL_PATH . '/processors/tag_processor.php'); + $this->registerClass('kMainTagProcessor', KERNEL_PATH . '/processors/main_processor.php','m_TagProcessor', 'kTagProcessor'); + $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', null, 'kTagProcessor'); + $this->registerClass('kCatDBItem', KERNEL_PATH . '/db/cat_dbitem.php'); + $this->registerClass('kCatDBList', KERNEL_PATH . '/db/cat_dblist.php'); + $this->registerClass('kCatDBEventHandler', KERNEL_PATH . '/db/cat_event_handler.php'); + $this->registerClass('kCatDBTagProcessor', KERNEL_PATH . '/db/cat_tag_processor.php'); - $this->registerClass('Params', KERNEL_PATH.'/utility/params.php', 'kActions'); + $this->registerClass('NParser', KERNEL_PATH . '/nparser/nparser.php'); + $this->registerClass('TemplatesCache', KERNEL_PATH . '/nparser/template_cache.php', null, Array ('kHelper', 'kDBTagProcessor')); - $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('kEmailSendingHelper', KERNEL_PATH . '/utility/email_send.php', 'EmailSender', 'kHelper'); + $this->registerClass('kSocket', KERNEL_PATH . '/utility/socket.php', 'Socket'); - $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',null, 'kDBTagProcessor'); - $this->registerClass('Template', KERNEL_PATH.'/parser/template.php'); - $this->registerClass('TemplateParser', KERNEL_PATH.'/parser/template_parser.php',null, 'kDBTagProcessor'); - $this->registerClass('NParser', KERNEL_PATH.'/nparser/nparser.php'); - - $this->registerClass('kEmailSendingHelper', KERNEL_PATH.'/utility/email_send.php', 'EmailSender', Array('kHelper')); - $this->registerClass('kSocket', KERNEL_PATH.'/utility/socket.php', 'Socket'); - - if (file_exists(MODULES_PATH.'/in-commerce/units/currencies/currency_rates.php')) { - $this->registerClass('kCurrencyRates', 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'); } - $this->registerClass('FCKeditor', FULL_PATH.'/admin/editor/cmseditor/fckeditor.php'); // need this? - - /* Moved from MyApplication */ - - $this->registerClass('Inp1Parser',KERNEL_PATH.'/../units/general/inp1_parser.php','Inp1Parser'); - - $this->registerClass('InpSession',KERNEL_PATH.'/../units/general/inp_ses_storage.php','Session'); - $this->registerClass('InpSessionStorage',KERNEL_PATH.'/../units/general/inp_ses_storage.php','SessionStorage'); - - $this->registerClass('kCatDBItem',KERNEL_PATH.'/../units/general/cat_dbitem.php'); - $this->registerClass('kCatDBItemExportHelper',KERNEL_PATH.'/../units/general/cat_dbitem_export.php', 'CatItemExportHelper'); - $this->registerClass('kCatDBList',KERNEL_PATH.'/../units/general/cat_dblist.php'); - $this->registerClass('kCatDBEventHandler',KERNEL_PATH.'/../units/general/cat_event_handler.php'); - $this->registerClass('kCatDBTagProcessor',KERNEL_PATH.'/../units/general/cat_tag_processor.php'); - - // Do not move to config - this helper is used before configs are read - $this->registerClass('kModulesHelper', KERNEL_PATH.'/../units/general/helpers/modules.php', 'ModulesHelper'); - - /* End moved */ - + // do not move to config - this helper is used before configs are read + $this->registerClass('kModulesHelper', KERNEL_PATH . '/../units/helpers/modules_helper.php', 'ModulesHelper'); } function RegisterDefaultBuildEvents() @@ -700,19 +685,30 @@ $this->setCache('category_tree', $id, $category_data['TreeLeft'] . ';' . $category_data['TreeRight']); } else { - $resource_id = $this->Conn->GetOne('SELECT ResourceId FROM '.$table.' WHERE '.$id_field.' = '.$this->Conn->qstr($id)); - if (is_null($category_id)) $category_id = $this->GetVar('m_cat_id'); - $sql = 'SELECT Filename FROM '.TABLE_PREFIX.'CategoryItems WHERE ItemResourceId = '.$resource_id.' AND CategoryId = '.$category_id; + $sql = 'SELECT ResourceId + FROM ' . $table . ' + WHERE ' . $id_field . ' = ' . $this->Conn->qstr($id); + $resource_id = $this->Conn->GetOne($sql); + + if (is_null($category_id)) { + $category_id = $this->GetVar('m_cat_id'); + } + + $sql = 'SELECT Filename + FROM ' . TABLE_PREFIX . 'CategoryItems + WHERE (ItemResourceId = ' . $resource_id . ') AND (CategoryId = ' . (int)$category_id . ')'; $filename = $this->Conn->GetOne($sql); /*if (!$filename) { - $sql = 'SELECT Filename FROM '.TABLE_PREFIX.'CategoryItems WHERE ItemResourceId = '.$resource_id.' AND PrimaryCat = 1'; + $sql = 'SELECT Filename + FROM ' . TABLE_PREFIX . 'CategoryItems + WHERE ItemResourceId = ' . $resource_id . ' AND PrimaryCat = 1'; $filename = $this->Conn->GetOne($sql); - }*/ + } - /*$sql = 'SELECT Filename - FROM '.$table.' - WHERE '.$id_field.' = '.$this->Conn->qstr($id); + $sql = 'SELECT Filename + FROM ' . $table . ' + WHERE ' . $id_field . ' = ' . $this->Conn->qstr($id); $filename = $this->Conn->GetOne($sql);*/ } $this->setCache('filenames', $prefix.'_'.$id, $filename); @@ -784,7 +780,7 @@ $event_manager =& $this->recallObject('EventManager'); /* @var $event_manager kEventManager */ - if($this->isDebugMode() && constOn('DBG_SHOW_HTTPQUERY')) { + if (defined('DEBUG_MODE') && $this->isDebugMode() && constOn('DBG_SHOW_HTTPQUERY')) { $this->Debugger->appendHTML('HTTPQuery:'); $this->Debugger->dumpVars($this->HttpQuery->_Params); } @@ -804,7 +800,7 @@ */ function Run() { - if($this->isDebugMode() && constOn('DBG_PROFILE_MEMORY')) { + if (defined('DEBUG_MODE') && $this->isDebugMode() && constOn('DBG_PROFILE_MEMORY')) { $this->Debugger->appendMemoryUsage('Application before Run:'); } @@ -836,7 +832,8 @@ if ($perm_helper->CheckUserPermission($user, 'CATEGORY.MODIFY', 0, 0)) { // user can edit cms blocks $editing_mode = $this->GetVar('editing_mode'); - define('EDITING_MODE', $editing_mode ? $editing_mode : EDITING_MODE_CMS); + define('EDITING_MODE', $editing_mode ? $editing_mode : EDITING_MODE_BROWSE); + $this->Phrases->setPhraseEditing(); } } @@ -853,48 +850,31 @@ $t = ltrim($cms_handler->GetDesignTemplate(), '/'); - if ($this->isDebugMode()) { + if (defined('DEBUG_MODE') && $this->isDebugMode()) { $this->Debugger->appendHTML('Design Template: ' . $t . '; CategoryID: ' . $this->GetVar('m_cat_id')); } } /*else { $cms_handler->SetCatByTemplate(); }*/ - if($this->isDebugMode() && constOn('DBG_PROFILE_MEMORY')) { + if (defined('DEBUG_MODE') && $this->isDebugMode() && constOn('DBG_PROFILE_MEMORY')) { $this->Debugger->appendMemoryUsage('Application before Parsing:'); } - if (defined('NPARSER') && 'NPARSER') { - $this->HTML = $this->NParser->Run( $t ); - } - else { - $this->HTML = $this->Parser->ParseTemplate( $t ); - } + $this->HTML = $this->Parser->Run($t); - if ($this->isDebugMode() && constOn('DBG_PROFILE_MEMORY')) { + if (defined('DEBUG_MODE') && $this->isDebugMode() && constOn('DBG_PROFILE_MEMORY')) { $this->Debugger->appendMemoryUsage('Application after Parsing:'); } } function InitParser($theme_name = false) { - if (defined('NPARSER') && 'NPARSER') { - if( !is_object($this->NParser) ) { - $this->NParser =& $this->recallObject('NParser'); - $this->TemplatesCache =& $this->recallObject('TemplatesCache'); - - // can be removed in future -// $this->Parser =& $this->recallObject('TemplateParser'); - $this->Parser =& $this->NParser; - } + if( !is_object($this->Parser) ) { + $this->Parser =& $this->recallObject('NParser'); + $this->TemplatesCache =& $this->recallObject('TemplatesCache'); } - else { - if( !is_object($this->Parser) ) { - $this->Parser =& $this->recallObject('TemplateParser'); - $this->TemplatesCache =& $this->recallObject('TemplatesCache'); - } - } $this->TemplatesCache->forceThemeName = $theme_name; } @@ -909,13 +889,12 @@ function Done() { $this->HandleEvent( new kEvent('adm:OnBeforeShutdown') ); - if ($this->isDebugMode() && constOn('DBG_PROFILE_MEMORY')) { + + if (defined('DEBUG_MODE') && $this->isDebugMode() && constOn('DBG_PROFILE_MEMORY')) { $this->Debugger->appendMemoryUsage('Application before Done:'); } - //eval("?".">".$this->HTML); - - if ($this->isDebugMode()) { + if (defined('DEBUG_MODE') && $this->isDebugMode()) { $this->EventManager->RunRegularEvents(reAFTER); $this->Session->SaveData(); @@ -966,7 +945,7 @@ $sql = 'SELECT * FROM ' . TABLE_PREFIX . 'StatisticsCapture - WHERE TemplateName = "' . $this->GetVar('t') . '"'; + WHERE TemplateName = ' . $this->Conn->qstr( $this->GetVar('t') ); $data = $this->Conn->GetRow($sql); if ($data) { @@ -1247,34 +1226,11 @@ $this->cache[$name] = $tpl; } - /* Seems to be not used anywhere... /Kostja - - function SetTemplateBody($title,$body) - { - $templates_cache =& $this->recallObject('TemplatesCache'); - $templates_cache->SetTemplateBody($title,$body); - }*/ - - function ProcessTag($tag_data) - { - $a_tag = new Tag($tag_data,$this->Parser); - return $a_tag->DoProcessTag(); - } - function ProcessParsedTag($prefix, $tag, $params) { - if (defined('NPARSER') && NPARSER) { - $p = $this->Parser->GetProcessor($prefix); - return $p->ProcessParsedTag($tag, $params, $prefix); - } + $processor = $this->Parser->GetProcessor($prefix); - $a_tag = new Tag('',$this->Parser); - $a_tag->Tag = $tag; - $tmp=$this->Application->processPrefix($prefix); - $a_tag->Processor = $tmp['prefix']; - $a_tag->Special = $tmp['special']; - $a_tag->NamedParams = $params; - return $a_tag->DoProcessTag(); + return $processor->ProcessParsedTag($tag, $params, $prefix); } /** @@ -1292,18 +1248,32 @@ /** * Allows to parse given block name or include template * - * @param Array $params Parameters to pass to block/template. Reserved parameter "name" used to specify block/template name. + * @param Array $params Parameters to pass to block. Reserved parameter "name" used to specify block name. * @param Array $pass_params Forces to pass current parser params to this block/template. Use with cauntion, because you can accidently pass "block_no_data" parameter. * @param bool $as_template * @return string */ function ParseBlock($params, $pass_params = 0, $as_template = false) { - if (substr($params['name'], 0, 5) == 'html:') return substr($params['name'], 6); + if (substr($params['name'], 0, 5) == 'html:') { + return substr($params['name'], 6); + } + return $this->Parser->ParseBlock($params, $pass_params, $as_template); } /** + * Allows to include template with a given name and given parameters + * + * @param Array $params Parameters to pass to template. Reserved parameter "name" used to specify template name. + * @return string + */ + function IncludeTemplate($params) + { + return $this->Parser->IncludeTemplate($params, isset($block_params['is_silent']) ? 1 : 0); + } + + /** * 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 @@ -1468,15 +1438,28 @@ // $params = array_merge_recursive2($this->getPassThroughVariables($params), $params); $params = array_merge($this->getPassThroughVariables($params), $params); - if ($force_rewrite || ($this->RewriteURLs($ssl) && !$no_rewrite)) - { + 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(); + + 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 - { + 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; @@ -1549,7 +1532,7 @@ foreach ($pass_info as $prefix) { list($prefix_only) = explode('.', $prefix, 1); - $sorted[$prefix] = $this->getUnitOption($prefix_only, 'PassPriority', 0); + $sorted[$prefix] = $this->getUnitOption($prefix_only, 'RewritePriority', 0); } arsort($sorted); @@ -1575,8 +1558,8 @@ $env = ''; $encode = false; - if (isset($params['__URLENCODE__'])) - { + + if (isset($params['__URLENCODE__'])) { $encode = $params['__URLENCODE__']; unset($params['__URLENCODE__']); } @@ -1585,59 +1568,104 @@ unset($params['__SSL__']); } - $m_only = true; + $catalog_item_found = false; $pass_info = $this->getPassInfo($pass); + if ($pass_info) { - if ($pass_info[0] == 'm') array_shift($pass_info); - $params['t'] = $t; - foreach($pass_info as $pass_index => $pass_element) - { - list($prefix) = explode('.', $pass_element); - $require_rewrite = $this->findModule('Var', $prefix) && $this->getUnitOption($prefix, 'CatalogItem'); - if ($require_rewrite) { + 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 = getArrayValue($pass_info, $pass_index + 1); + $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; + if ($prefix . '.' == $next_prefix) { + continue; + } } - $a = $this->BuildModuleEnv_NEW($pass_element, $params, $pass_events); - if ($a) { - $ret .= '/'.$a; - $m_only = false; + + // 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); + else { + $env .= ':' . $this->BuildModuleEnv($pass_element, $params, $pass_events); } } - if (!$m_only || preg_match('/c\.[-\d]*/', implode(',', $pass_info))) { - $params['pass_category'] = 1; + if ($catalog_item_found || preg_match('/c\.[-\d]*/', implode(',', $pass_info))) { + // "c" prefix is present -> keep category + $params['pass_category'] = true; } - $ret = $this->BuildModuleEnv_NEW('m', $params, $pass_events).$ret; - $cat_processed = isset($params['category_processed']) && $params['category_processed']; - if ($cat_processed) { - unset($params['category_processed']); - } - if (!$m_only || !$cat_processed || !defined('EXP_DIR_URLS')) { - $ret = trim($ret, '/').'.html'; + $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 ($catalog_item_found || !$cat_processed || !defined('EXP_DIR_URLS')) { + // this catalog item detail page OR there is no category given + $ret = trim($ret, '/') . '.html'; } else { - $ret .= '/'; + // url ends with "/" and not with ".html" + $ret = trim($ret, '/') . '/'; } -// $ret = trim($ret, '/').'/'; - if($env) $params[ENV_VAR_NAME] = ltrim($env, ':'); + if ($env) { + $params[ENV_VAR_NAME] = ltrim($env, ':'); + } } unset($params['pass'], $params['opener'], $params['m_event']); - if ($force_admin) $params['admin'] = 1; + if ($force_admin) { + $params['admin'] = 1; + } - if( getArrayValue($params,'escape') ) - { + if (array_key_exists('escape', $params) && $params['escape']) { $ret = addslashes($ret); unset($params['escape']); } @@ -1646,30 +1674,31 @@ $params_str = ''; $join_string = $encode ? '&' : '&'; - foreach ($params as $param => $value) - { - $params_str .= $join_string.$param.'='.$value; + + foreach ($params as $param => $value) { + $params_str .= $join_string . $param . '=' . $value; } - $ret .= preg_replace('/^'.$join_string.'(.*)/', '?\\1', $params_str); + 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, $pass_events = false) + function BuildModuleEnv_NEW($prefix_special, &$params, $keep_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 + list ($prefix) = explode('.', $prefix_special); - $ret = ''; - if ($event->getEventParam('env_string')) { - $ret = trim( $event->getEventParam('env_string'), '/'); - } + $url_parts = Array (); + $listener = $this->RewriteListeners[$prefix]; + + $ret = $listener[0]->$listener[1](REWRITE_MODE_BUILD, $prefix_special, $params, $url_parts, $keep_events); + return $ret; } @@ -1727,7 +1756,7 @@ $ret = ENV_VAR_NAME.'='; } - $ret .= $sid.(constOn('INPORTAL_ENV') ? '-' : ':'); + $ret .= $sid . '-'; // SID-TEMPLATE $encode = false; if (isset($params['__URLENCODE__'])) { @@ -1891,9 +1920,9 @@ exit; } - function Phrase($label) + function Phrase($label, $allow_editing = true) { - return $this->Phrases->GetPhrase($label); + return $this->Phrases->GetPhrase($label, $allow_editing); } /** @@ -1931,7 +1960,7 @@ $this->SetVar('u_id', $user_id); } - $this->StoreVar('user_id', $user_id); + $this->StoreVar('user_id', $user_id, $user_id == -2); // storing Guest user_id (-2) is optional if ($this->GetVar('expired') == 1) { // this parameter is set only from admin @@ -2169,8 +2198,9 @@ */ function &recallTagProcessor($prefix) { - $this->InitParser(); // because kDBTagProcesor is in TemplateParser dependencies - $result =& $this->recallObject($prefix.'_TagProcessor'); + $this->InitParser(); // because kDBTagProcesor is in NParser dependencies + $result =& $this->recallObject($prefix . '_TagProcessor'); + return $result; } @@ -2420,7 +2450,6 @@ $ignore_fatal_errors = defined('DBG_IGNORE_FATAL_ERRORS') && DBG_IGNORE_FATAL_ERRORS; if (($errno == E_USER_ERROR) && !$ignore_fatal_errors) { - header('HTTP/1.0 500 Script Fatal Error'); echo ('
Fatal Error: '."$errstr in $errfile on line $errline".'
'); @@ -2520,7 +2549,7 @@ * @param array $send_params associative array of direct send params, possible keys: to_email, to_name, from_email, from_name, message, message_text * @return unknown */ - function &EmailEventAdmin($email_event_name, $to_user_id = -1, $send_params = false) + function &EmailEventAdmin($email_event_name, $to_user_id = null, $send_params = false) { $event =& $this->EmailEvent($email_event_name, 1, $to_user_id, $send_params); return $event; @@ -2534,7 +2563,7 @@ * @param array $send_params associative array of direct send params, possible keys: to_email, to_name, from_email, from_name, message, message_text * @return unknown */ - function &EmailEventUser($email_event_name, $to_user_id = -1, $send_params = false) + function &EmailEventUser($email_event_name, $to_user_id = null, $send_params = false) { $event =& $this->EmailEvent($email_event_name, 0, $to_user_id, $send_params); return $event; @@ -2599,9 +2628,18 @@ */ function setVisitField($field, $value) { - $visit =& $this->recallObject('visits'); - $visit->SetDBField($field, $value); - $visit->Update(); + if ($this->IsAdmin() || !$this->ConfigValue('UseVisitorTracking')) { + // admin logins are not registred in visits list + return ; + } + + $visit =& $this->recallObject('visits', null, Array ('raise_warnings' => 0)); + /* @var $visit kDBItem */ + + if ($visit->isLoaded()) { + $visit->SetDBField($field, $value); + $visit->Update(); + } } /** @@ -2759,25 +2797,29 @@ function getUserGroups($user_id) { - switch($user_id) - { + switch ($user_id) { case -1: $user_groups = $this->ConfigValue('User_LoggedInGroup'); break; + case -2: - $user_groups = $this->ConfigValue('User_LoggedInGroup'); - $user_groups .= ','.$this->ConfigValue('User_GuestGroup'); + $user_groups = $this->ConfigValue('User_LoggedInGroup') . ',' . $this->ConfigValue('User_GuestGroup'); break; + default: - $sql = 'SELECT GroupId FROM '.TABLE_PREFIX.'UserGroup WHERE PortalUserId = '.$user_id; + $sql = 'SELECT GroupId + FROM ' . TABLE_PREFIX . 'UserGroup + WHERE PortalUserId = ' . (int)$user_id; $res = $this->Conn->GetCol($sql); + $user_groups = Array( $this->ConfigValue('User_LoggedInGroup') ); - if(is_array($res)) - { + if ($res) { $user_groups = array_merge($user_groups, $res); } + $user_groups = implode(',', $user_groups); } + return $user_groups; } @@ -2887,6 +2929,5 @@ return false; } -} -?> \ No newline at end of file +} \ No newline at end of file