openrat-cms

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

Link.class.php (4863B)


      1 <?php
      2 
      3 namespace template_engine\components;
      4 
      5 use Html;
      6 use JSON;
      7 
      8 /**
      9  * Erzeugt einen HTML-Link.
     10  * 
     11  * @author dankert
     12  *
     13  */
     14 class LinkComponent extends Component
     15 {
     16 
     17 	public $var1;
     18 
     19 	public $var2;
     20 
     21 	public $var3;
     22 
     23 	public $var4;
     24 
     25 	public $var5;
     26 
     27 	public $value1;
     28 
     29 	public $value2;
     30 
     31 	public $value3;
     32 
     33 	public $value4;
     34 
     35 	public $value5;
     36 
     37 	public $target;
     38 
     39 	public $type;
     40 
     41 	public $action;
     42 
     43 	public $subaction;
     44 
     45 	public $title;
     46 
     47 	public $class;
     48 
     49 	public $url;
     50 
     51 	public $config;
     52 
     53 	public $id;
     54 
     55 	public $accesskey;
     56 
     57 	public $name;
     58 
     59 	public $anchor;
     60 
     61 	public $frame = '_self';
     62 
     63 	public $modal = false;
     64 
     65 	public $afterSuccess;
     66 
     67 	/**
     68 	 * Link-Beginn
     69 	 * {@inheritDoc}
     70 	 * @see Component::begin()
     71 	 */
     72 	public function begin()
     73 	{
     74 		echo '<a';
     75 		
     76 		if ( $this->afterSuccess )
     77 			echo ' data-after-success="' . $this->htmlvalue($this->afterSuccess) . '"';
     78 		
     79 		if (isset($this->class))
     80 			echo ' class="' . $this->htmlvalue($this->class) . '"';
     81 
     82 		if (isset($this->title))
     83 			echo ' title="' . $this->htmlvalue($this->title) . '"';
     84 		
     85 		if (isset($this->accesskey))
     86 			echo ' accesskey="' . $this->htmlvalue($this->accesskey) . '"';
     87 		
     88 		if (isset($this->frame))
     89 			echo ' target="' . $this->htmlvalue($this->frame) . '"';
     90 		
     91 		if (isset($this->name))
     92 			echo ' date-name="' . $this->htmlvalue($this->name) . '" name="' . $this->htmlvalue($this->name) . '"';
     93 		
     94 		if (isset($this->url))
     95 			echo ' data-url="' . $this->htmlvalue($this->url) . '"';
     96 		
     97 		if (isset($this->type))
     98 			echo ' data-type="' . $this->htmlvalue($this->type) . '"';
     99 		
    100 		if (!empty($this->action))
    101 			echo ' data-action="' . $this->htmlvalue($this->action) . '"';
    102 		else
    103 			echo ' data-action=""';
    104 		
    105 		if (isset($this->subaction))
    106 			echo ' data-method="' . $this->htmlvalue($this->subaction) . '"';
    107 		else
    108 			echo ' data-method="'.$this->request->method.'"';
    109 		
    110 		if (isset($this->id))
    111 			echo ' data-id="' . $this->htmlvalue($this->id) . '"';
    112 		else
    113 			echo ' data-id="<?php echo OR_ID ?>"';
    114 
    115 		$json = new JSON();
    116         $arrayvalues = array();
    117         foreach( $this->getExtraParamArray() as $varname => $varvalue )
    118             $arrayvalues[ $this->htmlvalue($varname) ] = $this->htmlvalue($varvalue);
    119         echo ' data-extra="'.str_replace('"',"'",str_replace(array("\t", "\r", "\n"),'',$json->encode($arrayvalues))).'"';
    120 
    121 		switch ($this->type)
    122 		{
    123 			case 'post':
    124 				
    125 				// Zusammenbau eines einzeligen JSON-Strings.
    126 				// Aufpassen: Keine doppelten Hochkommas, keine Zeilenumbrüche.
    127 				echo ' data-data="{';
    128 				
    129 				echo "&quot;action&quot;:&quot;";
    130 				if (! empty($this->action))
    131 					echo $this->htmlvalue($this->action);
    132 				else
    133 					echo $this->htmlvalue($this->request->action);
    134 				echo "&quot;,";
    135 				
    136 				echo "&quot;subaction&quot;:&quot;";
    137 				if (! empty($this->subaction))
    138 					echo $this->htmlvalue($this->subaction);
    139 				else
    140 					echo $this->request->method;
    141 				echo "&quot;,";
    142 				
    143 				echo "&quot;id&quot;:&quot;";
    144 				if (! empty($this->id))
    145 					echo $this->htmlvalue($this->id);
    146 				else
    147 					echo "<?php echo OR_ID ?>";
    148 				echo "&quot;,";
    149 				
    150 				echo '&quot;'.REQ_PARAM_TOKEN . "&quot;:&quot;" . '<?php echo token() ?>' . "&quot;,";
    151 
    152                 foreach( $this->getExtraParamArray() as $varname => $varvalue )
    153 					echo "&quot;".$this->htmlvalue($varname)."&quot;:&quot;" . $this->htmlvalue($varvalue) . "&quot;,";
    154 
    155                 echo "&quot;none&quot;:&quot;0&quot;}\"";
    156 				
    157 				break;
    158 			
    159 			case 'html':
    160 				
    161 				echo ' href="' . $this->htmlvalue($this->url) . '"';
    162 				break;
    163 			
    164 			case 'external':
    165 
    166 				echo ' href="' . $this->htmlvalue($this->url) . '"';
    167 				break;
    168 
    169 			default:
    170 				//echo ' href="<?php echo Html::url('.$this->value($this->action).','.$this->value($this->subaction).','.$this->value($this->id);
    171 				echo ' href="./#/'.$this->htmlvalue($this->action).'/'.$this->htmlvalue($this->id).'"';
    172 
    173 // Verlinkungen von draußen brauchen nichts weiter.
    174 //				$arrayvalues = array();
    175 //				foreach( $this->getExtraParamArray() as $varname => $varvalue )
    176 //                    $arrayvalues[] = $this->value($varname) . '=>'.$this->value($varvalue);
    177 //
    178 //                echo ',array('.implode(',',$arrayvalues).')';
    179 //
    180 /*				echo ') ?>"';*/
    181 		}
    182 		
    183 		echo '>';
    184 	}
    185 
    186 	public function end()
    187 	{
    188 		echo '</a>';
    189 	}
    190 
    191 
    192 	private function getExtraParamArray()
    193 	{
    194 		$vars = array();
    195 		if (! empty($this->var1))		$vars[$this->var1] = $this->value1;
    196 		if (! empty($this->var2))		$vars[$this->var2] = $this->value2;
    197 		if (! empty($this->var3))		$vars[$this->var3] = $this->value3;
    198 		if (! empty($this->var4))		$vars[$this->var4] = $this->value4;
    199 		if (! empty($this->var5))		$vars[$this->var5] = $this->value5;
    200 
    201 		// Bei Dialogen kann der Dialog auch beim Öffnen in einem neuen Fenster direkt geöffnet werden.
    202 		if ( $this->type=='dialog')
    203 			$vars += array('dialogAction'=>$this->action,'dialogMethod'=>$this->subaction);
    204 
    205 		return $vars;
    206 	}
    207 }
    208 ?>