Completed
Push — 16.1 ( 96a09f...9e378a )
by Nathan
36:36 queued 19:17
created
api/src/DateTime.php 2 patches
Braces   +82 added lines, -20 removed lines patch added patch discarded remove patch
@@ -95,7 +95,11 @@  discard block
 block discarded – undo
95 95
 	 */
96 96
 	public function __construct($time='now',DateTimeZone $tz=null,&$type=null)
97 97
 	{
98
-		if (is_null($tz)) $tz = self::$user_timezone;	// default user timezone
98
+		if (is_null($tz))
99
+		{
100
+			$tz = self::$user_timezone;
101
+		}
102
+		// default user timezone
99 103
 
100 104
 		switch(($type = gettype($time)))
101 105
 		{
@@ -108,7 +112,11 @@  discard block
 block discarded – undo
108 112
 				if (!(is_numeric($time) && ($time > 21000000 || $time < 19000000)))
109 113
 				{
110 114
 					$t_str = $time;
111
-					if (is_numeric($time) && strlen($time) == 8) $t_str .= 'T000000';	// 'Ymd' string used in calendar to represent a date
115
+					if (is_numeric($time) && strlen($time) == 8)
116
+					{
117
+						$t_str .= 'T000000';
118
+					}
119
+					// 'Ymd' string used in calendar to represent a date
112 120
 					// $time ending in a Z (Zulu or UTC time), is unterstood by DateTime class itself
113 121
 					try {
114 122
 						parent::__construct($t_str,$tz);
@@ -116,7 +124,10 @@  discard block
 block discarded – undo
116 124
 					}
117 125
 					catch(Exception $e) {
118 126
 						// if string is nummeric, ignore the exception and treat string as timestamp
119
-						if (!is_numeric($time)) throw $e;
127
+						if (!is_numeric($time))
128
+						{
129
+							throw $e;
130
+						}
120 131
 					}
121 132
 				}
122 133
 				$type = 'integer';
@@ -137,7 +148,9 @@  discard block
 block discarded – undo
137 148
 
138 149
 			case 'array':
139 150
 				parent::__construct('now',$tz);
140
-				if (isset($time['Y']))	// array format used in eTemplate
151
+				if (isset($time['Y']))
152
+				{
153
+					// array format used in eTemplate
141 154
 				{
142 155
 					$time = array(
143 156
 						'year'   => $time['Y'],
@@ -148,13 +161,17 @@  discard block
 block discarded – undo
148 161
 						'second' => $time['s'],
149 162
 					);
150 163
 				}
164
+				}
151 165
 				if (!empty($time['full']) && empty($time['year']))
152 166
 				{
153 167
 					$time['year']  = (int)substr($time['full'],0,4);
154 168
 					$time['month'] = (int)substr($time['full'],4,2);
155 169
 					$time['day']   = (int)substr($time['full'],6,2);
156 170
 				}
157
-				if (isset($time['year'])) $this->setDate((int)$time['year'],(int)$time['month'],isset($time['day']) ? (int)$time['day'] : (int)$time['mday']);
171
+				if (isset($time['year']))
172
+				{
173
+					$this->setDate((int)$time['year'],(int)$time['month'],isset($time['day']) ? (int)$time['day'] : (int)$time['mday']);
174
+				}
158 175
 				$this->setTime((int)$time['hour'],(int)$time['minute'],(int)$time['second']);
159 176
 				break;
160 177
 
@@ -178,7 +195,10 @@  discard block
 block discarded – undo
178 195
 	 */
179 196
 	public function add($interval)
180 197
 	{
181
-		if (is_string($interval)) $interval = DateInterval::createFromDateString($interval);
198
+		if (is_string($interval))
199
+		{
200
+			$interval = DateInterval::createFromDateString($interval);
201
+		}
182 202
 
183 203
 		parent::add($interval);
184 204
 	}
@@ -202,7 +222,10 @@  discard block
 block discarded – undo
202 222
 				$wstart = -($wday ? $wday-1 : 6);
203 223
 				break;
204 224
 		}
205
-		if ($wstart) $this->add($wstart.'days');
225
+		if ($wstart)
226
+		{
227
+			$this->add($wstart.'days');
228
+		}
206 229
 	}
207 230
 
208 231
 	/**
@@ -263,15 +286,27 @@  discard block
 block discarded – undo
263 286
 			}
264 287
 			elseif ($sday || $eday)
265 288
 			{
266
-				if ($sday) $start->add($sday.'days');
267
-				if ($eday) $end->add($eday.'days');
289
+				if ($sday)
290
+				{
291
+					$start->add($sday.'days');
292
+				}
293
+				if ($eday)
294
+				{
295
+					$end->add($eday.'days');
296
+				}
268 297
 			}
269 298
 			elseif ($sweek || $eweek)
270 299
 			{
271 300
 				$start->setWeekstart();
272
-				if ($sweek) $start->add($sweek.'weeks');
301
+				if ($sweek)
302
+				{
303
+					$start->add($sweek.'weeks');
304
+				}
273 305
 				$end->setWeekstart();
274
-				if ($eweek) $end->add($eweek.'weeks');
306
+				if ($eweek)
307
+				{
308
+					$end->add($eweek.'weeks');
309
+				}
275 310
 			}
276 311
 		}
277 312
 		// convert start + end from user to servertime for the filter
@@ -416,7 +451,10 @@  discard block
 block discarded – undo
416 451
 		}
417 452
 		$time->setUser();
418 453
 
419
-		if (is_null($type)) $type = $typeof;
454
+		if (is_null($type))
455
+		{
456
+			$type = $typeof;
457
+		}
420 458
 
421 459
 		//echo "<p>".__METHOD__."($time,$type) = ".print_r($format->format($type),true)."</p>\n";
422 460
 		return $time->format($type);
@@ -446,7 +484,10 @@  discard block
 block discarded – undo
446 484
 		}
447 485
 		$time->setServer();
448 486
 
449
-		if (is_null($type)) $type = $typeof;
487
+		if (is_null($type))
488
+		{
489
+			$type = $typeof;
490
+		}
450 491
 
451 492
 		//echo "<p>".__METHOD__."($time,$type) = ".print_r($format->format($type),true)."</p>\n";
452 493
 		return $time->format($type);
@@ -520,8 +561,12 @@  discard block
 block discarded – undo
520 561
 					$time,
521 562
 					static::$user_timezone
522 563
 				);
523
-				if($date) break;
524
-			} catch (\Exception $e) {
564
+				if($date)
565
+				{
566
+					break;
567
+				}
568
+			}
569
+			catch (\Exception $e) {
525 570
 
526 571
 			}
527 572
 		}
@@ -540,7 +585,10 @@  discard block
 block discarded – undo
540 585
 	public static function setUserPrefs($tz,$dateformat='',$timeformat='')
541 586
 	{
542 587
 		//echo "<p>".__METHOD__."('$tz','$dateformat','$timeformat') ".function_backtrace()."</p>\n";
543
-		if (!empty($dateformat)) self::$user_dateformat = $dateformat;
588
+		if (!empty($dateformat))
589
+		{
590
+			self::$user_dateformat = $dateformat;
591
+		}
544 592
 
545 593
 		switch($timeformat)
546 594
 		{
@@ -578,7 +626,10 @@  discard block
 block discarded – undo
578 626
 	 */
579 627
 	public static function tz_offset_s($time='now')
580 628
 	{
581
-		if (!($time instanceof DateTime)) $time = new DateTime($time);
629
+		if (!($time instanceof DateTime))
630
+		{
631
+			$time = new DateTime($time);
632
+		}
582 633
 
583 634
 		return self::$user_timezone->getOffset($time) - self::$server_timezone->getOffset($time);
584 635
 	}
@@ -686,9 +737,17 @@  discard block
 block discarded – undo
686 737
 		);
687 738
 		foreach(DateTimeZone::listIdentifiers() as $name)
