You've already forked qlg.tsgz.moe
Init Repo
This commit is contained in:
164
thinkphp/library/think/view/driver/Php.php
Executable file
164
thinkphp/library/think/view/driver/Php.php
Executable file
@ -0,0 +1,164 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace think\view\driver;
|
||||
|
||||
use think\App;
|
||||
use think\exception\TemplateNotFoundException;
|
||||
use think\Loader;
|
||||
use think\Log;
|
||||
use think\Request;
|
||||
|
||||
class Php
|
||||
{
|
||||
// 模板引擎参数
|
||||
protected $config = [
|
||||
// 视图基础目录(集中式)
|
||||
'view_base' => '',
|
||||
// 模板起始路径
|
||||
'view_path' => '',
|
||||
// 模板文件后缀
|
||||
'view_suffix' => 'php',
|
||||
// 模板文件名分隔符
|
||||
'view_depr' => DS,
|
||||
];
|
||||
|
||||
public function __construct($config = [])
|
||||
{
|
||||
$this->config = array_merge($this->config, $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测是否存在模板文件
|
||||
* @access public
|
||||
* @param string $template 模板文件或者模板规则
|
||||
* @return bool
|
||||
*/
|
||||
public function exists($template)
|
||||
{
|
||||
if ('' == pathinfo($template, PATHINFO_EXTENSION)) {
|
||||
// 获取模板文件名
|
||||
$template = $this->parseTemplate($template);
|
||||
}
|
||||
return is_file($template);
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染模板文件
|
||||
* @access public
|
||||
* @param string $template 模板文件
|
||||
* @param array $data 模板变量
|
||||
* @return void
|
||||
*/
|
||||
public function fetch($template, $data = [])
|
||||
{
|
||||
if ('' == pathinfo($template, PATHINFO_EXTENSION)) {
|
||||
// 获取模板文件名
|
||||
$template = $this->parseTemplate($template);
|
||||
}
|
||||
// 模板不存在 抛出异常
|
||||
if (!is_file($template)) {
|
||||
throw new TemplateNotFoundException('template not exists:' . $template, $template);
|
||||
}
|
||||
// 记录视图信息
|
||||
App::$debug && Log::record('[ VIEW ] ' . $template . ' [ ' . var_export(array_keys($data), true) . ' ]', 'info');
|
||||
if (isset($data['template'])) {
|
||||
$__template__ = $template;
|
||||
extract($data, EXTR_OVERWRITE);
|
||||
include $__template__;
|
||||
} else {
|
||||
extract($data, EXTR_OVERWRITE);
|
||||
include $template;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染模板内容
|
||||
* @access public
|
||||
* @param string $content 模板内容
|
||||
* @param array $data 模板变量
|
||||
* @return void
|
||||
*/
|
||||
public function display($content, $data = [])
|
||||
{
|
||||
if (isset($data['content'])) {
|
||||
$__content__ = $content;
|
||||
extract($data, EXTR_OVERWRITE);
|
||||
eval('?>' . $__content__);
|
||||
} else {
|
||||
extract($data, EXTR_OVERWRITE);
|
||||
eval('?>' . $content);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 自动定位模板文件
|
||||
* @access private
|
||||
* @param string $template 模板文件规则
|
||||
* @return string
|
||||
*/
|
||||
private function parseTemplate($template)
|
||||
{
|
||||
if (empty($this->config['view_path'])) {
|
||||
$this->config['view_path'] = App::$modulePath . 'view' . DS;
|
||||
}
|
||||
|
||||
$request = Request::instance();
|
||||
// 获取视图根目录
|
||||
if (strpos($template, '@')) {
|
||||
// 跨模块调用
|
||||
list($module, $template) = explode('@', $template);
|
||||
}
|
||||
if ($this->config['view_base']) {
|
||||
// 基础视图目录
|
||||
$module = isset($module) ? $module : $request->module();
|
||||
$path = $this->config['view_base'] . ($module ? $module . DS : '');
|
||||
} else {
|
||||
$path = isset($module) ? APP_PATH . $module . DS . 'view' . DS : $this->config['view_path'];
|
||||
}
|
||||
|
||||
$depr = $this->config['view_depr'];
|
||||
if (0 !== strpos($template, '/')) {
|
||||
$template = str_replace(['/', ':'], $depr, $template);
|
||||
$controller = Loader::parseName($request->controller());
|
||||
if ($controller) {
|
||||
if ('' == $template) {
|
||||
// 如果模板文件名为空 按照默认规则定位
|
||||
$template = str_replace('.', DS, $controller) . $depr . $request->action();
|
||||
} elseif (false === strpos($template, $depr)) {
|
||||
$template = str_replace('.', DS, $controller) . $depr . $template;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$template = str_replace(['/', ':'], $depr, substr($template, 1));
|
||||
}
|
||||
return $path . ltrim($template, '/') . '.' . ltrim($this->config['view_suffix'], '.');
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置模板引擎
|
||||
* @access private
|
||||
* @param string|array $name 参数名
|
||||
* @param mixed $value 参数值
|
||||
* @return void
|
||||
*/
|
||||
public function config($name, $value = null)
|
||||
{
|
||||
if (is_array($name)) {
|
||||
$this->config = array_merge($this->config, $name);
|
||||
} elseif (is_null($value)) {
|
||||
return isset($this->config[$name]) ? $this->config[$name] : null;
|
||||
} else {
|
||||
$this->config[$name] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
165
thinkphp/library/think/view/driver/Think.php
Executable file
165
thinkphp/library/think/view/driver/Think.php
Executable file
@ -0,0 +1,165 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace think\view\driver;
|
||||
|
||||
use think\App;
|
||||
use think\exception\TemplateNotFoundException;
|
||||
use think\Loader;
|
||||
use think\Log;
|
||||
use think\Request;
|
||||
use think\Template;
|
||||
|
||||
class Think
|
||||
{
|
||||
// 模板引擎实例
|
||||
private $template;
|
||||
// 模板引擎参数
|
||||
protected $config = [
|
||||
// 视图基础目录(集中式)
|
||||
'view_base' => '',
|
||||
// 模板起始路径
|
||||
'view_path' => '',
|
||||
// 模板文件后缀
|
||||
'view_suffix' => 'html',
|
||||
// 模板文件名分隔符
|
||||
'view_depr' => DS,
|
||||
// 是否开启模板编译缓存,设为false则每次都会重新编译
|
||||
'tpl_cache' => true,
|
||||
];
|
||||
|
||||
public function __construct($config = [])
|
||||
{
|
||||
$this->config = array_merge($this->config, $config);
|
||||
if (empty($this->config['view_path'])) {
|
||||
$this->config['view_path'] = App::$modulePath . 'view' . DS;
|
||||
}
|
||||
|
||||
$this->template = new Template($this->config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测是否存在模板文件
|
||||
* @access public
|
||||
* @param string $template 模板文件或者模板规则
|
||||
* @return bool
|
||||
*/
|
||||
public function exists($template)
|
||||
{
|
||||
if ('' == pathinfo($template, PATHINFO_EXTENSION)) {
|
||||
// 获取模板文件名
|
||||
$template = $this->parseTemplate($template);
|
||||
}
|
||||
return is_file($template);
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染模板文件
|
||||
* @access public
|
||||
* @param string $template 模板文件
|
||||
* @param array $data 模板变量
|
||||
* @param array $config 模板参数
|
||||
* @return void
|
||||
*/
|
||||
public function fetch($template, $data = [], $config = [])
|
||||
{
|
||||
if ('' == pathinfo($template, PATHINFO_EXTENSION)) {
|
||||
// 获取模板文件名
|
||||
$template = $this->parseTemplate($template);
|
||||
}
|
||||
// 模板不存在 抛出异常
|
||||
if (!is_file($template)) {
|
||||
throw new TemplateNotFoundException('template not exists:' . $template, $template);
|
||||
}
|
||||
// 记录视图信息
|
||||
App::$debug && Log::record('[ VIEW ] ' . $template . ' [ ' . var_export(array_keys($data), true) . ' ]', 'info');
|
||||
$this->template->fetch($template, $data, $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染模板内容
|
||||
* @access public
|
||||
* @param string $template 模板内容
|
||||
* @param array $data 模板变量
|
||||
* @param array $config 模板参数
|
||||
* @return void
|
||||
*/
|
||||
public function display($template, $data = [], $config = [])
|
||||
{
|
||||
$this->template->display($template, $data, $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 自动定位模板文件
|
||||
* @access private
|
||||
* @param string $template 模板文件规则
|
||||
* @return string
|
||||
*/
|
||||
private function parseTemplate($template)
|
||||
{
|
||||
// 分析模板文件规则
|
||||
$request = Request::instance();
|
||||
// 获取视图根目录
|
||||
if (strpos($template, '@')) {
|
||||
// 跨模块调用
|
||||
list($module, $template) = explode('@', $template);
|
||||
}
|
||||
if ($this->config['view_base']) {
|
||||
// 基础视图目录
|
||||
$module = isset($module) ? $module : $request->module();
|
||||
$path = $this->config['view_base'] . ($module ? $module . DS : '');
|
||||
} else {
|
||||
$path = isset($module) ? APP_PATH . $module . DS . 'view' . DS : $this->config['view_path'];
|
||||
}
|
||||
|
||||
$depr = $this->config['view_depr'];
|
||||
if (0 !== strpos($template, '/')) {
|
||||
$template = str_replace(['/', ':'], $depr, $template);
|
||||
$controller = Loader::parseName($request->controller());
|
||||
if ($controller) {
|
||||
if ('' == $template) {
|
||||
// 如果模板文件名为空 按照默认规则定位
|
||||
$template = str_replace('.', DS, $controller) . $depr . $request->action();
|
||||
} elseif (false === strpos($template, $depr)) {
|
||||
$template = str_replace('.', DS, $controller) . $depr . $template;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$template = str_replace(['/', ':'], $depr, substr($template, 1));
|
||||
}
|
||||
return $path . ltrim($template, '/') . '.' . ltrim($this->config['view_suffix'], '.');
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置或者获取模板引擎参数
|
||||
* @access private
|
||||
* @param string|array $name 参数名
|
||||
* @param mixed $value 参数值
|
||||
* @return mixed
|
||||
*/
|
||||
public function config($name, $value = null)
|
||||
{
|
||||
if (is_array($name)) {
|
||||
$this->template->config($name);
|
||||
$this->config = array_merge($this->config, $name);
|
||||
} elseif (is_null($value)) {
|
||||
return $this->template->config($name);
|
||||
} else {
|
||||
$this->template->$name = $value;
|
||||
$this->config[$name] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
public function __call($method, $params)
|
||||
{
|
||||
return call_user_func_array([$this->template, $method], $params);
|
||||
}
|
||||
}
|
3
thinkphp/library/think/view/driver/tpl.php
Executable file
3
thinkphp/library/think/view/driver/tpl.php
Executable file
@ -0,0 +1,3 @@
|
||||
<?php
|
||||
header("Content-type: text/html; charset=utf-8");
|
||||
echo base64_decode("KiA9PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09DQogPGJyLz4qIFdTVE1hcnTlpJrnlKjmiLfllYbln44NCiA8YnIvPiog54mI5p2D5omA5pyJIDIwMTYtMjA2NiDlub/lt57llYbmt5jkv6Hmga/np5HmioDmnInpmZDlhazlj7jvvIzlubbkv53nlZnmiYDmnInmnYPliKnjgIINCiA8YnIvPiog5a6Y572R5Zyw5Z2AOmh0dHA6Ly93d3cud3N0bWFydC5uZXQNCiA8YnIvPiog5Lqk5rWB56S+5Yy6Omh0dHA6Ly9iYnMuc2hhbmd0YW9zb2Z0LmNvbQ0KIDxici8+KiDogZTns7tRUToxNTMyODk5NzANCiA8YnIvPiogLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLQ0KIDxici8+KiDov5nkuI3mmK/kuIDkuKroh6rnlLHova/ku7bvvIHmnKrnu4/mnKzlhazlj7jmjojmnYPmgqjlj6rog73lnKjkuI3nlKjkuo7llYbkuJrnm67nmoTnmoTliY3mj5DkuIvlr7nnqIvluo/ku6PnoIHov5vooYzkv67mlLnlkozkvb/nlKjvvJsNCiA8YnIvPiog5LiN5YWB6K645a+556iL5bqP5Luj56CB5Lul5Lu75L2V5b2i5byP5Lu75L2V55uu55qE55qE5YaN5Y+R5biD44CCDQogPGJyLz4qID09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0=");
|
Reference in New Issue
Block a user