Completed
Push — master ( c85f1f...df263c )
by Ralf
74:39 queued 51:38
created
api/src/Session.php 2 patches
Spacing   +181 added lines, -184 removed lines patch added patch discarded remove patch
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
 	const CD_SECOND_FACTOR_REQUIRED = 96;
178 178
 	const CD_FORCE_PASSWORD_CHANGE = 97;
179 179
 	const CD_ACCOUNT_EXPIRED = 98;
180
-	const CD_BLOCKED = 99;	// to many failed attempts to loing
180
+	const CD_BLOCKED = 99; // to many failed attempts to loing
181 181
 
182 182
 	/**
183 183
 	 * Verbose reason why session creation failed
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
 	 *
199 199
 	 * @param array $domain_names =null domain-names used in this install
200 200
 	 */
201
-	function __construct(array $domain_names=null)
201
+	function __construct(array $domain_names = null)
202 202
 	{
203 203
 		$this->required_files = $_SESSION[self::EGW_REQUIRED_FILES];
204 204
 
@@ -214,27 +214,27 @@  discard block
 block discarded – undo
214 214
 			$save_rep = false;
215 215
 			if (!isset($GLOBALS['egw_info']['server']['max_access_log_age']))
216 216
 			{
217
-				$GLOBALS['egw_info']['server']['max_access_log_age'] = 90;	// default 90 days
217
+				$GLOBALS['egw_info']['server']['max_access_log_age'] = 90; // default 90 days
218 218
 				$save_rep = true;
219 219
 			}
220 220
 			if (!isset($GLOBALS['egw_info']['server']['block_time']))
221 221
 			{
222
-				$GLOBALS['egw_info']['server']['block_time'] = 1;	// default 1min, its enough to slow down brute force attacks
222
+				$GLOBALS['egw_info']['server']['block_time'] = 1; // default 1min, its enough to slow down brute force attacks
223 223
 				$save_rep = true;
224 224
 			}
225 225
 			if (!isset($GLOBALS['egw_info']['server']['num_unsuccessful_id']))
226 226
 			{
227
-				$GLOBALS['egw_info']['server']['num_unsuccessful_id']  = 3;	// default 3 trys per id
227
+				$GLOBALS['egw_info']['server']['num_unsuccessful_id'] = 3; // default 3 trys per id
228 228
 				$save_rep = true;
229 229
 			}
230 230
 			if (!isset($GLOBALS['egw_info']['server']['num_unsuccessful_ip']))
231 231
 			{
232
-				$GLOBALS['egw_info']['server']['num_unsuccessful_ip']  = $GLOBALS['egw_info']['server']['num_unsuccessful_id'] * 5;	// default is 5 times as high as the id default; since accessing via proxy is quite common
232
+				$GLOBALS['egw_info']['server']['num_unsuccessful_ip'] = $GLOBALS['egw_info']['server']['num_unsuccessful_id'] * 5; // default is 5 times as high as the id default; since accessing via proxy is quite common
233 233
 				$save_rep = true;
234 234
 			}
235 235
 			if (!isset($GLOBALS['egw_info']['server']['install_id']))
236 236
 			{
237
-				$GLOBALS['egw_info']['server']['install_id']  = md5(Auth::randomstring(15));
237
+				$GLOBALS['egw_info']['server']['install_id'] = md5(Auth::randomstring(15));
238 238
 			}
239 239
 			if (!isset($GLOBALS['egw_info']['server']['max_history']))
240 240
 			{
@@ -246,18 +246,18 @@  discard block
 block discarded – undo
246 246
 			{
247 247
 				$config = new Config('phpgwapi');
248 248
 				$config->read_repository();
249
-				$config->value('max_access_log_age',$GLOBALS['egw_info']['server']['max_access_log_age']);
250
-				$config->value('block_time',$GLOBALS['egw_info']['server']['block_time']);
251
-				$config->value('num_unsuccessful_id',$GLOBALS['egw_info']['server']['num_unsuccessful_id']);
252
-				$config->value('num_unsuccessful_ip',$GLOBALS['egw_info']['server']['num_unsuccessful_ip']);
253
-				$config->value('install_id',$GLOBALS['egw_info']['server']['install_id']);
254
-				$config->value('max_history',$GLOBALS['egw_info']['server']['max_history']);
249
+				$config->value('max_access_log_age', $GLOBALS['egw_info']['server']['max_access_log_age']);
250
+				$config->value('block_time', $GLOBALS['egw_info']['server']['block_time']);
251
+				$config->value('num_unsuccessful_id', $GLOBALS['egw_info']['server']['num_unsuccessful_id']);
252
+				$config->value('num_unsuccessful_ip', $GLOBALS['egw_info']['server']['num_unsuccessful_ip']);
253
+				$config->value('install_id', $GLOBALS['egw_info']['server']['install_id']);
254
+				$config->value('max_history', $GLOBALS['egw_info']['server']['max_history']);
255 255
 				try
256 256
 				{
257 257
 					$config->save_repository();
258 258
 				}
259 259
 				catch (Db\Exception $e) {
260
-					_egw_log_exception($e);	// ignore exception, as it blocks session creation, if database is not writable
260
+					_egw_log_exception($e); // ignore exception, as it blocks session creation, if database is not writable
261 261
 				}
262 262
 			}
263 263
 		}
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
 		// set session_timeout from global php.ini and default to 14400=4h, if not set
267 267
 		if (!($GLOBALS['egw_info']['server']['sessions_timeout'] = ini_get('session.gc_maxlifetime')))
268 268
       	{
269
-      		ini_set('session.gc_maxlifetime', $GLOBALS['egw_info']['server']['sessions_timeout']=14400);
269
+      		ini_set('session.gc_maxlifetime', $GLOBALS['egw_info']['server']['sessions_timeout'] = 14400);
270 270
       	}
271 271
 	}
272 272
 
@@ -335,15 +335,15 @@  discard block
 block discarded – undo
335 335
 
336 336
 		if (!isset($_SESSION[self::EGW_SESSION_ENCRYPTED]) && self::init_crypt($kp3))
337 337
 		{
338
-			foreach(self::$egw_session_vars as $name)
338
+			foreach (self::$egw_session_vars as $name)
339 339
 			{
340 340
 				if (isset($_SESSION[$name]))
341 341
 				{
342
-					$_SESSION[$name] = mcrypt_generic(self::$mcrypt,serialize($_SESSION[$name]));
342
+					$_SESSION[$name] = mcrypt_generic(self::$mcrypt, serialize($_SESSION[$name]));
343 343
 					//error_log(__METHOD__."() 'encrypting' session var: $name, len=".strlen($_SESSION[$name]));
344 344
 				}
345 345
 			}
346
-			$_SESSION[self::EGW_SESSION_ENCRYPTED] = true;	// flag session as encrypted
346
+			$_SESSION[self::EGW_SESSION_ENCRYPTED] = true; // flag session as encrypted
347 347
 
348 348
 			mcrypt_generic_deinit(self::$mcrypt);
349 349
 			self::$mcrypt = null;
@@ -358,24 +358,24 @@  discard block
 block discarded – undo
358 358
 	 * @param boolean $recursion =true if true call itself for every item > $limit
359 359
 	 * @param int $limit =1000 log only differences > $limit
360 360
 	 */
361
-	static function log_session_usage(&$arr,$label,$recursion=true,$limit=1000)
361
+	static function log_session_usage(&$arr, $label, $recursion = true, $limit = 1000)
362 362
 	{
363 363
 		if (!is_array($arr)) return;
364 364
 
365 365
 		$sizes = array();
366
-		foreach($arr as $key => &$data)
366
+		foreach ($arr as $key => &$data)
367 367
 		{
368 368
 			$sizes[$key] = strlen(serialize($data));
369 369
 		}
370
-		arsort($sizes,SORT_NUMERIC);
371
-		foreach($sizes as $key => $size)
370
+		arsort($sizes, SORT_NUMERIC);
371
+		foreach ($sizes as $key => $size)
372 372
 		{
373 373
 			$diff = $size - (int)$_SESSION[$label.'-sizes'][$key];
374 374
 			$_SESSION[$label.'-sizes'][$key] = $size;
375 375
 			if ($diff > $limit)
376 376
 			{
377 377
 				error_log("strlen({$label}[$key])=".Vfs::hsize($size).", diff=".Vfs::hsize($diff));
378
-				if ($recursion) self::log_session_usage($arr[$key],$label.'['.$key.']',$recursion,$limit);
378
+				if ($recursion) self::log_session_usage($arr[$key], $label.'['.$key.']', $recursion, $limit);
379 379
 			}
380 380
 		}
381 381
 	}
@@ -390,15 +390,15 @@  discard block
 block discarded – undo
390 390
 	{
391 391
 		if ($_SESSION[self::EGW_SESSION_ENCRYPTED] && self::init_crypt(self::get_request('kp3')))
392 392
 		{
393
-			foreach(self::$egw_session_vars as $name)
393
+			foreach (self::$egw_session_vars as $name)
394 394
 			{
395 395
 				if (isset($_SESSION[$name]))
396 396
 				{
397
-					$_SESSION[$name] = unserialize(trim(mdecrypt_generic(self::$mcrypt,$_SESSION[$name])));
397
+					$_SESSION[$name] = unserialize(trim(mdecrypt_generic(self::$mcrypt, $_SESSION[$name])));
398 398
 					//error_log(__METHOD__."() 'decrypting' session var $name: gettype($name) = ".gettype($_SESSION[$name]));
399 399
 				}
400 400
 			}
401
-			unset($_SESSION[self::EGW_SESSION_ENCRYPTED]);	// delete encryption flag
401
+			unset($_SESSION[self::EGW_SESSION_ENCRYPTED]); // delete encryption flag
402 402
 		}
403 403
 	}
404 404
 
@@ -413,13 +413,13 @@  discard block
 block discarded – undo
413 413
 	 */
414 414
 	static private function init_crypt($kp3)
415 415
 	{
416
-		if(!$GLOBALS['egw_info']['server']['mcrypt_enabled'])
416
+		if (!$GLOBALS['egw_info']['server']['mcrypt_enabled'])
417 417
 		{
418
-			return false;	// session encryption is switched off
418
+			return false; // session encryption is switched off
419 419
 		}
420 420
 		if ($GLOBALS['egw_info']['currentapp'] == 'syncml' || !$kp3)
421 421
 		{
422
-			$kp3 = 'staticsyncmlkp3';	// syncml has no kp3!
422
+			$kp3 = 'staticsyncmlkp3'; // syncml has no kp3!
423 423
 		}
424 424
 		if (is_null(self::$mcrypt))
425 425
 		{
@@ -435,9 +435,9 @@  discard block
 block discarded – undo
435 435
 			}
436 436
 			$iv_size = mcrypt_enc_get_iv_size(self::$mcrypt);
437 437
 			$iv = !isset($GLOBALS['egw_info']['server']['mcrypt_iv']) || strlen($GLOBALS['egw_info']['server']['mcrypt_iv']) < $iv_size ?
438
-				mcrypt_create_iv ($iv_size, MCRYPT_RAND) : substr($GLOBALS['egw_info']['server']['mcrypt_iv'],0,$iv_size);
438
+				mcrypt_create_iv ($iv_size, MCRYPT_RAND) : substr($GLOBALS['egw_info']['server']['mcrypt_iv'], 0, $iv_size);
439 439
 
440
-			if (mcrypt_generic_init(self::$mcrypt,$kp3, $iv) < 0)
440
+			if (mcrypt_generic_init(self::$mcrypt, $kp3, $iv) < 0)
441 441
 			{
442 442
 				error_log(__METHOD__."() could not initialise mcrypt, sessions get NOT encrypted!");
443 443
 				return self::$mcrypt = false;
@@ -459,7 +459,7 @@  discard block
 block discarded – undo
459 459
 	 * @param string $remember_me =null "True" for checkbox checked, or periode for user-choice select-box eg. "P1W" or "" for NOT remember
460 460
 	 * @return string|boolean session id or false if session was not created, $this->(cd_)reason contains cause
461 461
 	 */
462
-	function create($login,$passwd = '',$passwd_type = '',$no_session=false,$auth_check=true,$fail_on_forced_password_change=false,$check_2fa=false,$remember_me=null)
462
+	function create($login, $passwd = '', $passwd_type = '', $no_session = false, $auth_check = true, $fail_on_forced_password_change = false, $check_2fa = false, $remember_me = null)
463 463
 	{
464 464
 		try {
465 465
 			if (is_array($login))
@@ -477,9 +477,9 @@  discard block
 block discarded – undo
477 477
 			}
478 478
 			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) starting ...");
479 479
 
480
-			self::split_login_domain($login,$this->account_lid,$this->account_domain);
480
+			self::split_login_domain($login, $this->account_lid, $this->account_domain);
481 481
 			// add domain to the login, if not already there
482
-			if (substr($this->login,-strlen($this->account_domain)-1) != '@'.$this->account_domain)
482
+			if (substr($this->login, -strlen($this->account_domain) - 1) != '@'.$this->account_domain)
483 483
 			{
484 484
 				$this->login .= '@'.$this->account_domain;
485 485
 			}
@@ -496,7 +496,7 @@  discard block
 block discarded – undo
496 496
 			{
497 497
 				$this->account_domain = $GLOBALS['egw_info']['user']['domain'];
498 498
 			}
499
-			elseif($this->account_domain != $GLOBALS['egw_info']['user']['domain'])
499
+			elseif ($this->account_domain != $GLOBALS['egw_info']['user']['domain'])
500 500
 			{
501 501
 				throw new Exception("Wrong domain! '$this->account_domain' != '{$GLOBALS['egw_info']['user']['domain']}'");
502 502
 			}
@@ -504,7 +504,7 @@  discard block
 block discarded – undo
504 504
 
505 505
 			$user_ip = self::getuser_ip();
506 506
 
507
-			$this->account_id = $GLOBALS['egw']->accounts->name2id($this->account_lid,'account_lid','u');
507
+			$this->account_id = $GLOBALS['egw']->accounts->name2id($this->account_lid, 'account_lid', 'u');
508 508
 
509 509
 			// do we need to check 'remember me' token (to bypass authentication)
510 510
 			if ($auth_check && !empty($_COOKIE[self::REMEMBER_ME_COOKIE]))
@@ -512,7 +512,7 @@  discard block
 block discarded – undo
512 512
 				$auth_check = !$this->skipPasswordAuth($_COOKIE[self::REMEMBER_ME_COOKIE], $this->account_id);
513 513
 			}
514 514
 
515
-			if (($blocked = $this->login_blocked($login,$user_ip)) ||	// too many unsuccessful attempts
515
+			if (($blocked = $this->login_blocked($login, $user_ip)) || // too many unsuccessful attempts
516 516
 				$GLOBALS['egw_info']['server']['global_denied_users'][$this->account_lid] ||
517 517
 				$auth_check && !$GLOBALS['egw']->auth->authenticate($this->account_lid, $this->passwd, $this->passwd_type) ||
518 518
 				$this->account_id && $GLOBALS['egw']->accounts->get_type($this->account_id) == 'g')
@@ -521,9 +521,9 @@  discard block
 block discarded – undo
521 521
 				$this->cd_reason = $blocked ? self::CD_BLOCKED : self::CD_BAD_LOGIN_OR_PASSWORD;
522 522
 
523 523
 				// we dont log anon users as it would block the website
524
-				if (!$GLOBALS['egw']->acl->get_specific_rights_for_account($this->account_id,'anonymous','phpgwapi'))
524
+				if (!$GLOBALS['egw']->acl->get_specific_rights_for_account($this->account_id, 'anonymous', 'phpgwapi'))
525 525
 				{
526
-					$this->log_access($this->reason,$login,$user_ip,0);	// log unsuccessfull login
526
+					$this->log_access($this->reason, $login, $user_ip, 0); // log unsuccessfull login
527 527
 				}
528 528
 				if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)");
529 529
 				return false;
@@ -541,7 +541,7 @@  discard block
 block discarded – undo
541 541
 			if ($this->account_lid != ($lid = $GLOBALS['egw']->accounts->id2name($this->account_id)))
542 542
 			{
543 543
 				$this->account_lid = $lid;
544
-				$this->login = $lid.substr($this->login,strlen($lid));
544
+				$this->login = $lid.substr($this->login, strlen($lid));
545 545
 			}
546 546
 
547 547
 			$GLOBALS['egw_info']['user']['account_id'] = $this->account_id;
@@ -566,7 +566,7 @@  discard block
 block discarded – undo
566 566
 				}
567 567
 				$this->sessionid = session_id();
568 568
 			}
569
-			$this->kp3       = Auth::randomstring(24);
569
+			$this->kp3 = Auth::randomstring(24);
570 570
 
571 571
 			$GLOBALS['egw_info']['user'] = $this->read_repositories();
572 572
 			if ($GLOBALS['egw']->accounts->is_expired($GLOBALS['egw_info']['user']))
@@ -586,10 +586,10 @@  discard block
 block discarded – undo
586 586
 				try {
587 587
 					$this->checkMultifactorAuth($check_2fa, $_COOKIE[self::REMEMBER_ME_COOKIE]);
588 588
 				}
589
-				catch(\Exception $e) {
589
+				catch (\Exception $e) {
590 590
 					$this->cd_reason = $e->getCode();
591 591
 					$this->reason = $e->getMessage();
592
-					$this->log_access($this->reason, $login, $user_ip, 0);	// log unsuccessfull login
592
+					$this->log_access($this->reason, $login, $user_ip, 0); // log unsuccessfull login
593 593
 					if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check,$fail_on_forced_password_change,'$check_2fa') UNSUCCESSFULL ($this->reason)");
594 594
 					return false;
595 595
 				}
@@ -601,7 +601,7 @@  discard block
 block discarded – undo
601 601
 				return false;
602 602
 			}
603 603
 
604
-			if ($GLOBALS['egw']->acl->check('anonymous',1,'phpgwapi'))
604
+			if ($GLOBALS['egw']->acl->check('anonymous', 1, 'phpgwapi'))
605 605
 			{
606 606
 				$this->session_flags = 'A';
607 607
 			}
@@ -619,41 +619,41 @@  discard block
 block discarded – undo
619 619
 				'passwd'         => $this->passwd,
620 620
 				'account_domain' => $this->account_domain,
621 621
 				'user_ip'        => $user_ip,
622
-			),'',true)))	// true = run hooks from all apps, not just the ones the current user has perms to run
622
+			), '', true)))	// true = run hooks from all apps, not just the ones the current user has perms to run
623 623
 			{
624
-				foreach($hook_result as $reason)
624
+				foreach ($hook_result as $reason)
625 625
 				{
626 626
 					if ($reason)	// called hook requests to deny the session
627 627
 					{
628 628
 						$this->reason = $this->cd_reason = $reason;
629
-						$this->log_access($this->reason,$login,$user_ip,0);		// log unsuccessfull login
629
+						$this->log_access($this->reason, $login, $user_ip, 0); // log unsuccessfull login
630 630
 						if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)");
631 631
 						return false;
632 632
 					}
633 633
 				}
