From 96af142bdc2cfa6a0208129563d5699625cef6d8 Mon Sep 17 00:00:00 2001 From: oldrind <1401019000@qq.com> Date: Fri, 15 Jan 2016 16:56:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=A0=87=E7=AD=BE=E7=9B=B4?= =?UTF-8?q?=E6=8E=A5=E4=BD=BF=E7=94=A8=E8=A1=A8=E8=BE=BE=E5=BC=8F=E6=97=B6?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2=E8=A2=AB=E5=A4=9A=E6=88=AA=E5=8F=96?= =?UTF-8?q?=E4=B8=80=E4=BD=8D=E7=9A=84bug=20=E6=B7=BB=E5=8A=A0switch?= =?UTF-8?q?=E5=92=8Ccase=E6=94=AF=E6=8C=81=E7=9B=B4=E6=8E=A5=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E8=A1=A8=E8=BE=BE=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Template.php | 26 +++++++++++++------------- library/think/template/TagLib.php | 7 +++---- library/think/template/taglib/Cx.php | 15 ++++++++------- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/library/think/Template.php b/library/think/Template.php index a101948d..ef4118d9 100644 --- a/library/think/Template.php +++ b/library/think/Template.php @@ -593,13 +593,13 @@ class Template $this->parseVar($str); $identify = isset($this->config['tpl_var_identify']) ? strtolower($this->config['tpl_var_identify']) : ''; switch ($identify) { - case 'array': + case 'array': $begin = 0; break; - case 'obj': + case 'obj': $begin = 1; break; - default: + default: // 如果是自动识别.语法,则要查找:之后的?号 $begin = strpos($str, ':'); } @@ -627,31 +627,31 @@ class Template } elseif ($begin || ')' == substr($name, -1, 1)) { // $name为对象或是自动识别,或者含有函数 switch ($first) { - case '?': + case '?': $str = ''; break; - case '=': + case '=': $str = ''; break; - default: + default: $str = ''; } } else { // $name为数组 switch ($first) { - case '?': + case '?': // {$varname??'xxx'} $varname有定义则输出$varname,否则输出xxx $str = ''; break; - case '=': + case '=': // {$varname?='xxx'} $varname为真时才输出xxx $str = ''; break; - case ':': + case ':': // {$varname?:'xxx'} $varname为真时输出$varname,否则输出xxx $str = ''; break; - default: + default: if (strpos($str, ':')) { // {$varname ? 'a' : 'b'} $varname为真时输出a,否则输出b $str = ''; @@ -730,7 +730,7 @@ class Template $parseStr = $first . '->' . implode('->', $vars); break; default: // 自动判断数组或对象 只支持二维 - $parseStr = 'is_array(' . $first . ')?' . $first . '[\'' . implode('\'][\'', $vars) . '\']:' . $first . '->' . implode('->', $vars); + $parseStr = '(is_array(' . $first . ')?' . $first . '[\'' . implode('\'][\'', $vars) . '\']:' . $first . '->' . implode('->', $vars) . ')'; } } } else { @@ -918,8 +918,8 @@ class Template if (false === strpos($template, '.')) { // 跨模块支持 $template = strpos($template, '@') ? - APP_PATH . str_replace('@', '/' . basename($this->config['tpl_path']) . '/', $template) . $this->config['tpl_suffix'] : - (defined('THEME_PATH') && substr_count($template, '/') < 2 ? THEME_PATH : $this->config['tpl_path']) . $template . $this->config['tpl_suffix']; + APP_PATH . str_replace('@', '/' . basename($this->config['tpl_path']) . '/', $template) . $this->config['tpl_suffix'] : + (defined('THEME_PATH') && substr_count($template, '/') < 2 ? THEME_PATH : $this->config['tpl_path']) . $template . $this->config['tpl_suffix']; } return $template; } diff --git a/library/think/template/TagLib.php b/library/think/template/TagLib.php index e7c97310..58d2b9b9 100644 --- a/library/think/template/TagLib.php +++ b/library/think/template/TagLib.php @@ -321,11 +321,10 @@ class TagLib if (!empty($this->tags[$tag]['expression'])) { static $_taglibs; if (!isset($_taglibs[$tag])) { - $_taglibs[$tag][0] = strlen($this->tpl->config('taglib_begin') . $tag); - $_taglibs[$tag][1] = strlen($this->tpl->config('taglib_end')); + $_taglibs[$tag][0] = strlen(ltrim($this->tpl->config('taglib_begin'), '\\') . $tag); + $_taglibs[$tag][1] = strlen(ltrim($this->tpl->config('taglib_end'), '\\')); } - $str = substr($str, $_taglibs[$tag][0], -$_taglibs[$tag][1]); - $result['expression'] = trim($str); + $result['expression'] = trim(substr($str, $_taglibs[$tag][0], -$_taglibs[$tag][1])); } elseif (empty($this->tags[$tag]) || !empty($this->tags[$tag]['attr'])) { throw new Exception('_XML_TAG_ERROR_:' . $tag); } diff --git a/library/think/template/taglib/Cx.php b/library/think/template/taglib/Cx.php index d772612d..377cb0b6 100644 --- a/library/think/template/taglib/Cx.php +++ b/library/think/template/taglib/Cx.php @@ -30,10 +30,10 @@ class Cx extends Taglib 'volist' => ['attr' => 'name,id,offset,length,key,mod', 'alias' => 'iterate'], 'foreach' => ['attr' => 'name,id,item,key,offset,length,mod', 'expression' => true], 'if' => ['attr' => 'condition', 'expression' => true], - 'elseif' => ['attr' => 'condition', 'close' => 0], + 'elseif' => ['attr' => 'condition', 'close' => 0, 'expression' => true], 'else' => ['attr' => '', 'close' => 0], - 'switch' => ['attr' => 'name'], - 'case' => ['attr' => 'value,break'], + 'switch' => ['attr' => 'name', 'expression' => true], + 'case' => ['attr' => 'value,break', 'expression' => true], 'default' => ['attr' => '', 'close' => 0], 'compare' => ['attr' => 'name,value,type', 'alias' => 'eq,equal,notequal,neq,gt,lt,egt,elt,heq,nheq'], 'range' => ['attr' => 'name,value,type', 'alias' => 'in,notin,between,notbetween'], @@ -251,7 +251,7 @@ class Cx extends Taglib */ public function _switch($tag, $content) { - $name = $tag['name']; + $name = !empty($tag['expression']) ? $tag['expression'] : $tag['name']; $name = $this->autoBuildVar($name); $parseStr = '' . $content . ''; return $parseStr; @@ -266,7 +266,7 @@ class Cx extends Taglib */ public function _case($tag, $content) { - $value = $tag['value']; + $value = !empty($tag['expression']) ? $tag['expression'] : $tag['value']; $flag = substr($value, 0, 1); if ('$' == $flag || ':' == $flag) { $value = $this->autoBuildVar($value); @@ -309,6 +309,7 @@ class Cx extends Taglib * @access public * @param array $tag 标签属性 * @param string $content 标签内容 + * @param string $type 比较类型 * @return string */ public function _compare($tag, $content, $type = 'eq') @@ -319,12 +320,12 @@ class Cx extends Taglib $name = $this->autoBuildVar($name); $flag = substr($value, 0, 1); if ('$' == $flag || ':' == $flag) { - $value = '(' . $this->autoBuildVar($value) . ')'; + $value = $this->autoBuildVar($value); } else { $value = '\'' . $value . '\''; } $type = $this->parseCondition(' ' . $type . ' '); - $parseStr = '' . $content . ''; + $parseStr = '' . $content . ''; return $parseStr; }