Completed
Push — 17.1 ( e791a5...a2e62e )
by Ralf
40:37 queued 26:22
created
api/src/Etemplate.php 2 patches
Doc Comments   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -579,7 +579,7 @@  discard block
 block discarded – undo
579 579
 	 *
580 580
 	 * @param string $name cell-name
581 581
 	 * @param string $attr attribute-name
582
-	 * @param mixed $val if not NULL sets attribute else returns it
582
+	 * @param boolean|string $val if not NULL sets attribute else returns it
583 583
 	 * @return reference to attribute
584 584
 	 * @deprecated use setElementAttribute($name, $attr, $val)
585 585
 	 */
@@ -638,7 +638,6 @@  discard block
 block discarded – undo
638 638
 	/**
639 639
 	 * Deep copy array to make sure there are no references
640 640
 	 *
641
-	 * @param Array $array
642 641
 	 * @return Array
643 642
 	 */
644 643
 	public static function deep_copy($source)
Please login to merge, or discard this patch.
Spacing   +62 added lines, -63 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
 			// Deep copy rows so we don't lose them when request is set to null
206 206
 			// (some content by reference)
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
 		}
209 209
 
210 210
 		// Info required to load the etemplate client-side
211
-		$dom_id = str_replace('.','-',$this->dom_id);
211
+		$dom_id = str_replace('.', '-', $this->dom_id);
212 212
 		$load_array = array(
213 213
 			'name' => $this->name,
214 214
 			'url' => self::rel2url($this->rel_path),
@@ -218,16 +218,16 @@  discard block
 block discarded – undo
218 218
 		if (self::$response)	// call is within an ajax event / form submit
219 219
 		{
220 220
 			//error_log("Ajax " . __LINE__);
221
-			self::$response->generic('et2_load', $load_array+Framework::get_extra());
222
-			Framework::clear_extra();	// to not send/set it twice for multiple etemplates (eg. CRM view)
221
+			self::$response->generic('et2_load', $load_array + Framework::get_extra());
222
+			Framework::clear_extra(); // to not send/set it twice for multiple etemplates (eg. CRM view)
223 223
 		}
224 224
 		else	// first call
225 225
 		{
226 226
 			// check if application of template has a app.js file --> load it
227
-			list($app) = explode('.',$this->name);
227
+			list($app) = explode('.', $this->name);
228 228
 			if (file_exists(EGW_SERVER_ROOT.'/'.$app.'/js/app.js'))
229 229
 			{
230
-				Framework::includeJS('.','app',$app,true);
230
+				Framework::includeJS('.', 'app', $app, true);
231 231
 			}
232 232
 			// Category styles
233 233
 			Categories::css($app);
@@ -245,12 +245,12 @@  discard block
 block discarded – undo
245 245
 				$content = '<form target="egw_iframe_autocomplete_helper" action="'.$form_action.'" id="'.$dom_id.'" class="et2_container"></form>'."\n".
246 246
 					'<iframe name="egw_iframe_autocomplete_helper" style="width:0;height:0;position: absolute;visibility:hidden;"></iframe>';
247 247
 				$GLOBALS['egw']->framework->response->generic("data", array($content));
248
-				$GLOBALS['egw']->framework->response->generic('et2_load',$load_array+Framework::get_extra());
249
-				Framework::clear_extra();	// to not send/set it twice for multiple etemplates (eg. CRM view)
248
+				$GLOBALS['egw']->framework->response->generic('et2_load', $load_array + Framework::get_extra());
249
+				Framework::clear_extra(); // to not send/set it twice for multiple etemplates (eg. CRM view)
250 250
 
251 251
 				// Really important to run this or weird things happen
252 252
 				// See https://help.egroupware.org/t/nextmatch-wert-im-header-ausgeben/73412/11
253
-				self::$request=null;
253
+				self::$request = null;
254 254
 				return;
255 255
 			}
256 256
 			// let framework know, if we are a popup or not ('popup' not true, which is allways used by index.php!)
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
 				echo '<div id="popupMainDiv" class="popupMainDiv">'."\n";
269 269
 			}
270 270
 			// Send any accumulated json responses - after flush to avoid sending the buffer as a response
271
-			if(Json\Response::isJSONResponse())
271
+			if (Json\Response::isJSONResponse())
272 272
 			{
273 273
 				$load_array['response'] = Json\Response::get()->returnResult();
274 274
 			}
@@ -297,10 +297,10 @@  discard block
 block discarded – undo
297 297
 	 */
298 298
 	static protected function fix_sel_options(array $sel_options)