634 634
 			}
635 635
 			$GLOBALS['egw']->db->transaction_begin();
636
-			$this->register_session($this->login,$user_ip,$now,$this->session_flags);
636
+			$this->register_session($this->login, $user_ip, $now, $this->session_flags);
637 637
 			if ($this->session_flags != 'A')		// dont log anonymous sessions
638 638
 			{
639
-				$this->sessionid_access_log = $this->log_access($this->sessionid,$login,$user_ip,$this->account_id);
639
+				$this->sessionid_access_log = $this->log_access($this->sessionid, $login, $user_ip, $this->account_id);
640 640
 				// We do NOT log anonymous sessions to not block website and also to cope with
641 641
 				// high rate anon endpoints might be called creating a bottleneck in the egw_accounts table.
642 642
 				Cache::setSession('phpgwapi', 'account_previous_login', $GLOBALS['egw']->auth->previous_login);
643
-				$GLOBALS['egw']->accounts->update_lastlogin($this->account_id,$user_ip);
643
+				$GLOBALS['egw']->accounts->update_lastlogin($this->account_id, $user_ip);
644 644
 			}
645 645
 			$GLOBALS['egw']->db->transaction_commit();
646 646
 
647 647
 			if ($GLOBALS['egw_info']['server']['usecookies'] && !$no_session)
648 648
 			{
649
-				self::egw_setcookie(self::EGW_SESSION_NAME,$this->sessionid);
650
-				self::egw_setcookie('kp3',$this->kp3);
651
-				self::egw_setcookie('domain',$this->account_domain);
649
+				self::egw_setcookie(self::EGW_SESSION_NAME, $this->sessionid);
650
+				self::egw_setcookie('kp3', $this->kp3);
651
+				self::egw_setcookie('domain', $this->account_domain);
652 652
 			}
653 653
 			if ($GLOBALS['egw_info']['server']['usecookies'] && !$no_session || isset($_COOKIE['last_loginid']))
654 654
 			{
655
-				self::egw_setcookie('last_loginid', $this->account_lid ,$now+1209600); /* For 2 weeks */
656
-				self::egw_setcookie('last_domain',$this->account_domain,$now+1209600);
655
+				self::egw_setcookie('last_loginid', $this->account_lid, $now + 1209600); /* For 2 weeks */
656
+				self::egw_setcookie('last_domain', $this->account_domain, $now + 1209600);
657 657
 			}
658 658
 
659 659
 			// set new remember me token/cookie, if requested and necessary
@@ -677,13 +677,13 @@  discard block
 block discarded – undo
677 677
 				'user_ip'        => $user_ip,
678 678
 				'session_type'   => Session\Type::get($_SERVER['REQUEST_URI'],
679 679
 					$GLOBALS['egw_info']['flags']['current_app'],
680
-					true),	// true return WebGUI instead of login, as we are logged in now
681
-			),'',true);
680
+					true), // true return WebGUI instead of login, as we are logged in now
681
+			), '', true);
682 682
 
683 683
 			return $this->sessionid;
684 684
 		}
685 685
 		// catch all exceptions, as their (allways logged) trace (eg. on a database error) would contain the user password
