File modules/template_engine/components/html/component_link/LinkComponent.class.php
Last commit: Wed Nov 17 23:22:19 2021 +0100 Jan Dankert Refactoring: Using a template context for templates instead of the HTTP-Request-Data
1 <?php 2 3 namespace template_engine\components\html\component_link; 4 5 use cms\action\RequestParams; 6 use template_engine\components\html\Component; 7 use template_engine\element\CMSElement; 8 use util\json\JSON; 9 10 /** 11 * Erzeugt einen HTML-Link. 12 * 13 * @author dankert 14 * 15 */ 16 class LinkComponent extends Component 17 { 18 19 public $var1; 20 21 public $var2; 22 23 public $var3; 24 25 public $var4; 26 27 public $var5; 28 29 public $value1; 30 31 public $value2; 32 33 public $value3; 34 35 public $value4; 36 37 public $value5; 38 39 public $target; 40 41 public $type; 42 43 public $action; 44 45 public $subaction; 46 47 public $title; 48 49 public $class; 50 51 public $url; 52 53 public $config; 54 55 public $id; 56 57 public $accesskey; 58 59 public $name; 60 61 public $anchor; 62 63 public $frame = '_self'; 64 65 public $afterSuccess; 66 67 public $clickable = false; 68 69 70 public function createElement() 71 { 72 73 $link = new CMSElement('a'); 74 $link->addStyleClass('link'); 75 76 if ( $this->afterSuccess ) 77 $link->addAttribute('data-after-success',$this->afterSuccess); 78 79 if ( $this->class ) 80 $link->addStyleClass($this->class); 81 82 if ( $this->clickable ) 83 $link->addStyleClass('act-clickable'); 84 85 if ( $this->title ) 86 $link->addAttribute('title',$this->title); 87 88 if ( $this->accesskey ) 89 $link->addAttribute('accesskey',$this->accesskey); 90 91 if ( $this->frame ) 92 $link->addAttribute('target',$this->frame); 93 94 if ( $this->name ) 95 $link->addAttribute('data-name',$this->name)->addAttribute('name',$this->name); 96 97 if ( $this->url ) 98 $link->addAttribute('data-url',$this->url); 99 100 if ( $this->type ) 101 $link->addAttribute('data-type',$this->type); 102 103 if ( $this->action ) 104 $link->addAttribute('data-action',$this->action); 105 else 106 $link->addAttribute('data-action',''); 107 108 if ( $this->subaction ) 109 $link->addAttribute('data-method',$this->subaction); 110 else 111 $link->addAttribute('data-method',''); 112 113 if ( $this->id ) 114 $link->addAttribute('data-id',$this->id); 115 else 116 $link->addAttribute('data-id',''); 117 118 $arrayvalues = array(); 119 foreach( $this->getExtraParamArray() as $varname => $varvalue ) { 120 121 $link->addAttribute('data-extra-'.$varname,$varvalue); 122 $arrayvalues[ $varname ] = $varvalue; 123 } 124 $link->addAttribute('data-extra',htmlentities(str_replace(array("\t", "\r", "\n"),'',JSON::encode($arrayvalues)),ENT_QUOTES, 'UTF-8')); 125 126 switch ($this->type) 127 { 128 case 'post': 129 130 // Zusammenbau eines einzeligen JSON-Strings. 131 // Aufpassen: Keine doppelten Hochkommas, keine Zeilenumbrüche. 132 $data = array(); 133 134 $data['action' ] = (!empty($this->action ))?$this->action :$this->context->action; 135 $data['subaction'] = (!empty($this->subaction))?$this->subaction:$this->context->method; 136 $data['id' ] = (!empty($this->id ))?$this->id :''; 137 $data[RequestParams::PARAM_TOKEN] = '${_token}'; 138 139 foreach( $this->getExtraParamArray() as $varname => $varvalue ) 140 $data[$varname] = $varvalue; 141 142 $data['none'] = '0'; 143 144 $link->addAttribute('data-data',str_replace(array("\t", "\r", "\n"),'',JSON::encode($data))); 145 break; 146 147 case 'html': 148 case 'external': 149 150 $link->addAttribute('href',$this->url); 151 break; 152 153 default: 154 if ( $this->action ) 155 $link->addAttribute('href','#/'.$this->action.($this->id?'/'.$this->id:'') ); 156 else 157 $link->addAttribute('href','' ); 158 159 } 160 161 return $link; 162 } 163 164 private function getExtraParamArray() 165 { 166 $vars = array(); 167 if (! empty($this->var1)) $vars[$this->var1] = $this->value1; 168 if (! empty($this->var2)) $vars[$this->var2] = $this->value2; 169 if (! empty($this->var3)) $vars[$this->var3] = $this->value3; 170 if (! empty($this->var4)) $vars[$this->var4] = $this->value4; 171 if (! empty($this->var5)) $vars[$this->var5] = $this->value5; 172 173 return $vars; 174 } 175 } 176 ?> 177
Downloadmodules/template_engine/components/html/component_link/LinkComponent.class.php
History Wed, 17 Nov 2021 23:22:19 +0100 Jan Dankert Refactoring: Using a template context for templates instead of the HTTP-Request-Data Wed, 17 Mar 2021 02:18:50 +0100 Jan Dankert Refactoring: Using "Jquery slim" without ajax and effects. Tue, 16 Mar 2021 02:38:13 +0100 Jan Dankert Fix: Using the new FormData object instead of JQuery (JQuery's serialize-functions are not available in the slim version) Fri, 26 Feb 2021 00:04:49 +0100 Jan Dankert New: Request may contain JSON,XML in POST data. This is good for API clients. Wed, 10 Feb 2021 00:00:21 +0100 Jan Dankert Using only fullscreen views; Navigate to parent instead of complete breadcrumb. Mon, 26 Oct 2020 21:36:14 +0100 Jan Dankert Rename css class 'clickable' to 'act-clickable'; enhanced view 'info' for projects. Sun, 25 Oct 2020 02:11:58 +0200 Jan Dankert Fix: The config was not read in the templates :-O. Sat, 24 Oct 2020 23:51:11 +0200 Jan Dankert Cleanup LESS files, introduce BEM. Thu, 22 Oct 2020 14:14:32 +0200 Jan Dankert The href-attribute of links should contain a relative url for internal links. Wed, 14 Oct 2020 22:36:29 +0200 Jan Dankert Refactoring: Fixed the namespace in component classes, now the are able to be load by the standard autoloader. Wed, 14 Oct 2020 22:20:22 +0200 Jan Dankert Refactoring: Renamed component folders, because 'if' is no valid namespace fragment.