Index: branches/5.0.x/core/kernel/application.php
===================================================================
diff -u -r12871 -r12877
--- branches/5.0.x/core/kernel/application.php (.../application.php) (revision 12871)
+++ branches/5.0.x/core/kernel/application.php (.../application.php) (revision 12877)
@@ -1,6 +1,6 @@
StoreVar('UserGroups', $user_groups, true); // true for optional
}
+ $this->LoadStructureTemplateMapping();
$this->HttpQuery->AfterInit();
$this->Session->ValidateExpired();
@@ -1334,18 +1342,48 @@
* @param string $t Template path
* @var string $prefix index.php prefix - could be blank, 'admin'
*/
- function HREF($t, $prefix='', $params=null, $index_file=null)
+ function HREF($t, $prefix = '', $params = null, $index_file = null)
{
+ static $theme_id = null;
+
+ if (!isset($theme_id)) {
+ $theme_id = $this->GetVar('m_theme');
+ }
+
if (!$t) {
- $t = $this->GetVar('t'); // moved from kMainTagProcessor->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 = '';
@@ -1876,29 +1914,31 @@
function Redirect($t='', $params=null, $prefix='', $index_file=null)
{
$js_redirect = getArrayValue($params, 'js_redirect');
- if (preg_match("/external:(.*)/", $t, $rets)) {
- $location = $rets[1];
+
+ if ($t == '' || $t === true) {
+ $t = $this->GetVar('t');
}
- else {
- if ($t == '' || $t === true) $t = $this->GetVar('t');
- // pass prefixes and special from previous url
- if( isset($params['js_redirect']) ) unset($params['js_redirect']);
+ // pass prefixes and special from previous url
+ if (array_key_exists('js_redirect', $params)) {
+ unset($params['js_redirect']);
+ }
- if (!isset($params['pass'])) $params['pass'] = 'all';
- if ($this->GetVar('ajax') == 'yes' && $t == $this->GetVar('t')) {
- // redirects to the same template as current
- $params['ajax'] = 'yes';
- }
- $params['__URLENCODE__'] = 1;
- $location = $this->HREF($t, $prefix, $params, $index_file);
- //echo " location : $location
";
+ if (!array_key_exists('pass', $params)) {
+ $params['pass'] = 'all';
}
+ if ($this->GetVar('ajax') == 'yes' && $t == $this->GetVar('t')) {
+ // redirects to the same template as current
+ $params['ajax'] = 'yes';
+ }
+
+ $params['__URLENCODE__'] = 1;
+ $location = $this->HREF($t, $prefix, $params, $index_file);
+
$a_location = $location;
$location = "Location: $location";
-
if ($this->isDebugMode() && constOn('DBG_REDIRECT')) {
$this->Debugger->appendTrace();
echo "Debug output above!!! Proceed to redirect: $a_location
";
@@ -2036,6 +2076,20 @@
$this->ConfigCacheIds = $config_ids;
}
+ function LoadStructureTemplateMapping()
+ {
+ // get template mapping
+ $sql = 'SELECT Data
+ FROM ' . TABLE_PREFIX . 'Cache
+ WHERE VarName = "template_mapping"';
+ $template_mapping = $this->Conn->GetOne($sql);
+
+ if (!$this->isAdmin && $template_mapping) {
+ // template mappings only for Front-End
+ $this->structureTemplateMapping = unserialize($template_mapping);
+ }
+ }
+
function UpdateCache()
{
$update = false;