📄 pub_dedetag.php
字号:
$ResultString .= $this->CTags[$i]->GetValue();
$nextTagEnd = $this->CTags[$i]->EndPos;
}
}
$slen = strlen($this->SourceString);
if($slen>$nextTagEnd){
$ResultString .= substr($this->SourceString,$nextTagEnd,$slen-$nextTagEnd);
}
return $ResultString;
}
//把分析模板输出到一个字符串中,并返回
function GetResult()
{
$ResultString = "";
if($this->Count==-1){
return $this->SourceString;
}
$this->AssignSysTag();
$nextTagEnd = 0;
$strok = "";
for($i=0;$i<=$this->Count;$i++){
$ResultString .= substr($this->SourceString,$nextTagEnd,$this->CTags[$i]->StartPos-$nextTagEnd);
$ResultString .= $this->CTags[$i]->GetValue();
$nextTagEnd = $this->CTags[$i]->EndPos;
}
$slen = strlen($this->SourceString);
if($slen>$nextTagEnd){
$ResultString .= substr($this->SourceString,$nextTagEnd,$slen-$nextTagEnd);
}
return $ResultString;
}
//直接输出分析模板
function Display()
{
echo $this->GetResult();
}
//把分析模板输出为文件
function SaveTo($filename)
{
$fp = @fopen($filename,"w") or die("DedeTag Engine Create File False:$filename");
fwrite($fp,$this->GetResult());
fclose($fp);
}
//解析模板
function ParseTemplet()
{
$TagStartWord = $this->TagStartWord;
$TagEndWord = $this->TagEndWord;
$sPos = 0; $ePos = 0;
$FullTagStartWord = $TagStartWord.$this->NameSpace.":";
$sTagEndWord = $TagStartWord."/".$this->NameSpace.":";
$eTagEndWord = "/".$TagEndWord;
$tsLen = strlen($FullTagStartWord);
$sourceLen=strlen($this->SourceString);
if( $sourceLen <= ($tsLen + 3) ) return;
$cAtt = new DedeAttributeParse();
$cAtt->CharToLow = $this->CharToLow;
//遍历模板字符串,请取标记及其属性信息
for($i=0;$i<$sourceLen;$i++)
{
$tTagName = "";
$t = 0;
if($i>0) $t = $i - 1;
$sPos = strpos($this->SourceString,$FullTagStartWord,$t);
$isTag = $sPos;
if($i==0){
$headerTag = substr($this->SourceString,0,strlen($FullTagStartWord));
if($headerTag==$FullTagStartWord){ $isTag=true; $sPos=0; }
}
if($isTag===FALSE) break;
if($sPos > ($sourceLen-$tsLen-3) ) break;
for($j=($sPos+$tsLen);$j<($sPos+$tsLen+$this->TagMaxLen);$j++)
{
if($j>($sourceLen-1)) break;
else if(ereg("[ \t\r\n]",$this->SourceString[$j])
||$this->SourceString[$j] == $this->TagEndWord) break;
else $tTagName .= $this->SourceString[$j];
}
if(strtolower($tTagName)=="comments")
{
$endPos = strpos($this->SourceString,$sTagEndWord ."comments",$i);
if($endPos!==false) $i=$endPos+strlen($sTagEndWord)+8;
continue;
}
$i = $sPos+$tsLen;
$sPos = $i;
$fullTagEndWord = $sTagEndWord.$tTagName;
$endTagPos1 = strpos($this->SourceString,$eTagEndWord,$i);
$endTagPos2 = strpos($this->SourceString,$fullTagEndWord,$i);
$newStartPos = strpos($this->SourceString,$FullTagStartWord,$i);
if($endTagPos1===FALSE) $endTagPos1=0;
if($endTagPos2===FALSE) $endTagPos2=0;
if($newStartPos===FALSE) $newStartPos=0;
//判断用何种标记作为结束
if($endTagPos1>0 &&
($endTagPos1 < $newStartPos || $newStartPos==0) &&
($endTagPos1 < $endTagPos2 || $endTagPos2==0 ))
{
$ePos = $endTagPos1;
$i = $ePos + 2;
}
else if($endTagPos2>0){
$ePos = $endTagPos2;
$i = $ePos + strlen($fullTagEndWord)+1;
}
else{
echo "Parse error the tag ".($this->GetCount()+1)." $tTagName' is incorrect !<br/>";
}
//分析所找到的标记位置等信息
$attStr = "";
$innerText = "";
$startInner = 0;
for($j=$sPos;$j < $ePos;$j++)
{
if($startInner==0 && $this->SourceString[$j]==$TagEndWord)
{ $startInner=1; continue; }
if($startInner==0) $attStr .= $this->SourceString[$j];
else $innerText .= $this->SourceString[$j];
}
$cAtt->SetSource($attStr);
if($cAtt->CAttribute->GetTagName()!="")
{
$this->Count++;
$CDTag = new DedeTag();
$CDTag->TagName = $cAtt->CAttribute->GetTagName();
$CDTag->StartPos = $sPos - $tsLen;
$CDTag->EndPos = $i;
$CDTag->CAttribute = $cAtt->CAttribute;
$CDTag->IsReplace = FALSE;
$CDTag->TagID = $this->Count;
$CDTag->InnerText = $innerText;
$this->CTags[$this->Count] = $CDTag;
//定义函数或执行PHP语句
if( $CDTag->TagName == "define"){
@eval($CDTag->InnerText);
}
}
}//结束遍历模板字符串
if($this->IsCache) $this->SaveCache();
}
//处理某字段的函数
function EvalFunc($fieldvalue,$functionname)
{
$DedeFieldValue = $fieldvalue;
$functionname = str_replace("{\"","[\"",$functionname);
$functionname = str_replace("\"}","\"]",$functionname);
$functionname = eregi_replace("'@me'|\"@me\"|@me",'$DedeFieldValue',$functionname);
$functionname = "\$DedeFieldValue = ".$functionname;
eval($functionname.";"); //or die("<xmp>$functionname</xmp>");
if(empty($DedeFieldValue)) return "";
else return $DedeFieldValue;
}
//获得一个外部变量
function GetGlobals($varname)
{
$varname = trim($varname);
//禁止在模板文件读取数据库密码
if($varname=="dbuserpwd"||$varname=="cfg_dbpwd") return "";
//正常情况
if(isset($GLOBALS[$varname])) return $GLOBALS[$varname];
else return "";
}
//引入文件
function IncludeFile($filename,$ismake='no')
{
global $cfg_df_style;
$restr = "";
if(file_exists($filename)){ $okfile = $filename; }
else if( file_exists(dirname(__FILE__)."/".$filename) ){ $okfile = dirname(__FILE__)."/".$filename; }
else if( file_exists(dirname(__FILE__)."/../".$filename) ){ $okfile = dirname(__FILE__)."/../".$filename; }
else if( file_exists(dirname(__FILE__)."/../templets/".$filename) ){ $okfile = dirname(__FILE__)."/../templets/".$filename; }
else if( file_exists(dirname(__FILE__)."/../templets/".$cfg_df_style."/".$filename) ){ $okfile = dirname(__FILE__)."/../templets/".$cfg_df_style."/".$filename; }
else{ return "无法在这个位置找到: $filename"; }
//编译
if($ismake=="yes"){
require_once(dirname(__FILE__)."/inc_arcpart_view.php");
$pvCopy = new PartView();
$pvCopy->SetTemplet($okfile,"file");
$restr = $pvCopy->GetResult();
}else{
$fp = @fopen($okfile,"r");
while($line=fgets($fp,1024)) $restr.=$line;
fclose($fp);
}
return $restr;
}
}
/**********************************************
//class DedeAttribute Dede模板标记属性集合
function c____DedeAttribute();
**********************************************/
//属性的数据描述
class DedeAttribute
{
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____DedeAttributeParse();
********************************/
class DedeAttributeParse
{
var $SourceString = "";
var $SourceMaxSize = 1024;
var $CAttribute = ""; //属性的数据描述类
var $CharToLow = true;
//////设置属性解析器源字符串////////////////////////
function SetSource($str="")
{
$this->CAttribute = new DedeAttribute();
//////////////////////
$strLen = 0;
$this->SourceString = trim(preg_replace("/[ \t\r\n]{1,}/"," ",$str));
$strLen = strlen($this->SourceString);
if($strLen>0&&$strLen<=$this->SourceMaxSize){
$this->ParseAttribute();
}
}
//////解析属性(私有成员,仅给SetSource调用)/////////////////
function ParseAttribute()
{
$d = "";
$tmpatt="";
$tmpvalue="";
$startdd=-1;
$ddtag="";
$notAttribute=true;
$strLen = strlen($this->SourceString);
// 这里是获得Tag的名称,可视情况是否需要
// 如果不在这个里解析,则在解析整个Tag时解析
// 属性中不应该存在tagname这个名称
for($i=0;$i<$strLen;$i++)
{
$d = substr($this->SourceString,$i,1);
if($d==' '){
$this->CAttribute->Count++;
if($this->CharToLow) $this->CAttribute->Items["tagname"]=strtolower(trim($tmpvalue));
else $this->CAttribute->Items["tagname"]=trim($tmpvalue);
$tmpvalue = "";
$notAttribute = false;
break;
}
else
$tmpvalue .= $d;
}
//不存在属性列表的情况
if($notAttribute)
{
$this->CAttribute->Count++;
if($this->CharToLow) $this->CAttribute->Items["tagname"]=strtolower(trim($tmpvalue));
else $this->CAttribute->Items["tagname"]=trim($tmpvalue);
}
//如果字符串含有属性值,遍历源字符串,并获得各属性
if(!$notAttribute){
for($i;$i<$strLen;$i++)
{
$d = substr($this->SourceString,$i,1);
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 ' ':
continue;
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){
$this->CAttribute->Count++;
$this->CAttribute->Items[$tmpatt] = trim($tmpvalue);//strtolower(trim($tmpvalue));
$tmpatt = "";
$tmpvalue = "";
$startdd=-1;
}
else
$tmpvalue.=$d;
}
}//for
if($tmpatt!=""){
$this->CAttribute->Count++;
$this->CAttribute->Items[$tmpatt]=trim($tmpvalue);//strtolower(trim($tmpvalue));
}
}//完成属性解析//has Attribute
}// end func
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -