openrat-cms

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

Text.class.php (3041B)


      1 <?php
      2 
      3 namespace template_engine\components;
      4 
      5 class TextComponent extends HtmlComponent
      6 {
      7 	public $prefix = '';
      8 	public $suffix = '';
      9 	public $title;
     10 	public $type;
     11 	public $escape = true;
     12 	public $var;
     13 	public $text;
     14 	public $key;
     15 	public $raw;
     16 	public $value;
     17 	public $maxlength;
     18 	public $accesskey;
     19 	public $cut = 'both';
     20 	public $label;
     21 	public $newline = true;
     22 
     23 	public function begin()
     24 	{
     25         if   ( $this->label )
     26             echo '<label class="or-form-row"><span class="or-form-label">'.'<?php echo lang('.$this->value($this->label).') ?>'.'</span><span class="or-form-input">';
     27 
     28         if	( $this->raw )
     29 			$this->escape = false;
     30 		
     31 		switch( $this->type )
     32 		{
     33 			case 'none':
     34 				$tag = '';
     35 				break;
     36 			case 'emphatic':
     37 				$tag = 'em';
     38 				break;
     39 			case 'italic':
     40 				$tag = 'em';
     41 				break;
     42 			case 'strong':
     43 				$tag = 'strong';
     44 				break;
     45 			case 'bold':
     46 				$tag = 'strong';
     47 				break;
     48 			case 'tt':
     49 				$tag = 'tt';
     50 				break;
     51 			case 'teletype':
     52 				$tag = 'tt';
     53 				break;
     54 			case 'preformatted':
     55 				$tag = 'pre';
     56 				break;
     57 			case 'code':
     58 				$tag = 'code';
     59 				break;
     60 			default:
     61 				$tag = 'span';
     62 		}
     63 
     64 		if   ( $tag )
     65         {
     66 
     67             echo '<'.$tag;
     68 
     69             if	( !empty($this->class))
     70                 echo ' class="'.$this->htmlvalue($this->class).'"';
     71 
     72             if	( !empty($this->title))
     73                 echo ' title="'.$this->htmlvalue($this->title).'"';
     74 
     75             echo '>';
     76         }
     77 		echo '<?php ';
     78 
     79 		
     80 		$functions = array(); // Funktionen, durch die der Text gefiltert wird.
     81 
     82         if   ( $this->newline)
     83 		    $functions[] = 'nl2br(@)';
     84 
     85 		
     86 		if	( $this->escape )
     87 		{
     88 			// When using UTF-8 as a charset, htmlentities will only convert 1-byte and 2-byte characters.
     89 			// Use this function if you also want to convert 3-byte and 4-byte characters:
     90 			// converts a UTF8-string into HTML entities
     91 			$functions[] = 'encodeHtml(@)';
     92 			$functions[] = 'htmlentities(@)';
     93 		}
     94 
     95 		if	( !empty($this->maxlength) )
     96 			$functions[] = 'Text::maxLength( @,'.intval($this->maxlength).",'..',constant('STR_PAD_".strtoupper($this->cut)."') )";
     97 	
     98 		if	( !empty($this->accesskey) )
     99 			$functions[] = "Text::accessKey('".$this->accesskey."',@)";
    100 		
    101 
    102 		
    103 		
    104 		$value ='';
    105 		
    106 		if	( isset($this->key))
    107 		{
    108 			$value = "'".$this->prefix."'.".$this->value($this->key).".'".$this->suffix."'";
    109 			$functions[] = "lang(@)";
    110 		}
    111 		elseif	( isset($this->text))
    112 		{
    113 			$value = $this->value($this->text);
    114 			$functions[] = "lang(@)";
    115 		}
    116 		elseif	( isset($this->var))
    117 			$value = '$'.$this->varname($this->var);
    118 		
    119 		elseif	( isset($this->raw))
    120 			$value = "'".str_replace('_','&nbsp;',$this->raw)."'";
    121 				
    122 		elseif	( isset($this->value))
    123 			$value = $this->value($this->value);
    124 
    125 		foreach( array_reverse($functions) as $f )
    126 		{
    127 			list($before,$after) = explode('@',$f);
    128 			$value = $before.$value.$after; 
    129 		}
    130 		echo "echo $value;";
    131 			
    132 		echo ' ?>';
    133 
    134         if   ( $tag )
    135             echo '</'.$tag.'>';  // Tag schliessen.
    136 
    137         if   ( $this->label )
    138             echo '</span></label>';
    139     }
    140 }
    141 
    142 
    143 ?>