686
-		catch(Exception $e) {
686
+		catch (Exception $e) {
687 687
 			$this->reason = $this->cd_reason = is_a($e, Db\Exception::class) ?
688 688
 				// do not output specific database error, eg. invalid SQL statement
689 689
 				lang('Database Error!') : $e->getMessage();
@@ -707,7 +707,7 @@  discard block
 block discarded – undo
707 707
 	 * @param int& $account_id =null account_id of token-owner to limit check on that user, on return account_id of token owner
708 708
 	 * @return boolean false: if further auth check is required, true: if token is sufficient for authentication
709 709
 	 */
710
-	public function skipPasswordAuth($token, &$account_id=null)
710
+	public function skipPasswordAuth($token, &$account_id = null)
711 711
 	{
712 712
 		// if token is empty or disabled --> password authentication required
713 713
 		if (empty($token) || $GLOBALS['egw_info']['server']['remember_me_token'] !== 'always' ||
@@ -749,7 +749,7 @@  discard block
 block discarded – undo
749 749
 
750 750
 		if ($GLOBALS['egw_info']['server']['2fa_required'] === 'disabled')
751 751
 		{
752
-			return;	// nothing to check
752
+			return; // nothing to check
753 753
 		}
754 754
 
755 755
 		// check if token exists and is (still) valid
@@ -834,7 +834,7 @@  discard block
 block discarded – undo
834 834
 				$tokenRepo = new OpenID\Repositories\AccessTokenRepository();
835 835
 				if ($tokenRepo->findToken($client, $this->account_id, 'PT1S', $token))
836 836
 				{
837
-					return null;	// token still valid, no need to set it again
837
+					return null; // token still valid, no need to set it again
838 838
 				}
839 839
 			}
840 840
 			$lifetime = $this->rememberMeTokenLifetime(is_string($remember_me) ? $remember_me : null);
@@ -885,17 +885,17 @@  discard block
 block discarded – undo
885 885
 
886 886
 		$clients = new OpenID\Repositories\ClientRepository();
887 887
 		try {
888
-			$client = $clients->getClientEntity(self::OPENID_REMEMBER_ME_CLIENT_ID, null, null, false);	// false = do NOT check client-secret
888
+			$client = $clients->getClientEntity(self::OPENID_REMEMBER_ME_CLIENT_ID, null, null, false); // false = do NOT check client-secret
889 889
 		}
890 890
 		catch (OAuthServerException $e)
891 891
 		{
892 892
 			unset($e);
893 893
 			$client = new OpenID\Entities\ClientEntity();
894 894
 			$client->setIdentifier(self::OPENID_REMEMBER_ME_CLIENT_ID);
895
-			$client->setSecret(Auth::randomstring(24));	// must not be unset
895
+			$client->setSecret(Auth::randomstring(24)); // must not be unset
896 896
 			$client->setName(lang('Remember me token'));
897 897
 			$client->setAccessTokenTTL($this->rememberMeTokenLifetime());
898
-			$client->setRefreshTokenTTL('P0S');	// no refresh token
898
+			$client->setRefreshTokenTTL('P0S'); // no refresh token
899 899
 			$client->setRedirectUri($GLOBALS['egw_info']['server']['webserver_url'].'/');
900 900
 			$clients->persistNewClient($client);
901 901
 		}
@@ -909,7 +909,7 @@  discard block
 block discarded – undo
909 909
 	 * @param boolean $ts =false false: return periode string, true: return integer timestamp
910 910
 	 * @return string periode spec eg. 'P1M'
911 911
 	 */
912
-	protected function rememberMeTokenLifetime($user=null, $ts=false)
912
+	protected function rememberMeTokenLifetime($user = null, $ts = false)
913 913
 	{
914 914
 		switch ((string)$GLOBALS['egw_info']['server']['remember_me_lifetime'])
915 915
 		{
@@ -944,13 +944,12 @@  discard block
 block discarded – undo
944 944
 	 * @param int $now
945 945
 	 * @param string $session_flags
946 946
 	 */
947
-	private function register_session($login,$user_ip,$now,$session_flags)
947
+	private function register_session($login, $user_ip, $now, $session_flags)
948 948
 	{
949 949
 		// restore session vars set before session was started
950 950
 		if (is_array($this->required_files))
951 951
 		{
952
-			$_SESSION[self::EGW_REQUIRED_FILES] = !is_array($_SESSION[self::EGW_REQUIRED_FILES]) ? $this->required_files :
953
-				array_unique(array_merge($_SESSION[self::EGW_REQUIRED_FILES],$this->required_files));
952
+			$_SESSION[self::EGW_REQUIRED_FILES] = !is_array($_SESSION[self::EGW_REQUIRED_FILES]) ? $this->required_files : array_unique(array_merge($_SESSION[self::EGW_REQUIRED_FILES], $this->required_files));
954 953
 			unset($this->required_files);
955 954
 		}
956 955
 		$_SESSION[self::EGW_SESSION_VAR] = array(
@@ -989,7 +988,7 @@  discard block
 block discarded – undo
989 988
 	 * @param int $account_id =0 numerical account_id
990 989
 	 * @return int $sessionid primary key of egw_access_log for login, null otherwise
991 990
 	 */
992
-	private function log_access($sessionid,$login='',$user_ip='',$account_id=0)
991
+	private function log_access($sessionid, $login = '', $user_ip = '', $account_id = 0)
993 992
 	{
994 993
 		// do not log anything for anonymous sessions
995 994
 		if ($this->session_flags === 'A')
@@ -1007,7 +1006,7 @@  discard block
 block discarded – undo
1007 1006
 
1008 1007
 		if ($login)
1009 1008
 		{
1010
-			$GLOBALS['egw']->db->insert(self::ACCESS_LOG_TABLE,array(
1009
+			$GLOBALS['egw']->db->insert(self::ACCESS_LOG_TABLE, array(
1011 1010
 				'session_php' => $sessionid,
1012 1011
 				'loginid'   => $login,
1013 1012
 				'ip'        => $user_ip,
@@ -1015,22 +1014,22 @@  discard block
 block discarded – undo
1015 1014
 				'account_id'=> $account_id,
1016 1015
 				'user_agent'=> $_SERVER['HTTP_USER_AGENT'],
1017 1016
 				'session_dla'    => $now,
1018
-				'session_action' => $this->update_dla(false),	// dont update egw_access_log
1019
-			),false,__LINE__,__FILE__);
1017
+				'session_action' => $this->update_dla(false), // dont update egw_access_log
1018
+			), false, __LINE__, __FILE__);
1020 1019
 
1021 1020
 			$_SESSION[self::EGW_SESSION_VAR]['session_logged_dla'] = $now;
1022 1021
 
1023
-			$ret = $GLOBALS['egw']->db->get_last_insert_id(self::ACCESS_LOG_TABLE,'sessionid');
1022
+			$ret = $GLOBALS['egw']->db->get_last_insert_id(self::ACCESS_LOG_TABLE, 'sessionid');
1024 1023
 
1025 1024
 			// if we can not store failed login attempts in database, store it in cache
1026 1025
 			if (!$ret && !$account_id)
1027 1026
 			{
1028 1027
 				Cache::setInstance(__CLASS__, self::FALSE_IP_CACHE_PREFIX.$user_ip,
1029
-					1+Cache::getInstance(__CLASS__, self::FALSE_IP_CACHE_PREFIX.$user_ip),
1028
+					1 + Cache::getInstance(__CLASS__, self::FALSE_IP_CACHE_PREFIX.$user_ip),
1030 1029
 					$GLOBALS['egw_info']['server']['block_time'] * 60);
1031 1030
 
1032 1031
 				Cache::setInstance(__CLASS__, self::FALSE_ID_CACHE_PREFIX.$login,
1033
-					1+Cache::getInstance(__CLASS__, self::FALSE_ID_CACHE_PREFIX.$login),
1032
+					1 + Cache::getInstance(__CLASS__, self::FALSE_ID_CACHE_PREFIX.$login),
1034 1033
 					$GLOBALS['egw_info']['server']['block_time'] * 60);
1035 1034
 			}
1036 1035
 		}
@@ -1040,20 +1039,20 @@  discard block
 block discarded – undo
1040 1039
 			{
1041 1040
 				$sessionid = $this->sessionid_access_log;
1042 1041
 			}
1043
-			$GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE,array(
1042
+			$GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE, array(
1044 1043
 				'lo' => $now
1045
-			),is_numeric($sessionid) ? array(
1044
+			), is_numeric($sessionid) ? array(
1046 1045
 				'sessionid' => $sessionid,
1047 1046
 			) : array(
1048 1047
 				'session_php' => $sessionid,
1049
-			),__LINE__,__FILE__);
1048
+			), __LINE__, __FILE__);
1050 1049
 
1051 1050
 			// run maintenance only on logout, to not delay login
1052 1051
 			if ($GLOBALS['egw_info']['server']['max_access_log_age'])
1053 1052
 			{
1054 1053
 				$max_age = $now - $GLOBALS['egw_info']['server']['max_access_log_age'] * 24 * 60 * 60;
1055 1054
 
1056
-				$GLOBALS['egw']->db->delete(self::ACCESS_LOG_TABLE,"li < $max_age",__LINE__,__FILE__);
1055
+				$GLOBALS['egw']->db->delete(self::ACCESS_LOG_TABLE, "li < $max_age", __LINE__, __FILE__);
1057 1056
 			}
1058 1057
 		}
1059 1058
 		//error_log(__METHOD__."('$sessionid', '$login', '$user_ip', $account_id) returning ".array2string($ret));
@@ -1067,12 +1066,12 @@  discard block
 block discarded – undo
1067 1066
 	 * @param string $ip ip of the user
1068 1067
 	 * @returns bool login blocked?
1069 1068
 	 */
1070
-	private function login_blocked($login,$ip)
1069
+	private function login_blocked($login, $ip)
1071 1070
 	{
1072 1071
 		$block_time = time() - $GLOBALS['egw_info']['server']['block_time'] * 60;
1073 1072
 
1074 1073
 		$false_id = $false_ip = 0;
1075
-		foreach($GLOBALS['egw']->db->union(array(
1074
+		foreach ($GLOBALS['egw']->db->union(array(
1076 1075
 			array(
1077 1076
 				'table' => self::ACCESS_LOG_TABLE,
1078 1077
 				'cols'  => "'false_ip' AS name,COUNT(*) AS num",
@@ -1115,7 +1114,7 @@  discard block
 block discarded – undo
1115 1114
 		if (!empty($GLOBALS['egw_info']['server']['unsuccessful_ip_whitelist']) &&
1116 1115
 			preg_match_all('/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(:\d+)?/',
1117 1116
 				$GLOBALS['egw_info']['server']['unsuccessful_ip_whitelist'], $matches) &&
1118
-			($key=array_search($ip, $matches[1])) !== false)
1117
+			($key = array_search($ip, $matches[1])) !== false)
1119 1118
 		{
1120 1119
 			$blocked = !empty($matches[3][$key]) && $false_ip > $matches[3][$key];
1121 1120
 		}
@@ -1130,28 +1129,28 @@  discard block
 block discarded – undo
1130 1129
 		//error_log(__METHOD__."('$login', '$ip') false_ip=$false_ip, false_id=$false_id --> blocked=".array2string($blocked));
1131 1130
 
1132 1131
 		if ($blocked && $GLOBALS['egw_info']['server']['admin_mails'] &&
1133
-			$GLOBALS['egw_info']['server']['login_blocked_mail_time'] < time()-5*60)	// max. one mail every 5mins
1132
+			$GLOBALS['egw_info']['server']['login_blocked_mail_time'] < time() - 5 * 60)	// max. one mail every 5mins
1134 1133
 		{
1135 1134
 			try {
1136 1135
 				$mailer = new Mailer();
1137 1136
 				// notify admin(s) via email
1138 1137
 				$mailer->setFrom('eGroupWare@'.$GLOBALS['egw_info']['server']['mail_suffix']);
1139
-				$mailer->addHeader('Subject', lang("eGroupWare: login blocked for user '%1', IP %2",$login,$ip));
1140
-				$mailer->setBody(lang("Too many unsucessful attempts to login: %1 for the user '%2', %3 for the IP %4",$false_id,$login,$false_ip,$ip));
1141
-				foreach(preg_split('/,\s*/',$GLOBALS['egw_info']['server']['admin_mails']) as $mail)
1138
+				$mailer->addHeader('Subject', lang("eGroupWare: login blocked for user '%1', IP %2", $login, $ip));
1139
+				$mailer->setBody(lang("Too many unsucessful attempts to login: %1 for the user '%2', %3 for the IP %4", $false_id, $login, $false_ip, $ip));
1140
+				foreach (preg_split('/,\s*/', $GLOBALS['egw_info']['server']['admin_mails']) as $mail)
1142 1141
 				{
1143 1142
 					$mailer->addAddress($mail);
1144 1143
 				}
1145 1144
 				$mailer->send();
1146 1145
 			}
1147
-			catch(\Exception $e) {
1146
+			catch (\Exception $e) {
1148 1147
 				// ignore exception, but log it, to block the account and give a correct error-message to user
1149 1148
 				error_log(__METHOD__."('$login', '$ip') ".$e->getMessage());
1150 1149
 			}
1151 1150
 			// save time of mail, to not send to many mails
1152 1151
 			$config = new Config('phpgwapi');
1153 1152
 			$config->read_repository();
1154
-			$config->value('login_blocked_mail_time',time());
1153
+			$config->value('login_blocked_mail_time', time());
1155 1154
 			$config->save_repository();
1156 1155
 		}
1157 1156
 		return $blocked;
@@ -1172,7 +1171,7 @@  discard block
 block discarded – undo
1172 1171
 	 * @param boolean $only_basic_auth =false return only a basic auth pseudo sessionid, default no
1173 1172
 	 * @return string|null (pseudo-)session-id use or NULL if no Cookie or Basic-Auth credentials
1174 1173
 	 */
1175
-	static function get_sessionid($only_basic_auth=false)
1174
+	static function get_sessionid($only_basic_auth = false)
1176 1175
 	{
1177 1176
 		// for WebDAV and GroupDAV we use a pseudo sessionid created from md5(user:passwd)
1178 1177
 		// --> allows this stateless protocolls which use basic auth to use sessions!
@@ -1199,11 +1198,11 @@  discard block
 block discarded – undo
1199 1198
 				EGW_SERVER_ROOT.':'.self::getuser_ip().':'.filemtime(EGW_SERVER_ROOT.'/api/setup/setup.inc.php').
1200 1199
 				':'.$_SERVER['HTTP_USER_AGENT']);
1201 1200
 		}
1202
-		elseif(!$only_basic_auth && isset($_REQUEST[self::EGW_SESSION_NAME]))
1201
+		elseif (!$only_basic_auth && isset($_REQUEST[self::EGW_SESSION_NAME]))
1203 1202
 		{
1204 1203
 			$sessionid = $_REQUEST[self::EGW_SESSION_NAME];
1205 1204
 		}
1206
-		elseif(!$only_basic_auth && isset($_COOKIE[self::EGW_SESSION_NAME]))
1205
+		elseif (!$only_basic_auth && isset($_COOKIE[self::EGW_SESSION_NAME]))
1207 1206
 		{
1208 1207
 			$sessionid = $_COOKIE[self::EGW_SESSION_NAME];
1209 1208
 		}
@@ -1211,7 +1210,7 @@  discard block
 block discarded – undo
1211 1210
 		{
1212 1211
 			$sessionid = null;
1213 1212
 		}
1214
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() _SERVER[REQUEST_URI]='$_SERVER[REQUEST_URI]' returning ".print_r($sessionid,true));
1213
+		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() _SERVER[REQUEST_URI]='$_SERVER[REQUEST_URI]' returning ".print_r($sessionid, true));
1215 1214
 		return $sessionid;
1216 1215
 	}
1217 1216
 
@@ -1227,9 +1226,7 @@  discard block
 block discarded – undo
1227 1226
 	 */
1228 1227
 	static function get_request($name)
1229 1228
 	{
1230
-		return isset($_REQUEST[$name]) ? $_REQUEST[$name] :
1231
-			(isset($_COOKIE[$name]) ? $_COOKIE[$name] :
1232
-			(isset($_COOKIE[$name=ucfirst($name)]) ? $_COOKIE[$name] : null));
1229
+		return isset($_REQUEST[$name]) ? $_REQUEST[$name] : (isset($_COOKIE[$name]) ? $_COOKIE[$name] : (isset($_COOKIE[$name = ucfirst($name)]) ? $_COOKIE[$name] : null));
1233 1230
 	}
1234 1231
 
1235 1232
 	/**
@@ -1239,13 +1236,13 @@  discard block
 block discarded – undo
1239 1236
 	 * @param string $kp3 ?? to be verified
1240 1237
 	 * @return bool is the session valid?
1241 1238
 	 */
1242
-	function verify($sessionid=null,$kp3=null)
1239
+	function verify($sessionid = null, $kp3 = null)
1243 1240
 	{
1244 1241
 		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid','$kp3') ".function_backtrace());
1245 1242
 
1246 1243
 		$fill_egw_info_and_repositories = !$GLOBALS['egw_info']['flags']['restored_from_session'];
1247 1244
 
1248
-		if(!$sessionid)
1245
+		if (!$sessionid)
1249 1246
 		{
1250 1247
 			$sessionid = self::get_sessionid();
1251 1248
 			$kp3       = self::get_request('kp3');
@@ -1281,23 +1278,23 @@  discard block
 block discarded – undo
1281 1278
 			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid') session does NOT exist!");
1282 1279
 			return false;
1283 1280
 		}
1284
-		$session =& $_SESSION[self::EGW_SESSION_VAR];
1281
+		$session = & $_SESSION[self::EGW_SESSION_VAR];
1285 1282
 
1286 1283
 		if ($session['session_dla'] <= time() - $GLOBALS['egw_info']['server']['sessions_timeout'])
1287 1284
 		{
1288 1285
 			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid') session timed out!");
1289
-			$this->destroy($sessionid,$kp3);
1286
+			$this->destroy($sessionid, $kp3);
1290 1287
 			return false;
1291 1288
 		}
1292 1289
 
1293 1290
 		$this->session_flags = $session['session_flags'];
1294 1291
 
1295
-		$this->split_login_domain($session['session_lid'],$this->account_lid,$this->account_domain);
1292
+		$this->split_login_domain($session['session_lid'], $this->account_lid, $this->account_domain);
1296 1293
 
1297 1294
 		// This is to ensure that we authenticate to the correct domain (might not be default)
1298
-		if($GLOBALS['egw_info']['user']['domain'] && $this->account_domain != $GLOBALS['egw_info']['user']['domain'])
1295
+		if ($GLOBALS['egw_info']['user']['domain'] && $this->account_domain != $GLOBALS['egw_info']['user']['domain'])
1299 1296
 		{
1300
-			return false;	// session not verified, domain changed
1297
+			return false; // session not verified, domain changed
1301 1298
 		}
1302 1299
 		$GLOBALS['egw_info']['user']['kp3'] = $this->kp3;
1303 1300
 
@@ -1310,7 +1307,7 @@  discard block
 block discarded – undo
1310 1307
 		{
1311 1308
 			$this->update_notification_heartbeat();
1312 1309
 		}
1313
-		$this->account_id = $GLOBALS['egw']->accounts->name2id($this->account_lid,'account_lid','u');
1310
+		$this->account_id = $GLOBALS['egw']->accounts->name2id($this->account_lid, 'account_lid', 'u');
1314 1311
 		if (!$this->account_id)
1315 1312
 		{
1316 1313
 			if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) !accounts::name2id('$this->account_lid')");
@@ -1357,7 +1354,7 @@  discard block
 block discarded – undo
1357 1354
 
1358 1355
 		if ($GLOBALS['egw_info']['server']['sessions_checkip'])
1359 1356
 		{
1360
-			if (strtoupper(substr(PHP_OS,0,3)) != 'WIN' && (!$GLOBALS['egw_info']['user']['session_ip'] ||
1357
+			if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN' && (!$GLOBALS['egw_info']['user']['session_ip'] ||
1361 1358
 				$GLOBALS['egw_info']['user']['session_ip'] != $this->getuser_ip()))
1362 1359
 			{
1363 1360
 				if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) wrong IP");
@@ -1380,9 +1377,9 @@  discard block
 block discarded – undo
1380 1377
 		// query accesslog-id, if not set in session (session is made persistent after login!)
1381 1378
 		if (!$this->sessionid_access_log && $this->session_flags != 'A')
1382 1379
 		{
1383
-			$this->sessionid_access_log = $GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE,'sessionid',array(
1380
+			$this->sessionid_access_log = $GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE, 'sessionid', array(
1384 1381
 				'session_php' => $this->sessionid,
1385
-			),__LINE__,__FILE__)->fetchColumn();
1382
+			), __LINE__, __FILE__)->fetchColumn();
1386 1383
 			//error_log(__METHOD__."() sessionid=$this->sessionid --> sessionid_access_log=$this->sessionid_access_log");
1387 1384
 		}
1388 1385
 
@@ -1393,9 +1390,9 @@  discard block
 block discarded – undo
1393 1390
 			(!isset($_COOKIE[self::EGW_SESSION_NAME]) || $_COOKIE[self::EGW_SESSION_NAME] !== $_REQUEST[self::EGW_SESSION_NAME]))
1394 1391
 		{
1395 1392
 			if (self::ERROR_LOG_DEBUG) error_log("--> Session::verify($sessionid) SUCCESS, but NO required cookies set --> setting them now");
1396
-			self::egw_setcookie(self::EGW_SESSION_NAME,$this->sessionid);
1397
-			self::egw_setcookie('kp3',$this->kp3);
1398
-			self::egw_setcookie('domain',$this->account_domain);
1393
+			self::egw_setcookie(self::EGW_SESSION_NAME, $this->sessionid);
1394
+			self::egw_setcookie('kp3', $this->kp3);
1395
+			self::egw_setcookie('domain', $this->account_domain);
1399 1396
 		}
1400 1397
 
1401 1398
 		if (self::ERROR_LOG_DEBUG) error_log("--> Session::verify($sessionid) SUCCESS");
@@ -1410,27 +1407,27 @@  discard block
 block discarded – undo
1410 1407
 	 * @param string $kp3
1411 1408
 	 * @return boolean true on success, false on error
1412 1409
 	 */
1413
-	function destroy($sessionid, $kp3='')
1410
+	function destroy($sessionid, $kp3 = '')
1414 1411
 	{
1415 1412
 		if (!$sessionid && $kp3)
1416 1413
 		{
1417 1414
 			return false;
1418 1415
 		}
1419
-		$this->log_access($sessionid);	// log logout-time
1416
+		$this->log_access($sessionid); // log logout-time
1420 1417
 
1421 1418
 		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($sessionid,$kp3)");
1422 1419
 
1423 1420
 		if (is_numeric($sessionid))	// do we have a access-log-id --> get PHP session id
1424 1421
 		{
1425
-			$sessionid = $GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE,'session_php',array(
1422
+			$sessionid = $GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE, 'session_php', array(
1426 1423
 					'sessionid' => $sessionid,
1427
-				),__LINE__,__FILE__)->fetchColumn();
1424
+				), __LINE__, __FILE__)->fetchColumn();
1428 1425
 		}
1429 1426
 
1430 1427
 		Hooks::process(array(
1431 1428
 			'location'  => 'session_destroyed',
1432 1429
 			'sessionid' => $sessionid,
1433
-		),'',true);	// true = run hooks from all apps, not just the ones the current user has perms to run
1430
+		), '', true); // true = run hooks from all apps, not just the ones the current user has perms to run
1434 1431
 
1435 1432
 		// Only do the following, if where working with the current user
1436 1433
 		if (!$GLOBALS['egw_info']['user']['sessionid'] || $sessionid == $GLOBALS['egw_info']['user']['sessionid'])
@@ -1451,7 +1448,7 @@  discard block
 block discarded – undo
1451 1448
 		}
1452 1449
 		else
1453 1450
 		{
1454
-			$this->commit_session();	// close our own session
1451
+			$this->commit_session(); // close our own session
1455 1452
 
1456 1453
 			session_id($sessionid);
1457 1454
 			if (session_start())
@@ -1491,25 +1488,25 @@  discard block
 block discarded – undo
1491 1488
 		// as $webserver_url may be part of $url (as /egw is part of phpgwapi/js/egw_instant_load.html)
1492 1489
 		if (($url[0] != '/' || $webserver_url != '/') && (!$webserver_url || strpos($url, $webserver_url.'/') === false))
1493 1490
 		{
1494
-			if($url[0] != '/' && substr($webserver_url,-1) != '/')
1491
+			if ($url[0] != '/' && substr($webserver_url, -1) != '/')
1495 1492
 			{
1496
-				$url = $webserver_url .'/'. $url;
1493
+				$url = $webserver_url.'/'.$url;
1497 1494
 			}
1498 1495
 			else
1499 1496
 			{
1500
-				$url = $webserver_url . $url;
1497
+				$url = $webserver_url.$url;
1501 1498
 			}
1502 1499
 		}
1503 1500
 
1504
-		if(isset($GLOBALS['egw_info']['server']['enforce_ssl']) && $GLOBALS['egw_info']['server']['enforce_ssl'])
1501
+		if (isset($GLOBALS['egw_info']['server']['enforce_ssl']) && $GLOBALS['egw_info']['server']['enforce_ssl'])
1505 1502
 		{
1506
-			if(substr($url ,0,4) != 'http')
1503
+			if (substr($url, 0, 4) != 'http')
1507 1504
 			{
1508 1505
 				$url = 'https://'.$_SERVER['HTTP_HOST'].$url;
1509 1506
 			}
1510 1507
 			else
1511 1508
 			{
1512
-				$url = str_replace ( 'http:', 'https:', $url);
1509
+				$url = str_replace('http:', 'https:', $url);
1513 1510
 			}
1514 1511
 		}
1515 1512
 		$vars = array();
@@ -1522,7 +1519,7 @@  discard block
 block discarded – undo
1522 1519
 		}
1523 1520
 
1524 1521
 		// check if the url already contains a query and ensure that vars is an array and all strings are in extravars
1525
-		list($ret_url,$othervars) = explode('?', $url, 2);
1522
+		list($ret_url, $othervars) = explode('?', $url, 2);
1526 1523
 		if ($extravars && is_array($extravars))
1527 1524
 		{
1528 1525
 			$vars += $extravars;
@@ -1530,19 +1527,19 @@  discard block
 block discarded – undo
1530 1527
 		}
1531 1528
 		else
1532 1529
 		{
1533
-			if ($othervars) $extravars .= ($extravars?'&':'').$othervars;
1530
+			if ($othervars) $extravars .= ($extravars ? '&' : '').$othervars;
1534 1531
 		}
1535 1532
 
1536 1533
 		// parse extravars string into the vars array
1537 1534
 		if ($extravars)
1538 1535
 		{
1539
-			foreach(explode('&',$extravars) as $expr)
1536
+			foreach (explode('&', $extravars) as $expr)
1540 1537
 			{
1541
-				list($var,$val) = explode('=', $expr,2);
1542
-				if (strpos($val,'%26') != false) $val = str_replace('%26','&',$val);	// make sure to not double encode &
1543
-				if (substr($var,-2) == '[]')
1538
+				list($var, $val) = explode('=', $expr, 2);
1539
+				if (strpos($val, '%26') != false) $val = str_replace('%26', '&', $val); // make sure to not double encode &
1540
+				if (substr($var, -2) == '[]')
1544 1541
 				{
1545
-					$vars[substr($var,0,-2)][] = $val;
1542
+					$vars[substr($var, 0, -2)][] = $val;
1546 1543
 				}
1547 1544
 				else
1548 1545
 				{
@@ -1555,11 +1552,11 @@  discard block
 block discarded – undo
1555 1552
 		if (count($vars))
1556 1553
 		{
1557 1554
 			$query = array();
1558
-			foreach($vars as $key => $value)
1555
+			foreach ($vars as $key => $value)
1559 1556
 			{
1560 1557
 				if (is_array($value))
1561 1558
 				{
1562
-					foreach($value as $val)
1559
+					foreach ($value as $val)
1563 1560
 					{
1564 1561
 						$query[] = $key.'[]='.urlencode($val);
1565 1562
 					}
@@ -1569,7 +1566,7 @@  discard block
 block discarded – undo
1569 1566
 					$query[] = $key.'='.urlencode($value);
1570 1567
 				}
1571 1568
 			}
1572
-			$ret_url .= '?' . implode('&',$query);
1569
+			$ret_url .= '?'.implode('&', $query);
1573 1570
 		}
1574 1571
 		return $ret_url;
1575 1572
 	}
@@ -1630,7 +1627,7 @@  discard block
 block discarded – undo
1630 1627
 	 * @param int $cookietime =0 when cookie should expire, 0 for session only (optional)
1631 1628
 	 * @param string $cookiepath =null optional path (eg. '/') if the eGW install-dir should not be used
1632 1629
 	 */
1633
-	public static function egw_setcookie($cookiename,$cookievalue='',$cookietime=0,$cookiepath=null)
1630
+	public static function egw_setcookie($cookiename, $cookievalue = '', $cookietime = 0, $cookiepath = null)
1634 1631
 	{
1635 1632
 		if (empty(self::$cookie_domain) || empty(self::$cookie_path))
1636 1633
 		{
@@ -1643,11 +1640,11 @@  discard block
 block discarded – undo
1643 1640
 		static $is_iOS = null;
1644 1641
 		if (!$cookietime && !isset($is_iOS)) $is_iOS = (bool)preg_match('/^(iPhone|iPad|iPod)/i', Header\UserAgent::mobile());
1645 1642
 
1646
-		if(!headers_sent())	// gives only a warning, but can not send the cookie anyway
1643
+		if (!headers_sent())	// gives only a warning, but can not send the cookie anyway
1647 1644
 		{
1648 1645
 			setcookie($cookiename, $cookievalue,
1649
-				!$cookietime && $is_iOS ? time()+self::IOS_SESSION_COOKIE_LIFETIME : $cookietime,
1650
-				is_null($cookiepath) ? self::$cookie_path : $cookiepath,self::$cookie_domain,
1646
+				!$cookietime && $is_iOS ? time() + self::IOS_SESSION_COOKIE_LIFETIME : $cookietime,
1647
+				is_null($cookiepath) ? self::$cookie_path : $cookiepath, self::$cookie_domain,
1651 1648
 				// if called via HTTPS, only send cookie for https and only allow cookie access via HTTP (true)
1652 1649
 				empty($GLOBALS['egw_info']['server']['insecure_cookies']) && Header\Http::schema() === 'https', true);
1653 1650
 		}
@@ -1658,7 +1655,7 @@  discard block
 block discarded – undo
1658 1655
 	 */
1659 1656
 	private static function set_cookiedomain()
1660 1657
 	{
1661
-		if (PHP_SAPI === "cli") return;	// gives warnings and has no benefit
1658
+		if (PHP_SAPI === "cli") return; // gives warnings and has no benefit
1662 1659
 
1663 1660
 		if ($GLOBALS['egw_info']['server']['cookiedomain'])
1664 1661
 		{
@@ -1672,17 +1669,17 @@  discard block
 block discarded – undo
1672 1669
 		}
1673 1670
 		// remove port from HTTP_HOST
1674 1671
 		$arr = null;
1675
-		if (preg_match("/^(.*):(.*)$/",self::$cookie_domain,$arr))
1672
+		if (preg_match("/^(.*):(.*)$/", self::$cookie_domain, $arr))
1676 1673
 		{
1677 1674
 			self::$cookie_domain = $arr[1];
1678 1675
 		}
1679
-		if (count(explode('.',self::$cookie_domain)) <= 1)
1676
+		if (count(explode('.', self::$cookie_domain)) <= 1)
1680 1677
 		{
1681 1678
 			// setcookie dont likes domains without dots, leaving it empty, gets setcookie to fill the domain in
1682 1679
 			self::$cookie_domain = '';
1683 1680
 		}
1684 1681
 		if (!$GLOBALS['egw_info']['server']['cookiepath'] ||
1685
-			!(self::$cookie_path = parse_url($GLOBALS['egw_info']['server']['webserver_url'],PHP_URL_PATH)))
1682
+			!(self::$cookie_path = parse_url($GLOBALS['egw_info']['server']['webserver_url'], PHP_URL_PATH)))
1686 1683
 		{
1687 1684
 			self::$cookie_path = '/';
1688 1685
 		}
@@ -1702,7 +1699,7 @@  discard block
 block discarded – undo
1702 1699
 	 * @param array $domains =null defaults to $GLOBALS['egw_domain'] from the header
1703 1700
 	 * @return string $GLOBALS['egw_info']['user']['domain'] set with the domain/instance to use
1704 1701
 	 */
1705
-	public static function search_instance($login,$domain_requested,&$default_domain,$server_names,array $domains=null)
1702
+	public static function search_instance($login, $domain_requested, &$default_domain, $server_names, array $domains = null)
1706 1703
 	{
1707 1704
 		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$login','$domain_requested',".array2string($default_domain).".".array2string($server_names).".".array2string($domains).")");
1708 1705
 
@@ -1710,10 +1707,10 @@  discard block
 block discarded – undo
1710 1707
 
1711 1708
 		if (!isset($default_domain) || !isset($domains[$default_domain]))	// allow to overwrite the default domain
1712 1709
 		{
1713
-			foreach((array)$server_names as $server_name)
1710
+			foreach ((array)$server_names as $server_name)
1714 1711
 			{
1715
-				list($server_name) = explode(':', $server_name);	// remove port from HTTP_HOST
1716
-				if(isset($domains[$server_name]))
1712
+				list($server_name) = explode(':', $server_name); // remove port from HTTP_HOST
1713
+				if (isset($domains[$server_name]))
1717 1714
 				{
1718 1715
 					$default_domain = $server_name;
1719 1716
 					break;
@@ -1723,7 +1720,7 @@  discard block
 block discarded – undo
1723 1720
 					$parts = explode('.', $server_name);
1724 1721
 					array_shift($parts);
1725 1722
 					$domain_part = implode('.', $parts);
1726
-					if(isset($domains[$domain_part]))
1723
+					if (isset($domains[$domain_part]))
1727 1724
 					{
1728 1725
 						$default_domain = $domain_part;
1729 1726
 						break;
@@ -1739,11 +1736,11 @@  discard block
 block discarded – undo
1739 1736
 		}
1740 1737
 		if (isset($login))	// on login
1741 1738
 		{
1742
-			if (strpos($login,'@') === false || count($domains) == 1)
1739
+			if (strpos($login, '@') === false || count($domains) == 1)
1743 1740
 			{
1744
-				$login .= '@' . (isset($_POST['logindomain']) ? $_POST['logindomain'] : $default_domain);
1741
+				$login .= '@'.(isset($_POST['logindomain']) ? $_POST['logindomain'] : $default_domain);
1745 1742
 			}
1746
-			$parts = explode('@',$login);
1743
+			$parts = explode('@', $login);
1747 1744
 			$domain = array_pop($parts);
1748 1745
 			$GLOBALS['login'] = $login;
1749 1746
 		}
@@ -1787,7 +1784,7 @@  discard block
 block discarded – undo
1787 1784
 	 * @param boolean $update_access_log =false false: dont update egw_access_log table, but set $this->action
1788 1785
 	 * @return string action as written to egw_access_log.session_action
1789 1786
 	 */
1790
-	private function update_dla($update_access_log=false)
1787
+	private function update_dla($update_access_log = false)
1791 1788
 	{
1792 1789
 		// This way XML-RPC users aren't always listed as xmlrpc.php
1793 1790
 		if (isset($_GET['menuaction']))
@@ -1801,14 +1798,14 @@  discard block
 block discarded – undo
1801 1798
 			$action = $_SERVER['PHP_SELF'];
1802 1799
 			// remove EGroupware path, if not installed in webroot
1803 1800
 			$egw_path = $GLOBALS['egw_info']['server']['webserver_url'];
1804
-			if ($egw_path[0] != '/') $egw_path = parse_url($egw_path,PHP_URL_PATH);
1801
+			if ($egw_path[0] != '/') $egw_path = parse_url($egw_path, PHP_URL_PATH);
1805 1802
 			if ($action == '/Microsoft-Server-ActiveSync')
1806 1803
 			{
1807 1804
 				$action .= '?Cmd='.$_GET['Cmd'].'&DeviceId='.$_GET['DeviceId'];
1808 1805
 			}
1809 1806
 			elseif ($egw_path)
1810 1807
 			{
1811
-				list(,$action) = explode($egw_path,$action,2);
1808
+				list(,$action) = explode($egw_path, $action, 2);
1812 1809
 			}
1813 1810
 		}
1814 1811
 		$this->set_action($action);
@@ -1822,14 +1819,14 @@  discard block
 block discarded – undo
1822 1819
 		{
1823 1820
 			$_SESSION[self::EGW_SESSION_VAR]['session_logged_dla'] = time();
1824 1821
 
1825
-			$GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE,array(
1822
+			$GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE, array(
1826 1823
 				'session_dla' => time(),
1827 1824
 				'session_action' => $this->action,
1828 1825
 			) + ($this->action === '/logout.php' ? array() : array(
1829
-				'lo' => null,	// just in case it was (automatic) timed out before
1830
-			)),array(
1826
+				'lo' => null, // just in case it was (automatic) timed out before
1827
+			)), array(
1831 1828
 				'sessionid' => $this->sessionid_access_log,
1832
-			),__LINE__,__FILE__);
1829
+			), __LINE__, __FILE__);
1833 1830
 		}
1834 1831
 
1835 1832
 		$_SESSION[self::EGW_SESSION_VAR]['session_dla'] = time();
@@ -1847,12 +1844,12 @@  discard block
 block discarded – undo
1847 1844
 		// update dla in access-log table, if we have an access-log row (non-anonymous session)
1848 1845
 		if ($this->sessionid_access_log)
1849 1846
 		{
1850
-			$GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE,array(
1847
+			$GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE, array(
1851 1848
 				'notification_heartbeat' => time(),
1852
-			),array(
1849
+			), array(
1853 1850
 				'sessionid' => $this->sessionid_access_log,
1854 1851
 				'lo IS NULL',
1855
-			),__LINE__,__FILE__);
1852
+			), __LINE__, __FILE__);
1856 1853
 		}
1857 1854
 	}
1858 1855
 
@@ -1873,7 +1870,7 @@  discard block
 block discarded – undo
1873 1870
 		{
1874 1871
 			// authentication happens in login.php, which does NOT yet create egw-object in session
1875 1872
 			// --> need to store homedirectory in session
1876
-			if(isset($GLOBALS['auto_create_acct']['homedirectory']))
1873
+			if (isset($GLOBALS['auto_create_acct']['homedirectory']))
1877 1874
 			{
1878 1875
 				Cache::setSession(__CLASS__, 'homedirectory',
1879 1876
 					$user['homedirectory'] = $GLOBALS['auto_create_acct']['homedirectory']);
@@ -1886,7 +1883,7 @@  discard block
 block discarded – undo
1886 1883
 		$user['preferences'] = $GLOBALS['egw']->preferences->read_repository();
1887 1884
 		if (is_object($GLOBALS['egw']->datetime))
1888 1885
 		{
1889
-			$GLOBALS['egw']->datetime->__construct();		// to set tz_offset from the now read prefs
1886
+			$GLOBALS['egw']->datetime->__construct(); // to set tz_offset from the now read prefs
1890 1887
 		}
1891 1888
 		$user['apps']        = $GLOBALS['egw']->applications->read_repository();
1892 1889
 		$user['domain']      = $this->account_domain;
@@ -1909,9 +1906,9 @@  discard block
 block discarded – undo
1909 1906
 	 * @param string &$account_lid returned account_lid (ie. user)
1910 1907
 	 * @param string &$domain returned domain (ie. domain)
1911 1908
 	 */
1912
-	private function split_login_domain($login,&$account_lid,&$domain)
1909
+	private function split_login_domain($login, &$account_lid, &$domain)
1913 1910
 	{
1914
-		$parts = explode('@',$login);
1911
+		$parts = explode('@', $login);
1915 1912
 
1916 1913
 		//conference - for strings like [email protected]@default ,
1917 1914
 		//allows that user have a login that is his e-mail. (viniciuscb)
@@ -1919,11 +1916,11 @@  discard block
 block discarded – undo
1919 1916
 		{
1920 1917
 			$probable_domain = array_pop($parts);
1921 1918
 			//Last part of login string, when separated by @, is a domain name
1922
-			if (in_array($probable_domain,$this->egw_domains))
1919
+			if (in_array($probable_domain, $this->egw_domains))
1923 1920
 			{
1924 1921
 				$got_login = true;
1925 1922
 				$domain = $probable_domain;
1926
-				$account_lid = implode('@',$parts);
1923
+				$account_lid = implode('@', $parts);
1927 1924
 			}
1928 1925
 		}
1929 1926
 
@@ -1946,9 +1943,9 @@  discard block
 block discarded – undo
1946 1943
 	 * @param boolean $allow_password_md5 =false can password alread be an md5 hash
1947 1944
 	 * @return string
1948 1945
 	 */
1949
-	static function user_pw_hash($user,$password,$allow_password_md5=false)
1946
+	static function user_pw_hash($user, $password, $allow_password_md5 = false)
1950 1947
 	{
1951
-		$password_md5 = $allow_password_md5 && preg_match('/^[a-f0-9]{32}$/',$password) ? $password : md5($password);
1948
+		$password_md5 = $allow_password_md5 && preg_match('/^[a-f0-9]{32}$/', $password) ? $password : md5($password);
1952 1949
 
1953 1950
 		$hash = sha1(strtolower($user).$password_md5);
1954 1951
 
@@ -1963,12 +1960,12 @@  discard block
 block discarded – undo
1963 1960
 	 */
1964 1961
 	public static function init_handler()
1965 1962
 	{
1966
-		switch(session_status())
1963
+		switch (session_status())
1967 1964
 		{
1968 1965
 			case PHP_SESSION_DISABLED:
1969 1966
 				throw new \ErrorException('EGroupware requires PHP session extension!');
1970 1967
 			case PHP_SESSION_NONE:
1971
-				ini_set('session.use_cookies',0);	// disable the automatic use of cookies, as it uses the path / by default
1968
+				ini_set('session.use_cookies', 0); // disable the automatic use of cookies, as it uses the path / by default
1972 1969
 				session_name(self::EGW_SESSION_NAME);
1973 1970
 				if (($sessionid = self::get_sessionid()))
1974 1971
 				{
@@ -1981,7 +1978,7 @@  discard block
 block discarded – undo
1981 1978
 				}
1982 1979
 				break;
1983 1980
 			case PHP_SESSION_ACTIVE:
1984
-				return true;	// session created by MServer
1981
+				return true; // session created by MServer
1985 1982
 		}
1986 1983
 		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() no active session!");
1987 1984
 
@@ -1999,7 +1996,7 @@  discard block
 block discarded – undo
1999 1996
 	 * @param int $expire =null expiration time in seconds, default $GLOBALS['egw_info']['flags']['nocachecontrol'] or php.ini session.cache_expire
2000 1997
 	 * @param int $private =null allows to set private caching with given expiration time, by setting it to true
2001 1998
 	 */
2002
-	public static function cache_control($expire=null, $private=null)
1999
+	public static function cache_control($expire = null, $private = null)
2003 2000
 	{
2004 2001
 		if (is_null($expire) && isset($GLOBALS['egw_info']['flags']['nocachecontrol']) && is_int($GLOBALS['egw_info']['flags']['nocachecontrol']))
2005 2002
 		{
@@ -2009,7 +2006,7 @@  discard block
 block discarded – undo
2009 2006
 		if (!isset($_SESSION))
2010 2007
 		{
2011 2008
 			// controling caching and expires header
2012
-			if(!isset($expire) && (!isset($GLOBALS['egw_info']['flags']['nocachecontrol']) ||
2009
+			if (!isset($expire) && (!isset($GLOBALS['egw_info']['flags']['nocachecontrol']) ||
2013 2010
 				!$GLOBALS['egw_info']['flags']['nocachecontrol']))
2014 2011
 			{
2015 2012
 				session_cache_limiter('nocache');
@@ -2019,7 +2016,7 @@  discard block
 block discarded – undo
2019 2016
 				// allow public caching: proxys, cdns, ...
2020 2017
 				if (isset($expire))
2021 2018
 				{
2022
-					session_cache_expire((int)ceil($expire/60));	// in minutes
2019
+					session_cache_expire((int)ceil($expire / 60)); // in minutes
2023 2020
 				}
2024 2021
 				session_cache_limiter($private ? 'private' : 'public');
2025 2022
 			}
@@ -2032,8 +2029,8 @@  discard block
 block discarded – undo
2032 2029
 		// session already started
2033 2030
 		if (isset($_SESSION))
2034 2031
 		{
2035
-			if ($expire && (session_cache_limiter() !== ($expire===true?'private_no_expire':'public') ||
2036
-				is_int($expire) && $expire/60 !== session_cache_expire()))
2032
+			if ($expire && (session_cache_limiter() !== ($expire === true ? 'private_no_expire' : 'public') ||
2033
+				is_int($expire) && $expire / 60 !== session_cache_expire()))
2037 2034
 			{
2038 2035
 				$file = $line = null;
2039 2036
 				if (headers_sent($file, $line))
@@ -2041,20 +2038,20 @@  discard block
 block discarded – undo
2041 2038
 					error_log(__METHOD__."($expire) called, but header already sent in $file: $line");
2042 2039
 					return;
2043 2040
 				}
2044
-				if($expire === true)	// same behavior as session_cache_limiter('private_no_expire')
2041
+				if ($expire === true)	// same behavior as session_cache_limiter('private_no_expire')
2045 2042
 				{
2046
-					header('Cache-Control: private, max-age='.(60*session_cache_expire()));
2043
+					header('Cache-Control: private, max-age='.(60 * session_cache_expire()));
2047 2044
 					header_remove('Expires');
2048 2045
 				}
2049 2046
 				elseif ($private)
2050 2047
 				{
2051 2048
 					header('Cache-Control: private, max-age='.$expire);
2052
-					header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expire) . ' GMT');
2049
+					header('Expires: '.gmdate('D, d M Y H:i:s', time() + $expire).' GMT');
2053 2050
 				}
2054 2051
 				else
2055 2052
 				{
2056 2053
 					header('Cache-Control: public, max-age='.$expire);
2057
-					header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expire) . ' GMT');
2054
+					header('Expires: '.gmdate('D, d M Y H:i:s', time() + $expire).' GMT');
2058 2055
 				}
2059 2056
 				// remove Pragma header, might be set by old header
2060 2057
 				if (function_exists('header_remove'))	// PHP 5.3+
@@ -2079,10 +2076,10 @@  discard block
 block discarded – undo
2079 2076
 	 * @param array $filter =array() extra filter for sessions
2080 2077
 	 * @return array with sessions (values for keys as in $sort)
2081 2078
 	 */
2082
-	public static function session_list($start,$sort='DESC',$order='session_dla',$all_no_sort=False,array $filter=array())
2079
+	public static function session_list($start, $sort = 'DESC', $order = 'session_dla', $all_no_sort = False, array $filter = array())
2083 2080
 	{
2084 2081
 		$sessions = array();
2085
-		if (!preg_match('/^[a-z0-9_ ,]+$/i',$order_by=$order.' '.$sort) || $order_by == ' ')
2082
+		if (!preg_match('/^[a-z0-9_ ,]+$/i', $order_by = $order.' '.$sort) || $order_by == ' ')
2086 2083
 		{
2087 2084
 			$order_by = 'session_dla DESC';
2088 2085
 		}
@@ -2090,7 +2087,7 @@  discard block
 block discarded – undo
2090 2087
 		$filter[] = 'account_id>0';
2091 2088
 		$filter[] = 'session_dla > '.(int)(time() - $GLOBALS['egw_info']['server']['sessions_timeout']);
2092 2089
 		$filter[] = '(notification_heartbeat IS NULL OR notification_heartbeat > '.self::heartbeat_limit().')';
2093
-		foreach($GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE, '*', $filter, __LINE__, __FILE__,
2090
+		foreach ($GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE, '*', $filter, __LINE__, __FILE__,
2094 2091
 			$all_no_sort ? false : $start, 'ORDER BY '.$order_by) as $row)
2095 2092
 		{
2096 2093
 			$sessions[$row['sessionid']] = $row;
@@ -2104,7 +2101,7 @@  discard block
 block discarded – undo
2104 2101
 	 * @param array $filter =array() extra filter for sessions
2105 2102
 	 * @return int number of active sessions
2106 2103
 	 */
2107
-	public static function session_count(array $filter=array())
2104
+	public static function session_count(array $filter = array())
2108 2105
 	{
2109 2106
 		$filter['lo'] = null;
2110 2107
 		$filter[] = 'account_id>0';
@@ -2120,16 +2117,16 @@  discard block
 block discarded – undo
2120 2117
 	 */
2121 2118
 	public static function heartbeat_limit()
2122 2119
 	{
2123
-		static $limit=null;
2120
+		static $limit = null;
2124 2121
 
2125 2122
 		if (is_null($limit))
2126 2123
 		{
2127 2124
 			$config = Config::read('notifications');
2128
-			if (!($popup_poll_interval  = $config['popup_poll_interval']))
2125
+			if (!($popup_poll_interval = $config['popup_poll_interval']))
2129 2126
 			{
2130 2127
 				$popup_poll_interval = 60;
2131 2128
 			}
2132
-			$limit = (int)(time() - $popup_poll_interval-10);	// 10s grace periode
2129
+			$limit = (int)(time() - $popup_poll_interval - 10); // 10s grace periode
2133 2130
 		}
2134 2131
 		return $limit;
2135 2132
 	}
Please login to merge, or discard this patch.
Braces   +189 added lines, -48 removed lines patch added patch discarded remove patch
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
 
266 266
 		// set session_timeout from global php.ini and default to 14400=4h, if not set
267 267
 		if (!($GLOBALS['egw_info']['server']['sessions_timeout'] = ini_get('session.gc_maxlifetime')))
268
-      	{
268
+		{
269 269
       		ini_set('session.gc_maxlifetime', $GLOBALS['egw_info']['server']['sessions_timeout']=14400);
270 270
       	}
271 271
 	}
@@ -298,7 +298,10 @@  discard block
 block discarded – undo
298 298
 	 */
299 299
 	function commit_session()
300 300
 	{
301
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() sessionid=$this->sessionid, _SESSION[".self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR]).' '.function_backtrace());
301
+		if (self::ERROR_LOG_DEBUG)
302
+		{
303
+			error_log(__METHOD__."() sessionid=$this->sessionid, _SESSION[".self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR]).' '.function_backtrace());
304
+		}
302 305
 		self::encrypt($this->kp3);
303 306
 
304 307
 		session_write_close();
@@ -360,7 +363,10 @@  discard block
 block discarded – undo
360 363
 	 */
361 364
 	static function log_session_usage(&$arr,$label,$recursion=true,$limit=1000)
362 365
 	{
363
-		if (!is_array($arr)) return;
366
+		if (!is_array($arr))
367
+		{
368
+			return;
369
+		}
364 370
 
365 371
 		$sizes = array();
366 372
 		foreach($arr as $key => &$data)
@@ -375,7 +381,10 @@  discard block
 block discarded – undo
375 381
 			if ($diff > $limit)
376 382
 			{
377 383
 				error_log("strlen({$label}[$key])=".Vfs::hsize($size).", diff=".Vfs::hsize($diff));
378
-				if ($recursion) self::log_session_usage($arr[$key],$label.'['.$key.']',$recursion,$limit);
384
+				if ($recursion)
385
+				{
386
+					self::log_session_usage($arr[$key],$label.'['.$key.']',$recursion,$limit);
387
+				}
379 388
 			}
380 389
 		}
381 390
 	}
@@ -475,7 +484,10 @@  discard block
 block discarded – undo
475 484
 				$this->passwd      = $passwd;
476 485
 				$this->passwd_type = $passwd_type;
477 486
 			}
478
-			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) starting ...");
487
+			if (self::ERROR_LOG_DEBUG)
488
+			{
489
+				error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) starting ...");
490
+			}
479 491
 
480 492
 			self::split_login_domain($login,$this->account_lid,$this->account_domain);
481 493
 			// add domain to the login, if not already there
@@ -525,7 +537,10 @@  discard block
 block discarded – undo
525 537
 				{
526 538
 					$this->log_access($this->reason,$login,$user_ip,0);	// log unsuccessfull login
527 539
 				}
528
-				if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)");
540
+				if (self::ERROR_LOG_DEBUG)
541
+				{
542
+					error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)");
543
+				}
529 544
 				return false;
530 545
 			}
531 546
 
@@ -550,10 +565,13 @@  discard block
 block discarded – undo
550 565
 			// --> allows this stateless protocolls which use basic auth to use sessions!
551 566
 			if (($this->sessionid = self::get_sessionid(true)))
552 567
 			{
553
-				if (session_status() !== PHP_SESSION_ACTIVE)	// gives warning including password
568
+				if (session_status() !== PHP_SESSION_ACTIVE)
569
+				{
570
+					// gives warning including password
554 571
 				{
555 572
 					session_id($this->sessionid);
556 573
 				}
574
+				}
557 575
 			}
558 576
 			else
559 577
 			{
@@ -574,7 +592,10 @@  discard block
 block discarded – undo
574 592
 				$this->reason = 'account is expired';
575 593
 				$this->cd_reason = self::CD_ACCOUNT_EXPIRED;
576 594
 
577
-				if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)");
595
+				if (self::ERROR_LOG_DEBUG)
596
+				{
597
+					error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)");
598
+				}
578 599
 				return false;
579 600
 			}
580 601
 
@@ -590,7 +611,10 @@  discard block
 block discarded – undo
590 611
 					$this->cd_reason = $e->getCode();
591 612
 					$this->reason = $e->getMessage();
592 613
 					$this->log_access($this->reason, $login, $user_ip, 0);	// log unsuccessfull login
593
-					if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check,$fail_on_forced_password_change,'$check_2fa') UNSUCCESSFULL ($this->reason)");
614
+					if (self::ERROR_LOG_DEBUG)
615
+					{
616
+						error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check,$fail_on_forced_password_change,'$check_2fa') UNSUCCESSFULL ($this->reason)");
617
+					}
594 618
 					return false;
595 619
 				}
596 620
 			}
@@ -619,24 +643,33 @@  discard block
 block discarded – undo
619 643
 				'passwd'         => $this->passwd,
620 644
 				'account_domain' => $this->account_domain,
621 645
 				'user_ip'        => $user_ip,
622
-			),'',true)))	// true = run hooks from all apps, not just the ones the current user has perms to run
646
+			),'',true)))
647
+			{
648
+				// true = run hooks from all apps, not just the ones the current user has perms to run
623 649
 			{
624 650
 				foreach($hook_result as $reason)
625 651
 				{
626 652
 					if ($reason)	// called hook requests to deny the session
627 653
 					{
628 654
 						$this->reason = $this->cd_reason = $reason;
655
+			}
629 656
 						$this->log_access($this->reason,$login,$user_ip,0);		// log unsuccessfull login
630
-						if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)");
657
+						if (self::ERROR_LOG_DEBUG)
658
+						{
659
+							error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)");
660
+						}
631 661
 						return false;
632 662
 					}
