diff --git a/Think/Template.php b/Think/Template.php
index 8020388e..f41cb0e5 100644
--- a/Think/Template.php
+++ b/Think/Template.php
@@ -57,9 +57,12 @@ class Template {
$this->config['taglib_end'] = $this->stripPreg($this->config['taglib_end']);
$this->config['tpl_begin'] = $this->stripPreg($this->config['tpl_begin']);
$this->config['tpl_end'] = $this->stripPreg($this->config['tpl_end']);
- if($this->config['cache_type']) {
+ if($this->config['display_cache']) {
Cache::connect($this->config['cache_options']);
}
+ // 初始化模板编译存储器
+ $class = '\Think\Template\Driver\\'.$this->config['compile_type'];
+ $this->storage = new $class();
}
/**
@@ -120,17 +123,11 @@ class Template {
// 页面缓存
ob_start();
ob_implicit_flush(0);
- // 模板阵列变量分解成为独立变量
- extract($this->tVar, EXTR_OVERWRITE);
- if($this->handler) {
- echo substr(ThinkCache::get(md5($cacheFile)),12);
- }else{
- //载入模版缓存文件
- include $cacheFile;
- }
+ // 读取编译存储
+ $this->storage->read($cacheFile);
// 获取并清空缓存
$content = ob_get_clean();
- if($cacheId && $this->config['display_cache'] && $this->handler) {
+ if($cacheId && $this->config['display_cache']) {
// 缓存页面输出
Cache::set($cacheId,$content,$this->config['cache_time']);
}
@@ -152,18 +149,12 @@ class Template {
// 模板编译
$this->compiler($content,$cacheFile);
}
- // 模板阵列变量分解成为独立变量
- extract($this->tVar, EXTR_OVERWRITE);
- if($this->handler) {
- echo substr(Cache::get(md5($cacheFile)),12);
- }else{
- //载入模版缓存文件
- include $cacheFile;
- }
+ // 读取编译存储
+ $this->storage->read($cacheFile);
}
/**
- * 检查缓存文件是否有效
+ * 检查编译缓存是否有效
* 如果无效则需要重新编译
* @access private
* @param string $template 模板文件名
@@ -173,28 +164,12 @@ class Template {
private function checkCache($template,$cacheFile) {
if (!$this->config['tpl_cache']) // 优先对配置设定检测
return false;
- if($this->handler) {
- $data = Cache::get(md5($cacheFile));
- if(!$data) {
- return false;
- }elseif(is_file($template) && filemtime($template) > (int)substr($data,0, 12) ) {
- return false;
- }
- }else{
- if(!is_file($cacheFile)|| (is_file($template) && filemtime($template) > filemtime($cacheFile))) {
- // 模板文件如果有更新则缓存需要更新
- return false;
- }elseif ($this->config['cache_time'] != 0 && time() > filemtime($cacheFile)+$this->config['cache_time']) {
- // 缓存是否在有效期
- return false;
- }
- }
- // 缓存有效
- return true;
+ // 检查编译存储是否有效
+ return $this->storage->check($template,$cacheFile,$this->config['cache_time']);
}
public function isCache($cacheId){
- if($cacheId && $this->config['display_cache'] && $this->handler) {
+ if($cacheId && $this->config['display_cache']) {
// 缓存页面输出
return Cache::get($cacheId)?true:false;
}
@@ -223,17 +198,8 @@ class Template {
}
// 优化生成的php代码
$content = str_replace('?>config['cache_type']) {
- Cache::set(md5($cacheFile),sprintf('%012d',$_SERVER['REQUEST_TIME']).$content,$this->config['cache_time']);
- }else{
- // 检测模板目录
- $dir = dirname($cacheFile);
- if(!is_dir($dir))
- mkdir($dir,0755,true);
- // 生成模板缓存文件
- if( false === file_put_contents($cacheFile,$content))
- throw_exception('_CACHE_WRITE_ERROR_:'.$cacheFile);
- }
+ // 编译存储
+ $this->storage->write($cacheFile,$content);
return ;
}
@@ -463,8 +429,7 @@ class Template {
protected function parseTagLib($tagLib,&$content,$hide=false) {
$begin = $this->config['taglib_begin'];
$end = $this->config['taglib_end'];
- include __DIR__.'/template/driver/'.$tagLib.'.php';
- $className = 'Think\\Template\\Driver\\'.ucwords($tagLib);
+ $className = 'Think\\Template\\Taglib\\'.ucwords($tagLib);
$tLib = new $className;
foreach ($tLib->getTags() as $name=>$val){
$tags = [$name];
diff --git a/Think/Template/Driver/Attr.php b/Think/Template/Driver/Attr.php
deleted file mode 100644
index 302ae4ea..00000000
--- a/Think/Template/Driver/Attr.php
+++ /dev/null
@@ -1,382 +0,0 @@
-
-// +----------------------------------------------------------------------
-// $Id$
-namespace Think\Template\Driver;
-// 属性类型标签库
-class Attr extends \Think\TagLib{
- // 标签定义
- protected $tags = array(
- // 标签定义: attr 属性列表 close 是否闭合(0 或者1 默认1) alias 标签别名 level 嵌套层次
- 'attr'=>array('attr'=>'var,complex,type,default','close'=>0),
- );
-
- //
- public function _attr($tag,$content){
- $var = $tag['var'];
- $default = isset($tag['default'])?$tag['default']:1;
- $read = isset($tag['read'])?$tag['read']:false;
- if(!empty($tag['type'])) {
- $parse = $this->_{$tag['type']}($var);
- }else{
- $parse = ''.$this->_string($var,$default,$read);
- $parse .= ''.$this->_num($var,$default,$read);
- $parse .= ''.$this->_bool($var,$default,$read);
- $parse .= ''.$this->_textarea($var,$default,$read);
- $parse .= ''.$this->_text($var,$default,$read);
- $parse .= ''.$this->_editor($var,$default,$read);
- $parse .= ''.$this->_file($var,$read);
- $parse .= ''.$this->_files($var,$read);
- $parse .= ''.$this->_radio($var,$default,$read);
- $parse .= ''.$this->_checkbox($var,$default,$read);
- $parse .= ''.$this->_select($var,$default,$read);
- $parse .= ''.$this->_image($var,$read);
- $parse .= ''.$this->_images($var,$read);
- $parse .= ''.$this->_date($var,$default,$read);
- $parse .= ''.$this->_zone($var,$read);
- $parse .= ''.$this->_html($var,$read);
- $parse .= ''.$this->_dynamic($var,$read);
- $parse .= ''.$this->_hidden($var,$read);
- $parse .= ''.$this->_verify($var,$read);
- $parse .= ''.$this->_password($var,$default,$read);
- $parse .= ''.$this->_serialize($var,$read);
- $parse .= ''.$this->_link($var,$read);
- if(!empty($tag['complex'])) {
- $parse .= ''.$this->_complex($var,$read);
- }
- $parse .= '';
- }
- return $parse;
- }
-
- // 验证码类型
- protected function _verify($var) {
- $parse = '
';
- return $parse;
- }
-
- // 密码类型
- protected function _password($var,$default) {
- $value = $default?'{$'.$var.'.value}':'';
- $parse = ' ';
- return $parse;
- }
-
- // 字符串类型
- protected function _string($var,$default,$read) {
- $value = $default?'{$'.$var.'.value}':'';
- if($read) {
- $parse = $value;
- }else{
- $parse = ' ';
- }
- return $parse;
- }
-
- // 字符串类型
- protected function _link($var,$read) {
- $value = '{$'.$var.'.value}';
- if($read) {
- $parse = $value;
- }else{
- $parse = ' ';
- }
- return $parse;
- }
-
- // 数字类型
- protected function _num($var,$default,$read) {
- $value = $default?'{$'.$var.'.value}':'';
- if($read) {
- $parse = $value;
- }else{
- $parse = ' ';
- }
- return $parse;
- }
-
- // 布尔类型 采用下拉列表模拟
- protected function _bool($var,$default,$read) {
- if($read) {
- $parse = '';
- $parse = '';
- }else{
- $parse = ' ';
- }
- return $parse;
- }
-
- // 文本域类型
- protected function _textarea($var,$default,$read) {
- $value = $default?'{$'.$var.'.value}':'';
- if($read) {
- $parse = $value;
- }else{
- $parse = ' ';
- }
- return $parse;
- }
-
- // 文本型
- protected function _text($var,$default,$read) {
- $value = $default?'{$'.$var.'.value}':'';
- if($read) {
- $parse = $value;
- }else{
- $parse = '
- ';
- }
- return $parse;
- }
-
- // 编辑器型
- protected function _editor($var,$default,$read) {
- $value = $default?'{$'.$var.'.value}':'';
- if($read) {
- $parse = $value;
- }else{
- $parse = ' ';
- }
- return $parse;
- }
-
- // 附件上传型 可配置
- protected function _file($var) {
- $parse = '
';
- return $parse;
- }
-
- // 多附件型
- protected function _files($var) {
- $parse = '
- $array = explode(\',\',$'.$var.'[\'value\']);
-
-
- ';
- return $parse;
- }
-
- // 单选型
- // 选项1,选项2,...
- // 选项1:显示1,选项2:显示2,...
- // @model.id 调用模型
- // :fun 函数
- protected function _radio($var,$default) {
- $parse = '
- ';
- return $parse;
- }
-
- // 组合字段
- protected function _complex($var,$read) {
- if($read) {
- $parse = ' ';
- }else{
- $parse = ' ';
- }
- return $parse;
- }
-
- // 多选型 用多选下拉列表模拟 支持函数定义
- // 选项1,选项2,...
- // 选项1:显示1,选项2:显示2,...
- // @model.id 调用模型
- // :fun 函数
- protected function _checkbox($var,$default) {
- $parse = ' ';
- return $parse;
- }
-
- // 枚举型 采用下拉列表模拟
- // 选项1,选项2,...
- // 选项1:显示1,选项2:显示2,...
- // @model.id 调用模型
- // :fun 函数
- protected function _select($var,$default,$read) {
- if($read) {
- $parse = '
- $array = explode(\':\',$option);$value = $array[0];$show = isset($array[1])?$array[1]:$array[0];
-
- ';
- }else{
- $parse = ' ';
- }
- return $parse;
- }
-
- // 序列化型 只支持字符串类型
- // 字段名1:显示名称:样式,...
- protected function _serialize($var) {
- $parse = '
-
- $array = explode(\':\',$option);$var = $array[0];$show = isset($array[1])?$array[1]:\'\';$class = isset($array[2])?$array[2]:\'medium\';$value = $'.$var.'[\'value\'][$var];
- {$show}
- ';
- return $parse;
- }
-
- // 图片型 支持配置
- protected function _image($var,$read) {
- if($read) {
- $parse = 'parse_str($'.$var.'[\'extra\'],$extra);$array = explode(\',\',$extra[\'thumbPrefix\']);
-
-
';
- }else{
- $parse = ' ';
- }
- return $parse;
- }
-
- // 多图型
- protected function _images($var) {
- $parse = '
- $array = explode(\',\',$'.$var.'[\'value\']);
-
-
- ';
- return $parse;
- }
-
- // 日期型
- protected function _date($var,$default) {
- $parse = '';
- return $parse;
- }
-
- // 动态型 用方法控制输出显示
- protected function _dynamic($var) {
- $parse = '$fun = $'.$var.'[\'extra\'];echo $fun($'.$var.'[\'value\']); ';
- return $parse;
- }
-
- // 地区联动
- protected function _zone($var) {
- $parse = '
-
-
-
-
- ';
- return $parse;
- }
-
- // 固定值 采用隐藏字段模拟
- protected function _hidden($var) {
- $parse = ' ';
- return $parse;
- }
-
- // HTML型
- protected function _html($var) {
- $parse = '{$'.$var.'.value}';
- return $parse;
- }
-}
-?>
\ No newline at end of file
diff --git a/Think/Template/Driver/File.php b/Think/Template/Driver/File.php
new file mode 100644
index 00000000..e83906c8
--- /dev/null
+++ b/Think/Template/Driver/File.php
@@ -0,0 +1,45 @@
+
+// +----------------------------------------------------------------------
+// $Id$
+
+namespace Think\Template\Driver;
+class File {
+ // 写入编译缓存
+ public function write($cacheFile,$content){
+ // 检测模板目录
+ $dir = dirname($cacheFile);
+ if(!is_dir($dir))
+ mkdir($dir,0755,true);
+ // 生成模板缓存文件
+ if( false === file_put_contents($cacheFile,$content))
+ throw_exception('_CACHE_WRITE_ERROR_:'.$cacheFile);
+ }
+
+ // 读取编译编译
+ public function read($cacheFile,$vars){
+ // 模板阵列变量分解成为独立变量
+ extract($vars, EXTR_OVERWRITE);
+ //载入模版缓存文件
+ include $cacheFile;
+ }
+
+ // 检查编译缓存是否有效
+ public function check($template,$cacheFile,$cacheTime){
+ if(!is_file($cacheFile)|| (is_file($template) && filemtime($template) > filemtime($cacheFile))) {
+ // 模板文件如果有更新则缓存需要更新
+ return false;
+ }elseif ($cacheTime != 0 && time() > filemtime($cacheFile)+$cacheTime) {
+ // 缓存是否在有效期
+ return false;
+ }
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/Think/Template/Driver/Html.php b/Think/Template/Driver/Html.php
deleted file mode 100644
index 86990818..00000000
--- a/Think/Template/Driver/Html.php
+++ /dev/null
@@ -1,570 +0,0 @@
-
-// +----------------------------------------------------------------------
-// $Id: TagLibHtml.class.php 2730 2012-02-12 04:45:34Z liu21st $
-
-namespace Think\Template\Driver;
-/**
- +-------------------------------
- * Html标签库驱动
- +-------------------------------
- */
-class Html extends \Think\TagLib{
- // 标签定义
- protected $tags = array(
- // 标签定义: attr 属性列表 close 是否闭合(0 或者1 默认1) alias 标签别名 level 嵌套层次
- 'editor' => array('attr'=>'id,name,style,width,height,type','close'=>1),
- 'select' => array('attr'=>'name,options,values,output,multiple,id,size,first,change,selected,dblclick','close'=>0),
- 'grid' => array('attr'=>'id,pk,style,action,actionlist,show,datasource','close'=>0),
- 'list' => array('attr'=>'id,pk,style,action,actionlist,show,datasource,checkbox','close'=>0),
- 'imagebtn' => array('attr'=>'id,name,value,type,style,click','close'=>0),
- 'checkbox' => array('attr'=>'name,checkboxes,checked,separator','close'=>0),
- 'radio' => array('attr'=>'name,radios,checked,separator','close'=>0)
- );
-
- /**
- +----------------------------------------------------------
- * editor标签解析 插入可视化编辑器
- * 格式: {$vo.remark}
- +----------------------------------------------------------
- * @access public
- +----------------------------------------------------------
- * @param string $attr 标签属性
- +----------------------------------------------------------
- * @return string|void
- +----------------------------------------------------------
- */
- public function _editor($tag,$content) {
- $id = !empty($tag['id'])?$tag['id']: '_editor';
- $name = $tag['name'];
- $style = !empty($tag['style'])?$tag['style']:'';
- $width = !empty($tag['width'])?$tag['width']: '100%';
- $height = !empty($tag['height'])?$tag['height'] :'320px';
- // $content = $tag['content'];
- $type = $tag['type'] ;
- switch(strtoupper($type)) {
- case 'FCKEDITOR':
- $parseStr = ' ';
- break;
- case 'FCKMINI':
- $parseStr = ' ';
- break;
- case 'EWEBEDITOR':
- $parseStr = "";
- break;
- case 'NETEASE':
- $parseStr = '';
- break;
- case 'UBB':
- $parseStr = '';
- break;
- case 'KINDEDITOR':
- $parseStr = '';
- break;
- default :
- $parseStr = '';
- }
-
- return $parseStr;
- }
-
- /**
- +----------------------------------------------------------
- * imageBtn标签解析
- * 格式:
- +----------------------------------------------------------
- * @access public
- +----------------------------------------------------------
- * @param string $attr 标签属性
- +----------------------------------------------------------
- * @return string|void
- +----------------------------------------------------------
- */
- public function _imageBtn($tag) {
- $name = $tag['name']; //名称
- $value = $tag['value']; //文字
- $id = isset($tag['id'])?$tag['id']:''; //ID
- $style = isset($tag['style'])?$tag['style']:''; //样式名
- $click = isset($tag['click'])?$tag['click']:''; //点击
- $type = empty($tag['type'])?'button':$tag['type']; //按钮类型
-
- if(!empty($name)) {
- $parseStr = '';
- }else {
- $parseStr = '';
- }
-
- return $parseStr;
- }
-
- /**
- +----------------------------------------------------------
- * imageLink标签解析
- * 格式:
- +----------------------------------------------------------
- * @access public
- +----------------------------------------------------------
- * @param string $attr 标签属性
- +----------------------------------------------------------
- * @return string|void
- +----------------------------------------------------------
- */
- public function _imgLink($tag) {
- $name = $tag['name']; //名称
- $alt = $tag['alt']; //文字
- $id = $tag['id']; //ID
- $style = $tag['style']; //样式名
- $click = $tag['click']; //点击
- $type = $tag['type']; //点击
- if(empty($type)) {
- $type = 'button';
- }
- $parseStr = '';
-
- return $parseStr;
- }
-
- /**
- +----------------------------------------------------------
- * select标签解析
- * 格式:
- +----------------------------------------------------------
- * @access public
- +----------------------------------------------------------
- * @param string $attr 标签属性
- +----------------------------------------------------------
- * @return string|void
- +----------------------------------------------------------
- */
- public function _select($tag) {
- $name = $tag['name'];
- $options = $tag['options'];
- $values = $tag['values'];
- $output = $tag['output'];
- $multiple = $tag['multiple'];
- $id = $tag['id'];
- $size = $tag['size'];
- $first = $tag['first'];
- $selected = $tag['selected'];
- $style = $tag['style'];
- $ondblclick = $tag['dblclick'];
- $onchange = $tag['change'];
-
- if(!empty($multiple)) {
- $parseStr = '