commit 316c68d33cf6b169a6b081828687d0fc30ac32ed
parent 143f10631ead05c49496354a3755167203cc2464
Author: Jan Dankert <develop@jandankert.de>
Date: Fri, 21 Feb 2020 23:39:54 +0100
Error fixed in the template compiler.
Diffstat:
9 files changed, 48 insertions(+), 73 deletions(-)
diff --git a/modules/template-engine/CMSElement.class.php b/modules/template-engine/CMSElement.class.php
@@ -14,5 +14,6 @@ class CMSElement extends HtmlElement
public function addConditionalAttribute($name, $condition, $value ) {
$this->attributes[] = new ConditionalAttribute($condition,$name,$value);
+ return $this;
}
}
\ No newline at end of file
diff --git a/modules/template-engine/ConditionalAttribute.php b/modules/template-engine/ConditionalAttribute.php
@@ -26,6 +26,6 @@ class ConditionalAttribute extends SimpleAttribute
public function render()
{
- return '<?php if('.(new Value($this->condition))->render(Value::CONTEXT_PHP).'){ ?>'.parent::render().'<?php } ?>';
+ return '<?php if('.$this->condition.'){ ?>'.parent::render().'<?php } ?>';
}
}
\ No newline at end of file
diff --git a/modules/template-engine/HtmlElement.class.php b/modules/template-engine/HtmlElement.class.php
@@ -55,7 +55,8 @@ class HtmlElement extends Element
public function render()
{
- $this->addAttribute('class', implode(' ',$this->styleClasses) );
+ if ( $this->styleClasses )
+ $this->addAttribute('class', implode(' ',$this->styleClasses) );
return parent::render();
}
diff --git a/modules/template-engine/components/html/checkbox/Checkbox.class.php b/modules/template-engine/components/html/checkbox/Checkbox.class.php
@@ -27,7 +27,7 @@ class CheckboxComponent extends Component
if ( $this->default )
$checkbox->addAttribute('checked',$this->default);
else {
- $condition = Value::createExpression(ValueExpression::TYPE_DATA_VAR,$this->name );
+ $condition = '$'.$this->name;
$checkbox->addConditionalAttribute('checked', $condition, '1');
}
diff --git a/modules/template-engine/components/html/editor/Editor.class.php b/modules/template-engine/components/html/editor/Editor.class.php
@@ -3,6 +3,8 @@
namespace template_engine\components;
use modules\template_engine\CMSElement;
+use modules\template_engine\Value;
+use modules\template_engine\ValueExpression;
class EditorComponent extends FieldComponent
{
@@ -53,6 +55,8 @@ class EditorComponent extends FieldComponent
throw new \LogicException("Unknown editor type: ".$this->type);
}
+ $textarea->content(Value::createExpression(ValueExpression::TYPE_DATA_VAR,$this->name));
+
return $textarea;
}
}
\ No newline at end of file
diff --git a/modules/template-engine/components/html/form/Form.class.php b/modules/template-engine/components/html/form/Form.class.php
@@ -99,7 +99,7 @@ class FormComponent extends Component
(new CMSElement('input'))
->addAttribute('type', 'hidden')
->addAttribute('name', REQ_PARAM_TOKEN)
- ->addAttribute('value', '<?php token();?>') // TODO escaping
+ ->addAttribute('value', '<?php echo token();?>') // TODO escaping
);
$form->addChild(
diff --git a/modules/template-engine/components/html/radiobox/Radiobox.class.php b/modules/template-engine/components/html/radiobox/Radiobox.class.php
@@ -2,6 +2,7 @@
namespace template_engine\components;
+use modules\template_engine\CMSElement;
use modules\template_engine\PHPBlockElement;
use modules\template_engine\Value;
use modules\template_engine\ValueExpression;
@@ -15,6 +16,9 @@ class RadioboxComponent extends Component
public $default;
+ /**
+ * @deprecated
+ */
public $onchange;
public $title;
@@ -26,17 +30,27 @@ class RadioboxComponent extends Component
{
$radiobox = new PHPBlockElement();
- $radiobox->beforeBlock = $radiobox->includeResource( 'radiobox/component-radio-box.php');
+ $radiobox->beforeBlock = 'foreach( $'.$this->list.' as $_key=>$_value)';
if ( $this->default )
$value = $this->default;
else
- $value = Value::createExpression(ValueExpression::TYPE_DATA_VAR,$this->name);
-
- $radiobox->inBlock = '<?php component_radio_box('.$this->name.',$'.$this->list.','.$value.') ?>';
+ $value = '$'.$this->name;
+
+ $label = (new CMSElement('label'))->asChildOf( $radiobox );
+
+ (new CMSElement('input'))
+ ->addAttribute('type','radio')->addAttribute('name',$this->name)
+ ->addAttribute('value',Value::createExpression(ValueExpression::TYPE_DATA_VAR,'_key'))
+ ->addConditionalAttribute('checked','$_key=='.$value,'checked')
+ ->asChildOf($label);
+
+ (new CMSElement('span'))
+ ->content( Value::createExpression(ValueExpression::TYPE_DATA_VAR,'_value'))
+ ->asChildOf( $label );
+ (new CMSElement('br'))
+ ->asChildOf( $radiobox );
return $radiobox;
}
-}
-
-?>-
\ No newline at end of file
+}+
\ No newline at end of file
diff --git a/modules/template-engine/components/html/selectbox/Selectbox.class.php b/modules/template-engine/components/html/selectbox/Selectbox.class.php
@@ -58,7 +58,7 @@ class SelectboxComponent extends Component
public function createElement()
{
- $selectbox = (new CMSElement('input'));
+ $selectbox = (new CMSElement('select'));
$selectbox->addAttribute('name',$this->name);
@@ -71,40 +71,36 @@ class SelectboxComponent extends Component
if ( $this->title )
$selectbox->addAttribute('title',$this->title);
- if (isset($this->default))
- $selectbox->addAttribute('value',$this->default);
- else
- $selectbox->addAttribute('value',Value::createExpression(ValueExpression::TYPE_DATA_VAR,$this->name));
-
if ( $this->multiple )
$selectbox->addAttribute('multiple','multiple');
$selectbox->addAttribute('size',$this->size);
- $code = new PHPBlockElement();
- $selectbox->addChild( $code );
+ if ( $this->addempty )
+ $selectbox->addChild( (new CMSElement('option'))->addAttribute('value','')->content( Value::createExpression(ValueExpression::TYPE_MESSAGE,'LIST_ENTRY_EMPTY')));
- //if ( ! $this->addempty )
- //$code->inBlock .= 'if (count($'.$this->varname($this->list).')<=1)'." echo ' disabled=\"disabled\"';";
+ $optionLoop = (new PHPBlockElement())->asChildOf($selectbox);
- if ( isset($this->default))
+ if ( $this->default )
$value = $this->default;
else
$value = '$'.$this->name;
-
- $code->beforeBlock = $code->includeResource( 'selectbox/component-select-box.php');
- $code->inBlock .= 'component_select_option_list($'.$this->list.','.$value.','.intval(boolval($this->addempty)).','.intval(boolval($this->lang)).')';
-
- // Keine Einträge in der Liste, wir benötigen ein verstecktes Feld.
- //echo '< ? php if (count($'.$this->varname($this->list).')==0) { ? >'.'<input type="hidden" name="'.$this->htmlvalue($this->name).'" value="" />'.'<?php } ? >';
- // Nur 1 Eintrag in Liste, da die Selectbox 'disabled' ist, muss ein hidden-Feld her.
- //echo '< ? php if (count($'.$this->varname($this->list).')==1) { ? >'.'<input type="hidden" name="'.$this->htmlvalue($this->name).'" value="'.'< ? php echo array_keys($'.$this->varname($this->list).')[0] ? >'.'" />'.'< ? php } ? >';
+ // Create the option list.
+ $optionLoop->beforeBlock = 'foreach($'.$this->list.' as $_key=>$_value)';
+ $option = (new CMSElement('option'))
+ ->addAttribute('value',Value::createExpression( ValueExpression::TYPE_DATA_VAR,'_key'))
+ ->content(Value::createExpression( ValueExpression::TYPE_DATA_VAR,'_value'))
+ ->addConditionalAttribute('selected','$_key=='.$value,'selected');
+
+ $optionLoop->addChild($option);
+
+ // Wrap into a label, if necessary.
if ( $this->label ) {
$label = new CMSElement('label');
$label->addStyleClass('or-form-row')->addStyleClass('or-form-input');
$label->addChild( (new CMSElement('span'))->addStyleClass('or-form-label')->content($this->label));
- $selectbox->asChildOf($label);
+ $label->addChild( $selectbox );
return $label;
}
else {
diff --git a/modules/template-engine/components/html/selectbox/component-select-box.php b/modules/template-engine/components/html/selectbox/component-select-box.php
@@ -1,41 +0,0 @@
-<?php
-
-/**
- * Create Option List for a HTML select box.
- * @param unknown $values
- * @param unknown $value
- * @param unknown $addEmptyOption
- * @param unknown $valuesAreLanguageKeys
- */
-function component_select_option_list($values, $value, $addEmptyOption, $valuesAreLanguageKeys)
-{
- if ($addEmptyOption)
- $values = array(
- '' => lang('LIST_ENTRY_EMPTY')
- ) + $values;
-
- foreach ($values as $box_key => $box_value)
- {
- if (is_array($box_value))
- {
- $box_key = $box_value['key'];
- $box_title = $box_value['title'];
- $box_value = $box_value['value'];
- }
- elseif ($valuesAreLanguageKeys)
- {
- $box_title = lang($box_value . '_DESC');
- $box_value = lang($box_value);
- }
- else
- {
- $box_title = '';
- }
- echo '<option value="' . $box_key . '" title="' . $box_title . '"';
-
- if ((string) $box_key == $value)
- echo ' selected="selected"';
-
- echo '>' . $box_value . '</option>';
- }
-}