Test Setup Failed
Push — 17.1 ( 152c57...380500 )
by Nathan
17:15 queued 07:57
created
api/src/Etemplate.php 1 patch
Spacing   +60 added lines, -61 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
 			{
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
 		);
202 202
 
203 203
 		// Info required to load the etemplate client-side
204
-		$dom_id = str_replace('.','-',$this->dom_id);
204
+		$dom_id = str_replace('.', '-', $this->dom_id);
205 205
 		$load_array = array(
206 206
 			'name' => $this->name,
207 207
 			'url' => self::rel2url($this->rel_path),
@@ -211,16 +211,16 @@  discard block
 block discarded – undo
211 211
 		if (self::$response)	// call is within an ajax event / form submit
212 212
 		{
213 213
 			//error_log("Ajax " . __LINE__);
214
-			self::$response->generic('et2_load', $load_array+Framework::get_extra());
215
-			Framework::clear_extra();	// to not send/set it twice for multiple etemplates (eg. CRM view)
214
+			self::$response->generic('et2_load', $load_array + Framework::get_extra());
215
+			Framework::clear_extra(); // to not send/set it twice for multiple etemplates (eg. CRM view)
216 216
 		}
217 217
 		else	// first call
218 218
 		{
219 219
 			// check if application of template has a app.js file --> load it
220
-			list($app) = explode('.',$this->name);
220
+			list($app) = explode('.', $this->name);
221 221
 			if (file_exists(EGW_SERVER_ROOT.'/'.$app.'/js/app.js'))
222 222
 			{
223
-				Framework::includeJS('.','app',$app,true);
223
+				Framework::includeJS('.', 'app', $app, true);
224 224
 			}
225 225
 			// Category styles
226 226
 			Categories::css($app);
@@ -238,8 +238,8 @@  discard block
 block discarded – undo
238 238
 				$content = '<form target="egw_iframe_autocomplete_helper" action="'.$form_action.'" id="'.$dom_id.'" class="et2_container"></form>'."\n".
239 239
 					'<iframe name="egw_iframe_autocomplete_helper" style="width:0;height:0;position: absolute;visibility:hidden;"></iframe>';
240 240
 				$GLOBALS['egw']->framework->response->generic("data", array($content));
241
-				$GLOBALS['egw']->framework->response->generic('et2_load',$load_array+Framework::get_extra());
242
-				Framework::clear_extra();	// to not send/set it twice for multiple etemplates (eg. CRM view)
241
+				$GLOBALS['egw']->framework->response->generic('et2_load', $load_array + Framework::get_extra());
242
+				Framework::clear_extra(); // to not send/set it twice for multiple etemplates (eg. CRM view)
243 243
 				return;
244 244
 			}
245 245
 			// let framework know, if we are a popup or not ('popup' not true, which is allways used by index.php!)
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
 				echo '<div id="popupMainDiv" class="popupMainDiv">'."\n";
258 258
 			}
259 259
 			// Send any accumulated json responses - after flush to avoid sending the buffer as a response
260
-			if(Json\Response::isJSONResponse())
260
+			if (Json\Response::isJSONResponse())
261 261
 			{
262 262
 				$load_array['response'] = Json\Response::get()->returnResult();
263 263
 			}
@@ -286,10 +286,10 @@  discard block
 block discarded – undo
286 286
 	 */
287 287
 	static protected function fix_sel_options(array $sel_options)
