📄 dedetemplate.class.php
字号:
if($bindFunc=='')
{
$rsvalue .= '$blockValue = MakePublicTag($atts,$this->refObj,$fields); '."\r\n";
}
else
{
//自定义绑定函数如果不指定 bindtype,则指向$this->refObj->绑定函数名,即是默认指向被引用的类对象
if($bindType=='') $rsvalue .= '$blockValue = $this->refObj->'.$bindFunc.'($atts,$this->refObj,$fields); '."\r\n";
else $rsvalue .= '$blockValue = '.$bindFunc.'($atts,$this->refObj,$fields); '."\r\n";
}
//返回结果类型:默认为 array 是一个二维数组,string 是字符串
if($rstype=='string')
{
$rsvalue .= 'echo $blockValue;'."\r\n".'?'.">";
}
else
{
$rsvalue .= 'if(is_array($blockValue) && count($blockValue) > 0){'."\r\n";
$rsvalue .= 'foreach( $blockValue as $key=>$fields )'."\r\n{\r\n".'?'.">";
$rsvalue .= $cTag->GetInnerText();
$rsvalue .= '<'.'?php'."\r\n}\r\n}\r\n".'?'.'>';
}
$cTag->tagValue = $rsvalue;
}
return $cTag->tagValue;
}
//编译可能为数组的变量
function CompilerArrayVar($vartype,$varname)
{
$okvalue = '';
if(!ereg("\[",$varname))
{
if(ereg("^value",$vartype))
{
$varname = $vartype.'.'.$varname;
}
$varnames = explode('.',$varname);
if(isset($varnames[1]))
{
$varname = $varnames[0];
for($i=1; isset($varnames[$i]); $i++)
{
$varname .= "['".$varnames[$i]."']";
}
}
}
if(ereg("\[",$varname))
{
$varnames = explode('[',$varname);
$arrend = '';
for($i=1;isset($varnames[$i]);$i++)
{
$arrend .= '['.$varnames[$i];
}
if($vartype=='var')
{
$okvalue = '$GLOBALS[\'_vars\'][\''.$varnames[0].'\']'.$arrend;
}
else if( ereg("^value",$vartype) )
{
$okvalue = '$'.$varnames[0].$arrend;
}
else if($vartype=='field')
{
$okvalue = '$fields[\''.$varnames[0].'\']'.$arrend;
}
else
{
$okvalue = '$GLOBALS[\''.$varnames[0].'\']'.$arrend;
}
}
else
{
if($vartype=='var')
{
$okvalue = '$GLOBALS[\'_vars\'][\''.$varname.'\']';
}
else if( ereg("^value",$vartype) )
{
$okvalue = '$'.$vartype;
}
else if($vartype=='field')
{
$okvalue = '$'.str_replace($varname);
}
else
{
$okvalue = '$GLOBALS[\''.$varname.'\']';
}
}
return $okvalue;
}
//编译if标记
function CompilerIf($cTag)
{
$condition = trim($cTag->GetAtt('condition'));
if($condition =='')
{
$cTag->tagValue=''; return '';
}
$condition = preg_replace("/((var\.|field\.|cfg\.|global\.|key[0-9]{0,}\.|value[0-9]{0,}\.)[\._a-z0-9]+)/ies", "private_rt('\\1')", $condition);
$rsvalue = '<'.'?php if('.$condition.'){ ?'.'>';
$rsvalue .= $cTag->GetInnerText();
$rsvalue .= '<'.'?php } ?'.'>';
return $rsvalue;
}
//处理block区块传递的atts属性的值
function TrimAtts($v)
{
$v = str_replace('<'.'?','<?',$v);
$v = str_replace('?'.'>','?>',$v);
return $v;
}
//函数 function 语法处理
function CompilerFunction($funcstr,$nvalue)
{
$funcstr = str_replace('@quote','"',$funcstr);
$funcstr = str_replace('@me',$nvalue,$funcstr);
return $funcstr;
}
//引入文件 include 语法处理
function CompilerInclude($filename,$isload=true)
{
$okfile = '';
if( @file_exists($filename) )
{
$okfile = $filename;
}
else if( @file_exists($this->refDir."/".$filename) )
{
$okfile = $this->refDir."/".$filename;
}
else if( @file_exists($this->refDir."/../".$filename) )
{
$okfile = $this->refDir."/../".$filename;
}
else
{
return '';
}
if(!$isload)
{
return 'ok';
}
$itpl = new DedeTemplate($this->templateDir);
$itpl->isCache = $this->isCache;
$itpl->SetObject($this->refObj);
$itpl->LoadTemplate($okfile);
return $itpl->CacheFile();
}
}
/*------------------------
//class TagAttribute Tag属性集合
function C__TagAttribute();
-------------------------*/
//属性的数据描述
class TagAttribute
{
var $count = -1;
var $items = ""; //属性元素的集合
//获得某个属性
function GetAtt($str)
{
if($str=="")
{
return "";
}
if(isset($this->items[$str]))
{
return $this->items[$str];
}
else
{
return "";
}
}
//同上
function GetAttribute($str)
{
return $this->GetAtt($str);
}
//判断属性是否存在
function IsAttribute($str)
{
if(isset($this->items[$str])) return true;
else return false;
}
//获得标记名称
function GettagName()
{
return $this->GetAtt("tagname");
}
// 获得属性个数
function Getcount()
{
return $this->count+1;
}
}
/*-------------------------------
//属性解析器
function C__TagAttributeParse();
-------------------------------*/
class TagAttributeParse
{
var $sourceString = "";
var $sourceMaxSize = 1024;
var $cAttributes = "";
var $charToLow = true;
function SetSource($str="")
{
$this->cAttributes = new TagAttribute();
$strLen = 0;
$this->sourceString = trim(preg_replace("/[ \r\n\t\f]{1,}/"," ",$str));
$strLen = strlen($this->sourceString);
if($strLen>0 && $strLen <= $this->sourceMaxSize)
{
$this->ParseAttribute();
}
}
//解析属性
function ParseAttribute()
{
$d = '';
$tmpatt = '';
$tmpvalue = '';
$startdd = -1;
$ddtag = '';
$hasAttribute=false;
$strLen = strlen($this->sourceString);
// 获得Tag的名称,解析到 cAtt->GetAtt('tagname') 中
for($i=0; $i<$strLen; $i++)
{
if($this->sourceString[$i]==' ')
{
$this->cAttributes->count++;
$tmpvalues = explode('.', $tmpvalue);
$this->cAttributes->items['tagname'] = ($this->charToLow ? strtolower($tmpvalues[0]) : $tmpvalues[0]);
if( isset($tmpvalues[2]) )
{
$okname = $tmpvalues[1];
for($j=2;isset($tmpvalues[$j]);$j++)
{
$okname .= "['".$tmpvalues[$j]."']";
}
$this->cAttributes->items['name'] = $okname;
}
else if(isset($tmpvalues[1]) && $tmpvalues[1]!='')
{
$this->cAttributes->items['name'] = $tmpvalues[1];
}
$tmpvalue = '';
$hasAttribute = true;
break;
}
else
{
$tmpvalue .= $this->sourceString[$i];
}
}
//不存在属性列表的情况
if(!$hasAttribute)
{
$this->cAttributes->count++;
$tmpvalues = explode('.', $tmpvalue);
$this->cAttributes->items['tagname'] = ($this->charToLow ? strtolower($tmpvalues[0]) : $tmpvalues[0]);
if( isset($tmpvalues[2]) )
{
$okname = $tmpvalues[1];
for($i=2;isset($tmpvalues[$i]);$i++)
{
$okname .= "['".$tmpvalues[$i]."']";
}
$this->cAttributes->items['name'] = $okname;
}
else if(isset($tmpvalues[1]) && $tmpvalues[1]!='')
{
$this->cAttributes->items['name'] = $tmpvalues[1];
}
return ;
}
$tmpvalue = '';
//如果字符串含有属性值,遍历源字符串,并获得各属性
for($i; $i<$strLen; $i++)
{
$d = $this->sourceString[$i];
//查找属性名称
if($startdd==-1)
{
if($d != '=')
{
$tmpatt .= $d;
}
else
{
if($this->charToLow)
{
$tmpatt = strtolower(trim($tmpatt));
}
else
{
$tmpatt = trim($tmpatt);
}
$startdd=0;
}
}
//查找属性的限定标志
else if($startdd==0)
{
switch($d)
{
case ' ':
break;
case '\'':
$ddtag = '\'';
$startdd = 1;
break;
case '"':
$ddtag = '"';
$startdd = 1;
break;
default:
$tmpvalue .= $d;
$ddtag = ' ';
$startdd = 1;
break;
}
}
else if($startdd==1)
{
if($d==$ddtag && ( isset($this->sourceString[$i-1]) && $this->sourceString[$i-1]!="\\") )
{
$this->cAttributes->count++;
$this->cAttributes->items[$tmpatt] = trim($tmpvalue);
$tmpatt = '';
$tmpvalue = '';
$startdd = -1;
}
else
{
$tmpvalue .= $d;
}
}
}//for
//最后一个属性的给值
if($tmpatt != '')
{
$this->cAttributes->count++;
$this->cAttributes->items[$tmpatt] = trim($tmpvalue);
}//print_r($this->cAttributes->items);
}// end func
}
function private_rt($str)
{
$arr = explode('.', $str);
$rs = '$GLOBALS[\'';
if($arr[0] == 'cfg')
{
return $rs.'cfg_'.$arr[1]."']";
}
elseif($arr[0] == 'var')
{
$arr[0] = '_vars';
$rs .= implode('\'][\'', $arr);
$rs .= "']";
return $rs;
}
elseif($arr[0] == 'global')
{
unset($arr[0]);
$rs .= implode('\'][\'', $arr);
$rs .= "']";
return $rs;
}
else
{
if($arr[0] == 'field') $arr[0] = 'fields';
$rs = '$'.$arr[0]."['";
unset($arr[0]);
$rs .= implode('\'][\'', $arr);
$rs .= "']";
return $rs;
}
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -