Completed
Push — master ( c85f1f...df263c )
by Ralf
74:39 queued 51:38
created
api/src/Session.php 1 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 1 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.