288 288
 	{
289
-		foreach($sel_options as &$options)
289
+		foreach ($sel_options as &$options)
290 290
 		{
291
-			if (!is_array($options)||empty($options)) continue;
292
-			foreach($options as $key => $value)
291
+			if (!is_array($options) || empty($options)) continue;
292
+			foreach ($options as $key => $value)
293 293
 			{
294 294
 				if (is_numeric($key) && (!is_array($value) || !isset($value['value'])))
295 295
 				{
@@ -328,9 +328,9 @@  discard block
 block discarded – undo
328 328
 		$GLOBALS['egw']->session->set_action('Etemplate: '.self::$request->method);
329 329
 
330 330
 		// Set current app for validation
331
-		list($app) = explode('.',self::$request->method);
332
-		if(!$app) list($app) = explode('::',self::$request->method);
333
-		if($app)
331
+		list($app) = explode('.', self::$request->method);
332
+		if (!$app) list($app) = explode('::', self::$request->method);
333
+		if ($app)
334 334
 		{
335 335
 			Translation::add_app($app);
336 336
 			$GLOBALS['egw_info']['flags']['currentapp'] = $app;
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
 		$expand = array(
340 340
 			'cont' => &self::$request->content,
341 341
 		);
342
-		$template->run('validate', array('', $expand, $_content, &$validated), true);	// $respect_disabled=true: do NOT validate disabled widgets and children
342
+		$template->run('validate', array('', $expand, $_content, &$validated), true); // $respect_disabled=true: do NOT validate disabled widgets and children
343 343
 
344 344
 		if ($no_validation)
345 345
 		{
@@ -355,14 +355,14 @@  discard block
 block discarded – undo
355 355
 		// tell request call to remove request, if it is not modified eg. by call to exec in callback
356 356
 		self::$request->remove_if_not_modified();
357 357
 
358
-		foreach(Hooks::process(array(
358
+		foreach (Hooks::process(array(
359 359
 			'hook_location'   => 'etemplate2_before_process',
360 360
 			'location_name'   => $template->id,
361 361
 		) + self::complete_array_merge(self::$request->preserv, $validated)) as $extras)
362 362
 		{
363 363
 			if (!$extras) continue;
364 364
 
365
-			foreach(isset($extras[0]) ? $extras : array($extras) as $extra)
365
+			foreach (isset($extras[0]) ? $extras : array($extras) as $extra)
366 366
 			{
367 367
 				if ($extra['data'] && is_array($extra['data']))
368 368
 				{
@@ -373,9 +373,9 @@  discard block
 block discarded – undo
373 373
 
374 374
 		//error_log(__METHOD__."(,".array2string($content).')');
375 375
 		//error_log(' validated='.array2string($validated));
376
-		if(is_callable(self::$request->method))
376
+		if (is_callable(self::$request->method))
377 377
 		{
378
-			call_user_func(self::$request->method,self::complete_array_merge(self::$request->preserv, $validated));
378
+			call_user_func(self::$request->method, self::complete_array_merge(self::$request->preserv, $validated));
379 379
 		}
380 380
 		else
381 381
 		{
@@ -383,8 +383,7 @@  discard block
 block discarded – undo
383 383
 			$content = ExecMethod(self::$request->method, self::complete_array_merge(self::$request->preserv, $validated));
384 384
 		}
385 385
 
386
-		$tcontent = is_array($content) ? $content :
387
-			self::complete_array_merge(self::$request->preserv, $validated);
386
+		$tcontent = is_array($content) ? $content : self::complete_array_merge(self::$request->preserv, $validated);
388 387
 
389 388
 		$hook_data = Hooks::process(
390 389
 			array(
@@ -396,11 +395,11 @@  discard block
 block discarded – undo
396 395
 
397 396
 		if (is_array($content))
398 397
 		{
399
-			foreach($hook_data as $extras)
398
+			foreach ($hook_data as $extras)
400 399
 			{
401 400
 				if (!$extras) continue;
402 401
 
403
-				foreach(isset($extras[0]) ? $extras : array($extras) as $extra) {
402
+				foreach (isset($extras[0]) ? $extras : array($extras) as $extra) {
404 403
 					if ($extra['data'] && is_array($extra['data'])) {
405 404
 						$content = array_merge($content, $extra['data']);
406 405
 					}
@@ -412,7 +411,7 @@  discard block
 block discarded – undo
412 411
 		if (isset($GLOBALS['egw_info']['flags']['java_script']))
413 412
 		{
414 413
 			// Strip out any script tags
415
-			$GLOBALS['egw_info']['flags']['java_script'] = preg_replace(array('/(<script[^>]*>)([^<]*)/is','/<\/script>/'),array('$2',''),$GLOBALS['egw_info']['flags']['java_script']);
414
+			$GLOBALS['egw_info']['flags']['java_script'] = preg_replace(array('/(<script[^>]*>)([^<]*)/is', '/<\/script>/'), array('$2', ''), $GLOBALS['egw_info']['flags']['java_script']);
416 415
 			self::$response->script($GLOBALS['egw_info']['flags']['java_script']);
417 416
 			//error_log($app .' added javascript to $GLOBALS[egw_info][flags][java_script] - use Json\Response->script() instead.');
418 417
 		}
@@ -441,7 +440,7 @@  discard block
 block discarded – undo
441 440
 	static public function process_exec()
442 441
 	{
443 442
 		if (get_magic_quotes_gpc()) $_POST['value'] = stripslashes($_POST['value']);
444
-		$content = json_decode($_POST['value'],true);
443
+		$content = json_decode($_POST['value'], true);
445 444
 		//error_log(__METHOD__."(".array2string($content).")");
446 445
 
447 446
 		self::$request = Etemplate\Request::read($_POST['etemplate_exec_id']);
@@ -455,7 +454,7 @@  discard block
 block discarded – undo
455 454
 		$expand = array(
456 455
 			'cont' => &self::$request->content,
457 456
 		);
458
-		$template->run('validate', array('', $expand, $content, &$validated), true);	// $respect_disabled=true: do NOT validate disabled widgets and children
457
+		$template->run('validate', array('', $expand, $content, &$validated), true); // $respect_disabled=true: do NOT validate disabled widgets and children
459 458
 		if (self::validation_errors(self::$request->ignore_validation))
460 459
 		{
461 460
 			error_log(__METHOD__."(,".array2string($content).') validation_errors='.array2string(self::$validation_errors));
@@ -491,7 +490,7 @@  discard block
 block discarded – undo
491 490
 	 *
492 491
 	 * @ToDo supported customized templates stored in DB
493 492
 	 */
494
-	public function read($name,$template_set=null,$lang='default',$group=0,$version='',$load_via='')
493
+	public function read($name, $template_set = null, $lang = 'default', $group = 0, $version = '', $load_via = '')
495 494
 	{
496 495
 
497 496
 		// For mobile experience try to load custom mobile templates
@@ -500,9 +499,9 @@  discard block
 block discarded – undo
500 499
 			$template_set = "mobile";
501 500
 		}
502 501
 
503
-		unset($lang); unset($group);	// not used, but in old signature
504
-		$this->rel_path = self::relPath($this->name=$name, $this->template_set=$template_set,
505
-			$this->version=$version, $this->laod_via = $load_via);
502
+		unset($lang); unset($group); // not used, but in old signature
503
+		$this->rel_path = self::relPath($this->name = $name, $this->template_set = $template_set,
504
+			$this->version = $version, $this->laod_via = $load_via);
506 505
 		//error_log(__METHOD__."('$name', '$template_set', '$lang', $group, '$version', '$load_via') rel_path=".array2string($this->rel_path));
507 506
 
508 507
 		$this->dom_id = $name;
@@ -557,7 +556,7 @@  discard block
 block discarded – undo
557 556
 	 * @return mixed reference to attribute, usually NULL
558 557
 	 * @deprecated use getElementAttribute($name, $attr)
559 558
 	 */
560
-	public function &get_cell_attribute($name,$attr)
559
+	public function &get_cell_attribute($name, $attr)
561 560
 	{
562 561
 		return self::getElementAttribute($name, $attr);
563 562
 	}
@@ -571,7 +570,7 @@  discard block
 block discarded – undo
571 570
 	 * @return reference to attribute
572 571
 	 * @deprecated use setElementAttribute($name, $attr, $val)
573 572
 	 */
574
-	public function &set_cell_attribute($name,$attr,$val)
573
+	public function &set_cell_attribute($name, $attr, $val)
575 574
 	{
576 575
 		return self::setElementAttribute($name, $attr, $val);
577 576
 	}
@@ -584,7 +583,7 @@  discard block
 block discarded – undo
584 583
 	 * @return reference to attribute
585 584
 	 * @deprecated use disableElement($name, $disabled=true)
586 585
 	 */
587
-	public function disable_cells($name,$disabled=True)
586
+	public function disable_cells($name, $disabled = True)
588 587
 	{
589 588
 		return self::disableElement($name, $disabled);
590 589
 	}
@@ -600,23 +599,23 @@  discard block
 block discarded – undo
600 599
 	 * @param array $new
601 600
 	 * @return array the merged array
602 601
 	 */
603
-	public static function complete_array_merge($old,$new)
602
+	public static function complete_array_merge($old, $new)
604 603
 	{
605 604
 		if (is_array($new))
606 605
 		{
607
-			if (!is_array($old)) $old = (array) $old;
606
+			if (!is_array($old)) $old = (array)$old;
608 607
 
609
-			foreach($new as $k => $v)
608
+			foreach ($new as $k => $v)
610 609
 			{
611
-				if (!is_array($v) || !isset($old[$k]) || 	// no array or a new array
612
-					isset($v[0]) && !is_array($v[0]) && isset($v[count($v)-1])	|| // or no associative array, eg. selecting multiple accounts
610
+				if (!is_array($v) || !isset($old[$k]) || // no array or a new array
611
+					isset($v[0]) && !is_array($v[0]) && isset($v[count($v) - 1]) || // or no associative array, eg. selecting multiple accounts
613 612
 					is_array($v) && count($v) == 0)			// Empty array replacing non-empty
614 613
 				{
615 614
 					$old[$k] = $v;
616 615
 				}
617 616
 				else
618 617
 				{
619
-					$old[$k] = self::complete_array_merge($old[$k],$v);
618
+					$old[$k] = self::complete_array_merge($old[$k], $v);
620 619
 				}
621 620
 			}
622 621
 		}
@@ -628,7 +627,7 @@  discard block
 block discarded – undo
628 627
 	 *
629 628
 	 * @param array $content =null
630 629
 	 */
631
-	public function debug(array $content=null)
630
+	public function debug(array $content = null)
632 631
 	{
633 632
 		$GLOBALS['egw']->framework->render(print_r($content, true));
634 633
 	}
@@ -642,11 +641,11 @@  discard block
 block discarded – undo
642 641
 	 * @param int &$max_upload=null on return max. upload size in byte
643 642
 	 * @return string
644 643
 	 */
645
-	static function max_upload_size_message(&$max_upload=null)
644
+	static function max_upload_size_message(&$max_upload = null)
646 645
 	{
647 646
 		$upload_max_filesize = ini_get('upload_max_filesize');
648 647
 		$post_max_size = ini_get('post_max_size');
649
-		$max_upload = min(self::km2int($upload_max_filesize),self::km2int($post_max_size)-2800);
648
+		$max_upload = min(self::km2int($upload_max_filesize), self::km2int($post_max_size) - 2800);
650 649
 
651 650
 		return lang('Maximum size for uploads').': '.Vfs::hsize($max_upload).
652 651
 			" (php.ini: upload_max_filesize=$upload_max_filesize, post_max_size=$post_max_size)";
@@ -660,9 +659,9 @@  discard block
 block discarded – undo
660 659
 	 * @param boolean $readonly =true
661 660
 	 * @return string
662 661
 	 */
663
-	static public function number_format($number,$num_decimal_places=2,$readonly=true)
662
+	static public function number_format($number, $num_decimal_places = 2, $readonly = true)
664 663
 	{
665
-		static $dec_separator=null,$thousands_separator=null;
664
+		static $dec_separator = null, $thousands_separator = null;
666 665
 		if (is_null($dec_separator))
667 666
 		{
668 667
 			$dec_separator = $GLOBALS['egw_info']['user']['preferences']['common']['number_format'][0];
@@ -671,7 +670,7 @@  discard block
 block discarded – undo
671 670
 		}
672 671
 		if ((string)$number === '') return '';
673 672
 
674
-		return number_format(str_replace(' ','',$number),$num_decimal_places,$dec_separator,$readonly ? $thousands_separator : '');
673
+		return number_format(str_replace(' ', '', $number), $num_decimal_places, $dec_separator, $readonly ? $thousands_separator : '');
675 674
 	}
676 675
 
677 676
 	/**
@@ -684,13 +683,13 @@  discard block
 block discarded – undo
684 683
 	{
685 684
 		if (!is_numeric($size))
686 685
 		{
687
-			switch(strtolower(substr($size,-1)))
686
+			switch (strtolower(substr($size, -1)))
688 687
 			{
689 688
 				case 'm':
690
-					$size = 1024*1024*(int)$size;
689
+					$size = 1024 * 1024 * (int)$size;
691 690
 					break;
692 691
 				case 'k':
693
-					$size = 1024*(int)$size;
692
+					$size = 1024 * (int)$size;
694 693
 					break;
695 694
 			}
696 695
 		}
Please login to merge, or discard this patch.