633 663
 				}
634 664
 			}
635 665
 			$GLOBALS['egw']->db->transaction_begin();
636 666
 			$this->register_session($this->login,$user_ip,$now,$this->session_flags);
637
-			if ($this->session_flags != 'A')		// dont log anonymous sessions
667
+			if ($this->session_flags != 'A')
668
+			{
669
+				// dont log anonymous sessions
638 670
 			{
639 671
 				$this->sessionid_access_log = $this->log_access($this->sessionid,$login,$user_ip,$this->account_id);
672
+			}
640 673
 				// We do NOT log anonymous sessions to not block website and also to cope with
641 674
 				// high rate anon endpoints might be called creating a bottleneck in the egw_accounts table.
642 675
 				Cache::setSession('phpgwapi', 'account_previous_login', $GLOBALS['egw']->auth->previous_login);
@@ -663,7 +696,10 @@  discard block
 block discarded – undo
663 696
 				self::egw_setcookie(self::REMEMBER_ME_COOKIE, $token, $expiration);
664 697
 			}
665 698
 
666
-			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) successfull sessionid=$this->sessionid");
699
+			if (self::ERROR_LOG_DEBUG)
700
+			{
701
+				error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) successfull sessionid=$this->sessionid");
702
+			}
667 703
 
668 704
 			// hook called once session is created
