当前位置: 网学 > 编程文档 > PHP > 正文

从康盛产品(discuz)提取出来的模板类

来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 13/06/22

以下是网学网为您推荐的PHP-从康盛产品(discuz)提取出来的模板类,希望本篇文章对您学习有所帮助。

复制代码 代码如下:
<?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();
}

网学推荐

免费论文

原创论文

浏览:
设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved
湘ICP备09003080号