国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

香港云服务器
服務器之家 - 編程語言 - PHP教程 - 從康盛產品(discuz)提取出來的模板類

從康盛產品(discuz)提取出來的模板類

2019-12-03 12:14PHP教程網 PHP教程

從康盛產品(discuz)提取出來的模板類,學習php的朋友可以參考下。

代碼如下:


<?php 
/*template.class.php 
@康盛微博 模板提取類 覺得這個模板好用 花些時間獨立出來。 by 雷日錦 
@看了一下ctt 這個模板 跟 phpcms的模板類似 難道?? ^_^ 嘿嘿!!! 
@ 微博 http://weibo.com/lrjxgl 
@ 好東西大家共享 磕磕絆絆的提取出來 有問題請提出來 
@ 模板文件默認為 .htm 
$tpl = new template('skin',"default"); 
$tpl->objdir='tpp'; 
$tpl->rewrite=true;//開啟rewrite 需要服務器支持 
$tpl->rewrite_rule=array(array("/index\.php/"),array("index.html")); //rewrite規則 
$tpl->assign("indexurl","index.php"); 
$tpl->assign("str","我是字符串啦啦啦"); 
$tpl->assign("ec","我是被echo出來的"); 
$tpl->assign("subhtml","{subtpl ttt}這是用來引入一個模板文件的,這個就是引入ttt.htm"); 
$tpl->assign("a",array('dasdasd'.'bbbbbbb','cccccccccccccc')); 
$tpl->assign("i",1); 
$tpl->display("index"); 
*/ 
if(!defined("CHARSET")) define("CHARSET","gb2312");//字符編碼 
if(!defined("DIR_TPL")) define("DIR_TPL","tpl");//默認模板目錄 
if(!defined("DIR_DATA")) define("DIR_DATA","data");//默認數據目錄 
if(!defined("DEBUG")) define("DEBUG",0);//默認運行模式 
class template { 
//note var 
public $rewrite=false;//是否開啟 偽靜態 rewrite 
public $rewrite_rule=array(); //設置偽靜態規則 
public $defaulttpldir;//默認的模板 
public $tpldir;//模板目錄 
public $objdir;//編譯緩存目錄 
public $tplfile;//模板文件 
public $objfile;//編譯文件 
public $tplid=1;//模板編號 
public $currdir='default';//當前風格目錄 
public $vars=array();//note 變量表 
public $removeblanks=false;//移除空格 
public $stdout='display';//輸出類型 
function __construct($tplid, $currdir) { 
$this->template($tplid, $currdir); 

function template($tplid, $currdir) { 
ob_start(); 
if(file_exists(DIR_TPL.'/'.$currdir)) { 
$this->currdir = $currdir; 
$this->tplid = $tplid; 
} else { 
$this->currdir = 'default'; 
$this->tplid = 1; 

$this->defaulttpldir = DIR_TPL.'/default'; 
$this->tpldir = DIR_TPL.'/'.$this->currdir; 
$this->objdir = DIR_DATA.'/cache/tpl'; 
if(version_compare(PHP_VERSION, '5') == -1) { 
register_shutdown_function(array(&$this, '__destruct')); 


//note publlic 
function assign($k, $v) { 
$this->vars[$k] = $v; 

//note publlic 
function display($file) { 
extract($this->vars, EXTR_SKIP); 
include $this->getObj($file); 

function getObj($file, $tpldir = '') { 
$subdir = ($pos = strpos($file, '/')) === false ? '' : substr($file, 0, $pos); 
$file = $subdir ? substr($file, $pos + 1) : $file; 
$this->tplfile = ($tpldir ? $tpldir : $this->tpldir).'/'.($subdir ? $subdir.'/' : '').$file.'.htm'; 
$this->objfile = $this->objdir.'/'.($tpldir ? '' : $this->tplid.'_').($subdir ? $subdir.'_' : '').$file.'.php'; 
//note 默認目錄 
if(@filemtime($this->tplfile) === FALSE) { 
$this->tplfile = $this->defaulttpldir.'/'.($subdir ? $subdir.'/' : '').$file.'.htm'; 

//note 判斷是否比較過期 
if(!file_exists($this->objfile) || DEBUG && @filemtime($this->objfile) < filemtime($this->tplfile)) { 
$this->compile(); 

return $this->objfile; 

function getTpl($file) { 
$subdir = ($pos = strpos($file, '/')) === false ? '' : substr($file, 0, $pos); 
$file = $subdir ? substr($file, $pos + 1) : $file; 
$tplfile = $this->tpldir.'/'.($subdir ? $subdir.'/' : '').$file.'.htm'; 
if(@filemtime($tplfile) === FALSE) { 
$tplfile = $this->defaulttpldir.'/'.($subdir ? $subdir.'/' : '').$file.'.htm'; 

return $tplfile; 

function compile() { 
$var_regexp = "\@?\\\$[a-zA-Z_]\w*(?:\[[\w\.\"\'\[\]\$]+\])*"; 
$vtag_regexp = "\<\?=(\@?\\\$[a-zA-Z_]\w*(?:\[[\w\.\"\'\[\]\$]+\])*)\?\>"; 
$const_regexp = "\{([\w]+)\}"; 
$template = file_get_contents($this->tplfile); 
for($i = 1; $i <= 3; $i++) { 
if(strpos($template, '{subtpl') !== FALSE) { 
if(DEBUG == 2) { 
$template = str_replace('{subtpl ', '{tpl ', $template); 
} else { 
$template = preg_replace("/[\n\r\t]*\{subtpl\s+([a-z0-9_:\/]+)\}[\n\r\t]*/ies", "file_get_contents(\$this->getTpl('\\1'))", $template); 



$remove = array( 
'/(^|\r|\n)\/\*.+?(\r|\n)\*\/(\r|\n)/is', 
'/\/\/note.+?(\r|\n)/i', 
'/\/\/debug.+?(\r|\n)/i', 
'/(^|\r|\n)(\s|\t)+/', 
'/(\r|\n)/', 
); 
$this->removeblanks && $template = preg_replace($remove, '', $template); 
$template = preg_replace("/\<\!\-\-\{(.+?)\}\-\-\>/s", "{\\1}", $template); 
$template = preg_replace("/\{($var_regexp)\}/", "<?=\\1?>", $template); 
$template = preg_replace("/\{($const_regexp)\}/", "<?=\\1?>", $template); 
$template = preg_replace("/(?<!\<\?\=|\\\\)$var_regexp/", "<?=\\0?>", $template); 
$template = preg_replace("/\<\?=(\@?\\\$[a-zA-Z_]\w*)((\[[\\$\[\]\w]+\])+)\?\>/ies", "\$this->arrayindex('\\1', '\\2')", $template); 
$template = preg_replace("/\{\{eval (.*?)\}\}/ies", "\$this->stripvtag('<? \\1?>')", $template); 
$template = preg_replace("/\{eval (.*?)\}/ies", "\$this->stripvtag('<? \\1?>')", $template); 
$template = preg_replace("/[\n\r\t]*\{echo\s+(.+?)\}[\n\r\t]*/ies", "\$this->stripvtag('<? echo \\1; ?>','')", $template); 
$template = preg_replace("/\{for (.*?)\}/ies", "\$this->stripvtag('<? for(\\1) {?>')", $template); 
$template = preg_replace("/\{elseif\s+(.+?)\}/ies", "\$this->stripvtag('<? } elseif(\\1) { ?>')", $template); 
for($i=0; $i<2; $i++) { 
$template = preg_replace("/\{loop\s+$vtag_regexp\s+$vtag_regexp\s+$vtag_regexp\}(.+?)\{\/loop\}/ies", "\$this->loopsection('\\1', '\\2', '\\3', '\\4')", $template); 
$template = preg_replace("/\{loop\s+$vtag_regexp\s+$vtag_regexp\}(.+?)\{\/loop\}/ies", "\$this->loopsection('\\1', '', '\\2', '\\3')", $template); 

$template = preg_replace("/\{if\s+(.+?)\}/ies", "\$this->stripvtag('<? if(\\1) { ?>')", $template); 
$template = preg_replace("/\{tpl\s+(\w+?)\}/is", "<? include \$this->getObj(\"\\1\");?>", $template); 
$template = preg_replace("/\{tpl\s+(.+?)\}/ise", "\$this->stripvtag('<? include \$this->getObj(\"\\1\"); ?>')", $template); 
$template = preg_replace("/\{tmptpl\s+(\w+?)\}/is", "<? include \$this->getObj(\"\\1\", \$this->objdir);?>", $template); 
$template = preg_replace("/\{tmptpl\s+(.+?)\}/ise", "\$this->stripvtag('<? include \$this->getObj(\"\\1\", \$this->objdir); ?>')", $template); 
$template = preg_replace("/\{else\}/is", "<? } else { ?>", $template); 
$template = preg_replace("/\{\/if\}/is", "<? } ?>", $template); 
$template = preg_replace("/\{\/for\}/is", "<? } ?>", $template); 
$template = preg_replace("/$const_regexp/", "<?=\\1?>", $template);//note {else} 也符合常量格式,此處要注意先后順序 
$template = preg_replace("/(\\\$[a-zA-Z_]\w+\[)([a-zA-Z_]\w+)\]/i", "\\1'\\2']", $template); 
$fp = fopen($this->objfile, 'w'); 
fwrite($fp, $template); 
fclose($fp); 

function arrayindex($name, $items) { 
$items = preg_replace("/\[([a-zA-Z_]\w*)\]/is", "['\\1']", $items); 
return "<?=$name$items?>"; 

function stripvtag($s) { 
$vtag_regexp = "\<\?=(\@?\\\$[a-zA-Z_]\w*(?:\[[\w\.\"\'\[\]\$]+\])*)\?\>"; 
return preg_replace("/$vtag_regexp/is", "\\1", str_replace("\\\"", '"', $s)); 

function loopsection($arr, $k, $v, $statement) { 
$arr = $this->stripvtag($arr); 
$k = $this->stripvtag($k); 
$v = $this->stripvtag($v); 
$statement = str_replace("\\\"", '"', $statement); 
return $k ? "<? foreach((array)$arr as $k => $v) {?>$statement<?}?>" : "<? foreach((array)$arr as $v) {?>$statement<? } ?>"; 

function __destruct() { 
$content = ob_get_contents(); 
//處理 rewrite 
if($this->rewrite) { 
$arr=$this->rewrite_rule; 
$s=$arr[0]; 
$e=$arr[1]; 
$content=preg_replace($s,$e,$content); 

ob_end_clean(); 
echo $content; 


$tpl = new template('skin',"default"); 
$tpl->objdir='tpp'; 
$tpl->rewrite=true;//開啟rewrite 需要服務器支持 
$tpl->rewrite_rule=array(array("/index\.php/"),array("index.html")); //rewrite規則 
$tpl->assign("indexurl","index.php"); 
$tpl->assign("str","我是字符串啦啦啦"); 
$tpl->assign("ec","我是被echo出來的"); 
$tpl->assign("subhtml","{subtpl ttt}這是用來引入一個模板文件的,這個就是引入ttt.htm"); 
$tpl->assign("a",array('dasdasd'.'bbbbbbb','cccccccccccccc')); 
$tpl->assign("i",1); 
$tpl->display("index"); 
?> 


新建 tpl/default/index.html 

復制代碼代碼如下:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
<title>無標題文檔</title> 
</head> 

<body> 
1.字符串賦值 :<br /> 
{$str} 
<br /> 
2.數組賦值 :<br /> 
{loop $a $v}{$v},{/loop} 
或者<br /> 
{loop $a $key $val }{$val},{/loop} 

3.{$subhtml}<br /> 
{subtpl ttt}<br /> 
4.原來我是{$indexurl } 現在我被變成了index.php<br /> 
5.我還可以 echo 出來呢<br /> 
{echo $ec}<br /> 
6.其實我還可以加減乘除的 6*7*8 
{echo 6*7*8;} 
7.常用的就這些了 還有什么不懂的 <br /> 

</body> 
</html> 


新建 tpl/default/ttt.html 
新建 tpp目錄 ok了

延伸 · 閱讀

精彩推薦
319
Weibo Article 1 Weibo Article 2 Weibo Article 3 Weibo Article 4 Weibo Article 5 Weibo Article 6 Weibo Article 7 Weibo Article 8 Weibo Article 9 Weibo Article 10 Weibo Article 11 Weibo Article 12 Weibo Article 13 Weibo Article 14 Weibo Article 15 Weibo Article 16 Weibo Article 17 Weibo Article 18 Weibo Article 19 Weibo Article 20 Weibo Article 21 Weibo Article 22 Weibo Article 23 Weibo Article 24 Weibo Article 25 Weibo Article 26 Weibo Article 27 Weibo Article 28 Weibo Article 29 Weibo Article 30 Weibo Article 31 Weibo Article 32 Weibo Article 33 Weibo Article 34 Weibo Article 35 Weibo Article 36 Weibo Article 37 Weibo Article 38 Weibo Article 39 Weibo Article 40
主站蜘蛛池模板: 亚洲精品日韩综合观看成人91 | 久久久久久久久久久久网站 | 国产精品成人国产乱一区 | www.av在线播放 | 日韩欧美在线看 | 久草视频观看 | 久久成人一区二区 | 91网站在线看 | 欧美日韩电影一区 | 亚洲成人av一区二区三区 | 国产麻豆乱码精品一区二区三区 | 羞羞av| 中文字幕精品一区 | 久久成人精品视频 | 色片视频免费 | 日韩中文字幕在线观看 | 九九九色 | 亚洲国产精品成人 | 国产黄大片 | 国产美女网站视频 | 好看的国产精彩视频 | 99免费在线播放99久久免费 | 亚洲一区二区免费视频 | 91麻豆产精品久久久久久 | 午夜视频播放 | 亚洲成av人影片在线观看 | 视频一区二区三区在线播放 | 亚洲精品久久 | 日韩成人一区二区 | 国厂毛片| 91成人看片 | 久久久久国产精品 | 久久久久久免费毛片精品 | 成人亚洲 | 另类在线 | 国产精品日韩欧美一区二区三区 | av中文字幕在线观看 | 日本精a在线观看 | 久久久久久国产免费 | 亚洲一区二区在线 | 亚洲日本在线观看视频 |