forked from ctxyzhanwei/weixin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLocationTemplateBehavior.class.php
55 lines (53 loc) · 2.22 KB
/
LocationTemplateBehavior.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2012 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <[email protected]>
// +----------------------------------------------------------------------
defined('THINK_PATH') or exit();
/**
* 系统行为扩展:定位模板文件
* @category Think
* @package Think
* @subpackage Behavior
* @author liu21st <[email protected]>
*/
class LocationTemplateBehavior extends Behavior {
// 行为扩展的执行入口必须是run
public function run(&$templateFile){
// 自动定位模板文件
if(!file_exists_case($templateFile))
$templateFile = $this->parseTemplateFile($templateFile);
}
/**
* 自动定位模板文件
* @access private
* @param string $templateFile 文件名
* @return string
*/
private function parseTemplateFile($templateFile) {
if(''==$templateFile) {
// 如果模板文件名为空 按照默认规则定位
$templateFile = C('TEMPLATE_NAME');
}elseif(false === strpos($templateFile,C('TMPL_TEMPLATE_SUFFIX'))){
// 解析规则为 模板主题:模块:操作 不支持 跨项目和跨分组调用
$path = explode(':',$templateFile);
$action = array_pop($path);
$module = !empty($path)?array_pop($path):MODULE_NAME;
if(!empty($path)) {// 设置模板主题
$path = dirname(THEME_PATH).'/'.array_pop($path).'/';
}else{
$path = THEME_PATH;
}
$depr = defined('GROUP_NAME')?C('TMPL_FILE_DEPR'):'/';
$templateFile = $path.$module.$depr.$action.C('TMPL_TEMPLATE_SUFFIX');
}
if(!file_exists_case($templateFile))
throw_exception(L('_TEMPLATE_NOT_EXIST_').'['.$templateFile.']');
return $templateFile;
}
}