Index: branches/unlabeled/unlabeled-1.115.2/core/kernel/application.php =================================================================== diff -u -N -r4278 -r4377 --- branches/unlabeled/unlabeled-1.115.2/core/kernel/application.php (.../application.php) (revision 4278) +++ branches/unlabeled/unlabeled-1.115.2/core/kernel/application.php (.../application.php) (revision 4377) @@ -411,6 +411,11 @@ $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.' @@ -925,6 +930,28 @@ return $ret; } + + /** + * Returns sorted array of passed prefixes (to build url from) + * + * @param string $pass + * @return Array + */ + function getPassInfo($pass = 'all') + { + $pass = str_replace('all', trim($this->GetVar('passed'), ','), $pass); + + $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 removed + $main_index = array_search('m', $pass_info); + if ($main_index !== false) { + unset($pass_info[$main_index]); + } + return $pass_info; + } + function BuildEnv_NEW($t, $params, $pass = 'all', $pass_events = false) { // $session =& $this->recallObject('Session'); @@ -946,20 +973,8 @@ unset($params['__SSL__']); } - $pass = str_replace('all', trim($this->GetVar('passed'), ','), $pass); - - if(strlen($pass) > 0) - { - $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 always first - $main_index = array_search('m', $pass_info); - if($main_index !== false) - { - unset($pass_info[$main_index]); - } - + $pass_info = $this->getPassInfo($pass); + if ($pass_info) { $params['t'] = $t; foreach($pass_info as $pass_index => $pass_element) { @@ -1066,18 +1081,19 @@ return $ret; } - function BuildEnv($t, $params, $pass='all', $pass_events=false, $env_var=true) + function BuildEnv($t, $params, $pass='all', $pass_events = false, $env_var = true) { $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(); + if (getArrayValue($params,'admin') == 1) $sid = $this->GetSID(); $ret = ''; if ($env_var) { $ret = ENV_VAR_NAME.'='; } - $ret .= constOn('INPORTAL_ENV') ? $sid.'-'.$t : $sid.':'.$t; + + $ret .= $sid.(constOn('INPORTAL_ENV') ? '-' : ':'); $encode = false; if (isset($params['__URLENCODE__'])) { @@ -1089,16 +1105,38 @@ unset($params['__SSL__']); } - $pass = trim( str_replace('all', $this->GetVar('passed'), $pass), ','); - - if(strlen($pass) > 0) - { - $pass_info = array_unique( explode(',',$pass) ); // array( prefix[.special], prefix[.special] ... - foreach($pass_info as $pass_element) - { - $ret .= ':'.$this->BuildModuleEnv($pass_element, $params, $pass_events); + $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) { + 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__') { + // to put category & item templates into cache + $filename = $this->getFilename('c', $category_id); + if ($item_id) { + $t = $this->getCache('item_templates', $category_id); + } + elseif ($category_id) { + $t = $this->getCache('category_templates', $category_id); + } + else { + $t = 'index'; + } + } + + $ret .= $t.':'.$this->BuildModuleEnv('m', $params, $pass_events).$env_string; + unset($params['pass']); unset($params['opener']); unset($params['m_event']);