mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 07:12:47 +08:00
Merge branch 'master' of https://github.com/top-think/think
This commit is contained in:
@@ -593,13 +593,13 @@ class Template
|
|||||||
$this->parseVar($str);
|
$this->parseVar($str);
|
||||||
$identify = isset($this->config['tpl_var_identify']) ? strtolower($this->config['tpl_var_identify']) : '';
|
$identify = isset($this->config['tpl_var_identify']) ? strtolower($this->config['tpl_var_identify']) : '';
|
||||||
switch ($identify) {
|
switch ($identify) {
|
||||||
case 'array':
|
case 'array':
|
||||||
$begin = 0;
|
$begin = 0;
|
||||||
break;
|
break;
|
||||||
case 'obj':
|
case 'obj':
|
||||||
$begin = 1;
|
$begin = 1;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// 如果是自动识别.语法,则要查找:之后的?号
|
// 如果是自动识别.语法,则要查找:之后的?号
|
||||||
$begin = strpos($str, ':');
|
$begin = strpos($str, ':');
|
||||||
}
|
}
|
||||||
@@ -627,31 +627,31 @@ class Template
|
|||||||
} elseif ($begin || ')' == substr($name, -1, 1)) {
|
} elseif ($begin || ')' == substr($name, -1, 1)) {
|
||||||
// $name为对象或是自动识别,或者含有函数
|
// $name为对象或是自动识别,或者含有函数
|
||||||
switch ($first) {
|
switch ($first) {
|
||||||
case '?':
|
case '?':
|
||||||
$str = '<?php echo ' . $name . ' ? ' . $name . ' : ' . substr($str, 1) . '; ?>';
|
$str = '<?php echo ' . $name . ' ? ' . $name . ' : ' . substr($str, 1) . '; ?>';
|
||||||
break;
|
break;
|
||||||
case '=':
|
case '=':
|
||||||
$str = '<?php if(' . $name . ') echo ' . substr($str, 1) . '; ?>';
|
$str = '<?php if(' . $name . ') echo ' . substr($str, 1) . '; ?>';
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$str = '<?php echo ' . $name . '?' . $str . '; ?>';
|
$str = '<?php echo ' . $name . '?' . $str . '; ?>';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// $name为数组
|
// $name为数组
|
||||||
switch ($first) {
|
switch ($first) {
|
||||||
case '?':
|
case '?':
|
||||||
// {$varname??'xxx'} $varname有定义则输出$varname,否则输出xxx
|
// {$varname??'xxx'} $varname有定义则输出$varname,否则输出xxx
|
||||||
$str = '<?php echo isset(' . $name . ') ? ' . $name . ' : ' . substr($str, 1) . '; ?>';
|
$str = '<?php echo isset(' . $name . ') ? ' . $name . ' : ' . substr($str, 1) . '; ?>';
|
||||||
break;
|
break;
|
||||||
case '=':
|
case '=':
|
||||||
// {$varname?='xxx'} $varname为真时才输出xxx
|
// {$varname?='xxx'} $varname为真时才输出xxx
|
||||||
$str = '<?php if(!empty(' . $name . ')) echo ' . substr($str, 1) . '; ?>';
|
$str = '<?php if(!empty(' . $name . ')) echo ' . substr($str, 1) . '; ?>';
|
||||||
break;
|
break;
|
||||||
case ':':
|
case ':':
|
||||||
// {$varname?:'xxx'} $varname为真时输出$varname,否则输出xxx
|
// {$varname?:'xxx'} $varname为真时输出$varname,否则输出xxx
|
||||||
$str = '<?php echo !empty(' . $name . ') ? ' . $name . $str . '; ?>';
|
$str = '<?php echo !empty(' . $name . ') ? ' . $name . $str . '; ?>';
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (strpos($str, ':')) {
|
if (strpos($str, ':')) {
|
||||||
// {$varname ? 'a' : 'b'} $varname为真时输出a,否则输出b
|
// {$varname ? 'a' : 'b'} $varname为真时输出a,否则输出b
|
||||||
$str = '<?php echo !empty(' . $name . ') ? ' . $str . '; ?>';
|
$str = '<?php echo !empty(' . $name . ') ? ' . $str . '; ?>';
|
||||||
@@ -730,7 +730,7 @@ class Template
|
|||||||
$parseStr = $first . '->' . implode('->', $vars);
|
$parseStr = $first . '->' . implode('->', $vars);
|
||||||
break;
|
break;
|
||||||
default: // 自动判断数组或对象 只支持二维
|
default: // 自动判断数组或对象 只支持二维
|
||||||
$parseStr = 'is_array(' . $first . ')?' . $first . '[\'' . implode('\'][\'', $vars) . '\']:' . $first . '->' . implode('->', $vars);
|
$parseStr = '(is_array(' . $first . ')?' . $first . '[\'' . implode('\'][\'', $vars) . '\']:' . $first . '->' . implode('->', $vars) . ')';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -918,8 +918,8 @@ class Template
|
|||||||
if (false === strpos($template, '.')) {
|
if (false === strpos($template, '.')) {
|
||||||
// 跨模块支持
|
// 跨模块支持
|
||||||
$template = strpos($template, '@') ?
|
$template = strpos($template, '@') ?
|
||||||
APP_PATH . str_replace('@', '/' . basename($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'];
|
(defined('THEME_PATH') && substr_count($template, '/') < 2 ? THEME_PATH : $this->config['tpl_path']) . $template . $this->config['tpl_suffix'];
|
||||||
}
|
}
|
||||||
return $template;
|
return $template;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -321,11 +321,10 @@ class TagLib
|
|||||||
if (!empty($this->tags[$tag]['expression'])) {
|
if (!empty($this->tags[$tag]['expression'])) {
|
||||||
static $_taglibs;
|
static $_taglibs;
|
||||||
if (!isset($_taglibs[$tag])) {
|
if (!isset($_taglibs[$tag])) {
|
||||||
$_taglibs[$tag][0] = strlen($this->tpl->config('taglib_begin') . $tag);
|
$_taglibs[$tag][0] = strlen(ltrim($this->tpl->config('taglib_begin'), '\\') . $tag);
|
||||||
$_taglibs[$tag][1] = strlen($this->tpl->config('taglib_end'));
|
$_taglibs[$tag][1] = strlen(ltrim($this->tpl->config('taglib_end'), '\\'));
|
||||||
}
|
}
|
||||||
$str = substr($str, $_taglibs[$tag][0], -$_taglibs[$tag][1]);
|
$result['expression'] = trim(substr($str, $_taglibs[$tag][0], -$_taglibs[$tag][1]));
|
||||||
$result['expression'] = trim($str);
|
|
||||||
} elseif (empty($this->tags[$tag]) || !empty($this->tags[$tag]['attr'])) {
|
} elseif (empty($this->tags[$tag]) || !empty($this->tags[$tag]['attr'])) {
|
||||||
throw new Exception('_XML_TAG_ERROR_:' . $tag);
|
throw new Exception('_XML_TAG_ERROR_:' . $tag);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,10 +30,10 @@ class Cx extends Taglib
|
|||||||
'volist' => ['attr' => 'name,id,offset,length,key,mod', 'alias' => 'iterate'],
|
'volist' => ['attr' => 'name,id,offset,length,key,mod', 'alias' => 'iterate'],
|
||||||
'foreach' => ['attr' => 'name,id,item,key,offset,length,mod', 'expression' => true],
|
'foreach' => ['attr' => 'name,id,item,key,offset,length,mod', 'expression' => true],
|
||||||
'if' => ['attr' => 'condition', 'expression' => true],
|
'if' => ['attr' => 'condition', 'expression' => true],
|
||||||
'elseif' => ['attr' => 'condition', 'close' => 0],
|
'elseif' => ['attr' => 'condition', 'close' => 0, 'expression' => true],
|
||||||
'else' => ['attr' => '', 'close' => 0],
|
'else' => ['attr' => '', 'close' => 0],
|
||||||
'switch' => ['attr' => 'name'],
|
'switch' => ['attr' => 'name', 'expression' => true],
|
||||||
'case' => ['attr' => 'value,break'],
|
'case' => ['attr' => 'value,break', 'expression' => true],
|
||||||
'default' => ['attr' => '', 'close' => 0],
|
'default' => ['attr' => '', 'close' => 0],
|
||||||
'compare' => ['attr' => 'name,value,type', 'alias' => 'eq,equal,notequal,neq,gt,lt,egt,elt,heq,nheq'],
|
'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'],
|
'range' => ['attr' => 'name,value,type', 'alias' => 'in,notin,between,notbetween'],
|
||||||
@@ -251,7 +251,7 @@ class Cx extends Taglib
|
|||||||
*/
|
*/
|
||||||
public function _switch($tag, $content)
|
public function _switch($tag, $content)
|
||||||
{
|
{
|
||||||
$name = $tag['name'];
|
$name = !empty($tag['expression']) ? $tag['expression'] : $tag['name'];
|
||||||
$name = $this->autoBuildVar($name);
|
$name = $this->autoBuildVar($name);
|
||||||
$parseStr = '<?php switch(' . $name . '): ?>' . $content . '<?php endswitch;?>';
|
$parseStr = '<?php switch(' . $name . '): ?>' . $content . '<?php endswitch;?>';
|
||||||
return $parseStr;
|
return $parseStr;
|
||||||
@@ -266,7 +266,7 @@ class Cx extends Taglib
|
|||||||
*/
|
*/
|
||||||
public function _case($tag, $content)
|
public function _case($tag, $content)
|
||||||
{
|
{
|
||||||
$value = $tag['value'];
|
$value = !empty($tag['expression']) ? $tag['expression'] : $tag['value'];
|
||||||
$flag = substr($value, 0, 1);
|
$flag = substr($value, 0, 1);
|
||||||
if ('$' == $flag || ':' == $flag) {
|
if ('$' == $flag || ':' == $flag) {
|
||||||
$value = $this->autoBuildVar($value);
|
$value = $this->autoBuildVar($value);
|
||||||
@@ -309,6 +309,7 @@ class Cx extends Taglib
|
|||||||
* @access public
|
* @access public
|
||||||
* @param array $tag 标签属性
|
* @param array $tag 标签属性
|
||||||
* @param string $content 标签内容
|
* @param string $content 标签内容
|
||||||
|
* @param string $type 比较类型
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function _compare($tag, $content, $type = 'eq')
|
public function _compare($tag, $content, $type = 'eq')
|
||||||
@@ -319,12 +320,12 @@ class Cx extends Taglib
|
|||||||
$name = $this->autoBuildVar($name);
|
$name = $this->autoBuildVar($name);
|
||||||
$flag = substr($value, 0, 1);
|
$flag = substr($value, 0, 1);
|
||||||
if ('$' == $flag || ':' == $flag) {
|
if ('$' == $flag || ':' == $flag) {
|
||||||
$value = '(' . $this->autoBuildVar($value) . ')';
|
$value = $this->autoBuildVar($value);
|
||||||
} else {
|
} else {
|
||||||
$value = '\'' . $value . '\'';
|
$value = '\'' . $value . '\'';
|
||||||
}
|
}
|
||||||
$type = $this->parseCondition(' ' . $type . ' ');
|
$type = $this->parseCondition(' ' . $type . ' ');
|
||||||
$parseStr = '<?php if((' . $name . ') ' . $type . ' ' . $value . '): ?>' . $content . '<?php endif; ?>';
|
$parseStr = '<?php if(' . $name . ' ' . $type . ' ' . $value . '): ?>' . $content . '<?php endif; ?>';
|
||||||
return $parseStr;
|
return $parseStr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user