This commit is contained in:
thinkphp
2016-01-15 18:23:06 +08:00
3 changed files with 24 additions and 24 deletions

View File

@@ -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 = '<?php echo ' . $name . ' ? ' . $name . ' : ' . substr($str, 1) . '; ?>';
break;
case '=':
case '=':
$str = '<?php if(' . $name . ') echo ' . substr($str, 1) . '; ?>';
break;
default:
default:
$str = '<?php echo ' . $name . '?' . $str . '; ?>';
}
} else {
// $name为数组
switch ($first) {
case '?':
case '?':
// {$varname??'xxx'} $varname有定义则输出$varname,否则输出xxx
$str = '<?php echo isset(' . $name . ') ? ' . $name . ' : ' . substr($str, 1) . '; ?>';
break;
case '=':
case '=':
// {$varname?='xxx'} $varname为真时才输出xxx
$str = '<?php if(!empty(' . $name . ')) echo ' . substr($str, 1) . '; ?>';
break;
case ':':
case ':':
// {$varname?:'xxx'} $varname为真时输出$varname,否则输出xxx
$str = '<?php echo !empty(' . $name . ') ? ' . $name . $str . '; ?>';
break;
default:
default:
if (strpos($str, ':')) {
// {$varname ? 'a' : 'b'} $varname为真时输出a,否则输出b
$str = '<?php echo !empty(' . $name . ') ? ' . $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;
}

View File

@@ -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);
}

View File

@@ -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 = '<?php switch(' . $name . '): ?>' . $content . '<?php endswitch;?>';
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 = '<?php if((' . $name . ') ' . $type . ' ' . $value . '): ?>' . $content . '<?php endif; ?>';
$parseStr = '<?php if(' . $name . ' ' . $type . ' ' . $value . '): ?>' . $content . '<?php endif; ?>';
return $parseStr;
}