openrat-cms

# OpenRat Content Management System
git clone http://git.code.weiherhei.de/openrat-cms.git
Log | Files | Refs

commit ac5465ed919577b7218eb9d04976efa973c59c44
parent a16be74191129f4a07b032be95a3d307dd268342
Author: Jan Dankert <develop@jandankert.de>
Date:   Thu, 27 Feb 2020 22:30:13 +0100

New: ValueExpressions are able to contain other Value objects. Now data-driven messages are possible again :)

Diffstat:
modules/cms/ui/themes/default/html/views/element/info.php | 2+-
modules/cms/ui/themes/default/html/views/folder/advanced.php | 2+-
modules/cms/ui/themes/default/html/views/group/rights.php | 2+-
modules/cms/ui/themes/default/html/views/object/aclform.php | 2+-
modules/cms/ui/themes/default/html/views/object/rights.php | 2+-
modules/cms/ui/themes/default/html/views/page/edit.php | 2+-
modules/cms/ui/themes/default/html/views/page/info.php | 2+-
modules/cms/ui/themes/default/html/views/pageelement/info.php | 2+-
modules/cms/ui/themes/default/html/views/pageelement/prop.php | 2+-
modules/cms/ui/themes/default/html/views/project/edit.php | 2+-
modules/cms/ui/themes/default/html/views/template/edit.php | 2+-
modules/cms/ui/themes/default/html/views/user/rights.php | 2+-
modules/template_engine/components/html/text/Text.class.php | 2+-
modules/template_engine/element/Value.class.php | 45++++++++++++++++++++++++++++-----------------
modules/template_engine/element/ValueExpression.class.php | 27++++++++++++++++++---------
15 files changed, 59 insertions(+), 39 deletions(-)

