openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 365faca4ce9d370b9dc8b10e87141b9711f331e2
parent 8539b686404950aea65cd750ba6980b2f7f50602
Author: Jan Dankert <devnull@localhost>
Date:   Wed, 22 Nov 2017 00:07:24 +0100

Template-Klassen weiter verbessert und ausgebaut.

Diffstat:
themes/default/include/elements.ini.php | 1-
themes/default/include/html/Component.class.php | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
themes/default/include/html/char/char-begin.inc.php | 7-------
themes/default/include/html/checkbox/Checkbox.class.php | 37+++++++++++++++++++++++++++++++++++++
themes/default/include/html/column/Column.class.php | 49+++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 160 insertions(+), 8 deletions(-)

diff --git a/themes/default/include/elements.ini.php b/themes/default/include/elements.ini.php @@ -5,7 +5,6 @@ output = button = type:submit,src,class:ok,value:ok,text:button_ok -char = type:* checkbox = default:false,readonly:false,name:* column = width,style,class,colspan,rowspan,header:false,title,url,action,id,name date = date diff --git a/themes/default/include/html/Component.class.php b/themes/default/include/html/Component.class.php @@ -33,6 +33,80 @@ abstract class Component protected function end() {} + + + protected function htmlvalue($value) + { + $erg = $this->value($value); + + // Für statische Texte muss kein PHP-Abschnitt geoeffnet werden. + if (substr($erg,0,1) == "'" && strpos($erg,'$')===FALSE ) + return substr($erg,1,-1); + else + return '<'.'?php echo '.$erg.' ?>'; + } + + + + protected function value( $value ) + { + $parts = explode( ':', $value, 2 ); + + if ( count($parts) < 2 ) + $parts = array('',$value); + + list( $type,$value ) = $parts; + + $invert = ''; + if ( substr($type,0,1)=='!' ) + { + $type = substr($type,1); + $invert = '! '; + } + + switch( $type ) + { + case 'var': + return $invert.'$'.$value; + case 'text': + case '': + // Sonderf�lle f�r die Attributwerte "true" und "false". + // Hinweis: Die Zeichenkette "false" entspricht in PHP true. + // Siehe http://de.php.net/manual/de/language.types.boolean.php + if ( $value == 'true' || $value == 'false' ) + return $value; + else + // macht aus "text1{var}text2" => "text1".$var."text2" + return "'".preg_replace('/{(\w+)\}/','\'.$\\1.\'',$value)."'"; + case 'function': + return $invert.$value.'()'; + case 'method': + return $invert.'$this->'.$value.'()'; + case 'size': + return '@count($'.$value.')'; + case 'property': + return $invert.'$this->'.$value; + case 'message': + // return 'lang('."'".$value."'".')'; + // macht aus "text1{var}text2" => "text1".$var."text2" + return 'lang('."'".preg_replace('/{(\w+)\}/','\'.$\\1.\'',$value)."'".')'; + case 'messagevar': + return 'lang($'.$value.')'; + case 'mode': + return $invert.'$mode=="'.$value.'"'; + case 'arrayvar': + list($arr,$key) = explode(':',$value.':none'); + return $invert.'@$'.$arr.'['.$key.']'; + case 'config': + $config_parts = explode('/',$value); + return $invert.'@$conf['."'".implode("'".']'.'['."'",$config_parts)."'".']'; + + default: + throw new LogicException("Unknown type '$type' in attribute. Allowed: var|function|method|text|size|property|message|messagevar|arrayvar|config or none"); + } + } + + } ?> \ No newline at end of file diff --git a/themes/default/include/html/char/char-begin.inc.php b/themes/default/include/html/char/char-begin.inc.php @@ -1,6 +0,0 @@ -<?php - if ($attr_type=='filesep') - echo '&nbsp;<strong>&raquo;</strong>&nbsp;'; - else - echo "char error"; -?>- \ No newline at end of file diff --git a/themes/default/include/html/checkbox/Checkbox.class.php b/themes/default/include/html/checkbox/Checkbox.class.php @@ -0,0 +1,36 @@ +<?php + +class CheckboxComponent extends Component +{ + + public $default; + public $name; + public $readonly; + + protected function begin(){ + + echo '<?php { '; + echo '$tmpname = '.$this->value($this->name).';'; + echo '$default = '.$this->value($this->default).';'; + echo '$readonly = '.$this->value($this->readonly).';'; + + echo <<<'HTML' + + if ( isset($$tmpname) ) + $checked = $$tmpname; + else + $checked = $default; + + ?><input class="checkbox" type="checkbox" id="<?php echo REQUEST_ID ?>_<?php echo $tmpname ?>" name="<?php echo $tmpname ?>" <?php if ($readonly) echo ' disabled="disabled"' ?> value="1" <?php if( $checked ) echo 'checked="checked"' ?> /><?php + + if ( $readonly && $checked ) + { + ?><input type="hidden" name="<?php echo $tmpname ?>" value="1" /><?php + } + } ?> +HTML; + } +} + + +?>+ \ No newline at end of file diff --git a/themes/default/include/html/column/Column.class.php b/themes/default/include/html/column/Column.class.php @@ -0,0 +1,48 @@ +<?php + +class ColumnComponent extends Component +{ + public $width; + public $style; + public $class; + public $colspan; + public $rowspan; + public $header = false; + public $title; + public $url; + public $action; + public $id; + public $name; + + protected function begin() + { + echo '<td'; + if ( ! empty($this->width)) + echo ' width="'.$this->htmlvalue($this->width).'"'; + if ( ! empty($this->style)) + echo ' style="'.$this->htmlvalue($this->style).'"'; + if ( ! empty($this->class)) + echo ' class="'.$this->htmlvalue($this->class).'"'; + if ( ! empty($this->colspan)) + echo ' colspan="'.$this->htmlvalue($this->colspan).'"'; + if ( ! empty($this->rowspan)) + echo ' rowspan="'.$this->htmlvalue($this->rowspan).'"'; + if ( ! empty($this->rowspan)) + echo ' rowspan="'.$this->htmlvalue($this->rowspan).'"'; + if ( ! empty($this->title)) + echo ' title="'.$this->htmlvalue($this->title).'"'; + if ( ! empty($this->id)) + echo ' onclick="javascript:openNewAction('."'".$this->htmlvalue($this->name)."','".$this->htmlvalue($this->action)."','".$this->htmlvalue($this->id)."');".'"'; + echo '>'; + } + + + protected function end() + { + echo '</td>'; + } + +} + + +?>+ \ No newline at end of file