669 705
 			Hooks::process(array(
@@ -1130,10 +1166,13 @@  discard block
 block discarded – undo
1130 1166
 		//error_log(__METHOD__."('$login', '$ip') false_ip=$false_ip, false_id=$false_id --> blocked=".array2string($blocked));
1131 1167
 
1132 1168
 		if ($blocked && $GLOBALS['egw_info']['server']['admin_mails'] &&
1133
-			$GLOBALS['egw_info']['server']['login_blocked_mail_time'] < time()-5*60)	// max. one mail every 5mins
1169
+			$GLOBALS['egw_info']['server']['login_blocked_mail_time'] < time()-5*60)
1170
+		{
1171
+			// max. one mail every 5mins
1134 1172
 		{
1135 1173
 			try {
1136 1174
 				$mailer = new Mailer();
1175
+		}
1137 1176
 				// notify admin(s) via email
1138 1177
 				$mailer->setFrom('eGroupWare@'.$GLOBALS['egw_info']['server']['mail_suffix']);
1139 1178
 				$mailer->addHeader('Subject', lang("eGroupWare: login blocked for user '%1', IP %2",$login,$ip));
@@ -1211,7 +1250,10 @@  discard block
 block discarded – undo
1211 1250
 		{
1212 1251
 			$sessionid = null;
1213 1252
 		}
1214
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() _SERVER[REQUEST_URI]='$_SERVER[REQUEST_URI]' returning ".print_r($sessionid,true));
1253
+		if (self::ERROR_LOG_DEBUG)
1254
+		{
1255
+			error_log(__METHOD__."() _SERVER[REQUEST_URI]='$_SERVER[REQUEST_URI]' returning ".print_r($sessionid,true));
1256
+		}
1215 1257
 		return $sessionid;
1216 1258
 	}
1217 1259
 
@@ -1241,7 +1283,10 @@  discard block
 block discarded – undo
1241 1283
 	 */
1242 1284
 	function verify($sessionid=null,$kp3=null)
1243 1285
 	{
1244
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid','$kp3') ".function_backtrace());
1286
+		if (self::ERROR_LOG_DEBUG)
1287
+		{
1288
+			error_log(__METHOD__."('$sessionid','$kp3') ".function_backtrace());
1289
+		}
1245 1290
 
1246 1291
 		$fill_egw_info_and_repositories = !$GLOBALS['egw_info']['flags']['restored_from_session'];
1247 1292
 
@@ -1257,7 +1302,10 @@  discard block
 block discarded – undo
1257 1302
 
1258 1303
 		if (!$this->sessionid)
1259 1304
 		{
1260
-			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid') get_sessionid()='".self::get_sessionid()."' No session ID");
1305
+			if (self::ERROR_LOG_DEBUG)
1306
+			{
1307
+				error_log(__METHOD__."('$sessionid') get_sessionid()='".self::get_sessionid()."' No session ID");
1308
+			}
1261 1309
 			return false;
1262 1310
 		}
1263 1311
 
@@ -1278,14 +1326,20 @@  discard block
 block discarded – undo
1278 1326
 		// check if we have a eGroupware session --> return false if not (but dont destroy it!)
1279 1327
 		if (is_null($_SESSION) || !isset($_SESSION[self::EGW_SESSION_VAR]))
1280 1328
 		{
1281
-			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid') session does NOT exist!");
1329
+			if (self::ERROR_LOG_DEBUG)
1330
+			{
1331
+				error_log(__METHOD__."('$sessionid') session does NOT exist!");
1332
+			}
1282 1333
 			return false;
1283 1334
 		}
1284 1335
 		$session =& $_SESSION[self::EGW_SESSION_VAR];
1285 1336
 
1286 1337
 		if ($session['session_dla'] <= time() - $GLOBALS['egw_info']['server']['sessions_timeout'])
1287 1338
 		{
1288
-			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid') session timed out!");
1339
+			if (self::ERROR_LOG_DEBUG)
1340
+			{
1341
+				error_log(__METHOD__."('$sessionid') session timed out!");
1342
+			}
1289 1343
 			$this->destroy($sessionid,$kp3);
1290 1344
 			return false;
1291 1345
 		}
@@ -1313,7 +1367,10 @@  discard block
 block discarded – undo
1313 1367
 		$this->account_id = $GLOBALS['egw']->accounts->name2id($this->account_lid,'account_lid','u');
1314 1368
 		if (!$this->account_id)
1315 1369
 		{
1316
-			if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) !accounts::name2id('$this->account_lid')");
1370
+			if (self::ERROR_LOG_DEBUG)
1371
+			{
1372
+				error_log("*** Session::verify($sessionid) !accounts::name2id('$this->account_lid')");
1373
+			}
1317 1374
 			return false;
1318 1375
 		}
1319 1376
 
@@ -1340,7 +1397,10 @@  discard block
 block discarded – undo
1340 1397
 
1341 1398
 		if ($GLOBALS['egw']->accounts->is_expired($GLOBALS['egw_info']['user']))
1342 1399
 		{
1343
-			if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) accounts is expired");
1400
+			if (self::ERROR_LOG_DEBUG)
1401
+			{
1402
+				error_log("*** Session::verify($sessionid) accounts is expired");
1403
+			}
1344 1404
 			return false;
1345 1405
 		}
1346 1406
 		$this->passwd = base64_decode(Cache::getSession('phpgwapi', 'password'));
@@ -1351,7 +1411,10 @@  discard block
 block discarded – undo
1351 1411
 		}
1352 1412
 		if ($this->account_domain != $GLOBALS['egw_info']['user']['domain'])
1353 1413
 		{
1354
-			if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) wrong domain");
1414
+			if (self::ERROR_LOG_DEBUG)
1415
+			{
1416
+				error_log("*** Session::verify($sessionid) wrong domain");
1417
+			}
1355 1418
 			return false;
1356 1419
 		}
1357 1420
 
@@ -1360,7 +1423,10 @@  discard block
 block discarded – undo
1360 1423
 			if (strtoupper(substr(PHP_OS,0,3)) != 'WIN' && (!$GLOBALS['egw_info']['user']['session_ip'] ||
1361 1424
 				$GLOBALS['egw_info']['user']['session_ip'] != $this->getuser_ip()))
1362 1425
 			{
1363
-				if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) wrong IP");
1426
+				if (self::ERROR_LOG_DEBUG)
1427
+				{
1428
+					error_log("*** Session::verify($sessionid) wrong IP");
1429
+				}
1364 1430
 				return false;
1365 1431
 			}
1366 1432
 		}
@@ -1373,7 +1439,10 @@  discard block
 block discarded – undo
1373 1439
 		}
1374 1440
 		if (!$this->account_lid)
1375 1441
 		{
1376
-			if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) !account_lid");
1442
+			if (self::ERROR_LOG_DEBUG)
1443
+			{
1444
+				error_log("*** Session::verify($sessionid) !account_lid");
1445
+			}
1377 1446
 			return false;
1378 1447
 		}
1379 1448
 
@@ -1392,13 +1461,19 @@  discard block
 block discarded – undo
1392 1461
 			$_REQUEST[self::EGW_SESSION_NAME] === $this->sessionid &&
1393 1462
 			(!isset($_COOKIE[self::EGW_SESSION_NAME]) || $_COOKIE[self::EGW_SESSION_NAME] !== $_REQUEST[self::EGW_SESSION_NAME]))
1394 1463
 		{
1395
-			if (self::ERROR_LOG_DEBUG) error_log("--> Session::verify($sessionid) SUCCESS, but NO required cookies set --> setting them now");
1464
+			if (self::ERROR_LOG_DEBUG)
1465
+			{
1466
+				error_log("--> Session::verify($sessionid) SUCCESS, but NO required cookies set --> setting them now");
1467
+			}
1396 1468
 			self::egw_setcookie(self::EGW_SESSION_NAME,$this->sessionid);
1397 1469
 			self::egw_setcookie('kp3',$this->kp3);
1398 1470
 			self::egw_setcookie('domain',$this->account_domain);
1399 1471
 		}
1400 1472
 
1401
-		if (self::ERROR_LOG_DEBUG) error_log("--> Session::verify($sessionid) SUCCESS");
1473
+		if (self::ERROR_LOG_DEBUG)
1474
+		{
1475
+			error_log("--> Session::verify($sessionid) SUCCESS");
1476
+		}
1402 1477
 
1403 1478
 		return true;
1404 1479
 	}
@@ -1418,14 +1493,20 @@  discard block
 block discarded – undo
1418 1493
 		}
1419 1494
 		$this->log_access($sessionid);	// log logout-time
1420 1495
 
1421
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($sessionid,$kp3)");
1496
+		if (self::ERROR_LOG_DEBUG)
1497
+		{
1498
+			error_log(__METHOD__."($sessionid,$kp3)");
1499
+		}
1422 1500
 
1423
-		if (is_numeric($sessionid))	// do we have a access-log-id --> get PHP session id
1501
+		if (is_numeric($sessionid))
1502
+		{
1503
+			// do we have a access-log-id --> get PHP session id
1424 1504
 		{
1425 1505
 			$sessionid = $GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE,'session_php',array(
1426 1506
 					'sessionid' => $sessionid,
1427 1507
 				),__LINE__,__FILE__)->fetchColumn();
1428 1508
 		}
1509
+		}
1429 1510
 
1430 1511
 		Hooks::process(array(
1431 1512
 			'location'  => 'session_destroyed',
@@ -1435,7 +1516,10 @@  discard block
 block discarded – undo
1435 1516
 		// Only do the following, if where working with the current user
1436 1517
 		if (!$GLOBALS['egw_info']['user']['sessionid'] || $sessionid == $GLOBALS['egw_info']['user']['sessionid'])
1437 1518
 		{
1438
-			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__." ********* about to call session_destroy!");
1519
+			if (self::ERROR_LOG_DEBUG)
1520
+			{
1521
+				error_log(__METHOD__." ********* about to call session_destroy!");
1522
+			}
1439 1523
 			session_unset();
1440 1524
 			@session_destroy();
1441 1525
 			// we need to (re-)load the eGW session-handler, as session_destroy unloads custom session-handlers
@@ -1530,7 +1614,10 @@  discard block
 block discarded – undo
1530 1614
 		}
1531 1615
 		else
1532 1616
 		{
1533
-			if ($othervars) $extravars .= ($extravars?'&':'').$othervars;
1617
+			if ($othervars)
1618
+			{
1619
+				$extravars .= ($extravars?'&':'').$othervars;
1620
+			}
1534 1621
 		}
1535 1622
 
1536 1623
 		// parse extravars string into the vars array
@@ -1539,7 +1626,11 @@  discard block
 block discarded – undo
1539 1626
 			foreach(explode('&',$extravars) as $expr)
1540 1627
 			{
1541 1628
 				list($var,$val) = explode('=', $expr,2);
1542
-				if (strpos($val,'%26') != false) $val = str_replace('%26','&',$val);	// make sure to not double encode &
1629
+				if (strpos($val,'%26') != false)
1630
+				{
1631
+					$val = str_replace('%26','&',$val);
1632
+				}
1633
+				// make sure to not double encode &
1543 1634
 				if (substr($var,-2) == '[]')
1544 1635
 				{
1545 1636
 					$vars[substr($var,0,-2)][] = $val;
@@ -1636,14 +1727,22 @@  discard block
 block discarded – undo
1636 1727
 		{
1637 1728
 			self::set_cookiedomain();
1638 1729
 		}
1639
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($cookiename,$cookievalue,$cookietime,$cookiepath,".self::$cookie_domain.")");
1730
+		if (self::ERROR_LOG_DEBUG)
1731
+		{
1732
+			error_log(__METHOD__."($cookiename,$cookievalue,$cookietime,$cookiepath,".self::$cookie_domain.")");
1733
+		}
1640 1734
 
1641 1735
 		// if we are installed in iOS as web-app, we must not set a cookietime==0 (session-cookie),
1642 1736
 		// as every change between apps will cause the cookie to get lost
1643 1737
 		static $is_iOS = null;
1644
-		if (!$cookietime && !isset($is_iOS)) $is_iOS = (bool)preg_match('/^(iPhone|iPad|iPod)/i', Header\UserAgent::mobile());
1738
+		if (!$cookietime && !isset($is_iOS))
1739
+		{
1740
+			$is_iOS = (bool)preg_match('/^(iPhone|iPad|iPod)/i', Header\UserAgent::mobile());
1741
+		}
1645 1742
 
1646
-		if(!headers_sent())	// gives only a warning, but can not send the cookie anyway
1743
+		if(!headers_sent())
1744
+		{
1745
+			// gives only a warning, but can not send the cookie anyway
1647 1746
 		{
1648 1747
 			setcookie($cookiename, $cookievalue,
1649 1748
 				!$cookietime && $is_iOS ? time()+self::IOS_SESSION_COOKIE_LIFETIME : $cookietime,
@@ -1651,6 +1750,7 @@  discard block
 block discarded – undo
1651 1750
 				// if called via HTTPS, only send cookie for https and only allow cookie access via HTTP (true)
1652 1751
 				empty($GLOBALS['egw_info']['server']['insecure_cookies']) && Header\Http::schema() === 'https', true);
1653 1752
 		}
1753
+		}
1654 1754
 	}
1655 1755
 
1656 1756
 	/**
@@ -1658,7 +1758,11 @@  discard block
 block discarded – undo
1658 1758
 	 */
1659 1759
 	private static function set_cookiedomain()
1660 1760
 	{
1661
-		if (PHP_SAPI === "cli") return;	// gives warnings and has no benefit
1761
+		if (PHP_SAPI === "cli")
1762
+		{
1763
+			return;
1764
+		}
1765
+		// gives warnings and has no benefit
1662 1766
 
1663 1767
 		if ($GLOBALS['egw_info']['server']['cookiedomain'])
1664 1768
 		{
@@ -1704,15 +1808,25 @@  discard block
 block discarded – undo
1704 1808
 	 */
1705 1809
 	public static function search_instance($login,$domain_requested,&$default_domain,$server_names,array $domains=null)
1706 1810
 	{
1707
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$login','$domain_requested',".array2string($default_domain).".".array2string($server_names).".".array2string($domains).")");
1811
+		if (self::ERROR_LOG_DEBUG)
1812
+		{
1813
+			error_log(__METHOD__."('$login','$domain_requested',".array2string($default_domain).".".array2string($server_names).".".array2string($domains).")");
1814
+		}
1708 1815
 
1709
-		if (is_null($domains)) $domains = $GLOBALS['egw_domain'];
1816
+		if (is_null($domains))
1817
+		{
1818
+			$domains = $GLOBALS['egw_domain'];
1819
+		}
1710 1820
 
1711
-		if (!isset($default_domain) || !isset($domains[$default_domain]))	// allow to overwrite the default domain
1821
+		if (!isset($default_domain) || !isset($domains[$default_domain]))
1822
+		{
1823
+			// allow to overwrite the default domain
1712 1824
 		{
1713 1825
 			foreach((array)$server_names as $server_name)
1714 1826
 			{
1715
-				list($server_name) = explode(':', $server_name);	// remove port from HTTP_HOST
1827
+				list($server_name) = explode(':', $server_name);
1828
+		}
1829
+		// remove port from HTTP_HOST
1716 1830
 				if(isset($domains[$server_name]))
1717 1831
 				{
1718 1832
 					$default_domain = $server_name;
@@ -1737,11 +1851,14 @@  discard block
 block discarded – undo
1737 1851
 				}
1738 1852
 			}
1739 1853
 		}
1740
-		if (isset($login))	// on login
1854
+		if (isset($login))
1855
+		{
1856
+			// on login
1741 1857
 		{
1742 1858
 			if (strpos($login,'@') === false || count($domains) == 1)
1743 1859
 			{
1744 1860
 				$login .= '@' . (isset($_POST['logindomain']) ? $_POST['logindomain'] : $default_domain);
1861
+		}
1745 1862
 			}
1746 1863
 			$parts = explode('@',$login);
1747 1864
 			$domain = array_pop($parts);
@@ -1755,7 +1872,10 @@  discard block
 block discarded – undo
1755 1872
 		{
1756 1873
 			$domain = $default_domain;
1757 1874
 		}
1758
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() default_domain=".array2string($default_domain).', login='.array2string($login)." returning ".array2string($domain));
1875
+		if (self::ERROR_LOG_DEBUG)
1876
+		{
1877
+			error_log(__METHOD__."() default_domain=".array2string($default_domain).', login='.array2string($login)." returning ".array2string($domain));
1878
+		}
1759 1879
 
1760 1880
 		return $domain;
1761 1881
 	}
@@ -1794,14 +1914,20 @@  discard block
 block discarded – undo
1794 1914
 		{
1795 1915
 			list(, $action) = explode('.ajax_exec.template.', $_GET['menuaction']);
1796 1916
 
1797
-			if (empty($action)) $action = $_GET['menuaction'];
1917
+			if (empty($action))
1918
+			{
1919
+				$action = $_GET['menuaction'];
1920
+			}
1798 1921
 		}
1799 1922
 		else
1800 1923
 		{
1801 1924
 			$action = $_SERVER['PHP_SELF'];
1802 1925
 			// remove EGroupware path, if not installed in webroot
1803 1926
 			$egw_path = $GLOBALS['egw_info']['server']['webserver_url'];
1804
-			if ($egw_path[0] != '/') $egw_path = parse_url($egw_path,PHP_URL_PATH);
1927
+			if ($egw_path[0] != '/')
1928
+			{
1929
+				$egw_path = parse_url($egw_path,PHP_URL_PATH);
1930
+			}
1805 1931
 			if ($action == '/Microsoft-Server-ActiveSync')
1806 1932
 			{
1807 1933
 				$action .= '?Cmd='.$_GET['Cmd'].'&DeviceId='.$_GET['DeviceId'];
@@ -1834,7 +1960,10 @@  discard block
 block discarded – undo
1834 1960
 
1835 1961
 		$_SESSION[self::EGW_SESSION_VAR]['session_dla'] = time();
1836 1962
 		$_SESSION[self::EGW_SESSION_VAR]['session_action'] = $this->action;
1837
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__.'() _SESSION['.self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR]));
1963
+		if (self::ERROR_LOG_DEBUG)
1964
+		{
1965
+			error_log(__METHOD__.'() _SESSION['.self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR]));
1966
+		}
1838 1967
 
1839 1968
 		return $this->action;
1840 1969
 	}
@@ -1976,14 +2105,20 @@  discard block
 block discarded – undo
1976 2105
 					self::cache_control();
1977 2106
 					$ok = session_start();
1978 2107
 					self::decrypt();
1979
-					if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() sessionid=$sessionid, _SESSION[".self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR]));
2108
+					if (self::ERROR_LOG_DEBUG)
2109
+					{
2110
+						error_log(__METHOD__."() sessionid=$sessionid, _SESSION[".self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR]));
2111
+					}
1980 2112
 					return $ok;