diff --git a/modules/cms/ui/themes/default/html/views/element/info.php b/modules/cms/ui/themes/default/html/views/element/info.php @@ -14,7 +14,7 @@ <td> <i class="image-icon image-icon--action-el_<?php echo encodeHtml(htmlentities(@$type)) ?>"> </i> - <span><?php echo encodeHtml(htmlentities(@lang('${type'))) ?>} + <span><?php echo encodeHtml(htmlentities(@lang(''.@$type.''))) ?> </span> </td> </tr> diff --git a/modules/cms/ui/themes/default/html/views/folder/advanced.php b/modules/cms/ui/themes/default/html/views/folder/advanced.php @@ -95,7 +95,7 @@ <label class="label"> <span> </span> - <span><?php echo encodeHtml(htmlentities(@lang('${actiontype'))) ?>} + <span><?php echo encodeHtml(htmlentities(@lang(''.@$actiontype.''))) ?> </span> </label> </div> diff --git a/modules/cms/ui/themes/default/html/views/group/rights.php b/modules/cms/ui/themes/default/html/views/group/rights.php @@ -45,7 +45,7 @@ </td> <?php foreach($show as $list_key=>$t) { ?> <td class="help"> - <span title="message:acl<?php echo encodeHtml(htmlentities()) ?>"><?php echo encodeHtml(htmlentities(@lang('${t'))) ?>} + <span title="message:acl<?php echo encodeHtml(htmlentities()) ?>"><?php echo encodeHtml(htmlentities(@lang(''.@$t.''))) ?> </span> </td> <?php } ?> diff --git a/modules/cms/ui/themes/default/html/views/object/aclform.php b/modules/cms/ui/themes/default/html/views/object/aclform.php @@ -122,7 +122,7 @@ <input type="checkbox" name="<?php echo encodeHtml(htmlentities(@$t)) ?>" value="1" <?php if(@$${t}){ ?>checked="1"<?php } ?> /> <?php } ?> <label class="label"> - <span><?php echo encodeHtml(htmlentities(@lang('${t'))) ?>} + <span><?php echo encodeHtml(htmlentities(@lang(''.@$t.''))) ?> </span> </label> </div> diff --git a/modules/cms/ui/themes/default/html/views/object/rights.php b/modules/cms/ui/themes/default/html/views/object/rights.php @@ -23,7 +23,7 @@ </td> <?php foreach($show as $list_key=>$t) { ?> <td class="help"> - <span><?php echo encodeHtml(htmlentities(@lang('${t'))) ?>} + <span><?php echo encodeHtml(htmlentities(@lang(''.@$t.''))) ?> </span> </td> <?php } ?> diff --git a/modules/cms/ui/themes/default/html/views/page/edit.php b/modules/cms/ui/themes/default/html/views/page/edit.php @@ -45,7 +45,7 @@ <td> <i class="image-icon image-icon--action-el_<?php echo encodeHtml(htmlentities(@$typename)) ?>"> </i> - <span><?php echo encodeHtml(htmlentities(@lang('${typename'))) ?>} + <span><?php echo encodeHtml(htmlentities(@lang(''.@$typename.''))) ?> </span> </td> </tr> diff --git a/modules/cms/ui/themes/default/html/views/page/info.php b/modules/cms/ui/themes/default/html/views/page/info.php @@ -17,7 +17,7 @@ </span> </div> <div class="input"> - <span><?php echo encodeHtml(htmlentities(@lang('${type'))) ?>} + <span><?php echo encodeHtml(htmlentities(@lang(''.@$type.''))) ?> </span> </div> </div> diff --git a/modules/cms/ui/themes/default/html/views/pageelement/info.php b/modules/cms/ui/themes/default/html/views/pageelement/info.php @@ -34,7 +34,7 @@ <td class="filename"> <i class="image-icon image-icon--action-el_<?php echo encodeHtml(htmlentities(@$element_type)) ?>"> </i> - <span><?php echo encodeHtml(htmlentities(@lang('el_${element_type'))) ?>} + <span><?php echo encodeHtml(htmlentities(@lang('el_'.@$element_type.''))) ?> </span> </td> </tr> diff --git a/modules/cms/ui/themes/default/html/views/pageelement/prop.php b/modules/cms/ui/themes/default/html/views/pageelement/prop.php @@ -40,7 +40,7 @@ <td class="filename"> <i class="image-icon image-icon--action-el_<?php echo encodeHtml(htmlentities(@$element_type)) ?>"> </i> - <span><?php echo encodeHtml(htmlentities(@lang('el_${element_type'))) ?>} + <span><?php echo encodeHtml(htmlentities(@lang('el_'.@$element_type.''))) ?> </span> </td> </tr> diff --git a/modules/cms/ui/themes/default/html/views/project/edit.php b/modules/cms/ui/themes/default/html/views/project/edit.php @@ -31,7 +31,7 @@ <a target="_self" date-name="<?php echo encodeHtml(htmlentities(@$name)) ?>" name="<?php echo encodeHtml(htmlentities(@$name)) ?>" data-type="open" data-action="<?php echo encodeHtml(htmlentities(@$type)) ?>" data-method="" data-id="<?php echo encodeHtml(htmlentities(@$id)) ?>" data-extra="[]" href="/#/<?php echo encodeHtml(htmlentities(@$type)) ?>/<?php echo encodeHtml(htmlentities(@$id)) ?>"> <i class="image-icon image-icon--action-<?php echo encodeHtml(htmlentities(@$type)) ?>"> </i> - <span><?php echo encodeHtml(htmlentities(@lang('${name'))) ?>} + <span><?php echo encodeHtml(htmlentities(@lang(''.@$name.''))) ?> </span> <span> </span> diff --git a/modules/cms/ui/themes/default/html/views/template/edit.php b/modules/cms/ui/themes/default/html/views/template/edit.php @@ -28,7 +28,7 @@ </a> </td> <td> - <span><?php echo encodeHtml(htmlentities(@lang('${type'))) ?>} + <span><?php echo encodeHtml(htmlentities(@lang(''.@$type.''))) ?> </span> </td> </tr> diff --git a/modules/cms/ui/themes/default/html/views/user/rights.php b/modules/cms/ui/themes/default/html/views/user/rights.php @@ -38,7 +38,7 @@ </td> <?php foreach($show as $list_key=>$t) { ?> <td class="help"> - <span title="message:acl<?php echo encodeHtml(htmlentities()) ?>"><?php echo encodeHtml(htmlentities(@lang('${t'))) ?>} + <span title="message:acl<?php echo encodeHtml(htmlentities()) ?>"><?php echo encodeHtml(htmlentities(@lang(''.@$t.''))) ?> </span> </td> <?php } ?> diff --git a/modules/template_engine/components/html/text/Text.class.php b/modules/template_engine/components/html/text/Text.class.php @@ -81,7 +81,7 @@ class TextComponent extends HtmlComponent // $functions[] = "Text::accessKey('".$this->accesskey."',@)"; if ( $this->key ) - $text->content( Value::createExpression(ValueExpression::TYPE_MESSAGE,$this->key) ); + $text->content( new ValueExpression( ValueExpression::TYPE_MESSAGE,new Value($this->key),0) ); elseif ( $this->text ) $text->content( Value::createExpression(ValueExpression::TYPE_MESSAGE,$this->text) ); diff --git a/modules/template_engine/element/Value.class.php b/modules/template_engine/element/Value.class.php @@ -18,23 +18,32 @@ class Value public function __construct($value) { - while (true) { - if (!$value) - break; + if ( $value instanceof ValueExpression ) + { + $value->position = 0; + $this->expressions = [ $value ]; + $this->value = ''; + } + else + { + while (true) { + if (!$value) + break; - $epos = strpos($value, '{', 1); - $fpos = strpos($value, '}', 1); + $epos = strpos($value, '{', 1); + $fpos = strpos($value, '}', 1); - if ($epos === false || $fpos === false) - break; + if ($epos === false || $fpos === false) + break; - $type = substr($value, $epos - 1, 1); - $name = substr($value, $epos + 1, $fpos - $epos - 1); + $type = substr($value, $epos - 1, 1); + $name = substr($value, $epos + 1, $fpos - $epos - 1); - $this->expressions[] = new ValueExpression($type, $name, $epos - 1); - $value = substr($value, 0, $epos - 1) . substr($value, $fpos + 1); - } - $this->value = $value; + $this->expressions[] = new ValueExpression($type, $name, $epos - 1); + $value = substr($value, 0, $epos - 1) . substr($value, $fpos + 1); + } + $this->value = $value; + } } @@ -42,8 +51,9 @@ class Value { switch ($context) { case Value::CONTEXT_PHP: - return "'" . array_reduce(array_reverse($this->expressions), function ($carry, $expr) { - return substr($carry, 0, $expr->position) . "'." . $expr->render() . '.\'' . substr($carry, $expr->position); + return "'" . array_reduce(array_reverse($this->expressions), function ($carry, $expr) use ($context) { + /** @var ValueExpression $expr */ + return substr($carry, 0, $expr->position) . "'." . $expr->render() . '.\'' . substr($carry, $expr->position); }, $this->value) . "'"; case Value::CONTEXT_HTML: @@ -54,9 +64,10 @@ class Value else return $expr; }; - return array_reduce(array_reverse($this->expressions), function ($carry, $expr) use ($escape) { + return array_reduce(array_reverse($this->expressions), function ($carry, $expr) use ($escape,$context) { //echo "carry:".$carry.";expr:".$expr->position.':'.$expr->name; - return substr($carry, 0, $expr->position) . "<?php echo " . $escape($expr->render()) . ' ?>' . substr($carry, $expr->position); + /** @var ValueExpression $expr */ + return substr($carry, 0, $expr->position) . "<?php echo " . $escape($expr->render()) . ' ?>' . substr($carry, $expr->position); }, $this->value); } } diff --git a/modules/template_engine/element/ValueExpression.class.php b/modules/template_engine/element/ValueExpression.class.php @@ -28,18 +28,27 @@ class ValueExpression public function render() { + switch ($this->type) { case self::TYPE_DATA_VAR: - $parts = explode('.', $this->name); - - return array_reduce($parts, function ($carry, $item) { - if (!$carry) - return '@$' . $item; - else - return $carry . '[\'' . $item . '\']'; - }, ''); + if ( $this->name instanceof Value ) + return '@$' . $this->name->render( Value::CONTEXT_PHP ) . ''; + else + { + $parts = explode('.', $this->name); + + return array_reduce($parts, function ($carry, $item) { + if (!$carry) + return '@$' . $item; + else + return $carry . '[\'' . $item . '\']'; + }, ''); + } case self::TYPE_MESSAGE: - return '@lang(\'' . $this->name . '\')'; + if ( $this->name instanceof Value ) + return '@lang(' . $this->name->render( Value::CONTEXT_PHP ) . ')'; + else + return '@lang(\'' . $this->name . '\')'; case self::TYPE_CONFIG: $config_parts = explode('/', $this->name);