688 739
 		{
689
-			if (in_array($name,$no_vtimezone)) continue;	// do NOT allow to set in EGroupware, as we have not VTIMEZONE component for it
740
+			if (in_array($name,$no_vtimezone))
741
+			{
742
+				continue;
743
+			}
744
+			// do NOT allow to set in EGroupware, as we have not VTIMEZONE component for it
690 745
 			list($continent) = explode('/',$name,2);
691
-			if (!isset($tzs[$continent])) continue;	// old depricated timezones
746
+			if (!isset($tzs[$continent]))
747
+			{
748
+				continue;
749
+			}
750
+			// old depricated timezones
692 751
 			$datetime = new DateTime('now',new DateTimeZone($name));
693 752
 			$tzs[$continent][$name] = str_replace(array('_','/'),array(' ',' / '),$name)."  ".$datetime->format();
694 753
 			unset($datetime);
@@ -727,10 +786,13 @@  discard block
 block discarded – undo
727 786
 		{
728 787
 			$user_tzs = array_merge(array($tz),$user_tzs);
729 788
 		}
730
-		if (!$user_tzs)	// if we have no user timezones, eg. user set no pref --> use server default
789
+		if (!$user_tzs)
790
+		{
791
+			// if we have no user timezones, eg. user set no pref --> use server default
731 792
 		{
732 793
 			$user_tzs = array($GLOBALS['egw_info']['server']['server_timezone']);
733 794
 		}
795
+		}
734 796
 		if ($extra && !in_array($extra,$user_tzs))
735 797
 		{
736 798
 			$user_tzs = array_merge(array($extra),$user_tzs);
Please login to merge, or discard this patch.
Spacing   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -93,11 +93,11 @@  discard block
 block discarded – undo
93 93
 	 * @param string &$type=null on return type of $time (optional)
94 94
 	 * @throws Exception if $time can NOT be parsed
95 95
 	 */
96
-	public function __construct($time='now',DateTimeZone $tz=null,&$type=null)
96
+	public function __construct($time = 'now', DateTimeZone $tz = null, &$type = null)
97 97
 	{
98
-		if (is_null($tz)) $tz = self::$user_timezone;	// default user timezone
98
+		if (is_null($tz)) $tz = self::$user_timezone; // default user timezone
99 99
 
100
-		switch(($type = gettype($time)))
100
+		switch (($type = gettype($time)))
101 101
 		{
102 102
 			case 'NULL':
103 103
 			case 'boolean':	// depricated use in calendar for 'now'
@@ -108,13 +108,13 @@  discard block
 block discarded – undo
108 108
 				if (!(is_numeric($time) && ($time > 21000000 || $time < 19000000)))
109 109
 				{
110 110
 					$t_str = $time;
111
-					if (is_numeric($time) && strlen($time) == 8) $t_str .= 'T000000';	// 'Ymd' string used in calendar to represent a date
111
+					if (is_numeric($time) && strlen($time) == 8) $t_str .= 'T000000'; // 'Ymd' string used in calendar to represent a date
112 112
 					// $time ending in a Z (Zulu or UTC time), is unterstood by DateTime class itself
113 113
 					try {
114
-						parent::__construct($t_str,$tz);
114
+						parent::__construct($t_str, $tz);
115 115
 						break;
116 116
 					}
117
-					catch(Exception $e) {
117
+					catch (Exception $e) {
118 118
 						// if string is nummeric, ignore the exception and treat string as timestamp
119 119
 						if (!is_numeric($time)) throw $e;
120 120
 					}
@@ -131,12 +131,12 @@  discard block
 block discarded – undo
131 131
 				}
132 132
 				else*/
133 133
 				{
134
-					parent::__construct(date('Y-m-d H:i:s',$time),$tz);
134
+					parent::__construct(date('Y-m-d H:i:s', $time), $tz);
135 135
 				}
136 136
 				break;
137 137
 
138 138
 			case 'array':
139
-				parent::__construct('now',$tz);
139
+				parent::__construct('now', $tz);
140 140
 				if (isset($time['Y']))	// array format used in eTemplate
141 141
 				{
142 142
 					$time = array(
@@ -150,18 +150,18 @@  discard block
 block discarded – undo
150 150
 				}
151 151
 				if (!empty($time['full']) && empty($time['year']))
152 152
 				{
153
-					$time['year']  = (int)substr($time['full'],0,4);
154
-					$time['month'] = (int)substr($time['full'],4,2);
155
-					$time['day']   = (int)substr($time['full'],6,2);
153
+					$time['year']  = (int)substr($time['full'], 0, 4);
154
+					$time['month'] = (int)substr($time['full'], 4, 2);
155
+					$time['day']   = (int)substr($time['full'], 6, 2);
156 156
 				}
157
-				if (isset($time['year'])) $this->setDate((int)$time['year'],(int)$time['month'],isset($time['day']) ? (int)$time['day'] : (int)$time['mday']);
158
-				$this->setTime((int)$time['hour'],(int)$time['minute'],(int)$time['second']);
157
+				if (isset($time['year'])) $this->setDate((int)$time['year'], (int)$time['month'], isset($time['day']) ? (int)$time['day'] : (int)$time['mday']);
158
+				$this->setTime((int)$time['hour'], (int)$time['minute'], (int)$time['second']);
159 159
 				break;
160 160
 
161 161
 			case 'object':
162 162
 				if ($time instanceof \DateTime)
163 163
 				{
164
-					parent::__construct($time->format('Y-m-d H:i:s'),$time->getTimezone());
164
+					parent::__construct($time->format('Y-m-d H:i:s'), $time->getTimezone());
165 165
 					$this->setTimezone($tz);
166 166
 					break;
167 167
 				}
@@ -188,18 +188,18 @@  discard block
 block discarded – undo
188 188
 	 */
189 189
 	public function setWeekstart()
190 190
 	{
191
-		$wday = (int) $this->format('w'); // 0=sun, ..., 6=sat
192
-		switch($GLOBALS['egw_info']['user']['preferences']['calendar']['weekdaystarts'])
191
+		$wday = (int)$this->format('w'); // 0=sun, ..., 6=sat
192
+		switch ($GLOBALS['egw_info']['user']['preferences']['calendar']['weekdaystarts'])
193 193
 		{
194 194
 			case 'Sunday':
195 195
 				$wstart = -$wday;
196 196
 				break;
197 197
 			case 'Saturday':
198
-				$wstart =  -(6-$wday);
198
+				$wstart = -(6 - $wday);
199 199
 				break;
200 200
 			case 'Moday':
201 201
 			default:
202
-				$wstart = -($wday ? $wday-1 : 6);
202
+				$wstart = -($wday ? $wday - 1 : 6);
203 203
 				break;
204 204
 		}
205 205
 		if ($wstart) $this->add($wstart.'days');
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
 	 * @param array $filters $name => list($syear,$smonth,$sday,$sweek,$eyear,$emonth,$eday,$eweek) pairs with offsets
216 216
 	 * @return string
217 217
 	 */
218
-	public static function sql_filter($name, &$start, &$end, $column, array $filters=array())
218
+	public static function sql_filter($name, &$start, &$end, $column, array $filters = array())
219 219
 	{
220 220
 		if ($name == 'custom' && $start)
221 221
 		{
@@ -240,26 +240,26 @@  discard block
 block discarded – undo
240 240
 			$end   = new DateTime('now');
241 241
 			$end->setTime(0, 0, 0);
242 242
 
243
-			$year  = (int) $start->format('Y');
244
-			$month = (int) $start->format('m');
243
+			$year  = (int)$start->format('Y');
244
+			$month = (int)$start->format('m');
245 245
 
246
-			list($syear,$smonth,$sday,$sweek,$eyear,$emonth,$eday,$eweek) = $filters[$name];
246
+			list($syear, $smonth, $sday, $sweek, $eyear, $emonth, $eday, $eweek) = $filters[$name];
247 247
 
248 248
 			// Handle quarters
249
-			if(stripos($name, 'quarter') !== false)
249
+			if (stripos($name, 'quarter') !== false)
250 250
 			{
251
-				$start->setDate($year, ((int)floor(($smonth+$month) / 3.1)) * 3 + 1, 1);
252
-				$end->setDate($year, ((int)floor(($emonth+$month) / 3.1)+1) * 3 + 1, 1);
251
+				$start->setDate($year, ((int)floor(($smonth + $month) / 3.1)) * 3 + 1, 1);
252
+				$end->setDate($year, ((int)floor(($emonth + $month) / 3.1) + 1) * 3 + 1, 1);
253 253
 			}
254 254
 			elseif ($syear || $eyear)
255 255
 			{
256
-				$start->setDate($year+$syear, 1, 1);
257
-				$end->setDate($year+$eyear, 1, 1);
256
+				$start->setDate($year + $syear, 1, 1);
257
+				$end->setDate($year + $eyear, 1, 1);
258 258
 			}
259 259
 			elseif ($smonth || $emonth)
260 260
 			{
261
-				$start->setDate($year, $month+$smonth, 1);
262
-				$end->setDate($year, $month+$emonth, 1);
261
+				$start->setDate($year, $month + $smonth, 1);
262
+				$end->setDate($year, $month + $emonth, 1);
263 263
 			}
264 264
 			elseif ($sday || $eday)
265 265
 			{
@@ -276,9 +276,9 @@  discard block
 block discarded – undo
276 276
 		}
277 277
 		// convert start + end from user to servertime for the filter
278 278
 		$sql = '('.DateTime::user2server($start, 'ts').' <= '.$column;
279
-		if($end)
279
+		if ($end)
280 280
 		{
281
-			$sql .=' AND '.$column.' < '.DateTime::user2server($end, 'ts');
281
+			$sql .= ' AND '.$column.' < '.DateTime::user2server($end, 'ts');
282 282
 
283 283
 			// returned timestamps: $end is an inclusive date, eg. for today it's equal to start!
284 284
 			$end->add('-1day');
@@ -320,9 +320,9 @@  discard block
 block discarded – undo
320 320
 	 * 		true = date only, false = time only as in user prefs, '' = date+time as in user prefs
321 321
 	 * @return int|string|array|datetime see $type
322 322
 	 */
323
-	public function format($type='')
323
+	public function format($type = '')
324 324
 	{
325
-		switch((string)$type)
325
+		switch ((string)$type)
326 326
 		{
327 327
 			case '':	// empty string:  date and time as in user prefs
328 328
 			//case '':	// boolean false: time as in user prefs
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
 			case 'integer':
348 348
 			case 'ts':
349 349
 				// ToDo: Check if PHP5.3 getTimestamp does the same, or always returns UTC timestamp
350
-				return mktime(parent::format('H'),parent::format('i'),parent::format('s'),parent::format('m'),parent::format('d'),parent::format('Y'));
350
+				return mktime(parent::format('H'), parent::format('i'), parent::format('s'), parent::format('m'), parent::format('d'), parent::format('Y'));
351 351
 
352 352
 			case 'object':
353 353
 			case 'datetime':
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
 					'second' => (int)parent::format('s'),
366 366
 					'full'   => parent::format('Ymd'),
367 367
 				);
368
-				$arr['raw'] = mktime($arr['hour'],$arr['minute'],$arr['second'],$arr['month'],$arr['day'],$arr['year']);
368
+				$arr['raw'] = mktime($arr['hour'], $arr['minute'], $arr['second'], $arr['month'], $arr['day'], $arr['year']);
369 369
 				return $arr;
370 370
 
371 371
 			case 'date_array':	// array with short keys used by date: Y, m, d, H, i, s (used in eTemplate)
@@ -399,19 +399,19 @@  discard block
 block discarded – undo
399 399
 	 * @param string $type =null type or return-value, default (null) same as $time
400 400
 	 * @return int|string|array|datetime null if time could not be parsed
401 401
 	 */
402
-	public static function server2user($time,$type=null)
402
+	public static function server2user($time, $type = null)
403 403
 	{
404
-		$typeof='DateTime';
404
+		$typeof = 'DateTime';
405 405
 		if (!($time instanceof DateTime))
406 406
 		{
407 407
 			try
408 408
 			{
409 409
 				$time = new DateTime($time, self::$server_timezone, $typeof);
410 410
 			}
411
-			catch(Exception $e)
411
+			catch (Exception $e)
412 412
 			{
413 413
 				unset($e);
414
-				return null;	// time could not be parsed
414
+				return null; // time could not be parsed
415 415
 			}
416 416
 		}
417 417
 		$time->setUser();
@@ -429,19 +429,19 @@  discard block
 block discarded – undo
429 429
 	 * @param string $type =null type or return-value, default (null) same as $time
430 430
 	 * @return int|string|array|datetime null if time could not be parsed
431 431
 	 */
432
-	public static function user2server($time,$type=null)
432
+	public static function user2server($time, $type = null)
433 433
 	{
434
-		$typeof='DateTime';
434
+		$typeof = 'DateTime';
435 435
 		if (!($time instanceof DateTime))
436 436
 		{
437 437
 			try
438 438
 			{
439
-				$time = new DateTime($time,self::$user_timezone,$typeof);
439
+				$time = new DateTime($time, self::$user_timezone, $typeof);
440 440
 			}
441
-			catch(Exception $e)
441
+			catch (Exception $e)
442 442
 			{
443 443
 				unset($e);
444
-				return null;	// time could not be parsed
444
+				return null; // time could not be parsed
445 445
 			}
446 446
 		}
447 447
 		$time->setServer();
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
 	 * 		true = date only, false = time only as in user prefs, '' = date+time as in user prefs
462 462
 	 * @return int|string|array|datetime see $type, null if time could not be parsed
463 463
 	 */
464
-	public static function to($time='now',$type='')
464
+	public static function to($time = 'now', $type = '')
465 465
 	{
466 466
 		if (!($time instanceof DateTime))
467 467
 		{
@@ -470,10 +470,10 @@  discard block
 block discarded – undo
470 470
 				// Try user format first
471 471
 				$time = static::createFromUserFormat($time);
472 472
 			}
473
-			catch(\Exception $e)
473
+			catch (\Exception $e)
474 474
 			{
475 475
 				unset($e);
476
-				return null;	// time could not be parsed
476
+				return null; // time could not be parsed
477 477
 			}
478 478
 		}
479 479
 		return $time->format($type);
@@ -497,22 +497,22 @@  discard block
 block discarded – undo
497 497
 		$date = null;
498 498
 
499 499
 		// If numeric, just let normal constructor do it
500
-		if(is_numeric($time))
500
+		if (is_numeric($time))
501 501
 		{
502 502
 			return new DateTime($time);
503 503
 		}
504 504
 
505 505
 		// Various date formats in decreasing preference
506 506
 		$formats = array(
507
-			'!'.static::$user_dateformat . ' ' .static::$user_timeformat.':s',
508
-			'!'.static::$user_dateformat . '*' .static::$user_timeformat.':s',
509
-			'!'.static::$user_dateformat . '* ' .static::$user_timeformat,
510
-			'!'.static::$user_dateformat . '*',
507
+			'!'.static::$user_dateformat.' '.static::$user_timeformat.':s',
508
+			'!'.static::$user_dateformat.'*'.static::$user_timeformat.':s',
509
+			'!'.static::$user_dateformat.'* '.static::$user_timeformat,
510
+			'!'.static::$user_dateformat.'*',
511 511
 			'!'.static::$user_dateformat,
512 512
 			'!Y-m-d\TH:i:s'
513 513
 		);
514 514
 		// Try the different formats, stop when one works
515
-		foreach($formats as $f)
515
+		foreach ($formats as $f)
516 516
 		{
517 517
 			try {
518 518
 				$date = static::createFromFormat(
@@ -520,7 +520,7 @@  discard block
 block discarded – undo
520 520
 					$time,
521 521
 					static::$user_timezone
522 522
 				);
523
-				if($date) break;
523
+				if ($date) break;
524 524
 			} catch (\Exception $e) {
525 525
 
526 526
 			}
@@ -537,12 +537,12 @@  discard block
 block discarded – undo
537 537
 	 * @param string|int $timeformat ='' integer 12, 24, or format string eg. 'H:i'
538 538
 	 * @return DateTimeZone
539 539
 	 */
540
-	public static function setUserPrefs($tz,$dateformat='',$timeformat='')
540
+	public static function setUserPrefs($tz, $dateformat = '', $timeformat = '')
541 541
 	{
542 542
 		//echo "<p>".__METHOD__."('$tz','$dateformat','$timeformat') ".function_backtrace()."</p>\n";
543 543
 		if (!empty($dateformat)) self::$user_dateformat = $dateformat;
544 544
 
545
-		switch($timeformat)
545
+		switch ($timeformat)
546 546
 		{
547 547
 			case '':
548 548
 				break;
@@ -559,7 +559,7 @@  discard block
 block discarded – undo
559 559
 		try {
560 560
 			self::$user_timezone = new DateTimeZone($tz);
561 561
 		}
562
-		catch(\Exception $e)
562
+		catch (\Exception $e)
563 563
 		{
564 564
 			unset($e);
565 565
 			// silently use server timezone, as we have no means to report the wrong timezone to the user from this class
@@ -576,7 +576,7 @@  discard block
 block discarded – undo
576 576
 	 * @param int|string|DateTime $time ='now'
577 577
 	 * @return int difference in seconds between user and server time (for the given time!)
578 578
 	 */
579
-	public static function tz_offset_s($time='now')
579
+	public static function tz_offset_s($time = 'now')
580 580
 	{
581 581
 		if (!($time instanceof DateTime)) $time = new DateTime($time);
582 582
 
@@ -597,17 +597,17 @@  discard block
 block discarded – undo
597 597
 		try {
598 598
 			self::$server_timezone = new DateTimeZone($GLOBALS['egw_info']['server']['server_timezone']);
599 599
 		}
600
-		catch(\Exception $e)
600
+		catch (\Exception $e)
601 601
 		{
602 602
 			try {
603 603
 				self::$server_timezone = new DateTimeZone(date_default_timezone_get());
604 604
 			}
605
-			catch(\Exception $e)
605
+			catch (\Exception $e)
606 606
 			{
607 607
 				self::$server_timezone = new DateTimeZone('Europe/Berlin');
608 608
 			}
609 609
 			error_log(__METHOD__."() invalid server_timezone='{$GLOBALS['egw_info']['server']['server_timezone']}' setting now '".self::$server_timezone->getName()."'!");
610
-			Config::save_value('server_timezone',$GLOBALS['egw_info']['server']['server_timezone'] = self::$server_timezone->getName(),'phpgwapi');
610
+			Config::save_value('server_timezone', $GLOBALS['egw_info']['server']['server_timezone'] = self::$server_timezone->getName(), 'phpgwapi');
611 611
 		}
612 612
 		if (!isset($GLOBALS['egw_info']['user']['preferences']['common']['tz']))
613 613
 		{
@@ -630,15 +630,15 @@  discard block
 block discarded – undo
630 630
 	{
631 631
 		// prepare list of timezones from php, ignoring depricated ones and sort as follows
632 632
 		$tzs = array(
633
-			'Africa'     => array(),	// Contients
633
+			'Africa'     => array(), // Contients
634 634
 			'America'    => array(),
635 635
 			'Asia'       => array(),
636 636
 			'Australia'  => array(),
637 637
 			'Europe'     => array(),
638
-			'Atlantic'   => array(),	// Oceans
638
+			'Atlantic'   => array(), // Oceans
639 639
 			'Pacific'    => array(),
640 640
 			'Indian'     => array(),
641
-			'Antarctica' => array(),	// Poles
641
+			'Antarctica' => array(), // Poles
642 642
 			'Arctic'     => array(),
643 643
 			'UTC'        => array('UTC' => 'UTC'),
644 644
 		);
@@ -684,27 +684,27 @@  discard block
 block discarded – undo
684 684
 			'Australia/Yancowinna',
685 685
 			'Pacific/Samoa',
686 686
 		);
687
-		foreach(DateTimeZone::listIdentifiers() as $name)
687
+		foreach (DateTimeZone::listIdentifiers() as $name)
688 688
 		{
689
-			if (in_array($name,$no_vtimezone)) continue;	// do NOT allow to set in EGroupware, as we have not VTIMEZONE component for it
690
-			list($continent) = explode('/',$name,2);
691
-			if (!isset($tzs[$continent])) continue;	// old depricated timezones
692
-			$datetime = new DateTime('now',new DateTimeZone($name));
693
-			$tzs[$continent][$name] = str_replace(array('_','/'),array(' ',' / '),$name)."  ".$datetime->format();
689
+			if (in_array($name, $no_vtimezone)) continue; // do NOT allow to set in EGroupware, as we have not VTIMEZONE component for it
690
+			list($continent) = explode('/', $name, 2);
691
+			if (!isset($tzs[$continent])) continue; // old depricated timezones
692
+			$datetime = new DateTime('now', new DateTimeZone($name));
693
+			$tzs[$continent][$name] = str_replace(array('_', '/'), array(' ', ' / '), $name)."  ".$datetime->format();
694 694
 			unset($datetime);
695 695
 		}
696
-		foreach($tzs as $continent => &$data)
696
+		foreach ($tzs as $continent => &$data)
697 697
 		{
698
-			natcasesort($data);	// sort cities
698
+			natcasesort($data); // sort cities
699 699
 		}
700 700
 		unset($data);
701 701
 
702 702
 		// if user lang or installed langs contain a european language --> move Europe to top of tz list
703 703
 		$langs = class_exists('EGroupware\\Api\\Translation') ? Translation::get_installed_langs() : array();
704
-		if (array_intersect(array($GLOBALS['egw_info']['user']['preferences']['common']['lang'])+array_keys($langs),
705
-			array('de','fr','it','nl','bg','ca','cs','da','el','es-es','et','eu','fi','hr','hu','lt','no','pl','pt','sk','sl','sv','tr','uk')))
704
+		if (array_intersect(array($GLOBALS['egw_info']['user']['preferences']['common']['lang']) + array_keys($langs),
705
+			array('de', 'fr', 'it', 'nl', 'bg', 'ca', 'cs', 'da', 'el', 'es-es', 'et', 'eu', 'fi', 'hr', 'hu', 'lt', 'no', 'pl', 'pt', 'sk', 'sl', 'sv', 'tr', 'uk')))
706 706
 		{
707
-			$tzs = array_merge(array('Europe' => $tzs['Europe']),$tzs);
707
+			$tzs = array_merge(array('Europe' => $tzs['Europe']), $tzs);
708 708
 		}
709 709
 		return $tzs;
710 710
 	}
@@ -715,30 +715,30 @@  discard block
 block discarded – undo
715 715
 	 * @param string $extra extra timezone to add, if not already included in user timezones
716 716
 	 * @return array tzid => label
717 717
 	 */
718
-	public static function getUserTimezones($extra=null)
718
+	public static function getUserTimezones($extra = null)
719 719
 	{
720 720
 		$tz = $GLOBALS['egw_info']['user']['preferences']['common']['tz'];
721
-		$user_tzs = explode(',',$GLOBALS['egw_info']['user']['preferences']['common']['tz_selection']);
721
+		$user_tzs = explode(',', $GLOBALS['egw_info']['user']['preferences']['common']['tz_selection']);
722 722
 		if (count($user_tzs) <= 1)
723 723
 		{
724 724
 			$user_tzs = $tz ? array($tz) : array();
725 725
 		}
726
-		if ($tz && !in_array($tz,$user_tzs))
726
+		if ($tz && !in_array($tz, $user_tzs))
727 727
 		{
728
-			$user_tzs = array_merge(array($tz),$user_tzs);
728
+			$user_tzs = array_merge(array($tz), $user_tzs);
729 729
 		}
730 730
 		if (!$user_tzs)	// if we have no user timezones, eg. user set no pref --> use server default
731 731
 		{
732 732
 			$user_tzs = array($GLOBALS['egw_info']['server']['server_timezone']);
733 733
 		}
734
-		if ($extra && !in_array($extra,$user_tzs))
734
+		if ($extra && !in_array($extra, $user_tzs))
735 735
 		{
736
-			$user_tzs = array_merge(array($extra),$user_tzs);
736
+			$user_tzs = array_merge(array($extra), $user_tzs);
737 737
 		}
738
-		$ret_user_tzs = array_combine($user_tzs,$user_tzs);
739
-		foreach($ret_user_tzs as &$label)
738
+		$ret_user_tzs = array_combine($user_tzs, $user_tzs);
739
+		foreach ($ret_user_tzs as &$label)
740 740
 		{
741
-			$label = str_replace(array('_','/'),array(' ',' / '),$label);
741
+			$label = str_replace(array('_', '/'), array(' ', ' / '), $label);
742 742
 		}
743 743
 		return $ret_user_tzs;
744 744
 	}
Please login to merge, or discard this patch.
infolog/inc/class.infolog_merge.inc.php 1 patch
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 	 * @param string &$content=null content to create some replacements only if they are use
64 64
 	 * @return array|boolean
65 65
 	 */
66
-	protected function get_replacements($id,&$content=null)
66
+	protected function get_replacements($id, &$content = null)
67 67
 	{
68 68
 		if (!($replacements = $this->infolog_replacements($id, '', $content)))
69 69
 		{
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 	 * @param string $prefix='' prefix like eg. 'erole'
80 80
 	 * @return array|boolean
81 81
 	 */
82
-	public function infolog_replacements($id,$prefix='', &$content = '')
82
+	public function infolog_replacements($id, $prefix = '', &$content = '')
83 83
 	{
84 84
 		$record = new infolog_egw_record($id);
85 85
 		$info = array();
@@ -87,13 +87,13 @@  discard block
 block discarded – undo
87 87
 		// Convert to human friendly values
88 88
 		$types = infolog_egw_record::$types;
89 89
 		$_selects = $this->bo->enums + array('status' => $this->bo->status[$record->info_type]);
90
-		foreach($_selects as $name => $value)
90
+		foreach ($_selects as $name => $value)
91 91
 		{
92 92
 			$selects['info_'.$name] = $value;
93
-			if(!in_array('info_'.$name, $types['select'])) $types['select'][] = 'info_'.$name;
93
+			if (!in_array('info_'.$name, $types['select'])) $types['select'][] = 'info_'.$name;
94 94
 		}
95 95
 
96
-		if($content && strpos($content, '$$#') !== FALSE)
96
+		if ($content && strpos($content, '$$#') !== FALSE)
97 97
 		{
98 98
 			$this->cf_link_to_expand($record->get_record_array(), $content, $info);
99 99
 		}
@@ -101,21 +101,21 @@  discard block
 block discarded – undo
101 101
 		importexport_export_csv::convert($record, $types, 'infolog', $selects);
102 102
 
103 103
 		$array = $record->get_record_array();
104
-		if($record->info_contact)
104
+		if ($record->info_contact)
105 105
 		{
106 106
 			$array['info_contact'] = $array['info_link']['title'];
107 107
 		}
108 108
 
109 109
 		// Set any missing custom fields, or the marker will stay
110 110
 		$array = $record->get_record_array();
111
-		foreach($this->bo->customfields as $name => $field)
111
+		foreach ($this->bo->customfields as $name => $field)
112 112
 		{
113
-			if(!$array['#'.$name])
113
+			if (!$array['#'.$name])
114 114
 			{
115 115
 				$array['#'.$name] = '';
116 116
 			}
117 117
 			// Format date cfs per user Api\Preferences
118
-			if($array['#'.$name] && ($field['type'] == 'date' || $field['type'] == 'date-time'))
118
+			if ($array['#'.$name] && ($field['type'] == 'date' || $field['type'] == 'date-time'))
119 119
 			{
120 120
 				$this->date_fields[] = '#'.$name;
121 121
 				$array['#'.$name] = Api\DateTime::to($array['#'.$name], $field['type'] == 'date' ? true : '');
@@ -126,16 +126,16 @@  discard block
 block discarded – undo
126 126
 		$array += $this->get_all_links('infolog', $id, $prefix, $content);
127 127
 
128 128
 		// Timesheet time
129
-		if(strpos($content, 'info_sum_timesheets'))
129
+		if (strpos($content, 'info_sum_timesheets'))
130 130
 		{
131
-			$links = Link::get_links('infolog',$id,'timesheet');
132
-			$sum = ExecMethod('timesheet.timesheet_bo.sum',$links);
131
+			$links = Link::get_links('infolog', $id, 'timesheet');
132
+			$sum = ExecMethod('timesheet.timesheet_bo.sum', $links);
133 133
 			$info['$$info_sum_timesheets$$'] = $sum['duration'];
134 134
 		}
135 135
 
136 136
 		// Check for linked project ID
137 137
 		$links = Link::get_links('infolog', $id, 'projectmanager');
138
-		foreach($links as $app_id)
138
+		foreach ($links as $app_id)
139 139
 		{
140 140
 			$array['pm_id'] = $app_id;
141 141
 			$array['project'] = Link::title('projectmanager', $app_id);
@@ -144,24 +144,24 @@  discard block
 block discarded – undo
144 144
 		if (strpos($content, '$$project/') !== false && $array['pm_id'] && class_exists('projectmanager_merge'))
145 145
 		{
146 146
 			$pm_merge = new projectmanager_merge($array['pm_id']);
147
-			$info += $pm_merge->projectmanager_replacements($array['pm_id'],'project',$content);
147
+			$info += $pm_merge->projectmanager_replacements($array['pm_id'], 'project', $content);
148 148
 		}
149 149
 
150 150
 		// Add markers
151
-		foreach($array as $key => &$value)
151
+		foreach ($array as $key => &$value)
152 152
 		{
153
-			if(!$value) $value = '';
154
-			$info['$$'.($prefix ? $prefix.'/':'').$key.'$$'] = $value;
153
+			if (!$value) $value = '';
154
+			$info['$$'.($prefix ? $prefix.'/' : '').$key.'$$'] = $value;
155 155
 		}
156 156
 
157 157
 		// Add contact fields
158
-		if($array['info_link']['app'] && $array['info_link']['id'])
158
+		if ($array['info_link']['app'] && $array['info_link']['id'])
159 159
 		{
160
-			$info+=$this->get_app_replacements($array['info_link']['app'], $array['info_link']['id'], $content, 'info_contact');
160
+			$info += $this->get_app_replacements($array['info_link']['app'], $array['info_link']['id'], $content, 'info_contact');
161 161
 		}
162 162
 
163 163
 		// Add parent
164
-		if($record->info_id_parent)
164
+		if ($record->info_id_parent)
165 165
 		{
166 166
 			$info += $this->infolog_replacements($record->info_id_parent, 'info_id_parent', $content);
167 167
 		}
@@ -185,11 +185,11 @@  discard block
 block discarded – undo
185 185
 		$tracking = new infolog_tracking($this->bo);
186 186
 		$fields = array('info_id' => lang('Infolog ID'), 'pm_id' => lang('Project ID'), 'project' => lang('Project name')) + $tracking->field2label + array('info_sum_timesheets' => lang('Used time'));
187 187
 		Api\Translation::add_app('projectmanager');
188
-		foreach($fields as $name => $label)
188
+		foreach ($fields as $name => $label)
189 189
 		{
190
-			if (in_array($name,array('custom'))) continue;	// dont show them
190
+			if (in_array($name, array('custom'))) continue; // dont show them
191 191
 
192
-			if (in_array($name,array('info_subject', 'info_des')) && $n&1)		// main values, which should be in the first column
192
+			if (in_array($name, array('info_subject', 'info_des')) && $n&1)		// main values, which should be in the first column
193 193
 			{
194 194
 				echo "</tr>\n";
195 195
 				$n++;
@@ -202,26 +202,26 @@  discard block
 block discarded – undo
202 202
 
203 203
 		echo '<tr><td colspan="4"><h3>'.lang('Custom fields').":</h3></td></tr>";
204 204
 		$contact_custom = false;
205
-		foreach($this->bo->customfields as $name => $field)
205
+		foreach ($this->bo->customfields as $name => $field)
206 206
 		{
207
-			echo '<tr><td>{{#'.$name.'}}</td><td colspan="3">'.$field['label'].($field['type'] == 'select-account' ? '*':'')."</td></tr>\n";
208
-			if($field['type'] == 'select-account') $contact_custom = true;
207
+			echo '<tr><td>{{#'.$name.'}}</td><td colspan="3">'.$field['label'].($field['type'] == 'select-account' ? '*' : '')."</td></tr>\n";
208
+			if ($field['type'] == 'select-account') $contact_custom = true;
209 209
 		}
210
-		if($contact_custom)
210
+		if ($contact_custom)
211 211
 		{
212
-			echo '<tr><td /><td colspan="3">* '.lang('Addressbook placeholders available'). '</td></tr>';
212
+			echo '<tr><td /><td colspan="3">* '.lang('Addressbook placeholders available').'</td></tr>';
213 213
 		}
214 214
 
215 215
 		echo '<tr><td colspan="4"><h3>'.lang('Parent').":</h3></td></tr>";
216
-		echo '<tr><td>{{info_id_parent/info_subject}}</td><td colspan="3">'.lang('All other %1 fields are valid',lang('infolog'))."</td></tr>\n";
216
+		echo '<tr><td>{{info_id_parent/info_subject}}</td><td colspan="3">'.lang('All other %1 fields are valid', lang('infolog'))."</td></tr>\n";
217 217
 
218 218
 		echo '<tr><td colspan="4"><h3>'.lang('Contact fields').':</h3></td></tr>';
219 219
 		$i = 0;
220
-		foreach($this->contacts->contact_fields as $name => $label)
220
+		foreach ($this->contacts->contact_fields as $name => $label)
221 221
 		{
222
-			if (in_array($name,array('tid','label','geo'))) continue;       // dont show them, as they are not used in the UI atm.
222
+			if (in_array($name, array('tid', 'label', 'geo'))) continue; // dont show them, as they are not used in the UI atm.
223 223
 
224
-			if (in_array($name,array('email','org_name','tel_work','url')) && $n&1)         // main values, which should be in the first column
224
+			if (in_array($name, array('email', 'org_name', 'tel_work', 'url')) && $n&1)         // main values, which should be in the first column
225 225
 			{
226 226
 					echo "</tr>\n";
227 227
 					$i++;
@@ -233,13 +233,13 @@  discard block
 block discarded – undo
233 233
 		}
234 234
 
235 235
 		echo '<tr><td colspan="4"><h3>'.lang('Custom fields').":</h3></td></tr>";
236
-		foreach($this->contacts->customfields as $name => $field)
236
+		foreach ($this->contacts->customfields as $name => $field)
237 237
 		{
238 238
 			echo '<tr><td>{{info_contact/#'.$name.'}}</td><td colspan="3">'.$field['label']."</td></tr>\n";
239 239
 		}
240 240
 
241 241
 		echo '<tr><td colspan="4"><h3>'.lang('General fields:')."</h3></td></tr>";
242
-		foreach(array(
242
+		foreach (array(
243 243
 			'link' => lang('HTML link to the current record'),
244 244
 			'links' => lang('Titles of any entries linked to the current record, excluding attached files'),
245 245
 			'attachments' => lang('List of files linked to the current record'),
Please login to merge, or discard this patch.
api/src/Storage/Merge.php 2 patches
Spacing   +364 added lines, -365 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,11 +171,11 @@  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.ms-word.document.macroenabled.12':
@@ -183,17 +183,17 @@  discard block
 block discarded – undo
183 183
 			case 'application/vnd.openxmlformats-officedocument.spreadsheetml.shee':
184 184
 			case 'application/vnd.ms-excel.sheet.macroenabled.12':
185 185
 				if (!$zip_available) break;
186
-				return true;	// ms word xml format
186
+				return true; // ms word xml format
187 187
 			case 'application/xml':
188
-				return true;	// alias for text/xml, eg. ms office 2003 word format
188
+				return true; // alias for text/xml, eg. ms office 2003 word format
189 189
 			case 'message/rfc822':
190 190
 				return true; // ToDo: check if you are theoretical able to send mail
191 191
 			case 'application/x-yaml':
192
-				return true;	// yaml file, plain text with marginal syntax support for multiline replacements
192
+				return true; // yaml file, plain text with marginal syntax support for multiline replacements
193 193
 			default:
194
-				if (substr($mimetype,0,5) == 'text/')
194
+				if (substr($mimetype, 0, 5) == 'text/')
195 195
 				{
196
-					return true;	// text files
196
+					return true; // text files
197 197
 				}
198 198
 				break;
199 199
 		}
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
 	 * @param boolean $ignore_acl =false true: no acl check
212 212
 	 * @return array
213 213
 	 */
214
-	public function contact_replacements($contact,$prefix='',$ignore_acl=false)
214
+	public function contact_replacements($contact, $prefix = '', $ignore_acl = false)
215 215
 	{
216 216
 		if (!is_array($contact))
217 217
 		{
@@ -220,13 +220,13 @@  discard block
 block discarded – undo
220 220
 		if (!is_array($contact)) return array();
221 221
 
222 222
 		$replacements = array();
223
-		foreach(array_keys($this->contacts->contact_fields) as $name)
223
+		foreach (array_keys($this->contacts->contact_fields) as $name)
224 224
 		{
225 225
 			$value = $contact[$name];
226
-			switch($name)
226
+			switch ($name)
227 227
 			{
228 228
 				case 'created': case 'modified':
229
-					if($value) $value = Api\DateTime::to($value);
229
+					if ($value) $value = Api\DateTime::to($value);
230 230
 					break;
231 231
 				case 'bday':
232 232
 					if ($value)
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
 							$value = Api\DateTime::to($value, true);
236 236
 						}
237 237
 						catch (\Exception $e) {
238
-							unset($e);	// ignore exception caused by wrongly formatted date
238
+							unset($e); // ignore exception caused by wrongly formatted date
239 239
 						}
240 240
 					}
241 241
 					break;
@@ -248,11 +248,11 @@  discard block
 block discarded – undo
248 248
 						// if cat-tree is displayed, we return a full category path not just the name of the cat
249 249
 						$use = $GLOBALS['egw_info']['server']['cat_tab'] == 'Tree' ? 'path' : 'name';
250 250
 						$cats = array();
251
-						foreach(is_array($value) ? $value : explode(',',$value) as $cat_id)
251
+						foreach (is_array($value) ? $value : explode(',', $value) as $cat_id)
252 252
 						{
253
-							$cats[] = $GLOBALS['egw']->categories->id2name($cat_id,$use);
253
+							$cats[] = $GLOBALS['egw']->categories->id2name($cat_id, $use);
254 254
 						}
255
-						$value = implode(', ',$cats);
255
+						$value = implode(', ', $cats);
256 256
 					}
257 257
 					break;
258 258
 				case 'jpegphoto':	// returning a link might make more sense then the binary photo
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
 					{
261 261
 						$value = ($GLOBALS['egw_info']['server']['webserver_url'][0] == '/' ?
262 262
 							($_SERVER['HTTPS'] ? 'https://' : 'http://').$_SERVER['HTTP_HOST'] : '').
263
-							$GLOBALS['egw']->link('/index.php',$contact['photo']);
263
+							$GLOBALS['egw']->link('/index.php', $contact['photo']);
264 264
 					}
265 265
 					break;
266 266
 				case 'tel_prefer':
@@ -272,40 +272,39 @@  discard block
 block discarded – undo
272 272
 				case 'account_id':
273 273
 					if ($value)
274 274
 					{
275
-						$replacements['$$'.($prefix ? $prefix.'/':'').'account_lid$$'] = $GLOBALS['egw']->accounts->id2name($value);
275
+						$replacements['$$'.($prefix ? $prefix.'/' : '').'account_lid$$'] = $GLOBALS['egw']->accounts->id2name($value);
276 276
 					}
277 277
 					break;
278 278
 			}
279
-			if ($name != 'photo') $replacements['$$'.($prefix ? $prefix.'/':'').$name.'$$'] = $value;
279
+			if ($name != 'photo') $replacements['$$'.($prefix ? $prefix.'/' : '').$name.'$$'] = $value;
280 280
 		}
281 281
 		// set custom fields, should probably go to a general method all apps can use
282 282
 		// need to load all cfs for $ignore_acl=true
283
-		foreach($ignore_acl ? Customfields::get('addressbook', true) : $this->contacts->customfields as $name => $field)
283
+		foreach ($ignore_acl ? Customfields::get('addressbook', true) : $this->contacts->customfields as $name => $field)
284 284
 		{
285 285
 			$name = '#'.$name;
286
-			$replacements['$$'.($prefix ? $prefix.'/':'').$name.'$$'] =
286
+			$replacements['$$'.($prefix ? $prefix.'/' : '').$name.'$$'] =
287 287
 				// use raw data for yaml, no user-preference specific formatting
288
-				$this->mimetype == 'application/x-yaml' ? (string)$contact[$name] :
289
-				Customfields::format($field, (string)$contact[$name]);
288
+				$this->mimetype == 'application/x-yaml' ? (string)$contact[$name] : Customfields::format($field, (string)$contact[$name]);
290 289
 		}
291 290
 
292 291
 		// Add in extra cat field
293 292
 		$cats = array();
294
-		foreach(is_array($contact['cat_id']) ? $contact['cat_id'] : explode(',',$contact['cat_id']) as $cat_id)
293
+		foreach (is_array($contact['cat_id']) ? $contact['cat_id'] : explode(',', $contact['cat_id']) as $cat_id)
295 294
 		{
296
-			if(!$cat_id) continue;
297
-			if($GLOBALS['egw']->categories->id2name($cat_id,'main') != $cat_id)
295
+			if (!$cat_id) continue;
296
+			if ($GLOBALS['egw']->categories->id2name($cat_id, 'main') != $cat_id)
298 297
 			{
299 298
 				$path = explode(' / ', $GLOBALS['egw']->categories->id2name($cat_id, 'path'));
300 299
 				unset($path[0]); // Drop main
301
-				$cats[$GLOBALS['egw']->categories->id2name($cat_id,'main')][] = implode(' / ', $path);
302
-			} elseif($cat_id) {
300
+				$cats[$GLOBALS['egw']->categories->id2name($cat_id, 'main')][] = implode(' / ', $path);
301
+			} elseif ($cat_id) {
303 302
 				$cats[$cat_id] = array();
304 303
 			}
305 304
 		}
306
-		foreach($cats as $main => $cat) {
307
-			$replacements['$$'.($prefix ? $prefix.'/':'').'categories$$'] .= $GLOBALS['egw']->categories->id2name($main,'name')
308
-				. (count($cat) > 0 ? ': ' : '') . implode(', ', $cats[$main]) . "\n";
305
+		foreach ($cats as $main => $cat) {
306
+			$replacements['$$'.($prefix ? $prefix.'/' : '').'categories$$'] .= $GLOBALS['egw']->categories->id2name($main, 'name')
307
+				. (count($cat) > 0 ? ': ' : '').implode(', ', $cats[$main])."\n";
309 308
 		}
310 309
 		return $replacements;
311 310
 	}
@@ -324,34 +323,34 @@  discard block
 block discarded – undo
324 323
 	 * 	'link' - URL to the entry
325 324
 	 * 	'href' - HREF tag wrapped around the title
326 325
 	 */
327
-	protected function get_links($app, $id, $only_app='', $exclude = array(), $style = 'title')
326
+	protected function get_links($app, $id, $only_app = '', $exclude = array(), $style = 'title')
328 327
 	{
329 328
 		$links = Api\Link::get_links($app, $id, $only_app);
330 329
 		$link_titles = array();
331
-		foreach($links as $link_info)
330
+		foreach ($links as $link_info)
332 331
 		{
333 332
 			// Using only_app only returns the ID
334
-			if(!is_array($link_info) && $only_app && $only_app[0] !== '!')
333
+			if (!is_array($link_info) && $only_app && $only_app[0] !== '!')
335 334
 			{
336 335
 				$link_info = array(
337 336
 					'app'	=> $only_app,
338 337
 					'id'	=> $link_info
339 338
 				);
340 339
 			}
341
-			if($exclude && in_array($link_info['id'], $exclude)) continue;
340
+			if ($exclude && in_array($link_info['id'], $exclude)) continue;
342 341
 
343 342
 			$title = Api\Link::title($link_info['app'], $link_info['id']);
344
-			if(class_exists('EGroupware\Stylite\Vfs\Links\StreamWrapper') && $link_info['app'] != Api\Link::VFS_APPNAME)
343
+			if (class_exists('EGroupware\Stylite\Vfs\Links\StreamWrapper') && $link_info['app'] != Api\Link::VFS_APPNAME)
345 344
 			{
346 345
 				$title = Stylite\Vfs\Links\StreamWrapper::entry2name($link_info['app'], $link_info['id'], $title);
347 346
 			}
348
-			if($style == 'href' || $style == 'link')
347
+			if ($style == 'href' || $style == 'link')
349 348
 			{
350 349
 				$link = Api\Link::view($link_info['app'], $link_info['id'], $link_info);
351
-				if($link_info['app'] != Api\Link::VFS_APPNAME)
350
+				if ($link_info['app'] != Api\Link::VFS_APPNAME)
352 351
 				{
353 352
 					// Set app to false so we always get an external link
354
-					$link = str_replace(',', '%2C', $GLOBALS['egw']->framework->link('/index.php',$link, false));
353
+					$link = str_replace(',', '%2C', $GLOBALS['egw']->framework->link('/index.php', $link, false));
355 354
 				}
356 355
 				else
357 356
 				{
@@ -367,7 +366,7 @@  discard block
 block discarded – undo
367 366
 			}
368 367
 			$link_titles[] = $title;
369 368
 		}
370
-		return implode("\n",$link_titles);
369
+		return implode("\n", $link_titles);
371 370
 	}
372 371
 
373 372
 	/**
@@ -384,33 +383,33 @@  discard block
 block discarded – undo
384 383
 	{
385 384
 		$array = array();
386 385
 		$pattern = '@\$(links_attachments|links|attachments|link)\/?(title|href|link)?\/?([a-z]*)\$@';
387
-		static $link_cache=null;
386
+		static $link_cache = null;
388 387
 		$matches = null;
389
-		if(preg_match_all($pattern, $content, $matches))
388
+		if (preg_match_all($pattern, $content, $matches))
390 389
 		{
391
-			foreach($matches[0] as $i => $placeholder)
390
+			foreach ($matches[0] as $i => $placeholder)
392 391
 			{
393 392
 				$placeholder = substr($placeholder, 1, -1);
394
-				if($link_cache[$id][$placeholder])
393
+				if ($link_cache[$id][$placeholder])
395 394
 				{
396 395
 					$array[$placeholder] = $link_cache[$id][$placeholder];
397 396
 					continue;
398 397
 				}
399
-				switch($matches[1][$i])
398
+				switch ($matches[1][$i])
400 399
 				{
401 400
 					case 'link':
402 401
 						// Link to current record
403 402
 						$title = Api\Link::title($app, $id);
404
-						if(class_exists('EGroupware\Stylite\Vfs\Links\StreamWrapper') && $app != Api\Link::VFS_APPNAME)
403
+						if (class_exists('EGroupware\Stylite\Vfs\Links\StreamWrapper') && $app != Api\Link::VFS_APPNAME)
405 404
 						{
406 405
 							$title = Stylite\Vfs\Links\StreamWrapper::entry2name($app, $id, $title);
407 406
 						}
408 407
 
409 408
 						$link = Api\Link::view($app, $id);
410
-						if($app != Api\Link::VFS_APPNAME)
409
+						if ($app != Api\Link::VFS_APPNAME)
411 410
 						{
412 411
 							// Set app to false so we always get an external link
413
-							$link = str_replace(',', '%2C', $GLOBALS['egw']->framework->link('/index.php',$link, false));
412
+							$link = str_replace(',', '%2C', $GLOBALS['egw']->framework->link('/index.php', $link, false));
414 413
 						}
415 414
 						else
416 415
 						{
@@ -422,26 +421,26 @@  discard block
 block discarded – undo
422 421
 							$link = ($_SERVER['HTTPS'] || $GLOBALS['egw_info']['server']['enforce_ssl'] ? 'https://' : 'http://').
423 422
 								($GLOBALS['egw_info']['server']['hostname'] ? $GLOBALS['egw_info']['server']['hostname'] : $_SERVER['HTTP_HOST']).$link;
424 423
 						}
425
-						$array[($prefix?$prefix.'/':'').$placeholder] = Api\Html::a_href(Api\Html::htmlspecialchars($title), $link);
424
+						$array[($prefix ? $prefix.'/' : '').$placeholder] = Api\Html::a_href(Api\Html::htmlspecialchars($title), $link);
426 425
 						break;
427 426
 					case 'links':
428
-						$link_app = $matches[3][$i] ? $matches[3][$i] :  '!'.Api\Link::VFS_APPNAME;
429
-						$array[($prefix?$prefix.'/':'').$placeholder] = $this->get_links($app, $id, $link_app, array(),$matches[2][$i]);
427
+						$link_app = $matches[3][$i] ? $matches[3][$i] : '!'.Api\Link::VFS_APPNAME;
428
+						$array[($prefix ? $prefix.'/' : '').$placeholder] = $this->get_links($app, $id, $link_app, array(), $matches[2][$i]);
430 429
 						break;
431 430
 					case 'attachments':
432
-						$array[($prefix?$prefix.'/':'').$placeholder] = $this->get_links($app, $id, Api\Link::VFS_APPNAME,array(),$matches[2][$i]);
431
+						$array[($prefix ? $prefix.'/' : '').$placeholder] = $this->get_links($app, $id, Api\Link::VFS_APPNAME, array(), $matches[2][$i]);
433 432
 						break;
434 433
 					default:
435
-						$array[($prefix?$prefix.'/':'').$placeholder] = $this->get_links($app, $id, $matches[3][$i], array(), $matches[2][$i]);
434
+						$array[($prefix ? $prefix.'/' : '').$placeholder] = $this->get_links($app, $id, $matches[3][$i], array(), $matches[2][$i]);
436 435
 						break;
437 436
 				}
438 437
 				$link_cache[$id][$placeholder] = $array[$placeholder];
439 438
 			}
440 439
 		}
441 440
 		// Need to set each app, to make sure placeholders are removed
442
-		foreach(array_keys($GLOBALS['egw_info']['user']['apps']) as $_app)
441
+		foreach (array_keys($GLOBALS['egw_info']['user']['apps']) as $_app)
443 442
 		{
444
-			$array[($prefix?$prefix.'/':'')."links/$app"] = $this->get_links($app,$id,$_app);
443
+			$array[($prefix ? $prefix.'/' : '')."links/$app"] = $this->get_links($app, $id, $_app);
445 444
 		}
446 445
 		return $array;
447 446
 	}
@@ -454,12 +453,12 @@  discard block
 block discarded – undo
454 453
 	 * @deprecated use Api\DateTime::to($time='now',$format='')
455 454
 	 * @return string
456 455
 	 */
457
-	protected function format_datetime($time,$format=null)
456
+	protected function format_datetime($time, $format = null)
458 457
 	{
459
-		trigger_error(__METHOD__ . ' is deprecated, use Api\DateTime::to($time, $format)', E_USER_DEPRECATED);
458
+		trigger_error(__METHOD__.' is deprecated, use Api\DateTime::to($time, $format)', E_USER_DEPRECATED);
460 459
 		if (is_null($format)) $format = $this->datetime_format;
461 460
 
462
-		return Api\DateTime::to($time,$format);
461
+		return Api\DateTime::to($time, $format);
463 462
 	}
464 463
 
465 464
 	/**
@@ -471,7 +470,7 @@  discard block
 block discarded – undo
471 470
 	 */
472 471
 	public static function is_export_limit_excepted()
473 472
 	{
474
-		static $is_excepted=null;
473
+		static $is_excepted = null;
475 474
 
476 475
 		if (is_null($is_excepted))
477 476
 		{
@@ -481,9 +480,9 @@  discard block
 block discarded – undo
481 480
 			if (!$is_excepted && (is_array($export_limit_excepted = $GLOBALS['egw_info']['server']['export_limit_excepted']) ||
482 481
 				is_array($export_limit_excepted = unserialize($export_limit_excepted))))
483 482
 			{
484
-				$id_and_memberships = $GLOBALS['egw']->accounts->memberships($GLOBALS['egw_info']['user']['account_id'],true);
483
+				$id_and_memberships = $GLOBALS['egw']->accounts->memberships($GLOBALS['egw_info']['user']['account_id'], true);
485 484
 				$id_and_memberships[] = $GLOBALS['egw_info']['user']['account_id'];
486
-				$is_excepted = (bool) array_intersect($id_and_memberships, $export_limit_excepted);
485
+				$is_excepted = (bool)array_intersect($id_and_memberships, $export_limit_excepted);
487 486
 			}
488 487
 		}
489 488
 		return $is_excepted;
@@ -496,18 +495,18 @@  discard block
 block discarded – undo
496 495
 	 * @return mixed - no if no export is allowed, false if there is no restriction and int as there is a valid restriction
497 496
 	 *		you may have to cast the returned value to int, if you want to use it as number
498 497
 	 */
499
-	public static function getExportLimit($app='common')
498
+	public static function getExportLimit($app = 'common')
500 499
 	{
501
-		static $exportLimitStore=array();
502
-		if (empty($app)) $app='common';
500
+		static $exportLimitStore = array();
501
+		if (empty($app)) $app = 'common';
503 502
 		//error_log(__METHOD__.__LINE__.' called with app:'.$app);
504
-		if (!array_key_exists($app,$exportLimitStore))
503
+		if (!array_key_exists($app, $exportLimitStore))
505 504
 		{
506 505
 			//error_log(__METHOD__.__LINE__.' -> '.$app_limit.' '.function_backtrace());
507 506
 			$exportLimitStore[$app] = $GLOBALS['egw_info']['server']['export_limit'];
508
-			if ($app !='common')
507
+			if ($app != 'common')
509 508
 			{
510
-				$app_limit = Api\Hooks::single('export_limit',$app);
509
+				$app_limit = Api\Hooks::single('export_limit', $app);
511 510
 				if ($app_limit) $exportLimitStore[$app] = $app_limit;
512 511
 			}
513 512
 			//error_log(__METHOD__.__LINE__.' building cache for app:'.$app.' -> '.$exportLimitStore[$app]);
@@ -539,9 +538,9 @@  discard block
 block discarded – undo
539 538
 	 *
540 539
 	 * @return bool - true if no export is allowed or a limit is set, false if there is no restriction
541 540
 	 */
542
-	public static function hasExportLimit($app_limit,$checkas='AND')
541
+	public static function hasExportLimit($app_limit, $checkas = 'AND')
543 542
 	{
544
-		if (strtoupper($checkas) == 'ISALLOWED') return (empty($app_limit) || ($app_limit !='no' && $app_limit > 0) );
543
+		if (strtoupper($checkas) == 'ISALLOWED') return (empty($app_limit) || ($app_limit != 'no' && $app_limit > 0));
545 544
 		if (empty($app_limit)) return false;
546 545
 		if ($app_limit == 'no') return true;
547 546
 		if ($app_limit > 0) return true;
@@ -557,28 +556,28 @@  discard block
 block discarded – undo
557 556
 	 * @param array $fix =null regular expression => replacement pairs eg. to fix garbled placeholders
558 557
 	 * @return string|boolean merged document or false on error
559 558
 	 */
560
-	public function &merge($document,$ids,&$err,$mimetype,array $fix=null)
559
+	public function &merge($document, $ids, &$err, $mimetype, array $fix = null)
561 560
 	{
562 561
 		if (!($content = file_get_contents($document)))
563 562
 		{
564
-			$err = lang("Document '%1' does not exist or is not readable for you!",$document);
563
+			$err = lang("Document '%1' does not exist or is not readable for you!", $document);
565 564
 			return false;
566 565
 		}
567 566
 
568 567
 		if (self::hasExportLimit($this->export_limit) && !self::is_export_limit_excepted() && count($ids) > (int)$this->export_limit)
569 568
 		{
570
-			$err = lang('No rights to export more than %1 entries!',(int)$this->export_limit);
569
+			$err = lang('No rights to export more than %1 entries!', (int)$this->export_limit);
571 570
 			return false;
572 571
 		}
573 572
 
574 573
 		// fix application/msword mimetype for rtf files
575
-		if ($mimetype == 'application/msword' && strtolower(substr($document,-4)) == '.rtf')
574
+		if ($mimetype == 'application/msword' && strtolower(substr($document, -4)) == '.rtf')
576 575
 		{
577 576
 			$mimetype = 'application/rtf';
578 577
 		}
579 578
 
580 579
 		try {
581
-			$content = $this->merge_string($content,$ids,$err,$mimetype,$fix);
580
+			$content = $this->merge_string($content, $ids, $err, $mimetype, $fix);
582 581
 		} catch (\Exception $e) {
583 582
 			_egw_log_exception($e);
584 583
 			$err = $e->getMessage();
@@ -587,18 +586,18 @@  discard block
 block discarded – undo
587 586
 		return $content;
588 587
 	}
589 588
 
590
-	protected function apply_styles (&$content, $mimetype, $mso_application_progid=null)
589
+	protected function apply_styles(&$content, $mimetype, $mso_application_progid = null)
591 590
 	{
592 591
 		if (!isset($mso_application_progid))
593 592
 		{
594 593
 			$matches = null;
595 594
 			$mso_application_progid = $mimetype == 'application/xml' &&
596
-				preg_match('/'.preg_quote('<?mso-application progid="').'([^"]+)'.preg_quote('"?>').'/',substr($content,0,200),$matches) ?
595
+				preg_match('/'.preg_quote('<?mso-application progid="').'([^"]+)'.preg_quote('"?>').'/', substr($content, 0, 200), $matches) ?
597 596
 					$matches[1] : '';
598 597
 		}
599 598
 		// Tags we can replace with the target document's version
600 599
 		$replace_tags = array();
601
-		switch($mimetype.$mso_application_progid)
600
+		switch ($mimetype.$mso_application_progid)
602 601
 		{
603 602
 			case 'application/vnd.oasis.opendocument.text':		// open office
604 603
 			case 'application/vnd.oasis.opendocument.spreadsheet':
@@ -608,7 +607,7 @@  discard block
 block discarded – undo
608 607
 					'/<\/(ol|ul|table)>/' => '</$1><text:p>',
609 608
 					//'/<(li)(.*?)>(.*?)<\/\1>/' => '<$1 $2>$3</$1>',
610 609
 				);
611
-				$content = preg_replace(array_keys($replace_tags),array_values($replace_tags),$content);
610
+				$content = preg_replace(array_keys($replace_tags), array_values($replace_tags), $content);
612 611
 
613 612
 				$doc = new DOMDocument();
614 613
 				$xslt = new XSLTProcessor();
@@ -635,7 +634,7 @@  discard block
 block discarded – undo
635 634
 					// Remove spans with no attributes, linebreaks inside them cause problems
636 635
 					'/<span>(.*?)<\/span>/' => '$1'
637 636
 				);
638
-				$content = preg_replace(array_keys($replace_tags),array_values($replace_tags),$content);
637
+				$content = preg_replace(array_keys($replace_tags), array_values($replace_tags), $content);
639 638
 
640 639
 				/*
641 640
 				In the case where you have something like <span><span></w:t><w:br/><w:t></span></span> (invalid - mismatched tags),
@@ -645,9 +644,9 @@  discard block
 block discarded – undo
645 644
 				$count = $i = 0;
646 645
 				do
647 646
 				{
648
-					$content = preg_replace('/<span>(.*?)<\/span>/','$1',$content, -1, $count);
647
+					$content = preg_replace('/<span>(.*?)<\/span>/', '$1', $content, -1, $count);
649 648
 					$i++;
650
-				} while($count > 0 && $i < 10);
649
+				} while ($count > 0 && $i < 10);
651 650
 
652 651
 				$doc = new DOMDocument();
653 652
 				$xslt = new XSLTProcessor();
@@ -658,20 +657,20 @@  discard block
 block discarded – undo
658 657
 		}
659 658
 
660 659
 		// XSLT transform known tags
661
-		if($xslt)
660
+		if ($xslt)
662 661
 		{
663 662
 			// does NOT work with php 5.2.6: Catchable fatal error: argument 1 to transformToXml() must be of type DOMDocument
664 663
 			//$element = new SimpleXMLelement($content);
665 664
 			$element = new DOMDocument('1.0', 'utf-8');
666 665
 			$result = $element->loadXML($content);
667
-			if(!$result)
666
+			if (!$result)
668 667
 			{
669 668
 				throw new Api\Exception('Unable to parse merged document for styles.  Check warnings in log for details.');
670 669
 			}
671 670
 			$content = $xslt->transformToXml($element);
672 671
 
673 672
 			// Word 2003 needs two declarations, add extra declaration back in
674
-			if($mimetype == 'application/xml' && $mso_application_progid == 'Word.Document' && strpos($content, '<?xml') !== 0) {
673
+			if ($mimetype == 'application/xml' && $mso_application_progid == 'Word.Document' && strpos($content, '<?xml') !== 0) {
675 674
 				$content = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'.$content;
676 675
 			}
677 676
 			// Validate
@@ -694,11 +693,11 @@  discard block
 block discarded – undo
694 693
 	 * @param string $charset =null charset to override default set by mimetype or export charset
695 694
 	 * @return string|boolean merged document or false on error
696 695
 	 */
697
-	public function &merge_string($_content,$ids,&$err,$mimetype,array $fix=null,$charset=null)
696
+	public function &merge_string($_content, $ids, &$err, $mimetype, array $fix = null, $charset = null)
698 697
 	{
699 698
 		$matches = null;
700 699
 		if ($mimetype == 'application/xml' &&
701
-			preg_match('/'.preg_quote('<?mso-application progid="').'([^"]+)'.preg_quote('"?>').'/',substr($_content,0,200),$matches))
700
+			preg_match('/'.preg_quote('<?mso-application progid="').'([^"]+)'.preg_quote('"?>').'/', substr($_content, 0, 200), $matches))
702 701
 		{
703 702
 			$mso_application_progid = $matches[1];
704 703
 		}
@@ -708,12 +707,12 @@  discard block
 block discarded – undo
708 707
 		}
709 708
 		// alternative syntax using double curly brackets (eg. {{cat_id}} instead $$cat_id$$),
710 709
 		// agressivly removing all xml-tags eg. Word adds within placeholders
711
-		$content = preg_replace_callback('/{{[^}]+}}/i',create_function('$p','return \'$$\'.strip_tags(substr($p[0],2,-2)).\'$$\';'),$_content);
710
+		$content = preg_replace_callback('/{{[^}]+}}/i', create_function('$p', 'return \'$$\'.strip_tags(substr($p[0],2,-2)).\'$$\';'), $_content);
712 711
 
713 712
 		// Handle escaped placeholder markers in RTF, they won't match when escaped
714
-		if($mimetype == 'application/rtf')
713
+		if ($mimetype == 'application/rtf')
715 714
 		{
716
-			$content = preg_replace('/\\\{\\\{([^\\}]+)\\\}\\\}/i','$$\1$$',$content);
715
+			$content = preg_replace('/\\\{\\\{([^\\}]+)\\\}\\\}/i', '$$\1$$', $content);
717 716
 		}
718 717
 
719 718
 		// make currently processed mimetype available to class methods;
@@ -722,16 +721,16 @@  discard block
 block discarded – undo
722 721
 		// fix garbled placeholders
723 722
 		if ($fix && is_array($fix))
724 723
 		{
725
-			$content = preg_replace(array_keys($fix),array_values($fix),$content);
724
+			$content = preg_replace(array_keys($fix), array_values($fix), $content);
726 725
 			//die("<pre>".htmlspecialchars($content)."</pre>\n");
727 726
 		}
728
-		list($contentstart,$contentrepeat,$contentend) = preg_split('/\$\$pagerepeat\$\$/',$content,-1, PREG_SPLIT_NO_EMPTY);  //get differt parts of document, seperatet by Pagerepeat
727
+		list($contentstart, $contentrepeat, $contentend) = preg_split('/\$\$pagerepeat\$\$/', $content, -1, PREG_SPLIT_NO_EMPTY); //get differt parts of document, seperatet by Pagerepeat
729 728
 		if ($mimetype == 'text/plain' && count($ids) > 1)
730 729
 		{
731 730
 			// textdocuments are simple, they do not hold start and end, but they may have content before and after the $$pagerepeat$$ tag
732 731
 			// header and footer should not hold any $$ tags; if we find $$ tags with the header, we assume it is the pagerepeatcontent
733 732
 			$nohead = false;
734
-			if (stripos($contentstart,'$$') !== false) $nohead = true;
733
+			if (stripos($contentstart, '$$') !== false) $nohead = true;
735 734
 			if ($nohead)
736 735
 			{
737 736
 				$contentend = $contentrepeat;
@@ -742,14 +741,14 @@  discard block
 block discarded – undo
742 741
 		}
743 742
 		if ($mimetype == 'application/vnd.oasis.opendocument.text' && count($ids) > 1)
744 743
 		{
745
-			if(strpos($content, '$$pagerepeat') === false)
744
+			if (strpos($content, '$$pagerepeat') === false)
746 745
 			{
747 746
 				//for odt files we have to split the content and add a style for page break to  the style area
748
-				list($contentstart,$contentrepeat,$contentend) = preg_split('/office:body>/',$content,-1, PREG_SPLIT_NO_EMPTY);  //get differt parts of document, seperatet by Pagerepeat
749
-				$contentstart = substr($contentstart,0,strlen($contentstart)-1);  //remove "<"
750
-				$contentrepeat = substr($contentrepeat,0,strlen($contentrepeat)-2);  //remove "</";
747
+				list($contentstart, $contentrepeat, $contentend) = preg_split('/office:body>/', $content, -1, PREG_SPLIT_NO_EMPTY); //get differt parts of document, seperatet by Pagerepeat
748
+				$contentstart = substr($contentstart, 0, strlen($contentstart) - 1); //remove "<"
749
+				$contentrepeat = substr($contentrepeat, 0, strlen($contentrepeat) - 2); //remove "</";
751 750
 				// need to add page-break style to the style list
752
-				list($stylestart,$stylerepeat,$styleend) = preg_split('/<\/office:automatic-styles>/',$content,-1, PREG_SPLIT_NO_EMPTY);  //get differt parts of document style sheets
751
+				list($stylestart, $stylerepeat, $styleend) = preg_split('/<\/office:automatic-styles>/', $content, -1, PREG_SPLIT_NO_EMPTY); //get differt parts of document style sheets
753 752
 				$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>';
754 753
 				$contentstart .= '<office:body>';
755 754
 				$contentend = '</office:body></office:document-content>';
@@ -757,22 +756,22 @@  discard block
 block discarded – undo
757 756
 			else
758 757
 			{
759 758
 				// Template specifies where to repeat
760
-				list($contentstart,$contentrepeat,$contentend) = preg_split('/\$\$pagerepeat\$\$/',$content,-1, PREG_SPLIT_NO_EMPTY);  //get different parts of document, seperated by pagerepeat
759
+				list($contentstart, $contentrepeat, $contentend) = preg_split('/\$\$pagerepeat\$\$/', $content, -1, PREG_SPLIT_NO_EMPTY); //get different parts of document, seperated by pagerepeat
761 760
 			}
762 761
 		}
763 762
 		if (in_array($mimetype, array('application/vnd.ms-word.document.macroenabled.12', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document')) && count($ids) > 1)
764 763
 		{
765 764
 			//for Word 2007 XML files we have to split the content and add a style for page break to  the style area
766
-			list($contentstart,$contentrepeat,$contentend) = preg_split('/w:body>/',$content,-1, PREG_SPLIT_NO_EMPTY);  //get differt parts of document, seperatet by Pagerepeat
767
-			$contentstart = substr($contentstart,0,strlen($contentstart)-1);  //remove "</"
768
-			$contentrepeat = substr($contentrepeat,0,strlen($contentrepeat)-2);  //remove "</";
765
+			list($contentstart, $contentrepeat, $contentend) = preg_split('/w:body>/', $content, -1, PREG_SPLIT_NO_EMPTY); //get differt parts of document, seperatet by Pagerepeat
766
+			$contentstart = substr($contentstart, 0, strlen($contentstart) - 1); //remove "</"
767
+			$contentrepeat = substr($contentrepeat, 0, strlen($contentrepeat) - 2); //remove "</";
769 768
 			$contentstart .= '<w:body>';
770 769
 			$contentend = '</w:body></w:document>';
771 770
 		}
772
-		list($Labelstart,$Labelrepeat,$Labeltend) = preg_split('/\$\$label\$\$/',$contentrepeat,-1, PREG_SPLIT_NO_EMPTY);  //get the Lable content
773
-		preg_match_all('/\$\$labelplacement\$\$/',$contentrepeat,$countlables, PREG_SPLIT_NO_EMPTY);
771
+		list($Labelstart, $Labelrepeat, $Labeltend) = preg_split('/\$\$label\$\$/', $contentrepeat, -1, PREG_SPLIT_NO_EMPTY); //get the Lable content
772
+		preg_match_all('/\$\$labelplacement\$\$/', $contentrepeat, $countlables, PREG_SPLIT_NO_EMPTY);
774 773
 		$countlables = count($countlables[0]);
775
-		preg_replace('/\$\$labelplacement\$\$/','',$Labelrepeat,1);
774
+		preg_replace('/\$\$labelplacement\$\$/', '', $Labelrepeat, 1);
776 775
 		if ($countlables > 1) $lableprint = true;
777 776
 		if (count($ids) > 1 && !$contentrepeat)
778 777
 		{
@@ -783,10 +782,10 @@  discard block
 block discarded – undo
783 782
 
784 783
 		if ($contentrepeat)
785 784
 		{
786
-			$content_stream = fopen('php://temp','r+');
785
+			$content_stream = fopen('php://temp', 'r+');
787 786
 			fwrite($content_stream, $contentstart);
788 787
 			$joiner = '';
789
-			switch($mimetype)
788
+			switch ($mimetype)
790 789
 			{
791 790
 				case 'application/rtf':
792 791
 				case 'text/rtf':
@@ -808,19 +807,19 @@  discard block
 block discarded – undo
808 807
 					$joiner = "\r\n";
809 808
 					break;
810 809
 				default:
811
-					$err = lang('%1 not implemented for %2!','$$pagerepeat$$',$mimetype);
810
+					$err = lang('%1 not implemented for %2!', '$$pagerepeat$$', $mimetype);
812 811
 					return false;
813 812
 			}
814 813
 		}
815 814
 		foreach ((array)$ids as $n => $id)
816 815
 		{
817
-			if ($contentrepeat) $content = $contentrepeat;   //content to repeat
816
+			if ($contentrepeat) $content = $contentrepeat; //content to repeat
818 817
 			if ($lableprint) $content = $Labelrepeat;
819 818
 
820 819
 			// generate replacements; if exeption is thrown, catch it set error message and return false
821 820
 			try
822 821
 			{
823
-				if(!($replacements = $this->get_replacements($id,$content)))
822
+				if (!($replacements = $this->get_replacements($id, $content)))
824 823
 				{
825 824
 					$err = lang('Entry not found!');
826 825
 					return false;
@@ -834,88 +833,88 @@  discard block
 block discarded – undo
834 833
 			}
835 834
 			if ($this->report_memory_usage) error_log(__METHOD__."() $n: $id ".Api\Vfs::hsize(memory_get_usage(true)));
836 835
 			// some general replacements: current user, date and time
837
-			if (strpos($content,'$$user/') !== null && ($user = $GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'],'person_id')))
836
+			if (strpos($content, '$$user/') !== null && ($user = $GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'], 'person_id')))
838 837
 			{
839
-				$replacements += $this->contact_replacements($user,'user');
840
-				$replacements['$$user/primary_group$$'] = $GLOBALS['egw']->accounts->id2name($GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'],'account_primary_group'));
838
+				$replacements += $this->contact_replacements($user, 'user');
839
+				$replacements['$$user/primary_group$$'] = $GLOBALS['egw']->accounts->id2name($GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'], 'account_primary_group'));
841 840
 			}
842
-			$replacements['$$date$$'] = Api\DateTime::to('now',true);
841
+			$replacements['$$date$$'] = Api\DateTime::to('now', true);
843 842
 			$replacements['$$datetime$$'] = Api\DateTime::to('now');
844
-			$replacements['$$time$$'] = Api\DateTime::to('now',false);
843
+			$replacements['$$time$$'] = Api\DateTime::to('now', false);
845 844
 
846 845
 			// does our extending class registered table-plugins AND document contains table tags
847
-			if ($this->table_plugins && preg_match_all('/\\$\\$table\\/([A-Za-z0-9_]+)\\$\\$(.*?)\\$\\$endtable\\$\\$/s',$content,$matches,PREG_SET_ORDER))
846
+			if ($this->table_plugins && preg_match_all('/\\$\\$table\\/([A-Za-z0-9_]+)\\$\\$(.*?)\\$\\$endtable\\$\\$/s', $content, $matches, PREG_SET_ORDER))
848 847
 			{
849 848
 				// process each table
850
-				foreach($matches as $match)
849
+				foreach ($matches as $match)
851 850
 				{
852
-					$plugin   = $match[1];	// plugin name
851
+					$plugin   = $match[1]; // plugin name
853 852
 					$callback = $this->table_plugins[$plugin];
854
-					$repeat   = $match[2];	// line to repeat
853
+					$repeat   = $match[2]; // line to repeat
855 854
 					$repeats = '';
856 855
 					if (isset($callback))
857 856
 					{
858
-						for($n = 0; ($row_replacements = $this->$callback($plugin,$id,$n,$repeat)); ++$n)
857
+						for ($n = 0; ($row_replacements = $this->$callback($plugin, $id, $n, $repeat)); ++$n)
859 858
 						{
860 859
 							$_repeat = $this->process_commands($repeat, $row_replacements);
861
-							$repeats .= $this->replace($_repeat,$row_replacements,$mimetype,$mso_application_progid);
860
+							$repeats .= $this->replace($_repeat, $row_replacements, $mimetype, $mso_application_progid);
862 861
 						}
863 862
 					}
864
-					$content = str_replace($match[0],$repeats,$content);
863
+					$content = str_replace($match[0], $repeats, $content);
865 864
 				}
866 865
 			}
867
-			$content = $this->process_commands($this->replace($content,$replacements,$mimetype,$mso_application_progid,$charset), $replacements);
866
+			$content = $this->process_commands($this->replace($content, $replacements, $mimetype, $mso_application_progid, $charset), $replacements);
868 867
 
869 868
 			// remove not existing replacements (eg. from calendar array)
870
-			if (strpos($content,'$$') !== null)
869
+			if (strpos($content, '$$') !== null)
871 870
 			{
872
-				$content = preg_replace('/\$\$[a-z0-9_\/]+\$\$/i','',$content);
871
+				$content = preg_replace('/\$\$[a-z0-9_\/]+\$\$/i', '', $content);
873 872
 			}
874 873
 			if ($contentrepeat)
875 874
 			{
876
-				fwrite($content_stream, ($n == 0 ? '' : $joiner) . $content);
875
+				fwrite($content_stream, ($n == 0 ? '' : $joiner).$content);
877 876
 			}
878
-			if($lableprint)
877
+			if ($lableprint)
879 878
 			{
880
-				$contentrep[is_array($id) ? implode(':',$id) : $id] = $content;
879
+				$contentrep[is_array($id) ? implode(':', $id) : $id] = $content;
881 880
 			}
882 881
 		}
883 882
 		if ($Labelrepeat)
884 883
 		{
885
-			$countpage=0;
886
-			$count=0;
884
+			$countpage = 0;
885
+			$count = 0;
887 886
 			$contentrepeatpages[$countpage] = $Labelstart.$Labeltend;
888 887
 
889 888
 			foreach ($contentrep as $Label)
890 889
 			{
891
-				$contentrepeatpages[$countpage] = preg_replace('/\$\$labelplacement\$\$/',$Label,$contentrepeatpages[$countpage],1);
892
-				$count=$count+1;
893
-				if (($count % $countlables) == 0 && count($contentrep)>$count)  //new page
890
+				$contentrepeatpages[$countpage] = preg_replace('/\$\$labelplacement\$\$/', $Label, $contentrepeatpages[$countpage], 1);
891
+				$count = $count + 1;
892
+				if (($count % $countlables) == 0 && count($contentrep) > $count)  //new page
894 893
 				{
895
-					$countpage = $countpage+1;
894
+					$countpage = $countpage + 1;
896 895
 					$contentrepeatpages[$countpage] = $Labelstart.$Labeltend;
897 896
 				}
898 897
 			}
899
-			$contentrepeatpages[$countpage] = preg_replace('/\$\$labelplacement\$\$/','',$contentrepeatpages[$countpage],-1);  //clean empty fields
898
+			$contentrepeatpages[$countpage] = preg_replace('/\$\$labelplacement\$\$/', '', $contentrepeatpages[$countpage], -1); //clean empty fields
900 899
 
901
-			switch($mimetype)
900
+			switch ($mimetype)
902 901
 			{
903 902
 				case 'application/rtf':
904 903
 				case 'text/rtf':
905
-					return $contentstart.implode('\\par \\page\\pard\\plain',$contentrepeatpages).$contentend;
904
+					return $contentstart.implode('\\par \\page\\pard\\plain', $contentrepeatpages).$contentend;
906 905
 				case 'application/vnd.oasis.opendocument.text':
907
-					return $contentstart.implode('<text:line-break />',$contentrepeatpages).$contentend;
906
+					return $contentstart.implode('<text:line-break />', $contentrepeatpages).$contentend;
908 907
 				case 'application/vnd.oasis.opendocument.spreadsheet':
909
-					return $contentstart.implode('</text:p><text:p>',$contentrepeatpages).$contentend;
908
+					return $contentstart.implode('</text:p><text:p>', $contentrepeatpages).$contentend;
910 909
 				case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
911 910
 				case 'application/vnd.ms-word.document.macroenabled.12':
912 911
 				case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
913 912
 				case 'application/vnd.ms-excel.sheet.macroenabled.12':
914
-					return $contentstart.implode('<w:br w:type="page" />',$contentrepeatpages).$contentend;
913
+					return $contentstart.implode('<w:br w:type="page" />', $contentrepeatpages).$contentend;
915 914
 				case 'text/plain':
916
-					return $contentstart.implode("\r\n",$contentrep).$contentend;
915
+					return $contentstart.implode("\r\n", $contentrep).$contentend;
917 916
 			}
918
-			$err = lang('%1 not implemented for %2!','$$labelplacement$$',$mimetype);
917
+			$err = lang('%1 not implemented for %2!', '$$labelplacement$$', $mimetype);
919 918
 			return false;
920 919
 		}
921 920
 
@@ -940,9 +939,9 @@  discard block
 block discarded – undo
940 939
 	 * @param string $charset =null charset to override default set by mimetype or export charset
941 940
 	 * @return string
942 941
 	 */
943
-	protected function replace($content,array $replacements,$mimetype,$mso_application_progid='',$charset=null)
942
+	protected function replace($content, array $replacements, $mimetype, $mso_application_progid = '', $charset = null)
944 943
 	{
945
-		switch($mimetype)
944
+		switch ($mimetype)
946 945
 		{
947 946
 			case 'application/vnd.oasis.opendocument.text':		// open office
948 947
 			case 'application/vnd.oasis.opendocument.spreadsheet':
@@ -953,13 +952,13 @@  discard block
 block discarded – undo
953 952
 			case 'application/xml':
954 953
 			case 'text/xml':
955 954
 				$is_xml = true;
956
-				$charset = 'utf-8';	// xml files --> always use utf-8
955
+				$charset = 'utf-8'; // xml files --> always use utf-8
957 956
 				break;
958 957
 
959 958
 			case 'text/html':
960 959
 				$is_xml = true;
961 960
 				$matches = null;
962
-				if (preg_match('/<meta http-equiv="content-type".*charset=([^;"]+)/i',$content,$matches))
961
+				if (preg_match('/<meta http-equiv="content-type".*charset=([^;"]+)/i', $content, $matches))
963 962
 				{
964 963
 					$charset = $matches[1];
965 964
 				}
@@ -978,18 +977,18 @@  discard block
 block discarded – undo
978 977
 		// do we need to convert charset
979 978
 		if ($charset && $charset != Api\Translation::charset())
980 979
 		{
981
-			$replacements = Api\Translation::convert($replacements,Api\Translation::charset(),$charset);
980
+			$replacements = Api\Translation::convert($replacements, Api\Translation::charset(), $charset);
982 981
 		}
983 982
 
984 983
 		// Date only placeholders for timestamps
985
-		if(is_array($this->date_fields))
984
+		if (is_array($this->date_fields))
986 985
 		{
987
-			foreach($this->date_fields as $field)
986
+			foreach ($this->date_fields as $field)
988 987
 			{
989
-				if(($value = $replacements['$$'.$field.'$$']))
988
+				if (($value = $replacements['$$'.$field.'$$']))
990 989
 				{
991 990
 					$time = Api\DateTime::createFromFormat('+'.Api\DateTime::$user_dateformat.' '.Api\DateTime::$user_timeformat.'*', $value);
992
-					$replacements['$$'.$field.'/date$$'] = $time ? $time->format(Api\DateTime::$user_dateformat)  : '';
991
+					$replacements['$$'.$field.'/date$$'] = $time ? $time->format(Api\DateTime::$user_dateformat) : '';
993 992
 				}
994 993
 			}
995 994
 		}
@@ -1003,19 +1002,19 @@  discard block
 block discarded – undo
1003 1002
 			// only keep tags, if we have xsl extension available
1004 1003
 			if (class_exists(XSLTProcessor) && class_exists(DOMDocument) && $this->parse_html_styles)
1005 1004
 			{
1006
-				switch($mimetype.$mso_application_progid)
1005
+				switch ($mimetype.$mso_application_progid)
1007 1006
 				{
1008 1007
 					case 'text/html':
1009 1008
 						$replace_tags = array(
1010
-							'<b>','<strong>','<i>','<em>','<u>','<span>','<ol>','<ul>','<li>',
1011
-							'<table>','<tr>','<td>','<a>','<style>',
1009
+							'<b>', '<strong>', '<i>', '<em>', '<u>', '<span>', '<ol>', '<ul>', '<li>',
1010
+							'<table>', '<tr>', '<td>', '<a>', '<style>',
1012 1011
 						);
1013 1012
 						break;
1014 1013
 					case 'application/vnd.oasis.opendocument.text':		// open office
1015 1014
 					case 'application/vnd.oasis.opendocument.spreadsheet':
1016 1015
 						$replace_tags = array(
1017
-							'<b>','<strong>','<i>','<em>','<u>','<span>','<ol>','<ul>','<li>',
1018
-							'<table>','<tr>','<td>','<a>',
1016
+							'<b>', '<strong>', '<i>', '<em>', '<u>', '<span>', '<ol>', '<ul>', '<li>',
1017
+							'<table>', '<tr>', '<td>', '<a>',
1019 1018
 						);
1020 1019
 						break;
1021 1020
 					case 'application/xmlWord.Document':	// Word 2003*/
@@ -1024,48 +1023,48 @@  discard block
 block discarded – undo
1024 1023
 					case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
1025 1024
 					case 'application/vnd.ms-excel.sheet.macroenabled.12':
1026 1025
 						$replace_tags = array(
1027
-							'<b>','<strong>','<i>','<em>','<u>','<span>','<ol>','<ul>','<li>',
1028
-							'<table>','<tr>','<td>',
1026
+							'<b>', '<strong>', '<i>', '<em>', '<u>', '<span>', '<ol>', '<ul>', '<li>',
1027
+							'<table>', '<tr>', '<td>',
1029 1028
 						);
1030 1029
 						break;
1031 1030
 				}
1032 1031
 			}
1033 1032
 			// clean replacements from array values and html or html-entities, which mess up xml
1034
-			foreach($replacements as $name => &$value)
1033
+			foreach ($replacements as $name => &$value)
1035 1034
 			{
1036 1035
 				// set unresolved array values to empty string
1037
-				if(is_array($value))
1036
+				if (is_array($value))
1038 1037
 				{
1039 1038
 					$value = '';
1040 1039
 					continue;
1041 1040
 				}
1042 1041
 				// decode html entities back to utf-8
1043 1042
 
1044
-				if (is_string($value) && (strpos($value,'&') !== false) && $this->parse_html_styles)
1043
+				if (is_string($value) && (strpos($value, '&') !== false) && $this->parse_html_styles)
1045 1044
 				{
1046
-					$value = html_entity_decode($value,ENT_QUOTES,$charset);
1045
+					$value = html_entity_decode($value, ENT_QUOTES, $charset);
1047 1046
 
1048 1047
 					// remove all non-decodable entities
1049
-					if (strpos($value,'&') !== false)
1048
+					if (strpos($value, '&') !== false)
1050 1049
 					{
1051
-						$value = preg_replace('/&[^; ]+;/','',$value);
1050
+						$value = preg_replace('/&[^; ]+;/', '', $value);
1052 1051
 					}
1053 1052
 				}
1054
-				if(!$this->parse_html_styles || (
1055
-					strpos($value, "\n") !== FALSE && strpos($value,'<br') === FALSE && strpos($value, '<span') === FALSE && strpos($value, '<p') === FALSE
1053
+				if (!$this->parse_html_styles || (
1054
+					strpos($value, "\n") !== FALSE && strpos($value, '<br') === FALSE && strpos($value, '<span') === FALSE && strpos($value, '<p') === FALSE
1056 1055
 				))
1057 1056
 				{
1058 1057
 					// Encode special chars so they don't break the file
1059
-					$value = htmlspecialchars($value,ENT_NOQUOTES);
1058
+					$value = htmlspecialchars($value, ENT_NOQUOTES);
1060 1059
 				}
1061
-				else if (is_string($value) && (strpos($value,'<') !== false))
1060
+				else if (is_string($value) && (strpos($value, '<') !== false))
1062 1061
 				{
1063 1062
 					// Clean HTML, if it's being kept
1064
-					if($replace_tags && extension_loaded('tidy')) {
1063
+					if ($replace_tags && extension_loaded('tidy')) {
1065 1064
 						$tidy = new tidy();
1066 1065
 						$cleaned = $tidy->repairString($value, self::$tidy_config);
1067 1066
 						// Found errors. Strip it all so there's some output
1068
-						if($tidy->getStatus() == 2)
1067
+						if ($tidy->getStatus() == 2)
1069 1068
 						{
1070 1069
 							error_log($tidy->errorBuffer);
1071 1070
 							$value = strip_tags($value);
@@ -1076,52 +1075,52 @@  discard block
 block discarded – undo
1076 1075
 						}
1077 1076
 					}
1078 1077
 					// replace </p> and <br /> with CRLF (remove <p> and CRLF)
1079
-					$value = strip_tags(str_replace(array("\r","\n",'<p>','</p>','<div>','</div>','<br />'),
1080
-						array('','','',"\r\n",'',"\r\n","\r\n"), $value),
1078
+					$value = strip_tags(str_replace(array("\r", "\n", '<p>', '</p>', '<div>', '</div>', '<br />'),
1079
+						array('', '', '', "\r\n", '', "\r\n", "\r\n"), $value),
1081 1080
 						implode('', $replace_tags));
1082 1081
 
1083 1082
 					// Change <tag>...\r\n</tag> to <tag>...</tag>\r\n or simplistic line break below will mangle it
1084 1083
 					// Loop to catch things like <b><span>Break:\r\n</span></b>
1085
-					if($mso_application_progid)
1084
+					if ($mso_application_progid)
1086 1085
 					{
1087 1086
 						$count = $i = 0;
1088 1087
 						do
1089 1088
 						{
1090
-							$value = preg_replace('/<(b|strong|i|em|u|span)\b([^>]*?)>(.*?)'."\r\n".'<\/\1>/u', '<$1$2>$3</$1>'."\r\n",$value,-1,$count);
1089
+							$value = preg_replace('/<(b|strong|i|em|u|span)\b([^>]*?)>(.*?)'."\r\n".'<\/\1>/u', '<$1$2>$3</$1>'."\r\n", $value, -1, $count);
1091 1090
 							$i++;
1092
-						} while($count > 0 && $i < 10); // Limit of 10 chosen arbitrarily just in case
1091
+						} while ($count > 0 && $i < 10); // Limit of 10 chosen arbitrarily just in case
1093 1092
 					}
1094 1093
 				}
1095 1094
 				// replace all control chars (C0+C1) but CR (\015), LF (\012) and TAB (\011) (eg. vertical tabulators) with space
1096 1095
 				// as they are not allowed in xml
1097
-				$value = preg_replace('/[\000-\010\013\014\016-\037\177-\237]/u',' ',$value);
1098
-				if(is_numeric($value) && $name != '$$user/account_id$$') // account_id causes problems with the preg_replace below
1096
+				$value = preg_replace('/[\000-\010\013\014\016-\037\177-\237]/u', ' ', $value);
1097
+				if (is_numeric($value) && $name != '$$user/account_id$$') // account_id causes problems with the preg_replace below
1099 1098
 				{
1100
-					$names[] = preg_quote($name,'/');
1099
+					$names[] = preg_quote($name, '/');
1101 1100
 				}
1102 1101
 			}
1103 1102
 
1104 1103
 			// Look for numbers, set their value if needed
1105
-			if($this->numeric_fields || count($names))
1104
+			if ($this->numeric_fields || count($names))
1106 1105
 			{
1107
-				foreach((array)$this->numeric_fields as $fieldname) {
1108
-					$names[] = preg_quote($fieldname,'/');
1106
+				foreach ((array)$this->numeric_fields as $fieldname) {
1107
+					$names[] = preg_quote($fieldname, '/');
1109 1108
 				}
1110 1109
 				$this->format_spreadsheet_numbers($content, $names, $mimetype.$mso_application_progid);
1111 1110
 			}
1112 1111
 
1113 1112
 			// Look for dates, set their value if needed
1114
-			if($this->date_fields || count($names))
1113
+			if ($this->date_fields || count($names))
1115 1114
 			{
1116 1115
 				$names = array();
1117
-				foreach((array)$this->date_fields as $fieldname) {
1116
+				foreach ((array)$this->date_fields as $fieldname) {
1118 1117
 					$names[] = $fieldname;
1119 1118
 				}
1120 1119
 				$this->format_spreadsheet_dates($content, $names, $replacements, $mimetype.$mso_application_progid);
1121 1120
 			}
1122 1121
 
1123 1122
 			// replace CRLF with linebreak tag of given type
1124
-			switch($mimetype.$mso_application_progid)
1123
+			switch ($mimetype.$mso_application_progid)
1125 1124
 			{
1126 1125
 				case 'application/vnd.oasis.opendocument.text':		// open office writer
1127 1126
 					$break = '<text:line-break/>';
@@ -1150,14 +1149,14 @@  discard block
 block discarded – undo
1150 1149
 			}
1151 1150
 			// now decode &, < and >, which need to be encoded as entities in xml
1152 1151
 			// Check for encoded >< getting double-encoded
1153
-			if($this->parse_html_styles)
1152
+			if ($this->parse_html_styles)
1154 1153
 			{
1155
-				$replacements = str_replace(array('&',"\r","\n",'&amp;lt;','&amp;gt;'),array('&amp;','',$break,'&lt;','&gt;'),$replacements);
1154
+				$replacements = str_replace(array('&', "\r", "\n", '&amp;lt;', '&amp;gt;'), array('&amp;', '', $break, '&lt;', '&gt;'), $replacements);
1156 1155
 			}
1157 1156
 			else
1158 1157
 			{
1159 1158
 				// Need to at least handle new lines, or it'll be run together on one line
1160
-				$replacements = str_replace(array("\r","\n"),array('',$break),$replacements);
1159
+				$replacements = str_replace(array("\r", "\n"), array('', $break), $replacements);
1161 1160
 			}
1162 1161
 		}
1163 1162
 		if ($mimetype == 'application/x-yaml')
@@ -1168,24 +1167,24 @@  discard block
 block discarded – undo
1168 1167
 				$parts = null;
1169 1168
 				if (preg_match('|^\$\$([^/]+)/([^/]+)/([^$]*)\$\$$|', $matches[3], $parts) && isset($replacements['$$'.$parts[1].'$$']))
1170 1169
 				{
1171
-					$replacement =& $replacements['$$'.$parts[1].'$$'];
1170
+					$replacement = & $replacements['$$'.$parts[1].'$$'];
1172 1171
 					$replacement = preg_replace('/'.$parts[2].'/', strtr($parts[3], array(
1173 1172
 						'\\n' => "\n", '\\r' => "\r", '\\t' => "\t", '\\v' => "\v", '\\\\' => '\\', '\\f' => "\f",
1174 1173
 					)), $replacement);
1175 1174
 				}
1176 1175
 				else
1177 1176
 				{
1178
-					$replacement =& $replacements[$matches[3]];
1177
+					$replacement = & $replacements[$matches[3]];
1179 1178
 				}
1180 1179
 				// replacement with multiple lines --> add same number of space as before placeholder
1181 1180
 				if (isset($replacement))
1182 1181
 				{
1183 1182
 					return $matches[1].$matches[2].implode("\n".$matches[1], preg_split("/\r?\n/", $replacement));
1184 1183
 				}
1185
-				return $matches[0];	// regular replacement below
1184
+				return $matches[0]; // regular replacement below
1186 1185
 			}, $content);
1187 1186
 		}
1188
-		return str_replace(array_keys($replacements),array_values($replacements),$content);
1187
+		return str_replace(array_keys($replacements), array_values($replacements), $content);
1189 1188
 	}
1190 1189
 
1191 1190
 	/**
@@ -1193,36 +1192,36 @@  discard block
 block discarded – undo
1193 1192
 	 */
1194 1193
 	protected function format_spreadsheet_numbers(&$content, $names, $mimetype)
1195 1194
 	{
1196
-		foreach((array)$this->numeric_fields as $fieldname) {
1197
-			$names[] = preg_quote($fieldname,'/');
1195
+		foreach ((array)$this->numeric_fields as $fieldname) {
1196
+			$names[] = preg_quote($fieldname, '/');
1198 1197
 		}
1199
-		switch($mimetype)
1198
+		switch ($mimetype)
1200 1199
 		{
1201 1200
 			case 'application/vnd.oasis.opendocument.spreadsheet':		// open office calc
1202
-				$format = '/<table:table-cell([^>]+?)office:value-type="[^"]+"([^>]*?)(?:calcext:value-type="[^"]+")?>.?<([a-z].*?)[^>]*>('.implode('|',$names).')<\/\3>.?<\/table:table-cell>/s';
1201
+				$format = '/<table:table-cell([^>]+?)office:value-type="[^"]+"([^>]*?)(?:calcext:value-type="[^"]+")?>.?<([a-z].*?)[^>]*>('.implode('|', $names).')<\/\3>.?<\/table:table-cell>/s';
1203 1202
 				$replacement = '<table:table-cell$1office:value-type="float" office:value="$4"$2 calcext:value-type="float"><$3>$4</$3></table:table-cell>';
1204 1203
 				break;
1205 1204
 			case 'application/vnd.oasis.opendocument.text':		// tables in open office writer
1206
-				$format = '/<table:table-cell([^>]+?)office:value-type="[^"]+"([^>]*?)>.?<([a-z].*?)[^>]*>('.implode('|',$names).')<\/\3>.?<\/table:table-cell>/s';
1205
+				$format = '/<table:table-cell([^>]+?)office:value-type="[^"]+"([^>]*?)>.?<([a-z].*?)[^>]*>('.implode('|', $names).')<\/\3>.?<\/table:table-cell>/s';
1207 1206
 				$replacement = '<table:table-cell$1office:value-type="float" office:value="$4"$2><text:p text:style-name="Standard">$4</text:p></table:table-cell>';
1208 1207
 				break;
1209 1208
 			case 'application/vnd.oasis.opendocument.text':		// open office writer
1210 1209
 			case 'application/xmlExcel.Sheet':	// Excel 2003
1211
-				$format = '/'.preg_quote('<Data ss:Type="String">','/').'('.implode('|',$names).')'.preg_quote('</Data>','/').'/';
1210
+				$format = '/'.preg_quote('<Data ss:Type="String">', '/').'('.implode('|', $names).')'.preg_quote('</Data>', '/').'/';
1212 1211
 				$replacement = '<Data ss:Type="Number">$1</Data>';
1213 1212
 
1214 1213
 				break;
1215 1214
 		}
1216
-		if($format && $names)
1215
+		if ($format && $names)
1217 1216
 		{
1218 1217
 			// Dealing with backtrack limit per AmigoJack 10-Jul-2010 comment on php.net preg-replace docs
1219 1218
 			do {
1220 1219
 				$result = preg_replace($format, $replacement, $content, -1);
1221 1220
 			}
1222 1221
 			// try to increase/double pcre.backtrack_limit failure
1223
-			while(preg_last_error() == PREG_BACKTRACK_LIMIT_ERROR && self::increase_backtrack_limit());
1222
+			while (preg_last_error() == PREG_BACKTRACK_LIMIT_ERROR && self::increase_backtrack_limit());
1224 1223
 
1225
-			if ($result) $content = $result;  // On failure $result would be NULL
1224
+			if ($result) $content = $result; // On failure $result would be NULL
1226 1225
 		}
1227 1226
 	}
1228 1227
 
@@ -1233,7 +1232,7 @@  discard block
 block discarded – undo
1233 1232
 	 */
1234 1233
 	protected static function increase_backtrack_limit()
1235 1234
 	{
1236
-		static $backtrack_limit=null,$memory_limit=null;
1235
+		static $backtrack_limit = null, $memory_limit = null;
1237 1236
 		if (!isset($backtrack_limit))
1238 1237
 		{
1239 1238
 			$backtrack_limit = ini_get('pcre.backtrack_limit');
@@ -1241,16 +1240,16 @@  discard block
 block discarded – undo
1241 1240
 		if (!isset($memory_limit))
1242 1241
 		{
1243 1242
 			$memory_limit = ini_get('memory_limit');
1244
-			switch(strtoupper(substr($memory_limit, -1)))
1243
+			switch (strtoupper(substr($memory_limit, -1)))
1245 1244
 			{
1246 1245
 				case 'G': $memory_limit *= 1024;
1247 1246
 				case 'M': $memory_limit *= 1024;
1248 1247
 				case 'K': $memory_limit *= 1024;
1249 1248
 			}
1250 1249
 		}
1251
-		if ($backtrack_limit < $memory_limit/8)
1250
+		if ($backtrack_limit < $memory_limit / 8)
1252 1251
 		{
1253
-			ini_set( 'pcre.backtrack_limit', $backtrack_limit*=2);
1252
+			ini_set('pcre.backtrack_limit', $backtrack_limit *= 2);
1254 1253
 			return true;
1255 1254
 		}
1256 1255
 		error_log("pcre.backtrack_limit exceeded @ $backtrack_limit, some cells left as text.");
@@ -1262,41 +1261,41 @@  discard block
 block discarded – undo
1262 1261
 	 */
1263 1262
 	protected function format_spreadsheet_dates(&$content, $names, &$values, $mimetype)
1264 1263
 	{
1265
-		if(!in_array($mimetype, array(
1266
-			'application/vnd.oasis.opendocument.spreadsheet',		// open office calc
1267
-			'application/xmlExcel.Sheet',					// Excel 2003
1264
+		if (!in_array($mimetype, array(
1265
+			'application/vnd.oasis.opendocument.spreadsheet', // open office calc
1266
+			'application/xmlExcel.Sheet', // Excel 2003
1268 1267
 			//'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'//Excel WTF
1269 1268
 		))) return;
1270 1269
 
1271 1270
 		// Some different formats dates could be in, depending what they've been through
1272 1271
 		$formats = array(
1273
-			'!'.Api\DateTime::$user_dateformat . ' ' .Api\DateTime::$user_timeformat.':s',
1274
-			'!'.Api\DateTime::$user_dateformat . '*' .Api\DateTime::$user_timeformat.':s',
1275
-			'!'.Api\DateTime::$user_dateformat . '* ' .Api\DateTime::$user_timeformat,
1276
-			'!'.Api\DateTime::$user_dateformat . '*',
1272
+			'!'.Api\DateTime::$user_dateformat.' '.Api\DateTime::$user_timeformat.':s',
1273
+			'!'.Api\DateTime::$user_dateformat.'*'.Api\DateTime::$user_timeformat.':s',
1274
+			'!'.Api\DateTime::$user_dateformat.'* '.Api\DateTime::$user_timeformat,
1275
+			'!'.Api\DateTime::$user_dateformat.'*',
1277 1276
 			'!'.Api\DateTime::$user_dateformat,
1278 1277
 			'!Y-m-d\TH:i:s'
1279 1278
 		);
1280 1279
 
1281 1280
 		// Properly format values for spreadsheet
1282
-		foreach($names as $idx => &$field)
1281
+		foreach ($names as $idx => &$field)
1283 1282
 		{
1284 1283
 			$key = '$$'.$field.'$$';
1285 1284
 			$field = preg_quote($field, '/');
1286
-			if($values[$key])
1285
+			if ($values[$key])
1287 1286
 			{
1288 1287
 				$date = Api\DateTime::createFromUserFormat($values[$key]);
1289
-				if($mimetype == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ||
1288
+				if ($mimetype == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ||
1290 1289
 					$mimetype == 'application/vnd.ms-excel.sheet.macroenabled.12')//Excel WTF
1291 1290
 				{
1292 1291
 					$interval = $date->diff(new Api\DateTime('1900-01-00 0:00'));
1293
-					$values[$key] = $interval->format('%a')+1;// 1900-02-29 did not exist
1292
+					$values[$key] = $interval->format('%a') + 1; // 1900-02-29 did not exist
1294 1293
 					// 1440 minutes in a day - fractional part
1295
-					$values[$key] += ($date->format('H') * 60 + $date->format('i'))/1440;
1294
+					$values[$key] += ($date->format('H') * 60 + $date->format('i')) / 1440;
1296 1295
 				}
1297 1296
 				else
1298 1297
 				{
1299
-					$values[$key] = date('Y-m-d\TH:i:s',Api\DateTime::to($date,'ts'));
1298
+					$values[$key] = date('Y-m-d\TH:i:s', Api\DateTime::to($date, 'ts'));
1300 1299
 				}
1301 1300
 			}
1302 1301
 			else
@@ -1305,17 +1304,17 @@  discard block
 block discarded – undo
1305 1304
 			}
1306 1305
 		}
1307 1306
 
1308
-		switch($mimetype)
1307
+		switch ($mimetype)
1309 1308
 		{
1310 1309
 			case 'application/vnd.oasis.opendocument.spreadsheet':		// open office calc
1311 1310
 				// Removing these forces calc to respect our set value-type
1312
-				$content = str_ireplace('calcext:value-type="string"','',$content);
1311
+				$content = str_ireplace('calcext:value-type="string"', '', $content);
1313 1312
 
1314
-				$format = '/<table:table-cell([^>]+?)office:value-type="[^"]+"([^>]*?)>.?<([a-z].*?)[^>]*>\$\$('.implode('|',$names).')\$\$<\/\3>.?<\/table:table-cell>/s';
1313
+				$format = '/<table:table-cell([^>]+?)office:value-type="[^"]+"([^>]*?)>.?<([a-z].*?)[^>]*>\$\$('.implode('|', $names).')\$\$<\/\3>.?<\/table:table-cell>/s';
1315 1314
 				$replacement = '<table:table-cell$1office:value-type="date" office:date-value="\$\$$4\$\$"$2><$3>\$\$$4\$\$</$3></table:table-cell>';
1316 1315
 				break;
1317 1316
 			case 'application/xmlExcel.Sheet':	// Excel 2003
1318
-				$format = '/'.preg_quote('<Data ss:Type="String">','/').'..('.implode('|',$names).')..'.preg_quote('</Data>','/').'/';
1317
+				$format = '/'.preg_quote('<Data ss:Type="String">', '/').'..('.implode('|', $names).')..'.preg_quote('</Data>', '/').'/';
1319 1318
 				$replacement = '<Data ss:Type="DateTime">\$\$$1\$\$</Data>';
1320 1319
 
1321 1320
 				break;
@@ -1323,16 +1322,16 @@  discard block
 block discarded – undo
1323 1322
 			case 'application/vnd.ms-excel.sheet.macroenabled.12':
1324 1323
 				break;
1325 1324
 		}
1326
-		if($format && $names)
1325
+		if ($format && $names)
1327 1326
 		{
1328 1327
 			// Dealing with backtrack limit per AmigoJack 10-Jul-2010 comment on php.net preg-replace docs
1329 1328
 			do {
1330 1329
 				$result = preg_replace($format, $replacement, $content, -1);
1331 1330
 			}
1332 1331
 			// try to increase/double pcre.backtrack_limit failure
1333
-			while(preg_last_error() == PREG_BACKTRACK_LIMIT_ERROR && self::increase_backtrack_limit());
1332
+			while (preg_last_error() == PREG_BACKTRACK_LIMIT_ERROR && self::increase_backtrack_limit());
1334 1333
 
1335
-			if ($result) $content = $result;  // On failure $result would be NULL
1334
+			if ($result) $content = $result; // On failure $result would be NULL
1336 1335
 		}
1337 1336
 	}
1338 1337
 
@@ -1342,9 +1341,9 @@  discard block
 block discarded – undo
1342 1341
 	 */
1343 1342
 	public function cf_link_to_expand($values, $content, &$replacements, $app = null)
1344 1343
 	{
1345
-		if($app == null)
1344
+		if ($app == null)
1346 1345
 		{
1347
-			$app = str_replace('_merge','',get_class($this));
1346
+			$app = str_replace('_merge', '', get_class($this));
1348 1347
 		}
1349 1348
 		$cfs = Api\Storage\Customfields::get($app);
1350 1349
 
@@ -1355,25 +1354,25 @@  discard block
 block discarded – undo
1355 1354
 		// Placeholders that need expanded will look like {{#name/placeholder}}
1356 1355
 		$matches = null;
1357 1356
 		preg_match_all('/\${2}(([^\/#]*?\/)?)#([^$\/]+)\/(.*?)[$}]{2}/', $content, $matches);
1358
-		list($placeholders, , , $cf, $sub) = $matches;
1357
+		list($placeholders,,, $cf, $sub) = $matches;
1359 1358
 
1360 1359
 		// Collect any used custom fields from entries so you can do
1361 1360
 		// {{#other_app/#other_app_cf/n_fn}}
1362 1361
 		$expand_sub_cfs = [];
1363
-		foreach($sub as $index => $cf_sub)
1362
+		foreach ($sub as $index => $cf_sub)
1364 1363
 		{
1365
-			if(strpos($cf_sub, '#') === 0)
1364
+			if (strpos($cf_sub, '#') === 0)
1366 1365
 			{
1367
-				$expand_sub_cfs[$cf[$index]] .= '$$'.$cf_sub . '$$ ';
1366
+				$expand_sub_cfs[$cf[$index]] .= '$$'.$cf_sub.'$$ ';
1368 1367
 			}
1369 1368
 		}
1370 1369
 		$expand_sub_cfs = array_unique($expand_sub_cfs);
1371 1370
 
1372
-		foreach($cf as $index => $field)
1371
+		foreach ($cf as $index => $field)
1373 1372
 		{
1374
-			if($cfs[$field])
1373
+			if ($cfs[$field])
1375 1374
 			{
1376
-				if(in_array($cfs[$field]['type'],array_keys($GLOBALS['egw_info']['apps'])))
1375
+				if (in_array($cfs[$field]['type'], array_keys($GLOBALS['egw_info']['apps'])))
1377 1376
 				{
1378 1377
 					$field_app = $cfs[$field]['type'];
1379 1378
 				}
@@ -1384,7 +1383,7 @@  discard block
 block discarded – undo
1384 1383
 					$account = $GLOBALS['egw']->accounts->read($values['#'.$field]);
1385 1384
 					$app_replacements[$field] = $this->contact_replacements($account['person_id']);
1386 1385
 				}
1387
-				else if (($list = explode('-',$cfs[$field]['type']) && in_array($list[0], array_keys($GLOBALS['egw_info']['apps']))))
1386
+				else if (($list = explode('-', $cfs[$field]['type']) && in_array($list[0], array_keys($GLOBALS['egw_info']['apps']))))
1388 1387
 				{
1389 1388
 					// Sub-type - use app
1390 1389
 					$field_app = $list[0];
@@ -1395,7 +1394,7 @@  discard block
 block discarded – undo
1395 1394
 				}
1396 1395
 
1397 1396
 				// Get replacements for that application
1398
-				if(!$app_replacements[$field])
1397
+				if (!$app_replacements[$field])
1399 1398
 				{
1400 1399
 					$app_replacements[$field] = $this->get_app_replacements($field_app, $values['#'.$field], $content);
1401 1400
 				}
@@ -1419,7 +1418,7 @@  discard block
 block discarded – undo
1419 1418
 	protected function get_app_replacements($app, $id, $content, $prefix)
1420 1419
 	{
1421 1420
 		$replacements = array();
1422
-		if($app == 'addressbook')
1421
+		if ($app == 'addressbook')
1423 1422
 		{
1424 1423
 			return $this->contact_replacements($id, $prefix);
1425 1424
 		}
@@ -1429,7 +1428,7 @@  discard block
 block discarded – undo
1429 1428
 			$classname = "{$app}_merge";
1430 1429
 			$class = new $classname();
1431 1430
 			$method = $app.'_replacements';
1432
-			if(method_exists($class,$method))
1431
+			if (method_exists($class, $method))
1433 1432
 			{
1434 1433
 				$replacements = $class->$method($id, $prefix, $content);
1435 1434
 			}
@@ -1456,33 +1455,33 @@  discard block
 block discarded – undo
1456 1455
 	 */
1457 1456
 	private function process_commands($content, $replacements)
1458 1457
 	{
1459
-		if (strpos($content,'$$IF') !== false)
1458
+		if (strpos($content, '$$IF') !== false)
1460 1459
 		{	//Example use to use: $$IF n_prefix~Herr~Sehr geehrter~Sehr geehrte$$
1461
-			$this->replacements =& $replacements;
1462
-			$content = preg_replace_callback('/\$\$IF ([#0-9a-z_\/-]+)~(.*)~(.*)~(.*)\$\$/imU',Array($this,'replace_callback'),$content);
1460
+			$this->replacements = & $replacements;
1461
+			$content = preg_replace_callback('/\$\$IF ([#0-9a-z_\/-]+)~(.*)~(.*)~(.*)\$\$/imU', Array($this, 'replace_callback'), $content);
1463 1462
 			unset($this->replacements);
1464 1463
 		}
1465
-		if (strpos($content,'$$NELF') !== false)
1464
+		if (strpos($content, '$$NELF') !== false)
1466 1465
 		{	//Example: $$NEPBR org_unit$$ sets a LF and value of org_unit, only if there is a value
1467
-			$this->replacements =& $replacements;
1468
-			$content = preg_replace_callback('/\$\$NELF ([#0-9a-z_\/-]+)\$\$/imU',Array($this,'replace_callback'),$content);
1466
+			$this->replacements = & $replacements;
1467
+			$content = preg_replace_callback('/\$\$NELF ([#0-9a-z_\/-]+)\$\$/imU', Array($this, 'replace_callback'), $content);
1469 1468
 			unset($this->replacements);
1470 1469
 		}
1471
-		if (strpos($content,'$$NENVLF') !== false)
1470
+		if (strpos($content, '$$NENVLF') !== false)
1472 1471
 		{	//Example: $$NEPBRNV org_unit$$ sets only a LF if there is a value for org_units, but did not add any value
1473
-			$this->replacements =& $replacements;
1474
-			$content = preg_replace_callback('/\$\$NENVLF ([#0-9a-z_\/-]+)\$\$/imU',Array($this,'replace_callback'),$content);
1472
+			$this->replacements = & $replacements;
1473
+			$content = preg_replace_callback('/\$\$NENVLF ([#0-9a-z_\/-]+)\$\$/imU', Array($this, 'replace_callback'), $content);
1475 1474
 			unset($this->replacements);
1476 1475
 		}
1477
-		if (strpos($content,'$$LETTERPREFIX$$') !== false)
1476
+		if (strpos($content, '$$LETTERPREFIX$$') !== false)
1478 1477
 		{	//Example use to use: $$LETTERPREFIX$$
1479 1478
 			$LETTERPREFIXCUSTOM = '$$LETTERPREFIXCUSTOM n_prefix title n_family$$';
1480
-			$content = str_replace('$$LETTERPREFIX$$',$LETTERPREFIXCUSTOM,$content);
1479
+			$content = str_replace('$$LETTERPREFIX$$', $LETTERPREFIXCUSTOM, $content);
1481 1480
 		}
1482
-		if (strpos($content,'$$LETTERPREFIXCUSTOM') !== false)
1481
+		if (strpos($content, '$$LETTERPREFIXCUSTOM') !== false)
1483 1482
 		{	//Example use to use for a custom Letter Prefix: $$LETTERPREFIX n_prefix title n_family$$
1484
-			$this->replacements =& $replacements;
1485
-			$content = preg_replace_callback('/\$\$LETTERPREFIXCUSTOM ([#0-9a-z_-]+)(.*)\$\$/imU',Array($this,'replace_callback'),$content);
1483
+			$this->replacements = & $replacements;
1484
+			$content = preg_replace_callback('/\$\$LETTERPREFIXCUSTOM ([#0-9a-z_-]+)(.*)\$\$/imU', Array($this, 'replace_callback'), $content);
1486 1485
 			unset($this->replacements);
1487 1486
 		}
1488 1487
 		return $content;
@@ -1496,16 +1495,16 @@  discard block
 block discarded – undo
1496 1495
 	 */
1497 1496
 	private function replace_callback($param)
1498 1497
 	{
1499
-		if (array_key_exists('$$'.$param[4].'$$',$this->replacements)) $param[4] = $this->replacements['$$'.$param[4].'$$'];
1500
-		if (array_key_exists('$$'.$param[3].'$$',$this->replacements)) $param[3] = $this->replacements['$$'.$param[3].'$$'];
1498
+		if (array_key_exists('$$'.$param[4].'$$', $this->replacements)) $param[4] = $this->replacements['$$'.$param[4].'$$'];
1499
+		if (array_key_exists('$$'.$param[3].'$$', $this->replacements)) $param[3] = $this->replacements['$$'.$param[3].'$$'];
1501 1500
 
1502 1501
 		$pattern = '/'.preg_quote($param[2], '/').'/';
1503
-		if (strpos($param[0],'$$IF') === 0 && (trim($param[2]) == "EMPTY" || $param[2] === ''))
1502
+		if (strpos($param[0], '$$IF') === 0 && (trim($param[2]) == "EMPTY" || $param[2] === ''))
1504 1503
 		{
1505 1504
 			$pattern = '/^$/';
1506 1505
 		}
1507
-		$replace = preg_match($pattern,$this->replacements['$$'.$param[1].'$$']) ? $param[3] : $param[4];
1508
-		switch($this->mimetype)
1506
+		$replace = preg_match($pattern, $this->replacements['$$'.$param[1].'$$']) ? $param[3] : $param[4];
1507
+		switch ($this->mimetype)
1509 1508
 		{
1510 1509
 			case 'application/vnd.oasis.opendocument.text':		// open office
1511 1510
 			case 'application/vnd.oasis.opendocument.spreadsheet':
@@ -1520,14 +1519,14 @@  discard block
 block discarded – undo
1520 1519
 				break;
1521 1520
 		}
1522 1521
 
1523
-		switch($this->mimetype)
1522
+		switch ($this->mimetype)
1524 1523
 			{
1525 1524
 				case 'application/rtf':
1526 1525
 				case 'text/rtf':
1527 1526
 					$LF = '}\par \pard\plain{';
1528 1527
 					break;
1529 1528
 				case 'application/vnd.oasis.opendocument.text':
1530
-					$LF ='<text:line-break/>';
1529
+					$LF = '<text:line-break/>';
1531 1530
 					break;
1532 1531
 				case 'application/vnd.oasis.opendocument.spreadsheet':		// open office calc
1533 1532
 					$LF = '</text:p><text:p>';
@@ -1539,10 +1538,10 @@  discard block
 block discarded – undo
1539 1538
 				case 'application/vnd.ms-word.document.macroenabled.12':
1540 1539
 				case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
1541 1540
 				case 'application/vnd.ms-excel.sheet.macroenabled.12':
1542
-					$LF ='</w:t></w:r></w:p><w:p><w:r><w:t>';
1541
+					$LF = '</w:t></w:r></w:p><w:p><w:r><w:t>';
1543 1542
 					break;
1544 1543
 				case 'application/xml';
1545
-					$LF ='</w:t></w:r><w:r><w:br w:type="text-wrapping" w:clear="all"/></w:r><w:r><w:t>';
1544
+					$LF = '</w:t></w:r><w:r><w:br w:type="text-wrapping" w:clear="all"/></w:r><w:r><w:t>';
1546 1545
 					break;
1547 1546
 				case 'text/html':
1548 1547
 					$LF = "<br/>";
@@ -1550,27 +1549,27 @@  discard block
 block discarded – undo
1550 1549
 				default:
1551 1550
 					$LF = "\n";
1552 1551
 			}
1553
-		if($is_xml) {
1554
-			$this->replacements = str_replace(array('&','&amp;amp;','<','>',"\r","\n"),array('&amp;','&amp;','&lt;','&gt;','',$LF),$this->replacements);
1552
+		if ($is_xml) {
1553
+			$this->replacements = str_replace(array('&', '&amp;amp;', '<', '>', "\r", "\n"), array('&amp;', '&amp;', '&lt;', '&gt;', '', $LF), $this->replacements);
1555 1554
 		}
1556
-		if (strpos($param[0],'$$NELF') === 0)
1555
+		if (strpos($param[0], '$$NELF') === 0)
1557 1556
 		{	//sets a Pagebreak and value, only if the field has a value
1558
-			if ($this->replacements['$$'.$param[1].'$$'] !='') $replace = $LF.$this->replacements['$$'.$param[1].'$$'];
1557
+			if ($this->replacements['$$'.$param[1].'$$'] != '') $replace = $LF.$this->replacements['$$'.$param[1].'$$'];
1559 1558
 		}
1560
-		if (strpos($param[0],'$$NENVLF') === 0)
1559
+		if (strpos($param[0], '$$NENVLF') === 0)
1561 1560
 		{	//sets a Pagebreak without any value, only if the field has a value
1562
-			if ($this->replacements['$$'.$param[1].'$$'] !='') $replace = $LF;
1561
+			if ($this->replacements['$$'.$param[1].'$$'] != '') $replace = $LF;
1563 1562
 		}
1564
-		if (strpos($param[0],'$$LETTERPREFIXCUSTOM') === 0)
1563
+		if (strpos($param[0], '$$LETTERPREFIXCUSTOM') === 0)
1565 1564
 		{	//sets a Letterprefix
1566 1565
 			$replaceprefixsort = array();
1567 1566
 			// ToDo Stefan: $contentstart is NOT defined here!!!
1568
-			$replaceprefix = explode(' ',substr($param[0],21,-2));
1567
+			$replaceprefix = explode(' ', substr($param[0], 21, -2));
1569 1568
 			foreach ($replaceprefix as $nameprefix)
1570 1569
 			{
1571
-				if ($this->replacements['$$'.$nameprefix.'$$'] !='') $replaceprefixsort[] = $this->replacements['$$'.$nameprefix.'$$'];
1570
+				if ($this->replacements['$$'.$nameprefix.'$$'] != '') $replaceprefixsort[] = $this->replacements['$$'.$nameprefix.'$$'];
1572 1571
 			}
1573
-			$replace = implode($replaceprefixsort,' ');
1572
+			$replace = implode($replaceprefixsort, ' ');
1574 1573
 		}
1575 1574
 		return $replace;
1576 1575
 	}
@@ -1584,7 +1583,7 @@  discard block
 block discarded – undo
1584 1583
 	 * @param string $dirs comma or whitespace separated directories, used if $document is a relative path
1585 1584
 	 * @return string with error-message on error, otherwise it does NOT return
1586 1585
 	 */
1587
-	public function download($document, $ids, $name='', $dirs='')
1586
+	public function download($document, $ids, $name = '', $dirs = '')
1588 1587
 	{
1589 1588
 		//error_log(__METHOD__."('$document', ".array2string($ids).", '$name', dirs='$dirs') ->".function_backtrace());
1590 1589
 		if (($error = $this->check_document($document, $dirs)))
@@ -1600,7 +1599,7 @@  discard block
 block discarded – undo
1600 1599
 				$mail_bo->openConnection();
1601 1600
 				try
1602 1601
 				{
1603
-					$msgs = $mail_bo->importMessageToMergeAndSend($this, $content_url, $ids, $_folder='');
1602
+					$msgs = $mail_bo->importMessageToMergeAndSend($this, $content_url, $ids, $_folder = '');
1604 1603
 				}
1605 1604
 				catch (Api\Exception\WrongUserinput $e)
1606 1605
 				{
@@ -1609,19 +1608,19 @@  discard block
 block discarded – undo
1609 1608
 				}
1610 1609
 				//error_log(__METHOD__.__LINE__.' Message after importMessageToMergeAndSend:'.array2string($msgs));
1611 1610
 				$retString = '';
1612
-				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']);
1611
+				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']);
1613 1612
 				//if (strlen($retString)>0) $retString .= '<br />';
1614
-				foreach($msgs['failed'] as $c =>$e)
1613
+				foreach ($msgs['failed'] as $c =>$e)
1615 1614
 				{
1616 1615
 					$errorString .= lang('contact').' '.lang('id').':'.$c.'->'.$e.'.';
1617 1616
 				}
1618
-				if (count($msgs['failed'])>0) $retString .= count($msgs['failed']).' '.lang('Message(s) send failed!').'=>'.$errorString;
1617
+				if (count($msgs['failed']) > 0) $retString .= count($msgs['failed']).' '.lang('Message(s) send failed!').'=>'.$errorString;
1619 1618
 				return $retString;
1620 1619
 			case 'application/vnd.oasis.opendocument.text':
1621 1620
 			case 'application/vnd.oasis.opendocument.spreadsheet':
1622 1621
 				$ext = $mimetype == 'application/vnd.oasis.opendocument.text' ? '.odt' : '.ods';
1623
-				$archive = tempnam($GLOBALS['egw_info']['server']['temp_dir'], basename($document,$ext).'-').$ext;
1624
-				copy($content_url,$archive);
1622
+				$archive = tempnam($GLOBALS['egw_info']['server']['temp_dir'], basename($document, $ext).'-').$ext;
1623
+				copy($content_url, $archive);
1625 1624
 				$content_url = 'zip://'.$archive.'#'.($content_file = 'content.xml');
1626 1625
 				$this->parse_html_styles = true;
1627 1626
 				break;
@@ -1629,20 +1628,20 @@  discard block
 block discarded – undo
1629 1628
 				$mimetype = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
1630 1629
 			case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
1631 1630
 			case 'application/vnd.ms-word.document.macroenabled.12':
1632
-				$archive = tempnam($GLOBALS['egw_info']['server']['temp_dir'], basename($document,'.docx').'-').'.docx';
1633
-				copy($content_url,$archive);
1631
+				$archive = tempnam($GLOBALS['egw_info']['server']['temp_dir'], basename($document, '.docx').'-').'.docx';
1632
+				copy($content_url, $archive);
1634 1633
 				$content_url = 'zip://'.$archive.'#'.($content_file = 'word/document.xml');
1635 1634
 				$fix = array(		// regular expression to fix garbled placeholders
1636
-					'/'.preg_quote('$$</w:t></w:r><w:proofErr w:type="spellStart"/><w:r><w:t>','/').'([a-z0-9_]+)'.
1637
-						preg_quote('</w:t></w:r><w:proofErr w:type="spellEnd"/><w:r><w:t>','/').'/i' => '$$\\1$$',
1638
-					'/'.preg_quote('$$</w:t></w:r><w:proofErr w:type="spellStart"/><w:r><w:rPr><w:lang w:val="','/').
1639
-						'([a-z]{2}-[A-Z]{2})'.preg_quote('"/></w:rPr><w:t>','/').'([a-z0-9_]+)'.
1640
-						preg_quote('</w:t></w:r><w:proofErr w:type="spellEnd"/><w:r><w:rPr><w:lang w:val="','/').
1641
-						'([a-z]{2}-[A-Z]{2})'.preg_quote('"/></w:rPr><w:t>$$','/').'/i' => '$$\\2$$',
1642
-					'/'.preg_quote('$</w:t></w:r><w:proofErr w:type="spellStart"/><w:r><w:t>','/').'([a-z0-9_]+)'.
1643
-						preg_quote('</w:t></w:r><w:proofErr w:type="spellEnd"/><w:r><w:t>','/').'/i' => '$\\1$',
1644
-					'/'.preg_quote('$ $</w:t></w:r><w:proofErr w:type="spellStart"/><w:r><w:t>','/').'([a-z0-9_]+)'.
1645
-						preg_quote('</w:t></w:r><w:proofErr w:type="spellEnd"/><w:r><w:t>','/').'/i' => '$ $\\1$ $',
1635
+					'/'.preg_quote('$$</w:t></w:r><w:proofErr w:type="spellStart"/><w:r><w:t>', '/').'([a-z0-9_]+)'.
1636
+						preg_quote('</w:t></w:r><w:proofErr w:type="spellEnd"/><w:r><w:t>', '/').'/i' => '$$\\1$$',
1637
+					'/'.preg_quote('$$</w:t></w:r><w:proofErr w:type="spellStart"/><w:r><w:rPr><w:lang w:val="', '/').
1638
+						'([a-z]{2}-[A-Z]{2})'.preg_quote('"/></w:rPr><w:t>', '/').'([a-z0-9_]+)'.
1639
+						preg_quote('</w:t></w:r><w:proofErr w:type="spellEnd"/><w:r><w:rPr><w:lang w:val="', '/').
1640
+						'([a-z]{2}-[A-Z]{2})'.preg_quote('"/></w:rPr><w:t>$$', '/').'/i' => '$$\\2$$',
1641
+					'/'.preg_quote('$</w:t></w:r><w:proofErr w:type="spellStart"/><w:r><w:t>', '/').'([a-z0-9_]+)'.
1642
+						preg_quote('</w:t></w:r><w:proofErr w:type="spellEnd"/><w:r><w:t>', '/').'/i' => '$\\1$',
1643
+					'/'.preg_quote('$ $</w:t></w:r><w:proofErr w:type="spellStart"/><w:r><w:t>', '/').'([a-z0-9_]+)'.
1644
+						preg_quote('</w:t></w:r><w:proofErr w:type="spellEnd"/><w:r><w:t>', '/').'/i' => '$ $\\1$ $',
1646 1645
 				);
1647 1646
 				break;
1648 1647
 			case 'application/xml':
@@ -1657,13 +1656,13 @@  discard block
 block discarded – undo
1657 1656
 				$fix = array(	// hack to get Excel 2007 to display additional rows in tables
1658 1657
 					'/ss:ExpandedRowCount="\d+"/' => 'ss:ExpandedRowCount="9999"',
1659 1658
 				);
1660
-				$archive = tempnam($GLOBALS['egw_info']['server']['temp_dir'], basename($document,'.xlsx').'-').'.xlsx';
1661
-				copy($content_url,$archive);
1659
+				$archive = tempnam($GLOBALS['egw_info']['server']['temp_dir'], basename($document, '.xlsx').'-').'.xlsx';
1660
+				copy($content_url, $archive);
1662 1661
 				$content_url = 'zip://'.$archive.'#'.($content_file = 'xl/sharedStrings.xml');
1663 1662
 				break;
1664 1663
 		}
1665 1664
 		$err = null;
1666
-		if (!($merged =& $this->merge($content_url,$ids,$err,$mimetype,$fix)))
1665
+		if (!($merged = & $this->merge($content_url, $ids, $err, $mimetype, $fix)))
1667 1666
 		{
1668 1667
 			//error_log(__METHOD__."() !this->merge() err=$err");
1669 1668
 			return $err;
@@ -1680,22 +1679,22 @@  discard block
 block discarded – undo
1680 1679
 			{
1681 1680
 				// Error converting HTML styles over
1682 1681
 				error_log($e->getMessage());
1683
-				error_log("Target document: $content_url, IDs: ". array2string($ids));
1682
+				error_log("Target document: $content_url, IDs: ".array2string($ids));
1684 1683
 
1685 1684
 				// Try again, but strip HTML so user gets something
1686 1685
 				$this->parse_html_styles = false;
1687
-				if (!($merged =& $this->merge($content_url,$ids,$err,$mimetype,$fix)))
1686
+				if (!($merged = & $this->merge($content_url, $ids, $err, $mimetype, $fix)))
1688 1687
 				{
1689 1688
 					return $err;
1690 1689
 				}
1691 1690
 			}
1692 1691
 			if ($this->report_memory_usage) error_log(__METHOD__."() after HTML processing ".Api\Vfs::hsize(memory_get_peak_usage(true)));
1693 1692
 		}
1694
-		if(!empty($name))
1693
+		if (!empty($name))
1695 1694
 		{
1696
-			if(empty($ext))
1695
+			if (empty($ext))
1697 1696
 			{
1698
-				$ext = '.'.pathinfo($document,PATHINFO_EXTENSION);
1697
+				$ext = '.'.pathinfo($document, PATHINFO_EXTENSION);
1699 1698
 			}
1700 1699
 			$name .= $ext;
1701 1700
 		}
@@ -1711,25 +1710,25 @@  discard block
 block discarded – undo
1711 1710
 				error_log(__METHOD__.__LINE__." !ZipArchive::open('$archive',ZIPARCHIVE"."::CHECKCONS) failed. Trying open without validating");
1712 1711
 				if ($zip->open($archive) !== true) throw new Api\Exception("!ZipArchive::open('$archive',|ZIPARCHIVE::CHECKCONS)");
1713 1712
 			}
1714
-			if ($zip->addFromString($content_file,$merged) !== true) throw new Api\Exception("!ZipArchive::addFromString('$content_file',\$merged)");
1713
+			if ($zip->addFromString($content_file, $merged) !== true) throw new Api\Exception("!ZipArchive::addFromString('$content_file',\$merged)");
1715 1714
 			if ($zip->close() !== true) throw new Api\Exception("!ZipArchive::close()");
1716 1715
 			unset($zip);
1717 1716
 			unset($merged);
1718 1717
 			if ($this->report_memory_usage) error_log(__METHOD__."() after ZIP processing ".Api\Vfs::hsize(memory_get_peak_usage(true)));
1719
-			Api\Header\Content::type($name,$mimetype,filesize($archive));
1720
-			readfile($archive,'r');
1718
+			Api\Header\Content::type($name, $mimetype, filesize($archive));
1719
+			readfile($archive, 'r');
1721 1720
 		}
1722 1721
 		else
1723 1722
 		{
1724 1723
 			if ($mimetype == 'application/xml')
1725 1724
 			{
1726
-				if (strpos($merged,'<?mso-application progid="Word.Document"?>') !== false)
1725
+				if (strpos($merged, '<?mso-application progid="Word.Document"?>') !== false)
1727 1726
 				{
1728
-					$mimetype = 'application/msword';	// to open it automatically in word or oowriter
1727
+					$mimetype = 'application/msword'; // to open it automatically in word or oowriter
1729 1728
 				}
1730
-				elseif (strpos($merged,'<?mso-application progid="Excel.Sheet"?>') !== false)
1729
+				elseif (strpos($merged, '<?mso-application progid="Excel.Sheet"?>') !== false)
1731 1730
 				{
1732
-					$mimetype = 'application/vnd.ms-excel';	// to open it automatically in excel or oocalc
1731
+					$mimetype = 'application/vnd.ms-excel'; // to open it automatically in excel or oocalc
1733 1732
 				}
1734 1733
 			}
1735 1734
 			Api\Header\Content::type($name, $mimetype);
@@ -1750,13 +1749,13 @@  discard block
 block discarded – undo
1750 1749
 	 */
1751 1750
 	public function download_by_request()
1752 1751
 	{
1753
-		if(empty($_POST['data_document_name'])) return false;
1754
-		if(empty($_POST['data_document_dir'])) return false;
1755
-		if(empty($_POST['data_checked'])) return false;
1752
+		if (empty($_POST['data_document_name'])) return false;
1753
+		if (empty($_POST['data_document_dir'])) return false;
1754
+		if (empty($_POST['data_checked'])) return false;
1756 1755
 
1757 1756
 		return $this->download(
1758 1757
 			$_POST['data_document_name'],
1759
-			explode(',',$_POST['data_checked']),
1758
+			explode(',', $_POST['data_checked']),
1760 1759
 			'',
1761 1760
 			$_POST['data_document_dir']
1762 1761
 		);
@@ -1770,18 +1769,18 @@  discard block
 block discarded – undo
1770 1769
 	 * @param array|string $mime_filter=null allowed mime type(s), default all, negative filter if $mime_filter[0] === '!'
1771 1770
 	 * @return array List of documents, suitable for a selectbox.  The key is document_<filename>.
1772 1771
 	 */
1773
-	public static function get_documents($dirs, $prefix='document_', $mime_filter=null, $app='')
1772
+	public static function get_documents($dirs, $prefix = 'document_', $mime_filter = null, $app = '')
1774 1773
 	{
1775
-		$export_limit=self::getExportLimit($app);
1776
-		if (!$dirs || (!self::hasExportLimit($export_limit,'ISALLOWED') && !self::is_export_limit_excepted())) return array();
1774
+		$export_limit = self::getExportLimit($app);
1775
+		if (!$dirs || (!self::hasExportLimit($export_limit, 'ISALLOWED') && !self::is_export_limit_excepted())) return array();
1777 1776
 
1778 1777
 		// split multiple comma or whitespace separated directories
1779 1778
 		// to still allow space or comma in dirnames, we also use the trailing slash of all pathes to split
1780 1779
 		if (count($dirs = preg_split('/[,\s]+\//', $dirs)) > 1)
1781 1780
 		{
1782
-			foreach($dirs as $n => &$d)
1781
+			foreach ($dirs as $n => &$d)
1783 1782
 			{
1784
-				if ($n) $d = '/'.$d;	// re-adding trailing slash removed by split
1783
+				if ($n) $d = '/'.$d; // re-adding trailing slash removed by split
1785 1784
 			}
1786 1785
 		}
1787 1786
 		if ($mime_filter && ($negativ_filter = $mime_filter[0] === '!'))
@@ -1796,15 +1795,15 @@  discard block
 block discarded – undo
1796 1795
 			}
1797 1796
 		}
1798 1797
 		$list = array();
1799
-		foreach($dirs as $dir)
1798
+		foreach ($dirs as $dir)
1800 1799
 		{
1801
-			if (($files = Api\Vfs::find($dir,array('need_mime'=>true),true)))
1800
+			if (($files = Api\Vfs::find($dir, array('need_mime'=>true), true)))
1802 1801
 			{
1803
-				foreach($files as $file)
1802
+				foreach ($files as $file)
1804 1803
 				{
1805 1804
 					// return only the mime-types we support
1806
-					$parts = explode('.',$file['name']);
1807
-					if (!self::is_implemented($file['mime'],'.'.array_pop($parts))) continue;
1805
+					$parts = explode('.', $file['name']);
1806
+					if (!self::is_implemented($file['mime'], '.'.array_pop($parts))) continue;
1808 1807
 					if ($mime_filter && $negativ_filter === in_array($file['mime'], (array)$mime_filter)) continue;
1809 1808
 					$list[$prefix.$file['name']] = Api\Vfs::decodePath($file['name']);
1810 1809
 				}
@@ -1831,14 +1830,14 @@  discard block
 block discarded – undo
1831 1830
 	 * @param int|string $export_limit =null export-limit, default $GLOBALS['egw_info']['server']['export_limit']
1832 1831
 	 * @return array see nextmatch_widget::egw_actions
1833 1832
 	 */
1834
-	public static function document_action($dirs, $group=0, $caption='Insert in document', $prefix='document_', $default_doc='',
1835
-		$export_limit=null)
1833
+	public static function document_action($dirs, $group = 0, $caption = 'Insert in document', $prefix = 'document_', $default_doc = '',
1834
+		$export_limit = null)
1836 1835
 	{
1837 1836
 		$documents = array();
1838 1837
 		if ($export_limit == null) $export_limit = self::getExportLimit(); // check if there is a globalsetting
1839 1838
 		if ($default_doc && ($file = Api\Vfs::stat($default_doc)))	// put default document on top
1840 1839
 		{
1841
-			if(!$file['mime'])
1840
+			if (!$file['mime'])
1842 1841
 			{
1843 1842
 				$file['mime'] = Api\Vfs::mime_content_type($default_doc);
1844 1843
 				$file['path'] = $default_doc;
@@ -1847,7 +1846,7 @@  discard block
 block discarded – undo
1847 1846
 				'icon' => Api\Vfs::mime_icon($file['mime']),
1848 1847
 				'caption' => Api\Vfs::decodePath(Api\Vfs::basename($default_doc)),
1849 1848
 				'group' => 1,
1850
-				'postSubmit' => true,	// download needs post submit (not Ajax) to work
1849
+				'postSubmit' => true, // download needs post submit (not Ajax) to work
1851 1850
 			);
1852 1851
 			if ($file['mime'] == 'message/rfc822')
1853 1852
 			{
@@ -1862,28 +1861,28 @@  discard block
 block discarded – undo
1862 1861
 			// to still allow space or comma in dirnames, we also use the trailing slash of all pathes to split
1863 1862
 			if (count($dirs = preg_split('/[,\s]+\//', $dirs)) > 1)
1864 1863
 			{
1865
-				foreach($dirs as $n => &$d)
1864
+				foreach ($dirs as $n => &$d)
1866 1865
 				{
1867
-					if ($n) $d = '/'.$d;	// re-adding trailing slash removed by split
1866
+					if ($n) $d = '/'.$d; // re-adding trailing slash removed by split
1868 1867
 				}
1869 1868
 			}
1870
-			foreach($dirs as $dir)
1869
+			foreach ($dirs as $dir)
1871 1870
 			{
1872
-				$files += Api\Vfs::find($dir,array(
1871
+				$files += Api\Vfs::find($dir, array(
1873 1872
 					'need_mime' => true,
1874 1873
 					'order' => 'fs_name',
1875 1874
 					'sort' => 'ASC',
1876
-				),true);
1875
+				), true);
1877 1876
 			}
1878 1877
 		}
1879 1878
 
1880 1879
 		$dircount = array();
1881
-		foreach($files as $key => $file)
1880
+		foreach ($files as $key => $file)
1882 1881
 		{
1883 1882
 			// use only the mime-types we support
1884
-			$parts = explode('.',$file['name']);
1885
-			if (!self::is_implemented($file['mime'],'.'.array_pop($parts)) ||
1886
-				!Api\Vfs::check_access($file['path'], Api\Vfs::READABLE, $file) ||	// remove files not readable by user
1883
+			$parts = explode('.', $file['name']);
1884
+			if (!self::is_implemented($file['mime'], '.'.array_pop($parts)) ||
1885
+				!Api\Vfs::check_access($file['path'], Api\Vfs::READABLE, $file) || // remove files not readable by user
1887 1886
 				$file['path'] === $default_doc)	// default doc already added
1888 1887
 			{
1889 1888
 				unset($files[$key]);
@@ -1891,40 +1890,40 @@  discard block
 block discarded – undo
1891 1890
 			else
1892 1891
 			{
1893 1892
 				$dirname = Api\Vfs::dirname($file['path']);
1894
-				if(!isset($dircount[$dirname]))
1893
+				if (!isset($dircount[$dirname]))
1895 1894
 				{
1896 1895
 					$dircount[$dirname] = 1;
1897 1896
 				}
1898 1897
 				else
1899 1898
 				{
1900
-					$dircount[$dirname] ++;
1899
+					$dircount[$dirname]++;
1901 1900
 				}
1902 1901
 			}
1903 1902
 		}
1904
-		foreach($files as $file)
1903
+		foreach ($files as $file)
1905 1904
 		{
1906 1905
 			if (count($dircount) > 1)
1907 1906
 			{
1908 1907
 				$name_arr = explode('/', $file['name']);
1909 1908
 				$current_level = &$documents;
1910
-				for($count = 0; $count < count($name_arr); $count++)
1909
+				for ($count = 0; $count < count($name_arr); $count++)
1911 1910
 				{
1912
-					if($count == 0)
1911
+					if ($count == 0)
1913 1912
 					{
1914 1913
 						$current_level = &$documents;
1915 1914
 					}
1916 1915
 					else
1917 1916
 					{
1918
-						$current_level = &$current_level[$prefix.$name_arr[($count-1)]]['children'];
1917
+						$current_level = &$current_level[$prefix.$name_arr[($count - 1)]]['children'];
1919 1918
 					}
1920
-					switch($count)
1919
+					switch ($count)
1921 1920
 					{
1922
-						case (count($name_arr)-1):
1921
+						case (count($name_arr) - 1):
1923 1922
 							$current_level[$prefix.$file['name']] = array(
1924 1923
 								'icon'		=> Api\Vfs::mime_icon($file['mime']),
1925 1924
 								'caption'	=> Api\Vfs::decodePath($name_arr[$count]),
1926 1925
 								'group'		=> 2,
1927
-								'postSubmit' => true,	// download needs post submit (not Ajax) to work
1926
+								'postSubmit' => true, // download needs post submit (not Ajax) to work
1928 1927
 							);
1929 1928
 							if ($file['mime'] == 'message/rfc822')
1930 1929
 							{
@@ -1933,7 +1932,7 @@  discard block
 block discarded – undo
1933 1932
 							break;
1934 1933
 
1935 1934
 						default:
1936
-							if(!is_array($current_level[$prefix.$name_arr[$count]]))
1935
+							if (!is_array($current_level[$prefix.$name_arr[$count]]))
1937 1936
 							{
1938 1937
 								// create parent folder
1939 1938
 								$current_level[$prefix.$name_arr[$count]] = array(
@@ -1960,7 +1959,7 @@  discard block
 block discarded – undo
1960 1959
 				}
1961 1960
 				$documents[$file['mime']]['children'][$prefix.$file['name']] = array(
1962 1961
 					'caption' => Api\Vfs::decodePath($file['name']),
1963
-					'postSubmit' => true,	// download needs post submit (not Ajax) to work
1962
+					'postSubmit' => true, // download needs post submit (not Ajax) to work
1964 1963
 				);
1965 1964
 				if ($file['mime'] == 'message/rfc822')
1966 1965
 				{
@@ -1973,7 +1972,7 @@  discard block
 block discarded – undo
1973 1972
 					'icon' => Api\Vfs::mime_icon($file['mime']),
1974 1973
 					'caption' => Api\Vfs::decodePath($file['name']),
1975 1974
 					'group' => 2,
1976
-					'postSubmit' => true,	// download needs post submit (not Ajax) to work
1975
+					'postSubmit' => true, // download needs post submit (not Ajax) to work
1977 1976
 				);
1978 1977
 				if ($file['mime'] == 'message/rfc822')
1979 1978
 				{
@@ -1987,8 +1986,8 @@  discard block
 block discarded – undo
1987 1986
 			'caption' => $caption,
1988 1987
 			'children' => $documents,
1989 1988
 			// disable action if no document or export completly forbidden for non-admins
1990
-			'enabled' => (boolean)$documents && (self::hasExportLimit($export_limit,'ISALLOWED') || self::is_export_limit_excepted()),
1991
-			'hideOnDisabled' => true,	// do not show 'Insert in document', if no documents defined or no export allowed
1989
+			'enabled' => (boolean)$documents && (self::hasExportLimit($export_limit, 'ISALLOWED') || self::is_export_limit_excepted()),
1990
+			'hideOnDisabled' => true, // do not show 'Insert in document', if no documents defined or no export allowed
1992 1991
 			'group' => $group,
1993 1992
 		);
1994 1993
 	}
@@ -2019,14 +2018,14 @@  discard block
 block discarded – undo
2019 2018
 		);
2020 2019
 
2021 2020
 		// egw.open() used if only 1 row selected
2022
-		$action['egw_open'] = 'edit-mail--'.implode('&',$extra);
2023
-		$action['target'] = 'compose_' .$file['path'];
2021
+		$action['egw_open'] = 'edit-mail--'.implode('&', $extra);
2022
+		$action['target'] = 'compose_'.$file['path'];
2024 2023
 
2025 2024
 		// long_task runs menuaction once for each selected row
2026 2025
 		$action['nm_action'] = 'long_task';
2027 2026
 		$action['popup'] = Api\Link::get_registry('mail', 'edit_popup');
2028
-		$action['message'] = lang('insert in %1',Api\Vfs::decodePath($file['name']));
2029
-		$action['menuaction'] = 'mail.mail_compose.ajax_merge&document='.$file['path'].'&merge='. get_called_class();
2027
+		$action['message'] = lang('insert in %1', Api\Vfs::decodePath($file['name']));
2028
+		$action['menuaction'] = 'mail.mail_compose.ajax_merge&document='.$file['path'].'&merge='.get_called_class();
2030 2029
 	}
2031 2030
 
2032 2031
 	/**
@@ -2038,15 +2037,15 @@  discard block
 block discarded – undo
2038 2037
 	 */
2039 2038
 	public static function check_document(&$document, $dirs)
2040 2039
 	{
2041
-		if($document[0] !== '/')
2040
+		if ($document[0] !== '/')
2042 2041
 		{
2043 2042
 			// split multiple comma or whitespace separated directories
2044 2043
 			// to still allow space or comma in dirnames, we also use the trailing slash of all pathes to split
2045 2044
 			if ($dirs && ($dirs = preg_split('/[,\s]+\//', $dirs)))
2046 2045
 			{
2047
-				foreach($dirs as $n => $dir)
2046
+				foreach ($dirs as $n => $dir)
2048 2047
 				{
2049
-					if ($n) $dir = '/'.$dir;	// re-adding trailing slash removed by split
2048
+					if ($n) $dir = '/'.$dir; // re-adding trailing slash removed by split
2050 2049
 					if (Api\Vfs::stat($dir.'/'.$document) && Api\Vfs::is_readable($dir.'/'.$document))
2051 2050
 					{
2052 2051
 						$document = $dir.'/'.$document;
@@ -2060,7 +2059,7 @@  discard block
 block discarded – undo
2060 2059
 			return false;
2061 2060
 		}
2062 2061
 		//error_log(__METHOD__."('$document', dirs='$dirs') returning 'Document '$document' does not exist or is not readable for you!'");
2063
-		return lang("Document '%1' does not exist or is not readable for you!",$document);
2062
+		return lang("Document '%1' does not exist or is not readable for you!", $document);
2064 2063
 	}
2065 2064
 
2066 2065
 	/**
@@ -2081,16 +2080,16 @@  discard block
 block discarded – undo
2081 2080
 	 * @param string $_mimetype =''
2082 2081
 	 * @return string
2083 2082
 	 */
2084
-	static public function number_format($number,$num_decimal_places=2,$_mimetype='')
2083
+	static public function number_format($number, $num_decimal_places = 2, $_mimetype = '')
2085 2084
 	{
2086 2085
 		if ((string)$number === '') return '';
2087 2086
 		//error_log(__METHOD__.$_mimetype);
2088
-		switch($_mimetype)
2087
+		switch ($_mimetype)
2089 2088
 		{
2090 2089
 			case 'application/xml':	// Excel 2003
2091 2090
 			case 'application/vnd.oasis.opendocument.spreadsheet': // OO.o spreadsheet
2092
-				return number_format(str_replace(' ','',$number),$num_decimal_places,'.','');
2091
+				return number_format(str_replace(' ', '', $number), $num_decimal_places, '.', '');
2093 2092
 		}
2094
-		return Api\Etemplate::number_format($number,$num_decimal_places);
2093
+		return Api\Etemplate::number_format($number, $num_decimal_places);
2095 2094
 	}
2096 2095
 }
Please login to merge, or discard this patch.
Braces   +268 added lines, -74 removed lines patch added patch discarded remove patch
@@ -168,13 +168,19 @@  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
@@ -182,7 +188,10 @@  discard block
 block discarded – undo
182 188
 			case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':	// ms excel 2007 xml format
183 189
 			case 'application/vnd.openxmlformats-officedocument.spreadsheetml.shee':
184 190
 			case 'application/vnd.ms-excel.sheet.macroenabled.12':
185
-				if (!$zip_available) break;
191
+				if (!$zip_available)
192
+				{
193
+					break;
194
+				}
186 195
 				return true;	// ms word xml format
187 196
 			case 'application/xml':
188 197
 				return true;	// alias for text/xml, eg. ms office 2003 word format
@@ -217,7 +226,10 @@  discard block
 block discarded – undo
217 226
 		{
218 227
 			$contact = $this->contacts->read($contact, $ignore_acl);
219 228
 		}
220
-		if (!is_array($contact)) return array();
229
+		if (!is_array($contact))
230
+		{
231
+			return array();
232
+		}
221 233
 
222 234
 		$replacements = array();
223 235
 		foreach(array_keys($this->contacts->contact_fields) as $name)
@@ -226,7 +238,10 @@  discard block
 block discarded – undo
226 238
 			switch($name)
227 239
 			{
228 240
 				case 'created': case 'modified':
229
-					if($value) $value = Api\DateTime::to($value);
241
+					if($value)
242
+					{
243
+						$value = Api\DateTime::to($value);
244
+					}
230 245
 					break;
231 246
 				case 'bday':
232 247
 					if ($value)
@@ -276,7 +291,10 @@  discard block
 block discarded – undo
276 291
 					}
277 292
 					break;
278 293
 			}
279
-			if ($name != 'photo') $replacements['$$'.($prefix ? $prefix.'/':'').$name.'$$'] = $value;
294
+			if ($name != 'photo')
295
+			{
296
+				$replacements['$$'.($prefix ? $prefix.'/':'').$name.'$$'] = $value;
297
+			}
280 298
 		}
281 299
 		// set custom fields, should probably go to a general method all apps can use
282 300
 		// need to load all cfs for $ignore_acl=true
@@ -293,17 +311,23 @@  discard block
 block discarded – undo
293 311
 		$cats = array();
294 312
 		foreach(is_array($contact['cat_id']) ? $contact['cat_id'] : explode(',',$contact['cat_id']) as $cat_id)
295 313
 		{
296
-			if(!$cat_id) continue;
314
+			if(!$cat_id)
315
+			{
316
+				continue;
317
+			}
297 318
 			if($GLOBALS['egw']->categories->id2name($cat_id,'main') != $cat_id)
298 319
 			{
299 320
 				$path = explode(' / ', $GLOBALS['egw']->categories->id2name($cat_id, 'path'));
300 321
 				unset($path[0]); // Drop main
301 322
 				$cats[$GLOBALS['egw']->categories->id2name($cat_id,'main')][] = implode(' / ', $path);
302
-			} elseif($cat_id) {
323
+			}
324
+			elseif($cat_id)
325
+			{
303 326
 				$cats[$cat_id] = array();
304 327
 			}
305 328
 		}
306
-		foreach($cats as $main => $cat) {
329
+		foreach($cats as $main => $cat)
330
+		{
307 331
 			$replacements['$$'.($prefix ? $prefix.'/':'').'categories$$'] .= $GLOBALS['egw']->categories->id2name($main,'name')
308 332
 				. (count($cat) > 0 ? ': ' : '') . implode(', ', $cats[$main]) . "\n";
309 333
 		}
@@ -338,7 +362,10 @@  discard block
 block discarded – undo
338 362
 					'id'	=> $link_info
339 363
 				);
340 364
 			}
341
-			if($exclude && in_array($link_info['id'], $exclude)) continue;
365
+			if($exclude && in_array($link_info['id'], $exclude))
366
+			{
367
+				continue;
368
+			}
342 369
 
343 370
 			$title = Api\Link::title($link_info['app'], $link_info['id']);
344 371
 			if(class_exists('EGroupware\Stylite\Vfs\Links\StreamWrapper') && $link_info['app'] != Api\Link::VFS_APPNAME)
@@ -457,7 +484,10 @@  discard block
 block discarded – undo
457 484
 	protected function format_datetime($time,$format=null)
458 485
 	{
459 486
 		trigger_error(__METHOD__ . ' is deprecated, use Api\DateTime::to($time, $format)', E_USER_DEPRECATED);
460
-		if (is_null($format)) $format = $this->datetime_format;
487
+		if (is_null($format))
488
+		{
489
+			$format = $this->datetime_format;
490
+		}
461 491
 
462 492
 		return Api\DateTime::to($time,$format);
463 493
 	}
@@ -499,7 +529,10 @@  discard block
 block discarded – undo
499 529
 	public static function getExportLimit($app='common')
500 530
 	{
501 531
 		static $exportLimitStore=array();
502
-		if (empty($app)) $app='common';
532
+		if (empty($app))
533
+		{
534
+			$app='common';
535
+		}
503 536
 		//error_log(__METHOD__.__LINE__.' called with app:'.$app);
504 537
 		if (!array_key_exists($app,$exportLimitStore))
505 538
 		{
@@ -508,7 +541,10 @@  discard block
 block discarded – undo
508 541
 			if ($app !='common')
509 542
 			{
510 543
 				$app_limit = Api\Hooks::single('export_limit',$app);
511
-				if ($app_limit) $exportLimitStore[$app] = $app_limit;
544
+				if ($app_limit)
545
+				{
546
+					$exportLimitStore[$app] = $app_limit;
547
+				}
512 548
 			}
513 549
 			//error_log(__METHOD__.__LINE__.' building cache for app:'.$app.' -> '.$exportLimitStore[$app]);
514 550
 			if (empty($exportLimitStore[$app]))
@@ -541,10 +577,22 @@  discard block
 block discarded – undo
541 577
 	 */
542 578
 	public static function hasExportLimit($app_limit,$checkas='AND')
543 579
 	{
544
-		if (strtoupper($checkas) == 'ISALLOWED') return (empty($app_limit) || ($app_limit !='no' && $app_limit > 0) );
545
-		if (empty($app_limit)) return false;
546
-		if ($app_limit == 'no') return true;
547
-		if ($app_limit > 0) return true;
580
+		if (strtoupper($checkas) == 'ISALLOWED')
581
+		{
582
+			return (empty($app_limit) || ($app_limit !='no' && $app_limit > 0) );
583
+		}
584
+		if (empty($app_limit))
585
+		{
586
+			return false;
587
+		}
588
+		if ($app_limit == 'no')
589
+		{
590
+			return true;
591
+		}
592
+		if ($app_limit > 0)
593
+		{
594
+			return true;
595
+		}
548 596
 	}
549 597
 
550 598
 	/**
@@ -579,7 +627,8 @@  discard block
 block discarded – undo
579 627
 
580 628
 		try {
581 629
 			$content = $this->merge_string($content,$ids,$err,$mimetype,$fix);
582
-		} catch (\Exception $e) {
630
+		}
631
+		catch (\Exception $e) {
583 632
 			_egw_log_exception($e);
584 633
 			$err = $e->getMessage();
585 634
 			return false;
@@ -671,7 +720,8 @@  discard block
 block discarded – undo
671 720
 			$content = $xslt->transformToXml($element);
672 721
 
673 722
 			// Word 2003 needs two declarations, add extra declaration back in
674
-			if($mimetype == 'application/xml' && $mso_application_progid == 'Word.Document' && strpos($content, '<?xml') !== 0) {
723
+			if($mimetype == 'application/xml' && $mso_application_progid == 'Word.Document' && strpos($content, '<?xml') !== 0)
724
+			{
675 725
 				$content = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'.$content;
676 726
 			}
677 727
 			// Validate
@@ -731,7 +781,10 @@  discard block
 block discarded – undo
731 781
 			// textdocuments are simple, they do not hold start and end, but they may have content before and after the $$pagerepeat$$ tag
732 782
 			// header and footer should not hold any $$ tags; if we find $$ tags with the header, we assume it is the pagerepeatcontent
733 783
 			$nohead = false;
734
-			if (stripos($contentstart,'$$') !== false) $nohead = true;
784
+			if (stripos($contentstart,'$$') !== false)
785
+			{
786
+				$nohead = true;
787
+			}
735 788
 			if ($nohead)
736 789
 			{
737 790
 				$contentend = $contentrepeat;
@@ -773,13 +826,19 @@  discard block
 block discarded – undo
773 826
 		preg_match_all('/\$\$labelplacement\$\$/',$contentrepeat,$countlables, PREG_SPLIT_NO_EMPTY);
774 827
 		$countlables = count($countlables[0]);
775 828
 		preg_replace('/\$\$labelplacement\$\$/','',$Labelrepeat,1);
776
-		if ($countlables > 1) $lableprint = true;
829
+		if ($countlables > 1)
830
+		{
831
+			$lableprint = true;
832
+		}
777 833
 		if (count($ids) > 1 && !$contentrepeat)
778 834
 		{
779 835
 			$err = lang('for more than one contact in a document use the tag pagerepeat!');
780 836
 			return false;
781 837
 		}
782
-		if ($this->report_memory_usage) error_log(__METHOD__."(count(ids)=".count($ids).") strlen(contentrepeat)=".strlen($contentrepeat).', strlen(labelrepeat)='.strlen($Labelrepeat));
838
+		if ($this->report_memory_usage)
839
+		{
840
+			error_log(__METHOD__."(count(ids)=".count($ids).") strlen(contentrepeat)=".strlen($contentrepeat).', strlen(labelrepeat)='.strlen($Labelrepeat));
841
+		}
783 842
 
784 843
 		if ($contentrepeat)
785 844
 		{
@@ -814,8 +873,15 @@  discard block
 block discarded – undo
814 873
 		}
815 874
 		foreach ((array)$ids as $n => $id)
816 875
 		{
817
-			if ($contentrepeat) $content = $contentrepeat;   //content to repeat
818
-			if ($lableprint) $content = $Labelrepeat;
876
+			if ($contentrepeat)
877
+			{
878
+				$content = $contentrepeat;
879
+			}
880
+			//content to repeat
881
+			if ($lableprint)
882
+			{
883
+				$content = $Labelrepeat;
884
+			}
819 885
 
820 886
 			// generate replacements; if exeption is thrown, catch it set error message and return false
821 887
 			try
@@ -832,7 +898,10 @@  discard block
 block discarded – undo
832 898
 				$err = $e->getMessage();
833 899
 				return false;
834 900
 			}
835
-			if ($this->report_memory_usage) error_log(__METHOD__."() $n: $id ".Api\Vfs::hsize(memory_get_usage(true)));
901
+			if ($this->report_memory_usage)
902
+			{
903
+				error_log(__METHOD__."() $n: $id ".Api\Vfs::hsize(memory_get_usage(true)));
904
+			}
836 905
 			// some general replacements: current user, date and time
837 906
 			if (strpos($content,'$$user/') !== null && ($user = $GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'],'person_id')))
838 907
 			{
@@ -890,9 +959,12 @@  discard block
 block discarded – undo
890 959
 			{
891 960
 				$contentrepeatpages[$countpage] = preg_replace('/\$\$labelplacement\$\$/',$Label,$contentrepeatpages[$countpage],1);
892 961
 				$count=$count+1;
893
-				if (($count % $countlables) == 0 && count($contentrep)>$count)  //new page
962
+				if (($count % $countlables) == 0 && count($contentrep)>$count)
963
+				{
964
+					//new page
894 965
 				{
895 966
 					$countpage = $countpage+1;
967
+				}
896 968
 					$contentrepeatpages[$countpage] = $Labelstart.$Labeltend;
897 969
 				}
898 970
 			}
@@ -925,7 +997,10 @@  discard block
 block discarded – undo
925 997
 			rewind($content_stream);
926 998
 			return stream_get_contents($content_stream);
927 999
 		}
928
-		if ($this->report_memory_usage) error_log(__METHOD__."() returning ".Api\Vfs::hsize(memory_get_peak_usage(true)));
1000
+		if ($this->report_memory_usage)
1001
+		{
1002
+			error_log(__METHOD__."() returning ".Api\Vfs::hsize(memory_get_peak_usage(true)));
1003
+		}
929 1004
 
930 1005
 		return $content;
931 1006
 	}
@@ -970,7 +1045,10 @@  discard block
 block discarded – undo
970 1045
 				break;
971 1046
 
972 1047
 			default:	// div. text files --> use our export-charset, defined in addressbook prefs
973
-				if (empty($charset)) $charset = $this->contacts->prefs['csv_charset'];
1048
+				if (empty($charset))
1049
+				{
1050
+					$charset = $this->contacts->prefs['csv_charset'];
1051
+				}
974 1052
 				break;
975 1053
 		}
976 1054
 		//error_log(__METHOD__."('$document', ... ,$mimetype) --> $charset (egw=".Api\Translation::charset().', export='.$this->contacts->prefs['csv_charset'].')');
@@ -993,10 +1071,13 @@  discard block
 block discarded – undo
993 1071
 				}
994 1072
 			}
995 1073
 		}
996
-		if ($is_xml)	// zip'ed xml document (eg. OO)
1074
+		if ($is_xml)
1075
+		{
1076
+			// zip'ed xml document (eg. OO)
997 1077
 		{
998 1078
 			// Numeric fields
999 1079
 			$names = array();
1080
+		}
1000 1081
 
1001 1082
 			// Tags we can replace with the target document's version
1002 1083
 			$replace_tags = array();
@@ -1061,7 +1142,8 @@  discard block
 block discarded – undo
1061 1142
 				else if (is_string($value) && (strpos($value,'<') !== false))
1062 1143
 				{
1063 1144
 					// Clean HTML, if it's being kept
1064
-					if($replace_tags && extension_loaded('tidy')) {
1145
+					if($replace_tags && extension_loaded('tidy'))
1146
+					{
1065 1147
 						$tidy = new tidy();
1066 1148
 						$cleaned = $tidy->repairString($value, self::$tidy_config);
1067 1149
 						// Found errors. Strip it all so there's some output
@@ -1095,16 +1177,20 @@  discard block
 block discarded – undo
1095 1177
 				// replace all control chars (C0+C1) but CR (\015), LF (\012) and TAB (\011) (eg. vertical tabulators) with space
1096 1178
 				// as they are not allowed in xml
1097 1179
 				$value = preg_replace('/[\000-\010\013\014\016-\037\177-\237]/u',' ',$value);
1098
-				if(is_numeric($value) && $name != '$$user/account_id$$') // account_id causes problems with the preg_replace below
1180
+				if(is_numeric($value) && $name != '$$user/account_id$$')
1181
+				{
1182
+					// account_id causes problems with the preg_replace below
1099 1183
 				{
1100 1184
 					$names[] = preg_quote($name,'/');
1101 1185
 				}
1186
+				}
1102 1187
 			}
1103 1188
 
1104 1189
 			// Look for numbers, set their value if needed
1105 1190
 			if($this->numeric_fields || count($names))
1106 1191
 			{
1107
-				foreach((array)$this->numeric_fields as $fieldname) {
1192
+				foreach((array)$this->numeric_fields as $fieldname)
1193
+				{
1108 1194
 					$names[] = preg_quote($fieldname,'/');
1109 1195
 				}
1110 1196
 				$this->format_spreadsheet_numbers($content, $names, $mimetype.$mso_application_progid);
@@ -1114,7 +1200,8 @@  discard block
 block discarded – undo
1114 1200
 			if($this->date_fields || count($names))
1115 1201
 			{
1116 1202
 				$names = array();
1117
-				foreach((array)$this->date_fields as $fieldname) {
1203
+				foreach((array)$this->date_fields as $fieldname)
1204
+				{
1118 1205
 					$names[] = $fieldname;
1119 1206
 				}
1120 1207
 				$this->format_spreadsheet_dates($content, $names, $replacements, $mimetype.$mso_application_progid);
@@ -1193,7 +1280,8 @@  discard block
 block discarded – undo
1193 1280
 	 */
1194 1281
 	protected function format_spreadsheet_numbers(&$content, $names, $mimetype)
1195 1282
 	{
1196
-		foreach((array)$this->numeric_fields as $fieldname) {
1283
+		foreach((array)$this->numeric_fields as $fieldname)
1284
+		{
1197 1285
 			$names[] = preg_quote($fieldname,'/');
1198 1286
 		}
1199 1287
 		switch($mimetype)
@@ -1222,7 +1310,11 @@  discard block
 block discarded – undo
1222 1310
 			// try to increase/double pcre.backtrack_limit failure
1223 1311
 			while(preg_last_error() == PREG_BACKTRACK_LIMIT_ERROR && self::increase_backtrack_limit());
1224 1312
 
1225
-			if ($result) $content = $result;  // On failure $result would be NULL
1313
+			if ($result)
1314
+			{
1315
+				$content = $result;
1316
+			}
1317
+			// On failure $result would be NULL
1226 1318
 		}
1227 1319
 	}
1228 1320
 
@@ -1266,7 +1358,10 @@  discard block
 block discarded – undo
1266 1358
 			'application/vnd.oasis.opendocument.spreadsheet',		// open office calc
1267 1359
 			'application/xmlExcel.Sheet',					// Excel 2003
1268 1360
 			//'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'//Excel WTF
1269
-		))) return;
1361
+		)))
1362
+		{
1363
+			return;
1364
+		}
1270 1365
 
1271 1366
 		// Some different formats dates could be in, depending what they've been through
1272 1367
 		$formats = array(
@@ -1287,9 +1382,12 @@  discard block
 block discarded – undo
1287 1382
 			{
1288 1383
 				$date = Api\DateTime::createFromUserFormat($values[$key]);
1289 1384
 				if($mimetype == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ||
1290
-					$mimetype == 'application/vnd.ms-excel.sheet.macroenabled.12')//Excel WTF
1385
+					$mimetype == 'application/vnd.ms-excel.sheet.macroenabled.12')
1386
+				{
1387
+					//Excel WTF
1291 1388
 				{
1292 1389
 					$interval = $date->diff(new Api\DateTime('1900-01-00 0:00'));
1390
+				}
1293 1391
 					$values[$key] = $interval->format('%a')+1;// 1900-02-29 did not exist
1294 1392
 					// 1440 minutes in a day - fractional part
1295 1393
 					$values[$key] += ($date->format('H') * 60 + $date->format('i'))/1440;
@@ -1332,7 +1430,11 @@  discard block
 block discarded – undo
1332 1430
 			// try to increase/double pcre.backtrack_limit failure
1333 1431
 			while(preg_last_error() == PREG_BACKTRACK_LIMIT_ERROR && self::increase_backtrack_limit());
1334 1432
 
1335
-			if ($result) $content = $result;  // On failure $result would be NULL
1433
+			if ($result)
1434
+			{
1435
+				$content = $result;
1436
+			}
1437
+			// On failure $result would be NULL
1336 1438
 		}
1337 1439
 	}
1338 1440
 
@@ -1403,7 +1505,10 @@  discard block
 block discarded – undo
1403 1505
 			}
1404 1506
 			else
1405 1507
 			{
1406
-				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
+				}
1407 1512
 			}
1408 1513
 		}
1409 1514
 	}
@@ -1457,30 +1562,35 @@  discard block
 block discarded – undo
1457 1562
 	private function process_commands($content, $replacements)
1458 1563
 	{
1459 1564
 		if (strpos($content,'$$IF') !== false)
1460
-		{	//Example use to use: $$IF n_prefix~Herr~Sehr geehrter~Sehr geehrte$$
1565
+		{
1566
+//Example use to use: $$IF n_prefix~Herr~Sehr geehrter~Sehr geehrte$$
1461 1567
 			$this->replacements =& $replacements;
1462 1568
 			$content = preg_replace_callback('/\$\$IF ([#0-9a-z_\/-]+)~(.*)~(.*)~(.*)\$\$/imU',Array($this,'replace_callback'),$content);
1463 1569
 			unset($this->replacements);
1464 1570
 		}
1465 1571
 		if (strpos($content,'$$NELF') !== false)
1466
-		{	//Example: $$NEPBR org_unit$$ sets a LF and value of org_unit, only if there is a value
1572
+		{
1573
+//Example: $$NEPBR org_unit$$ sets a LF and value of org_unit, only if there is a value
1467 1574
 			$this->replacements =& $replacements;
1468 1575
 			$content = preg_replace_callback('/\$\$NELF ([#0-9a-z_\/-]+)\$\$/imU',Array($this,'replace_callback'),$content);
1469 1576
 			unset($this->replacements);
1470 1577
 		}
1471 1578
 		if (strpos($content,'$$NENVLF') !== false)
1472
-		{	//Example: $$NEPBRNV org_unit$$ sets only a LF if there is a value for org_units, but did not add any value
1579
+		{
1580
+//Example: $$NEPBRNV org_unit$$ sets only a LF if there is a value for org_units, but did not add any value
1473 1581
 			$this->replacements =& $replacements;
1474 1582
 			$content = preg_replace_callback('/\$\$NENVLF ([#0-9a-z_\/-]+)\$\$/imU',Array($this,'replace_callback'),$content);
1475 1583
 			unset($this->replacements);
1476 1584
 		}
1477 1585
 		if (strpos($content,'$$LETTERPREFIX$$') !== false)
1478
-		{	//Example use to use: $$LETTERPREFIX$$
1586
+		{
1587
+//Example use to use: $$LETTERPREFIX$$
1479 1588
 			$LETTERPREFIXCUSTOM = '$$LETTERPREFIXCUSTOM n_prefix title n_family$$';
1480 1589
 			$content = str_replace('$$LETTERPREFIX$$',$LETTERPREFIXCUSTOM,$content);
1481 1590
 		}
1482 1591
 		if (strpos($content,'$$LETTERPREFIXCUSTOM') !== false)
1483
-		{	//Example use to use for a custom Letter Prefix: $$LETTERPREFIX n_prefix title n_family$$
1592
+		{
1593
+//Example use to use for a custom Letter Prefix: $$LETTERPREFIX n_prefix title n_family$$
1484 1594
 			$this->replacements =& $replacements;
1485 1595
 			$content = preg_replace_callback('/\$\$LETTERPREFIXCUSTOM ([#0-9a-z_-]+)(.*)\$\$/imU',Array($this,'replace_callback'),$content);
1486 1596
 			unset($this->replacements);
@@ -1496,8 +1606,14 @@  discard block
 block discarded – undo
1496 1606
 	 */
1497 1607
 	private function replace_callback($param)
1498 1608
 	{
1499
-		if (array_key_exists('$$'.$param[4].'$$',$this->replacements)) $param[4] = $this->replacements['$$'.$param[4].'$$'];
1500
-		if (array_key_exists('$$'.$param[3].'$$',$this->replacements)) $param[3] = $this->replacements['$$'.$param[3].'$$'];
1609
+		if (array_key_exists('$$'.$param[4].'$$',$this->replacements))
1610
+		{
1611
+			$param[4] = $this->replacements['$$'.$param[4].'$$'];
1612
+		}
1613
+		if (array_key_exists('$$'.$param[3].'$$',$this->replacements))
1614
+		{
1615
+			$param[3] = $this->replacements['$$'.$param[3].'$$'];
1616
+		}
1501 1617
 
1502 1618
 		$pattern = '/'.preg_quote($param[2], '/').'/';
1503 1619
 		if (strpos($param[0],'$$IF') === 0 && (trim($param[2]) == "EMPTY" || $param[2] === ''))
@@ -1521,7 +1637,7 @@  discard block
 block discarded – undo
1521 1637
 		}
1522 1638
 
1523 1639
 		switch($this->mimetype)
1524
-			{
1640
+		{
1525 1641
 				case 'application/rtf':
1526 1642
 				case 'text/rtf':
1527 1643
 					$LF = '}\par \pard\plain{';
@@ -1550,25 +1666,38 @@  discard block
 block discarded – undo
1550 1666
 				default:
1551 1667
 					$LF = "\n";
1552 1668
 			}
1553
-		if($is_xml) {
1669
+		if($is_xml)
1670
+		{
1554 1671
 			$this->replacements = str_replace(array('&','&amp;amp;','<','>',"\r","\n"),array('&amp;','&amp;','&lt;','&gt;','',$LF),$this->replacements);
1555 1672
 		}
1556 1673
 		if (strpos($param[0],'$$NELF') === 0)
1557
-		{	//sets a Pagebreak and value, only if the field has a value
1558
-			if ($this->replacements['$$'.$param[1].'$$'] !='') $replace = $LF.$this->replacements['$$'.$param[1].'$$'];
1674
+		{
1675
+//sets a Pagebreak and value, only if the field has a value
1676
+			if ($this->replacements['$$'.$param[1].'$$'] !='')
1677
+			{
1678
+				$replace = $LF.$this->replacements['$$'.$param[1].'$$'];
1679
+			}
1559 1680
 		}
1560 1681
 		if (strpos($param[0],'$$NENVLF') === 0)
1561
-		{	//sets a Pagebreak without any value, only if the field has a value
1562
-			if ($this->replacements['$$'.$param[1].'$$'] !='') $replace = $LF;
1682
+		{
1683
+//sets a Pagebreak without any value, only if the field has a value
1684
+			if ($this->replacements['$$'.$param[1].'$$'] !='')
1685
+			{
1686
+				$replace = $LF;
1687
+			}
1563 1688
 		}
1564 1689
 		if (strpos($param[0],'$$LETTERPREFIXCUSTOM') === 0)
1565
-		{	//sets a Letterprefix
1690
+		{
1691
+//sets a Letterprefix
1566 1692
 			$replaceprefixsort = array();
1567 1693
 			// ToDo Stefan: $contentstart is NOT defined here!!!
1568 1694
 			$replaceprefix = explode(' ',substr($param[0],21,-2));
1569 1695
 			foreach ($replaceprefix as $nameprefix)
1570 1696
 			{
1571
-				if ($this->replacements['$$'.$nameprefix.'$$'] !='') $replaceprefixsort[] = $this->replacements['$$'.$nameprefix.'$$'];
1697
+				if ($this->replacements['$$'.$nameprefix.'$$'] !='')
1698
+				{
1699
+					$replaceprefixsort[] = $this->replacements['$$'.$nameprefix.'$$'];
1700
+				}
1572 1701
 			}
1573 1702
 			$replace = implode($replaceprefixsort,' ');
1574 1703
 		}
@@ -1609,13 +1738,20 @@  discard block
 block discarded – undo
1609 1738
 				}
1610 1739
 				//error_log(__METHOD__.__LINE__.' Message after importMessageToMergeAndSend:'.array2string($msgs));
1611 1740
 				$retString = '';
1612
-				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']);
1741
+				if (count($msgs['success'])>0)
1742
+				{
1743
+					$retString .= count($msgs['success']).' '.(count($msgs['success'])+count($msgs['failed'])==1?lang('Message prepared for sending.'):lang('Message(s) send ok.'));
1744
+				}
1745
+				//implode('<br />',$msgs['success']);
1613 1746
 				//if (strlen($retString)>0) $retString .= '<br />';
1614 1747
 				foreach($msgs['failed'] as $c =>$e)
1615 1748
 				{
1616 1749
 					$errorString .= lang('contact').' '.lang('id').':'.$c.'->'.$e.'.';
1617 1750
 				}
1618
-				if (count($msgs['failed'])>0) $retString .= count($msgs['failed']).' '.lang('Message(s) send failed!').'=>'.$errorString;
1751
+				if (count($msgs['failed'])>0)
1752
+				{
1753
+					$retString .= count($msgs['failed']).' '.lang('Message(s) send failed!').'=>'.$errorString;
1754
+				}
1619 1755
 				return $retString;
1620 1756
 			case 'application/vnd.oasis.opendocument.text':
1621 1757
 			case 'application/vnd.oasis.opendocument.spreadsheet':
@@ -1689,7 +1825,10 @@  discard block
 block discarded – undo
1689 1825
 					return $err;
1690 1826
 				}
1691 1827
 			}
1692
-			if ($this->report_memory_usage) error_log(__METHOD__."() after HTML processing ".Api\Vfs::hsize(memory_get_peak_usage(true)));
1828
+			if ($this->report_memory_usage)
1829
+			{
1830
+				error_log(__METHOD__."() after HTML processing ".Api\Vfs::hsize(memory_get_peak_usage(true)));
1831
+			}
1693 1832
 		}
1694 1833
 		if(!empty($name))
1695 1834
 		{
@@ -1709,13 +1848,25 @@  discard block
 block discarded – undo
1709 1848
 			if ($zip->open($archive, ZipArchive::CHECKCONS) !== true)
1710 1849
 			{
1711 1850
 				error_log(__METHOD__.__LINE__." !ZipArchive::open('$archive',ZIPARCHIVE"."::CHECKCONS) failed. Trying open without validating");
1712
-				if ($zip->open($archive) !== true) throw new Api\Exception("!ZipArchive::open('$archive',|ZIPARCHIVE::CHECKCONS)");
1851
+				if ($zip->open($archive) !== true)
1852
+				{
1853
+					throw new Api\Exception("!ZipArchive::open('$archive',|ZIPARCHIVE::CHECKCONS)");
1854
+				}
1855
+			}
1856
+			if ($zip->addFromString($content_file,$merged) !== true)
1857
+			{
1858
+				throw new Api\Exception("!ZipArchive::addFromString('$content_file',\$merged)");
1859
+			}
1860
+			if ($zip->close() !== true)
1861
+			{
1862
+				throw new Api\Exception("!ZipArchive::close()");
1713 1863
 			}
1714
-			if ($zip->addFromString($content_file,$merged) !== true) throw new Api\Exception("!ZipArchive::addFromString('$content_file',\$merged)");
1715
-			if ($zip->close() !== true) throw new Api\Exception("!ZipArchive::close()");
1716 1864
 			unset($zip);
1717 1865
 			unset($merged);
1718
-			if ($this->report_memory_usage) error_log(__METHOD__."() after ZIP processing ".Api\Vfs::hsize(memory_get_peak_usage(true)));
1866
+			if ($this->report_memory_usage)
1867
+			{
1868
+				error_log(__METHOD__."() after ZIP processing ".Api\Vfs::hsize(memory_get_peak_usage(true)));
1869
+			}
1719 1870
 			Api\Header\Content::type($name,$mimetype,filesize($archive));
1720 1871
 			readfile($archive,'r');
1721 1872
 		}
@@ -1750,9 +1901,18 @@  discard block
 block discarded – undo
1750 1901
 	 */
1751 1902
 	public function download_by_request()
1752 1903
 	{
1753
-		if(empty($_POST['data_document_name'])) return false;
1754
-		if(empty($_POST['data_document_dir'])) return false;
1755
-		if(empty($_POST['data_checked'])) return false;
1904
+		if(empty($_POST['data_document_name']))
1905
+		{
1906
+			return false;
1907
+		}
1908
+		if(empty($_POST['data_document_dir']))
1909
+		{
1910
+			return false;
1911
+		}
1912
+		if(empty($_POST['data_checked']))
1913
+		{
1914
+			return false;
1915
+		}
1756 1916
 
1757 1917
 		return $this->download(
1758 1918
 			$_POST['data_document_name'],
@@ -1773,7 +1933,10 @@  discard block
 block discarded – undo
1773 1933
 	public static function get_documents($dirs, $prefix='document_', $mime_filter=null, $app='')
1774 1934
 	{
1775 1935
 		$export_limit=self::getExportLimit($app);
1776
-		if (!$dirs || (!self::hasExportLimit($export_limit,'ISALLOWED') && !self::is_export_limit_excepted())) return array();
1936
+		if (!$dirs || (!self::hasExportLimit($export_limit,'ISALLOWED') && !self::is_export_limit_excepted()))
1937
+		{
1938
+			return array();
1939
+		}
1777 1940
 
1778 1941
 		// split multiple comma or whitespace separated directories
1779 1942
 		// to still allow space or comma in dirnames, we also use the trailing slash of all pathes to split
@@ -1781,7 +1944,11 @@  discard block
 block discarded – undo
1781 1944
 		{
1782 1945
 			foreach($dirs as $n => &$d)
1783 1946
 			{
1784
-				if ($n) $d = '/'.$d;	// re-adding trailing slash removed by split
1947
+				if ($n)
1948
+				{
1949
+					$d = '/'.$d;
1950
+				}
1951
+				// re-adding trailing slash removed by split
1785 1952
 			}
1786 1953
 		}
1787 1954
 		if ($mime_filter && ($negativ_filter = $mime_filter[0] === '!'))
@@ -1804,8 +1971,14 @@  discard block
 block discarded – undo
1804 1971
 				{
1805 1972
 					// return only the mime-types we support
1806 1973
 					$parts = explode('.',$file['name']);
1807
-					if (!self::is_implemented($file['mime'],'.'.array_pop($parts))) continue;
1808
-					if ($mime_filter && $negativ_filter === in_array($file['mime'], (array)$mime_filter)) continue;
1974
+					if (!self::is_implemented($file['mime'],'.'.array_pop($parts)))
1975
+					{
1976
+						continue;
1977
+					}
1978
+					if ($mime_filter && $negativ_filter === in_array($file['mime'], (array)$mime_filter))
1979
+					{
1980
+						continue;
1981
+					}
1809 1982
 					$list[$prefix.$file['name']] = Api\Vfs::decodePath($file['name']);
1810 1983
 				}
1811 1984
 			}
@@ -1835,12 +2008,19 @@  discard block
 block discarded – undo
1835 2008
 		$export_limit=null)
1836 2009
 	{
1837 2010
 		$documents = array();
1838
-		if ($export_limit == null) $export_limit = self::getExportLimit(); // check if there is a globalsetting
1839
-		if ($default_doc && ($file = Api\Vfs::stat($default_doc)))	// put default document on top
2011
+		if ($export_limit == null)
2012
+		{
2013
+			$export_limit = self::getExportLimit();
2014
+		}
2015
+		// check if there is a globalsetting
2016
+		if ($default_doc && ($file = Api\Vfs::stat($default_doc)))
2017
+		{
2018
+			// put default document on top
1840 2019
 		{
1841 2020
 			if(!$file['mime'])
1842 2021
 			{
1843 2022
 				$file['mime'] = Api\Vfs::mime_content_type($default_doc);
2023
+		}
1844 2024
 				$file['path'] = $default_doc;
1845 2025
 			}
1846 2026
 			$documents['document'] = array(
@@ -1864,7 +2044,11 @@  discard block
 block discarded – undo
1864 2044
 			{
1865 2045
 				foreach($dirs as $n => &$d)
1866 2046
 				{
1867
-					if ($n) $d = '/'.$d;	// re-adding trailing slash removed by split
2047
+					if ($n)
2048
+					{
2049
+						$d = '/'.$d;
2050
+					}
2051
+					// re-adding trailing slash removed by split
1868 2052
 				}
1869 2053
 			}
1870 2054
 			foreach($dirs as $dir)
@@ -1884,10 +2068,13 @@  discard block
 block discarded – undo
1884 2068
 			$parts = explode('.',$file['name']);
1885 2069
 			if (!self::is_implemented($file['mime'],'.'.array_pop($parts)) ||
1886 2070
 				!Api\Vfs::check_access($file['path'], Api\Vfs::READABLE, $file) ||	// remove files not readable by user
1887
-				$file['path'] === $default_doc)	// default doc already added
2071
+				$file['path'] === $default_doc)
2072
+			{
2073
+				// default doc already added
1888 2074
 			{
1889 2075
 				unset($files[$key]);
1890 2076
 			}
2077
+			}
1891 2078
 			else
1892 2079
 			{
1893 2080
 				$dirname = Api\Vfs::dirname($file['path']);
@@ -2046,7 +2233,11 @@  discard block
 block discarded – undo
2046 2233
 			{
2047 2234
 				foreach($dirs as $n => $dir)
2048 2235
 				{
2049
-					if ($n) $dir = '/'.$dir;	// re-adding trailing slash removed by split
2236
+					if ($n)
2237
+					{
2238
+						$dir = '/'.$dir;
2239
+					}
2240
+					// re-adding trailing slash removed by split
2050 2241
 					if (Api\Vfs::stat($dir.'/'.$document) && Api\Vfs::is_readable($dir.'/'.$document))
2051 2242
 					{
2052 2243
 						$document = $dir.'/'.$document;
@@ -2083,7 +2274,10 @@  discard block
 block discarded – undo
2083 2274
 	 */
2084 2275
 	static public function number_format($number,$num_decimal_places=2,$_mimetype='')
2085 2276
 	{
2086
-		if ((string)$number === '') return '';
2277
+		if ((string)$number === '')
2278
+		{
2279
+			return '';
2280
+		}
2087 2281
 		//error_log(__METHOD__.$_mimetype);
2088 2282
 		switch($_mimetype)
2089 2283
 		{
Please login to merge, or discard this patch.