1981 2113
 				}
1982 2114
 				break;
1983 2115
 			case PHP_SESSION_ACTIVE:
1984 2116
 				return true;	// session created by MServer
1985 2117
 		}
1986
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() no active session!");
2118
+		if (self::ERROR_LOG_DEBUG)
2119
+		{
2120
+			error_log(__METHOD__."() no active session!");
2121
+		}
1987 2122
 
1988 2123
 		return false;
1989 2124
 	}
@@ -2041,9 +2176,12 @@  discard block
 block discarded – undo
2041 2176
 					error_log(__METHOD__."($expire) called, but header already sent in $file: $line");
2042 2177
 					return;
2043 2178
 				}
2044
-				if($expire === true)	// same behavior as session_cache_limiter('private_no_expire')
2179
+				if($expire === true)
2180
+				{
2181
+					// same behavior as session_cache_limiter('private_no_expire')
2045 2182
 				{
2046 2183
 					header('Cache-Control: private, max-age='.(60*session_cache_expire()));
2184
+				}
2047 2185
 					header_remove('Expires');
2048 2186
 				}
2049 2187
 				elseif ($private)
@@ -2057,10 +2195,13 @@  discard block
 block discarded – undo
2057 2195
 					header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expire) . ' GMT');
2058 2196
 				}
2059 2197
 				// remove Pragma header, might be set by old header
2060
-				if (function_exists('header_remove'))	// PHP 5.3+
2198
+				if (function_exists('header_remove'))
2199
+				{
2200
+					// PHP 5.3+
2061 2201
 				{
2062 2202
 					header_remove('Pragma');
2063 2203
 				}
2204
+				}
2064 2205
 				else
