谁能帮忙注释下代码。有研究代码的来看ia谢谢了

cash2914 2010-12-07 05:19:11

function loadTempletFile($file,$refresh=false) {
global $royalfield,$messageStack;
$cachedir = DIR_FS_ROOT.'cache/templets/'.md5(strtolower(dirname($file))).'/';
$cachename = $cachedir.basename($file).'.php';
if(!$refresh&&is_file($cachename)&&filemtime($cachename)>filemtime($file)&&filemtime($cachename)>time()-864000){
return file_get_contents($cachename);
} else {
$filestr = $this->parseFileString($file);
$shiftpos = 0;
$this->templetstring = '<?php if(!defined("ROYALERP_INCLUDE")) die("<a href=\'http://www.royalerp.com\'>RoyalERP.com</a>");?>'.$this->loadTempletString($filestr,$shiftpos);
$this->templetstring = parseTagInnerHTML($this->templetstring,'royalfield',$default);

@mkdir_r($cachedir);
if(is_writable($cachedir)){
$fp = @fopen($cachename,"w") or die("RoaylERP Create File False");
fwrite($fp,$this->templetstring);
fclose($fp);
}
if ($messageStack->size > 0) {
$this->templetstring.= $messageStack->output();
}
return $this->templetstring;
}
}
function loadTempletFileString($data){
global $royalfield;
$filestr = $this->parseFileString($data,true);
$shiftpos = 0;
$this->templetstring = $this->loadTempletString($filestr,$shiftpos);
$this->templetstring = parseTagInnerHTML($this->templetstring,'royalfield',$default);
return $this->templetstring;
}
function parseFileString($file,$istext=false) {
if($istext){
$filestr= $file;
} else {
$filestr= ' '.file_get_contents($file);
}
$startpos = 0;
$includepos = strpos($filestr,'<include:',$startpos);
while(false!==$includepos) {
if($includepos>$startpos) {
$string=substr($filestr,$startpos,$includepos-1);
$spacepos = strpos($filestr,' ',$includepos);
if($spacepos>$includepos+9){
$tagname = substr($filestr,$includepos+9,$spacepos-$includepos-9);
$filenamepos = strpos($filestr,'filename',$includepos);
$filenamelastpos = strpos($filestr,'>',$includepos);
if($filestr[$filenamelastpos-1]=='/'){
$filenamelastpos++;
$tmpstr = substr($filestr,$filenamepos,$filenamelastpos-$filenamepos);
} else {
$filenamelastpos = strpos($filestr,'</include:'.$tagname.'>',$includepos);
$filenamelastpos += strlen($tagname)+11;
$tmpstr = substr($filestr,$filenamepos,$filenamelastpos-$filenamepos);
}

$filenames = explode('"',$tmpstr,3);
$tfile = DIR_FS_ROOT.'templets/'.DEFAULT_CSS_PATH.'/'.($tagname==''?'':$tagname.'/').$filenames[1];
if(file_exists($tfile)) {
$loadstring = file_get_contents($tfile);
} else {
$loadstring = "";
}
$laststring = substr($filestr,$filenamelastpos);
$filestr = $string . $loadstring .$laststring;
}
}
if($startpos<strlen($filestr)) {
$includepos = strpos($filestr,'<include:',$startpos);
} else {
break;
}
}
return trim($filestr);
}
function loadTempletString(&$filestr,&$shiftpos,$issub=false) {
$lastpos = $shiftpos;
$strlen = strlen($filestr);
$ret = "";
while ($shiftpos<$strlen) {
$matchs = array();
$subret = "";
if($filestr[$shiftpos]=='<'&&preg_match($this->reg_match_string,substr($filestr,$shiftpos,$this->maxtaglen+3),$matchs)) { //find
if($shiftpos>$lastpos){
$ret.=substr($filestr,$lastpos,$shiftpos-$lastpos);
$lastpos = $shiftpos;
}
$matchlen = strlen($matchs[0]);
$currenttag = substr($matchs[0],1,$matchlen-2);
$shiftpos+=$matchlen;

$index1 = strpos($filestr,' ',$shiftpos)-$shiftpos;
$index2 = strpos($filestr,'/>',$shiftpos)-$shiftpos;
$index3x = strpos($filestr,'>',$shiftpos);
$index3 = $index3x-$shiftpos;
if($index1<0)$index1=100000;
if($index2<0)$index2=100000;
if($index3<0)$index3=100000;
$minindex = min(min($index1,$index2),$index3);
$tagclass = substr($filestr,$shiftpos,$minindex);
$tagstring = '<'.$currenttag.':'.$tagclass;
$shiftpos+=strlen($tagclass);

while($shiftpos<$strlen){
if(substr($filestr,$shiftpos,2)=='/>'){ //tag end
if($shiftpos<=$index3x){
$tagstring.='>';
$ret.=$this->parseTempletTag($tagstring.'</'.substr($matchs[0],1).$tagclass.'>',$currenttag,$tagclass); //trans standard
$shiftpos+=2;
if($issub){
return $ret;
} else {
$lastpos = $shiftpos;
break;
}
} else {
$tagstring.=$filestr[$shiftpos];
$shiftpos++;
}
} else if(substr($filestr,$shiftpos,strlen('</'.substr($matchs[0],1).$tagclass.'>'))=='</'.substr($matchs[0],1).$tagclass.'>'){
$ret.=$this->parseTempletTag($tagstring.'</'.substr($matchs[0],1).$tagclass.'>',$currenttag,$tagclass);
$shiftpos+=strlen(substr($matchs[0],1).$tagclass)+3;
if($issub){
return $ret;
} else {
$lastpos = $shiftpos;
break;
}
} else if($filestr[$shiftpos]=='<'&&preg_match($this->reg_match_string,substr($filestr,$shiftpos,$this->maxtaglen+3))) {//enbed tag
$tmp = $this->loadTempletString($filestr,$shiftpos,true);
$subret.=$tmp;
$tagstring.=$tmp;
} else {
$tagstring.=$filestr[$shiftpos];
$shiftpos++;
}
}
} else {
$shiftpos++;
}
}
if($shiftpos>$lastpos){
$ret.=substr($filestr,$lastpos,$shiftpos-$lastpos);
$lastpos = $shiftpos;
}
return $ret;
}
function parseTempletTag($tagstring,$namespace='',$tagname=''){
global $db;
$pos = strpos($tagstring,'>');
require_once(DIR_FS_CLASSES.'xml.php');
$xml = new RoyalXmlParser();
$string = substr($tagstring,0,$pos);
if(substr($string,'-1')=='/')$string = substr($string,0,$pos-1);
$xml->parseString($string.'></'.$namespace.':'.$tagname.'>');
$tagarray = $xml->getTree();
$tagarray = $tagarray[$namespace.':'.$tagname];
switch ($namespace) {
case 'fun':
if(eip_not_null($tagarray['params'])){
$phpstring = '<?php echo '.$tagname.'('.$tagarray['params'].');?>';
} else {
$phpstring = '<?php echo '.$tagname.';?>';
}
return $phpstring;
case 'const':
return '<?php echo '.$tagname.';?>';
case 'exp':
return '<?php '.$tagname.';?>';
case 'var':
if(isset($tagarray['params'])&&$tagarray['params']!=""){
return '<?php echo $'.$tagname.'["'.$tagarray['params'].'"];?>';
}
return '<?php echo $'.$tagname.';?>';
case 'field':
return '<?php echo $royalfield["'.$tagname.'"];?>';
case 'sys':
$tagarray['innerHTML'] = substr($tagstring,$pos+1,strlen($tagstring)-strlen('</'.$namespace.':'.$tagname.'>')-$pos-1);
if(file_exists(DIR_FS_INCLUDES.'/tags/tag_'.$tagname.'.php')){
include_once(DIR_FS_INCLUDES.'/tags/tag_'.$tagname.'.php');
$funcname = $namespace.'_'.$tagname.'_tag';
$retvalue = "";
if($funcname($tagarray,$retvalue)){
return $retvalue;
}
} else {
return '';
}
default:
$tagarray['innerHTML'] = substr($tagstring,$pos+1,strlen($tagstring)-strlen('</'.$namespace.':'.$tagname.'>')-$pos-1);
if(file_exists(DIR_FS_ROOT.$namespace.'/tags/tag_'.$tagname.'.php')){
include_once(DIR_FS_ROOT.$namespace.'/tags/tag_'.$tagname.'.php');
$funcname = $namespace.'_'.$tagname.'_tag';
$retvalue = "";
if($funcname($tagarray,$retvalue)){
return $retvalue;
}
} else {
return '';
}
}
}
}
?>


...全文
137 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
yun3948 2011-01-03
  • 打赏
  • 举报
回复
我看了头晕了
li861115 2010-12-20
  • 打赏
  • 举报
回复
看不明白
LKK 2010-12-20
  • 打赏
  • 举报
回复
好长的代码。。
seai 2010-12-20
  • 打赏
  • 举报
回复
一套模板引擎吧

无非就是加载模板分析模板那些东东,有些关键代码没有,更具体的注释没法写
caomoba 2010-12-20
  • 打赏
  • 举报
回复


咋说呢! 代码长了看着头晕


都市社区
baizhongwei 2010-12-09
  • 打赏
  • 举报
回复
一个模板引擎?
helloyou0 2010-12-09
  • 打赏
  • 举报
回复
大家都和你一样懒.......
在-云端 2010-12-07
  • 打赏
  • 举报
回复
注释还是你自己动手写吧!
哎~~现在csdn上的伸手党越来越多了!
沪php攻城师 2010-12-07
  • 打赏
  • 举报
回复
这么长代码。。。。
看函数名字是获得临时文件。。。

4,249

社区成员

发帖
与我相关
我的任务
社区描述
国内外优秀PHP框架讨论学习
社区管理员
  • Framework
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