299 299
 	{
300
-		foreach($sel_options as &$options)
300
+		foreach ($sel_options as &$options)
301 301
 		{
302
-			if (!is_array($options)||empty($options)) continue;
303
-			foreach($options as $key => $value)
302
+			if (!is_array($options) || empty($options)) continue;
303
+			foreach ($options as $key => $value)
304 304
 			{
305 305
 				if (is_numeric($key) && (!is_array($value) || !isset($value['value'])))
306 306
 				{
@@ -339,9 +339,9 @@  discard block
 block discarded – undo
339 339
 		$GLOBALS['egw']->session->set_action('Etemplate: '.self::$request->method);
340 340
 
341 341
 		// Set current app for validation
342
-		list($app) = explode('.',self::$request->method);
343
-		if(!$app) list($app) = explode('::',self::$request->method);
344
-		if($app)
342
+		list($app) = explode('.', self::$request->method);
343
+		if (!$app) list($app) = explode('::', self::$request->method);
344
+		if ($app)
345 345
 		{
346 346
 			Translation::add_app($app);
347 347
 			$GLOBALS['egw_info']['flags']['currentapp'] = $app;
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
 		$expand = array(
351 351
 			'cont' => &self::$request->content,
352 352
 		);
353
-		$template->run('validate', array('', $expand, $_content, &$validated), true);	// $respect_disabled=true: do NOT validate disabled widgets and children
353
+		$template->run('validate', array('', $expand, $_content, &$validated), true); // $respect_disabled=true: do NOT validate disabled widgets and children
354 354
 
355 355
 		if ($no_validation)
356 356
 		{
@@ -366,14 +366,14 @@  discard block
 block discarded – undo
366 366
 		// tell request call to remove request, if it is not modified eg. by call to exec in callback
367 367
 		self::$request->remove_if_not_modified();
368 368
 
369
-		foreach(Hooks::process(array(
369
+		foreach (Hooks::process(array(
370 370
 			'hook_location'   => 'etemplate2_before_process',
371 371
 			'location_name'   => $template->id,
372 372
 		) + self::complete_array_merge(self::$request->preserv, $validated)) as $extras)
373 373
 		{
374 374
 			if (!$extras) continue;
375 375
 
376
-			foreach(isset($extras[0]) ? $extras : array($extras) as $extra)
376
+			foreach (isset($extras[0]) ? $extras : array($extras) as $extra)
377 377
 			{
378 378
 				if ($extra['data'] && is_array($extra['data']))
379 379
 				{
@@ -384,9 +384,9 @@  discard block
 block discarded – undo
384 384
 
385 385
 		//error_log(__METHOD__."(,".array2string($content).')');
386 386
 		//error_log(' validated='.array2string($validated));
387
-		if(is_callable(self::$request->method))
387
+		if (is_callable(self::$request->method))
388 388
 		{
389
-			call_user_func(self::$request->method,self::complete_array_merge(self::$request->preserv, $validated));
389
+			call_user_func(self::$request->method, self::complete_array_merge(self::$request->preserv, $validated));
390 390
 		}
391 391
 		else
392 392
 		{
@@ -394,8 +394,7 @@  discard block
 block discarded – undo
394 394
 			$content = ExecMethod(self::$request->method, self::complete_array_merge(self::$request->preserv, $validated));
395 395
 		}
396 396
 
397
-		$tcontent = is_array($content) ? $content :
398
-			self::complete_array_merge(self::$request->preserv, $validated);
397
+		$tcontent = is_array($content) ? $content : self::complete_array_merge(self::$request->preserv, $validated);
399 398
 
400 399
 		$hook_data = Hooks::process(
401 400
 			array(
@@ -407,11 +406,11 @@  discard block
 block discarded – undo
407 406
 
408 407
 		if (is_array($content))
409 408
 		{
410
-			foreach($hook_data as $extras)
409
+			foreach ($hook_data as $extras)
411 410
 			{
412 411
 				if (!$extras) continue;
413 412
 
414
-				foreach(isset($extras[0]) ? $extras : array($extras) as $extra) {
413
+				foreach (isset($extras[0]) ? $extras : array($extras) as $extra) {
415 414
 					if ($extra['data'] && is_array($extra['data'])) {
416 415
 						$content = array_merge($content, $extra['data']);
417 416
 					}
@@ -423,7 +422,7 @@  discard block
 block discarded – undo
423 422
 		if (isset($GLOBALS['egw_info']['flags']['java_script']))
424 423
 		{
425 424
 			// Strip out any script tags
426
-			$GLOBALS['egw_info']['flags']['java_script'] = preg_replace(array('/(<script[^>]*>)([^<]*)/is','/<\/script>/'),array('$2',''),$GLOBALS['egw_info']['flags']['java_script']);
425
+			$GLOBALS['egw_info']['flags']['java_script'] = preg_replace(array('/(<script[^>]*>)([^<]*)/is', '/<\/script>/'), array('$2', ''), $GLOBALS['egw_info']['flags']['java_script']);
427 426
 			self::$response->script($GLOBALS['egw_info']['flags']['java_script']);
428 427
 			//error_log($app .' added javascript to $GLOBALS[egw_info][flags][java_script] - use Json\Response->script() instead.');
429 428
 		}
@@ -452,7 +451,7 @@  discard block
 block discarded – undo
452 451
 	static public function process_exec()
453 452
 	{
454 453
 		if (get_magic_quotes_gpc()) $_POST['value'] = stripslashes($_POST['value']);
455
-		$content = json_decode($_POST['value'],true);
454
+		$content = json_decode($_POST['value'], true);
456 455
 		//error_log(__METHOD__."(".array2string($content).")");
457 456
 
458 457
 		self::$request = Etemplate\Request::read($_POST['etemplate_exec_id']);
@@ -466,7 +465,7 @@  discard block
 block discarded – undo
466 465
 		$expand = array(
467 466
 			'cont' => &self::$request->content,
468 467
 		);
469
-		$template->run('validate', array('', $expand, $content, &$validated), true);	// $respect_disabled=true: do NOT validate disabled widgets and children
468
+		$template->run('validate', array('', $expand, $content, &$validated), true); // $respect_disabled=true: do NOT validate disabled widgets and children
470 469
 		if (self::validation_errors(self::$request->ignore_validation))
471 470
 		{
472 471
 			error_log(__METHOD__."(,".array2string($content).') validation_errors='.array2string(self::$validation_errors));
@@ -502,7 +501,7 @@  discard block
 block discarded – undo
502 501
 	 *
503 502
 	 * @ToDo supported customized templates stored in DB
504 503
 	 */
505
-	public function read($name,$template_set=null,$lang='default',$group=0,$version='',$load_via='')
504
+	public function read($name, $template_set = null, $lang = 'default', $group = 0, $version = '', $load_via = '')
506 505
 	{
507 506
 
508 507
 		// For mobile experience try to load custom mobile templates
@@ -511,9 +510,9 @@  discard block
 block discarded – undo
511 510
 			$template_set = "mobile";
512 511
 		}
513 512
 
514
-		unset($lang); unset($group);	// not used, but in old signature
515
-		$this->rel_path = self::relPath($this->name=$name, $this->template_set=$template_set,
516
-			$this->version=$version, $this->laod_via = $load_via);
513
+		unset($lang); unset($group); // not used, but in old signature
514
+		$this->rel_path = self::relPath($this->name = $name, $this->template_set = $template_set,
515
+			$this->version = $version, $this->laod_via = $load_via);
517 516
 		//error_log(__METHOD__."('$name', '$template_set', '$lang', $group, '$version', '$load_via') rel_path=".array2string($this->rel_path));
518 517
 
519 518
 		$this->dom_id = $name;
@@ -568,7 +567,7 @@  discard block
 block discarded – undo
568 567
 	 * @return mixed reference to attribute, usually NULL
569 568
 	 * @deprecated use getElementAttribute($name, $attr)
570 569
 	 */
571
-	public function &get_cell_attribute($name,$attr)
570
+	public function &get_cell_attribute($name, $attr)
572 571
 	{
573 572
 		return self::getElementAttribute($name, $attr);
574 573
 	}
@@ -582,7 +581,7 @@  discard block
 block discarded – undo
582 581
 	 * @return reference to attribute
583 582
 	 * @deprecated use setElementAttribute($name, $attr, $val)
584 583
 	 */
585
-	public function &set_cell_attribute($name,$attr,$val)
584
+	public function &set_cell_attribute($name, $attr, $val)
586 585
 	{
587 586
 		return self::setElementAttribute($name, $attr, $val);
588 587
 	}
@@ -595,7 +594,7 @@  discard block
 block discarded – undo
595 594
 	 * @return reference to attribute
596 595
 	 * @deprecated use disableElement($name, $disabled=true)
597 596
 	 */
598
-	public function disable_cells($name,$disabled=True)
597
+	public function disable_cells($name, $disabled = True)
599 598
 	{
600 599
 		return self::disableElement($name, $disabled);
601 600
 	}
@@ -611,23 +610,23 @@  discard block
 block discarded – undo
611 610
 	 * @param array $new
612 611
 	 * @return array the merged array
613 612
 	 */
614
-	public static function complete_array_merge($old,$new)
613
+	public static function complete_array_merge($old, $new)
615 614
 	{
616 615
 		if (is_array($new))
617 616
 		{
618
-			if (!is_array($old)) $old = (array) $old;
617
+			if (!is_array($old)) $old = (array)$old;
619 618
 
620
-			foreach($new as $k => $v)
619
+			foreach ($new as $k => $v)
621 620
 			{
622
-				if (!is_array($v) || !isset($old[$k]) || 	// no array or a new array
623
-					isset($v[0]) && !is_array($v[0]) && isset($v[count($v)-1])	|| // or no associative array, eg. selecting multiple accounts
621
+				if (!is_array($v) || !isset($old[$k]) || // no array or a new array
622
+					isset($v[0]) && !is_array($v[0]) && isset($v[count($v) - 1]) || // or no associative array, eg. selecting multiple accounts
624 623
 					is_array($v) && count($v) == 0)			// Empty array replacing non-empty
625 624
 				{
626 625
 					$old[$k] = $v;
627 626
 				}
628 627
 				else
629 628
 				{
630
-					$old[$k] = self::complete_array_merge($old[$k],$v);
629
+					$old[$k] = self::complete_array_merge($old[$k], $v);
631 630
 				}
632 631
 			}
633 632
 		}
@@ -669,7 +668,7 @@  discard block
 block discarded – undo
669 668
 	 *
670 669
 	 * @param array $content =null
671 670
 	 */
672
-	public function debug(array $content=null)
671
+	public function debug(array $content = null)
673 672
 	{
674 673
 		$GLOBALS['egw']->framework->render(print_r($content, true));
675 674
 	}
@@ -683,11 +682,11 @@  discard block
 block discarded – undo
683 682
 	 * @param int &$max_upload=null on return max. upload size in byte
684 683
 	 * @return string
685 684
 	 */
686
-	static function max_upload_size_message(&$max_upload=null)
685
+	static function max_upload_size_message(&$max_upload = null)
687 686
 	{
688 687
 		$upload_max_filesize = ini_get('upload_max_filesize');
689 688
 		$post_max_size = ini_get('post_max_size');
690
-		$max_upload = min(self::km2int($upload_max_filesize),self::km2int($post_max_size)-2800);
689
+		$max_upload = min(self::km2int($upload_max_filesize), self::km2int($post_max_size) - 2800);
691 690
 
692 691
 		return lang('Maximum size for uploads').': '.Vfs::hsize($max_upload).
693 692
 			" (php.ini: upload_max_filesize=$upload_max_filesize, post_max_size=$post_max_size)";
@@ -701,9 +700,9 @@  discard block
 block discarded – undo
701 700
 	 * @param boolean $readonly =true
702 701
 	 * @return string
703 702
 	 */
704
-	static public function number_format($number,$num_decimal_places=2,$readonly=true)
703
+	static public function number_format($number, $num_decimal_places = 2, $readonly = true)
705 704
 	{
706
-		static $dec_separator=null,$thousands_separator=null;
705
+		static $dec_separator = null, $thousands_separator = null;
707 706
 		if (is_null($dec_separator))
708 707
 		{
709 708
 			$dec_separator = $GLOBALS['egw_info']['user']['preferences']['common']['number_format'][0];
@@ -712,7 +711,7 @@  discard block
 block discarded – undo
712 711
 		}
713 712
 		if ((string)$number === '') return '';
714 713
 
715
-		return number_format(str_replace(' ','',$number),$num_decimal_places,$dec_separator,$readonly ? $thousands_separator : '');
714
+		return number_format(str_replace(' ', '', $number), $num_decimal_places, $dec_separator, $readonly ? $thousands_separator : '');
716 715
 	}
717 716
 
718 717
 	/**
@@ -725,13 +724,13 @@  discard block
 block discarded – undo
725 724
 	{
726 725
 		if (!is_numeric($size))
727 726
 		{
728
-			switch(strtolower(substr($size,-1)))
727
+			switch (strtolower(substr($size, -1)))
729 728
 			{
730 729
 				case 'm':
731
-					$size = 1024*1024*(int)$size;
730
+					$size = 1024 * 1024 * (int)$size;
732 731
 					break;
733 732
 				case 'k':
734
-					$size = 1024*(int)$size;
733
+					$size = 1024 * (int)$size;
735 734
 					break;
736 735
 			}
737 736
 		}
Please login to merge, or discard this patch.