From 92fe8dd67a0f3bc4eb5ebabc1e68778ae9b75ef5 Mon Sep 17 00:00:00 2001 From: swh Date: 2017年2月17日 10:48:15 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=94=B9=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- helper.php | 12 ++++++------ library/think/App.php | 7 +++---- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/helper.php b/helper.php index da0dc9c5a8..784525dcb7 100644 --- a/helper.php +++ b/helper.php @@ -103,7 +103,7 @@ function lang($name, $vars = [], $lang = '') function config($name = '', $value = null, $range = '') { if (is_null($value) && is_string($name)) { - return 0 === strpos($name, '?') ? Config::has(substr($name, 1), $range) : Config::get($name, $range); + return isset($name[0]) && $name[0] == '?' ? Config::has(substr($name, 1), $range) : Config::get($name, $range); } else { return Config::set($name, $value, $range); } @@ -120,7 +120,7 @@ function config($name = '', $value = null, $range = '') */ function input($key = '', $default = null, $filter = '') { - if (0 === strpos($key, '?')) { + if (isset($key[0]) && $key[0] === '?') { $key = substr($key, 1); $has = true; } @@ -301,7 +301,7 @@ function session($name, $value = '', $prefix = null) Session::clear('' === $value ? null : $value); } elseif ('' === $value) { // 判断或获取 - return 0 === strpos($name, '?') ? Session::has(substr($name, 1), $prefix) : Session::get($name, $prefix); + return isset($name[0]) && $name[0] === '?' ? Session::has(substr($name, 1), $prefix) : Session::get($name, $prefix); } elseif (is_null($value)) { // 删除 return Session::delete($name, $prefix); @@ -330,7 +330,7 @@ function cookie($name, $value = '', $option = null) Cookie::clear($value); } elseif ('' === $value) { // 获取 - return 0 === strpos($name, '?') ? Cookie::has(substr($name, 1), $option) : Cookie::get($name, $option); + return isset($name[0]) && $name[0] === '?' ? Cookie::has(substr($name, 1), $option) : Cookie::get($name, $option); } elseif (is_null($value)) { // 删除 return Cookie::delete($name); @@ -363,11 +363,11 @@ function cache($name, $value = '', $options = null, $tag = null) return Cache::clear($value); } elseif ('' === $value) { // 获取缓存 - return 0 === strpos($name, '?') ? Cache::has(substr($name, 1)) : Cache::get($name); + return isset($name[0]) && $name[0] === '?' ? Cache::has(substr($name, 1)) : Cache::get($name); } elseif (is_null($value)) { // 删除缓存 return Cache::rm($name); - } elseif (0 === strpos($name, '?') && '' !== $value) { + } elseif (isset($name[0]) && $name[0] === '?' && '' !== $value) { $expire = is_numeric($options) ? $options : null; return Cache::remember(substr($name, 1), $value, $expire); } else { diff --git a/library/think/App.php b/library/think/App.php index 963d8b3527..dcc6e1f244 100644 --- a/library/think/App.php +++ b/library/think/App.php @@ -453,14 +453,13 @@ private static function init($module = '') { // 定位模块目录 $module = $module ? $module . DS : ''; - + $path = APP_PATH . $module; // 加载初始化文件 - if (is_file(APP_PATH . $module . 'init' . EXT)) { - include APP_PATH . $module . 'init' . EXT; + if (is_file($path . 'init' . EXT)) { + include $path . 'init' . EXT; } elseif (is_file(RUNTIME_PATH . $module . 'init' . EXT)) { include RUNTIME_PATH . $module . 'init' . EXT; } else { - $path = APP_PATH . $module; // 加载模块配置 $config = Config::load(CONF_PATH . $module . 'config' . CONF_EXT); // 读取数据库配置文件 From 97834f5bcc0a221497c4edcb29c019adc90abf71 Mon Sep 17 00:00:00 2001 From: swh Date: 2017年2月17日 10:51:47 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- helper.php | 10 +++++----- library/think/console/command/optimize/Autoload.php | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/helper.php b/helper.php index 784525dcb7..26b82271d8 100644 --- a/helper.php +++ b/helper.php @@ -120,7 +120,7 @@ function config($name = '', $value = null, $range = '') */ function input($key = '', $default = null, $filter = '') { - if (isset($key[0]) && $key[0] === '?') { + if (isset($key[0]) && $key[0] == '?') { $key = substr($key, 1); $has = true; } @@ -301,7 +301,7 @@ function session($name, $value = '', $prefix = null) Session::clear('' === $value ? null : $value); } elseif ('' === $value) { // 判断或获取 - return isset($name[0]) && $name[0] === '?' ? Session::has(substr($name, 1), $prefix) : Session::get($name, $prefix); + return isset($name[0]) && $name[0] == '?' ? Session::has(substr($name, 1), $prefix) : Session::get($name, $prefix); } elseif (is_null($value)) { // 删除 return Session::delete($name, $prefix); @@ -330,7 +330,7 @@ function cookie($name, $value = '', $option = null) Cookie::clear($value); } elseif ('' === $value) { // 获取 - return isset($name[0]) && $name[0] === '?' ? Cookie::has(substr($name, 1), $option) : Cookie::get($name, $option); + return isset($name[0]) && $name[0] == '?' ? Cookie::has(substr($name, 1), $option) : Cookie::get($name, $option); } elseif (is_null($value)) { // 删除 return Cookie::delete($name); @@ -363,11 +363,11 @@ function cache($name, $value = '', $options = null, $tag = null) return Cache::clear($value); } elseif ('' === $value) { // 获取缓存 - return isset($name[0]) && $name[0] === '?' ? Cache::has(substr($name, 1)) : Cache::get($name); + return isset($name[0]) && $name[0] == '?' ? Cache::has(substr($name, 1)) : Cache::get($name); } elseif (is_null($value)) { // 删除缓存 return Cache::rm($name); - } elseif (isset($name[0]) && $name[0] === '?' && '' !== $value) { + } elseif (isset($name[0]) && $name[0] == '?' && '' !== $value) { $expire = is_numeric($options) ? $options : null; return Cache::remember(substr($name, 1), $value, $expire); } else { diff --git a/library/think/console/command/optimize/Autoload.php b/library/think/console/command/optimize/Autoload.php index 7311aafb3b..3ac295aed5 100644 --- a/library/think/console/command/optimize/Autoload.php +++ b/library/think/console/command/optimize/Autoload.php @@ -266,9 +266,9 @@ protected function findClasses($path) $namespace = str_replace([' ', "\t", "\r", "\n"], '', $matches['nsname'][$i]) . '\\'; } else { $name = $matches['name'][$i]; - if ($name[0] === ':') { + if (isset($name[0]) && $name[0] == ':') { $name = 'xhp' . substr(str_replace(['-', ':'], ['_', '__'], $name), 1); - } elseif ($matches['type'][$i] === 'enum') { + } elseif ($matches['type'][$i] == 'enum') { $name = rtrim($name, ':'); } $classes[] = ltrim($namespace . $name, '\\'); From 57942f9e252510a40a2331a4a2d2baacfac38568 Mon Sep 17 00:00:00 2001 From: Wenhui Shen Date: Sun, 8 Apr 2018 11:44:05 +0800 Subject: [PATCH 3/3] =?UTF-8?q?include=20=E6=A8=A1=E6=9D=BF=E5=8D=A0?= =?UTF-8?q?=E4=BD=8D=E7=AC=A6=E6=9B=BF=E6=8D=A2=E8=A7=84=E5=88=99=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Template.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/library/think/Template.php b/library/think/Template.php index 9ba0ff35bf..5a54723df4 100644 --- a/library/think/Template.php +++ b/library/think/Template.php @@ -474,12 +474,30 @@ private function parseInclude(&$content) unset($array['file']); // 分析模板文件名并读取内容 $parseStr = $this->parseTemplateName($file); + //[SWH|+]删掉必须替换掉的占位符==\ + $mustReplaces = []; + $parseStr = preg_replace_callback('{^[\s]*<\\!\\-\\-[\s]*()[\s]*\\-\\->[\s]*}',function($p)use(&$mustReplaces){ + $mustReplaces = $this->parseAttr($p[1]); + return ''; + },$parseStr); + //===========================/ foreach ($array as $k => $v) { // 以$开头字符串转换成模板变量 if (0 === strpos($v, '$')) { $v = $this->get(substr($v, 1)); } $parseStr = str_replace('[' . $k . ']', $v, $parseStr); + if($mustReplaces && isset($mustReplaces[$k])) unset($mustReplaces[$k]);//[SWH|+]删掉必须替换掉的占位符 + } + //[SWH|+]删掉必须替换掉的占位符 + if($mustReplaces){ + foreach ($mustReplaces as $k => $v) { + // 以$开头字符串转换成模板变量 + if (0 === strpos($v, '$')) { + $v = $this->get(substr($v, 1)); + } + $parseStr = str_replace('[' . $k . ']', $v, $parseStr); + } } $content = str_replace($match[0], $parseStr, $content); // 再次对包含文件进行模板分析

AltStyle によって変換されたページ (->オリジナル) /