Index: trunk/kernel/include/parse.php
===================================================================
diff -u -r3428 -r3576
--- trunk/kernel/include/parse.php (.../parse.php) (revision 3428)
+++ trunk/kernel/include/parse.php (.../parse.php) (revision 3576)
@@ -424,245 +424,229 @@
function clsTemplateList($root_dir)
{
- $this->templates = array();
+ $this->templates = Array();
$this->root_dir = $root_dir;
- $this->ErrorStr = "";
+ $this->ErrorStr = '';
$this->ErrorNo = 0;
$this->SkipIncludes = 0;
- $this->stack = array();
+ $this->stack = Array();
}
function InStack($template)
{
- return in_array($template,$this->stack) ? true : false;
+ return in_array($template, $this->stack) ? true : false;
}
- function GetTemplate($name,$SupressError=FALSE, $tbody=null)
+ function GetTemplate($name, $SupressError = false, $tbody = null)
{
- if(!strlen($name))
- {
- $ret = FALSE;
- if(!$SupressError)
- {
+ if (!$name) {
+ $ret = false;
+ if (!$SupressError) {
$this->ErrorNo = -2;
- $this->ErrorStr=language("lu_template_error").":".language("lu_no_template_error");
+ $this->ErrorStr = language('lu_template_error').':'.language('lu_no_template_error');
}
}
- else
- {
- $ret = FALSE;
+ else {
+ $ret = false;
if ( !isset($tbody) ) { //Kernel4 fix
$ret = isset($this->templates[$name]) ? $this->templates[$name] : false;
- // this was original:
- /*foreach($this->templates as $n => $t)
- {
- if($n == $name)
- {
- $ret = $t;
- break;
- }
- }*/
}
- if(!is_object($ret))
- {
+
+ if (!is_object($ret)) {
$ret = new clsTemplate($name);
- if($ret->LoadFile($this->root_dir, $SupressError, $tbody))
- {
- $this->templates[$name]=$ret;
+ if ($ret->LoadFile($this->root_dir, $SupressError, $tbody)) {
+ $this->templates[$name] = $ret;
}
- else
- {
- if( IsDebugMode() )
- {
+ else {
+ if ( IsDebugMode() ) {
$GLOBALS['debugger']->appendHTML('Warning: Template '.$name.' not found');
}
- if(!$SupressError)
- {
+
+ if (!$SupressError) {
$this->ErrorNo = -1;
- $this->ErrorStr = language("lu_template_error").":".language($ret->error).":"."'$name'";
+ $this->ErrorStr = language('lu_template_error').':'.language($ret->error).':'.'"'.$name.'"';
LogEntry($this->ErrorStr);
}
}
}
}
+
return $ret;
}
- function GetTemplateCache($template,$SupressError=FALSE)
+ function GetTemplateCache($template, $SupressError = false)
{
global $CurrentTheme, $pathtoroot;
+
$ret = '';
- if(!is_object($CurrentTheme)) {
- $CurrentTheme = $objThemes->GetItem($m_var_list["theme"]);
+ if (!is_object($CurrentTheme)) {
+ $CurrentTheme = $objThemes->GetItem($m_var_list['theme']);
}
- if( $CurrentTheme->Get("CacheTimeout") > 0)
- {
+
+ if ($CurrentTheme->Get('CacheTimeout') > 0) {
$id = $CurrentTheme->GetTemplateId($template);
- if($id)
- {
+
+ if ($id) {
$exp = isset($CurrentTheme->ParseCacheDate[$id]) ? $CurrentTheme->ParseCacheDate[$id] : false;
- if($exp)
- {
+
+ if($exp) {
//echo "$template Cache expires: ".adodb_date("m-d-Y h:m s",$exp)."
\n";
- if( $exp > adodb_mktime() )
- {
+ if ($exp > adodb_mktime()) {
/* look for a cache file */
$t = new clsTemplate($template);
$dir = $CurrentTheme->ThemeDirectory();
- if( $t->LoadFile($dir."/_cache/",$SupressError) ) $ret = $t->source;
+ if( $t->LoadFile($dir.'/_cache/', $SupressError) ) {
+ $ret = $t->source;
+ }
}
}
}
}
+
return $ret;
}
function SaveTemplateCache($objTemplate)
{
global $CurrentTheme, $objThemes, $pathtoroot;
- if(!is_object($CurrentTheme))
- $CurrentTheme = $objThemes->GetItem($m_var_list["theme"]);
+ if (!is_object($CurrentTheme)) {
+ $CurrentTheme = $objThemes->GetItem($m_var_list['theme']);
+ }
- if($CurrentTheme->Get("CacheTimeout")>0)
- {
+ if ($CurrentTheme->Get('CacheTimeout') > 0) {
$TemplateId = $CurrentTheme->GetTemplateId($objTemplate->name);
- if($TemplateId)
- {
- if(isset($CurrentTheme->ParseCacheDate[$TemplateId]))
- {
+
+ if($TemplateId) {
+ if (isset($CurrentTheme->ParseCacheDate[$TemplateId])) {
//echo "Writing Template ".$objTemplate->name."
\n";
$interval = $CurrentTheme->ParseCacheTimeout[$TemplateId];
- $CurrentTheme->UpdateFileCacheData($TemplateId,adodb_mktime()+$interval);
- $dir = $CurrentTheme->ThemeDirectory()."/_cache/";
+ $CurrentTheme->UpdateFileCacheData($TemplateId, adodb_mktime() + $interval);
+ $dir = $CurrentTheme->ThemeDirectory().'/_cache/';
$objTemplate->WriteFile($dir);
}
}
}
}
- function IncludeTemplate($tag, $SupressError=FALSE)
- {
- global $LogLevel, $objSession,$objLanguages, $var_list;
+ function IncludeTemplate($tag, $SupressError = false)
+ {
+ global $LogLevel, $objSession, $objLanguages, $var_list;
- $t = '';
- $ret = '';
- $SupressError = ($SupressError || $tag->GetAttributeByName("_supresserror"));
- switch($tag->name)
- {
- case 'perm_include':
- $perms = $tag->GetAttributeByName('_permission');
- if(strlen($perms))
- {
- $plist = explode(',',$perms);
- $value=0;
- $CheckSys = $tag->GetAttributeByName('_system');
- for($p=0;$pGetAttributeByName('_supresserror'));
+ switch ($tag->name) {
+ case 'perm_include':
+ $perms = $tag->GetAttributeByName('_permission');
+ if ($perms) {
+ $plist = explode(',', $perms);
+ $value = 0;
+ $CheckSys = $tag->GetAttributeByName('_system');
+ for ($p = 0; $p < count($plist); $p++) {
+ if ($plist[$p] == 'login') {
+ $var_list['dest'] = $var_list['t'];
+ }
+
+ $perm_name = trim($plist[$p]);
+ if ($objSession->HasCatPermission($perm_name)) {
+ $value = 1;
+ break;
+ }
+ elseif ($CheckSys && $objSession->HasSystemPermission($perm_name)) {
+ $value = 1;
+ break;
+ }
+ }
+ $t = $tag->GetAttributeByName( $value ? '_template' : '_noaccess');
+
+ }
+ else {
+ $module = $tag->GetAttributeByName('_module');
+ if ($module) {
+ $t = $tag->GetAttributeByName( ModuleEnabled($module) ? '_template' : '_noaccess' );
+ }
+ }
+ break;
- if($objSession->HasCatPermission(trim($plist[$p])))
- {
- $value = 1;
- break;
+ case 'lang_include':
+ $lang = $tag->GetAttributeByName('_language');
+ if ($lang) {
+ $LangId = $objSession->Get('Language');
+ $l = $objLanguages->GetItem($LangId);
+ if (strtolower($lang) == strtolower($l->Get('PackName'))) {
+ $t = $tag->GetAttributeByName('_template');
}
- else
+ }
+ break;
+
+ case 'include':
+ $t = $tag->GetAttributeByName('_template');
+ break;
+ }
+
+ LogEntry("Parsing $t\n");
+ $LogLevel++;
+
+ if ($t) {
+ if (!$this->InStack($t)) {
+ $parser_params = GetVar('parser_params'); // backup parser params from include we are currentry processing
+
+ $ret = $this->GetTemplateCache($t, $SupressError);
+ if (!$ret) {
+ SetVar('parser_params', $tag->attributes); // set new parser params from new include statement
+
+ $req = $tag->GetAttributeByName("_dataexists");
+ if($req)
{
- if($CheckSys)
+ global $content_set;
+ $content_set=1;
+ $temp = $this->ParseTemplate($t,0,0,$SupressError);
+ if($content_set)
{
- if($objSession->HasSystemPermission(trim($plist[$p])))
+ $ret = $temp;
+ }
+ else
+ {
+ $t_nodata = $tag->GetAttributeByName("_nodatatemplate");
+ if(strlen($t_nodata))
{
- $value = 1;
- break;
+ $nodata_tag = new clsHtmlTag();
+ $nodata = $tag;
+ $nodata->attributes = $tag->attributes;
+ $nodata->SetAttributeByName("_template",$t_nodata);
+ $nodata->SetAttributeByName("_nodatatemplate","");
+ $nodata->SetAttributeByName("_dataexists","");
+
+ $ret = $this->IncludeTemplate($nodata,$SupressError);
}
+ else
+ $ret = "";
}
}
- }
- $t = $tag->GetAttributeByName( $value ? '_template' : '_noaccess');
+ else {
+ $ret = $this->ParseTemplate($t,0,0,$SupressError);
+ }
- }
- else
- {
- $module = $tag->GetAttributeByName('_module');
- if(strlen($module))
- {
- $t = $tag->GetAttributeByName( ModuleEnabled($module) ? '_template' : '_noaccess' );
+ SetVar('parser_params', $parser_params); // restore parser params to backuped ones
}
}
- break;
+ else {
+ $ret = '';
+ }
+ }
+
+ $LogLevel--;
+ if ($LogLevel < 0) {
+ $LogLevel = 0;
+ }
+
+ LogEntry("Finished Parsing $t\n");
+ return $ret;
+ }
- case "lang_include":
- $lang = $tag->GetAttributeByName("_language");
- if(strlen($lang))
- {
- $LangId = $objSession->Get("Language");
- $l = $objLanguages->GetItem($LangId);
- if(strtolower($lang)==strtolower($l->Get("PackName")))
- {
- $t = $tag->GetAttributeByName("_template");
- }
- }
- break;
- case 'include':
- $t = $tag->GetAttributeByName("_template");
- break;
- }
-
- LogEntry("Parsing $t\n");
- $LogLevel++;
-
- if($t)
- {
- if(!$this->InStack($t))
- {
- //return $this->ParseTemplate($t);
- //if(!$tag->GetAttributeByName("_nocache"));
- $ret = $this->GetTemplateCache($t,$SupressError);
- if(!strlen($ret))
- {
- $req = $tag->GetAttributeByName("_dataexists");
- if($req)
- {
- global $content_set;
- $content_set=1;
- $temp = $this->ParseTemplate($t,0,0,$SupressError);
- if($content_set)
- {
- $ret = $temp;
- }
- else
- {
- $t_nodata = $tag->GetAttributeByName("_nodatatemplate");
- if(strlen($t_nodata))
- {
- $nodata_tag = new clsHtmlTag();
- $nodata = $tag;
- $nodata->attributes = $tag->attributes;
- $nodata->SetAttributeByName("_template",$t_nodata);
- $nodata->SetAttributeByName("_nodatatemplate","");
- $nodata->SetAttributeByName("_dataexists","");
- $ret = $this->IncludeTemplate($nodata,$SupressError);
- }
- else
- $ret = "";
- }
- }
- else
- $ret = $this->ParseTemplate($t,0,0,$SupressError);
- }
- }
- else
- $ret = "";
- }
- $LogLevel--;
- if($LogLevel<0)
- $LogLevel=0;
- LogEntry("Finished Parsing $t\n");
- return $ret;
- }
-
/* attributes = $tag->attributes;
$el->attributes["_template"] = $tpath[$m].$t;
$el->attributes["_module"] = $m;