Index: trunk/kernel/include/parse.php
===================================================================
diff -u -r720 -r817
--- trunk/kernel/include/parse.php (.../parse.php) (revision 720)
+++ trunk/kernel/include/parse.php (.../parse.php) (revision 817)
@@ -1,80 +1,89 @@
SetRawText($text);
- if(strlen($text))
- $this->parse();
- }
+ function clsHtmlTag($text=null)
+ {
+ $this->SetRawText($text);
+ if(strlen($text)) $this->parse();
+ }
- function Clear()
- {
- $this->parsed = FALSE;
- $this->rawtext = NULL;
- $this->prefix = "";
- $this->name = "";
- $this->attributes = NULL;
- $this->inner_html = "";
- }
+ function Clear()
+ {
+ $this->parsed = FALSE;
+ $this->rawtext = NULL;
+ $this->prefix = "";
+ $this->name = "";
+ $this->attributes = NULL;
+ $this->inner_html = "";
+ }
- function ValidTag()
- {
- return (strlen($this->prefix) && strlen($this->name));
- }
+ function ValidTag()
+ {
+ return (strlen($this->prefix) && strlen($this->name));
+ }
- function SetRawText($text)
- {
- $this->Clear();
- if($text != NULL)
- $text = trim($text);
- $this->rawtext = $text;
- }
+ function SetRawText($text)
+ {
+ $this->Clear();
+ if($text != NULL) $text = trim($text);
+ $this->rawtext = $text;
+ }
- function GetAttributeByName($attr)
- {
- if(is_array($this->attributes))
- {
- $attr = strtolower($attr);
- if( array_key_exists($attr,$this->attributes))
- {
- return $this->attributes[$attr];
- }
- else
- return FALSE;
- }
- else
- return FALSE;
- }
+ function GetAttributeByName($attr)
+ {
+ if(is_array($this->attributes))
+ {
+ $attr = strtolower($attr);
+ if( array_key_exists($attr,$this->attributes))
+ {
+ return $this->attributes[$attr];
+ }
+ else
+ {
+ return FALSE;
+ }
+ }
+ else
+ {
+ return FALSE;
+ }
+ }
- function SetAttributeByName($attr,$value)
- {
- if(!is_array($this->attributes))
- $this->attributes = array();
- $this->attributes[$attr] = $value;
- }
+ function SetAttributeByName($attr,$value)
+ {
+ if(!is_array($this->attributes))
+ {
+ $this->attributes = array();
+ }
+ $this->attributes[$attr] = $value;
+ }
function GetAttributeByIndex($index)
{
- if(is_array($this->attributes))
- {
- if($index < count($this->attributes))
- {
- return $this->attributes[$index];
- }
- else
- return FALSE;
- }
- else
- return FALSE;
+ if(is_array($this->attributes))
+ {
+ if($index < count($this->attributes))
+ {
+ return $this->attributes[$index];
+ }
+ else
+ {
+ return FALSE;
+ }
+ }
+ else
+ {
+ return FALSE;
+ }
}
+
function ParseAttributes($attributes)
{
unset($output);
@@ -189,51 +198,53 @@
return($output);
}
- function parse()
- {
- global $objSession;
-
- $html = $this->rawtext;
- $html = substr($html,1,strlen($html)-2);
- if(substr($html,strlen($html)-1,1)=="/")
- {
- $html = substr($html,0,strlen($html)-1);
- }
+ function parse()
+ {
+ global $objSession;
- $tagparts = explode(" ",$html,2);
- $tagname = $tagparts[0];
- $attribs = array();
- if(count($tagparts)>0)
- $attribs = $this->ParseAttributes( isset($tagparts[1]) ? $tagparts[1] : '');
+ $html = $this->rawtext;
+ $html = substr($html,1,strlen($html)-2);
+ if(substr($html,strlen($html)-1,1)=="/")
+ {
+ $html = substr($html,0,strlen($html)-1);
+ }
- if(is_object($objSession) && is_array($attribs))
- {
- $referer = $objSession->GetVariable("Template_Referer");
- foreach($attribs as $key=>$value)
- {
- if($value=="_referer_")
- $attribs[$key] = $referer;
- }
- }
- $name = explode(":",$tagname);
- $this->prefix = strtolower($name[0]);
- $this->name = strtolower($name[1]);
- if(is_array($attribs))
- {
- foreach($attribs as $key=>$value)
- {
- if(!strlen($value))
- {
- $attribs[$key]=1;
- }
- }
- $this->attributes = $attribs;
- }
- else
- $this->attributes = array();
- $this->parsed=TRUE;
- }
+ $tagparts = explode(" ",$html,2);
+ $tagname = $tagparts[0];
+ $attribs = array();
+ if(count($tagparts)>0)
+ $attribs = $this->ParseAttributes( isset($tagparts[1]) ? $tagparts[1] : '');
+ if(is_object($objSession) && is_array($attribs))
+ {
+ $referer = $objSession->GetVariable("Template_Referer");
+ foreach($attribs as $key=>$value)
+ {
+ if($value=="_referer_")
+ $attribs[$key] = $referer;
+ }
+ }
+ $name = explode(":",$tagname);
+ $this->prefix = strtolower($name[0]);
+ $this->name = strtolower($name[1]);
+ if(is_array($attribs))
+ {
+ foreach($attribs as $key=>$value)
+ {
+ if(!strlen($value))
+ {
+ $attribs[$key]=1;
+ }
+ }
+ $this->attributes = $attribs;
+ }
+ else
+ {
+ $this->attributes = array();
+ }
+ $this->parsed=TRUE;
+ }
+
function Execute()
{
$func = $this->name;
@@ -247,7 +258,13 @@
{
if(function_exists($func))
{
- $ret = @$func($this->attributes);
+ if( IsDebugMode() && !$GLOBALS['FrontEnd'] )
+ {
+ global $debugger;
+ $debugger->dumpVars($this->name, $this->attributes);
+ $debugger->appendTrace();
+ }
+ $ret = @$func($this->attributes);
}
else
{
@@ -389,132 +406,126 @@
class clsTemplateList
{
- var $templates;
- var $root_dir;
- var $ErrorStr;
- var $ErrorNo;
- var $stack;
- var $SkipIncludes = 0;
+ var $templates;
+ var $root_dir;
+ var $ErrorStr;
+ var $ErrorNo;
+ var $stack;
+ var $SkipIncludes = 0;
- function clsTemplateList($root_dir)
- {
- $this->templates = array();
- $this->root_dir = $root_dir;
- $this->ErrorStr = "";
- $this->ErrorNo = 0;
- $this->SkipIncludes = 0;
- $this->stack = array();
- }
+ function clsTemplateList($root_dir)
+ {
+ $this->templates = array();
+ $this->root_dir = $root_dir;
+ $this->ErrorStr = "";
+ $this->ErrorNo = 0;
+ $this->SkipIncludes = 0;
+ $this->stack = array();
+ }
- function InStack($template)
- {
- if(in_array($template,$this->stack))
- {
- return TRUE;
- }
- else
- return FALSE;
- }
+ function InStack($template)
+ {
+ return in_array($template,$this->stack) ? true : false;
+ }
- function GetTemplate($name,$SupressError=FALSE)
- {
- if(!strlen($name))
- {
- $ret = FALSE;
- if(!$SupressError)
- {
- $this->ErrorNo = -2;
- $this->ErrorStr=language("lu_template_error").":".language("lu_no_template_error");
- }
- }
- else
- {
- $ret = FALSE;
- foreach($this->templates as $n => $t)
- {
- if($n == $name)
- {
- $ret=$t;
- break;
- }
- }
- if(!is_object($ret))
- {
- $ret = new clsTemplate($name);
- if($ret->LoadFile($this->root_dir,$SupressError))
- {
- $this->templates[$name]=$ret;
- }
- else
- {
- if( IsDebugMode() )
- {
- echo 'Template '.$name.' not found
';
-
- }
- if(!$SupressError)
- {
- $this->ErrorNo = -1;
- $this->ErrorStr = language("lu_template_error").":".language($ret->error).":"."'$name'";
- LogEntry($this->ErrorStr);
- }
- }
- }
- }
- return $ret;
- }
+ function GetTemplate($name,$SupressError=FALSE)
+ {
+ if(!strlen($name))
+ {
+ $ret = FALSE;
+ if(!$SupressError)
+ {
+ $this->ErrorNo = -2;
+ $this->ErrorStr=language("lu_template_error").":".language("lu_no_template_error");
+ }
+ }
+ else
+ {
+ $ret = FALSE;
+ foreach($this->templates as $n => $t)
+ {
+ if($n == $name)
+ {
+ $ret=$t;
+ break;
+ }
+ }
+ if(!is_object($ret))
+ {
+ $ret = new clsTemplate($name);
+ if($ret->LoadFile($this->root_dir,$SupressError))
+ {
+ $this->templates[$name]=$ret;
+ }
+ else
+ {
+ if( IsDebugMode() )
+ {
+ $GLOBALS['debugger']->appendHTML('Warning: Template '.$name.' not found');
+ }
+ if(!$SupressError)
+ {
+ $this->ErrorNo = -1;
+ $this->ErrorStr = language("lu_template_error").":".language($ret->error).":"."'$name'";
+ LogEntry($this->ErrorStr);
+ }
+ }
+ }
+ }
+ return $ret;
+ }
- function GetTemplateCache($template,$SupressError=FALSE)
- {
- global $CurrentTheme, $pathtoroot;
+ function GetTemplateCache($template,$SupressError=FALSE)
+ {
+ global $CurrentTheme, $pathtoroot;
$ret = '';
- if( $CurrentTheme->Get("CacheTimeout") > 0)
- {
- $id = $CurrentTheme->GetTemplateId($template);
- if($id)
- {
- $exp = isset($CurrentTheme->ParseCacheDate[$id]) ? $CurrentTheme->ParseCacheDate[$id] : false;
- if($exp)
- {
- //echo "$template Cache expires: ".date("m-d-Y h:m s",$exp)."
\n";
- if( $exp > time() )
- {
- /* look for a cache file */
- $t = new clsTemplate($template);
- $dir = $CurrentTheme->ThemeDirectory();
- if( $t->LoadFile($dir."/_cache/",$SupressError) ) $ret = $t->source;
- }
- }
- }
- }
- return $ret;
- }
+ if( $CurrentTheme->Get("CacheTimeout") > 0)
+ {
+ $id = $CurrentTheme->GetTemplateId($template);
+ if($id)
+ {
+ $exp = isset($CurrentTheme->ParseCacheDate[$id]) ? $CurrentTheme->ParseCacheDate[$id] : false;
+ if($exp)
+ {
+ //echo "$template Cache expires: ".date("m-d-Y h:m s",$exp)."
\n";
+ if( $exp > time() )
+ {
+ /* look for a cache file */
+ $t = new clsTemplate($template);
+ $dir = $CurrentTheme->ThemeDirectory();
+ if( $t->LoadFile($dir."/_cache/",$SupressError) ) $ret = $t->source;
+ }
+ }
+ }
+ }
+ return $ret;
+ }
- function SaveTemplateCache($objTemplate)
- {
- global $CurrentTheme, $objThemes, $pathtoroot;
+ 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)
- {
- $TemplateId = $CurrentTheme->GetTemplateId($objTemplate->name);
- if($TemplateId)
- {
- if(isset($CurrentTheme->ParseCacheDate[$TemplateId]))
- {
- //echo "Writing Template ".$objTemplate->name."
\n";
- $interval = $CurrentTheme->ParseCacheTimeout[$TemplateId];
- $CurrentTheme->UpdateFileCacheData($TemplateId,time()+$interval);
- $dir = $CurrentTheme->ThemeDirectory()."/_cache/";
- $objTemplate->WriteFile($dir);
- }
- }
- }
-
- }
+ if($CurrentTheme->Get("CacheTimeout")>0)
+ {
+ $TemplateId = $CurrentTheme->GetTemplateId($objTemplate->name);
+ if($TemplateId)
+ {
+ if(isset($CurrentTheme->ParseCacheDate[$TemplateId]))
+ {
+ //echo "Writing Template ".$objTemplate->name."
\n";
+ $interval = $CurrentTheme->ParseCacheTimeout[$TemplateId];
+ $CurrentTheme->UpdateFileCacheData($TemplateId,time()+$interval);
+ $dir = $CurrentTheme->ThemeDirectory()."/_cache/";
+ $objTemplate->WriteFile($dir);
+ }
+ }
+ }
+ }
+
function IncludeTemplate($tag, $SupressError=FALSE)
{
global $LogLevel, $objSession,$objLanguages;
@@ -636,68 +647,68 @@
/* attributes = $tag->attributes;
- $el->parsed=1;
- $t = $tag->attributes["_template"];
- if(!strlen($t))
- $t = $var_list["t"];
-
- $el->name = "perm_include";
- $tpath = GetModuleArray("template");
+ global $var_list;
- if(!strlen( $tag->GetAttributeByName('_modules') ))
- {
- $mods = array_keys($tpath);
- }
- else
- $mods = explode(",",$tag->attributes["_modules"]);
-
- foreach($mods as $m)
- {
- if($t==$var_list["t"] && !strlen($tpath[$m]))
- continue;
- $el->attributes = $tag->attributes;
- $el->attributes["_template"] = $tpath[$m].$t;
- $el->attributes["_module"] = $m;
-
- if(strlen( $tag->GetAttributeByName('_nodatatemplate') ))
- {
- $el->attributes["_nodatatemplate"] = $tpath[$m].$tag->attributes["_nodatatemplate"];
- }
+ $o = "";
+ $el = new clsHtmlTag();
+ $el->attributes = $tag->attributes;
+ $el->parsed=1;
+ $t = $tag->attributes["_template"];
+ if(!strlen($t))
+ $t = $var_list["t"];
- //print_pre($el);
- $o .= $this->IncludeTemplate($el,true);
- }
- if(!strlen($o) && strlen($tag->attributes["_nodatamaintemplate"]))
- $o = $this->ParseTemplate($tag->attributes["_nodatamaintemplate"]);
- return $o;
+ $el->name = "perm_include";
+ $tpath = GetModuleArray("template");
+
+ if(!strlen( $tag->GetAttributeByName('_modules') ))
+ {
+ $mods = array_keys($tpath);
+ }
+ else
+ $mods = explode(",",$tag->attributes["_modules"]);
+
+ foreach($mods as $m)
+ {
+ if($t==$var_list["t"] && !strlen($tpath[$m]))
+ continue;
+ $el->attributes = $tag->attributes;
+ $el->attributes["_template"] = $tpath[$m].$t;
+ $el->attributes["_module"] = $m;
+
+ if(strlen( $tag->GetAttributeByName('_nodatatemplate') ))
+ {
+ $el->attributes["_nodatatemplate"] = $tpath[$m].$tag->attributes["_nodatatemplate"];
+ }
+
+ //print_pre($el);
+ $o .= $this->IncludeTemplate($el,true);
+ }
+ if(!strlen($o) && strlen($tag->attributes["_nodatamaintemplate"]))
+ $o = $this->ParseTemplate($tag->attributes["_nodatamaintemplate"]);
+ return $o;
}
function ParseTag($raw)
{
- $tag = new clsHtmlTag($raw);
- $res = "";
- switch($tag->name)
- {
- case "lang_include":
- case "include":
- case "perm_include":
- $res = $this->IncludeTemplate($tag);
- break;
- case "mod_include":
- $res = $this->ModuleInclude($tag);
- break;
- default:
- //print_pre($tag);
- $res = $tag->Execute();
- break;
- }
- unset($tag);
- return $res;
+ $tag = new clsHtmlTag($raw);
+ $res = "";
+ switch($tag->name)
+ {
+ case "lang_include":
+ case "include":
+ case "perm_include":
+ $res = $this->IncludeTemplate($tag);
+ break;
+ case "mod_include":
+ $res = $this->ModuleInclude($tag);
+ break;
+ default:
+ //print_pre($tag);
+ $res = $tag->Execute();
+ break;
+ }
+ unset($tag);
+ return $res;
}
function ParseTemplateText($text)