Completed
Push — 17.1 ( 68420f...e791a5 )
by Ralf
20:28 queued 08:42
created
api/src/Etemplate.php 1 patch
Spacing   +61 added lines, -62 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 	 *
30 30
 	 * @public boolean
31 31
 	 */
32
-	public $sitemgr=false;
32
+	public $sitemgr = false;
33 33
 
34 34
 	/**
35 35
 	 * Tell egw framework it's ok to call this
@@ -44,17 +44,17 @@  discard block
 block discarded – undo
44 44
 	 * @param string $name of etemplate or array with name and other keys
45 45
 	 * @param string|array $load_via with keys of other etemplate to load in order to get $name
46 46
 	 */
47
-	function __construct($name='',$load_via='')
47
+	function __construct($name = '', $load_via = '')
48 48
 	{
49 49
 		// we do NOT call parent consturctor, as we only want to enherit it's (static) methods
50
-		if (false) parent::__construct ($name);	// satisfy IDE, as we dont call parent constructor
50
+		if (false) parent::__construct($name); // satisfy IDE, as we dont call parent constructor
51 51
 
52 52
 		$this->sitemgr = isset($GLOBALS['Common_BO']) && is_object($GLOBALS['Common_BO']);
53 53
 
54
-		if ($name) $this->read($name,$template='default','default',0,'',$load_via);
54
+		if ($name) $this->read($name, $template = 'default', 'default', 0, '', $load_via);
55 55
 
56 56
 		// generate new etemplate request object, if not already existing
57
-		if(!isset(self::$request)) self::$request = Etemplate\Request::read();
57
+		if (!isset(self::$request)) self::$request = Etemplate\Request::read();
58 58
 	}
59 59
 
60 60
 	/**
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 	 *
66 66
 	 * @param string|array $params url or array with get-params incl. menuaction
67 67
 	 */
