mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-09 11:44:10 +09:00
Add widget directive for Template v2
This commit is contained in:
parent
3e052d2d00
commit
e192bc0ff6
3 changed files with 22 additions and 7 deletions
|
|
@ -760,6 +760,7 @@ class TemplateParser_v2
|
||||||
* @dd($var, $var, ...)
|
* @dd($var, $var, ...)
|
||||||
* @stack('name')
|
* @stack('name')
|
||||||
* @url(['mid' => $mid, 'act' => $act])
|
* @url(['mid' => $mid, 'act' => $act])
|
||||||
|
* @widget('name', $args)
|
||||||
*
|
*
|
||||||
* @param string $content
|
* @param string $content
|
||||||
* @return string
|
* @return string
|
||||||
|
|
@ -773,7 +774,7 @@ class TemplateParser_v2
|
||||||
|
|
||||||
// Insert JSON, lang codes, and dumps.
|
// Insert JSON, lang codes, and dumps.
|
||||||
$parentheses = self::_getRegexpForParentheses(2);
|
$parentheses = self::_getRegexpForParentheses(2);
|
||||||
$content = preg_replace_callback('#(?<!@)@(json|lang|dump|stack|url)\x20?('. $parentheses . ')#', function($match) {
|
$content = preg_replace_callback('#(?<!@)@(json|lang|dump|dd|stack|url|widget)\x20?('. $parentheses . ')#', function($match) {
|
||||||
$args = self::_convertVariableScope(substr($match[2], 1, -1));
|
$args = self::_convertVariableScope(substr($match[2], 1, -1));
|
||||||
switch ($match[1])
|
switch ($match[1])
|
||||||
{
|
{
|
||||||
|
|
@ -791,6 +792,8 @@ class TemplateParser_v2
|
||||||
return sprintf('<?php echo implode("\n", self::\$_stacks[%s] ?? []) . "\n"; ?>', $args);
|
return sprintf('<?php echo implode("\n", self::\$_stacks[%s] ?? []) . "\n"; ?>', $args);
|
||||||
case 'url':
|
case 'url':
|
||||||
return sprintf('<?php echo $this->config->context === \'HTML\' ? getUrl(%s) : $this->_v2_escape(getNotEncodedUrl(%s)); ?>', $args, $args);
|
return sprintf('<?php echo $this->config->context === \'HTML\' ? getUrl(%s) : $this->_v2_escape(getNotEncodedUrl(%s)); ?>', $args, $args);
|
||||||
|
case 'widget':
|
||||||
|
return sprintf('<?php echo \WidgetController::getInstance()->execute(%s); ?>', $args);
|
||||||
default:
|
default:
|
||||||
return $match[0];
|
return $match[0];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -450,14 +450,21 @@ class WidgetController extends Widget
|
||||||
// Save for debug run-time widget
|
// Save for debug run-time widget
|
||||||
$start = microtime(true);
|
$start = microtime(true);
|
||||||
|
|
||||||
// urldecode the value of args haejum
|
// Type juggling
|
||||||
$object_vars = get_object_vars($args);
|
if (is_array($args))
|
||||||
if(count($object_vars))
|
|
||||||
{
|
{
|
||||||
foreach($object_vars as $key => $val)
|
$args = (object)$args;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply urldecode for backward compatibility
|
||||||
|
if ($escaped)
|
||||||
{
|
{
|
||||||
if(in_array($key, array('widgetbox_content','body','class','style','widget_sequence','widget','widget_padding_left','widget_padding_top','widget_padding_bottom','widget_padding_right','widgetstyle','document_srl'))) continue;
|
foreach (get_object_vars($args) ?: [] as $key => $val)
|
||||||
if($escaped) $args->{$key} = utf8RawUrlDecode($val);
|
{
|
||||||
|
if (!in_array($key, ['body', 'class', 'style', 'document_srl', 'widget', 'widget_sequence', 'widgetstyle', 'widgetbox_content', 'widget_padding_left', 'widget_padding_top', 'widget_padding_bottom', 'widget_padding_right']))
|
||||||
|
{
|
||||||
|
$args->{$key} = utf8RawUrlDecode($val);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1031,6 +1031,11 @@ class TemplateParserV2Test extends \Codeception\Test\Unit
|
||||||
$source = "@url('', 'mid', \$mid, 'act', \$act])";
|
$source = "@url('', 'mid', \$mid, 'act', \$act])";
|
||||||
$target = "<?php echo \$this->config->context === 'HTML' ? getUrl('', 'mid', \$__Context->mid, 'act', \$__Context->act]) : \$this->_v2_escape(getNotEncodedUrl('', 'mid', \$__Context->mid, 'act', \$__Context->act])); ?>";
|
$target = "<?php echo \$this->config->context === 'HTML' ? getUrl('', 'mid', \$__Context->mid, 'act', \$__Context->act]) : \$this->_v2_escape(getNotEncodedUrl('', 'mid', \$__Context->mid, 'act', \$__Context->act])); ?>";
|
||||||
$this->assertEquals($target, $this->_parse($source));
|
$this->assertEquals($target, $this->_parse($source));
|
||||||
|
|
||||||
|
// Widget
|
||||||
|
$source = "@widget('login_info', ['skin' => 'default'])";
|
||||||
|
$target = "<?php echo \WidgetController::getInstance()->execute('login_info', ['skin' => 'default']); ?>";
|
||||||
|
$this->assertEquals($target, $this->_parse($source));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testComments()
|
public function testComments()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue