Completed
Push — master ( aa44e9...fa84e5 )
by Ralf
90:14 queued 73:21
created
api/src/Storage/Customfields.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -159,7 +159,7 @@
 block discarded – undo
159 159
 	 * @param string $app
160 160
 	 * @param boolean $all_private_too =false should all the private fields be returned too, default no
161 161
 	 * @param string $only_type2 =null if given only return fields of type2 == $only_type2
162
-	 * @return boolen true: if there is a custom field useing html, false if not
162
+	 * @return boolean true: if there is a custom field useing html, false if not
163 163
 	 */
164 164
 	public static function use_html($app, $all_private_too=false, $only_type2=null)
165 165
 	{
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 	 *
43 43
 	 * @var boolean
44 44
 	 */
45
-	protected $all_private_too=false;
45
+	protected $all_private_too = false;
46 46
 
47 47
 	/**
48 48
 	 * Iterator initialised for custom fields
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 	 * @param Api\Db $db =null reference to database instance to use
63 63
 	 * @return array with customfields
64 64
 	 */
65
-	function __construct($app, $all_private_too=false, $only_type2=null, $start=0, $num_rows=null, Api\Db $db=null)
65
+	function __construct($app, $all_private_too = false, $only_type2 = null, $start = 0, $num_rows = null, Api\Db $db = null)
66 66
 	{
67 67
 		$this->app = $app;
68 68
 		$this->all_private_too = $all_private_too;
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
 	protected function commasep_match($column, $values)
117 117
 	{
118 118
 		$to_or = array($column.' IS NULL');
119
-		foreach((array) $values as $value)
119
+		foreach ((array)$values as $value)
120 120
 		{
121 121
 			$to_or[] = self::$db->concat("','", $column, "','").' LIKE '.self::$db->quote('%,'.$value.',%');
122 122
 		}
@@ -132,9 +132,9 @@  discard block
 block discarded – undo
132 132
 	 * @param Api\Db $db =null reference to database to use
133 133
 	 * @return array with customfields
134 134
 	 */
135
-	public static function get($app, $all_private_too=false, $only_type2=null, Api\Db $db=null)
135
+	public static function get($app, $all_private_too = false, $only_type2 = null, Api\Db $db = null)
136 136
 	{
137
-		$cache_key = $app.':'.($all_private_too?'all':$GLOBALS['egw_info']['user']['account_id']).':'.$only_type2;
137
+		$cache_key = $app.':'.($all_private_too ? 'all' : $GLOBALS['egw_info']['user']['account_id']).':'.$only_type2;
138 138
 		$cfs = Api\Cache::getInstance(__CLASS__, $cache_key);
139 139
 
140 140
 		if (!isset($cfs))
@@ -161,9 +161,9 @@  discard block
 block discarded – undo
161 161
 	 * @param string $only_type2 =null if given only return fields of type2 == $only_type2
162 162
 	 * @return boolen true: if there is a custom field useing html, false if not
163 163
 	 */
164
-	public static function use_html($app, $all_private_too=false, $only_type2=null)
164
+	public static function use_html($app, $all_private_too = false, $only_type2 = null)
165 165
 	{
166
-		foreach(self::get($app, $all_private_too, $only_type2) as $data)
166
+		foreach (self::get($app, $all_private_too, $only_type2) as $data)
167 167
 		{
168 168
 			if ($data['type'] == 'htmlarea') return true;
169 169
 		}
@@ -186,17 +186,17 @@  discard block
 block discarded – undo
186 186
 	 */
187 187
 	public static function format(array $field, $value)
188 188
 	{
189
-		switch($field['type'])
189
+		switch ($field['type'])
190 190
 		{
191 191
 			case 'select-account':
192 192
 				if ($value)
193 193
 				{
194 194
 					$values = array();
195
-					foreach($field['rows'] > 1 ? explode(',', $value) : (array) $value as $value)
195
+					foreach ($field['rows'] > 1 ? explode(',', $value) : (array)$value as $value)
196 196
 					{
197 197
 						$values[] = Api\Accounts::username($value);
198 198
 					}
199
-					$value = implode(', ',$values);
199
+					$value = implode(', ', $values);
200 200
 				}
201 201
 				break;
202 202
 
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
 					$field['values'] = self::get_options_from_file($field['values']['@']);
212 212
 				}
213 213
 				$values = array();
214
-				foreach($field['rows'] > 1 ? explode(',', $value) : (array) $value as $value)
214
+				foreach ($field['rows'] > 1 ? explode(',', $value) : (array)$value as $value)
215 215
 				{
216 216
 					$values[] = isset($field['values'][$value]) ? $field['values'][$value] : '#'.$value;
217 217
 				}
@@ -275,12 +275,12 @@  discard block
 block discarded – undo
275 275
 	{
276 276
 		$options = array();
277 277
 
278
-		if (!($path = realpath($file[0] == '/' ? $file : EGW_SERVER_ROOT.'/'.$file)) ||	// file does not exist
279
-			substr($path,0,strlen(EGW_SERVER_ROOT)+1) != EGW_SERVER_ROOT.'/' ||	// we are NOT inside the eGW root
280
-			basename($path,'.php').'.php' != basename($path) ||	// extension is NOT .php
278
+		if (!($path = realpath($file[0] == '/' ? $file : EGW_SERVER_ROOT.'/'.$file)) || // file does not exist
279
+			substr($path, 0, strlen(EGW_SERVER_ROOT) + 1) != EGW_SERVER_ROOT.'/' || // we are NOT inside the eGW root
280
+			basename($path, '.php').'.php' != basename($path) || // extension is NOT .php
281 281
 			basename($path) == 'header.inc.php')	// dont allow to include our header again
282 282
 		{
283
-			return array(lang("'%1' is no php file in the eGW server root (%2)!".': '.$path,$file,EGW_SERVER_ROOT));
283
+			return array(lang("'%1' is no php file in the eGW server root (%2)!".': '.$path, $file, EGW_SERVER_ROOT));
284 284
 		}
285 285
 		include($path);
286 286
 
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
 
299 299
 		if (is_null($link_types))
300 300
 		{
301
-			$link_types = array_keys(array_intersect(Api\Link::app_list('query'),Api\Link::app_list('title')));
301
+			$link_types = array_keys(array_intersect(Api\Link::app_list('query'), Api\Link::app_list('title')));
302 302
 			$link_types[] = 'link-entry';
303 303
 		}
304 304
 		return $link_types;
@@ -315,31 +315,31 @@  discard block
 block discarded – undo
315 315
 	 * @param array $old =null old values before the update, if existing
316 316
 	 * @param string $id_name ='id' name/key of the (link-)id in $values
317 317
 	 */
318
-	public static function update_links($own_app,array $values,array $old=null,$id_name='id')
318
+	public static function update_links($own_app, array $values, array $old = null, $id_name = 'id')
319 319
 	{
320 320
 		$link_types = self::get_link_types();
321 321
 
322
-		foreach(self::get($own_app) as $name => $data)
322
+		foreach (self::get($own_app) as $name => $data)
323 323
 		{
324
-			if (!in_array($data['type'],$link_types)) continue;
324
+			if (!in_array($data['type'], $link_types)) continue;
325 325
 
326 326
 			// do we have a different old value --> delete that link
327 327
 			if ($old && $old['#'.$name] && $old['#'.$name] != $values['#'.$name])
328 328
 			{
329 329
 				if ($data['type'] == 'link-entry')
330 330
 				{
331
-					list($app,$id) = explode(':',$old['#'.$name]);
331
+					list($app, $id) = explode(':', $old['#'.$name]);
332 332
 				}
333 333
 				else
334 334
 				{
335 335
 					$app = $data['type'];
336 336
 					$id = $old['#'.$name];
337 337
 				}
338
-				Api\Link::unlink(false,$own_app,$values[$id_name],'',$app,$id);
338
+				Api\Link::unlink(false, $own_app, $values[$id_name], '', $app, $id);
339 339
 			}
340 340
 			if ($data['type'] == 'link-entry')
341 341
 			{
342
-				list($app,$id) = explode(':',$values['#'.$name]);
342
+				list($app, $id) = explode(':', $values['#'.$name]);
343 343
 			}
344 344
 			else
345 345
 			{
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
 			}
349 349
 			if ($id)	// create new link, does nothing for already existing links
350 350
 			{
351
-				Api\Link::link($own_app,$values[$id_name],$app,$id);
351
+				Api\Link::link($own_app, $values[$id_name], $app, $id);
352 352
 			}
353 353
 		}
354 354
 	}
@@ -369,25 +369,25 @@  discard block
 block discarded – undo
369 369
 		$old = $cfs[$cf['name']];
370 370
 
371 371
 		// Add new one in for numbering
372
-		if(!$cf['id'])
372
+		if (!$cf['id'])
373 373
 		{
374 374
 			$cfs[$cf['name']] = $cf;
375 375
 		}
376 376
 
377
-		if($old['order'] != $cf['order'] || $cf['order'] % 10 !== 0)
377
+		if ($old['order'] != $cf['order'] || $cf['order'] % 10 !== 0)
378 378
 		{
379 379
 			$cfs[$cf['name']]['order'] = $cf['order'];
380
-			uasort($cfs, function($a1, $a2){
380
+			uasort($cfs, function($a1, $a2) {
381 381
 				return $a1['order'] - $a2['order'];
382 382
 			});
383 383
 			$n = 0;
384
-			foreach($cfs as $old_cf)
384
+			foreach ($cfs as $old_cf)
385 385
 			{
386 386
 				$n += 10;
387
-				if($old_cf['order'] != $n)
387
+				if ($old_cf['order'] != $n)
388 388
 				{
389 389
 					$old_cf['order'] = $n;
390
-					if($old_cf['name'] != $cf['name'])
390
+					if ($old_cf['name'] != $cf['name'])
391 391
 					{
392 392
 						$update[] = $old_cf;
393 393
 					}
@@ -417,7 +417,7 @@  discard block
 block discarded – undo
417 417
 			'cf_app' => $cf['app'],
418 418
 		), __LINE__, __FILE__);
419 419
 
420
-		foreach($update as $old_cf)
420
+		foreach ($update as $old_cf)
421 421
 		{
422 422
 			self::$db->$op(self::TABLE, array(
423 423
 				'cf_order' => $old_cf['order'],
@@ -442,7 +442,7 @@  discard block
 block discarded – undo
442 442
 		if ($cfs) $query[] = self::$db->expression(self::TABLE, 'NOT ', array('cf_name' => array_keys($cfs)));
443 443
 		self::$db->delete(self::TABLE, $query, __LINE__, __FILE__);
444 444
 
445
-		foreach($cfs as $name => $cf)
445
+		foreach ($cfs as $name => $cf)
446 446
 		{
447 447
 			if (empty($cf['name'])) $cf['name'] = $name;
448 448
 			if (empty($cf['app']))  $cf['app'] = $app;
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
 	{
462 462
 		if (($cached = Api\Cache::getInstance(__CLASS__, $app)))
463 463
 		{
464
-			foreach($cached as $key)
464
+			foreach ($cached as $key)
465 465
 			{
466 466
 				Api\Cache::unsetInstance(__CLASS__, $key);
467 467
 			}
@@ -481,12 +481,12 @@  discard block
 block discarded – undo
481 481
 		$total = 0;
482 482
 		if (($cfs = self::get($app, true)))
483 483
 		{
484
-			foreach($cfs as &$data)
484
+			foreach ($cfs as &$data)
485 485
 			{
486 486
 				if ($data['private'])
487 487
 				{
488 488
 					$changed = 0;
489
-					foreach($data['private'] as &$id)
489
+					foreach ($data['private'] as &$id)
490 490
 					{
491 491
 						if (isset($ids2change[$id]))
492 492
 						{
@@ -516,7 +516,7 @@  discard block
 block discarded – undo
516 516
 		$types = array();
517 517
 		if (($cfs = self::get($app, true)))
518 518
 		{
519
-			foreach($cfs as $name => $data)
519
+			foreach ($cfs as $name => $data)
520 520
 			{
521 521
 				if ($data['type'] == 'select-account' || $data['type'] == 'api-accounts')
522 522
 				{
Please login to merge, or discard this patch.
Braces   +42 added lines, -11 removed lines patch added patch discarded remove patch
@@ -80,7 +80,10 @@  discard block
 block discarded – undo
80 80
 		{
81 81
 			$query[] = $this->commasep_match('cf_type2', $only_type2);
82 82
 		}
83
-		if (!$db) $db = self::$db;
83
+		if (!$db)
84
+		{
85
+			$db = self::$db;
86
+		}
84 87
 		$this->iterator = $db->select(self::TABLE, '*', $query, __LINE__, __FILE__,
85 88
 			!isset($num_rows) ? false : $start, 'ORDER BY cf_order ASC', 'phpgwapi', $num_rows);
86 89
 	}
@@ -165,7 +168,10 @@  discard block
 block discarded – undo
165 168
 	{
166 169
 		foreach(self::get($app, $all_private_too, $only_type2) as $data)
167 170
 		{
168
-			if ($data['type'] == 'htmlarea') return true;
171
+			if ($data['type'] == 'htmlarea')
172
+			{
173
+				return true;
174
+			}
169 175
 		}
170 176
 		return false;
171 177
 	}
@@ -227,7 +233,10 @@  discard block
 block discarded – undo
227 233
 				break;
228 234
 
229 235
 			case 'htmlarea':	// ToDo: EMail probably has a nicer html2text method
230
-				if ($value) $value = strip_tags(preg_replace('/<(br|p)[^>]*>/i', "\r\n", str_replace(array("\r", "\n"), '', $value)));
236
+				if ($value)
237
+				{
238
+					$value = strip_tags(preg_replace('/<(br|p)[^>]*>/i', "\r\n", str_replace(array("\r", "\n"), '', $value)));
239
+				}
231 240
 				break;
232 241
 
233 242
 			case 'ajax_select':	// ToDo: returns unchanged value for now
@@ -245,7 +254,10 @@  discard block
 block discarded – undo
245 254
 					{
246 255
 						$app = $field['type'];
247 256
 					}
248
-					if ($value) $value = Api\Link::title($app, $value);
257
+					if ($value)
258
+					{
259
+						$value = Api\Link::title($app, $value);
260
+					}
249 261
 				}
250 262
 				break;
251 263
 		}
@@ -278,10 +290,13 @@  discard block
 block discarded – undo
278 290
 		if (!($path = realpath($file[0] == '/' ? $file : EGW_SERVER_ROOT.'/'.$file)) ||	// file does not exist
279 291
 			substr($path,0,strlen(EGW_SERVER_ROOT)+1) != EGW_SERVER_ROOT.'/' ||	// we are NOT inside the eGW root
280 292
 			basename($path,'.php').'.php' != basename($path) ||	// extension is NOT .php
281
-			basename($path) == 'header.inc.php')	// dont allow to include our header again
293
+			basename($path) == 'header.inc.php')
294
+		{
295
+			// dont allow to include our header again
282 296
 		{
283 297
 			return array(lang("'%1' is no php file in the eGW server root (%2)!".': '.$path,$file,EGW_SERVER_ROOT));
284 298
 		}
299
+		}
285 300
 		include($path);
286 301
 
287 302
 		return $options;
@@ -321,7 +336,10 @@  discard block
 block discarded – undo
321 336
 
322 337
 		foreach(self::get($own_app) as $name => $data)
323 338
 		{
324
-			if (!in_array($data['type'],$link_types)) continue;
339
+			if (!in_array($data['type'],$link_types))
340
+			{
341
+				continue;
342
+			}
325 343
 
326 344
 			// do we have a different old value --> delete that link
327 345
 			if ($old && $old['#'.$name] && $old['#'.$name] != $values['#'.$name])
@@ -346,10 +364,13 @@  discard block
 block discarded – undo
346 364
 				$app = $data['type'];
347 365
 				$id = $values['#'.$name];
348 366
 			}
349
-			if ($id)	// create new link, does nothing for already existing links
367
+			if ($id)
368
+			{
369
+				// create new link, does nothing for already existing links
350 370
 			{
351 371
 				Api\Link::link($own_app,$values[$id_name],$app,$id);
352 372
 			}
373
+			}
353 374
 		}
354 375
 	}
355 376
 
@@ -377,7 +398,8 @@  discard block
 block discarded – undo
377 398
 		if($old['order'] != $cf['order'] || $cf['order'] % 10 !== 0)
378 399
 		{
379 400
 			$cfs[$cf['name']]['order'] = $cf['order'];
380
-			uasort($cfs, function($a1, $a2){
401
+			uasort($cfs, function($a1, $a2)
402
+			{
381 403
 				return $a1['order'] - $a2['order'];
382 404
 			});
383 405
 			$n = 0;
@@ -439,13 +461,22 @@  discard block
 block discarded – undo
439 461
 	public static function save($app, array $cfs)
440 462
 	{
441 463
 		$query = array('cf_app' => $app);
442
-		if ($cfs) $query[] = self::$db->expression(self::TABLE, 'NOT ', array('cf_name' => array_keys($cfs)));
464
+		if ($cfs)
465
+		{
466
+			$query[] = self::$db->expression(self::TABLE, 'NOT ', array('cf_name' => array_keys($cfs)));
467
+		}
443 468
 		self::$db->delete(self::TABLE, $query, __LINE__, __FILE__);
444 469
 
445 470
 		foreach($cfs as $name => $cf)
446 471
 		{
447
-			if (empty($cf['name'])) $cf['name'] = $name;
448
-			if (empty($cf['app']))  $cf['app'] = $app;
472
+			if (empty($cf['name']))
473
+			{
474
+				$cf['name'] = $name;
475
+			}
476
+			if (empty($cf['app']))
477
+			{
478
+				$cf['app'] = $app;
479
+			}
449 480
 
450 481
 			self::update($cf);
451 482
 		}
Please login to merge, or discard this patch.
api/src/Storage/History.php 3 patches
Doc Comments   +2 added lines patch added patch discarded remove patch
@@ -112,6 +112,8 @@
 block discarded – undo
112 112
 
113 113
 	/**
114 114
 	 * Static function to add a history record
115
+	 * @param string $field_code
116
+	 * @param string $new_value
115 117
 	 */
116 118
 	public static function static_add($appname, $id, $user, $field_code, $new_value, $old_value = '')
117 119
 	{
Please login to merge, or discard this patch.
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 	 * @param string $appname app name this instance operates on
52 52
 	 * @return historylog
53 53
 	 */
54
-	function __construct($appname='',$user=null)
54
+	function __construct($appname = '', $user = null)
55 55
 	{
56 56
 		$this->appname = $appname ? $appname : $GLOBALS['egw_info']['flags']['currentapp'];
57 57
 		$this->user = !is_null($user) ? $user : $GLOBALS['egw_info']['user']['account_id'];
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 		{
81 81
 			$where['history_record_id'] = $record_id;
82 82
 		}
83
-		$this->db->delete(self::TABLE,$where,__LINE__,__FILE__);
83
+		$this->db->delete(self::TABLE, $where, __LINE__, __FILE__);
84 84
 
85 85
 		return $this->db->affected_rows();
86 86
 	}
@@ -93,11 +93,11 @@  discard block
 block discarded – undo
93 93
 	 * @param string $new_value new value
94 94
 	 * @param string $old_value old value
95 95
 	 */
96
-	function add($status,$record_id,$new_value,$old_value)
96
+	function add($status, $record_id, $new_value, $old_value)
97 97
 	{
98 98
 		if ($new_value != $old_value)
99 99
 		{
100
-			$this->db->insert(self::TABLE,array(
100
+			$this->db->insert(self::TABLE, array(
101 101
 				'history_record_id' => $record_id,
102 102
 				'history_appname'   => $this->appname,
103 103
 				'history_owner'     => $this->user,
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 				'history_old_value' => $old_value,
107 107
 				'history_timestamp' => time(),
108 108
 				'sessionid' => $GLOBALS['egw']->session->sessionid_access_log,
109
-			),false,__LINE__,__FILE__);
109
+			), false, __LINE__, __FILE__);
110 110
 		}
111 111
 	}
112 112
 
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 	{
118 118
 		if ($new_value != $old_value)
119 119
 		{
120
-			$GLOBALS['egw']->db->insert(self::TABLE,array(
120
+			$GLOBALS['egw']->db->insert(self::TABLE, array(
121 121
 				'history_record_id' => $id,
122 122
 				'history_appname'   => $appname,
123 123
 				'history_owner'     => (int)$user,
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 				'history_old_value' => $old_value,
127 127
 				'history_timestamp' => time(),
128 128
 				'sessionid' => $GLOBALS['egw']->session->sessionid_access_log,
129
-			),false,__LINE__,__FILE__);
129
+			), false, __LINE__, __FILE__);
130 130
 		}
131 131
 	}
132 132
 
@@ -140,11 +140,11 @@  discard block
 block discarded – undo
140 140
 	 * @return array of arrays with keys id, record_id, appname, owner (account_id), status, new_value, old_value,
141 141
 	 * 	timestamp (Y-m-d H:i:s in servertime), user_ts (timestamp in user-time)
142 142
 	 */
143
-	function search($filter,$order='history_id',$sort='DESC',$limit=null)
143
+	function search($filter, $order = 'history_id', $sort = 'DESC', $limit = null)
144 144
 	{
145 145
 		if (!is_array($filter)) $filter = is_numeric($filter) ? array('history_record_id' => $filter) : array();
146 146
 
147
-		if (!$order || !preg_match('/^[a-z0-9_]+$/i',$order) || !preg_match('/^(asc|desc)?$/i',$sort))
147
+		if (!$order || !preg_match('/^[a-z0-9_]+$/i', $order) || !preg_match('/^(asc|desc)?$/i', $sort))
148 148
 		{
149 149
 			$orderby = 'ORDER BY history_id DESC';
150 150
 		}
@@ -152,9 +152,9 @@  discard block
 block discarded – undo
152 152
 		{
153 153
 			$orderby = "ORDER BY $order $sort";
154 154
 		}
155
-		foreach($filter as $col => $value)
155
+		foreach ($filter as $col => $value)
156 156
 		{
157
-			if (!is_numeric($col) && substr($col,0,8) != 'history_')
157
+			if (!is_numeric($col) && substr($col, 0, 8) != 'history_')
158 158
 			{
159 159
 				$filter['history_'.$col] = $value;
160 160
 				unset($filter[$col]);
@@ -166,11 +166,11 @@  discard block
 block discarded – undo
166 166
 		if (!$filter['history_record_id']) return array();
167 167
 
168 168
 		$rows = array();
169
-		foreach($this->db->select(self::TABLE, '*', $filter, __LINE__, __FILE__,
169
+		foreach ($this->db->select(self::TABLE, '*', $filter, __LINE__, __FILE__,
170 170
 			isset($limit) ? 0 : false, $orderby, 'phpgwapi', $limit) as $row)
171 171
 		{
172 172
 			$row['user_ts'] = $this->db->from_timestamp($row['history_timestamp']) + 3600 * $GLOBALS['egw_info']['user']['preferences']['common']['tz_offset'];
173
-			$rows[] = Api\Db::strip_array_keys($row,'history_');
173
+			$rows[] = Api\Db::strip_array_keys($row, 'history_');
174 174
 		}
175 175
 		return $rows;
176 176
 	}
@@ -188,8 +188,8 @@  discard block
 block discarded – undo
188 188
 		$rows = array();
189 189
 		$filter['history_appname'] = $query['appname'];
190 190
 		$filter['history_record_id'] = $query['record_id'];
191
-		if(is_array($query['colfilter'])) {
192
-			foreach($query['colfilter'] as $column => $value) {
191
+		if (is_array($query['colfilter'])) {
192
+			foreach ($query['colfilter'] as $column => $value) {
193 193
 				$filter[$column] = $value;
194 194
 			}
195 195
 		}
@@ -199,20 +199,20 @@  discard block
 block discarded – undo
199 199
 		}
200 200
 		else
201 201
 		{
202
-			$total = $GLOBALS['egw']->db->select(self::TABLE,'COUNT(*)',$filter,__LINE__,__FILE__,false,'','phpgwapi',0)->fetchColumn();
202
+			$total = $GLOBALS['egw']->db->select(self::TABLE, 'COUNT(*)', $filter, __LINE__, __FILE__, false, '', 'phpgwapi', 0)->fetchColumn();
203 203
 		}
204 204
 		// filter out private (or no longer defined) custom fields
205 205
 		if ($filter['history_appname'])
206 206
 		{
207 207
 			$to_or[] = "history_status NOT LIKE '#%'";
208 208
 			// explicitly allow "##" used to store iCal/vCard X-attributes
209
-			if (in_array($filter['history_appname'], array('calendar','infolog','addressbook')))
209
+			if (in_array($filter['history_appname'], array('calendar', 'infolog', 'addressbook')))
210 210
 			{
211 211
 				$to_or[] = "history_status LIKE '##%'";
212 212
 			}
213 213
 			if (($cfs = Customfields::get($filter['history_appname'])))
214 214
 			{
215
-				$to_or[] =  'history_status IN ('.implode(',', array_map(function($str)
215
+				$to_or[] = 'history_status IN ('.implode(',', array_map(function($str)
216 216
 				{
217 217
 					return $GLOBALS['egw']->db->quote('#'.$str);
218 218
 				}, array_keys($cfs))).')';
@@ -221,25 +221,25 @@  discard block
 block discarded – undo
221 221
 		}
222 222
 		$_query = array(array(
223 223
 			'table' => self::TABLE,
224
-			'cols' => array('history_id', 'history_record_id','history_appname','history_owner','history_status','history_new_value', 'history_timestamp','history_old_value'),
224
+			'cols' => array('history_id', 'history_record_id', 'history_appname', 'history_owner', 'history_status', 'history_new_value', 'history_timestamp', 'history_old_value'),
225 225
 			'where' => $filter,
226 226
 		));
227 227
 
228 228
 		// Add in files, if possible
229
-		if($GLOBALS['egw_info']['user']['apps']['filemanager'] &&
230
-			$file = Api\Vfs\Sqlfs\StreamWrapper::url_stat("/apps/{$query['appname']}/{$query['record_id']}",STREAM_URL_STAT_LINK))
229
+		if ($GLOBALS['egw_info']['user']['apps']['filemanager'] &&
230
+			$file = Api\Vfs\Sqlfs\StreamWrapper::url_stat("/apps/{$query['appname']}/{$query['record_id']}", STREAM_URL_STAT_LINK))
231 231
 		{
232 232
 			$_query[] = array(
233 233
 				'table' => Api\Vfs\Sqlfs\StreamWrapper::TABLE,
234
-				'cols' =>array('fs_id', 'fs_dir', "'filemanager'",'COALESCE(fs_modifier,fs_creator)',"'~file~'",'fs_name','fs_modified', 'fs_mime'),
234
+				'cols' =>array('fs_id', 'fs_dir', "'filemanager'", 'COALESCE(fs_modifier,fs_creator)', "'~file~'", 'fs_name', 'fs_modified', 'fs_mime'),
235 235
 				'where' => array('fs_dir' => $file['ino'])
236 236
 			);
237 237
 		}
238 238
 		$new_file_id = array();
239
-		foreach($GLOBALS['egw']->db->union(
239
+		foreach ($GLOBALS['egw']->db->union(
240 240
 			$_query,
241 241
 			__LINE__, __FILE__,
242
-			' ORDER BY ' . ($query['order'] ? $query['order'] : 'history_timestamp') . ' ' . ($query['sort'] ? $query['sort'] : 'DESC'),
242
+			' ORDER BY '.($query['order'] ? $query['order'] : 'history_timestamp').' '.($query['sort'] ? $query['sort'] : 'DESC'),
243 243
 			$query['start'],
244 244
 			$query['num_rows']
245 245
 		) as $row)
@@ -247,15 +247,15 @@  discard block
 block discarded – undo
247 247
 			$row['user_ts'] = $GLOBALS['egw']->db->from_timestamp($row['history_timestamp']) + 3600 * $GLOBALS['egw_info']['user']['preferences']['common']['tz_offset'];
248 248
 
249 249
 			// Explode multi-part values
250
-			foreach(array('history_new_value','history_old_value') as $field)
250
+			foreach (array('history_new_value', 'history_old_value') as $field)
251 251
 			{
252
-				if(strpos($row[$field],Tracking::ONE2N_SEPERATOR) !== false)
252
+				if (strpos($row[$field], Tracking::ONE2N_SEPERATOR) !== false)
253 253
 				{
254
-					$row[$field] = explode(Tracking::ONE2N_SEPERATOR,$row[$field]);
254
+					$row[$field] = explode(Tracking::ONE2N_SEPERATOR, $row[$field]);
255 255
 				}
256 256
 			}
257 257
 			// Get information needed for proper display
258
-			if($row['history_appname'] == 'filemanager')
258
+			if ($row['history_appname'] == 'filemanager')
259 259
 			{
260 260
 				$new_version = $new_file_id[$row['history_new_value']];
261 261
 				$new_file_id[$row['history_new_value']] = count($rows);
@@ -271,12 +271,12 @@  discard block
 block discarded – undo
271 271
 					'mime' => $row['history_old_value']
272 272
 				);
273 273
 				$row['history_old_value'] = '';
274
-				if($new_version !== null)
274
+				if ($new_version !== null)
275 275
 				{
276 276
 					$rows[$new_version]['old_value'] = $row['history_new_value'];
277 277
 				}
278 278
 			}
279
-			$rows[] = Api\Db::strip_array_keys($row,'history_');
279
+			$rows[] = Api\Db::strip_array_keys($row, 'history_');
280 280
 		}
281 281
 		if ($mysql_calc_rows)
282 282
 		{
Please login to merge, or discard this patch.
Braces   +16 added lines, -5 removed lines patch added patch discarded remove patch
@@ -142,7 +142,10 @@  discard block
 block discarded – undo
142 142
 	 */
143 143
 	function search($filter,$order='history_id',$sort='DESC',$limit=null)
144 144
 	{
145
-		if (!is_array($filter)) $filter = is_numeric($filter) ? array('history_record_id' => $filter) : array();
145
+		if (!is_array($filter))
146
+		{
147
+			$filter = is_numeric($filter) ? array('history_record_id' => $filter) : array();
148
+		}
146 149
 
147 150
 		if (!$order || !preg_match('/^[a-z0-9_]+$/i',$order) || !preg_match('/^(asc|desc)?$/i',$sort))
148 151
 		{
@@ -160,10 +163,16 @@  discard block
 block discarded – undo
160 163
 				unset($filter[$col]);
161 164
 			}
162 165
 		}
163
-		if (!isset($filter['history_appname'])) $filter['history_appname'] = $this->appname;
166
+		if (!isset($filter['history_appname']))
167
+		{
168
+			$filter['history_appname'] = $this->appname;
169
+		}
164 170
 
165 171
 		// do not try to read all history entries of an app
166
-		if (!$filter['history_record_id']) return array();
172
+		if (!$filter['history_record_id'])
173
+		{
174
+			return array();
175
+		}
167 176
 
168 177
 		$rows = array();
169 178
 		foreach($this->db->select(self::TABLE, '*', $filter, __LINE__, __FILE__,
@@ -188,8 +197,10 @@  discard block
 block discarded – undo
188 197
 		$rows = array();
189 198
 		$filter['history_appname'] = $query['appname'];
190 199
 		$filter['history_record_id'] = $query['record_id'];
191
-		if(is_array($query['colfilter'])) {
192
-			foreach($query['colfilter'] as $column => $value) {
200
+		if(is_array($query['colfilter']))
201
+		{
202
+			foreach($query['colfilter'] as $column => $value)
203
+			{
193 204
 				$filter[$column] = $value;
194 205
 			}
195 206
 		}
Please login to merge, or discard this patch.
api/src/Storage/Merge.php 4 patches
Doc Comments   +14 added lines, -7 removed lines patch added patch discarded remove patch
@@ -368,9 +368,9 @@  discard block
 block discarded – undo
368 368
 	 *
369 369
 	 * Calls get_links() repeatedly to get all the combinations for the content.
370 370
 	 *
371
-	 * @param $app String appname
371
+	 * @param string $app String appname
372 372
 	 * @param $id String ID of record
373
-	 * @param $prefix
373
+	 * @param string $prefix
374 374
 	 * @param $content String document content
375 375
 	 */
376 376
 	protected function get_all_links($app, $id, $prefix, &$content)
@@ -530,7 +530,7 @@  discard block
 block discarded – undo
530 530
 	 * @param mixed $app_limit app_limit, if not set checks the global limit
531 531
 	 * @param string $checkas [AND|ISALLOWED], AND default; if set to ISALLOWED it is checked if Export is allowed
532 532
 	 *
533
-	 * @return bool - true if no export is allowed or a limit is set, false if there is no restriction
533
+	 * @return boolean|null - true if no export is allowed or a limit is set, false if there is no restriction
534 534
 	 */
535 535
 	public static function hasExportLimit($app_limit,$checkas='AND')
536 536
 	{
@@ -579,6 +579,9 @@  discard block
 block discarded – undo
579 579
 		return $content;
580 580
 	}
581 581
 
582
+	/**
583
+	 * @param string $mimetype
584
+	 */
582 585
 	protected function apply_styles (&$content, $mimetype, $mso_application_progid=null)
583 586
 	{
584 587
 		if (!isset($mso_application_progid))
@@ -1169,6 +1172,8 @@  discard block
 block discarded – undo
1169 1172
 
1170 1173
 	/**
1171 1174
 	 * Convert numeric values in spreadsheets into actual numeric values
1175
+	 * @param string $content
1176
+	 * @param string $mimetype
1172 1177
 	 */
1173 1178
 	protected function format_spreadsheet_numbers(&$content, $names, $mimetype)
1174 1179
 	{
@@ -1238,6 +1243,7 @@  discard block
 block discarded – undo
1238 1243
 
1239 1244
 	/**
1240 1245
 	 * Convert date / timestamp values in spreadsheets into actual date / timestamp values
1246
+	 * @param string $mimetype
1241 1247
 	 */
1242 1248
 	protected function format_spreadsheet_dates(&$content, $names, &$values, $mimetype)
1243 1249
 	{
@@ -1342,6 +1348,7 @@  discard block
 block discarded – undo
1342 1348
 	/**
1343 1349
 	 * Expand link_to custom fields with the merge replacements from the app
1344 1350
 	 * but only if the template uses them.
1351
+	 * @param string $app
1345 1352
 	 */
1346 1353
 	public function cf_link_to_expand($values, $content, &$replacements, $app = null)
1347 1354
 	{
@@ -1407,7 +1414,7 @@  discard block
 block discarded – undo
1407 1414
 	/**
1408 1415
 	 * Process special flags, such as IF or NELF
1409 1416
 	 *
1410
-	 * @param content Text to be examined and changed
1417
+	 * @param content string to be examined and changed
1411 1418
 	 * @param replacements array of markers => replacement
1412 1419
 	 *
1413 1420
 	 * @return changed content
@@ -1720,8 +1727,7 @@  discard block
 block discarded – undo
1720 1727
 	 * Get a list of document actions / files from the given directory
1721 1728
 	 *
1722 1729
 	 * @param string $dirs Directory(s comma or space separated) to search
1723
-	 * @param string $prefix='document_' prefix for array keys
1724
-	 * @param array|string $mime_filter=null allowed mime type(s), default all, negative filter if $mime_filter[0] === '!'
1730
+	 * @param array|string $mime_filter allowed mime type(s), default all, negative filter if $mime_filter[0] === '!'
1725 1731
 	 * @return array List of documents, suitable for a selectbox.  The key is document_<filename>.
1726 1732
 	 */
1727 1733
 	public static function get_documents($dirs, $prefix='document_', $mime_filter=null, $app='')
@@ -1988,7 +1994,8 @@  discard block
 block discarded – undo
1988 1994
 	 *
1989 1995
 	 * @param string &$document maybe relative path of document, on return true absolute path to existing document
1990 1996
 	 * @param string $dirs comma or whitespace separated directories
1991
-	 * @return string|boolean false if document exists, otherwise string with error-message
1997
+	 * @param string $document
1998
+	 * @return false|string false if document exists, otherwise string with error-message
1992 1999
 	 */
1993 2000
 	public static function check_document(&$document, $dirs)
1994 2001
 	{
Please login to merge, or discard this patch.
Spacing   +363 added lines, -364 removed lines patch added patch discarded remove patch
@@ -82,14 +82,14 @@  discard block
 block discarded – undo
82 82
 	 * Configuration for HTML Tidy to clean up any HTML content that is kept
83 83
 	 */
84 84
 	public static $tidy_config = array(
85
-		'output-xml'		=> true,	// Entity encoding
85
+		'output-xml'		=> true, // Entity encoding
86 86
 		'show-body-only'	=> true,
87 87
 		'output-encoding'	=> 'utf-8',
88 88
 		'input-encoding'	=> 'utf-8',
89
-		'quote-ampersand'	=> false,	// Prevent double encoding
90
-		'quote-nbsp'		=> true,	// XSLT can handle spaces easier
89
+		'quote-ampersand'	=> false, // Prevent double encoding
90
+		'quote-nbsp'		=> true, // XSLT can handle spaces easier
91 91
 		'preserve-entities'	=> true,
92
-		'wrap'			=> 0,		// Wrapping can break output
92
+		'wrap'			=> 0, // Wrapping can break output
93 93
 	);
94 94
 
95 95
 	/**
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 		$this->contacts = new Api\Contacts();
121 121
 
122 122
 		$this->datetime_format = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'].' '.
123
-			($GLOBALS['egw_info']['user']['preferences']['common']['timeformat']==12 ? 'h:i a' : 'H:i');
123
+			($GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] == 12 ? 'h:i a' : 'H:i');
124 124
 
125 125
 		$this->export_limit = self::getExportLimit();
126 126
 	}
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
 		$accountsel = new uiaccountsel();
136 136
 
137 137
 		return '<input type="hidden" value="" name="newsettings[export_limit_excepted]" />'.
138
-			$accountsel->selection('newsettings[export_limit_excepted]','export_limit_excepted',$config['export_limit_excepted'],'both',4);
138
+			$accountsel->selection('newsettings[export_limit_excepted]', 'export_limit_excepted', $config['export_limit_excepted'], 'both', 4);
139 139
 	}
140 140
 
141 141
 	/**
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
 	 * @param string &$content=null content to create some replacements only if they are use
150 150
 	 * @return array|boolean array with replacements or false if entry not found
151 151
 	 */
152
-	abstract protected function get_replacements($id,&$content=null);
152
+	abstract protected function get_replacements($id, &$content = null);
153 153
 
154 154
 	/**
155 155
 	 * Return if merge-print is implemented for given mime-type (and/or extension)
@@ -157,13 +157,13 @@  discard block
 block discarded – undo
157 157
 	 * @param string $mimetype eg. text/plain
158 158
 	 * @param string $extension only checked for applications/msword and .rtf
159 159
 	 */
160
-	static public function is_implemented($mimetype,$extension=null)
160
+	static public function is_implemented($mimetype, $extension = null)
161 161
 	{
162
-		static $zip_available=null;
162
+		static $zip_available = null;
163 163
 		if (is_null($zip_available))
164 164
 		{
165 165
 			$zip_available = check_load_extension('zip') &&
166
-				class_exists('ZipArchive');	// some PHP has zip extension, but no ZipArchive (eg. RHEL5!)
166
+				class_exists('ZipArchive'); // some PHP has zip extension, but no ZipArchive (eg. RHEL5!)
167 167
 		}
168 168
 		switch ($mimetype)
169 169
 		{
@@ -171,27 +171,27 @@  discard block
 block discarded – undo
171 171
 				if (strtolower($extension) != '.rtf') break;
172 172
 			case 'application/rtf':
173 173
 			case 'text/rtf':
174
-				return true;	// rtf files
174
+				return true; // rtf files
175 175
 			case 'application/vnd.oasis.opendocument.text':	// oo text
176 176
 			case 'application/vnd.oasis.opendocument.spreadsheet':	// oo spreadsheet
177 177
 				if (!$zip_available) break;
178
-				return true;	// open office write xml files
178
+				return true; // open office write xml files
179 179
 			case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':	// ms word 2007 xml format
180 180
 			case 'application/vnd.openxmlformats-officedocument.wordprocessingml.d':	// mimetypes in vfs are limited to 64 chars
181 181
 			case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':	// ms excel 2007 xml format
182 182
 			case 'application/vnd.openxmlformats-officedocument.spreadsheetml.shee':
183 183
 				if (!$zip_available) break;
184
-				return true;	// ms word xml format
184
+				return true; // ms word xml format
185 185
 			case 'application/xml':
186
-				return true;	// alias for text/xml, eg. ms office 2003 word format
186
+				return true; // alias for text/xml, eg. ms office 2003 word format
187 187
 			case 'message/rfc822':
188 188
 				return true; // ToDo: check if you are theoretical able to send mail
189 189
 			case 'application/x-yaml':
190
-				return true;	// yaml file, plain text with marginal syntax support for multiline replacements
190
+				return true; // yaml file, plain text with marginal syntax support for multiline replacements
191 191
 			default:
192
-				if (substr($mimetype,0,5) == 'text/')
192
+				if (substr($mimetype, 0, 5) == 'text/')
193 193
 				{
194
-					return true;	// text files
194
+					return true; // text files
195 195
 				}
196 196
 				break;
197 197
 		}
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 	 * @param boolean $ignore_acl =false true: no acl check
210 210
 	 * @return array
211 211
 	 */
212
-	public function contact_replacements($contact,$prefix='',$ignore_acl=false)
212
+	public function contact_replacements($contact, $prefix = '', $ignore_acl = false)
213 213
 	{
214 214
 		if (!is_array($contact))
215 215
 		{
@@ -218,13 +218,13 @@  discard block
 block discarded – undo
218 218
 		if (!is_array($contact)) return array();
219 219
 
220 220
 		$replacements = array();
221
-		foreach(array_keys($this->contacts->contact_fields) as $name)
221
+		foreach (array_keys($this->contacts->contact_fields) as $name)
222 222
 		{
223 223
 			$value = $contact[$name];
224
-			switch($name)
224
+			switch ($name)
225 225
 			{
226 226
 				case 'created': case 'modified':
227
-					if($value) $value = Api\DateTime::to($value);
227
+					if ($value) $value = Api\DateTime::to($value);
228 228
 					break;
229 229
 				case 'bday':
230 230
 					if ($value)
@@ -241,11 +241,11 @@  discard block
 block discarded – undo
241 241
 						// if cat-tree is displayed, we return a full category path not just the name of the cat
242 242
 						$use = $GLOBALS['egw_info']['server']['cat_tab'] == 'Tree' ? 'path' : 'name';
243 243
 						$cats = array();
244
-						foreach(is_array($value) ? $value : explode(',',$value) as $cat_id)
244
+						foreach (is_array($value) ? $value : explode(',', $value) as $cat_id)
245 245
 						{
246
-							$cats[] = $GLOBALS['egw']->categories->id2name($cat_id,$use);
246
+							$cats[] = $GLOBALS['egw']->categories->id2name($cat_id, $use);
247 247
 						}
248
-						$value = implode(', ',$cats);
248
+						$value = implode(', ', $cats);
249 249
 					}
250 250
 					break;
251 251
 				case 'jpegphoto':	// returning a link might make more sense then the binary photo
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
 					{
254 254
 						$value = ($GLOBALS['egw_info']['server']['webserver_url'][0] == '/' ?
255 255
 							($_SERVER['HTTPS'] ? 'https://' : 'http://').$_SERVER['HTTP_HOST'] : '').
256
-							$GLOBALS['egw']->link('/index.php',$contact['photo']);
256
+							$GLOBALS['egw']->link('/index.php', $contact['photo']);
257 257
 					}
258 258
 					break;
259 259
 				case 'tel_prefer':
@@ -265,40 +265,39 @@  discard block
 block discarded – undo
265 265
 				case 'account_id':
266 266
 					if ($value)
267 267
 					{
268
-						$replacements['$$'.($prefix ? $prefix.'/':'').'account_lid$$'] = $GLOBALS['egw']->accounts->id2name($value);
268
+						$replacements['$$'.($prefix ? $prefix.'/' : '').'account_lid$$'] = $GLOBALS['egw']->accounts->id2name($value);
269 269
 					}
270 270
 					break;
271 271
 			}
272
-			if ($name != 'photo') $replacements['$$'.($prefix ? $prefix.'/':'').$name.'$$'] = $value;
272
+			if ($name != 'photo') $replacements['$$'.($prefix ? $prefix.'/' : '').$name.'$$'] = $value;
273 273
 		}
274 274
 		// set custom fields, should probably go to a general method all apps can use
275 275
 		// need to load all cfs for $ignore_acl=true
276
-		foreach($ignore_acl ? Customfields::get('addressbook', true) : $this->contacts->customfields as $name => $field)
276
+		foreach ($ignore_acl ? Customfields::get('addressbook', true) : $this->contacts->customfields as $name => $field)
277 277
 		{
278 278
 			$name = '#'.$name;
279
-			$replacements['$$'.($prefix ? $prefix.'/':'').$name.'$$'] =
279
+			$replacements['$$'.($prefix ? $prefix.'/' : '').$name.'$$'] =
280 280
 				// use raw data for yaml, no user-preference specific formatting
281
-				$this->mimetype == 'application/x-yaml' ? (string)$contact[$name] :
282
-				Customfields::format($field, (string)$contact[$name]);
281
+				$this->mimetype == 'application/x-yaml' ? (string)$contact[$name] : Customfields::format($field, (string)$contact[$name]);
283 282
 		}
284 283
 
285 284
 		// Add in extra cat field
286 285
 		$cats = array();
287
-		foreach(is_array($contact['cat_id']) ? $contact['cat_id'] : explode(',',$contact['cat_id']) as $cat_id)
286
+		foreach (is_array($contact['cat_id']) ? $contact['cat_id'] : explode(',', $contact['cat_id']) as $cat_id)
288 287
 		{
289
-			if(!$cat_id) continue;
290
-			if($GLOBALS['egw']->categories->id2name($cat_id,'main') != $cat_id)
288
+			if (!$cat_id) continue;
289
+			if ($GLOBALS['egw']->categories->id2name($cat_id, 'main') != $cat_id)
291 290
 			{
292 291
 				$path = explode(' / ', $GLOBALS['egw']->categories->id2name($cat_id, 'path'));
293 292
 				unset($path[0]); // Drop main
294
-				$cats[$GLOBALS['egw']->categories->id2name($cat_id,'main')][] = implode(' / ', $path);
295
-			} elseif($cat_id) {
293
+				$cats[$GLOBALS['egw']->categories->id2name($cat_id, 'main')][] = implode(' / ', $path);
294
+			} elseif ($cat_id) {
296 295
 				$cats[$cat_id] = array();
297 296
 			}
298 297
 		}
299
-		foreach($cats as $main => $cat) {
300
-			$replacements['$$'.($prefix ? $prefix.'/':'').'categories$$'] .= $GLOBALS['egw']->categories->id2name($main,'name')
301
-				. (count($cat) > 0 ? ': ' : '') . implode(', ', $cats[$main]) . "\n";
298
+		foreach ($cats as $main => $cat) {
299
+			$replacements['$$'.($prefix ? $prefix.'/' : '').'categories$$'] .= $GLOBALS['egw']->categories->id2name($main, 'name')
300
+				. (count($cat) > 0 ? ': ' : '').implode(', ', $cats[$main])."\n";
302 301
 		}
303 302
 		return $replacements;
304 303
 	}
@@ -317,34 +316,34 @@  discard block
 block discarded – undo
317 316
 	 * 	'link' - URL to the entry
318 317
 	 * 	'href' - HREF tag wrapped around the title
319 318
 	 */
320
-	protected function get_links($app, $id, $only_app='', $exclude = array(), $style = 'title')
319
+	protected function get_links($app, $id, $only_app = '', $exclude = array(), $style = 'title')
321 320
 	{
322 321
 		$links = Api\Link::get_links($app, $id, $only_app);
323 322
 		$link_titles = array();
324
-		foreach($links as $link_info)
323
+		foreach ($links as $link_info)
325 324
 		{
326 325
 			// Using only_app only returns the ID
327
-			if(!is_array($link_info) && $only_app && $only_app[0] !== '!')
326
+			if (!is_array($link_info) && $only_app && $only_app[0] !== '!')
328 327
 			{
329 328
 				$link_info = array(
330 329
 					'app'	=> $only_app,
331 330
 					'id'	=> $link_info
332 331
 				);
333 332
 			}
334
-			if($exclude && in_array($link_info['id'], $exclude)) continue;
333
+			if ($exclude && in_array($link_info['id'], $exclude)) continue;
335 334
 
336 335
 			$title = Api\Link::title($link_info['app'], $link_info['id']);
337
-			if(class_exists('EGroupware\Stylite\Vfs\Links\StreamWrapper') && $link_info['app'] != Api\Link::VFS_APPNAME)
336
+			if (class_exists('EGroupware\Stylite\Vfs\Links\StreamWrapper') && $link_info['app'] != Api\Link::VFS_APPNAME)
338 337
 			{
339 338
 				$title = Stylite\Vfs\Links\StreamWrapper::entry2name($link_info['app'], $link_info['id'], $title);
340 339
 			}
341
-			if($style == 'href' || $style == 'link')
340
+			if ($style == 'href' || $style == 'link')
342 341
 			{
343 342
 				$link = Api\Link::view($link_info['app'], $link_info['id'], $link_info);
344
-				if($link_info['app'] != Api\Link::VFS_APPNAME)
343
+				if ($link_info['app'] != Api\Link::VFS_APPNAME)
345 344
 				{
346 345
 					// Set app to false so we always get an external link
347
-					$link = str_replace(',', '%2C', $GLOBALS['egw']->framework->link('/index.php',$link, false));
346
+					$link = str_replace(',', '%2C', $GLOBALS['egw']->framework->link('/index.php', $link, false));
348 347
 				}
349 348
 				else
350 349
 				{
@@ -360,7 +359,7 @@  discard block
 block discarded – undo
360 359
 			}
361 360
 			$link_titles[] = $title;
362 361
 		}
363
-		return implode("\n",$link_titles);
362
+		return implode("\n", $link_titles);
364 363
 	}
365 364
 
366 365
 	/**
@@ -377,33 +376,33 @@  discard block
 block discarded – undo
377 376
 	{
378 377
 		$array = array();
379 378
 		$pattern = '@\$(links_attachments|links|attachments|link)\/?(title|href|link)?\/?([a-z]*)\$@';
380
-		static $link_cache=null;
379
+		static $link_cache = null;
381 380
 		$matches = null;
382
-		if(preg_match_all($pattern, $content, $matches))
381
+		if (preg_match_all($pattern, $content, $matches))
383 382
 		{
384
-			foreach($matches[0] as $i => $placeholder)
383
+			foreach ($matches[0] as $i => $placeholder)
385 384
 			{
386 385
 				$placeholder = substr($placeholder, 1, -1);
387
-				if($link_cache[$id][$placeholder])
386
+				if ($link_cache[$id][$placeholder])
388 387
 				{
389 388
 					$array[$placeholder] = $link_cache[$id][$placeholder];
390 389
 					continue;
391 390
 				}
392
-				switch($matches[1][$i])
391
+				switch ($matches[1][$i])
393 392
 				{
394 393
 					case 'link':
395 394
 						// Link to current record
396 395
 						$title = Api\Link::title($app, $id);
397
-						if(class_exists('EGroupware\Stylite\Vfs\Links\StreamWrapper') && $app != Api\Link::VFS_APPNAME)
396
+						if (class_exists('EGroupware\Stylite\Vfs\Links\StreamWrapper') && $app != Api\Link::VFS_APPNAME)
398 397
 						{
399 398
 							$title = Stylite\Vfs\Links\StreamWrapper::entry2name($app, $id, $title);
400 399
 						}
401 400
 
402 401
 						$link = Api\Link::view($app, $id);
403
-						if($app != Api\Link::VFS_APPNAME)
402
+						if ($app != Api\Link::VFS_APPNAME)
404 403
 						{
405 404
 							// Set app to false so we always get an external link
406
-							$link = str_replace(',', '%2C', $GLOBALS['egw']->framework->link('/index.php',$link, false));
405
+							$link = str_replace(',', '%2C', $GLOBALS['egw']->framework->link('/index.php', $link, false));
407 406
 						}
408 407
 						else
409 408
 						{
@@ -415,26 +414,26 @@  discard block
 block discarded – undo
415 414
 							$link = ($_SERVER['HTTPS'] || $GLOBALS['egw_info']['server']['enforce_ssl'] ? 'https://' : 'http://').
416 415
 								($GLOBALS['egw_info']['server']['hostname'] ? $GLOBALS['egw_info']['server']['hostname'] : $_SERVER['HTTP_HOST']).$link;
417 416
 						}
418
-						$array[($prefix?$prefix.'/':'').$placeholder] = Api\Html::a_href(Api\Html::htmlspecialchars($title), $link);
417
+						$array[($prefix ? $prefix.'/' : '').$placeholder] = Api\Html::a_href(Api\Html::htmlspecialchars($title), $link);
419 418
 						break;
420 419
 					case 'links':
421
-						$link_app = $matches[3][$i] ? $matches[3][$i] :  '!'.Api\Link::VFS_APPNAME;
422
-						$array[($prefix?$prefix.'/':'').$placeholder] = $this->get_links($app, $id, $link_app, array(),$matches[2][$i]);
420
+						$link_app = $matches[3][$i] ? $matches[3][$i] : '!'.Api\Link::VFS_APPNAME;
421
+						$array[($prefix ? $prefix.'/' : '').$placeholder] = $this->get_links($app, $id, $link_app, array(), $matches[2][$i]);
423 422
 						break;
424 423
 					case 'attachments':
425
-						$array[($prefix?$prefix.'/':'').$placeholder] = $this->get_links($app, $id, Api\Link::VFS_APPNAME,array(),$matches[2][$i]);
424
+						$array[($prefix ? $prefix.'/' : '').$placeholder] = $this->get_links($app, $id, Api\Link::VFS_APPNAME, array(), $matches[2][$i]);
426 425
 						break;
427 426
 					default:
428
-						$array[($prefix?$prefix.'/':'').$placeholder] = $this->get_links($app, $id, $matches[3][$i], array(), $matches[2][$i]);
427
+						$array[($prefix ? $prefix.'/' : '').$placeholder] = $this->get_links($app, $id, $matches[3][$i], array(), $matches[2][$i]);
429 428
 						break;
430 429
 				}
431 430
 				$link_cache[$id][$placeholder] = $array[$placeholder];
432 431
 			}
433 432
 		}
434 433
 		// Need to set each app, to make sure placeholders are removed
435
-		foreach(array_keys($GLOBALS['egw_info']['user']['apps']) as $_app)
434
+		foreach (array_keys($GLOBALS['egw_info']['user']['apps']) as $_app)
436 435
 		{
437
-			$array[($prefix?$prefix.'/':'')."links/$app"] = $this->get_links($app,$id,$_app);
436
+			$array[($prefix ? $prefix.'/' : '')."links/$app"] = $this->get_links($app, $id, $_app);
438 437
 		}
439 438
 		return $array;
440 439
 	}
@@ -447,12 +446,12 @@  discard block
 block discarded – undo
447 446
 	 * @deprecated use Api\DateTime::to($time='now',$format='')
448 447
 	 * @return string
449 448
 	 */
450
-	protected function format_datetime($time,$format=null)
449
+	protected function format_datetime($time, $format = null)
451 450
 	{
452
-		trigger_error(__METHOD__ . ' is deprecated, use Api\DateTime::to($time, $format)', E_USER_DEPRECATED);
451
+		trigger_error(__METHOD__.' is deprecated, use Api\DateTime::to($time, $format)', E_USER_DEPRECATED);
453 452
 		if (is_null($format)) $format = $this->datetime_format;
454 453
 
455
-		return Api\DateTime::to($time,$format);
454
+		return Api\DateTime::to($time, $format);
456 455
 	}
457 456
 
458 457
 	/**
@@ -464,7 +463,7 @@  discard block
 block discarded – undo
464 463
 	 */
465 464
 	public static function is_export_limit_excepted()
466 465
 	{
467
-		static $is_excepted=null;
466
+		static $is_excepted = null;
468 467
 
469 468
 		if (is_null($is_excepted))
470 469
 		{
@@ -474,9 +473,9 @@  discard block
 block discarded – undo
474 473
 			if (!$is_excepted && (is_array($export_limit_excepted = $GLOBALS['egw_info']['server']['export_limit_excepted']) ||
475 474
 				is_array($export_limit_excepted = unserialize($export_limit_excepted))))
476 475
 			{
477
-				$id_and_memberships = $GLOBALS['egw']->accounts->memberships($GLOBALS['egw_info']['user']['account_id'],true);
476
+				$id_and_memberships = $GLOBALS['egw']->accounts->memberships($GLOBALS['egw_info']['user']['account_id'], true);
478 477
 				$id_and_memberships[] = $GLOBALS['egw_info']['user']['account_id'];
479
-				$is_excepted = (bool) array_intersect($id_and_memberships, $export_limit_excepted);
478
+				$is_excepted = (bool)array_intersect($id_and_memberships, $export_limit_excepted);
480 479
 			}
481 480
 		}
482 481
 		return $is_excepted;
@@ -489,18 +488,18 @@  discard block
 block discarded – undo
489 488
 	 * @return mixed - no if no export is allowed, false if there is no restriction and int as there is a valid restriction
490 489
 	 *		you may have to cast the returned value to int, if you want to use it as number
491 490
 	 */
492
-	public static function getExportLimit($app='common')
491
+	public static function getExportLimit($app = 'common')
493 492
 	{
494
-		static $exportLimitStore=array();
495
-		if (empty($app)) $app='common';
493
+		static $exportLimitStore = array();
494
+		if (empty($app)) $app = 'common';
496 495
 		//error_log(__METHOD__.__LINE__.' called with app:'.$app);
497
-		if (!array_key_exists($app,$exportLimitStore))
496
+		if (!array_key_exists($app, $exportLimitStore))
498 497
 		{
499 498
 			//error_log(__METHOD__.__LINE__.' -> '.$app_limit.' '.function_backtrace());
500 499
 			$exportLimitStore[$app] = $GLOBALS['egw_info']['server']['export_limit'];
501
-			if ($app !='common')
500
+			if ($app != 'common')
502 501
 			{
503
-				$app_limit = Api\Hooks::single('export_limit',$app);
502
+				$app_limit = Api\Hooks::single('export_limit', $app);
504 503
 				if ($app_limit) $exportLimitStore[$app] = $app_limit;
505 504
 			}
506 505
 			//error_log(__METHOD__.__LINE__.' building cache for app:'.$app.' -> '.$exportLimitStore[$app]);
@@ -532,9 +531,9 @@  discard block
 block discarded – undo
532 531
 	 *
533 532
 	 * @return bool - true if no export is allowed or a limit is set, false if there is no restriction
534 533
 	 */
535
-	public static function hasExportLimit($app_limit,$checkas='AND')
534
+	public static function hasExportLimit($app_limit, $checkas = 'AND')
536 535
 	{
537
-		if (strtoupper($checkas) == 'ISALLOWED') return (empty($app_limit) || ($app_limit !='no' && $app_limit > 0) );
536
+		if (strtoupper($checkas) == 'ISALLOWED') return (empty($app_limit) || ($app_limit != 'no' && $app_limit > 0));
538 537
 		if (empty($app_limit)) return false;
539 538
 		if ($app_limit == 'no') return true;
540 539
 		if ($app_limit > 0) return true;
@@ -550,28 +549,28 @@  discard block
 block discarded – undo
550 549
 	 * @param array $fix =null regular expression => replacement pairs eg. to fix garbled placeholders
551 550
 	 * @return string|boolean merged document or false on error
552 551
 	 */
553
-	public function &merge($document,$ids,&$err,$mimetype,array $fix=null)
552
+	public function &merge($document, $ids, &$err, $mimetype, array $fix = null)
554 553
 	{
555 554
 		if (!($content = file_get_contents($document)))
556 555
 		{
557
-			$err = lang("Document '%1' does not exist or is not readable for you!",$document);
556
+			$err = lang("Document '%1' does not exist or is not readable for you!", $document);
558 557
 			return false;
559 558
 		}
560 559
 
561 560
 		if (self::hasExportLimit($this->export_limit) && !self::is_export_limit_excepted() && count($ids) > (int)$this->export_limit)
562 561
 		{
563
-			$err = lang('No rights to export more than %1 entries!',(int)$this->export_limit);
562
+			$err = lang('No rights to export more than %1 entries!', (int)$this->export_limit);
564 563
 			return false;
565 564
 		}
566 565
 
567 566
 		// fix application/msword mimetype for rtf files
568
-		if ($mimetype == 'application/msword' && strtolower(substr($document,-4)) == '.rtf')
567
+		if ($mimetype == 'application/msword' && strtolower(substr($document, -4)) == '.rtf')
569 568
 		{
570 569
 			$mimetype = 'application/rtf';
571 570
 		}
572 571
 
573 572
 		try {
574
-			$content = $this->merge_string($content,$ids,$err,$mimetype,$fix);
573
+			$content = $this->merge_string($content, $ids, $err, $mimetype, $fix);
575 574
 		} catch (\Exception $e) {
576 575
 			$err = $e->getMessage();
577 576
 			return false;
@@ -579,18 +578,18 @@  discard block
 block discarded – undo
579 578
 		return $content;
580 579
 	}
581 580
 
582
-	protected function apply_styles (&$content, $mimetype, $mso_application_progid=null)
581
+	protected function apply_styles(&$content, $mimetype, $mso_application_progid = null)
583 582
 	{
584 583
 		if (!isset($mso_application_progid))
585 584
 		{
586 585
 			$matches = null;
587 586
 			$mso_application_progid = $mimetype == 'application/xml' &&
588
-				preg_match('/'.preg_quote('<?mso-application progid="').'([^"]+)'.preg_quote('"?>').'/',substr($content,0,200),$matches) ?
587
+				preg_match('/'.preg_quote('<?mso-application progid="').'([^"]+)'.preg_quote('"?>').'/', substr($content, 0, 200), $matches) ?
589 588
 					$matches[1] : '';
590 589
 		}
591 590
 		// Tags we can replace with the target document's version
592 591
 		$replace_tags = array();
593
-		switch($mimetype.$mso_application_progid)
592
+		switch ($mimetype.$mso_application_progid)
594 593
 		{
595 594
 			case 'application/vnd.oasis.opendocument.text':		// open office
596 595
 			case 'application/vnd.oasis.opendocument.spreadsheet':
@@ -600,7 +599,7 @@  discard block
 block discarded – undo
600 599
 					'/<\/(ol|ul|table)>/' => '</$1><text:p>',
601 600
 					//'/<(li)(.*?)>(.*?)<\/\1>/' => '<$1 $2>$3</$1>',
602 601
 				);
603
-				$content = preg_replace(array_keys($replace_tags),array_values($replace_tags),$content);
602
+				$content = preg_replace(array_keys($replace_tags), array_values($replace_tags), $content);
604 603
 
605 604
 				$doc = new DOMDocument();
606 605
 				$xslt = new XSLTProcessor();
@@ -625,7 +624,7 @@  discard block
 block discarded – undo
625 624
 					// Remove spans with no attributes, linebreaks inside them cause problems
626 625
 					'/<span>(.*?)<\/span>/' => '$1'
627 626
 				);
628
-				$content = preg_replace(array_keys($replace_tags),array_values($replace_tags),$content);
627
+				$content = preg_replace(array_keys($replace_tags), array_values($replace_tags), $content);
629 628
 
630 629
 				/*
631 630
 				In the case where you have something like <span><span></w:t><w:br/><w:t></span></span> (invalid - mismatched tags),
@@ -635,9 +634,9 @@  discard block
 block discarded – undo
635 634
 				$count = $i = 0;
636 635
 				do
637 636
 				{
638
-					$content = preg_replace('/<span>(.*?)<\/span>/','$1',$content, -1, $count);
637
+					$content = preg_replace('/<span>(.*?)<\/span>/', '$1', $content, -1, $count);
639 638
 					$i++;
640
-				} while($count > 0 && $i < 10);
639
+				} while ($count > 0 && $i < 10);
641 640
 
642 641
 				$doc = new DOMDocument();
643 642
 				$xslt = new XSLTProcessor();
@@ -648,20 +647,20 @@  discard block
 block discarded – undo
648 647
 		}
649 648
 
650 649
 		// XSLT transform known tags
651
-		if($xslt)
650
+		if ($xslt)
652 651
 		{
653 652
 			// does NOT work with php 5.2.6: Catchable fatal error: argument 1 to transformToXml() must be of type DOMDocument
654 653
 			//$element = new SimpleXMLelement($content);
655 654
 			$element = new DOMDocument('1.0', 'utf-8');
656 655
 			$result = $element->loadXML($content);
657
-			if(!$result)
656
+			if (!$result)
658 657
 			{
659 658
 				throw new Api\Exception('Unable to parse merged document for styles.  Check warnings in log for details.');
660 659
 			}
661 660
 			$content = $xslt->transformToXml($element);
662 661
 
663 662
 			// Word 2003 needs two declarations, add extra declaration back in
664
-			if($mimetype == 'application/xml' && $mso_application_progid == 'Word.Document' && strpos($content, '<?xml') !== 0) {
663
+			if ($mimetype == 'application/xml' && $mso_application_progid == 'Word.Document' && strpos($content, '<?xml') !== 0) {
665 664
 				$content = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'.$content;
666 665
 			}
667 666
 			// Validate
@@ -684,11 +683,11 @@  discard block
 block discarded – undo
684 683
 	 * @param string $charset =null charset to override default set by mimetype or export charset
685 684
 	 * @return string|boolean merged document or false on error
686 685
 	 */
687
-	public function &merge_string($_content,$ids,&$err,$mimetype,array $fix=null,$charset=null)
686
+	public function &merge_string($_content, $ids, &$err, $mimetype, array $fix = null, $charset = null)
688 687
 	{
689 688
 		$matches = null;
690 689
 		if ($mimetype == 'application/xml' &&
691
-			preg_match('/'.preg_quote('<?mso-application progid="').'([^"]+)'.preg_quote('"?>').'/',substr($_content,0,200),$matches))
690
+			preg_match('/'.preg_quote('<?mso-application progid="').'([^"]+)'.preg_quote('"?>').'/', substr($_content, 0, 200), $matches))
692 691
 		{
693 692
 			$mso_application_progid = $matches[1];
694 693
 		}
@@ -698,12 +697,12 @@  discard block
 block discarded – undo
698 697
 		}
699 698
 		// alternative syntax using double curly brackets (eg. {{cat_id}} instead $$cat_id$$),
700 699
 		// agressivly removing all xml-tags eg. Word adds within placeholders
701
-		$content = preg_replace_callback('/{{[^}]+}}/i',create_function('$p','return \'$$\'.strip_tags(substr($p[0],2,-2)).\'$$\';'),$_content);
700
+		$content = preg_replace_callback('/{{[^}]+}}/i', create_function('$p', 'return \'$$\'.strip_tags(substr($p[0],2,-2)).\'$$\';'), $_content);
702 701
 
703 702
 		// Handle escaped placeholder markers in RTF, they won't match when escaped
704
-		if($mimetype == 'application/rtf')
703
+		if ($mimetype == 'application/rtf')
705 704
 		{
706
-			$content = preg_replace('/\\\{\\\{([^\\}]+)\\\}\\\}/i','$$\1$$',$content);
705
+			$content = preg_replace('/\\\{\\\{([^\\}]+)\\\}\\\}/i', '$$\1$$', $content);
707 706
 		}
708 707
 
709 708
 		// make currently processed mimetype available to class methods;
@@ -712,16 +711,16 @@  discard block
 block discarded – undo
712 711
 		// fix garbled placeholders
713 712
 		if ($fix && is_array($fix))
714 713
 		{
715
-			$content = preg_replace(array_keys($fix),array_values($fix),$content);
714
+			$content = preg_replace(array_keys($fix), array_values($fix), $content);
716 715
 			//die("<pre>".htmlspecialchars($content)."</pre>\n");
717 716
 		}
718
-		list($contentstart,$contentrepeat,$contentend) = preg_split('/\$\$pagerepeat\$\$/',$content,-1, PREG_SPLIT_NO_EMPTY);  //get differt parts of document, seperatet by Pagerepeat
717
+		list($contentstart, $contentrepeat, $contentend) = preg_split('/\$\$pagerepeat\$\$/', $content, -1, PREG_SPLIT_NO_EMPTY); //get differt parts of document, seperatet by Pagerepeat
719 718
 		if ($mimetype == 'text/plain' && count($ids) > 1)
720 719
 		{
721 720
 			// textdocuments are simple, they do not hold start and end, but they may have content before and after the $$pagerepeat$$ tag
722 721
 			// header and footer should not hold any $$ tags; if we find $$ tags with the header, we assume it is the pagerepeatcontent
723 722
 			$nohead = false;
724
-			if (stripos($contentstart,'$$') !== false) $nohead = true;
723
+			if (stripos($contentstart, '$$') !== false) $nohead = true;
725 724
 			if ($nohead)
726 725
 			{
727 726
 				$contentend = $contentrepeat;
@@ -732,14 +731,14 @@  discard block
 block discarded – undo
732 731
 		}
733 732
 		if ($mimetype == 'application/vnd.oasis.opendocument.text' && count($ids) > 1)
734 733
 		{
735
-			if(strpos($content, '$$pagerepeat') === false)
734
+			if (strpos($content, '$$pagerepeat') === false)
736 735
 			{
737 736
 				//for odt files we have to split the content and add a style for page break to  the style area
738
-				list($contentstart,$contentrepeat,$contentend) = preg_split('/office:body>/',$content,-1, PREG_SPLIT_NO_EMPTY);  //get differt parts of document, seperatet by Pagerepeat
739
-				$contentstart = substr($contentstart,0,strlen($contentstart)-1);  //remove "<"
740
-				$contentrepeat = substr($contentrepeat,0,strlen($contentrepeat)-2);  //remove "</";
737
+				list($contentstart, $contentrepeat, $contentend) = preg_split('/office:body>/', $content, -1, PREG_SPLIT_NO_EMPTY); //get differt parts of document, seperatet by Pagerepeat
738
+				$contentstart = substr($contentstart, 0, strlen($contentstart) - 1); //remove "<"
739
+				$contentrepeat = substr($contentrepeat, 0, strlen($contentrepeat) - 2); //remove "</";
741 740
 				// need to add page-break style to the style list
742
-				list($stylestart,$stylerepeat,$styleend) = preg_split('/<\/office:automatic-styles>/',$content,-1, PREG_SPLIT_NO_EMPTY);  //get differt parts of document style sheets
741
+				list($stylestart, $stylerepeat, $styleend) = preg_split('/<\/office:automatic-styles>/', $content, -1, PREG_SPLIT_NO_EMPTY); //get differt parts of document style sheets
743 742
 				$contentstart = $stylestart.'<style:style style:name="P200" style:family="paragraph" style:parent-style-name="Standard"><style:paragraph-properties fo:break-before="page"/></style:style></office:automatic-styles>';
744 743
 				$contentstart .= '<office:body>';
745 744
 				$contentend = '</office:body></office:document-content>';
@@ -747,22 +746,22 @@  discard block
 block discarded – undo
747 746
 			else
748 747
 			{
749 748
 				// Template specifies where to repeat
750
-				list($contentstart,$contentrepeat,$contentend) = preg_split('/\$\$pagerepeat\$\$/',$content,-1, PREG_SPLIT_NO_EMPTY);  //get different parts of document, seperated by pagerepeat
749
+				list($contentstart, $contentrepeat, $contentend) = preg_split('/\$\$pagerepeat\$\$/', $content, -1, PREG_SPLIT_NO_EMPTY); //get different parts of document, seperated by pagerepeat
751 750
 			}
752 751
 		}
753 752
 		if ($mimetype == 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' && count($ids) > 1)
754 753
 		{
755 754
 			//for Word 2007 XML files we have to split the content and add a style for page break to  the style area
756
-			list($contentstart,$contentrepeat,$contentend) = preg_split('/w:body>/',$content,-1, PREG_SPLIT_NO_EMPTY);  //get differt parts of document, seperatet by Pagerepeat
757
-			$contentstart = substr($contentstart,0,strlen($contentstart)-1);  //remove "</"
758
-			$contentrepeat = substr($contentrepeat,0,strlen($contentrepeat)-2);  //remove "</";
755
+			list($contentstart, $contentrepeat, $contentend) = preg_split('/w:body>/', $content, -1, PREG_SPLIT_NO_EMPTY); //get differt parts of document, seperatet by Pagerepeat
756
+			$contentstart = substr($contentstart, 0, strlen($contentstart) - 1); //remove "</"
757
+			$contentrepeat = substr($contentrepeat, 0, strlen($contentrepeat) - 2); //remove "</";
759 758
 			$contentstart .= '<w:body>';
760 759
 			$contentend = '</w:body></w:document>';
761 760
 		}
762
-		list($Labelstart,$Labelrepeat,$Labeltend) = preg_split('/\$\$label\$\$/',$contentrepeat,-1, PREG_SPLIT_NO_EMPTY);  //get the Lable content
763
-		preg_match_all('/\$\$labelplacement\$\$/',$contentrepeat,$countlables, PREG_SPLIT_NO_EMPTY);
761
+		list($Labelstart, $Labelrepeat, $Labeltend) = preg_split('/\$\$label\$\$/', $contentrepeat, -1, PREG_SPLIT_NO_EMPTY); //get the Lable content
762
+		preg_match_all('/\$\$labelplacement\$\$/', $contentrepeat, $countlables, PREG_SPLIT_NO_EMPTY);
764 763
 		$countlables = count($countlables[0]);
765
-		preg_replace('/\$\$labelplacement\$\$/','',$Labelrepeat,1);
764
+		preg_replace('/\$\$labelplacement\$\$/', '', $Labelrepeat, 1);
766 765
 		if ($countlables > 1) $lableprint = true;
767 766
 		if (count($ids) > 1 && !$contentrepeat)
768 767
 		{
@@ -773,10 +772,10 @@  discard block
 block discarded – undo
773 772
 
774 773
 		if ($contentrepeat)
775 774
 		{
776
-			$content_stream = fopen('php://temp','r+');
775
+			$content_stream = fopen('php://temp', 'r+');
777 776
 			fwrite($content_stream, $contentstart);
778 777
 			$joiner = '';
779
-			switch($mimetype)
778
+			switch ($mimetype)
780 779
 			{
781 780
 				case 'application/rtf':
782 781
 				case 'text/rtf':
@@ -796,19 +795,19 @@  discard block
 block discarded – undo
796 795
 					$joiner = "\r\n";
797 796
 					break;
798 797
 				default:
799
-					$err = lang('%1 not implemented for %2!','$$pagerepeat$$',$mimetype);
798
+					$err = lang('%1 not implemented for %2!', '$$pagerepeat$$', $mimetype);
800 799
 					return false;
801 800
 			}
802 801
 		}
803 802
 		foreach ((array)$ids as $n => $id)
804 803
 		{
805
-			if ($contentrepeat) $content = $contentrepeat;   //content to repeat
804
+			if ($contentrepeat) $content = $contentrepeat; //content to repeat
806 805
 			if ($lableprint) $content = $Labelrepeat;
807 806
 
808 807
 			// generate replacements; if exeption is thrown, catch it set error message and return false
809 808
 			try
810 809
 			{
811
-				if(!($replacements = $this->get_replacements($id,$content)))
810
+				if (!($replacements = $this->get_replacements($id, $content)))
812 811
 				{
813 812
 					$err = lang('Entry not found!');
814 813
 					return false;
@@ -822,86 +821,86 @@  discard block
 block discarded – undo
822 821
 			}
823 822
 			if ($this->report_memory_usage) error_log(__METHOD__."() $n: $id ".Api\Vfs::hsize(memory_get_usage(true)));
824 823
 			// some general replacements: current user, date and time
825
-			if (strpos($content,'$$user/') !== null && ($user = $GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'],'person_id')))
824
+			if (strpos($content, '$$user/') !== null && ($user = $GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'], 'person_id')))
826 825
 			{
827
-				$replacements += $this->contact_replacements($user,'user');
828
-				$replacements['$$user/primary_group$$'] = $GLOBALS['egw']->accounts->id2name($GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'],'account_primary_group'));
826
+				$replacements += $this->contact_replacements($user, 'user');
827
+				$replacements['$$user/primary_group$$'] = $GLOBALS['egw']->accounts->id2name($GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'], 'account_primary_group'));
829 828
 			}
830
-			$replacements['$$date$$'] = Api\DateTime::to('now',true);
829
+			$replacements['$$date$$'] = Api\DateTime::to('now', true);
831 830
 			$replacements['$$datetime$$'] = Api\DateTime::to('now');
832
-			$replacements['$$time$$'] = Api\DateTime::to('now',false);
831
+			$replacements['$$time$$'] = Api\DateTime::to('now', false);
833 832
 
834 833
 			// does our extending class registered table-plugins AND document contains table tags
835
-			if ($this->table_plugins && preg_match_all('/\\$\\$table\\/([A-Za-z0-9_]+)\\$\\$(.*?)\\$\\$endtable\\$\\$/s',$content,$matches,PREG_SET_ORDER))
834
+			if ($this->table_plugins && preg_match_all('/\\$\\$table\\/([A-Za-z0-9_]+)\\$\\$(.*?)\\$\\$endtable\\$\\$/s', $content, $matches, PREG_SET_ORDER))
836 835
 			{
837 836
 				// process each table
838
-				foreach($matches as $match)
837
+				foreach ($matches as $match)
839 838
 				{
840
-					$plugin   = $match[1];	// plugin name
839
+					$plugin   = $match[1]; // plugin name
841 840
 					$callback = $this->table_plugins[$plugin];
842
-					$repeat   = $match[2];	// line to repeat
841
+					$repeat   = $match[2]; // line to repeat
843 842
 					$repeats = '';
844 843
 					if (isset($callback))
845 844
 					{
846
-						for($n = 0; ($row_replacements = $this->$callback($plugin,$id,$n,$repeat)); ++$n)
845
+						for ($n = 0; ($row_replacements = $this->$callback($plugin, $id, $n, $repeat)); ++$n)
847 846
 						{
848 847
 							$_repeat = $this->process_commands($repeat, $row_replacements);
849
-							$repeats .= $this->replace($_repeat,$row_replacements,$mimetype,$mso_application_progid);
848
+							$repeats .= $this->replace($_repeat, $row_replacements, $mimetype, $mso_application_progid);
850 849
 						}
851 850
 					}
852
-					$content = str_replace($match[0],$repeats,$content);
851
+					$content = str_replace($match[0], $repeats, $content);
853 852
 				}
854 853
 			}
855
-			$content = $this->process_commands($this->replace($content,$replacements,$mimetype,$mso_application_progid,$charset), $replacements);
854
+			$content = $this->process_commands($this->replace($content, $replacements, $mimetype, $mso_application_progid, $charset), $replacements);
856 855
 
857 856
 			// remove not existing replacements (eg. from calendar array)
858
-			if (strpos($content,'$$') !== null)
857
+			if (strpos($content, '$$') !== null)
859 858
 			{
860
-				$content = preg_replace('/\$\$[a-z0-9_\/]+\$\$/i','',$content);
859
+				$content = preg_replace('/\$\$[a-z0-9_\/]+\$\$/i', '', $content);
861 860
 			}
862 861
 			if ($contentrepeat)
863 862
 			{
864
-				fwrite($content_stream, ($n == 0 ? '' : $joiner) . $content);
863
+				fwrite($content_stream, ($n == 0 ? '' : $joiner).$content);
865 864
 			}
866
-			if($lableprint)
865
+			if ($lableprint)
867 866
 			{
868
-				$contentrep[is_array($id) ? implode(':',$id) : $id] = $content;
867
+				$contentrep[is_array($id) ? implode(':', $id) : $id] = $content;
869 868
 			}
870 869
 		}
871 870
 		if ($Labelrepeat)
872 871
 		{
873
-			$countpage=0;
874
-			$count=0;
872
+			$countpage = 0;
873
+			$count = 0;
875 874
 			$contentrepeatpages[$countpage] = $Labelstart.$Labeltend;
876 875
 
877 876
 			foreach ($contentrep as $Label)
878 877
 			{
879
-				$contentrepeatpages[$countpage] = preg_replace('/\$\$labelplacement\$\$/',$Label,$contentrepeatpages[$countpage],1);
880
-				$count=$count+1;
881
-				if (($count % $countlables) == 0 && count($contentrep)>$count)  //new page
878
+				$contentrepeatpages[$countpage] = preg_replace('/\$\$labelplacement\$\$/', $Label, $contentrepeatpages[$countpage], 1);
879
+				$count = $count + 1;
880
+				if (($count % $countlables) == 0 && count($contentrep) > $count)  //new page
882 881
 				{
883
-					$countpage = $countpage+1;
882
+					$countpage = $countpage + 1;
884 883
 					$contentrepeatpages[$countpage] = $Labelstart.$Labeltend;
885 884
 				}
886 885
 			}
887
-			$contentrepeatpages[$countpage] = preg_replace('/\$\$labelplacement\$\$/','',$contentrepeatpages[$countpage],-1);  //clean empty fields
886
+			$contentrepeatpages[$countpage] = preg_replace('/\$\$labelplacement\$\$/', '', $contentrepeatpages[$countpage], -1); //clean empty fields
888 887
 
889
-			switch($mimetype)
888
+			switch ($mimetype)
890 889
 			{
891 890
 				case 'application/rtf':
892 891
 				case 'text/rtf':
893
-					return $contentstart.implode('\\par \\page\\pard\\plain',$contentrepeatpages).$contentend;
892
+					return $contentstart.implode('\\par \\page\\pard\\plain', $contentrepeatpages).$contentend;
894 893
 				case 'application/vnd.oasis.opendocument.text':
895
-					return $contentstart.implode('<text:line-break />',$contentrepeatpages).$contentend;
894
+					return $contentstart.implode('<text:line-break />', $contentrepeatpages).$contentend;
896 895
 				case 'application/vnd.oasis.opendocument.spreadsheet':
897
-					return $contentstart.implode('</text:p><text:p>',$contentrepeatpages).$contentend;
896
+					return $contentstart.implode('</text:p><text:p>', $contentrepeatpages).$contentend;
898 897
 				case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
899 898
 				case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
900
-					return $contentstart.implode('<w:br w:type="page" />',$contentrepeatpages).$contentend;
899
+					return $contentstart.implode('<w:br w:type="page" />', $contentrepeatpages).$contentend;
901 900
 				case 'text/plain':
902
-					return $contentstart.implode("\r\n",$contentrep).$contentend;
901
+					return $contentstart.implode("\r\n", $contentrep).$contentend;
903 902
 			}
904
-			$err = lang('%1 not implemented for %2!','$$labelplacement$$',$mimetype);
903
+			$err = lang('%1 not implemented for %2!', '$$labelplacement$$', $mimetype);
905 904
 			return false;
906 905
 		}
907 906
 
@@ -926,9 +925,9 @@  discard block
 block discarded – undo
926 925
 	 * @param string $charset =null charset to override default set by mimetype or export charset
927 926
 	 * @return string
928 927
 	 */
929
-	protected function replace($content,array $replacements,$mimetype,$mso_application_progid='',$charset=null)
928
+	protected function replace($content, array $replacements, $mimetype, $mso_application_progid = '', $charset = null)
930 929
 	{
931
-		switch($mimetype)
930
+		switch ($mimetype)
932 931
 		{
933 932
 			case 'application/vnd.oasis.opendocument.text':		// open office
934 933
 			case 'application/vnd.oasis.opendocument.spreadsheet':
@@ -937,13 +936,13 @@  discard block
 block discarded – undo
937 936
 			case 'application/xml':
938 937
 			case 'text/xml':
939 938
 				$is_xml = true;
940
-				$charset = 'utf-8';	// xml files --> always use utf-8
939
+				$charset = 'utf-8'; // xml files --> always use utf-8
941 940
 				break;
942 941
 
943 942
 			case 'text/html':
944 943
 				$is_xml = true;
945 944
 				$matches = null;
946
-				if (preg_match('/<meta http-equiv="content-type".*charset=([^;"]+)/i',$content,$matches))
945
+				if (preg_match('/<meta http-equiv="content-type".*charset=([^;"]+)/i', $content, $matches))
947 946
 				{
948 947
 					$charset = $matches[1];
949 948
 				}
@@ -962,18 +961,18 @@  discard block
 block discarded – undo
962 961
 		// do we need to convert charset
963 962
 		if ($charset && $charset != Api\Translation::charset())
964 963
 		{
965
-			$replacements = Api\Translation::convert($replacements,Api\Translation::charset(),$charset);
964
+			$replacements = Api\Translation::convert($replacements, Api\Translation::charset(), $charset);
966 965
 		}
967 966
 
968 967
 		// Date only placeholders for timestamps
969
-		if(is_array($this->date_fields))
968
+		if (is_array($this->date_fields))
970 969
 		{
971
-			foreach($this->date_fields as $field)
970
+			foreach ($this->date_fields as $field)
972 971
 			{
973
-				if(($value = $replacements['$$'.$field.'$$']))
972
+				if (($value = $replacements['$$'.$field.'$$']))
974 973
 				{
975 974
 					$time = Api\DateTime::createFromFormat('+'.Api\DateTime::$user_dateformat.' '.Api\DateTime::$user_timeformat.'*', $value);
976
-					$replacements['$$'.$field.'/date$$'] = $time ? $time->format(Api\DateTime::$user_dateformat)  : '';
975
+					$replacements['$$'.$field.'/date$$'] = $time ? $time->format(Api\DateTime::$user_dateformat) : '';
977 976
 				}
978 977
 			}
979 978
 		}
@@ -987,66 +986,66 @@  discard block
 block discarded – undo
987 986
 			// only keep tags, if we have xsl extension available
988 987
 			if (class_exists(XSLTProcessor) && class_exists(DOMDocument) && $this->parse_html_styles)
989 988
 			{
990
-				switch($mimetype.$mso_application_progid)
989
+				switch ($mimetype.$mso_application_progid)
991 990
 				{
992 991
 					case 'text/html':
993 992
 						$replace_tags = array(
994
-							'<b>','<strong>','<i>','<em>','<u>','<span>','<ol>','<ul>','<li>',
995
-							'<table>','<tr>','<td>','<a>','<style>',
993
+							'<b>', '<strong>', '<i>', '<em>', '<u>', '<span>', '<ol>', '<ul>', '<li>',
994
+							'<table>', '<tr>', '<td>', '<a>', '<style>',
996 995
 						);
997 996
 						break;
998 997
 					case 'application/vnd.oasis.opendocument.text':		// open office
999 998
 					case 'application/vnd.oasis.opendocument.spreadsheet':
1000 999
 						$replace_tags = array(
1001
-							'<b>','<strong>','<i>','<em>','<u>','<span>','<ol>','<ul>','<li>',
1002
-							'<table>','<tr>','<td>','<a>',
1000
+							'<b>', '<strong>', '<i>', '<em>', '<u>', '<span>', '<ol>', '<ul>', '<li>',
1001
+							'<table>', '<tr>', '<td>', '<a>',
1003 1002
 						);
1004 1003
 						break;
1005 1004
 					case 'application/xmlWord.Document':	// Word 2003*/
1006 1005
 					case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':	// ms office 2007
1007 1006
 					case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
1008 1007
 						$replace_tags = array(
1009
-							'<b>','<strong>','<i>','<em>','<u>','<span>','<ol>','<ul>','<li>',
1010
-							'<table>','<tr>','<td>',
1008
+							'<b>', '<strong>', '<i>', '<em>', '<u>', '<span>', '<ol>', '<ul>', '<li>',
1009
+							'<table>', '<tr>', '<td>',
1011 1010
 						);
1012 1011
 						break;
1013 1012
 				}
1014 1013
 			}
1015 1014
 			// clean replacements from array values and html or html-entities, which mess up xml
1016
-			foreach($replacements as $name => &$value)
1015
+			foreach ($replacements as $name => &$value)
1017 1016
 			{
1018 1017
 				// set unresolved array values to empty string
1019
-				if(is_array($value))
1018
+				if (is_array($value))
1020 1019
 				{
1021 1020
 					$value = '';
1022 1021
 					continue;
1023 1022
 				}
1024 1023
 				// decode html entities back to utf-8
1025 1024
 
1026
-				if (is_string($value) && (strpos($value,'&') !== false) && $this->parse_html_styles)
1025
+				if (is_string($value) && (strpos($value, '&') !== false) && $this->parse_html_styles)
1027 1026
 				{
1028
-					$value = html_entity_decode($value,ENT_QUOTES,$charset);
1027
+					$value = html_entity_decode($value, ENT_QUOTES, $charset);
1029 1028
 
1030 1029
 					// remove all non-decodable entities
1031
-					if (strpos($value,'&') !== false)
1030
+					if (strpos($value, '&') !== false)
1032 1031
 					{
1033
-						$value = preg_replace('/&[^; ]+;/','',$value);
1032
+						$value = preg_replace('/&[^; ]+;/', '', $value);
1034 1033
 					}
1035 1034
 				}
1036 1035
 
1037
-				if(!$this->parse_html_styles)
1036
+				if (!$this->parse_html_styles)
1038 1037
 				{
1039 1038
 					// Encode special chars so they don't break the file
1040
-					$value = htmlspecialchars($value,ENT_NOQUOTES);
1039
+					$value = htmlspecialchars($value, ENT_NOQUOTES);
1041 1040
 				}
1042
-				else if (is_string($value) && (strpos($value,'<') !== false))
1041
+				else if (is_string($value) && (strpos($value, '<') !== false))
1043 1042
 				{
1044 1043
 					// Clean HTML, if it's being kept
1045
-					if($replace_tags && extension_loaded('tidy')) {
1044
+					if ($replace_tags && extension_loaded('tidy')) {
1046 1045
 						$tidy = new tidy();
1047 1046
 						$cleaned = $tidy->repairString($value, self::$tidy_config);
1048 1047
 						// Found errors. Strip it all so there's some output
1049
-						if($tidy->getStatus() == 2)
1048
+						if ($tidy->getStatus() == 2)
1050 1049
 						{
1051 1050
 							error_log($tidy->errorBuffer);
1052 1051
 							$value = strip_tags($value);
@@ -1057,52 +1056,52 @@  discard block
 block discarded – undo
1057 1056
 						}
1058 1057
 					}
1059 1058
 					// replace </p> and <br /> with CRLF (remove <p> and CRLF)
1060
-					$value = strip_tags(str_replace(array("\r","\n",'<p>','</p>','<div>','</div>','<br />'),
1061
-						array('','','',"\r\n",'',"\r\n","\r\n"), $value),
1059
+					$value = strip_tags(str_replace(array("\r", "\n", '<p>', '</p>', '<div>', '</div>', '<br />'),
1060
+						array('', '', '', "\r\n", '', "\r\n", "\r\n"), $value),
1062 1061
 						implode('', $replace_tags));
1063 1062
 
1064 1063
 					// Change <tag>...\r\n</tag> to <tag>...</tag>\r\n or simplistic line break below will mangle it
1065 1064
 					// Loop to catch things like <b><span>Break:\r\n</span></b>
1066
-					if($mso_application_progid)
1065
+					if ($mso_application_progid)
1067 1066
 					{
1068 1067
 						$count = $i = 0;
1069 1068
 						do
1070 1069
 						{
1071
-							$value = preg_replace('/<(b|strong|i|em|u|span)\b([^>]*?)>(.*?)'."\r\n".'<\/\1>/u', '<$1$2>$3</$1>'."\r\n",$value,-1,$count);
1070
+							$value = preg_replace('/<(b|strong|i|em|u|span)\b([^>]*?)>(.*?)'."\r\n".'<\/\1>/u', '<$1$2>$3</$1>'."\r\n", $value, -1, $count);
1072 1071
 							$i++;
1073
-						} while($count > 0 && $i < 10); // Limit of 10 chosen arbitrarily just in case
1072
+						} while ($count > 0 && $i < 10); // Limit of 10 chosen arbitrarily just in case
1074 1073
 					}
1075 1074
 				}
1076 1075
 				// replace all control chars (C0+C1) but CR (\015), LF (\012) and TAB (\011) (eg. vertical tabulators) with space
1077 1076
 				// as they are not allowed in xml
1078
-				$value = preg_replace('/[\000-\010\013\014\016-\037\177-\237]/u',' ',$value);
1079
-				if(is_numeric($value) && $name != '$$user/account_id$$') // account_id causes problems with the preg_replace below
1077
+				$value = preg_replace('/[\000-\010\013\014\016-\037\177-\237]/u', ' ', $value);
1078
+				if (is_numeric($value) && $name != '$$user/account_id$$') // account_id causes problems with the preg_replace below
1080 1079
 				{
1081
-					$names[] = preg_quote($name,'/');
1080
+					$names[] = preg_quote($name, '/');
1082 1081
 				}
1083 1082
 			}
1084 1083
 
1085 1084
 			// Look for numbers, set their value if needed
1086
-			if($this->numeric_fields || count($names))
1085
+			if ($this->numeric_fields || count($names))
1087 1086
 			{
1088
-				foreach((array)$this->numeric_fields as $fieldname) {
1089
-					$names[] = preg_quote($fieldname,'/');
1087
+				foreach ((array)$this->numeric_fields as $fieldname) {
1088
+					$names[] = preg_quote($fieldname, '/');
1090 1089
 				}
1091 1090
 				$this->format_spreadsheet_numbers($content, $names, $mimetype.$mso_application_progid);
1092 1091
 			}
1093 1092
 
1094 1093
 			// Look for dates, set their value if needed
1095
-			if($this->date_fields || count($names))
1094
+			if ($this->date_fields || count($names))
1096 1095
 			{
1097 1096
 				$names = array();
1098
-				foreach((array)$this->date_fields as $fieldname) {
1097
+				foreach ((array)$this->date_fields as $fieldname) {
1099 1098
 					$names[] = $fieldname;
1100 1099
 				}
1101 1100
 				$this->format_spreadsheet_dates($content, $names, $replacements, $mimetype.$mso_application_progid);
1102 1101
 			}
1103 1102
 
1104 1103
 			// replace CRLF with linebreak tag of given type
1105
-			switch($mimetype.$mso_application_progid)
1104
+			switch ($mimetype.$mso_application_progid)
1106 1105
 			{
1107 1106
 				case 'application/vnd.oasis.opendocument.text':		// open office writer
1108 1107
 					$break = '<text:line-break/>';
@@ -1129,14 +1128,14 @@  discard block
 block discarded – undo
1129 1128
 			}
1130 1129
 			// now decode &, < and >, which need to be encoded as entities in xml
1131 1130
 			// Check for encoded >< getting double-encoded
1132
-			if($this->parse_html_styles)
1131
+			if ($this->parse_html_styles)
1133 1132
 			{
1134
-				$replacements = str_replace(array('&',"\r","\n",'&amp;lt;','&amp;gt;'),array('&amp;','',$break,'&lt;','&gt;'),$replacements);
1133
+				$replacements = str_replace(array('&', "\r", "\n", '&amp;lt;', '&amp;gt;'), array('&amp;', '', $break, '&lt;', '&gt;'), $replacements);
1135 1134
 			}
1136 1135
 			else
1137 1136
 			{
1138 1137
 				// Need to at least handle new lines, or it'll be run together on one line
1139
-				$replacements = str_replace(array("\r","\n"),array('',$break),$replacements);
1138
+				$replacements = str_replace(array("\r", "\n"), array('', $break), $replacements);
1140 1139
 			}
1141 1140
 		}
1142 1141
 		if ($mimetype == 'application/x-yaml')
@@ -1147,24 +1146,24 @@  discard block
 block discarded – undo
1147 1146
 				$parts = null;
1148 1147
 				if (preg_match('|^\$\$([^/]+)/([^/]+)/([^$]*)\$\$$|', $matches[3], $parts) && isset($replacements['$$'.$parts[1].'$$']))
1149 1148
 				{
1150
-					$replacement =& $replacements['$$'.$parts[1].'$$'];
1149
+					$replacement = & $replacements['$$'.$parts[1].'$$'];
1151 1150
 					$replacement = preg_replace('/'.$parts[2].'/', strtr($parts[3], array(
1152 1151
 						'\\n' => "\n", '\\r' => "\r", '\\t' => "\t", '\\v' => "\v", '\\\\' => '\\', '\\f' => "\f",
1153 1152
 					)), $replacement);
1154 1153
 				}
1155 1154
 				else
1156 1155
 				{
1157
-					$replacement =& $replacements[$matches[3]];
1156
+					$replacement = & $replacements[$matches[3]];
1158 1157
 				}
1159 1158
 				// replacement with multiple lines --> add same number of space as before placeholder
1160 1159
 				if (isset($replacement))
1161 1160
 				{
1162 1161
 					return $matches[1].$matches[2].implode("\n".$matches[1], preg_split("/\r?\n/", $replacement));
1163 1162
 				}
1164
-				return $matches[0];	// regular replacement below
1163
+				return $matches[0]; // regular replacement below
1165 1164
 			}, $content);
1166 1165
 		}
1167
-		return str_replace(array_keys($replacements),array_values($replacements),$content);
1166
+		return str_replace(array_keys($replacements), array_values($replacements), $content);
1168 1167
 	}
1169 1168
 
1170 1169
 	/**
@@ -1172,36 +1171,36 @@  discard block
 block discarded – undo
1172 1171
 	 */
1173 1172
 	protected function format_spreadsheet_numbers(&$content, $names, $mimetype)
1174 1173
 	{
1175
-		foreach((array)$this->numeric_fields as $fieldname) {
1176
-			$names[] = preg_quote($fieldname,'/');
1174
+		foreach ((array)$this->numeric_fields as $fieldname) {
1175
+			$names[] = preg_quote($fieldname, '/');
1177 1176
 		}
1178
-		switch($mimetype)
1177
+		switch ($mimetype)
1179 1178
 		{
1180 1179
 			case 'application/vnd.oasis.opendocument.spreadsheet':		// open office calc
1181
-				$format = '/<table:table-cell([^>]+?)office:value-type="[^"]+"([^>]*?)(?:calcext:value-type="[^"]+")?>.?<([a-z].*?)[^>]*>('.implode('|',$names).')<\/\3>.?<\/table:table-cell>/s';
1180
+				$format = '/<table:table-cell([^>]+?)office:value-type="[^"]+"([^>]*?)(?:calcext:value-type="[^"]+")?>.?<([a-z].*?)[^>]*>('.implode('|', $names).')<\/\3>.?<\/table:table-cell>/s';
1182 1181
 				$replacement = '<table:table-cell$1office:value-type="float" office:value="$4"$2 calcext:value-type="float"><$3>$4</$3></table:table-cell>';
1183 1182
 				break;
1184 1183
 			case 'application/vnd.oasis.opendocument.text':		// tables in open office writer
1185
-				$format = '/<table:table-cell([^>]+?)office:value-type="[^"]+"([^>]*?)>.?<([a-z].*?)[^>]*>('.implode('|',$names).')<\/\3>.?<\/table:table-cell>/s';
1184
+				$format = '/<table:table-cell([^>]+?)office:value-type="[^"]+"([^>]*?)>.?<([a-z].*?)[^>]*>('.implode('|', $names).')<\/\3>.?<\/table:table-cell>/s';
1186 1185
 				$replacement = '<table:table-cell$1office:value-type="float" office:value="$4"$2><text:p text:style-name="Standard">$4</text:p></table:table-cell>';
1187 1186
 				break;
1188 1187
 			case 'application/vnd.oasis.opendocument.text':		// open office writer
1189 1188
 			case 'application/xmlExcel.Sheet':	// Excel 2003
1190
-				$format = '/'.preg_quote('<Data ss:Type="String">','/').'('.implode('|',$names).')'.preg_quote('</Data>','/').'/';
1189
+				$format = '/'.preg_quote('<Data ss:Type="String">', '/').'('.implode('|', $names).')'.preg_quote('</Data>', '/').'/';
1191 1190
 				$replacement = '<Data ss:Type="Number">$1</Data>';
1192 1191
 
1193 1192
 				break;
1194 1193
 		}
1195
-		if($format && $names)
1194
+		if ($format && $names)
1196 1195
 		{
1197 1196
 			// Dealing with backtrack limit per AmigoJack 10-Jul-2010 comment on php.net preg-replace docs
1198 1197
 			do {
1199 1198
 				$result = preg_replace($format, $replacement, $content, -1);
1200 1199
 			}
1201 1200
 			// try to increase/double pcre.backtrack_limit failure
1202
-			while(preg_last_error() == PREG_BACKTRACK_LIMIT_ERROR && self::increase_backtrack_limit());
1201
+			while (preg_last_error() == PREG_BACKTRACK_LIMIT_ERROR && self::increase_backtrack_limit());
1203 1202
 
1204
-			if ($result) $content = $result;  // On failure $result would be NULL
1203
+			if ($result) $content = $result; // On failure $result would be NULL
1205 1204
 		}
1206 1205
 	}
1207 1206
 
@@ -1212,7 +1211,7 @@  discard block
 block discarded – undo
1212 1211
 	 */
1213 1212
 	protected static function increase_backtrack_limit()
1214 1213
 	{
1215
-		static $backtrack_limit=null,$memory_limit=null;
1214
+		static $backtrack_limit = null, $memory_limit = null;
1216 1215
 		if (!isset($backtrack_limit))
1217 1216
 		{
1218 1217
 			$backtrack_limit = ini_get('pcre.backtrack_limit');
@@ -1220,16 +1219,16 @@  discard block
 block discarded – undo
1220 1219
 		if (!isset($memory_limit))
1221 1220
 		{
1222 1221
 			$memory_limit = ini_get('memory_limit');
1223
-			switch(strtoupper(substr($memory_limit, -1)))
1222
+			switch (strtoupper(substr($memory_limit, -1)))
1224 1223
 			{
1225 1224
 				case 'G': $memory_limit *= 1024;
1226 1225
 				case 'M': $memory_limit *= 1024;
1227 1226
 				case 'K': $memory_limit *= 1024;
1228 1227
 			}
1229 1228
 		}
1230
-		if ($backtrack_limit < $memory_limit/8)
1229
+		if ($backtrack_limit < $memory_limit / 8)
1231 1230
 		{
1232
-			ini_set( 'pcre.backtrack_limit', $backtrack_limit*=2);
1231
+			ini_set('pcre.backtrack_limit', $backtrack_limit *= 2);
1233 1232
 			return true;
1234 1233
 		}
1235 1234
 		error_log("pcre.backtrack_limit exceeded @ $backtrack_limit, some cells left as text.");
@@ -1241,32 +1240,32 @@  discard block
 block discarded – undo
1241 1240
 	 */
1242 1241
 	protected function format_spreadsheet_dates(&$content, $names, &$values, $mimetype)
1243 1242
 	{
1244
-		if(!in_array($mimetype, array(
1245
-			'application/vnd.oasis.opendocument.spreadsheet',		// open office calc
1246
-			'application/xmlExcel.Sheet',					// Excel 2003
1243
+		if (!in_array($mimetype, array(
1244
+			'application/vnd.oasis.opendocument.spreadsheet', // open office calc
1245
+			'application/xmlExcel.Sheet', // Excel 2003
1247 1246
 			//'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'//Excel WTF
1248 1247
 		))) return;
1249 1248
 
1250 1249
 		// Some different formats dates could be in, depending what they've been through
1251 1250
 		$formats = array(
1252
-			'!'.Api\DateTime::$user_dateformat . ' ' .Api\DateTime::$user_timeformat.':s',
1253
-			'!'.Api\DateTime::$user_dateformat . '*' .Api\DateTime::$user_timeformat.':s',
1254
-			'!'.Api\DateTime::$user_dateformat . '* ' .Api\DateTime::$user_timeformat,
1255
-			'!'.Api\DateTime::$user_dateformat . '*',
1251
+			'!'.Api\DateTime::$user_dateformat.' '.Api\DateTime::$user_timeformat.':s',
1252
+			'!'.Api\DateTime::$user_dateformat.'*'.Api\DateTime::$user_timeformat.':s',
1253
+			'!'.Api\DateTime::$user_dateformat.'* '.Api\DateTime::$user_timeformat,
1254
+			'!'.Api\DateTime::$user_dateformat.'*',
1256 1255
 			'!'.Api\DateTime::$user_dateformat,
1257 1256
 		);
1258 1257
 
1259 1258
 		// Properly format values for spreadsheet
1260
-		foreach($names as $idx => &$field)
1259
+		foreach ($names as $idx => &$field)
1261 1260
 		{
1262 1261
 			$key = '$$'.$field.'$$';
1263 1262
 			$field = preg_quote($field, '/');
1264
-			if($values[$key])
1263
+			if ($values[$key])
1265 1264
 			{
1266
-				if(!is_numeric($values[$key]))
1265
+				if (!is_numeric($values[$key]))
1267 1266
 				{
1268 1267
 					// Try the different formats, stop when one works
1269
-					foreach($formats as $f)
1268
+					foreach ($formats as $f)
1270 1269
 					{
1271 1270
 						try {
1272 1271
 							$date = Api\DateTime::createFromFormat(
@@ -1274,12 +1273,12 @@  discard block
 block discarded – undo
1274 1273
 								$values[$key],
1275 1274
 								Api\DateTime::$user_timezone
1276 1275
 							);
1277
-							if($date) break;
1276
+							if ($date) break;
1278 1277
 						} catch (Exception $e) {
1279 1278
 
1280 1279
 						}
1281 1280
 					}
1282
-					if(!$date)
1281
+					if (!$date)
1283 1282
 					{
1284 1283
 						// Couldn't get a date out of it... skip it
1285 1284
 						trigger_error("Unable to parse date $key = '{$values[$key]}' - left as text", E_USER_NOTICE);
@@ -1291,16 +1290,16 @@  discard block
 block discarded – undo
1291 1290
 				{
1292 1291
 					$date = new Api\DateTime($values[$key]);
1293 1292
 				}
1294
-				if($mimetype == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')//Excel WTF
1293
+				if ($mimetype == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')//Excel WTF
1295 1294
 				{
1296 1295
 					$interval = $date->diff(new Api\DateTime('1900-01-00 0:00'));
1297
-					$values[$key] = $interval->format('%a')+1;// 1900-02-29 did not exist
1296
+					$values[$key] = $interval->format('%a') + 1; // 1900-02-29 did not exist
1298 1297
 					// 1440 minutes in a day - fractional part
1299
-					$values[$key] += ($date->format('H') * 60 + $date->format('i'))/1440;
1298
+					$values[$key] += ($date->format('H') * 60 + $date->format('i')) / 1440;
1300 1299
 				}
1301 1300
 				else
1302 1301
 				{
1303
-					$values[$key] = date('Y-m-d\TH:i:s',Api\DateTime::to($date,'ts'));
1302
+					$values[$key] = date('Y-m-d\TH:i:s', Api\DateTime::to($date, 'ts'));
1304 1303
 				}
1305 1304
 			}
1306 1305
 			else
@@ -1309,33 +1308,33 @@  discard block
 block discarded – undo
1309 1308
 			}
1310 1309
 		}
1311 1310
 
1312
-		switch($mimetype)
1311
+		switch ($mimetype)
1313 1312
 		{
1314 1313
 			case 'application/vnd.oasis.opendocument.spreadsheet':		// open office calc
1315 1314
 				// Removing these forces calc to respect our set value-type
1316
-				$content = str_ireplace('calcext:value-type="string"','',$content);
1315
+				$content = str_ireplace('calcext:value-type="string"', '', $content);
1317 1316
 
1318
-				$format = '/<table:table-cell([^>]+?)office:value-type="[^"]+"([^>]*?)>.?<([a-z].*?)[^>]*>\$\$('.implode('|',$names).')\$\$<\/\3>.?<\/table:table-cell>/s';
1317
+				$format = '/<table:table-cell([^>]+?)office:value-type="[^"]+"([^>]*?)>.?<([a-z].*?)[^>]*>\$\$('.implode('|', $names).')\$\$<\/\3>.?<\/table:table-cell>/s';
1319 1318
 				$replacement = '<table:table-cell$1office:value-type="date" office:date-value="\$\$$4\$\$"$2><$3>\$\$$4\$\$</$3></table:table-cell>';
1320 1319
 				break;
1321 1320
 			case 'application/xmlExcel.Sheet':	// Excel 2003
1322
-				$format = '/'.preg_quote('<Data ss:Type="String">','/').'..('.implode('|',$names).')..'.preg_quote('</Data>','/').'/';
1321
+				$format = '/'.preg_quote('<Data ss:Type="String">', '/').'..('.implode('|', $names).')..'.preg_quote('</Data>', '/').'/';
1323 1322
 				$replacement = '<Data ss:Type="DateTime">\$\$$1\$\$</Data>';
1324 1323
 
1325 1324
 				break;
1326 1325
 			case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
1327 1326
 				break;
1328 1327
 		}
1329
-		if($format && $names)
1328
+		if ($format && $names)
1330 1329
 		{
1331 1330
 			// Dealing with backtrack limit per AmigoJack 10-Jul-2010 comment on php.net preg-replace docs
1332 1331
 			do {
1333 1332
 				$result = preg_replace($format, $replacement, $content, -1);
1334 1333
 			}
1335 1334
 			// try to increase/double pcre.backtrack_limit failure
1336
-			while(preg_last_error() == PREG_BACKTRACK_LIMIT_ERROR && self::increase_backtrack_limit());
1335
+			while (preg_last_error() == PREG_BACKTRACK_LIMIT_ERROR && self::increase_backtrack_limit());
1337 1336
 
1338
-			if ($result) $content = $result;  // On failure $result would be NULL
1337
+			if ($result) $content = $result; // On failure $result would be NULL
1339 1338
 		}
1340 1339
 	}
1341 1340
 
@@ -1345,9 +1344,9 @@  discard block
 block discarded – undo
1345 1344
 	 */
1346 1345
 	public function cf_link_to_expand($values, $content, &$replacements, $app = null)
1347 1346
 	{
1348
-		if($app == null)
1347
+		if ($app == null)
1349 1348
 		{
1350
-			$app = str_replace('_merge','',get_class($this));
1349
+			$app = str_replace('_merge', '', get_class($this));
1351 1350
 		}
1352 1351
 		$cfs = Api\Storage\Customfields::get($app);
1353 1352
 
@@ -1358,13 +1357,13 @@  discard block
 block discarded – undo
1358 1357
 		// Placeholders that need expanded will look like {{#name/placeholder}}
1359 1358
 		$matches = null;
1360 1359
 		preg_match_all('/\${2}(([^\/#]*?\/)?)#([^$\/]+)\/(.*?)[$}]{2}/', $content, $matches);
1361
-		list($placeholders, , , $cf, $sub) = $matches;
1360
+		list($placeholders,,, $cf, $sub) = $matches;
1362 1361
 
1363
-		foreach($cf as $index => $field)
1362
+		foreach ($cf as $index => $field)
1364 1363
 		{
1365
-			if($cfs[$field])
1364
+			if ($cfs[$field])
1366 1365
 			{
1367
-				if(in_array($cfs[$field]['type'],array_keys($GLOBALS['egw_info']['apps'])))
1366
+				if (in_array($cfs[$field]['type'], array_keys($GLOBALS['egw_info']['apps'])))
1368 1367
 				{
1369 1368
 					$field_app = $cfs[$field]['type'];
1370 1369
 				}
@@ -1375,7 +1374,7 @@  discard block
 block discarded – undo
1375 1374
 					$account = $GLOBALS['egw']->accounts->read($values['#'.$field]);
1376 1375
 					$app_replacements[$field] = $this->contact_replacements($account['person_id']);
1377 1376
 				}
1378
-				else if (($list = explode('-',$cfs[$field]['type']) && in_array($list[0], array_keys($GLOBALS['egw_info']['apps']))))
1377
+				else if (($list = explode('-', $cfs[$field]['type']) && in_array($list[0], array_keys($GLOBALS['egw_info']['apps']))))
1379 1378
 				{
1380 1379
 					// Sub-type - use app
1381 1380
 					$field_app = $list[0];
@@ -1386,7 +1385,7 @@  discard block
 block discarded – undo
1386 1385
 				}
1387 1386
 
1388 1387
 				// Get replacements for that application
1389
-				if(!$app_replacements[$field])
1388
+				if (!$app_replacements[$field])
1390 1389
 				{
1391 1390
 					$classname = "{$field_app}_merge";
1392 1391
 					$class = new $classname();
@@ -1414,33 +1413,33 @@  discard block
 block discarded – undo
1414 1413
 	 */
1415 1414
 	private function process_commands($content, $replacements)
1416 1415
 	{
1417
-		if (strpos($content,'$$IF') !== false)
1416
+		if (strpos($content, '$$IF') !== false)
1418 1417
 		{	//Example use to use: $$IF n_prefix~Herr~Sehr geehrter~Sehr geehrte$$
1419
-			$this->replacements =& $replacements;
1420
-			$content = preg_replace_callback('/\$\$IF ([#0-9a-z_\/-]+)~(.*)~(.*)~(.*)\$\$/imU',Array($this,'replace_callback'),$content);
1418
+			$this->replacements = & $replacements;
1419
+			$content = preg_replace_callback('/\$\$IF ([#0-9a-z_\/-]+)~(.*)~(.*)~(.*)\$\$/imU', Array($this, 'replace_callback'), $content);
1421 1420
 			unset($this->replacements);
1422 1421
 		}
1423
-		if (strpos($content,'$$NELF') !== false)
1422
+		if (strpos($content, '$$NELF') !== false)
1424 1423
 		{	//Example: $$NEPBR org_unit$$ sets a LF and value of org_unit, only if there is a value
1425
-			$this->replacements =& $replacements;
1426
-			$content = preg_replace_callback('/\$\$NELF ([#0-9a-z_\/-]+)\$\$/imU',Array($this,'replace_callback'),$content);
1424
+			$this->replacements = & $replacements;
1425
+			$content = preg_replace_callback('/\$\$NELF ([#0-9a-z_\/-]+)\$\$/imU', Array($this, 'replace_callback'), $content);
1427 1426
 			unset($this->replacements);
1428 1427
 		}
1429
-		if (strpos($content,'$$NENVLF') !== false)
1428
+		if (strpos($content, '$$NENVLF') !== false)
1430 1429
 		{	//Example: $$NEPBRNV org_unit$$ sets only a LF if there is a value for org_units, but did not add any value
1431
-			$this->replacements =& $replacements;
1432
-			$content = preg_replace_callback('/\$\$NENVLF ([#0-9a-z_\/-]+)\$\$/imU',Array($this,'replace_callback'),$content);
1430
+			$this->replacements = & $replacements;
1431
+			$content = preg_replace_callback('/\$\$NENVLF ([#0-9a-z_\/-]+)\$\$/imU', Array($this, 'replace_callback'), $content);
1433 1432
 			unset($this->replacements);
1434 1433
 		}
1435
-		if (strpos($content,'$$LETTERPREFIX$$') !== false)
1434
+		if (strpos($content, '$$LETTERPREFIX$$') !== false)
1436 1435
 		{	//Example use to use: $$LETTERPREFIX$$
1437 1436
 			$LETTERPREFIXCUSTOM = '$$LETTERPREFIXCUSTOM n_prefix title n_family$$';
1438
-			$content = str_replace('$$LETTERPREFIX$$',$LETTERPREFIXCUSTOM,$content);
1437
+			$content = str_replace('$$LETTERPREFIX$$', $LETTERPREFIXCUSTOM, $content);
1439 1438
 		}
1440
-		if (strpos($content,'$$LETTERPREFIXCUSTOM') !== false)
1439
+		if (strpos($content, '$$LETTERPREFIXCUSTOM') !== false)
1441 1440
 		{	//Example use to use for a custom Letter Prefix: $$LETTERPREFIX n_prefix title n_family$$
1442
-			$this->replacements =& $replacements;
1443
-			$content = preg_replace_callback('/\$\$LETTERPREFIXCUSTOM ([#0-9a-z_-]+)(.*)\$\$/imU',Array($this,'replace_callback'),$content);
1441
+			$this->replacements = & $replacements;
1442
+			$content = preg_replace_callback('/\$\$LETTERPREFIXCUSTOM ([#0-9a-z_-]+)(.*)\$\$/imU', Array($this, 'replace_callback'), $content);
1444 1443
 			unset($this->replacements);
1445 1444
 		}
1446 1445
 		return $content;
@@ -1454,16 +1453,16 @@  discard block
 block discarded – undo
1454 1453
 	 */
1455 1454
 	private function replace_callback($param)
1456 1455
 	{
1457
-		if (array_key_exists('$$'.$param[4].'$$',$this->replacements)) $param[4] = $this->replacements['$$'.$param[4].'$$'];
1458
-		if (array_key_exists('$$'.$param[3].'$$',$this->replacements)) $param[3] = $this->replacements['$$'.$param[3].'$$'];
1456
+		if (array_key_exists('$$'.$param[4].'$$', $this->replacements)) $param[4] = $this->replacements['$$'.$param[4].'$$'];
1457
+		if (array_key_exists('$$'.$param[3].'$$', $this->replacements)) $param[3] = $this->replacements['$$'.$param[3].'$$'];
1459 1458
 
1460 1459
 		$pattern = '/'.preg_quote($param[2], '/').'/';
1461
-		if (strpos($param[0],'$$IF') === 0 && (trim($param[2]) == "EMPTY" || $param[2] === ''))
1460
+		if (strpos($param[0], '$$IF') === 0 && (trim($param[2]) == "EMPTY" || $param[2] === ''))
1462 1461
 		{
1463 1462
 			$pattern = '/^$/';
1464 1463
 		}
1465
-		$replace = preg_match($pattern,$this->replacements['$$'.$param[1].'$$']) ? $param[3] : $param[4];
1466
-		switch($this->mimetype)
1464
+		$replace = preg_match($pattern, $this->replacements['$$'.$param[1].'$$']) ? $param[3] : $param[4];
1465
+		switch ($this->mimetype)
1467 1466
 		{
1468 1467
 			case 'application/vnd.oasis.opendocument.text':		// open office
1469 1468
 			case 'application/vnd.oasis.opendocument.spreadsheet':
@@ -1476,14 +1475,14 @@  discard block
 block discarded – undo
1476 1475
 				break;
1477 1476
 		}
1478 1477
 
1479
-		switch($this->mimetype)
1478
+		switch ($this->mimetype)
1480 1479
 			{
1481 1480
 				case 'application/rtf':
1482 1481
 				case 'text/rtf':
1483 1482
 					$LF = '}\par \pard\plain{';
1484 1483
 					break;
1485 1484
 				case 'application/vnd.oasis.opendocument.text':
1486
-					$LF ='<text:line-break/>';
1485
+					$LF = '<text:line-break/>';
1487 1486
 					break;
1488 1487
 				case 'application/vnd.oasis.opendocument.spreadsheet':		// open office calc
1489 1488
 					$LF = '</text:p><text:p>';
@@ -1493,35 +1492,35 @@  discard block
 block discarded – undo
1493 1492
 					break;
1494 1493
 				case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
1495 1494
 				case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
1496
-					$LF ='</w:t></w:r></w:p><w:p><w:r><w:t>';
1495
+					$LF = '</w:t></w:r></w:p><w:p><w:r><w:t>';
1497 1496
 					break;
1498 1497
 				case 'application/xml';
1499
-					$LF ='</w:t></w:r><w:r><w:br w:type="text-wrapping" w:clear="all"/></w:r><w:r><w:t>';
1498
+					$LF = '</w:t></w:r><w:r><w:br w:type="text-wrapping" w:clear="all"/></w:r><w:r><w:t>';
1500 1499
 					break;
1501 1500
 				default:
1502 1501
 					$LF = "\n";
1503 1502
 			}
1504
-		if($is_xml) {
1505
-			$this->replacements = str_replace(array('&','&amp;amp;','<','>',"\r","\n"),array('&amp;','&amp;','&lt;','&gt;','',$LF),$this->replacements);
1503
+		if ($is_xml) {
1504
+			$this->replacements = str_replace(array('&', '&amp;amp;', '<', '>', "\r", "\n"), array('&amp;', '&amp;', '&lt;', '&gt;', '', $LF), $this->replacements);
1506 1505
 		}
1507
-		if (strpos($param[0],'$$NELF') === 0)
1506
+		if (strpos($param[0], '$$NELF') === 0)
1508 1507
 		{	//sets a Pagebreak and value, only if the field has a value
1509
-			if ($this->replacements['$$'.$param[1].'$$'] !='') $replace = $LF.$this->replacements['$$'.$param[1].'$$'];
1508
+			if ($this->replacements['$$'.$param[1].'$$'] != '') $replace = $LF.$this->replacements['$$'.$param[1].'$$'];
1510 1509
 		}
1511
-		if (strpos($param[0],'$$NENVLF') === 0)
1510
+		if (strpos($param[0], '$$NENVLF') === 0)
1512 1511
 		{	//sets a Pagebreak without any value, only if the field has a value
1513
-			if ($this->replacements['$$'.$param[1].'$$'] !='') $replace = $LF;
1512
+			if ($this->replacements['$$'.$param[1].'$$'] != '') $replace = $LF;
1514 1513
 		}
1515
-		if (strpos($param[0],'$$LETTERPREFIXCUSTOM') === 0)
1514
+		if (strpos($param[0], '$$LETTERPREFIXCUSTOM') === 0)
1516 1515
 		{	//sets a Letterprefix
1517 1516
 			$replaceprefixsort = array();
1518 1517
 			// ToDo Stefan: $contentstart is NOT defined here!!!
1519
-			$replaceprefix = explode(' ',substr($param[0],21,-2));
1518
+			$replaceprefix = explode(' ', substr($param[0], 21, -2));
1520 1519
 			foreach ($replaceprefix as $nameprefix)
1521 1520
 			{
1522
-				if ($this->replacements['$$'.$nameprefix.'$$'] !='') $replaceprefixsort[] = $this->replacements['$$'.$nameprefix.'$$'];
1521
+				if ($this->replacements['$$'.$nameprefix.'$$'] != '') $replaceprefixsort[] = $this->replacements['$$'.$nameprefix.'$$'];
1523 1522
 			}
1524
-			$replace = implode($replaceprefixsort,' ');
1523
+			$replace = implode($replaceprefixsort, ' ');
1525 1524
 		}
1526 1525
 		return $replace;
1527 1526
 	}
@@ -1535,7 +1534,7 @@  discard block
 block discarded – undo
1535 1534
 	 * @param string $dirs comma or whitespace separated directories, used if $document is a relative path
1536 1535
 	 * @return string with error-message on error, otherwise it does NOT return
1537 1536
 	 */
1538
-	public function download($document, $ids, $name='', $dirs='')
1537
+	public function download($document, $ids, $name = '', $dirs = '')
1539 1538
 	{
1540 1539
 		//error_log(__METHOD__."('$document', ".array2string($ids).", '$name', dirs='$dirs') ->".function_backtrace());
1541 1540
 		if (($error = $this->check_document($document, $dirs)))
@@ -1551,7 +1550,7 @@  discard block
 block discarded – undo
1551 1550
 				$mail_bo->openConnection();
1552 1551
 				try
1553 1552
 				{
1554
-					$msgs = $mail_bo->importMessageToMergeAndSend($this, $content_url, $ids, $_folder='');
1553
+					$msgs = $mail_bo->importMessageToMergeAndSend($this, $content_url, $ids, $_folder = '');
1555 1554
 				}
1556 1555
 				catch (Api\Exception\WrongUserinput $e)
1557 1556
 				{
@@ -1560,39 +1559,39 @@  discard block
 block discarded – undo
1560 1559
 				}
1561 1560
 				//error_log(__METHOD__.__LINE__.' Message after importMessageToMergeAndSend:'.array2string($msgs));
1562 1561
 				$retString = '';
1563
-				if (count($msgs['success'])>0) $retString .= count($msgs['success']).' '.(count($msgs['success'])+count($msgs['failed'])==1?lang('Message prepared for sending.'):lang('Message(s) send ok.'));//implode('<br />',$msgs['success']);
1562
+				if (count($msgs['success']) > 0) $retString .= count($msgs['success']).' '.(count($msgs['success']) + count($msgs['failed']) == 1 ? lang('Message prepared for sending.') : lang('Message(s) send ok.')); //implode('<br />',$msgs['success']);
1564 1563
 				//if (strlen($retString)>0) $retString .= '<br />';
1565
-				foreach($msgs['failed'] as $c =>$e)
1564
+				foreach ($msgs['failed'] as $c =>$e)
1566 1565
 				{
1567 1566
 					$errorString .= lang('contact').' '.lang('id').':'.$c.'->'.$e.'.';
1568 1567
 				}
1569
-				if (count($msgs['failed'])>0) $retString .= count($msgs['failed']).' '.lang('Message(s) send failed!').'=>'.$errorString;
1568
+				if (count($msgs['failed']) > 0) $retString .= count($msgs['failed']).' '.lang('Message(s) send failed!').'=>'.$errorString;
1570 1569
 				return $retString;
1571 1570
 			case 'application/vnd.oasis.opendocument.text':
1572 1571
 			case 'application/vnd.oasis.opendocument.spreadsheet':
1573 1572
 				$ext = $mimetype == 'application/vnd.oasis.opendocument.text' ? '.odt' : '.ods';
1574
-				$archive = tempnam($GLOBALS['egw_info']['server']['temp_dir'], basename($document,$ext).'-').$ext;
1575
-				copy($content_url,$archive);
1573
+				$archive = tempnam($GLOBALS['egw_info']['server']['temp_dir'], basename($document, $ext).'-').$ext;
1574
+				copy($content_url, $archive);
1576 1575
 				$content_url = 'zip://'.$archive.'#'.($content_file = 'content.xml');
1577 1576
 				$this->parse_html_styles = true;
1578 1577
 				break;
1579 1578
 			case 'application/vnd.openxmlformats-officedocument.wordprocessingml.d':	// mimetypes in vfs are limited to 64 chars
1580 1579
 				$mimetype = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
1581 1580
 			case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
1582
-				$archive = tempnam($GLOBALS['egw_info']['server']['temp_dir'], basename($document,'.docx').'-').'.docx';
1583
-				copy($content_url,$archive);
1581
+				$archive = tempnam($GLOBALS['egw_info']['server']['temp_dir'], basename($document, '.docx').'-').'.docx';
1582
+				copy($content_url, $archive);
1584 1583
 				$content_url = 'zip://'.$archive.'#'.($content_file = 'word/document.xml');
1585 1584
 				$fix = array(		// regular expression to fix garbled placeholders
1586
-					'/'.preg_quote('$$</w:t></w:r><w:proofErr w:type="spellStart"/><w:r><w:t>','/').'([a-z0-9_]+)'.
1587
-						preg_quote('</w:t></w:r><w:proofErr w:type="spellEnd"/><w:r><w:t>','/').'/i' => '$$\\1$$',
1588
-					'/'.preg_quote('$$</w:t></w:r><w:proofErr w:type="spellStart"/><w:r><w:rPr><w:lang w:val="','/').
1589
-						'([a-z]{2}-[A-Z]{2})'.preg_quote('"/></w:rPr><w:t>','/').'([a-z0-9_]+)'.
1590
-						preg_quote('</w:t></w:r><w:proofErr w:type="spellEnd"/><w:r><w:rPr><w:lang w:val="','/').
1591
-						'([a-z]{2}-[A-Z]{2})'.preg_quote('"/></w:rPr><w:t>$$','/').'/i' => '$$\\2$$',
1592
-					'/'.preg_quote('$</w:t></w:r><w:proofErr w:type="spellStart"/><w:r><w:t>','/').'([a-z0-9_]+)'.
1593
-						preg_quote('</w:t></w:r><w:proofErr w:type="spellEnd"/><w:r><w:t>','/').'/i' => '$\\1$',
1594
-					'/'.preg_quote('$ $</w:t></w:r><w:proofErr w:type="spellStart"/><w:r><w:t>','/').'([a-z0-9_]+)'.
1595
-						preg_quote('</w:t></w:r><w:proofErr w:type="spellEnd"/><w:r><w:t>','/').'/i' => '$ $\\1$ $',
1585
+					'/'.preg_quote('$$</w:t></w:r><w:proofErr w:type="spellStart"/><w:r><w:t>', '/').'([a-z0-9_]+)'.
1586
+						preg_quote('</w:t></w:r><w:proofErr w:type="spellEnd"/><w:r><w:t>', '/').'/i' => '$$\\1$$',
1587
+					'/'.preg_quote('$$</w:t></w:r><w:proofErr w:type="spellStart"/><w:r><w:rPr><w:lang w:val="', '/').
1588
+						'([a-z]{2}-[A-Z]{2})'.preg_quote('"/></w:rPr><w:t>', '/').'([a-z0-9_]+)'.
1589
+						preg_quote('</w:t></w:r><w:proofErr w:type="spellEnd"/><w:r><w:rPr><w:lang w:val="', '/').
1590
+						'([a-z]{2}-[A-Z]{2})'.preg_quote('"/></w:rPr><w:t>$$', '/').'/i' => '$$\\2$$',
1591
+					'/'.preg_quote('$</w:t></w:r><w:proofErr w:type="spellStart"/><w:r><w:t>', '/').'([a-z0-9_]+)'.
1592
+						preg_quote('</w:t></w:r><w:proofErr w:type="spellEnd"/><w:r><w:t>', '/').'/i' => '$\\1$',
1593
+					'/'.preg_quote('$ $</w:t></w:r><w:proofErr w:type="spellStart"/><w:r><w:t>', '/').'([a-z0-9_]+)'.
1594
+						preg_quote('</w:t></w:r><w:proofErr w:type="spellEnd"/><w:r><w:t>', '/').'/i' => '$ $\\1$ $',
1596 1595
 				);
1597 1596
 				break;
1598 1597
 			case 'application/xml':
@@ -1606,13 +1605,13 @@  discard block
 block discarded – undo
1606 1605
 				$fix = array(	// hack to get Excel 2007 to display additional rows in tables
1607 1606
 					'/ss:ExpandedRowCount="\d+"/' => 'ss:ExpandedRowCount="9999"',
1608 1607
 				);
1609
-				$archive = tempnam($GLOBALS['egw_info']['server']['temp_dir'], basename($document,'.xlsx').'-').'.xlsx';
1610
-				copy($content_url,$archive);
1608
+				$archive = tempnam($GLOBALS['egw_info']['server']['temp_dir'], basename($document, '.xlsx').'-').'.xlsx';
1609
+				copy($content_url, $archive);
1611 1610
 				$content_url = 'zip://'.$archive.'#'.($content_file = 'xl/sharedStrings.xml');
1612 1611
 				break;
1613 1612
 		}
1614 1613
 		$err = null;
1615
-		if (!($merged =& $this->merge($content_url,$ids,$err,$mimetype,$fix)))
1614
+		if (!($merged = & $this->merge($content_url, $ids, $err, $mimetype, $fix)))
1616 1615
 		{
1617 1616
 			//error_log(__METHOD__."() !this->merge() err=$err");
1618 1617
 			return $err;
@@ -1629,22 +1628,22 @@  discard block
 block discarded – undo
1629 1628
 			{
1630 1629
 				// Error converting HTML styles over
1631 1630
 				error_log($e->getMessage());
1632
-				error_log("Target document: $content_url, IDs: ". array2string($ids));
1631
+				error_log("Target document: $content_url, IDs: ".array2string($ids));
1633 1632
 
1634 1633
 				// Try again, but strip HTML so user gets something
1635 1634
 				$this->parse_html_styles = false;
1636
-				if (!($merged =& $this->merge($content_url,$ids,$err,$mimetype,$fix)))
1635
+				if (!($merged = & $this->merge($content_url, $ids, $err, $mimetype, $fix)))
1637 1636
 				{
1638 1637
 					return $err;
1639 1638
 				}
1640 1639
 			}
1641 1640
 			if ($this->report_memory_usage) error_log(__METHOD__."() after HTML processing ".Api\Vfs::hsize(memory_get_peak_usage(true)));
1642 1641
 		}
1643
-		if(!empty($name))
1642
+		if (!empty($name))
1644 1643
 		{
1645
-			if(empty($ext))
1644
+			if (empty($ext))
1646 1645
 			{
1647
-				$ext = '.'.pathinfo($document,PATHINFO_EXTENSION);
1646
+				$ext = '.'.pathinfo($document, PATHINFO_EXTENSION);
1648 1647
 			}
1649 1648
 			$name .= $ext;
1650 1649
 		}
@@ -1660,30 +1659,30 @@  discard block
 block discarded – undo
1660 1659
 				error_log(__METHOD__.__LINE__." !ZipArchive::open('$archive',ZIPARCHIVE"."::CHECKCONS) failed. Trying open without validating");
1661 1660
 				if ($zip->open($archive) !== true) throw new Api\Exception("!ZipArchive::open('$archive',|ZIPARCHIVE::CHECKCONS)");
1662 1661
 			}
1663
-			if ($zip->addFromString($content_file,$merged) !== true) throw new Api\Exception("!ZipArchive::addFromString('$content_file',\$merged)");
1662
+			if ($zip->addFromString($content_file, $merged) !== true) throw new Api\Exception("!ZipArchive::addFromString('$content_file',\$merged)");
1664 1663
 			if ($zip->close() !== true) throw new Api\Exception("!ZipArchive::close()");
1665 1664
 			unset($zip);
1666 1665
 			unset($merged);
1667
-			if (substr($mimetype,0,35) == 'application/vnd.oasis.opendocument.' && 			// only open office archives need that, ms word files brake
1668
-				file_exists('/usr/bin/zip') && version_compare(PHP_VERSION,'5.3.1','<'))	// fix broken zip archives generated by current php
1666
+			if (substr($mimetype, 0, 35) == 'application/vnd.oasis.opendocument.' && // only open office archives need that, ms word files brake
1667
+				file_exists('/usr/bin/zip') && version_compare(PHP_VERSION, '5.3.1', '<'))	// fix broken zip archives generated by current php
1669 1668
 			{
1670 1669
 				exec('/usr/bin/zip -F '.escapeshellarg($archive));
1671 1670
 			}
1672 1671
 			if ($this->report_memory_usage) error_log(__METHOD__."() after ZIP processing ".Api\Vfs::hsize(memory_get_peak_usage(true)));
1673
-			Api\Header\Content::type($name,$mimetype,filesize($archive));
1674
-			readfile($archive,'r');
1672
+			Api\Header\Content::type($name, $mimetype, filesize($archive));
1673
+			readfile($archive, 'r');
1675 1674
 		}
1676 1675
 		else
1677 1676
 		{
1678 1677
 			if ($mimetype == 'application/xml')
1679 1678
 			{
1680
-				if (strpos($merged,'<?mso-application progid="Word.Document"?>') !== false)
1679
+				if (strpos($merged, '<?mso-application progid="Word.Document"?>') !== false)
1681 1680
 				{
1682
-					$mimetype = 'application/msword';	// to open it automatically in word or oowriter
1681
+					$mimetype = 'application/msword'; // to open it automatically in word or oowriter
1683 1682
 				}
1684
-				elseif (strpos($merged,'<?mso-application progid="Excel.Sheet"?>') !== false)
1683
+				elseif (strpos($merged, '<?mso-application progid="Excel.Sheet"?>') !== false)
1685 1684
 				{
1686
-					$mimetype = 'application/vnd.ms-excel';	// to open it automatically in excel or oocalc
1685
+					$mimetype = 'application/vnd.ms-excel'; // to open it automatically in excel or oocalc
1687 1686
 				}
1688 1687
 			}
1689 1688
 			Api\Header\Content::type($name, $mimetype);
@@ -1704,13 +1703,13 @@  discard block
 block discarded – undo
1704 1703
 	 */
1705 1704
 	public function download_by_request()
1706 1705
 	{
1707
-		if(empty($_POST['data_document_name'])) return false;
1708
-		if(empty($_POST['data_document_dir'])) return false;
1709
-		if(empty($_POST['data_checked'])) return false;
1706
+		if (empty($_POST['data_document_name'])) return false;
1707
+		if (empty($_POST['data_document_dir'])) return false;
1708
+		if (empty($_POST['data_checked'])) return false;
1710 1709
 
1711 1710
 		return $this->download(
1712 1711
 			$_POST['data_document_name'],
1713
-			explode(',',$_POST['data_checked']),
1712
+			explode(',', $_POST['data_checked']),
1714 1713
 			'',
1715 1714
 			$_POST['data_document_dir']
1716 1715
 		);
@@ -1724,18 +1723,18 @@  discard block
 block discarded – undo
1724 1723
 	 * @param array|string $mime_filter=null allowed mime type(s), default all, negative filter if $mime_filter[0] === '!'
1725 1724
 	 * @return array List of documents, suitable for a selectbox.  The key is document_<filename>.
1726 1725
 	 */
1727
-	public static function get_documents($dirs, $prefix='document_', $mime_filter=null, $app='')
1726
+	public static function get_documents($dirs, $prefix = 'document_', $mime_filter = null, $app = '')
1728 1727
 	{
1729
-		$export_limit=self::getExportLimit($app);
1730
-		if (!$dirs || (!self::hasExportLimit($export_limit,'ISALLOWED') && !self::is_export_limit_excepted())) return array();
1728
+		$export_limit = self::getExportLimit($app);
1729
+		if (!$dirs || (!self::hasExportLimit($export_limit, 'ISALLOWED') && !self::is_export_limit_excepted())) return array();
1731 1730
 
1732 1731
 		// split multiple comma or whitespace separated directories
1733 1732
 		// to still allow space or comma in dirnames, we also use the trailing slash of all pathes to split
1734 1733
 		if (count($dirs = preg_split('/[,\s]+\//', $dirs)) > 1)
1735 1734
 		{
1736
-			foreach($dirs as $n => &$d)
1735
+			foreach ($dirs as $n => &$d)
1737 1736
 			{
1738
-				if ($n) $d = '/'.$d;	// re-adding trailing slash removed by split
1737
+				if ($n) $d = '/'.$d; // re-adding trailing slash removed by split
1739 1738
 			}
1740 1739
 		}
1741 1740
 		if ($mime_filter && ($negativ_filter = $mime_filter[0] === '!'))
@@ -1750,15 +1749,15 @@  discard block
 block discarded – undo
1750 1749
 			}
1751 1750
 		}
1752 1751
 		$list = array();
1753
-		foreach($dirs as $dir)
1752
+		foreach ($dirs as $dir)
1754 1753
 		{
1755
-			if (($files = Api\Vfs::find($dir,array('need_mime'=>true),true)))
1754
+			if (($files = Api\Vfs::find($dir, array('need_mime'=>true), true)))
1756 1755
 			{
1757
-				foreach($files as $file)
1756
+				foreach ($files as $file)
1758 1757
 				{
1759 1758
 					// return only the mime-types we support
1760
-					$parts = explode('.',$file['name']);
1761
-					if (!self::is_implemented($file['mime'],'.'.array_pop($parts))) continue;
1759
+					$parts = explode('.', $file['name']);
1760
+					if (!self::is_implemented($file['mime'], '.'.array_pop($parts))) continue;
1762 1761
 					if ($mime_filter && $negativ_filter === in_array($file['mime'], (array)$mime_filter)) continue;
1763 1762
 					$list[$prefix.$file['name']] = Api\Vfs::decodePath($file['name']);
1764 1763
 				}
@@ -1785,14 +1784,14 @@  discard block
 block discarded – undo
1785 1784
 	 * @param int|string $export_limit =null export-limit, default $GLOBALS['egw_info']['server']['export_limit']
1786 1785
 	 * @return array see nextmatch_widget::egw_actions
1787 1786
 	 */
1788
-	public static function document_action($dirs, $group=0, $caption='Insert in document', $prefix='document_', $default_doc='',
1789
-		$export_limit=null)
1787
+	public static function document_action($dirs, $group = 0, $caption = 'Insert in document', $prefix = 'document_', $default_doc = '',
1788
+		$export_limit = null)
1790 1789
 	{
1791 1790
 		$documents = array();
1792 1791
 		if ($export_limit == null) $export_limit = self::getExportLimit(); // check if there is a globalsetting
1793 1792
 		if ($default_doc && ($file = Api\Vfs::stat($default_doc)))	// put default document on top
1794 1793
 		{
1795
-			if(!$file['mime'])
1794
+			if (!$file['mime'])
1796 1795
 			{
1797 1796
 				$file['mime'] = Api\Vfs::mime_content_type($default_doc);
1798 1797
 				$file['path'] = $default_doc;
@@ -1801,7 +1800,7 @@  discard block
 block discarded – undo
1801 1800
 				'icon' => Api\Vfs::mime_icon($file['mime']),
1802 1801
 				'caption' => Api\Vfs::decodePath(Api\Vfs::basename($default_doc)),
1803 1802
 				'group' => 1,
1804
-				'postSubmit' => true,	// download needs post submit (not Ajax) to work
1803
+				'postSubmit' => true, // download needs post submit (not Ajax) to work
1805 1804
 			);
1806 1805
 			if ($file['mime'] == 'message/rfc822')
1807 1806
 			{
@@ -1816,28 +1815,28 @@  discard block
 block discarded – undo
1816 1815
 			// to still allow space or comma in dirnames, we also use the trailing slash of all pathes to split
1817 1816
 			if (count($dirs = preg_split('/[,\s]+\//', $dirs)) > 1)
1818 1817
 			{
1819
-				foreach($dirs as $n => &$d)
1818
+				foreach ($dirs as $n => &$d)
1820 1819
 				{
1821
-					if ($n) $d = '/'.$d;	// re-adding trailing slash removed by split
1820
+					if ($n) $d = '/'.$d; // re-adding trailing slash removed by split
1822 1821
 				}
1823 1822
 			}
1824
-			foreach($dirs as $dir)
1823
+			foreach ($dirs as $dir)
1825 1824
 			{
1826
-				$files += Api\Vfs::find($dir,array(
1825
+				$files += Api\Vfs::find($dir, array(
1827 1826
 					'need_mime' => true,
1828 1827
 					'order' => 'fs_name',
1829 1828
 					'sort' => 'ASC',
1830
-				),true);
1829
+				), true);
1831 1830
 			}
1832 1831
 		}
1833 1832
 
1834 1833
 		$dircount = array();
1835
-		foreach($files as $key => $file)
1834
+		foreach ($files as $key => $file)
1836 1835
 		{
1837 1836
 			// use only the mime-types we support
1838
-			$parts = explode('.',$file['name']);
1839
-			if (!self::is_implemented($file['mime'],'.'.array_pop($parts)) ||
1840
-				!Api\Vfs::check_access($file['path'], Api\Vfs::READABLE, $file) ||	// remove files not readable by user
1837
+			$parts = explode('.', $file['name']);
1838
+			if (!self::is_implemented($file['mime'], '.'.array_pop($parts)) ||
1839
+				!Api\Vfs::check_access($file['path'], Api\Vfs::READABLE, $file) || // remove files not readable by user
1841 1840
 				$file['path'] === $default_doc)	// default doc already added
1842 1841
 			{
1843 1842
 				unset($files[$key]);
@@ -1845,40 +1844,40 @@  discard block
 block discarded – undo
1845 1844
 			else
1846 1845
 			{
1847 1846
 				$dirname = Api\Vfs::dirname($file['path']);
1848
-				if(!isset($dircount[$dirname]))
1847
+				if (!isset($dircount[$dirname]))
1849 1848
 				{
1850 1849
 					$dircount[$dirname] = 1;
1851 1850
 				}
1852 1851
 				else
1853 1852
 				{
1854
-					$dircount[$dirname] ++;
1853
+					$dircount[$dirname]++;
1855 1854
 				}
1856 1855
 			}
1857 1856
 		}
1858
-		foreach($files as $file)
1857
+		foreach ($files as $file)
1859 1858
 		{
1860 1859
 			if (count($dircount) > 1)
1861 1860
 			{
1862 1861
 				$name_arr = explode('/', $file['name']);
1863 1862
 				$current_level = &$documents;
1864
-				for($count = 0; $count < count($name_arr); $count++)
1863
+				for ($count = 0; $count < count($name_arr); $count++)
1865 1864
 				{
1866
-					if($count == 0)
1865
+					if ($count == 0)
1867 1866
 					{
1868 1867
 						$current_level = &$documents;
1869 1868
 					}
1870 1869
 					else
1871 1870
 					{
1872
-						$current_level = &$current_level[$prefix.$name_arr[($count-1)]]['children'];
1871
+						$current_level = &$current_level[$prefix.$name_arr[($count - 1)]]['children'];
1873 1872
 					}
1874
-					switch($count)
1873
+					switch ($count)
1875 1874
 					{
1876
-						case (count($name_arr)-1):
1875
+						case (count($name_arr) - 1):
1877 1876
 							$current_level[$prefix.$file['name']] = array(
1878 1877
 								'icon'		=> Api\Vfs::mime_icon($file['mime']),
1879 1878
 								'caption'	=> Api\Vfs::decodePath($name_arr[$count]),
1880 1879
 								'group'		=> 2,
1881
-								'postSubmit' => true,	// download needs post submit (not Ajax) to work
1880
+								'postSubmit' => true, // download needs post submit (not Ajax) to work
1882 1881
 							);
1883 1882
 							if ($file['mime'] == 'message/rfc822')
1884 1883
 							{
@@ -1887,7 +1886,7 @@  discard block
 block discarded – undo
1887 1886
 							break;
1888 1887
 
1889 1888
 						default:
1890
-							if(!is_array($current_level[$prefix.$name_arr[$count]]))
1889
+							if (!is_array($current_level[$prefix.$name_arr[$count]]))
1891 1890
 							{
1892 1891
 								// create parent folder
1893 1892
 								$current_level[$prefix.$name_arr[$count]] = array(
@@ -1914,7 +1913,7 @@  discard block
 block discarded – undo
1914 1913
 				}
1915 1914
 				$documents[$file['mime']]['children'][$prefix.$file['name']] = array(
1916 1915
 					'caption' => Api\Vfs::decodePath($file['name']),
1917
-					'postSubmit' => true,	// download needs post submit (not Ajax) to work
1916
+					'postSubmit' => true, // download needs post submit (not Ajax) to work
1918 1917
 				);
1919 1918
 				if ($file['mime'] == 'message/rfc822')
1920 1919
 				{
@@ -1927,7 +1926,7 @@  discard block
 block discarded – undo
1927 1926
 					'icon' => Api\Vfs::mime_icon($file['mime']),
1928 1927
 					'caption' => Api\Vfs::decodePath($file['name']),
1929 1928
 					'group' => 2,
1930
-					'postSubmit' => true,	// download needs post submit (not Ajax) to work
1929
+					'postSubmit' => true, // download needs post submit (not Ajax) to work
1931 1930
 				);
1932 1931
 				if ($file['mime'] == 'message/rfc822')
1933 1932
 				{
@@ -1941,8 +1940,8 @@  discard block
 block discarded – undo
1941 1940
 			'caption' => $caption,
1942 1941
 			'children' => $documents,
1943 1942
 			// disable action if no document or export completly forbidden for non-admins
1944
-			'enabled' => (boolean)$documents && (self::hasExportLimit($export_limit,'ISALLOWED') || self::is_export_limit_excepted()),
1945
-			'hideOnDisabled' => true,	// do not show 'Insert in document', if no documents defined or no export allowed
1943
+			'enabled' => (boolean)$documents && (self::hasExportLimit($export_limit, 'ISALLOWED') || self::is_export_limit_excepted()),
1944
+			'hideOnDisabled' => true, // do not show 'Insert in document', if no documents defined or no export allowed
1946 1945
 			'group' => $group,
1947 1946
 		);
1948 1947
 	}
@@ -1973,14 +1972,14 @@  discard block
 block discarded – undo
1973 1972
 		);
1974 1973
 
1975 1974
 		// egw.open() used if only 1 row selected
1976
-		$action['egw_open'] = 'edit-mail--'.implode('&',$extra);
1977
-		$action['target'] = 'compose_' .$file['path'];
1975
+		$action['egw_open'] = 'edit-mail--'.implode('&', $extra);
1976
+		$action['target'] = 'compose_'.$file['path'];
1978 1977
 
1979 1978
 		// long_task runs menuaction once for each selected row
1980 1979
 		$action['nm_action'] = 'long_task';
1981 1980
 		$action['popup'] = Api\Link::get_registry('mail', 'edit_popup');
1982
-		$action['message'] = lang('insert in %1',Api\Vfs::decodePath($file['name']));
1983
-		$action['menuaction'] = 'mail.mail_compose.ajax_merge&document='.$file['path'].'&merge='. get_called_class();
1981
+		$action['message'] = lang('insert in %1', Api\Vfs::decodePath($file['name']));
1982
+		$action['menuaction'] = 'mail.mail_compose.ajax_merge&document='.$file['path'].'&merge='.get_called_class();
1984 1983
 	}
1985 1984
 
1986 1985
 	/**
@@ -1992,15 +1991,15 @@  discard block
 block discarded – undo
1992 1991
 	 */
1993 1992
 	public static function check_document(&$document, $dirs)
1994 1993
 	{
1995
-		if($document[0] !== '/')
1994
+		if ($document[0] !== '/')
1996 1995
 		{
1997 1996
 			// split multiple comma or whitespace separated directories
1998 1997
 			// to still allow space or comma in dirnames, we also use the trailing slash of all pathes to split
1999 1998
 			if ($dirs && ($dirs = preg_split('/[,\s]+\//', $dirs)))
2000 1999
 			{
2001
-				foreach($dirs as $n => $dir)
2000
+				foreach ($dirs as $n => $dir)
2002 2001
 				{
2003
-					if ($n) $dir = '/'.$dir;	// re-adding trailing slash removed by split
2002
+					if ($n) $dir = '/'.$dir; // re-adding trailing slash removed by split
2004 2003
 					if (Api\Vfs::stat($dir.'/'.$document) && Api\Vfs::is_readable($dir.'/'.$document))
2005 2004
 					{
2006 2005
 						$document = $dir.'/'.$document;
@@ -2014,7 +2013,7 @@  discard block
 block discarded – undo
2014 2013
 			return false;
2015 2014
 		}
2016 2015
 		//error_log(__METHOD__."('$document', dirs='$dirs') returning 'Document '$document' does not exist or is not readable for you!'");
2017
-		return lang("Document '%1' does not exist or is not readable for you!",$document);
2016
+		return lang("Document '%1' does not exist or is not readable for you!", $document);
2018 2017
 	}
2019 2018
 
2020 2019
 	/**
@@ -2035,16 +2034,16 @@  discard block
 block discarded – undo
2035 2034
 	 * @param string $_mimetype =''
2036 2035
 	 * @return string
2037 2036
 	 */
2038
-	static public function number_format($number,$num_decimal_places=2,$_mimetype='')
2037
+	static public function number_format($number, $num_decimal_places = 2, $_mimetype = '')
2039 2038
 	{
2040 2039
 		if ((string)$number === '') return '';
2041 2040
 		//error_log(__METHOD__.$_mimetype);
2042
-		switch($_mimetype)
2041
+		switch ($_mimetype)
2043 2042
 		{
2044 2043
 			case 'application/xml':	// Excel 2003
2045 2044
 			case 'application/vnd.oasis.opendocument.spreadsheet': // OO.o spreadsheet
2046
-				return number_format(str_replace(' ','',$number),$num_decimal_places,'.','');
2045
+				return number_format(str_replace(' ', '', $number), $num_decimal_places, '.', '');
2047 2046
 		}
2048
-		return Api\Etemplate::number_format($number,$num_decimal_places);
2047
+		return Api\Etemplate::number_format($number, $num_decimal_places);
2049 2048
 	}
2050 2049
 }
Please login to merge, or discard this patch.
Braces   +278 added lines, -77 removed lines patch added patch discarded remove patch
@@ -168,19 +168,28 @@  discard block
 block discarded – undo
168 168
 		switch ($mimetype)
169 169
 		{
170 170
 			case 'application/msword':
171
-				if (strtolower($extension) != '.rtf') break;
171
+				if (strtolower($extension) != '.rtf')
172
+				{
173
+					break;
174
+				}
172 175
 			case 'application/rtf':
173 176
 			case 'text/rtf':
174 177
 				return true;	// rtf files
175 178
 			case 'application/vnd.oasis.opendocument.text':	// oo text
176 179
 			case 'application/vnd.oasis.opendocument.spreadsheet':	// oo spreadsheet
177
-				if (!$zip_available) break;
180
+				if (!$zip_available)
181
+				{
182
+					break;
183
+				}
178 184
 				return true;	// open office write xml files
179 185
 			case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':	// ms word 2007 xml format
180 186
 			case 'application/vnd.openxmlformats-officedocument.wordprocessingml.d':	// mimetypes in vfs are limited to 64 chars
181 187
 			case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':	// ms excel 2007 xml format
182 188
 			case 'application/vnd.openxmlformats-officedocument.spreadsheetml.shee':
183
-				if (!$zip_available) break;
189
+				if (!$zip_available)
190
+				{
191
+					break;
192
+				}
184 193
 				return true;	// ms word xml format
185 194
 			case 'application/xml':
186 195
 				return true;	// alias for text/xml, eg. ms office 2003 word format
@@ -215,7 +224,10 @@  discard block
 block discarded – undo
215 224
 		{
216 225
 			$contact = $this->contacts->read($contact, $ignore_acl);
217 226
 		}
218
-		if (!is_array($contact)) return array();
227
+		if (!is_array($contact))
228
+		{
229
+			return array();
230
+		}
219 231
 
220 232
 		$replacements = array();
221 233
 		foreach(array_keys($this->contacts->contact_fields) as $name)
@@ -224,7 +236,10 @@  discard block
 block discarded – undo
224 236
 			switch($name)
225 237
 			{
226 238
 				case 'created': case 'modified':
227
-					if($value) $value = Api\DateTime::to($value);
239
+					if($value)
240
+					{
241
+						$value = Api\DateTime::to($value);
242
+					}
228 243
 					break;
229 244
 				case 'bday':
230 245
 					if ($value)
@@ -269,7 +284,10 @@  discard block
 block discarded – undo
269 284
 					}
270 285
 					break;
271 286
 			}
272
-			if ($name != 'photo') $replacements['$$'.($prefix ? $prefix.'/':'').$name.'$$'] = $value;
287
+			if ($name != 'photo')
288
+			{
289
+				$replacements['$$'.($prefix ? $prefix.'/':'').$name.'$$'] = $value;
290
+			}
273 291
 		}
274 292
 		// set custom fields, should probably go to a general method all apps can use
275 293
 		// need to load all cfs for $ignore_acl=true
@@ -286,17 +304,23 @@  discard block
 block discarded – undo
286 304
 		$cats = array();
287 305
 		foreach(is_array($contact['cat_id']) ? $contact['cat_id'] : explode(',',$contact['cat_id']) as $cat_id)
288 306
 		{
289
-			if(!$cat_id) continue;
307
+			if(!$cat_id)
308
+			{
309
+				continue;
310
+			}
290 311
 			if($GLOBALS['egw']->categories->id2name($cat_id,'main') != $cat_id)
291 312
 			{
292 313
 				$path = explode(' / ', $GLOBALS['egw']->categories->id2name($cat_id, 'path'));
293 314
 				unset($path[0]); // Drop main
294 315
 				$cats[$GLOBALS['egw']->categories->id2name($cat_id,'main')][] = implode(' / ', $path);
295
-			} elseif($cat_id) {
316
+			}
317
+			elseif($cat_id)
318
+			{
296 319
 				$cats[$cat_id] = array();
297 320
 			}
298 321
 		}
299
-		foreach($cats as $main => $cat) {
322
+		foreach($cats as $main => $cat)
323
+		{
300 324
 			$replacements['$$'.($prefix ? $prefix.'/':'').'categories$$'] .= $GLOBALS['egw']->categories->id2name($main,'name')
301 325
 				. (count($cat) > 0 ? ': ' : '') . implode(', ', $cats[$main]) . "\n";
302 326
 		}
@@ -331,7 +355,10 @@  discard block
 block discarded – undo
331 355
 					'id'	=> $link_info
332 356
 				);
333 357
 			}
334
-			if($exclude && in_array($link_info['id'], $exclude)) continue;
358
+			if($exclude && in_array($link_info['id'], $exclude))
359
+			{
360
+				continue;
361
+			}
335 362
 
336 363
 			$title = Api\Link::title($link_info['app'], $link_info['id']);
337 364
 			if(class_exists('EGroupware\Stylite\Vfs\Links\StreamWrapper') && $link_info['app'] != Api\Link::VFS_APPNAME)
@@ -450,7 +477,10 @@  discard block
 block discarded – undo
450 477
 	protected function format_datetime($time,$format=null)
451 478
 	{
452 479
 		trigger_error(__METHOD__ . ' is deprecated, use Api\DateTime::to($time, $format)', E_USER_DEPRECATED);
453
-		if (is_null($format)) $format = $this->datetime_format;
480
+		if (is_null($format))
481
+		{
482
+			$format = $this->datetime_format;
483
+		}
454 484
 
455 485
 		return Api\DateTime::to($time,$format);
456 486
 	}
@@ -492,7 +522,10 @@  discard block
 block discarded – undo
492 522
 	public static function getExportLimit($app='common')
493 523
 	{
494 524
 		static $exportLimitStore=array();
495
-		if (empty($app)) $app='common';
525
+		if (empty($app))
526
+		{
527
+			$app='common';
528
+		}
496 529
 		//error_log(__METHOD__.__LINE__.' called with app:'.$app);
497 530
 		if (!array_key_exists($app,$exportLimitStore))
498 531
 		{
@@ -501,7 +534,10 @@  discard block
 block discarded – undo
501 534
 			if ($app !='common')
502 535
 			{
503 536
 				$app_limit = Api\Hooks::single('export_limit',$app);
504
-				if ($app_limit) $exportLimitStore[$app] = $app_limit;
537
+				if ($app_limit)
538
+				{
539
+					$exportLimitStore[$app] = $app_limit;
540
+				}
505 541
 			}
506 542
 			//error_log(__METHOD__.__LINE__.' building cache for app:'.$app.' -> '.$exportLimitStore[$app]);
507 543
 			if (empty($exportLimitStore[$app]))
@@ -534,10 +570,22 @@  discard block
 block discarded – undo
534 570
 	 */
535 571
 	public static function hasExportLimit($app_limit,$checkas='AND')
536 572
 	{
537
-		if (strtoupper($checkas) == 'ISALLOWED') return (empty($app_limit) || ($app_limit !='no' && $app_limit > 0) );
538
-		if (empty($app_limit)) return false;
539
-		if ($app_limit == 'no') return true;
540
-		if ($app_limit > 0) return true;
573
+		if (strtoupper($checkas) == 'ISALLOWED')
574
+		{
575
+			return (empty($app_limit) || ($app_limit !='no' && $app_limit > 0) );
576
+		}
577
+		if (empty($app_limit))
578
+		{
579
+			return false;
580
+		}
581
+		if ($app_limit == 'no')
582
+		{
583
+			return true;
584
+		}
585
+		if ($app_limit > 0)
586
+		{
587
+			return true;
588
+		}
541 589
 	}
542 590
 
543 591
 	/**
@@ -572,7 +620,8 @@  discard block
 block discarded – undo
572 620
 
573 621
 		try {
574 622
 			$content = $this->merge_string($content,$ids,$err,$mimetype,$fix);
575
-		} catch (\Exception $e) {
623
+		}
624
+		catch (\Exception $e) {
576 625
 			$err = $e->getMessage();
577 626
 			return false;
578 627
 		}
@@ -661,7 +710,8 @@  discard block
 block discarded – undo
661 710
 			$content = $xslt->transformToXml($element);
662 711
 
663 712
 			// Word 2003 needs two declarations, add extra declaration back in
664
-			if($mimetype == 'application/xml' && $mso_application_progid == 'Word.Document' && strpos($content, '<?xml') !== 0) {
713
+			if($mimetype == 'application/xml' && $mso_application_progid == 'Word.Document' && strpos($content, '<?xml') !== 0)
714
+			{
665 715
 				$content = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'.$content;
666 716
 			}
667 717
 			// Validate
@@ -721,7 +771,10 @@  discard block
 block discarded – undo
721 771
 			// textdocuments are simple, they do not hold start and end, but they may have content before and after the $$pagerepeat$$ tag
722 772
 			// header and footer should not hold any $$ tags; if we find $$ tags with the header, we assume it is the pagerepeatcontent
723 773
 			$nohead = false;
724
-			if (stripos($contentstart,'$$') !== false) $nohead = true;
774
+			if (stripos($contentstart,'$$') !== false)
775
+			{
776
+				$nohead = true;
777
+			}
725 778
 			if ($nohead)
726 779
 			{
727 780
 				$contentend = $contentrepeat;
@@ -763,13 +816,19 @@  discard block
 block discarded – undo
763 816
 		preg_match_all('/\$\$labelplacement\$\$/',$contentrepeat,$countlables, PREG_SPLIT_NO_EMPTY);
764 817
 		$countlables = count($countlables[0]);
765 818
 		preg_replace('/\$\$labelplacement\$\$/','',$Labelrepeat,1);
766
-		if ($countlables > 1) $lableprint = true;
819
+		if ($countlables > 1)
820
+		{
821
+			$lableprint = true;
822
+		}
767 823
 		if (count($ids) > 1 && !$contentrepeat)
768 824
 		{
769 825
 			$err = lang('for more than one contact in a document use the tag pagerepeat!');
770 826
 			return false;
771 827
 		}
772
-		if ($this->report_memory_usage) error_log(__METHOD__."(count(ids)=".count($ids).") strlen(contentrepeat)=".strlen($contentrepeat).', strlen(labelrepeat)='.strlen($Labelrepeat));
828
+		if ($this->report_memory_usage)
829
+		{
830
+			error_log(__METHOD__."(count(ids)=".count($ids).") strlen(contentrepeat)=".strlen($contentrepeat).', strlen(labelrepeat)='.strlen($Labelrepeat));
831
+		}
773 832
 
774 833
 		if ($contentrepeat)
775 834
 		{
@@ -802,8 +861,15 @@  discard block
 block discarded – undo
802 861
 		}
803 862
 		foreach ((array)$ids as $n => $id)
804 863
 		{
805
-			if ($contentrepeat) $content = $contentrepeat;   //content to repeat
806
-			if ($lableprint) $content = $Labelrepeat;
864
+			if ($contentrepeat)
865
+			{
866
+				$content = $contentrepeat;
867
+			}
868
+			//content to repeat
869
+			if ($lableprint)
870
+			{
871
+				$content = $Labelrepeat;
872
+			}
807 873
 
808 874
 			// generate replacements; if exeption is thrown, catch it set error message and return false
809 875
 			try
@@ -820,7 +886,10 @@  discard block
 block discarded – undo
820 886
 				$err = $e->getMessage();
821 887
 				return false;
822 888
 			}
823
-			if ($this->report_memory_usage) error_log(__METHOD__."() $n: $id ".Api\Vfs::hsize(memory_get_usage(true)));
889
+			if ($this->report_memory_usage)
890
+			{
891
+				error_log(__METHOD__."() $n: $id ".Api\Vfs::hsize(memory_get_usage(true)));
892
+			}
824 893
 			// some general replacements: current user, date and time
825 894
 			if (strpos($content,'$$user/') !== null && ($user = $GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'],'person_id')))
826 895
 			{
@@ -878,9 +947,12 @@  discard block
 block discarded – undo
878 947
 			{
879 948
 				$contentrepeatpages[$countpage] = preg_replace('/\$\$labelplacement\$\$/',$Label,$contentrepeatpages[$countpage],1);
880 949
 				$count=$count+1;
881
-				if (($count % $countlables) == 0 && count($contentrep)>$count)  //new page
950
+				if (($count % $countlables) == 0 && count($contentrep)>$count)
951
+				{
952
+					//new page
882 953
 				{
883 954
 					$countpage = $countpage+1;
955
+				}
884 956
 					$contentrepeatpages[$countpage] = $Labelstart.$Labeltend;
885 957
 				}
886 958
 			}
@@ -911,7 +983,10 @@  discard block
 block discarded – undo
911 983
 			rewind($content_stream);
912 984
 			return stream_get_contents($content_stream);
913 985
 		}
914
-		if ($this->report_memory_usage) error_log(__METHOD__."() returning ".Api\Vfs::hsize(memory_get_peak_usage(true)));
986
+		if ($this->report_memory_usage)
987
+		{
988
+			error_log(__METHOD__."() returning ".Api\Vfs::hsize(memory_get_peak_usage(true)));
989
+		}
915 990
 
916 991
 		return $content;
917 992
 	}
@@ -954,7 +1029,10 @@  discard block
 block discarded – undo
954 1029
 				break;
955 1030
 
956 1031
 			default:	// div. text files --> use our export-charset, defined in addressbook prefs
957
-				if (empty($charset)) $charset = $this->contacts->prefs['csv_charset'];
1032
+				if (empty($charset))
1033
+				{
1034
+					$charset = $this->contacts->prefs['csv_charset'];
1035
+				}
958 1036
 				break;
959 1037
 		}
960 1038
 		//error_log(__METHOD__."('$document', ... ,$mimetype) --> $charset (egw=".Api\Translation::charset().', export='.$this->contacts->prefs['csv_charset'].')');
@@ -977,10 +1055,13 @@  discard block
 block discarded – undo
977 1055
 				}
978 1056
 			}
979 1057
 		}
980
-		if ($is_xml)	// zip'ed xml document (eg. OO)
1058
+		if ($is_xml)
1059
+		{
1060
+			// zip'ed xml document (eg. OO)
981 1061
 		{
982 1062
 			// Numeric fields
983 1063
 			$names = array();
1064
+		}
984 1065
 
985 1066
 			// Tags we can replace with the target document's version
986 1067
 			$replace_tags = array();
@@ -1042,7 +1123,8 @@  discard block
 block discarded – undo
1042 1123
 				else if (is_string($value) && (strpos($value,'<') !== false))
1043 1124
 				{
1044 1125
 					// Clean HTML, if it's being kept
1045
-					if($replace_tags && extension_loaded('tidy')) {
1126
+					if($replace_tags && extension_loaded('tidy'))
1127
+					{
1046 1128
 						$tidy = new tidy();
1047 1129
 						$cleaned = $tidy->repairString($value, self::$tidy_config);
1048 1130
 						// Found errors. Strip it all so there's some output
@@ -1076,16 +1158,20 @@  discard block
 block discarded – undo
1076 1158
 				// replace all control chars (C0+C1) but CR (\015), LF (\012) and TAB (\011) (eg. vertical tabulators) with space
1077 1159
 				// as they are not allowed in xml
1078 1160
 				$value = preg_replace('/[\000-\010\013\014\016-\037\177-\237]/u',' ',$value);
1079
-				if(is_numeric($value) && $name != '$$user/account_id$$') // account_id causes problems with the preg_replace below
1161
+				if(is_numeric($value) && $name != '$$user/account_id$$')
1162
+				{
1163
+					// account_id causes problems with the preg_replace below
1080 1164
 				{
1081 1165
 					$names[] = preg_quote($name,'/');
1082 1166
 				}
1167
+				}
1083 1168
 			}
1084 1169
 
1085 1170
 			// Look for numbers, set their value if needed
1086 1171
 			if($this->numeric_fields || count($names))
1087 1172
 			{
1088
-				foreach((array)$this->numeric_fields as $fieldname) {
1173
+				foreach((array)$this->numeric_fields as $fieldname)
1174
+				{
1089 1175
 					$names[] = preg_quote($fieldname,'/');
1090 1176
 				}
1091 1177
 				$this->format_spreadsheet_numbers($content, $names, $mimetype.$mso_application_progid);
@@ -1095,7 +1181,8 @@  discard block
 block discarded – undo
1095 1181
 			if($this->date_fields || count($names))
1096 1182
 			{
1097 1183
 				$names = array();
1098
-				foreach((array)$this->date_fields as $fieldname) {
1184
+				foreach((array)$this->date_fields as $fieldname)
1185
+				{
1099 1186
 					$names[] = $fieldname;
1100 1187
 				}
1101 1188
 				$this->format_spreadsheet_dates($content, $names, $replacements, $mimetype.$mso_application_progid);
@@ -1172,7 +1259,8 @@  discard block
 block discarded – undo
1172 1259
 	 */
1173 1260
 	protected function format_spreadsheet_numbers(&$content, $names, $mimetype)
1174 1261
 	{
1175
-		foreach((array)$this->numeric_fields as $fieldname) {
1262
+		foreach((array)$this->numeric_fields as $fieldname)
1263
+		{
1176 1264
 			$names[] = preg_quote($fieldname,'/');
1177 1265
 		}
1178 1266
 		switch($mimetype)
@@ -1201,7 +1289,11 @@  discard block
 block discarded – undo
1201 1289
 			// try to increase/double pcre.backtrack_limit failure
1202 1290
 			while(preg_last_error() == PREG_BACKTRACK_LIMIT_ERROR && self::increase_backtrack_limit());
1203 1291
 
1204
-			if ($result) $content = $result;  // On failure $result would be NULL
1292
+			if ($result)
1293
+			{
1294
+				$content = $result;
1295
+			}
1296
+			// On failure $result would be NULL
1205 1297
 		}
1206 1298
 	}
1207 1299
 
@@ -1245,7 +1337,10 @@  discard block
 block discarded – undo
1245 1337
 			'application/vnd.oasis.opendocument.spreadsheet',		// open office calc
1246 1338
 			'application/xmlExcel.Sheet',					// Excel 2003
1247 1339
 			//'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'//Excel WTF
1248
-		))) return;
1340
+		)))
1341
+		{
1342
+			return;
1343
+		}
1249 1344
 
1250 1345
 		// Some different formats dates could be in, depending what they've been through
1251 1346
 		$formats = array(
@@ -1274,8 +1369,12 @@  discard block
 block discarded – undo
1274 1369
 								$values[$key],
1275 1370
 								Api\DateTime::$user_timezone
1276 1371
 							);
1277
-							if($date) break;
1278
-						} catch (Exception $e) {
1372
+							if($date)
1373
+							{
1374
+								break;
1375
+							}
1376
+						}
1377
+						catch (Exception $e) {
1279 1378
 
1280 1379
 						}
1281 1380
 					}
@@ -1291,9 +1390,12 @@  discard block
 block discarded – undo
1291 1390
 				{
1292 1391
 					$date = new Api\DateTime($values[$key]);
1293 1392
 				}
1294
-				if($mimetype == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')//Excel WTF
1393
+				if($mimetype == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
1394
+				{
1395
+					//Excel WTF
1295 1396
 				{
1296 1397
 					$interval = $date->diff(new Api\DateTime('1900-01-00 0:00'));
1398
+				}
1297 1399
 					$values[$key] = $interval->format('%a')+1;// 1900-02-29 did not exist
1298 1400
 					// 1440 minutes in a day - fractional part
1299 1401
 					$values[$key] += ($date->format('H') * 60 + $date->format('i'))/1440;
@@ -1335,7 +1437,11 @@  discard block
 block discarded – undo
1335 1437
 			// try to increase/double pcre.backtrack_limit failure
1336 1438
 			while(preg_last_error() == PREG_BACKTRACK_LIMIT_ERROR && self::increase_backtrack_limit());
1337 1439
 
1338
-			if ($result) $content = $result;  // On failure $result would be NULL
1440
+			if ($result)
1441
+			{
1442
+				$content = $result;
1443
+			}
1444
+			// On failure $result would be NULL
1339 1445
 		}
1340 1446
 	}
1341 1447
 
@@ -1399,7 +1505,10 @@  discard block
 block discarded – undo
1399 1505
 			}
1400 1506
 			else
1401 1507
 			{
1402
-				if ($cfs[$field]['type'] == 'date' || $cfs[$field]['type'] == 'date-time') $this->date_fields[] = '#'.$field;
1508
+				if ($cfs[$field]['type'] == 'date' || $cfs[$field]['type'] == 'date-time')
1509
+				{
1510
+					$this->date_fields[] = '#'.$field;
1511
+				}
1403 1512
 			}
1404 1513
 		}
1405 1514
 	}
@@ -1415,30 +1524,35 @@  discard block
 block discarded – undo
1415 1524
 	private function process_commands($content, $replacements)
1416 1525
 	{
1417 1526
 		if (strpos($content,'$$IF') !== false)
1418
-		{	//Example use to use: $$IF n_prefix~Herr~Sehr geehrter~Sehr geehrte$$
1527
+		{
1528
+//Example use to use: $$IF n_prefix~Herr~Sehr geehrter~Sehr geehrte$$
1419 1529
 			$this->replacements =& $replacements;
1420 1530
 			$content = preg_replace_callback('/\$\$IF ([#0-9a-z_\/-]+)~(.*)~(.*)~(.*)\$\$/imU',Array($this,'replace_callback'),$content);
1421 1531
 			unset($this->replacements);
1422 1532
 		}
1423 1533
 		if (strpos($content,'$$NELF') !== false)
1424
-		{	//Example: $$NEPBR org_unit$$ sets a LF and value of org_unit, only if there is a value
1534
+		{
1535
+//Example: $$NEPBR org_unit$$ sets a LF and value of org_unit, only if there is a value
1425 1536
 			$this->replacements =& $replacements;
1426 1537
 			$content = preg_replace_callback('/\$\$NELF ([#0-9a-z_\/-]+)\$\$/imU',Array($this,'replace_callback'),$content);
1427 1538
 			unset($this->replacements);
1428 1539
 		}
1429 1540
 		if (strpos($content,'$$NENVLF') !== false)
1430
-		{	//Example: $$NEPBRNV org_unit$$ sets only a LF if there is a value for org_units, but did not add any value
1541
+		{
1542
+//Example: $$NEPBRNV org_unit$$ sets only a LF if there is a value for org_units, but did not add any value
1431 1543
 			$this->replacements =& $replacements;
1432 1544
 			$content = preg_replace_callback('/\$\$NENVLF ([#0-9a-z_\/-]+)\$\$/imU',Array($this,'replace_callback'),$content);
1433 1545
 			unset($this->replacements);
1434 1546
 		}
1435 1547
 		if (strpos($content,'$$LETTERPREFIX$$') !== false)
1436
-		{	//Example use to use: $$LETTERPREFIX$$
1548
+		{
1549
+//Example use to use: $$LETTERPREFIX$$
1437 1550
 			$LETTERPREFIXCUSTOM = '$$LETTERPREFIXCUSTOM n_prefix title n_family$$';
1438 1551
 			$content = str_replace('$$LETTERPREFIX$$',$LETTERPREFIXCUSTOM,$content);
1439 1552
 		}
1440 1553
 		if (strpos($content,'$$LETTERPREFIXCUSTOM') !== false)
1441
-		{	//Example use to use for a custom Letter Prefix: $$LETTERPREFIX n_prefix title n_family$$
1554
+		{
1555
+//Example use to use for a custom Letter Prefix: $$LETTERPREFIX n_prefix title n_family$$
1442 1556
 			$this->replacements =& $replacements;
1443 1557
 			$content = preg_replace_callback('/\$\$LETTERPREFIXCUSTOM ([#0-9a-z_-]+)(.*)\$\$/imU',Array($this,'replace_callback'),$content);
1444 1558
 			unset($this->replacements);
@@ -1454,8 +1568,14 @@  discard block
 block discarded – undo
1454 1568
 	 */
1455 1569
 	private function replace_callback($param)
1456 1570
 	{
1457
-		if (array_key_exists('$$'.$param[4].'$$',$this->replacements)) $param[4] = $this->replacements['$$'.$param[4].'$$'];
1458
-		if (array_key_exists('$$'.$param[3].'$$',$this->replacements)) $param[3] = $this->replacements['$$'.$param[3].'$$'];
1571
+		if (array_key_exists('$$'.$param[4].'$$',$this->replacements))
1572
+		{
1573
+			$param[4] = $this->replacements['$$'.$param[4].'$$'];
1574
+		}
1575
+		if (array_key_exists('$$'.$param[3].'$$',$this->replacements))
1576
+		{
1577
+			$param[3] = $this->replacements['$$'.$param[3].'$$'];
1578
+		}
1459 1579
 
1460 1580
 		$pattern = '/'.preg_quote($param[2], '/').'/';
1461 1581
 		if (strpos($param[0],'$$IF') === 0 && (trim($param[2]) == "EMPTY" || $param[2] === ''))
@@ -1477,7 +1597,7 @@  discard block
 block discarded – undo
1477 1597
 		}
1478 1598
 
1479 1599
 		switch($this->mimetype)
1480
-			{
1600
+		{
1481 1601
 				case 'application/rtf':
1482 1602
 				case 'text/rtf':
1483 1603
 					$LF = '}\par \pard\plain{';
@@ -1501,25 +1621,38 @@  discard block
 block discarded – undo
1501 1621
 				default:
1502 1622
 					$LF = "\n";
1503 1623
 			}
1504
-		if($is_xml) {
1624
+		if($is_xml)
1625
+		{
1505 1626
 			$this->replacements = str_replace(array('&','&amp;amp;','<','>',"\r","\n"),array('&amp;','&amp;','&lt;','&gt;','',$LF),$this->replacements);
1506 1627
 		}
1507 1628
 		if (strpos($param[0],'$$NELF') === 0)
1508
-		{	//sets a Pagebreak and value, only if the field has a value
1509
-			if ($this->replacements['$$'.$param[1].'$$'] !='') $replace = $LF.$this->replacements['$$'.$param[1].'$$'];
1629
+		{
1630
+//sets a Pagebreak and value, only if the field has a value
1631
+			if ($this->replacements['$$'.$param[1].'$$'] !='')
1632
+			{
1633
+				$replace = $LF.$this->replacements['$$'.$param[1].'$$'];
1634
+			}
1510 1635
 		}
1511 1636
 		if (strpos($param[0],'$$NENVLF') === 0)
1512
-		{	//sets a Pagebreak without any value, only if the field has a value
1513
-			if ($this->replacements['$$'.$param[1].'$$'] !='') $replace = $LF;
1637
+		{
1638
+//sets a Pagebreak without any value, only if the field has a value
1639
+			if ($this->replacements['$$'.$param[1].'$$'] !='')
1640
+			{
1641
+				$replace = $LF;
1642
+			}
1514 1643
 		}
1515 1644
 		if (strpos($param[0],'$$LETTERPREFIXCUSTOM') === 0)
1516
-		{	//sets a Letterprefix
1645
+		{
1646
+//sets a Letterprefix
1517 1647
 			$replaceprefixsort = array();
1518 1648
 			// ToDo Stefan: $contentstart is NOT defined here!!!
1519 1649
 			$replaceprefix = explode(' ',substr($param[0],21,-2));
1520 1650
 			foreach ($replaceprefix as $nameprefix)
1521 1651
 			{
1522
-				if ($this->replacements['$$'.$nameprefix.'$$'] !='') $replaceprefixsort[] = $this->replacements['$$'.$nameprefix.'$$'];
1652
+				if ($this->replacements['$$'.$nameprefix.'$$'] !='')
1653
+				{
1654
+					$replaceprefixsort[] = $this->replacements['$$'.$nameprefix.'$$'];
1655
+				}
1523 1656
 			}
1524 1657
 			$replace = implode($replaceprefixsort,' ');
1525 1658
 		}
@@ -1560,13 +1693,20 @@  discard block
 block discarded – undo
1560 1693
 				}
1561 1694
 				//error_log(__METHOD__.__LINE__.' Message after importMessageToMergeAndSend:'.array2string($msgs));
1562 1695
 				$retString = '';
1563
-				if (count($msgs['success'])>0) $retString .= count($msgs['success']).' '.(count($msgs['success'])+count($msgs['failed'])==1?lang('Message prepared for sending.'):lang('Message(s) send ok.'));//implode('<br />',$msgs['success']);
1696
+				if (count($msgs['success'])>0)
1697
+				{
1698
+					$retString .= count($msgs['success']).' '.(count($msgs['success'])+count($msgs['failed'])==1?lang('Message prepared for sending.'):lang('Message(s) send ok.'));
1699
+				}
1700
+				//implode('<br />',$msgs['success']);
1564 1701
 				//if (strlen($retString)>0) $retString .= '<br />';
1565 1702
 				foreach($msgs['failed'] as $c =>$e)
1566 1703
 				{
1567 1704
 					$errorString .= lang('contact').' '.lang('id').':'.$c.'->'.$e.'.';
1568 1705
 				}
1569
-				if (count($msgs['failed'])>0) $retString .= count($msgs['failed']).' '.lang('Message(s) send failed!').'=>'.$errorString;
1706
+				if (count($msgs['failed'])>0)
1707
+				{
1708
+					$retString .= count($msgs['failed']).' '.lang('Message(s) send failed!').'=>'.$errorString;
1709
+				}
1570 1710
 				return $retString;
1571 1711
 			case 'application/vnd.oasis.opendocument.text':
1572 1712
 			case 'application/vnd.oasis.opendocument.spreadsheet':
@@ -1638,7 +1778,10 @@  discard block
 block discarded – undo
1638 1778
 					return $err;
1639 1779
 				}
1640 1780
 			}
1641
-			if ($this->report_memory_usage) error_log(__METHOD__."() after HTML processing ".Api\Vfs::hsize(memory_get_peak_usage(true)));
1781
+			if ($this->report_memory_usage)
1782
+			{
1783
+				error_log(__METHOD__."() after HTML processing ".Api\Vfs::hsize(memory_get_peak_usage(true)));
1784
+			}
1642 1785
 		}
1643 1786
 		if(!empty($name))
1644 1787
 		{
@@ -1658,18 +1801,33 @@  discard block
 block discarded – undo
1658 1801
 			if ($zip->open($archive, ZipArchive::CHECKCONS) !== true)
1659 1802
 			{
1660 1803
 				error_log(__METHOD__.__LINE__." !ZipArchive::open('$archive',ZIPARCHIVE"."::CHECKCONS) failed. Trying open without validating");
1661
-				if ($zip->open($archive) !== true) throw new Api\Exception("!ZipArchive::open('$archive',|ZIPARCHIVE::CHECKCONS)");
1804
+				if ($zip->open($archive) !== true)
1805
+				{
1806
+					throw new Api\Exception("!ZipArchive::open('$archive',|ZIPARCHIVE::CHECKCONS)");
1807
+				}
1808
+			}
1809
+			if ($zip->addFromString($content_file,$merged) !== true)
1810
+			{
1811
+				throw new Api\Exception("!ZipArchive::addFromString('$content_file',\$merged)");
1812
+			}
1813
+			if ($zip->close() !== true)
1814
+			{
1815
+				throw new Api\Exception("!ZipArchive::close()");
1662 1816
 			}
1663
-			if ($zip->addFromString($content_file,$merged) !== true) throw new Api\Exception("!ZipArchive::addFromString('$content_file',\$merged)");
1664
-			if ($zip->close() !== true) throw new Api\Exception("!ZipArchive::close()");
1665 1817
 			unset($zip);
1666 1818
 			unset($merged);
1667 1819
 			if (substr($mimetype,0,35) == 'application/vnd.oasis.opendocument.' && 			// only open office archives need that, ms word files brake
1668
-				file_exists('/usr/bin/zip') && version_compare(PHP_VERSION,'5.3.1','<'))	// fix broken zip archives generated by current php
1820
+				file_exists('/usr/bin/zip') && version_compare(PHP_VERSION,'5.3.1','<'))
1821
+			{
1822
+				// fix broken zip archives generated by current php
1669 1823
 			{
1670 1824
 				exec('/usr/bin/zip -F '.escapeshellarg($archive));
1671 1825
 			}
1672
-			if ($this->report_memory_usage) error_log(__METHOD__."() after ZIP processing ".Api\Vfs::hsize(memory_get_peak_usage(true)));
1826
+			}
1827
+			if ($this->report_memory_usage)
1828
+			{
1829
+				error_log(__METHOD__."() after ZIP processing ".Api\Vfs::hsize(memory_get_peak_usage(true)));
1830
+			}
1673 1831
 			Api\Header\Content::type($name,$mimetype,filesize($archive));
1674 1832
 			readfile($archive,'r');
1675 1833
 		}
@@ -1704,9 +1862,18 @@  discard block
 block discarded – undo
1704 1862
 	 */
1705 1863
 	public function download_by_request()
1706 1864
 	{
1707
-		if(empty($_POST['data_document_name'])) return false;
1708
-		if(empty($_POST['data_document_dir'])) return false;
1709
-		if(empty($_POST['data_checked'])) return false;
1865
+		if(empty($_POST['data_document_name']))
1866
+		{
1867
+			return false;
1868
+		}
1869
+		if(empty($_POST['data_document_dir']))
1870
+		{
1871
+			return false;
1872
+		}
1873
+		if(empty($_POST['data_checked']))
1874
+		{
1875
+			return false;
1876
+		}
1710 1877
 
1711 1878
 		return $this->download(
1712 1879
 			$_POST['data_document_name'],
@@ -1727,7 +1894,10 @@  discard block
 block discarded – undo
1727 1894
 	public static function get_documents($dirs, $prefix='document_', $mime_filter=null, $app='')
1728 1895
 	{
1729 1896
 		$export_limit=self::getExportLimit($app);
1730
-		if (!$dirs || (!self::hasExportLimit($export_limit,'ISALLOWED') && !self::is_export_limit_excepted())) return array();
1897
+		if (!$dirs || (!self::hasExportLimit($export_limit,'ISALLOWED') && !self::is_export_limit_excepted()))
1898
+		{
1899
+			return array();
1900
+		}
1731 1901
 
1732 1902
 		// split multiple comma or whitespace separated directories
1733 1903
 		// to still allow space or comma in dirnames, we also use the trailing slash of all pathes to split
@@ -1735,7 +1905,11 @@  discard block
 block discarded – undo
1735 1905
 		{
1736 1906
 			foreach($dirs as $n => &$d)
1737 1907
 			{
1738
-				if ($n) $d = '/'.$d;	// re-adding trailing slash removed by split
1908
+				if ($n)
1909
+				{
1910
+					$d = '/'.$d;
1911
+				}
1912
+				// re-adding trailing slash removed by split
1739 1913
 			}
1740 1914
 		}
1741 1915
 		if ($mime_filter && ($negativ_filter = $mime_filter[0] === '!'))
@@ -1758,8 +1932,14 @@  discard block
 block discarded – undo
1758 1932
 				{
1759 1933
 					// return only the mime-types we support
1760 1934
 					$parts = explode('.',$file['name']);
1761
-					if (!self::is_implemented($file['mime'],'.'.array_pop($parts))) continue;
1762
-					if ($mime_filter && $negativ_filter === in_array($file['mime'], (array)$mime_filter)) continue;
1935
+					if (!self::is_implemented($file['mime'],'.'.array_pop($parts)))
1936
+					{
1937
+						continue;
1938
+					}
1939
+					if ($mime_filter && $negativ_filter === in_array($file['mime'], (array)$mime_filter))
1940
+					{
1941
+						continue;
1942
+					}
1763 1943
 					$list[$prefix.$file['name']] = Api\Vfs::decodePath($file['name']);
1764 1944
 				}
1765 1945
 			}
@@ -1789,12 +1969,19 @@  discard block
 block discarded – undo
1789 1969
 		$export_limit=null)
1790 1970
 	{
1791 1971
 		$documents = array();
1792
-		if ($export_limit == null) $export_limit = self::getExportLimit(); // check if there is a globalsetting
1793
-		if ($default_doc && ($file = Api\Vfs::stat($default_doc)))	// put default document on top
1972
+		if ($export_limit == null)
1973
+		{
1974
+			$export_limit = self::getExportLimit();
1975
+		}
1976
+		// check if there is a globalsetting
1977
+		if ($default_doc && ($file = Api\Vfs::stat($default_doc)))
1978
+		{
1979
+			// put default document on top
1794 1980
 		{
1795 1981
 			if(!$file['mime'])
1796 1982
 			{
1797 1983
 				$file['mime'] = Api\Vfs::mime_content_type($default_doc);
1984
+		}
1798 1985
 				$file['path'] = $default_doc;
1799 1986
 			}
1800 1987
 			$documents['document'] = array(
@@ -1818,7 +2005,11 @@  discard block
 block discarded – undo
1818 2005
 			{
1819 2006
 				foreach($dirs as $n => &$d)
1820 2007
 				{
1821
-					if ($n) $d = '/'.$d;	// re-adding trailing slash removed by split
2008
+					if ($n)
2009
+					{
2010
+						$d = '/'.$d;
2011
+					}
2012
+					// re-adding trailing slash removed by split
1822 2013
 				}
1823 2014
 			}
1824 2015
 			foreach($dirs as $dir)
@@ -1838,10 +2029,13 @@  discard block
 block discarded – undo
1838 2029
 			$parts = explode('.',$file['name']);
1839 2030
 			if (!self::is_implemented($file['mime'],'.'.array_pop($parts)) ||
1840 2031
 				!Api\Vfs::check_access($file['path'], Api\Vfs::READABLE, $file) ||	// remove files not readable by user
1841
-				$file['path'] === $default_doc)	// default doc already added
2032
+				$file['path'] === $default_doc)
2033
+			{
2034
+				// default doc already added
1842 2035
 			{
1843 2036
 				unset($files[$key]);
1844 2037
 			}
2038
+			}
1845 2039
 			else
1846 2040
 			{
1847 2041
 				$dirname = Api\Vfs::dirname($file['path']);
@@ -2000,7 +2194,11 @@  discard block
 block discarded – undo
2000 2194
 			{
2001 2195
 				foreach($dirs as $n => $dir)
2002 2196
 				{
2003
-					if ($n) $dir = '/'.$dir;	// re-adding trailing slash removed by split
2197
+					if ($n)
2198
+					{
2199
+						$dir = '/'.$dir;
2200
+					}
2201
+					// re-adding trailing slash removed by split
2004 2202
 					if (Api\Vfs::stat($dir.'/'.$document) && Api\Vfs::is_readable($dir.'/'.$document))
2005 2203
 					{
2006 2204
 						$document = $dir.'/'.$document;
@@ -2037,7 +2235,10 @@  discard block
 block discarded – undo
2037 2235
 	 */
2038 2236
 	static public function number_format($number,$num_decimal_places=2,$_mimetype='')
2039 2237
 	{
2040
-		if ((string)$number === '') return '';
2238
+		if ((string)$number === '')
2239
+		{
2240
+			return '';
2241
+		}
2041 2242
 		//error_log(__METHOD__.$_mimetype);
2042 2243
 		switch($_mimetype)
2043 2244
 		{
Please login to merge, or discard this patch.
Upper-Lower-Casing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1417,19 +1417,19 @@  discard block
 block discarded – undo
1417 1417
 		if (strpos($content,'$$IF') !== false)
1418 1418
 		{	//Example use to use: $$IF n_prefix~Herr~Sehr geehrter~Sehr geehrte$$
1419 1419
 			$this->replacements =& $replacements;
1420
-			$content = preg_replace_callback('/\$\$IF ([#0-9a-z_\/-]+)~(.*)~(.*)~(.*)\$\$/imU',Array($this,'replace_callback'),$content);
1420
+			$content = preg_replace_callback('/\$\$IF ([#0-9a-z_\/-]+)~(.*)~(.*)~(.*)\$\$/imU',array($this,'replace_callback'),$content);
1421 1421
 			unset($this->replacements);
1422 1422
 		}
1423 1423
 		if (strpos($content,'$$NELF') !== false)
1424 1424
 		{	//Example: $$NEPBR org_unit$$ sets a LF and value of org_unit, only if there is a value
1425 1425
 			$this->replacements =& $replacements;
1426
-			$content = preg_replace_callback('/\$\$NELF ([#0-9a-z_\/-]+)\$\$/imU',Array($this,'replace_callback'),$content);
1426
+			$content = preg_replace_callback('/\$\$NELF ([#0-9a-z_\/-]+)\$\$/imU',array($this,'replace_callback'),$content);
1427 1427
 			unset($this->replacements);
1428 1428
 		}
1429 1429
 		if (strpos($content,'$$NENVLF') !== false)
1430 1430
 		{	//Example: $$NEPBRNV org_unit$$ sets only a LF if there is a value for org_units, but did not add any value
1431 1431
 			$this->replacements =& $replacements;
1432
-			$content = preg_replace_callback('/\$\$NENVLF ([#0-9a-z_\/-]+)\$\$/imU',Array($this,'replace_callback'),$content);
1432
+			$content = preg_replace_callback('/\$\$NENVLF ([#0-9a-z_\/-]+)\$\$/imU',array($this,'replace_callback'),$content);
1433 1433
 			unset($this->replacements);
1434 1434
 		}
1435 1435
 		if (strpos($content,'$$LETTERPREFIX$$') !== false)
@@ -1440,7 +1440,7 @@  discard block
 block discarded – undo
1440 1440
 		if (strpos($content,'$$LETTERPREFIXCUSTOM') !== false)
1441 1441
 		{	//Example use to use for a custom Letter Prefix: $$LETTERPREFIX n_prefix title n_family$$
1442 1442
 			$this->replacements =& $replacements;
1443
-			$content = preg_replace_callback('/\$\$LETTERPREFIXCUSTOM ([#0-9a-z_-]+)(.*)\$\$/imU',Array($this,'replace_callback'),$content);
1443
+			$content = preg_replace_callback('/\$\$LETTERPREFIXCUSTOM ([#0-9a-z_-]+)(.*)\$\$/imU',array($this,'replace_callback'),$content);
1444 1444
 			unset($this->replacements);
1445 1445
 		}
1446 1446
 		return $content;
@@ -1958,7 +1958,7 @@  discard block
 block discarded – undo
1958 1958
 	 * @param Array $file Array of information about the document from Api\Vfs::find
1959 1959
 	 * @return void
1960 1960
 	 */
1961
-	private static function document_mail_action(Array &$action, $file)
1961
+	private static function document_mail_action(array &$action, $file)
1962 1962
 	{
1963 1963
 		unset($action['postSubmit']);
1964 1964
 
Please login to merge, or discard this patch.
api/src/Storage/Tracking.php 3 patches
Doc Comments   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -528,7 +528,7 @@  discard block
 block discarded – undo
528 528
 	 * @param array $data current entry
529 529
 	 * @param array $old = null old/last state of the entry or null for a new entry
530 530
 	 * @param boolean $deleted = null can be set to true to let the tracking know the item got deleted or undelted
531
-	 * @param array $email_notified=null if present will return the emails notified, if given emails in that list will not be notified
531
+	 * @param array $email_notified if present will return the emails notified, if given emails in that list will not be notified
532 532
 	 * @return boolean true on success, false on error (error messages are in $this->errors)
533 533
 	 */
534 534
 	public function do_notifications($data,$old,$deleted=null,&$email_notified=null)
@@ -824,7 +824,6 @@  discard block
 block discarded – undo
824 824
 	 * The default implementation prefers depending on the prefer_user_as_sender class-var the user over
825 825
 	 * what is returned by get_config('sender').
826 826
 	 *
827
-	 * @param int $user account_lid of user
828 827
 	 * @param array $data
829 828
 	 * @param array $old
830 829
 	 * @param bool $prefer_id returns the userid rather than email
Please login to merge, or discard this patch.
Spacing   +163 added lines, -163 removed lines patch added patch discarded remove patch
@@ -194,12 +194,12 @@  discard block
 block discarded – undo
194 194
 	{
195 195
 		if ($cf_app)
196 196
 		{
197
-			$linkable_cf_types = array('link-entry')+array_keys(Api\Link::app_list());
198
-			foreach(Customfields::get($cf_app, true) as $cf_name => $cf_data)
197
+			$linkable_cf_types = array('link-entry') + array_keys(Api\Link::app_list());
198
+			foreach (Customfields::get($cf_app, true) as $cf_name => $cf_data)
199 199
 			{
200 200
 				$this->field2history['#'.$cf_name] = '#'.$cf_name;
201 201
 
202
-				if (in_array($cf_data['type'],$linkable_cf_types))
202
+				if (in_array($cf_data['type'], $linkable_cf_types))
203 203
 				{
204 204
 					$this->cf_link_fields['#'.$cf_name] = $cf_data['type'] == 'link-entry' ? '' : $cf_data['type'];
205 205
 				}
@@ -216,9 +216,9 @@  discard block
 block discarded – undo
216 216
 	 * @param int|string $receiver nummeric account_id or email address
217 217
 	 * @return array of details as array with values for keys 'label','value','type'
218 218
 	 */
219
-	function get_details($data,$receiver=null)
219
+	function get_details($data, $receiver = null)
220 220
 	{
221
-		unset($data, $receiver);	// not uses as just a stub
221
+		unset($data, $receiver); // not uses as just a stub
222 222
 
223 223
 		return array();
224 224
 	}
@@ -230,14 +230,14 @@  discard block
 block discarded – undo
230 230
 	 * @param string $only_type2 = null if given only return fields of type2 == $only_type2
231 231
 	 * @return array of details as array with values for keys 'label','value','type'
232 232
 	 */
233
-	function get_customfields($data, $only_type2=null)
233
+	function get_customfields($data, $only_type2 = null)
234 234
 	{
235 235
 		$details = array();
236 236
 
237
-		if (($cfs = Customfields::get($this->app, $all_private_too=false, $only_type2)))
237
+		if (($cfs = Customfields::get($this->app, $all_private_too = false, $only_type2)))
238 238
 		{
239 239
 			$header_done = false;
240
-			foreach($cfs as $name => $field)
240
+			foreach ($cfs as $name => $field)
241 241
 			{
242 242
 				if (in_array($field['type'], Customfields::$non_printable_fields)) continue;
243 243
 
@@ -278,9 +278,9 @@  discard block
 block discarded – undo
278 278
 	 * @param array $old = null old/last state of the entry or null for a new entry
279 279
 	 * @return mixed
280 280
 	 */
281
-	protected function get_config($name,$data,$old=null)
281
+	protected function get_config($name, $data, $old = null)
282 282
 	{
283
-		unset($name, $data, $old);	// not used as just a stub
283
+		unset($name, $data, $old); // not used as just a stub
284 284
 
285 285
 		return null;
286 286
 	}
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
 	 * @param boolean $skip_notification = false do NOT send any notification
297 297
 	 * @return int|boolean false on error, integer number of changes logged or true for new entries ($old == null)
298 298
 	 */
299
-	public function track(array $data,array $old=null,$user=null,$deleted=null,array $changed_fields=null,$skip_notification=false)
299
+	public function track(array $data, array $old = null, $user = null, $deleted = null, array $changed_fields = null, $skip_notification = false)
300 300
 	{
301 301
 		$this->user = !is_null($user) ? $user : $GLOBALS['egw_info']['user']['account_id'];
302 302
 
@@ -305,7 +305,7 @@  discard block
 block discarded – undo
305 305
 		if ($old && $this->field2history)
306 306
 		{
307 307
 			//error_log(__METHOD__.__LINE__.' Changedfields:'.print_r($changed_fields,true));
308
-			$changes = $this->save_history($data,$old,$deleted,$changed_fields);
308
+			$changes = $this->save_history($data, $old, $deleted, $changed_fields);
309 309
 			//error_log(__METHOD__.__LINE__.' Changedfields:'.print_r($changed_fields,true));
310 310
 			//error_log(__METHOD__.__LINE__.' Changes:'.print_r($changes,true));
311 311
 		}
@@ -313,10 +313,10 @@  discard block
 block discarded – undo
313 313
 		//error_log(__METHOD__.__LINE__.' LinkFields:'.array2string($this->cf_link_fields));
314 314
 		if ($changes && $this->cf_link_fields)
315 315
 		{
316
-			$this->update_links($data,(array)$old);
316
+			$this->update_links($data, (array)$old);
317 317
 		}
318 318
 		// do not run do_notifications if we have no changes
319
-		if ($changes && !$skip_notification && !$this->do_notifications($data,$old,$deleted))
319
+		if ($changes && !$skip_notification && !$this->do_notifications($data, $old, $deleted))
320 320
 		{
321 321
 			$changes = false;
322 322
 		}
@@ -333,45 +333,45 @@  discard block
 block discarded – undo
333 333
 	{
334 334
 		//error_log(__METHOD__.__LINE__.array2string($data).function_backtrace());
335 335
 		//error_log(__METHOD__.__LINE__.array2string($this->cf_link_fields));
336
-		foreach(array_keys((array)$this->cf_link_fields) as $name)
336
+		foreach (array_keys((array)$this->cf_link_fields) as $name)
337 337
 		{
338 338
 			//error_log(__METHOD__.__LINE__.' Field:'.$name. ' Value (new):'.array2string($data[$name]));
339 339
 			//error_log(__METHOD__.__LINE__.' Field:'.$name. ' Value (old):'.array2string($old[$name]));
340
-			if (is_array($data[$name]) && array_key_exists('id',$data[$name])) $data[$name] = $data[$name]['id'];
341
-			if (is_array($old[$name]) && array_key_exists('id',$old[$name])) $old[$name] = $old[$name]['id'];
340
+			if (is_array($data[$name]) && array_key_exists('id', $data[$name])) $data[$name] = $data[$name]['id'];
341
+			if (is_array($old[$name]) && array_key_exists('id', $old[$name])) $old[$name] = $old[$name]['id'];
342 342
 			//error_log(__METHOD__.__LINE__.'(After processing) Field:'.$name. ' Value (new):'.array2string($data[$name]));
343 343
 			//error_log(__METHOD__.__LINE__.'(After processing) Field:'.$name. ' Value (old):'.array2string($old[$name]));
344 344
 		}
345
-		$current_ids = array_unique(array_diff(array_intersect_key($data,$this->cf_link_fields),array('',0,NULL)));
346
-		$old_ids = $old ? array_unique(array_diff(array_intersect_key($old,$this->cf_link_fields),array('',0,NULL))) : array();
345
+		$current_ids = array_unique(array_diff(array_intersect_key($data, $this->cf_link_fields), array('', 0, NULL)));
346
+		$old_ids = $old ? array_unique(array_diff(array_intersect_key($old, $this->cf_link_fields), array('', 0, NULL))) : array();
347 347
 		//error_log(__METHOD__.__LINE__.array2string($current_ids));
348 348
 		//error_log(__METHOD__.__LINE__.array2string($old_ids));
349 349
 		// create links for added application entry
350
-		foreach(array_diff($current_ids,$old_ids) as $name => $id)
350
+		foreach (array_diff($current_ids, $old_ids) as $name => $id)
351 351
 		{
352 352
 			if (!($app = $this->cf_link_fields[$name]))
353 353
 			{
354
-				list($app,$id) = explode(':',$id);
355
-				if (!$id) continue;	// can be eg. 'addressbook:', if no contact selected
354
+				list($app, $id) = explode(':', $id);
355
+				if (!$id) continue; // can be eg. 'addressbook:', if no contact selected
356 356
 			}
357 357
 			$source_id = $data[$this->id_field];
358 358
 			//error_log(__METHOD__.__LINE__.array2string($source_id));
359
-			if ($source_id) Api\Link::link($this->app,$source_id,$app,$id);
359
+			if ($source_id) Api\Link::link($this->app, $source_id, $app, $id);
360 360
 			//error_log(__METHOD__.__LINE__."Api\Link::link('$this->app',".array2string($source_id).",'$app',$id);");
361 361
 			//echo "<p>Api\Link::link('$this->app',{$data[$this->id_field]},'$app',$id);</p>\n";
362 362
 		}
363 363
 
364 364
 		// unlink removed application entries
365
-		foreach(array_diff($old_ids,$current_ids) as $name => $id)
365
+		foreach (array_diff($old_ids, $current_ids) as $name => $id)
366 366
 		{
367
-			if (!isset($data[$name])) continue;	// ignore not set link cf's, eg. from sync clients
367
+			if (!isset($data[$name])) continue; // ignore not set link cf's, eg. from sync clients
368 368
 			if (!($app = $this->cf_link_fields[$name]))
369 369
 			{
370
-				list($app,$id) = explode(':',$id);
370
+				list($app, $id) = explode(':', $id);
371 371
 				if (!$id) continue;
372 372
 			}
373 373
 			$source_id = $data[$this->id_field];
374
-			if ($source_id) Api\Link::unlink(null,$this->app,$source_id,0,$app,$id);
374
+			if ($source_id) Api\Link::unlink(null, $this->app, $source_id, 0, $app, $id);
375 375
 			//echo "<p>Api\Link::unlink(NULL,'$this->app',{$data[$this->id_field]},0,'$app',$id);</p>\n";
376 376
 		}
377 377
 	}
@@ -386,14 +386,14 @@  discard block
 block discarded – undo
386 386
 	 * @param array $changed_fields = null changed fields from ealier call to $this->changed_fields($data,$old), to not compute it again
387 387
 	 * @return int number of log-entries made
388 388
 	 */
389
-	protected function save_history(array $data,array $old=null,$deleted=null,array $changed_fields=null)
389
+	protected function save_history(array $data, array $old = null, $deleted = null, array $changed_fields = null)
390 390
 	{
391
-		unset($deleted);	// not used, but required by function signature
391
+		unset($deleted); // not used, but required by function signature
392 392
 
393 393
 		//error_log(__METHOD__.__LINE__.' Changedfields:'.array2string($changed_fields));
394 394
 		if (is_null($changed_fields))
395 395
 		{
396
-			$changed_fields = self::changed_fields($data,$old);
396
+			$changed_fields = self::changed_fields($data, $old);
397 397
 			//error_log(__METHOD__.__LINE__.' Changedfields:'.array2string($changed_fields));
398 398
 		}
399 399
 		if (!$changed_fields && ($old || !$GLOBALS['egw_info']['server']['log_user_agent_action'])) return 0;
@@ -408,30 +408,30 @@  discard block
 block discarded – undo
408 408
 			$this->historylog->add('user_agent_action', $data[$this->id_field],
409 409
 				$_SERVER['HTTP_USER_AGENT'], $_SESSION[Api\Session::EGW_SESSION_VAR]['session_action']);
410 410
 		}
411
-		foreach($changed_fields as $name)
411
+		foreach ($changed_fields as $name)
412 412
 		{
413 413
 			$status = isset($this->field2history[$name]) ? $this->field2history[$name] : $name;
414 414
 			//error_log(__METHOD__.__LINE__." Name $name,".' Status:'.array2string($status));
415 415
 			if (is_array($status))	// 1:N relation --> remove common rows
416 416
 			{
417 417
 				//error_log(__METHOD__.__LINE__.' is Array');
418
-				self::compact_1_N_relation($data[$name],$status);
419
-				self::compact_1_N_relation($old[$name],$status);
420
-				$added = array_values(array_diff($data[$name],$old[$name]));
421
-				$removed = array_values(array_diff($old[$name],$data[$name]));
422
-				$n = max(array(count($added),count($removed)));
423
-				for($i = 0; $i < $n; ++$i)
418
+				self::compact_1_N_relation($data[$name], $status);
419
+				self::compact_1_N_relation($old[$name], $status);
420
+				$added = array_values(array_diff($data[$name], $old[$name]));
421
+				$removed = array_values(array_diff($old[$name], $data[$name]));
422
+				$n = max(array(count($added), count($removed)));
423
+				for ($i = 0; $i < $n; ++$i)
424 424
 				{
425 425
 					//error_log(__METHOD__."() $i: historylog->add('$name',data['$this->id_field']={$data[$this->id_field]},".array2string($added[$i]).','.array2string($removed[$i]));
426
-					$this->historylog->add($name,$data[$this->id_field],$added[$i],$removed[$i]);
426
+					$this->historylog->add($name, $data[$this->id_field], $added[$i], $removed[$i]);
427 427
 				}
428 428
 			}
429 429
 			else
430 430
 			{
431 431
 				//error_log(__METHOD__.__LINE__.' IDField:'.array2string($this->id_field).' ->'.$data[$this->id_field].' New:'.$data[$name].' Old:'.$old[$name]);
432
-				$this->historylog->add($status,$data[$this->id_field],
433
-					is_array($data[$name]) ? implode(',',$data[$name]) : $data[$name],
434
-					is_array($old[$name]) ? implode(',',$old[$name]) : $old[$name]);
432
+				$this->historylog->add($status, $data[$this->id_field],
433
+					is_array($data[$name]) ? implode(',', $data[$name]) : $data[$name],
434
+					is_array($old[$name]) ? implode(',', $old[$name]) : $old[$name]);
435 435
 			}
436 436
 		}
437 437
 		//error_log(__METHOD__.__LINE__.' return:'.count($changed_fields));
@@ -447,28 +447,28 @@  discard block
 block discarded – undo
447 447
 	 * @param array $old = null
448 448
 	 * @return array of keys with different values in $data and $old
449 449
 	 */
450
-	public function changed_fields(array $data,array $old=null)
450
+	public function changed_fields(array $data, array $old = null)
451 451
 	{
452 452
 		if (is_null($old)) return array_keys($data);
453 453
 		$changed_fields = array();
454
-		foreach($this->field2history as $name => $status)
454
+		foreach ($this->field2history as $name => $status)
455 455
 		{
456
-			if (!$old[$name] && !$data[$name]) continue;	// treat all sorts of empty equally
456
+			if (!$old[$name] && !$data[$name]) continue; // treat all sorts of empty equally
457 457
 
458
-			if ($name[0] == '#' && !isset($data[$name])) continue;	// no set customfields are not stored, therefore not changed
458
+			if ($name[0] == '#' && !isset($data[$name])) continue; // no set customfields are not stored, therefore not changed
459 459
 
460 460
 			if (is_array($status))	// 1:N relation
461 461
 			{
462
-				self::compact_1_N_relation($data[$name],$status);
463
-				self::compact_1_N_relation($old[$name],$status);
462
+				self::compact_1_N_relation($data[$name], $status);
463
+				self::compact_1_N_relation($old[$name], $status);
464 464
 			}
465 465
 			if ($old[$name] != $data[$name])
466 466
 			{
467 467
 				// normalize arrays, we do NOT care for the order of multiselections
468 468
 				if (is_array($data[$name]) || is_array($old[$name]))
469 469
 				{
470
-					if (!is_array($data[$name])) $data[$name] = explode(',',$data[$name]);
471
-					if (!is_array($old[$name])) $old[$name] = explode(',',$old[$name]);
470
+					if (!is_array($data[$name])) $data[$name] = explode(',', $data[$name]);
471
+					if (!is_array($old[$name])) $old[$name] = explode(',', $old[$name]);
472 472
 					if (count($data[$name]) == count($old[$name]))
473 473
 					{
474 474
 						sort($data[$name]);
@@ -478,13 +478,13 @@  discard block
 block discarded – undo
478 478
 				}
479 479
 				elseif (str_replace("\r", '', $old[$name]) == str_replace("\r", '', $data[$name]))
480 480
 				{
481
-					continue;	// change only in CR (eg. different OS) --> ignore
481
+					continue; // change only in CR (eg. different OS) --> ignore
482 482
 				}
483 483
 				$changed_fields[] = $name;
484 484
 				//echo "<p>$name: ".array2string($data[$name]).' != '.array2string($old[$name])."</p>\n";
485 485
 			}
486 486
 		}
487
-		foreach($data as $name => $value)
487
+		foreach ($data as $name => $value)
488 488
 		{
489 489
 			if ($name[0] == '#' && $name[1] == '#' && $value !== $old[$name])
490 490
 			{
@@ -501,18 +501,18 @@  discard block
 block discarded – undo
501 501
 	 * @param array &$rows rows of the 1:N relation
502 502
 	 * @param array $cols field names as values
503 503
 	 */
504
-	private static function compact_1_N_relation(&$rows,array $cols)
504
+	private static function compact_1_N_relation(&$rows, array $cols)
505 505
 	{
506 506
 		if (is_array($rows))
507 507
 		{
508
-			foreach($rows as &$row)
508
+			foreach ($rows as &$row)
509 509
 			{
510 510
 				$values = array();
511
-				foreach($cols as $col)
511
+				foreach ($cols as $col)
512 512
 				{
513 513
 					$values[] = $row[$col];
514 514
 				}
515
-				$row = implode(self::ONE2N_SEPERATOR,$values);
515
+				$row = implode(self::ONE2N_SEPERATOR, $values);
516 516
 			}
517 517
 		}
518 518
 		else
@@ -531,7 +531,7 @@  discard block
 block discarded – undo
531 531
 	 * @param array $email_notified=null if present will return the emails notified, if given emails in that list will not be notified
532 532
 	 * @return boolean true on success, false on error (error messages are in $this->errors)
533 533
 	 */
534
-	public function do_notifications($data,$old,$deleted=null,&$email_notified=null)
534
+	public function do_notifications($data, $old, $deleted = null, &$email_notified = null)
535 535
 	{
536 536
 		$this->errors = $email_sent = array();
537 537
 		if (!empty($email_notified) && is_array($email_notified)) $email_sent = $email_notified;
@@ -539,19 +539,19 @@  discard block
 block discarded – undo
539 539
 		if (!$this->notify_current_user && $this->user)		// do we have a current user and should we notify the current user about his own changes
540 540
 		{
541 541
 			//error_log("do_notificaton() adding user=$this->user to email_sent, to not notify him");
542
-			$email_sent[] = $GLOBALS['egw']->accounts->id2name($this->user,'account_email');
542
+			$email_sent[] = $GLOBALS['egw']->accounts->id2name($this->user, 'account_email');
543 543
 		}
544
-		$skip_notify = $this->get_config('skip_notify',$data,$old);
545
-		if($skip_notify && is_array($skip_notify))
544
+		$skip_notify = $this->get_config('skip_notify', $data, $old);
545
+		if ($skip_notify && is_array($skip_notify))
546 546
 		{
547 547
 			$email_sent = array_merge($email_sent, $skip_notify);
548 548
 		}
549 549
 
550 550
 		// entry creator
551
-		if ($this->creator_field && ($email = $GLOBALS['egw']->accounts->id2name($data[$this->creator_field],'account_email')) &&
551
+		if ($this->creator_field && ($email = $GLOBALS['egw']->accounts->id2name($data[$this->creator_field], 'account_email')) &&
552 552
 			!in_array($email, $email_sent))
553 553
 		{
554
-			if ($this->send_notification($data,$old,$email,$data[$this->creator_field],'notify_creator'))
554
+			if ($this->send_notification($data, $old, $email, $data[$this->creator_field], 'notify_creator'))
555 555
 			{
556 556
 				$email_sent[] = $email;
557 557
 			}
@@ -560,12 +560,12 @@  discard block
 block discarded – undo
560 560
 		// members of group when entry owned by group
561 561
 		if ($this->creator_field && $GLOBALS['egw']->accounts->get_type($data[$this->creator_field]) == 'g')
562 562
 		{
563
-			foreach($GLOBALS['egw']->accounts->members($data[$this->creator_field],true) as $u)
563
+			foreach ($GLOBALS['egw']->accounts->members($data[$this->creator_field], true) as $u)
564 564
 			{
565
-				if (($email = $GLOBALS['egw']->accounts->id2name($u,'account_email')) &&
565
+				if (($email = $GLOBALS['egw']->accounts->id2name($u, 'account_email')) &&
566 566
 					!in_array($email, $email_sent))
567 567
 				{
568
-					if ($this->send_notification($data,$old,$email,$u,'notify_owner_group_member'))
568
+					if ($this->send_notification($data, $old, $email, $u, 'notify_owner_group_member'))
569 569
 					{
570 570
 						$email_sent[] = $email;
571 571
 					}
@@ -582,14 +582,14 @@  discard block
 block discarded – undo
582 582
 			if ($data[$this->assigned_field])	// current assignments
583 583
 			{
584 584
 				$assignees = is_array($data[$this->assigned_field]) ?
585
-					$data[$this->assigned_field] : explode(',',$data[$this->assigned_field]);
585
+					$data[$this->assigned_field] : explode(',', $data[$this->assigned_field]);
586 586
 			}
587 587
 			if ($old && $old[$this->assigned_field])
588 588
 			{
589 589
 				$old_assignees = is_array($old[$this->assigned_field]) ?
590
-					$old[$this->assigned_field] : explode(',',$old[$this->assigned_field]);
590
+					$old[$this->assigned_field] : explode(',', $old[$this->assigned_field]);
591 591
 			}
592
-			foreach(array_unique(array_merge($assignees,$old_assignees)) as $assignee)
592
+			foreach (array_unique(array_merge($assignees, $old_assignees)) as $assignee)
593 593
 			{
594 594
 				//error_log(__METHOD__."() assignee=$assignee, type=".$GLOBALS['egw']->accounts->get_type($assignee).", email=".$GLOBALS['egw']->accounts->id2name($assignee,'account_email'));
595 595
 				if (!$assignee) continue;
@@ -597,10 +597,10 @@  discard block
 block discarded – undo
597 597
 				// item assignee is a user
598 598
 				if ($GLOBALS['egw']->accounts->get_type($assignee) == 'u')
599 599
 				{
600
-					if (($email = $GLOBALS['egw']->accounts->id2name($assignee,'account_email')) && !in_array($email, $email_sent))
600
+					if (($email = $GLOBALS['egw']->accounts->id2name($assignee, 'account_email')) && !in_array($email, $email_sent))
601 601
 					{
602
-						if ($this->send_notification($data,$old,$email,$assignee,'notify_assigned',
603
-							in_array($assignee,$assignees) !== in_array($assignee,$old_assignees) || $deleted))	// assignment changed
602
+						if ($this->send_notification($data, $old, $email, $assignee, 'notify_assigned',
603
+							in_array($assignee, $assignees) !== in_array($assignee, $old_assignees) || $deleted))	// assignment changed
604 604
 						{
605 605
 							$email_sent[] = $email;
606 606
 						}
@@ -608,12 +608,12 @@  discard block
 block discarded – undo
608 608
 				}
609 609
 				else	// item assignee is a group
610 610
 				{
611
-					foreach($GLOBALS['egw']->accounts->members($assignee,true) as $u)
611
+					foreach ($GLOBALS['egw']->accounts->members($assignee, true) as $u)
612 612
 					{
613
-						if (($email = $GLOBALS['egw']->accounts->id2name($u,'account_email')) && !in_array($email, $email_sent))
613
+						if (($email = $GLOBALS['egw']->accounts->id2name($u, 'account_email')) && !in_array($email, $email_sent))
614 614
 						{
615
-							if ($this->send_notification($data,$old,$email,$u,'notify_assigned',
616
-								in_array($u,$assignees) !== in_array($u,$old_assignees) || $deleted))	// assignment changed
615
+							if ($this->send_notification($data, $old, $email, $u, 'notify_assigned',
616
+								in_array($u, $assignees) !== in_array($u, $old_assignees) || $deleted))	// assignment changed
617 617
 							{
618 618
 								$email_sent[] = $email;
619 619
 							}
@@ -624,14 +624,14 @@  discard block
 block discarded – undo
624 624
 		}
625 625
 
626 626
 		// notification copies
627
-		if (($copies = $this->get_config('copy',$data,$old)))
627
+		if (($copies = $this->get_config('copy', $data, $old)))
628 628
 		{
629
-			$lang = $this->get_config('lang',$data,$old);
630
-			foreach($copies as $email)
629
+			$lang = $this->get_config('lang', $data, $old);
630
+			foreach ($copies as $email)
631 631
 			{
632
-				if (strchr($email,'@') !== false && !in_array($email, $email_sent))
632
+				if (strchr($email, '@') !== false && !in_array($email, $email_sent))
633 633
 				{
634
-					if ($this->send_notification($data,$old,$email,$lang,'notify_copy'))
634
+					if ($this->send_notification($data, $old, $email, $lang, 'notify_copy'))
635 635
 					{
636 636
 						$email_sent[] = $email;
637 637
 					}
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
 	 * @param boolean $deleted = null can be set to true to let the tracking know the item got deleted or undelted
677 677
 	 * @return boolean true on success or false if notification not requested or error (error-message is in $this->errors)
678 678
 	 */
679
-	public function send_notification($data,$old,$email,$user_or_lang,$check=null,$assignment_changed=true,$deleted=null)
679
+	public function send_notification($data, $old, $email, $user_or_lang, $check = null, $assignment_changed = true, $deleted = null)
680 680
 	{
681 681
 		//error_log(__METHOD__."(,,'$email',$user_or_lang,$check,$assignment_changed,$deleted)");
682 682
 		if (!$email) return false;
@@ -688,16 +688,16 @@  discard block
 block discarded – undo
688 688
 		{
689 689
 			$GLOBALS['egw_info']['user']['account_id'] = $user_or_lang;
690 690
 			$GLOBALS['egw']->preferences->__construct($user_or_lang);
691
-			$GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->read_repository(false);	// no session prefs!
691
+			$GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->read_repository(false); // no session prefs!
692 692
 
693 693
 			if ($check && $this->check2pref) $check = $this->check2pref[$check];
694 694
 
695
-			if ($check && !$GLOBALS['egw_info']['user']['preferences'][$this->app][$check] ||	// no notification requested
695
+			if ($check && !$GLOBALS['egw_info']['user']['preferences'][$this->app][$check] || // no notification requested
696 696
 				// only notification about changed assignment requested
697 697
 				$check && $GLOBALS['egw_info']['user']['preferences'][$this->app][$check] === 'assignment' && !$assignment_changed ||
698 698
 				$this->user == $user_or_lang && !$this->notify_current_user)  // no popup for own actions
699 699
 			{
700
-				$do_notify = false;	// no notification requested / necessary
700
+				$do_notify = false; // no notification requested / necessary
701 701
 			}
702 702
 		}
703 703
 		else
@@ -720,33 +720,33 @@  discard block
 block discarded – undo
720 720
 
721 721
 			// Cache message body to not have to re-generate it every time
722 722
 			$lang = Api\Translation::$userlang;
723
-			$date_format = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'] .
723
+			$date_format = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'].
724 724
 				$GLOBALS['egw_info']['user']['preferences']['common']['timeformat'];
725 725
 
726 726
 			// Cache text body
727
-			$body_cache =& $this->body_cache[$data[$this->id_field]][$lang][$date_format];
728
-			if(empty($data[$this->id_field]) || !isset($body_cache['text']))
727
+			$body_cache = & $this->body_cache[$data[$this->id_field]][$lang][$date_format];
728
+			if (empty($data[$this->id_field]) || !isset($body_cache['text']))
729 729
 			{
730
-				$body_cache['text'] = $this->get_body(false,$data,$old,false,$receiver);
730
+				$body_cache['text'] = $this->get_body(false, $data, $old, false, $receiver);
731 731
 			}
732 732
 			// Cache HTML body
733
-			if(empty($data[$this->id_field]) || !isset($body_cache['html']))
733
+			if (empty($data[$this->id_field]) || !isset($body_cache['html']))
734 734
 			{
735
-				$body_cache['html'] = $this->get_body(true,$data,$old,false,$receiver);
735
+				$body_cache['html'] = $this->get_body(true, $data, $old, false, $receiver);
736 736
 			}
737 737
 
738 738
 			// get rest of notification message
739
-			$sender = $this->get_sender($data,$old,true,$receiver);
740
-			$subject = $this->get_subject($data,$old,$deleted,$receiver);
741
-			$link = $this->get_notification_link($data,$old,$receiver);
742
-			$attachments = $this->get_attachments($data,$old,$receiver);
739
+			$sender = $this->get_sender($data, $old, true, $receiver);
740
+			$subject = $this->get_subject($data, $old, $deleted, $receiver);
741
+			$link = $this->get_notification_link($data, $old, $receiver);
742
+			$attachments = $this->get_attachments($data, $old, $receiver);
743 743
 		}
744 744
 
745 745
 		// restore user enviroment BEFORE calling notification class or returning
746 746
 		$GLOBALS['egw_info']['user'] = $save_user;
747 747
 		// need to call preferences constructor and read_repository, to set user timezone again
748 748
 		$GLOBALS['egw']->preferences->__construct($GLOBALS['egw_info']['user']['account_id']);
749
-		$GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->read_repository(false);	// no session prefs!
749
+		$GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->read_repository(false); // no session prefs!
750 750
 
751 751
 		// Re-load date/time preferences
752 752
 		Api\DateTime::init();
@@ -801,11 +801,11 @@  discard block
 block discarded – undo
801 801
 	 *
802 802
 	 * @return string
803 803
 	 */
804
-	public function datetime($timestamp,$do_time=true)
804
+	public function datetime($timestamp, $do_time = true)
805 805
 	{
806
-		if (!is_a($timestamp,'DateTime'))
806
+		if (!is_a($timestamp, 'DateTime'))
807 807
 		{
808
-			$timestamp = new Api\DateTime($timestamp,Api\DateTime::$server_timezone);
808
+			$timestamp = new Api\DateTime($timestamp, Api\DateTime::$server_timezone);
809 809
 		}
810 810
 		$timestamp->setTimezone(Api\DateTime::$user_timezone);
811 811
 		if (is_null($do_time))
@@ -831,25 +831,25 @@  discard block
 block discarded – undo
831 831
 	 * @param int|string $receiver nummeric account_id or email address
832 832
 	 * @return string or userid
833 833
 	 */
834
-	protected function get_sender($data,$old,$prefer_id=false,$receiver=null)
834
+	protected function get_sender($data, $old, $prefer_id = false, $receiver = null)
835 835
 	{
836
-		unset($receiver);	// not used, but required by function signature
836
+		unset($receiver); // not used, but required by function signature
837 837
 
838
-		$sender = $this->get_config('sender',$data,$old);
838
+		$sender = $this->get_config('sender', $data, $old);
839 839
 		//echo "<p>".__METHOD__."() get_config('sender',...)='".htmlspecialchars($sender)."'</p>\n";
840 840
 
841 841
 		if (($this->prefer_user_as_sender || !$sender) && $this->user &&
842
-			($email = $GLOBALS['egw']->accounts->id2name($this->user,'account_email')))
842
+			($email = $GLOBALS['egw']->accounts->id2name($this->user, 'account_email')))
843 843
 		{
844
-			$name = $GLOBALS['egw']->accounts->id2name($this->user,'account_fullname');
844
+			$name = $GLOBALS['egw']->accounts->id2name($this->user, 'account_fullname');
845 845
 
846
-			if($prefer_id) {
846
+			if ($prefer_id) {
847 847
 				$sender = $this->user;
848 848
 			} else {
849 849
 				$sender = $name ? $name.' <'.$email.'>' : $email;
850 850
 			}
851 851
 		}
852
-		elseif(!$sender)
852
+		elseif (!$sender)
853 853
 		{
854 854
 			$sender = 'eGroupWare '.lang($this->app).' <noreply@'.$GLOBALS['egw_info']['server']['mail_suffix'].'>';
855 855
 		}
@@ -864,11 +864,11 @@  discard block
 block discarded – undo
864 864
 	 * @param array $old
865 865
 	 * @return string
866 866
 	 */
867
-	protected function get_title($data,$old)
867
+	protected function get_title($data, $old)
868 868
 	{
869
-		unset($old);	// not used, but required by function signature
869
+		unset($old); // not used, but required by function signature
870 870
 
871
-		return Api\Link::title($this->app,$data[$this->id_field]);
871
+		return Api\Link::title($this->app, $data[$this->id_field]);
872 872
 	}
873 873
 
874 874
 	/**
@@ -882,11 +882,11 @@  discard block
 block discarded – undo
882 882
 	 * @param int|string $receiver nummeric account_id or email address
883 883
 	 * @return string
884 884
 	 */
885
-	protected function get_subject($data,$old,$deleted=null,$receiver=null)
885
+	protected function get_subject($data, $old, $deleted = null, $receiver = null)
886 886
 	{
887
-		unset($old, $deleted, $receiver);	// not used, but required by function signature
887
+		unset($old, $deleted, $receiver); // not used, but required by function signature
888 888
 
889
-		return Api\Link::title($this->app,$data[$this->id_field]);
889
+		return Api\Link::title($this->app, $data[$this->id_field]);
890 890
 	}
891 891
 
892 892
 	/**
@@ -899,9 +899,9 @@  discard block
 block discarded – undo
899 899
 	 * @param int|string $receiver nummeric account_id or email address
900 900
 	 * @return string
901 901
 	 */
902
-	protected function get_message($data,$old,$receiver=null)
902
+	protected function get_message($data, $old, $receiver = null)
903 903
 	{
904
-		unset($data, $old, $receiver);	// not used, but required by function signature
904
+		unset($data, $old, $receiver); // not used, but required by function signature
905 905
 
906 906
 		return '';
907 907
 	}
@@ -917,24 +917,24 @@  discard block
 block discarded – undo
917 917
 	 * @param int|string $receiver nummeric account_id or email address
918 918
 	 * @return string|array string with link (!$allow_popup) or array(link,popup-size), popup size is something like '640x480'
919 919
 	 */
920
-	protected function get_link($data,$old,$allow_popup=false,$receiver=null)
920
+	protected function get_link($data, $old, $allow_popup = false, $receiver = null)
921 921
 	{
922
-		unset($receiver);	// not used, but required by function signature
922
+		unset($receiver); // not used, but required by function signature
923 923
 
924
-		if (($link = $this->get_config('link',$data,$old)))
924
+		if (($link = $this->get_config('link', $data, $old)))
925 925
 		{
926
-			if (!$this->get_config('link_no_id', $data) && strpos($link,$this->id_field.'=') === false && isset($data[$this->id_field]))
926
+			if (!$this->get_config('link_no_id', $data) && strpos($link, $this->id_field.'=') === false && isset($data[$this->id_field]))
927 927
 			{
928
-				$link .= strpos($link,'?') === false ? '?' : '&';
928
+				$link .= strpos($link, '?') === false ? '?' : '&';
929 929
 				$link .= $this->id_field.'='.$data[$this->id_field];
930 930
 			}
931 931
 		}
932 932
 		else
933 933
 		{
934
-			if (($view = Api\Link::view($this->app,$data[$this->id_field])))
934
+			if (($view = Api\Link::view($this->app, $data[$this->id_field])))
935 935
 			{
936
-				$link = $GLOBALS['egw']->link('/index.php',$view);
937
-				$popup = Api\Link::is_popup($this->app,'view');
936
+				$link = $GLOBALS['egw']->link('/index.php', $view);
937
+				$popup = Api\Link::is_popup($this->app, 'view');
938 938
 			}
939 939
 		}
940 940
 		if ($link[0] == '/')
@@ -945,12 +945,12 @@  discard block
 block discarded – undo
945 945
 		if (!$allow_popup)
946 946
 		{
947 947
 			// remove the session-id in the notification mail!
948
-			$link = preg_replace('/(sessionid|kp3|domain)=[^&]+&?/','',$link);
948
+			$link = preg_replace('/(sessionid|kp3|domain)=[^&]+&?/', '', $link);
949 949
 
950 950
 			if ($popup) $link .= '&nopopup=1';
951 951
 		}
952 952
 		//error_log(__METHOD__."(..., $allow_popup, $receiver) returning ".array2string($allow_popup ? array($link,$popup) : $link));
953
-		return $allow_popup ? array($link,$popup) : $link;
953
+		return $allow_popup ? array($link, $popup) : $link;
954 954
 	}
955 955
 
956 956
 	/**
@@ -961,18 +961,18 @@  discard block
 block discarded – undo
961 961
 	 * @param int|string $receiver nummeric account_id or email address
962 962
 	 * @return array with link
963 963
 	 */
964
-	protected function get_notification_link($data,$old,$receiver=null)
964
+	protected function get_notification_link($data, $old, $receiver = null)
965 965
 	{
966
-		unset($receiver);	// not used, but required by function signature
966
+		unset($receiver); // not used, but required by function signature
967 967
 
968
-		if (($view = Api\Link::view($this->app,$data[$this->id_field])))
968
+		if (($view = Api\Link::view($this->app, $data[$this->id_field])))
969 969
 		{
970 970
 			return array(
971
-				'text' 	=> $this->get_title($data,$old),
971
+				'text' 	=> $this->get_title($data, $old),
972 972
 				'app'	=> $this->app,
973 973
 				'id'	=> $data[$this->id_field],
974 974
 				'view' 	=> $view,
975
-				'popup'	=> Api\Link::is_popup($this->app,'view'),
975
+				'popup'	=> Api\Link::is_popup($this->app, 'view'),
976 976
 			);
977 977
 		}
978 978
 		return false;
@@ -988,15 +988,15 @@  discard block
 block discarded – undo
988 988
 	 * @param int|string $receiver nummeric account_id or email address
989 989
 	 * @return string
990 990
 	 */
991
-	public function get_body($html_email,$data,$old,$integrate_link = true,$receiver=null)
991
+	public function get_body($html_email, $data, $old, $integrate_link = true, $receiver = null)
992 992
 	{
993 993
 		$body = '';
994
-		if($this->get_config(self::CUSTOM_NOTIFICATION, $data, $old))
994
+		if ($this->get_config(self::CUSTOM_NOTIFICATION, $data, $old))
995 995
 		{
996
-			$body = $this->get_custom_message($data,$old);
997
-			if(($sig = $this->get_signature($data,$old,$receiver)))
996
+			$body = $this->get_custom_message($data, $old);
997
+			if (($sig = $this->get_signature($data, $old, $receiver)))
998 998
 			{
999
-				$body .= ($html_email ? '<br />':'') . "\n$sig";
999
+				$body .= ($html_email ? '<br />' : '')."\n$sig";
1000 1000
 			}
1001 1001
 			return $body;
1002 1002
 		}
@@ -1005,35 +1005,35 @@  discard block
 block discarded – undo
1005 1005
 			$body = '<table cellspacing="2" cellpadding="0" border="0" width="100%">'."\n";
1006 1006
 		}
1007 1007
 		// new or modified message
1008
-		if (($message = $this->get_message($data,$old,$receiver)))
1008
+		if (($message = $this->get_message($data, $old, $receiver)))
1009 1009
 		{
1010 1010
 			foreach ((array)$message as $_message)
1011 1011
 			{
1012
-				$body .= $this->format_line($html_email,'message',false,($_message=='---'?($html_email?'<hr/>':$_message):$_message));
1012
+				$body .= $this->format_line($html_email, 'message', false, ($_message == '---' ? ($html_email ? '<hr/>' : $_message) : $_message));
1013 1013
 			}
1014 1014
 		}
1015
-		if ($integrate_link && ($link = $this->get_link($data,$old,false,$receiver)))
1015
+		if ($integrate_link && ($link = $this->get_link($data, $old, false, $receiver)))
1016 1016
 		{
1017
-			$body .= $this->format_line($html_email,'link',false,$integrate_link === true ? lang('You can respond by visiting:') : $integrate_link,$link);
1017
+			$body .= $this->format_line($html_email, 'link', false, $integrate_link === true ? lang('You can respond by visiting:') : $integrate_link, $link);
1018 1018
 		}
1019
-		foreach($this->get_details($data,$receiver) as $name => $detail)
1019
+		foreach ($this->get_details($data, $receiver) as $name => $detail)
1020 1020
 		{
1021 1021
 			// if there's no old entry, the entry is not modified by definition
1022 1022
 			// if both values are '', 0 or null, we count them as equal too
1023 1023
 			$modified = $old && $data[$name] != $old[$name] && !(!$data[$name] && !$old[$name]);
1024 1024
 			//if ($modified) error_log("data[$name]=".print_r($data[$name],true).", old[$name]=".print_r($old[$name],true)." --> modified=".(int)$modified);
1025
-			if (empty($detail['value']) && !$modified) continue;	// skip unchanged, empty values
1025
+			if (empty($detail['value']) && !$modified) continue; // skip unchanged, empty values
1026 1026
 
1027
-			$body .= $this->format_line($html_email,$detail['type'],$modified,
1027
+			$body .= $this->format_line($html_email, $detail['type'], $modified,
1028 1028
 				$detail['label'] ? $detail['label'] : '', $detail['value']);
1029 1029
 		}
1030 1030
 		if ($html_email)
1031 1031
 		{
1032 1032
 			$body .= "</table>\n";
1033 1033
 		}
1034
-		if(($sig = $this->get_signature($data,$old,$receiver)))
1034
+		if (($sig = $this->get_signature($data, $old, $receiver)))
1035 1035
 		{
1036
-			$body .= ($html_email ? '<br />':'') . "\n$sig";
1036
+			$body .= ($html_email ? '<br />' : '')."\n$sig";
1037 1037
 		}
1038 1038
 		return $body;
1039 1039
 	}
@@ -1049,20 +1049,20 @@  discard block
 block discarded – undo
1049 1049
 	 * @param string $data = null data or null to display just $line over 2 columns
1050 1050
 	 * @return string
1051 1051
 	 */
1052
-	protected function format_line($html_mail,$type,$modified,$line,$data=null)
1052
+	protected function format_line($html_mail, $type, $modified, $line, $data = null)
1053 1053
 	{
1054 1054
 		//error_log(__METHOD__.'('.array2string($html_mail).",'$type',".array2string($modified).",'$line',".array2string($data).')');
1055 1055
 		$content = '';
1056 1056
 
1057 1057
 		if ($html_mail)
1058 1058
 		{
1059
-			if (!$this->html_content_allow) $line = Api\Html::htmlspecialchars($line);	// XSS
1059
+			if (!$this->html_content_allow) $line = Api\Html::htmlspecialchars($line); // XSS
1060 1060
 
1061 1061
 			$color = $modified ? 'red' : false;
1062 1062
 			$size  = '110%';
1063 1063
 			$bold = false;
1064 1064
 			$background = '#FFFFF1';
1065
-			switch($type)
1065
+			switch ($type)
1066 1066
 			{
1067 1067
 				case 'message':
1068 1068
 					$background = '#D3DCE3;';
@@ -1080,7 +1080,7 @@  discard block
 block discarded – undo
1080 1080
 					if (strpos($data, '<br') === false)
1081 1081
 					{
1082 1082
 						$data = nl2br($this->html_content_allow ? $data : Api\Html::htmlspecialchars($data));
1083
-						$this->html_content_allow = true;	// to NOT do htmlspecialchars again
1083
+						$this->html_content_allow = true; // to NOT do htmlspecialchars again
1084 1084
 					}
1085 1085
 					break;
1086 1086
 				case 'reply':
@@ -1089,13 +1089,13 @@  discard block
 block discarded – undo
1089 1089
 				default:
1090 1090
 					$size = false;
1091 1091
 			}
1092
-			$style = ($bold ? 'font-weight:bold;' : '').($size ? 'font-size:'.$size.';' : '').($color?'color:'.$color:'');
1092
+			$style = ($bold ? 'font-weight:bold;' : '').($size ? 'font-size:'.$size.';' : '').($color ? 'color:'.$color : '');
1093 1093
 
1094
-			$content = '<tr style="background-color: '.$background.';"><td style="'.$style.($line && $data?'" width="20%':'" colspan="2').'">';
1094
+			$content = '<tr style="background-color: '.$background.';"><td style="'.$style.($line && $data ? '" width="20%' : '" colspan="2').'">';
1095 1095
 		}
1096 1096
 		else	// text-mail
1097 1097
 		{
1098
-			if ($type == 'reply') $content = str_repeat('-',64)."\n";
1098
+			if ($type == 'reply') $content = str_repeat('-', 64)."\n";
1099 1099
 
1100 1100
 			if ($modified) $content .= '> ';
1101 1101
 		}
@@ -1107,7 +1107,7 @@  discard block
 block discarded – undo
1107 1107
 			if ($type == 'link')
1108 1108
 			{
1109 1109
 				// the link is often too long for html boxes chunk-split allows to break lines if needed
1110
-				$content .= Api\Html::a_href(chunk_split(rawurldecode($data),40,'&#8203;'),$data,'','target="_blank"');
1110
+				$content .= Api\Html::a_href(chunk_split(rawurldecode($data), 40, '&#8203;'), $data, '', 'target="_blank"');
1111 1111
 			}
1112 1112
 			elseif ($this->html_content_allow)
1113 1113
 			{
@@ -1120,7 +1120,7 @@  discard block
 block discarded – undo
1120 1120
 		}
1121 1121
 		else
1122 1122
 		{
1123
-			$content .= ($content&&$data?': ':'').$data;
1123
+			$content .= ($content && $data ? ': ' : '').$data;
1124 1124
 		}
1125 1125
 		if ($html_mail) $content .= '</td></tr>';
1126 1126
 
@@ -1137,9 +1137,9 @@  discard block
 block discarded – undo
1137 1137
 	 * @param int|string $receiver nummeric account_id or email address
1138 1138
 	 * @return array or array with values for either 'string' or 'path' and optionally (mime-)'type', 'filename' and 'encoding'
1139 1139
 	 */
1140
-	protected function get_attachments($data,$old,$receiver=null)
1140
+	protected function get_attachments($data, $old, $receiver = null)
1141 1141
 	{
1142
-		unset($data, $old, $receiver);	// not used, but required by function signature
1142
+		unset($data, $old, $receiver); // not used, but required by function signature
1143 1143
 
1144 1144
 	 	return array();
1145 1145
 	}
@@ -1152,20 +1152,20 @@  discard block
 block discarded – undo
1152 1152
 	 */
1153 1153
 	protected function get_signature($data, $old, $receiver)
1154 1154
 	{
1155
-		unset($old, $receiver);	// not used, but required by function signature
1155
+		unset($old, $receiver); // not used, but required by function signature
1156 1156
 
1157 1157
 		$config = Api\Config::read('notifications');
1158
-		if(!isset($data[$this->id_field]))
1158
+		if (!isset($data[$this->id_field]))
1159 1159
 		{
1160
-			error_log($this->app . ' did not properly implement bo_tracking->id_field.  Merge skipped.');
1160
+			error_log($this->app.' did not properly implement bo_tracking->id_field.  Merge skipped.');
1161 1161
 		}
1162
-		elseif(class_exists($this->app. '_merge'))
1162
+		elseif (class_exists($this->app.'_merge'))
1163 1163
 		{
1164 1164
 			$merge_class = $this->app.'_merge';
1165 1165
 			$merge = new $merge_class();
1166 1166
 			$error = null;
1167 1167
 			$sig = $merge->merge_string($config['signature'], array($data[$this->id_field]), $error, 'text/html');
1168
-			if($error)
1168
+			if ($error)
1169 1169
 			{
1170 1170
 				error_log($error);
1171 1171
 				return $config['signature'];
@@ -1182,27 +1182,27 @@  discard block
 block discarded – undo
1182 1182
 	protected function get_custom_message($data, $old, $merge_class = null)
1183 1183
 	{
1184 1184
 		$message = $this->get_config(self::CUSTOM_NOTIFICATION, $data, $old);
1185
-		if(!$message)
1185
+		if (!$message)
1186 1186
 		{
1187 1187
 			return '';
1188 1188
 		}
1189 1189
 
1190 1190
 		// Automatically set merge class from naming conventions
1191
-		if($merge_class == null)
1191
+		if ($merge_class == null)
1192 1192
 		{
1193 1193
 			$merge_class = $this->app.'_merge';
1194 1194
 		}
1195
-		if(!isset($data[$this->id_field]))
1195
+		if (!isset($data[$this->id_field]))
1196 1196
 		{
1197
-			error_log($this->app . ' did not properly implement bo_tracking->id_field.  Merge skipped.');
1197
+			error_log($this->app.' did not properly implement bo_tracking->id_field.  Merge skipped.');
1198 1198
 			return $message;
1199 1199
 		}
1200
-		elseif(class_exists($merge_class))
1200
+		elseif (class_exists($merge_class))
1201 1201
 		{
1202 1202
 			$merge = new $merge_class();
1203 1203
 			$error = null;
1204 1204
 			$merged_message = $merge->merge_string($message, array($data[$this->id_field]), $error, 'text/html');
1205
-			if($error)
1205
+			if ($error)
1206 1206
 			{
1207 1207
 				error_log($error);
1208 1208
 				return $message;
Please login to merge, or discard this patch.
Braces   +157 added lines, -39 removed lines patch added patch discarded remove patch
@@ -239,7 +239,10 @@  discard block
 block discarded – undo
239 239
 			$header_done = false;
240 240
 			foreach($cfs as $name => $field)
241 241
 			{
242
-				if (in_array($field['type'], Customfields::$non_printable_fields)) continue;
242
+				if (in_array($field['type'], Customfields::$non_printable_fields))
243
+				{
244
+					continue;
245
+				}
243 246
 
244 247
 				if (!$header_done)
245 248
 				{
@@ -337,8 +340,14 @@  discard block
 block discarded – undo
337 340
 		{
338 341
 			//error_log(__METHOD__.__LINE__.' Field:'.$name. ' Value (new):'.array2string($data[$name]));
339 342
 			//error_log(__METHOD__.__LINE__.' Field:'.$name. ' Value (old):'.array2string($old[$name]));
340
-			if (is_array($data[$name]) && array_key_exists('id',$data[$name])) $data[$name] = $data[$name]['id'];
341
-			if (is_array($old[$name]) && array_key_exists('id',$old[$name])) $old[$name] = $old[$name]['id'];
343
+			if (is_array($data[$name]) && array_key_exists('id',$data[$name]))
344
+			{
345
+				$data[$name] = $data[$name]['id'];
346
+			}
347
+			if (is_array($old[$name]) && array_key_exists('id',$old[$name]))
348
+			{
349
+				$old[$name] = $old[$name]['id'];
350
+			}
342 351
 			//error_log(__METHOD__.__LINE__.'(After processing) Field:'.$name. ' Value (new):'.array2string($data[$name]));
343 352
 			//error_log(__METHOD__.__LINE__.'(After processing) Field:'.$name. ' Value (old):'.array2string($old[$name]));
344 353
 		}
@@ -352,11 +361,18 @@  discard block
 block discarded – undo
352 361
 			if (!($app = $this->cf_link_fields[$name]))
353 362
 			{
354 363
 				list($app,$id) = explode(':',$id);
355
-				if (!$id) continue;	// can be eg. 'addressbook:', if no contact selected
364
+				if (!$id)
365
+				{
366
+					continue;
367
+				}
368
+				// can be eg. 'addressbook:', if no contact selected
356 369
 			}
357 370
 			$source_id = $data[$this->id_field];
358 371
 			//error_log(__METHOD__.__LINE__.array2string($source_id));
359
-			if ($source_id) Api\Link::link($this->app,$source_id,$app,$id);
372
+			if ($source_id)
373
+			{
374
+				Api\Link::link($this->app,$source_id,$app,$id);
375
+			}
360 376
 			//error_log(__METHOD__.__LINE__."Api\Link::link('$this->app',".array2string($source_id).",'$app',$id);");
361 377
 			//echo "<p>Api\Link::link('$this->app',{$data[$this->id_field]},'$app',$id);</p>\n";
362 378
 		}
@@ -364,14 +380,24 @@  discard block
 block discarded – undo
364 380
 		// unlink removed application entries
365 381
 		foreach(array_diff($old_ids,$current_ids) as $name => $id)
366 382
 		{
367
-			if (!isset($data[$name])) continue;	// ignore not set link cf's, eg. from sync clients
383
+			if (!isset($data[$name]))
384
+			{
385
+				continue;
386
+			}
387
+			// ignore not set link cf's, eg. from sync clients
368 388
 			if (!($app = $this->cf_link_fields[$name]))
369 389
 			{
370 390
 				list($app,$id) = explode(':',$id);
371
-				if (!$id) continue;
391
+				if (!$id)
392
+				{
393
+					continue;
394
+				}
372 395
 			}
373 396
 			$source_id = $data[$this->id_field];
374
-			if ($source_id) Api\Link::unlink(null,$this->app,$source_id,0,$app,$id);
397
+			if ($source_id)
398
+			{
399
+				Api\Link::unlink(null,$this->app,$source_id,0,$app,$id);
400
+			}
375 401
 			//echo "<p>Api\Link::unlink(NULL,'$this->app',{$data[$this->id_field]},0,'$app',$id);</p>\n";
376 402
 		}
377 403
 	}
@@ -396,7 +422,10 @@  discard block
 block discarded – undo
396 422
 			$changed_fields = self::changed_fields($data,$old);
397 423
 			//error_log(__METHOD__.__LINE__.' Changedfields:'.array2string($changed_fields));
398 424
 		}
399
-		if (!$changed_fields && ($old || !$GLOBALS['egw_info']['server']['log_user_agent_action'])) return 0;
425
+		if (!$changed_fields && ($old || !$GLOBALS['egw_info']['server']['log_user_agent_action']))
426
+		{
427
+			return 0;
428
+		}
400 429
 
401 430
 		if (!is_object($this->historylog) || $this->historylog->user != $this->user)
402 431
 		{
@@ -412,10 +441,13 @@  discard block
 block discarded – undo
412 441
 		{
413 442
 			$status = isset($this->field2history[$name]) ? $this->field2history[$name] : $name;
414 443
 			//error_log(__METHOD__.__LINE__." Name $name,".' Status:'.array2string($status));
415
-			if (is_array($status))	// 1:N relation --> remove common rows
444
+			if (is_array($status))
445
+			{
446
+				// 1:N relation --> remove common rows
416 447
 			{
417 448
 				//error_log(__METHOD__.__LINE__.' is Array');
418 449
 				self::compact_1_N_relation($data[$name],$status);
450
+			}
419 451
 				self::compact_1_N_relation($old[$name],$status);
420 452
 				$added = array_values(array_diff($data[$name],$old[$name]));
421 453
 				$removed = array_values(array_diff($old[$name],$data[$name]));
@@ -449,17 +481,31 @@  discard block
 block discarded – undo
449 481
 	 */
450 482
 	public function changed_fields(array $data,array $old=null)
451 483
 	{
452
-		if (is_null($old)) return array_keys($data);
484
+		if (is_null($old))
485
+		{
486
+			return array_keys($data);
487
+		}
453 488
 		$changed_fields = array();
454 489
 		foreach($this->field2history as $name => $status)
455 490
 		{
456
-			if (!$old[$name] && !$data[$name]) continue;	// treat all sorts of empty equally
491
+			if (!$old[$name] && !$data[$name])
492
+			{
493
+				continue;
494
+			}
495
+			// treat all sorts of empty equally
457 496
 
458
-			if ($name[0] == '#' && !isset($data[$name])) continue;	// no set customfields are not stored, therefore not changed
497
+			if ($name[0] == '#' && !isset($data[$name]))
498
+			{
499
+				continue;
500
+			}
501
+			// no set customfields are not stored, therefore not changed
459 502
 
460
-			if (is_array($status))	// 1:N relation
503
+			if (is_array($status))
504
+			{
505
+				// 1:N relation
461 506
 			{
462 507
 				self::compact_1_N_relation($data[$name],$status);
508
+			}
463 509
 				self::compact_1_N_relation($old[$name],$status);
464 510
 			}
465 511
 			if ($old[$name] != $data[$name])
@@ -467,13 +513,22 @@  discard block
 block discarded – undo
467 513
 				// normalize arrays, we do NOT care for the order of multiselections
468 514
 				if (is_array($data[$name]) || is_array($old[$name]))
469 515
 				{
470
-					if (!is_array($data[$name])) $data[$name] = explode(',',$data[$name]);
471
-					if (!is_array($old[$name])) $old[$name] = explode(',',$old[$name]);
516
+					if (!is_array($data[$name]))
517
+					{
518
+						$data[$name] = explode(',',$data[$name]);
519
+					}
520
+					if (!is_array($old[$name]))
521
+					{
522
+						$old[$name] = explode(',',$old[$name]);
523
+					}
472 524
 					if (count($data[$name]) == count($old[$name]))
473 525
 					{
474 526
 						sort($data[$name]);
475 527
 						sort($old[$name]);
476
-						if ($data[$name] == $old[$name]) continue;
528
+						if ($data[$name] == $old[$name])
529
+						{
530
+							continue;
531
+						}
477 532
 					}
478 533
 				}
479 534
 				elseif (str_replace("\r", '', $old[$name]) == str_replace("\r", '', $data[$name]))
@@ -534,13 +589,19 @@  discard block
 block discarded – undo
534 589
 	public function do_notifications($data,$old,$deleted=null,&$email_notified=null)
535 590
 	{
536 591
 		$this->errors = $email_sent = array();
537
-		if (!empty($email_notified) && is_array($email_notified)) $email_sent = $email_notified;
592
+		if (!empty($email_notified) && is_array($email_notified))
593
+		{
594
+			$email_sent = $email_notified;
595
+		}
538 596
 
539
-		if (!$this->notify_current_user && $this->user)		// do we have a current user and should we notify the current user about his own changes
597
+		if (!$this->notify_current_user && $this->user)
598
+		{
599
+			// do we have a current user and should we notify the current user about his own changes
540 600
 		{
541 601
 			//error_log("do_notificaton() adding user=$this->user to email_sent, to not notify him");
542 602
 			$email_sent[] = $GLOBALS['egw']->accounts->id2name($this->user,'account_email');
543 603
 		}
604
+		}
544 605
 		$skip_notify = $this->get_config('skip_notify',$data,$old);
545 606
 		if($skip_notify && is_array($skip_notify))
546 607
 		{
@@ -579,11 +640,14 @@  discard block
 block discarded – undo
579 640
 			//error_log(__METHOD__."() data[$this->assigned_field]=".print_r($data[$this->assigned_field],true).", old[$this->assigned_field]=".print_r($old[$this->assigned_field],true));
580 641
 			$old_assignees = array();
581 642
 			$assignees = $assigned ? $assigned : array();
582
-			if ($data[$this->assigned_field])	// current assignments
643
+			if ($data[$this->assigned_field])
644
+			{
645
+				// current assignments
583 646
 			{
584 647
 				$assignees = is_array($data[$this->assigned_field]) ?
585 648
 					$data[$this->assigned_field] : explode(',',$data[$this->assigned_field]);
586 649
 			}
650
+			}
587 651
 			if ($old && $old[$this->assigned_field])
588 652
 			{
589 653
 				$old_assignees = is_array($old[$this->assigned_field]) ?
@@ -592,7 +656,10 @@  discard block
 block discarded – undo
592 656
 			foreach(array_unique(array_merge($assignees,$old_assignees)) as $assignee)
593 657
 			{
594 658
 				//error_log(__METHOD__."() assignee=$assignee, type=".$GLOBALS['egw']->accounts->get_type($assignee).", email=".$GLOBALS['egw']->accounts->id2name($assignee,'account_email'));
595
-				if (!$assignee) continue;
659
+				if (!$assignee)
660
+				{
661
+					continue;
662
+				}
596 663
 
597 664
 				// item assignee is a user
598 665
 				if ($GLOBALS['egw']->accounts->get_type($assignee) == 'u')
@@ -600,10 +667,13 @@  discard block
 block discarded – undo
600 667
 					if (($email = $GLOBALS['egw']->accounts->id2name($assignee,'account_email')) && !in_array($email, $email_sent))
601 668
 					{
602 669
 						if ($this->send_notification($data,$old,$email,$assignee,'notify_assigned',
603
-							in_array($assignee,$assignees) !== in_array($assignee,$old_assignees) || $deleted))	// assignment changed
670
+							in_array($assignee,$assignees) !== in_array($assignee,$old_assignees) || $deleted))
671
+						{
672
+							// assignment changed
604 673
 						{
605 674
 							$email_sent[] = $email;
606 675
 						}
676
+						}
607 677
 					}
608 678
 				}
609 679
 				else	// item assignee is a group
@@ -613,10 +683,13 @@  discard block
 block discarded – undo
613 683
 						if (($email = $GLOBALS['egw']->accounts->id2name($u,'account_email')) && !in_array($email, $email_sent))
614 684
 						{
615 685
 							if ($this->send_notification($data,$old,$email,$u,'notify_assigned',
616
-								in_array($u,$assignees) !== in_array($u,$old_assignees) || $deleted))	// assignment changed
686
+								in_array($u,$assignees) !== in_array($u,$old_assignees) || $deleted))
687
+							{
688
+								// assignment changed
617 689
 							{
618 690
 								$email_sent[] = $email;
619 691
 							}
692
+							}
620 693
 						}
621 694
 					}
622 695
 				}
@@ -679,25 +752,38 @@  discard block
 block discarded – undo
679 752
 	public function send_notification($data,$old,$email,$user_or_lang,$check=null,$assignment_changed=true,$deleted=null)
680 753
 	{
681 754
 		//error_log(__METHOD__."(,,'$email',$user_or_lang,$check,$assignment_changed,$deleted)");
682
-		if (!$email) return false;
755
+		if (!$email)
756
+		{
757
+			return false;
758
+		}
683 759
 
684 760
 		$save_user = $GLOBALS['egw_info']['user'];
685 761
 		$do_notify = true;
686 762
 
687
-		if (is_numeric($user_or_lang))	// user --> read everything from his prefs
763
+		if (is_numeric($user_or_lang))
764
+		{
765
+			// user --> read everything from his prefs
688 766
 		{
689 767
 			$GLOBALS['egw_info']['user']['account_id'] = $user_or_lang;
768
+		}
690 769
 			$GLOBALS['egw']->preferences->__construct($user_or_lang);
691 770
 			$GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->read_repository(false);	// no session prefs!
692 771
 
693
-			if ($check && $this->check2pref) $check = $this->check2pref[$check];
772
+			if ($check && $this->check2pref)
773
+			{
774
+				$check = $this->check2pref[$check];
775
+			}
694 776
 
695 777
 			if ($check && !$GLOBALS['egw_info']['user']['preferences'][$this->app][$check] ||	// no notification requested
696 778
 				// only notification about changed assignment requested
697 779
 				$check && $GLOBALS['egw_info']['user']['preferences'][$this->app][$check] === 'assignment' && !$assignment_changed ||
698
-				$this->user == $user_or_lang && !$this->notify_current_user)  // no popup for own actions
780
+				$this->user == $user_or_lang && !$this->notify_current_user)
699 781
 			{
700
-				$do_notify = false;	// no notification requested / necessary
782
+				// no popup for own actions
783
+			{
784
+				$do_notify = false;
785
+			}
786
+			// no notification requested / necessary
701 787
 			}
702 788
 		}
703 789
 		else
@@ -706,10 +792,13 @@  discard block
 block discarded – undo
706 792
 			$GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->default_prefs();
707 793
 			$GLOBALS['egw_info']['user']['preferences']['common']['lang'] = $user_or_lang;
708 794
 		}
709
-		if ($GLOBALS['egw_info']['user']['preferences']['common']['lang'] != Api\Translation::$userlang)	// load the right language if needed
795
+		if ($GLOBALS['egw_info']['user']['preferences']['common']['lang'] != Api\Translation::$userlang)
796
+		{
797
+			// load the right language if needed
710 798
 		{
711 799
 			Api\Translation::init();
712 800
 		}
801
+		}
713 802
 
714 803
 		$receiver = is_numeric($user_or_lang) ? $user_or_lang : $email;
715 804
 
@@ -813,7 +902,10 @@  discard block
 block discarded – undo
813 902
 			$do_time = ($timestamp->format('Hi') != '0000');
814 903
 		}
815 904
 		$format = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'];
816
-		if ($do_time) $format .= ' '.($GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] != 12 ? 'H:i' : 'h:i a');
905
+		if ($do_time)
906
+		{
907
+			$format .= ' '.($GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] != 12 ? 'H:i' : 'h:i a');
908
+		}
817 909
 
818 910
 		return $timestamp->format($format);
819 911
 	}
@@ -843,9 +935,12 @@  discard block
 block discarded – undo
843 935
 		{
844 936
 			$name = $GLOBALS['egw']->accounts->id2name($this->user,'account_fullname');
845 937
 
846
-			if($prefer_id) {
938
+			if($prefer_id)
939
+			{
847 940
 				$sender = $this->user;
848
-			} else {
941
+			}
942
+			else
943
+			{
849 944
 				$sender = $name ? $name.' <'.$email.'>' : $email;
850 945
 			}
851 946
 		}
@@ -947,7 +1042,10 @@  discard block
 block discarded – undo
947 1042
 			// remove the session-id in the notification mail!
948 1043
 			$link = preg_replace('/(sessionid|kp3|domain)=[^&]+&?/','',$link);
949 1044
 
950
-			if ($popup) $link .= '&nopopup=1';
1045
+			if ($popup)
1046
+			{
1047
+				$link .= '&nopopup=1';
1048
+			}
951 1049
 		}
952 1050
 		//error_log(__METHOD__."(..., $allow_popup, $receiver) returning ".array2string($allow_popup ? array($link,$popup) : $link));
953 1051
 		return $allow_popup ? array($link,$popup) : $link;
@@ -1022,7 +1120,11 @@  discard block
 block discarded – undo
1022 1120
 			// if both values are '', 0 or null, we count them as equal too
1023 1121
 			$modified = $old && $data[$name] != $old[$name] && !(!$data[$name] && !$old[$name]);
1024 1122
 			//if ($modified) error_log("data[$name]=".print_r($data[$name],true).", old[$name]=".print_r($old[$name],true)." --> modified=".(int)$modified);
1025
-			if (empty($detail['value']) && !$modified) continue;	// skip unchanged, empty values
1123
+			if (empty($detail['value']) && !$modified)
1124
+			{
1125
+				continue;
1126
+			}
1127
+			// skip unchanged, empty values
1026 1128
 
1027 1129
 			$body .= $this->format_line($html_email,$detail['type'],$modified,
1028 1130
 				$detail['label'] ? $detail['label'] : '', $detail['value']);
@@ -1056,7 +1158,11 @@  discard block
 block discarded – undo
1056 1158
 
1057 1159
 		if ($html_mail)
1058 1160
 		{
1059
-			if (!$this->html_content_allow) $line = Api\Html::htmlspecialchars($line);	// XSS
1161
+			if (!$this->html_content_allow)
1162
+			{
1163
+				$line = Api\Html::htmlspecialchars($line);
1164
+			}
1165
+			// XSS
1060 1166
 
1061 1167
 			$color = $modified ? 'red' : false;
1062 1168
 			$size  = '110%';
@@ -1095,15 +1201,24 @@  discard block
 block discarded – undo
1095 1201
 		}
1096 1202
 		else	// text-mail
1097 1203
 		{
1098
-			if ($type == 'reply') $content = str_repeat('-',64)."\n";
1204
+			if ($type == 'reply')
1205
+			{
1206
+				$content = str_repeat('-',64)."\n";
1207
+			}
1099 1208
 
1100
-			if ($modified) $content .= '> ';
1209
+			if ($modified)
1210
+			{
1211
+				$content .= '> ';
1212
+			}
1101 1213
 		}
1102 1214
 		$content .= $line;
1103 1215
 
1104 1216
 		if ($html_mail)
1105 1217
 		{
1106
-			if ($line && $data) $content .= '</td><td style="'.$style.'">';
1218
+			if ($line && $data)
1219
+			{
1220
+				$content .= '</td><td style="'.$style.'">';
1221
+			}
1107 1222
 			if ($type == 'link')
1108 1223
 			{
1109 1224
 				// the link is often too long for html boxes chunk-split allows to break lines if needed
@@ -1122,7 +1237,10 @@  discard block
 block discarded – undo
1122 1237
 		{
1123 1238
 			$content .= ($content&&$data?': ':'').$data;
1124 1239
 		}
1125
-		if ($html_mail) $content .= '</td></tr>';
1240
+		if ($html_mail)
1241
+		{
1242
+			$content .= '</td></tr>';
1243
+		}
1126 1244
 
1127 1245
 		$content .= "\n";
1128 1246
 
Please login to merge, or discard this patch.
api/src/Translation.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -742,7 +742,7 @@
 block discarded – undo
742 742
 	 *
743 743
 	 * @param string $app application name
744 744
 	 * @param string $lang language code
745
-	 * @return the full path of the filename for the requested app and language
745
+	 * @return string full path of the filename for the requested app and language
746 746
 	 */
747 747
 	static function get_lang_file($app,$lang)
748 748
 	{
Please login to merge, or discard this patch.
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -738,12 +738,12 @@  discard block
 block discarded – undo
738 738
 	}
739 739
 
740 740
  	/**
741
-	 * provides centralization and compatibility to locate the lang files
742
-	 *
743
-	 * @param string $app application name
744
-	 * @param string $lang language code
745
-	 * @return the full path of the filename for the requested app and language
746
-	 */
741
+ 	 * provides centralization and compatibility to locate the lang files
742
+ 	 *
743
+ 	 * @param string $app application name
744
+ 	 * @param string $lang language code
745
+ 	 * @return the full path of the filename for the requested app and language
746
+ 	 */
747 747
 	static function get_lang_file($app,$lang)
748 748
 	{
749 749
 		if ($app == 'common') $app = 'phpgwapi';
@@ -1074,13 +1074,13 @@  discard block
 block discarded – undo
1074 1074
 	}
1075 1075
 
1076 1076
  	/**
1077
-	 * detect_encoding - try to detect the encoding
1078
-	 *    only to be used if the string in question has no structure that determines his encoding
1079
-	 *
1080
-	 * @param string - to be evaluated
1081
-	 * @param string $verify =null encoding to verify, get checked first and have a match for only ascii or no detection available
1082
-	 * @return string - encoding
1083
-	 */
1077
+ 	 * detect_encoding - try to detect the encoding
1078
+ 	 *    only to be used if the string in question has no structure that determines his encoding
1079
+ 	 *
1080
+ 	 * @param string - to be evaluated
1081
+ 	 * @param string $verify =null encoding to verify, get checked first and have a match for only ascii or no detection available
1082
+ 	 * @return string - encoding
1083
+ 	 */
1084 1084
 	static function detect_encoding($string, $verify=null)
1085 1085
 	{
1086 1086
 		if (function_exists('iconv'))
Please login to merge, or discard this patch.
Spacing   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 	 *
100 100
 	 * @var array
101 101
 	 */
102
-	static $instance_specific_translations = array('loginscreen','mainscreen','custom');
102
+	static $instance_specific_translations = array('loginscreen', 'mainscreen', 'custom');
103 103
 
104 104
 	/**
105 105
 	 * returns the charset to use (!$lang) or the charset of the lang-files or $lang
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
 	 * @param string|boolean $lang =False return charset of the active user-lang, or $lang if specified
108 108
 	 * @return string charset
109 109
 	 */
110
-	static function charset($lang=False)
110
+	static function charset($lang = False)
111 111
 	{
112 112
 		static $charsets = array();
113 113
 
@@ -115,11 +115,11 @@  discard block
 block discarded – undo
115 115
 		{
116 116
 			if (!isset($charsets[$lang]))
117 117
 			{
118
-				if (!($charsets[$lang] = self::$db->select(self::LANG_TABLE,'content',array(
118
+				if (!($charsets[$lang] = self::$db->select(self::LANG_TABLE, 'content', array(
119 119
 					'lang'		=> $lang,
120 120
 					'message_id'=> 'charset',
121 121
 					'app_name'	=> 'common',
122
-				),__LINE__,__FILE__)->fetchColumn()))
122
+				), __LINE__, __FILE__)->fetchColumn()))
123 123
 				{
124 124
 					$charsets[$lang] = 'utf-8';
125 125
 				}
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 	 *
154 154
 	 * @param boolean $load_translations =true should we also load translations for common and currentapp
155 155
 	 */
156
-	static function init($load_translations=true)
156
+	static function init($load_translations = true)
157 157
 	{
158 158
 		if (!isset(self::$db))
159 159
 		{
@@ -165,11 +165,11 @@  discard block
 block discarded – undo
165 165
 		}
166 166
 		else
167 167
 		{
168
-			self::$system_charset =& $GLOBALS['egw_setup']->system_charset;
168
+			self::$system_charset = & $GLOBALS['egw_setup']->system_charset;
169 169
 		}
170 170
 		if ((self::$mbstring = check_load_extension('mbstring')))
171 171
 		{
172
-			if(!empty(self::$system_charset))
172
+			if (!empty(self::$system_charset))
173 173
 			{
174 174
 				$ini_default_charset = version_compare(PHP_VERSION, '5.6', '<') ? 'mbstring.internal_encoding' : 'default_charset';
175 175
 				ini_set($ini_default_charset, self::$system_charset);
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
 
179 179
 		// try loading load_via from tree-wide cache and check if it contains more rules
180 180
 		if (($load_via = Cache::getTree(__CLASS__, 'load_via')) &&
181
-			$load_via >= self::$load_via && 	// > for array --> contains more elements
181
+			$load_via >= self::$load_via && // > for array --> contains more elements
182 182
 			// little sanity check: cached array contains all stock keys, otherwise ignore it
183 183
 			!array_diff_key(self::$load_via, $load_via))
184 184
 		{
@@ -217,13 +217,13 @@  discard block
 block discarded – undo
217 217
 	 * @param string $not_found ='*' what to add to not found phrases, default '*'
218 218
 	 * @return string with translation
219 219
 	 */
220
-	static function translate($key, $vars=null, $not_found='' )
220
+	static function translate($key, $vars = null, $not_found = '')
221 221
 	{
222 222
 		if (!self::$lang_arr)
223 223
 		{
224 224
 			self::init();
225 225
 		}
226
-		$ret = $key;				// save key if we dont find a translation
226
+		$ret = $key; // save key if we dont find a translation
227 227
 		if ($not_found) $ret .= $not_found;
228 228
 
229 229
 		if (isset(self::$lang_arr[$key]))
@@ -243,16 +243,16 @@  discard block
 block discarded – undo
243 243
 		{
244 244
 			if (count($vars) > 1)
245 245
 			{
246
-				static $placeholders = array('%3','%2','%1','|%2|','|%3|','%4','%5','%6','%7','%8','%9','%10');
246
+				static $placeholders = array('%3', '%2', '%1', '|%2|', '|%3|', '%4', '%5', '%6', '%7', '%8', '%9', '%10');
247 247
 				// to cope with $vars[0] containing '%2' (eg. an urlencoded path like a referer),
248 248
 				// we first replace '%2' in $ret with '|%2|' and then use that as 2. placeholder
249 249
 				// we do that for %3 as well, ...
250
-				$vars = array_merge(array('|%3|','|%2|'),$vars);	// push '|%2|' (and such) as first replacement on $vars
251
-				$ret = str_replace($placeholders,$vars,$ret);
250
+				$vars = array_merge(array('|%3|', '|%2|'), $vars); // push '|%2|' (and such) as first replacement on $vars
251
+				$ret = str_replace($placeholders, $vars, $ret);
252 252
 			}
253 253
 			else
254 254
 			{
255
-				$ret = str_replace('%1',$vars[0],$ret);
255
+				$ret = str_replace('%1', $vars[0], $ret);
256 256
 			}
257 257
 		}
258 258
 		return $ret;
@@ -267,14 +267,14 @@  discard block
 block discarded – undo
267 267
 	 * 	if multiple names given, they are requested in one request from cache and loaded in given order
268 268
 	 * @param string $lang =false 2 or 5 char lang-code or false for the users language
269 269
 	 */
270
-	static function add_app($apps, $lang=null)
270
+	static function add_app($apps, $lang = null)
271 271
 	{
272 272
 		//error_log(__METHOD__."(".array2string($apps).", $lang) count(self::\$lang_arr)=".count(self::$lang_arr));
273 273
 		//$start = microtime(true);
274 274
 		if (!$lang) $lang = self::$userlang;
275 275
 		$tree_level = $instance_level = array();
276 276
 		if (!is_array($apps)) $apps = (array)$apps;
277
-		foreach($apps as $key => $app)
277
+		foreach ($apps as $key => $app)
278 278
 		{
279 279
 			if (!isset(self::$loaded_apps[$app]) || self::$loaded_apps[$app] != $lang && $app != 'common')
280 280
 			{
@@ -298,26 +298,26 @@  discard block
 block discarded – undo
298 298
 
299 299
 		// merging loaded translations together
300 300
 		$updated_load_via = false;
301
-		foreach((array)$apps as $app)
301
+		foreach ((array)$apps as $app)
302 302
 		{
303 303
 			$l = $app == 'custom' ? 'en' : $lang;
304 304
 			if (isset($tree_level[$app.':'.$l]))
305 305
 			{
306
-				$loaded =& $tree_level[$app.':'.$l];
306
+				$loaded = & $tree_level[$app.':'.$l];
307 307
 			}
308 308
 			elseif (isset($instance_level[$app.':'.$l]))
309 309
 			{
310
-				$loaded =& $instance_level[$app.':'.$l];
310
+				$loaded = & $instance_level[$app.':'.$l];
311 311
 			}
312 312
 			else
313 313
 			{
314 314
 				if (($instance_specific = in_array($app, self::$instance_specific_translations)))
315 315
 				{
316
-					$loaded =& self::load_app($app, $l);
316
+					$loaded = & self::load_app($app, $l);
317 317
 				}
318 318
 				else
319 319
 				{
320
-					$loaded =& self::load_app_files($app, $l, null, $updated_load_via);
320
+					$loaded = & self::load_app_files($app, $l, null, $updated_load_via);
321 321
 				}
322 322
 				//error_log(__METHOD__."('$app', '$lang') instance_specific=$instance_specific, load_app(_files)() returned ".(is_array($loaded)?'Array('.count($loaded).')':array2string($loaded)));
323 323
 				if ($loaded || $instance_specific)
@@ -330,14 +330,14 @@  discard block
 block discarded – undo
330 330
 			if ($loaded)
331 331
 			{
332 332
 				self::$lang_arr = array_merge(self::$lang_arr, $loaded);
333
-				self::$loaded_apps[$app] = $l;	// dont set something not existing to $loaded_apps, no need to load client-side
333
+				self::$loaded_apps[$app] = $l; // dont set something not existing to $loaded_apps, no need to load client-side
334 334
 			}
335 335
 		}
336 336
 		// Re-merge custom over instance level, they have higher precidence
337
-		if($tree_level && !$instance_level && self::$instance_specific_translations)
337
+		if ($tree_level && !$instance_level && self::$instance_specific_translations)
338 338
 		{
339 339
 			$custom = Cache::getInstance(__CLASS__, 'custom:en');
340
-			if($custom)
340
+			if ($custom)
341 341
 			{
342 342
 				self::$lang_arr = array_merge(self::$lang_arr, $custom);
343 343
 			}
@@ -358,15 +358,15 @@  discard block
 block discarded – undo
358 358
 	 * @param string $lang =false 2 or 5 char lang-code or false for the users language
359 359
 	 * @return array the loaded strings
360 360
 	 */
361
-	static function &load_app($app,$lang)
361
+	static function &load_app($app, $lang)
362 362
 	{
363 363
 		//$start = microtime(true);
364 364
 		if (is_null(self::$db)) self::init(false);
365 365
 		$loaded = array();
366
-		foreach(self::$db->select(self::LANG_TABLE,'message_id,content',array(
366
+		foreach (self::$db->select(self::LANG_TABLE, 'message_id,content', array(
367 367
 			'lang'		=> $lang,
368 368
 			'app_name'	=> $app,
369
-		),__LINE__,__FILE__) as $row)
369
+		), __LINE__, __FILE__) as $row)
370 370
 		{
371 371
 			$loaded[strtolower($row['message_id'])] = $row['content'];
372 372
 		}
@@ -390,7 +390,7 @@  discard block
 block discarded – undo
390 390
 		'sitemgr-link' => array('sitemgr'),
391 391
 		'groupdav' => array('api'),
392 392
 		'developer_tools' => array('etemplate'),
393
-		'login' => array('api','registration'),
393
+		'login' => array('api', 'registration'),
394 394
 	);
395 395
 
396 396
 	/**
@@ -402,7 +402,7 @@  discard block
 block discarded – undo
402 402
 	{
403 403
 		$lang = $GLOBALS['egw_info']['user']['preferences']['common']['lang'];
404 404
 		$apps = array_keys($GLOBALS['egw_info']['apps']);
405
-		foreach($apps as $app)
405
+		foreach ($apps as $app)
406 406
 		{
407 407
 			$file = self::get_lang_file($app, $lang);
408 408
 			// check if file has changed compared to what's cached
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
 		Cache::unsetTree(__CLASS__, $app.':'.$lang);
433 433
 		Cache::unsetTree(__CLASS__, self::get_lang_file($app, $lang));
434 434
 
435
-		foreach(self::$load_via as $load => $via)
435
+		foreach (self::$load_via as $load => $via)
436 436
 		{
437 437
 			//error_log("load_via[load='$load'] = via = ".array2string($via));
438 438
 			if ($via === 'all-apps' || in_array($app, (array)$via))
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
 	 * @param string $_lang =null
455 455
 	 * @return array $lang or $app => number pairs
456 456
 	 */
457
-	static function statistics($_lang=null)
457
+	static function statistics($_lang = null)
458 458
 	{
459 459
 		$cache = Cache::getTree(__CLASS__, 'statistics');
460 460
 
@@ -465,7 +465,7 @@  discard block
 block discarded – undo
465 465
 			{
466 466
 				$en_phrases = array_keys(self::load_app_files(null, 'en', 'all-apps'));
467 467
 				$cache['']['en'] = count($en_phrases);
468
-				foreach(array_keys(self::get_available_langs()) as $lang)
468
+				foreach (array_keys(self::get_available_langs()) as $lang)
469 469
 				{
470 470
 					if ($lang == 'en') continue;
471 471
 					$lang_phrases = array_keys(self::load_app_files(null, $lang, 'all-apps'));
@@ -476,7 +476,7 @@  discard block
 block discarded – undo
476 476
 			else
477 477
 			{
478 478
 				$cache['en'] = array();
479
-				foreach(scandir(EGW_SERVER_ROOT) as $app)
479
+				foreach (scandir(EGW_SERVER_ROOT) as $app)
480 480
 				{
481 481
 					if ($app[0] == '.' || !is_dir(EGW_SERVER_ROOT.'/'.$app) ||
482 482
 						!file_exists(self::get_lang_file($app, 'en')))
@@ -514,7 +514,7 @@  discard block
 block discarded – undo
514 514
 		if (!in_array($_app, self::$instance_specific_translations))
515 515
 		{
516 516
 			// check if cache is NOT invalided by checking if we have a modification time for concerned lang-file
517
-			$time = Cache::getTree(__CLASS__, $file=self::get_lang_file($_app, $_lang));
517
+			$time = Cache::getTree(__CLASS__, $file = self::get_lang_file($_app, $_lang));
518 518
 			// if we dont have one, cache has been invalidated and we need to load translations
519 519
 			if (!isset($time)) self::add_app($_app, $_lang);
520 520
 
@@ -534,7 +534,7 @@  discard block
 block discarded – undo
534 534
 	 * @param type $time
535 535
 	 * @return type
536 536
 	 */
537
-	static function max_lang_time($time=null)
537
+	static function max_lang_time($time = null)
538 538
 	{
539 539
 		static $max_lang_time = null;
540 540
 
@@ -545,7 +545,7 @@  discard block
 block discarded – undo
545 545
 		if (isset($time) && $time > $max_lang_time)
546 546
 		{
547 547
 			//error_log(__METHOD__."($time) updating previous max_lang_time=$max_lang_time to $time");
548
-			Cache::setTree(__CLASS__, 'max_lang_time', $max_lang_time=$time);
548
+			Cache::setTree(__CLASS__, 'max_lang_time', $max_lang_time = $time);
549 549
 		}
550 550
 		return $max_lang_time;
551 551
 	}
@@ -561,34 +561,34 @@  discard block
 block discarded – undo
561 561
 	 * @param boolean $updated_load_via =false on return true if self::$load_via was updated
562 562
 	 * @return array the loaded strings
563 563
 	 */
564
-	static function &load_app_files($app, $lang, $just_app_file=null, &$updated_load_via=false)
564
+	static function &load_app_files($app, $lang, $just_app_file = null, &$updated_load_via = false)
565 565
 	{
566 566
 		//$start = microtime(true);
567 567
 		$load_app = isset($just_app_file) ? $just_app_file : (isset(self::$load_via[$app]) ? self::$load_via[$app] : $app);
568 568
 		$loaded = array();
569
-		foreach($load_app == 'all-apps' ? scandir(EGW_SERVER_ROOT) : (array)$load_app as $app_dir)
569
+		foreach ($load_app == 'all-apps' ? scandir(EGW_SERVER_ROOT) : (array)$load_app as $app_dir)
570 570
 		{
571
-			if ($load_app == 'all-apps' && $app_dir=='..') continue; // do not try to break out of egw server root
571
+			if ($load_app == 'all-apps' && $app_dir == '..') continue; // do not try to break out of egw server root
572 572
 			if ($app_dir[0] == '.' || !is_dir(EGW_SERVER_ROOT.'/'.$app_dir) ||
573
-				!@file_exists($file=self::get_lang_file($app_dir, $lang)) ||
573
+				!@file_exists($file = self::get_lang_file($app_dir, $lang)) ||
574 574
 				!($f = fopen($file, 'r')))
575 575
 			{
576 576
 				continue;
577 577
 			}
578 578
 			// store ctime of file we parse
579
-			Cache::setTree(__CLASS__, $file, $time=filemtime($file));
579
+			Cache::setTree(__CLASS__, $file, $time = filemtime($file));
580 580
 			self::max_lang_time($time);
581 581
 
582 582
 			$line_nr = 0;
583 583
 			//use fgets and split the line, as php5.3.3 with squeeze does not support splitting lines with fgetcsv while reading properly
584 584
 			//if the first letter after the delimiter is a german umlaut (UTF8 representation thereoff)
585 585
 			//while(($line = fgetcsv($f, 1024, "\t")))
586
-			while(($read = fgets($f)))
586
+			while (($read = fgets($f)))
587 587
 			{
588 588
 				$line = explode("\t", trim($read));
589 589
 				++$line_nr;
590 590
 				if (count($line) != 4) continue;
591
-				list($l_id,$l_app,$l_lang,$l_translation) = $line;
591
+				list($l_id, $l_app, $l_lang, $l_translation) = $line;
592 592
 				if ($l_lang != $lang) continue;
593 593
 				if (!isset($just_app_file) && $l_app != $app)
594 594
 				{
@@ -629,7 +629,7 @@  discard block
 block discarded – undo
629 629
 			// little sanity check: cached array contains all stock keys, otherwise ignore it
630 630
 			!array_diff_key(self::$load_via, $load_via))
631 631
 		{
632
-			foreach($load_via as $app => $via)
632
+			foreach ($load_via as $app => $via)
633 633
 			{
634 634
 				if (self::$load_via[$app] != $via)
635 635
 				{
@@ -655,15 +655,15 @@  discard block
 block discarded – undo
655 655
 	 * @param boolean $force_read =false force a re-read of the languages
656 656
 	 * @return array with lang-code => descriptiv lang-name pairs
657 657
 	 */
658
-	static function get_available_langs($translate=true, $force_read=false)
658
+	static function get_available_langs($translate = true, $force_read = false)
659 659
 	{
660 660
 		if (!is_array(self::$langs) || $force_read)
661 661
 		{
662
-			if (!($f = fopen($file=EGW_SERVER_ROOT.'/setup/lang/languages','rb')))
662
+			if (!($f = fopen($file = EGW_SERVER_ROOT.'/setup/lang/languages', 'rb')))
663 663
 			{
664 664
 				throw new Exception("List of available languages (%1) missing!", $file);
665 665
 			}
666
-			while(($line = fgetcsv($f, null, "\t")))
666
+			while (($line = fgetcsv($f, null, "\t")))
667 667
 			{
668 668
 				self::$langs[$line[0]] = $line[1];
669 669
 			}
@@ -673,12 +673,12 @@  discard block
 block discarded – undo
673 673
 			{
674 674
 				if (is_null(self::$db)) self::init(false);
675 675
 
676
-				foreach(self::$langs as $lang => $name)
676
+				foreach (self::$langs as $lang => $name)
677 677
 				{
678
-					self::$langs[$lang] = self::translate($name,False,'');
678
+					self::$langs[$lang] = self::translate($name, False, '');
679 679
 				}
680 680
 			}
681
-			uasort(self::$langs,'strcasecmp');
681
+			uasort(self::$langs, 'strcasecmp');
682 682
 		}
683 683
 		return self::$langs;
684 684
 	}
@@ -691,7 +691,7 @@  discard block
 block discarded – undo
691 691
 	 * @param boolean $force_read =false force a re-read of the languages
692 692
 	 * @return array with lang-code => descriptiv lang-name pairs
693 693
 	 */
694
-	static function get_installed_langs($force_read=false)
694
+	static function get_installed_langs($force_read = false)
695 695
 	{
696 696
 		return self::get_available_langs($force_read);
697 697
 	}
@@ -708,7 +708,7 @@  discard block
 block discarded – undo
708 708
 		{
709 709
 			return self::$langs[$lang];
710 710
 		}
711
-		return self::$db->select(self::LANGUAGES_TABLE,'lang_name',array('lang_id' => $lang),__LINE__,__FILE__)->fetchColumn();
711
+		return self::$db->select(self::LANGUAGES_TABLE, 'lang_name', array('lang_id' => $lang), __LINE__, __FILE__)->fetchColumn();
712 712
 	}
713 713
 
714 714
 	/**
@@ -717,20 +717,20 @@  discard block
 block discarded – undo
717 717
 	 * @param boolean $force_read =false
718 718
 	 * @return array with lang_id => lang_name pairs
719 719
 	 */
720
-	static function list_langs($force_read=false)
720
+	static function list_langs($force_read = false)
721 721
 	{
722 722
 		if (!$force_read)
723 723
 		{
724
-			return Cache::getInstance(__CLASS__,'list_langs',array(__CLASS__,'list_langs'),array(true));
724
+			return Cache::getInstance(__CLASS__, 'list_langs', array(__CLASS__, 'list_langs'), array(true));
725 725
 		}
726
-		$languages = self::get_installed_langs();	// available languages
727
-		$availible = "('".implode("','",array_keys($languages))."')";
726
+		$languages = self::get_installed_langs(); // available languages
727
+		$availible = "('".implode("','", array_keys($languages))."')";
728 728
 
729 729
 		// this shows first the installed, then the available and then the rest
730
-		foreach(self::$db->select(self::LANGUAGES_TABLE,array(
731
-			'lang_id','lang_name',
730
+		foreach (self::$db->select(self::LANGUAGES_TABLE, array(
731
+			'lang_id', 'lang_name',
732 732
 			"CASE WHEN lang_id IN $availible THEN 1 ELSE 0 END AS availible",
733
-		),"lang_id NOT IN ('".implode("','",array_keys($languages))."')",__LINE__,__FILE__,false,' ORDER BY availible DESC,lang_name') as $row)
733
+		), "lang_id NOT IN ('".implode("','", array_keys($languages))."')", __LINE__, __FILE__, false, ' ORDER BY availible DESC,lang_name') as $row)
734 734
 		{
735 735
 			$languages[$row['lang_id']] = $row['lang_name'];
736 736
 		}
@@ -744,7 +744,7 @@  discard block
 block discarded – undo
744 744
 	 * @param string $lang language code
745 745
 	 * @return the full path of the filename for the requested app and language
746 746
 	 */
747
-	static function get_lang_file($app,$lang)
747
+	static function get_lang_file($app, $lang)
748 748
 	{
749 749
 		if ($app == 'common') $app = 'phpgwapi';
750 750
 		return EGW_SERVER_ROOT.'/'.$app.'/'.self::LANG_DIR.'/'.self::LANGFILE_PREFIX.$lang.self::LANGFILE_EXTENSION;
@@ -757,7 +757,7 @@  discard block
 block discarded – undo
757 757
 	 */
758 758
 	static function get_installed_charsets()
759 759
 	{
760
-		static $charsets=null;
760
+		static $charsets = null;
761 761
 
762 762
 		if (!isset($charsets))
763 763
 		{
@@ -787,13 +787,13 @@  discard block
 block discarded – undo
787 787
 		static $extra = array(
788 788
 			'&szlig;' => 'ss',
789 789
 		);
790
-		$entities = htmlentities($_str,ENT_QUOTES,self::charset());
790
+		$entities = htmlentities($_str, ENT_QUOTES, self::charset());
791 791
 
792
-		$estr = str_replace(array_keys($extra),array_values($extra), $entities);
793
-		$ustr = preg_replace('/&([aAuUoO])uml;/','\\1e', $estr);	// replace german umlauts with the letter plus one 'e'
794
-		$astr = preg_replace('/&([a-zA-Z])(grave|acute|circ|ring|cedil|tilde|slash|uml);/','\\1', $ustr);	// remove all types of accents
792
+		$estr = str_replace(array_keys($extra), array_values($extra), $entities);
793
+		$ustr = preg_replace('/&([aAuUoO])uml;/', '\\1e', $estr); // replace german umlauts with the letter plus one 'e'
794
+		$astr = preg_replace('/&([a-zA-Z])(grave|acute|circ|ring|cedil|tilde|slash|uml);/', '\\1', $ustr); // remove all types of accents
795 795
 
796
-		return preg_replace('/&([a-zA-Z]+|#[0-9]+|);/','', $astr);	// remove all other entities
796
+		return preg_replace('/&([a-zA-Z]+|#[0-9]+|);/', '', $astr); // remove all other entities
797 797
 	}
798 798
 
799 799
 	/**
@@ -805,7 +805,7 @@  discard block
 block discarded – undo
805 805
 	 * @param boolean $check_to_from =true internal to bypass all charset replacements
806 806
 	 * @return string|array converted string(s) from $data
807 807
 	 */
808
-	static function convert($data,$from=False,$to=False,$check_to_from=true)
808
+	static function convert($data, $from = False, $to = False, $check_to_from = true)
809 809
 	{
810 810
 		if ($check_to_from)
811 811
 		{
@@ -816,7 +816,7 @@  discard block
 block discarded – undo
816 816
 			if (!$from)
817 817
 			{
818 818
 				$from = self::$mbstring ? strtolower(mb_detect_encoding($data)) : 'iso-8859-1';
819
-				if($from == 'ascii')
819
+				if ($from == 'ascii')
820 820
 				{
821 821
 					$from = 'iso-8859-1';
822 822
 				}
@@ -826,7 +826,7 @@  discard block
 block discarded – undo
826 826
 				 php does not seem to support gb2312
827 827
 				 but seems to be able to decode it as EUC-CN
828 828
 			*/
829
-			switch($from)
829
+			switch ($from)
830 830
 			{
831 831
 				case 'ks_c_5601-1987':
832 832
 					$from = 'CP949';
@@ -872,9 +872,9 @@  discard block
 block discarded – undo
872 872
 		}
873 873
 		if (is_array($data))
874 874
 		{
875
-			foreach($data as $key => $str)
875
+			foreach ($data as $key => $str)
876 876
 			{
877
-				$ret[$key] = self::convert($str,$from,$to,false);	// false = bypass the above checks, as they are already done
877
+				$ret[$key] = self::convert($str, $from, $to, false); // false = bypass the above checks, as they are already done
878 878
 			}
879 879
 			return $ret;
880 880
 		}
@@ -886,7 +886,7 @@  discard block
 block discarded – undo
886 886
 		{
887 887
 			return utf8_decode($data);
888 888
 		}
889
-		if (self::$mbstring && !$prefer_iconv && ($data = @mb_convert_encoding($data,$to,$from)) != '')
889
+		if (self::$mbstring && !$prefer_iconv && ($data = @mb_convert_encoding($data, $to, $from)) != '')
890 890
 		{
891 891
 			return $data;
892 892
 		}
@@ -914,12 +914,12 @@  discard block
 block discarded – undo
914 914
 			// in an email on the first Traditional/Japanese/Korean character,
915 915
 			// but in reality when people send mails in GB2312, UMA mostly use
916 916
 			// extended GB13000/GB18030 which allow T/Jap/Korean characters.
917
-			if($from == 'euc-cn')
917
+			if ($from == 'euc-cn')
918 918
 			{
919 919
 				$from = 'gb18030';
920 920
 			}
921 921
 
922
-			if (($convertedData = iconv($from,$to,$data)))
922
+			if (($convertedData = iconv($from, $to, $data)))
923 923
 			{
924 924
 				return $convertedData;
925 925
 			}
@@ -934,9 +934,9 @@  discard block
 block discarded – undo
934 934
 	 * @param string|boolean $from charset $data is in or False if it should be detected
935 935
 	 * @return string|array converted string(s) from $data
936 936
 	 */
937
-	static function convert_jsonsafe($_data,$from=False)
937
+	static function convert_jsonsafe($_data, $from = False)
938 938
 	{
939
-		if ($from===false) $from = self::detect_encoding($_data);
939
+		if ($from === false) $from = self::detect_encoding($_data);
940 940
 
941 941
 		$data = self::convert($_data, strtolower($from));
942 942
 
@@ -945,12 +945,12 @@  discard block
 block discarded – undo
945 945
 		{
946 946
 			$test = @json_encode($data);
947 947
 			//error_log(__METHOD__.__LINE__.' ->'.strlen($data).' Error:'.json_last_error().'<- data:#'.$test.'#');
948
-			if (($test=="null" || $test === false || is_null($test)) && strlen($data)>0)
948
+			if (($test == "null" || $test === false || is_null($test)) && strlen($data) > 0)
949 949
 			{
950 950
 				// try to fix broken utf8
951
-				$x = (function_exists('mb_convert_encoding')?mb_convert_encoding($data,'UTF-8','UTF-8'):(function_exists('iconv')?@iconv("UTF-8","UTF-8//IGNORE",$data):$data));
951
+				$x = (function_exists('mb_convert_encoding') ? mb_convert_encoding($data, 'UTF-8', 'UTF-8') : (function_exists('iconv') ? @iconv("UTF-8", "UTF-8//IGNORE", $data) : $data));
952 952
 				$test = @json_encode($x);
953
-				if (($test=="null" || $test === false || is_null($test)) && strlen($data)>0)
953
+				if (($test == "null" || $test === false || is_null($test)) && strlen($data) > 0)
954 954
 				{
955 955
 					// this should not be needed, unless something fails with charset detection/ wrong charset passed
956 956
 					error_log(__METHOD__.__LINE__.' Charset Reported:'.$from.' Charset Detected:'.self::detect_encoding($data));
@@ -973,36 +973,36 @@  discard block
 block discarded – undo
973 973
 	 * @param string $message_id
974 974
 	 * @param string $content translation or null to delete translation
975 975
 	 */
976
-	static function write($lang,$app,$message_id,$content)
976
+	static function write($lang, $app, $message_id, $content)
977 977
 	{
978 978
 		if ($content)
979 979
 		{
980
-			self::$db->insert(self::LANG_TABLE,array(
980
+			self::$db->insert(self::LANG_TABLE, array(
981 981
 				'content' => $content,
982
-			),array(
982
+			), array(
983 983
 				'lang' => $lang,
984 984
 				'app_name' => $app,
985 985
 				'message_id' => $message_id,
986
-			),__LINE__,__FILE__);
986
+			), __LINE__, __FILE__);
987 987
 		}
988 988
 		else
989 989
 		{
990
-			self::$db->delete(self::LANG_TABLE,array(
990
+			self::$db->delete(self::LANG_TABLE, array(
991 991
 				'lang' => $lang,
992 992
 				'app_name' => $app,
993 993
 				'message_id' => $message_id,
994
-			),__LINE__,__FILE__);
994
+			), __LINE__, __FILE__);
995 995
 		}
996 996
 		// invalidate the cache
997
-		if(!in_array($app,self::$instance_specific_translations))
997
+		if (!in_array($app, self::$instance_specific_translations))
998 998
 		{
999
-			Cache::unsetCache(Cache::TREE,__CLASS__,$app.':'.$lang);
999
+			Cache::unsetCache(Cache::TREE, __CLASS__, $app.':'.$lang);
1000 1000
 		}
1001 1001
 		else
1002 1002
 		{
1003
-			foreach(array_keys((array)self::get_installed_langs()) as $key)
1003
+			foreach (array_keys((array)self::get_installed_langs()) as $key)
1004 1004
 			{
1005
-				Cache::unsetCache(Cache::INSTANCE,__CLASS__,$app.':'.$key);
1005
+				Cache::unsetCache(Cache::INSTANCE, __CLASS__, $app.':'.$key);
1006 1006
 			}
1007 1007
 		}
1008 1008
  	}
@@ -1015,13 +1015,13 @@  discard block
 block discarded – undo
1015 1015
 	 * @param string $message_id
1016 1016
 	 * @return string|boolean content or false if not found
1017 1017
 	 */
1018
-	static function read($lang,$app_name,$message_id)
1018
+	static function read($lang, $app_name, $message_id)
1019 1019
 	{
1020
-		return self::$db->select(self::LANG_TABLE,'content',array(
1020
+		return self::$db->select(self::LANG_TABLE, 'content', array(
1021 1021
 			'lang' => $lang,
1022 1022
 			'app_name' => $app_name,
1023 1023
 			'message_id' => $message_id,
1024
-		),__LINE__,__FILE__)->fetchColumn();
1024
+		), __LINE__, __FILE__)->fetchColumn();
1025 1025
 	}
1026 1026
 
1027 1027
 	/**
@@ -1032,22 +1032,22 @@  discard block
 block discarded – undo
1032 1032
 	 * @param string $lang ='' default check all langs
1033 1033
 	 * @return string
1034 1034
 	 */
1035
-	static function get_message_id($translation,$app=null,$lang=null)
1035
+	static function get_message_id($translation, $app = null, $lang = null)
1036 1036
 	{
1037 1037
 		$where = array('content '.self::$db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.self::$db->quote($translation));
1038 1038
 		if ($app) $where['app_name'] = $app;
1039 1039
 		if ($lang) $where['lang'] = $lang;
1040 1040
 
1041
-		$id = self::$db->select(self::LANG_TABLE,'message_id',$where,__LINE__,__FILE__)->fetchColumn();
1041
+		$id = self::$db->select(self::LANG_TABLE, 'message_id', $where, __LINE__, __FILE__)->fetchColumn();
1042 1042
 
1043 1043
 		// Check cache, since most things aren't in the DB anymore
1044
-		if(!$id)
1044
+		if (!$id)
1045 1045
 		{
1046 1046
 			$ids = array_filter(array_keys(self::$lang_arr), function($haystack) use($translation) {
1047
-				return stripos(self::$lang_arr[$haystack],$translation) !== false;
1047
+				return stripos(self::$lang_arr[$haystack], $translation) !== false;
1048 1048
 			});
1049 1049
 			$id = array_shift($ids);
1050
-			if(!$id && ($lang && $lang !== 'en' || self::$userlang != 'en'))
1050
+			if (!$id && ($lang && $lang !== 'en' || self::$userlang != 'en'))
1051 1051
 			{
1052 1052
 				// Try english
1053 1053
 				if (in_array($app, self::$instance_specific_translations))
@@ -1064,7 +1064,7 @@  discard block
 block discarded – undo
1064 1064
 				if ($instance_level) $lang_arr = Cache::getInstance(__CLASS__, $instance_level);
1065 1065
 				$lang_arr = $lang_arr[$app.':en'];
1066 1066
 				$ids = array_filter(array_keys($lang_arr), function($haystack) use($translation, $lang_arr) {
1067
-					return stripos($lang_arr[$haystack],$translation) !== false;
1067
+					return stripos($lang_arr[$haystack], $translation) !== false;
1068 1068
 				});
1069 1069
 				$id = array_shift($ids);
1070 1070
 			}
@@ -1081,7 +1081,7 @@  discard block
 block discarded – undo
1081 1081
 	 * @param string $verify =null encoding to verify, get checked first and have a match for only ascii or no detection available
1082 1082
 	 * @return string - encoding
1083 1083
 	 */
1084
-	static function detect_encoding($string, $verify=null)
1084
+	static function detect_encoding($string, $verify = null)
1085 1085
 	{
1086 1086
 		if (function_exists('iconv'))
1087 1087
 		{
@@ -1104,7 +1104,7 @@  discard block
 block discarded – undo
1104 1104
 		}
1105 1105
 		if ($verify && (!isset($detected) || $detected === 'ascii'))
1106 1106
 		{
1107
-			return $verify;	// ascii matches all charsets
1107
+			return $verify; // ascii matches all charsets
1108 1108
 		}
1109 1109
 		return isset($detected) ? $detected : 'iso-8859-1'; // we choose to return iso-8859-1 as default
1110 1110
 	}
Please login to merge, or discard this patch.
Braces   +121 added lines, -31 removed lines patch added patch discarded remove patch
@@ -126,17 +126,23 @@  discard block
 block discarded – undo
126 126
 			}
127 127
 			return $charsets[$lang];
128 128
 		}
129
-		if (self::$system_charset)	// do we have a system-charset ==> return it
129
+		if (self::$system_charset)
130
+		{
131
+			// do we have a system-charset ==> return it
130 132
 		{
131 133
 			$charset = self::$system_charset;
132 134
 		}
135
+		}
133 136
 		else
134 137
 		{
135 138
 			// if no translations are loaded (system-startup) use a default, else lang('charset')
136 139
 			$charset = !self::$lang_arr ? 'utf-8' : strtolower(self::translate('charset'));
137 140
 		}
138 141
 		// in case no charset is set, default to utf-8
139
-		if (empty($charset) || $charset == 'charset') $charset = 'utf-8';
142
+		if (empty($charset) || $charset == 'charset')
143
+		{
144
+			$charset = 'utf-8';
145
+		}
140 146
 
141 147
 		// we need to set our charset as mbstring.internal_encoding if mbstring.func_overlaod > 0
142 148
 		// else we get problems for a charset is different from the default utf-8
@@ -195,8 +201,14 @@  discard block
 block discarded – undo
195 201
 			}
196 202
 			$apps = array('common');
197 203
 			// for eTemplate apps, load etemplate before app itself (allowing app to overwrite etemplate translations)
198
-			if (class_exists('EGroupware\\Api\\Etemplate', false) || class_exists('etemplate', false)) $apps[] = 'etemplate';
199
-			if ($GLOBALS['egw_info']['flags']['currentapp']) $apps[] = $GLOBALS['egw_info']['flags']['currentapp'];
204
+			if (class_exists('EGroupware\\Api\\Etemplate', false) || class_exists('etemplate', false))
205
+			{
206
+				$apps[] = 'etemplate';
207
+			}
208
+			if ($GLOBALS['egw_info']['flags']['currentapp'])
209
+			{
210
+				$apps[] = $GLOBALS['egw_info']['flags']['currentapp'];
211
+			}
200 212
 			// load instance specific translations last, so they can overwrite everything
201 213
 			$apps[] = 'custom';
202 214
 			self::add_app($apps);
@@ -224,7 +236,10 @@  discard block
 block discarded – undo
224 236
 			self::init();
225 237
 		}
226 238
 		$ret = $key;				// save key if we dont find a translation
227
-		if ($not_found) $ret .= $not_found;
239
+		if ($not_found)
240
+		{
241
+			$ret .= $not_found;
242
+		}
228 243
 
229 244
 		if (isset(self::$lang_arr[$key]))
230 245
 		{
@@ -271,9 +286,15 @@  discard block
 block discarded – undo
271 286
 	{
272 287
 		//error_log(__METHOD__."(".array2string($apps).", $lang) count(self::\$lang_arr)=".count(self::$lang_arr));
273 288
 		//$start = microtime(true);
274
-		if (!$lang) $lang = self::$userlang;
289
+		if (!$lang)
290
+		{
291
+			$lang = self::$userlang;
292
+		}
275 293
 		$tree_level = $instance_level = array();
276
-		if (!is_array($apps)) $apps = (array)$apps;
294
+		if (!is_array($apps))
295
+		{
296
+			$apps = (array)$apps;
297
+		}
277 298
 		foreach($apps as $key => $app)
278 299
 		{
279 300
 			if (!isset(self::$loaded_apps[$app]) || self::$loaded_apps[$app] != $lang && $app != 'common')
@@ -293,8 +314,14 @@  discard block
 block discarded – undo
293 314
 			}
294 315
 		}
295 316
 		// load all translations from cache at once
296
-		if ($tree_level) $tree_level = Cache::getTree(__CLASS__, $tree_level);
297
-		if ($instance_level) $instance_level = Cache::getInstance(__CLASS__, $instance_level);
317
+		if ($tree_level)
318
+		{
319
+			$tree_level = Cache::getTree(__CLASS__, $tree_level);
320
+		}
321
+		if ($instance_level)
322
+		{
323
+			$instance_level = Cache::getInstance(__CLASS__, $instance_level);
324
+		}
298 325
 
299 326
 		// merging loaded translations together
300 327
 		$updated_load_via = false;
@@ -361,7 +388,10 @@  discard block
 block discarded – undo
361 388
 	static function &load_app($app,$lang)
362 389
 	{
363 390
 		//$start = microtime(true);
364
-		if (is_null(self::$db)) self::init(false);
391
+		if (is_null(self::$db))
392
+		{
393
+			self::init(false);
394
+		}
365 395
 		$loaded = array();
366 396
 		foreach(self::$db->select(self::LANG_TABLE,'message_id,content',array(
367 397
 			'lang'		=> $lang,
@@ -467,7 +497,10 @@  discard block
 block discarded – undo
467 497
 				$cache['']['en'] = count($en_phrases);
468 498
 				foreach(array_keys(self::get_available_langs()) as $lang)
469 499
 				{
470
-					if ($lang == 'en') continue;
500
+					if ($lang == 'en')
501
+					{
502
+						continue;
503
+					}
471 504
 					$lang_phrases = array_keys(self::load_app_files(null, $lang, 'all-apps'));
472 505
 					$valid_phrases = array_intersect($lang_phrases, $en_phrases);
473 506
 					$cache[''][$lang] = count($valid_phrases);
@@ -484,7 +517,10 @@  discard block
 block discarded – undo
484 517
 						continue;
485 518
 					}
486 519
 					$en_phrases = array_keys(self::load_app_files(null, 'en', $app));
487
-					if (count($en_phrases) <= 2) continue;
520
+					if (count($en_phrases) <= 2)
521
+					{
522
+						continue;
523
+					}
488 524
 					$cache['en'][$app] = count($en_phrases);
489 525
 					$lang_phrases = array_keys(self::load_app_files(null, $_lang, $app));
490 526
 					$valid_phrases = array_intersect($lang_phrases, $en_phrases);
@@ -516,7 +552,10 @@  discard block
 block discarded – undo
516 552
 			// check if cache is NOT invalided by checking if we have a modification time for concerned lang-file
517 553
 			$time = Cache::getTree(__CLASS__, $file=self::get_lang_file($_app, $_lang));
518 554
 			// if we dont have one, cache has been invalidated and we need to load translations
519
-			if (!isset($time)) self::add_app($_app, $_lang);
555
+			if (!isset($time))
556
+			{
557
+				self::add_app($_app, $_lang);
558
+			}
520 559
 
521 560
 			$etag = self::max_lang_time();
522 561
 		}
@@ -568,7 +607,11 @@  discard block
 block discarded – undo
568 607
 		$loaded = array();
569 608
 		foreach($load_app == 'all-apps' ? scandir(EGW_SERVER_ROOT) : (array)$load_app as $app_dir)
570 609
 		{
571
-			if ($load_app == 'all-apps' && $app_dir=='..') continue; // do not try to break out of egw server root
610
+			if ($load_app == 'all-apps' && $app_dir=='..')
611
+			{
612
+				continue;
613
+			}
614
+			// do not try to break out of egw server root
572 615
 			if ($app_dir[0] == '.' || !is_dir(EGW_SERVER_ROOT.'/'.$app_dir) ||
573 616
 				!@file_exists($file=self::get_lang_file($app_dir, $lang)) ||
574 617
 				!($f = fopen($file, 'r')))
@@ -587,9 +630,15 @@  discard block
 block discarded – undo
587 630
 			{
588 631
 				$line = explode("\t", trim($read));
589 632
 				++$line_nr;
590
-				if (count($line) != 4) continue;
633
+				if (count($line) != 4)
634
+				{
635
+					continue;
636
+				}
591 637
 				list($l_id,$l_app,$l_lang,$l_translation) = $line;
592
-				if ($l_lang != $lang) continue;
638
+				if ($l_lang != $lang)
639
+				{
640
+					continue;
641
+				}
593 642
 				if (!isset($just_app_file) && $l_app != $app)
594 643
 				{
595 644
 					// check if $l_app contained in file in $app_dir is mentioned in $load_via
@@ -603,8 +652,14 @@  discard block
 block discarded – undo
603 652
 						}
604 653
 						// if not update load_via accordingly and store it as config
605 654
 						//error_log(__METHOD__."() load_via does not contain $l_app => $app_dir");
606
-						if (!isset(self::$load_via[$l_app])) self::$load_via[$l_app] = array($l_app);
607
-						if (!is_array(self::$load_via[$l_app])) self::$load_via[$l_app] = array(self::$load_via[$l_app]);
655
+						if (!isset(self::$load_via[$l_app]))
656
+						{
657
+							self::$load_via[$l_app] = array($l_app);
658
+						}
659
+						if (!is_array(self::$load_via[$l_app]))
660
+						{
661
+							self::$load_via[$l_app] = array(self::$load_via[$l_app]);
662
+						}
608 663
 						self::$load_via[$l_app][] = $app_dir;
609 664
 						$updated_load_via = true;
610 665
 					}
@@ -671,7 +726,10 @@  discard block
 block discarded – undo
671 726
 
672 727
 			if ($translate)
673 728
 			{
674
-				if (is_null(self::$db)) self::init(false);
729
+				if (is_null(self::$db))
730
+				{
731
+					self::init(false);
732
+				}
675 733
 
676 734
 				foreach(self::$langs as $lang => $name)
677 735
 				{
@@ -704,10 +762,13 @@  discard block
 block discarded – undo
704 762
 	 */
705 763
 	static function lang2language($lang)
706 764
 	{
707
-		if (isset(self::$langs[$lang]))	// no need to query the DB
765
+		if (isset(self::$langs[$lang]))
766
+		{
767
+			// no need to query the DB
708 768
 		{
709 769
 			return self::$langs[$lang];
710 770
 		}
771
+		}
711 772
 		return self::$db->select(self::LANGUAGES_TABLE,'lang_name',array('lang_id' => $lang),__LINE__,__FILE__)->fetchColumn();
712 773
 	}
713 774
 
@@ -746,7 +807,10 @@  discard block
 block discarded – undo
746 807
 	 */
747 808
 	static function get_lang_file($app,$lang)
748 809
 	{
749
-		if ($app == 'common') $app = 'phpgwapi';
810
+		if ($app == 'common')
811
+		{
812
+			$app = 'phpgwapi';
813
+		}
750 814
 		return EGW_SERVER_ROOT.'/'.$app.'/'.self::LANG_DIR.'/'.self::LANGFILE_PREFIX.$lang.self::LANGFILE_EXTENSION;
751 815
 	}
752 816
 
@@ -809,9 +873,15 @@  discard block
 block discarded – undo
809 873
 	{
810 874
 		if ($check_to_from)
811 875
 		{
812
-			if ($from) $from = strtolower($from);
876
+			if ($from)
877
+			{
878
+				$from = strtolower($from);
879
+			}
813 880
 
814
-			if ($to) $to = strtolower($to);
881
+			if ($to)
882
+			{
883
+				$to = strtolower($to);
884
+			}
815 885
 
816 886
 			if (!$from)
817 887
 			{
@@ -936,7 +1006,10 @@  discard block
 block discarded – undo
936 1006
 	 */
937 1007
 	static function convert_jsonsafe($_data,$from=False)
938 1008
 	{
939
-		if ($from===false) $from = self::detect_encoding($_data);
1009
+		if ($from===false)
1010
+		{
1011
+			$from = self::detect_encoding($_data);
1012
+		}
940 1013
 
941 1014
 		$data = self::convert($_data, strtolower($from));
942 1015
 
@@ -1035,15 +1108,22 @@  discard block
 block discarded – undo
1035 1108
 	static function get_message_id($translation,$app=null,$lang=null)
1036 1109
 	{
1037 1110
 		$where = array('content '.self::$db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.self::$db->quote($translation));
1038
-		if ($app) $where['app_name'] = $app;
1039
-		if ($lang) $where['lang'] = $lang;
1111
+		if ($app)
1112
+		{
1113
+			$where['app_name'] = $app;
1114
+		}
1115
+		if ($lang)
1116
+		{
1117
+			$where['lang'] = $lang;
1118
+		}
1040 1119
 
1041 1120
 		$id = self::$db->select(self::LANG_TABLE,'message_id',$where,__LINE__,__FILE__)->fetchColumn();
1042 1121
 
1043 1122
 		// Check cache, since most things aren't in the DB anymore
1044 1123
 		if(!$id)
1045 1124
 		{
1046
-			$ids = array_filter(array_keys(self::$lang_arr), function($haystack) use($translation) {
1125
+			$ids = array_filter(array_keys(self::$lang_arr), function($haystack) use($translation)
1126
+			{
1047 1127
 				return stripos(self::$lang_arr[$haystack],$translation) !== false;
1048 1128
 			});
1049 1129
 			$id = array_shift($ids);
@@ -1060,10 +1140,17 @@  discard block
 block discarded – undo
1060 1140
 				}
1061 1141
 
1062 1142
 				// load all translations from cache at once
1063
-				if ($tree_level) $lang_arr = Cache::getTree(__CLASS__, $tree_level);
1064
-				if ($instance_level) $lang_arr = Cache::getInstance(__CLASS__, $instance_level);
1143
+				if ($tree_level)
1144
+				{
1145
+					$lang_arr = Cache::getTree(__CLASS__, $tree_level);
1146
+				}
1147
+				if ($instance_level)
1148
+				{
1149
+					$lang_arr = Cache::getInstance(__CLASS__, $instance_level);
1150
+				}
1065 1151
 				$lang_arr = $lang_arr[$app.':en'];
1066
-				$ids = array_filter(array_keys($lang_arr), function($haystack) use($translation, $lang_arr) {
1152
+				$ids = array_filter(array_keys($lang_arr), function($haystack) use($translation, $lang_arr)
1153
+				{
1067 1154
 					return stripos($lang_arr[$haystack],$translation) !== false;
1068 1155
 				});
1069 1156
 				$id = array_shift($ids);
@@ -1087,7 +1174,10 @@  discard block
 block discarded – undo
1087 1174
 		{
1088 1175
 			$list = array('utf-8', 'iso-8859-1', 'windows-1251'); // list may be extended
1089 1176
 
1090
-			if ($verify) array_unshift($list, $verify);
1177
+			if ($verify)
1178
+			{
1179
+				array_unshift($list, $verify);
1180
+			}
1091 1181
 
1092 1182
 			foreach ($list as $item)
1093 1183
 			{
Please login to merge, or discard this patch.
api/src/Vfs.php 5 patches
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
 	 * dir working on just the eGW VFS: returns directory object
153 153
 	 *
154 154
 	 * @param string $path filename with absolute path in the eGW VFS
155
-	 * @return Directory
155
+	 * @return \Directory
156 156
 	 */
157 157
 	static function dir($path)
158 158
 	{
@@ -1295,7 +1295,7 @@  discard block
 block discarded – undo
1295 1295
 	 * Also works around PHP under Windows returning dirname('/something') === '\\', which is NOT understood by EGroupware's VFS!
1296 1296
 	 *
1297 1297
 	 * @param string $_url path or url
1298
-	 * @return string|boolean parent or false if there's none ($path == '/')
1298
+	 * @return false|string parent or false if there's none ($path == '/')
1299 1299
 	 */
1300 1300
 	static function dirname($_url)
1301 1301
 	{
@@ -1719,7 +1719,7 @@  discard block
 block discarded – undo
1719 1719
 	 * checkLock() helper
1720 1720
 	 *
1721 1721
 	 * @param  string resource path to check for locks
1722
-	 * @return array|boolean false if there's no lock, else array with lock info
1722
+	 * @return string|null false if there's no lock, else array with lock info
1723 1723
 	 */
1724 1724
 	static function checkLock($path)
1725 1725
 	{
@@ -1935,7 +1935,7 @@  discard block
 block discarded – undo
1935 1935
 	/**
1936 1936
 	 * Copies the files given in $src to $dst.
1937 1937
 	 *
1938
-	 * @param array $src contains the source file
1938
+	 * @param string[] $src contains the source file
1939 1939
 	 * @param string $dst is the destination directory
1940 1940
 	 * @param int& $errs =null on return number of errors happened
1941 1941
 	 * @param array& $copied =null on return files copied
Please login to merge, or discard this patch.
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -672,7 +672,7 @@  discard block
 block discarded – undo
672 672
 			return;	// not found, should not happen
673 673
 		}
674 674
 		if ($type && (($type == 'd') == !($stat['mode'] & Vfs\Sqlfs\StreamWrapper::MODE_DIR) ||	// != is_dir() which can be true for symlinks
675
-		    $type == 'F' && is_dir($path)))	// symlink to a directory
675
+			$type == 'F' && is_dir($path)))	// symlink to a directory
676 676
 		{
677 677
 			return;	// wrong type
678 678
 		}
@@ -1621,13 +1621,13 @@  discard block
 block discarded – undo
1621 1621
 		{
1622 1622
 			return false;
1623 1623
 		}
1624
-    	// remove the lock info evtl. set in the cache
1625
-    	unset(self::$lock_cache[$path]);
1624
+		// remove the lock info evtl. set in the cache
1625
+		unset(self::$lock_cache[$path]);
1626 1626
 
1627
-    	if ($timeout < 1000000)	// < 1000000 is a relative timestamp, so we add the current time
1628
-    	{
1629
-    		$timeout += time();
1630
-    	}
1627
+		if ($timeout < 1000000)	// < 1000000 is a relative timestamp, so we add the current time
1628
+		{
1629
+			$timeout += time();
1630
+		}
1631 1631
 
1632 1632
 		if ($update)	// Lock Update
1633 1633
 		{
@@ -1688,32 +1688,32 @@  discard block
 block discarded – undo
1688 1688
 		return $ret;
1689 1689
 	}
1690 1690
 
1691
-    /**
1692
-     * unlock a ressource/path
1693
-     *
1694
-     * @param string $path path to unlock
1695
-     * @param string $token locktoken
1691
+	/**
1692
+	 * unlock a ressource/path
1693
+	 *
1694
+	 * @param string $path path to unlock
1695
+	 * @param string $token locktoken
1696 1696
 	 * @param boolean $check_writable =true should we check if the ressource is writable, before granting locks, default yes
1697
-     * @return boolean true on success
1698
-     */
1699
-    static function unlock($path,$token,$check_writable=true)
1700
-    {
1697
+	 * @return boolean true on success
1698
+	 */
1699
+	static function unlock($path,$token,$check_writable=true)
1700
+	{
1701 1701
 		// we require write rights to lock/unlock a resource
1702 1702
 		if ($check_writable && !self::is_writable($path))
1703 1703
 		{
1704 1704
 			return false;
1705 1705
 		}
1706
-        if (($ret = self::$db->delete(self::LOCK_TABLE,array(
1707
-        	'lock_path' => $path,
1708
-        	'lock_token' => $token,
1709
-        ),__LINE__,__FILE__) && self::$db->affected_rows()))
1710
-        {
1711
-        	// remove the lock from the cache too
1712
-        	unset(self::$lock_cache[$path]);
1713
-        }
1706
+		if (($ret = self::$db->delete(self::LOCK_TABLE,array(
1707
+			'lock_path' => $path,
1708
+			'lock_token' => $token,
1709
+		),__LINE__,__FILE__) && self::$db->affected_rows()))
1710
+		{
1711
+			// remove the lock from the cache too
1712
+			unset(self::$lock_cache[$path]);
1713
+		}
1714 1714
 		if (self::LOCK_DEBUG) error_log(__METHOD__."($path,$token,$check_writable) returns ".($ret ? 'true' : 'false'));
1715 1715
 		return $ret;
1716
-    }
1716
+	}
1717 1717
 
1718 1718
 	/**
1719 1719
 	 * checkLock() helper
@@ -1741,13 +1741,13 @@  discard block
 block discarded – undo
1741 1741
 		}
1742 1742
 		if ($result && $result['expires'] < time())	// lock is expired --> remove it
1743 1743
 		{
1744
-	        self::$db->delete(self::LOCK_TABLE,array(
1745
-	        	'lock_path' => $result['path'],
1746
-	        	'lock_token' => $result['token'],
1747
-	        ),__LINE__,__FILE__);
1744
+			self::$db->delete(self::LOCK_TABLE,array(
1745
+				'lock_path' => $result['path'],
1746
+				'lock_token' => $result['token'],
1747
+			),__LINE__,__FILE__);
1748 1748
 
1749 1749
 			if (self::LOCK_DEBUG) error_log(__METHOD__."($path) lock is expired at ".date('Y-m-d H:i:s',$result['expires'])." --> removed");
1750
-	        $result = false;
1750
+			$result = false;
1751 1751
 		}
1752 1752
 		if (self::LOCK_DEBUG) error_log(__METHOD__."($path) returns ".($result?array2string($result):'false'));
1753 1753
 		return self::$lock_cache[$path] = $result;
@@ -1887,9 +1887,9 @@  discard block
 block discarded – undo
1887 1887
 			$image = Image::find($mime_sub, 'navbar');
1888 1888
 		}
1889 1889
 		else if ($file && $mime_main == 'image' && in_array($mime_sub, array('png','jpeg','jpg','gif','bmp')) &&
1890
-		         (string)$GLOBALS['egw_info']['server']['link_list_thumbnail'] != '0' &&
1891
-		         (string)$GLOBALS['egw_info']['user']['preferences']['common']['link_list_thumbnail'] != '0' &&
1892
-		         ($stat = self::stat($file)) && $stat['size'] < 1500000)
1890
+				 (string)$GLOBALS['egw_info']['server']['link_list_thumbnail'] != '0' &&
1891
+				 (string)$GLOBALS['egw_info']['user']['preferences']['common']['link_list_thumbnail'] != '0' &&
1892
+				 ($stat = self::stat($file)) && $stat['size'] < 1500000)
1893 1893
 		{
1894 1894
 			if (substr($file, 0, 6) == '/apps/')
1895 1895
 			{
Please login to merge, or discard this patch.
Spacing   +269 added lines, -273 removed lines patch added patch discarded remove patch
@@ -124,13 +124,13 @@  discard block
 block discarded – undo
124 124
 	 * @param string $mode 'r', 'w', ... like fopen
125 125
 	 * @return resource
126 126
 	 */
127
-	static function fopen($path,$mode)
127
+	static function fopen($path, $mode)
128 128
 	{
129 129
 		if ($path[0] != '/')
130 130
 		{
131 131
 			throw new Exception\AssertionFailed("Filename '$path' is not an absolute path!");
132 132
 		}
133
-		return fopen(self::PREFIX.$path,$mode);
133
+		return fopen(self::PREFIX.$path, $mode);
134 134
 	}
135 135
 
136 136
 	/**
@@ -170,13 +170,13 @@  discard block
 block discarded – undo
170 170
 	 * @param int $sorting_order =0 !$sorting_order (default) alphabetical in ascending order, $sorting_order alphabetical in descending order.
171 171
 	 * @return array
172 172
 	 */
173
-	static function scandir($path,$sorting_order=0)
173
+	static function scandir($path, $sorting_order = 0)
174 174
 	{
175 175
 		if ($path[0] != '/')
176 176
 		{
177 177
 			throw new Exception\AssertionFailed("Directory '$path' is not an absolute path!");
178 178
 		}
179
-		return scandir(self::PREFIX.$path,$sorting_order);
179
+		return scandir(self::PREFIX.$path, $sorting_order);
180 180
 	}
181 181
 
182 182
 	/**
@@ -186,22 +186,22 @@  discard block
 block discarded – undo
186 186
 	 * @param string $to
187 187
 	 * @return boolean
188 188
 	 */
189
-	static function copy($from,$to)
189
+	static function copy($from, $to)
190 190
 	{
191
-		$old_props = self::file_exists($to) ? self::propfind($to,null) : array();
191
+		$old_props = self::file_exists($to) ? self::propfind($to, null) : array();
192 192
 		// copy properties (eg. file comment), if there are any and evtl. existing old properties
193
-		$props = self::propfind($from,null);
193
+		$props = self::propfind($from, null);
194 194
 
195
-		foreach($old_props as $prop)
195
+		foreach ($old_props as $prop)
196 196
 		{
197
-			if (!self::find_prop($props,$prop))
197
+			if (!self::find_prop($props, $prop))
198 198
 			{
199
-				$prop['val'] = null;	// null = delete prop
199
+				$prop['val'] = null; // null = delete prop
200 200
 				$props[] = $prop;
201 201
 			}
202 202
 		}
203 203
 		// using self::copy_uploaded() to treat copying incl. properties as atomar operation in respect of notifications
204
-		return self::copy_uploaded(self::PREFIX.$from,$to,$props,false);	// false = no is_uploaded_file check!
204
+		return self::copy_uploaded(self::PREFIX.$from, $to, $props, false); // false = no is_uploaded_file check!
205 205
 	}
206 206
 
207 207
 	/**
@@ -212,14 +212,14 @@  discard block
 block discarded – undo
212 212
 	 * @param string $ns =self::DEFAULT_PROP_NAMESPACE namespace, only if $prop is no array
213 213
 	 * @return &array reference to property in $props or null if not found
214 214
 	 */
215
-	static function &find_prop(array &$props,$name,$ns=self::DEFAULT_PROP_NAMESPACE)
215
+	static function &find_prop(array &$props, $name, $ns = self::DEFAULT_PROP_NAMESPACE)
216 216
 	{
217 217
 		if (is_array($name))
218 218
 		{
219 219
 			$ns = $name['ns'];
220 220
 			$name = $name['name'];
221 221
 		}
222
-		foreach($props as &$prop)
222
+		foreach ($props as &$prop)
223 223
 		{
224 224
 			if ($prop['name'] == $name && $prop['ns'] == $ns) return $prop;
225 225
 		}
@@ -233,15 +233,15 @@  discard block
 block discarded – undo
233 233
 	 * @param boolean $try_create_home =false should a non-existing home-directory be automatically created
234 234
 	 * @return array
235 235
 	 */
236
-	static function stat($path,$try_create_home=false)
236
+	static function stat($path, $try_create_home = false)
237 237
 	{
238 238
 		if ($path[0] != '/')
239 239
 		{
240 240
 			throw new Exception\AssertionFailed("File '$path' is not an absolute path!");
241 241
 		}
242
-		if (($stat = self::url_stat($path,0,$try_create_home)))
242
+		if (($stat = self::url_stat($path, 0, $try_create_home)))
243 243
 		{
244
-			$stat = array_slice($stat,13);	// remove numerical indices 0-12
244
+			$stat = array_slice($stat, 13); // remove numerical indices 0-12
245 245
 		}
246 246
 		return $stat;
247 247
 	}
@@ -253,15 +253,15 @@  discard block
 block discarded – undo
253 253
 	 * @param boolean $try_create_home =false should a non-existing home-directory be automatically created
254 254
 	 * @return array
255 255
 	 */
256
-	static function lstat($path,$try_create_home=false)
256
+	static function lstat($path, $try_create_home = false)
257 257
 	{
258 258
 		if ($path[0] != '/')
259 259
 		{
260 260
 			throw new Exception\AssertionFailed("File '$path' is not an absolute path!");
261 261
 		}
262
-		if (($stat = self::url_stat($path,STREAM_URL_STAT_LINK,$try_create_home)))
262
+		if (($stat = self::url_stat($path, STREAM_URL_STAT_LINK, $try_create_home)))
263 263
 		{
264
-			$stat = array_slice($stat,13);	// remove numerical indices 0-12
264
+			$stat = array_slice($stat, 13); // remove numerical indices 0-12
265 265
 		}
266 266
 		return $stat;
267 267
 	}
@@ -312,9 +312,9 @@  discard block
 block discarded – undo
312 312
 	 * @param boolean $clear_fstab =false true clear current fstab, false (default) only add given mount
313 313
 	 * @return array|boolean array with fstab, if called without parameter or true on successful mount
314 314
 	 */
315
-	static function mount($url=null,$path=null,$check_url=null,$persitent_mount=true,$clear_fstab=false)
315
+	static function mount($url = null, $path = null, $check_url = null, $persitent_mount = true, $clear_fstab = false)
316 316
 	{
317
-		if (is_null($check_url)) $check_url = strpos($url,'$') === false;
317
+		if (is_null($check_url)) $check_url = strpos($url, '$') === false;
318 318
 
319 319
 		if (!isset($GLOBALS['egw_info']['server']['vfs_fstab']))	// happens eg. in setup
320 320
 		{
@@ -340,7 +340,7 @@  discard block
 block discarded – undo
340 340
 		if (!self::$is_root)
341 341
 		{
342 342
 			if (self::LOG_LEVEL > 0) error_log(__METHOD__.'('.array2string($url).','.array2string($path).') permission denied, you are NOT root!');
343
-			return false;	// only root can mount
343
+			return false; // only root can mount
344 344
 		}
345 345
 		if ($clear_fstab)
346 346
 		{
@@ -349,14 +349,14 @@  discard block
 block discarded – undo
349 349
 		if (isset(self::$fstab[$path]) && self::$fstab[$path] === $url)
350 350
 		{
351 351
 			if (self::LOG_LEVEL > 0) error_log(__METHOD__.'('.array2string($url).','.array2string($path).') already mounted.');
352
-			return true;	// already mounted
352
+			return true; // already mounted
353 353
 		}
354
-		self::load_wrapper(self::parse_url($url,PHP_URL_SCHEME));
354
+		self::load_wrapper(self::parse_url($url, PHP_URL_SCHEME));
355 355
 
356 356
 		if ($check_url && (!file_exists($url) || opendir($url) === false))
357 357
 		{
358 358
 			if (self::LOG_LEVEL > 0) error_log(__METHOD__.'('.array2string($url).','.array2string($path).') url does NOT exist!');
359
-			return false;	// url does not exist
359
+			return false; // url does not exist
360 360
 		}
361 361
 		self::$fstab[$path] = $url;
362 362
 
@@ -367,10 +367,10 @@  discard block
 block discarded – undo
367 367
 
368 368
 		if ($persitent_mount)
369 369
 		{
370
-			Config::save_value('vfs_fstab',self::$fstab,'phpgwapi');
370
+			Config::save_value('vfs_fstab', self::$fstab, 'phpgwapi');
371 371
 			$GLOBALS['egw_info']['server']['vfs_fstab'] = self::$fstab;
372 372
 			// invalidate session cache
373
-			if (method_exists($GLOBALS['egw'],'invalidate_session_cache'))	// egw object in setup is limited
373
+			if (method_exists($GLOBALS['egw'], 'invalidate_session_cache'))	// egw object in setup is limited
374 374
 			{
375 375
 				$GLOBALS['egw']->invalidate_session_cache();
376 376
 			}
@@ -389,19 +389,19 @@  discard block
 block discarded – undo
389 389
 		if (!self::$is_root)
390 390
 		{
391 391
 			if (self::LOG_LEVEL > 0) error_log(__METHOD__.'('.array2string($path).','.array2string($path).') permission denied, you are NOT root!');
392
-			return false;	// only root can mount
392
+			return false; // only root can mount
393 393
 		}
394
-		if (!isset(self::$fstab[$path]) && ($path = array_search($path,self::$fstab)) === false)
394
+		if (!isset(self::$fstab[$path]) && ($path = array_search($path, self::$fstab)) === false)
395 395
 		{
396 396
 			if (self::LOG_LEVEL > 0) error_log(__METHOD__.'('.array2string($path).') NOT mounted!');
397
-			return false;	// $path not mounted
397
+			return false; // $path not mounted
398 398
 		}
399 399
 		unset(self::$fstab[$path]);
400 400
 
401
-		Config::save_value('vfs_fstab',self::$fstab,'phpgwapi');
401
+		Config::save_value('vfs_fstab', self::$fstab, 'phpgwapi');
402 402
 		$GLOBALS['egw_info']['server']['vfs_fstab'] = self::$fstab;
403 403
 		// invalidate session cache
404
-		if (method_exists($GLOBALS['egw'],'invalidate_session_cache'))	// egw object in setup is limited
404
+		if (method_exists($GLOBALS['egw'], 'invalidate_session_cache'))	// egw object in setup is limited
405 405
 		{
406 406
 			$GLOBALS['egw']->invalidate_session_cache();
407 407
 		}
@@ -416,7 +416,7 @@  discard block
 block discarded – undo
416 416
 	 * @param boolean $allow_versions =false allow .versions or .attic
417 417
 	 * @return boolean
418 418
 	 */
419
-	public static function is_hidden($path, $allow_versions=false)
419
+	public static function is_hidden($path, $allow_versions = false)
420 420
 	{
421 421
 		$file = self::basename($path);
422 422
 
@@ -452,30 +452,30 @@  discard block
 block discarded – undo
452 452
 	 * @param array $exec_params =null further params for exec as array, path is always the first param and stat the last!
453 453
 	 * @return array of pathes if no $exec, otherwise path => stat pairs
454 454
 	 */
455
-	static function find($base,$options=null,$exec=null,$exec_params=null)
455
+	static function find($base, $options = null, $exec = null, $exec_params = null)
456 456
 	{
457 457
 		//error_log(__METHOD__."(".print_r($base,true).",".print_r($options,true).",".print_r($exec,true).",".print_r($exec_params,true).")\n");
458 458
 
459
-		$type = $options['type'];	// 'd', 'f' or 'F'
460
-		$dirs_last = $options['depth'];	// put content of dirs before the dir itself
459
+		$type = $options['type']; // 'd', 'f' or 'F'
460
+		$dirs_last = $options['depth']; // put content of dirs before the dir itself
461 461
 		// show dirs on top by default, if no recursive listing (allways disabled if $type specified, as unnecessary)
462
-		$dirsontop = !$type && (isset($options['dirsontop']) ? (boolean)$options['dirsontop'] : isset($options['maxdepth'])&&$options['maxdepth']>0);
463
-		if ($dirsontop) $options['need_mime'] = true;	// otherwise dirsontop can NOT work
462
+		$dirsontop = !$type && (isset($options['dirsontop']) ? (boolean)$options['dirsontop'] : isset($options['maxdepth']) && $options['maxdepth'] > 0);
463
+		if ($dirsontop) $options['need_mime'] = true; // otherwise dirsontop can NOT work
464 464
 
465 465
 		// process some of the options (need to be done only once)
466 466
 		if (isset($options['name']) && !isset($options['name_preg']))	// change from simple *,? wildcards to preg regular expression once
467 467
 		{
468
-			$options['name_preg'] = '/^'.str_replace(array('\\?','\\*'),array('.{1}','.*'),preg_quote($options['name'])).'$/i';
468
+			$options['name_preg'] = '/^'.str_replace(array('\\?', '\\*'), array('.{1}', '.*'), preg_quote($options['name'])).'$/i';
469 469
 		}
470 470
 		if (isset($options['path']) && !isset($options['preg_path']))	// change from simple *,? wildcards to preg regular expression once
471 471
 		{
472
-			$options['path_preg'] = '/^'.str_replace(array('\\?','\\*'),array('.{1}','.*'),preg_quote($options['path'])).'$/i';
472
+			$options['path_preg'] = '/^'.str_replace(array('\\?', '\\*'), array('.{1}', '.*'), preg_quote($options['path'])).'$/i';
473 473
 		}
474 474
 		if (!isset($options['uid']))
475 475
 		{
476 476
 			if (isset($options['user']))
477 477
 			{
478
-				$options['uid'] = $GLOBALS['egw']->accounts->name2id($options['user'],'account_lid','u');
478
+				$options['uid'] = $GLOBALS['egw']->accounts->name2id($options['user'], 'account_lid', 'u');
479 479
 			}
480 480
 			elseif (isset($options['nouser']))
481 481
 			{
@@ -486,7 +486,7 @@  discard block
 block discarded – undo
486 486
 		{
487 487
 			if (isset($options['group']))
488 488
 			{
489
-				$options['gid'] = abs($GLOBALS['egw']->accounts->name2id($options['group'],'account_lid','g'));
489
+				$options['gid'] = abs($GLOBALS['egw']->accounts->name2id($options['group'], 'account_lid', 'g'));
490 490
 			}
491 491
 			elseif (isset($options['nogroup']))
492 492
 			{
@@ -495,7 +495,7 @@  discard block
 block discarded – undo
495 495
 		}
496 496
 		if ($options['order'] == 'mime')
497 497
 		{
498
-			$options['need_mime'] = true;	// we need to return the mime colum
498
+			$options['need_mime'] = true; // we need to return the mime colum
499 499
 		}
500 500
 		// implicit show deleted files, if hidden is enabled (requires versioning!)
501 501
 		if (!empty($options['hidden']) && !isset($options['show-deleted']))
@@ -513,37 +513,37 @@  discard block
 block discarded – undo
513 513
 			$base = array($base);
514 514
 		}
515 515
 		$result = array();
516
-		foreach($base as $path)
516
+		foreach ($base as $path)
517 517
 		{
518 518
 			if (!$url)
519 519
 			{
520 520
 				if ($path[0] != '/' || !self::stat($path)) continue;
521
-				$path = self::PREFIX . $path;
521
+				$path = self::PREFIX.$path;
522 522
 			}
523 523
 			if (!isset($options['remove']))
524 524
 			{
525
-				$options['remove'] = count($base) == 1 ? count(explode('/',$path))-3+(int)(substr($path,-1)!='/') : 0;
525
+				$options['remove'] = count($base) == 1 ? count(explode('/', $path)) - 3 + (int)(substr($path, -1) != '/') : 0;
526 526
 			}
527 527
 			$is_dir = is_dir($path);
528 528
 			if ((int)$options['mindepth'] == 0 && (!$dirs_last || !$is_dir))
529 529
 			{
530
-				self::_check_add($options,$path,$result);
530
+				self::_check_add($options, $path, $result);
531 531
 			}
532 532
 			if ($is_dir && (!isset($options['maxdepth']) || ($options['maxdepth'] > 0 &&
533 533
 				$options['depth'] < $options['maxdepth'])) &&
534 534
 				($dir = @opendir($path, $context)))
535 535
 			{
536
-				while(($fname = readdir($dir)) !== false)
536
+				while (($fname = readdir($dir)) !== false)
537 537
 				{
538
-					if ($fname == '.' || $fname == '..') continue;	// ignore current and parent dir!
538
+					if ($fname == '.' || $fname == '..') continue; // ignore current and parent dir!
539 539
 
540
-					if (self::is_hidden($fname, $options['show-deleted']) && !$options['hidden']) continue;	// ignore hidden files
540
+					if (self::is_hidden($fname, $options['show-deleted']) && !$options['hidden']) continue; // ignore hidden files
541 541
 
542 542
 					$file = self::concat($path, $fname);
543 543
 
544 544
 					if ((int)$options['mindepth'] <= 1)
545 545
 					{
546
-						self::_check_add($options,$file,$result);
546
+						self::_check_add($options, $file, $result);
547 547
 					}
548 548
 					// only descend into subdirs, if it's a real dir (no link to a dir) or we should follow symlinks
549 549
 					if (is_dir($file) && ($options['follow'] || !is_link($file)) && (!isset($options['maxdepth']) || $options['maxdepth'] > 1))
@@ -553,7 +553,7 @@  discard block
 block discarded – undo
553 553
 						if ($opts['maxdepth']) $opts['depth']++;
554 554
 						unset($opts['order']);
555 555
 						unset($opts['limit']);
556
-						foreach(self::find($options['url']?$file:self::parse_url($file,PHP_URL_PATH),$opts,true) as $p => $s)
556
+						foreach (self::find($options['url'] ? $file : self::parse_url($file, PHP_URL_PATH), $opts, true) as $p => $s)
557 557
 						{
558 558
 							unset($result[$p]);
559 559
 							$result[$p] = $s;
@@ -564,7 +564,7 @@  discard block
 block discarded – undo
564 564
 			}
565 565
 			if ($is_dir && (int)$options['mindepth'] == 0 && $dirs_last)
566 566
 			{
567
-				self::_check_add($options,$path,$result);
567
+				self::_check_add($options, $path, $result);
568 568
 			}
569 569
 		}
570 570
 		// sort code, to place directories before files, if $dirsontop enabled
@@ -574,7 +574,7 @@  discard block
 block discarded – undo
574 574
 		if (isset($options['order']))
575 575
 		{
576 576
 			$sort = strtolower($options['sort']) == 'desc' ? '-' : '';
577
-			switch($options['order'])
577
+			switch ($options['order'])
578 578
 			{
579 579
 				// sort numerical
580 580
 				case 'size':
@@ -586,7 +586,7 @@  discard block
 block discarded – undo
586 586
 					$code = $dirsfirst.$sort.'($a[\''.$options['order'].'\']-$b[\''.$options['order'].'\']);';
587 587
 					// always use name as second sort criteria
588 588
 					$code = '$cmp = '.$code.' return $cmp ? $cmp : strcasecmp($a[\'name\'],$b[\'name\']);';
589
-					$ok = uasort($result,create_function('$a,$b',$code));
589
+					$ok = uasort($result, create_function('$a,$b', $code));
590 590
 					break;
591 591
 
592 592
 				// sort alphanumerical
@@ -605,7 +605,7 @@  discard block
 block discarded – undo
605 605
 					{
606 606
 						$code = 'return '.$code;
607 607
 					}
608
-					$ok = uasort($result,create_function('$a,$b',$code));
608
+					$ok = uasort($result, create_function('$a,$b', $code));
609 609
 					break;
610 610
 			}
611 611
 			//echo "<p>order='$options[order]', sort='$options[sort]' --> uasort($result,create_function(,'$code'))=".array2string($ok)."</p>>\n";
@@ -614,13 +614,13 @@  discard block
 block discarded – undo
614 614
 		self::$find_total = count($result);
615 615
 		if (isset($options['limit']))
616 616
 		{
617
-			list($limit,$start) = explode(',',$options['limit']);
617
+			list($limit, $start) = explode(',', $options['limit']);
618 618
 			if (!$limit && !($limit = $GLOBALS['egw_info']['user']['preferences']['comman']['maxmatches'])) $limit = 15;
619 619
 			//echo "total=".self::$find_total.", limit=$options[limit] --> start=$start, limit=$limit<br>\n";
620 620
 
621 621
 			if ((int)$start || self::$find_total > $limit)
622 622
 			{
623
-				$result = array_slice($result,(int)$start,(int)$limit,true);
623
+				$result = array_slice($result, (int)$start, (int)$limit, true);
624 624
 			}
625 625
 		}
626 626
 		//echo $path; _debug_array($result);
@@ -630,13 +630,13 @@  discard block
 block discarded – undo
630 630
 			{
631 631
 				$exec_params = is_null($exec_params) ? array() : array($exec_params);
632 632
 			}
633
-			foreach($result as $path => &$stat)
633
+			foreach ($result as $path => &$stat)
634 634
 			{
635 635
 				$options = $exec_params;
636
-				array_unshift($options,$path);
637
-				array_push($options,$stat);
636
+				array_unshift($options, $path);
637
+				array_push($options, $stat);
638 638
 				//echo "calling ".print_r($exec,true).print_r($options,true)."\n";
639
-				$stat = call_user_func_array($exec,$options);
639
+				$stat = call_user_func_array($exec, $options);
640 640
 			}
641 641
 			return $result;
642 642
 		}
@@ -655,9 +655,9 @@  discard block
 block discarded – undo
655 655
 	 * @param string $path name of path to add
656 656
 	 * @param array &$result here we add the stat for the key $path, if the checks are successful
657 657
 	 */
658
-	private static function _check_add($options,$path,&$result)
658
+	private static function _check_add($options, $path, &$result)
659 659
 	{
660
-		$type = $options['type'];	// 'd' or 'f'
660
+		$type = $options['type']; // 'd' or 'f'
661 661
 
662 662
 		if ($options['url'])
663 663
 		{
@@ -665,35 +665,35 @@  discard block
 block discarded – undo
665 665
 		}
666 666
 		else
667 667
 		{
668
-			$stat = self::url_stat($path,STREAM_URL_STAT_LINK);
668
+			$stat = self::url_stat($path, STREAM_URL_STAT_LINK);
669 669
 		}
670 670
 		if (!$stat)
671 671
 		{
672
-			return;	// not found, should not happen
672
+			return; // not found, should not happen
673 673
 		}
674
-		if ($type && (($type == 'd') == !($stat['mode'] & Vfs\Sqlfs\StreamWrapper::MODE_DIR) ||	// != is_dir() which can be true for symlinks
674
+		if ($type && (($type == 'd') == !($stat['mode']&Vfs\Sqlfs\StreamWrapper::MODE_DIR) || // != is_dir() which can be true for symlinks
675 675
 		    $type == 'F' && is_dir($path)))	// symlink to a directory
676 676
 		{
677
-			return;	// wrong type
677
+			return; // wrong type
678 678
 		}
679
-		$stat = array_slice($stat,13);	// remove numerical indices 0-12
680
-		$stat['path'] = self::parse_url($path,PHP_URL_PATH);
681
-		$stat['name'] = $options['remove'] > 0 ? implode('/',array_slice(explode('/',$stat['path']),$options['remove'])) : self::basename($path);
679
+		$stat = array_slice($stat, 13); // remove numerical indices 0-12
680
+		$stat['path'] = self::parse_url($path, PHP_URL_PATH);
681
+		$stat['name'] = $options['remove'] > 0 ? implode('/', array_slice(explode('/', $stat['path']), $options['remove'])) : self::basename($path);
682 682
 
683 683
 		if ($options['mime'] || $options['need_mime'])
684 684
 		{
685 685
 			$stat['mime'] = self::mime_content_type($path);
686 686
 		}
687
-		if (isset($options['name_preg']) && !preg_match($options['name_preg'],$stat['name']) ||
688
-			isset($options['path_preg']) && !preg_match($options['path_preg'],$path))
687
+		if (isset($options['name_preg']) && !preg_match($options['name_preg'], $stat['name']) ||
688
+			isset($options['path_preg']) && !preg_match($options['path_preg'], $path))
689 689
 		{
690 690
 			//echo "<p>!preg_match('{$options['name_preg']}','{$stat['name']}')</p>\n";
691
-			return;	// wrong name or path
691
+			return; // wrong name or path
692 692
 		}
693 693
 		if (isset($options['gid']) && $stat['gid'] != $options['gid'] ||
694 694
 			isset($options['uid']) && $stat['uid'] != $options['uid'])
695 695
 		{
696
-			return;	// wrong user or group
696
+			return; // wrong user or group
697 697
 		}
698 698
 		if (isset($options['mime']) && $options['mime'] != $stat['mime'])
699 699
 		{
@@ -701,40 +701,40 @@  discard block
 block discarded – undo
701 701
 			{
702 702
 				if (!preg_match($options['mime'], $stat['mime']))
703 703
 				{
704
-					return;	// wrong mime-type
704
+					return; // wrong mime-type
705 705
 				}
706 706
 			}
707 707
 			else
708 708
 			{
709
-				list($type,$subtype) = explode('/',$options['mime']);
709
+				list($type, $subtype) = explode('/', $options['mime']);
710 710
 				// no subtype (eg. 'image') --> check only the main type
711
-				if ($subtype || substr($stat['mime'],0,strlen($type)+1) != $type.'/')
711
+				if ($subtype || substr($stat['mime'], 0, strlen($type) + 1) != $type.'/')
712 712
 				{
713
-					return;	// wrong mime-type
713
+					return; // wrong mime-type
714 714
 				}
715 715
 			}
716 716
 		}
717
-		if (isset($options['size']) && !self::_check_num($stat['size'],$options['size']) ||
717
+		if (isset($options['size']) && !self::_check_num($stat['size'], $options['size']) ||
718 718
 			(isset($options['empty']) && !!$options['empty'] !== !$stat['size']))
719 719
 		{
720
-			return;	// wrong size
720
+			return; // wrong size
721 721
 		}
722
-		if (isset($options['cmin']) && !self::_check_num(round((time()-$stat['ctime'])/60),$options['cmin']) ||
723
-			isset($options['mmin']) && !self::_check_num(round((time()-$stat['mtime'])/60),$options['mmin']) ||
724
-			isset($options['ctime']) && !self::_check_num(round((time()-$stat['ctime'])/86400),$options['ctime']) ||
725
-			isset($options['mtime']) && !self::_check_num(round((time()-$stat['mtime'])/86400),$options['mtime']))
722
+		if (isset($options['cmin']) && !self::_check_num(round((time() - $stat['ctime']) / 60), $options['cmin']) ||
723
+			isset($options['mmin']) && !self::_check_num(round((time() - $stat['mtime']) / 60), $options['mmin']) ||
724
+			isset($options['ctime']) && !self::_check_num(round((time() - $stat['ctime']) / 86400), $options['ctime']) ||
725
+			isset($options['mtime']) && !self::_check_num(round((time() - $stat['mtime']) / 86400), $options['mtime']))
726 726
 		{
727
-			return;	// not create/modified in the spezified time
727
+			return; // not create/modified in the spezified time
728 728
 		}
729 729
 		// do we return url or just vfs pathes
730 730
 		if (!$options['url'])
731 731
 		{
732
-			$path = self::parse_url($path,PHP_URL_PATH);
732
+			$path = self::parse_url($path, PHP_URL_PATH);
733 733
 		}
734 734
 		$result[$path] = $stat;
735 735
 	}
736 736
 
737
-	private static function _check_num($value,$argument)
737
+	private static function _check_num($value, $argument)
738 738
 	{
739 739
 		if (is_int($argument) && $argument >= 0 || $argument[0] != '-' && $argument[0] != '+')
740 740
 		{
@@ -747,7 +747,7 @@  discard block
 block discarded – undo
747 747
 			return $value < abs($argument);
748 748
 		}
749 749
 		//echo "_check_num($value,$argument) check > == ".(int)($value > (int)substr($argument,1))."\n";
750
-		return $value > (int) substr($argument,1);
750
+		return $value > (int)substr($argument, 1);
751 751
 	}
752 752
 
753 753
 	/**
@@ -758,18 +758,18 @@  discard block
 block discarded – undo
758 758
 	 * @throws Exception\AssertionFailed when trainig to remove /, /apps or /home
759 759
 	 * @return array
760 760
 	 */
761
-	static function remove($urls,$allow_urls=false)
761
+	static function remove($urls, $allow_urls = false)
762 762
 	{
763 763
 		//error_log(__METHOD__.'('.array2string($urls).')');
764 764
 		// some precaution to never allow to (recursivly) remove /, /apps or /home
765
-		foreach((array)$urls as $url)
765
+		foreach ((array)$urls as $url)
766 766
 		{
767
-			if (preg_match('/^\/?(home|apps|)\/*$/',self::parse_url($url,PHP_URL_PATH)))
767
+			if (preg_match('/^\/?(home|apps|)\/*$/', self::parse_url($url, PHP_URL_PATH)))
768 768
 			{
769 769
 				throw new Exception\AssertionFailed(__METHOD__.'('.array2string($urls).") Cautiously rejecting to remove folder '$url'!");
770 770
 			}
771 771
 		}
772
-		return self::find($urls,array('depth'=>true,'url'=>$allow_urls,'hidden'=>true),array(__CLASS__,'_rm_rmdir'));
772
+		return self::find($urls, array('depth'=>true, 'url'=>$allow_urls, 'hidden'=>true), array(__CLASS__, '_rm_rmdir'));
773 773
 	}
774 774
 
775 775
 	/**
@@ -782,11 +782,11 @@  discard block
 block discarded – undo
782 782
 	{
783 783
 		if ($url[0] == '/')
784 784
 		{
785
-			$url = self::PREFIX . $url;
785
+			$url = self::PREFIX.$url;
786 786
 		}
787 787
 		if (is_dir($url) && !is_link($url))
788 788
 		{
789
-			return self::rmdir($url,0);
789
+			return self::rmdir($url, 0);
790 790
 		}
791 791
 		return self::unlink($url);
792 792
 	}
@@ -800,9 +800,9 @@  discard block
 block discarded – undo
800 800
 	 * 	2 = self::WRITABLE, 1 = self::EXECUTABLE
801 801
 	 * @return boolean
802 802
 	 */
803
-	static function is_readable($path,$check = self::READABLE)
803
+	static function is_readable($path, $check = self::READABLE)
804 804
 	{
805
-		return self::check_access($path,$check);
805
+		return self::check_access($path, $check);
806 806
 	}
807 807
 
808 808
 	/**
@@ -816,7 +816,7 @@  discard block
 block discarded – undo
816 816
 	 * @param int $user =null user used for check, if not current user (self::$user)
817 817
 	 * @return boolean
818 818
 	 */
819
-	static function check_access($path, $check, $stat=null, $user=null)
819
+	static function check_access($path, $check, $stat = null, $user = null)
820 820
 	{
821 821
 		if (is_null($stat) && $user && $user != self::$user)
822 822
 		{
@@ -831,7 +831,7 @@  discard block
 block discarded – undo
831 831
 
832 832
 				$path_user_stat[$path][$user] = self::url_stat($path, 0);
833 833
 
834
-				self::clearstatcache($path);	// we need to clear the stat-cache after the call too, as the next call might be the regular user again!
834
+				self::clearstatcache($path); // we need to clear the stat-cache after the call too, as the next call might be the regular user again!
835 835
 			}
836 836
 			if (($stat = $path_user_stat[$path][$user]))
837 837
 			{
@@ -847,7 +847,7 @@  discard block
 block discarded – undo
847 847
 			}
848 848
 			else
849 849
 			{
850
-				$ret = false;	// no access, if we can not stat the file
850
+				$ret = false; // no access, if we can not stat the file
851 851
 			}
852 852
 			self::$user = $backup_user;
853 853
 
@@ -871,20 +871,20 @@  discard block
 block discarded – undo
871 871
 		// query stat array, if not given
872 872
 		if (is_null($stat))
873 873
 		{
874
-			$stat = self::url_stat($path,0);
874
+			$stat = self::url_stat($path, 0);
875 875
 		}
876 876
 		//error_log(__METHOD__."(path=$path||stat[name]={$stat['name']},stat[mode]=".sprintf('%o',$stat['mode']).",$check)");
877 877
 
878 878
 		if (!$stat)
879 879
 		{
880 880
 			//error_log(__METHOD__."(path=$path||stat[name]={$stat['name']},stat[mode]=".sprintf('%o',$stat['mode']).",$check) no stat array!");
881
-			return false;	// file not found
881
+			return false; // file not found
882 882
 		}
883 883
 		// check if we use an EGroupwre stream wrapper, or a stock php one
884 884
 		// if it's not an EGroupware one, we can NOT use uid, gid and mode!
885
-		if (($scheme = self::parse_url($stat['url'],PHP_URL_SCHEME)) && !(class_exists(self::scheme2class($scheme))))
885
+		if (($scheme = self::parse_url($stat['url'], PHP_URL_SCHEME)) && !(class_exists(self::scheme2class($scheme))))
886 886
 		{
887
-			switch($check)
887
+			switch ($check)
888 888
 			{
889 889
 				case self::READABLE:
890 890
 					return is_readable($stat['url']);
@@ -895,19 +895,19 @@  discard block
 block discarded – undo
895 895
 			}
896 896
 		}
897 897
 		// check if other rights grant access
898
-		if (($stat['mode'] & $check) == $check)
898
+		if (($stat['mode']&$check) == $check)
899 899
 		{
900 900
 			//error_log(__METHOD__."(path=$path||stat[name]={$stat['name']},stat[mode]=".sprintf('%o',$stat['mode']).",$check) access via other rights!");
901 901
 			return true;
902 902
 		}
903 903
 		// check if there's owner access and we are the owner
904
-		if (($stat['mode'] & ($check << 6)) == ($check << 6) && $stat['uid'] && $stat['uid'] == self::$user)
904
+		if (($stat['mode']&($check << 6)) == ($check << 6) && $stat['uid'] && $stat['uid'] == self::$user)
905 905
 		{
906 906
 			//error_log(__METHOD__."(path=$path||stat[name]={$stat['name']},stat[mode]=".sprintf('%o',$stat['mode']).",$check) access via owner rights!");
907 907
 			return true;
908 908
 		}
909 909
 		// check if there's a group access and we have the right membership
910
-		if (($stat['mode'] & ($check << 3)) == ($check << 3) && $stat['gid'])
910
+		if (($stat['mode']&($check << 3)) == ($check << 3) && $stat['gid'])
911 911
 		{
912 912
 			if (($memberships = $GLOBALS['egw']->accounts->memberships(self::$user, true)) && in_array(-abs($stat['gid']), $memberships))
913 913
 			{
@@ -916,7 +916,7 @@  discard block
 block discarded – undo
916 916
 			}
917 917
 		}
918 918
 		// check backend for extended acls (only if path given)
919
-		$ret = $path && self::_call_on_backend('check_extended_acl',array(isset($stat['url'])?$stat['url']:$path,$check),true);	// true = fail silent if backend does not support
919
+		$ret = $path && self::_call_on_backend('check_extended_acl', array(isset($stat['url']) ? $stat['url'] : $path, $check), true); // true = fail silent if backend does not support
920 920
 
921 921
 		//error_log(__METHOD__."(path=$path||stat[name]={$stat['name']},stat[mode]=".sprintf('%o',$stat['mode']).",$check) ".($ret ? 'backend extended acl granted access.' : 'no access!!!'));
922 922
 		return $ret;
@@ -931,7 +931,7 @@  discard block
 block discarded – undo
931 931
 	 */
932 932
 	static function is_writable($path)
933 933
 	{
934
-		return self::is_readable($path,self::WRITABLE);
934
+		return self::is_readable($path, self::WRITABLE);
935 935
 	}
936 936
 
937 937
 	/**
@@ -943,7 +943,7 @@  discard block
 block discarded – undo
943 943
 	 */
944 944
 	static function is_executable($path)
945 945
 	{
946
-		return self::is_readable($path,self::EXECUTABLE);
946
+		return self::is_readable($path, self::EXECUTABLE);
947 947
 	}
948 948
 
949 949
 	/**
@@ -954,7 +954,7 @@  discard block
 block discarded – undo
954 954
 	 */
955 955
 	static function deny_script($path)
956 956
 	{
957
-		return self::_call_on_backend('deny_script',array($path),true);
957
+		return self::_call_on_backend('deny_script', array($path), true);
958 958
 	}
959 959
 
960 960
 	/**
@@ -973,11 +973,11 @@  discard block
 block discarded – undo
973 973
 	 * @param boolean $session_only =false true: set eacl only for this session, does NO further checks currently!
974 974
 	 * @return boolean true if acl is set/deleted, false on error
975 975
 	 */
976
-	static function eacl($url,$rights=null,$owner=null,$session_only=false)
976
+	static function eacl($url, $rights = null, $owner = null, $session_only = false)
977 977
 	{
978 978
 		if ($session_only)
979 979
 		{
980
-			$session_eacls =& Cache::getSession(__CLASS__, self::SESSION_EACL);
980
+			$session_eacls = & Cache::getSession(__CLASS__, self::SESSION_EACL);
981 981
 			$session_eacls[] = array(
982 982
 				'path'   => $url[0] == '/' ? $url : self::parse_url($url, PHP_URL_PATH),
983 983
 				'owner'  => $owner ? $owner : self::$user,
@@ -985,7 +985,7 @@  discard block
 block discarded – undo
985 985
 			);
986 986
 			return true;
987 987
 		}
988
-		return self::_call_on_backend('eacl',array($url,$rights,$owner));
988
+		return self::_call_on_backend('eacl', array($url, $rights, $owner));
989 989
 	}
990 990
 
991 991
 	/**
@@ -998,9 +998,9 @@  discard block
 block discarded – undo
998 998
 	 */
999 999
 	static function get_eacl($path)
1000 1000
 	{
1001
-		$eacls = self::_call_on_backend('get_eacl',array($path),true);	// true = fail silent (no PHP Warning)
1001
+		$eacls = self::_call_on_backend('get_eacl', array($path), true); // true = fail silent (no PHP Warning)
1002 1002
 
1003
-		$session_eacls =& Cache::getSession(__CLASS__, self::SESSION_EACL);
1003
+		$session_eacls = & Cache::getSession(__CLASS__, self::SESSION_EACL);
1004 1004
 		if ($session_eacls)
1005 1005
 		{
1006 1006
 			// eacl is recursive, therefore we have to match all parent-dirs too
@@ -1009,7 +1009,7 @@  discard block
 block discarded – undo
1009 1009
 			{
1010 1010
 				$paths[] = $path = self::dirname($path);
1011 1011
 			}
1012
-			foreach((array)$session_eacls as $eacl)
1012
+			foreach ((array)$session_eacls as $eacl)
1013 1013
 			{
1014 1014
 				if (in_array($eacl['path'], $paths))
1015 1015
 				{
@@ -1032,9 +1032,9 @@  discard block
 block discarded – undo
1032 1032
 	 * @param array $props array of array with values for keys 'name', 'ns', 'val' (null to delete the prop)
1033 1033
 	 * @return boolean true if props are updated, false otherwise (eg. ressource not found)
1034 1034
 	 */
1035
-	static function proppatch($path,array $props)
1035
+	static function proppatch($path, array $props)
1036 1036
 	{
1037
-		return self::_call_on_backend('proppatch',array($path,$props));
1037
+		return self::_call_on_backend('proppatch', array($path, $props));
1038 1038
 	}
1039 1039
 
1040 1040
 	/**
@@ -1051,9 +1051,9 @@  discard block
 block discarded – undo
1051 1051
 	 * @return array|boolean array with props (values for keys 'name', 'ns', 'val'), or path => array of props for is_array($path)
1052 1052
 	 * 	false if $path does not exist
1053 1053
 	 */
1054
-	static function propfind($path,$ns=self::DEFAULT_PROP_NAMESPACE)
1054
+	static function propfind($path, $ns = self::DEFAULT_PROP_NAMESPACE)
1055 1055
 	{
1056
-		return self::_call_on_backend('propfind',array($path,$ns),true);	// true = fail silent (no PHP Warning)
1056
+		return self::_call_on_backend('propfind', array($path, $ns), true); // true = fail silent (no PHP Warning)
1057 1057
 	}
1058 1058
 
1059 1059
 	/**
@@ -1071,7 +1071,7 @@  discard block
 block discarded – undo
1071 1071
 	 * @param int $mode =0 current mode of the file, necessary for +/- operation
1072 1072
 	 * @return int
1073 1073
 	 */
1074
-	static function mode2int($set,$mode=0)
1074
+	static function mode2int($set, $mode = 0)
1075 1075
 	{
1076 1076
 		if (is_int($set))		// already an integer
1077 1077
 		{
@@ -1080,23 +1080,23 @@  discard block
 block discarded – undo
1080 1080
 		if (is_numeric($set))	// octal string
1081 1081
 		{
1082 1082
 			//error_log(__METHOD__."($set,$mode) returning ".(int)base_convert($set,8,10));
1083
-			return (int)base_convert($set,8,10);	// convert octal to decimal
1083
+			return (int)base_convert($set, 8, 10); // convert octal to decimal
1084 1084
 		}
1085
-		foreach(explode(',',$set) as $s)
1085
+		foreach (explode(',', $set) as $s)
1086 1086
 		{
1087 1087
 			$matches = null;
1088
-			if (!preg_match($use='/^([ugoa]*)([+=-]+)([rwx]+)$/',$s,$matches))
1088
+			if (!preg_match($use = '/^([ugoa]*)([+=-]+)([rwx]+)$/', $s, $matches))
1089 1089
 			{
1090
-				$use = str_replace(array('/','^','$','(',')'),'',$use);
1090
+				$use = str_replace(array('/', '^', '$', '(', ')'), '', $use);
1091 1091
 				throw new Exception\WrongUserinput("$s is not an allowed mode, use $use !");
1092 1092
 			}
1093
-			$base = (strpos($matches[3],'r') !== false ? self::READABLE : 0) |
1094
-				(strpos($matches[3],'w') !== false ? self::WRITABLE : 0) |
1095
-				(strpos($matches[3],'x') !== false ? self::EXECUTABLE : 0);
1093
+			$base = (strpos($matches[3], 'r') !== false ? self::READABLE : 0)|
1094
+				(strpos($matches[3], 'w') !== false ? self::WRITABLE : 0)|
1095
+				(strpos($matches[3], 'x') !== false ? self::EXECUTABLE : 0);
1096 1096
 
1097
-			for($n = $m = 0; $n < strlen($matches[1]); $n++)
1097
+			for ($n = $m = 0; $n < strlen($matches[1]); $n++)
1098 1098
 			{
1099
-				switch($matches[1][$n])
1099
+				switch ($matches[1][$n])
1100 1100
 				{
1101 1101
 					case 'o':
1102 1102
 						$m |= $base;
@@ -1109,10 +1109,10 @@  discard block
 block discarded – undo
1109 1109
 						break;
1110 1110
 					default:
1111 1111
 					case 'a':
1112
-						$m = $base | ($base << 3) | ($base << 6);
1112
+						$m = $base|($base << 3)|($base << 6);
1113 1113
 				}
1114 1114
 			}
1115
-			switch($matches[2])
1115
+			switch ($matches[2])
1116 1116
 			{
1117 1117
 				case '+':
1118 1118
 					$mode |= $m;
@@ -1134,33 +1134,33 @@  discard block
 block discarded – undo
1134 1134
 	 * @param int $mode
1135 1135
 	 * @return string
1136 1136
 	 */
1137
-	static function int2mode( $mode )
1137
+	static function int2mode($mode)
1138 1138
 	{
1139
-		if(($mode & self::MODE_LINK) == self::MODE_LINK) // Symbolic Link
1139
+		if (($mode&self::MODE_LINK) == self::MODE_LINK) // Symbolic Link
1140 1140
 		{
1141 1141
 			$sP = 'l';
1142 1142
 		}
1143
-		elseif(($mode & 0xC000) == 0xC000) // Socket
1143
+		elseif (($mode&0xC000) == 0xC000) // Socket
1144 1144
 		{
1145 1145
 			$sP = 's';
1146 1146
 		}
1147
-		elseif($mode & 0x1000)     // FIFO pipe
1147
+		elseif ($mode&0x1000)     // FIFO pipe
1148 1148
 		{
1149 1149
 			$sP = 'p';
1150 1150
 		}
1151
-		elseif($mode & 0x2000) // Character special
1151
+		elseif ($mode&0x2000) // Character special
1152 1152
 		{
1153 1153
 			$sP = 'c';
1154 1154
 		}
1155
-		elseif($mode & 0x4000) // Directory
1155
+		elseif ($mode&0x4000) // Directory
1156 1156
 		{
1157 1157
 			$sP = 'd';
1158 1158
 		}
1159
-		elseif($mode & 0x6000) // Block special
1159
+		elseif ($mode&0x6000) // Block special
1160 1160
 		{
1161 1161
 			$sP = 'b';
1162 1162
 		}
1163
-		elseif($mode & 0x8000) // Regular
1163
+		elseif ($mode&0x8000) // Regular
1164 1164
 		{
1165 1165
 			$sP = '-';
1166 1166
 		}
@@ -1170,22 +1170,19 @@  discard block
 block discarded – undo
1170 1170
 		}
1171 1171
 
1172 1172
 		// owner
1173
-		$sP .= (($mode & 0x0100) ? 'r' : '-') .
1174
-		(($mode & 0x0080) ? 'w' : '-') .
1175
-		(($mode & 0x0040) ? (($mode & 0x0800) ? 's' : 'x' ) :
1176
-		(($mode & 0x0800) ? 'S' : '-'));
1173
+		$sP .= (($mode&0x0100) ? 'r' : '-').
1174
+		(($mode&0x0080) ? 'w' : '-').
1175
+		(($mode&0x0040) ? (($mode&0x0800) ? 's' : 'x') : (($mode&0x0800) ? 'S' : '-'));
1177 1176
 
1178 1177
 		// group
1179
-		$sP .= (($mode & 0x0020) ? 'r' : '-') .
1180
-		(($mode & 0x0010) ? 'w' : '-') .
1181
-		(($mode & 0x0008) ? (($mode & 0x0400) ? 's' : 'x' ) :
1182
-		(($mode & 0x0400) ? 'S' : '-'));
1178
+		$sP .= (($mode&0x0020) ? 'r' : '-').
1179
+		(($mode&0x0010) ? 'w' : '-').
1180
+		(($mode&0x0008) ? (($mode&0x0400) ? 's' : 'x') : (($mode&0x0400) ? 'S' : '-'));
1183 1181
 
1184 1182
 		// world
1185
-		$sP .= (($mode & 0x0004) ? 'r' : '-') .
1186
-		(($mode & 0x0002) ? 'w' : '-') .
1187
-		(($mode & 0x0001) ? (($mode & 0x0200) ? 't' : 'x' ) :
1188
-		(($mode & 0x0200) ? 'T' : '-'));
1183
+		$sP .= (($mode&0x0004) ? 'r' : '-').
1184
+		(($mode&0x0002) ? 'w' : '-').
1185
+		(($mode&0x0001) ? (($mode&0x0200) ? 't' : 'x') : (($mode&0x0200) ? 'T' : '-'));
1189 1186
 
1190 1187
 		return $sP;
1191 1188
 	}
@@ -1198,26 +1195,26 @@  discard block
 block discarded – undo
1198 1195
 	 * @param int $size =128
1199 1196
 	 * @return string
1200 1197
 	 */
1201
-	static function mime_icon($mime_type, $et_image=true, $size=128)
1198
+	static function mime_icon($mime_type, $et_image = true, $size = 128)
1202 1199
 	{
1203 1200
 		if ($mime_type == self::DIR_MIME_TYPE)
1204 1201
 		{
1205 1202
 			$mime_type = 'Directory';
1206 1203
 		}
1207
-		if(!$mime_type)
1204
+		if (!$mime_type)
1208 1205
 		{
1209 1206
 			$mime_type = 'unknown';
1210 1207
 		}
1211
-		$mime_full = strtolower(str_replace	('/','_',$mime_type));
1212
-		list($mime_part) = explode('_',$mime_full);
1208
+		$mime_full = strtolower(str_replace('/', '_', $mime_type));
1209
+		list($mime_part) = explode('_', $mime_full);
1213 1210
 
1214
-		if (!($img=Image::find('etemplate',$icon='mime'.$size.'_'.$mime_full)) &&
1211
+		if (!($img = Image::find('etemplate', $icon = 'mime'.$size.'_'.$mime_full)) &&
1215 1212
 			// check mime-alias-map before falling back to more generic icons
1216 1213
 			!(isset(MimeMagic::$mime_alias_map[$mime_type]) &&
1217
-				($img=Image::find('etemplate',$icon='mime'.$size.'_'.str_replace('/','_',MimeMagic::$mime_alias_map[$mime_full])))) &&
1218
-			!($img=Image::find('etemplate',$icon='mime'.$size.'_'.$mime_part)))
1214
+				($img = Image::find('etemplate', $icon = 'mime'.$size.'_'.str_replace('/', '_', MimeMagic::$mime_alias_map[$mime_full])))) &&
1215
+			!($img = Image::find('etemplate', $icon = 'mime'.$size.'_'.$mime_part)))
1219 1216
 		{
1220
-			$img = Image::find('etemplate',$icon='mime'.$size.'_unknown');
1217
+			$img = Image::find('etemplate', $icon = 'mime'.$size.'_unknown');
1221 1218
 		}
1222 1219
 		return $et_image ? 'etemplate/'.$icon : $img;
1223 1220
 	}
@@ -1231,9 +1228,9 @@  discard block
 block discarded – undo
1231 1228
 	static function hsize($size)
1232 1229
 	{
1233 1230
 		if ($size < 1024) return $size;
1234
-		if ($size < 1024*1024) return sprintf('%3.1lfk',(float)$size/1024);
1235
-		if ($size < 1024*1024*1024) return sprintf('%3.1lfM',(float)$size/(1024*1024));
1236
-		return sprintf('%3.1lfG',(float)$size/(1024*1024*1024));
1231
+		if ($size < 1024 * 1024) return sprintf('%3.1lfk', (float)$size / 1024);
1232
+		if ($size < 1024 * 1024 * 1024) return sprintf('%3.1lfM', (float)$size / (1024 * 1024));
1233
+		return sprintf('%3.1lfG', (float)$size / (1024 * 1024 * 1024));
1237 1234
 	}
1238 1235
 
1239 1236
 	/**
@@ -1243,7 +1240,7 @@  discard block
 block discarded – undo
1243 1240
 	 */
1244 1241
 	static function int_size($_val)
1245 1242
 	{
1246
-		if(empty($_val))return 0;
1243
+		if (empty($_val))return 0;
1247 1244
 
1248 1245
 		$val = trim($_val);
1249 1246
 
@@ -1251,12 +1248,12 @@  discard block
 block discarded – undo
1251 1248
 		preg_match('#([0-9]+)[\s]*([a-z]+)#i', $val, $matches);
1252 1249
 
1253 1250
 		$last = '';
1254
-		if(isset($matches[2])){
1251
+		if (isset($matches[2])) {
1255 1252
 			$last = $matches[2];
1256 1253
 		}
1257 1254
 
1258
-		if(isset($matches[1])){
1259
-			$val = (int) $matches[1];
1255
+		if (isset($matches[1])) {
1256
+			$val = (int)$matches[1];
1260 1257
 		}
1261 1258
 
1262 1259
 		switch (strtolower($last))
@@ -1272,7 +1269,7 @@  discard block
 block discarded – undo
1272 1269
 			$val *= 1024;
1273 1270
 		}
1274 1271
 
1275
-		return (int) $val;
1272
+		return (int)$val;
1276 1273
 	}
1277 1274
 
1278 1275
 	/**
@@ -1283,8 +1280,8 @@  discard block
 block discarded – undo
1283 1280
 	 */
1284 1281
 	static function basename($_path)
1285 1282
 	{
1286
-		list($path) = explode('?',$_path);	// remove query
1287
-		$parts = explode('/',$path);
1283
+		list($path) = explode('?', $_path); // remove query
1284
+		$parts = explode('/', $path);
1288 1285
 
1289 1286
 		return array_pop($parts);
1290 1287
 	}
@@ -1299,22 +1296,22 @@  discard block
 block discarded – undo
1299 1296
 	 */
1300 1297
 	static function dirname($_url)
1301 1298
 	{
1302
-		list($url,$query) = explode('?',$_url,2);	// strip the query first, as it can contain slashes
1299
+		list($url, $query) = explode('?', $_url, 2); // strip the query first, as it can contain slashes
1303 1300
 
1304
-		if ($url == '/' || $url[0] != '/' && self::parse_url($url,PHP_URL_PATH) == '/')
1301
+		if ($url == '/' || $url[0] != '/' && self::parse_url($url, PHP_URL_PATH) == '/')
1305 1302
 		{
1306 1303
 			//error_log(__METHOD__."($url) returning FALSE: already in root!");
1307 1304
 			return false;
1308 1305
 		}
1309
-		$parts = explode('/',$url);
1310
-		if (substr($url,-1) == '/') array_pop($parts);
1306
+		$parts = explode('/', $url);
1307
+		if (substr($url, -1) == '/') array_pop($parts);
1311 1308
 		array_pop($parts);
1312 1309
 		if ($url[0] != '/' && count($parts) == 3 || count($parts) == 1 && $parts[0] === '')
1313 1310
 		{
1314
-			array_push($parts,'');	// scheme://host is wrong (no path), has to be scheme://host/
1311
+			array_push($parts, ''); // scheme://host is wrong (no path), has to be scheme://host/
1315 1312
 		}
1316 1313
 		//error_log(__METHOD__."($url)=".implode('/',$parts).($query ? '?'.$query : ''));
1317
-		return implode('/',$parts).($query ? '?'.$query : '');
1314
+		return implode('/', $parts).($query ? '?'.$query : '');
1318 1315
 	}
1319 1316
 
1320 1317
 	/**
@@ -1326,13 +1323,13 @@  discard block
 block discarded – undo
1326 1323
 	 * @param array $stat =null stat for path, default queried by this function
1327 1324
 	 * @return boolean
1328 1325
 	 */
1329
-	static function has_owner_rights($path,array $stat=null)
1326
+	static function has_owner_rights($path, array $stat = null)
1330 1327
 	{
1331
-		if (!$stat) $stat = self::url_stat($path,0);
1328
+		if (!$stat) $stat = self::url_stat($path, 0);
1332 1329
 
1333
-		return $stat['uid'] == self::$user ||	// user is the owner
1334
-			self::$is_root ||					// class runs with root rights
1335
-			!$stat['uid'] && $stat['gid'] && self::$is_admin;	// group directory and user is an eGW admin
1330
+		return $stat['uid'] == self::$user || // user is the owner
1331
+			self::$is_root || // class runs with root rights
1332
+			!$stat['uid'] && $stat['gid'] && self::$is_admin; // group directory and user is an eGW admin
1336 1333
 	}
1337 1334
 
1338 1335
 	/**
@@ -1344,22 +1341,22 @@  discard block
 block discarded – undo
1344 1341
 	 * @param string $relative relative path to add to $url
1345 1342
 	 * @return string
1346 1343
 	 */
1347
-	static function concat($_url,$relative)
1344
+	static function concat($_url, $relative)
1348 1345
 	{
1349
-		list($url,$query) = explode('?',$_url,2);
1350
-		if (substr($url,-1) == '/') $url = substr($url,0,-1);
1346
+		list($url, $query) = explode('?', $_url, 2);
1347
+		if (substr($url, -1) == '/') $url = substr($url, 0, -1);
1351 1348
 		$ret = ($relative === '' || $relative[0] == '/' ? $url.$relative : $url.'/'.$relative);
1352 1349
 
1353 1350
 		// now normalize the path (remove "/something/..")
1354
-		while (strpos($ret,'/../') !== false)
1351
+		while (strpos($ret, '/../') !== false)
1355 1352
 		{
1356
-			list($a_str,$b_str) = explode('/../',$ret,2);
1357
-			$a = explode('/',$a_str);
1353
+			list($a_str, $b_str) = explode('/../', $ret, 2);
1354
+			$a = explode('/', $a_str);
1358 1355
 			array_pop($a);
1359
-			$b = explode('/',$b_str);
1360
-			$ret = implode('/',array_merge($a,$b));
1356
+			$b = explode('/', $b_str);
1357
+			$ret = implode('/', array_merge($a, $b));
1361 1358
 		}
1362
-		return $ret.($query ? (strpos($url,'?')===false ? '?' : '&').$query : '');
1359
+		return $ret.($query ? (strpos($url, '?') === false ? '?' : '&').$query : '');
1363 1360
 	}
1364 1361
 
1365 1362
 	/**
@@ -1370,11 +1367,11 @@  discard block
 block discarded – undo
1370 1367
 	 */
1371 1368
 	static function build_url(array $url_parts)
1372 1369
 	{
1373
-		$url = (!isset($url_parts['scheme'])?'':$url_parts['scheme'].'://'.
1374
-			(!isset($url_parts['user'])?'':$url_parts['user'].(!isset($url_parts['pass'])?'':':'.$url_parts['pass']).'@').
1370
+		$url = (!isset($url_parts['scheme']) ? '' : $url_parts['scheme'].'://'.
1371
+			(!isset($url_parts['user']) ? '' : $url_parts['user'].(!isset($url_parts['pass']) ? '' : ':'.$url_parts['pass']).'@').
1375 1372
 			$url_parts['host']).$url_parts['path'].
1376
-			(!isset($url_parts['query'])?'':'?'.$url_parts['query']).
1377
-			(!isset($url_parts['fragment'])?'':'?'.$url_parts['fragment']);
1373
+			(!isset($url_parts['query']) ? '' : '?'.$url_parts['query']).
1374
+			(!isset($url_parts['fragment']) ? '' : '?'.$url_parts['fragment']);
1378 1375
 		//error_log(__METHOD__.'('.array2string($url_parts).") = '".$url."'");
1379 1376
 		return $url;
1380 1377
 	}
@@ -1392,19 +1389,19 @@  discard block
 block discarded – undo
1392 1389
 	 * @todo get $force_download working through webdav
1393 1390
 	 * @return string
1394 1391
 	 */
1395
-	static function download_url($path,$force_download=false)
1392
+	static function download_url($path, $force_download = false)
1396 1393
 	{
1397
-		if (($url = self::_call_on_backend('download_url',array($path,$force_download),true)))
1394
+		if (($url = self::_call_on_backend('download_url', array($path, $force_download), true)))
1398 1395
 		{
1399 1396
 			return $url;
1400 1397
 		}
1401 1398
 		if ($path[0] != '/')
1402 1399
 		{
1403
-			$path = self::parse_url($path,PHP_URL_PATH);
1400
+			$path = self::parse_url($path, PHP_URL_PATH);
1404 1401
 		}
1405 1402
 		// we do NOT need to encode % itself, as our path are already url encoded, with the exception of ' ' and '+'
1406 1403
 		// we urlencode double quotes '"', as that fixes many problems in html markup
1407
-		return '/webdav.php'.strtr($path,array('+' => '%2B',' ' => '%20','"' => '%22')).($force_download ? '?download' : '');
1404
+		return '/webdav.php'.strtr($path, array('+' => '%2B', ' ' => '%20', '"' => '%22')).($force_download ? '?download' : '');
1408 1405
 	}
1409 1406
 
1410 1407
 	/**
@@ -1432,12 +1429,12 @@  discard block
 block discarded – undo
1432 1429
 		// eg: User selected /home/nathan/picture.jpg, /home/Pictures/logo.jpg
1433 1430
 		// We want /home
1434 1431
 		$dirs = array();
1435
-		foreach($_files as $file)
1432
+		foreach ($_files as $file)
1436 1433
 		{
1437 1434
 			$dirs[] = self::dirname($file);
1438 1435
 		}
1439 1436
 		$paths = array_unique($dirs);
1440
-		if(count($paths) > 0)
1437
+		if (count($paths) > 0)
1441 1438
 		{
1442 1439
 			// Shortest to longest
1443 1440
 			usort($paths, function($a, $b) {
@@ -1445,13 +1442,13 @@  discard block
 block discarded – undo
1445 1442
 			});
1446 1443
 
1447 1444
 			// Start with shortest, pop off sub-directories that don't match
1448
-			$parts = explode('/',$paths[0]);
1449
-			foreach($paths as $path)
1445
+			$parts = explode('/', $paths[0]);
1446
+			foreach ($paths as $path)
1450 1447
 			{
1451
-				$dirs = explode('/',$path);
1452
-				foreach($dirs as $dir_index => $dir)
1448
+				$dirs = explode('/', $path);
1449
+				foreach ($dirs as $dir_index => $dir)
1453 1450
 				{
1454
-					if($parts[$dir_index] && $parts[$dir_index] != $dir)
1451
+					if ($parts[$dir_index] && $parts[$dir_index] != $dir)
1455 1452
 					{
1456 1453
 						unset($parts[$dir_index]);
1457 1454
 					}
@@ -1470,24 +1467,23 @@  discard block
 block discarded – undo
1470 1467
 			// Linux
1471 1468
 			'/',
1472 1469
 			// Windows
1473
-			'\\','?','%','*',':','|',/*'.',*/ '"','<','>'
1470
+			'\\', '?', '%', '*', ':', '|', /*'.',*/ '"', '<', '>'
1474 1471
 		);
1475 1472
 
1476 1473
 		// A nice name for the user,
1477
-		$filename = $GLOBALS['egw_info']['server']['site_title'] . '_' .
1478
-			str_replace($replace,'_',(
1474
+		$filename = $GLOBALS['egw_info']['server']['site_title'].'_'.
1475
+			str_replace($replace, '_', (
1479 1476
 			$name ? $name : (
1480 1477
 			count($_files) == 1 ?
1481 1478
 			// Just one file (hopefully a directory?) selected
1482
-			self::basename($_files[0]) :
1483
-			// Use the lowest common directory (eg: Infolog, Open, nathan)
1479
+			self::basename($_files[0]) : // Use the lowest common directory (eg: Infolog, Open, nathan)
1484 1480
 			self::basename($base_dir))
1485
-		)) . '.zip';
1481
+		)).'.zip';
1486 1482
 
1487 1483
 		// Make sure basename is a dir
1488
-		if(substr($base_dir, -1) != '/')
1484
+		if (substr($base_dir, -1) != '/')
1489 1485
 		{
1490
-			$base_dir .='/';
1486
+			$base_dir .= '/';
1491 1487
 		}
1492 1488
 
1493 1489
 		// Go into directories, find them all
@@ -1498,37 +1494,37 @@  discard block
 block discarded – undo
1498 1494
 		$tempfiles = array();
1499 1495
 
1500 1496
 		// Give 1 second per file, but try to allow more time for big files when amount of files is low
1501
-		set_time_limit((count($files)<=9?10:count($files)));
1497
+		set_time_limit((count($files) <= 9 ? 10 : count($files)));
1502 1498
 
1503 1499
 		// Add files to archive
1504
-		foreach($files as &$addfile)
1500
+		foreach ($files as &$addfile)
1505 1501
 		{
1506 1502
 			// Use relative paths inside zip
1507 1503
 			$relative = substr($addfile, strlen($base_dir));
1508 1504
 
1509 1505
 			// Use safe names - replace unsafe chars, convert to ASCII (ZIP spec says CP437, but we'll try)
1510
-			$path = explode('/',$relative);
1511
-			$_name = Translation::convert(Translation::to_ascii(implode('/', str_replace($replace,'_',$path))),false,'ASCII');
1506
+			$path = explode('/', $relative);
1507
+			$_name = Translation::convert(Translation::to_ascii(implode('/', str_replace($replace, '_', $path))), false, 'ASCII');
1512 1508
 
1513 1509
 			// Don't go infinite with app entries
1514
-			if(self::is_link($addfile))
1510
+			if (self::is_link($addfile))
1515 1511
 			{
1516
-				if(in_array($addfile, $links)) continue;
1512
+				if (in_array($addfile, $links)) continue;
1517 1513
 				$links[] = $addfile;
1518 1514
 			}
1519 1515
 			// Add directory - if empty, client app might not show it though
1520
-			if(self::is_dir($addfile))
1516
+			if (self::is_dir($addfile))
1521 1517
 			{
1522 1518
 				// Zip directories
1523 1519
 				$zip->addEmptyDir($addfile);
1524 1520
 			}
1525
-			else if(self::is_readable($addfile))
1521
+			else if (self::is_readable($addfile))
1526 1522
 			{
1527 1523
 				// Copy to temp file, as ZipArchive fails to read VFS
1528 1524
 				$temp = tempnam($GLOBALS['egw_info']['server']['temp_dir'], 'zip_');
1529
-				$from = self::fopen($addfile,'r');
1530
-		 		$to = fopen($temp,'w');
1531
-				if(!stream_copy_to_stream($from,$to) || !$zip->addFile($temp, $_name))
1525
+				$from = self::fopen($addfile, 'r');
1526
+		 		$to = fopen($temp, 'w');
1527
+				if (!stream_copy_to_stream($from, $to) || !$zip->addFile($temp, $_name))
1532 1528
 				{
1533 1529
 					unlink($temp);
1534 1530
 					trigger_error("Could not add $addfile to ZIP file", E_USER_ERROR);
@@ -1539,10 +1535,10 @@  discard block
 block discarded – undo
1539 1535
 
1540 1536
 				// Add comment in
1541 1537
 				$props = self::propfind($addfile);
1542
-				if($props)
1538
+				if ($props)
1543 1539
 				{
1544
-					$comment = self::find_prop($props,'comment');
1545
-					if($comment)
1540
+					$comment = self::find_prop($props, 'comment');
1541
+					if ($comment)
1546 1542
 					{
1547 1543
 						$zip->setCommentName($_name, $comment);
1548 1544
 					}
@@ -1552,34 +1548,34 @@  discard block
 block discarded – undo
1552 1548
 		}
1553 1549
 
1554 1550
 		// Set a comment to help tell them apart
1555
-		$zip->setArchiveComment(lang('Created by %1', $GLOBALS['egw_info']['user']['account_lid']) . ' ' .DateTime::to());
1551
+		$zip->setArchiveComment(lang('Created by %1', $GLOBALS['egw_info']['user']['account_lid']).' '.DateTime::to());
1556 1552
 
1557 1553
 		// Record total for debug, not available after close()
1558 1554
 		$total_files = $zip->numFiles;
1559 1555
 
1560 1556
 		$result = $zip->close();
1561
-		if(!$result || !filesize($zip_file))
1557
+		if (!$result || !filesize($zip_file))
1562 1558
 		{
1563 1559
 			error_log('close() result: '.array2string($result));
1564 1560
 			return 'Error creating zip file';
1565 1561
 		}
1566 1562
 
1567
-		error_log("Total files: " . $total_files . " Peak memory to zip: " . self::hsize(memory_get_peak_usage(true)));
1563
+		error_log("Total files: ".$total_files." Peak memory to zip: ".self::hsize(memory_get_peak_usage(true)));
1568 1564
 
1569 1565
 		// Stop any buffering
1570
-		while(ob_get_level() > 0)
1566
+		while (ob_get_level() > 0)
1571 1567
 		{
1572 1568
 			ob_end_clean();
1573 1569
 		}
1574 1570
 
1575 1571
 		// Stream the file to the client
1576 1572
 		header("Content-Type: application/zip");
1577
-		header("Content-Length: " . filesize($zip_file));
1573
+		header("Content-Length: ".filesize($zip_file));
1578 1574
 		header("Content-Disposition: attachment; filename=\"$filename\"");
1579 1575
 		readfile($zip_file);
1580 1576
 
1581 1577
 		unlink($zip_file);
1582
-		foreach($tempfiles as $temp_file)
1578
+		foreach ($tempfiles as $temp_file)
1583 1579
 		{
1584 1580
 			unlink($temp_file);
1585 1581
 		}
@@ -1613,7 +1609,7 @@  discard block
 block discarded – undo
1613 1609
 	 * @param boolean $check_writable =true should we check if the ressource is writable, before granting locks, default yes
1614 1610
 	 * @return boolean true on success
1615 1611
 	 */
1616
-	static function lock($path,&$token,&$timeout,&$owner,&$scope,&$type,$update=false,$check_writable=true)
1612
+	static function lock($path, &$token, &$timeout, &$owner, &$scope, &$type, $update = false, $check_writable = true)
1617 1613
 	{
1618 1614
 		// we require write rights to lock/unlock a resource
1619 1615
 		if (!$path || $update && !$token || $check_writable &&
@@ -1631,28 +1627,28 @@  discard block
 block discarded – undo
1631 1627
 
1632 1628
 		if ($update)	// Lock Update
1633 1629
 		{
1634
-			if (($ret = (boolean)($row = self::$db->select(self::LOCK_TABLE,array('lock_owner','lock_exclusive','lock_write'),array(
1630
+			if (($ret = (boolean)($row = self::$db->select(self::LOCK_TABLE, array('lock_owner', 'lock_exclusive', 'lock_write'), array(
1635 1631
 				'lock_path' => $path,
1636 1632
 				'lock_token' => $token,
1637
-			),__LINE__,__FILE__)->fetch())))
1633
+			), __LINE__, __FILE__)->fetch())))
1638 1634
 			{
1639 1635
 				$owner = $row['lock_owner'];
1640 1636
 				$scope = Db::from_bool($row['lock_exclusive']) ? 'exclusive' : 'shared';
1641 1637
 				$type  = Db::from_bool($row['lock_write']) ? 'write' : 'read';
1642 1638
 
1643
-				self::$db->update(self::LOCK_TABLE,array(
1639
+				self::$db->update(self::LOCK_TABLE, array(
1644 1640
 					'lock_expires' => $timeout,
1645 1641
 					'lock_modified' => time(),
1646
-				),array(
1642
+				), array(
1647 1643
 					'lock_path' => $path,
1648 1644
 					'lock_token' => $token,
1649
-				),__LINE__,__FILE__);
1645
+				), __LINE__, __FILE__);
1650 1646
 			}
1651 1647
 		}
1652 1648
 		// HTTP_WebDAV_Server does this check before calling LOCK, but we want to be complete and usable outside WebDAV
1653
-		elseif(($lock = self::checkLock($path)) && ($lock['scope'] == 'exclusive' || $scope == 'exclusive'))
1649
+		elseif (($lock = self::checkLock($path)) && ($lock['scope'] == 'exclusive' || $scope == 'exclusive'))
1654 1650
 		{
1655
-			$ret = false;	// there's alread a lock
1651
+			$ret = false; // there's alread a lock
1656 1652
 		}
1657 1653
 		else
1658 1654
 		{
@@ -1667,7 +1663,7 @@  discard block
 block discarded – undo
1667 1663
 				$token = HTTP_WebDAV_Server::_new_locktoken();
1668 1664
 			}
1669 1665
 			try {
1670
-				self::$db->insert(self::LOCK_TABLE,array(
1666
+				self::$db->insert(self::LOCK_TABLE, array(
1671 1667
 					'lock_token' => $token,
1672 1668
 					'lock_path'  => $path,
1673 1669
 					'lock_created' => time(),
@@ -1676,12 +1672,12 @@  discard block
 block discarded – undo
1676 1672
 					'lock_expires' => $timeout,
1677 1673
 					'lock_exclusive' => $scope == 'exclusive',
1678 1674
 					'lock_write' => $type == 'write',
1679
-				),false,__LINE__,__FILE__);
1675
+				), false, __LINE__, __FILE__);
1680 1676
 				$ret = true;
1681 1677
 			}
1682
-			catch(Db\Exception $e) {
1678
+			catch (Db\Exception $e) {
1683 1679
 				unset($e);
1684
-				$ret = false;	// there's already a lock
1680
+				$ret = false; // there's already a lock
1685 1681
 			}
1686 1682
 		}
1687 1683
 		if (self::LOCK_DEBUG) error_log(__METHOD__."($path,$token,$timeout,$owner,$scope,$type,update=$update,check_writable=$check_writable) returns ".($ret ? 'true' : 'false'));
@@ -1696,17 +1692,17 @@  discard block
 block discarded – undo
1696 1692
 	 * @param boolean $check_writable =true should we check if the ressource is writable, before granting locks, default yes
1697 1693
      * @return boolean true on success
1698 1694
      */
1699
-    static function unlock($path,$token,$check_writable=true)
1695
+    static function unlock($path, $token, $check_writable = true)
1700 1696
     {
1701 1697
 		// we require write rights to lock/unlock a resource
1702 1698
 		if ($check_writable && !self::is_writable($path))
1703 1699
 		{
1704 1700
 			return false;
1705 1701
 		}
1706
-        if (($ret = self::$db->delete(self::LOCK_TABLE,array(
1702
+        if (($ret = self::$db->delete(self::LOCK_TABLE, array(
1707 1703
         	'lock_path' => $path,
1708 1704
         	'lock_token' => $token,
1709
-        ),__LINE__,__FILE__) && self::$db->affected_rows()))
1705
+        ), __LINE__, __FILE__) && self::$db->affected_rows()))
1710 1706
         {
1711 1707
         	// remove the lock from the cache too
1712 1708
         	unset(self::$lock_cache[$path]);
@@ -1725,31 +1721,31 @@  discard block
 block discarded – undo
1725 1721
 	{
1726 1722
 		if (isset(self::$lock_cache[$path]))
1727 1723
 		{
1728
-			if (self::LOCK_DEBUG) error_log(__METHOD__."($path) returns from CACHE ".str_replace(array("\n",'    '),'',print_r(self::$lock_cache[$path],true)));
1724
+			if (self::LOCK_DEBUG) error_log(__METHOD__."($path) returns from CACHE ".str_replace(array("\n", '    '), '', print_r(self::$lock_cache[$path], true)));
1729 1725
 			return self::$lock_cache[$path];
1730 1726
 		}
1731 1727
 		$where = 'lock_path='.self::$db->quote($path);
1732 1728
 		// ToDo: additional check parent dirs for locks and children of the requested directory
1733 1729
 		//$where .= ' OR '.self::$db->quote($path).' LIKE '.self::$db->concat('lock_path',"'%'").' OR lock_path LIKE '.self::$db->quote($path.'%');
1734 1730
 		// ToDo: shared locks can return multiple rows
1735
-		if (($result = self::$db->select(self::LOCK_TABLE,'*',$where,__LINE__,__FILE__)->fetch()))
1731
+		if (($result = self::$db->select(self::LOCK_TABLE, '*', $where, __LINE__, __FILE__)->fetch()))
1736 1732
 		{
1737
-			$result = Db::strip_array_keys($result,'lock_');
1733
+			$result = Db::strip_array_keys($result, 'lock_');
1738 1734
 			$result['type']  = Db::from_bool($result['write']) ? 'write' : 'read';
1739 1735
 			$result['scope'] = Db::from_bool($result['exclusive']) ? 'exclusive' : 'shared';
1740 1736
 			$result['depth'] = Db::from_bool($result['recursive']) ? 'infinite' : 0;
1741 1737
 		}
1742 1738
 		if ($result && $result['expires'] < time())	// lock is expired --> remove it
1743 1739
 		{
1744
-	        self::$db->delete(self::LOCK_TABLE,array(
1740
+	        self::$db->delete(self::LOCK_TABLE, array(
1745 1741
 	        	'lock_path' => $result['path'],
1746 1742
 	        	'lock_token' => $result['token'],
1747
-	        ),__LINE__,__FILE__);
1743
+	        ), __LINE__, __FILE__);
1748 1744
 
1749
-			if (self::LOCK_DEBUG) error_log(__METHOD__."($path) lock is expired at ".date('Y-m-d H:i:s',$result['expires'])." --> removed");
1745
+			if (self::LOCK_DEBUG) error_log(__METHOD__."($path) lock is expired at ".date('Y-m-d H:i:s', $result['expires'])." --> removed");
1750 1746
 	        $result = false;
1751 1747
 		}
1752
-		if (self::LOCK_DEBUG) error_log(__METHOD__."($path) returns ".($result?array2string($result):'false'));
1748
+		if (self::LOCK_DEBUG) error_log(__METHOD__."($path) returns ".($result ? array2string($result) : 'false'));
1753 1749
 		return self::$lock_cache[$path] = $result;
1754 1750
 	}
1755 1751
 
@@ -1760,10 +1756,10 @@  discard block
 block discarded – undo
1760 1756
 	 * @param array $content =null
1761 1757
 	 * @return array|boolean array with values for keys 'data','etemplate','name','label','help' or false if not supported by backend
1762 1758
 	 */
1763
-	static function getExtraInfo($path,array $content=null)
1759
+	static function getExtraInfo($path, array $content = null)
1764 1760
 	{
1765 1761
 		$extra = array();
1766
-		if (($extra_info = self::_call_on_backend('extra_info',array($path,$content),true)))	// true = fail silent if backend does NOT support it
1762
+		if (($extra_info = self::_call_on_backend('extra_info', array($path, $content), true)))	// true = fail silent if backend does NOT support it
1767 1763
 		{
1768 1764
 			$extra[] = $extra_info;
1769 1765
 		}
@@ -1774,7 +1770,7 @@  discard block
 block discarded – undo
1774 1770
 			'content' => $content,
1775 1771
 		))))
1776 1772
 		{
1777
-			foreach($vfs_extra as $data)
1773
+			foreach ($vfs_extra as $data)
1778 1774
 			{
1779 1775
 				$extra = $extra ? array_merge($extra, $data) : $data;
1780 1776
 			}
@@ -1789,7 +1785,7 @@  discard block
 block discarded – undo
1789 1785
 	 * @param int|string $id
1790 1786
 	 * @return string
1791 1787
 	 */
1792
-	static function app_entry_lock_path($app,$id)
1788
+	static function app_entry_lock_path($app, $id)
1793 1789
 	{
1794 1790
 		return "/apps/$app/entry/$id";
1795 1791
 	}
@@ -1803,7 +1799,7 @@  discard block
 block discarded – undo
1803 1799
 		//'%' => '%25',	// % should be encoded, but easily leads to double encoding, therefore better NOT encodig it
1804 1800
 		'#' => '%23',
1805 1801
 		'?' => '%3F',
1806
-		'/' => '',	// better remove it completly
1802
+		'/' => '', // better remove it completly
1807 1803
 	);
1808 1804
 
1809 1805
 	/**
@@ -1818,7 +1814,7 @@  discard block
 block discarded – undo
1818 1814
 	 */
1819 1815
 	static public function encodePathComponent($component)
1820 1816
 	{
1821
-		return str_replace(array_keys(self::$encode),array_values(self::$encode),$component);
1817
+		return str_replace(array_keys(self::$encode), array_values(self::$encode), $component);
1822 1818
 	}
1823 1819
 
1824 1820
 	/**
@@ -1831,7 +1827,7 @@  discard block
 block discarded – undo
1831 1827
 	 */
1832 1828
 	static public function encodePath($path)
1833 1829
 	{
1834
-		return implode('/',self::encodePathComponent(explode('/',$path)));
1830
+		return implode('/', self::encodePathComponent(explode('/', $path)));
1835 1831
 	}
1836 1832
 
1837 1833
 	/**
@@ -1886,7 +1882,7 @@  discard block
 block discarded – undo
1886 1882
 		{
1887 1883
 			$image = Image::find($mime_sub, 'navbar');
1888 1884
 		}
1889
-		else if ($file && $mime_main == 'image' && in_array($mime_sub, array('png','jpeg','jpg','gif','bmp')) &&
1885
+		else if ($file && $mime_main == 'image' && in_array($mime_sub, array('png', 'jpeg', 'jpg', 'gif', 'bmp')) &&
1890 1886
 		         (string)$GLOBALS['egw_info']['server']['link_list_thumbnail'] != '0' &&
1891 1887
 		         (string)$GLOBALS['egw_info']['user']['preferences']['common']['link_list_thumbnail'] != '0' &&
1892 1888
 		         ($stat = self::stat($file)) && $stat['size'] < 1500000)
@@ -1941,7 +1937,7 @@  discard block
 block discarded – undo
1941 1937
 	 * @param array& $copied =null on return files copied
1942 1938
 	 * @return boolean true for no errors, false otherwise
1943 1939
 	 */
1944
-	static public function copy_files(array $src, $dst, &$errs=null, array &$copied=null)
1940
+	static public function copy_files(array $src, $dst, &$errs = null, array &$copied = null)
1945 1941
 	{
1946 1942
 		if (self::is_dir($dst))
1947 1943
 		{
@@ -1959,7 +1955,7 @@  discard block
 block discarded – undo
1959 1955
 						if ($file !== $target)
1960 1956
 						{
1961 1957
 							// Create the target directory
1962
-							self::mkdir($target,null,STREAM_MKDIR_RECURSIVE);
1958
+							self::mkdir($target, null, STREAM_MKDIR_RECURSIVE);
1963 1959
 
1964 1960
 							$copied[] = $file;
1965 1961
 							$copied[] = $target; // < newly created folder must not be copied again!
@@ -2002,7 +1998,7 @@  discard block
 block discarded – undo
2002 1998
 	{
2003 1999
 		if (self::is_dir($dst))
2004 2000
 		{
2005
-			foreach($src as $file)
2001
+			foreach ($src as $file)
2006 2002
 			{
2007 2003
 				$target = self::concat($dst, self::basename($file));
2008 2004
 
@@ -2034,7 +2030,7 @@  discard block
 block discarded – undo
2034 2030
 	 * @param boolean $check_is_uploaded_file =true should method perform an is_uploaded_file check, default yes
2035 2031
 	 * @return boolean|array stat array on success, false on error
2036 2032
 	 */
2037
-	static public function copy_uploaded($src,$target,$props=null,$check_is_uploaded_file=true)
2033
+	static public function copy_uploaded($src, $target, $props = null, $check_is_uploaded_file = true)
2038 2034
 	{
2039 2035
 		$tmp_name = is_array($src) ? $src['tmp_name'] : $src;
2040 2036
 
@@ -2054,12 +2050,12 @@  discard block
 block discarded – undo
2054 2050
 		}
2055 2051
 		if ($props)
2056 2052
 		{
2057
-			if (!is_array($props)) $props = array(array('name' => 'comment','val' => $props));
2053
+			if (!is_array($props)) $props = array(array('name' => 'comment', 'val' => $props));
2058 2054
 
2059 2055
 			// if $props is name => value pairs, convert it to internal array or array with values for keys 'name', 'val' and optional 'ns'
2060 2056
 			if (!isset($props[0]))
2061 2057
 			{
2062
-				foreach($props as $name => $val)
2058
+				foreach ($props as $name => $val)
2063 2059
 				{
2064 2060
 					if (($name == 'comment' || $name[0] == '#') && $val)	// only copy 'comment' and cfs
2065 2061
 					{
@@ -2077,8 +2073,8 @@  discard block
 block discarded – undo
2077 2073
 			// set props before copying the file, so notifications already contain them
2078 2074
 			if (!self::stat($target))
2079 2075
 			{
2080
-				self::touch($target);	// create empty file, to be able to attach properties
2081
-				self::$treat_as_new = true;	// notify as new
2076
+				self::touch($target); // create empty file, to be able to attach properties
2077
+				self::$treat_as_new = true; // notify as new
2082 2078
 			}
2083 2079
 			self::proppatch($target, $props);
2084 2080
 		}
@@ -2092,7 +2088,7 @@  discard block
 block discarded – undo
2092 2088
 		}
2093 2089
 		else
2094 2090
 		{
2095
-			$ret = copy($tmp_name,self::PREFIX.$target) ? self::stat($target) : false;
2091
+			$ret = copy($tmp_name, self::PREFIX.$target) ? self::stat($target) : false;
2096 2092
 		}
2097 2093
 		if (self::LOG_LEVEL > 1 || !$ret && self::LOG_LEVEL) error_log(__METHOD__."($tmp_name, $target, ".array2string($props).") returning ".array2string($ret));
2098 2094
 		return $ret;
Please login to merge, or discard this patch.
Braces   +237 added lines, -62 removed lines patch added patch discarded remove patch
@@ -221,7 +221,10 @@  discard block
 block discarded – undo
221 221
 		}
222 222
 		foreach($props as &$prop)
223 223
 		{
224
-			if ($prop['name'] == $name && $prop['ns'] == $ns) return $prop;
224
+			if ($prop['name'] == $name && $prop['ns'] == $ns)
225
+			{
226
+				return $prop;
227
+			}
225 228
 		}
226 229
 		return null;
227 230
 	}
@@ -314,11 +317,17 @@  discard block
 block discarded – undo
314 317
 	 */
315 318
 	static function mount($url=null,$path=null,$check_url=null,$persitent_mount=true,$clear_fstab=false)
316 319
 	{
317
-		if (is_null($check_url)) $check_url = strpos($url,'$') === false;
320
+		if (is_null($check_url))
321
+		{
322
+			$check_url = strpos($url,'$') === false;
323
+		}
318 324
 
319
-		if (!isset($GLOBALS['egw_info']['server']['vfs_fstab']))	// happens eg. in setup
325
+		if (!isset($GLOBALS['egw_info']['server']['vfs_fstab']))
326
+		{
327
+			// happens eg. in setup
320 328
 		{
321 329
 			$api_config = Config::read('phpgwapi');
330
+		}
322 331
 			if (isset($api_config['vfs_fstab']) && is_array($api_config['vfs_fstab']))
323 332
 			{
324 333
 				self::$fstab = $api_config['vfs_fstab'];
@@ -334,12 +343,18 @@  discard block
 block discarded – undo
334 343
 		}
335 344
 		if (is_null($url) || is_null($path))
336 345
 		{
337
-			if (self::LOG_LEVEL > 1) error_log(__METHOD__.'('.array2string($url).','.array2string($path).') returns '.array2string(self::$fstab));
346
+			if (self::LOG_LEVEL > 1)
347
+			{
348
+				error_log(__METHOD__.'('.array2string($url).','.array2string($path).') returns '.array2string(self::$fstab));
349
+			}
338 350
 			return self::$fstab;
339 351
 		}
340 352
 		if (!self::$is_root)
341 353
 		{
342
-			if (self::LOG_LEVEL > 0) error_log(__METHOD__.'('.array2string($url).','.array2string($path).') permission denied, you are NOT root!');
354
+			if (self::LOG_LEVEL > 0)
355
+			{
356
+				error_log(__METHOD__.'('.array2string($url).','.array2string($path).') permission denied, you are NOT root!');
357
+			}
343 358
 			return false;	// only root can mount
344 359
 		}
345 360
 		if ($clear_fstab)
@@ -348,14 +363,20 @@  discard block
 block discarded – undo
348 363
 		}
349 364
 		if (isset(self::$fstab[$path]) && self::$fstab[$path] === $url)
350 365
 		{
351
-			if (self::LOG_LEVEL > 0) error_log(__METHOD__.'('.array2string($url).','.array2string($path).') already mounted.');
366
+			if (self::LOG_LEVEL > 0)
367
+			{
368
+				error_log(__METHOD__.'('.array2string($url).','.array2string($path).') already mounted.');
369
+			}
352 370
 			return true;	// already mounted
353 371
 		}
354 372
 		self::load_wrapper(self::parse_url($url,PHP_URL_SCHEME));
355 373
 
356 374
 		if ($check_url && (!file_exists($url) || opendir($url) === false))
357 375
 		{
358
-			if (self::LOG_LEVEL > 0) error_log(__METHOD__.'('.array2string($url).','.array2string($path).') url does NOT exist!');
376
+			if (self::LOG_LEVEL > 0)
377
+			{
378
+				error_log(__METHOD__.'('.array2string($url).','.array2string($path).') url does NOT exist!');
379
+			}
359 380
 			return false;	// url does not exist
360 381
 		}
361 382
 		self::$fstab[$path] = $url;
@@ -370,12 +391,18 @@  discard block
 block discarded – undo
370 391
 			Config::save_value('vfs_fstab',self::$fstab,'phpgwapi');
371 392
 			$GLOBALS['egw_info']['server']['vfs_fstab'] = self::$fstab;
372 393
 			// invalidate session cache
373
-			if (method_exists($GLOBALS['egw'],'invalidate_session_cache'))	// egw object in setup is limited
394
+			if (method_exists($GLOBALS['egw'],'invalidate_session_cache'))
395
+			{
396
+				// egw object in setup is limited
374 397
 			{
375 398
 				$GLOBALS['egw']->invalidate_session_cache();
376 399
 			}
400
+			}
401
+		}
402
+		if (self::LOG_LEVEL > 1)
403
+		{
404
+			error_log(__METHOD__.'('.array2string($url).','.array2string($path).') returns true (successful new mount).');
377 405
 		}
378
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__.'('.array2string($url).','.array2string($path).') returns true (successful new mount).');
379 406
 		return true;
380 407
 	}
381 408
 
@@ -388,12 +415,18 @@  discard block
 block discarded – undo
388 415
 	{
389 416
 		if (!self::$is_root)
390 417
 		{
391
-			if (self::LOG_LEVEL > 0) error_log(__METHOD__.'('.array2string($path).','.array2string($path).') permission denied, you are NOT root!');
418
+			if (self::LOG_LEVEL > 0)
419
+			{
420
+				error_log(__METHOD__.'('.array2string($path).','.array2string($path).') permission denied, you are NOT root!');
421
+			}
392 422
 			return false;	// only root can mount
393 423
 		}
394 424
 		if (!isset(self::$fstab[$path]) && ($path = array_search($path,self::$fstab)) === false)
395 425
 		{
396
-			if (self::LOG_LEVEL > 0) error_log(__METHOD__.'('.array2string($path).') NOT mounted!');
426
+			if (self::LOG_LEVEL > 0)
427
+			{
428
+				error_log(__METHOD__.'('.array2string($path).') NOT mounted!');
429
+			}
397 430
 			return false;	// $path not mounted
398 431
 		}
399 432
 		unset(self::$fstab[$path]);
@@ -401,11 +434,17 @@  discard block
 block discarded – undo
401 434
 		Config::save_value('vfs_fstab',self::$fstab,'phpgwapi');
402 435
 		$GLOBALS['egw_info']['server']['vfs_fstab'] = self::$fstab;
403 436
 		// invalidate session cache
404
-		if (method_exists($GLOBALS['egw'],'invalidate_session_cache'))	// egw object in setup is limited
437
+		if (method_exists($GLOBALS['egw'],'invalidate_session_cache'))
438
+		{
439
+			// egw object in setup is limited
405 440
 		{
406 441
 			$GLOBALS['egw']->invalidate_session_cache();
407 442
 		}
408
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__.'('.array2string($path).') returns true (successful unmount).');
443
+		}
444
+		if (self::LOG_LEVEL > 1)
445
+		{
446
+			error_log(__METHOD__.'('.array2string($path).') returns true (successful unmount).');
447
+		}
409 448
 		return true;
410 449
 	}
411 450
 
@@ -460,17 +499,27 @@  discard block
 block discarded – undo
460 499
 		$dirs_last = $options['depth'];	// put content of dirs before the dir itself
461 500
 		// show dirs on top by default, if no recursive listing (allways disabled if $type specified, as unnecessary)
462 501
 		$dirsontop = !$type && (isset($options['dirsontop']) ? (boolean)$options['dirsontop'] : isset($options['maxdepth'])&&$options['maxdepth']>0);
463
-		if ($dirsontop) $options['need_mime'] = true;	// otherwise dirsontop can NOT work
502
+		if ($dirsontop)
503
+		{
504
+			$options['need_mime'] = true;
505
+		}
506
+		// otherwise dirsontop can NOT work
464 507
 
465 508
 		// process some of the options (need to be done only once)
466
-		if (isset($options['name']) && !isset($options['name_preg']))	// change from simple *,? wildcards to preg regular expression once
509
+		if (isset($options['name']) && !isset($options['name_preg']))
510
+		{
511
+			// change from simple *,? wildcards to preg regular expression once
467 512
 		{
468 513
 			$options['name_preg'] = '/^'.str_replace(array('\\?','\\*'),array('.{1}','.*'),preg_quote($options['name'])).'$/i';
469 514
 		}
470
-		if (isset($options['path']) && !isset($options['preg_path']))	// change from simple *,? wildcards to preg regular expression once
515
+		}
516
+		if (isset($options['path']) && !isset($options['preg_path']))
517
+		{
518
+			// change from simple *,? wildcards to preg regular expression once
471 519
 		{
472 520
 			$options['path_preg'] = '/^'.str_replace(array('\\?','\\*'),array('.{1}','.*'),preg_quote($options['path'])).'$/i';
473 521
 		}
522
+		}
474 523
 		if (!isset($options['uid']))
475 524
 		{
476 525
 			if (isset($options['user']))
@@ -517,7 +566,10 @@  discard block
 block discarded – undo
517 566
 		{
518 567
 			if (!$url)
519 568
 			{
520
-				if ($path[0] != '/' || !self::stat($path)) continue;
569
+				if ($path[0] != '/' || !self::stat($path))
570
+				{
571
+					continue;
572
+				}
521 573
 				$path = self::PREFIX . $path;
522 574
 			}
523 575
 			if (!isset($options['remove']))
@@ -535,9 +587,17 @@  discard block
 block discarded – undo
535 587
 			{
536 588
 				while(($fname = readdir($dir)) !== false)
537 589
 				{
538
-					if ($fname == '.' || $fname == '..') continue;	// ignore current and parent dir!
590
+					if ($fname == '.' || $fname == '..')
591
+					{
592
+						continue;
593
+					}
594
+					// ignore current and parent dir!
539 595
 
540
-					if (self::is_hidden($fname, $options['show-deleted']) && !$options['hidden']) continue;	// ignore hidden files
596
+					if (self::is_hidden($fname, $options['show-deleted']) && !$options['hidden'])
597
+					{
598
+						continue;
599
+					}
600
+					// ignore hidden files
541 601
 
542 602
 					$file = self::concat($path, $fname);
543 603
 
@@ -549,8 +609,14 @@  discard block
 block discarded – undo
549 609
 					if (is_dir($file) && ($options['follow'] || !is_link($file)) && (!isset($options['maxdepth']) || $options['maxdepth'] > 1))
550 610
 					{
551 611
 						$opts = $options;
552
-						if ($opts['mindepth']) $opts['mindepth']--;
553
-						if ($opts['maxdepth']) $opts['depth']++;
612
+						if ($opts['mindepth'])
613
+						{
614
+							$opts['mindepth']--;
615
+						}
616
+						if ($opts['maxdepth'])
617
+						{
618
+							$opts['depth']++;
619
+						}
554 620
 						unset($opts['order']);
555 621
 						unset($opts['limit']);
556 622
 						foreach(self::find($options['url']?$file:self::parse_url($file,PHP_URL_PATH),$opts,true) as $p => $s)
@@ -615,7 +681,10 @@  discard block
 block discarded – undo
615 681
 		if (isset($options['limit']))
616 682
 		{
617 683
 			list($limit,$start) = explode(',',$options['limit']);
618
-			if (!$limit && !($limit = $GLOBALS['egw_info']['user']['preferences']['comman']['maxmatches'])) $limit = 15;
684
+			if (!$limit && !($limit = $GLOBALS['egw_info']['user']['preferences']['comman']['maxmatches']))
685
+			{
686
+				$limit = 15;
687
+			}
619 688
 			//echo "total=".self::$find_total.", limit=$options[limit] --> start=$start, limit=$limit<br>\n";
620 689
 
621 690
 			if ((int)$start || self::$find_total > $limit)
@@ -672,9 +741,13 @@  discard block
 block discarded – undo
672 741
 			return;	// not found, should not happen
673 742
 		}
674 743
 		if ($type && (($type == 'd') == !($stat['mode'] & Vfs\Sqlfs\StreamWrapper::MODE_DIR) ||	// != is_dir() which can be true for symlinks
675
-		    $type == 'F' && is_dir($path)))	// symlink to a directory
744
+		    $type == 'F' && is_dir($path)))
676 745
 		{
677
-			return;	// wrong type
746
+			// symlink to a directory
747
+		{
748
+			return;
749
+		}
750
+		// wrong type
678 751
 		}
679 752
 		$stat = array_slice($stat,13);	// remove numerical indices 0-12
680 753
 		$stat['path'] = self::parse_url($path,PHP_URL_PATH);
@@ -697,11 +770,15 @@  discard block
 block discarded – undo
697 770
 		}
698 771
 		if (isset($options['mime']) && $options['mime'] != $stat['mime'])
699 772
 		{
700
-			if ($options['mime'][0] == '/')	// perl regular expression given
773
+			if ($options['mime'][0] == '/')
774
+			{
775
+				// perl regular expression given
701 776
 			{
702 777
 				if (!preg_match($options['mime'], $stat['mime']))
703 778
 				{
704
-					return;	// wrong mime-type
779
+					return;
780
+			}
781
+			// wrong mime-type
705 782
 				}
706 783
 			}
707 784
 			else
@@ -1018,7 +1095,8 @@  discard block
 block discarded – undo
1018 1095
 			}
1019 1096
 
1020 1097
 			// sort by length descending, to show precedence
1021
-			usort($eacls, function($a, $b) {
1098
+			usort($eacls, function($a, $b)
1099
+			{
1022 1100
 				return strlen($b['path']) - strlen($a['path']);
1023 1101
 			});
1024 1102
 		}
@@ -1073,14 +1151,21 @@  discard block
 block discarded – undo
1073 1151
 	 */
1074 1152
 	static function mode2int($set,$mode=0)
1075 1153
 	{
1076
-		if (is_int($set))		// already an integer
1154
+		if (is_int($set))
1155
+		{
1156
+			// already an integer
1077 1157
 		{
1078 1158
 			return $set;
1079 1159
 		}
1080
-		if (is_numeric($set))	// octal string
1160
+		}
1161
+		if (is_numeric($set))
1162
+		{
1163
+			// octal string
1081 1164
 		{
1082 1165
 			//error_log(__METHOD__."($set,$mode) returning ".(int)base_convert($set,8,10));
1083
-			return (int)base_convert($set,8,10);	// convert octal to decimal
1166
+			return (int)base_convert($set,8,10);
1167
+		}
1168
+		// convert octal to decimal
1084 1169
 		}
1085 1170
 		foreach(explode(',',$set) as $s)
1086 1171
 		{
@@ -1136,34 +1221,55 @@  discard block
 block discarded – undo
1136 1221
 	 */
1137 1222
 	static function int2mode( $mode )
1138 1223
 	{
1139
-		if(($mode & self::MODE_LINK) == self::MODE_LINK) // Symbolic Link
1224
+		if(($mode & self::MODE_LINK) == self::MODE_LINK)
1225
+		{
1226
+			// Symbolic Link
1140 1227
 		{
1141 1228
 			$sP = 'l';
1142 1229
 		}
1143
-		elseif(($mode & 0xC000) == 0xC000) // Socket
1230
+		}
1231
+		elseif(($mode & 0xC000) == 0xC000)
1232
+		{
1233
+			// Socket
1144 1234
 		{
1145 1235
 			$sP = 's';
1146 1236
 		}
1147
-		elseif($mode & 0x1000)     // FIFO pipe
1237
+		}
1238
+		elseif($mode & 0x1000)
1239
+		{
1240
+			// FIFO pipe
1148 1241
 		{
1149 1242
 			$sP = 'p';
1150 1243
 		}
1151
-		elseif($mode & 0x2000) // Character special
1244
+		}
1245
+		elseif($mode & 0x2000)
1246
+		{
1247
+			// Character special
1152 1248
 		{
1153 1249
 			$sP = 'c';
1154 1250
 		}
1155
-		elseif($mode & 0x4000) // Directory
1251
+		}
1252
+		elseif($mode & 0x4000)
1253
+		{
1254
+			// Directory
1156 1255
 		{
1157 1256
 			$sP = 'd';
1158 1257
 		}
1159
-		elseif($mode & 0x6000) // Block special
1258
+		}
1259
+		elseif($mode & 0x6000)
1260
+		{
1261
+			// Block special
1160 1262
 		{
1161 1263
 			$sP = 'b';
1162 1264
 		}
1163
-		elseif($mode & 0x8000) // Regular
1265
+		}
1266
+		elseif($mode & 0x8000)
1267
+		{
1268
+			// Regular
1164 1269
 		{
1165 1270
 			$sP = '-';
1166 1271
 		}
1272
+		}
1167 1273
 		else                         // UNKNOWN
1168 1274
 		{
1169 1275
 			$sP = 'u';
@@ -1230,9 +1336,18 @@  discard block
 block discarded – undo
1230 1336
 	 */
1231 1337
 	static function hsize($size)
1232 1338
 	{
1233
-		if ($size < 1024) return $size;
1234
-		if ($size < 1024*1024) return sprintf('%3.1lfk',(float)$size/1024);
1235
-		if ($size < 1024*1024*1024) return sprintf('%3.1lfM',(float)$size/(1024*1024));
1339
+		if ($size < 1024)
1340
+		{
1341
+			return $size;
1342
+		}
1343
+		if ($size < 1024*1024)
1344
+		{
1345
+			return sprintf('%3.1lfk',(float)$size/1024);
1346
+		}
1347
+		if ($size < 1024*1024*1024)
1348
+		{
1349
+			return sprintf('%3.1lfM',(float)$size/(1024*1024));
1350
+		}
1236 1351
 		return sprintf('%3.1lfG',(float)$size/(1024*1024*1024));
1237 1352
 	}
1238 1353
 
@@ -1243,7 +1358,10 @@  discard block
 block discarded – undo
1243 1358
 	 */
1244 1359
 	static function int_size($_val)
1245 1360
 	{
1246
-		if(empty($_val))return 0;
1361
+		if(empty($_val))
1362
+		{
1363
+			return 0;
1364
+		}
1247 1365
 
1248 1366
 		$val = trim($_val);
1249 1367
 
@@ -1251,11 +1369,13 @@  discard block
 block discarded – undo
1251 1369
 		preg_match('#([0-9]+)[\s]*([a-z]+)#i', $val, $matches);
1252 1370
 
1253 1371
 		$last = '';
1254
-		if(isset($matches[2])){
1372
+		if(isset($matches[2]))
1373
+		{
1255 1374
 			$last = $matches[2];
1256 1375
 		}
1257 1376
 
1258
-		if(isset($matches[1])){
1377
+		if(isset($matches[1]))
1378
+		{
1259 1379
 			$val = (int) $matches[1];
1260 1380
 		}
1261 1381
 
@@ -1307,7 +1427,10 @@  discard block
 block discarded – undo
1307 1427
 			return false;
1308 1428
 		}
1309 1429
 		$parts = explode('/',$url);
1310
-		if (substr($url,-1) == '/') array_pop($parts);
1430
+		if (substr($url,-1) == '/')
1431
+		{
1432
+			array_pop($parts);
1433
+		}
1311 1434
 		array_pop($parts);
1312 1435
 		if ($url[0] != '/' && count($parts) == 3 || count($parts) == 1 && $parts[0] === '')
1313 1436
 		{
@@ -1328,7 +1451,10 @@  discard block
 block discarded – undo
1328 1451
 	 */
1329 1452
 	static function has_owner_rights($path,array $stat=null)
1330 1453
 	{
1331
-		if (!$stat) $stat = self::url_stat($path,0);
1454
+		if (!$stat)
1455
+		{
1456
+			$stat = self::url_stat($path,0);
1457
+		}
1332 1458
 
1333 1459
 		return $stat['uid'] == self::$user ||	// user is the owner
1334 1460
 			self::$is_root ||					// class runs with root rights
@@ -1347,7 +1473,10 @@  discard block
 block discarded – undo
1347 1473
 	static function concat($_url,$relative)
1348 1474
 	{
1349 1475
 		list($url,$query) = explode('?',$_url,2);
1350
-		if (substr($url,-1) == '/') $url = substr($url,0,-1);
1476
+		if (substr($url,-1) == '/')
1477
+		{
1478
+			$url = substr($url,0,-1);
1479
+		}
1351 1480
 		$ret = ($relative === '' || $relative[0] == '/' ? $url.$relative : $url.'/'.$relative);
1352 1481
 
1353 1482
 		// now normalize the path (remove "/something/..")
@@ -1440,7 +1569,8 @@  discard block
 block discarded – undo
1440 1569
 		if(count($paths) > 0)
1441 1570
 		{
1442 1571
 			// Shortest to longest
1443
-			usort($paths, function($a, $b) {
1572
+			usort($paths, function($a, $b)
1573
+			{
1444 1574
 				return strlen($a) - strlen($b);
1445 1575
 			});
1446 1576
 
@@ -1513,7 +1643,10 @@  discard block
 block discarded – undo
1513 1643
 			// Don't go infinite with app entries
1514 1644
 			if(self::is_link($addfile))
1515 1645
 			{
1516
-				if(in_array($addfile, $links)) continue;
1646
+				if(in_array($addfile, $links))
1647
+				{
1648
+					continue;
1649
+				}
1517 1650
 				$links[] = $addfile;
1518 1651
 			}
1519 1652
 			// Add directory - if empty, client app might not show it though
@@ -1624,12 +1757,17 @@  discard block
 block discarded – undo
1624 1757
     	// remove the lock info evtl. set in the cache
1625 1758
     	unset(self::$lock_cache[$path]);
1626 1759
 
1627
-    	if ($timeout < 1000000)	// < 1000000 is a relative timestamp, so we add the current time
1760
+    	if ($timeout < 1000000)
1761
+    	{
1762
+    		// < 1000000 is a relative timestamp, so we add the current time
1628 1763
     	{
1629 1764
     		$timeout += time();
1630 1765
     	}
1766
+    	}
1631 1767
 
1632
-		if ($update)	// Lock Update
1768
+		if ($update)
1769
+		{
1770
+			// Lock Update
1633 1771
 		{
1634 1772
 			if (($ret = (boolean)($row = self::$db->select(self::LOCK_TABLE,array('lock_owner','lock_exclusive','lock_write'),array(
1635 1773
 				'lock_path' => $path,
@@ -1637,6 +1775,7 @@  discard block
 block discarded – undo
1637 1775
 			),__LINE__,__FILE__)->fetch())))
1638 1776
 			{
1639 1777
 				$owner = $row['lock_owner'];
1778
+		}
1640 1779
 				$scope = Db::from_bool($row['lock_exclusive']) ? 'exclusive' : 'shared';
1641 1780
 				$type  = Db::from_bool($row['lock_write']) ? 'write' : 'read';
1642 1781
 
@@ -1684,7 +1823,10 @@  discard block
 block discarded – undo
1684 1823
 				$ret = false;	// there's already a lock
1685 1824
 			}
1686 1825
 		}
1687
-		if (self::LOCK_DEBUG) error_log(__METHOD__."($path,$token,$timeout,$owner,$scope,$type,update=$update,check_writable=$check_writable) returns ".($ret ? 'true' : 'false'));
1826
+		if (self::LOCK_DEBUG)
1827
+		{
1828
+			error_log(__METHOD__."($path,$token,$timeout,$owner,$scope,$type,update=$update,check_writable=$check_writable) returns ".($ret ? 'true' : 'false'));
1829
+		}
1688 1830
 		return $ret;
1689 1831
 	}
1690 1832
 
@@ -1711,7 +1853,10 @@  discard block
 block discarded – undo
1711 1853
         	// remove the lock from the cache too
1712 1854
         	unset(self::$lock_cache[$path]);
1713 1855
         }
1714
-		if (self::LOCK_DEBUG) error_log(__METHOD__."($path,$token,$check_writable) returns ".($ret ? 'true' : 'false'));
1856
+		if (self::LOCK_DEBUG)
1857
+		{
1858
+			error_log(__METHOD__."($path,$token,$check_writable) returns ".($ret ? 'true' : 'false'));
1859
+		}
1715 1860
 		return $ret;
1716 1861
     }
1717 1862
 
@@ -1725,7 +1870,10 @@  discard block
 block discarded – undo
1725 1870
 	{
1726 1871
 		if (isset(self::$lock_cache[$path]))
1727 1872
 		{
1728
-			if (self::LOCK_DEBUG) error_log(__METHOD__."($path) returns from CACHE ".str_replace(array("\n",'    '),'',print_r(self::$lock_cache[$path],true)));
1873
+			if (self::LOCK_DEBUG)
1874
+			{
1875
+				error_log(__METHOD__."($path) returns from CACHE ".str_replace(array("\n",'    '),'',print_r(self::$lock_cache[$path],true)));
1876
+			}
1729 1877
 			return self::$lock_cache[$path];
1730 1878
 		}
1731 1879
 		$where = 'lock_path='.self::$db->quote($path);
@@ -1739,17 +1887,26 @@  discard block
 block discarded – undo
1739 1887
 			$result['scope'] = Db::from_bool($result['exclusive']) ? 'exclusive' : 'shared';
1740 1888
 			$result['depth'] = Db::from_bool($result['recursive']) ? 'infinite' : 0;
1741 1889
 		}
1742
-		if ($result && $result['expires'] < time())	// lock is expired --> remove it
1890
+		if ($result && $result['expires'] < time())
1891
+		{
1892
+			// lock is expired --> remove it
1743 1893
 		{
1744 1894
 	        self::$db->delete(self::LOCK_TABLE,array(
1745 1895
 	        	'lock_path' => $result['path'],
1746 1896
 	        	'lock_token' => $result['token'],
1747 1897
 	        ),__LINE__,__FILE__);
1898
+		}
1748 1899
 
1749
-			if (self::LOCK_DEBUG) error_log(__METHOD__."($path) lock is expired at ".date('Y-m-d H:i:s',$result['expires'])." --> removed");
1900
+			if (self::LOCK_DEBUG)
1901
+			{
1902
+				error_log(__METHOD__."($path) lock is expired at ".date('Y-m-d H:i:s',$result['expires'])." --> removed");
1903
+			}
1750 1904
 	        $result = false;
1751 1905
 		}
1752
-		if (self::LOCK_DEBUG) error_log(__METHOD__."($path) returns ".($result?array2string($result):'false'));
1906
+		if (self::LOCK_DEBUG)
1907
+		{
1908
+			error_log(__METHOD__."($path) returns ".($result?array2string($result):'false'));
1909
+		}
1753 1910
 		return self::$lock_cache[$path] = $result;
1754 1911
 	}
1755 1912
 
@@ -1763,10 +1920,13 @@  discard block
 block discarded – undo
1763 1920
 	static function getExtraInfo($path,array $content=null)
1764 1921
 	{
1765 1922
 		$extra = array();
1766
-		if (($extra_info = self::_call_on_backend('extra_info',array($path,$content),true)))	// true = fail silent if backend does NOT support it
1923
+		if (($extra_info = self::_call_on_backend('extra_info',array($path,$content),true)))
1924
+		{
1925
+			// true = fail silent if backend does NOT support it
1767 1926
 		{
1768 1927
 			$extra[] = $extra_info;
1769 1928
 		}
1929
+		}
1770 1930
 
1771 1931
 		if (($vfs_extra = Hooks::process(array(
1772 1932
 			'location' => 'vfs_extra',
@@ -2044,30 +2204,42 @@  discard block
 block discarded – undo
2044 2204
 		}
2045 2205
 		if ($check_is_uploaded_file && !is_resource($tmp_name) && !is_uploaded_file($tmp_name))
2046 2206
 		{
2047
-			if (self::LOG_LEVEL) error_log(__METHOD__."($tmp_name, $target, ".array2string($props).",$check_is_uploaded_file) returning FALSE !is_uploaded_file()");
2207
+			if (self::LOG_LEVEL)
2208
+			{
2209
+				error_log(__METHOD__."($tmp_name, $target, ".array2string($props).",$check_is_uploaded_file) returning FALSE !is_uploaded_file()");
2210
+			}
2048 2211
 			return false;
2049 2212
 		}
2050 2213
 		if (!(self::is_writable($target) || self::is_writable(self::dirname($target))))
2051 2214
 		{
2052
-			if (self::LOG_LEVEL) error_log(__METHOD__."($tmp_name, $target, ".array2string($props).",$check_is_uploaded_file) returning FALSE !writable");
2215
+			if (self::LOG_LEVEL)
2216
+			{
2217
+				error_log(__METHOD__."($tmp_name, $target, ".array2string($props).",$check_is_uploaded_file) returning FALSE !writable");
2218
+			}
2053 2219
 			return false;
2054 2220
 		}
2055 2221
 		if ($props)
2056 2222
 		{
2057
-			if (!is_array($props)) $props = array(array('name' => 'comment','val' => $props));
2223
+			if (!is_array($props))
2224
+			{
2225
+				$props = array(array('name' => 'comment','val' => $props));
2226
+			}
2058 2227
 
2059 2228
 			// if $props is name => value pairs, convert it to internal array or array with values for keys 'name', 'val' and optional 'ns'
2060 2229
 			if (!isset($props[0]))
2061 2230
 			{
2062 2231
 				foreach($props as $name => $val)
2063 2232
 				{
2064
-					if (($name == 'comment' || $name[0] == '#') && $val)	// only copy 'comment' and cfs
2233
+					if (($name == 'comment' || $name[0] == '#') && $val)
2234
+					{
2235
+						// only copy 'comment' and cfs
2065 2236
 					{
2066 2237
 						$vfs_props[] = array(
2067 2238
 							'name' => $name,
2068 2239
 							'val'  => $val,
2069 2240
 						);
2070 2241
 					}
2242
+					}
2071 2243
 				}
2072 2244
 				$props = $vfs_props;
2073 2245
 			}
@@ -2094,7 +2266,10 @@  discard block
 block discarded – undo
2094 2266
 		{
2095 2267
 			$ret = copy($tmp_name,self::PREFIX.$target) ? self::stat($target) : false;
2096 2268
 		}
2097
-		if (self::LOG_LEVEL > 1 || !$ret && self::LOG_LEVEL) error_log(__METHOD__."($tmp_name, $target, ".array2string($props).") returning ".array2string($ret));
2269
+		if (self::LOG_LEVEL > 1 || !$ret && self::LOG_LEVEL)
2270
+		{
2271
+			error_log(__METHOD__."($tmp_name, $target, ".array2string($props).") returning ".array2string($ret));
2272
+		}
2098 2273
 		return $ret;
2099 2274
 	}
2100 2275
 
Please login to merge, or discard this patch.
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1415,7 +1415,7 @@
 block discarded – undo
1415 1415
 	 *
1416 1416
 	 * @todo use https://github.com/maennchen/ZipStream-PHP to not assamble all files in memmory
1417 1417
 	 */
1418
-	public static function download_zip(Array $_files, $name = false)
1418
+	public static function download_zip(array $_files, $name = false)
1419 1419
 	{
1420 1420
 		//error_log(__METHOD__ . ': '.implode(',',$_files));
1421 1421
 
Please login to merge, or discard this patch.
api/src/Vfs/Dav/Directory.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -84,7 +84,7 @@
 block discarded – undo
84 84
 	/**
85 85
 	 * Returns available diskspace information
86 86
 	 *
87
-	 * @return array [ available-space, free-space ]
87
+	 * @return false[] [ available-space, free-space ]
88 88
 	 */
89 89
 	function getQuotaInfo()
90 90
 	{
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -66,10 +66,10 @@  discard block
 block discarded – undo
66 66
 	function getChild($name)
67 67
 	{
68 68
 		//error_log(__METHOD__."('$name') this->path=$this->path, this->vfs_path=$this->vfs_path");
69
-		$path = $this->vfs_path . '/' . $name;
70
-		$vfs_path = $this->vfs_path . '/' . Vfs::encodePathComponent($name);
69
+		$path = $this->vfs_path.'/'.$name;
70
+		$vfs_path = $this->vfs_path.'/'.Vfs::encodePathComponent($name);
71 71
 
72
-		if (!Vfs::file_exists($vfs_path)) throw new DAV\Exception\NotFound('File with name ' . $path . ' could not be located');
72
+		if (!Vfs::file_exists($vfs_path)) throw new DAV\Exception\NotFound('File with name '.$path.' could not be located');
73 73
 
74 74
 		if (Vfs::is_dir($vfs_path))
75 75
 		{
@@ -88,6 +88,6 @@  discard block
 block discarded – undo
88 88
 	 */
89 89
 	function getQuotaInfo()
90 90
 	{
91
-		return [ false, false ];
91
+		return [false, false];
92 92
 	}
93 93
 }
Please login to merge, or discard this patch.
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -69,7 +69,10 @@
 block discarded – undo
69 69
 		$path = $this->vfs_path . '/' . $name;
70 70
 		$vfs_path = $this->vfs_path . '/' . Vfs::encodePathComponent($name);
71 71
 
72
-		if (!Vfs::file_exists($vfs_path)) throw new DAV\Exception\NotFound('File with name ' . $path . ' could not be located');
72
+		if (!Vfs::file_exists($vfs_path))
73
+		{
74
+			throw new DAV\Exception\NotFound('File with name ' . $path . ' could not be located');
75
+		}
73 76
 
74 77
 		if (Vfs::is_dir($vfs_path))
75 78
 		{
Please login to merge, or discard this patch.
api/src/Vfs/Dav/File.php 1 patch
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 	 *
63 63
 	 * Return null if the ETag can not effectively be determined
64 64
 	 *
65
-	 * @return mixed
65
+	 * @return string|null
66 66
 	 */
67 67
 	function getETag()
68 68
 	{
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 	 *
79 79
 	 * If null is returned, we'll assume application/octet-stream
80 80
 	 *
81
-	 * @return mixed
81
+	 * @return string
82 82
 	 */
83 83
 	function getContentType()
84 84
 	{
Please login to merge, or discard this patch.
api/src/Vfs/Filesystem/StreamWrapper.php 4 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
 	 *
272 272
 	 * If you have cached data in your stream but not yet stored it into the underlying storage, you should do so now.
273 273
 	 *
274
-	 * @return booelan TRUE if the cached data was successfully stored (or if there was no data to store), or FALSE if the data could not be stored.
274
+	 * @return boolean TRUE if the cached data was successfully stored (or if there was no data to store), or FALSE if the data could not be stored.
275 275
 	 */
276 276
 	function stream_flush ( )
277 277
 	{
@@ -507,7 +507,7 @@  discard block
 block discarded – undo
507 507
 	 *
508 508
 	 * @param string $url URL that was passed to opendir() and that this object is expected to explore.
509 509
 	 * @param int $options
510
-	 * @return booelan
510
+	 * @return boolean
511 511
 	 */
512 512
 	function dir_opendir ( $url, $options )
513 513
 	{
@@ -616,7 +616,7 @@  discard block
 block discarded – undo
616 616
 	 * It should reset the output generated by dir_readdir(). i.e.:
617 617
 	 * The next call to dir_readdir() should return the first entry in the location returned by dir_opendir().
618 618
 	 *
619
-	 * @return boolean
619
+	 * @return boolean|null
620 620
 	 */
621 621
 	function dir_rewinddir ( )
622 622
 	{
Please login to merge, or discard this patch.
Spacing   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 	/**
52 52
 	 * Mime type of directories, the old vfs used 'Directory', while eg. WebDAV uses 'httpd/unix-directory'
53 53
 	 */
54
-	const DIR_MIME_TYPE = Vfs::DIR_MIME_TYPE ;
54
+	const DIR_MIME_TYPE = Vfs::DIR_MIME_TYPE;
55 55
 
56 56
 	/**
57 57
 	 * mode-bits, which have to be set for files
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 	/**
61 61
 	 * mode-bits, which have to be set for directories
62 62
 	 */
63
-	const MODE_DIR =   040000;
63
+	const MODE_DIR = 040000;
64 64
 
65 65
 	/**
66 66
 	 * optional context param when opening the stream, null if no context passed
@@ -123,50 +123,50 @@  discard block
 block discarded – undo
123 123
 	 * @param string $opened_path full path of the file/resource, if the open was successfull and STREAM_USE_PATH was set
124 124
 	 * @return boolean true if the ressource was opened successful, otherwise false
125 125
 	 */
126
-	function stream_open ( $url, $mode, $options, &$opened_path )
126
+	function stream_open($url, $mode, $options, &$opened_path)
127 127
 	{
128
-		unset($opened_path);	// not used, but required by interface
128
+		unset($opened_path); // not used, but required by interface
129 129
 
130 130
 		$this->opened_stream = $this->opened_stream_url = null;
131
-		$read_only = str_replace('b','',$mode) == 'r';
131
+		$read_only = str_replace('b', '', $mode) == 'r';
132 132
 
133 133
 		// check access rights, based on the eGW mount perms
134
-		if (!($stat = self::url_stat($url,0)) || $mode[0] == 'x')	// file not found or file should NOT exist
134
+		if (!($stat = self::url_stat($url, 0)) || $mode[0] == 'x')	// file not found or file should NOT exist
135 135
 		{
136 136
 			$dir = Vfs::dirname($url);
137
-			if ($mode[0] == 'r' ||	// does $mode require the file to exist (r,r+)
138
-				$mode[0] == 'x' ||	// or file should not exist, but does
139
-				!Vfs::check_access($dir,Vfs::WRITABLE,$dir_stat=self::url_stat($dir,0)))	// or we are not allowed to 																																			create it
137
+			if ($mode[0] == 'r' || // does $mode require the file to exist (r,r+)
138
+				$mode[0] == 'x' || // or file should not exist, but does
139
+				!Vfs::check_access($dir, Vfs::WRITABLE, $dir_stat = self::url_stat($dir, 0)))	// or we are not allowed to 																																			create it
140 140
 			{
141 141
 				if (self::LOG_LEVEL) error_log(__METHOD__."($url,$mode,$options) file does not exist or can not be created!");
142
-				if (!($options & STREAM_URL_STAT_QUIET))
142
+				if (!($options&STREAM_URL_STAT_QUIET))
143 143
 				{
144
-					trigger_error(__METHOD__."($url,$mode,$options) file does not exist or can not be created!",E_USER_WARNING);
144
+					trigger_error(__METHOD__."($url,$mode,$options) file does not exist or can not be created!", E_USER_WARNING);
145 145
 				}
146 146
 				return false;
147 147
 			}
148 148
 		}
149
-		elseif (!$read_only && !Vfs::check_access($url,Vfs::WRITABLE,$stat))	// we are not allowed to edit it
149
+		elseif (!$read_only && !Vfs::check_access($url, Vfs::WRITABLE, $stat))	// we are not allowed to edit it
150 150
 		{
151 151
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url,$mode,$options) file can not be edited!");
152
-			if (!($options & STREAM_URL_STAT_QUIET))
152
+			if (!($options&STREAM_URL_STAT_QUIET))
153 153
 			{
154
-				trigger_error(__METHOD__."($url,$mode,$options) file can not be edited!",E_USER_WARNING);
154
+				trigger_error(__METHOD__."($url,$mode,$options) file can not be edited!", E_USER_WARNING);
155 155
 			}
156 156
 			return false;
157 157
 		}
158 158
 		if (!$read_only && self::deny_script($url))
159 159
 		{
160 160
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url,$mode,$options) permission denied, file is a script!");
161
-			if (!($options & STREAM_URL_STAT_QUIET))
161
+			if (!($options&STREAM_URL_STAT_QUIET))
162 162
 			{
163
-				trigger_error(__METHOD__."($url,$mode,$options) permission denied, file is a script!",E_USER_WARNING);
163
+				trigger_error(__METHOD__."($url,$mode,$options) permission denied, file is a script!", E_USER_WARNING);
164 164
 			}
165 165
 			return false;
166 166
 		}
167 167
 
168 168
 		// open the "real" file
169
-		if (!($this->opened_stream = fopen($path=Vfs::decodePath(Vfs::parse_url($url,PHP_URL_PATH)),$mode,$options)))
169
+		if (!($this->opened_stream = fopen($path = Vfs::decodePath(Vfs::parse_url($url, PHP_URL_PATH)), $mode, $options)))
170 170
 		{
171 171
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url,$mode,$options) fopen('$path','$mode',$options) returned false!");
172 172
 			return false;
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 	 *
182 182
 	 * You must release any resources that were locked or allocated by the stream.
183 183
 	 */
184
-	function stream_close ( )
184
+	function stream_close( )
185 185
 	{
186 186
 		$ret = fclose($this->opened_stream);
187 187
 
@@ -201,9 +201,9 @@  discard block
 block discarded – undo
201 201
 	 * @param int $count
202 202
 	 * @return string/false up to count bytes read or false on EOF
203 203
 	 */
204
-	function stream_read ( $count )
204
+	function stream_read($count)
205 205
 	{
206
-		return fread($this->opened_stream,$count);
206
+		return fread($this->opened_stream, $count);
207 207
 	}
208 208
 
209 209
 	/**
@@ -217,9 +217,9 @@  discard block
 block discarded – undo
217 217
 	 * @param string $data
218 218
 	 * @return integer
219 219
 	 */
220
-	function stream_write ( $data )
220
+	function stream_write($data)
221 221
 	{
222
-		return fwrite($this->opened_stream,$data);
222
+		return fwrite($this->opened_stream, $data);
223 223
 	}
224 224
 
225 225
  	/**
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
   	 *
235 235
  	 * @return boolean true if the read/write position is at the end of the stream and no more data availible, false otherwise
236 236
  	 */
237
-	function stream_eof ( )
237
+	function stream_eof( )
238 238
 	{
239 239
 		return feof($this->opened_stream);
240 240
 	}
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
 	 *
245 245
 	 * @return integer current read/write position of the stream
246 246
 	 */
247
- 	function stream_tell ( )
247
+ 	function stream_tell( )
248 248
  	{
249 249
  		return ftell($this->opened_stream);
250 250
  	}
@@ -261,9 +261,9 @@  discard block
 block discarded – undo
261 261
  	 * 							SEEK_END - 2 - Set position to end-of-file plus offset. (To move to a position before the end-of-file, you need to pass a negative value in offset.)
262 262
  	 * @return boolean TRUE if the position was updated, FALSE otherwise.
263 263
  	 */
264
-	function stream_seek ( $offset, $whence )
264
+	function stream_seek($offset, $whence)
265 265
 	{
266
-		return !fseek($this->opened_stream,$offset,$whence);	// fseek returns 0 on success and -1 on failure
266
+		return !fseek($this->opened_stream, $offset, $whence); // fseek returns 0 on success and -1 on failure
267 267
 	}
268 268
 
269 269
 	/**
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
 	 *
274 274
 	 * @return booelan TRUE if the cached data was successfully stored (or if there was no data to store), or FALSE if the data could not be stored.
275 275
 	 */
276
-	function stream_flush ( )
276
+	function stream_flush( )
277 277
 	{
278 278
 		return fflush($this->opened_stream);
279 279
 	}
@@ -292,9 +292,9 @@  discard block
 block discarded – undo
292 292
 	 *
293 293
 	 * @return array containing the same values as appropriate for the stream.
294 294
 	 */
295
-	function stream_stat ( )
295
+	function stream_stat( )
296 296
 	{
297
-		return self::url_stat($this->opened_stream_url,0);
297
+		return self::url_stat($this->opened_stream_url, 0);
298 298
 	}
299 299
 
300 300
 	/**
@@ -306,15 +306,15 @@  discard block
 block discarded – undo
306 306
 	 * @param string $url
307 307
 	 * @return boolean TRUE on success or FALSE on failure
308 308
 	 */
309
-	static function unlink ( $url )
309
+	static function unlink($url)
310 310
 	{
311
-		$path = Vfs::decodePath(Vfs::parse_url($url,PHP_URL_PATH));
311
+		$path = Vfs::decodePath(Vfs::parse_url($url, PHP_URL_PATH));
312 312
 
313 313
 		// check access rights (file need to exist and directory need to be writable
314
-		if (!file_exists($path) || is_dir($path) || !Vfs::check_access(Vfs::dirname($url),Vfs::WRITABLE))
314
+		if (!file_exists($path) || is_dir($path) || !Vfs::check_access(Vfs::dirname($url), Vfs::WRITABLE))
315 315
 		{
316 316
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url) permission denied!");
317
-			return false;	// no permission or file does not exist
317
+			return false; // no permission or file does not exist
318 318
 		}
319 319
 		return unlink($path);
320 320
 	}
@@ -331,22 +331,22 @@  discard block
 block discarded – undo
331 331
 	 * @param string $url_to
332 332
 	 * @return boolean TRUE on success or FALSE on failure
333 333
 	 */
334
-	static function rename ( $url_from, $url_to )
334
+	static function rename($url_from, $url_to)
335 335
 	{
336 336
 		$from = Vfs::parse_url($url_from);
337 337
 		$to   = Vfs::parse_url($url_to);
338 338
 
339 339
 		// check access rights
340
-		if (!($from_stat = self::url_stat($url_from,0)) || !Vfs::check_access(Vfs::dirname($url_from),Vfs::WRITABLE))
340
+		if (!($from_stat = self::url_stat($url_from, 0)) || !Vfs::check_access(Vfs::dirname($url_from), Vfs::WRITABLE))
341 341
 		{
342 342
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url_from,$url_to): $from[path] permission denied!");
343
-			return false;	// no permission or file does not exist
343
+			return false; // no permission or file does not exist
344 344
 		}
345 345
 		$to_dir = Vfs::dirname($url_to);
346
-		if (!Vfs::check_access($to_dir,Vfs::WRITABLE,$to_dir_stat = self::url_stat($to_dir,0)))
346
+		if (!Vfs::check_access($to_dir, Vfs::WRITABLE, $to_dir_stat = self::url_stat($to_dir, 0)))
347 347
 		{
348 348
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url_from,$url_to): $to_dir permission denied!");
349
-			return false;	// no permission or parent-dir does not exist
349
+			return false; // no permission or parent-dir does not exist
350 350
 		}
351 351
 		if (self::deny_script($url_to))
352 352
 		{
@@ -355,12 +355,12 @@  discard block
 block discarded – undo
355 355
 		}
356 356
 		// the filesystem stream-wrapper does NOT allow to rename files to directories, as this makes problems
357 357
 		// for our vfs too, we abort here with an error, like the filesystem one does
358
-		if (($to_stat = self::url_stat($to['path'],0)) &&
358
+		if (($to_stat = self::url_stat($to['path'], 0)) &&
359 359
 			($to_stat['mime'] === self::DIR_MIME_TYPE) !== ($from_stat['mime'] === self::DIR_MIME_TYPE))
360 360
 		{
361 361
 			$is_dir = $to_stat['mime'] === self::DIR_MIME_TYPE ? 'a' : 'no';
362 362
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url_to,$url_from) $to[path] is $is_dir directory!");
363
-			return false;	// no permission or file does not exist
363
+			return false; // no permission or file does not exist
364 364
 		}
365 365
 		// if destination file already exists, delete it
366 366
 		if ($to_stat && !self::unlink($url_to))
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url_to,$url_from) can't unlink existing $url_to!");
369 369
 			return false;
370 370
 		}
371
-		return rename(Vfs::decodePath($from['path']),Vfs::decodePath($to['path']));
371
+		return rename(Vfs::decodePath($from['path']), Vfs::decodePath($to['path']));
372 372
 	}
373 373
 
374 374
 	/**
@@ -382,12 +382,12 @@  discard block
 block discarded – undo
382 382
 	 * @param int $options Posible values include STREAM_REPORT_ERRORS and STREAM_MKDIR_RECURSIVE
383 383
 	 * @return boolean TRUE on success or FALSE on failure
384 384
 	 */
385
-	static function mkdir ( $url, $mode, $options )
385
+	static function mkdir($url, $mode, $options)
386 386
 	{
387
-		unset($mode);	// not used, but required by interface
387
+		unset($mode); // not used, but required by interface
388 388
 
389
-		$path = Vfs::decodePath(Vfs::parse_url($url,PHP_URL_PATH));
390
-		$recursive = (bool)($options & STREAM_MKDIR_RECURSIVE);
389
+		$path = Vfs::decodePath(Vfs::parse_url($url, PHP_URL_PATH));
390
+		$recursive = (bool)($options&STREAM_MKDIR_RECURSIVE);
391 391
 
392 392
 		// find the real parent (might be more then one level if $recursive!)
393 393
 		do {
@@ -398,12 +398,12 @@  discard block
 block discarded – undo
398 398
 		//echo __METHOD__."($url,$mode,$options) path=$path, recursive=$recursive, parent=$parent, Vfs::check_access(parent_url=$parent_url,Vfs::WRITABLE)=".(int)Vfs::check_access($parent_url,Vfs::WRITABLE)."\n";
399 399
 
400 400
 		// check access rights (in real filesystem AND by mount perms)
401
-		if (file_exists($path) || !file_exists($parent) || !is_writable($parent) || !Vfs::check_access($parent_url,Vfs::WRITABLE))
401
+		if (file_exists($path) || !file_exists($parent) || !is_writable($parent) || !Vfs::check_access($parent_url, Vfs::WRITABLE))
402 402
 		{
403 403
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url) permission denied!");
404 404
 			return false;
405 405
 		}
406
-		return mkdir($path, 0700, $recursive);	// setting mode 0700 allows (only) apache to write into the dir
406
+		return mkdir($path, 0700, $recursive); // setting mode 0700 allows (only) apache to write into the dir
407 407
 	}
408 408
 
409 409
 	/**
@@ -416,15 +416,15 @@  discard block
 block discarded – undo
416 416
 	 * @param int $options Possible values include STREAM_REPORT_ERRORS.
417 417
 	 * @return boolean TRUE on success or FALSE on failure.
418 418
 	 */
419
-	static function rmdir ( $url, $options )
419
+	static function rmdir($url, $options)
420 420
 	{
421
-		unset($options);	// not used, but required by interface
421
+		unset($options); // not used, but required by interface
422 422
 
423
-		$path = Vfs::decodePath(Vfs::parse_url($url,PHP_URL_PATH));
423
+		$path = Vfs::decodePath(Vfs::parse_url($url, PHP_URL_PATH));
424 424
 		$parent = dirname($path);
425 425
 
426 426
 		// check access rights (in real filesystem AND by mount perms)
427
-		if (!file_exists($path) || !is_writable($parent) || !Vfs::check_access(Vfs::dirname($url),Vfs::WRITABLE))
427
+		if (!file_exists($path) || !is_writable($parent) || !Vfs::check_access(Vfs::dirname($url), Vfs::WRITABLE))
428 428
 		{
429 429
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url) permission denied!");
430 430
 			return false;
@@ -440,18 +440,18 @@  discard block
 block discarded – undo
440 440
 	 * @param int $atime =null access time (unix timestamp), default null = current time, not implemented in the vfs!
441 441
 	 * @return boolean true on success, false otherwise
442 442
 	 */
443
-	static function touch($url,$time=null,$atime=null)
443
+	static function touch($url, $time = null, $atime = null)
444 444
 	{
445
-		$path = Vfs::decodePath(Vfs::parse_url($url,PHP_URL_PATH));
445
+		$path = Vfs::decodePath(Vfs::parse_url($url, PHP_URL_PATH));
446 446
 		$parent = dirname($path);
447 447
 
448 448
 		// check access rights (in real filesystem AND by mount perms)
449
-		if (!file_exists($path) || !is_writable($parent) || !Vfs::check_access(Vfs::dirname($url),Vfs::WRITABLE))
449
+		if (!file_exists($path) || !is_writable($parent) || !Vfs::check_access(Vfs::dirname($url), Vfs::WRITABLE))
450 450
 		{
451 451
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url) permission denied!");
452 452
 			return false;
453 453
 		}
454
-		return touch($path,$time,$atime);
454
+		return touch($path, $time, $atime);
455 455
 	}
456 456
 
457 457
 	/**
@@ -463,9 +463,9 @@  discard block
 block discarded – undo
463 463
 	 * @param string $mode mode string see Vfs::mode2int
464 464
 	 * @return boolean true on success, false otherwise
465 465
 	 */
466
-	static function chmod($path,$mode)
466
+	static function chmod($path, $mode)
467 467
 	{
468
-		unset($path, $mode);	// not used, but required by interface
468
+		unset($path, $mode); // not used, but required by interface
469 469
 
470 470
 		return false;
471 471
 	}
@@ -479,9 +479,9 @@  discard block
 block discarded – undo
479 479
 	 * @param int $owner numeric user id
480 480
 	 * @return boolean true on success, false otherwise
481 481
 	 */
482
-	static function chown($path,$owner)
482
+	static function chown($path, $owner)
483 483
 	{
484
-		unset($path, $owner);	// not used, but required by interface
484
+		unset($path, $owner); // not used, but required by interface
485 485
 
486 486
 		return false;
487 487
 	}
@@ -495,9 +495,9 @@  discard block
 block discarded – undo
495 495
 	 * @param int $group numeric group id
496 496
 	 * @return boolean true on success, false otherwise
497 497
 	 */
498
-	static function chgrp($path,$group)
498
+	static function chgrp($path, $group)
499 499
 	{
500
-		unset($path, $group);	// not used, but required by interface
500
+		unset($path, $group); // not used, but required by interface
501 501
 
502 502
 		return false;
503 503
 	}
@@ -509,13 +509,13 @@  discard block
 block discarded – undo
509 509
 	 * @param int $options
510 510
 	 * @return booelan
511 511
 	 */
512
-	function dir_opendir ( $url, $options )
512
+	function dir_opendir($url, $options)
513 513
 	{
514 514
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$options)");
515 515
 
516 516
 		$this->opened_dir = null;
517 517
 
518
-		$path = Vfs::decodePath(Vfs::parse_url($this->opened_dir_url = $url,PHP_URL_PATH));
518
+		$path = Vfs::decodePath(Vfs::parse_url($this->opened_dir_url = $url, PHP_URL_PATH));
519 519
 
520 520
 		// ToDo: check access rights
521 521
 
@@ -553,31 +553,31 @@  discard block
 block discarded – undo
553 553
 	 *                          stat triggers it's own warning anyway, so it makes no sense to trigger one by our stream-wrapper!
554 554
 	 * @return array
555 555
 	 */
556
-	static function url_stat ( $url, $flags )
556
+	static function url_stat($url, $flags)
557 557
 	{
558 558
 		$parts = Vfs::parse_url($url);
559 559
 		$path = Vfs::decodePath($parts['path']);
560 560
 
561
-		$stat = @stat($path);	// suppressed the stat failed warnings
561
+		$stat = @stat($path); // suppressed the stat failed warnings
562 562
 
563 563
 		if ($stat)
564 564
 		{
565 565
 			// set owner, group and mode from mount options
566 566
 			$uid = $gid = $mode = null;
567
-			if (!self::parse_query($parts['query'],$uid,$gid,$mode))
567
+			if (!self::parse_query($parts['query'], $uid, $gid, $mode))
568 568
 			{
569 569
 				return false;
570 570
 			}
571 571
 			$stat['uid'] = $stat[4] = $uid;
572 572
 			$stat['gid'] = $stat[5] = $gid;
573
-			$stat['mode'] = $stat[2] = $stat['mode'] & self::MODE_DIR ? self::MODE_DIR | $mode : self::MODE_FILE | ($mode & ~0111);
573
+			$stat['mode'] = $stat[2] = $stat['mode']&self::MODE_DIR ? self::MODE_DIR|$mode : self::MODE_FILE|($mode&~0111);
574 574
 			// write rights also depend on the write rights of the webserver
575 575
 			if (!is_writable($path))
576 576
 			{
577
-				$stat['mode'] = $stat[2] = $stat['mode'] & ~0222;
577
+				$stat['mode'] = $stat[2] = $stat['mode']&~0222;
578 578
 			}
579 579
 		}
580
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$flags) path=$path, mount_mode=".sprintf('0%o',$mode).", mode=".sprintf('0%o',$stat['mode']).'='.Vfs::int2mode($stat['mode']));
580
+		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$flags) path=$path, mount_mode=".sprintf('0%o', $mode).", mode=".sprintf('0%o', $stat['mode']).'='.Vfs::int2mode($stat['mode']));
581 581
 		return $stat;
582 582
 	}
583 583
 
@@ -591,13 +591,13 @@  discard block
 block discarded – undo
591 591
 	 *
592 592
 	 * @return string
593 593
 	 */
594
-	function dir_readdir ( )
594
+	function dir_readdir( )
595 595
 	{
596 596
 		do {
597 597
 			$file = readdir($this->opened_dir);
598 598
 
599
-			$ignore = !($file === false ||							// stop if no more dirs or
600
-				($file != '.' && $file != '..' ));					// file not . or ..
599
+			$ignore = !($file === false || // stop if no more dirs or
600
+				($file != '.' && $file != '..')); // file not . or ..
601 601
 			if (self::LOG_LEVEL > 1 && $ignore) error_log(__METHOD__.'() ignoring '.array2string($file));
602 602
 		}
603 603
 		while ($ignore);
@@ -618,7 +618,7 @@  discard block
 block discarded – undo
618 618
 	 *
619 619
 	 * @return boolean
620 620
 	 */
621
-	function dir_rewinddir ( )
621
+	function dir_rewinddir( )
622 622
 	{
623 623
 		return rewinddir($this->opened_dir);
624 624
 	}
@@ -630,7 +630,7 @@  discard block
 block discarded – undo
630 630
 	 *
631 631
 	 * @return boolean
632 632
 	 */
633
-	function dir_closedir ( )
633
+	function dir_closedir( )
634 634
 	{
635 635
 		closedir($this->opened_dir);
636 636
 
@@ -648,18 +648,18 @@  discard block
 block discarded – undo
648 648
 	 * @param int &$mode default if not set is 05 r-x for others
649 649
 	 * @return boolean true on successfull parse, false on error
650 650
 	 */
651
-	static function parse_query($query,&$uid,&$gid,&$mode)
651
+	static function parse_query($query, &$uid, &$gid, &$mode)
652 652
 	{
653 653
 		$params = null;
654
-		parse_str(is_array($query) ? $query['query'] : $query,$params);
654
+		parse_str(is_array($query) ? $query['query'] : $query, $params);
655 655
 
656 656
 		// setting the default perms root.root r-x for other
657 657
 		$uid = $gid = 0;
658 658
 		$mode = 05;
659 659
 
660
-		foreach($params as $name => $value)
660
+		foreach ($params as $name => $value)
661 661
 		{
662
-			switch($name)
662
+			switch ($name)
663 663
 			{
664 664
 				case 'user':
665 665
 					if (!is_numeric($value))
@@ -668,10 +668,10 @@  discard block
 block discarded – undo
668 668
 						{
669 669
 							$value = 0;
670 670
 						}
671
-						elseif (($value = $GLOBALS['egw']->accounts->name2id($value,'account_lid','u')) === false)
671
+						elseif (($value = $GLOBALS['egw']->accounts->name2id($value, 'account_lid', 'u')) === false)
672 672
 						{
673 673
 							error_log(__METHOD__."('$query') unknown user-name '$value'!");
674
-							return false;	// wrong user-name
674
+							return false; // wrong user-name
675 675
 						}
676 676
 					}
677 677
 					// fall-through
@@ -690,12 +690,12 @@  discard block
 block discarded – undo
690 690
 						{
691 691
 							$value = 0;
692 692
 						}
693
-						elseif (($value = $GLOBALS['egw']->accounts->name2id($value,'account_lid','g')) === false)
693
+						elseif (($value = $GLOBALS['egw']->accounts->name2id($value, 'account_lid', 'g')) === false)
694 694
 						{
695 695
 							error_log(__METHOD__."('$query') unknown group-name '$value'!");
696
-							return false;	// wrong group-name
696
+							return false; // wrong group-name
697 697
 						}
698
-						$value = -$value;	// vfs uses positiv gid's!
698
+						$value = -$value; // vfs uses positiv gid's!
699 699
 					}
700 700
 					// fall-through
701 701
 				case 'gid':
@@ -731,9 +731,9 @@  discard block
 block discarded – undo
731 731
 	{
732 732
 		$parts = Vfs::parse_url($url);
733 733
 		$get = null;
734
-		parse_str($parts['query'],$get);
734
+		parse_str($parts['query'], $get);
735 735
 
736
-		$deny = !$get['exec'] && preg_match(self::SCRIPT_EXTENSIONS_PREG,$parts['path']);
736
+		$deny = !$get['exec'] && preg_match(self::SCRIPT_EXTENSIONS_PREG, $parts['path']);
737 737
 
738 738
 		if (self::LOG_LEVEL > 1 || self::LOG_LEVEL > 0 && $deny)
739 739
 		{
@@ -753,21 +753,21 @@  discard block
 block discarded – undo
753 753
 	 * @todo get $force_download working through webdav
754 754
 	 * @return string|false string with full download url or false to use default webdav.php url
755 755
 	 */
756
-	static function download_url($_url,$force_download=false)
756
+	static function download_url($_url, $force_download = false)
757 757
 	{
758
-		unset($force_download);	// not used, but required by interface
758
+		unset($force_download); // not used, but required by interface
759 759
 
760
-		list($url,$query) = explode('?',$_url,2);
760
+		list($url, $query) = explode('?', $_url, 2);
761 761
 		$get = null;
762
-		parse_str($query,$get);
763
-		if (empty($get['url'])) return false;	// no download url given for this mount-point
762
+		parse_str($query, $get);
763
+		if (empty($get['url'])) return false; // no download url given for this mount-point
764 764
 
765
-		if (!($mount_url = Vfs::mount_url($_url))) return false;	// no mount url found, should not happen
766
-		list($mount_url) = explode('?',$mount_url);
765
+		if (!($mount_url = Vfs::mount_url($_url))) return false; // no mount url found, should not happen
766
+		list($mount_url) = explode('?', $mount_url);
767 767
 
768
-		$relpath = substr($url,strlen($mount_url));
768
+		$relpath = substr($url, strlen($mount_url));
769 769
 
770
-		$download_url = Vfs::concat($get['url'],$relpath);
770
+		$download_url = Vfs::concat($get['url'], $relpath);
771 771
 		if ($download_url[0] == '/')
772 772
 		{
773 773
 			$download_url = ($_SERVER['HTTPS'] ? 'https://' : 'http://').
Please login to merge, or discard this patch.
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -80,10 +80,10 @@
 block discarded – undo
80 80
  	 * Important: PHP 5.0 introduced a bug that wasn't fixed until 5.1: the return value has to be the oposite!
81 81
  	 *
82 82
  	 * if(version_compare(PHP_VERSION,'5.0','>=') && version_compare(PHP_VERSION,'5.1','<'))
83
-  	 * {
83
+ 	 * {
84 84
  	 * 		$eof = !$eof;
85 85
  	 * }
86
-  	 *
86
+ 	 *
87 87
  	 * @return boolean true if the read/write position is at the end of the stream and no more data availible, false otherwise
88 88
  	 */
89 89
 	function stream_eof ( );
Please login to merge, or discard this patch.
Braces   +90 added lines, -22 removed lines patch added patch discarded remove patch
@@ -131,14 +131,20 @@  discard block
 block discarded – undo
131 131
 		$read_only = str_replace('b','',$mode) == 'r';
132 132
 
133 133
 		// check access rights, based on the eGW mount perms
134
-		if (!($stat = self::url_stat($url,0)) || $mode[0] == 'x')	// file not found or file should NOT exist
134
+		if (!($stat = self::url_stat($url,0)) || $mode[0] == 'x')
135
+		{
136
+			// file not found or file should NOT exist
135 137
 		{
136 138
 			$dir = Vfs::dirname($url);
139
+		}
137 140
 			if ($mode[0] == 'r' ||	// does $mode require the file to exist (r,r+)
138 141
 				$mode[0] == 'x' ||	// or file should not exist, but does
139
-				!Vfs::check_access($dir,Vfs::WRITABLE,$dir_stat=self::url_stat($dir,0)))	// or we are not allowed to 																																			create it
142
+				!Vfs::check_access($dir,Vfs::WRITABLE,$dir_stat=self::url_stat($dir,0)))
143
+			{
144
+				// or we are not allowed to 																																			create it
140 145
 			{
141 146
 				if (self::LOG_LEVEL) error_log(__METHOD__."($url,$mode,$options) file does not exist or can not be created!");
147
+			}
142 148
 				if (!($options & STREAM_URL_STAT_QUIET))
143 149
 				{
144 150
 					trigger_error(__METHOD__."($url,$mode,$options) file does not exist or can not be created!",E_USER_WARNING);
@@ -146,9 +152,12 @@  discard block
 block discarded – undo
146 152
 				return false;
147 153
 			}
148 154
 		}
149
-		elseif (!$read_only && !Vfs::check_access($url,Vfs::WRITABLE,$stat))	// we are not allowed to edit it
155
+		elseif (!$read_only && !Vfs::check_access($url,Vfs::WRITABLE,$stat))
156
+		{
157
+			// we are not allowed to edit it
150 158
 		{
151 159
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url,$mode,$options) file can not be edited!");
160
+		}
152 161
 			if (!($options & STREAM_URL_STAT_QUIET))
153 162
 			{
154 163
 				trigger_error(__METHOD__."($url,$mode,$options) file can not be edited!",E_USER_WARNING);
@@ -157,7 +166,10 @@  discard block
 block discarded – undo
157 166
 		}
158 167
 		if (!$read_only && self::deny_script($url))
159 168
 		{
160
-			if (self::LOG_LEVEL) error_log(__METHOD__."($url,$mode,$options) permission denied, file is a script!");
169
+			if (self::LOG_LEVEL)
170
+			{
171
+				error_log(__METHOD__."($url,$mode,$options) permission denied, file is a script!");
172
+			}
161 173
 			if (!($options & STREAM_URL_STAT_QUIET))
162 174
 			{
163 175
 				trigger_error(__METHOD__."($url,$mode,$options) permission denied, file is a script!",E_USER_WARNING);
@@ -168,7 +180,10 @@  discard block
 block discarded – undo
168 180
 		// open the "real" file
169 181
 		if (!($this->opened_stream = fopen($path=Vfs::decodePath(Vfs::parse_url($url,PHP_URL_PATH)),$mode,$options)))
170 182
 		{
171
-			if (self::LOG_LEVEL) error_log(__METHOD__."($url,$mode,$options) fopen('$path','$mode',$options) returned false!");
183
+			if (self::LOG_LEVEL)
184
+			{
185
+				error_log(__METHOD__."($url,$mode,$options) fopen('$path','$mode',$options) returned false!");
186
+			}
172 187
 			return false;
173 188
 		}
174 189
 		$this->opened_stream_url = $url;
@@ -313,7 +328,10 @@  discard block
 block discarded – undo
313 328
 		// check access rights (file need to exist and directory need to be writable
314 329
 		if (!file_exists($path) || is_dir($path) || !Vfs::check_access(Vfs::dirname($url),Vfs::WRITABLE))
315 330
 		{
316
-			if (self::LOG_LEVEL) error_log(__METHOD__."($url) permission denied!");
331
+			if (self::LOG_LEVEL)
332
+			{
333
+				error_log(__METHOD__."($url) permission denied!");
334
+			}
317 335
 			return false;	// no permission or file does not exist
318 336
 		}
319 337
 		return unlink($path);
@@ -339,18 +357,27 @@  discard block
 block discarded – undo
339 357
 		// check access rights
340 358
 		if (!($from_stat = self::url_stat($url_from,0)) || !Vfs::check_access(Vfs::dirname($url_from),Vfs::WRITABLE))
341 359
 		{
342
-			if (self::LOG_LEVEL) error_log(__METHOD__."($url_from,$url_to): $from[path] permission denied!");
360
+			if (self::LOG_LEVEL)
361
+			{
362
+				error_log(__METHOD__."($url_from,$url_to): $from[path] permission denied!");
363
+			}
343 364
 			return false;	// no permission or file does not exist
344 365
 		}
345 366
 		$to_dir = Vfs::dirname($url_to);
346 367
 		if (!Vfs::check_access($to_dir,Vfs::WRITABLE,$to_dir_stat = self::url_stat($to_dir,0)))
347 368
 		{
348
-			if (self::LOG_LEVEL) error_log(__METHOD__."($url_from,$url_to): $to_dir permission denied!");
369
+			if (self::LOG_LEVEL)
370
+			{
371
+				error_log(__METHOD__."($url_from,$url_to): $to_dir permission denied!");
372
+			}
349 373
 			return false;	// no permission or parent-dir does not exist
350 374
 		}
351 375
 		if (self::deny_script($url_to))
352 376
 		{
353
-			if (self::LOG_LEVEL) error_log(__METHOD__."($url_from,$url_to) permission denied, file is a script!");
377
+			if (self::LOG_LEVEL)
378
+			{
379
+				error_log(__METHOD__."($url_from,$url_to) permission denied, file is a script!");
380
+			}
354 381
 			return false;
355 382
 		}
356 383
 		// the filesystem stream-wrapper does NOT allow to rename files to directories, as this makes problems
@@ -359,13 +386,19 @@  discard block
 block discarded – undo
359 386
 			($to_stat['mime'] === self::DIR_MIME_TYPE) !== ($from_stat['mime'] === self::DIR_MIME_TYPE))
360 387
 		{
361 388
 			$is_dir = $to_stat['mime'] === self::DIR_MIME_TYPE ? 'a' : 'no';
362
-			if (self::LOG_LEVEL) error_log(__METHOD__."($url_to,$url_from) $to[path] is $is_dir directory!");
389
+			if (self::LOG_LEVEL)
390
+			{
391
+				error_log(__METHOD__."($url_to,$url_from) $to[path] is $is_dir directory!");
392
+			}
363 393
 			return false;	// no permission or file does not exist
364 394
 		}
365 395
 		// if destination file already exists, delete it
366 396
 		if ($to_stat && !self::unlink($url_to))
367 397
 		{
368
-			if (self::LOG_LEVEL) error_log(__METHOD__."($url_to,$url_from) can't unlink existing $url_to!");
398
+			if (self::LOG_LEVEL)
399
+			{
400
+				error_log(__METHOD__."($url_to,$url_from) can't unlink existing $url_to!");
401
+			}
369 402
 			return false;
370 403
 		}
371 404
 		return rename(Vfs::decodePath($from['path']),Vfs::decodePath($to['path']));
@@ -400,7 +433,10 @@  discard block
 block discarded – undo
400 433
 		// check access rights (in real filesystem AND by mount perms)
401 434
 		if (file_exists($path) || !file_exists($parent) || !is_writable($parent) || !Vfs::check_access($parent_url,Vfs::WRITABLE))
402 435
 		{
403
-			if (self::LOG_LEVEL) error_log(__METHOD__."($url) permission denied!");
436
+			if (self::LOG_LEVEL)
437
+			{
438
+				error_log(__METHOD__."($url) permission denied!");
439
+			}
404 440
 			return false;
405 441
 		}
406 442
 		return mkdir($path, 0700, $recursive);	// setting mode 0700 allows (only) apache to write into the dir
@@ -426,7 +462,10 @@  discard block
 block discarded – undo
426 462
 		// check access rights (in real filesystem AND by mount perms)
427 463
 		if (!file_exists($path) || !is_writable($parent) || !Vfs::check_access(Vfs::dirname($url),Vfs::WRITABLE))
428 464
 		{
429
-			if (self::LOG_LEVEL) error_log(__METHOD__."($url) permission denied!");
465
+			if (self::LOG_LEVEL)
466
+			{
467
+				error_log(__METHOD__."($url) permission denied!");
468
+			}
430 469
 			return false;
431 470
 		}
432 471
 		return rmdir($path);
@@ -448,7 +487,10 @@  discard block
 block discarded – undo
448 487
 		// check access rights (in real filesystem AND by mount perms)
449 488
 		if (!file_exists($path) || !is_writable($parent) || !Vfs::check_access(Vfs::dirname($url),Vfs::WRITABLE))
450 489
 		{
451
-			if (self::LOG_LEVEL) error_log(__METHOD__."($url) permission denied!");
490
+			if (self::LOG_LEVEL)
491
+			{
492
+				error_log(__METHOD__."($url) permission denied!");
493
+			}
452 494
 			return false;
453 495
 		}
454 496
 		return touch($path,$time,$atime);
@@ -511,7 +553,10 @@  discard block
 block discarded – undo
511 553
 	 */
512 554
 	function dir_opendir ( $url, $options )
513 555
 	{
514
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$options)");
556
+		if (self::LOG_LEVEL > 1)
557
+		{
558
+			error_log(__METHOD__."($url,$options)");
559
+		}
515 560
 
516 561
 		$this->opened_dir = null;
517 562
 
@@ -521,7 +566,10 @@  discard block
 block discarded – undo
521 566
 
522 567
 		if (!($this->opened_dir = opendir($path)))
523 568
 		{
524
-			if (self::LOG_LEVEL > 0) error_log(__METHOD__."($url,$options) opendir('$path') failed!");
569
+			if (self::LOG_LEVEL > 0)
570
+			{
571
+				error_log(__METHOD__."($url,$options) opendir('$path') failed!");
572
+			}
525 573
 			return false;
526 574
 		}
527 575
 		return true;
@@ -577,7 +625,10 @@  discard block
 block discarded – undo
577 625
 				$stat['mode'] = $stat[2] = $stat['mode'] & ~0222;
578 626
 			}
579 627
 		}
580
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$flags) path=$path, mount_mode=".sprintf('0%o',$mode).", mode=".sprintf('0%o',$stat['mode']).'='.Vfs::int2mode($stat['mode']));
628
+		if (self::LOG_LEVEL > 1)
629
+		{
630
+			error_log(__METHOD__."($url,$flags) path=$path, mount_mode=".sprintf('0%o',$mode).", mode=".sprintf('0%o',$stat['mode']).'='.Vfs::int2mode($stat['mode']));
631
+		}
581 632
 		return $stat;
582 633
 	}
583 634
 
@@ -598,14 +649,23 @@  discard block
 block discarded – undo
598 649
 
599 650
 			$ignore = !($file === false ||							// stop if no more dirs or
600 651
 				($file != '.' && $file != '..' ));					// file not . or ..
601
-			if (self::LOG_LEVEL > 1 && $ignore) error_log(__METHOD__.'() ignoring '.array2string($file));
652
+			if (self::LOG_LEVEL > 1 && $ignore)
653
+			{
654
+				error_log(__METHOD__.'() ignoring '.array2string($file));
655
+			}
602 656
 		}
603 657
 		while ($ignore);
604 658
 
605 659
 		// encode special chars messing up url's
606
-		if ($file !== false) $file = Vfs::encodePathComponent($file);
660
+		if ($file !== false)
661
+		{
662
+			$file = Vfs::encodePathComponent($file);
663
+		}
607 664
 
608
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__.'() returning '.array2string($file));
665
+		if (self::LOG_LEVEL > 1)
666
+		{
667
+			error_log(__METHOD__.'() returning '.array2string($file));
668
+		}
609 669
 
610 670
 		return $file;
611 671
 	}
@@ -760,9 +820,17 @@  discard block
 block discarded – undo
760 820
 		list($url,$query) = explode('?',$_url,2);
761 821
 		$get = null;
762 822
 		parse_str($query,$get);
763
-		if (empty($get['url'])) return false;	// no download url given for this mount-point
823
+		if (empty($get['url']))
824
+		{
825
+			return false;
826
+		}
827
+		// no download url given for this mount-point
764 828
 
765
-		if (!($mount_url = Vfs::mount_url($_url))) return false;	// no mount url found, should not happen
829
+		if (!($mount_url = Vfs::mount_url($_url)))
830
+		{
831
+			return false;
832
+		}
833
+		// no mount url found, should not happen
766 834
 		list($mount_url) = explode('?',$mount_url);
767 835
 
768 836
 		$relpath = substr($url,strlen($mount_url));
Please login to merge, or discard this patch.