2065 2206
 				{
2066 2207
 					header('Pragma:');
Please login to merge, or discard this patch.
api/src/Translation.php 2 patches
Spacing   +107 added lines, -107 removed lines patch added patch discarded remove patch
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 	 *
99 99
 	 * @var array
100 100
 	 */
101
-	static $instance_specific_translations = array('loginscreen','mainscreen','custom');
101
+	static $instance_specific_translations = array('loginscreen', 'mainscreen', 'custom');
102 102
 
103 103
 	/**
104 104
 	 * returns the charset to use (!$lang) or the charset of the lang-files or $lang
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 	 * @param string|boolean $lang =False return charset of the active user-lang, or $lang if specified
107 107
 	 * @return string charset
108 108
 	 */
109
-	static function charset($lang=False)
109
+	static function charset($lang = False)
110 110
 	{
111 111
 		static $charsets = array();
112 112
 
@@ -114,11 +114,11 @@  discard block
 block discarded – undo
114 114
 		{
115 115
 			if (!isset($charsets[$lang]))
116 116
 			{
117
-				if (!($charsets[$lang] = self::$db->select(self::LANG_TABLE,'content',array(
117
+				if (!($charsets[$lang] = self::$db->select(self::LANG_TABLE, 'content', array(
118 118
 					'lang'		=> $lang,
119 119
 					'message_id'=> 'charset',
120 120
 					'app_name'	=> 'common',
121
-				),__LINE__,__FILE__)->fetchColumn()))
121
+				), __LINE__, __FILE__)->fetchColumn()))
122 122
 				{
123 123
 					$charsets[$lang] = 'utf-8';
124 124
 				}
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
 	 *
153 153
 	 * @param boolean $load_translations =true should we also load translations for common and currentapp
154 154
 	 */
155
-	static function init($load_translations=true)
155
+	static function init($load_translations = true)
156 156
 	{
157 157
 		if (!isset(self::$db))
158 158
 		{
@@ -164,11 +164,11 @@  discard block
 block discarded – undo
164 164
 		}
165 165
 		else
166 166
 		{
167
-			self::$system_charset =& $GLOBALS['egw_setup']->system_charset;
167
+			self::$system_charset = & $GLOBALS['egw_setup']->system_charset;
168 168
 		}
169 169
 		if ((self::$mbstring = check_load_extension('mbstring')))
170 170
 		{
171
-			if(!empty(self::$system_charset))
171
+			if (!empty(self::$system_charset))
172 172
 			{
173 173
 				$ini_default_charset = version_compare(PHP_VERSION, '5.6', '<') ? 'mbstring.internal_encoding' : 'default_charset';
174 174
 				ini_set($ini_default_charset, self::$system_charset);
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
 
178 178
 		// try loading load_via from tree-wide cache and check if it contains more rules
179 179
 		if (($load_via = Cache::getTree(__CLASS__, 'load_via')) &&
180
-			$load_via >= self::$load_via && 	// > for array --> contains more elements
180
+			$load_via >= self::$load_via && // > for array --> contains more elements
181 181
 			// little sanity check: cached array contains all stock keys, otherwise ignore it
182 182
 			!array_diff_key(self::$load_via, $load_via))
183 183
 		{
@@ -216,13 +216,13 @@  discard block
 block discarded – undo
216 216
 	 * @param string $not_found ='*' what to add to not found phrases, default '*'
217 217
 	 * @return string with translation
218 218
 	 */
219
-	static function translate($key, $vars=null, $not_found='' )
219
+	static function translate($key, $vars = null, $not_found = '')
220 220
 	{
221 221
 		if (!self::$lang_arr)
222 222
 		{
223 223
 			self::init();
224 224
 		}
225
-		$ret = $key;				// save key if we dont find a translation
225
+		$ret = $key; // save key if we dont find a translation
226 226
 		if ($not_found) $ret .= $not_found;
227 227
 
228 228
 		if (isset(self::$lang_arr[$key]))
@@ -242,16 +242,16 @@  discard block
 block discarded – undo
242 242
 		{
243 243
 			if (count($vars) > 1)
244 244
 			{
245
-				static $placeholders = array('%3','%2','%1','|%2|','|%3|','%4','%5','%6','%7','%8','%9','%10');
245
+				static $placeholders = array('%3', '%2', '%1', '|%2|', '|%3|', '%4', '%5', '%6', '%7', '%8', '%9', '%10');
246 246
 				// to cope with $vars[0] containing '%2' (eg. an urlencoded path like a referer),
247 247
 				// we first replace '%2' in $ret with '|%2|' and then use that as 2. placeholder
248 248
 				// we do that for %3 as well, ...
249
-				$vars = array_merge(array('|%3|','|%2|'),$vars);	// push '|%2|' (and such) as first replacement on $vars
250
-				$ret = str_replace($placeholders,$vars,$ret);
249
+				$vars = array_merge(array('|%3|', '|%2|'), $vars); // push '|%2|' (and such) as first replacement on $vars
250
+				$ret = str_replace($placeholders, $vars, $ret);
251 251
 			}
252 252
 			else
253 253
 			{
254
-				$ret = str_replace('%1',$vars[0],$ret);
254
+				$ret = str_replace('%1', $vars[0], $ret);
255 255
 			}
256 256
 		}
257 257
 		return $ret;
@@ -265,16 +265,16 @@  discard block
 block discarded – undo
265 265
 	 * @param string $message
266 266
 	 * @param array $vars =null vars to replace the placeholders, or null for none
267 267
 	 */
268
-	static function translate_as($account_id, $message, $vars=null)
268
+	static function translate_as($account_id, $message, $vars = null)
269 269
 	{
270
-		if(!is_numeric($account_id))
270
+		if (!is_numeric($account_id))
271 271
 		{
272 272
 			return static::translate($message, $vars);
273 273
 		}
274 274
 
275 275
 		$preferences = new Preferences($account_id);
276 276
 		$prefs = $preferences->read();
277
-		if($prefs['common']['lang'] != $GLOBALS['egw_info']['user']['preferences']['common']['lang'])
277
+		if ($prefs['common']['lang'] != $GLOBALS['egw_info']['user']['preferences']['common']['lang'])
278 278
 		{
279 279
 			$old_lang = self::$userlang;
280 280
 			$GLOBALS['egw_info']['user']['preferences']['common']['lang'] = $prefs['common']['lang'];
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
 			self::add_app($apps);
284 284
 		}
285 285
 		$phrase = static::translate($message, $vars);
286
-		if($old_lang)
286
+		if ($old_lang)
287 287
 		{
288 288
 			$GLOBALS['egw_info']['user']['preferences']['common']['lang'] = $old_lang;
289 289
 			self::init(true);
@@ -301,14 +301,14 @@  discard block
 block discarded – undo
301 301
 	 * 	if multiple names given, they are requested in one request from cache and loaded in given order
302 302
 	 * @param string $lang =false 2 or 5 char lang-code or false for the users language
303 303
 	 */
304
-	static function add_app($apps, $lang=null)
304
+	static function add_app($apps, $lang = null)
305 305
 	{
306 306
 		//error_log(__METHOD__."(".array2string($apps).", $lang) count(self::\$lang_arr)=".count(self::$lang_arr));
307 307
 		//$start = microtime(true);
308 308
 		if (!$lang) $lang = self::$userlang;
309 309
 		$tree_level = $instance_level = array();
310 310
 		if (!is_array($apps)) $apps = (array)$apps;
311
-		foreach($apps as $key => $app)
311
+		foreach ($apps as $key => $app)
312 312
 		{
313 313
 			if (!isset(self::$loaded_apps[$app]) || self::$loaded_apps[$app] != $lang && $app != 'common')
314 314
 			{
@@ -332,26 +332,26 @@  discard block
 block discarded – undo
332 332
 
333 333
 		// merging loaded translations together
334 334
 		$updated_load_via = false;
335
-		foreach((array)$apps as $app)
335
+		foreach ((array)$apps as $app)
336 336
 		{
337 337
 			$l = $app == 'custom' ? 'en' : $lang;
338 338
 			if (isset($tree_level[$app.':'.$l]))
339 339
 			{
340
-				$loaded =& $tree_level[$app.':'.$l];
340
+				$loaded = & $tree_level[$app.':'.$l];
341 341
 			}
342 342
 			elseif (isset($instance_level[$app.':'.$l]))
343 343
 			{
344
-				$loaded =& $instance_level[$app.':'.$l];
344
+				$loaded = & $instance_level[$app.':'.$l];
345 345
 			}
346 346
 			else
347 347
 			{
348 348
 				if (($instance_specific = in_array($app, self::$instance_specific_translations)))
349 349
 				{
350
-					$loaded =& self::load_app($app, $l);
350
+					$loaded = & self::load_app($app, $l);
351 351
 				}
352 352
 				else
353 353
 				{
354
-					$loaded =& self::load_app_files($app, $l, null, $updated_load_via);
354
+					$loaded = & self::load_app_files($app, $l, null, $updated_load_via);
355 355
 				}
356 356
 				//error_log(__METHOD__."('$app', '$lang') instance_specific=$instance_specific, load_app(_files)() returned ".(is_array($loaded)?'Array('.count($loaded).')':array2string($loaded)));
357 357
 				if ($loaded || $instance_specific)
@@ -364,14 +364,14 @@  discard block
 block discarded – undo
364 364
 			if ($loaded)
365 365
 			{
366 366
 				self::$lang_arr = array_merge(self::$lang_arr, $loaded);
367
-				self::$loaded_apps[$app] = $l;	// dont set something not existing to $loaded_apps, no need to load client-side
367
+				self::$loaded_apps[$app] = $l; // dont set something not existing to $loaded_apps, no need to load client-side
368 368
 			}
369 369
 		}
370 370
 		// Re-merge custom over instance level, they have higher precidence
371
-		if($tree_level && !$instance_level && self::$instance_specific_translations)
371
+		if ($tree_level && !$instance_level && self::$instance_specific_translations)
372 372
 		{
373 373
 			$custom = Cache::getInstance(__CLASS__, 'custom:en');
374
-			if($custom)
374
+			if ($custom)
375 375
 			{
376 376
 				self::$lang_arr = array_merge(self::$lang_arr, $custom);
377 377
 			}
@@ -392,7 +392,7 @@  discard block
 block discarded – undo
392 392
 	 * @param string $lang =false 2 or 5 char lang-code or false for the users language
393 393
 	 * @return array the loaded strings
394 394
 	 */
395
-	static function &load_app($app,$lang)
395
+	static function &load_app($app, $lang)
396 396
 	{
397 397
 		//$start = microtime(true);
398 398
 		if (!isset(self::$db))
@@ -401,10 +401,10 @@  discard block
 block discarded – undo
401 401
 			if (!isset(self::$db)) return;
402 402
 		}
403 403
 		$loaded = array();
404
-		foreach(self::$db->select(self::LANG_TABLE,'message_id,content',array(
404
+		foreach (self::$db->select(self::LANG_TABLE, 'message_id,content', array(
405 405
 			'lang'		=> $lang,
406 406
 			'app_name'	=> $app,
407
-		),__LINE__,__FILE__) as $row)
407
+		), __LINE__, __FILE__) as $row)
408 408
 		{
409 409
 			$loaded[strtolower($row['message_id'])] = $row['content'];
410 410
 		}
@@ -428,7 +428,7 @@  discard block
 block discarded – undo
428 428
 		'sitemgr-link' => array('sitemgr'),
429 429
 		'groupdav' => array('api'),
430 430
 		'developer_tools' => array('etemplate'),
431
-		'login' => array('api','registration'),
431
+		'login' => array('api', 'registration'),
432 432
 	);
433 433
 
434 434
 	/**
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
 	{
441 441
 		$lang = $GLOBALS['egw_info']['user']['preferences']['common']['lang'];
442 442
 		$apps = array_keys($GLOBALS['egw_info']['apps']);
443
-		foreach($apps as $app)
443
+		foreach ($apps as $app)
444 444
 		{
445 445
 			$file = self::get_lang_file($app, $lang);
446 446
 			// check if file has changed compared to what's cached
@@ -470,7 +470,7 @@  discard block
 block discarded – undo
470 470
 		Cache::unsetTree(__CLASS__, $app.':'.$lang);
471 471
 		Cache::unsetTree(__CLASS__, self::get_lang_file($app, $lang));
472 472
 
473
-		foreach(self::$load_via as $load => $via)
473
+		foreach (self::$load_via as $load => $via)
474 474
 		{
475 475
 			//error_log("load_via[load='$load'] = via = ".array2string($via));
476 476
 			if ($via === 'all-apps' || in_array($app, (array)$via))
@@ -492,7 +492,7 @@  discard block
 block discarded – undo
492 492
 	 * @param string $_lang =null
493 493
 	 * @return array $lang or $app => number pairs
494 494
 	 */
495
-	static function statistics($_lang=null)
495
+	static function statistics($_lang = null)
496 496
 	{
497 497
 		$cache = Cache::getTree(__CLASS__, 'statistics');
498 498
 
@@ -503,7 +503,7 @@  discard block
 block discarded – undo
503 503
 			{
504 504
 				$en_phrases = array_keys(self::load_app_files(null, 'en', 'all-apps'));
505 505
 				$cache['']['en'] = count($en_phrases);
506
-				foreach(array_keys(self::get_available_langs()) as $lang)
506
+				foreach (array_keys(self::get_available_langs()) as $lang)
507 507
 				{
508 508
 					if ($lang == 'en') continue;
509 509
 					$lang_phrases = array_keys(self::load_app_files(null, $lang, 'all-apps'));
@@ -514,7 +514,7 @@  discard block
 block discarded – undo
514 514
 			else
515 515
 			{
516 516
 				$cache['en'] = array();
517
-				foreach(scandir(EGW_SERVER_ROOT) as $app)
517
+				foreach (scandir(EGW_SERVER_ROOT) as $app)
518 518
 				{
519 519
 					if ($app[0] == '.' || !is_dir(EGW_SERVER_ROOT.'/'.$app) ||
520 520
 						!file_exists(self::get_lang_file($app, 'en')))
@@ -552,7 +552,7 @@  discard block
 block discarded – undo
552 552
 		if (!in_array($_app, self::$instance_specific_translations))
553 553
 		{
554 554
 			// check if cache is NOT invalided by checking if we have a modification time for concerned lang-file
555
-			$time = Cache::getTree(__CLASS__, $file=self::get_lang_file($_app, $_lang));
555
+			$time = Cache::getTree(__CLASS__, $file = self::get_lang_file($_app, $_lang));
556 556
 			// if we dont have one, cache has been invalidated and we need to load translations
557 557
 			if (!isset($time)) self::add_app($_app, $_lang);
558 558
 
@@ -572,7 +572,7 @@  discard block
 block discarded – undo
572 572
 	 * @param type $time
573 573
 	 * @return type
574 574
 	 */
575
-	static function max_lang_time($time=null)
575
+	static function max_lang_time($time = null)
576 576
 	{
577 577
 		static $max_lang_time = null;
578 578
 
@@ -583,7 +583,7 @@  discard block
 block discarded – undo
583 583
 		if (isset($time) && $time > $max_lang_time)
584 584
 		{
585 585
 			//error_log(__METHOD__."($time) updating previous max_lang_time=$max_lang_time to $time");
586
-			Cache::setTree(__CLASS__, 'max_lang_time', $max_lang_time=$time);
586
+			Cache::setTree(__CLASS__, 'max_lang_time', $max_lang_time = $time);
587 587
 		}
588 588
 		return $max_lang_time;
589 589
 	}
@@ -599,34 +599,34 @@  discard block
 block discarded – undo
599 599
 	 * @param boolean $updated_load_via =false on return true if self::$load_via was updated
600 600
 	 * @return array the loaded strings
601 601
 	 */
602
-	static function &load_app_files($app, $lang, $just_app_file=null, &$updated_load_via=false)
602
+	static function &load_app_files($app, $lang, $just_app_file = null, &$updated_load_via = false)
603 603
 	{
604 604
 		//$start = microtime(true);
605 605
 		$load_app = isset($just_app_file) ? $just_app_file : (isset(self::$load_via[$app]) ? self::$load_via[$app] : $app);
606 606
 		$loaded = array();
607
-		foreach($load_app == 'all-apps' ? scandir(EGW_SERVER_ROOT) : (array)$load_app as $app_dir)
607
+		foreach ($load_app == 'all-apps' ? scandir(EGW_SERVER_ROOT) : (array)$load_app as $app_dir)
608 608
 		{
609
-			if ($load_app == 'all-apps' && $app_dir=='..') continue; // do not try to break out of egw server root
609
+			if ($load_app == 'all-apps' && $app_dir == '..') continue; // do not try to break out of egw server root
610 610
 			if ($app_dir[0] == '.' || !is_dir(EGW_SERVER_ROOT.'/'.$app_dir) ||
611
-				!@file_exists($file=self::get_lang_file($app_dir, $lang)) ||
611
+				!@file_exists($file = self::get_lang_file($app_dir, $lang)) ||
612 612
 				!($f = fopen($file, 'r')))
613 613
 			{
614 614
 				continue;
615 615
 			}
616 616
 			// store ctime of file we parse
617
-			Cache::setTree(__CLASS__, $file, $time=filemtime($file));
617
+			Cache::setTree(__CLASS__, $file, $time = filemtime($file));
618 618
 			self::max_lang_time($time);
619 619
 
620 620
 			$line_nr = 0;
621 621
 			//use fgets and split the line, as php5.3.3 with squeeze does not support splitting lines with fgetcsv while reading properly
622 622
 			//if the first letter after the delimiter is a german umlaut (UTF8 representation thereoff)
623 623
 			//while(($line = fgetcsv($f, 1024, "\t")))
624
-			while(($read = fgets($f)))
624
+			while (($read = fgets($f)))
625 625
 			{
626 626
 				$line = explode("\t", trim($read));
627 627
 				++$line_nr;
628 628
 				if (count($line) != 4) continue;
629
-				list($l_id,$l_app,$l_lang,$l_translation) = $line;
629
+				list($l_id, $l_app, $l_lang, $l_translation) = $line;
630 630
 				if ($l_lang != $lang) continue;
631 631
 				if (!isset($just_app_file) && $l_app != $app)
632 632
 				{
@@ -672,7 +672,7 @@  discard block
 block discarded – undo
672 672
 			// little sanity check: cached array contains all stock keys, otherwise ignore it
673 673
 			!array_diff_key(self::$load_via, $load_via))
674 674
 		{
675
-			foreach($load_via as $app => $via)
675
+			foreach ($load_via as $app => $via)
676 676
 			{
677 677
 				if (self::$load_via[$app] != $via)
678 678
 				{
@@ -698,15 +698,15 @@  discard block
 block discarded – undo
698 698
 	 * @param boolean $force_read =false force a re-read of the languages
699 699
 	 * @return array with lang-code => descriptiv lang-name pairs
700 700
 	 */
701
-	static function get_available_langs($translate=true, $force_read=false)
701
+	static function get_available_langs($translate = true, $force_read = false)
702 702
 	{
703 703
 		if (!is_array(self::$langs) || $force_read)
704 704
 		{
705
-			if (!($f = fopen($file=EGW_SERVER_ROOT.'/setup/lang/languages','rb')))
705
+			if (!($f = fopen($file = EGW_SERVER_ROOT.'/setup/lang/languages', 'rb')))
706 706
 			{
707 707
 				throw new Exception("List of available languages (%1) missing!", $file);
708 708
 			}
709
-			while(($line = fgetcsv($f, null, "\t")))
709
+			while (($line = fgetcsv($f, null, "\t")))
710 710
 			{
711 711
 				self::$langs[$line[0]] = $line[1];
712 712
 			}
@@ -716,12 +716,12 @@  discard block
 block discarded – undo
716 716
 			{
717 717
 				if (is_null(self::$db)) self::init(false);
718 718
 
719
-				foreach(self::$langs as $lang => $name)
719
+				foreach (self::$langs as $lang => $name)
720 720
 				{
721
-					self::$langs[$lang] = self::translate($name,False,'');
721
+					self::$langs[$lang] = self::translate($name, False, '');
722 722
 				}
723 723
 			}
724
-			uasort(self::$langs,'strcasecmp');
724
+			uasort(self::$langs, 'strcasecmp');
725 725
 		}
726 726
 		return self::$langs;
727 727
 	}
@@ -734,7 +734,7 @@  discard block
 block discarded – undo
734 734
 	 * @param boolean $force_read =false force a re-read of the languages
735 735
 	 * @return array with lang-code => descriptiv lang-name pairs
736 736
 	 */
737
-	static function get_installed_langs($force_read=false)
737
+	static function get_installed_langs($force_read = false)
738 738
 	{
739 739
 		return self::get_available_langs($force_read);
740 740
 	}
@@ -751,7 +751,7 @@  discard block
 block discarded – undo
751 751
 		{
752 752
 			return self::$langs[$lang];
753 753
 		}
754
-		return self::$db->select(self::LANGUAGES_TABLE,'lang_name',array('lang_id' => $lang),__LINE__,__FILE__)->fetchColumn();
754
+		return self::$db->select(self::LANGUAGES_TABLE, 'lang_name', array('lang_id' => $lang), __LINE__, __FILE__)->fetchColumn();
755 755
 	}
756 756
 
757 757
 	/**
@@ -760,20 +760,20 @@  discard block
 block discarded – undo
760 760
 	 * @param boolean $force_read =false
761 761
 	 * @return array with lang_id => lang_name pairs
762 762
 	 */
763
-	static function list_langs($force_read=false)
763
+	static function list_langs($force_read = false)
764 764
 	{
765 765
 		if (!$force_read)
766 766
 		{
767
-			return Cache::getInstance(__CLASS__,'list_langs',array(__CLASS__,'list_langs'),array(true));
767
+			return Cache::getInstance(__CLASS__, 'list_langs', array(__CLASS__, 'list_langs'), array(true));
768 768
 		}
769
-		$languages = self::get_installed_langs();	// available languages
770
-		$availible = "('".implode("','",array_keys($languages))."')";
769
+		$languages = self::get_installed_langs(); // available languages
770
+		$availible = "('".implode("','", array_keys($languages))."')";
771 771
 
772 772
 		// this shows first the installed, then the available and then the rest
773
-		foreach(self::$db->select(self::LANGUAGES_TABLE,array(
774
-			'lang_id','lang_name',
773
+		foreach (self::$db->select(self::LANGUAGES_TABLE, array(
774
+			'lang_id', 'lang_name',
775 775
 			"CASE WHEN lang_id IN $availible THEN 1 ELSE 0 END AS availible",
776
-		),"lang_id NOT IN ('".implode("','",array_keys($languages))."')",__LINE__,__FILE__,false,' ORDER BY availible DESC,lang_name') as $row)
776
+		), "lang_id NOT IN ('".implode("','", array_keys($languages))."')", __LINE__, __FILE__, false, ' ORDER BY availible DESC,lang_name') as $row)
777 777
 		{
778 778
 			$languages[$row['lang_id']] = $row['lang_name'];
779 779
 		}
@@ -787,7 +787,7 @@  discard block
 block discarded – undo
787 787
 	 * @param string $lang language code
788 788
 	 * @return the full path of the filename for the requested app and language
789 789
 	 */
790
-	static function get_lang_file($app,$lang,$root=EGW_SERVER_ROOT)
790
+	static function get_lang_file($app, $lang, $root = EGW_SERVER_ROOT)
791 791
 	{
792 792
 		if ($app == 'common') $app = 'api';
793 793
 
@@ -801,7 +801,7 @@  discard block
 block discarded – undo
801 801
 	 */
802 802
 	static function get_installed_charsets()
803 803
 	{
804
-		static $charsets=null;
804
+		static $charsets = null;
805 805
 
806 806
 		if (!isset($charsets))
807 807
 		{
@@ -830,7 +830,7 @@  discard block
 block discarded – undo
830 830
 	{
831 831
 		static $extra = array(
832 832
 			'&szlig;' => 'ss',
833
-			'&#776;'  => 'e',	// mb_convert_encoding return &#776; for all German umlauts
833
+			'&#776;'  => 'e', // mb_convert_encoding return &#776; for all German umlauts
834 834
 		);
835 835
 		if (function_exists('mb_convert_encoding'))
836 836
 		{
@@ -841,12 +841,12 @@  discard block
 block discarded – undo
841 841
 			$entities = htmlentities($_str, ENT_QUOTES, self::charset());
842 842
 		}
843 843
 
844
-		$estr = str_replace(array_keys($extra),array_values($extra), $entities);
845
-		$ustr = preg_replace('/&([aAuUoO])uml;/','\\1e', $estr);	// replace german umlauts with the letter plus one 'e'
846
-		$astr = preg_replace('/&([a-zA-Z])(grave|acute|circ|ring|cedil|tilde|slash|uml);/','\\1', $ustr);	// remove all types of accents
844
+		$estr = str_replace(array_keys($extra), array_values($extra), $entities);
845
+		$ustr = preg_replace('/&([aAuUoO])uml;/', '\\1e', $estr); // replace german umlauts with the letter plus one 'e'
846
+		$astr = preg_replace('/&([a-zA-Z])(grave|acute|circ|ring|cedil|tilde|slash|uml);/', '\\1', $ustr); // remove all types of accents
847 847
 
848
-		return preg_replace('/[^\x20-\x7f]/', '',					// remove all non-ascii
849
-			preg_replace('/&([a-zA-Z]+|#[0-9]+|);/','', $astr));	// remove all other entities
848
+		return preg_replace('/[^\x20-\x7f]/', '', // remove all non-ascii
849
+			preg_replace('/&([a-zA-Z]+|#[0-9]+|);/', '', $astr)); // remove all other entities
850 850
 	}
851 851
 
852 852
 	/**
@@ -858,11 +858,11 @@  discard block
 block discarded – undo
858 858
 	 * @param boolean $check_to_from =true internal to bypass all charset replacements
859 859
 	 * @return NULL|string|array converted string(s) from $data
860 860
 	 */
861
-	static function convert($data,$from=False,$to=False,$check_to_from=true)
861
+	static function convert($data, $from = False, $to = False, $check_to_from = true)
862 862
 	{
863 863
 		if (empty($data))
864 864
 		{
865
-			return $data;	// no need for any charset conversation (NULL, '', 0, '0', array())
865
+			return $data; // no need for any charset conversation (NULL, '', 0, '0', array())
866 866
 		}
867 867
 		if ($check_to_from)
868 868
 		{
@@ -873,7 +873,7 @@  discard block
 block discarded – undo
873 873
 			if (!$from)
874 874
 			{
875 875
 				$from = self::$mbstring ? strtolower(mb_detect_encoding($data)) : 'iso-8859-1';
876
-				if($from == 'ascii')
876
+				if ($from == 'ascii')
877 877
 				{
878 878
 					$from = 'iso-8859-1';
879 879
 				}
@@ -883,7 +883,7 @@  discard block
 block discarded – undo
883 883
 				 php does not seem to support gb2312
884 884
 				 but seems to be able to decode it as EUC-CN
885 885
 			*/
886
-			switch($from)
886
+			switch ($from)
887 887
 			{
888 888
 				case 'ks_c_5601-1987':
889 889
 					$from = 'CP949';
@@ -932,10 +932,10 @@  discard block
 block discarded – undo
932 932
 		}
933 933
 		if (is_array($data))
934 934
 		{
935
-			foreach($data as $key => $str)
935
+			foreach ($data as $key => $str)
936 936
 			{
937
-				$ret[$key] = empty($str) ? $str :	// do NOT convert null to '' (other empty values need no conversation too)
938
-					self::convert($str,$from,$to,false);	// false = bypass the above checks, as they are already done
937
+				$ret[$key] = empty($str) ? $str : // do NOT convert null to '' (other empty values need no conversation too)
938
+					self::convert($str, $from, $to, false); // false = bypass the above checks, as they are already done
939 939
 			}
940 940
 			return $ret;
941 941
 		}
@@ -947,7 +947,7 @@  discard block
 block discarded – undo
947 947
 		{
948 948
 			return utf8_decode($data);
949 949
 		}
950
-		if (self::$mbstring && !$prefer_iconv && ($data = @mb_convert_encoding($data,$to,$from)) != '')
950
+		if (self::$mbstring && !$prefer_iconv && ($data = @mb_convert_encoding($data, $to, $from)) != '')
951 951
 		{
952 952
 			return $data;
953 953
 		}
@@ -975,12 +975,12 @@  discard block
 block discarded – undo
975 975
 			// in an email on the first Traditional/Japanese/Korean character,
976 976
 			// but in reality when people send mails in GB2312, UMA mostly use
977 977
 			// extended GB13000/GB18030 which allow T/Jap/Korean characters.
978
-			if($from == 'euc-cn')
978
+			if ($from == 'euc-cn')
979 979
 			{
980 980
 				$from = 'gb18030';
981 981
 			}
982 982
 
983
-			if (($convertedData = iconv($from,$to,$data)))
983
+			if (($convertedData = iconv($from, $to, $data)))
984 984
 			{
985 985
 				return $convertedData;
986 986
 			}
@@ -995,9 +995,9 @@  discard block
 block discarded – undo
995 995
 	 * @param string|boolean $from charset $data is in or False if it should be detected
996 996
 	 * @return string|array converted string(s) from $data
997 997
 	 */
998
-	static function convert_jsonsafe($_data,$from=False)
998
+	static function convert_jsonsafe($_data, $from = False)
999 999
 	{
1000
-		if ($from===false) $from = self::detect_encoding($_data);
1000
+		if ($from === false) $from = self::detect_encoding($_data);
1001 1001
 
1002 1002
 		$data = self::convert($_data, strtolower($from));
1003 1003
 
@@ -1006,12 +1006,12 @@  discard block
 block discarded – undo
1006 1006
 		{
1007 1007
 			$test = @json_encode($data);
1008 1008
 			//error_log(__METHOD__.__LINE__.' ->'.strlen($data).' Error:'.json_last_error().'<- data:#'.$test.'#');
1009
-			if (($test=="null" || $test === false || is_null($test)) && strlen($data)>0)
1009
+			if (($test == "null" || $test === false || is_null($test)) && strlen($data) > 0)
1010 1010
 			{
1011 1011
 				// try to fix broken utf8
1012
-				$x = (function_exists('mb_convert_encoding')?mb_convert_encoding($data,'UTF-8','UTF-8'):(function_exists('iconv')?@iconv("UTF-8","UTF-8//IGNORE",$data):$data));
1012
+				$x = (function_exists('mb_convert_encoding') ?mb_convert_encoding($data, 'UTF-8', 'UTF-8') : (function_exists('iconv') ? @iconv("UTF-8", "UTF-8//IGNORE", $data) : $data));
1013 1013
 				$test = @json_encode($x);
1014
-				if (($test=="null" || $test === false || is_null($test)) && strlen($data)>0)
1014
+				if (($test == "null" || $test === false || is_null($test)) && strlen($data) > 0)
1015 1015
 				{
1016 1016
 					// this should not be needed, unless something fails with charset detection/ wrong charset passed
1017 1017
 					error_log(__METHOD__.__LINE__.' Charset Reported:'.$from.' Charset Detected:'.self::detect_encoding($data));
@@ -1034,36 +1034,36 @@  discard block
 block discarded – undo
1034 1034
 	 * @param string $message_id
1035 1035
 	 * @param string $content translation or null to delete translation
1036 1036
 	 */
1037
-	static function write($lang,$app,$message_id,$content)
1037
+	static function write($lang, $app, $message_id, $content)
1038 1038
 	{
1039 1039
 		if ($content)
1040 1040
 		{
1041
-			self::$db->insert(self::LANG_TABLE,array(
1041
+			self::$db->insert(self::LANG_TABLE, array(
1042 1042
 				'content' => $content,
1043
-			),array(
1043
+			), array(
1044 1044
 				'lang' => $lang,
1045 1045
 				'app_name' => $app,
1046 1046
 				'message_id' => $message_id,
1047
-			),__LINE__,__FILE__);
1047
+			), __LINE__, __FILE__);
1048 1048
 		}
1049 1049
 		else
1050 1050
 		{
1051
-			self::$db->delete(self::LANG_TABLE,array(
1051
+			self::$db->delete(self::LANG_TABLE, array(
1052 1052
 				'lang' => $lang,
1053 1053
 				'app_name' => $app,
1054 1054
 				'message_id' => $message_id,
1055
-			),__LINE__,__FILE__);
1055
+			), __LINE__, __FILE__);
1056 1056
 		}
1057 1057
 		// invalidate the cache
1058
-		if(!in_array($app,self::$instance_specific_translations))
1058
+		if (!in_array($app, self::$instance_specific_translations))
1059 1059
 		{
1060
-			Cache::unsetCache(Cache::TREE,__CLASS__,$app.':'.$lang);
1060
+			Cache::unsetCache(Cache::TREE, __CLASS__, $app.':'.$lang);
1061 1061
 		}
1062 1062
 		else
1063 1063
 		{
1064
-			foreach(array_keys((array)self::get_installed_langs()) as $key)
1064
+			foreach (array_keys((array)self::get_installed_langs()) as $key)
1065 1065
 			{
1066
-				Cache::unsetCache(Cache::INSTANCE,__CLASS__,$app.':'.$key);
1066
+				Cache::unsetCache(Cache::INSTANCE, __CLASS__, $app.':'.$key);
1067 1067
 			}
1068 1068
 		}
1069 1069
  	}
@@ -1076,13 +1076,13 @@  discard block
 block discarded – undo
1076 1076
 	 * @param string $message_id
1077 1077
 	 * @return string|boolean content or false if not found
1078 1078
 	 */
1079
-	static function read($lang,$app_name,$message_id)
1079
+	static function read($lang, $app_name, $message_id)
1080 1080
 	{
1081
-		return self::$db->select(self::LANG_TABLE,'content',array(
1081
+		return self::$db->select(self::LANG_TABLE, 'content', array(
1082 1082
 			'lang' => $lang,
1083 1083
 			'app_name' => $app_name,
1084 1084
 			'message_id' => $message_id,
1085
-		),__LINE__,__FILE__)->fetchColumn();
1085
+		), __LINE__, __FILE__)->fetchColumn();
1086 1086
 	}
1087 1087
 
1088 1088
 	/**
@@ -1093,22 +1093,22 @@  discard block
 block discarded – undo
1093 1093
 	 * @param string $lang ='' default check all langs
1094 1094
 	 * @return string
1095 1095
 	 */
1096
-	static function get_message_id($translation,$app=null,$lang=null)
1096
+	static function get_message_id($translation, $app = null, $lang = null)
1097 1097
 	{
1098 1098
 		$where = array('content '.self::$db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.self::$db->quote($translation));
1099 1099
 		if ($app) $where['app_name'] = $app;
1100 1100
 		if ($lang) $where['lang'] = $lang;
1101 1101
 
1102
-		$id = self::$db->select(self::LANG_TABLE,'message_id',$where,__LINE__,__FILE__)->fetchColumn();
1102
+		$id = self::$db->select(self::LANG_TABLE, 'message_id', $where, __LINE__, __FILE__)->fetchColumn();
1103 1103
 
1104 1104
 		// Check cache, since most things aren't in the DB anymore
1105
-		if(!$id)
1105
+		if (!$id)
1106 1106
 		{
1107 1107
 			$ids = array_filter(array_keys(self::$lang_arr), function($haystack) use($translation) {
1108
-				return stripos(self::$lang_arr[$haystack],$translation) !== false;
1108
+				return stripos(self::$lang_arr[$haystack], $translation) !== false;
1109 1109
 			});
1110 1110
 			$id = array_shift($ids);
1111
-			if(!$id && ($lang && $lang !== 'en' || self::$userlang != 'en'))
1111
+			if (!$id && ($lang && $lang !== 'en' || self::$userlang != 'en'))
1112 1112
 			{
1113 1113
 				// Try english
1114 1114
 				if (in_array($app, self::$instance_specific_translations))
@@ -1125,7 +1125,7 @@  discard block
 block discarded – undo
1125 1125
 				if ($instance_level) $lang_arr = Cache::getInstance(__CLASS__, $instance_level);
1126 1126
 				$lang_arr = $lang_arr[$app.':en'];
1127 1127
 				$ids = array_filter(array_keys($lang_arr), function($haystack) use($translation, $lang_arr) {
1128
-					return stripos($lang_arr[$haystack],$translation) !== false;
1128
+					return stripos($lang_arr[$haystack], $translation) !== false;
1129 1129
 				});
1130 1130
 				$id = array_shift($ids);
1131 1131
 			}
@@ -1142,7 +1142,7 @@  discard block
 block discarded – undo
1142 1142
 	 * @param string $verify =null encoding to verify, get checked first and have a match for only ascii or no detection available
1143 1143
 	 * @return string - encoding
1144 1144
 	 */
1145
-	static function detect_encoding($string, $verify=null)
1145
+	static function detect_encoding($string, $verify = null)
1146 1146
 	{
1147 1147
 		if (function_exists('iconv'))
1148 1148
 		{
@@ -1165,7 +1165,7 @@  discard block
 block discarded – undo
1165 1165
 		}
1166 1166
 		if ($verify && (!isset($detected) || $detected === 'ascii'))
1167 1167
 		{
1168
-			return $verify;	// ascii matches all charsets
1168
+			return $verify; // ascii matches all charsets
1169 1169
 		}
1170 1170
 		return isset($detected) ? $detected : 'iso-8859-1'; // we choose to return iso-8859-1 as default
1171 1171
 	}
Please login to merge, or discard this patch.
Braces   +121 added lines, -31 removed lines patch added patch discarded remove patch
@@ -125,17 +125,23 @@  discard block
 block discarded – undo
125 125
 			}
126 126
 			return $charsets[$lang];
127 127
 		}
128
-		if (self::$system_charset)	// do we have a system-charset ==> return it
128
+		if (self::$system_charset)
129
+		{
130
+			// do we have a system-charset ==> return it
129 131
 		{
130 132
 			$charset = self::$system_charset;
131 133
 		}
134
+		}
132 135
 		else
133 136
 		{
134 137
 			// if no translations are loaded (system-startup) use a default, else lang('charset')
135 138
 			$charset = !self::$lang_arr ? 'utf-8' : strtolower(self::translate('charset'));
136 139
 		}
137 140
 		// in case no charset is set, default to utf-8
138
-		if (empty($charset) || $charset == 'charset') $charset = 'utf-8';
141
+		if (empty($charset) || $charset == 'charset')
142
+		{
143
+			$charset = 'utf-8';
144
+		}
139 145
 
140 146
 		// we need to set our charset as mbstring.internal_encoding if mbstring.func_overlaod > 0
141 147
 		// else we get problems for a charset is different from the default utf-8
@@ -194,8 +200,14 @@  discard block
 block discarded – undo
194 200
 			}
195 201
 			$apps = array('common');
196 202
 			// for eTemplate apps, load etemplate before app itself (allowing app to overwrite etemplate translations)
197
-			if (class_exists('EGroupware\\Api\\Etemplate', false) || class_exists('etemplate', false)) $apps[] = 'etemplate';
198
-			if ($GLOBALS['egw_info']['flags']['currentapp']) $apps[] = $GLOBALS['egw_info']['flags']['currentapp'];
203
+			if (class_exists('EGroupware\\Api\\Etemplate', false) || class_exists('etemplate', false))
204
+			{
205
+				$apps[] = 'etemplate';
206
+			}
207
+			if ($GLOBALS['egw_info']['flags']['currentapp'])
208
+			{
209
+				$apps[] = $GLOBALS['egw_info']['flags']['currentapp'];
210
+			}
199 211
 			// load instance specific translations last, so they can overwrite everything
200 212
 			$apps[] = 'custom';
201 213
 			self::add_app($apps);
@@ -223,7 +235,10 @@  discard block
 block discarded – undo
223 235
 			self::init();
224 236
 		}
225 237
 		$ret = $key;				// save key if we dont find a translation
226
-		if ($not_found) $ret .= $not_found;
238
+		if ($not_found)
239
+		{
240
+			$ret .= $not_found;
241
+		}
227 242
 
228 243
 		if (isset(self::$lang_arr[$key]))
229 244
 		{
@@ -305,9 +320,15 @@  discard block
 block discarded – undo
305 320
 	{
306 321
 		//error_log(__METHOD__."(".array2string($apps).", $lang) count(self::\$lang_arr)=".count(self::$lang_arr));
307 322
 		//$start = microtime(true);
308
-		if (!$lang) $lang = self::$userlang;
323
+		if (!$lang)
324
+		{
325
+			$lang = self::$userlang;
326
+		}
309 327
 		$tree_level = $instance_level = array();
310
-		if (!is_array($apps)) $apps = (array)$apps;
328
+		if (!is_array($apps))
329
+		{
330
+			$apps = (array)$apps;
331
+		}
311 332
 		foreach($apps as $key => $app)
312 333
 		{
313 334
 			if (!isset(self::$loaded_apps[$app]) || self::$loaded_apps[$app] != $lang && $app != 'common')
@@ -327,8 +348,14 @@  discard block
 block discarded – undo
327 348
 			}
328 349
 		}
329 350
 		// load all translations from cache at once
330
-		if ($tree_level) $tree_level = Cache::getTree(__CLASS__, $tree_level);
331
-		if ($instance_level) $instance_level = Cache::getInstance(__CLASS__, $instance_level);
351
+		if ($tree_level)
352
+		{
353
+			$tree_level = Cache::getTree(__CLASS__, $tree_level);
354
+		}
355
+		if ($instance_level)
356
+		{
357
+			$instance_level = Cache::getInstance(__CLASS__, $instance_level);
358
+		}
332 359
 
333 360
 		// merging loaded translations together
334 361
 		$updated_load_via = false;
@@ -398,7 +425,10 @@  discard block
 block discarded – undo
398 425
 		if (!isset(self::$db))
399 426
 		{
400 427
 			self::init(false);
401
-			if (!isset(self::$db)) return;
428
+			if (!isset(self::$db))
429
+			{
430
+				return;
431
+			}
402 432
 		}
403 433
 		$loaded = array();
404 434
 		foreach(self::$db->select(self::LANG_TABLE,'message_id,content',array(
@@ -505,7 +535,10 @@  discard block
 block discarded – undo
505 535
 				$cache['']['en'] = count($en_phrases);
506 536
 				foreach(array_keys(self::get_available_langs()) as $lang)
507 537
 				{
508
-					if ($lang == 'en') continue;
538
+					if ($lang == 'en')
539
+					{
540
+						continue;
541
+					}
509 542
 					$lang_phrases = array_keys(self::load_app_files(null, $lang, 'all-apps'));
510 543
 					$valid_phrases = array_intersect($lang_phrases, $en_phrases);
511 544
 					$cache[''][$lang] = count($valid_phrases);
@@ -522,7 +555,10 @@  discard block
 block discarded – undo
522 555
 						continue;
523 556
 					}
524 557
 					$en_phrases = array_keys(self::load_app_files(null, 'en', $app));
525
-					if (count($en_phrases) <= 2) continue;
558
+					if (count($en_phrases) <= 2)
559
+					{
560
+						continue;
561
+					}
526 562
 					$cache['en'][$app] = count($en_phrases);
527 563
 					$lang_phrases = array_keys(self::load_app_files(null, $_lang, $app));
528 564
 					$valid_phrases = array_intersect($lang_phrases, $en_phrases);
@@ -554,7 +590,10 @@  discard block
 block discarded – undo
554 590
 			// check if cache is NOT invalided by checking if we have a modification time for concerned lang-file
555 591
 			$time = Cache::getTree(__CLASS__, $file=self::get_lang_file($_app, $_lang));
556 592
 			// if we dont have one, cache has been invalidated and we need to load translations
557
-			if (!isset($time)) self::add_app($_app, $_lang);
593
+			if (!isset($time))
594
+			{
595
+				self::add_app($_app, $_lang);
596
+			}
558 597
 
559 598
 			$etag = self::max_lang_time();
560 599
 		}
@@ -606,7 +645,11 @@  discard block
 block discarded – undo
606 645
 		$loaded = array();
607 646
 		foreach($load_app == 'all-apps' ? scandir(EGW_SERVER_ROOT) : (array)$load_app as $app_dir)
608 647
 		{
609
-			if ($load_app == 'all-apps' && $app_dir=='..') continue; // do not try to break out of egw server root
648
+			if ($load_app == 'all-apps' && $app_dir=='..')
649
+			{
650
+				continue;
651
+			}
652
+			// do not try to break out of egw server root
610 653
 			if ($app_dir[0] == '.' || !is_dir(EGW_SERVER_ROOT.'/'.$app_dir) ||
611 654
 				!@file_exists($file=self::get_lang_file($app_dir, $lang)) ||
612 655
 				!($f = fopen($file, 'r')))
@@ -625,9 +668,15 @@  discard block
 block discarded – undo
625 668
 			{
626 669
 				$line = explode("\t", trim($read));
627 670
 				++$line_nr;
628
-				if (count($line) != 4) continue;
671
+				if (count($line) != 4)
672
+				{
673
+					continue;
674
+				}
629 675
 				list($l_id,$l_app,$l_lang,$l_translation) = $line;
630
-				if ($l_lang != $lang) continue;
676
+				if ($l_lang != $lang)
677
+				{
678
+					continue;
679
+				}
631 680
 				if (!isset($just_app_file) && $l_app != $app)
632 681
 				{
633 682
 					// check if $l_app contained in file in $app_dir is mentioned in $load_via
@@ -641,8 +690,14 @@  discard block
 block discarded – undo
641 690
 						}
642 691
 						// if not update load_via accordingly and store it as config
643 692
 						//error_log(__METHOD__."() load_via does not contain $l_app => $app_dir");
644
-						if (!isset(self::$load_via[$l_app])) self::$load_via[$l_app] = array($l_app);
645
-						if (!is_array(self::$load_via[$l_app])) self::$load_via[$l_app] = array(self::$load_via[$l_app]);
693
+						if (!isset(self::$load_via[$l_app]))
694
+						{
695
+							self::$load_via[$l_app] = array($l_app);
696
+						}
697
+						if (!is_array(self::$load_via[$l_app]))
698
+						{
699
+							self::$load_via[$l_app] = array(self::$load_via[$l_app]);
700
+						}
646 701
 						self::$load_via[$l_app][] = $app_dir;
647 702
 						$updated_load_via = true;
648 703
 					}
@@ -714,7 +769,10 @@  discard block
 block discarded – undo
714 769
 
715 770
 			if ($translate)
716 771
 			{
717
-				if (is_null(self::$db)) self::init(false);
772
+				if (is_null(self::$db))
773
+				{
774
+					self::init(false);
775
+				}
718 776
 
719 777
 				foreach(self::$langs as $lang => $name)
720 778
 				{
@@ -747,10 +805,13 @@  discard block
 block discarded – undo
747 805
 	 */
748 806
 	static function lang2language($lang)
749 807
 	{
750
-		if (isset(self::$langs[$lang]))	// no need to query the DB
808
+		if (isset(self::$langs[$lang]))
809
+		{
810
+			// no need to query the DB
751 811
 		{
752 812
 			return self::$langs[$lang];
753 813
 		}
814
+		}
754 815
 		return self::$db->select(self::LANGUAGES_TABLE,'lang_name',array('lang_id' => $lang),__LINE__,__FILE__)->fetchColumn();
755 816
 	}
756 817
 
@@ -789,7 +850,10 @@  discard block
 block discarded – undo
789 850
 	 */
790 851
 	static function get_lang_file($app,$lang,$root=EGW_SERVER_ROOT)
791 852
 	{
792
-		if ($app == 'common') $app = 'api';
853
+		if ($app == 'common')
854
+		{
855
+			$app = 'api';
856
+		}
793 857
 
794 858
 		return $root.'/'.$app.'/'.self::LANG_DIR.'/'.self::LANGFILE_PREFIX.$lang.self::LANGFILE_EXTENSION;
795 859
 	}
@@ -866,9 +930,15 @@  discard block
 block discarded – undo
866 930
 		}
867 931
 		if ($check_to_from)
868 932
 		{
869
-			if ($from) $from = strtolower($from);
933
+			if ($from)
934
+			{
935
+				$from = strtolower($from);
936
+			}
870 937
 
871
-			if ($to) $to = strtolower($to);
938
+			if ($to)
939
+			{
940
+				$to = strtolower($to);
941
+			}
872 942
 
873 943
 			if (!$from)
874 944
 			{
@@ -997,7 +1067,10 @@  discard block
 block discarded – undo
997 1067
 	 */
998 1068
 	static function convert_jsonsafe($_data,$from=False)
999 1069
 	{
1000
-		if ($from===false) $from = self::detect_encoding($_data);
1070
+		if ($from===false)
1071
+		{
1072
+			$from = self::detect_encoding($_data);
1073
+		}
1001 1074
 
1002 1075
 		$data = self::convert($_data, strtolower($from));
1003 1076
 
@@ -1096,15 +1169,22 @@  discard block
 block discarded – undo
1096 1169
 	static function get_message_id($translation,$app=null,$lang=null)
1097 1170
 	{
1098 1171
 		$where = array('content '.self::$db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.self::$db->quote($translation));
1099
-		if ($app) $where['app_name'] = $app;
1100
-		if ($lang) $where['lang'] = $lang;
1172
+		if ($app)
1173
+		{
1174
+			$where['app_name'] = $app;
1175
+		}
1176
+		if ($lang)
1177
+		{
1178
+			$where['lang'] = $lang;
1179
+		}
1101 1180
 
1102 1181
 		$id = self::$db->select(self::LANG_TABLE,'message_id',$where,__LINE__,__FILE__)->fetchColumn();
1103 1182
 
1104 1183
 		// Check cache, since most things aren't in the DB anymore
1105 1184
 		if(!$id)
1106 1185
 		{
1107
-			$ids = array_filter(array_keys(self::$lang_arr), function($haystack) use($translation) {
1186
+			$ids = array_filter(array_keys(self::$lang_arr), function($haystack) use($translation)
1187
+			{
1108 1188
 				return stripos(self::$lang_arr[$haystack],$translation) !== false;
1109 1189
 			});
1110 1190
 			$id = array_shift($ids);
@@ -1121,10 +1201,17 @@  discard block
 block discarded – undo
1121 1201
 				}
1122 1202
 
1123 1203
 				// load all translations from cache at once
1124
-				if ($tree_level) $lang_arr = Cache::getTree(__CLASS__, $tree_level);
1125
-				if ($instance_level) $lang_arr = Cache::getInstance(__CLASS__, $instance_level);
1204
+				if ($tree_level)
1205
+				{
1206
+					$lang_arr = Cache::getTree(__CLASS__, $tree_level);
1207
+				}
1208
+				if ($instance_level)
1209
+				{
1210
+					$lang_arr = Cache::getInstance(__CLASS__, $instance_level);
1211
+				}
1126 1212
 				$lang_arr = $lang_arr[$app.':en'];
1127
-				$ids = array_filter(array_keys($lang_arr), function($haystack) use($translation, $lang_arr) {
1213
+				$ids = array_filter(array_keys($lang_arr), function($haystack) use($translation, $lang_arr)
1214
+				{
1128 1215
 					return stripos($lang_arr[$haystack],$translation) !== false;
1129 1216
 				});
1130 1217
 				$id = array_shift($ids);
@@ -1148,7 +1235,10 @@  discard block
 block discarded – undo
1148 1235
 		{
1149 1236
 			$list = array('utf-8', 'iso-8859-1', 'windows-1251'); // list may be extended
1150 1237
 
1151
-			if ($verify) array_unshift($list, $verify);
1238
+			if ($verify)
1239
+			{
1240
+				array_unshift($list, $verify);
1241
+			}
1152 1242
 
1153 1243
 			foreach ($list as $item)
1154 1244
 			{
Please login to merge, or discard this patch.