68
-	static function location($params='')
68
+	static function location($params = '')
69 69
 	{
70 70
 		Framework::redirect_link(is_array($params) ? '/index.php' : $params,
71 71
 			is_array($params) ? $params : '');
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 	 * @param array $changes change made in the last call if looping, only used internaly by process_exec
101 101
 	 * @return string html for $output_mode == 1, else nothing
102 102
 	 */
103
-	function exec($method,array $content,array $sel_options=null,array $readonlys=null,array $preserv=null,$output_mode=0,$ignore_validation='',array $changes=null)
103
+	function exec($method, array $content, array $sel_options = null, array $readonlys = null, array $preserv = null, $output_mode = 0, $ignore_validation = '', array $changes = null)
104 104
 	{
105 105
 		$hook_data = Hooks::process(
106 106
 			array('hook_location'   => 'etemplate2_before_exec') +
@@ -109,11 +109,11 @@  discard block
 block discarded – undo
109 109
 			$content
110 110
 		);
111 111
 
112
-		foreach($hook_data as $extras)
112
+		foreach ($hook_data as $extras)
113 113
 		{
114 114
 			if (!$extras) continue;
115 115
 
116
-			foreach(isset($extras[0]) ? $extras : array($extras) as $extra)
116
+			foreach (isset($extras[0]) ? $extras : array($extras) as $extra)
117 117
 			{
118 118
 				if ($extra['data'] && is_array($extra['data']))
119 119
 				{
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 			$output_mode = 0;
149 149
 			self::$response = Json\Response::get();
150 150
 		}
151
-		self::$request->output_mode = $output_mode;	// let extensions "know" they are run eg. in a popup
151
+		self::$request->output_mode = $output_mode; // let extensions "know" they are run eg. in a popup
152 152
 		self::$request->content = self::$cont = $content;
153 153
 		self::$request->changes = $changes;
154 154
 		self::$request->sel_options = is_array($sel_options) ? self::fix_sel_options($sel_options) : array();
@@ -172,15 +172,15 @@  discard block
 block discarded – undo
172 172
 
173 173
 		// compile required translations translations
174 174
 		$currentapp = $GLOBALS['egw_info']['flags']['currentapp'];
175
-		$langRequire = array('common' => array(), 'etemplate' => array());	// keep that order
176
-		foreach(Translation::$loaded_apps as $l_app => $lang)
175
+		$langRequire = array('common' => array(), 'etemplate' => array()); // keep that order
176
+		foreach (Translation::$loaded_apps as $l_app => $lang)
177 177
 		{
178 178
 			if (!in_array($l_app, array($currentapp, 'custom')))
179 179
 			{
180 180
 				$langRequire[$l_app] = array('app' => $l_app, 'lang' => $lang, 'etag' => Translation::etag($l_app, $lang));
181 181
 			}
182 182
 		}
183
-		foreach(array($currentapp, 'custom') as $l_app)
183
+		foreach (array($currentapp, 'custom') as $l_app)
184 184
 		{
185 185
 			if (isset(Translation::$loaded_apps[$l_app]))
186 186
 			{
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
 			'currentapp' => $currentapp,
201 201
 		);
202 202
 
203
-		if($data['content']['nm']['rows'] && is_array($data['content']['nm']['rows']))
203
+		if ($data['content']['nm']['rows'] && is_array($data['content']['nm']['rows']))
204 204
 		{
205 205
 			// Api\Storage::search() returns (historically) a reference!
206 206
 			// We need to un-reference the rows here, so they are not lost,
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
 		}
212 212
 
213 213
 		// Info required to load the etemplate client-side
214
-		$dom_id = str_replace('.','-',$this->dom_id);
214
+		$dom_id = str_replace('.', '-', $this->dom_id);
215 215
 		$load_array = array(
216 216
 			'name' => $this->name,
217 217
 			'url' => self::rel2url($this->rel_path),
@@ -221,16 +221,16 @@  discard block
 block discarded – undo
221 221
 		if (self::$response)	// call is within an ajax event / form submit
222 222
 		{
223 223
 			//error_log("Ajax " . __LINE__);
224
-			self::$response->generic('et2_load', $load_array+Framework::get_extra());
225
-			Framework::clear_extra();	// to not send/set it twice for multiple etemplates (eg. CRM view)
224
+			self::$response->generic('et2_load', $load_array + Framework::get_extra());
225
+			Framework::clear_extra(); // to not send/set it twice for multiple etemplates (eg. CRM view)
226 226
 		}
227 227
 		else	// first call
228 228
 		{
229 229
 			// check if application of template has a app.js file --> load it
230
-			list($app) = explode('.',$this->name);
230
+			list($app) = explode('.', $this->name);
231 231
 			if (file_exists(EGW_SERVER_ROOT.'/'.$app.'/js/app.js'))
232 232
 			{
233
-				Framework::includeJS('.','app',$app,true);
233
+				Framework::includeJS('.', 'app', $app, true);
234 234
 			}
235 235
 			// Category styles
236 236
 			Categories::css($app);
@@ -248,8 +248,8 @@  discard block
 block discarded – undo
248 248
 				$content = '<form target="egw_iframe_autocomplete_helper" action="'.$form_action.'" id="'.$dom_id.'" class="et2_container"></form>'."\n".
249 249
 					'<iframe name="egw_iframe_autocomplete_helper" style="width:0;height:0;position: absolute;visibility:hidden;"></iframe>';
250 250
 				$GLOBALS['egw']->framework->response->generic("data", array($content));
251
-				$GLOBALS['egw']->framework->response->generic('et2_load',$load_array+Framework::get_extra());
252
-				Framework::clear_extra();	// to not send/set it twice for multiple etemplates (eg. CRM view)
251
+				$GLOBALS['egw']->framework->response->generic('et2_load', $load_array + Framework::get_extra());
252
+				Framework::clear_extra(); // to not send/set it twice for multiple etemplates (eg. CRM view)
253 253
 
254 254
 				// Really important to run this or weird things happen
255 255
 				// See https://help.egroupware.org/t/nextmatch-wert-im-header-ausgeben/73412/11
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
 				echo '<div id="popupMainDiv" class="popupMainDiv">'."\n";
273 273
 			}
274 274
 			// Send any accumulated json responses - after flush to avoid sending the buffer as a response
275
-			if(Json\Response::isJSONResponse())
275
+			if (Json\Response::isJSONResponse())
276 276
 			{
277 277
 				$load_array['response'] = Json\Response::get()->returnResult();
278 278
 			}
@@ -301,10 +301,10 @@  discard block
 block discarded – undo
301 301
 	 */
302 302
 	static protected function fix_sel_options(array $sel_options)
303 303
 	{
304
-		foreach($sel_options as &$options)
304
+		foreach ($sel_options as &$options)
305 305
 		{
306
-			if (!is_array($options)||empty($options)) continue;
307
-			foreach($options as $key => $value)
306
+			if (!is_array($options) || empty($options)) continue;
307
+			foreach ($options as $key => $value)
308 308
 			{
309 309
 				if (is_numeric($key) && (!is_array($value) || !isset($value['value'])))
310 310
 				{
@@ -343,9 +343,9 @@  discard block
 block discarded – undo
343 343
 		$GLOBALS['egw']->session->set_action('Etemplate: '.self::$request->method);
344 344
 
345 345
 		// Set current app for validation
346
-		list($app) = explode('.',self::$request->method);
347
-		if(!$app) list($app) = explode('::',self::$request->method);
348
-		if($app)
346
+		list($app) = explode('.', self::$request->method);
347
+		if (!$app) list($app) = explode('::', self::$request->method);
348
+		if ($app)
349 349
 		{
350 350
 			Translation::add_app($app);
351 351
 			$GLOBALS['egw_info']['flags']['currentapp'] = $app;
@@ -354,7 +354,7 @@  discard block
 block discarded – undo
354 354
 		$expand = array(
355 355
 			'cont' => &self::$request->content,
356 356
 		);
357
-		$template->run('validate', array('', $expand, $_content, &$validated), true);	// $respect_disabled=true: do NOT validate disabled widgets and children
357
+		$template->run('validate', array('', $expand, $_content, &$validated), true); // $respect_disabled=true: do NOT validate disabled widgets and children
358 358
 
359 359
 		if ($no_validation)
360 360
 		{
@@ -370,14 +370,14 @@  discard block
 block discarded – undo
370 370
 		// tell request call to remove request, if it is not modified eg. by call to exec in callback
371 371
 		self::$request->remove_if_not_modified();
372 372
 
373
-		foreach(Hooks::process(array(
373
+		foreach (Hooks::process(array(
374 374
 			'hook_location'   => 'etemplate2_before_process',
375 375
 			'location_name'   => $template->id,
376 376
 		) + self::complete_array_merge(self::$request->preserv, $validated)) as $extras)
377 377
 		{
378 378
 			if (!$extras) continue;
379 379
 
380
-			foreach(isset($extras[0]) ? $extras : array($extras) as $extra)
380
+			foreach (isset($extras[0]) ? $extras : array($extras) as $extra)
381 381
 			{
382 382
 				if ($extra['data'] && is_array($extra['data']))
383 383
 				{
@@ -388,9 +388,9 @@  discard block
 block discarded – undo
388 388
 
389 389
 		//error_log(__METHOD__."(,".array2string($content).')');
390 390
 		//error_log(' validated='.array2string($validated));
391
-		if(is_callable(self::$request->method))
391
+		if (is_callable(self::$request->method))
392 392
 		{
393
-			call_user_func(self::$request->method,self::complete_array_merge(self::$request->preserv, $validated));
393
+			call_user_func(self::$request->method, self::complete_array_merge(self::$request->preserv, $validated));
394 394
 		}
395 395
 		else
396 396
 		{
@@ -398,8 +398,7 @@  discard block
 block discarded – undo
398 398
 			$content = ExecMethod(self::$request->method, self::complete_array_merge(self::$request->preserv, $validated));
399 399
 		}
400 400
 
401
-		$tcontent = is_array($content) ? $content :
402
-			self::complete_array_merge(self::$request->preserv, $validated);
401
+		$tcontent = is_array($content) ? $content : self::complete_array_merge(self::$request->preserv, $validated);
403 402
 
404 403
 		$hook_data = Hooks::process(
405 404
 			array(
@@ -411,11 +410,11 @@  discard block
 block discarded – undo
411 410
 
412 411
 		if (is_array($content))
413 412
 		{
414
-			foreach($hook_data as $extras)
413
+			foreach ($hook_data as $extras)
415 414
 			{
416 415
 				if (!$extras) continue;
417 416
 
418
-				foreach(isset($extras[0]) ? $extras : array($extras) as $extra) {
417
+				foreach (isset($extras[0]) ? $extras : array($extras) as $extra) {
419 418
 					if ($extra['data'] && is_array($extra['data'])) {
420 419
 						$content = array_merge($content, $extra['data']);
421 420
 					}
@@ -427,7 +426,7 @@  discard block
 block discarded – undo
427 426
 		if (isset($GLOBALS['egw_info']['flags']['java_script']))
428 427
 		{
429 428
 			// Strip out any script tags
430
-			$GLOBALS['egw_info']['flags']['java_script'] = preg_replace(array('/(<script[^>]*>)([^<]*)/is','/<\/script>/'),array('$2',''),$GLOBALS['egw_info']['flags']['java_script']);
429
+			$GLOBALS['egw_info']['flags']['java_script'] = preg_replace(array('/(<script[^>]*>)([^<]*)/is', '/<\/script>/'), array('$2', ''), $GLOBALS['egw_info']['flags']['java_script']);
431 430
 			self::$response->script($GLOBALS['egw_info']['flags']['java_script']);
432 431
 			//error_log($app .' added javascript to $GLOBALS[egw_info][flags][java_script] - use Json\Response->script() instead.');
433 432
 		}
@@ -456,7 +455,7 @@  discard block
 block discarded – undo
456 455
 	static public function process_exec()
457 456
 	{
458 457
 		if (get_magic_quotes_gpc()) $_POST['value'] = stripslashes($_POST['value']);
459
-		$content = json_decode($_POST['value'],true);
458
+		$content = json_decode($_POST['value'], true);
460 459
 		//error_log(__METHOD__."(".array2string($content).")");
461 460
 
462 461
 		self::$request = Etemplate\Request::read($_POST['etemplate_exec_id']);
@@ -470,7 +469,7 @@  discard block
 block discarded – undo
470 469
 		$expand = array(
471 470
 			'cont' => &self::$request->content,
472 471
 		);
473
-		$template->run('validate', array('', $expand, $content, &$validated), true);	// $respect_disabled=true: do NOT validate disabled widgets and children
472
+		$template->run('validate', array('', $expand, $content, &$validated), true); // $respect_disabled=true: do NOT validate disabled widgets and children
474 473
 		if (self::validation_errors(self::$request->ignore_validation))
475 474
 		{
476 475
 			error_log(__METHOD__."(,".array2string($content).') validation_errors='.array2string(self::$validation_errors));
@@ -506,7 +505,7 @@  discard block
 block discarded – undo
506 505
 	 *
507 506
 	 * @ToDo supported customized templates stored in DB
508 507
 	 */
509
-	public function read($name,$template_set=null,$lang='default',$group=0,$version='',$load_via='')
508
+	public function read($name, $template_set = null, $lang = 'default', $group = 0, $version = '', $load_via = '')
510 509
 	{
511 510
 
512 511
 		// For mobile experience try to load custom mobile templates
@@ -515,9 +514,9 @@  discard block
 block discarded – undo
515 514
 			$template_set = "mobile";
516 515
 		}
517 516
 
518
-		unset($lang); unset($group);	// not used, but in old signature
519
-		$this->rel_path = self::relPath($this->name=$name, $this->template_set=$template_set,
520
-			$this->version=$version, $this->laod_via = $load_via);
517
+		unset($lang); unset($group); // not used, but in old signature
518
+		$this->rel_path = self::relPath($this->name = $name, $this->template_set = $template_set,
519
+			$this->version = $version, $this->laod_via = $load_via);
521 520
 		//error_log(__METHOD__."('$name', '$template_set', '$lang', $group, '$version', '$load_via') rel_path=".array2string($this->rel_path));
522 521
 
523 522
 		$this->dom_id = $name;
@@ -572,7 +571,7 @@  discard block
 block discarded – undo
572 571
 	 * @return mixed reference to attribute, usually NULL
573 572
 	 * @deprecated use getElementAttribute($name, $attr)
574 573
 	 */
575
-	public function &get_cell_attribute($name,$attr)
574
+	public function &get_cell_attribute($name, $attr)
576 575
 	{
577 576
 		return self::getElementAttribute($name, $attr);
578 577
 	}
@@ -586,7 +585,7 @@  discard block
 block discarded – undo
586 585
 	 * @return reference to attribute
587 586
 	 * @deprecated use setElementAttribute($name, $attr, $val)
588 587
 	 */
589
-	public function &set_cell_attribute($name,$attr,$val)
588
+	public function &set_cell_attribute($name, $attr, $val)
590 589
 	{
591 590
 		return self::setElementAttribute($name, $attr, $val);
592 591
 	}
@@ -599,7 +598,7 @@  discard block
 block discarded – undo
599 598
 	 * @return reference to attribute
600 599
 	 * @deprecated use disableElement($name, $disabled=true)
601 600
 	 */
602
-	public function disable_cells($name,$disabled=True)
601
+	public function disable_cells($name, $disabled = True)
603 602
 	{
604 603
 		return self::disableElement($name, $disabled);
605 604
 	}
@@ -615,23 +614,23 @@  discard block
 block discarded – undo
615 614
 	 * @param array $new
616 615
 	 * @return array the merged array
617 616
 	 */
618
-	public static function complete_array_merge($old,$new)
617
+	public static function complete_array_merge($old, $new)
619 618
 	{
620 619
 		if (is_array($new))
621 620
 		{
622
-			if (!is_array($old)) $old = (array) $old;
621
+			if (!is_array($old)) $old = (array)$old;
623 622
 
624
-			foreach($new as $k => $v)
623
+			foreach ($new as $k => $v)
625 624
 			{
626
-				if (!is_array($v) || !isset($old[$k]) || 	// no array or a new array
627
-					isset($v[0]) && !is_array($v[0]) && isset($v[count($v)-1])	|| // or no associative array, eg. selecting multiple accounts
625
+				if (!is_array($v) || !isset($old[$k]) || // no array or a new array
626
+					isset($v[0]) && !is_array($v[0]) && isset($v[count($v) - 1]) || // or no associative array, eg. selecting multiple accounts
628 627
 					is_array($v) && count($v) == 0)			// Empty array replacing non-empty
629 628
 				{
630 629
 					$old[$k] = $v;
631 630
 				}
632 631
 				else
633 632
 				{
634
-					$old[$k] = self::complete_array_merge($old[$k],$v);
633
+					$old[$k] = self::complete_array_merge($old[$k], $v);
635 634
 				}
636 635
 			}
637 636
 		}
@@ -643,7 +642,7 @@  discard block
 block discarded – undo
643 642
 	 *
644 643
 	 * @param array $content =null
645 644
 	 */
646
-	public function debug(array $content=null)
645
+	public function debug(array $content = null)
647 646
 	{
648 647
 		$GLOBALS['egw']->framework->render(print_r($content, true));
649 648
 	}
@@ -657,11 +656,11 @@  discard block
 block discarded – undo
657 656
 	 * @param int &$max_upload=null on return max. upload size in byte
658 657
 	 * @return string
659 658
 	 */
660
-	static function max_upload_size_message(&$max_upload=null)
659
+	static function max_upload_size_message(&$max_upload = null)
661 660
 	{
662 661
 		$upload_max_filesize = ini_get('upload_max_filesize');
663 662
 		$post_max_size = ini_get('post_max_size');
664
-		$max_upload = min(self::km2int($upload_max_filesize),self::km2int($post_max_size)-2800);
663
+		$max_upload = min(self::km2int($upload_max_filesize), self::km2int($post_max_size) - 2800);
665 664
 
666 665
 		return lang('Maximum size for uploads').': '.Vfs::hsize($max_upload).
667 666
 			" (php.ini: upload_max_filesize=$upload_max_filesize, post_max_size=$post_max_size)";
@@ -675,9 +674,9 @@  discard block
 block discarded – undo
675 674
 	 * @param boolean $readonly =true
676 675
 	 * @return string
677 676
 	 */
678
-	static public function number_format($number,$num_decimal_places=2,$readonly=true)
677
+	static public function number_format($number, $num_decimal_places = 2, $readonly = true)
679 678
 	{
680
-		static $dec_separator=null,$thousands_separator=null;
679
+		static $dec_separator = null, $thousands_separator = null;
681 680
 		if (is_null($dec_separator))
682 681
 		{
683 682
 			$dec_separator = $GLOBALS['egw_info']['user']['preferences']['common']['number_format'][0];
@@ -686,7 +685,7 @@  discard block
 block discarded – undo
686 685
 		}
687 686
 		if ((string)$number === '') return '';
688 687
 
689
-		return number_format(str_replace(' ','',$number),$num_decimal_places,$dec_separator,$readonly ? $thousands_separator : '');
688
+		return number_format(str_replace(' ', '', $number), $num_decimal_places, $dec_separator, $readonly ? $thousands_separator : '');
690 689
 	}
691 690
 
692 691
 	/**
@@ -699,13 +698,13 @@  discard block
 block discarded – undo
699 698
 	{
700 699
 		if (!is_numeric($size))
701 700
 		{
702
-			switch(strtolower(substr($size,-1)))
701
+			switch (strtolower(substr($size, -1)))
703 702
 			{
704 703
 				case 'm':
705
-					$size = 1024*1024*(int)$size;
704
+					$size = 1024 * 1024 * (int)$size;
706 705
 					break;
707 706
 				case 'k':
708
-					$size = 1024*(int)$size;
707
+					$size = 1024 * (int)$size;
709 708
 					break;
710 709
 			}
711 710
 		}
Please login to merge, or discard this patch.