Page MenuHomeIn-Portal Phabricator

in-portal
No OneTemporary

File Metadata

Created
Sat, Feb 1, 10:48 PM

in-portal

Index: trunk/kernel/include/parse.php
===================================================================
--- trunk/kernel/include/parse.php (revision 492)
+++ trunk/kernel/include/parse.php (revision 493)
@@ -1,977 +1,971 @@
<?php
class clsHtmlTag
{
var $rawtext;
var $parsed;
var $prefix;
var $name;
var $attributes;
var $inner_html;
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 ValidTag()
{
return (strlen($this->prefix) && strlen($this->name));
}
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 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;
}
function ParseAttributes($attributes)
{
unset($output);
$attribute = "";
$attributes = str_replace("\\>",">",$attributes);
$attributes = str_replace("\\<","<",$attributes);
$attributes = str_replace("\\\\","\\",$attributes);
while(strpos($attributes,"=")>0)
{
$pos = strpos($attributes,"=");
$attribute = trim(substr($attributes,0,$pos));
$attributes = trim(substr($attributes,$pos+1));
$pos2 = strpos($attributes,"\"");
$pos3 = strpos($attributes,"'");
if(!($pos3===false) and !($pos2===false) and ($pos3<$pos2)) $pos2 = $pos3;
if(!($pos3===false) and ($pos2===false) and (($pos3<$pos) or ($pos==0))) $pos2 = $pos3;
if(!($pos2===false) and (($pos2<$pos) or ($pos==0)))
{
if (substr($attributes,0,1) == "\"")
{
$pos = strpos($attributes,"\"",1);
$val = substr($attributes,1,$pos-1);
}
elseif (substr($attributes,0,1) == "'")
{
$pos = strpos($attributes,"'",1);
$val = substr($attributes,1,$pos-1);
}
else
{
$pos1 = strpos($attributes,"=",1);
$val = substr($attributes,0,$pos1);
$pos1a = strrpos($val," ");
$pos = $pos1-(strlen($val)-$pos1a);
$val = substr($val,0,$pos1a);
}
while (strpos($attribute," ")>0)
{
$pos1 = strpos($attribute," ");
$attr1 = substr($attribute,0,$pos1);
$output[$attr1] = null;
$attribute = trim(substr($attribute,$pos1+1));
}
$output[strtolower($attribute)] = $val;
$attributes = trim(substr($attributes,$pos+1));
}
elseif ($pos>0)
{
if (strpos($attributes,"=")>0)
{
$pos = strpos($attributes,"=");
$val = substr($attributes,0,$pos);
}
else
{
$val = $attributes;
}
$pos2 = strrpos($val," ");
if($pos2>0)
{
$len = strlen($val);
$val = substr($val,0,$pos2);
$attributes = trim(substr($attributes,($pos-$len)+$pos2));
}
else
{
$len = strlen($val);
$attributes = trim(substr($attributes,$len));
}
while (strpos($attribute," ")>0)
{
$pos1 = strpos($attribute," ");
$attr1 = substr($attribute,0,$pos1);
$output[$attr1] = null;
$attribute = trim(substr($attribute,$pos1+1));
}
$output[strtolower($attribute)] = $val;
}
else
{
while (strpos($attribute," ")>0)
{
$pos1 = strpos($attribute," ");
$attr1 = substr($attribute,0,$pos1);
$output[$attr1] = null;
$attribute = trim(substr($attribute,$pos1+1));
}
$output[strtolower($attribute)] = $attributes;
}
}
if(strlen(trim($attributes))>0)
{
while (strpos($attribute," ")>0)
{
$pos1 = strpos($attribute," ");
$attr1 = substr($attribute,0,$pos1);
$output[$attr1] = null;
$attribute = trim(substr($attribute,$pos1+1));
}
$output[strtolower($attributes)] = null;
}
if (isset($output))
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);
}
$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;
$override = "_".$func;
if( function_exists($override) )
{
$ret = @$override($this->attributes);
}
else
{
if(function_exists($func))
{
$ret = @$func($this->attributes);
}
else
{
//$ret = "{Unknown Tag:" .$this->name."}";
}
}
return $ret;
}
}
class clsTemplate
{
var $source;
var $name;
var $out;
var $error;
function clsTemplate($template=NULL)
{
$this->name=$template;
$this->source=NULL;
$this->out = NULL;
$this->error = "";
}
function LoadByFileName($file,$SupressError=FALSE)
{
if(file_exists($file))
{
$fp = fopen ($file, "r");
if($fp)
{
$this->source = fread($fp, filesize ($file));
$this->source = trim($this->source);
fclose($fp);
return TRUE;
}
else
{
if(!$SupressError)
$this->error = "lu_read_error";
return FALSE;
}
}
else
{
if(!$SupressError)
$this->error = "lu_missing_error";
return FALSE;
}
}
function HasExtension()
{
$t = strtolower($this->name);
if(strlen($t))
{
return (substr($t,-4)==".tpl");
}
else
return false;
}
function TemplateFilename($template_root)
{
if(!$this->HasExtension())
{
$filename = $template_root.$this->name.".tpl";
}
else
$filename = $template_root.$this->name;
return $filename;
}
function LoadFile($template_root="",$SupressError=FALSE)
{
$filename = $this->TemplateFilename($template_root);
if(file_exists($filename))
{
//echo "Loading $filename from Filesystem<br>\n";
$fp = @fopen ($filename, "r");
if($fp)
{
$this->source = fread($fp, filesize ($filename));
$this->source = trim($this->source);
fclose($fp);
return TRUE;
}
else
{
if(!$SupressError)
$this->error = "lu_read_error";
return FALSE;
}
}
else
{
if(!$SupressError)
$this->error = "lu_missing_error";
return FALSE;
}
}
function WriteFile($template_root="")
{
$filename = $this->TemplateFilename($template_root);
$pos = strrpos($this->name,"/");
if(!is_dir(substr($template_root,0,-1)))
@mkdir(substr($tempalate_root0,-1));
if($pos>0)
$path=$template_root.substr($this->name,0,$pos);
if(!is_dir($path))
{
@mkdir($path);
}
if(strlen($this->out))
{
$fp = @fopen($filename, "w");
if($fp)
{
fwrite($fp,$this->out);
fclose($fp);
return TRUE;
}
else
return FALSE;
}
else
return TRUE;
}
}
class clsTemplateList
{
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 InStack($template)
{
if(in_array($template,$this->stack))
{
return TRUE;
}
else
return 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(!$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;
$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)."<br>\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;
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."<br>\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;
-
+
+ $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;$p<count($plist);$p++)
- {
- if($objSession->HasCatPermission(trim($plist[$p])))
- {
- $value = 1;
- break;
- }
- else
- {
- if($CheckSys)
- {
- if($objSession->HasSystemPermission(trim($plist[$p])))
- {
- $value = 1;
- break;
- }
- }
- }
- }
- if($value)
- {
- $t = $tag->GetAttributeByName("_template");
- }
- else
- $t = $tag->GetAttributeByName("_noaccess");
- }
- else
- {
- $module = $tag->GetAttributeByName("_module");
- if(strlen($module))
- {
- if(ModuleEnabled($module))
- {
- $t = $tag->GetAttributeByName("_template");
- }
- else
- $t = $tag->GetAttributeByName("_noaccess");
- }
- }
- break;
- 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")))
+ case 'perm_include':
+ $perms = $tag->GetAttributeByName('_permission');
+ if(strlen($perms))
+ {
+ $plist = explode(',',$perms);
+ $value=0;
+ $CheckSys = $tag->GetAttributeByName('_system');
+ for($p=0;$p<count($plist);$p++)
+ {
+ if($objSession->HasCatPermission(trim($plist[$p])))
+ {
+ $value = 1;
+ break;
+ }
+ else
+ {
+ if($CheckSys)
+ {
+ if($objSession->HasSystemPermission(trim($plist[$p])))
+ {
+ $value = 1;
+ break;
+ }
+ }
+ }
+ }
+ $t = $tag->GetAttributeByName( $value ? '_template' : '_noaccess');
+
+ }
+ else
+ {
+ $module = $tag->GetAttributeByName('_module');
+ if(strlen($module))
+ {
+ $t = $tag->GetAttributeByName( ModuleEnabled($module) ? '_template' : '_noaccess' );
+ }
+ }
+ break;
+
+ case "lang_include":
+ $lang = $tag->GetAttributeByName("_language");
+ if(strlen($lang))
{
- $t = $tag->GetAttributeByName("_template");
+ $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;
- }//switch
+ 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(!$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;
+ $LogLevel=0;
LogEntry("Finished Parsing $t\n");
return $ret;
}
/* <inp:mod_include _Template=".." [_perm=".."] [_modules=".."] [_system=".."] */
function ModuleInclude($tag)
{
global $var_list;
$o = "";
$el = new clsHtmlTag();
$el->attributes = $tag->attributes;
$el->parsed=1;
$t = $tag->attributes["_template"];
if(!strlen($t))
$t = $var_list["t"];
$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;
}
function ParseTemplateText($text)
{
$html = $text;
$search = "<inp:";
$next_tag = strpos($html,$search);
$left = substr($html,0,5);
while($next_tag || $left=="<inp:")
{
$left = "";
$closer = strpos(strtolower($html),">",$next_tag);
$tmp = substr($html,$next_tag,$closer+1 - $next_tag);
while(substr($html,$closer-1,1)=="\\" && $closer < strlen($html))
{
$closer = strpos(strtolower($html),">",$closer+1);
}
$end_tag = strpos($html,"/>",$next_tag);
if(($end_tag < $closer || $closer == 0))
{
$tagtext = substr($html,$next_tag,($end_tag - $next_tag)+2);
$pre = substr($html,0,$next_tag);
$post = substr($html,$end_tag+2);
$inner = $this->ParseTag($tagtext);
$html = $pre.$inner.$post;
}
else
{
$OldTagStyle = "</inp>";
## Try to find end of TagName
$TagNameEnd = strpos($html, " ", $next_tag);
## Support Old version
// $closer = strpos(strtolower($html),"</inp>",$next_tag);
if ($TagNameEnd)
{
$Tag = strtolower(substr($html, $next_tag, $TagNameEnd-$next_tag));
$TagName = explode(":", $Tag);
if (strlen($TagName[1]))
$CloserTag = "</inp:".$TagName[1].">";
}
else
{
$CloserTag = $OldTagStyle;
}
$closer = strpos(strtolower($html), $CloserTag, $next_tag);
## Try to find old tag closer
if (!$closer && ($CloserTag != $OldTagStyle))
{
$CloserTag = $OldTagStyle;
$closer = strpos(strtolower($html), $CloserTag, $next_tag);
}
$end_tag = strpos($html,">",$next_tag);
$tagtext = substr($html,$next_tag,($end_tag - $next_tag)+1);
$pre = substr($html,0,$next_tag);
$inner = substr($html,$end_tag+1,$closer-($end_tag+1));
$post = substr($html,$end_tag+1+strlen($inner) + strlen($CloserTag));
$parsed = trim($this->ParseTag($tagtext));
if(strlen($parsed))
{
$html = $pre.$this->ParseTemplateText($inner).$post;
}
else
$html = $pre.$post;
}
//$next_tag = strpos($html,"<inp:");
$next_tag = 0;
$next_tag = strpos($html,$search);
}
return $html;
}
function ParseTemplate($tname, $NoCache=0, $NoStack=0,$SupressError=FALSE)
{
$html = "";
$t = $this->GetTemplate($tname,$SupressError);
if(is_object($t))
{
if(!$NoStack)
array_push($this->stack,$tname);
$html = $t->source;
$html = $this->ParseTemplateText($html);
if(!$NoStack)
array_pop($this->stack);
$t->out = $html;
if(!$NoCache)
$this->SaveTemplateCache($t);
}
unset($t);
return $html;
}
}
class clsAdminTemplateList extends clsTemplateList
{
function clsAdminTemplateList()
{
global $TemplateRoot;
$this->clsTemplateList($TemplateRoot);
}
function GetTemplate($file)
{
$ret = FALSE;
$ret = new clsTemplate();
if(!$ret->LoadByFileName($file))
{
$this->ErrorNo = -1;
$this->ErrorStr = "Error Loading Template '$file'";
}
return $ret;
}
}
class clsTemplateChecker extends clsTemplateList
{
var $Dependencies;
var $TemplateType;
var $Tags;
function clsTemplateChecker($rootdir)
{
$this->clsTemplateList($rootdir);
$this->Dependencies = Array();
$this->Tags = array();
$this->TemplateType="global"; //default
}
function ParseTag($text)
{
$this->Tags[] = new clsHtmlTag($text);
return "";
}
function ParseTemplateText($text)
{
$html = $text;
$search = "<inp:";
$next_tag = strpos($html,$search);
$left = substr($html,0,5);
while($next_tag || $left=="<inp:")
{
$left = "";
$closer = strpos(strtolower($html),">",$next_tag);
$end_tag = strpos($html,"/>",$next_tag);
if($end_tag < $closer || $closer == 0)
{
$tagtext = substr($html,$next_tag,($end_tag - $next_tag)+2);
$pre = substr($html,0,$next_tag);
$post = substr($html,$end_tag+2);
$inner = $this->ParseTag($tagtext);
$html = $pre.$inner.$post;
}
else
{
$closer = strpos(strtolower($html),"</inp>",$next_tag);
$end_tag = strpos($html,">",$next_tag);
$tagtext = substr($html,$next_tag,($end_tag - $next_tag)+1);
$pre = substr($html,0,$next_tag);
$inner = substr($html,$end_tag+1,$closer-($end_tag+1));
$post = substr($html,$end_tag+1+strlen($inner)+6);
$parsed = $this->ParseTag($tagtext);
if(strlen($parsed))
{
$html = $pre.$inner.$post;
}
else
$html = $pre.$post;
}
//$next_tag = strpos($html,"<inp:");
$next_tag = 0;
$next_tag = strpos($html,$search);
}
return $html;
}
function ParseTemplate($tname, $NoCache=0, $NoStack=0,$SupressError=FALSE)
{
$html = "";
$t = $this->GetTemplate($tname,$SupressError);
if(is_object($t))
{
$html = $this->ParseTemplateText($t->source);
$t->out = $html;
}
unset($t);
return $html;
}
function ReadTemplateTags($tname)
{
$this->Tags[]=Array();
$this->ParseTemplate($tname,1,1,TRUE);
return $this->Tags;
}
function GetTemplateType($tname)
{
global $ItemTypePrefixes;
$ret = "global";
$this->ReadTemplateTags($tname);
if(count($this->Tags)>0)
{
foreach($this->Tags as $t)
{
if(in_array($t->name,$ItemTypePrefixes))
{
$ret = $t->name;
break;
}
}
}
return $ret;
}
function IncludeTemplate($tag, $SupressError=FALSE)
{
$this->AddDependency($tag->GetAttributeByName("_template"));
$this->AddDependency($tag->GetAttributeByName("_noaccess"));
}
function ModuleInclude($tag)
{
}
function AddDependency($template)
{
$template = strtolower($template);
if(!in_array($template,$this->Dependencies))
$this->Dependencies[] = $template;
}
}
function admintemplate($fileh)
{
if(file_exists($fileh))
{ $fd = fopen($fileh, "r");
$ret=fread($fd, filesize($fileh));
fclose($fd);
return $ret;
}
else
echo "Unable to load $fileh";
}
function ExtraAttributes($attribs)
{
$html_attr = "";
if(is_array($attribs))
{
foreach($attribs as $name=>$value)
{
if(substr($name,0,1)!="_")
$html_attr .= $name."=\"$value\" ";
}
}
return $html_attr;
}
?>
Property changes on: trunk/kernel/include/parse.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.4
\ No newline at end of property
+1.5
\ No newline at end of property
Index: trunk/globals.php
===================================================================
--- trunk/globals.php (revision 492)
+++ trunk/globals.php (revision 493)
@@ -1,1439 +1,1446 @@
<?php
$vars = parse_portal_ini($pathtoroot."config.php");
while($key = key($vars))
{
$key = "g_".$key;
global $$key;
$$key = current($vars); //variable variables
next($vars);
}
/*list the tables which contain item data */
$ItemTables = array();
$KeywordIgnore = array();
global $debuglevel;
$debuglevel = 0;
//$GLOBALS['debuglevel'] = 0;
/*New, Hot, Pop field values */
define('NEVER', 0);
define('ALWAYS', 1);
define('AUTO', 2);
/*Status Values */
define('STATUS_DISABLED', 0);
define('STATUS_ACTIVE', 1);
define('STATUS_PENDING', 2);
$LogLevel=0;
$LogFile = NULL;
function parse_portal_ini($file, $parse_section = false) {
if(!file_exists($file) && !is_readable($file))
die('Could Not Open Ini File');
$contents = file($file);
$retval = array();
$section = '';
$ln = 1;
$resave = false;
foreach($contents as $line) {
if ($ln == 1 && $line != '<'.'?'.'php die() ?'.">\n") {
$resave = true;
}
$ln++;
$line = trim($line);
$line = eregi_replace(';[.]*','',$line);
if(strlen($line) > 0) {
//echo $line . " - ";
if(eregi('^[[a-z]+]$',str_replace(' ', '', $line))) {
//echo 'section';
$section = substr($line,1,(strlen($line)-2));
if ($parse_section) {
$retval[$section] = array();
}
continue;
} elseif(eregi('=',$line)) {
//echo 'main element';
list($key,$val) = explode(' = ',$line);
if (!$parse_section) {
$retval[trim($key)] = str_replace('"', '', $val);
}
else {
$retval[$section][trim($key)] = str_replace('"', '', $val);
}
} //end if
//echo '<br />';
} //end if
} //end foreach
if ($resave) {
$fp = fopen($file, "w");
reset($contents);
fwrite($fp,'<'.'?'.'php die() ?'.">\n\n");
foreach($contents as $line) fwrite($fp,"$line");
fclose($fp);
}
return $retval;
}
/**
* @return object
* @desc Returns reference to database connection
*/
function &GetADODBConnection()
{
static $DB = null;
global $g_DBType, $g_DBHost, $g_DBUser, $g_DBUserPassword, $g_DBName, $g_DebugMode;
global $ADODB_FETCH_MODE, $ADODB_COUNTRECS, $ADODB_CACHE_DIR, $pathtoroot;
if( !isset($DB) && strlen($g_DBType) > 0 )
{
$DB = ADONewConnection($g_DBType);
$connected = $DB->Connect($g_DBHost, $g_DBUser, $g_DBUserPassword, $g_DBName);
if(!$connected) die("Error connecting to database $g_DBHost <br>\n");
$ADODB_CACHE_DIR = $pathtoroot."cache";
$ADODB_FETCH_MODE = 2;
$ADODB_COUNTRECS = false;
$DB->debug = defined('ADODB_OUTP') ? 1 : 0;
$DB->cacheSecs = 3600;
$DB->Execute('SET SQL_BIG_SELECTS = 1');
}
elseif( !strlen($g_DBType) )
{
global $rootURL;
echo 'In-Portal is probably not installed, or configuration file is missing.<br>';
echo 'Please use the installation script to fix the problem.<br><br>';
if ( !preg_match('/admin/', $_SERVER['SCRIPT_FILENAME']) ) $ins = 'admin/';
echo '<a href="'.$rootURL.$ins.'install.php">Go to installation script</a><br><br>';
flush();
exit;
}
return $DB;
}
function GetNextResourceId($Increment=1)
{
$sql = "UPDATE ".GetTablePrefix()."IdGenerator SET lastid=lastid+".$Increment;
$adodbConnection = GetADODBConnection();
$adodbConnection->Execute($sql);
$rs = $adodbConnection->Execute("SELECT lastid FROM ".GetTablePrefix()."IdGenerator");
$val = $rs->fields["lastid"];
if(!$rs || $rs->EOF)
{
echo $adodbConnection->ErrorMsg();
$sql = "INSERT INTO ".GetTablePrefix()."IdGenerator (lastid) VALUES ($Increment)";
$adodbConnection->Execute($sql);
$val = 1;
}
$val = $val-($Increment-1);
return $val;
}
function AddSlash($s)
{
if(substr($s,-1) != "/")
{
return $s."/";
}
else
return $s;
}
function StripNewline($s)
{
$bfound = false;
while (strlen($s)>0 && !$bfound)
{
if(ord(substr($s,-1))<32)
{
$s = substr($s,0,-1);
}
else
$bfound = true;
}
return $s;
}
function DeleteElement($array, $indice)
{
for($i=$indice;$i<count($array)-1;$i++)
$array[$i] = $array[$i+1];
unset($array[count($array)-1]);
return $array;
}
function DeleteElementValue($needle, &$haystack)
{
while(($gotcha = array_search($needle,$haystack)) > -1)
unset($haystack[$gotcha]);
}
function TableCount($TableName, $where="",$JoinCats=1)
{
$db = GetADODBConnection();
if(!$JoinCats)
{
$sql = "SELECT count(*) as TableCount FROM $TableName";
}
else
$sql = "SELECT count(*) as TableCount FROM $TableName INNER JOIN ".GetTablePrefix()."CategoryItems ON ".GetTablePrefix()."CategoryItems.ItemResourceId=$TableName.ResourceId";
if(strlen($where)>0)
$sql .= " WHERE ".$where;
$rs = $db->Execute($sql);
// echo "SQL TABLE COUNT: ".$sql."<br>\n";
$res = $rs->fields["TableCount"];
return $res;
}
Function QueryCount($sql)
{
$countsql = "SELECT count(*) as TableCount ".substr($sql,strpos($sql," FROM "));
if(strpos($countsql,"LIMIT"))
$countsql = substr($countsql,0,strpos($countsql,"LIMIT"));
if(strpos($countsql,"ORDER BY"))
$countsql = substr($countsql,0,strpos($countsql,"ORDER BY"));
$db = GetADODBConnection();
$rs = $db->Execute($countsql);
//echo $countsql."<br>\n";
$res = $rs->fields["TableCount"];
return $res;
}
function GetPageCount($ItemsPerPage,$NumItems)
{
if($ItemsPerPage==0 || $NumItems==0)
{
return 1;
}
$value = $NumItems/$ItemsPerPage;
return ceil($value);
}
/**
* @return string
* @desc Returns database table prefix entered while installation
*/
function GetTablePrefix()
{
global $g_TablePrefix;
return $g_TablePrefix;
}
function TableHasPrefix($t)
{
$pre = GetTablePrefix();
if(strlen($pre)>0)
{
if(substr($t,0,strlen($pre))==$pre)
{
return TRUE;
}
else
return FALSE;
}
else
return TRUE;
}
function AddTablePrefix($t)
{
if(!TableHasPrefix($t))
$t = GetTablePrefix().$t;
return $t;
}
function ThisDomain()
{
global $objConfig, $g_Domain;
if($objConfig->Get("DomainDetect"))
{
$d = $_SERVER['HTTP_HOST'];
}
else
$d = $g_Domain;
return $d;
}
function GetIndexUrl($secure=0)
{
global $indexURL, $rootURL, $secureURL;
switch($secure)
{
case 0:
$ret = $indexURL;
break;
case 1:
$ret = $secureURL."index.php";
break;
case 2:
$ret = $rootURL."index.php";
break;
default:
$ret = $i;
}
return $ret;
}
function GetLimitSQL($Page,$PerPage)
{
if($Page<1)
$Page=1;
if(is_numeric($PerPage))
{
if($PerPage==0)
$PerPage = 20;
$Start = ($Page-1)*$PerPage;
$limit = "LIMIT ".$Start.",".$PerPage;
}
else
$limit = NULL;
return $limit;
}
function filelist ($currentdir, $startdir=NULL,$ext=NULL)
{
global $pathchar;
//chdir ($currentdir);
// remember where we started from
if (!$startdir)
{
$startdir = $currentdir;
}
$d = @opendir($currentdir);
$files = array();
if(!$d)
return $files;
//list the files in the dir
while (false !== ($file = readdir($d)))
{
if ($file != ".." && $file != ".")
{
if (is_dir($currentdir."/".$file))
{
// If $file is a directory take a look inside
$a = filelist ($currentdir."/".$file, $startdir,$ext);
if(is_array($a))
$files = array_merge($files,$a);
}
else
{
if($ext!=NULL)
{
$extstr = stristr($file,".".$ext);
if(strlen($extstr))
$files[] = $currentdir."/".$file;
}
else
$files[] = $currentdir.'/'.$file;
}
}
}
closedir ($d);
return $files;
}
function DecimalToBin($dec,$WordLength=8)
{
$bits = array();
$str = str_pad(decbin($dec),$WordLength,"0",STR_PAD_LEFT);
for($i=$WordLength;$i>0;$i--)
{
$bits[$i-1] = (int)substr($str,$i-1,1);
}
return $bits;
}
function inp_escape($in, $html_enable=0)
{
$out = stripslashes($in);
$out = str_replace("\n", "\n^br^", $out);
if($html_enable==0)
{
$out=ereg_replace("<","&lt;",$out);
$out=ereg_replace(">","&gt;",$out);
$out=ereg_replace("\"","&quot;",$out);
$out = str_replace("\n^br^", "\n<br />", $out);
}
else
$out = str_replace("\n^br^", "\n", $out);
$out=addslashes($out);
return $out;
}
function inp_unescape($in)
{
$out=stripslashes($in);
return $out;
}
function inp_textarea_unescape($in)
{
$out=stripslashes($in);
$out = str_replace("\n<br />", "\n", $out);
return $out;
}
function HighlightKeywords($Keywords, $html, $OpenTag="", $CloseTag="")
{
global $objConfig;
if(!strlen($OpenTag))
$OpenTag = "<B>";
if(!strlen($CloseTag))
$CloseTag = "</B>";
$r = preg_split('((>)|(<))', $html, -1, PREG_SPLIT_DELIM_CAPTURE);
foreach ($Keywords as $k) {
for ($i = 0; $i < count($r); $i++) {
if ($r[$i] == "<") {
$i++; continue;
}
$r[$i] = preg_replace("/($k)/i", "$OpenTag\\1$CloseTag", $r[$i]);
}
}
return join("", $r);
}
/*
function HighlightKeywords($Keywords,$html, $OpenTag="", $CloseTag="")
{
global $objConfig;
if(!strlen($OpenTag))
$OpenTag = "<B>";
if(!strlen($CloseTag))
$CloseTag = "</B>";
$ret = strip_tags($html);
foreach ($Keywords as $k)
{
if(strlen($k))
{
//$html = str_replace("<$k>", ":#:", $html);
//$html = str_replace("</$k>", ":##:", $html);
//$html = strip_tags($html);
if ($html = preg_replace("/($k)/Ui","$OpenTag\\1$CloseTag", $html))
//if ($html = preg_replace("/(>[^<]*)($k)([^<]*< )/Ui","$OpenTag\\1$CloseTag", $html))
$ret = $html;
//$ret = str_replace(":#:", "<$k>", $ret);
//$ret = str_replace(":##:", "</$k>", $ret);
}
}
return $ret;
}
*/
function ExtractDatePart($part,$datestamp)
{
switch($part)
{
case "month":
if($datestamp<=0)
{
$ret = "";
}
else
$ret = adodb_date("m",$datestamp);
break;
case "day":
if($datestamp<=0)
{
$ret = "";
}
else
$ret = adodb_date("d", $datestamp);
break;
case "year":
if($datestamp<=0)
{
$ret = "";
}
else
$ret = adodb_date("Y", $datestamp);
break;
case "time_24hr":
if($datestamp<=0)
{
$ret = "";
}
else
$ret = adodb_date("H:i", $datestamp);
break;
case "time_12hr":
if($datestamp<=0)
{
$ret = "";
}
else
$ret = adodb_date("g:i a",$datestamp);
break;
}
return $ret;
}
function GetLocalTime($TimeStamp,$TargetZone=NULL)
{
if($TargetZone==NULL)
$TargetZone = $objConfig->Get("Config_Site_Time");
$server = $objConfig->Get("Config_Server_Time");
if($TargetZone!=$server)
{
$offset = ($server - $TargetZone) * -1;
$TimeStamp = $TimeStamp + (3600 * $offset);
}
return $TimeStamp;
}
function _unhtmlentities ($string)
{
$trans_tbl = get_html_translation_table (HTML_ENTITIES);
$trans_tbl = array_flip ($trans_tbl);
return strtr ($string, $trans_tbl);
}
function getLastStr($hay, $need){
$getLastStr = 0;
$pos = strpos($hay, $need);
if (is_int ($pos)){ //this is to decide whether it is "false" or "0"
while($pos) {
$getLastStr = $getLastStr + $pos + strlen($need);
$hay = substr ($hay , $pos + strlen($need));
$pos = strpos($hay, $need);
}
return $getLastStr - strlen($need);
} else {
return -1; //if $need wasn´t found it returns "-1" , because it could return "0" if it´s found on position "0".
}
}
function ReplaceSingleTag($tag,$text)
{
$tag = strtolower($tag);
$opentag = '['.$tag;
$closetag = '[/'.$tag.']';
if( stristr($text,$opentag) )
{
$pos = strpos( strtolower($text), $opentag.' '); // tag has parameters
if($pos === false)
{
$pos = strpos($text,$opentag.']');
}
$endopen = strpos($text,']',$pos);
$closepos = strpos($text,$closetag,$pos);
if($closepos)
{
$taglength = ($closepos - $endopen) + strlen($closetag);
$tagText = substr($text,$pos, $closepos + strlen($closetag) - $pos);
$innerText = substr($text,$endopen+1,$closepos - $endopen-1);
if($tag=="UL")
{
$innerText = str_replace("[*]","<LI>",$innerText);
}
$tagText = substr($tagText,1,($endopen - $pos)-1);
//echo "Matched $tagText <br>\n";
$tagText = "<".$tagText.">";
$replace_text = $tagText.$innerText."</".$tag.">";
$text = substr($text,0,$pos).$replace_text.substr($text,$closepos+strlen($closetag));
return $text;
}
else
return $text;
}
else
return $text;
}
function ReplaceTag($tag,$text)
{
$new_text = ReplaceSingleTag($tag,$text);
while($new_text != $text)
{
$text = $new_text;
$new_text = ReplaceSingleTag($tag,$text);
}
return $new_text;
}
function ReplaceURL($text)
{
// process url bbtags without href parameter
$text = preg_replace('/\[url\]([^\]]*)\[\/url\]/U', '[url href="$1"]$1[/url]', $text);
// change bbcode to href's
while( stristr($text,'[url') )
{
$urlpos = strpos( strtolower($text), '[url');
$endopen = strpos($text,']',$urlpos);
if($endopen)
{
$url = '<a target="_blank"'.substr($text,$urlpos+4,$endopen - ($urlpos+4));
$url .= '>';
$url = _unhtmlentities($url);
$text = substr($text,0,$urlpos).$url.substr($text,$endopen+1);
}
}
$text = str_replace('[/url]','</a>',$text);
return $text;
}
function ReplaceBBCode($text)
{
- global $objConfig;
+ global $objConfig;
- $tags = explode(",",$objConfig->Get("BBTags"));
- for($i=0;$i<count($tags);$i++)
- {
- $text = ReplaceTag(strtoupper($tags[$i]),$text);
- }
- $text = ReplaceURL($text);
- return $text;
+ // BBCode: [b], [i], [u], [ul], [font]
+ $tags = explode(",",$objConfig->Get("BBTags"));
+ for($i = 0; $i < count($tags); $i++)
+ {
+ $text = ReplaceTag(strtoupper($tags[$i]),$text);
+ }
+
+ // BBCode: [url href="xxx"]xxx[/url]
+ $text = ReplaceURL($text);
+
+ // BBCode: [code]xxx[/code]
+ $text = preg_replace('/\[code\]([^\]]*)\[\/code\]/Ue', 'highlight_string( stripslashes(_unhtmlentities("$1") ), true)', $text);
+
+ return $text;
}
function GetMinValue($Table,$Field, $Where=NULL)
{
$ret = 0;
$sql = "SELECT min($Field) as val FROM $Table ";
if(strlen($where))
$sql .= "WHERE $Where";
$ado = GetADODBConnection();
$rs = $ado->execute($sql);
if($rs)
$ret = (int)$rs->fields["val"];
return $ret;
}
function getmicrotime()
{
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
function SetMissingDataErrors($f)
{
global $FormError;
$count = 0;
if(is_array($_POST))
{
if(is_array($_POST["required"]))
{
foreach($_POST["required"] as $r)
{
$found = FALSE;
if(is_array($_FILES))
{
if( isset($_FILES[$r]) && $_FILES[$r]['size'] > 0 ) $found = TRUE;
}
if(!strlen(trim($_POST[$r])) && !$found)
{
$count++;
if (($r == "dob_day") || ($r == "dob_month") || ($r == "dob_year"))
$r = "dob";
$tag = isset($_POST["errors"]) ? $_POST["errors"][$r] : '';
if(!strlen($tag))
$tag = "lu_ferror_".$f."_".$r;
$FormError[$f][$r] = language($tag);
}
}
}
}
return $count;
}
function makepassword($length=10)
{
$pass_length=$length;
$p1=array('b','c','d','f','g','h','j','k','l','m','n','p','q','r','s','t','v','w','x','y','z');
$p2=array('a','e','i','o','u');
$p3=array('1','2','3','4','5','6','7','8','9');
$p4=array('(','&',')',';','%'); // if you need real strong stuff
// how much elements in the array
// can be done with a array count but counting once here is faster
$s1=21;// this is the count of $p1
$s2=5; // this is the count of $p2
$s3=9; // this is the count of $p3
$s4=5; // this is the count of $p4
// possible readable combinations
$c1='121'; // will be like 'bab'
$c2='212'; // will be like 'aba'
$c3='12'; // will be like 'ab'
$c4='3'; // will be just a number '1 to 9' if you dont like number delete the 3
// $c5='4'; // uncomment to active the strong stuff
$comb='4'; // the amount of combinations you made above (and did not comment out)
for ($p=0;$p<$pass_length;)
{
mt_srand((double)microtime()*1000000);
$strpart=mt_rand(1,$comb);
// checking if the stringpart is not the same as the previous one
if($strpart<>$previous)
{
$pass_structure.=${'c'.$strpart};
// shortcutting the loop a bit
$p=$p+strlen(${'c'.$strpart});
}
$previous=$strpart;
}
// generating the password from the structure defined in $pass_structure
for ($g=0;$g<strlen($pass_structure);$g++)
{
mt_srand((double)microtime()*1000000);
$sel=substr($pass_structure,$g,1);
$pass.=${'p'.$sel}[mt_rand(0,-1+${'s'.$sel})];
}
return $pass;
}
function LogEntry($text,$writefile=FALSE)
{
global $g_LogFile,$LogFile, $LogData, $LogLevel, $timestart;
static $last;
if(strlen($g_LogFile))
{
$el = str_pad(getmicrotime()- $timestart,10," ");
if($last>0)
$elapsed = getmicrotime() - $last;
if(strlen($el)>10)
$el = substr($el,0,10);
$indent = str_repeat(" ",$LogLevel);
$text = str_pad($text,$LogLevel,"==",STR_PAD_LEFT);
$LogData .= "$el:". round($elapsed,6).":$indent $text";
$last = getmicrotime();
if($writefile==TRUE && is_writable($g_LogFile))
{
if(!$LogFile)
{
if(file_exists($g_LogFile))
unlink($g_LogFile);
$LogFile=@fopen($g_LogFile,"w");
}
if($LogFile)
{
fputs($LogFile,$LogData);
}
}
}
}
function ValidEmail($email)
{
if (eregi("^[a-z0-9]+([-_\.]?[a-z0-9])+@[a-z0-9]+([-_\.]?[a-z0-9])+\.[a-z]{2,4}", $email))
{
return TRUE;
}
else
{
return FALSE;
}
}
function language($phrase,$LangId=0)
{
global $objSession, $objLanguageCache, $objLanguages;
if($LangId==0)
$LangId = $objSession->Get("Language");
if($LangId==0)
$LangId = $objLanguages->GetPrimary();
$translation = $objLanguageCache->GetTranslation($phrase,$LangId);
return $translation;
}
function admin_language($phrase,$lang=0,$LinkMissing=FALSE)
{
global $objSession, $objLanguageCache, $objLanguages;
//echo "Language passed: $lang<br>";
if($lang==0)
$lang = $objSession->Get("Language");
//echo "Language from session: $lang<br>";
if($lang==0)
$lang = $objLanguages->GetPrimary();
//echo "Language after primary: $lang<br>";
//echo "Phrase: $phrase<br>";
$translation = $objLanguageCache->GetTranslation($phrase,$lang);
if($LinkMissing && substr($translation,0,1)=="!" && substr($translation,-1)=="!")
{
$res = "<A href=\"javascript:OpenPhraseEditor('&direct=1&label=$phrase'); \">$translation</A>";
return $res;
}
else
return $translation;
}
function prompt_language($phrase,$lang=0)
{
return admin_language($phrase,$lang,TRUE);
}
function GetPrimaryTranslation($Phrase)
{
global $objLanguages;
$l = $objLanguages->GetPrimary();
return language($Phrase,$l);
}
function CategoryNameCount($ParentId,$Name)
{
$cat_table = GetTablePrefix()."Category";
$sql = "SELECT Name from $cat_table WHERE ParentId=$ParentId AND ";
$sql .="(Name LIKE '".addslashes($Name)."' OR Name LIKE 'Copy of ".addslashes($Name)."' OR Name LIKE 'Copy % of ".addslashes($Name)."')";
$ado = GetADODBConnection();
$rs = $ado->Execute($sql);
$ret = array();
while($rs && !$rs->EOF)
{
$ret[] = $rs->fields["Name"];
$rs->MoveNext();
}
return $ret;
}
function CategoryItemNameCount($CategoryId,$Table,$Field,$Name)
{
$cat_table = GetTablePrefix()."CategoryItems";
$sql = "SELECT $Field FROM $Table INNER JOIN $cat_table ON ($Table.ResourceId=$cat_table.ItemResourceId) ";
$sql .=" WHERE ($Field LIKE 'Copy % of $Name' OR $Field LIKE '$Name' OR $Field LIKE 'Copy of $Name') AND CategoryId=$CategoryId";
//echo $sql."<br>\n ";
$ado = GetADODBConnection();
$rs = $ado->Execute($sql);
$ret = array();
while($rs && !$rs->EOF)
{
$ret[] = $rs->fields[$Field];
$rs->MoveNext();
}
return $ret;
}
function &GetItemCollection($ItemName)
{
global $objItemTypes;
if(is_numeric($ItemName))
{
$item = $objItemTypes->GetItem($ItemName);
}
else
$item = $objItemTypes->GetTypeByName($ItemName);
if(is_object($item))
{
$module = $item->Get("Module");
$prefix = ModuleTagPrefix($module);
$func = $prefix."_ItemCollection";
if(function_exists($func))
{
$var =& $func();
}
}
return $var;
}
function UpdateCategoryCount($ItemTypeName=0,$ListType=NULL)
{
global $objCountCache, $objItemTypes;
if(is_numeric($ItemTypeName))
$item = $objItemTypes->GetItem($ItemTypeName);
else
$item = $objItemTypes->GetTypeByName($ItemTypeName);
if(is_object($item))
{
$ItemType = $item->Get("ItemType");
$sql = "DELETE FROM ".$objCountCache->SourceTable." WHERE ItemType=$ItemType";
if( is_numeric($ListType) ) $sql .= " AND ListType=$ListType";
$objCountCache->adodbConnection->Execute($sql);
}
}
function UpdateModifiedCategoryCount($ItemTypeName,$CatId=NULL,$Modifier=0,$ExtraId=NULL)
{
}
function UpdateGroupCategoryCount($ItemTypeName,$CatId=NULL,$Modifier=0,$GroupId=NULL)
{
}
function GetTagCache($module,$tag,$attribs,$env)
{
global $objSystemCache, $objSession, $objConfig;
if($objConfig->Get("SystemTagCache"))
{
$name = $tag;
if(is_array($attribs))
{
foreach($attribs as $n => $val)
{
$name .= "-".$val;
}
}
$CachedValue = $objSystemCache->GetContextValue($name,$module,$env, $objSession->Get("GroupList"));
}
else
$CachedValue="";
return $CachedValue;
}
function SaveTagCache($module, $tag, $attribs, $env, $newvalue)
{
global $objSystemCache, $objSession, $objConfig;
if($objConfig->Get("SystemTagCache"))
{
$name = $tag;
if(is_array($attribs))
{
foreach($attribs as $a => $val)
{
$name .= "-".$val;
}
}
$objSystemCache->EditCacheItem($name,$newvalue,$module,0,$env,$objSession->Get("GroupList"));
}
}
function DeleteTagCache($name,$extraparams, $env="")
{
global $objSystemCache, $objConfig;
if($objConfig->Get("SystemTagCache"))
{
$where = "Name LIKE '$name%".$extraparams."'";
if(strlen($env))
$where .= " AND Context LIKE $env";
$objSystemCache->DeleteCachedItem($where);
}
}
function ParseTagLibrary()
{
$objTagList = new clsTagList();
$objTagList->ParseInportalTags();
unset($objTagList);
}
function GetDateFormat($LangId=0)
{
global $objLanguages;
if(!$LangId)
$LangId= $objLanguages->GetPrimary();
$l = $objLanguages->GetItem($LangId);
if(is_object($l))
{
$fmt = $l->Get("DateFormat");
}
else
$fmt = "m-d-Y";
return $fmt;
}
function GetTimeFormat($LangId=0)
{
global $objLanguages;
if(!$LangId)
$LangId= $objLanguages->GetPrimary();
$l = $objLanguages->GetItem($LangId);
if(is_object($l))
{
$fmt = $l->Get("TimeFormat");
}
else
$fmt = "H:i:s";
return $fmt;
}
function LangDate($TimeStamp=NULL,$LangId=0)
{
$fmt = GetDateFormat($LangId);
$ret = adodb_date($fmt,$TimeStamp);
return $ret;
}
function LangTime($TimeStamp=NULL,$LangId=0)
{
$fmt = GetTimeFormat($LangId);
$ret = adodb_date($fmt,$TimeStamp);
return $ret;
}
function LangNumber($Num,$DecPlaces=NULL,$LangId=0)
{
global $objLanguages;
if(!$LangId)
$LangId= $objLanguages->GetPrimary();
$l = $objLanguages->GetItem($LangId);
if(is_object($l))
{
$ret = number_format($Num,$DecPlaces,$l->Get("DecimalPoint"),$l->Get("ThousandSep"));
}
else
$ret = $num;
return $ret;
}
function replacePngTags($x, $spacer="images/spacer.gif")
{
global $rootURL,$pathtoroot;
// make sure that we are only replacing for the Windows versions of Internet
// Explorer 5+, and not Opera identified as MSIE
$msie='/msie\s([5-9])\.?[0-9]*.*(win)/i';
$opera='/opera\s+[0-9]+/i';
if(!isset($_SERVER['HTTP_USER_AGENT']) ||
!preg_match($msie,$_SERVER['HTTP_USER_AGENT']) ||
preg_match($opera,$_SERVER['HTTP_USER_AGENT']))
return $x;
// find all the png images in backgrounds
preg_match_all('/background-image:\s*url\(\'(.*\.png)\'\);/Uis',$x,$background);
for($i=0;$i<count($background[0]);$i++){
// simply replace:
// "background-image: url('image.png');"
// with:
// "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(
// enabled=true, sizingMethod=scale src='image.png');"
// haven't tested to see if background-repeat styles work...
$x=str_replace($background[0][$i],'filter:progid:DXImageTransform.'.
'Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale'.
' src=\''.$background[1][$i].'\');',$x);
}
// OK, time to find all the IMG tags with ".png" in them
preg_match_all('/(<img.*\.png.*>|<input.*type=([\'"])image\\2.*\.png.*>)/Uis',$x,$images);
while(list($imgnum,$v)=@each($images[0])){
$original=$v;
$atts=''; $width=0; $height=0;
// If the size is defined by styles, find
preg_match_all('/style=".*(width: ([0-9]+))px.*'.
'(height: ([0-9]+))px.*"/Ui',$v,$arr2);
if(is_array($arr2) && count($arr2[0])){
// size was defined by styles, get values
$width=$arr2[2][0];
$height=$arr2[4][0];
}
// size was not defined by styles, get values
preg_match_all('/width=\"?([0-9]+)\"?/i',$v,$arr2);
if(is_array($arr2) && count($arr2[0])){
$width=$arr2[1][0];
}
preg_match_all('/height=\"?([0-9]+)\"?/i',$v,$arr2);
if(is_array($arr2) && count($arr2[0])){
$height=$arr2[1][0];
}
preg_match_all('/src=\"([^\"]+\.png)\"/i',$v,$arr2);
if(isset($arr2[1][0]) && !empty($arr2[1][0]))
$image=$arr2[1][0];
else
$image=NULL;
// We do this so that we can put our spacer.gif image in the same
// directory as the image
$tmp=split('[\\/]',$image);
array_pop($tmp);
$image_path=join('/',$tmp);
if(substr($image,0,strlen($rootURL))==$rootURL)
{
$path = str_replace($rootURL,$pathtoroot,$image);
}
else
{
$path = $pathtoroot."themes/telestial/$image";
}
// echo "Sizing $path.. <br>\n";
// echo "Full Tag: ".htmlentities($image)."<br>\n";
//if(!$height || !$width)
//{
$g = imagecreatefrompng($path);
if($g)
{
$height = imagesy($g);
$width = imagesx($g);
}
//}
if(strlen($image_path)) $image_path.='/';
// end quote is already supplied by originial src attribute
$replace_src_with=$spacer.'" style="width: '.$width.
'px; height: '.$height.'px; filter: progid:DXImageTransform.'.
'Microsoft.AlphaImageLoader(src=\''.$image.'\', sizingMethod='.
'\'scale\')';
// now create the new tag from the old
$new_tag=str_replace($image,$replace_src_with,$original);
// now place the new tag into the content
$x=str_replace($original,$new_tag,$x);
}
return $x;
}
function print_pre($str)
{
// no comments here :)
echo '<pre>'.print_r($str, true).'</pre>';
}
function GetOptions($field) // by Alex
{
// get dropdown values from custom field
$tmp =& new clsCustomField();
$tmp->LoadFromDatabase($field, 'FieldName');
$tmp_values = $tmp->Get('ValueList');
unset($tmp);
$tmp_values = explode(',', $tmp_values);
foreach($tmp_values as $mixed)
{
$elem = explode('=', trim($mixed));
$ret[ $elem[0] ] = $elem[1];
}
return $ret;
}
function ResetPage($module_prefix, $page_variable = 'p')
{
// resets page in specific module when category is changed
global $objSession;
if( !is_object($objSession) ) // when changing pages session doesn't exist -> InPortal BUG
{
global $var_list, $SessionQueryString, $FrontEnd;
//if(!$var_list["sid"]) $var_list["sid"] = $_COOKIE["sid"];
$objSession = new clsUserSession($var_list["sid"],($SessionQueryString && $FrontEnd==1));
}
//echo "SID_RESET: ".$GLOBALS['var_list']["sid"].'(COOKIE_SID: '.$_COOKIE["sid"].')<br>';
$last_cat = $objSession->GetVariable('last_category');
$prev_cat = $objSession->GetVariable('prev_category');
//echo "Resetting Page [$prev_cat] -> [$last_cat]<br>";
if($prev_cat != $last_cat) $GLOBALS[$module_prefix.'_var_list'][$page_variable] = 1;
}
if( !function_exists('GetVar') )
{
/**
* @return string
* @param string $name
* @param bool $post_priority
* @desc Get's variable from http query
*/
function GetVar($name, $post_priority = false)
{
if(!$post_priority) // follow gpc_order in php.ini
return isset($_REQUEST[$name]) ? $_REQUEST[$name] : false;
else // get variable from post 1stly if not found then from get
return isset($_POST[$name]) && $_POST[$name] !== false ? $_POST[$name] : ( isset($_GET[$name]) && $_GET[$name] ? $_GET[$name] : false );
}
}
function PassVar(&$source)
{
// source array + any count of key names in passed array
$params = func_get_args();
array_shift($params);
if( count($params) )
{
$ret = Array();
foreach($params as $var_name)
if( isset($source[$var_name]) )
$ret[] = $var_name.'='.$source[$var_name];
$ret = '&'.implode('&', $ret);
}
return $ret;
}
function GetSubmitVariable(&$array, $postfix)
{
// gets edit status of module
// used in case if some modules share
// common action parsed by kernel parser,
// but each module uses own EditStatus variable
$modules = Array('In-Link' => 'Link', 'In-News' => 'News', 'In-Bulletin' => 'Topic');
foreach($modules as $module => $prefix)
if( isset($array[$prefix.$postfix]) )
return Array('Module' => $module, 'variable' => $array[$prefix.$postfix]);
return false;
}
function GetModuleByAction()
{
$prefix2module = Array('m' => 'In-Portal', 'l' => 'In-Link', 'n' => 'In-News', 'bb' => 'In-Bulletin');
$action = GetVar('Action');
if($action)
{
$module_prefix = explode('_', $action);
return $prefix2module[ $module_prefix[0] ];
}
else
return false;
}
function dir_size($dir) {
// calculates folder size based on filesizes inside it (recursively)
$totalsize=0;
if ($dirstream = @opendir($dir)) {
while (false !== ($filename = readdir($dirstream))) {
if ($filename!="." && $filename!="..")
{
if (is_file($dir."/".$filename))
$totalsize+=filesize($dir."/".$filename);
if (is_dir($dir."/".$filename))
$totalsize+=dir_size($dir."/".$filename);
}
}
}
closedir($dirstream);
return $totalsize;
}
function size($bytes) {
// shows formatted file/directory size
$types = Array("la_bytes","la_kilobytes","la_megabytes","la_gigabytes","la_terabytes");
$current = 0;
while ($bytes > 1024) {
$current++;
$bytes /= 1024;
}
return round($bytes,2)." ".language($types[$current]);
}
function echod($str)
{
// echo debug output
echo str_replace( Array('[',']'), Array('[<b>', '</b>]'), $str).'<br>';
}
function PrepareParams($source, $to_lower, $mapping)
{
// prepare array with form values to use with item
$result = Array();
foreach($to_lower as $field)
$result[ $field ] = $source[ strtolower($field) ];
if( is_array($mapping) )
{
foreach($mapping as $field_from => $field_to)
$result[$field_to] = $source[$field_from];
}
return $result;
}
function GetELT($field, $phrases = Array())
{
// returns FieldOptions equivalent in In-Portal
$ret = Array();
foreach($phrases as $phrase)
$ret[] = admin_language($phrase);
$ret = "'".implode("','", $ret)."'";
return 'ELT('.$field.','.$ret.')';
}
function GetModuleImgPath($module)
{
global $rootURL, $admin;
return $rootURL.$module.'/'.$admin.'/images';
}
function ActionPostProcess($StatusField, $ListClass, $ListObjectName = '', $IDField = null)
{
// each action postprocessing stuff from admin
if( !isset($_REQUEST[$StatusField]) ) return false;
$list =& $GLOBALS[$ListObjectName];
if( !is_object($list) ) $list = new $ListClass();
$SFValue = $_REQUEST[$StatusField]; // status field value
switch($SFValue)
{
case 1: // User hit "Save" button
$list->CopyFromEditTable($IDField);
break;
case 2: // User hit "Cancel" button
$list->PurgeEditTable($IDField);
break;
}
if( function_exists('SpecificProcessing') ) SpecificProcessing($StatusField, $SFValue);
if($SFValue == 1 || $SFValue == 2) $list->Clear();
}
function GetElem(&$array, $index)
{
// returns array element by index if
// such index exists
return isset($array[$index]) ? $array[$index] : false;
}
function MakeHTMLTag($element, $attrib_prefix)
{
$result = Array();
$ap_length = strlen($attrib_prefix);
foreach($element->attributes as $attib_name => $attr_value)
if( substr($attib_name, $ap_length) == $ap_length )
$result[] = substr($attib_name, $ap_length, strlen($attib_name)).'="'.$attr_value.'"';
return count($result) ? implode(' ', $result) : false;
}
function GetImportScripts()
{
// return currently installed import scripts
static $import_scripts = Array();
if( count($import_scripts) == 0 )
{
$sql = 'SELECT * FROM '.GetTablePrefix().'ImportScripts ORDER BY is_id';
$db =& GetADODBConnection();
$rs = $db->Execute($sql);
if( $rs && $rs->RecordCount() > 0 )
{
while(!$rs->EOF)
{
$rec =& $rs->fields;
$import_scripts[] = Array( 'label' => $rec['is_label'], 'url' => $rec['is_script'],
'enabled' => $rec['is_enabled'], 'field_prefix' => $rec['is_field_prefix'],
'id' => $rec['is_string_id'], 'required_fields' => $rec['is_requred_fields'],
'module' => strtolower($rec['is_Module']) );
$rs->MoveNext();
}
}
else
{
$import_scripts = Array();
}
}
return $import_scripts;
}
function GetImportScript($id)
{
$scripts = GetImportScripts();
return isset($scripts[$id]) ? $scripts[$id] : false;
}
function GetNextTemplate($current_template)
{
// used on front, returns next template to make
// redirect to
$dest = GetVar('dest', true);
if(!$dest) $dest = GetVar('DestTemplate', true);
return $dest ? $dest : $current_template;
}
// functions for dealign with enviroment variable construction
function GenerateModuleEnv($prefix, $var_list)
{
// globalize module varible arrays
$main =& $GLOBALS[$prefix.'_var_list'];
$update =& $GLOBALS[$prefix.'_var_list_update'];
//echo "VAR: [$main]; VAR_UPDATE: [$update]<br>";
// ensure that we have no empty values in enviroment variable
foreach($update as $vl_key => $vl_value)
if(!$vl_value) $update[$vl_key] = '0'; // unset($update[$vl_key]);
// if update var count is zero, then do nothing
if(count($update) == 0) return '';
foreach($main as $vl_key => $vl_value)
if(!$vl_value) $main[$vl_key] = '0'; // unset($main[$vl_key]);
$ret = Array();
foreach($var_list as $var_name)
$ret[] = GetEnvVar($prefix, $var_name);
return ':'.$prefix.implode('-',$ret);
}
function GetEnvVar($prefix, $name)
{
// get variable from template variable's list
// (used in module parsers to build env string)
$main =& $GLOBALS[$prefix.'_var_list'];
$update =& $GLOBALS[$prefix.'_var_list_update'];
return isset($update[$name]) ? $update[$name] : ( isset($main[$name]) ? $main[$name] : '');
}
function IsDebugMode()
{
return defined('DEBUG_MODE') && constant('DEBUG_MODE') == 1 ? 1 : 0;
}
?>
Property changes on: trunk/globals.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.29
\ No newline at end of property
+1.30
\ No newline at end of property

Event Timeline