Completed
Push — 14.2 ( 8c75f3...7aeda4 )
by Ralf
108:06 queued 84:21
created
phpgwapi/inc/class.egw_json.inc.php 4 patches
Doc Comments   +6 added lines, -5 removed lines patch added patch discarded remove patch
@@ -235,8 +235,7 @@  discard block
 block discarded – undo
235 235
 	/**
236 236
 	 * Allows to call a global javascript function with given parameters: window[$func].call(window[, $param1[, ...]])
237 237
 	 *
238
-	 * @param string $func name of the global (window) javascript function to call
239
-	 * @param mixed $parameters variable number of parameters
238
+	 * @param string $function
240 239
 	 */
241 240
 	public function call($function)
242 241
 	{
@@ -261,7 +260,7 @@  discard block
 block discarded – undo
261 260
 	 *
262 261
 	 * @param string $selector jquery selector
263 262
 	 * @param string $method name of the jquery to call
264
-	 * @param array $parameters =array()
263
+	 * @param string[] $parameters =array()
265 264
 	 */
266 265
 	public function jquery($selector,$method,array $parameters=array())
267 266
 	{
@@ -279,6 +278,9 @@  discard block
 block discarded – undo
279 278
 		}
280 279
 	}
281 280
 
281
+	/**
282
+	 * @param string $type
283
+	 */
282 284
 	public function generic($type, array $parameters = array())
283 285
 	{
284 286
 		if (is_string($type))
@@ -544,7 +546,6 @@  discard block
 block discarded – undo
544 546
 	/**
545 547
 	 * Init responseArray
546 548
 	 *
547
-	 * @param array $arr
548 549
 	 * @return array previous content
549 550
 	 */
550 551
 	public function initResponseArray()
@@ -628,7 +629,7 @@  discard block
 block discarded – undo
628 629
 	 *
629 630
 	 * @param midex $var
630 631
 	 * @param string $prefix =''
631
-	 * @return mixed
632
+	 * @return midex|null
632 633
 	 */
633 634
 	public static function fix_content($var, $prefix='')
634 635
 	{
Please login to merge, or discard this patch.
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -242,13 +242,13 @@
 block discarded – undo
242 242
 		if ($ret === false && ($err = json_last_error()))
243 243
 		{
244 244
 			static $json_err2str = array(
245
-	        	JSON_ERROR_NONE => 'No errors',
246
-	        	JSON_ERROR_DEPTH => 'Maximum stack depth exceeded',
247
-	        	JSON_ERROR_STATE_MISMATCH => 'Underflow or the modes mismatch',
248
-	        	JSON_ERROR_CTRL_CHAR => 'Unexpected control character found',
249
-	        	JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON',
250
-	        	JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded',
251
-	        );
245
+				JSON_ERROR_NONE => 'No errors',
246
+				JSON_ERROR_DEPTH => 'Maximum stack depth exceeded',
247
+				JSON_ERROR_STATE_MISMATCH => 'Underflow or the modes mismatch',
248
+				JSON_ERROR_CTRL_CHAR => 'Unexpected control character found',
249
+				JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON',
250
+				JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded',
251
+			);
252 252
 			error_log(__METHOD__.'('.array2string($var).') json_last_error()='.$err.'='.$json_err2str[$err]);
253 253
 
254 254
 			if (($var = self::fix_content($var)))
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 	 * @param boolean $set =null
31 31
 	 * @return boolean
32 32
 	 */
33
-	public static function isJSONRequest($set=null)
33
+	public static function isJSONRequest($set = null)
34 34
 	{
35 35
 		$ret = self::$_hadJSONRequest;
36 36
 		if (isset($set)) self::$_hadJSONRequest = $set;
@@ -53,11 +53,11 @@  discard block
 block discarded – undo
53 53
 
54 54
 		if (get_magic_quotes_gpc()) $input_data = stripslashes($input_data);
55 55
 
56
-		$json_data = json_decode($input_data,true);
56
+		$json_data = json_decode($input_data, true);
57 57
 		if (is_array($json_data) && isset($json_data['request']) && isset($json_data['request']['parameters']) && is_array($json_data['request']['parameters']))
58 58
 		{
59 59
 			//error_log(__METHOD__.__LINE__.array2string($json_data['request']).function_backtrace());
60
-			$parameters =& $json_data['request']['parameters'];
60
+			$parameters = & $json_data['request']['parameters'];
61 61
 		}
62 62
 		else
63 63
 		{
@@ -68,14 +68,14 @@  discard block
 block discarded – undo
68 68
 		{
69 69
 			$responses = array();
70 70
 			$response = egw_json_response::get();
71
-			foreach($parameters[0] as $uid => $data)
71
+			foreach ($parameters[0] as $uid => $data)
72 72
 			{
73 73
 				//error_log("$uid: menuaction=$data[menuaction], parameters=".array2string($data['parameters']));
74 74
 				$this->handleRequest($data['menuaction'], (array)$data['parameters']);
75 75
 				$responses[$uid] = $response->initResponseArray();
76 76
 				//error_log("responses[$uid]=".array2string($responses[$uid]));
77 77
 			}
78
-			$response->data($responses);	// send all responses as data
78
+			$response->data($responses); // send all responses as data
79 79
 		}
80 80
 		else
81 81
 		{
@@ -91,25 +91,25 @@  discard block
 block discarded – undo
91 91
 	 */
92 92
 	public function handleRequest($menuaction, array $parameters)
93 93
 	{
94
-		if (strpos($menuaction,'::') !== false && strpos($menuaction,'.') === false)	// static method name app_something::method
94
+		if (strpos($menuaction, '::') !== false && strpos($menuaction, '.') === false)	// static method name app_something::method
95 95
 		{
96
-			@list($className,$functionName,$handler) = explode('::',$menuaction);
97
-			list($appName) = explode('_',$className);
96
+			@list($className, $functionName, $handler) = explode('::', $menuaction);
97
+			list($appName) = explode('_', $className);
98 98
 
99 99
 			// Check for a real static method, avoid instanciation if it is
100 100
 			$m = new ReflectionMethod($menuaction);
101
-			if($m->isStatic())
101
+			if ($m->isStatic())
102 102
 			{
103 103
 				$ajaxClass = $className;
104 104
 			}
105 105
 		}
106 106
 		else
107 107
 		{
108
-			@list($appName, $className, $functionName, $handler) = explode('.',$menuaction);
108
+			@list($appName, $className, $functionName, $handler) = explode('.', $menuaction);
109 109
 		}
110 110
 		//error_log("json.php: appName=$appName, className=$className, functionName=$functionName, handler=$handler");
111 111
 
112
-		switch($handler)
112
+		switch ($handler)
113 113
 		{
114 114
 			case '/etemplate/process_exec':
115 115
 				$_GET['menuaction'] = $appName.'.'.$className.'.'.$functionName;
@@ -135,14 +135,14 @@  discard block
 block discarded – undo
135 135
 				break;
136 136
 		}
137 137
 
138
-		if(substr($className,0,4) != 'ajax' && substr($className,-4) != 'ajax' &&
139
-			$menuaction != 'etemplate.etemplate.process_exec' && substr($functionName,0,4) != 'ajax' ||
140
-			!preg_match('/^[A-Za-z0-9_-]+(\.[A-Za-z0-9_]+\.|::)[A-Za-z0-9_]+$/',$menuaction))
138
+		if (substr($className, 0, 4) != 'ajax' && substr($className, -4) != 'ajax' &&
139
+			$menuaction != 'etemplate.etemplate.process_exec' && substr($functionName, 0, 4) != 'ajax' ||
140
+			!preg_match('/^[A-Za-z0-9_-]+(\.[A-Za-z0-9_]+\.|::)[A-Za-z0-9_]+$/', $menuaction))
141 141
 		{
142 142
 			// stopped for security reasons
143
-			error_log($_SERVER['PHP_SELF']. ' stopped for security reason. '.$menuaction.' is not valid. class- or function-name must start with ajax!!!');
143
+			error_log($_SERVER['PHP_SELF'].' stopped for security reason. '.$menuaction.' is not valid. class- or function-name must start with ajax!!!');
144 144
 			// send message also to the user
145
-			throw new Exception($_SERVER['PHP_SELF']. ' stopped for security reason. '.$menuaction.' is not valid. class- or function-name must start with ajax!!!');
145
+			throw new Exception($_SERVER['PHP_SELF'].' stopped for security reason. '.$menuaction.' is not valid. class- or function-name must start with ajax!!!');
146 146
 		}
147 147
 
148 148
 		if (isset($template))
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
 	 * @param string $function name of the global (window) javascript function to call
218 218
 	 * @param array $parameters =array()
219 219
 	 */
220
-	public function apply($function,array $parameters=array())
220
+	public function apply($function, array $parameters = array())
221 221
 	{
222 222
 		if (is_string($function))
223 223
 		{
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
 	public function call($function)
242 242
 	{
243 243
 		$parameters = func_get_args();
244
-		array_shift($parameters);	// shift off $function
244
+		array_shift($parameters); // shift off $function
245 245
 
246 246
 		if (is_string($function))
247 247
 		{
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
 	 * @param string $method name of the jquery to call
264 264
 	 * @param array $parameters =array()
265 265
 	 */
266
-	public function jquery($selector,$method,array $parameters=array())
266
+	public function jquery($selector, $method, array $parameters = array())
267 267
 	{
268 268
 		if (is_string($selector) && is_string($method))
269 269
 		{
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
 	 * @param string $app =null default current app from flags
323 323
 	 * or only the current application
324 324
 	 */
325
-	public function redirect($url, $global = false, $app=null)
325
+	public function redirect($url, $global = false, $app = null)
326 326
 	{
327 327
 		if (is_string($url) && is_bool($global))
328 328
 		{
@@ -590,7 +590,7 @@  discard block
 block discarded – undo
590 590
 		/* Wrap the result array into a parent "response" Object */
591 591
 		$res = array('response' => $inst->responseArray);
592 592
 
593
-		return self::json_encode($res);	//PHP5.3+, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP);
593
+		return self::json_encode($res); //PHP5.3+, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP);
594 594
 	}
595 595
 
596 596
 	/**
@@ -630,7 +630,7 @@  discard block
 block discarded – undo
630 630
 	 * @param string $prefix =''
631 631
 	 * @return mixed
632 632
 	 */
633
-	public static function fix_content($var, $prefix='')
633
+	public static function fix_content($var, $prefix = '')
634 634
 	{
635 635
 		if (json_encode($var) !== false) return $var;
636 636
 
@@ -641,7 +641,7 @@  discard block
 block discarded – undo
641 641
 		}
642 642
 		else
643 643
 		{
644
-			foreach($var as $name => &$value)
644
+			foreach ($var as $name => &$value)
645 645
 			{
646 646
 				$value = self::fix_content($value, $prefix ? $prefix.'['.$name.']' : $name);
647 647
 			}
Please login to merge, or discard this patch.
Braces   +20 added lines, -5 removed lines patch added patch discarded remove patch
@@ -33,7 +33,10 @@  discard block
 block discarded – undo
33 33
 	public static function isJSONRequest($set=null)
34 34
 	{
35 35
 		$ret = self::$_hadJSONRequest;
36
-		if (isset($set)) self::$_hadJSONRequest = $set;
36
+		if (isset($set))
37
+		{
38
+			self::$_hadJSONRequest = $set;
39
+		}
37 40
 		return $ret;
38 41
 	}
39 42
 
@@ -51,7 +54,10 @@  discard block
 block discarded – undo
51 54
 		// Remember that we currently are in a JSON request - e.g. used in the redirect code
52 55
 		self::$_hadJSONRequest = true;
53 56
 
54
-		if (get_magic_quotes_gpc()) $input_data = stripslashes($input_data);
57
+		if (get_magic_quotes_gpc())
58
+		{
59
+			$input_data = stripslashes($input_data);
60
+		}
55 61
 
56 62
 		$json_data = json_decode($input_data,true);
57 63
 		if (is_array($json_data) && isset($json_data['request']) && isset($json_data['request']['parameters']) && is_array($json_data['request']['parameters']))
@@ -91,9 +97,12 @@  discard block
 block discarded – undo
91 97
 	 */
92 98
 	public function handleRequest($menuaction, array $parameters)
93 99
 	{
94
-		if (strpos($menuaction,'::') !== false && strpos($menuaction,'.') === false)	// static method name app_something::method
100
+		if (strpos($menuaction,'::') !== false && strpos($menuaction,'.') === false)
101
+		{
102
+			// static method name app_something::method
95 103
 		{
96 104
 			@list($className,$functionName,$handler) = explode('::',$menuaction);
105
+		}
97 106
 			list($appName) = explode('_',$className);
98 107
 
99 108
 			// Check for a real static method, avoid instanciation if it is
@@ -162,7 +171,10 @@  discard block
 block discarded – undo
162 171
 			translation::convert($parameters, 'utf-8'));
163 172
 
164 173
 		// check if we have push notifications, if notifications app available
165
-		if (class_exists('notifications_push')) notifications_push::get();
174
+		if (class_exists('notifications_push'))
175
+		{
176
+			notifications_push::get();
177
+		}
166 178
 	}
167 179
 }
168 180
 
@@ -632,7 +644,10 @@  discard block
 block discarded – undo
632 644
 	 */
633 645
 	public static function fix_content($var, $prefix='')
634 646
 	{
635
-		if (json_encode($var) !== false) return $var;
647
+		if (json_encode($var) !== false)
648
+		{
649
+			return $var;
650
+		}
636 651
 
637 652
 		if (is_scalar($var))
638 653
 		{
Please login to merge, or discard this patch.
phpgwapi/inc/class.egw_link.inc.php 4 patches
Doc Comments   +3 added lines, -5 removed lines patch added patch discarded remove patch
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
 	 * generate temporary link_id used as array-key
434 434
 	 *
435 435
 	 * @param string $app app-name
436
-	 * @param mixed $id
436
+	 * @param string $id
437 437
 	 * @return string
438 438
 	 */
439 439
 	static function temp_link_id($app,$id)
@@ -579,7 +579,7 @@  discard block
 block discarded – undo
579 579
 	 * @param string|array $id ='' id if $app_link_id is an appname or array with links, if 1. entry not yet created
580 580
 	 * @param string $app2 ='' second app
581 581
 	 * @param string $id2 ='' id in $app2
582
-	 * @return array with link-data or False
582
+	 * @return string with link-data or False
583 583
 	 */
584 584
 	static function get_link($app_link_id,$id='',$app2='',$id2='')
585 585
 	{
@@ -734,7 +734,6 @@  discard block
 block discarded – undo
734 734
 	 *
735 735
 	 * @param string $app app to search
736 736
 	 * @param string $pattern pattern to search
737
-	 * @param string $type Search only a certain sub-type of records (optional)
738 737
 	 * @return array with $id => $title pairs of matching entries of app
739 738
 	 */
740 739
 	static function query($app,$pattern, &$options = array())
@@ -1232,7 +1231,6 @@  discard block
 block discarded – undo
1232 1231
 	 * @param string $app appname to link the file to
1233 1232
 	 * @param string $id id in $app
1234 1233
 	 * @param string $file VFS path to link to
1235
-	 * @param string $comment ='' comment to add to the link
1236 1234
 	 */
1237 1235
 	static function link_file($app,$id,$file)//,$comment='')
1238 1236
 	{
@@ -1259,7 +1257,7 @@  discard block
 block discarded – undo
1259 1257
 	 * @param int|string $app > 0: file_id of an attchemnt or $app/$id entry which linked to
1260 1258
 	 * @param string $id ='' id in app
1261 1259
 	 * @param string $fname ='' filename
1262
-	 * @return boolean|array false on error ($app or $id not found), array with path as key and boolean result of delete
1260
+	 * @return boolean false on error ($app or $id not found), array with path as key and boolean result of delete
1263 1261
 	 */
1264 1262
 	static function delete_attached($app,$id='',$fname='')
1265 1263
 	{
Please login to merge, or discard this patch.
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -480,7 +480,7 @@  discard block
 block discarded – undo
480 480
 		}
481 481
 		$ids = Link\Storage::get_links($app, $id, $only_app, $order, $deleted, $limit);
482 482
 		if (empty($only_app) || $only_app == self::VFS_APPNAME ||
483
-		    ($only_app[0] == '!' && $only_app != '!'.self::VFS_APPNAME))
483
+			($only_app[0] == '!' && $only_app != '!'.self::VFS_APPNAME))
484 484
 		{
485 485
 			if (($vfs_ids = self::list_attached($app,$id)))
486 486
 			{
@@ -536,7 +536,7 @@  discard block
 block discarded – undo
536 536
 		$links = Link\Storage::get_links($app,$ids,$only_app,$order,$deleted);
537 537
 
538 538
 		if (empty($only_app) || $only_app == self::VFS_APPNAME ||
539
-		    ($only_app[0] == '!' && $only_app != '!'.self::VFS_APPNAME))
539
+			($only_app[0] == '!' && $only_app != '!'.self::VFS_APPNAME))
540 540
 		{
541 541
 			// todo do that in a single query, eg. directory listing, too
542 542
 			foreach($ids as $id)
@@ -793,7 +793,7 @@  discard block
 block discarded – undo
793 793
 
794 794
 		if (!isset($options['total']))
795 795
 		{
796
-		       $options['total'] = count($result);
796
+			   $options['total'] = count($result);
797 797
 		}
798 798
 		if (is_array($result) && (isset($options['start']) || (isset($options['num_rows']) && count($result) > $options['num_rows'])))
799 799
 		{
Please login to merge, or discard this patch.
Spacing   +179 added lines, -179 removed lines patch added patch discarded remove patch
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 	/**
111 111
 	 * appname used for returned attached files (!= 'filemanager'!)
112 112
 	 */
113
-	const VFS_APPNAME = 'file';		// pseudo-appname for own file-attachments in vfs, this is NOT the vfs-app
113
+	const VFS_APPNAME = 'file'; // pseudo-appname for own file-attachments in vfs, this is NOT the vfs-app
114 114
 
115 115
 	/**
116 116
 	 * Appname used of files stored via egw_link::set_data()
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
 			'icon' => 'addressbook/accounts',
144 144
 			'query' => 'accounts::link_query',
145 145
 			'title' => 'common::grab_owner_name',
146
-			'view' => array('menuaction'=>'addressbook.addressbook_ui.view','ajax'=>'true'),
146
+			'view' => array('menuaction'=>'addressbook.addressbook_ui.view', 'ajax'=>'true'),
147 147
 			'view_id' => 'account_id'
148 148
 		),
149 149
 		'home' => array(
@@ -201,21 +201,21 @@  discard block
 block discarded – undo
201 201
 		// other apps can participate in the linking by implementing a search_link hook, which
202 202
 		// has to return an array in the format of an app_register entry
203 203
 		// for performance reasons, we do it only once / cache it in the session
204
-		if (!($search_link_hooks = $GLOBALS['egw']->session->appsession('search_link_hooks','phpgwapi')))
204
+		if (!($search_link_hooks = $GLOBALS['egw']->session->appsession('search_link_hooks', 'phpgwapi')))
205 205
 		{
206
-			$search_link_hooks = $GLOBALS['egw']->hooks->process('search_link',array(), (bool)$GLOBALS['egw_info']['flags']['async-service']);
207
-			$GLOBALS['egw']->session->appsession('search_link_hooks','phpgwapi',$search_link_hooks);
206
+			$search_link_hooks = $GLOBALS['egw']->hooks->process('search_link', array(), (bool)$GLOBALS['egw_info']['flags']['async-service']);
207
+			$GLOBALS['egw']->session->appsession('search_link_hooks', 'phpgwapi', $search_link_hooks);
208 208
 		}
209 209
 		if (is_array($search_link_hooks))
210 210
 		{
211
-			foreach($search_link_hooks as $app => $data)
211
+			foreach ($search_link_hooks as $app => $data)
212 212
 			{
213 213
 				// allow apps to register additional types
214 214
 				if (isset($data['additional']))
215 215
 				{
216
-					foreach($data['additional'] as $name => $values)
216
+					foreach ($data['additional'] as $name => $values)
217 217
 					{
218
-						$values['app'] = $app;	// store name of registring app, to be able to check access
218
+						$values['app'] = $app; // store name of registring app, to be able to check access
219 219
 						self::$app_register[$name] = $values;
220 220
 					}
221 221
 					unset($data['additional']);
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
 				{
226 226
 					$data['list'] = array('menuaction' => $data['view_list']);
227 227
 				}
228
-				elseif(isset($data['list']) && !isset($data['view_list']))
228
+				elseif (isset($data['list']) && !isset($data['view_list']))
229 229
 				{
230 230
 					$data['view_list'] = $data['list']['menuaction'];
231 231
 				}
@@ -241,11 +241,11 @@  discard block
 block discarded – undo
241 241
 		{
242 242
 			unset(self::$app_register['home-accounts']);
243 243
 		}
244
-		if (!(self::$title_cache = $GLOBALS['egw']->session->appsession('link_title_cache','phpgwapi')))
244
+		if (!(self::$title_cache = $GLOBALS['egw']->session->appsession('link_title_cache', 'phpgwapi')))
245 245
 		{
246 246
 			self::$title_cache = array();
247 247
 		}
248
-		if (!(self::$file_access_cache = $GLOBALS['egw']->session->appsession('link_file_access_cache','phpgwapi')))
248
+		if (!(self::$file_access_cache = $GLOBALS['egw']->session->appsession('link_file_access_cache', 'phpgwapi')))
249 249
 		{
250 250
 			self::$file_access_cache = array();
251 251
 		}
@@ -269,18 +269,18 @@  discard block
 block discarded – undo
269 269
 	public static function json_registry()
270 270
 	{
271 271
 		$to_json = array();
272
-		foreach(self::$app_register as $app => $data)
272
+		foreach (self::$app_register as $app => $data)
273 273
 		{
274 274
 			if (isset($GLOBALS['egw_info']['user']['apps'][$app]) ||
275 275
 				isset($data['app']) && isset($GLOBALS['egw_info']['user']['apps'][$data['app']]))
276 276
 			{
277 277
 				$to_json[$app] = array_intersect_key($data, array_flip(array(
278
-					'view','view_id','view_popup',
279
-					'add','add_app','add_id','add_popup',
280
-					'edit','edit_id','edit_popup',
281
-					'list','list_popup',
282
-					'name','icon','query',
283
-					'mime','entry','entries',
278
+					'view', 'view_id', 'view_popup',
279
+					'add', 'add_app', 'add_id', 'add_popup',
280
+					'edit', 'edit_id', 'edit_popup',
281
+					'list', 'list_popup',
282
+					'name', 'icon', 'query',
283
+					'mime', 'entry', 'entries',
284 284
 				)));
285 285
 			}
286 286
 		}
@@ -297,8 +297,8 @@  discard block
 block discarded – undo
297 297
 		if (isset($GLOBALS['egw']->session))	// eg. cron-jobs use it too, without any session
298 298
 		{
299 299
 			//error_log(__METHOD__.'() items in title-cache: '.count(self::$title_cache).' file-access-cache: '.count(self::$file_access_cache));
300
-			$GLOBALS['egw']->session->appsession('link_title_cache','phpgwapi',self::$title_cache);
301
-			$GLOBALS['egw']->session->appsession('link_file_access_cache','phpgwapi',self::$file_access_cache);
300
+			$GLOBALS['egw']->session->appsession('link_title_cache', 'phpgwapi', self::$title_cache);
301
+			$GLOBALS['egw']->session->appsession('link_file_access_cache', 'phpgwapi', self::$file_access_cache);
302 302
 		}
303 303
 	}
304 304
 
@@ -325,11 +325,11 @@  discard block
 block discarded – undo
325 325
 	 * @param int $no_notify =0 &1 dont notify $app1, &2 dont notify $app2
326 326
 	 * @return int/boolean False (for db or param-error) or on success link_id (Please not the return-value of $id1)
327 327
 	 */
328
-	static function link( $app1,&$id1,$app2,$id2='',$remark='',$owner=0,$lastmod=0,$no_notify=0 )
328
+	static function link($app1, &$id1, $app2, $id2 = '', $remark = '', $owner = 0, $lastmod = 0, $no_notify = 0)
329 329
 	{
330 330
 		if (self::DEBUG)
331 331
 		{
332
-			echo "<p>egw_link::link('$app1',$id1,'".print_r($app2,true)."',".print_r($id2,true).",'$remark',$owner,$lastmod)</p>\n";
332
+			echo "<p>egw_link::link('$app1',$id1,'".print_r($app2, true)."',".print_r($id2, true).",'$remark',$owner,$lastmod)</p>\n";
333 333
 		}
334 334
 		if (!$app1 || !$app2 || $app1 == $app2 && $id1 == $id2)
335 335
 		{
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
 				}
349 349
 				if (is_array($id1) || !$id1)		// create link only in $id1 array
350 350
 				{
351
-					self::link($app1, $id1, $link['app'], $link['id'], $link['remark'],$link['owner'],$link['lastmod']);
351
+					self::link($app1, $id1, $link['app'], $link['id'], $link['remark'], $link['owner'], $link['lastmod']);
352 352
 					continue;
353 353
 				}
354 354
 				switch ($link['app'])
@@ -361,19 +361,19 @@  discard block
 block discarded – undo
361 361
 						}
362 362
 						// fall through
363 363
 					case self::VFS_APPNAME:
364
-						$link_id = self::attach_file($app1,$id1,$link['id'],$link['remark']);
364
+						$link_id = self::attach_file($app1, $id1, $link['id'], $link['remark']);
365 365
 						break;
366 366
 
367 367
 					case self::VFS_LINK:
368
-						$link_id = self::link_file($app1,$id1, $link['id'],$link['remark']);
368
+						$link_id = self::link_file($app1, $id1, $link['id'], $link['remark']);
369 369
 						break;
370 370
 
371 371
 					default:
372
-						$link_id = solink::link($app1,$id1,$link['app'],$link['id'],
373
-							$link['remark'],$link['owner'],$link['lastmod']);
372
+						$link_id = solink::link($app1, $id1, $link['app'], $link['id'],
373
+							$link['remark'], $link['owner'], $link['lastmod']);
374 374
 						// notify both sides
375
-						if (!($no_notify&2)) self::notify('link',$link['app'],$link['id'],$app1,$id1,$link_id);
376
-						if (!($no_notify&1)) self::notify('link',$app1,$id1,$link['app'],$link['id'],$link_id);
375
+						if (!($no_notify&2)) self::notify('link', $link['app'], $link['id'], $app1, $id1, $link_id);
376
+						if (!($no_notify&1)) self::notify('link', $app1, $id1, $link['app'], $link['id'], $link_id);
377 377
 						break;
378 378
 				}
379 379
 			}
@@ -385,7 +385,7 @@  discard block
 block discarded – undo
385 385
 			{
386 386
 				$id1 = array( );
387 387
 			}
388
-			$link_id = self::temp_link_id($app2,$id2);
388
+			$link_id = self::temp_link_id($app2, $id2);
389 389
 
390 390
 			$id1[$link_id] = array(
391 391
 				'app' => $app2,
@@ -403,24 +403,24 @@  discard block
 block discarded – undo
403 403
 		}
404 404
 		if ($app1 == self::VFS_LINK)
405 405
 		{
406
-			return self::link_file($app2,$id2,$id1,$remark);
406
+			return self::link_file($app2, $id2, $id1, $remark);
407 407
 		}
408 408
 		elseif ($app2 == self::VFS_LINK)
409 409
 		{
410
-			return self::link_file($app1,$id1,$id2,$remark);
410
+			return self::link_file($app1, $id1, $id2, $remark);
411 411
 		}
412 412
 		if ($app1 == self::VFS_APPNAME)
413 413
 		{
414
-			return self::attach_file($app2,$id2,$id1,$remark);
414
+			return self::attach_file($app2, $id2, $id1, $remark);
415 415
 		}
416 416
 		elseif ($app2 == self::VFS_APPNAME)
417 417
 		{
418
-			return self::attach_file($app1,$id1,$id2,$remark);
418
+			return self::attach_file($app1, $id1, $id2, $remark);
419 419
 		}
420
-		$link_id = solink::link($app1,$id1,$app2,$id2,$remark,$owner);
420
+		$link_id = solink::link($app1, $id1, $app2, $id2, $remark, $owner);
421 421
 
422
-		if (!($no_notify&2)) self::notify('link',$app2,$id2,$app1,$id1,$link_id);
423
-		if (!($no_notify&1)) self::notify('link',$app1,$id1,$app2,$id2,$link_id);
422
+		if (!($no_notify&2)) self::notify('link', $app2, $id2, $app1, $id1, $link_id);
423
+		if (!($no_notify&1)) self::notify('link', $app1, $id1, $app2, $id2, $link_id);
424 424
 
425 425
 		return $link_id;
426 426
 	}
@@ -432,9 +432,9 @@  discard block
 block discarded – undo
432 432
 	 * @param mixed $id
433 433
 	 * @return string
434 434
 	 */
435
-	static function temp_link_id($app,$id)
435
+	static function temp_link_id($app, $id)
436 436
 	{
437
-		return $app.':'.(!in_array($app, array(self::VFS_APPNAME,self::VFS_LINK, self::DATA_APPNAME)) ? $id : $id['name']);
437
+		return $app.':'.(!in_array($app, array(self::VFS_APPNAME, self::VFS_LINK, self::DATA_APPNAME)) ? $id : $id['name']);
438 438
 	}
439 439
 
440 440
 	/**
@@ -450,7 +450,7 @@  discard block
 block discarded – undo
450 450
 	 * @param int $limit =null number of entries to return, only affects links, attachments are allways reported!
451 451
 	 * @return array id => links pairs if $id is an array or just the links (only_app: ids) or empty array if no matching links found
452 452
 	 */
453
-	static function get_links($app, $id, $only_app='', $order='link_lastmod DESC',$cache_titles=false, $deleted=false, $limit=null)
453
+	static function get_links($app, $id, $only_app = '', $order = 'link_lastmod DESC', $cache_titles = false, $deleted = false, $limit = null)
454 454
 	{
455 455
 		if (self::DEBUG) echo "<p>egw_link::get_links(app='$app',id='$id',only_app='$only_app',order='$order',deleted='$deleted')</p>\n";
456 456
 
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
 			{
462 462
 				if (($not_only = $only_app[0] == '!'))
463 463
 				{
464
-					$only_app = substr(1,$only_app);
464
+					$only_app = substr(1, $only_app);
465 465
 				}
466 466
 				foreach (array_reverse($id) as $link)
467 467
 				{
@@ -478,7 +478,7 @@  discard block
 block discarded – undo
478 478
 		if (empty($only_app) || $only_app == self::VFS_APPNAME ||
479 479
 		    ($only_app[0] == '!' && $only_app != '!'.self::VFS_APPNAME))
480 480
 		{
481
-			if (($vfs_ids = self::list_attached($app,$id)))
481
+			if (($vfs_ids = self::list_attached($app, $id)))
482 482
 			{
483 483
 				$ids += $vfs_ids;
484 484
 			}
@@ -488,18 +488,18 @@  discard block
 block discarded – undo
488 488
 		{
489 489
 			// agregate links by app
490 490
 			$app_ids = array();
491
-			foreach($ids as $link)
491
+			foreach ($ids as $link)
492 492
 			{
493 493
 				$app_ids[$link['app']][] = $link['id'];
494 494
 			}
495
-			foreach($app_ids as $appname => $a_ids)
495
+			foreach ($app_ids as $appname => $a_ids)
496 496
 			{
497
-				self::titles($appname,array_unique($a_ids));
497
+				self::titles($appname, array_unique($a_ids));
498 498
 			}
499 499
 			// remove links, current user has no access, from result
500
-			foreach($ids as $key => $link)
500
+			foreach ($ids as $key => $link)
501 501
 			{
502
-				if (!self::title($link['app'],$link['id']))
502
+				if (!self::title($link['app'], $link['id']))
503 503
 				{
504 504
 					unset($ids[$key]);
505 505
 				}
@@ -521,27 +521,27 @@  discard block
 block discarded – undo
521 521
 	 * @param boolean $deleted =false Include links that have been flagged as deleted, waiting for purge of linked record.
522 522
 	 * @return array of $id => array($links) pairs
523 523
 	 */
524
-	static function get_links_multiple($app,array $ids,$cache_titles=true,$only_app='',$order='link_lastmod DESC', $deleted=false )
524
+	static function get_links_multiple($app, array $ids, $cache_titles = true, $only_app = '', $order = 'link_lastmod DESC', $deleted = false)
525 525
 	{
526
-		if (self::DEBUG) echo "<p>".__METHOD__."('$app',".print_r($ids,true).",$cache_titles,'$only_app','$order')</p>\n";
526
+		if (self::DEBUG) echo "<p>".__METHOD__."('$app',".print_r($ids, true).",$cache_titles,'$only_app','$order')</p>\n";
527 527
 
528 528
 		if (!$ids)
529 529
 		{
530
-			return array();		// no ids are linked to nothing
530
+			return array(); // no ids are linked to nothing
531 531
 		}
532
-		$links = solink::get_links($app,$ids,$only_app,$order,$deleted);
532
+		$links = solink::get_links($app, $ids, $only_app, $order, $deleted);
533 533
 
534 534
 		if (empty($only_app) || $only_app == self::VFS_APPNAME ||
535 535
 		    ($only_app[0] == '!' && $only_app != '!'.self::VFS_APPNAME))
536 536
 		{
537 537
 			// todo do that in a single query, eg. directory listing, too
538
-			foreach($ids as $id)
538
+			foreach ($ids as $id)
539 539
 			{
540 540
 				if (!isset($links[$id]))
541 541
 				{
542 542
 					$links[$id] = array();
543 543
 				}
544
-				if (($vfs_ids = self::list_attached($app,$id)))
544
+				if (($vfs_ids = self::list_attached($app, $id)))
545 545
 				{
546 546
 					$links[$id] += $vfs_ids;
547 547
 				}
@@ -551,16 +551,16 @@  discard block
 block discarded – undo
551 551
 		{
552 552
 			// agregate links by app
553 553
 			$app_ids = array();
554
-			foreach($links as &$targets)
554
+			foreach ($links as &$targets)
555 555
 			{
556
-				foreach($targets as $link)
556
+				foreach ($targets as $link)
557 557
 				{
558 558
 					if (is_array($link)) $app_ids[$link['app']][] = $link['id'];
559 559
 				}
560 560
 			}
561
-			foreach($app_ids as $app => $a_ids)
561
+			foreach ($app_ids as $app => $a_ids)
562 562
 			{
563
-				self::titles($app,array_unique($a_ids));
563
+				self::titles($app, array_unique($a_ids));
564 564
 			}
565 565
 		}
566 566
 		return $links;
@@ -577,7 +577,7 @@  discard block
 block discarded – undo
577 577
 	 * @param string $id2 ='' id in $app2
578 578
 	 * @return array with link-data or False
579 579
 	 */
580
-	static function get_link($app_link_id,$id='',$app2='',$id2='')
580
+	static function get_link($app_link_id, $id = '', $app2 = '', $id2 = '')
581 581
 	{
582 582
 		if (self::DEBUG)
583 583
 		{
@@ -585,7 +585,7 @@  discard block
 block discarded – undo
585 585
 		}
586 586
 		if (is_array($id))
587 587
 		{
588
-			if (strpos($app_link_id,':') === false) $app_link_id = self::temp_link_id($app2,$id2);	// create link_id of temporary link, if not given
588
+			if (strpos($app_link_id, ':') === false) $app_link_id = self::temp_link_id($app2, $id2); // create link_id of temporary link, if not given
589 589
 
590 590
 			if (isset($id[$app_link_id]) && is_array($id[$app_link_id]))	// check for unlinked-marker
591 591
 			{
@@ -601,11 +601,11 @@  discard block
 block discarded – undo
601 601
 			}
602 602
 			if ($app_link_id == self::VFS_APPNAME)
603 603
 			{
604
-				return self::info_attached($app2,$id2,$id);
604
+				return self::info_attached($app2, $id2, $id);
605 605
 			}
606
-			return self::info_attached($app_link_id,$id,$id2);
606
+			return self::info_attached($app_link_id, $id, $id2);
607 607
 		}
608
-		return solink::get_link($app_link_id,$id,$app2,$id2);
608
+		return solink::get_link($app_link_id, $id, $app2, $id2);
609 609
 	}
610 610
 
611 611
 	/**
@@ -623,9 +623,9 @@  discard block
 block discarded – undo
623 623
 	 * @param boolean $hold_for_purge Don't really delete the link, just mark it as deleted and wait for final delete
624 624
 	 * @return the number of links deleted
625 625
 	 */
626
-	static function unlink($link_id,$app='',$id='',$owner=0,$app2='',$id2='',$hold_for_purge=false)
626
+	static function unlink($link_id, $app = '', $id = '', $owner = 0, $app2 = '', $id2 = '', $hold_for_purge = false)
627 627
 	{
628
-		return self::unlink2($link_id,$app,$id,$owner,$app2,$id2,$hold_for_purge);
628
+		return self::unlink2($link_id, $app, $id, $owner, $app2, $id2, $hold_for_purge);
629 629
 	}
630 630
 
631 631
 	/**
@@ -640,7 +640,7 @@  discard block
 block discarded – undo
640 640
 	 * @param boolean $hold_for_purge Don't really delete the link, just mark it as deleted and wait for final delete
641 641
 	 * @return the number of links deleted
642 642
 	 */
643
-	static function unlink2($link_id,$app,&$id,$owner=0,$app2='',$id2='',$hold_for_purge=false)
643
+	static function unlink2($link_id, $app, &$id, $owner = 0, $app2 = '', $id2 = '', $hold_for_purge = false)
644 644
 	{
645 645
 		if (self::DEBUG)
646 646
 		{
@@ -652,22 +652,22 @@  discard block
 block discarded – undo
652 652
 		}
653 653
 		elseif ($app == self::VFS_APPNAME)
654 654
 		{
655
-			return self::delete_attached($app2,$id2,$id);
655
+			return self::delete_attached($app2, $id2, $id);
656 656
 		}
657 657
 		elseif ($app2 == self::VFS_APPNAME)
658 658
 		{
659
-			return self::delete_attached($app,$id,$id2);
659
+			return self::delete_attached($app, $id, $id2);
660 660
 		}
661 661
 		if (!is_array($id))
662 662
 		{
663 663
 			if (!$link_id && !$app2 && !$id2 && $app2 != '!'.self::VFS_APPNAME)
664 664
 			{
665
-				self::delete_attached($app,$id);	// deleting all attachments
666
-				self::delete_cache($app,$id);
665
+				self::delete_attached($app, $id); // deleting all attachments
666
+				self::delete_cache($app, $id);
667 667
 			}
668 668
 
669 669
 			// Log in history
670
-			if($link_id && (!$app || !$app2))
670
+			if ($link_id && (!$app || !$app2))
671 671
 			{
672 672
 				// Need to load it first
673 673
 				$link = self::get_link($link_id);
@@ -678,21 +678,21 @@  discard block
 block discarded – undo
678 678
 			}
679 679
 			if ($app && $app2)
680 680
 			{
681
-				historylog::static_add($app,$id,$GLOBALS['egw_info']['user']['account_id'],'~link~','',$app2.':'.$id2);
682
-				historylog::static_add($app2,$id2,$GLOBALS['egw_info']['user']['account_id'],'~link~','',$app.':'.$id);
681
+				historylog::static_add($app, $id, $GLOBALS['egw_info']['user']['account_id'], '~link~', '', $app2.':'.$id2);
682
+				historylog::static_add($app2, $id2, $GLOBALS['egw_info']['user']['account_id'], '~link~', '', $app.':'.$id);
683 683
 			}
684
-			$deleted =& solink::unlink($link_id,$app,$id,$owner,$app2 != '!'.self::VFS_APPNAME ? $app2 : '',$id2,$hold_for_purge);
684
+			$deleted = & solink::unlink($link_id, $app, $id, $owner, $app2 != '!'.self::VFS_APPNAME ? $app2 : '', $id2, $hold_for_purge);
685 685
 
686 686
 			// only notify on real links, not the one cached for writing or fileattachments
687 687
 			self::notify_unlink($deleted);
688 688
 
689 689
 			return count($deleted);
690 690
 		}
691
-		if (!$link_id) $link_id = self::temp_link_id($app2,$id2);	// create link_id of temporary link, if not given
691
+		if (!$link_id) $link_id = self::temp_link_id($app2, $id2); // create link_id of temporary link, if not given
692 692
 
693 693
 		if (isset($id[$link_id]))
694 694
 		{
695
-			$id[$link_id] = False;	// set the unlink marker
695
+			$id[$link_id] = False; // set the unlink marker
696 696
 
697 697
 			if (self::DEBUG)
698 698
 			{
@@ -709,10 +709,10 @@  discard block
 block discarded – undo
709 709
 	 * @param string $must_support capability the apps need to support, eg. 'add', default ''=list all apps
710 710
 	 * @return array with app => title pairs
711 711
 	 */
712
-	static function app_list($must_support='')
712
+	static function app_list($must_support = '')
713 713
 	{
714 714
 		$apps = array();
715
-		foreach(self::$app_register as $type => $reg)
715
+		foreach (self::$app_register as $type => $reg)
716 716
 		{
717 717
 			if ($must_support && !isset($reg[$must_support])) continue;
718 718
 
@@ -733,7 +733,7 @@  discard block
 block discarded – undo
733 733
 	 * @param string $type Search only a certain sub-type of records (optional)
734 734
 	 * @return array with $id => $title pairs of matching entries of app
735 735
 	 */
736
-	static function query($app,$pattern, &$options = array())
736
+	static function query($app, $pattern, &$options = array())
737 737
 	{
738 738
 		if ($app == '' || !is_array($reg = self::$app_register[$app]) || !isset($reg['query']))
739 739
 		{
@@ -749,14 +749,14 @@  discard block
 block discarded – undo
749 749
 
750 750
 		// See etemplate's nextmatch widget, following was copied from there
751 751
 		// allow static callbacks
752
-		if(strpos($method,'::') !== false)
752
+		if (strpos($method, '::') !== false)
753 753
 		{
754 754
 			//  workaround for php < 5.3: do NOT call it static, but allow application code to specify static callbacks
755
-			if (version_compare(PHP_VERSION,'5.3','<')) list($class,$method) = explode('::',$method);
755
+			if (version_compare(PHP_VERSION, '5.3', '<')) list($class, $method) = explode('::', $method);
756 756
 		}
757 757
 		else
758 758
 		{
759
-			list($app,$class,$method) = explode('.',$method);
759
+			list($app, $class, $method) = explode('.', $method);
760 760
 		}
761 761
 		if ($class)
762 762
 		{
@@ -773,13 +773,13 @@  discard block
 block discarded – undo
773 773
 				$obj = CreateObject($app.'.'.$class);
774 774
 			}
775 775
 		}
776
-		if(is_callable($method))        // php5.3+ call
776
+		if (is_callable($method))        // php5.3+ call
777 777
 		{
778
-			$result = call_user_func($method,$pattern,$options);
778
+			$result = call_user_func($method, $pattern, $options);
779 779
 		}
780
-		elseif(is_object($obj) && method_exists($obj,$method))
780
+		elseif (is_object($obj) && method_exists($obj, $method))
781 781
 		{
782
-			$result = $obj->$method($pattern,$options);
782
+			$result = $obj->$method($pattern, $options);
783 783
 		}
784 784
 		else
785 785
 		{
@@ -807,11 +807,11 @@  discard block
 block discarded – undo
807 807
 	 * @param array $link =null link-data for file-attachments
808 808
 	 * @return string/boolean string with title, null if $id does not exist in $app or false if no perms to view it
809 809
 	 */
810
-	static function title($app,$id,$link=null)
810
+	static function title($app, $id, $link = null)
811 811
 	{
812 812
 		if (!$id) return '';
813 813
 
814
-		$title =& self::get_cache($app,$id);
814
+		$title = & self::get_cache($app, $id);
815 815
 		if (isset($title) && !empty($title) && !is_array($id))
816 816
 		{
817 817
 			if (self::DEBUG) echo '<p>'.__METHOD__."('$app','$id')='$title' (from cache)</p>\n";
@@ -844,7 +844,7 @@  discard block
 block discarded – undo
844 844
 		}
845 845
 		$method = $reg['title'];
846 846
 
847
-		if (true) $title = ExecMethod($method,$id);
847
+		if (true) $title = ExecMethod($method, $id);
848 848
 
849 849
 		if ($id && is_null($title))	// $app,$id has been deleted ==> unlink all links to it
850 850
 		{
@@ -853,7 +853,7 @@  discard block
 block discarded – undo
853 853
 			if (!isset($unlinking[$app]) || !isset($unlinking[$app][$id]))
854 854
 			{
855 855
 				$unlinking[$app][$id] = true;
856
-				self::unlink(0,$app,$id);
856
+				self::unlink(0, $app, $id);
857 857
 				unset($unlinking[$app][$id]);
858 858
 			}
859 859
 			if (self::DEBUG) echo '<p>'.__METHOD__."('$app','$id') unlinked, as $method returned null</p>\n";
@@ -878,36 +878,36 @@  discard block
 block discarded – undo
878 878
 	 * @param string $app
879 879
 	 * @param array $ids
880 880
 	 */
881
-	static function titles($app,array $ids)
881
+	static function titles($app, array $ids)
882 882
 	{
883 883
 		if (self::DEBUG)
884 884
 		{
885
-			echo "<p>".__METHOD__."($app,".implode(',',$ids).")</p>\n";
885
+			echo "<p>".__METHOD__."($app,".implode(',', $ids).")</p>\n";
886 886
 		}
887 887
 		$titles = $ids_to_query = array();
888
-		foreach($ids as $id)
888
+		foreach ($ids as $id)
889 889
 		{
890
-			$title =& self::get_cache($app,$id);
890
+			$title = & self::get_cache($app, $id);
891 891
 			if (!isset($title))
892 892
 			{
893 893
 				if (isset(self::$app_register[$app]['titles']))
894 894
 				{
895
-					$ids_to_query[] = $id;	// titles method --> collect links to query at once
895
+					$ids_to_query[] = $id; // titles method --> collect links to query at once
896 896
 				}
897 897
 				else
898 898
 				{
899
-					$title = self::title($app,$id);	// no titles method --> fallback to query each link separate
899
+					$title = self::title($app, $id); // no titles method --> fallback to query each link separate
900 900
 				}
901 901
 			}
902 902
 			$titles[$id] = $title;
903 903
 		}
904 904
 		if ($ids_to_query)
905 905
 		{
906
-			for ($n = 0; ($ids = array_slice($ids_to_query,$n*self::MAX_TITLES_QUERY,self::MAX_TITLES_QUERY)); ++$n)
906
+			for ($n = 0; ($ids = array_slice($ids_to_query, $n * self::MAX_TITLES_QUERY, self::MAX_TITLES_QUERY)); ++$n)
907 907
 			{
908
-				foreach(ExecMethod(self::$app_register[$app]['titles'],$ids) as $id => $t)
908
+				foreach (ExecMethod(self::$app_register[$app]['titles'], $ids) as $id => $t)
909 909
 				{
910
-					$title =& self::get_cache($app,$id);
910
+					$title = & self::get_cache($app, $id);
911 911
 					$titles[$id] = $title = $t;
912 912
 				}
913 913
 			}
@@ -923,7 +923,7 @@  discard block
 block discarded – undo
923 923
 	 * @param string $to_id =''id in $to_app
924 924
 	 * @return array/boolean with name-value pairs for link to add-methode of $app or false if add not supported
925 925
 	 */
926
-	static function add($app,$to_app='',$to_id='')
926
+	static function add($app, $to_app = '', $to_id = '')
927 927
 	{
928 928
 		//echo "<p>egw_link::add('$app','$to_app','$to_id') app_register[$app] ="; _debug_array($app_register[$app]);
929 929
 		if ($app == '' || !is_array($reg = self::$app_register[$app]) || !isset($reg['add']))
@@ -948,7 +948,7 @@  discard block
 block discarded – undo
948 948
 	 * @param string &$popup=null on return popup size eg. '600x400' or null
949 949
 	 * @return array|boolean with name-value pairs for link to edit-methode of $app or false if edit not supported
950 950
 	 */
951
-	static function edit($app,$id,&$popup=null)
951
+	static function edit($app, $id, &$popup = null)
952 952
 	{
953 953
 		//echo "<p>egw_link::add('$app','$to_app','$to_id') app_register[$app] ="; _debug_array($app_register[$app]);
954 954
 		if (empty($app) || empty($id) || !is_array($reg = self::$app_register[$app]) || !isset($reg['edit']))
@@ -956,7 +956,7 @@  discard block
 block discarded – undo
956 956
 			if ($reg && isset($reg['view']))
957 957
 			{
958 958
 				$popup = $reg['view_popup'];
959
-				return self::view($app,$id);	// fallback to view
959
+				return self::view($app, $id); // fallback to view
960 960
 			}
961 961
 			return false;
962 962
 		}
@@ -976,12 +976,12 @@  discard block
 block discarded – undo
976 976
 	 * @param array $link =null link-data for file-attachments
977 977
 	 * @return array with name-value pairs for link to view-methode of $app to view $id
978 978
 	 */
979
-	static function view($app,$id,$link=null)
979
+	static function view($app, $id, $link = null)
980 980
 	{
981 981
 		if ($app == self::VFS_APPNAME && !empty($id) && is_array($link))
982 982
 		{
983 983
 			//return egw_vfs::download_url(self::vfs_path($link['app2'],$link['id2'],$link['id'],true));
984
-			return self::mime_open(self::vfs_path($link['app2'],$link['id2'],$link['id'],true), $link['type']);
984
+			return self::mime_open(self::vfs_path($link['app2'], $link['id2'], $link['id'], true), $link['type']);
985 985
 		}
986 986
 		if ($app == '' || !is_array($reg = self::$app_register[$app]) || !isset($reg['view']) || !isset($reg['view_id']))
987 987
 		{
@@ -989,11 +989,11 @@  discard block
 block discarded – undo
989 989
 		}
990 990
 		$view = $reg['view'];
991 991
 
992
-		$names = explode(':',$reg['view_id']);
992
+		$names = explode(':', $reg['view_id']);
993 993
 		if (count($names) > 1)
994 994
 		{
995
-			$id = explode(':',$id);
996
-			while (list($n,$name) = each($names))
995
+			$id = explode(':', $id);
996
+			while (list($n, $name) = each($names))
997 997
 			{
998 998
 				$view[$name] = $id[$n];
999 999
 			}
@@ -1017,13 +1017,13 @@  discard block
 block discarded – undo
1017 1017
 	 */
1018 1018
 	static function get_mime_info($type)
1019 1019
 	{
1020
-		foreach(self::$app_register as $app => $registry)
1020
+		foreach (self::$app_register as $app => $registry)
1021 1021
 		{
1022 1022
 			if (isset($registry['mime']) &&
1023 1023
 				(isset($GLOBALS['egw_info']['user']['apps'][$app]) ||
1024 1024
 				isset($registry['app']) && isset($GLOBALS['egw_info']['user']['apps'][$registry['app']])))
1025 1025
 			{
1026
-				foreach($registry['mime'] as $mime => $data)
1026
+				foreach ($registry['mime'] as $mime => $data)
1027 1027
 				{
1028 1028
 					if ($mime == $type) return $data;
1029 1029
 					if ($mime[0] == '/' && preg_match($mime.'i', $type))
@@ -1044,7 +1044,7 @@  discard block
 block discarded – undo
1044 1044
 	 * @param string &$popup=null on return popup size or null
1045 1045
 	 * @return string|array string with EGw relative link, array with get-parameters for '/index.php' or null (directory and not filemanager access)
1046 1046
 	 */
1047
-	static function mime_open($path, $type=null, &$popup=null)
1047
+	static function mime_open($path, $type = null, &$popup = null)
1048 1048
 	{
1049 1049
 		if (is_null($type)) $type = egw_vfs::mime_content_type($path);
1050 1050
 
@@ -1060,7 +1060,7 @@  discard block
 block discarded – undo
1060 1060
 				$data[$data['mime_id']] = $path;
1061 1061
 				unset($data['mime_id']);
1062 1062
 			}
1063
-			elseif(isset($data['mime_popup']))
1063
+			elseif (isset($data['mime_popup']))
1064 1064
 			{
1065 1065
 				$popup = $data['mime_popup'];
1066 1066
 			}
@@ -1085,9 +1085,9 @@  discard block
 block discarded – undo
1085 1085
 	 * @param array $link =null link-data for file-attachments
1086 1086
 	 * @return boolean|string false if no popup is used or $app is not registered, otherwise string with the prefered popup size (eg. '640x400)
1087 1087
 	 */
1088
-	static function is_popup($app, $action='view', $link=null)
1088
+	static function is_popup($app, $action = 'view', $link = null)
1089 1089
 	{
1090
-		$popup = self::get_registry($app,$action.'_popup');
1090
+		$popup = self::get_registry($app, $action.'_popup');
1091 1091
 
1092 1092
 		// for files/attachments check mime-registry
1093 1093
 		if ($app == self::VFS_APPNAME && is_array($link) && !empty($link['type']))
@@ -1110,7 +1110,7 @@  discard block
 block discarded – undo
1110 1110
 	 * @param string $name name / key in the registry, eg. 'view'
1111 1111
 	 * @return boolean|string false if $app is not registered, otherwise string with the value for $name
1112 1112
 	 */
1113
-	static function get_registry($app,$name)
1113
+	static function get_registry($app, $name)
1114 1114
 	{
1115 1115
 		$reg = self::$app_register[$app];
1116 1116
 
@@ -1118,7 +1118,7 @@  discard block
 block discarded – undo
1118 1118
 
1119 1119
 		if (!isset($reg[$name]))	// some defaults
1120 1120
 		{
1121
-			switch($name)
1121
+			switch ($name)
1122 1122
 			{
1123 1123
 				case 'name':
1124 1124
 					$reg[$name] = $app;
@@ -1151,7 +1151,7 @@  discard block
 block discarded – undo
1151 1151
 	 * @param boolean $just_the_path =false return url or just the vfs path
1152 1152
 	 * @return string/array path or array with path and relatives, depending on $relatives
1153 1153
 	 */
1154
-	static function vfs_path($app,$id='',$file='',$just_the_path=false)
1154
+	static function vfs_path($app, $id = '', $file = '', $just_the_path = false)
1155 1155
 	{
1156 1156
 		$path = self::VFS_BASEURL;
1157 1157
 
@@ -1171,7 +1171,7 @@  discard block
 block discarded – undo
1171 1171
 		}
1172 1172
 		if ($just_the_path)
1173 1173
 		{
1174
-			$path = parse_url($path,PHP_URL_PATH);
1174
+			$path = parse_url($path, PHP_URL_PATH);
1175 1175
 		}
1176 1176
 		else
1177 1177
 		{
@@ -1195,16 +1195,16 @@  discard block
 block discarded – undo
1195 1195
 	 * @param string $comment ='' comment to add to the link
1196 1196
 	 * @return int negative id of egw_sqlfs table as negative link-id's are for vfs attachments
1197 1197
 	 */
1198
-	static function attach_file($app,$id,$file,$comment='')
1198
+	static function attach_file($app, $id, $file, $comment = '')
1199 1199
 	{
1200
-		$entry_dir = self::vfs_path($app,$id);
1200
+		$entry_dir = self::vfs_path($app, $id);
1201 1201
 		if (self::DEBUG)
1202 1202
 		{
1203 1203
 			echo "<p>attach_file: app='$app', id='$id', tmp_name='$file[tmp_name]', name='$file[name]', size='$file[size]', type='$file[type]', path='$file[path]', ip='$file[ip]', comment='$comment', entry_dir='$entry_dir'</p>\n";
1204 1204
 		}
1205
-		if (file_exists($entry_dir) || ($Ok = mkdir($entry_dir,0,true)))
1205
+		if (file_exists($entry_dir) || ($Ok = mkdir($entry_dir, 0, true)))
1206 1206
 		{
1207
-			$Ok = egw_vfs::copy_uploaded($file, $p=self::vfs_path($app,$id,'',true), $comment, false);	// no is_uploaded_file() check!
1207
+			$Ok = egw_vfs::copy_uploaded($file, $p = self::vfs_path($app, $id, '', true), $comment, false); // no is_uploaded_file() check!
1208 1208
 			if (!$Ok) error_log(__METHOD__."('$app', '$id', ".array2string($file).", '$comment') called egw_vfs::copy_uploaded('$file[tmp_name]', '$p', '$comment', false)=".array2string($Ok));
1209 1209
 		}
1210 1210
 		else
@@ -1222,24 +1222,24 @@  discard block
 block discarded – undo
1222 1222
 	 * @param string $file VFS path to link to
1223 1223
 	 * @param string $comment ='' comment to add to the link
1224 1224
 	 */
1225
-	static function link_file($app,$id,$file)//,$comment='')
1225
+	static function link_file($app, $id, $file)//,$comment='')
1226 1226
 	{
1227 1227
 		// Don't try to link into app dir if there is no id
1228
-		if(!$id) return;
1228
+		if (!$id) return;
1229 1229
 
1230
-		$app_path = self::vfs_path($app,$id);
1230
+		$app_path = self::vfs_path($app, $id);
1231 1231
 		$ok = true;
1232
-		if (egw_vfs::file_exists($app_path) || ($ok = egw_vfs::mkdir($app_path,0,true)))
1232
+		if (egw_vfs::file_exists($app_path) || ($ok = egw_vfs::mkdir($app_path, 0, true)))
1233 1233
 		{
1234 1234
 			if (!egw_vfs::stat($file))
1235 1235
 			{
1236
-				error_log(__METHOD__. ' (Link target ' . egw_vfs::decodePath($file) . ' not found!');
1236
+				error_log(__METHOD__.' (Link target '.egw_vfs::decodePath($file).' not found!');
1237 1237
 				return false;
1238 1238
 			}
1239 1239
 		}
1240 1240
 
1241
-		$link = egw_vfs::concat($app_path,egw_vfs::basename($file));
1242
-		return egw_vfs::symlink($file,$link);
1241
+		$link = egw_vfs::concat($app_path, egw_vfs::basename($file));
1242
+		return egw_vfs::symlink($file, $link);
1243 1243
 	}
1244 1244
 	/**
1245 1245
 	 * deletes a single or all attached files of an entry (for all there's no acl check, as the entry probably not exists any more!)
@@ -1249,7 +1249,7 @@  discard block
 block discarded – undo
1249 1249
 	 * @param string $fname ='' filename
1250 1250
 	 * @return boolean|array false on error ($app or $id not found), array with path as key and boolean result of delete
1251 1251
 	 */
1252
-	static function delete_attached($app,$id='',$fname='')
1252
+	static function delete_attached($app, $id = '', $fname = '')
1253 1253
 	{
1254 1254
 		if ((int)$app > 0)	// is file_id
1255 1255
 		{
@@ -1259,9 +1259,9 @@  discard block
 block discarded – undo
1259 1259
 		{
1260 1260
 			if (empty($app) || empty($id))
1261 1261
 			{
1262
-				return False;	// dont delete more than all attachments of an entry
1262
+				return False; // dont delete more than all attachments of an entry
1263 1263
 			}
1264
-			$url = self::vfs_path($app,$id,$fname);
1264
+			$url = self::vfs_path($app, $id, $fname);
1265 1265
 
1266 1266
 			if (!$fname || !$id)	// we delete the whole entry (or all entries), which probably not exist anymore
1267 1267
 			{
@@ -1274,15 +1274,15 @@  discard block
 block discarded – undo
1274 1274
 			echo '<p>'.__METHOD__."('$app','$id','$fname') url=$url</p>\n";
1275 1275
 		}
1276 1276
 		// Log in history - Need to load it first
1277
-		if((int)$app > 0)
1277
+		if ((int)$app > 0)
1278 1278
 		{
1279 1279
 			$link = self::get_link(-$app);
1280
-			if($link['app2'] && $link['id2'])
1280
+			if ($link['app2'] && $link['id2'])
1281 1281
 			{
1282
-				historylog::static_add($link['app2'],$link['id2'],$GLOBALS['egw_info']['user']['account_id'],'~file~','', basename($url));
1282
+				historylog::static_add($link['app2'], $link['id2'], $GLOBALS['egw_info']['user']['account_id'], '~file~', '', basename($url));
1283 1283
 			}
1284 1284
 		}
1285
-		if (($Ok = !file_exists($url) || egw_vfs::remove($url,true)) && ((int)$app > 0 || $fname))
1285
+		if (($Ok = !file_exists($url) || egw_vfs::remove($url, true)) && ((int)$app > 0 || $fname))
1286 1286
 		{
1287 1287
 			// try removing the dir, in case it's empty
1288 1288
 			@egw_vfs::rmdir(egw_vfs::dirname($url));
@@ -1302,14 +1302,14 @@  discard block
 block discarded – undo
1302 1302
 	 * @param string $filename filename
1303 1303
 	 * @return array 'kind' of link-array
1304 1304
 	 */
1305
-	static function info_attached($app,$id,$filename)
1305
+	static function info_attached($app, $id, $filename)
1306 1306
 	{
1307
-		$path = self::vfs_path($app,$id,$filename,true);
1308
-		if (!($stat = egw_vfs::stat($path,STREAM_URL_STAT_QUIET)))
1307
+		$path = self::vfs_path($app, $id, $filename, true);
1308
+		if (!($stat = egw_vfs::stat($path, STREAM_URL_STAT_QUIET)))
1309 1309
 		{
1310 1310
 			return false;
1311 1311
 		}
1312
-		return self::fileinfo2link($stat,$path);
1312
+		return self::fileinfo2link($stat, $path);
1313 1313
 	}
1314 1314
 
1315 1315
 	/**
@@ -1318,24 +1318,24 @@  discard block
 block discarded – undo
1318 1318
 	 * @param array|int $fileinfo a row from the vfs-db-table (eg. returned by the vfs ls static function) or a file_id of that table
1319 1319
 	 * @return array a 'kind' of link-array
1320 1320
 	 */
1321
-	static function fileinfo2link($fileinfo,$url=null)
1321
+	static function fileinfo2link($fileinfo, $url = null)
1322 1322
 	{
1323 1323
 		if (!is_array($fileinfo))
1324 1324
 		{
1325 1325
 			$url = sqlfs_stream_wrapper::id2path($fileinfo);
1326
-			if (!($fileinfo = egw_vfs::url_stat($url,STREAM_URL_STAT_QUIET)))
1326
+			if (!($fileinfo = egw_vfs::url_stat($url, STREAM_URL_STAT_QUIET)))
1327 1327
 			{
1328 1328
 				return false;
1329 1329
 			}
1330 1330
 		}
1331
-		list(,,$app,$id) = explode('/',$url[0] == '/' ? $url : parse_url($url,PHP_URL_PATH));	// /apps/$app/$id
1331
+		list(,, $app, $id) = explode('/', $url[0] == '/' ? $url : parse_url($url, PHP_URL_PATH)); // /apps/$app/$id
1332 1332
 
1333 1333
 		return array(
1334 1334
 			'app'       => self::VFS_APPNAME,
1335 1335
 			'id'        => $fileinfo['name'],
1336 1336
 			'app2'      => $app,
1337 1337
 			'id2'       => $id,
1338
-			'remark'    => '',					// only list_attached currently sets the remark
1338
+			'remark'    => '', // only list_attached currently sets the remark
1339 1339
 			'owner'     => $fileinfo['uid'],
1340 1340
 			'link_id'   => -$fileinfo['ino'],
1341 1341
 			'lastmod'   => $fileinfo['mtime'],
@@ -1351,26 +1351,26 @@  discard block
 block discarded – undo
1351 1351
 	 * @param string $id id in app
1352 1352
 	 * @return array with link_id => 'kind' of link-array pairs
1353 1353
 	 */
1354
-	static function list_attached($app,$id)
1354
+	static function list_attached($app, $id)
1355 1355
 	{
1356
-		$path = self::vfs_path($app,$id);
1356
+		$path = self::vfs_path($app, $id);
1357 1357
 		//error_log(__METHOD__."($app,$id) url=$url");
1358 1358
 
1359
-		if (!($extra = self::get_registry($app,'find_extra'))) $extra = array();
1359
+		if (!($extra = self::get_registry($app, 'find_extra'))) $extra = array();
1360 1360
 
1361 1361
 		// always use regular links stream wrapper here: extended one is unnecessary (slow) for just listing attachments
1362
-		if (substr($path,0,13) == 'stylite.links') $path = substr($path,8);
1362
+		if (substr($path, 0, 13) == 'stylite.links') $path = substr($path, 8);
1363 1363
 
1364 1364
 		$attached = array();
1365
-		if (($url2stats = egw_vfs::find($path,array('need_mime'=>true,'type'=>'F','url'=>true)+$extra,true)))
1365
+		if (($url2stats = egw_vfs::find($path, array('need_mime'=>true, 'type'=>'F', 'url'=>true) + $extra, true)))
1366 1366
 		{
1367
-			$props = egw_vfs::propfind(array_keys($url2stats));	// get the comments
1368
-			foreach($url2stats as $url => &$fileinfo)
1367
+			$props = egw_vfs::propfind(array_keys($url2stats)); // get the comments
1368
+			foreach ($url2stats as $url => &$fileinfo)
1369 1369
 			{
1370
-				$link = self::fileinfo2link($fileinfo,$url);
1370
+				$link = self::fileinfo2link($fileinfo, $url);
1371 1371
 				if ($props && isset($props[$url]))
1372 1372
 				{
1373
-					foreach($props[$url] as $prop)
1373
+					foreach ($props[$url] as $prop)
1374 1374
 					{
1375 1375
 						if ($prop['ns'] == egw_vfs::DEFAULT_PROP_NAMESPACE && $prop['name'] == 'comment')
1376 1376
 						{
@@ -1392,7 +1392,7 @@  discard block
 block discarded – undo
1392 1392
 	 */
1393 1393
 	static private function decode_htmlspecialchars($str)
1394 1394
 	{
1395
-		return str_replace(array('&amp;','&quot;','&lt;','&gt;'),array('&','"','<','>'),$str);
1395
+		return str_replace(array('&amp;', '&quot;', '&lt;', '&gt;'), array('&', '"', '<', '>'), $str);
1396 1396
 	}
1397 1397
 
1398 1398
 	/**
@@ -1410,18 +1410,18 @@  discard block
 block discarded – undo
1410 1410
 	 * @param string $id id in $app of the updated entry
1411 1411
 	 * @param array $data =null updated data of changed entry, as the read-method of the BO-layer would supply it
1412 1412
 	 */
1413
-	static function notify_update($app,$id,$data=null)
1413
+	static function notify_update($app, $id, $data = null)
1414 1414
 	{
1415
-		self::delete_cache($app,$id);
1415
+		self::delete_cache($app, $id);
1416 1416
 		//error_log(__METHOD__."('$app', $id, $data)");
1417
-		foreach(self::get_links($app,$id,'!'.self::VFS_APPNAME) as $link_id => $link)
1417
+		foreach (self::get_links($app, $id, '!'.self::VFS_APPNAME) as $link_id => $link)
1418 1418
 		{
1419
-			self::notify('update',$link['app'],$link['id'],$app,$id,$link_id,$data);
1419
+			self::notify('update', $link['app'], $link['id'], $app, $id, $link_id, $data);
1420 1420
 		}
1421
-		if($data[egw_link::OLD_LINK_TITLE] && egw_json_response::isJSONResponse())
1421
+		if ($data[egw_link::OLD_LINK_TITLE] && egw_json_response::isJSONResponse())
1422 1422
 		{
1423 1423
 			// Update client side with new title
1424
-			egw_json_response::get()->apply('egw.link_title_callback',array(array($app => array($id => self::title($app, $id)))));
1424
+			egw_json_response::get()->apply('egw.link_title_callback', array(array($app => array($id => self::title($app, $id)))));
1425 1425
 		}
1426 1426
 	}
1427 1427
 
@@ -1445,7 +1445,7 @@  discard block
 block discarded – undo
1445 1445
 	 * @param string $target_id id in $target_app
1446 1446
 	 * @param array $data =null data of entry in app2 (optional)
1447 1447
 	 */
1448
-	static private function notify($type,$notify_app,$notify_id,$target_app,$target_id,$link_id,$data=null)
1448
+	static private function notify($type, $notify_app, $notify_id, $target_app, $target_id, $link_id, $data = null)
1449 1449
 	{
1450 1450
 		//error_log(__METHOD__."('$type', '$notify_app', $notify_id, '$target_app', $target_id, $link_id, $data)");
1451 1451
 		if ($link_id && isset(self::$app_register[$notify_app]) && isset(self::$app_register[$notify_app]['notify']))
@@ -1472,7 +1472,7 @@  discard block
 block discarded – undo
1472 1472
 	static public function run_notifies()
1473 1473
 	{
1474 1474
 		//error_log(__METHOD__."() count(self::\$notifies)=".count(self::$notifies));
1475
-		while(self::$notifies)
1475
+		while (self::$notifies)
1476 1476
 		{
1477 1477
 			$args = array_shift(self::$notifies);
1478 1478
 			$method = $args['method'];
@@ -1490,11 +1490,11 @@  discard block
 block discarded – undo
1490 1490
 	 */
1491 1491
 	static private function notify_unlink(&$links)
1492 1492
 	{
1493
-		foreach($links as $link)
1493
+		foreach ($links as $link)
1494 1494
 		{
1495 1495
 			// we notify both sides of the link, as the unlink command NOT clearly knows which side initiated the unlink
1496
-			self::notify('unlink',$link['link_app1'],$link['link_id1'],$link['link_app2'],$link['link_id2'],$link['link_id']);
1497
-			self::notify('unlink',$link['link_app2'],$link['link_id2'],$link['link_app1'],$link['link_id1'],$link['link_id']);
1496
+			self::notify('unlink', $link['link_app1'], $link['link_id1'], $link['link_app2'], $link['link_id2'], $link['link_id']);
1497
+			self::notify('unlink', $link['link_app2'], $link['link_id2'], $link['link_app1'], $link['link_id1'], $link['link_id']);
1498 1498
 		}
1499 1499
 	}
1500 1500
 
@@ -1506,9 +1506,9 @@  discard block
 block discarded – undo
1506 1506
 	 * @param string $type ='title' 'title' or 'file_access'
1507 1507
 	 * @return int|string can be null, if cache not yet set
1508 1508
 	 */
1509
-	private static function &get_cache($app,$id,$type = 'title')
1509
+	private static function &get_cache($app, $id, $type = 'title')
1510 1510
 	{
1511
-		switch($type)
1511
+		switch ($type)
1512 1512
 		{
1513 1513
 			case 'title':
1514 1514
 				return self::$title_cache[$app.':'.$id];
@@ -1531,7 +1531,7 @@  discard block
 block discarded – undo
1531 1531
 	 * @param string $title title string or null
1532 1532
 	 * @param int $file_access =null EGW_ACL_READ, EGW_ACL_EDIT or both or'ed together
1533 1533
 	 */
1534
-	public static function set_cache($app,$id,$title,$file_access=null)
1534
+	public static function set_cache($app, $id, $title, $file_access = null)
1535 1535
 	{
1536 1536
 		//error_log(__METHOD__."($app,$id,$title,$file_access)");
1537 1537
 		if (!is_null($title))
@@ -1550,7 +1550,7 @@  discard block
 block discarded – undo
1550 1550
 	 * @param string $app app-name or null to delete the whole cache
1551 1551
 	 * @param int|string $id id or null to delete only file_access cache of given app (keeps title cache, if app implements file_access!)
1552 1552
 	 */
1553
-	private static function delete_cache($app,$id)
1553
+	private static function delete_cache($app, $id)
1554 1554
 	{
1555 1555
 		unset(self::$title_cache[$app.':'.$id]);
1556 1556
 		unset(self::$file_access_cache[$app.':'.$id]);
@@ -1565,7 +1565,7 @@  discard block
 block discarded – undo
1565 1565
 	 * @param boolean $ignore_mime =false true: return id, even if nothing registered for given mime-type
1566 1566
 	 * @return string|null md5 hash of stored data of server-side supported mime-type or null otherwise
1567 1567
 	 */
1568
-	public static function set_data($mime_type, $method, array $params, $ignore_mime=false)
1568
+	public static function set_data($mime_type, $method, array $params, $ignore_mime = false)
1569 1569
 	{
1570 1570
 		if (!$ignore_mime && (!($info = self::get_mime_info($mime_type)) || empty($info['mime_data'])))
1571 1571
 		{
@@ -1586,7 +1586,7 @@  discard block
 block discarded – undo
1586 1586
 	 * @return mixed null if id is not found or invalid
1587 1587
 	 * @throws egw_exception_wrong_parameter
1588 1588
 	 */
1589
-	public static function get_data($id, $return_resource=false)
1589
+	public static function get_data($id, $return_resource = false)
1590 1590
 	{
1591 1591
 		$data = egw_cache::getSession(__CLASS__, $id);
1592 1592
 
@@ -1610,7 +1610,7 @@  discard block
 block discarded – undo
1610 1610
 			{
1611 1611
 				$fp = $ret;
1612 1612
 				$ret = '';
1613
-				while(!feof($fp))
1613
+				while (!feof($fp))
1614 1614
 				{
1615 1615
 					$ret .= fread($fp, 8192);
1616 1616
 				}
@@ -1635,42 +1635,42 @@  discard block
 block discarded – undo
1635 1635
 	 * @param int $user =null default null = current user
1636 1636
 	 * @return boolean true if access granted, false otherwise
1637 1637
 	 */
1638
-	static function file_access($app,$id,$required=EGW_ACL_READ,$rel_path=null,$user=null)
1638
+	static function file_access($app, $id, $required = EGW_ACL_READ, $rel_path = null, $user = null)
1639 1639
 	{
1640 1640
 		// are we called for an other user
1641 1641
 		if ($user && $user != $GLOBALS['egw_info']['user']['account_id'])
1642 1642
 		{
1643 1643
 			// check if app supports file_access WITH 4th $user parameter --> return false if not
1644
-			if (!self::get_registry($app,'file_access_user') || !($method = self::get_registry($app,'file_access')))
1644
+			if (!self::get_registry($app, 'file_access_user') || !($method = self::get_registry($app, 'file_access')))
1645 1645
 			{
1646 1646
 				$ret = false;
1647 1647
 				$err = "(no file_access_user)";
1648 1648
 			}
1649 1649
 			else
1650 1650
 			{
1651
-				$ret = ExecMethod2($method,$id,$required,$rel_path,$user);
1651
+				$ret = ExecMethod2($method, $id, $required, $rel_path, $user);
1652 1652
 				$err = "(from $method)";
1653 1653
 			}
1654 1654
 			//error_log(__METHOD__."('$app',$id,$required,'$rel_path',$user) returning $err ".array2string($ret));
1655 1655
 			return $ret;
1656 1656
 		}
1657 1657
 
1658
-		$cache =& self::get_cache($app,$id,'file_access');
1658
+		$cache = & self::get_cache($app, $id, 'file_access');
1659 1659
 
1660
-		if (!isset($cache) || $required == EGW_ACL_EDIT && !($cache & $required))
1660
+		if (!isset($cache) || $required == EGW_ACL_EDIT && !($cache&$required))
1661 1661
 		{
1662
-			if(($method = self::get_registry($app,'file_access')))
1662
+			if (($method = self::get_registry($app, 'file_access')))
1663 1663
 			{
1664
-				$cache |= ExecMethod2($method,$id,$required,$rel_path) ? $required|EGW_ACL_READ : 0;
1664
+				$cache |= ExecMethod2($method, $id, $required, $rel_path) ? $required|EGW_ACL_READ : 0;
1665 1665
 			}
1666 1666
 			else
1667 1667
 			{
1668
-				$cache |= self::title($app,$id) ? EGW_ACL_READ|EGW_ACL_EDIT : 0;
1668
+				$cache |= self::title($app, $id) ? EGW_ACL_READ|EGW_ACL_EDIT : 0;
1669 1669
 			}
1670 1670
 			//error_log(__METHOD__."($app,$id,$required,$rel_path) got $cache --> ".($cache & $required ? 'true' : 'false'));
1671 1671
 		}
1672 1672
 		//else error_log(__METHOD__."($app,$id,$required,$rel_path) using cached value $cache --> ".($cache & $required ? 'true' : 'false'));
1673
-		return !!($cache & $required);
1673
+		return !!($cache&$required);
1674 1674
 	}
1675 1675
 }
1676 1676
 egw_link::init_static();
Please login to merge, or discard this patch.
Braces   +158 added lines, -39 removed lines patch added patch discarded remove patch
@@ -294,10 +294,13 @@  discard block
 block discarded – undo
294 294
 	 */
295 295
 	static function save_session_cache()
296 296
 	{
297
-		if (isset($GLOBALS['egw']->session))	// eg. cron-jobs use it too, without any session
297
+		if (isset($GLOBALS['egw']->session))
298
+		{
299
+			// eg. cron-jobs use it too, without any session
298 300
 		{
299 301
 			//error_log(__METHOD__.'() items in title-cache: '.count(self::$title_cache).' file-access-cache: '.count(self::$file_access_cache));
300 302
 			$GLOBALS['egw']->session->appsession('link_title_cache','phpgwapi',self::$title_cache);
303
+		}
301 304
 			$GLOBALS['egw']->session->appsession('link_file_access_cache','phpgwapi',self::$file_access_cache);
302 305
 		}
303 306
 	}
@@ -341,14 +344,20 @@  discard block
 block discarded – undo
341 344
 			$link_id = True;
342 345
 			while ($link_id && list(,$link) = each($app2))
343 346
 			{
344
-				if (!is_array($link))	// check for unlink-marker
347
+				if (!is_array($link))
348
+				{
349
+					// check for unlink-marker
345 350
 				{
346 351
 					//echo "<b>link='$link' is no array</b><br>\n";
347 352
 					continue;
348 353
 				}
349
-				if (is_array($id1) || !$id1)		// create link only in $id1 array
354
+				}
355
+				if (is_array($id1) || !$id1)
356
+				{
357
+					// create link only in $id1 array
350 358
 				{
351 359
 					self::link($app1, $id1, $link['app'], $link['id'], $link['remark'],$link['owner'],$link['lastmod']);
360
+				}
352 361
 					continue;
353 362
 				}
354 363
 				switch ($link['app'])
@@ -372,18 +381,27 @@  discard block
 block discarded – undo
372 381
 						$link_id = solink::link($app1,$id1,$link['app'],$link['id'],
373 382
 							$link['remark'],$link['owner'],$link['lastmod']);
374 383
 						// notify both sides
375
-						if (!($no_notify&2)) self::notify('link',$link['app'],$link['id'],$app1,$id1,$link_id);
376
-						if (!($no_notify&1)) self::notify('link',$app1,$id1,$link['app'],$link['id'],$link_id);
384
+						if (!($no_notify&2))
385
+						{
386
+							self::notify('link',$link['app'],$link['id'],$app1,$id1,$link_id);
387
+						}
388
+						if (!($no_notify&1))
389
+						{
390
+							self::notify('link',$app1,$id1,$link['app'],$link['id'],$link_id);
391
+						}
377 392
 						break;
378 393
 				}
379 394
 			}
380 395
 			return $link_id;
381 396
 		}
382
-		if (is_array($id1) || !$id1)		// create link only in $id1 array
397
+		if (is_array($id1) || !$id1)
398
+		{
399
+			// create link only in $id1 array
383 400
 		{
384 401
 			if (!is_array($id1))
385 402
 			{
386 403
 				$id1 = array( );
404
+		}
387 405
 			}
388 406
 			$link_id = self::temp_link_id($app2,$id2);
389 407
 
@@ -419,8 +437,14 @@  discard block
 block discarded – undo
419 437
 		}
420 438
 		$link_id = solink::link($app1,$id1,$app2,$id2,$remark,$owner);
421 439
 
422
-		if (!($no_notify&2)) self::notify('link',$app2,$id2,$app1,$id1,$link_id);
423
-		if (!($no_notify&1)) self::notify('link',$app1,$id1,$app2,$id2,$link_id);
440
+		if (!($no_notify&2))
441
+		{
442
+			self::notify('link',$app2,$id2,$app1,$id1,$link_id);
443
+		}
444
+		if (!($no_notify&1))
445
+		{
446
+			self::notify('link',$app1,$id1,$app2,$id2,$link_id);
447
+		}
424 448
 
425 449
 		return $link_id;
426 450
 	}
@@ -452,7 +476,10 @@  discard block
 block discarded – undo
452 476
 	 */
453 477
 	static function get_links($app, $id, $only_app='', $order='link_lastmod DESC',$cache_titles=false, $deleted=false, $limit=null)
454 478
 	{
455
-		if (self::DEBUG) echo "<p>egw_link::get_links(app='$app',id='$id',only_app='$only_app',order='$order',deleted='$deleted')</p>\n";
479
+		if (self::DEBUG)
480
+		{
481
+			echo "<p>egw_link::get_links(app='$app',id='$id',only_app='$only_app',order='$order',deleted='$deleted')</p>\n";
482
+		}
456 483
 
457 484
 		if (is_array($id) || !$id)
458 485
 		{
@@ -523,7 +550,10 @@  discard block
 block discarded – undo
523 550
 	 */
524 551
 	static function get_links_multiple($app,array $ids,$cache_titles=true,$only_app='',$order='link_lastmod DESC', $deleted=false )
525 552
 	{
526
-		if (self::DEBUG) echo "<p>".__METHOD__."('$app',".print_r($ids,true).",$cache_titles,'$only_app','$order')</p>\n";
553
+		if (self::DEBUG)
554
+		{
555
+			echo "<p>".__METHOD__."('$app',".print_r($ids,true).",$cache_titles,'$only_app','$order')</p>\n";
556
+		}
527 557
 
528 558
 		if (!$ids)
529 559
 		{
@@ -555,7 +585,10 @@  discard block
 block discarded – undo
555 585
 			{
556 586
 				foreach($targets as $link)
557 587
 				{
558
-					if (is_array($link)) $app_ids[$link['app']][] = $link['id'];
588
+					if (is_array($link))
589
+					{
590
+						$app_ids[$link['app']][] = $link['id'];
591
+					}
559 592
 				}
560 593
 			}
561 594
 			foreach($app_ids as $app => $a_ids)
@@ -585,20 +618,30 @@  discard block
 block discarded – undo
585 618
 		}
586 619
 		if (is_array($id))
587 620
 		{
588
-			if (strpos($app_link_id,':') === false) $app_link_id = self::temp_link_id($app2,$id2);	// create link_id of temporary link, if not given
621
+			if (strpos($app_link_id,':') === false)
622
+			{
623
+				$app_link_id = self::temp_link_id($app2,$id2);
624
+			}
625
+			// create link_id of temporary link, if not given
589 626
 
590
-			if (isset($id[$app_link_id]) && is_array($id[$app_link_id]))	// check for unlinked-marker
627
+			if (isset($id[$app_link_id]) && is_array($id[$app_link_id]))
628
+			{
629
+				// check for unlinked-marker
591 630
 			{
592 631
 				return $id[$app_link_id];
593 632
 			}
633
+			}
594 634
 			return False;
595 635
 		}
596 636
 		if ((int)$app_link_id < 0 || $app_link_id == self::VFS_APPNAME || $app2 == self::VFS_APPNAME)
597 637
 		{
598
-			if ((int)$app_link_id < 0)	// vfs link_id ?
638
+			if ((int)$app_link_id < 0)
639
+			{
640
+				// vfs link_id ?
599 641
 			{
600 642
 				return self::fileinfo2link(-$app_link_id);
601 643
 			}
644
+			}
602 645
 			if ($app_link_id == self::VFS_APPNAME)
603 646
 			{
604 647
 				return self::info_attached($app2,$id2,$id);
@@ -646,10 +689,13 @@  discard block
 block discarded – undo
646 689
 		{
647 690
 			echo "<p>egw_link::unlink('$link_id','$app',".array2string($id).",'$owner','$app2','$id2', $hold_for_purge)</p>\n";
648 691
 		}
649
-		if ($link_id < 0)	// vfs-link?
692
+		if ($link_id < 0)
693
+		{
694
+			// vfs-link?
650 695
 		{
651 696
 			return self::delete_attached(-$link_id);
652 697
 		}
698
+		}
653 699
 		elseif ($app == self::VFS_APPNAME)
654 700
 		{
655 701
 			return self::delete_attached($app2,$id2,$id);
@@ -688,7 +734,11 @@  discard block
 block discarded – undo
688 734
 
689 735
 			return count($deleted);
690 736
 		}
691
-		if (!$link_id) $link_id = self::temp_link_id($app2,$id2);	// create link_id of temporary link, if not given
737
+		if (!$link_id)
738
+		{
739
+			$link_id = self::temp_link_id($app2,$id2);
740
+		}
741
+		// create link_id of temporary link, if not given
692 742
 
693 743
 		if (isset($id[$link_id]))
694 744
 		{
@@ -714,7 +764,10 @@  discard block
 block discarded – undo
714 764
 		$apps = array();
715 765
 		foreach(self::$app_register as $type => $reg)
716 766
 		{
717
-			if ($must_support && !isset($reg[$must_support])) continue;
767
+			if ($must_support && !isset($reg[$must_support]))
768
+			{
769
+				continue;
770
+			}
718 771
 
719 772
 			list($app) = explode('-', $type);
720 773
 			if ($GLOBALS['egw_info']['user']['apps'][$app])
@@ -752,7 +805,10 @@  discard block
 block discarded – undo
752 805
 		if(strpos($method,'::') !== false)
753 806
 		{
754 807
 			//  workaround for php < 5.3: do NOT call it static, but allow application code to specify static callbacks
755
-			if (version_compare(PHP_VERSION,'5.3','<')) list($class,$method) = explode('::',$method);
808
+			if (version_compare(PHP_VERSION,'5.3','<'))
809
+			{
810
+				list($class,$method) = explode('::',$method);
811
+			}
756 812
 		}
757 813
 		else
758 814
 		{
@@ -764,19 +820,25 @@  discard block
 block discarded – undo
764 820
 			{
765 821
 				$GLOBALS[$class] = new $class();
766 822
 			}
767
-			if (is_object($GLOBALS[$class]))        // use existing instance (put there by a previous CreateObject)
823
+			if (is_object($GLOBALS[$class]))
824
+			{
825
+				// use existing instance (put there by a previous CreateObject)
768 826
 			{
769 827
 				$obj = $GLOBALS[$class];
770 828
 			}
829
+			}
771 830
 			else
772 831
 			{
773 832
 				$obj = CreateObject($app.'.'.$class);
774 833
 			}
775 834
 		}
776
-		if(is_callable($method))        // php5.3+ call
835
+		if(is_callable($method))
836
+		{
837
+			// php5.3+ call
777 838
 		{
778 839
 			$result = call_user_func($method,$pattern,$options);
779 840
 		}
841
+		}
780 842
 		elseif(is_object($obj) && method_exists($obj,$method))
781 843
 		{
782 844
 			$result = $obj->$method($pattern,$options);
@@ -809,12 +871,18 @@  discard block
 block discarded – undo
809 871
 	 */
810 872
 	static function title($app,$id,$link=null)
811 873
 	{
812
-		if (!$id) return '';
874
+		if (!$id)
875
+		{
876
+			return '';
877
+		}
813 878
 
814 879
 		$title =& self::get_cache($app,$id);
815 880
 		if (isset($title) && !empty($title) && !is_array($id))
816 881
 		{
817
-			if (self::DEBUG) echo '<p>'.__METHOD__."('$app','$id')='$title' (from cache)</p>\n";
882
+			if (self::DEBUG)
883
+			{
884
+				echo '<p>'.__METHOD__."('$app','$id')='$title' (from cache)</p>\n";
885
+			}
818 886
 			return $title;
819 887
 		}
820 888
 		if ($app == self::VFS_APPNAME)
@@ -834,21 +902,33 @@  discard block
 block discarded – undo
834 902
 			{
835 903
 				$title .= ': '.$link['type'] . ' '.egw_vfs::hsize($link['size']);
836 904
 			}*/
837
-			if (self::DEBUG) echo '<p>'.__METHOD__."('$app','$id')='$title' (file)</p>\n";
905
+			if (self::DEBUG)
906
+			{
907
+				echo '<p>'.__METHOD__."('$app','$id')='$title' (file)</p>\n";
908
+			}
838 909
 			return $title;
839 910
 		}
840 911
 		if ($app == '' || !is_array($reg = self::$app_register[$app]) || !isset($reg['title']))
841 912
 		{
842
-			if (self::DEBUG) echo "<p>".__METHOD__."('$app','$id') something is wrong!!!</p>\n";
913
+			if (self::DEBUG)
914
+			{
915
+				echo "<p>".__METHOD__."('$app','$id') something is wrong!!!</p>\n";
916
+			}
843 917
 			return false; //array(); // not sure why it should return an array on failure, as the description states boolean/string
844 918
 		}
845 919
 		$method = $reg['title'];
846 920
 
847
-		if (true) $title = ExecMethod($method,$id);
921
+		if (true)
922
+		{
923
+			$title = ExecMethod($method,$id);
924
+		}
848 925
 
849
-		if ($id && is_null($title))	// $app,$id has been deleted ==> unlink all links to it
926
+		if ($id && is_null($title))
927
+		{
928
+			// $app,$id has been deleted ==> unlink all links to it
850 929
 		{
851 930
 			static $unlinking = array();
931
+		}
852 932
 			// check if we are already trying to unlink the entry, to avoid an infinit recursion
853 933
 			if (!isset($unlinking[$app]) || !isset($unlinking[$app][$id]))
854 934
 			{
@@ -856,10 +936,16 @@  discard block
 block discarded – undo
856 936
 				self::unlink(0,$app,$id);
857 937
 				unset($unlinking[$app][$id]);
858 938
 			}
859
-			if (self::DEBUG) echo '<p>'.__METHOD__."('$app','$id') unlinked, as $method returned null</p>\n";
939
+			if (self::DEBUG)
940
+			{
941
+				echo '<p>'.__METHOD__."('$app','$id') unlinked, as $method returned null</p>\n";
942
+			}
860 943
 			return False;
861 944
 		}
862
-		if (self::DEBUG) echo '<p>'.__METHOD__."('$app','$id')='$title' (from $method)</p>\n";
945
+		if (self::DEBUG)
946
+		{
947
+			echo '<p>'.__METHOD__."('$app','$id')='$title' (from $method)</p>\n";
948
+		}
863 949
 
864 950
 		return $title;
865 951
 	}
@@ -1025,7 +1111,10 @@  discard block
 block discarded – undo
1025 1111
 			{
1026 1112
 				foreach($registry['mime'] as $mime => $data)
1027 1113
 				{
1028
-					if ($mime == $type) return $data;
1114
+					if ($mime == $type)
1115
+					{
1116
+						return $data;
1117
+					}
1029 1118
 					if ($mime[0] == '/' && preg_match($mime.'i', $type))
1030 1119
 					{
1031 1120
 						$wildcard_mime = $data;
@@ -1046,7 +1135,10 @@  discard block
 block discarded – undo
1046 1135
 	 */
1047 1136
 	static function mime_open($path, $type=null, &$popup=null)
1048 1137
 	{
1049
-		if (is_null($type)) $type = egw_vfs::mime_content_type($path);
1138
+		if (is_null($type))
1139
+		{
1140
+			$type = egw_vfs::mime_content_type($path);
1141
+		}
1050 1142
 
1051 1143
 		if (($data = self::get_mime_info($type)))
1052 1144
 		{
@@ -1114,14 +1206,20 @@  discard block
 block discarded – undo
1114 1206
 	{
1115 1207
 		$reg = self::$app_register[$app];
1116 1208
 
1117
-		if (!isset($reg)) return false;
1209
+		if (!isset($reg))
1210
+		{
1211
+			return false;
1212
+		}
1118 1213
 
1119
-		if (!isset($reg[$name]))	// some defaults
1214
+		if (!isset($reg[$name]))
1215
+		{
1216
+			// some defaults
1120 1217
 		{
1121 1218
 			switch($name)
1122 1219
 			{
1123 1220
 				case 'name':
1124 1221
 					$reg[$name] = $app;
1222
+		}
1125 1223
 					break;
1126 1224
 				case 'icon':
1127 1225
 					if (isset($GLOBALS['egw_info']['apps'][$app]['icon']))
@@ -1205,7 +1303,10 @@  discard block
 block discarded – undo
1205 1303
 		if (file_exists($entry_dir) || ($Ok = mkdir($entry_dir,0,true)))
1206 1304
 		{
1207 1305
 			$Ok = egw_vfs::copy_uploaded($file, $p=self::vfs_path($app,$id,'',true), $comment, false);	// no is_uploaded_file() check!
1208
-			if (!$Ok) error_log(__METHOD__."('$app', '$id', ".array2string($file).", '$comment') called egw_vfs::copy_uploaded('$file[tmp_name]', '$p', '$comment', false)=".array2string($Ok));
1306
+			if (!$Ok)
1307
+			{
1308
+				error_log(__METHOD__."('$app', '$id', ".array2string($file).", '$comment') called egw_vfs::copy_uploaded('$file[tmp_name]', '$p', '$comment', false)=".array2string($Ok));
1309
+			}
1209 1310
 		}
1210 1311
 		else
1211 1312
 		{
@@ -1225,7 +1326,10 @@  discard block
 block discarded – undo
1225 1326
 	static function link_file($app,$id,$file)//,$comment='')
1226 1327
 	{
1227 1328
 		// Don't try to link into app dir if there is no id
1228
-		if(!$id) return;
1329
+		if(!$id)
1330
+		{
1331
+			return;
1332
+		}
1229 1333
 
1230 1334
 		$app_path = self::vfs_path($app,$id);
1231 1335
 		$ok = true;
@@ -1251,10 +1355,13 @@  discard block
 block discarded – undo
1251 1355
 	 */
1252 1356
 	static function delete_attached($app,$id='',$fname='')
1253 1357
 	{
1254
-		if ((int)$app > 0)	// is file_id
1358
+		if ((int)$app > 0)
1359
+		{
1360
+			// is file_id
1255 1361
 		{
1256 1362
 			$url = egw_vfs::resolve_url(sqlfs_stream_wrapper::id2path($app));
1257 1363
 		}
1364
+		}
1258 1365
 		else
1259 1366
 		{
1260 1367
 			if (empty($app) || empty($id))
@@ -1263,9 +1370,12 @@  discard block
 block discarded – undo
1263 1370
 			}
1264 1371
 			$url = self::vfs_path($app,$id,$fname);
1265 1372
 
1266
-			if (!$fname || !$id)	// we delete the whole entry (or all entries), which probably not exist anymore
1373
+			if (!$fname || !$id)
1374
+			{
1375
+				// we delete the whole entry (or all entries), which probably not exist anymore
1267 1376
 			{
1268 1377
 				$current_is_root = egw_vfs::$is_root;
1378
+			}
1269 1379
 				egw_vfs::$is_root = true;
1270 1380
 			}
1271 1381
 		}
@@ -1356,10 +1466,16 @@  discard block
 block discarded – undo
1356 1466
 		$path = self::vfs_path($app,$id);
1357 1467
 		//error_log(__METHOD__."($app,$id) url=$url");
1358 1468
 
1359
-		if (!($extra = self::get_registry($app,'find_extra'))) $extra = array();
1469
+		if (!($extra = self::get_registry($app,'find_extra')))
1470
+		{
1471
+			$extra = array();
1472
+		}
1360 1473
 
1361 1474
 		// always use regular links stream wrapper here: extended one is unnecessary (slow) for just listing attachments
1362
-		if (substr($path,0,13) == 'stylite.links') $path = substr($path,8);
1475
+		if (substr($path,0,13) == 'stylite.links')
1476
+		{
1477
+			$path = substr($path,8);
1478
+		}
1363 1479
 
1364 1480
 		$attached = array();
1365 1481
 		if (($url2stats = egw_vfs::find($path,array('need_mime'=>true,'type'=>'F','url'=>true)+$extra,true)))
@@ -1596,7 +1712,10 @@  discard block
 block discarded – undo
1596 1712
 		}
1597 1713
 		$ret = call_user_func_array('ExecMethod2', $data);
1598 1714
 
1599
-		if (is_resource($ret)) fseek($ret, 0);
1715
+		if (is_resource($ret))
1716
+		{
1717
+			fseek($ret, 0);
1718
+		}
1600 1719
 
1601 1720
 		if ($return_resource != is_resource($ret))
1602 1721
 		{
Please login to merge, or discard this patch.
phpgwapi/inc/class.egw_mailer.inc.php 4 patches
Doc Comments   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
 	/**
236 236
 	 * Add one or multiple addresses to Cc
237 237
 	 *
238
-	 * @param string|array|Horde_Mail_Rfc822_List $address
238
+	 * @param string $address
239 239
 	 * @param string $personal ='' only used if $address is a string
240 240
 	 */
241 241
 	function addCc($address, $personal=null)
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
 	/**
255 255
 	 * Add one or multiple addresses to Bcc
256 256
 	 *
257
-	 * @param string|array|Horde_Mail_Rfc822_List $address
257
+	 * @param string $address
258 258
 	 * @param string $personal ='' only used if $address is a string
259 259
 	 */
260 260
 	function addBcc($address, $personal=null)
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
 	/**
274 274
 	 * Add one or multiple addresses to Reply-To
275 275
 	 *
276
-	 * @param string|array|Horde_Mail_Rfc822_List $address
276
+	 * @param false|string $address
277 277
 	 * @param string $personal ='' only used if $address is a string
278 278
 	 */
279 279
 	function addReplyTo($address, $personal=null)
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
 	/**
366 366
 	 * Adds an embedded image or other inline attachment
367 367
 	 *
368
-	 * @param string|resource $data Path to the attachment or open file-descriptor
368
+	 * @param string $data Path to the attachment or open file-descriptor
369 369
 	 * @param string $cid Content ID of the attachment.  Use this to identify
370 370
 	 *        the Id for accessing the image in an HTML form.
371 371
 	 * @param string $name Overrides the attachment name.
@@ -833,6 +833,7 @@  discard block
 block discarded – undo
833 833
 
834 834
 	/**
835 835
 	 * @deprecated use AddHeader($header, $value)
836
+	 * @param string $str
836 837
 	 */
837 838
 	function AddCustomHeader($str)
838 839
 	{
@@ -851,6 +852,7 @@  discard block
 block discarded – undo
851 852
 	}
852 853
 	/**
853 854
 	 * @deprecated done by Horde automatic
855
+	 * @return string
854 856
 	 */
855 857
 	function EncodeHeader($str/*, $position = 'text'*/)
856 858
 	{
Please login to merge, or discard this patch.
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -615,15 +615,15 @@  discard block
 block discarded – undo
615 615
 	}
616 616
 
617 617
 	/**
618
-     * Get the raw email data sent by this object.
619
-     *
618
+	 * Get the raw email data sent by this object.
619
+	 *
620 620
 	 * Reimplement to be able to call it for saveAsDraft by calling
621 621
 	 * $this->send(new Horde_Mail_Transport_Null()),
622 622
 	 * if no base-part is set, because send is not called before.
623 623
 	 *
624
-     * @param  boolean $stream  If true, return a stream resource, otherwise
625
-     * @return stream|string  The raw email data.
626
-     */
624
+	 * @param  boolean $stream  If true, return a stream resource, otherwise
625
+	 * @return stream|string  The raw email data.
626
+	 */
627 627
 	function getRaw($stream=true)
628 628
 	{
629 629
 		try {
@@ -636,20 +636,20 @@  discard block
 block discarded – undo
636 636
 		}
637 637
 		// code copied from Horde_Mime_Mail::getRaw(), as there is no way to inject charset in
638 638
 		// _headers->toString(), which is required to encode headers containing non-ascii chars correct
639
-        if ($stream) {
640
-            $hdr = new Horde_Stream();
641
-            $hdr->add($this->_headers->toString(array('charset' => 'utf-8', 'canonical' => true)), true);
642
-            return Horde_Stream_Wrapper_Combine::getStream(
643
-                array($hdr->stream,
644
-                      $this->getBasePart()->toString(
645
-                        array('stream' => true, 'canonical' => true, 'encode' => Horde_Mime_Part::ENCODE_7BIT | Horde_Mime_Part::ENCODE_8BIT | Horde_Mime_Part::ENCODE_BINARY))
646
-                )
647
-            );
648
-        }
649
-
650
-        return $this->_headers->toString(array('charset' => 'utf-8', 'canonical' => true)) .
639
+		if ($stream) {
640
+			$hdr = new Horde_Stream();
641
+			$hdr->add($this->_headers->toString(array('charset' => 'utf-8', 'canonical' => true)), true);
642
+			return Horde_Stream_Wrapper_Combine::getStream(
643
+				array($hdr->stream,
644
+					  $this->getBasePart()->toString(
645
+						array('stream' => true, 'canonical' => true, 'encode' => Horde_Mime_Part::ENCODE_7BIT | Horde_Mime_Part::ENCODE_8BIT | Horde_Mime_Part::ENCODE_BINARY))
646
+				)
647
+			);
648
+		}
649
+
650
+		return $this->_headers->toString(array('charset' => 'utf-8', 'canonical' => true)) .
651 651
 			$this->getBasePart()->toString(array('canonical' => true));
652
-    }
652
+	}
653 653
 
654 654
 	/**
655 655
 	 * Find body: 1. part with mimetype "text/$subtype"
Please login to merge, or discard this patch.
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 	 *
55 55
 	 * @param int|emailadmin_account $account =null mail account to use, default use emailadmin_account::get_default($smtp=true)
56 56
 	 */
57
-	function __construct($account=null)
57
+	function __construct($account = null)
58 58
 	{
59 59
 		// Horde use locale for translation of error messages
60 60
 		common::setlocale(LC_MESSAGES);
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 	 * @param int|emailadmin_account $account =null mail account to use, default use emailadmin_account::get_default($smtp=true)
90 90
 	 * @throws egw_exception_not_found if account was not found (or not valid for current user)
91 91
 	 */
92
-	function  setAccount($account=null)
92
+	function  setAccount($account = null)
93 93
 	{
94 94
 		if (is_a($account, 'emailadmin_account'))
95 95
 		{
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
 		{
112 112
 			$identity = emailadmin_account::read_identity($this->account->ident_id, true, null, $this->account);
113 113
 		}
114
-		catch(Exception $e)
114
+		catch (Exception $e)
115 115
 		{
116 116
 			unset($e);
117 117
 			error_log(__METHOD__.__LINE__.' Could not read_identity for account:'.$account['acc_id'].' with IdentID:'.$account['ident_id']);
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
 	 * @param string $address
134 134
 	 * @param string $personal =''
135 135
 	 */
136
-	public function setFrom($address, $personal='')
136
+	public function setFrom($address, $personal = '')
137 137
 	{
138 138
 		$this->addHeader('From', self::add_personal($address, $personal));
139 139
 	}
@@ -145,13 +145,13 @@  discard block
 block discarded – undo
145 145
 	 * @param string $personal ='' only used if $address is a string
146 146
 	 * @param string $type ='to' type of address to add "to", "cc", "bcc" or "replyto"
147 147
 	 */
148
-	function addAddress($address, $personal='', $type='to')
148
+	function addAddress($address, $personal = '', $type = 'to')
149 149
 	{
150 150
 		if (!isset(self::$type2header[$type]))
151 151
 		{
152 152
 			throw new egw_exception_wrong_parameter("Unknown type '$type'!");
153 153
 		}
154
-		if ($personal) $address = self::add_personal ($address, $personal);
154
+		if ($personal) $address = self::add_personal($address, $personal);
155 155
 
156 156
 		// add to our local list
157 157
 		$this->$type->add($address);
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 	 *
166 166
 	 * @param string $type ='to' type of address to add "to", "cc", "bcc" or "replyto"
167 167
 	 */
168
-	function clearAddresses($type='to')
168
+	function clearAddresses($type = 'to')
169 169
 	{
170 170
 		$this->$type = new Horde_Mail_Rfc822_List();
171 171
 
@@ -179,12 +179,12 @@  discard block
 block discarded – undo
179 179
 	 * @param boolean $return_array =false true: return array of string, false: Horde_Mail_Rfc822_List
180 180
 	 * @return array|Horde_Mail_Rfc822_List supporting arrayAccess and Iterable
181 181
 	 */
182
-	function getAddresses($type='to', $return_array=false)
182
+	function getAddresses($type = 'to', $return_array = false)
183 183
 	{
184 184
 		if ($return_array)
185 185
 		{
186 186
 			$addresses = array();
187
-			foreach($this->$type as $addr)
187
+			foreach ($this->$type as $addr)
188 188
 			{
189 189
 				$addresses[] = (string)$addr;
190 190
 			}
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
 			//if (!preg_match('/^[!#$%&\'*+/0-9=?A-Z^_`a-z{|}~-]+$/u', $personal))	// that's how I read the rfc(2)822
226 226
 			if ($personal && !preg_match('/^[0-9A-Z -]*$/iu', $personal))	// but quoting is never wrong, so quote more then necessary
227 227
 			{
228
-				$personal = '"'.str_replace(array('\\', '"'),array('\\\\', '\\"'), $personal).'"';
228
+				$personal = '"'.str_replace(array('\\', '"'), array('\\\\', '\\"'), $personal).'"';
229 229
 			}
230 230
 			$address = ($personal ? $personal.' <' : '').$address.($personal ? '>' : '');
231 231
 		}
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
 	 * @param string|array|Horde_Mail_Rfc822_List $address
239 239
 	 * @param string $personal ='' only used if $address is a string
240 240
 	 */
241
-	function addCc($address, $personal=null)
241
+	function addCc($address, $personal = null)
242 242
 	{
243 243
 		$this->addAddress($address, $personal, 'cc');
244 244
 	}
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
 	 * @param string|array|Horde_Mail_Rfc822_List $address
258 258
 	 * @param string $personal ='' only used if $address is a string
259 259
 	 */
260
-	function addBcc($address, $personal=null)
260
+	function addBcc($address, $personal = null)
261 261
 	{
262 262
 		$this->addAddress($address, $personal, 'bcc');
263 263
 	}
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
 	 * @param string|array|Horde_Mail_Rfc822_List $address
277 277
 	 * @param string $personal ='' only used if $address is a string
278 278
 	 */
279
-	function addReplyTo($address, $personal=null)
279
+	function addReplyTo($address, $personal = null)
280 280
 	{
281 281
 		$this->addAddress($address, $personal, 'replyto');
282 282
 	}
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
 	 * @return integer part-number
312 312
 	 * @throws egw_exception_not_found if $file could not be opened for reading
313 313
 	 */
314
-	public function addAttachment($data, $name = null, $type = null, $old_type=null)
314
+	public function addAttachment($data, $name = null, $type = null, $old_type = null)
315 315
 	{
316 316
 		// deprecated PHPMailer::AddAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream') call
317 317
 		if ($type === 'base64')
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
 		// set content-type parameters, which get ignored by setType
345 345
 		if (preg_match_all('/;\s*([^=]+)=([^;]*)/', $type, $matches))
346 346
 		{
347
-			foreach($matches[1] as $n => $label)
347
+			foreach ($matches[1] as $n => $label)
348 348
 			{
349 349
 				$part->setContentTypeParameter($label, $matches[2][$n]);
350 350
 			}
@@ -446,11 +446,11 @@  discard block
 block discarded – undo
446 446
 	 * @param array $parameters =array() eg. array('method' => 'REQUEST')
447 447
 	 * @param string $charset =null default to $this->_charset="utf-8"
448 448
 	 */
449
-	function setAlternativBody($content, $type, $parameters=array(), $charset=null)
449
+	function setAlternativBody($content, $type, $parameters = array(), $charset = null)
450 450
 	{
451 451
 		$this->_alternativBody = new Horde_Mime_Part();
452 452
 		$this->_alternativBody->setType($type);
453
-		foreach($parameters as $label => $data)
453
+		foreach ($parameters as $label => $data)
454 454
 		{
455 455
 			$this->_alternativBody->setContentTypeParameter($label, $data);
456 456
 		}
@@ -476,24 +476,24 @@  discard block
 block discarded – undo
476 476
 			$message_id = Horde_Mime_Headers_MessageId::create('EGroupware');
477 477
 			$this->addHeader('Message-ID', $message_id);
478 478
 		}
479
-		$body_sha1 = null;	// skip sha1, it requires whole mail in memory, which we traing to avoid now
479
+		$body_sha1 = null; // skip sha1, it requires whole mail in memory, which we traing to avoid now
480 480
 
481 481
 		$mail_id = $GLOBALS['egw']->hooks->process(array(
482 482
 			'location' => 'send_mail',
483
-			'subject' => $subject=$this->getHeader('Subject'),
483
+			'subject' => $subject = $this->getHeader('Subject'),
484 484
 			'from' => $this->getHeader('Return-Path') ? $this->getHeader('Return-Path') : $this->getHeader('From'),
485
-			'to' => $to=$this->getAddresses('to', true),
486
-			'cc' => $cc=$this->getAddresses('cc', true),
487
-			'bcc' => $bcc=$this->getAddresses('bcc', true),
485
+			'to' => $to = $this->getAddresses('to', true),
486
+			'cc' => $cc = $this->getAddresses('cc', true),
487
+			'bcc' => $bcc = $this->getAddresses('bcc', true),
488 488
 			'body_sha1' => $body_sha1,
489 489
 			'message_id' => (string)$message_id,
490
-		), array(), true);	// true = call all apps
490
+		), array(), true); // true = call all apps
491 491
 
492 492
 		// check if we are sending an html mail with inline images
493 493
 		if (!empty($this->_htmlBody) && count($this->_parts))
494 494
 		{
495 495
 			$related = null;
496
-			foreach($this->_parts as $n => $part)
496
+			foreach ($this->_parts as $n => $part)
497 497
 			{
498 498
 				if ($part->getDisposition() == 'inline' && $part->getContentId())
499 499
 				{
@@ -547,7 +547,7 @@  discard block
 block discarded – undo
547 547
 				$this->_body = $body;
548 548
 				$flowed = false;
549 549
 			}
550
-			parent::send($this->account->smtpTransport(), true,	$flowed);	// true: keep Message-ID
550
+			parent::send($this->account->smtpTransport(), true, $flowed); // true: keep Message-ID
551 551
 		}
552 552
 		catch (Exception $e) {
553 553
 			// in case of errors/exceptions call hook again with previous returned mail_id and error-message to log
@@ -562,7 +562,7 @@  discard block
 block discarded – undo
562 562
 				'message_id' => (string)$message_id,
563 563
 				'mail_id' => $mail_id,
564 564
 				'error' => $e->getMessage(),
565
-			), array(), true);	// true = call all apps
565
+			), array(), true); // true = call all apps
566 566
 		}
567 567
 
568 568
 		// log mails to file specified in $GLOBALS['egw_info']['server']['log_mail'] or error_log for true
@@ -575,7 +575,7 @@  discard block
 block discarded – undo
575 575
 			$msg .= ' from instance '.$GLOBALS['egw_info']['user']['domain'].' and IP '.egw_session::getuser_ip();
576 576
 			$msg .= ' from user #'.$GLOBALS['egw_info']['user']['account_id'];
577 577
 
578
-			if ($GLOBALS['egw_info']['user']['account_id'] && class_exists('common',false))
578
+			if ($GLOBALS['egw_info']['user']['account_id'] && class_exists('common', false))
579 579
 			{
580 580
 				$msg .= ' ('.common::grab_owner_name($GLOBALS['egw_info']['user']['account_id']).')';
581 581
 			}
@@ -587,7 +587,7 @@  discard block
 block discarded – undo
587 587
 			$msg .= ' cc='.implode(', ', $cc).', bcc='.implode(', ', $bcc);
588 588
 			if ($GLOBALS['egw_info']['server']['log_mail'] !== true) $msg .= "\n\n";
589 589
 
590
-			error_log($msg,$GLOBALS['egw_info']['server']['log_mail'] === true ? 0 : 3,
590
+			error_log($msg, $GLOBALS['egw_info']['server']['log_mail'] === true ? 0 : 3,
591 591
 				$GLOBALS['egw_info']['server']['log_mail']);
592 592
 		}
593 593
 		// rethrow error
@@ -624,15 +624,15 @@  discard block
 block discarded – undo
624 624
      * @param  boolean $stream  If true, return a stream resource, otherwise
625 625
      * @return stream|string  The raw email data.
626 626
      */
627
-	function getRaw($stream=true)
627
+	function getRaw($stream = true)
628 628
 	{
629 629
 		try {
630 630
 			$this->getBasePart();
631 631
 		}
632
-		catch(Horde_Mail_Exception $e)
632
+		catch (Horde_Mail_Exception $e)
633 633
 		{
634 634
 			unset($e);
635
-			parent::send(new Horde_Mail_Transport_Null(), true);	// true: keep Message-ID
635
+			parent::send(new Horde_Mail_Transport_Null(), true); // true: keep Message-ID
636 636
 		}
637 637
 		// code copied from Horde_Mime_Mail::getRaw(), as there is no way to inject charset in
638 638
 		// _headers->toString(), which is required to encode headers containing non-ascii chars correct
@@ -642,12 +642,12 @@  discard block
 block discarded – undo
642 642
             return Horde_Stream_Wrapper_Combine::getStream(
643 643
                 array($hdr->stream,
644 644
                       $this->getBasePart()->toString(
645
-                        array('stream' => true, 'canonical' => true, 'encode' => Horde_Mime_Part::ENCODE_7BIT | Horde_Mime_Part::ENCODE_8BIT | Horde_Mime_Part::ENCODE_BINARY))
645
+                        array('stream' => true, 'canonical' => true, 'encode' => Horde_Mime_Part::ENCODE_7BIT|Horde_Mime_Part::ENCODE_8BIT|Horde_Mime_Part::ENCODE_BINARY))
646 646
                 )
647 647
             );
648 648
         }
649 649
 
650
-        return $this->_headers->toString(array('charset' => 'utf-8', 'canonical' => true)) .
650
+        return $this->_headers->toString(array('charset' => 'utf-8', 'canonical' => true)).
651 651
 			$this->getBasePart()->toString(array('canonical' => true));
652 652
     }
653 653
 
@@ -659,7 +659,7 @@  discard block
 block discarded – undo
659 659
 	 * @param string $subtype =null
660 660
 	 * @return Horde_Mime_Part part with body or null
661 661
 	 */
662
-	function findBody($subtype=null)
662
+	function findBody($subtype = null)
663 663
 	{
664 664
 		try {
665 665
 			$base = $this->getBasePart();
@@ -691,11 +691,11 @@  discard block
 block discarded – undo
691 691
 			$this->_body = $this->_htmlBody = $this->_alternativBody = null;
692 692
 			$this->clearParts();
693 693
 
694
-			foreach($base->partIterator() as $part)
694
+			foreach ($base->partIterator() as $part)
695 695
 			{
696 696
 				$id = $part->getMimeId();
697 697
 				//error_log(__METHOD__."() plain=$plain_id, html=$html_id: $id: ".$part->getType());
698
-				switch($id)
698
+				switch ($id)
699 699
 				{
700 700
 					case '0':	// base-part itself
701 701
 						continue 2;
@@ -768,7 +768,7 @@  discard block
 block discarded – undo
768 768
 	 */
769 769
 	function clearCustomHeaders()
770 770
 	{
771
-		foreach($this->_headers->toArray() as $header => $value)
771
+		foreach ($this->_headers->toArray() as $header => $value)
772 772
 		{
773 773
 			if (stripos($header, 'x-') === 0 || $header == 'Received')
774 774
 			{
@@ -793,10 +793,10 @@  discard block
 block discarded – undo
793 793
 		try {
794 794
 			$this->getBasePart();
795 795
 		}
796
-		catch(Horde_Mail_Exception $e)
796
+		catch (Horde_Mail_Exception $e)
797 797
 		{
798 798
 			unset($e);
799
-			parent::send(new Horde_Mail_Transport_Null(), true);	// true: keep Message-ID
799
+			parent::send(new Horde_Mail_Transport_Null(), true); // true: keep Message-ID
800 800
 		}
801 801
 		return $this->_headers->toString();
802 802
 	}
@@ -812,13 +812,13 @@  discard block
 block discarded – undo
812 812
 		try {
813 813
 			$this->getBasePart();
814 814
 		}
815
-		catch(Horde_Mail_Exception $e)
815
+		catch (Horde_Mail_Exception $e)
816 816
 		{
817 817
 			unset($e);
818
-			parent::send(new Horde_Mail_Transport_Null(), true);	// true: keep Message-ID
818
+			parent::send(new Horde_Mail_Transport_Null(), true); // true: keep Message-ID
819 819
 		}
820 820
 		return $this->getBasePart()->toString(
821
-			array('stream' => false, 'encode' => Horde_Mime_Part::ENCODE_7BIT | Horde_Mime_Part::ENCODE_8BIT | Horde_Mime_Part::ENCODE_BINARY));
821
+			array('stream' => false, 'encode' => Horde_Mime_Part::ENCODE_7BIT|Horde_Mime_Part::ENCODE_8BIT|Horde_Mime_Part::ENCODE_BINARY));
822 822
 	}
823 823
 
824 824
 	/**
@@ -910,10 +910,10 @@  discard block
 block discarded – undo
910 910
 	 */
911 911
 	function __set($name, $value)
912 912
 	{
913
-		switch($name)
913
+		switch ($name)
914 914
 		{
915 915
 			case '_bcc':
916
-				$this->_bcc = $value;	// this is NOT PHPMailer compatibility, but need for working BCC, if $this->_bcc is NOT set
916
+				$this->_bcc = $value; // this is NOT PHPMailer compatibility, but need for working BCC, if $this->_bcc is NOT set
917 917
 				break;
918 918
 			case 'Sender':
919 919
 				$this->addHeader('Return-Path', '<'.$value.'>', true);
@@ -970,10 +970,10 @@  discard block
 block discarded – undo
970 970
 	 */
971 971
 	function __get($name)
972 972
 	{
973
-		switch($name)
973
+		switch ($name)
974 974
 		{
975 975
 			case '_bcc':
976
-				return $this->_bcc;	// this is NOT PHPMailer compatibility, but quietening below log, if $this->_bcc is NOT set
976
+				return $this->_bcc; // this is NOT PHPMailer compatibility, but quietening below log, if $this->_bcc is NOT set
977 977
 			case 'Sender':
978 978
 				return $this->getHeader('Return-Path');
979 979
 			case 'From':
Please login to merge, or discard this patch.
Braces   +50 added lines, -13 removed lines patch added patch discarded remove patch
@@ -101,10 +101,13 @@  discard block
 block discarded – undo
101 101
 		}
102 102
 		else
103 103
 		{
104
-			if (!($this->account = emailadmin_account::get_default(true)))	// true = need an SMTP (not just IMAP) account
104
+			if (!($this->account = emailadmin_account::get_default(true)))
105
+			{
106
+				// true = need an SMTP (not just IMAP) account
105 107
 			{
106 108
 				throw new egw_exception_not_found('SMTP: '.lang('Account not found!'));
107 109
 			}
110
+			}
108 111
 		}
109 112
 
110 113
 		try
@@ -151,7 +154,10 @@  discard block
 block discarded – undo
151 154
 		{
152 155
 			throw new egw_exception_wrong_parameter("Unknown type '$type'!");
153 156
 		}
154
-		if ($personal) $address = self::add_personal ($address, $personal);
157
+		if ($personal)
158
+		{
159
+			$address = self::add_personal ($address, $personal);
160
+		}
155 161
 
156 162
 		// add to our local list
157 163
 		$this->$type->add($address);
@@ -223,10 +229,13 @@  discard block
 block discarded – undo
223 229
 		if (is_string($address) && !empty($personal))
224 230
 		{
225 231
 			//if (!preg_match('/^[!#$%&\'*+/0-9=?A-Z^_`a-z{|}~-]+$/u', $personal))	// that's how I read the rfc(2)822
226
-			if ($personal && !preg_match('/^[0-9A-Z -]*$/iu', $personal))	// but quoting is never wrong, so quote more then necessary
232
+			if ($personal && !preg_match('/^[0-9A-Z -]*$/iu', $personal))
233
+			{
234
+				// but quoting is never wrong, so quote more then necessary
227 235
 			{
228 236
 				$personal = '"'.str_replace(array('\\', '"'),array('\\\\', '\\"'), $personal).'"';
229 237
 			}
238
+			}
230 239
 			$address = ($personal ? $personal.' <' : '').$address.($personal ? '>' : '');
231 240
 		}
232 241
 		return $address;
@@ -329,7 +338,10 @@  discard block
 block discarded – undo
329 338
 			throw new egw_exception_not_found("File '$data' not found!");
330 339
 		}
331 340
 
332
-		if (empty($type) && !is_resource($data)) $type = egw_vfs::mime_content_type($data);
341
+		if (empty($type) && !is_resource($data))
342
+		{
343
+			$type = egw_vfs::mime_content_type($data);
344
+		}
333 345
 
334 346
 		// set "text/calendar; method=*" as alternativ body
335 347
 		$matches = null;
@@ -352,11 +364,17 @@  discard block
 block discarded – undo
352 364
 		$part->setContents($resource);
353 365
 
354 366
 		// setting name, also sets content-disposition attachment (!), therefore we have to do it after "text/calendar; method=" handling
355
-		if ($name || !is_resource($data)) $part->setName($name ? $name : egw_vfs::basename($data));
367
+		if ($name || !is_resource($data))
368
+		{
369
+			$part->setName($name ? $name : egw_vfs::basename($data));
370
+		}
356 371
 
357 372
 		// this should not be necessary, because binary data get detected by mime-type,
358 373
 		// but at least Cyrus complains about NUL characters
359
-		if (substr($type, 0, 5) != 'text/') $part->setTransferEncoding('base64', array('send' => true));
374
+		if (substr($type, 0, 5) != 'text/')
375
+		{
376
+			$part->setTransferEncoding('base64', array('send' => true));
377
+		}
360 378
 		$part->setDisposition('attachment');
361 379
 
362 380
 		return $this->addMimePart($part);
@@ -471,9 +489,12 @@  discard block
 block discarded – undo
471 489
 	function send()
472 490
 	{
473 491
 		if (!($message_id = $this->getHeader('Message-ID')) &&
474
-			class_exists('Horde_Mime_Headers_MessageId'))	// since 2.5.0
492
+			class_exists('Horde_Mime_Headers_MessageId'))
493
+		{
494
+			// since 2.5.0
475 495
 		{
476 496
 			$message_id = Horde_Mime_Headers_MessageId::create('EGroupware');
497
+		}
477 498
 			$this->addHeader('Message-ID', $message_id);
478 499
 		}
479 500
 		$body_sha1 = null;	// skip sha1, it requires whole mail in memory, which we traing to avoid now
@@ -585,13 +606,19 @@  discard block
 block discarded – undo
585 606
 				$msg .= 'ERROR '.$e->getMessage();
586 607
 			}
587 608
 			$msg .= ' cc='.implode(', ', $cc).', bcc='.implode(', ', $bcc);
588
-			if ($GLOBALS['egw_info']['server']['log_mail'] !== true) $msg .= "\n\n";
609
+			if ($GLOBALS['egw_info']['server']['log_mail'] !== true)
610
+			{
611
+				$msg .= "\n\n";
612
+			}
589 613
 
590 614
 			error_log($msg,$GLOBALS['egw_info']['server']['log_mail'] === true ? 0 : 3,
591 615
 				$GLOBALS['egw_info']['server']['log_mail']);
592 616
 		}
593 617
 		// rethrow error
594
-		if (isset($e)) throw $e;
618
+		if (isset($e))
619
+		{
620
+			throw $e;
621
+		}
595 622
 	}
596 623
 
597 624
 
@@ -636,7 +663,8 @@  discard block
 block discarded – undo
636 663
 		}
637 664
 		// code copied from Horde_Mime_Mail::getRaw(), as there is no way to inject charset in
638 665
 		// _headers->toString(), which is required to encode headers containing non-ascii chars correct
639
-        if ($stream) {
666
+        if ($stream)
667
+        {
640 668
             $hdr = new Horde_Stream();
641 669
             $hdr->add($this->_headers->toString(array('charset' => 'utf-8', 'canonical' => true)), true);
642 670
             return Horde_Stream_Wrapper_Combine::getStream(
@@ -663,7 +691,10 @@  discard block
 block discarded – undo
663 691
 	{
664 692
 		try {
665 693
 			$base = $this->getBasePart();
666
-			if (!($part_id = $base->findBody($subtype))) return null;
694
+			if (!($part_id = $base->findBody($subtype)))
695
+			{
696
+				return null;
697
+			}
667 698
 			return $base->getPart($part_id);
668 699
 		}
669 700
 		catch (Exception $e) {
@@ -730,7 +761,10 @@  discard block
 block discarded – undo
730 761
 	 */
731 762
 	public function addMimePart($part)
732 763
 	{
733
-		if ($this->_base) $this->parseBasePart();
764
+		if ($this->_base)
765
+		{
766
+			$this->parseBasePart();
767
+		}
734 768
 
735 769
 		return parent::addMimePart($part);
736 770
 	}
@@ -945,7 +979,10 @@  discard block
 block discarded – undo
945 979
 				break;
946 980
 			case 'Date':
947 981
 			case 'RFCDateToSet':
948
-				if ($value) $this->addHeader('Date', $value, true);
982
+				if ($value)
983
+				{
984
+					$this->addHeader('Date', $value, true);
985
+				}
949 986
 				break;
950 987
 			case 'AltExtended':
951 988
 			case 'AltExtendedContentType':
Please login to merge, or discard this patch.
phpgwapi/inc/class.egw_session.inc.php 4 patches
Doc Comments   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -311,6 +311,7 @@  discard block
 block discarded – undo
311 311
 	 * Encrypt the variables in the session
312 312
 	 *
313 313
 	 * Is called by self::__destruct().
314
+	 * @param string $kp3
314 315
 	 */
315 316
 	static function encrypt($kp3)
316 317
 	{
@@ -439,7 +440,7 @@  discard block
 block discarded – undo
439 440
 	 * @param boolean $no_session =false dont create a real session, eg. for GroupDAV clients using only basic auth, no cookie support
440 441
 	 * @param boolean $auth_check =true if false, the user is loged in without checking his password (eg. for single sign on), default = true
441 442
 	 * @param boolean $fail_on_forced_password_change =false true: do NOT create session, if password change requested
442
-	 * @return string|boolean session id or false if session was not created, $this->(cd_)reason contains cause
443
+	 * @return false|string session id or false if session was not created, $this->(cd_)reason contains cause
443 444
 	 */
444 445
 	function create($login,$passwd = '',$passwd_type = '',$no_session=false,$auth_check=true,$fail_on_forced_password_change=false)
445 446
 	{
@@ -1021,7 +1022,7 @@  discard block
 block discarded – undo
1021 1022
 	/**
1022 1023
 	 * Terminate a session
1023 1024
 	 *
1024
-	 * @param int|string $sessionid nummeric or php session id of session to be terminated
1025
+	 * @param string $sessionid nummeric or php session id of session to be terminated
1025 1026
 	 * @param string $kp3
1026 1027
 	 * @return boolean true on success, false on error
1027 1028
 	 */
Please login to merge, or discard this patch.
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -80,60 +80,60 @@  discard block
 block discarded – undo
80 80
 	const MCRYPT_MODE = MCRYPT_MODE_ECB;
81 81
 
82 82
 	/**
83
-	* current user login (account_lid@domain)
84
-	*
85
-	* @var string
86
-	*/
83
+	 * current user login (account_lid@domain)
84
+	 *
85
+	 * @var string
86
+	 */
87 87
 	var $login;
88 88
 
89 89
 	/**
90
-	* current user password
91
-	*
92
-	* @var string
93
-	*/
90
+	 * current user password
91
+	 *
92
+	 * @var string
93
+	 */
94 94
 	var $passwd;
95 95
 
96 96
 	/**
97
-	* current user db/ldap account id
98
-	*
99
-	* @var int
100
-	*/
97
+	 * current user db/ldap account id
98
+	 *
99
+	 * @var int
100
+	 */
101 101
 	var $account_id;
102 102
 
103 103
 	/**
104
-	* current user account login id (without the eGW-domain/-instance part
105
-	*
106
-	* @var string
107
-	*/
104
+	 * current user account login id (without the eGW-domain/-instance part
105
+	 *
106
+	 * @var string
107
+	 */
108 108
 	var $account_lid;
109 109
 
110 110
 	/**
111
-	* domain for current user
112
-	*
113
-	* @var string
114
-	*/
111
+	 * domain for current user
112
+	 *
113
+	 * @var string
114
+	 */
115 115
 	var $account_domain;
116 116
 
117 117
 	/**
118
-	* type flag, A - anonymous session, N - None, normal session
119
-	*
120
-	* @var string
121
-	*/
118
+	 * type flag, A - anonymous session, N - None, normal session
119
+	 *
120
+	 * @var string
121
+	 */
122 122
 	var $session_flags;
123 123
 
124 124
 	/**
125
-	* current user session id
126
-	*
127
-	* @var string
128
-	*/
125
+	 * current user session id
126
+	 *
127
+	 * @var string
128
+	 */
129 129
 	var $sessionid;
130 130
 
131 131
 	/**
132
-	* an other session specific id (md5 from a random string),
133
-	* used together with the sessionid for xmlrpc basic auth and the encryption of session-data (if that's enabled)
134
-	*
135
-	* @var string
136
-	*/
132
+	 * an other session specific id (md5 from a random string),
133
+	 * used together with the sessionid for xmlrpc basic auth and the encryption of session-data (if that's enabled)
134
+	 *
135
+	 * @var string
136
+	 */
137 137
 	var $kp3;
138 138
 
139 139
 	/**
@@ -144,17 +144,17 @@  discard block
 block discarded – undo
144 144
 	var $sessionid_access_log;
145 145
 
146 146
 	/**
147
-	* name of XML-RPC/SOAP method called
148
-	*
149
-	* @var string
150
-	*/
147
+	 * name of XML-RPC/SOAP method called
148
+	 *
149
+	 * @var string
150
+	 */
151 151
 	var $xmlrpc_method_called;
152 152
 
153 153
 	/**
154
-	* Array with the name of the system domains
155
-	*
156
-	* @var array
157
-	*/
154
+	 * Array with the name of the system domains
155
+	 *
156
+	 * @var array
157
+	 */
158 158
 	private $egw_domains;
159 159
 
160 160
 	/**
@@ -248,9 +248,9 @@  discard block
 block discarded – undo
248 248
 
249 249
 		// set session_timeout from global php.ini and default to 14400=4h, if not set
250 250
 		if (!($GLOBALS['egw_info']['server']['sessions_timeout'] = ini_get('session.gc_maxlifetime')))
251
-      	{
252
-      		ini_set('session.gc_maxlifetime', $GLOBALS['egw_info']['server']['sessions_timeout']=14400);
253
-      	}
251
+	  	{
252
+	  		ini_set('session.gc_maxlifetime', $GLOBALS['egw_info']['server']['sessions_timeout']=14400);
253
+	  	}
254 254
 	}
255 255
 
256 256
 	/**
@@ -661,14 +661,14 @@  discard block
 block discarded – undo
661 661
 	const ACCESS_LOG_TABLE = 'egw_access_log';
662 662
 
663 663
 	/**
664
-    * Write or update (for logout) the access_log
665
-	*
666
-	* @param string|int $sessionid nummeric or PHP session id or 0 for unsuccessful logins
667
-	* @param string $login ='' account_lid (evtl. with domain) or '' for setting the logout-time
668
-	* @param string $user_ip ='' ip to log
669
-	* @param int $account_id =0 numerical account_id
670
-	* @return int $sessionid primary key of egw_access_log for login, null otherwise
671
-	*/
664
+	 * Write or update (for logout) the access_log
665
+	 *
666
+	 * @param string|int $sessionid nummeric or PHP session id or 0 for unsuccessful logins
667
+	 * @param string $login ='' account_lid (evtl. with domain) or '' for setting the logout-time
668
+	 * @param string $user_ip ='' ip to log
669
+	 * @param int $account_id =0 numerical account_id
670
+	 * @return int $sessionid primary key of egw_access_log for login, null otherwise
671
+	 */
672 672
 	private function log_access($sessionid,$login='',$user_ip='',$account_id=0)
673 673
 	{
674 674
 		$now = time();
@@ -716,7 +716,7 @@  discard block
 block discarded – undo
716 716
 
717 717
 	/**
718 718
 	 * Protect against brute force attacks, block login if too many unsuccessful login attmepts
719
-     *
719
+	 *
720 720
 	 * @param string $login account_lid (evtl. with domain)
721 721
 	 * @param string $ip ip of the user
722 722
 	 * @returns bool login blocked?
Please login to merge, or discard this patch.
Spacing   +175 added lines, -179 removed lines patch added patch discarded remove patch
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
 	const CD_BAD_LOGIN_OR_PASSWORD = 5;
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
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
 	 *
192 192
 	 * @param array $domain_names =null domain-names used in this install
193 193
 	 */
194
-	function __construct(array $domain_names=null)
194
+	function __construct(array $domain_names = null)
195 195
 	{
196 196
 		$this->required_files = $_SESSION[self::EGW_REQUIRED_FILES];
197 197
 
@@ -207,27 +207,27 @@  discard block
 block discarded – undo
207 207
 			$save_rep = false;
208 208
 			if (!isset($GLOBALS['egw_info']['server']['max_access_log_age']))
209 209
 			{
210
-				$GLOBALS['egw_info']['server']['max_access_log_age'] = 90;	// default 90 days
210
+				$GLOBALS['egw_info']['server']['max_access_log_age'] = 90; // default 90 days
211 211
 				$save_rep = true;
212 212
 			}
213 213
 			if (!isset($GLOBALS['egw_info']['server']['block_time']))
214 214
 			{
215
-				$GLOBALS['egw_info']['server']['block_time'] = 1;	// default 1min, its enough to slow down brute force attacks
215
+				$GLOBALS['egw_info']['server']['block_time'] = 1; // default 1min, its enough to slow down brute force attacks
216 216
 				$save_rep = true;
217 217
 			}
218 218
 			if (!isset($GLOBALS['egw_info']['server']['num_unsuccessful_id']))
219 219
 			{
220
-				$GLOBALS['egw_info']['server']['num_unsuccessful_id']  = 3;	// default 3 trys per id
220
+				$GLOBALS['egw_info']['server']['num_unsuccessful_id'] = 3; // default 3 trys per id
221 221
 				$save_rep = true;
222 222
 			}
223 223
 			if (!isset($GLOBALS['egw_info']['server']['num_unsuccessful_ip']))
224 224
 			{
225
-				$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
225
+				$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
226 226
 				$save_rep = true;
227 227
 			}
228 228
 			if (!isset($GLOBALS['egw_info']['server']['install_id']))
229 229
 			{
230
-				$GLOBALS['egw_info']['server']['install_id']  = md5(common::randomstring(15));
230
+				$GLOBALS['egw_info']['server']['install_id'] = md5(common::randomstring(15));
231 231
 			}
232 232
 			if (!isset($GLOBALS['egw_info']['server']['max_history']))
233 233
 			{
@@ -239,12 +239,12 @@  discard block
 block discarded – undo
239 239
 			{
240 240
 				$config = new config('phpgwapi');
241 241
 				$config->read_repository();
242
-				$config->value('max_access_log_age',$GLOBALS['egw_info']['server']['max_access_log_age']);
243
-				$config->value('block_time',$GLOBALS['egw_info']['server']['block_time']);
244
-				$config->value('num_unsuccessful_id',$GLOBALS['egw_info']['server']['num_unsuccessful_id']);
245
-				$config->value('num_unsuccessful_ip',$GLOBALS['egw_info']['server']['num_unsuccessful_ip']);
246
-				$config->value('install_id',$GLOBALS['egw_info']['server']['install_id']);
247
-				$config->value('max_history',$GLOBALS['egw_info']['server']['max_history']);
242
+				$config->value('max_access_log_age', $GLOBALS['egw_info']['server']['max_access_log_age']);
243
+				$config->value('block_time', $GLOBALS['egw_info']['server']['block_time']);
244
+				$config->value('num_unsuccessful_id', $GLOBALS['egw_info']['server']['num_unsuccessful_id']);
245
+				$config->value('num_unsuccessful_ip', $GLOBALS['egw_info']['server']['num_unsuccessful_ip']);
246
+				$config->value('install_id', $GLOBALS['egw_info']['server']['install_id']);
247
+				$config->value('max_history', $GLOBALS['egw_info']['server']['max_history']);
248 248
 				$config->save_repository();
249 249
 			}
250 250
 		}
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
 		// set session_timeout from global php.ini and default to 14400=4h, if not set
254 254
 		if (!($GLOBALS['egw_info']['server']['sessions_timeout'] = ini_get('session.gc_maxlifetime')))
255 255
       	{
256
-      		ini_set('session.gc_maxlifetime', $GLOBALS['egw_info']['server']['sessions_timeout']=14400);
256
+      		ini_set('session.gc_maxlifetime', $GLOBALS['egw_info']['server']['sessions_timeout'] = 14400);
257 257
       	}
258 258
 	}
259 259
 
@@ -323,15 +323,15 @@  discard block
 block discarded – undo
323 323
 
324 324
 		if (!isset($_SESSION[self::EGW_SESSION_ENCRYPTED]) && self::init_crypt($kp3))
325 325
 		{
326
-			foreach(self::$egw_session_vars as $name)
326
+			foreach (self::$egw_session_vars as $name)
327 327
 			{
328 328
 				if (isset($_SESSION[$name]))
329 329
 				{
330
-					$_SESSION[$name] = mcrypt_generic(self::$mcrypt,serialize($_SESSION[$name]));
330
+					$_SESSION[$name] = mcrypt_generic(self::$mcrypt, serialize($_SESSION[$name]));
331 331
 					//error_log(__METHOD__."() 'encrypting' session var: $name, len=".strlen($_SESSION[$name]));
332 332
 				}
333 333
 			}
334
-			$_SESSION[self::EGW_SESSION_ENCRYPTED] = true;	// flag session as encrypted
334
+			$_SESSION[self::EGW_SESSION_ENCRYPTED] = true; // flag session as encrypted
335 335
 
336 336
 			mcrypt_generic_deinit(self::$mcrypt);
337 337
 			self::$mcrypt = null;
@@ -346,24 +346,24 @@  discard block
 block discarded – undo
346 346
 	 * @param boolean $recursion =true if true call itself for every item > $limit
347 347
 	 * @param int $limit =1000 log only differences > $limit
348 348
 	 */
349
-	static function log_session_usage(&$arr,$label,$recursion=true,$limit=1000)
349
+	static function log_session_usage(&$arr, $label, $recursion = true, $limit = 1000)
350 350
 	{
351 351
 		if (!is_array($arr)) return;
352 352
 
353 353
 		$sizes = array();
354
-		foreach($arr as $key => &$data)
354
+		foreach ($arr as $key => &$data)
355 355
 		{
356 356
 			$sizes[$key] = strlen(serialize($data));
357 357
 		}
358
-		arsort($sizes,SORT_NUMERIC);
359
-		foreach($sizes as $key => $size)
358
+		arsort($sizes, SORT_NUMERIC);
359
+		foreach ($sizes as $key => $size)
360 360
 		{
361 361
 			$diff = $size - (int)$_SESSION[$label.'-sizes'][$key];
362 362
 			$_SESSION[$label.'-sizes'][$key] = $size;
363 363
 			if ($diff > $limit)
364 364
 			{
365 365
 				error_log("strlen({$label}[$key])=".egw_vfs::hsize($size).", diff=".egw_vfs::hsize($diff));
366
-				if ($recursion) self::log_session_usage($arr[$key],$label.'['.$key.']',$recursion,$limit);
366
+				if ($recursion) self::log_session_usage($arr[$key], $label.'['.$key.']', $recursion, $limit);
367 367
 			}
368 368
 		}
369 369
 	}
@@ -378,15 +378,15 @@  discard block
 block discarded – undo
378 378
 	{
379 379
 		if ($_SESSION[self::EGW_SESSION_ENCRYPTED] && self::init_crypt(self::get_request('kp3')))
380 380
 		{
381
-			foreach(self::$egw_session_vars as $name)
381
+			foreach (self::$egw_session_vars as $name)
382 382
 			{
383 383
 				if (isset($_SESSION[$name]))
384 384
 				{
385
-					$_SESSION[$name] = unserialize(trim(mdecrypt_generic(self::$mcrypt,$_SESSION[$name])));
385
+					$_SESSION[$name] = unserialize(trim(mdecrypt_generic(self::$mcrypt, $_SESSION[$name])));
386 386
 					//error_log(__METHOD__."() 'decrypting' session var $name: gettype($name) = ".gettype($_SESSION[$name]));
387 387
 				}
388 388
 			}
389
-			unset($_SESSION[self::EGW_SESSION_ENCRYPTED]);	// delete encryption flag
389
+			unset($_SESSION[self::EGW_SESSION_ENCRYPTED]); // delete encryption flag
390 390
 		}
391 391
 	}
392 392
 
@@ -399,15 +399,15 @@  discard block
 block discarded – undo
399 399
 	 * @param string $mode =self::MCRYPT_MODE
400 400
 	 * @return boolean true if encryption is used, false otherwise
401 401
 	 */
402
-	static private function init_crypt($kp3,$algo=self::MCRYPT_ALGO,$mode=self::MCRYPT_MODE)
402
+	static private function init_crypt($kp3, $algo = self::MCRYPT_ALGO, $mode = self::MCRYPT_MODE)
403 403
 	{
404
-		if(!$GLOBALS['egw_info']['server']['mcrypt_enabled'])
404
+		if (!$GLOBALS['egw_info']['server']['mcrypt_enabled'])
405 405
 		{
406
-			return false;	// session encryption is switched off
406
+			return false; // session encryption is switched off
407 407
 		}
408 408
 		if ($GLOBALS['egw_info']['currentapp'] == 'syncml' || !$kp3)
409 409
 		{
410
-			$kp3 = 'staticsyncmlkp3';	// syncml has no kp3!
410
+			$kp3 = 'staticsyncmlkp3'; // syncml has no kp3!
411 411
 		}
412 412
 		if (is_null(self::$mcrypt))
413 413
 		{
@@ -423,9 +423,9 @@  discard block
 block discarded – undo
423 423
 			}
424 424
 			$iv_size = mcrypt_enc_get_iv_size(self::$mcrypt);
425 425
 			$iv = !isset($GLOBALS['egw_info']['server']['mcrypt_iv']) || strlen($GLOBALS['egw_info']['server']['mcrypt_iv']) < $iv_size ?
426
-				mcrypt_create_iv ($iv_size, MCRYPT_RAND) : substr($GLOBALS['egw_info']['server']['mcrypt_iv'],0,$iv_size);
426
+				mcrypt_create_iv($iv_size, MCRYPT_RAND) : substr($GLOBALS['egw_info']['server']['mcrypt_iv'], 0, $iv_size);
427 427
 
428
-			if (mcrypt_generic_init(self::$mcrypt,$kp3, $iv) < 0)
428
+			if (mcrypt_generic_init(self::$mcrypt, $kp3, $iv) < 0)
429 429
 			{
430 430
 				error_log(__METHOD__."() could not initialise mcrypt, sessions get NOT encrypted!");
431 431
 				return self::$mcrypt = false;
@@ -445,7 +445,7 @@  discard block
 block discarded – undo
445 445
 	 * @param boolean $fail_on_forced_password_change =false true: do NOT create session, if password change requested
446 446
 	 * @return string|boolean session id or false if session was not created, $this->(cd_)reason contains cause
447 447
 	 */
448
-	function create($login,$passwd = '',$passwd_type = '',$no_session=false,$auth_check=true,$fail_on_forced_password_change=false)
448
+	function create($login, $passwd = '', $passwd_type = '', $no_session = false, $auth_check = true, $fail_on_forced_password_change = false)
449 449
 	{
450 450
 		try {
451 451
 			if (is_array($login))
@@ -463,9 +463,9 @@  discard block
 block discarded – undo
463 463
 			}
464 464
 			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) starting ...");
465 465
 
466
-			self::split_login_domain($login,$this->account_lid,$this->account_domain);
466
+			self::split_login_domain($login, $this->account_lid, $this->account_domain);
467 467
 			// add domain to the login, if not already there
468
-			if (substr($this->login,-strlen($this->account_domain)-1) != '@'.$this->account_domain)
468
+			if (substr($this->login, -strlen($this->account_domain) - 1) != '@'.$this->account_domain)
469 469
 			{
470 470
 				$this->login .= '@'.$this->account_domain;
471 471
 			}
@@ -482,7 +482,7 @@  discard block
 block discarded – undo
482 482
 			{
483 483
 				$this->account_domain = $GLOBALS['egw_info']['user']['domain'];
484 484
 			}
485
-			elseif($this->account_domain != $GLOBALS['egw_info']['user']['domain'])
485
+			elseif ($this->account_domain != $GLOBALS['egw_info']['user']['domain'])
486 486
 			{
487 487
 				throw new Exception("Wrong domain! '$this->account_domain' != '{$GLOBALS['egw_info']['user']['domain']}'");
488 488
 			}
@@ -491,9 +491,9 @@  discard block
 block discarded – undo
491 491
 			//echo "<p>session::create(login='$login'): lid='$this->account_lid', domain='$this->account_domain'</p>\n";
492 492
 			$user_ip = self::getuser_ip();
493 493
 
494
-			$this->account_id = $GLOBALS['egw']->accounts->name2id($this->account_lid,'account_lid','u');
494
+			$this->account_id = $GLOBALS['egw']->accounts->name2id($this->account_lid, 'account_lid', 'u');
495 495
 
496
-			if (($blocked = $this->login_blocked($login,$user_ip)) ||	// too many unsuccessful attempts
496
+			if (($blocked = $this->login_blocked($login, $user_ip)) || // too many unsuccessful attempts
497 497
 				$GLOBALS['egw_info']['server']['global_denied_users'][$this->account_lid] ||
498 498
 				$auth_check && !$GLOBALS['egw']->auth->authenticate($this->account_lid, $this->passwd, $this->passwd_type) ||
499 499
 				$this->account_id && $GLOBALS['egw']->accounts->get_type($this->account_id) == 'g')
@@ -502,9 +502,9 @@  discard block
 block discarded – undo
502 502
 				$this->cd_reason = $blocked ? self::CD_BLOCKED : self::CD_BAD_LOGIN_OR_PASSWORD;
503 503
 
504 504
 				// we dont log anon users as it would block the website
505
-				if (!$GLOBALS['egw']->acl->get_specific_rights_for_account($this->account_id,'anonymous','phpgwapi'))
505
+				if (!$GLOBALS['egw']->acl->get_specific_rights_for_account($this->account_id, 'anonymous', 'phpgwapi'))
506 506
 				{
507
-					$this->log_access($this->reason,$login,$user_ip,0);	// log unsuccessfull login
507
+					$this->log_access($this->reason, $login, $user_ip, 0); // log unsuccessfull login
508 508
 				}
509 509
 				if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)");
510 510
 				return false;
@@ -526,7 +526,7 @@  discard block
 block discarded – undo
526 526
 			if ($this->account_lid != ($lid = $GLOBALS['egw']->accounts->id2name($this->account_id)))
527 527
 			{
528 528
 				$this->account_lid = $lid;
529
-				$this->login = $lid.substr($this->login,strlen($lid));
529
+				$this->login = $lid.substr($this->login, strlen($lid));
530 530
 			}
531 531
 
532 532
 			$GLOBALS['egw_info']['user']['account_id'] = $this->account_id;
@@ -549,7 +549,7 @@  discard block
 block discarded – undo
549 549
 				}
550 550
 				$this->sessionid = session_id();
551 551
 			}
552
-			$this->kp3       = common::randomstring(24);
552
+			$this->kp3 = common::randomstring(24);
553 553
 
554 554
 			$GLOBALS['egw_info']['user'] = $this->read_repositories();
555 555
 			if ($GLOBALS['egw']->accounts->is_expired($GLOBALS['egw_info']['user']))
@@ -563,7 +563,7 @@  discard block
 block discarded – undo
563 563
 
564 564
 			egw_cache::setSession('phpgwapi', 'password', base64_encode($this->passwd));
565 565
 
566
-			if ($GLOBALS['egw']->acl->check('anonymous',1,'phpgwapi'))
566
+			if ($GLOBALS['egw']->acl->check('anonymous', 1, 'phpgwapi'))
567 567
 			{
568 568
 				$this->session_flags = 'A';
569 569
 			}
@@ -581,39 +581,39 @@  discard block
 block discarded – undo
581 581
 				'passwd'         => $this->passwd,
582 582
 				'account_domain' => $this->account_domain,
583 583
 				'user_ip'        => $user_ip,
584
-			),'',true)))	// true = run hooks from all apps, not just the ones the current user has perms to run
584
+			), '', true)))	// true = run hooks from all apps, not just the ones the current user has perms to run
585 585
 			{
586
-				foreach($hook_result as $reason)
586
+				foreach ($hook_result as $reason)
587 587
 				{
588 588
 					if ($reason)	// called hook requests to deny the session
589 589
 					{
590 590
 						$this->reason = $this->cd_reason = $reason;
591
-						$this->log_access($this->reason,$login,$user_ip,0);		// log unsuccessfull login
591
+						$this->log_access($this->reason, $login, $user_ip, 0); // log unsuccessfull login
592 592
 						if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)");
593 593
 						return false;
594 594
 					}
595 595
 				}
596 596
 			}
597 597
 			$GLOBALS['egw']->db->transaction_begin();
598
-			$this->register_session($this->login,$user_ip,$now,$this->session_flags);
598
+			$this->register_session($this->login, $user_ip, $now, $this->session_flags);
599 599
 			if ($this->session_flags != 'A')		// dont log anonymous sessions
600 600
 			{
601
-				$this->sessionid_access_log = $this->log_access($this->sessionid,$login,$user_ip,$this->account_id);
601
+				$this->sessionid_access_log = $this->log_access($this->sessionid, $login, $user_ip, $this->account_id);
602 602
 			}
603
-			self::appsession('account_previous_login','phpgwapi',$GLOBALS['egw']->auth->previous_login);
604
-			$GLOBALS['egw']->accounts->update_lastlogin($this->account_id,$user_ip);
603
+			self::appsession('account_previous_login', 'phpgwapi', $GLOBALS['egw']->auth->previous_login);
604
+			$GLOBALS['egw']->accounts->update_lastlogin($this->account_id, $user_ip);
605 605
 			$GLOBALS['egw']->db->transaction_commit();
606 606
 
607 607
 			if ($GLOBALS['egw_info']['server']['usecookies'] && !$no_session)
608 608
 			{
609
-				self::egw_setcookie(self::EGW_SESSION_NAME,$this->sessionid);
610
-				self::egw_setcookie('kp3',$this->kp3);
611
-				self::egw_setcookie('domain',$this->account_domain);
609
+				self::egw_setcookie(self::EGW_SESSION_NAME, $this->sessionid);
610
+				self::egw_setcookie('kp3', $this->kp3);
611
+				self::egw_setcookie('domain', $this->account_domain);
612 612
 			}
613 613
 			if ($GLOBALS['egw_info']['server']['usecookies'] && !$no_session || isset($_COOKIE['last_loginid']))
614 614
 			{
615
-				self::egw_setcookie('last_loginid', $this->account_lid ,$now+1209600); /* For 2 weeks */
616
-				self::egw_setcookie('last_domain',$this->account_domain,$now+1209600);
615
+				self::egw_setcookie('last_loginid', $this->account_lid, $now + 1209600); /* For 2 weeks */
616
+				self::egw_setcookie('last_domain', $this->account_domain, $now + 1209600);
617 617
 			}
618 618
 			//if (!$this->sessionid) echo "<p>session::create(login='$login') = '$this->sessionid': lid='$this->account_lid', domain='$this->account_domain'</p>\n";
619 619
 			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) successfull sessionid=$this->sessionid");
@@ -621,7 +621,7 @@  discard block
 block discarded – undo
621 621
 			return $this->sessionid;
622 622
 		}
623 623
 		// catch all exceptions, as their (allways logged) trace (eg. on a database error) would contain the user password
624
-		catch(Exception $e) {
624
+		catch (Exception $e) {
625 625
 			$this->reason = $this->cd_reason = $e->getMessage();
626 626
 			error_log(__METHOD__."('$login', ".array2string(str_repeat('*', strlen($passwd))).
627 627
 				", '$passwd_type', no_session=".array2string($no_session).
@@ -640,13 +640,12 @@  discard block
 block discarded – undo
640 640
 	 * @param int $now
641 641
 	 * @param string $session_flags
642 642
 	 */
643
-	private function register_session($login,$user_ip,$now,$session_flags)
643
+	private function register_session($login, $user_ip, $now, $session_flags)
644 644
 	{
645 645
 		// restore session vars set before session was started
646 646
 		if (is_array($this->required_files))
647 647
 		{
648
-			$_SESSION[self::EGW_REQUIRED_FILES] = !is_array($_SESSION[self::EGW_REQUIRED_FILES]) ? $this->required_files :
649
-				array_unique(array_merge($_SESSION[self::EGW_REQUIRED_FILES],$this->required_files));
648
+			$_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));
650 649
 			unset($this->required_files);
651 650
 		}
652 651
 		$_SESSION[self::EGW_SESSION_VAR] = array(
@@ -676,13 +675,13 @@  discard block
 block discarded – undo
676 675
 	* @param int $account_id =0 numerical account_id
677 676
 	* @return int $sessionid primary key of egw_access_log for login, null otherwise
678 677
 	*/
679
-	private function log_access($sessionid,$login='',$user_ip='',$account_id=0)
678
+	private function log_access($sessionid, $login = '', $user_ip = '', $account_id = 0)
680 679
 	{
681 680
 		$now = time();
682 681
 
683 682
 		if ($login)
684 683
 		{
685
-			$GLOBALS['egw']->db->insert(self::ACCESS_LOG_TABLE,array(
684
+			$GLOBALS['egw']->db->insert(self::ACCESS_LOG_TABLE, array(
686 685
 				'session_php' => $sessionid,
687 686
 				'loginid'   => $login,
688 687
 				'ip'        => $user_ip,
@@ -690,10 +689,10 @@  discard block
 block discarded – undo
690 689
 				'account_id'=> $account_id,
691 690
 				'user_agent'=> $_SERVER['HTTP_USER_AGENT'],
692 691
 				'session_dla'    => $now,
693
-				'session_action' => $this->update_dla(false),	// dont update egw_access_log
694
-			),false,__LINE__,__FILE__);
692
+				'session_action' => $this->update_dla(false), // dont update egw_access_log
693
+			), false, __LINE__, __FILE__);
695 694
 
696
-			$ret = $GLOBALS['egw']->db->get_last_insert_id(self::ACCESS_LOG_TABLE,'sessionid');
695
+			$ret = $GLOBALS['egw']->db->get_last_insert_id(self::ACCESS_LOG_TABLE, 'sessionid');
697 696
 		}
698 697
 		else
699 698
 		{
@@ -701,20 +700,20 @@  discard block
 block discarded – undo
701 700
 			{
702 701
 				$sessionid = $this->sessionid_access_log;
703 702
 			}
704
-			$GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE,array(
703
+			$GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE, array(
705 704
 				'lo' => $now
706
-			),is_numeric($sessionid) ? array(
705
+			), is_numeric($sessionid) ? array(
707 706
 				'sessionid' => $sessionid,
708 707
 			) : array(
709 708
 				'session_php' => $sessionid,
710
-			),__LINE__,__FILE__);
709
+			), __LINE__, __FILE__);
711 710
 
712 711
 			// run maintenance only on logout, to not delay login
713 712
 			if ($GLOBALS['egw_info']['server']['max_access_log_age'])
714 713
 			{
715 714
 				$max_age = $now - $GLOBALS['egw_info']['server']['max_access_log_age'] * 24 * 60 * 60;
716 715
 
717
-				$GLOBALS['egw']->db->delete(self::ACCESS_LOG_TABLE,"li < $max_age",__LINE__,__FILE__);
716
+				$GLOBALS['egw']->db->delete(self::ACCESS_LOG_TABLE, "li < $max_age", __LINE__, __FILE__);
718 717
 			}
719 718
 		}
720 719
 		//error_log(__METHOD__."('$sessionid', '$login', '$user_ip', $account_id) returning ".array2string($ret));
@@ -728,12 +727,12 @@  discard block
 block discarded – undo
728 727
 	 * @param string $ip ip of the user
729 728
 	 * @returns bool login blocked?
730 729
 	 */
731
-	private function login_blocked($login,$ip)
730
+	private function login_blocked($login, $ip)
732 731
 	{
733 732
 		$block_time = time() - $GLOBALS['egw_info']['server']['block_time'] * 60;
734 733
 
735 734
 		$false_id = $false_ip = 0;
736
-		foreach($GLOBALS['egw']->db->union(array(
735
+		foreach ($GLOBALS['egw']->db->union(array(
737 736
 			array(
738 737
 				'table' => self::ACCESS_LOG_TABLE,
739 738
 				'cols'  => "'false_ip' AS name,COUNT(*) AS num",
@@ -770,28 +769,28 @@  discard block
 block discarded – undo
770 769
 		//error_log(__METHOD__."('$login', '$ip') false_ip=$false_ip, false_id=$false_id --> blocked=".array2string($blocked));
771 770
 
772 771
 		if ($blocked && $GLOBALS['egw_info']['server']['admin_mails'] &&
773
-			$GLOBALS['egw_info']['server']['login_blocked_mail_time'] < time()-5*60)	// max. one mail every 5mins
772
+			$GLOBALS['egw_info']['server']['login_blocked_mail_time'] < time() - 5 * 60)	// max. one mail every 5mins
774 773
 		{
775 774
 			try {
776 775
 				$mailer = new egw_mailer();
777 776
 				// notify admin(s) via email
778 777
 				$mailer->setFrom('eGroupWare@'.$GLOBALS['egw_info']['server']['mail_suffix']);
779
-				$mailer->addHeader('Subject', lang("eGroupWare: login blocked for user '%1', IP %2",$login,$ip));
780
-				$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));
781
-				foreach(preg_split('/,\s*/',$GLOBALS['egw_info']['server']['admin_mails']) as $mail)
778
+				$mailer->addHeader('Subject', lang("eGroupWare: login blocked for user '%1', IP %2", $login, $ip));
779
+				$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));
780
+				foreach (preg_split('/,\s*/', $GLOBALS['egw_info']['server']['admin_mails']) as $mail)
782 781
 				{
783 782
 					$mailer->addAddress($mail);
784 783
 				}
785 784
 				$mailer->send();
786 785
 			}
787
-			catch(Exception $e) {
786
+			catch (Exception $e) {
788 787
 				// ignore exception, but log it, to block the account and give a correct error-message to user
789 788
 				error_log(__METHOD__."('$login', '$ip') ".$e->getMessage());
790 789
 			}
791 790
 			// save time of mail, to not send to many mails
792 791
 			$config = new config('phpgwapi');
793 792
 			$config->read_repository();
794
-			$config->value('login_blocked_mail_time',time());
793
+			$config->value('login_blocked_mail_time', time());
795 794
 			$config->save_repository();
796 795
 		}
797 796
 		return $blocked;
@@ -812,7 +811,7 @@  discard block
 block discarded – undo
812 811
 	 * @param boolean $only_basic_auth =false return only a basic auth pseudo sessionid, default no
813 812
 	 * @return string
814 813
 	 */
815
-	static function get_sessionid($only_basic_auth=false)
814
+	static function get_sessionid($only_basic_auth = false)
816 815
 	{
817 816
 		// for WebDAV and GroupDAV we use a pseudo sessionid created from md5(user:passwd)
818 817
 		// --> allows this stateless protocolls which use basic auth to use sessions!
@@ -839,11 +838,11 @@  discard block
 block discarded – undo
839 838
 				EGW_SERVER_ROOT.':'.self::getuser_ip().':'.filemtime(EGW_SERVER_ROOT.'/phpgwapi/setup/setup.inc.php').
840 839
 				':'.$_SERVER['HTTP_USER_AGENT']);
841 840
 		}
842
-		elseif(!$only_basic_auth && isset($_REQUEST[self::EGW_SESSION_NAME]))
841
+		elseif (!$only_basic_auth && isset($_REQUEST[self::EGW_SESSION_NAME]))
843 842
 		{
844 843
 			$sessionid = $_REQUEST[self::EGW_SESSION_NAME];
845 844
 		}
846
-		elseif(!$only_basic_auth && isset($_COOKIE[self::EGW_SESSION_NAME]))
845
+		elseif (!$only_basic_auth && isset($_COOKIE[self::EGW_SESSION_NAME]))
847 846
 		{
848 847
 			$sessionid = $_COOKIE[self::EGW_SESSION_NAME];
849 848
 		}
@@ -851,7 +850,7 @@  discard block
 block discarded – undo
851 850
 		{
852 851
 			$sessionid = false;
853 852
 		}
854
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() _SERVER[REQUEST_URI]='$_SERVER[REQUEST_URI]' returning ".print_r($sessionid,true));
853
+		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() _SERVER[REQUEST_URI]='$_SERVER[REQUEST_URI]' returning ".print_r($sessionid, true));
855 854
 		return $sessionid;
856 855
 	}
857 856
 
@@ -867,9 +866,7 @@  discard block
 block discarded – undo
867 866
 	 */
868 867
 	static function get_request($name)
869 868
 	{
870
-		return isset($_REQUEST[$name]) ? $_REQUEST[$name] :
871
-			(isset($_COOKIE[$name]) ? $_COOKIE[$name] :
872
-			(isset($_COOKIE[$name=ucfirst($name)]) ? $_COOKIE[$name] : null));
869
+		return isset($_REQUEST[$name]) ? $_REQUEST[$name] : (isset($_COOKIE[$name]) ? $_COOKIE[$name] : (isset($_COOKIE[$name = ucfirst($name)]) ? $_COOKIE[$name] : null));
873 870
 	}
874 871
 
875 872
 	/**
@@ -879,13 +876,13 @@  discard block
 block discarded – undo
879 876
 	 * @param string $kp3 ?? to be verified
880 877
 	 * @return bool is the session valid?
881 878
 	 */
882
-	function verify($sessionid=null,$kp3=null)
879
+	function verify($sessionid = null, $kp3 = null)
883 880
 	{
884 881
 		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid','$kp3') ".function_backtrace());
885 882
 
886 883
 		$fill_egw_info_and_repositories = !$GLOBALS['egw_info']['flags']['restored_from_session'];
887 884
 
888
-		if(!$sessionid)
885
+		if (!$sessionid)
889 886
 		{
890 887
 			$sessionid = self::get_sessionid();
891 888
 			$kp3       = self::get_request('kp3');
@@ -912,23 +909,23 @@  discard block
 block discarded – undo
912 909
 			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid') session does NOT exist!");
913 910
 			return false;
914 911
 		}
915
-		$session =& $_SESSION[self::EGW_SESSION_VAR];
912
+		$session = & $_SESSION[self::EGW_SESSION_VAR];
916 913
 
917 914
 		if ($session['session_dla'] <= time() - $GLOBALS['egw_info']['server']['sessions_timeout'])
918 915
 		{
919 916
 			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid') session timed out!");
920
-			$this->destroy($sessionid,$kp3);
917
+			$this->destroy($sessionid, $kp3);
921 918
 			return false;
922 919
 		}
923 920
 
924 921
 		$this->session_flags = $session['session_flags'];
925 922
 
926
-		$this->split_login_domain($session['session_lid'],$this->account_lid,$this->account_domain);
923
+		$this->split_login_domain($session['session_lid'], $this->account_lid, $this->account_domain);
927 924
 
928 925
 		// This is to ensure that we authenticate to the correct domain (might not be default)
929
-		if($GLOBALS['egw_info']['user']['domain'] && $this->account_domain != $GLOBALS['egw_info']['user']['domain'])
926
+		if ($GLOBALS['egw_info']['user']['domain'] && $this->account_domain != $GLOBALS['egw_info']['user']['domain'])
930 927
 		{
931
-			return false;	// session not verified, domain changed
928
+			return false; // session not verified, domain changed
932 929
 		}
933 930
 		$GLOBALS['egw_info']['user']['kp3'] = $this->kp3;
934 931
 
@@ -941,7 +938,7 @@  discard block
 block discarded – undo
941 938
 		{
942 939
 			$this->update_notification_heartbeat();
943 940
 		}
944
-		$this->account_id = $GLOBALS['egw']->accounts->name2id($this->account_lid,'account_lid','u');
941
+		$this->account_id = $GLOBALS['egw']->accounts->name2id($this->account_lid, 'account_lid', 'u');
945 942
 		if (!$this->account_id)
946 943
 		{
947 944
 			if (self::ERROR_LOG_DEBUG) error_log("*** session::verify($sessionid) !accounts::name2id('$this->account_lid')");
@@ -979,7 +976,7 @@  discard block
 block discarded – undo
979 976
 
980 977
 		if ($GLOBALS['egw_info']['server']['sessions_checkip'])
981 978
 		{
982
-			if (strtoupper(substr(PHP_OS,0,3)) != 'WIN' && (!$GLOBALS['egw_info']['user']['session_ip'] ||
979
+			if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN' && (!$GLOBALS['egw_info']['user']['session_ip'] ||
983 980
 				$GLOBALS['egw_info']['user']['session_ip'] != $this->getuser_ip()))
984 981
 			{
985 982
 				if (self::ERROR_LOG_DEBUG) error_log("*** session::verify($sessionid) wrong IP");
@@ -1002,9 +999,9 @@  discard block
 block discarded – undo
1002 999
 		// query accesslog-id, if not set in session (session is made persistent after login!)
1003 1000
 		if (!$this->sessionid_access_log && $this->session_flags != 'A')
1004 1001
 		{
1005
-			$this->sessionid_access_log = $GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE,'sessionid',array(
1002
+			$this->sessionid_access_log = $GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE, 'sessionid', array(
1006 1003
 				'session_php' => $this->sessionid,
1007
-			),__LINE__,__FILE__)->fetchColumn();
1004
+			), __LINE__, __FILE__)->fetchColumn();
1008 1005
 			//error_log(__METHOD__."() sessionid=$this->sessionid --> sessionid_access_log=$this->sessionid_access_log");
1009 1006
 		}
1010 1007
 
@@ -1015,9 +1012,9 @@  discard block
 block discarded – undo
1015 1012
 			(!isset($_COOKIE[self::EGW_SESSION_NAME]) || $_COOKIE[self::EGW_SESSION_NAME] !== $_REQUEST[self::EGW_SESSION_NAME]))
1016 1013
 		{
1017 1014
 			if (self::ERROR_LOG_DEBUG) error_log("--> session::verify($sessionid) SUCCESS, but NO required cookies set --> setting them now");
1018
-			self::egw_setcookie(self::EGW_SESSION_NAME,$this->sessionid);
1019
-			self::egw_setcookie('kp3',$this->kp3);
1020
-			self::egw_setcookie('domain',$this->account_domain);
1015
+			self::egw_setcookie(self::EGW_SESSION_NAME, $this->sessionid);
1016
+			self::egw_setcookie('kp3', $this->kp3);
1017
+			self::egw_setcookie('domain', $this->account_domain);
1021 1018
 		}
1022 1019
 
1023 1020
 		if (self::ERROR_LOG_DEBUG) error_log("--> session::verify($sessionid) SUCCESS");
@@ -1032,27 +1029,27 @@  discard block
 block discarded – undo
1032 1029
 	 * @param string $kp3
1033 1030
 	 * @return boolean true on success, false on error
1034 1031
 	 */
1035
-	function destroy($sessionid, $kp3='')
1032
+	function destroy($sessionid, $kp3 = '')
1036 1033
 	{
1037 1034
 		if (!$sessionid && $kp3)
1038 1035
 		{
1039 1036
 			return false;
1040 1037
 		}
1041
-		$this->log_access($sessionid);	// log logout-time
1038
+		$this->log_access($sessionid); // log logout-time
1042 1039
 
1043 1040
 		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($sessionid,$kp3)");
1044 1041
 
1045 1042
 		if (is_numeric($sessionid))	// do we have a access-log-id --> get PHP session id
1046 1043
 		{
1047
-			$sessionid = $GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE,'session_php',array(
1044
+			$sessionid = $GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE, 'session_php', array(
1048 1045
 					'sessionid' => $sessionid,
1049
-				),__LINE__,__FILE__)->fetchColumn();
1046
+				), __LINE__, __FILE__)->fetchColumn();
1050 1047
 		}
1051 1048
 
1052 1049
 		$GLOBALS['egw']->hooks->process(array(
1053 1050
 			'location'  => 'session_destroyed',
1054 1051
 			'sessionid' => $sessionid,
1055
-		),'',true);	// true = run hooks from all apps, not just the ones the current user has perms to run
1052
+		), '', true); // true = run hooks from all apps, not just the ones the current user has perms to run
1056 1053
 
1057 1054
 		// Only do the following, if where working with the current user
1058 1055
 		if (!$GLOBALS['egw_info']['user']['sessionid'] || $sessionid == $GLOBALS['egw_info']['user']['sessionid'])
@@ -1074,7 +1071,7 @@  discard block
 block discarded – undo
1074 1071
 		}
1075 1072
 		else
1076 1073
 		{
1077
-			$this->commit_session();	// close our own session
1074
+			$this->commit_session(); // close our own session
1078 1075
 
1079 1076
 			session_id($sessionid);
1080 1077
 			if (session_start())
@@ -1114,25 +1111,25 @@  discard block
 block discarded – undo
1114 1111
 		// as $webserver_url may be part of $url (as /egw is part of phpgwapi/js/egw_instant_load.html)
1115 1112
 		if (($url[0] != '/' || $webserver_url != '/') && (!$webserver_url || strpos($url, $webserver_url.'/') === false))
1116 1113
 		{
1117
-			if($url[0] != '/' && substr($webserver_url,-1) != '/')
1114
+			if ($url[0] != '/' && substr($webserver_url, -1) != '/')
1118 1115
 			{
1119
-				$url = $webserver_url .'/'. $url;
1116
+				$url = $webserver_url.'/'.$url;
1120 1117
 			}
1121 1118
 			else
1122 1119
 			{
1123
-				$url = $webserver_url . $url;
1120
+				$url = $webserver_url.$url;
1124 1121
 			}
1125 1122
 		}
1126 1123
 
1127
-		if(isset($GLOBALS['egw_info']['server']['enforce_ssl']) && $GLOBALS['egw_info']['server']['enforce_ssl'])
1124
+		if (isset($GLOBALS['egw_info']['server']['enforce_ssl']) && $GLOBALS['egw_info']['server']['enforce_ssl'])
1128 1125
 		{
1129
-			if(substr($url ,0,4) != 'http')
1126
+			if (substr($url, 0, 4) != 'http')
1130 1127
 			{
1131 1128
 				$url = 'https://'.$_SERVER['HTTP_HOST'].$url;
1132 1129
 			}
1133 1130
 			else
1134 1131
 			{
1135
-				$url = str_replace ( 'http:', 'https:', $url);
1132
+				$url = str_replace('http:', 'https:', $url);
1136 1133
 			}
1137 1134
 		}
1138 1135
 		$vars = array();
@@ -1145,7 +1142,7 @@  discard block
 block discarded – undo
1145 1142
 		}
1146 1143
 
1147 1144
 		// check if the url already contains a query and ensure that vars is an array and all strings are in extravars
1148
-		list($ret_url,$othervars) = explode('?', $url, 2);
1145
+		list($ret_url, $othervars) = explode('?', $url, 2);
1149 1146
 		if ($extravars && is_array($extravars))
1150 1147
 		{
1151 1148
 			$vars += $extravars;
@@ -1153,19 +1150,19 @@  discard block
 block discarded – undo
1153 1150
 		}
1154 1151
 		else
1155 1152
 		{
1156
-			if ($othervars) $extravars .= ($extravars?'&':'').$othervars;
1153
+			if ($othervars) $extravars .= ($extravars ? '&' : '').$othervars;
1157 1154
 		}
1158 1155
 
1159 1156
 		// parse extravars string into the vars array
1160 1157
 		if ($extravars)
1161 1158
 		{
1162
-			foreach(explode('&',$extravars) as $expr)
1159
+			foreach (explode('&', $extravars) as $expr)
1163 1160
 			{
1164
-				list($var,$val) = explode('=', $expr,2);
1165
-				if (strpos($val,'%26') != false) $val = str_replace('%26','&',$val);	// make sure to not double encode &
1166
-				if (substr($var,-2) == '[]')
1161
+				list($var, $val) = explode('=', $expr, 2);
1162
+				if (strpos($val, '%26') != false) $val = str_replace('%26', '&', $val); // make sure to not double encode &
1163
+				if (substr($var, -2) == '[]')
1167 1164
 				{
1168
-					$vars[substr($var,0,-2)][] = $val;
1165
+					$vars[substr($var, 0, -2)][] = $val;
1169 1166
 				}
1170 1167
 				else
1171 1168
 				{
@@ -1178,11 +1175,11 @@  discard block
 block discarded – undo
1178 1175
 		if (count($vars))
1179 1176
 		{
1180 1177
 			$query = array();
1181
-			foreach($vars as $key => $value)
1178
+			foreach ($vars as $key => $value)
1182 1179
 			{
1183 1180
 				if (is_array($value))
1184 1181
 				{
1185
-					foreach($value as $val)
1182
+					foreach ($value as $val)
1186 1183
 					{
1187 1184
 						$query[] = $key.'[]='.urlencode($val);
1188 1185
 					}
@@ -1192,7 +1189,7 @@  discard block
 block discarded – undo
1192 1189
 					$query[] = $key.'='.urlencode($value);
1193 1190
 				}
1194 1191
 			}
1195
-			$ret_url .= '?' . implode('&',$query);
1192
+			$ret_url .= '?'.implode('&', $query);
1196 1193
 		}
1197 1194
 		return $ret_url;
1198 1195
 	}
@@ -1211,7 +1208,7 @@  discard block
 block discarded – undo
1211 1208
 		if (isset($_SESSION[self::EGW_SESSION_ENCRYPTED]))
1212 1209
 		{
1213 1210
 			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__.' called after session was encrypted --> ignored!');
1214
-			return false;	// can no longer store something in the session, eg. because commit_session() was called
1211
+			return false; // can no longer store something in the session, eg. because commit_session() was called
1215 1212
 		}
1216 1213
 		if (!$appname)
1217 1214
 		{
@@ -1221,9 +1218,9 @@  discard block
 block discarded – undo
1221 1218
 		// allow to store eg. '' as the value.
1222 1219
 		if ($data === '##NOTHING##')
1223 1220
 		{
1224
-			if(isset($_SESSION[self::EGW_APPSESSION_VAR][$appname]) && array_key_exists($location,$_SESSION[self::EGW_APPSESSION_VAR][$appname]))
1221
+			if (isset($_SESSION[self::EGW_APPSESSION_VAR][$appname]) && array_key_exists($location, $_SESSION[self::EGW_APPSESSION_VAR][$appname]))
1225 1222
 			{
1226
-				$ret =& $_SESSION[self::EGW_APPSESSION_VAR][$appname][$location];
1223
+				$ret = & $_SESSION[self::EGW_APPSESSION_VAR][$appname][$location];
1227 1224
 			}
1228 1225
 			else
1229 1226
 			{
@@ -1232,14 +1229,13 @@  discard block
 block discarded – undo
1232 1229
 		}
1233 1230
 		else
1234 1231
 		{
1235
-			$_SESSION[self::EGW_APPSESSION_VAR][$appname][$location] =& $data;
1236
-			$ret =& $_SESSION[self::EGW_APPSESSION_VAR][$appname][$location];
1232
+			$_SESSION[self::EGW_APPSESSION_VAR][$appname][$location] = & $data;
1233
+			$ret = & $_SESSION[self::EGW_APPSESSION_VAR][$appname][$location];
1237 1234
 		}
1238 1235
 		if (self::ERROR_LOG_DEBUG === 'appsession')
1239 1236
 		{
1240 1237
 			error_log(__METHOD__."($location,$appname,$data) === ".(is_scalar($ret) && strlen($ret) < 50 ?
1241
-				(is_bool($ret) ? ($ret ? '(bool)true' : '(bool)false') : $ret) :
1242
-				(strlen($r = array2string($ret)) < 50 ? $r : substr($r,0,50).' ...')));
1238
+				(is_bool($ret) ? ($ret ? '(bool)true' : '(bool)false') : $ret) : (strlen($r = array2string($ret)) < 50 ? $r : substr($r, 0, 50).' ...')));
1243 1239
 		}
1244 1240
 		return $ret;
1245 1241
 	}
@@ -1284,7 +1280,7 @@  discard block
 block discarded – undo
1284 1280
 	 * @param int $cookietime =0 when cookie should expire, 0 for session only (optional)
1285 1281
 	 * @param string $cookiepath =null optional path (eg. '/') if the eGW install-dir should not be used
1286 1282
 	 */
1287
-	public static function egw_setcookie($cookiename,$cookievalue='',$cookietime=0,$cookiepath=null)
1283
+	public static function egw_setcookie($cookiename, $cookievalue = '', $cookietime = 0, $cookiepath = null)
1288 1284
 	{
1289 1285
 		if (empty(self::$cookie_domain) || empty(self::$cookie_path))
1290 1286
 		{
@@ -1297,11 +1293,11 @@  discard block
 block discarded – undo
1297 1293
 		static $is_iOS = null;
1298 1294
 		if (!$cookietime && !isset($is_iOS)) $is_iOS = (bool)preg_match('/^(iPhone|iPad|iPod)/i', html::$ua_mobile);
1299 1295
 
1300
-		if(!headers_sent())	// gives only a warning, but can not send the cookie anyway
1296
+		if (!headers_sent())	// gives only a warning, but can not send the cookie anyway
1301 1297
 		{
1302 1298
 			setcookie($cookiename, $cookievalue,
1303
-				!$cookietime && $is_iOS ? time()+self::IOS_SESSION_COOKIE_LIFETIME : $cookietime,
1304
-				is_null($cookiepath) ? self::$cookie_path : $cookiepath,self::$cookie_domain,
1299
+				!$cookietime && $is_iOS ? time() + self::IOS_SESSION_COOKIE_LIFETIME : $cookietime,
1300
+				is_null($cookiepath) ? self::$cookie_path : $cookiepath, self::$cookie_domain,
1305 1301
 				// if called via HTTPS, only send cookie for https and only allow cookie access via HTTP (true)
1306 1302
 				empty($GLOBALS['egw_info']['server']['insecure_cookies']) && !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off', true);
1307 1303
 		}
@@ -1320,21 +1316,21 @@  discard block
 block discarded – undo
1320 1316
 		else
1321 1317
 		{
1322 1318
 			// Use HTTP_X_FORWARDED_HOST if set, which is the case behind a none-transparent proxy
1323
-			self::$cookie_domain = isset($_SERVER['HTTP_X_FORWARDED_HOST']) ?  $_SERVER['HTTP_X_FORWARDED_HOST'] : $_SERVER['HTTP_HOST'];
1319
+			self::$cookie_domain = isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : $_SERVER['HTTP_HOST'];
1324 1320
 		}
1325 1321
 		// remove port from HTTP_HOST
1326 1322
 		$arr = null;
1327
-		if (preg_match("/^(.*):(.*)$/",self::$cookie_domain,$arr))
1323
+		if (preg_match("/^(.*):(.*)$/", self::$cookie_domain, $arr))
1328 1324
 		{
1329 1325
 			self::$cookie_domain = $arr[1];
1330 1326
 		}
1331
-		if (count(explode('.',self::$cookie_domain)) <= 1)
1327
+		if (count(explode('.', self::$cookie_domain)) <= 1)
1332 1328
 		{
1333 1329
 			// setcookie dont likes domains without dots, leaving it empty, gets setcookie to fill the domain in
1334 1330
 			self::$cookie_domain = '';
1335 1331
 		}
1336 1332
 		if (!$GLOBALS['egw_info']['server']['cookiepath'] ||
1337
-			!(self::$cookie_path = parse_url($GLOBALS['egw_info']['server']['webserver_url'],PHP_URL_PATH)))
1333
+			!(self::$cookie_path = parse_url($GLOBALS['egw_info']['server']['webserver_url'], PHP_URL_PATH)))
1338 1334
 		{
1339 1335
 			self::$cookie_path = '/';
1340 1336
 		}
@@ -1355,7 +1351,7 @@  discard block
 block discarded – undo
1355 1351
 	 * @param array $domains =null defaults to $GLOBALS['egw_domain'] from the header
1356 1352
 	 * @return string $GLOBALS['egw_info']['user']['domain'] set with the domain/instance to use
1357 1353
 	 */
1358
-	public static function search_instance($login,$domain_requested,&$default_domain,$server_names,array $domains=null)
1354
+	public static function search_instance($login, $domain_requested, &$default_domain, $server_names, array $domains = null)
1359 1355
 	{
1360 1356
 		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$login','$domain_requested',".array2string($default_domain).".".array2string($server_names).".".array2string($domains).")");
1361 1357
 
@@ -1363,10 +1359,10 @@  discard block
 block discarded – undo
1363 1359
 
1364 1360
 		if (!isset($default_domain) || !isset($domains[$default_domain]))	// allow to overwrite the default domain
1365 1361
 		{
1366
-			foreach((array)$server_names as $server_name)
1362
+			foreach ((array)$server_names as $server_name)
1367 1363
 			{
1368
-				list($server_name) = explode(':', $server_name);	// remove port from HTTP_HOST
1369
-				if(isset($domains[$server_name]))
1364
+				list($server_name) = explode(':', $server_name); // remove port from HTTP_HOST
1365
+				if (isset($domains[$server_name]))
1370 1366
 				{
1371 1367
 					$default_domain = $server_name;
1372 1368
 					break;
@@ -1376,7 +1372,7 @@  discard block
 block discarded – undo
1376 1372
 					$parts = explode('.', $server_name);
1377 1373
 					array_shift($parts);
1378 1374
 					$domain_part = implode('.', $parts);
1379
-					if(isset($domains[$domain_part]))
1375
+					if (isset($domains[$domain_part]))
1380 1376
 					{
1381 1377
 						$default_domain = $domain_part;
1382 1378
 						break;
@@ -1392,11 +1388,11 @@  discard block
 block discarded – undo
1392 1388
 		}
1393 1389
 		if (isset($login))	// on login
1394 1390
 		{
1395
-			if (strpos($login,'@') === false || count($domains) == 1)
1391
+			if (strpos($login, '@') === false || count($domains) == 1)
1396 1392
 			{
1397
-				$login .= '@' . (isset($_POST['logindomain']) ? $_POST['logindomain'] : $default_domain);
1393
+				$login .= '@'.(isset($_POST['logindomain']) ? $_POST['logindomain'] : $default_domain);
1398 1394
 			}
1399
-			$parts = explode('@',$login);
1395
+			$parts = explode('@', $login);
1400 1396
 			$domain = array_pop($parts);
1401 1397
 			$GLOBALS['login'] = $login;
1402 1398
 		}
@@ -1419,7 +1415,7 @@  discard block
 block discarded – undo
1419 1415
 	 * @param boolean $update_access_log =true false: dont update egw_access_log table
1420 1416
 	 * @return string action as written to egw_access_log.session_action
1421 1417
 	 */
1422
-	private function update_dla($update_access_log=true)
1418
+	private function update_dla($update_access_log = true)
1423 1419
 	{
1424 1420
 		// This way XML-RPC users aren't always listed as xmlrpc.php
1425 1421
 		if ($this->xmlrpc_method_called)
@@ -1435,27 +1431,27 @@  discard block
 block discarded – undo
1435 1431
 			$action = $_SERVER['PHP_SELF'];
1436 1432
 			// remove EGroupware path, if not installed in webroot
1437 1433
 			$egw_path = $GLOBALS['egw_info']['server']['webserver_url'];
1438
-			if ($egw_path[0] != '/') $egw_path = parse_url($egw_path,PHP_URL_PATH);
1434
+			if ($egw_path[0] != '/') $egw_path = parse_url($egw_path, PHP_URL_PATH);
1439 1435
 			if ($action == '/Microsoft-Server-ActiveSync')
1440 1436
 			{
1441 1437
 				$action .= '?Cmd='.$_GET['Cmd'].'&DeviceId='.$_GET['DeviceId'];
1442 1438
 			}
1443 1439
 			elseif ($egw_path)
1444 1440
 			{
1445
-				list(,$action) = explode($egw_path,$action,2);
1441
+				list(,$action) = explode($egw_path, $action, 2);
1446 1442
 			}
1447 1443
 		}
1448 1444
 
1449 1445
 		// update dla in access-log table, if we have an access-log row (non-anonymous session)
1450 1446
 		if ($this->sessionid_access_log && $update_access_log)
1451 1447
 		{
1452
-			$GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE,array(
1448
+			$GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE, array(
1453 1449
 				'session_dla' => time(),
1454 1450
 				'session_action' => $action,
1455
-				'lo' => null,	// just in case it was (automatic) timed out before
1456
-			),array(
1451
+				'lo' => null, // just in case it was (automatic) timed out before
1452
+			), array(
1457 1453
 				'sessionid' => $this->sessionid_access_log,
1458
-			),__LINE__,__FILE__);
1454
+			), __LINE__, __FILE__);
1459 1455
 		}
1460 1456
 
1461 1457
 		$_SESSION[self::EGW_SESSION_VAR]['session_dla'] = time();
@@ -1473,12 +1469,12 @@  discard block
 block discarded – undo
1473 1469
 		// update dla in access-log table, if we have an access-log row (non-anonymous session)
1474 1470
 		if ($this->sessionid_access_log)
1475 1471
 		{
1476
-			$GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE,array(
1472
+			$GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE, array(
1477 1473
 				'notification_heartbeat' => time(),
1478
-			),array(
1474
+			), array(
1479 1475
 				'sessionid' => $this->sessionid_access_log,
1480 1476
 				'lo IS NULL',
1481
-			),__LINE__,__FILE__);
1477
+			), __LINE__, __FILE__);
1482 1478
 		}
1483 1479
 	}
1484 1480
 
@@ -1499,7 +1495,7 @@  discard block
 block discarded – undo
1499 1495
 		{
1500 1496
 			// authentication happens in login.php, which does NOT yet create egw-object in session
1501 1497
 			// --> need to store homedirectory in session
1502
-			if(isset($GLOBALS['auto_create_acct']['homedirectory']))
1498
+			if (isset($GLOBALS['auto_create_acct']['homedirectory']))
1503 1499
 			{
1504 1500
 				egw_cache::setSession(__CLASS__, 'homedirectory',
1505 1501
 					$user['homedirectory'] = $GLOBALS['auto_create_acct']['homedirectory']);
@@ -1512,7 +1508,7 @@  discard block
 block discarded – undo
1512 1508
 		$user['preferences'] = $GLOBALS['egw']->preferences->read_repository();
1513 1509
 		if (is_object($GLOBALS['egw']->datetime))
1514 1510
 		{
1515
-			$GLOBALS['egw']->datetime->datetime();		// to set tz_offset from the now read prefs
1511
+			$GLOBALS['egw']->datetime->datetime(); // to set tz_offset from the now read prefs
1516 1512
 		}
1517 1513
 		$user['apps']        = $GLOBALS['egw']->applications->read_repository();
1518 1514
 		$user['domain']      = $this->account_domain;
@@ -1535,9 +1531,9 @@  discard block
 block discarded – undo
1535 1531
 	 * @param string &$account_lid returned account_lid (ie. user)
1536 1532
 	 * @param string &$domain returned domain (ie. domain)
1537 1533
 	 */
1538
-	private function split_login_domain($login,&$account_lid,&$domain)
1534
+	private function split_login_domain($login, &$account_lid, &$domain)
1539 1535
 	{
1540
-		$parts = explode('@',$login);
1536
+		$parts = explode('@', $login);
1541 1537
 
1542 1538
 		//conference - for strings like [email protected]@default ,
1543 1539
 		//allows that user have a login that is his e-mail. (viniciuscb)
@@ -1545,11 +1541,11 @@  discard block
 block discarded – undo
1545 1541
 		{
1546 1542
 			$probable_domain = array_pop($parts);
1547 1543
 			//Last part of login string, when separated by @, is a domain name
1548
-			if (in_array($probable_domain,$this->egw_domains))
1544
+			if (in_array($probable_domain, $this->egw_domains))
1549 1545
 			{
1550 1546
 				$got_login = true;
1551 1547
 				$domain = $probable_domain;
1552
-				$account_lid = implode('@',$parts);
1548
+				$account_lid = implode('@', $parts);
1553 1549
 			}
1554 1550
 		}
1555 1551
 
@@ -1572,9 +1568,9 @@  discard block
 block discarded – undo
1572 1568
 	 * @param boolean $allow_password_md5 =false can password alread be an md5 hash
1573 1569
 	 * @return string
1574 1570
 	 */
1575
-	static function user_pw_hash($user,$password,$allow_password_md5=false)
1571
+	static function user_pw_hash($user, $password, $allow_password_md5 = false)
1576 1572
 	{
1577
-		$password_md5 = $allow_password_md5 && preg_match('/^[a-f0-9]{32}$/',$password) ? $password : md5($password);
1573
+		$password_md5 = $allow_password_md5 && preg_match('/^[a-f0-9]{32}$/', $password) ? $password : md5($password);
1578 1574
 
1579 1575
 		$hash = sha1(strtolower($user).$password_md5);
1580 1576
 		//echo "<p>".__METHOD__."('$user','$password',$allow_password_md5) sha1('".strtolower($user)."$password_md5')='$hash'</p>\n";
@@ -1603,11 +1599,11 @@  discard block
 block discarded – undo
1603 1599
 		}
1604 1600
 		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__.'() session_handler='.self::$session_handler.', egw_info[server][session_handler]='.$GLOBALS['egw_info']['server']['session_handler'].' called from:'.function_backtrace());
1605 1601
 
1606
-		if (method_exists(self::$session_handler,'init_session_handler'))
1602
+		if (method_exists(self::$session_handler, 'init_session_handler'))
1607 1603
 		{
1608
-			call_user_func(array(self::$session_handler,'init_session_handler'));
1604
+			call_user_func(array(self::$session_handler, 'init_session_handler'));
1609 1605
 		}
1610
-		ini_set('session.use_cookies',0);	// disable the automatic use of cookies, as it uses the path / by default
1606
+		ini_set('session.use_cookies', 0); // disable the automatic use of cookies, as it uses the path / by default
1611 1607
 		session_name(self::EGW_SESSION_NAME);
1612 1608
 		if (($sessionid = self::get_sessionid()))
1613 1609
 		{
@@ -1631,7 +1627,7 @@  discard block
 block discarded – undo
1631 1627
 	 *
1632 1628
 	 * @param int $expire =null expiration time in seconds, default $GLOBALS['egw_info']['flags']['nocachecontrol'] or php.ini session.cache_expire
1633 1629
 	 */
1634
-	public static function cache_control($expire=null)
1630
+	public static function cache_control($expire = null)
1635 1631
 	{
1636 1632
 		if (is_null($expire) && isset($GLOBALS['egw_info']['flags']['nocachecontrol']) && is_int($GLOBALS['egw_info']['flags']['nocachecontrol']))
1637 1633
 		{
@@ -1641,7 +1637,7 @@  discard block
 block discarded – undo
1641 1637
 		if (!isset($_SESSION))
1642 1638
 		{
1643 1639
 			// controling caching and expires header
1644
-			if(!isset($GLOBALS['egw_info']['flags']['nocachecontrol']) || !$GLOBALS['egw_info']['flags']['nocachecontrol'])
1640
+			if (!isset($GLOBALS['egw_info']['flags']['nocachecontrol']) || !$GLOBALS['egw_info']['flags']['nocachecontrol'])
1645 1641
 			{
1646 1642
 				session_cache_limiter('nocache');
1647 1643
 			}
@@ -1650,7 +1646,7 @@  discard block
 block discarded – undo
1650 1646
 				// allow public caching: proxys, cdns, ...
1651 1647
 				if (isset($expire))
1652 1648
 				{
1653
-					session_cache_expire((int)ceil($expire/60));	// in minutes
1649
+					session_cache_expire((int)ceil($expire / 60)); // in minutes
1654 1650
 				}
1655 1651
 				session_cache_limiter('public');
1656 1652
 			}
@@ -1663,8 +1659,8 @@  discard block
 block discarded – undo
1663 1659
 		// session already started
1664 1660
 		if (isset($_SESSION))
1665 1661
 		{
1666
-			if ($expire && (session_cache_limiter() !== ($expire===true?'private_no_expire':'public') ||
1667
-				is_int($expire) && $expire/60 !== session_cache_expire()))
1662
+			if ($expire && (session_cache_limiter() !== ($expire === true ? 'private_no_expire' : 'public') ||
1663
+				is_int($expire) && $expire / 60 !== session_cache_expire()))
1668 1664
 			{
1669 1665
 				$file = $line = null;
1670 1666
 				if (headers_sent($file, $line))
@@ -1672,15 +1668,15 @@  discard block
 block discarded – undo
1672 1668
 					error_log(__METHOD__."($expire) called, but header already sent in $file: $line");
1673 1669
 					return;
1674 1670
 				}
1675
-				if($expire === true)	// same behavior as session_cache_limiter('private_no_expire')
1671
+				if ($expire === true)	// same behavior as session_cache_limiter('private_no_expire')
1676 1672
 				{
1677
-					header('Cache-Control: private, max-age='.(60*session_cache_expire()));
1673
+					header('Cache-Control: private, max-age='.(60 * session_cache_expire()));
1678 1674
 					header_remove('Expires');
1679 1675
 				}
1680 1676
 				else
1681 1677
 				{
1682 1678
 					header('Cache-Control: public, max-age='.$expire);
1683
-					header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expire) . ' GMT');
1679
+					header('Expires: '.gmdate('D, d M Y H:i:s', time() + $expire).' GMT');
1684 1680
 				}
1685 1681
 				// remove Pragma header, might be set by old header
1686 1682
 				if (function_exists('header_remove'))	// PHP 5.3+
@@ -1705,10 +1701,10 @@  discard block
 block discarded – undo
1705 1701
 	 * @param array $filter =array() extra filter for sessions
1706 1702
 	 * @return array with sessions (values for keys as in $sort)
1707 1703
 	 */
1708
-	public static function session_list($start,$sort='DESC',$order='session_dla',$all_no_sort=False,array $filter=array())
1704
+	public static function session_list($start, $sort = 'DESC', $order = 'session_dla', $all_no_sort = False, array $filter = array())
1709 1705
 	{
1710 1706
 		$sessions = array();
1711
-		if (!preg_match('/^[a-z0-9_ ,]+$/i',$order_by=$order.' '.$sort) || $order_by == ' ')
1707
+		if (!preg_match('/^[a-z0-9_ ,]+$/i', $order_by = $order.' '.$sort) || $order_by == ' ')
1712 1708
 		{
1713 1709
 			$order_by = 'session_dla DESC';
1714 1710
 		}
@@ -1716,7 +1712,7 @@  discard block
 block discarded – undo
1716 1712
 		$filter[] = 'account_id>0';
1717 1713
 		$filter[] = 'session_dla > '.(int)(time() - $GLOBALS['egw_info']['server']['sessions_timeout']);
1718 1714
 		$filter[] = '(notification_heartbeat IS NULL OR notification_heartbeat > '.self::heartbeat_limit().')';
1719
-		foreach($GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE, '*', $filter, __LINE__, __FILE__,
1715
+		foreach ($GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE, '*', $filter, __LINE__, __FILE__,
1720 1716
 			$all_no_sort ? false : $start, 'ORDER BY '.$order_by) as $row)
1721 1717
 		{
1722 1718
 			$sessions[$row['sessionid']] = $row;
@@ -1730,7 +1726,7 @@  discard block
 block discarded – undo
1730 1726
 	 * @param array $filter =array() extra filter for sessions
1731 1727
 	 * @return int number of active sessions
1732 1728
 	 */
1733
-	public static function session_count(array $filter=array())
1729
+	public static function session_count(array $filter = array())
1734 1730
 	{
1735 1731
 		$filter['lo'] = null;
1736 1732
 		$filter[] = 'account_id>0';
@@ -1746,16 +1742,16 @@  discard block
 block discarded – undo
1746 1742
 	 */
1747 1743
 	public static function heartbeat_limit()
1748 1744
 	{
1749
-		static $limit=null;
1745
+		static $limit = null;
1750 1746
 
1751 1747
 		if (is_null($limit))
1752 1748
 		{
1753 1749
 			$config = config::read('notifications');
1754
-			if (!($popup_poll_interval  = $config['popup_poll_interval']))
1750
+			if (!($popup_poll_interval = $config['popup_poll_interval']))
1755 1751
 			{
1756 1752
 				$popup_poll_interval = 60;
1757 1753
 			}
1758
-			$limit = (int)(time() - $popup_poll_interval-10);	// 10s grace periode
1754
+			$limit = (int)(time() - $popup_poll_interval - 10); // 10s grace periode
1759 1755
 		}
1760 1756
 		return $limit;
1761 1757
 	}
@@ -1788,8 +1784,8 @@  discard block
 block discarded – undo
1788 1784
 	 * @param int $accountid user account id, defaults to current user (optional)
1789 1785
 	 * @deprecated not longer used / necessary
1790 1786
 	 */
1791
-	function delete_cache($accountid='')
1787
+	function delete_cache($accountid = '')
1792 1788
 	{
1793
-		unset($accountid);	// not used, but required by function signature
1789
+		unset($accountid); // not used, but required by function signature
1794 1790
 	}
1795 1791
 }
Please login to merge, or discard this patch.
Braces   +180 added lines, -46 removed lines patch added patch discarded remove patch
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
 
253 253
 		// set session_timeout from global php.ini and default to 14400=4h, if not set
254 254
 		if (!($GLOBALS['egw_info']['server']['sessions_timeout'] = ini_get('session.gc_maxlifetime')))
255
-      	{
255
+		{
256 256
       		ini_set('session.gc_maxlifetime', $GLOBALS['egw_info']['server']['sessions_timeout']=14400);
257 257
       	}
258 258
 	}
@@ -286,7 +286,10 @@  discard block
 block discarded – undo
286 286
 	 */
287 287
 	function commit_session()
288 288
 	{
289
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() sessionid=$this->sessionid, _SESSION[".self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR]).' '.function_backtrace());
289
+		if (self::ERROR_LOG_DEBUG)
290
+		{
291
+			error_log(__METHOD__."() sessionid=$this->sessionid, _SESSION[".self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR]).' '.function_backtrace());
292
+		}
290 293
 		self::encrypt($this->kp3);
291 294
 
292 295
 		session_write_close();
@@ -348,7 +351,10 @@  discard block
 block discarded – undo
348 351
 	 */
349 352
 	static function log_session_usage(&$arr,$label,$recursion=true,$limit=1000)
350 353
 	{
351
-		if (!is_array($arr)) return;
354
+		if (!is_array($arr))
355
+		{
356
+			return;
357
+		}
352 358
 
353 359
 		$sizes = array();
354 360
 		foreach($arr as $key => &$data)
@@ -363,7 +369,10 @@  discard block
 block discarded – undo
363 369
 			if ($diff > $limit)
364 370
 			{
365 371
 				error_log("strlen({$label}[$key])=".egw_vfs::hsize($size).", diff=".egw_vfs::hsize($diff));
366
-				if ($recursion) self::log_session_usage($arr[$key],$label.'['.$key.']',$recursion,$limit);
372
+				if ($recursion)
373
+				{
374
+					self::log_session_usage($arr[$key],$label.'['.$key.']',$recursion,$limit);
375
+				}
367 376
 			}
368 377
 		}
369 378
 	}
@@ -461,7 +470,10 @@  discard block
 block discarded – undo
461 470
 				$this->passwd      = $passwd;
462 471
 				$this->passwd_type = $passwd_type;
463 472
 			}
464
-			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) starting ...");
473
+			if (self::ERROR_LOG_DEBUG)
474
+			{
475
+				error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) starting ...");
476
+			}
465 477
 
466 478
 			self::split_login_domain($login,$this->account_lid,$this->account_domain);
467 479
 			// add domain to the login, if not already there
@@ -506,7 +518,10 @@  discard block
 block discarded – undo
506 518
 				{
507 519
 					$this->log_access($this->reason,$login,$user_ip,0);	// log unsuccessfull login
508 520
 				}
509
-				if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)");
521
+				if (self::ERROR_LOG_DEBUG)
522
+				{
523
+					error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)");
524
+				}
510 525
 				return false;
511 526
 			}
512 527
 			if ($fail_on_forced_password_change && auth::check_password_change($this->reason) === false)
@@ -557,7 +572,10 @@  discard block
 block discarded – undo
557 572
 				$this->reason = 'account is expired';
558 573
 				$this->cd_reason = self::CD_ACCOUNT_EXPIRED;
559 574
 
560
-				if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)");
575
+				if (self::ERROR_LOG_DEBUG)
576
+				{
577
+					error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)");
578
+				}
561 579
 				return false;
562 580
 			}
563 581
 
@@ -581,25 +599,34 @@  discard block
 block discarded – undo
581 599
 				'passwd'         => $this->passwd,
582 600
 				'account_domain' => $this->account_domain,
583 601
 				'user_ip'        => $user_ip,
584
-			),'',true)))	// true = run hooks from all apps, not just the ones the current user has perms to run
602
+			),'',true)))
603
+			{
604
+				// true = run hooks from all apps, not just the ones the current user has perms to run
585 605
 			{
586 606
 				foreach($hook_result as $reason)
587 607
 				{
588 608
 					if ($reason)	// called hook requests to deny the session
589 609
 					{
590 610
 						$this->reason = $this->cd_reason = $reason;
611
+			}
591 612
 						$this->log_access($this->reason,$login,$user_ip,0);		// log unsuccessfull login
592
-						if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)");
613
+						if (self::ERROR_LOG_DEBUG)
614
+						{
615
+							error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)");
616
+						}
593 617
 						return false;
594 618
 					}
595 619
 				}
596 620
 			}
597 621
 			$GLOBALS['egw']->db->transaction_begin();
598 622
 			$this->register_session($this->login,$user_ip,$now,$this->session_flags);
599
-			if ($this->session_flags != 'A')		// dont log anonymous sessions
623
+			if ($this->session_flags != 'A')
624
+			{
625
+				// dont log anonymous sessions
600 626
 			{
601 627
 				$this->sessionid_access_log = $this->log_access($this->sessionid,$login,$user_ip,$this->account_id);
602 628
 			}
629
+			}
603 630
 			self::appsession('account_previous_login','phpgwapi',$GLOBALS['egw']->auth->previous_login);
604 631
 			$GLOBALS['egw']->accounts->update_lastlogin($this->account_id,$user_ip);
605 632
 			$GLOBALS['egw']->db->transaction_commit();
@@ -616,7 +643,10 @@  discard block
 block discarded – undo
616 643
 				self::egw_setcookie('last_domain',$this->account_domain,$now+1209600);
617 644
 			}
618 645
 			//if (!$this->sessionid) echo "<p>session::create(login='$login') = '$this->sessionid': lid='$this->account_lid', domain='$this->account_domain'</p>\n";
619
-			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) successfull sessionid=$this->sessionid");
646
+			if (self::ERROR_LOG_DEBUG)
647
+			{
648
+				error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) successfull sessionid=$this->sessionid");
649
+			}
620 650
 
621 651
 			return $this->sessionid;
622 652
 		}
@@ -770,10 +800,13 @@  discard block
 block discarded – undo
770 800
 		//error_log(__METHOD__."('$login', '$ip') false_ip=$false_ip, false_id=$false_id --> blocked=".array2string($blocked));
771 801
 
772 802
 		if ($blocked && $GLOBALS['egw_info']['server']['admin_mails'] &&
773
-			$GLOBALS['egw_info']['server']['login_blocked_mail_time'] < time()-5*60)	// max. one mail every 5mins
803
+			$GLOBALS['egw_info']['server']['login_blocked_mail_time'] < time()-5*60)
804
+		{
805
+			// max. one mail every 5mins
774 806
 		{
775 807
 			try {
776 808
 				$mailer = new egw_mailer();
809
+		}
777 810
 				// notify admin(s) via email
778 811
 				$mailer->setFrom('eGroupWare@'.$GLOBALS['egw_info']['server']['mail_suffix']);
779 812
 				$mailer->addHeader('Subject', lang("eGroupWare: login blocked for user '%1', IP %2",$login,$ip));
@@ -851,7 +884,10 @@  discard block
 block discarded – undo
851 884
 		{
852 885
 			$sessionid = false;
853 886
 		}
854
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() _SERVER[REQUEST_URI]='$_SERVER[REQUEST_URI]' returning ".print_r($sessionid,true));
887
+		if (self::ERROR_LOG_DEBUG)
888
+		{
889
+			error_log(__METHOD__."() _SERVER[REQUEST_URI]='$_SERVER[REQUEST_URI]' returning ".print_r($sessionid,true));
890
+		}
855 891
 		return $sessionid;
856 892
 	}
857 893
 
@@ -881,7 +917,10 @@  discard block
 block discarded – undo
881 917
 	 */
882 918
 	function verify($sessionid=null,$kp3=null)
883 919
 	{
884
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid','$kp3') ".function_backtrace());
920
+		if (self::ERROR_LOG_DEBUG)
921
+		{
922
+			error_log(__METHOD__."('$sessionid','$kp3') ".function_backtrace());
923
+		}
885 924
 
886 925
 		$fill_egw_info_and_repositories = !$GLOBALS['egw_info']['flags']['restored_from_session'];
887 926
 
@@ -897,7 +936,10 @@  discard block
 block discarded – undo
897 936
 
898 937
 		if (!$this->sessionid)
899 938
 		{
900
-			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid') get_sessionid()='".self::get_sessionid()."' No session ID");
939
+			if (self::ERROR_LOG_DEBUG)
940
+			{
941
+				error_log(__METHOD__."('$sessionid') get_sessionid()='".self::get_sessionid()."' No session ID");
942
+			}
901 943
 			return false;
902 944
 		}
903 945
 
@@ -909,14 +951,20 @@  discard block
 block discarded – undo
909 951
 		// check if we have a eGroupware session --> return false if not (but dont destroy it!)
910 952
 		if (is_null($_SESSION) || !isset($_SESSION[self::EGW_SESSION_VAR]))
911 953
 		{
912
-			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid') session does NOT exist!");
954
+			if (self::ERROR_LOG_DEBUG)
955
+			{
956
+				error_log(__METHOD__."('$sessionid') session does NOT exist!");
957
+			}
913 958
 			return false;
914 959
 		}
915 960
 		$session =& $_SESSION[self::EGW_SESSION_VAR];
916 961
 
917 962
 		if ($session['session_dla'] <= time() - $GLOBALS['egw_info']['server']['sessions_timeout'])
918 963
 		{
919
-			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid') session timed out!");
964
+			if (self::ERROR_LOG_DEBUG)
965
+			{
966
+				error_log(__METHOD__."('$sessionid') session timed out!");
967
+			}
920 968
 			$this->destroy($sessionid,$kp3);
921 969
 			return false;
922 970
 		}
@@ -944,7 +992,10 @@  discard block
 block discarded – undo
944 992
 		$this->account_id = $GLOBALS['egw']->accounts->name2id($this->account_lid,'account_lid','u');
945 993
 		if (!$this->account_id)
946 994
 		{
947
-			if (self::ERROR_LOG_DEBUG) error_log("*** session::verify($sessionid) !accounts::name2id('$this->account_lid')");
995
+			if (self::ERROR_LOG_DEBUG)
996
+			{
997
+				error_log("*** session::verify($sessionid) !accounts::name2id('$this->account_lid')");
998
+			}
948 999
 			return false;
949 1000
 		}
950 1001
 
@@ -962,7 +1013,10 @@  discard block
 block discarded – undo
962 1013
 
963 1014
 		if ($GLOBALS['egw']->accounts->is_expired($GLOBALS['egw_info']['user']))
964 1015
 		{
965
-			if (self::ERROR_LOG_DEBUG) error_log("*** session::verify($sessionid) accounts is expired");
1016
+			if (self::ERROR_LOG_DEBUG)
1017
+			{
1018
+				error_log("*** session::verify($sessionid) accounts is expired");
1019
+			}
966 1020
 			return false;
967 1021
 		}
968 1022
 		$this->passwd = base64_decode(egw_cache::getSession('phpgwapi', 'password'));
@@ -973,7 +1027,10 @@  discard block
 block discarded – undo
973 1027
 		}
974 1028
 		if ($this->account_domain != $GLOBALS['egw_info']['user']['domain'])
975 1029
 		{
976
-			if (self::ERROR_LOG_DEBUG) error_log("*** session::verify($sessionid) wrong domain");
1030
+			if (self::ERROR_LOG_DEBUG)
1031
+			{
1032
+				error_log("*** session::verify($sessionid) wrong domain");
1033
+			}
977 1034
 			return false;
978 1035
 		}
979 1036
 
@@ -982,7 +1039,10 @@  discard block
 block discarded – undo
982 1039
 			if (strtoupper(substr(PHP_OS,0,3)) != 'WIN' && (!$GLOBALS['egw_info']['user']['session_ip'] ||
983 1040
 				$GLOBALS['egw_info']['user']['session_ip'] != $this->getuser_ip()))
984 1041
 			{
985
-				if (self::ERROR_LOG_DEBUG) error_log("*** session::verify($sessionid) wrong IP");
1042
+				if (self::ERROR_LOG_DEBUG)
1043
+				{
1044
+					error_log("*** session::verify($sessionid) wrong IP");
1045
+				}
986 1046
 				return false;
987 1047
 			}
988 1048
 		}
@@ -995,7 +1055,10 @@  discard block
 block discarded – undo
995 1055
 		}
996 1056
 		if (!$this->account_lid)
997 1057
 		{
998
-			if (self::ERROR_LOG_DEBUG) error_log("*** session::verify($sessionid) !account_lid");
1058
+			if (self::ERROR_LOG_DEBUG)
1059
+			{
1060
+				error_log("*** session::verify($sessionid) !account_lid");
1061
+			}
999 1062
 			return false;
1000 1063
 		}
1001 1064
 
@@ -1014,13 +1077,19 @@  discard block
 block discarded – undo
1014 1077
 			$_REQUEST[self::EGW_SESSION_NAME] === $this->sessionid &&
1015 1078
 			(!isset($_COOKIE[self::EGW_SESSION_NAME]) || $_COOKIE[self::EGW_SESSION_NAME] !== $_REQUEST[self::EGW_SESSION_NAME]))
1016 1079
 		{
1017
-			if (self::ERROR_LOG_DEBUG) error_log("--> session::verify($sessionid) SUCCESS, but NO required cookies set --> setting them now");
1080
+			if (self::ERROR_LOG_DEBUG)
1081
+			{
1082
+				error_log("--> session::verify($sessionid) SUCCESS, but NO required cookies set --> setting them now");
1083
+			}
1018 1084
 			self::egw_setcookie(self::EGW_SESSION_NAME,$this->sessionid);
1019 1085
 			self::egw_setcookie('kp3',$this->kp3);
1020 1086
 			self::egw_setcookie('domain',$this->account_domain);
1021 1087
 		}
1022 1088
 
1023
-		if (self::ERROR_LOG_DEBUG) error_log("--> session::verify($sessionid) SUCCESS");
1089
+		if (self::ERROR_LOG_DEBUG)
1090
+		{
1091
+			error_log("--> session::verify($sessionid) SUCCESS");
1092
+		}
1024 1093
 
1025 1094
 		return true;
1026 1095
 	}
@@ -1040,14 +1109,20 @@  discard block
 block discarded – undo
1040 1109
 		}
1041 1110
 		$this->log_access($sessionid);	// log logout-time
1042 1111
 
1043
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($sessionid,$kp3)");
1112
+		if (self::ERROR_LOG_DEBUG)
1113
+		{
1114
+			error_log(__METHOD__."($sessionid,$kp3)");
1115
+		}
1044 1116
 
1045
-		if (is_numeric($sessionid))	// do we have a access-log-id --> get PHP session id
1117
+		if (is_numeric($sessionid))
1118
+		{
1119
+			// do we have a access-log-id --> get PHP session id
1046 1120
 		{
1047 1121
 			$sessionid = $GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE,'session_php',array(
1048 1122
 					'sessionid' => $sessionid,
1049 1123
 				),__LINE__,__FILE__)->fetchColumn();
1050 1124
 		}
1125
+		}
1051 1126
 
1052 1127
 		$GLOBALS['egw']->hooks->process(array(
1053 1128
 			'location'  => 'session_destroyed',
@@ -1057,7 +1132,10 @@  discard block
 block discarded – undo
1057 1132
 		// Only do the following, if where working with the current user
1058 1133
 		if (!$GLOBALS['egw_info']['user']['sessionid'] || $sessionid == $GLOBALS['egw_info']['user']['sessionid'])
1059 1134
 		{
1060
-			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__." ********* about to call session_destroy!");
1135
+			if (self::ERROR_LOG_DEBUG)
1136
+			{
1137
+				error_log(__METHOD__." ********* about to call session_destroy!");
1138
+			}
1061 1139
 			session_unset();
1062 1140
 			//echo '<p>'.__METHOD__.": session_destroy() returned ".(session_destroy() ? 'true' : 'false')."</p>\n";
1063 1141
 			@session_destroy();
@@ -1153,7 +1231,10 @@  discard block
 block discarded – undo
1153 1231
 		}
1154 1232
 		else
1155 1233
 		{
1156
-			if ($othervars) $extravars .= ($extravars?'&':'').$othervars;
1234
+			if ($othervars)
1235
+			{
1236
+				$extravars .= ($extravars?'&':'').$othervars;
1237
+			}
1157 1238
 		}
1158 1239
 
1159 1240
 		// parse extravars string into the vars array
@@ -1162,7 +1243,11 @@  discard block
 block discarded – undo
1162 1243
 			foreach(explode('&',$extravars) as $expr)
1163 1244
 			{
1164 1245
 				list($var,$val) = explode('=', $expr,2);
1165
-				if (strpos($val,'%26') != false) $val = str_replace('%26','&',$val);	// make sure to not double encode &
1246
+				if (strpos($val,'%26') != false)
1247
+				{
1248
+					$val = str_replace('%26','&',$val);
1249
+				}
1250
+				// make sure to not double encode &
1166 1251
 				if (substr($var,-2) == '[]')
1167 1252
 				{
1168 1253
 					$vars[substr($var,0,-2)][] = $val;
@@ -1210,7 +1295,10 @@  discard block
 block discarded – undo
1210 1295
 	{
1211 1296
 		if (isset($_SESSION[self::EGW_SESSION_ENCRYPTED]))
1212 1297
 		{
1213
-			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__.' called after session was encrypted --> ignored!');
1298
+			if (self::ERROR_LOG_DEBUG)
1299
+			{
1300
+				error_log(__METHOD__.' called after session was encrypted --> ignored!');
1301
+			}
1214 1302
 			return false;	// can no longer store something in the session, eg. because commit_session() was called
1215 1303
 		}
1216 1304
 		if (!$appname)
@@ -1290,14 +1378,22 @@  discard block
 block discarded – undo
1290 1378
 		{
1291 1379
 			self::set_cookiedomain();
1292 1380
 		}
1293
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($cookiename,$cookievalue,$cookietime,$cookiepath,".self::$cookie_domain.")");
1381
+		if (self::ERROR_LOG_DEBUG)
1382
+		{
1383
+			error_log(__METHOD__."($cookiename,$cookievalue,$cookietime,$cookiepath,".self::$cookie_domain.")");
1384
+		}
1294 1385
 
1295 1386
 		// if we are installed in iOS as web-app, we must not set a cookietime==0 (session-cookie),
1296 1387
 		// as every change between apps will cause the cookie to get lost
1297 1388
 		static $is_iOS = null;
1298
-		if (!$cookietime && !isset($is_iOS)) $is_iOS = (bool)preg_match('/^(iPhone|iPad|iPod)/i', html::$ua_mobile);
1389
+		if (!$cookietime && !isset($is_iOS))
1390
+		{
1391
+			$is_iOS = (bool)preg_match('/^(iPhone|iPad|iPod)/i', html::$ua_mobile);
1392
+		}
1299 1393
 
1300
-		if(!headers_sent())	// gives only a warning, but can not send the cookie anyway
1394
+		if(!headers_sent())
1395
+		{
1396
+			// gives only a warning, but can not send the cookie anyway
1301 1397
 		{
1302 1398
 			setcookie($cookiename, $cookievalue,
1303 1399
 				!$cookietime && $is_iOS ? time()+self::IOS_SESSION_COOKIE_LIFETIME : $cookietime,
@@ -1305,6 +1401,7 @@  discard block
 block discarded – undo
1305 1401
 				// if called via HTTPS, only send cookie for https and only allow cookie access via HTTP (true)
1306 1402
 				empty($GLOBALS['egw_info']['server']['insecure_cookies']) && !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off', true);
1307 1403
 		}
1404
+		}
1308 1405
 	}
1309 1406
 
1310 1407
 	/**
@@ -1357,15 +1454,25 @@  discard block
 block discarded – undo
1357 1454
 	 */
1358 1455
 	public static function search_instance($login,$domain_requested,&$default_domain,$server_names,array $domains=null)
1359 1456
 	{
1360
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$login','$domain_requested',".array2string($default_domain).".".array2string($server_names).".".array2string($domains).")");
1457
+		if (self::ERROR_LOG_DEBUG)
1458
+		{
1459
+			error_log(__METHOD__."('$login','$domain_requested',".array2string($default_domain).".".array2string($server_names).".".array2string($domains).")");
1460
+		}
1361 1461
 
1362
-		if (is_null($domains)) $domains = $GLOBALS['egw_domain'];
1462
+		if (is_null($domains))
1463
+		{
1464
+			$domains = $GLOBALS['egw_domain'];
1465
+		}
1363 1466
 
1364
-		if (!isset($default_domain) || !isset($domains[$default_domain]))	// allow to overwrite the default domain
1467
+		if (!isset($default_domain) || !isset($domains[$default_domain]))
1468
+		{
1469
+			// allow to overwrite the default domain
1365 1470
 		{
1366 1471
 			foreach((array)$server_names as $server_name)
1367 1472
 			{
1368
-				list($server_name) = explode(':', $server_name);	// remove port from HTTP_HOST
1473
+				list($server_name) = explode(':', $server_name);
1474
+		}
1475
+		// remove port from HTTP_HOST
1369 1476
 				if(isset($domains[$server_name]))
1370 1477
 				{
1371 1478
 					$default_domain = $server_name;
@@ -1390,11 +1497,14 @@  discard block
 block discarded – undo
1390 1497
 				}
1391 1498
 			}
1392 1499
 		}
1393
-		if (isset($login))	// on login
1500
+		if (isset($login))
1501
+		{
1502
+			// on login
1394 1503
 		{
1395 1504
 			if (strpos($login,'@') === false || count($domains) == 1)
1396 1505
 			{
1397 1506
 				$login .= '@' . (isset($_POST['logindomain']) ? $_POST['logindomain'] : $default_domain);
1507
+		}
1398 1508
 			}
1399 1509
 			$parts = explode('@',$login);
1400 1510
 			$domain = array_pop($parts);
@@ -1408,7 +1518,10 @@  discard block
 block discarded – undo
1408 1518
 		{
1409 1519
 			$domain = $default_domain;
1410 1520
 		}
1411
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() default_domain=".array2string($default_domain).', login='.array2string($login)." returning ".array2string($domain));
1521
+		if (self::ERROR_LOG_DEBUG)
1522
+		{
1523
+			error_log(__METHOD__."() default_domain=".array2string($default_domain).', login='.array2string($login)." returning ".array2string($domain));
1524
+		}
1412 1525
 
1413 1526
 		return $domain;
1414 1527
 	}
@@ -1435,7 +1548,10 @@  discard block
 block discarded – undo
1435 1548
 			$action = $_SERVER['PHP_SELF'];
1436 1549
 			// remove EGroupware path, if not installed in webroot
1437 1550
 			$egw_path = $GLOBALS['egw_info']['server']['webserver_url'];
1438
-			if ($egw_path[0] != '/') $egw_path = parse_url($egw_path,PHP_URL_PATH);
1551
+			if ($egw_path[0] != '/')
1552
+			{
1553
+				$egw_path = parse_url($egw_path,PHP_URL_PATH);
1554
+			}
1439 1555
 			if ($action == '/Microsoft-Server-ActiveSync')
1440 1556
 			{
1441 1557
 				$action .= '?Cmd='.$_GET['Cmd'].'&DeviceId='.$_GET['DeviceId'];
@@ -1460,7 +1576,10 @@  discard block
 block discarded – undo
1460 1576
 
1461 1577
 		$_SESSION[self::EGW_SESSION_VAR]['session_dla'] = time();
1462 1578
 		$_SESSION[self::EGW_SESSION_VAR]['session_action'] = $action;
1463
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__.'() _SESSION['.self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR]));
1579
+		if (self::ERROR_LOG_DEBUG)
1580
+		{
1581
+			error_log(__METHOD__.'() _SESSION['.self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR]));
1582
+		}
1464 1583
 
1465 1584
 		return $action;
1466 1585
 	}
@@ -1601,7 +1720,10 @@  discard block
 block discarded – undo
1601 1720
 		{
1602 1721
 			self::$session_handler = $GLOBALS['egw_info']['server']['session_handler'];
1603 1722
 		}
1604
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__.'() session_handler='.self::$session_handler.', egw_info[server][session_handler]='.$GLOBALS['egw_info']['server']['session_handler'].' called from:'.function_backtrace());
1723
+		if (self::ERROR_LOG_DEBUG)
1724
+		{
1725
+			error_log(__METHOD__.'() session_handler='.self::$session_handler.', egw_info[server][session_handler]='.$GLOBALS['egw_info']['server']['session_handler'].' called from:'.function_backtrace());
1726
+		}
1605 1727
 
1606 1728
 		if (method_exists(self::$session_handler,'init_session_handler'))
1607 1729
 		{
@@ -1615,10 +1737,16 @@  discard block
 block discarded – undo
1615 1737
 		 	self::cache_control();
1616 1738
 			$ok = session_start();
1617 1739
 			self::decrypt();
1618
-			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() sessionid=$sessionid, _SESSION[".self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR]));
1740
+			if (self::ERROR_LOG_DEBUG)
1741
+			{
1742
+				error_log(__METHOD__."() sessionid=$sessionid, _SESSION[".self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR]));
1743
+			}
1619 1744
 			return $ok;
1620 1745
 		}
1621
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() no active session!");
1746
+		if (self::ERROR_LOG_DEBUG)
1747
+		{
1748
+			error_log(__METHOD__."() no active session!");
1749
+		}
1622 1750
 
1623 1751
 		return false;
1624 1752
 	}
@@ -1672,9 +1800,12 @@  discard block
 block discarded – undo
1672 1800
 					error_log(__METHOD__."($expire) called, but header already sent in $file: $line");
1673 1801
 					return;
1674 1802
 				}
1675
-				if($expire === true)	// same behavior as session_cache_limiter('private_no_expire')
1803
+				if($expire === true)
1804
+				{
1805
+					// same behavior as session_cache_limiter('private_no_expire')
1676 1806
 				{
1677 1807
 					header('Cache-Control: private, max-age='.(60*session_cache_expire()));
1808
+				}
1678 1809
 					header_remove('Expires');
1679 1810
 				}
1680 1811
 				else
@@ -1683,10 +1814,13 @@  discard block
 block discarded – undo
1683 1814
 					header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expire) . ' GMT');
1684 1815
 				}
1685 1816
 				// remove Pragma header, might be set by old header
1686
-				if (function_exists('header_remove'))	// PHP 5.3+
1817
+				if (function_exists('header_remove'))
1818
+				{
1819
+					// PHP 5.3+
1687 1820
 				{
1688 1821
 					header_remove('Pragma');
1689 1822
 				}
1823
+				}
1690 1824
 				else
1691 1825
 				{
1692 1826
 					header('Pragma:');
Please login to merge, or discard this patch.
phpgwapi/inc/class.egw_session_files.inc.php 3 patches
Doc Comments   +1 added lines, -3 removed lines patch added patch discarded remove patch
@@ -32,9 +32,7 @@
 block discarded – undo
32 32
 	 * The data from the session-files get cached in $_SESSION['egw_files_session_cache']
33 33
 	 *
34 34
 	 * @param int $start
35
-	 * @param string $sort='session_dla' session_lid, session_id, session_started, session_logintime, session_action, or (default) session_dla
36
-	 * @param string $order='DESC' ASC or DESC
37
-	 * @param boolean $all_no_sort=False skip sorting and limiting to maxmatchs if set to true
35
+	 * @param boolean $all_no_sort skip sorting and limiting to maxmatchs if set to true
38 36
 	 * @return array with sessions (values for keys as in $sort) or array() if not supported by session-handler
39 37
 	 */
40 38
 	public static function session_list($start,$sort='DESC',$order='session_dla',$all_no_sort=False)
Please login to merge, or discard this patch.
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -37,14 +37,14 @@  discard block
 block discarded – undo
37 37
 	 * @param boolean $all_no_sort=False skip sorting and limiting to maxmatchs if set to true
38 38
 	 * @return array with sessions (values for keys as in $sort) or array() if not supported by session-handler
39 39
 	 */
40
-	public static function session_list($start,$sort='DESC',$order='session_dla',$all_no_sort=False)
40
+	public static function session_list($start, $sort = 'DESC', $order = 'session_dla', $all_no_sort = False)
41 41
 	{
42 42
 		if (session_module_name() != 'files')
43 43
 		{
44 44
 			return array();
45 45
 		}
46 46
 		//echo '<p>'.__METHOD__."($start,sort='$sort',order='$order',$all)</p>\n".function_backtrace();
47
-		$session_cache =& $_SESSION['egw_files_session_cache'];
47
+		$session_cache = & $_SESSION['egw_files_session_cache'];
48 48
 
49 49
 		$values = array();
50 50
 		$maxmatchs = $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'];
@@ -54,14 +54,14 @@  discard block
 block discarded – undo
54 54
 			return $values;
55 55
 		}
56 56
 		if (!($max_session_size = ini_get('memory_limit'))) $max_session_size = '16M';
57
-		if($max_session_size > 0)
57
+		if ($max_session_size > 0)
58 58
 		{
59
-			switch(strtoupper(substr($max_session_size,-1)))
59
+			switch (strtoupper(substr($max_session_size, -1)))
60 60
 			{
61
-				case 'M': $max_session_size *= 1024*1024; break;
61
+				case 'M': $max_session_size *= 1024 * 1024; break;
62 62
 				case 'K': $max_session_size *= 1024; break;
63 63
 			}
64
-			$max_session_size /= 4;	// use at max 1/4 of the memory_limit to read sessions, the others get ignored
64
+			$max_session_size /= 4; // use at max 1/4 of the memory_limit to read sessions, the others get ignored
65 65
 		}
66 66
 
67 67
 		while (($file = readdir($dir)))
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 			if ($file{0} == '.') continue;
70 70
 			if ($max_session_size > 0 && filesize($path.'/'.$file) >= $max_session_size) continue;
71 71
 
72
-			if (substr($file,0,5) != 'sess_' || $session_cache[$file] === false)
72
+			if (substr($file, 0, 5) != 'sess_' || $session_cache[$file] === false)
73 73
 			{
74 74
 				continue;
75 75
 			}
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 			{
83 83
 				$session = $session_cache[$file];
84 84
 
85
-				if (!$all_no_sort || 			// we need the up-to-date data --> unset and reread it
85
+				if (!$all_no_sort || // we need the up-to-date data --> unset and reread it
86 86
 					$session['session_dla'] <= (time() - $GLOBALS['egw_info']['server']['sessions_timeout']))	// cached dla is timeout
87 87
 				{
88 88
 					unset($session_cache[$file]);
@@ -90,34 +90,34 @@  discard block
 block discarded – undo
90 90
 			}
91 91
 			if (!isset($session_cache[$file]))	// not in cache, read and cache it
92 92
 			{
93
-				if (!is_readable($path. '/' . $file))
93
+				if (!is_readable($path.'/'.$file))
94 94
 				{
95
-					$session_cache[$file] = false;	// dont try reading it again
96
-					continue;	// happens if webserver runs multiple user-ids
95
+					$session_cache[$file] = false; // dont try reading it again
96
+					continue; // happens if webserver runs multiple user-ids
97 97
 				}
98 98
 				unset($session);
99
-				list(,$session) = explode(egw_session::EGW_SESSION_VAR.'|',file_get_contents($path . '/' . $file,'r'));
99
+				list(,$session) = explode(egw_session::EGW_SESSION_VAR.'|', file_get_contents($path.'/'.$file, 'r'));
100 100
 				if (!$session || !($session = unserialize($session)))
101 101
 				{
102
-					$session_cache[$file] = false;	// dont try reading it again
102
+					$session_cache[$file] = false; // dont try reading it again
103 103
 					continue;
104 104
 				}
105
-				unset($session[egw_session::EGW_APPSESSION_VAR]);	// not needed, saves memory
106
-				$session['php_session_file'] = $path . '/' . $file;
105
+				unset($session[egw_session::EGW_APPSESSION_VAR]); // not needed, saves memory
106
+				$session['php_session_file'] = $path.'/'.$file;
107 107
 				$session_cache[$file] = $session;
108 108
 
109
-				if($session['session_flags'] == 'A' || !$session['session_id'] ||
109
+				if ($session['session_flags'] == 'A' || !$session['session_id'] ||
110 110
 					$session['session_install_id'] != $GLOBALS['egw_info']['server']['install_id'])
111 111
 				{
112
-					$session_cache[$file] = false;	// dont try reading it again
113
-					continue;	// no anonymous sessions or other domains or installations
112
+					$session_cache[$file] = false; // dont try reading it again
113
+					continue; // no anonymous sessions or other domains or installations
114 114
 				}
115 115
 				// check for and terminate sessions which are timed out ==> destroy them
116 116
 				// this should be not necessary if php is configured right, but I'm sick of the questions on the list
117 117
 				if ($session['session_dla'] <= (time() - $GLOBALS['egw_info']['server']['sessions_timeout']))
118 118
 				{
119 119
 					//echo "session $session[session_id] is timed out !!!<br>\n";
120
-					@unlink($path . '/' . $file);
120
+					@unlink($path.'/'.$file);
121 121
 					$session_cache[$file] = false;
122 122
 					continue;
123 123
 				}
@@ -130,14 +130,14 @@  discard block
 block discarded – undo
130 130
 		}
131 131
 		closedir($dir);
132 132
 
133
-		if(!$all_no_sort)
133
+		if (!$all_no_sort)
134 134
 		{
135
-			if(!$order || !in_array($order,array('session_lid','session_ip','session_logintime','session_action','session_dla')))
135
+			if (!$order || !in_array($order, array('session_lid', 'session_ip', 'session_logintime', 'session_action', 'session_dla')))
136 136
 			{
137 137
 				$order = 'session_dla';
138 138
 			}
139
-			uasort($values,create_function('$a,$b','return '.(!strcasecmp($sort,'ASC') ? '' : '-').'strcasecmp($a['.$order.'],$b['.$order.']);'));
140
-			return array_slice($values,(int)$start,$maxmatchs);
139
+			uasort($values, create_function('$a,$b', 'return '.(!strcasecmp($sort, 'ASC') ? '' : '-').'strcasecmp($a['.$order.'],$b['.$order.']);'));
140
+			return array_slice($values, (int)$start, $maxmatchs);
141 141
 		}
142 142
 		return $values;
143 143
 	}
@@ -149,6 +149,6 @@  discard block
 block discarded – undo
149 149
 	 */
150 150
 	public static function session_count()
151 151
 	{
152
-		return count(self::session_list(0,'','',True));
152
+		return count(self::session_list(0, '', '', True));
153 153
 	}
154 154
 }
Please login to merge, or discard this patch.
Braces   +38 added lines, -10 removed lines patch added patch discarded remove patch
@@ -49,11 +49,17 @@  discard block
 block discarded – undo
49 49
 		$values = array();
50 50
 		$maxmatchs = $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'];
51 51
 		$dir = @opendir($path = ini_get('session.save_path'));
52
-		if (!$dir || !@file_exists($path.'/.'))	// eg. openbasedir restrictions, or dir not listable
52
+		if (!$dir || !@file_exists($path.'/.'))
53
+		{
54
+			// eg. openbasedir restrictions, or dir not listable
53 55
 		{
54 56
 			return $values;
55 57
 		}
56
-		if (!($max_session_size = ini_get('memory_limit'))) $max_session_size = '16M';
58
+		}
59
+		if (!($max_session_size = ini_get('memory_limit')))
60
+		{
61
+			$max_session_size = '16M';
62
+		}
57 63
 		if($max_session_size > 0)
58 64
 		{
59 65
 			switch(strtoupper(substr($max_session_size,-1)))
@@ -66,33 +72,52 @@  discard block
 block discarded – undo
66 72
 
67 73
 		while (($file = readdir($dir)))
68 74
 		{
69
-			if ($file{0} == '.') continue;
70
-			if ($max_session_size > 0 && filesize($path.'/'.$file) >= $max_session_size) continue;
75
+			if ($file{0} == '.')
76
+			{
77
+				continue;
78
+			}
79
+			if ($max_session_size > 0 && filesize($path.'/'.$file) >= $max_session_size)
80
+			{
81
+				continue;
82
+			}
71 83
 
72 84
 			if (substr($file,0,5) != 'sess_' || $session_cache[$file] === false)
73 85
 			{
74 86
 				continue;
75 87
 			}
76 88
 			//echo "<p>$path/$file: ".substr(file_get_contents($path . '/' . $file,'r'),0,256)."</p>\n";
77
-			if (isset($session_cache[$file]) && !$session_cache[$file])		// session is marked as not to list (not ours or anonymous)
89
+			if (isset($session_cache[$file]) && !$session_cache[$file])
90
+			{
91
+				// session is marked as not to list (not ours or anonymous)
78 92
 			{
79 93
 				continue;
80 94
 			}
81
-			if (isset($session_cache[$file]))	// use copy from cache
95
+			}
96
+			if (isset($session_cache[$file]))
97
+			{
98
+				// use copy from cache
82 99
 			{
83 100
 				$session = $session_cache[$file];
101
+			}
84 102
 
85 103
 				if (!$all_no_sort || 			// we need the up-to-date data --> unset and reread it
86
-					$session['session_dla'] <= (time() - $GLOBALS['egw_info']['server']['sessions_timeout']))	// cached dla is timeout
104
+					$session['session_dla'] <= (time() - $GLOBALS['egw_info']['server']['sessions_timeout']))
105
+				{
106
+					// cached dla is timeout
87 107
 				{
88 108
 					unset($session_cache[$file]);
89 109
 				}
110
+				}
90 111
 			}
91
-			if (!isset($session_cache[$file]))	// not in cache, read and cache it
112
+			if (!isset($session_cache[$file]))
113
+			{
114
+				// not in cache, read and cache it
92 115
 			{
93 116
 				if (!is_readable($path. '/' . $file))
94 117
 				{
95
-					$session_cache[$file] = false;	// dont try reading it again
118
+					$session_cache[$file] = false;
119
+			}
120
+			// dont try reading it again
96 121
 					continue;	// happens if webserver runs multiple user-ids
97 122
 				}
98 123
 				unset($session);
@@ -123,7 +148,10 @@  discard block
 block discarded – undo
123 148
 				}
124 149
 			}
125 150
 			// ignore (empty) login sessions created by IE and konqueror, when clicking on [login] (double submission of the form)
126
-			if ($session['session_action'] == $GLOBALS['egw_info']['server']['webserver_url'].'/login.php') continue;
151
+			if ($session['session_action'] == $GLOBALS['egw_info']['server']['webserver_url'].'/login.php')
152
+			{
153
+				continue;
154
+			}
127 155
 
128 156
 			//echo "file='$file'=<pre>"; print_r($session); echo "</pre>";
129 157
 			$values[$session['session_id']] = $session;
Please login to merge, or discard this patch.
phpgwapi/inc/class.egw_session_memcache.inc.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -109,7 +109,7 @@
 block discarded – undo
109 109
 	 * with a fatal error!
110 110
 	 *
111 111
 	 * @param string $id
112
-	 * @return string|boolean false on error, '' for not found session otherwise session data
112
+	 * @return false|string false on error, '' for not found session otherwise session data
113 113
 	 */
114 114
 	public static function read($id)
115 115
 	{
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
 	 */
59 59
 	public static function init_session_handler()
60 60
 	{
61
-		self::$mbstring_func_overload = @extension_loaded('mbstring') && (ini_get('mbstring.func_overload') & 2);
61
+		self::$mbstring_func_overload = @extension_loaded('mbstring') && (ini_get('mbstring.func_overload')&2);
62 62
 
63 63
 		// session needs to be closed before objects get destroyed, as this session-handler is an object ;-)
64 64
 		register_shutdown_function('session_write_close');
@@ -73,13 +73,13 @@  discard block
 block discarded – undo
73 73
 	 */
74 74
 	public static function open($save_path, $session_name)
75 75
 	{
76
-		check_load_extension('memcache',true);	// true = throw exception if not loadable
76
+		check_load_extension('memcache', true); // true = throw exception if not loadable
77 77
 
78 78
 		self::$memcache = new Memcache;
79
-		foreach(explode(',',$save_path) as $path)
79
+		foreach (explode(',', $save_path) as $path)
80 80
 		{
81 81
 			$parts = parse_url($path);
82
-			self::$memcache->addServer($parts['host'],$parts['port']);	// todo parse query
82
+			self::$memcache->addServer($parts['host'], $parts['port']); // todo parse query
83 83
 		}
84 84
 		return true;
85 85
 	}
@@ -117,9 +117,9 @@  discard block
 block discarded – undo
117 117
 
118 118
 		if (!self::_acquire_and_wait($id)) return false;
119 119
 
120
-		for($data='',$n=0; ($read = self::$memcache->get($id.($n?'-'.$n:''))); ++$n)
120
+		for ($data = '', $n = 0; ($read = self::$memcache->get($id.($n ? '-'.$n : ''))); ++$n)
121 121
 		{
122
-			if (self::DEBUG > 0) error_log("\n memcache ".$_SERVER["REQUEST_TIME"]." read $id:$n:".print_r(self::_bytes($read),true));
122
+			if (self::DEBUG > 0) error_log("\n memcache ".$_SERVER["REQUEST_TIME"]." read $id:$n:".print_r(self::_bytes($read), true));
123 123
 			$data .= $read;
124 124
 		}
125 125
 		self::_release($id);
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 
141 141
 		if ($id == 'no-session')
142 142
 		{
143
-			return true;	// no need to save
143
+			return true; // no need to save
144 144
 		}
145 145
 		// give anon sessions only a lifetime of 10min
146 146
 		if (is_object($GLOBALS['egw']->session) && $GLOBALS['egw']->session->session_flags == 'A' ||
@@ -152,17 +152,17 @@  discard block
 block discarded – undo
152 152
 
153 153
 		if (!self::_acquire_and_wait($id)) return false;
154 154
 
155
-		for($n=$i=0,$len=self::_bytes($sess_data); $i < $len; $i += self::MEMCACHED_MAX_JUNK,++$n)
155
+		for ($n = $i = 0, $len = self::_bytes($sess_data); $i < $len; $i += self::MEMCACHED_MAX_JUNK, ++$n)
156 156
 		{
157
-			if (self::DEBUG > 1) error_log("\n memcache ".$_SERVER["REQUEST_TIME"]." in :$n write $id:$i:".print_r(self::_bytes($sess_data),true));
157
+			if (self::DEBUG > 1) error_log("\n memcache ".$_SERVER["REQUEST_TIME"]." in :$n write $id:$i:".print_r(self::_bytes($sess_data), true));
158 158
 
159
-			if (!self::$memcache->set($id.($n?'-'.$n:''),self::_cut_bytes($sess_data,$i,self::MEMCACHED_MAX_JUNK),0,$lifetime)) {
159
+			if (!self::$memcache->set($id.($n ? '-'.$n : ''), self::_cut_bytes($sess_data, $i, self::MEMCACHED_MAX_JUNK), 0, $lifetime)) {
160 160
 				self::_release($id);
161 161
 				return false;
162 162
 			}
163 163
 		}
164 164
 		if (self::DEBUG > 0) error_log("\n memcache ".$_SERVER["REQUEST_TIME"]." DELETE :$n");
165
-		for($n=$n; self::$memcache->delete($id.($n?'-'.$n:'')); ++$n) ;
165
+		for ($n = $n; self::$memcache->delete($id.($n ? '-'.$n : '')); ++$n);
166 166
 
167 167
 		self::_release($id);
168 168
 
@@ -179,26 +179,26 @@  discard block
 block discarded – undo
179 179
 	{
180 180
 		if (self::DEBUG > 0) error_log("\n memcache ".$_SERVER["REQUEST_TIME"]." ACQUIRE :$id");
181 181
 
182
-		$i=0;
182
+		$i = 0;
183 183
 		// Acquire lock for 3 seconds, after that i should have done my job
184
-		while(!self::$memcache->add($id.'-lock',1,0,3))
184
+		while (!self::$memcache->add($id.'-lock', 1, 0, 3))
185 185
 		{
186 186
 			if (self::DEBUG > 0) error_log("\n memcache ".$_SERVER["REQUEST_TIME"]." ACQUIRE Lock Loop :$id:$i");
187 187
 			usleep(100000);
188 188
 			$i++;
189 189
 			if ($i > 40)
190 190
 			{
191
-				if (self::DEBUG > 1) error_log("\n memcache ".print_r(getenv('HOSTNAME'),true).$_SERVER["REQUEST_TIME"]." blocked :$id");
191
+				if (self::DEBUG > 1) error_log("\n memcache ".print_r(getenv('HOSTNAME'), true).$_SERVER["REQUEST_TIME"]." blocked :$id");
192 192
 				// Could not acquire lock after 3 seconds, Continue, and pretend the locking process get stuck
193 193
 				// return false;A
194 194
 				break;
195 195
 			}
196 196
 		}
197
-		if($i > 1)
197
+		if ($i > 1)
198 198
 		{
199 199
 			if (self::DEBUG > 0) error_log("\n memcache ".$_SERVER["REQUEST_TIME"]." ACQUIRE LOOP $i :$id");
200 200
 		}
201
-		if (self::DEBUG > 0) error_log("\n memcache ".print_r(getenv('HOSTNAME'),true).$_SERVER["REQUEST_TIME"]." Lock ACQUIRED $i:$id");
201
+		if (self::DEBUG > 0) error_log("\n memcache ".print_r(getenv('HOSTNAME'), true).$_SERVER["REQUEST_TIME"]." Lock ACQUIRED $i:$id");
202 202
 
203 203
 		return true;
204 204
 	}
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
 	 */
225 225
 	private static function _bytes(&$data)
226 226
 	{
227
-		return self::$mbstring_func_overload ? mb_strlen($data,'ascii') : strlen($data);
227
+		return self::$mbstring_func_overload ? mb_strlen($data, 'ascii') : strlen($data);
228 228
 	}
229 229
 
230 230
 	/**
@@ -235,16 +235,16 @@  discard block
 block discarded – undo
235 235
 	 * @param int $len
236 236
 	 * @return string
237 237
 	 */
238
-	private static function _cut_bytes(&$data,$offset,$len=null)
238
+	private static function _cut_bytes(&$data, $offset, $len = null)
239 239
 	{
240
-		if (self::DEBUG > 1) error_log("\n memcache in cutbyte mb $id:$n:".print_r(mb_substr($data,$offset,$len,'ascii'),true));
241
-		if (self::DEBUG > 1) error_log("\n memcache in cutbyte norm $id:$n:".print_r(substr($data,$offset,$len),true));
240
+		if (self::DEBUG > 1) error_log("\n memcache in cutbyte mb $id:$n:".print_r(mb_substr($data, $offset, $len, 'ascii'), true));
241
+		if (self::DEBUG > 1) error_log("\n memcache in cutbyte norm $id:$n:".print_r(substr($data, $offset, $len), true));
242 242
 
243 243
 		if (is_null($len))
244 244
 		{
245
-			return self::$mbstring_func_overload ? mb_substr($data,$offset,self::_bytes($data),'ascii') : substr($data,$offset);
245
+			return self::$mbstring_func_overload ? mb_substr($data, $offset, self::_bytes($data), 'ascii') : substr($data, $offset);
246 246
 		}
247
-		return self::$mbstring_func_overload ? mb_substr($data,$offset,$len,'ascii') : substr($data,$offset,$len);
247
+		return self::$mbstring_func_overload ? mb_substr($data, $offset, $len, 'ascii') : substr($data, $offset, $len);
248 248
 	}
249 249
 
250 250
 	/**
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
 	{
258 258
 		if (!self::_acquire_and_wait($id)) return false;
259 259
 
260
-		for($n=0; self::$memcache->delete($id.($n?'-'.$n:'')); ++$n)
260
+		for ($n = 0; self::$memcache->delete($id.($n ? '-'.$n : '')); ++$n)
261 261
 		{
262 262
 			if (self::DEBUG > 0) error_log("******* memcache destroy  $id:$n:");
263 263
 		}
@@ -281,12 +281,12 @@  discard block
 block discarded – undo
281 281
 {
282 282
 	$ses = 'egw_session_memcache';
283 283
 	$ret = session_set_save_handler(
284
-		array($ses,'open'),
285
-		array($ses,'close'),
286
-		array($ses,'read'),
287
-		array($ses,'write'),
288
-		array($ses,'destroy'),
289
-		array($ses,'gc'));
284
+		array($ses, 'open'),
285
+		array($ses, 'close'),
286
+		array($ses, 'read'),
287
+		array($ses, 'write'),
288
+		array($ses, 'destroy'),
289
+		array($ses, 'gc'));
290 290
 	if (!$ret) error_log(__METHOD__.'() session_set_save_handler(...)='.(int)$ret.', session_module_name()='.session_module_name().' *******************************');
291 291
 }
292 292
 init_session_handler();
Please login to merge, or discard this patch.
Braces   +75 added lines, -20 removed lines patch added patch discarded remove patch
@@ -113,13 +113,22 @@  discard block
 block discarded – undo
113 113
 	 */
114 114
 	public static function read($id)
115 115
 	{
116
-		if (self::DEBUG > 0) error_log("\n memcache ".$_SERVER["REQUEST_TIME"]." READ start $id:");
116
+		if (self::DEBUG > 0)
117
+		{
118
+			error_log("\n memcache ".$_SERVER["REQUEST_TIME"]." READ start $id:");
119
+		}
117 120
 
118
-		if (!self::_acquire_and_wait($id)) return false;
121
+		if (!self::_acquire_and_wait($id))
122
+		{
123
+			return false;
124
+		}
119 125
 
120 126
 		for($data='',$n=0; ($read = self::$memcache->get($id.($n?'-'.$n:''))); ++$n)
121 127
 		{
122
-			if (self::DEBUG > 0) error_log("\n memcache ".$_SERVER["REQUEST_TIME"]." read $id:$n:".print_r(self::_bytes($read),true));
128
+			if (self::DEBUG > 0)
129
+			{
130
+				error_log("\n memcache ".$_SERVER["REQUEST_TIME"]." read $id:$n:".print_r(self::_bytes($read),true));
131
+			}
123 132
 			$data .= $read;
124 133
 		}
125 134
 		self::_release($id);
@@ -148,20 +157,33 @@  discard block
 block discarded – undo
148 157
 		{
149 158
 			$lifetime = 600;
150 159
 		}
151
-		if (self::DEBUG > 0) error_log("\n memcache ".$_SERVER["REQUEST_TIME"]." WRITE start $id:");
160
+		if (self::DEBUG > 0)
161
+		{
162
+			error_log("\n memcache ".$_SERVER["REQUEST_TIME"]." WRITE start $id:");
163
+		}
152 164
 
153
-		if (!self::_acquire_and_wait($id)) return false;
165
+		if (!self::_acquire_and_wait($id))
166
+		{
167
+			return false;
168
+		}
154 169
 
155 170
 		for($n=$i=0,$len=self::_bytes($sess_data); $i < $len; $i += self::MEMCACHED_MAX_JUNK,++$n)
156 171
 		{
157
-			if (self::DEBUG > 1) error_log("\n memcache ".$_SERVER["REQUEST_TIME"]." in :$n write $id:$i:".print_r(self::_bytes($sess_data),true));
172
+			if (self::DEBUG > 1)
173
+			{
174
+				error_log("\n memcache ".$_SERVER["REQUEST_TIME"]." in :$n write $id:$i:".print_r(self::_bytes($sess_data),true));
175
+			}
158 176
 
159
-			if (!self::$memcache->set($id.($n?'-'.$n:''),self::_cut_bytes($sess_data,$i,self::MEMCACHED_MAX_JUNK),0,$lifetime)) {
177
+			if (!self::$memcache->set($id.($n?'-'.$n:''),self::_cut_bytes($sess_data,$i,self::MEMCACHED_MAX_JUNK),0,$lifetime))
178
+			{
160 179
 				self::_release($id);
161 180
 				return false;
162 181
 			}
163 182
 		}
164
-		if (self::DEBUG > 0) error_log("\n memcache ".$_SERVER["REQUEST_TIME"]." DELETE :$n");
183
+		if (self::DEBUG > 0)
184
+		{
185
+			error_log("\n memcache ".$_SERVER["REQUEST_TIME"]." DELETE :$n");
186
+		}
165 187
 		for($n=$n; self::$memcache->delete($id.($n?'-'.$n:'')); ++$n) ;
166 188
 
167 189
 		self::_release($id);
@@ -177,18 +199,27 @@  discard block
 block discarded – undo
177 199
 	 */
178 200
 	private static function _acquire_and_wait($id)
179 201
 	{
180
-		if (self::DEBUG > 0) error_log("\n memcache ".$_SERVER["REQUEST_TIME"]." ACQUIRE :$id");
202
+		if (self::DEBUG > 0)
203
+		{
204
+			error_log("\n memcache ".$_SERVER["REQUEST_TIME"]." ACQUIRE :$id");
205
+		}
181 206
 
182 207
 		$i=0;
183 208
 		// Acquire lock for 3 seconds, after that i should have done my job
184 209
 		while(!self::$memcache->add($id.'-lock',1,0,3))
185 210
 		{
186
-			if (self::DEBUG > 0) error_log("\n memcache ".$_SERVER["REQUEST_TIME"]." ACQUIRE Lock Loop :$id:$i");
211
+			if (self::DEBUG > 0)
212
+			{
213
+				error_log("\n memcache ".$_SERVER["REQUEST_TIME"]." ACQUIRE Lock Loop :$id:$i");
214
+			}
187 215
 			usleep(100000);
188 216
 			$i++;
189 217
 			if ($i > 40)
190 218
 			{
191
-				if (self::DEBUG > 1) error_log("\n memcache ".print_r(getenv('HOSTNAME'),true).$_SERVER["REQUEST_TIME"]." blocked :$id");
219
+				if (self::DEBUG > 1)
220
+				{
221
+					error_log("\n memcache ".print_r(getenv('HOSTNAME'),true).$_SERVER["REQUEST_TIME"]." blocked :$id");
222
+				}
192 223
 				// Could not acquire lock after 3 seconds, Continue, and pretend the locking process get stuck
193 224
 				// return false;A
194 225
 				break;
@@ -196,9 +227,15 @@  discard block
 block discarded – undo
196 227
 		}
197 228
 		if($i > 1)
198 229
 		{
199
-			if (self::DEBUG > 0) error_log("\n memcache ".$_SERVER["REQUEST_TIME"]." ACQUIRE LOOP $i :$id");
230
+			if (self::DEBUG > 0)
231
+			{
232
+				error_log("\n memcache ".$_SERVER["REQUEST_TIME"]." ACQUIRE LOOP $i :$id");
233
+			}
234
+		}
235
+		if (self::DEBUG > 0)
236
+		{
237
+			error_log("\n memcache ".print_r(getenv('HOSTNAME'),true).$_SERVER["REQUEST_TIME"]." Lock ACQUIRED $i:$id");
200 238
 		}
201
-		if (self::DEBUG > 0) error_log("\n memcache ".print_r(getenv('HOSTNAME'),true).$_SERVER["REQUEST_TIME"]." Lock ACQUIRED $i:$id");
202 239
 
203 240
 		return true;
204 241
 	}
@@ -211,7 +248,10 @@  discard block
 block discarded – undo
211 248
 	 */
212 249
 	private static function _release($id)
213 250
 	{
214
-		if (self::DEBUG > 0) error_log("\n memcache ".$_SERVER["REQUEST_TIME"]." RELEASE :$id");
251
+		if (self::DEBUG > 0)
252
+		{
253
+			error_log("\n memcache ".$_SERVER["REQUEST_TIME"]." RELEASE :$id");
254
+		}
215 255
 
216 256
 		return self::$memcache->delete($id.'-lock');
217 257
 	}
@@ -237,8 +277,14 @@  discard block
 block discarded – undo
237 277
 	 */
238 278
 	private static function _cut_bytes(&$data,$offset,$len=null)
239 279
 	{
240
-		if (self::DEBUG > 1) error_log("\n memcache in cutbyte mb $id:$n:".print_r(mb_substr($data,$offset,$len,'ascii'),true));
241
-		if (self::DEBUG > 1) error_log("\n memcache in cutbyte norm $id:$n:".print_r(substr($data,$offset,$len),true));
280
+		if (self::DEBUG > 1)
281
+		{
282
+			error_log("\n memcache in cutbyte mb $id:$n:".print_r(mb_substr($data,$offset,$len,'ascii'),true));
283
+		}
284
+		if (self::DEBUG > 1)
285
+		{
286
+			error_log("\n memcache in cutbyte norm $id:$n:".print_r(substr($data,$offset,$len),true));
287
+		}
242 288
 
243 289
 		if (is_null($len))
244 290
 		{
@@ -255,11 +301,17 @@  discard block
 block discarded – undo
255 301
 	 */
256 302
 	public static function destroy($id)
257 303
 	{
258
-		if (!self::_acquire_and_wait($id)) return false;
304
+		if (!self::_acquire_and_wait($id))
305
+		{
306
+			return false;
307
+		}
259 308
 
260 309
 		for($n=0; self::$memcache->delete($id.($n?'-'.$n:'')); ++$n)
261 310
 		{
262
-			if (self::DEBUG > 0) error_log("******* memcache destroy  $id:$n:");
311
+			if (self::DEBUG > 0)
312
+			{
313
+				error_log("******* memcache destroy  $id:$n:");
314
+			}
263 315
 		}
264 316
 		self::_release($id);
265 317
 
@@ -287,6 +339,9 @@  discard block
 block discarded – undo
287 339
 		array($ses,'write'),
288 340
 		array($ses,'destroy'),
289 341
 		array($ses,'gc'));
290
-	if (!$ret) error_log(__METHOD__.'() session_set_save_handler(...)='.(int)$ret.', session_module_name()='.session_module_name().' *******************************');
291
-}
342
+	if (!$ret)
343
+	{
344
+		error_log(__METHOD__.'() session_set_save_handler(...)='.(int)$ret.', session_module_name()='.session_module_name().' *******************************');
345
+	}
346
+	}
292 347
 init_session_handler();
Please login to merge, or discard this patch.
phpgwapi/inc/class.egw_sharing.inc.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -98,7 +98,6 @@  discard block
 block discarded – undo
98 98
 	/**
99 99
 	 * Protected constructor called via self::create_session
100 100
 	 *
101
-	 * @param string $token
102 101
 	 * @param array $share
103 102
 	 */
104 103
 	protected function __construct(array $share)
@@ -109,6 +108,7 @@  discard block
 block discarded – undo
109 108
 
110 109
 	/**
111 110
 	 * Get token from url
111
+	 * @return string
112 112
 	 */
113 113
 	public static function get_token()
114 114
 	{
Please login to merge, or discard this patch.
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -72,10 +72,10 @@  discard block
 block discarded – undo
72 72
 	const WRITABLE = 'share_rw';
73 73
 
74 74
  	/**
75
-	 * Modes for sharing files
76
-	 *
77
-	 * @var array
78
-	 */
75
+ 	 * Modes for sharing files
76
+ 	 *
77
+ 	 * @var array
78
+ 	 */
79 79
 	static $modes = array(
80 80
 		self::ATTACH => array(
81 81
 			'label' => 'Attachment',
@@ -112,16 +112,16 @@  discard block
 block discarded – undo
112 112
 	 */
113 113
 	public static function get_token()
114 114
 	{
115
-        // WebDAV has no concept of a query string and clients (including cadaver)
116
-        // seem to pass '?' unencoded, so we need to extract the path info out
117
-        // of the request URI ourselves
118
-        // if request URI contains a full url, remove schema and domain
115
+		// WebDAV has no concept of a query string and clients (including cadaver)
116
+		// seem to pass '?' unencoded, so we need to extract the path info out
117
+		// of the request URI ourselves
118
+		// if request URI contains a full url, remove schema and domain
119 119
 		$matches = null;
120
-        if (preg_match('|^https?://[^/]+(/.*)$|', $path_info=$_SERVER['REQUEST_URI'], $matches))
121
-        {
122
-        	$path_info = $matches[1];
123
-        }
124
-        $path_info = substr($path_info, strlen($_SERVER['SCRIPT_NAME']));
120
+		if (preg_match('|^https?://[^/]+(/.*)$|', $path_info=$_SERVER['REQUEST_URI'], $matches))
121
+		{
122
+			$path_info = $matches[1];
123
+		}
124
+		$path_info = substr($path_info, strlen($_SERVER['SCRIPT_NAME']));
125 125
 		list(, $token/*, $path*/) = preg_split('|[/?]|', $path_info, 3);
126 126
 
127 127
 		return $token;
Please login to merge, or discard this patch.
Spacing   +26 added lines, -27 removed lines patch added patch discarded remove patch
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
         // of the request URI ourselves
104 104
         // if request URI contains a full url, remove schema and domain
105 105
 		$matches = null;
106
-        if (preg_match('|^https?://[^/]+(/.*)$|', $path_info=$_SERVER['REQUEST_URI'], $matches))
106
+        if (preg_match('|^https?://[^/]+(/.*)$|', $path_info = $_SERVER['REQUEST_URI'], $matches))
107 107
         {
108 108
         	$path_info = $matches[1];
109 109
         }
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
 	 * @param boolean $keep_session =null null: create a new session, true: try mounting it into existing (already verified) session
142 142
 	 * @return string with sessionid, does NOT return if no session created
143 143
 	 */
144
-	public static function create_session($keep_session=null)
144
+	public static function create_session($keep_session = null)
145 145
 	{
146 146
 		self::$db = $GLOBALS['egw']->db;
147 147
 
@@ -194,11 +194,11 @@  discard block
 block discarded – undo
194 194
 		// need to reset fs_tab, as resolve_url does NOT work with just share mounted
195 195
 		if (count($GLOBALS['egw_info']['server']['vfs_fstab']) <= 1)
196 196
 		{
197
-			unset($GLOBALS['egw_info']['server']['vfs_fstab']);	// triggers reset of fstab in mount()
197
+			unset($GLOBALS['egw_info']['server']['vfs_fstab']); // triggers reset of fstab in mount()
198 198
 			$GLOBALS['egw_info']['server']['vfs_fstab'] = egw_vfs::mount();
199 199
 			egw_vfs::clearstatcache();
200 200
 		}
201
-		$share['resolve_url'] = egw_vfs::resolve_url($share['share_path'], true, true, true, true);	// true = fix evtl. contained url parameter
201
+		$share['resolve_url'] = egw_vfs::resolve_url($share['share_path'], true, true, true, true); // true = fix evtl. contained url parameter
202 202
 		// if share not writable append ro=1 to mount url to make it readonly
203 203
 		if (!self::$db->from_bool($share['share_writable']))
204 204
 		{
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
 
244 244
 		// update accessed timestamp
245 245
 		self::$db->update(self::TABLE, array(
246
-			'share_last_accessed' => $share['share_last_accessed']=time(),
246
+			'share_last_accessed' => $share['share_last_accessed'] = time(),
247 247
 		), array(
248 248
 			'share_id' => $share['share_id'],
249 249
 		), __LINE__, __FILE__);
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
 		if ($keep_session || $sessionid)
286 286
 		{
287 287
 			$_SESSION[egw_session::EGW_INFO_CACHE] = $GLOBALS['egw_info'];
288
-			unset($_SESSION[egw_session::EGW_INFO_CACHE]['flags']);	// dont save the flags, they change on each request
288
+			unset($_SESSION[egw_session::EGW_INFO_CACHE]['flags']); // dont save the flags, they change on each request
289 289
 
290 290
 			$_SESSION[egw_session::EGW_OBJECT_CACHE] = serialize($GLOBALS['egw']);
291 291
 		}
@@ -354,8 +354,7 @@  discard block
 block discarded – undo
354 354
 		// generate random token (using oppenssl if available otherwise mt_rand based auth::randomstring)
355 355
 		do {
356 356
 			$token = function_exists('openssl_random_pseudo_bytes') ?
357
-				base64_encode(openssl_random_pseudo_bytes(3*self::TOKEN_LENGTH/4)) :
358
-				auth::randomstring(self::TOKEN_LENGTH);
357
+				base64_encode(openssl_random_pseudo_bytes(3 * self::TOKEN_LENGTH / 4)) : auth::randomstring(self::TOKEN_LENGTH);
359 358
 			// base64 can contain chars not allowed in our vfs-urls eg. / or #
360 359
 		} while ($token != egw_vfs::encodePathComponent($token));
361 360
 
@@ -375,13 +374,13 @@  discard block
 block discarded – undo
375 374
 	 * @throw egw_excpetion_assertion_failed if user temp. directory does not exist and can not be created
376 375
 	 * @return array with share data, eg. value for key 'share_token'
377 376
 	 */
378
-	public static function create($path, $mode, $name, $recipients, $extra=array())
377
+	public static function create($path, $mode, $name, $recipients, $extra = array())
379 378
 	{
380 379
 		if (!isset(self::$db)) self::$db = $GLOBALS['egw']->db;
381 380
 
382 381
 		if (empty($name)) $name = $path;
383 382
 
384
-		$path2tmp =& egw_cache::getSession(__CLASS__, 'path2tmp');
383
+		$path2tmp = & egw_cache::getSession(__CLASS__, 'path2tmp');
385 384
 
386 385
 		// allow filesystem path only for temp_dir
387 386
 		$temp_dir = $GLOBALS['egw_info']['server']['temp_dir'].'/';
@@ -392,7 +391,7 @@  discard block
 block discarded – undo
392 391
 		}
393 392
 		else
394 393
 		{
395
-			if(parse_url($path, PHP_URL_SCHEME) !== 'vfs')
394
+			if (parse_url($path, PHP_URL_SCHEME) !== 'vfs')
396 395
 			{
397 396
 				$path = 'vfs://default'.($path[0] == '/' ? '' : '/').$path;
398 397
 			}
@@ -406,7 +405,7 @@  discard block
 block discarded – undo
406 405
 		}
407 406
 		// check if file has been shared before, with identical attributes
408 407
 		if (($mode != self::LINK || isset($path2tmp[$path])) &&
409
-			($share = self::$db->select(self::TABLE, '*', $extra+array(
408
+			($share = self::$db->select(self::TABLE, '*', $extra + array(
410 409
 				'share_path' => $mode == 'link' ? $path2tmp[$path] : $vfs_path,
411 410
 				'share_owner' => $GLOBALS['egw_info']['user']['account_id'],
412 411
 				'share_expires' => null,
@@ -417,7 +416,7 @@  discard block
 block discarded – undo
417 416
 			// if yes, just add additional recipients
418 417
 			$share['share_with'] = $share['share_with'] ? explode(',', $share['share_with']) : array();
419 418
 			$need_save = false;
420
-			foreach((array)$recipients as $recipient)
419
+			foreach ((array)$recipients as $recipient)
421 420
 			{
422 421
 				if (!in_array($recipient, $share['share_with']))
423 422
 				{
@@ -447,9 +446,9 @@  discard block
 block discarded – undo
447 446
 				}
448 447
 				$n = 0;
449 448
 				do {
450
-					$tmp_file = egw_vfs::concat($user_tmp, ($n?$n.'.':'').egw_vfs::basename($name));
449
+					$tmp_file = egw_vfs::concat($user_tmp, ($n ? $n.'.' : '').egw_vfs::basename($name));
451 450
 				}
452
-				while(!(is_dir($path) && egw_vfs::mkdir($tmp_file, null, STREAM_MKDIR_RECURSIVE) ||
451
+				while (!(is_dir($path) && egw_vfs::mkdir($tmp_file, null, STREAM_MKDIR_RECURSIVE) ||
453 452
 					!is_dir($path) && (!egw_vfs::file_exists($tmp_file) && ($fp = egw_vfs::fopen($tmp_file, 'x')) ||
454 453
 						// do not copy identical files again to users tmp dir, just re-use them
455 454
 						egw_vfs::file_exists($tmp_file) && egw_vfs::compare(egw_vfs::PREFIX.$tmp_file, $path))) && $n++ < 100);
@@ -474,12 +473,12 @@  discard block
 block discarded – undo
474 473
 				$async = new asyncservice();
475 474
 				if (!$async->read('egw_sharing-tmp-cleanup'))
476 475
 				{
477
-					$async->set_timer(array('day' => 28),'egw_sharing-tmp_cleanup','egw_sharing::tmp_cleanup',null);
476
+					$async->set_timer(array('day' => 28), 'egw_sharing-tmp_cleanup', 'egw_sharing::tmp_cleanup', null);
478 477
 				}
479 478
 			}
480 479
 
481 480
 			$i = 0;
482
-			while(true)	// self::token() can return an existing value
481
+			while (true)	// self::token() can return an existing value
483 482
 			{
484 483
 				try {
485 484
 					self::$db->insert(self::TABLE, $share = array(
@@ -488,12 +487,12 @@  discard block
 block discarded – undo
488 487
 						'share_owner' => $GLOBALS['egw_info']['user']['account_id'],
489 488
 						'share_with' => implode(',', (array)$recipients),
490 489
 						'share_created' => time(),
491
-					)+$extra, false, __LINE__, __FILE__);
490
+					) + $extra, false, __LINE__, __FILE__);
492 491
 
493 492
 					$share['share_id'] = self::$db->get_last_insert_id(self::TABLE, 'share_id');
494 493
 					break;
495 494
 				}
496
-				catch(egw_exception_db $e) {
495
+				catch (egw_exception_db $e) {
497 496
 					if ($i++ > 3) throw $e;
498 497
 					unset($e);
499 498
 				}
@@ -536,8 +535,8 @@  discard block
 block discarded – undo
536 535
 
537 536
 		// get all temp. files, to be able to delete them
538 537
 		$tmp_paths = array();
539
-		foreach(self::$db->select(self::TABLE, 'share_path', array(
540
-			"share_path LIKE '/home/%/.tmp/%'")+$keys, __LINE__, __FILE__, false) as $row)
538
+		foreach (self::$db->select(self::TABLE, 'share_path', array(
539
+			"share_path LIKE '/home/%/.tmp/%'") + $keys, __LINE__, __FILE__, false) as $row)
541 540
 		{
542 541
 			$tmp_paths[] = $row['share_path'];
543 542
 		}
@@ -549,7 +548,7 @@  discard block
 block discarded – undo
549 548
 		// check if temp. files are used elsewhere
550 549
 		if ($tmp_paths)
551 550
 		{
552
-			foreach(self::$db->select(self::TABLE, 'share_path,COUNT(*) AS cnt', array(
551
+			foreach (self::$db->select(self::TABLE, 'share_path,COUNT(*) AS cnt', array(
553 552
 				'share_path' => $tmp_paths,
554 553
 			), __LINE__, __FILE__, false, 'GROUP BY share_path') as $row)
555 554
 			{
@@ -559,7 +558,7 @@  discard block
 block discarded – undo
559 558
 				}
560 559
 			}
561 560
 			// if not delete them
562
-			foreach($tmp_paths as $path)
561
+			foreach ($tmp_paths as $path)
563 562
 			{
564 563
 				egw_vfs::remove($path);
565 564
 			}
@@ -593,11 +592,11 @@  discard block
 block discarded – undo
593 592
 			// remove expired tmp-files unconditionally
594 593
 			$having = 'HAVING share_expires < '.self::$db->quote(self::$db->to_timestamp(time())).' OR '.
595 594
 				// remove without expiration date, when created over 100 days ago AND
596
-				'share_expires IS NULL AND share_created < '.self::$db->quote(self::$db->to_timestamp(time()-self::TMP_KEEP)). ' AND '.
595
+				'share_expires IS NULL AND share_created < '.self::$db->quote(self::$db->to_timestamp(time() - self::TMP_KEEP)).' AND '.
597 596
 					// (last accessed over 100 days ago OR never)
598
-					'(share_last_accessed IS NULL OR share_last_accessed < '.self::$db->quote(self::$db->to_timestamp(time()-self::TMP_KEEP)).')';
597
+					'(share_last_accessed IS NULL OR share_last_accessed < '.self::$db->quote(self::$db->to_timestamp(time() - self::TMP_KEEP)).')';
599 598
 
600
-			foreach(self::$db->select(self::TABLE, $cols, array(
599
+			foreach (self::$db->select(self::TABLE, $cols, array(
601 600
 				"share_path LIKE '/home/%/.tmp/%'",
602 601
 			), __LINE__, __FILE__, false, 'GROUP BY share_path '.$having) as $row)
603 602
 			{
@@ -610,7 +609,7 @@  discard block
 block discarded – undo
610 609
 				else
611 610
 				{
612 611
 					$share_ids = array();
613
-					foreach(self::$db->selec(self::TABLE, 'share_id', array(
612
+					foreach (self::$db->selec(self::TABLE, 'share_id', array(
614 613
 						'share_path' => $row['share_path'],
615 614
 					), __LINE__, __FILE__) as $id)
616 615
 					{
Please login to merge, or discard this patch.
Braces   +48 added lines, -12 removed lines patch added patch discarded remove patch
@@ -166,7 +166,10 @@  discard block
 block discarded – undo
166 166
 		if ($token && !$keep_session)
167 167
 		{
168 168
 			$_SERVER['PHP_AUTH_USER'] = $token;
169
-			if (!isset($_SERVER['PHP_AUTH_PW'])) $_SERVER['PHP_AUTH_PW'] = '';
169
+			if (!isset($_SERVER['PHP_AUTH_PW']))
170
+			{
171
+				$_SERVER['PHP_AUTH_PW'] = '';
172
+			}
170 173
 
171 174
 			unset($GLOBALS['egw_info']['flags']['autocreate_session_callback']);
172 175
 			if ($GLOBALS['egw']->session->verify() && isset($GLOBALS['egw']->sharing) &&
@@ -220,9 +223,12 @@  discard block
 block discarded – undo
220 223
 		}
221 224
 		//_debug_array($share);
222 225
 
223
-		if ($keep_session)	// add share to existing session
226
+		if ($keep_session)
227
+		{
228
+			// add share to existing session
224 229
 		{
225 230
 			$share['share_root'] = '/'.$share['share_token'];
231
+		}
226 232
 
227 233
 			// if current user is not the share owner, we cant just mount share
228 234
 			if (Vfs::$user != $share['share_owner'])
@@ -230,12 +236,15 @@  discard block
 block discarded – undo
230 236
 				$keep_session = false;
231 237
 			}
232 238
 		}
233
-		if (!$keep_session)	// do NOT change to else, as we might have set $keep_session=false!
239
+		if (!$keep_session)
240
+		{
241
+			// do NOT change to else, as we might have set $keep_session=false!
234 242
 		{
235 243
 			// only allow filemanager app
236 244
 			$GLOBALS['egw_info']['user']['apps'] = array(
237 245
 				'filemanager' => $GLOBALS['egw_info']['apps']['filemanager']
238 246
 			);
247
+		}
239 248
 
240 249
 			$share['share_root'] = '/';
241 250
 			Vfs::$user = $share['share_owner'];
@@ -391,9 +400,15 @@  discard block
 block discarded – undo
391 400
 	 */
392 401
 	public static function create($path, $mode, $name, $recipients, $extra=array())
393 402
 	{
394
-		if (!isset(self::$db)) self::$db = $GLOBALS['egw']->db;
403
+		if (!isset(self::$db))
404
+		{
405
+			self::$db = $GLOBALS['egw']->db;
406
+		}
395 407
 
396
-		if (empty($name)) $name = $path;
408
+		if (empty($name))
409
+		{
410
+			$name = $path;
411
+		}
397 412
 
398 413
 		$path2tmp =& Api\Cache::getSession(__CLASS__, 'path2tmp');
399 414
 
@@ -472,7 +487,10 @@  discard block
 block discarded – undo
472 487
 				{
473 488
 					throw new Api\Exception\AssertionFailed("Could NOT create temp. file '$tmp_file'!");
474 489
 				}
475
-				if ($fp) fclose($fp);
490
+				if ($fp)
491
+				{
492
+					fclose($fp);
493
+				}
476 494
 
477 495
 				if (is_dir($path) && !Vfs::copy_files(array($path), $tmp_file) ||
478 496
 					!is_dir($path) && !copy($path, Vfs::PREFIX.$tmp_file))
@@ -493,7 +511,9 @@  discard block
 block discarded – undo
493 511
 			}
494 512
 
495 513
 			$i = 0;
496
-			while(true)	// self::token() can return an existing value
514
+			while(true)
515
+			{
516
+				// self::token() can return an existing value
497 517
 			{
498 518
 				try {
499 519
 					self::$db->insert(self::TABLE, $share = array(
@@ -503,12 +523,16 @@  discard block
 block discarded – undo
503 523
 						'share_with' => implode(',', (array)$recipients),
504 524
 						'share_created' => time(),
505 525
 					)+$extra, false, __LINE__, __FILE__);
526
+			}
506 527
 
507 528
 					$share['share_id'] = self::$db->get_last_insert_id(self::TABLE, 'share_id');
508 529
 					break;
509 530
 				}
510 531
 				catch(Api\Db\Exception $e) {
511
-					if ($i++ > 3) throw $e;
532
+					if ($i++ > 3)
533
+					{
534
+						throw $e;
535
+					}
512 536
 					unset($e);
513 537
 				}
514 538
 			}
@@ -546,7 +570,10 @@  discard block
 block discarded – undo
546 570
 	{
547 571
 		self::$db = $GLOBALS['egw']->db;
548 572
 
549
-		if (is_scalar($keys)) $keys = array('share_id' => $keys);
573
+		if (is_scalar($keys))
574
+		{
575
+			$keys = array('share_id' => $keys);
576
+		}
550 577
 
551 578
 		// get all temp. files, to be able to delete them
552 579
 		$tmp_paths = array();
@@ -593,7 +620,10 @@  discard block
 block discarded – undo
593 620
 	 */
594 621
 	public static function tmp_cleanup()
595 622
 	{
596
-		if (!isset(self::$db)) self::$db = $GLOBALS['egw']->db;
623
+		if (!isset(self::$db))
624
+		{
625
+			self::$db = $GLOBALS['egw']->db;
626
+		}
597 627
 		Vfs::$is_root = true;
598 628
 
599 629
 		try {
@@ -603,7 +633,10 @@  discard block
 block discarded – undo
603 633
 				'MAX(share_created) AS share_created',
604 634
 				'MAX(share_last_accessed) AS share_last_accessed',
605 635
 			);
606
-			if (($group_concat = self::$db->group_concat('share_id'))) $cols[] = $group_concat.' AS share_id';
636
+			if (($group_concat = self::$db->group_concat('share_id')))
637
+			{
638
+				$cols[] = $group_concat.' AS share_id';
639
+			}
607 640
 			// remove expired tmp-files unconditionally
608 641
 			$having = 'HAVING share_expires < '.self::$db->quote(self::$db->to_timestamp(time())).' OR '.
609 642
 				// remove without expiration date, when created over 100 days ago AND
@@ -651,7 +684,10 @@  discard block
 block discarded – undo
651 684
 	 */
652 685
 	public static function share2link($share)
653 686
 	{
654
-		if (is_array($share)) $share = $share['share_token'];
687
+		if (is_array($share))
688
+		{
689
+			$share = $share['share_token'];
690
+		}
655 691
 
656 692
 		$link = Api\Framework::link('/share.php').'/'.$share;
657 693
 		if ($link[0] == '/')
Please login to merge, or discard this patch.
phpgwapi/inc/class.egw_tail.inc.php 3 patches
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 	/**
63 63
 	 * Constructor
64 64
 	 *
65
-	 * @param string $filename=null if not starting with as slash relative to EGw files dir (this is strongly prefered for security reasons)
65
+	 * @param string $filename if not starting with as slash relative to EGw files dir (this is strongly prefered for security reasons)
66 66
 	 */
67 67
 	public function __construct($filename=null)
68 68
 	{
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 	 * Ajax callback to load next chunk of log-file
81 81
 	 *
82 82
 	 * @param string $filename
83
-	 * @param int $start=0 last position in log-file
83
+	 * @param int $start last position in log-file
84 84
 	 * @throws egw_exception_wrong_parameter
85 85
 	 */
86 86
 	public function ajax_chunk($filename,$start=0)
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 	 * Ajax callback to delete log-file
125 125
 	 *
126 126
 	 * @param string $filename
127
-	 * @param boolean $truncate=false true: truncate file, false: delete file
127
+	 * @param boolean $truncate true: truncate file, false: delete file
128 128
 	 * @throws egw_exception_wrong_parameter
129 129
 	 */
130 130
 	public function ajax_delete($filename,$truncate=false)
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
 	/**
148 148
 	 * Return html & javascript for logviewer
149 149
 	 *
150
-	 * @param string $header=null default $this->filename
150
+	 * @param string $header default $this->filename
151 151
 	 * @return string
152 152
 	 * @throws egw_exception_wrong_parameter
153 153
 	 */
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -64,15 +64,15 @@  discard block
 block discarded – undo
64 64
 	 *
65 65
 	 * @param string $filename=null if not starting with as slash relative to EGw files dir (this is strongly prefered for security reasons)
66 66
 	 */
67
-	public function __construct($filename=null)
67
+	public function __construct($filename = null)
68 68
 	{
69
-		$this->filenames =& egw_cache::getSession('phpgwapi', __CLASS__);
69
+		$this->filenames = & egw_cache::getSession('phpgwapi', __CLASS__);
70 70
 
71 71
 		if ($filename)
72 72
 		{
73 73
 			$this->filename = $filename;
74 74
 
75
-			if (!$this->filenames || !in_array($filename,$this->filenames)) $this->filenames[] = $filename;
75
+			if (!$this->filenames || !in_array($filename, $this->filenames)) $this->filenames[] = $filename;
76 76
 		}
77 77
 	}
78 78
 
@@ -83,9 +83,9 @@  discard block
 block discarded – undo
83 83
 	 * @param int $start=0 last position in log-file
84 84
 	 * @throws egw_exception_wrong_parameter
85 85
 	 */
86
-	public function ajax_chunk($filename,$start=0)
86
+	public function ajax_chunk($filename, $start = 0)
87 87
 	{
88
-		if (!in_array($filename,$this->filenames))
88
+		if (!in_array($filename, $this->filenames))
89 89
 		{
90 90
 			throw new egw_exception_wrong_parameter("Not allowed to view '$filename'!");
91 91
 		}
@@ -94,9 +94,9 @@  discard block
 block discarded – undo
94 94
 		if (file_exists($filename))
95 95
 		{
96 96
 			$size = filesize($filename);
97
-			if (!$start || $start < 0 || $start > $size || $size-$start > 4*self::MAX_CHUNK_SIZE)
97
+			if (!$start || $start < 0 || $start > $size || $size - $start > 4 * self::MAX_CHUNK_SIZE)
98 98
 			{
99
-				$start = $size - 4*self::MAX_CHUNK_SIZE;
99
+				$start = $size - 4 * self::MAX_CHUNK_SIZE;
100 100
 				if ($start < 0) $start = 0;
101 101
 			}
102 102
 			$size = egw_vfs::hsize($size);
@@ -127,9 +127,9 @@  discard block
 block discarded – undo
127 127
 	 * @param boolean $truncate=false true: truncate file, false: delete file
128 128
 	 * @throws egw_exception_wrong_parameter
129 129
 	 */
130
-	public function ajax_delete($filename,$truncate=false)
130
+	public function ajax_delete($filename, $truncate = false)
131 131
 	{
132
-		if (!in_array($filename,$this->filenames))
132
+		if (!in_array($filename, $this->filenames))
133 133
 		{
134 134
 			throw new egw_exception_wrong_parameter("Not allowed to view '$filename'!");
135 135
 		}
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
 	 * @return string
152 152
 	 * @throws egw_exception_wrong_parameter
153 153
 	 */
154
-	public function show($header=null)
154
+	public function show($header = null)
155 155
 	{
156 156
 		if (!isset($this->filename))
157 157
 		{
@@ -163,11 +163,11 @@  discard block
 block discarded – undo
163 163
 <p style="float: left; margin: 5px"><b>'.htmlspecialchars($header).'</b></p>
164 164
 <div style="float: right; margin: 2px; margin-right: 5px">
165 165
 	'.html::form(
166
-		html::input('clear_log',lang('Clear window'),'button','id="clear_log"')."\n".
167
-		html::input('delete_log',lang('Delete file'),'button','id="purge_log"')."\n".
168
-		html::input('empty_log',lang('Empty file'),'button','id="empty_log"')."\n".
169
-		html::input('download_log',lang('Download'),'submit','id="download_log"'),
170
-		'','/index.php',array(
166
+		html::input('clear_log', lang('Clear window'), 'button', 'id="clear_log"')."\n".
167
+		html::input('delete_log', lang('Delete file'), 'button', 'id="purge_log"')."\n".
168
+		html::input('empty_log', lang('Empty file'), 'button', 'id="empty_log"')."\n".
169
+		html::input('download_log', lang('Download'), 'submit', 'id="download_log"'),
170
+		'', '/index.php', array(
171 171
 		'menuaction' => 'phpgwapi.egw_tail.download',
172 172
 		'filename' => $this->filename,
173 173
 	)).'
@@ -183,13 +183,13 @@  discard block
 block discarded – undo
183 183
 	public function download()
184 184
 	{
185 185
 		$filename = $_GET['filename'];
186
-		if (!in_array($filename,$this->filenames))
186
+		if (!in_array($filename, $this->filenames))
187 187
 		{
188 188
 			throw new egw_exception_wrong_parameter("Not allowed to download '$filename'!");
189 189
 		}
190
-		html::content_header(basename($filename),'text/plain');
190
+		html::content_header(basename($filename), 'text/plain');
191 191
 		if ($filename[0] != '/') $filename = $GLOBALS['egw_info']['server']['files_dir'].'/'.$filename;
192
-		for($n=ob_get_level(); $n > 0; --$n) ob_end_clean();	// stop all output buffering, to NOT run into memory_limit
192
+		for ($n = ob_get_level(); $n > 0; --$n) ob_end_clean(); // stop all output buffering, to NOT run into memory_limit
193 193
 		readfile($filename);
194 194
 		common::egw_exit();
195 195
 	}
Please login to merge, or discard this patch.
Braces   +29 added lines, -7 removed lines patch added patch discarded remove patch
@@ -72,7 +72,10 @@  discard block
 block discarded – undo
72 72
 		{
73 73
 			$this->filename = $filename;
74 74
 
75
-			if (!$this->filenames || !in_array($filename,$this->filenames)) $this->filenames[] = $filename;
75
+			if (!$this->filenames || !in_array($filename,$this->filenames))
76
+			{
77
+				$this->filenames[] = $filename;
78
+			}
76 79
 		}
77 80
 	}
78 81
 
@@ -89,7 +92,10 @@  discard block
 block discarded – undo
89 92
 		{
90 93
 			throw new egw_exception_wrong_parameter("Not allowed to view '$filename'!");
91 94
 		}
92
-		if ($filename[0] != '/') $filename = $GLOBALS['egw_info']['server']['files_dir'].'/'.$filename;
95
+		if ($filename[0] != '/')
96
+		{
97
+			$filename = $GLOBALS['egw_info']['server']['files_dir'].'/'.$filename;
98
+		}
93 99
 
94 100
 		if (file_exists($filename))
95 101
 		{
@@ -97,7 +103,10 @@  discard block
 block discarded – undo
97 103
 			if (!$start || $start < 0 || $start > $size || $size-$start > 4*self::MAX_CHUNK_SIZE)
98 104
 			{
99 105
 				$start = $size - 4*self::MAX_CHUNK_SIZE;
100
-				if ($start < 0) $start = 0;
106
+				if ($start < 0)
107
+				{
108
+					$start = 0;
109
+				}
101 110
 			}
102 111
 			$size = egw_vfs::hsize($size);
103 112
 			$content = file_get_contents($filename, false, null, $start, self::MAX_CHUNK_SIZE);
@@ -133,7 +142,10 @@  discard block
 block discarded – undo
133 142
 		{
134 143
 			throw new egw_exception_wrong_parameter("Not allowed to view '$filename'!");
135 144
 		}
136
-		if ($filename[0] != '/') $filename = $GLOBALS['egw_info']['server']['files_dir'].'/'.$filename;
145
+		if ($filename[0] != '/')
146
+		{
147
+			$filename = $GLOBALS['egw_info']['server']['files_dir'].'/'.$filename;
148
+		}
137 149
 		if ($truncate)
138 150
 		{
139 151
 			file_put_contents($filename, '');
@@ -157,7 +169,10 @@  discard block
 block discarded – undo
157 169
 		{
158 170
 			throw new egw_exception_wrong_parameter("Must be instanciated with filename!");
159 171
 		}
160
-		if (is_null($header)) $header = $this->filename;
172
+		if (is_null($header))
173
+		{
174
+			$header = $this->filename;
175
+		}
161 176
 
162 177
 		return '
163 178
 <p style="float: left; margin: 5px"><b>'.htmlspecialchars($header).'</b></p>
@@ -188,8 +203,15 @@  discard block
 block discarded – undo
188 203
 			throw new egw_exception_wrong_parameter("Not allowed to download '$filename'!");
189 204
 		}
190 205
 		html::content_header(basename($filename),'text/plain');
191
-		if ($filename[0] != '/') $filename = $GLOBALS['egw_info']['server']['files_dir'].'/'.$filename;
192
-		for($n=ob_get_level(); $n > 0; --$n) ob_end_clean();	// stop all output buffering, to NOT run into memory_limit
206
+		if ($filename[0] != '/')
207
+		{
208
+			$filename = $GLOBALS['egw_info']['server']['files_dir'].'/'.$filename;
209
+		}
210
+		for($n=ob_get_level(); $n > 0; --$n)
211
+		{
212
+			ob_end_clean();
213
+		}
214
+		// stop all output buffering, to NOT run into memory_limit
193 215
 		readfile($filename);
194 216
 		common::egw_exit();
195 217
 	}
Please login to merge, or discard this patch.
phpgwapi/inc/class.egw_time.inc.php 3 patches
Doc Comments   +6 added lines, -10 removed lines patch added patch discarded remove patch
@@ -76,10 +76,8 @@  discard block
 block discarded – undo
76 76
 	/**
77 77
 	 * Constructor
78 78
 	 *
79
-	 * @param int|string|array|DateTime $time='now' integer timestamp, string with date+time, DateTime object or
80
-	 * 	array with values for keys('year','month','day') or 'full' plus 'hour','minute' and optional 'second'
81
-	 * @param DateTimeZone $tz=null timezone, default user time (PHP DateTime default to server time!)
82 79
 	 * @param string &$type=null on return type of $time (optional)
80
+	 * @param string $type
83 81
 	 * @throws Exception if $time can NOT be parsed
84 82
 	 * @return egw_time
85 83
 	 */
@@ -164,7 +162,7 @@  discard block
 block discarded – undo
164 162
 	/**
165 163
 	 * Like DateTime::add, but additional allow to use a string run through DateInterval::createFromDateString
166 164
 	 *
167
-	 * @param DateInterval|string $interval eg. '1 day', '-2 weeks'
165
+	 * @param string $interval eg. '1 day', '-2 weeks'
168 166
 	 */
169 167
 	public function add($interval)
170 168
 	{
@@ -384,7 +382,7 @@  discard block
 block discarded – undo
384 382
 	 * Convert a server time into a user time
385 383
 	 *
386 384
 	 * @param int|string|array|DateTime $time
387
-	 * @param string $type=null type or return-value, default (null) same as $time
385
+	 * @param string $type
388 386
 	 * @return int|string|array|datetime null if time could not be parsed
389 387
 	 */
390 388
 	public static function server2user($time,$type=null)
@@ -413,8 +411,8 @@  discard block
 block discarded – undo
413 411
 	 * Convert a user time into a server time
414 412
 	 *
415 413
 	 * @param int|string|array|datetime $time
416
-	 * @param string $type=null type or return-value, default (null) same as $time
417
-	 * @return int|string|array|datetime null if time could not be parsed
414
+	 * @param string $type
415
+	 * @return integer|null null if time could not be parsed
418 416
 	 */
419 417
 	public static function user2server($time,$type=null)
420 418
 	{
@@ -441,7 +439,6 @@  discard block
 block discarded – undo
441 439
 	/**
442 440
 	 * Convert time to a specific format or string, static version of egw_time::format()
443 441
 	 *
444
-	 * @param int|string|array|DateTime $time='now' see constructor
445 442
 	 * @param string $type='' 'integer'|'ts'=timestamp, 'server'=timestamp in servertime, 'string'='Y-m-d H:i:s', 'object'=DateTime,
446 443
 	 * 		'array'=array with values for keys ('year','month','day','hour','minute','second','full','raw') or string with format
447 444
 	 * 		true = date only, false = time only as in user prefs, '' = date+time as in user prefs
@@ -507,7 +504,6 @@  discard block
 block discarded – undo
507 504
 	 *
508 505
 	 * Compatibility method for old code. It is only valid for the given time, because of possible daylight saving changes!
509 506
 	 *
510
-	 * @param int|string|DateTime $time='now'
511 507
 	 * @return int difference in seconds between user and server time (for the given time!)
512 508
 	 */
513 509
 	public static function tz_offset_s($time='now')
@@ -558,7 +554,7 @@  discard block
 block discarded – undo
558 554
 	 * - return UTC and oceans at the end
559 555
 	 * - if (user lang is a european language), move Europe to top
560 556
 	 *
561
-	 * @return array continent|ocean => array(tz-name => tz-label incl. current time)
557
+	 * @return string continent|ocean => array(tz-name => tz-label incl. current time)
562 558
 	 */
563 559
 	public static function getTimezones()
564 560
 	{
Please login to merge, or discard this patch.
Spacing   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -83,11 +83,11 @@  discard block
 block discarded – undo
83 83
 	 * @throws Exception if $time can NOT be parsed
84 84
 	 * @return egw_time
85 85
 	 */
86
-	public function __construct($time='now',DateTimeZone $tz=null,&$type=null)
86
+	public function __construct($time = 'now', DateTimeZone $tz = null, &$type = null)
87 87
 	{
88
-		if (is_null($tz)) $tz = self::$user_timezone;	// default user timezone
88
+		if (is_null($tz)) $tz = self::$user_timezone; // default user timezone
89 89
 
90
-		switch(($type = gettype($time)))
90
+		switch (($type = gettype($time)))
91 91
 		{
92 92
 			case 'NULL':
93 93
 			case 'boolean':	// depricated use in calendar for 'now'
@@ -98,13 +98,13 @@  discard block
 block discarded – undo
98 98
 				if (!(is_numeric($time) && ($time > 21000000 || $time < 19000000)))
99 99
 				{
100 100
 					$t_str = $time;
101
-					if (is_numeric($time) && strlen($time) == 8) $t_str .= 'T000000';	// 'Ymd' string used in calendar to represent a date
101
+					if (is_numeric($time) && strlen($time) == 8) $t_str .= 'T000000'; // 'Ymd' string used in calendar to represent a date
102 102
 					// $time ending in a Z (Zulu or UTC time), is unterstood by DateTime class itself
103 103
 					try {
104
-						parent::__construct($t_str,$tz);
104
+						parent::__construct($t_str, $tz);
105 105
 						break;
106 106
 					}
107
-					catch(Exception $e) {
107
+					catch (Exception $e) {
108 108
 						// if string is nummeric, ignore the exception and treat string as timestamp
109 109
 						if (!is_numeric($time)) throw $e;
110 110
 					}
@@ -121,12 +121,12 @@  discard block
 block discarded – undo
121 121
 				}
122 122
 				else*/
123 123
 				{
124
-					parent::__construct(date('Y-m-d H:i:s',$time),$tz);
124
+					parent::__construct(date('Y-m-d H:i:s', $time), $tz);
125 125
 				}
126 126
 				break;
127 127
 
128 128
 			case 'array':
129
-				parent::__construct('now',$tz);
129
+				parent::__construct('now', $tz);
130 130
 				if (isset($time['Y']))	// array format used in eTemplate
131 131
 				{
132 132
 					$time = array(
@@ -140,18 +140,18 @@  discard block
 block discarded – undo
140 140
 				}
141 141
 				if (!empty($time['full']) && empty($time['year']))
142 142
 				{
143
-					$time['year']  = (int)substr($time['full'],0,4);
144
-					$time['month'] = (int)substr($time['full'],4,2);
145
-					$time['day']   = (int)substr($time['full'],6,2);
143
+					$time['year']  = (int)substr($time['full'], 0, 4);
144
+					$time['month'] = (int)substr($time['full'], 4, 2);
145
+					$time['day']   = (int)substr($time['full'], 6, 2);
146 146
 				}
147
-				if (isset($time['year'])) $this->setDate((int)$time['year'],(int)$time['month'],isset($time['day']) ? (int)$time['day'] : (int)$time['mday']);
148
-				$this->setTime((int)$time['hour'],(int)$time['minute'],(int)$time['second']);
147
+				if (isset($time['year'])) $this->setDate((int)$time['year'], (int)$time['month'], isset($time['day']) ? (int)$time['day'] : (int)$time['mday']);
148
+				$this->setTime((int)$time['hour'], (int)$time['minute'], (int)$time['second']);
149 149
 				break;
150 150
 
151 151
 			case 'object':
152 152
 				if ($time instanceof DateTime)
153 153
 				{
154
-					parent::__construct($time->format('Y-m-d H:i:s'),$time->getTimezone());
154
+					parent::__construct($time->format('Y-m-d H:i:s'), $time->getTimezone());
155 155
 					$this->setTimezone($tz);
156 156
 					break;
157 157
 				}
@@ -178,18 +178,18 @@  discard block
 block discarded – undo
178 178
 	 */
179 179
 	public function setWeekstart()
180 180
 	{
181
-		$wday = (int) $this->format('w'); // 0=sun, ..., 6=sat
182
-		switch($GLOBALS['egw_info']['user']['preferences']['calendar']['weekdaystarts'])
181
+		$wday = (int)$this->format('w'); // 0=sun, ..., 6=sat
182
+		switch ($GLOBALS['egw_info']['user']['preferences']['calendar']['weekdaystarts'])
183 183
 		{
184 184
 			case 'Sunday':
185 185
 				$wstart = -$wday;
186 186
 				break;
187 187
 			case 'Saturday':
188
-				$wstart =  -(6-$wday);
188
+				$wstart = -(6 - $wday);
189 189
 				break;
190 190
 			case 'Moday':
191 191
 			default:
192
-				$wstart = -($wday ? $wday-1 : 6);
192
+				$wstart = -($wday ? $wday - 1 : 6);
193 193
 				break;
194 194
 		}
195 195
 		if ($wstart) $this->add($wstart.'days');
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
 	 * @param array $filters $name => list($syear,$smonth,$sday,$sweek,$eyear,$emonth,$eday,$eweek) pairs with offsets
206 206
 	 * @return string
207 207
 	 */
208
-	public static function sql_filter($name, &$start, &$end, $column, array $filters=array())
208
+	public static function sql_filter($name, &$start, &$end, $column, array $filters = array())
209 209
 	{
210 210
 		if ($name == 'custom' && $start)
211 211
 		{
@@ -235,26 +235,26 @@  discard block
 block discarded – undo
235 235
 			$end   = new egw_time('now');
236 236
 			$end->setTime(0, 0, 0);
237 237
 
238
-			$year  = (int) $start->format('Y');
239
-			$month = (int) $start->format('m');
238
+			$year  = (int)$start->format('Y');
239
+			$month = (int)$start->format('m');
240 240
 
241
-			list($syear,$smonth,$sday,$sweek,$eyear,$emonth,$eday,$eweek) = $filters[$name];
241
+			list($syear, $smonth, $sday, $sweek, $eyear, $emonth, $eday, $eweek) = $filters[$name];
242 242
 
243 243
 			// Handle quarters
244
-			if(stripos($name, 'quarter') !== false)
244
+			if (stripos($name, 'quarter') !== false)
245 245
 			{
246
-				$start->setDate($year, ((int)floor(($smonth+$month) / 3.1)) * 3 + 1, 1);
247
-				$end->setDate($year, ((int)floor(($emonth+$month) / 3.1)+1) * 3 + 1, 1);
246
+				$start->setDate($year, ((int)floor(($smonth + $month) / 3.1)) * 3 + 1, 1);
247
+				$end->setDate($year, ((int)floor(($emonth + $month) / 3.1) + 1) * 3 + 1, 1);
248 248
 			}
249 249
 			elseif ($syear || $eyear)
250 250
 			{
251
-				$start->setDate($year+$syear, 1, 1);
252
-				$end->setDate($year+$eyear, 1, 1);
251
+				$start->setDate($year + $syear, 1, 1);
252
+				$end->setDate($year + $eyear, 1, 1);
253 253
 			}
254 254
 			elseif ($smonth || $emonth)
255 255
 			{
256
-				$start->setDate($year, $month+$smonth, 1);
257
-				$end->setDate($year, $month+$emonth, 1);
256
+				$start->setDate($year, $month + $smonth, 1);
257
+				$end->setDate($year, $month + $emonth, 1);
258 258
 			}
259 259
 			elseif ($sday || $eday)
260 260
 			{
@@ -309,9 +309,9 @@  discard block
 block discarded – undo
309 309
 	 * 		true = date only, false = time only as in user prefs, '' = date+time as in user prefs
310 310
 	 * @return int|string|array|datetime see $type
311 311
 	 */
312
-	public function format($type='')
312
+	public function format($type = '')
313 313
 	{
314
-		switch((string)$type)
314
+		switch ((string)$type)
315 315
 		{
316 316
 			case '':	// empty string:  date and time as in user prefs
317 317
 			//case '':	// boolean false: time as in user prefs
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
 			case 'integer':
337 337
 			case 'ts':
338 338
 				// ToDo: Check if PHP5.3 getTimestamp does the same, or always returns UTC timestamp
339
-				return mktime(parent::format('H'),parent::format('i'),parent::format('s'),parent::format('m'),parent::format('d'),parent::format('Y'));
339
+				return mktime(parent::format('H'), parent::format('i'), parent::format('s'), parent::format('m'), parent::format('d'), parent::format('Y'));
340 340
 
341 341
 			case 'object':
342 342
 			case 'datetime':
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
 					'second' => (int)parent::format('s'),
354 354
 					'full'   => parent::format('Ymd'),
355 355
 				);
356
-				$arr['raw'] = mktime($arr['hour'],$arr['minute'],$arr['second'],$arr['month'],$arr['day'],$arr['year']);
356
+				$arr['raw'] = mktime($arr['hour'], $arr['minute'], $arr['second'], $arr['month'], $arr['day'], $arr['year']);
357 357
 				return $arr;
358 358
 
359 359
 			case 'date_array':	// array with short keys used by date: Y, m, d, H, i, s (used in eTemplate)
@@ -387,18 +387,18 @@  discard block
 block discarded – undo
387 387
 	 * @param string $type=null type or return-value, default (null) same as $time
388 388
 	 * @return int|string|array|datetime null if time could not be parsed
389 389
 	 */
390
-	public static function server2user($time,$type=null)
390
+	public static function server2user($time, $type = null)
391 391
 	{
392
-		$typeof='egw_time';
392
+		$typeof = 'egw_time';
393 393
 		if (!($time instanceof egw_time))
394 394
 		{
395 395
 			try
396 396
 			{
397
-				$time = new egw_time($time,self::$server_timezone,$typeof);
397
+				$time = new egw_time($time, self::$server_timezone, $typeof);
398 398
 			}
399
-			catch(Exception $e)
399
+			catch (Exception $e)
400 400
 			{
401
-				return null;	// time could not be parsed
401
+				return null; // time could not be parsed
402 402
 			}
403 403
 		}
404 404
 		$time->setUser();
@@ -416,18 +416,18 @@  discard block
 block discarded – undo
416 416
 	 * @param string $type=null type or return-value, default (null) same as $time
417 417
 	 * @return int|string|array|datetime null if time could not be parsed
418 418
 	 */
419
-	public static function user2server($time,$type=null)
419
+	public static function user2server($time, $type = null)
420 420
 	{
421
-		$typeof='egw_time';
421
+		$typeof = 'egw_time';
422 422
 		if (!($time instanceof egw_time))
423 423
 		{
424 424
 			try
425 425
 			{
426
-				$time = new egw_time($time,self::$user_timezone,$typeof);
426
+				$time = new egw_time($time, self::$user_timezone, $typeof);
427 427
 			}
428
-			catch(Exception $e)
428
+			catch (Exception $e)
429 429
 			{
430
-				return null;	// time could not be parsed
430
+				return null; // time could not be parsed
431 431
 			}
432 432
 		}
433 433
 		$time->setServer();
@@ -447,7 +447,7 @@  discard block
 block discarded – undo
447 447
 	 * 		true = date only, false = time only as in user prefs, '' = date+time as in user prefs
448 448
 	 * @return int|string|array|datetime see $type, null if time could not be parsed
449 449
 	 */
450
-	public static function to($time='now',$type='')
450
+	public static function to($time = 'now', $type = '')
451 451
 	{
452 452
 		if (!($time instanceof egw_time))
453 453
 		{
@@ -455,9 +455,9 @@  discard block
 block discarded – undo
455 455
 			{
456 456
 				$time = new egw_time($time);
457 457
 			}
458
-			catch(Exception $e)
458
+			catch (Exception $e)
459 459
 			{
460
-				return null;	// time could not be parsed
460
+				return null; // time could not be parsed
461 461
 			}
462 462
 		}
463 463
 		return $time->format($type);
@@ -472,12 +472,12 @@  discard block
 block discarded – undo
472 472
 	 * @throws egw_exception_wrong_userinput if invalid $tz parameter
473 473
 	 * @return DateTimeZone
474 474
 	 */
475
-	public static function setUserPrefs($tz,$dateformat='',$timeformat='')
475
+	public static function setUserPrefs($tz, $dateformat = '', $timeformat = '')
476 476
 	{
477 477
 		//echo "<p>".__METHOD__."('$tz','$dateformat','$timeformat') ".function_backtrace()."</p>\n";
478 478
 		if (!empty($dateformat)) self::$user_dateformat = $dateformat;
479 479
 
480
-		switch($timeformat)
480
+		switch ($timeformat)
481 481
 		{
482 482
 			case '':
483 483
 				break;
@@ -494,7 +494,7 @@  discard block
 block discarded – undo
494 494
 		try {
495 495
 			self::$user_timezone = new DateTimeZone($tz);
496 496
 		}
497
-		catch(Exception $e)
497
+		catch (Exception $e)
498 498
 		{
499 499
 			// silently use server timezone, as we have no means to report the wrong timezone to the user from this class
500 500
 			self::$user_timezone = clone(self::$server_timezone);
@@ -510,7 +510,7 @@  discard block
 block discarded – undo
510 510
 	 * @param int|string|DateTime $time='now'
511 511
 	 * @return int difference in seconds between user and server time (for the given time!)
512 512
 	 */
513
-	public static function tz_offset_s($time='now')
513
+	public static function tz_offset_s($time = 'now')
514 514
 	{
515 515
 		if (!($time instanceof DateTime)) $time = new egw_time($time);
516 516
 
@@ -531,17 +531,17 @@  discard block
 block discarded – undo
531 531
 		try {
532 532
 			self::$server_timezone = new DateTimeZone($GLOBALS['egw_info']['server']['server_timezone']);
533 533
 		}
534
-		catch(Exception $e)
534
+		catch (Exception $e)
535 535
 		{
536 536
 			try {
537 537
 				self::$server_timezone = new DateTimeZone(date_default_timezone_get());
538 538
 			}
539
-			catch(Exception $e)
539
+			catch (Exception $e)
540 540
 			{
541 541
 				self::$server_timezone = new DateTimeZone('Europe/Berlin');
542 542
 			}
543 543
 			error_log(__METHOD__."() invalid server_timezone='{$GLOBALS['egw_info']['server']['server_timezone']}' setting now '".self::$server_timezone->getName()."'!");
544
-			config::save_value('server_timezone',$GLOBALS['egw_info']['server']['server_timezone'] = self::$server_timezone->getName(),'phpgwapi');
544
+			config::save_value('server_timezone', $GLOBALS['egw_info']['server']['server_timezone'] = self::$server_timezone->getName(), 'phpgwapi');
545 545
 		}
546 546
 		if (!isset($GLOBALS['egw_info']['user']['preferences']['common']['tz']))
547 547
 		{
@@ -564,15 +564,15 @@  discard block
 block discarded – undo
564 564
 	{
565 565
 		// prepare list of timezones from php, ignoring depricated ones and sort as follows
566 566
 		$tzs = array(
567
-			'Africa'     => array(),	// Contients
567
+			'Africa'     => array(), // Contients
568 568
 			'America'    => array(),
569 569
 			'Asia'       => array(),
570 570
 			'Australia'  => array(),
571 571
 			'Europe'     => array(),
572
-			'Atlantic'   => array(),	// Oceans
572
+			'Atlantic'   => array(), // Oceans
573 573
 			'Pacific'    => array(),
574 574
 			'Indian'     => array(),
575
-			'Antarctica' => array(),	// Poles
575
+			'Antarctica' => array(), // Poles
576 576
 			'Arctic'     => array(),
577 577
 			'UTC'        => array('UTC' => 'UTC'),
578 578
 		);
@@ -618,27 +618,27 @@  discard block
 block discarded – undo
618 618
 			'Australia/Yancowinna',
619 619
 			'Pacific/Samoa',
620 620
 		);
621
-		foreach(DateTimeZone::listIdentifiers() as $name)
621
+		foreach (DateTimeZone::listIdentifiers() as $name)
622 622
 		{
623
-			if (in_array($name,$no_vtimezone)) continue;	// do NOT allow to set in EGroupware, as we have not VTIMEZONE component for it
624
-			list($continent,$rest) = explode('/',$name,2);
625
-			if (!isset($tzs[$continent])) continue;	// old depricated timezones
626
-			$datetime = new egw_time('now',new DateTimeZone($name));
627
-			$tzs[$continent][$name] = str_replace(array('_','/'),array(' ',' / '),$name)."  ".$datetime->format();
623
+			if (in_array($name, $no_vtimezone)) continue; // do NOT allow to set in EGroupware, as we have not VTIMEZONE component for it
624
+			list($continent, $rest) = explode('/', $name, 2);
625
+			if (!isset($tzs[$continent])) continue; // old depricated timezones
626
+			$datetime = new egw_time('now', new DateTimeZone($name));
627
+			$tzs[$continent][$name] = str_replace(array('_', '/'), array(' ', ' / '), $name)."  ".$datetime->format();
628 628
 			unset($datetime);
629 629
 		}
630
-		foreach($tzs as $continent => &$data)
630
+		foreach ($tzs as $continent => &$data)
631 631
 		{
632
-			natcasesort($data);	// sort cities
632
+			natcasesort($data); // sort cities
633 633
 		}
634 634
 		unset($data);
635 635
 
636 636
 		// if user lang or installed langs contain a european language --> move Europe to top of tz list
637 637
 		$langs = class_exists('translation') ? translation::get_installed_langs() : array();
638
-		if (array_intersect(array($GLOBALS['egw_info']['user']['preferences']['common']['lang'])+array_keys($langs),
639
-			array('de','fr','it','nl','bg','ca','cs','da','el','es-es','et','eu','fi','hr','hu','lt','no','pl','pt','sk','sl','sv','tr','uk')))
638
+		if (array_intersect(array($GLOBALS['egw_info']['user']['preferences']['common']['lang']) + array_keys($langs),
639
+			array('de', 'fr', 'it', 'nl', 'bg', 'ca', 'cs', 'da', 'el', 'es-es', 'et', 'eu', 'fi', 'hr', 'hu', 'lt', 'no', 'pl', 'pt', 'sk', 'sl', 'sv', 'tr', 'uk')))
640 640
 		{
641
-			$tzs = array_merge(array('Europe' => $tzs['Europe']),$tzs);
641
+			$tzs = array_merge(array('Europe' => $tzs['Europe']), $tzs);
642 642
 		}
643 643
 		return $tzs;
644 644
 	}
@@ -649,30 +649,30 @@  discard block
 block discarded – undo
649 649
 	 * @param string $extra extra timezone to add, if not already included in user timezones
650 650
 	 * @return array tzid => label
651 651
 	 */
652
-	public static function getUserTimezones($extra=null)
652
+	public static function getUserTimezones($extra = null)
653 653
 	{
654 654
 		$tz = $GLOBALS['egw_info']['user']['preferences']['common']['tz'];
655
-		$user_tzs = explode(',',$GLOBALS['egw_info']['user']['preferences']['common']['tz_selection']);
655
+		$user_tzs = explode(',', $GLOBALS['egw_info']['user']['preferences']['common']['tz_selection']);
656 656
 		if (count($user_tzs) <= 1)
657 657
 		{
658 658
 			$user_tzs = $tz ? array($tz) : array();
659 659
 		}
660
-		if ($tz && !in_array($tz,$user_tzs))
660
+		if ($tz && !in_array($tz, $user_tzs))
661 661
 		{
662
-			$user_tzs = array_merge(array($tz),$user_tzs);
662
+			$user_tzs = array_merge(array($tz), $user_tzs);
663 663
 		}
664 664
 		if (!$user_tzs)	// if we have no user timezones, eg. user set no pref --> use server default
665 665
 		{
666 666
 			$user_tzs = array($GLOBALS['egw_info']['server']['server_timezone']);
667 667
 		}
668
-		if ($extra && !in_array($extra,$user_tzs))
668
+		if ($extra && !in_array($extra, $user_tzs))
669 669
 		{
670
-			$user_tzs = array_merge(array($extra),$user_tzs);
670
+			$user_tzs = array_merge(array($extra), $user_tzs);
671 671
 		}
672
-		$user_tzs = array_combine($user_tzs,$user_tzs);
673
-		foreach($user_tzs as $name => &$label)
672
+		$user_tzs = array_combine($user_tzs, $user_tzs);
673
+		foreach ($user_tzs as $name => &$label)
674 674
 		{
675
-			$label = str_replace(array('_','/'),array(' ',' / '),$label);
675
+			$label = str_replace(array('_', '/'), array(' ', ' / '), $label);
676 676
 		}
677 677
 		//_debug_array($user_tzs);
678 678
 		return $user_tzs;
Please login to merge, or discard this patch.
Braces   +76 added lines, -18 removed lines patch added patch discarded remove patch
@@ -85,7 +85,11 @@  discard block
 block discarded – undo
85 85
 	 */
86 86
 	public function __construct($time='now',DateTimeZone $tz=null,&$type=null)
87 87
 	{
88
-		if (is_null($tz)) $tz = self::$user_timezone;	// default user timezone
88
+		if (is_null($tz))
89
+		{
90
+			$tz = self::$user_timezone;
91
+		}
92
+		// default user timezone
89 93
 
90 94
 		switch(($type = gettype($time)))
91 95
 		{
@@ -98,7 +102,11 @@  discard block
 block discarded – undo
98 102
 				if (!(is_numeric($time) && ($time > 21000000 || $time < 19000000)))
99 103
 				{
100 104
 					$t_str = $time;
101
-					if (is_numeric($time) && strlen($time) == 8) $t_str .= 'T000000';	// 'Ymd' string used in calendar to represent a date
105
+					if (is_numeric($time) && strlen($time) == 8)
106
+					{
107
+						$t_str .= 'T000000';
108
+					}
109
+					// 'Ymd' string used in calendar to represent a date
102 110
 					// $time ending in a Z (Zulu or UTC time), is unterstood by DateTime class itself
103 111
 					try {
104 112
 						parent::__construct($t_str,$tz);
@@ -106,7 +114,10 @@  discard block
 block discarded – undo
106 114
 					}
107 115
 					catch(Exception $e) {
108 116
 						// if string is nummeric, ignore the exception and treat string as timestamp
109
-						if (!is_numeric($time)) throw $e;
117
+						if (!is_numeric($time))
118
+						{
119
+							throw $e;
120
+						}
110 121
 					}
111 122
 				}
112 123
 				$type = 'integer';
@@ -127,7 +138,9 @@  discard block
 block discarded – undo
127 138
 
128 139
 			case 'array':
129 140
 				parent::__construct('now',$tz);
130
-				if (isset($time['Y']))	// array format used in eTemplate
141
+				if (isset($time['Y']))
142
+				{
143
+					// array format used in eTemplate
131 144
 				{
132 145
 					$time = array(
133 146
 						'year'   => $time['Y'],
@@ -138,13 +151,17 @@  discard block
 block discarded – undo
138 151
 						'second' => $time['s'],
139 152
 					);
140 153
 				}
154
+				}
141 155
 				if (!empty($time['full']) && empty($time['year']))
142 156
 				{
143 157
 					$time['year']  = (int)substr($time['full'],0,4);
144 158
 					$time['month'] = (int)substr($time['full'],4,2);
145 159
 					$time['day']   = (int)substr($time['full'],6,2);
146 160
 				}
147
-				if (isset($time['year'])) $this->setDate((int)$time['year'],(int)$time['month'],isset($time['day']) ? (int)$time['day'] : (int)$time['mday']);
161
+				if (isset($time['year']))
162
+				{
163
+					$this->setDate((int)$time['year'],(int)$time['month'],isset($time['day']) ? (int)$time['day'] : (int)$time['mday']);
164
+				}
148 165
 				$this->setTime((int)$time['hour'],(int)$time['minute'],(int)$time['second']);
149 166
 				break;
150 167
 
@@ -168,7 +185,10 @@  discard block
 block discarded – undo
168 185
 	 */
169 186
 	public function add($interval)
170 187
 	{
171
-		if (is_string($interval)) $interval = DateInterval::createFromDateString($interval);
188
+		if (is_string($interval))
189
+		{
190
+			$interval = DateInterval::createFromDateString($interval);
191
+		}
172 192
 
173 193
 		parent::add($interval);
174 194
 	}
@@ -192,7 +212,10 @@  discard block
 block discarded – undo
192 212
 				$wstart = -($wday ? $wday-1 : 6);
193 213
 				break;
194 214
 		}
195
-		if ($wstart) $this->add($wstart.'days');
215
+		if ($wstart)
216
+		{
217
+			$this->add($wstart.'days');
218
+		}
196 219
 	}
197 220
 
198 221
 	/**
@@ -258,15 +281,27 @@  discard block
 block discarded – undo
258 281
 			}
259 282
 			elseif ($sday || $eday)
260 283
 			{
261
-				if ($sday) $start->add($sday.'days');
262
-				if ($eday) $end->add($eday.'days');
284
+				if ($sday)
285
+				{
286
+					$start->add($sday.'days');
287
+				}
288
+				if ($eday)
289
+				{
290
+					$end->add($eday.'days');
291
+				}
263 292
 			}
264 293
 			elseif ($sweek || $eweek)
265 294
 			{
266 295
 				$start->setWeekstart();
267
-				if ($sweek) $start->add($sweek.'weeks');
296
+				if ($sweek)
297
+				{
298
+					$start->add($sweek.'weeks');
299
+				}
268 300
 				$end->setWeekstart();
269
-				if ($eweek) $end->add($eweek.'weeks');
301
+				if ($eweek)
302
+				{
303
+					$end->add($eweek.'weeks');
304
+				}
270 305
 			}
271 306
 		}
272 307
 		// convert start + end from user to servertime for the filter
@@ -403,7 +438,10 @@  discard block
 block discarded – undo
403 438
 		}
404 439
 		$time->setUser();
405 440
 
406
-		if (is_null($type)) $type = $typeof;
441
+		if (is_null($type))
442
+		{
443
+			$type = $typeof;
444
+		}
407 445
 
408 446
 		//echo "<p>".__METHOD__."($time,$type) = ".print_r($format->format($type),true)."</p>\n";
409 447
 		return $time->format($type);
@@ -432,7 +470,10 @@  discard block
 block discarded – undo
432 470
 		}
433 471
 		$time->setServer();
434 472
 
435
-		if (is_null($type)) $type = $typeof;
473
+		if (is_null($type))
474
+		{
475
+			$type = $typeof;
476
+		}
436 477
 
437 478
 		//echo "<p>".__METHOD__."($time,$type) = ".print_r($format->format($type),true)."</p>\n";
438 479
 		return $time->format($type);
@@ -475,7 +516,10 @@  discard block
 block discarded – undo
475 516
 	public static function setUserPrefs($tz,$dateformat='',$timeformat='')
476 517
 	{
477 518
 		//echo "<p>".__METHOD__."('$tz','$dateformat','$timeformat') ".function_backtrace()."</p>\n";
478
-		if (!empty($dateformat)) self::$user_dateformat = $dateformat;
519
+		if (!empty($dateformat))
520
+		{
521
+			self::$user_dateformat = $dateformat;
522
+		}
479 523
 
480 524
 		switch($timeformat)
481 525
 		{
@@ -512,7 +556,10 @@  discard block
 block discarded – undo
512 556
 	 */
513 557
 	public static function tz_offset_s($time='now')
514 558
 	{
515
-		if (!($time instanceof DateTime)) $time = new egw_time($time);
559
+		if (!($time instanceof DateTime))
560
+		{
561
+			$time = new egw_time($time);
562
+		}
516 563
 
517 564
 		return egw_time::$user_timezone->getOffset($time) - egw_time::$server_timezone->getOffset($time);
518 565
 	}
@@ -620,9 +667,17 @@  discard block
 block discarded – undo
620 667
 		);
621 668
 		foreach(DateTimeZone::listIdentifiers() as $name)
622 669
 		{
623
-			if (in_array($name,$no_vtimezone)) continue;	// do NOT allow to set in EGroupware, as we have not VTIMEZONE component for it
670
+			if (in_array($name,$no_vtimezone))
671
+			{
672
+				continue;
673
+			}
674
+			// do NOT allow to set in EGroupware, as we have not VTIMEZONE component for it
624 675
 			list($continent,$rest) = explode('/',$name,2);
625
-			if (!isset($tzs[$continent])) continue;	// old depricated timezones
676
+			if (!isset($tzs[$continent]))
677
+			{
678
+				continue;
679
+			}
680
+			// old depricated timezones
626 681
 			$datetime = new egw_time('now',new DateTimeZone($name));
627 682
 			$tzs[$continent][$name] = str_replace(array('_','/'),array(' ',' / '),$name)."  ".$datetime->format();
628 683
 			unset($datetime);
@@ -661,10 +716,13 @@  discard block
 block discarded – undo
661 716
 		{
662 717
 			$user_tzs = array_merge(array($tz),$user_tzs);
663 718
 		}
664
-		if (!$user_tzs)	// if we have no user timezones, eg. user set no pref --> use server default
719
+		if (!$user_tzs)
720
+		{
721
+			// if we have no user timezones, eg. user set no pref --> use server default
665 722
 		{
666 723
 			$user_tzs = array($GLOBALS['egw_info']['server']['server_timezone']);
667 724
 		}
725
+		}
668 726
 		if ($extra && !in_array($extra,$user_tzs))
669 727
 		{
670 728
 			$user_tzs = array_merge(array($extra),$user_tzs);
Please login to merge, or discard this patch.