Passed
Push — 16.1 ( 80c42d...d90aea )
by Ralf
13:49
created
api/src/Storage/Merge.php 2 patches
Spacing   +366 added lines, -367 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,33 +1261,33 @@  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
-				if(!is_numeric($values[$key]))
1287
+				if (!is_numeric($values[$key]))
1289 1288
 				{
1290 1289
 					// Try the different formats, stop when one works
1291
-					foreach($formats as $f)
1290
+					foreach ($formats as $f)
1292 1291
 					{
1293 1292
 						try {
1294 1293
 							$date = Api\DateTime::createFromFormat(
@@ -1296,12 +1295,12 @@  discard block
 block discarded – undo
1296 1295
 								$values[$key],
1297 1296
 								Api\DateTime::$user_timezone
1298 1297
 							);
1299
-							if($date) break;
1298
+							if ($date) break;
1300 1299
 						} catch (\Exception $e) {
1301 1300
 
1302 1301
 						}
1303 1302
 					}
1304
-					if(!$date)
1303
+					if (!$date)
1305 1304
 					{
1306 1305
 						// Couldn't get a date out of it... skip it
1307 1306
 						trigger_error("Unable to parse date $key = '{$values[$key]}' - left as text", E_USER_NOTICE);
@@ -1313,17 +1312,17 @@  discard block
 block discarded – undo
1313 1312
 				{
1314 1313
 					$date = new Api\DateTime($values[$key]);
1315 1314
 				}
1316
-				if($mimetype == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ||
1315
+				if ($mimetype == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ||
1317 1316
 					$mimetype == 'application/vnd.ms-excel.sheet.macroenabled.12')//Excel WTF
1318 1317
 				{
1319 1318
 					$interval = $date->diff(new Api\DateTime('1900-01-00 0:00'));
1320
-					$values[$key] = $interval->format('%a')+1;// 1900-02-29 did not exist
1319
+					$values[$key] = $interval->format('%a') + 1; // 1900-02-29 did not exist
1321 1320
 					// 1440 minutes in a day - fractional part
1322
-					$values[$key] += ($date->format('H') * 60 + $date->format('i'))/1440;
1321
+					$values[$key] += ($date->format('H') * 60 + $date->format('i')) / 1440;
1323 1322
 				}
1324 1323
 				else
1325 1324
 				{
1326
-					$values[$key] = date('Y-m-d\TH:i:s',Api\DateTime::to($date,'ts'));
1325
+					$values[$key] = date('Y-m-d\TH:i:s', Api\DateTime::to($date, 'ts'));
1327 1326
 				}
1328 1327
 			}
1329 1328
 			else
@@ -1332,17 +1331,17 @@  discard block
 block discarded – undo
1332 1331
 			}
1333 1332
 		}
1334 1333
 
1335
-		switch($mimetype)
1334
+		switch ($mimetype)
1336 1335
 		{
1337 1336
 			case 'application/vnd.oasis.opendocument.spreadsheet':		// open office calc
1338 1337
 				// Removing these forces calc to respect our set value-type
1339
-				$content = str_ireplace('calcext:value-type="string"','',$content);
1338
+				$content = str_ireplace('calcext:value-type="string"', '', $content);
1340 1339
 
1341
-				$format = '/<table:table-cell([^>]+?)office:value-type="[^"]+"([^>]*?)>.?<([a-z].*?)[^>]*>\$\$('.implode('|',$names).')\$\$<\/\3>.?<\/table:table-cell>/s';
1340
+				$format = '/<table:table-cell([^>]+?)office:value-type="[^"]+"([^>]*?)>.?<([a-z].*?)[^>]*>\$\$('.implode('|', $names).')\$\$<\/\3>.?<\/table:table-cell>/s';
1342 1341
 				$replacement = '<table:table-cell$1office:value-type="date" office:date-value="\$\$$4\$\$"$2><$3>\$\$$4\$\$</$3></table:table-cell>';
1343 1342
 				break;
1344 1343
 			case 'application/xmlExcel.Sheet':	// Excel 2003
1345
-				$format = '/'.preg_quote('<Data ss:Type="String">','/').'..('.implode('|',$names).')..'.preg_quote('</Data>','/').'/';
1344
+				$format = '/'.preg_quote('<Data ss:Type="String">', '/').'..('.implode('|', $names).')..'.preg_quote('</Data>', '/').'/';
1346 1345
 				$replacement = '<Data ss:Type="DateTime">\$\$$1\$\$</Data>';
1347 1346
 
1348 1347
 				break;
@@ -1350,16 +1349,16 @@  discard block
 block discarded – undo
1350 1349
 			case 'application/vnd.ms-excel.sheet.macroenabled.12':
1351 1350
 				break;
1352 1351
 		}
1353
-		if($format && $names)
1352
+		if ($format && $names)
1354 1353
 		{
1355 1354
 			// Dealing with backtrack limit per AmigoJack 10-Jul-2010 comment on php.net preg-replace docs
1356 1355
 			do {
1357 1356
 				$result = preg_replace($format, $replacement, $content, -1);
1358 1357
 			}
1359 1358
 			// try to increase/double pcre.backtrack_limit failure
1360
-			while(preg_last_error() == PREG_BACKTRACK_LIMIT_ERROR && self::increase_backtrack_limit());
1359
+			while (preg_last_error() == PREG_BACKTRACK_LIMIT_ERROR && self::increase_backtrack_limit());
1361 1360
 
1362
-			if ($result) $content = $result;  // On failure $result would be NULL
1361
+			if ($result) $content = $result; // On failure $result would be NULL
1363 1362
 		}
1364 1363
 	}
1365 1364
 
@@ -1369,9 +1368,9 @@  discard block
 block discarded – undo
1369 1368
 	 */
1370 1369
 	public function cf_link_to_expand($values, $content, &$replacements, $app = null)
1371 1370
 	{
1372
-		if($app == null)
1371
+		if ($app == null)
1373 1372
 		{
1374
-			$app = str_replace('_merge','',get_class($this));
1373
+			$app = str_replace('_merge', '', get_class($this));
1375 1374
 		}
1376 1375
 		$cfs = Api\Storage\Customfields::get($app);
1377 1376
 
@@ -1382,25 +1381,25 @@  discard block
 block discarded – undo
1382 1381
 		// Placeholders that need expanded will look like {{#name/placeholder}}
1383 1382
 		$matches = null;
1384 1383
 		preg_match_all('/\${2}(([^\/#]*?\/)?)#([^$\/]+)\/(.*?)[$}]{2}/', $content, $matches);
1385
-		list($placeholders, , , $cf, $sub) = $matches;
1384
+		list($placeholders,,, $cf, $sub) = $matches;
1386 1385
 
1387 1386
 		// Collect any used custom fields from entries so you can do
1388 1387
 		// {{#other_app/#other_app_cf/n_fn}}
1389 1388
 		$expand_sub_cfs = [];
1390
-		foreach($sub as $index => $cf_sub)
1389
+		foreach ($sub as $index => $cf_sub)
1391 1390
 		{
1392
-			if(strpos($cf_sub, '#') === 0)
1391
+			if (strpos($cf_sub, '#') === 0)
1393 1392
 			{
1394
-				$expand_sub_cfs[$cf[$index]] .= '$$'.$cf_sub . '$$ ';
1393
+				$expand_sub_cfs[$cf[$index]] .= '$$'.$cf_sub.'$$ ';
1395 1394
 			}
1396 1395
 		}
1397 1396
 		$expand_sub_cfs = array_unique($expand_sub_cfs);
1398 1397
 
1399
-		foreach($cf as $index => $field)
1398
+		foreach ($cf as $index => $field)
1400 1399
 		{
1401
-			if($cfs[$field])
1400
+			if ($cfs[$field])
1402 1401
 			{
1403
-				if(in_array($cfs[$field]['type'],array_keys($GLOBALS['egw_info']['apps'])))
1402
+				if (in_array($cfs[$field]['type'], array_keys($GLOBALS['egw_info']['apps'])))
1404 1403
 				{
1405 1404
 					$field_app = $cfs[$field]['type'];
1406 1405
 				}
@@ -1411,7 +1410,7 @@  discard block
 block discarded – undo
1411 1410
 					$account = $GLOBALS['egw']->accounts->read($values['#'.$field]);
1412 1411
 					$app_replacements[$field] = $this->contact_replacements($account['person_id']);
1413 1412
 				}
1414
-				else if (($list = explode('-',$cfs[$field]['type']) && in_array($list[0], array_keys($GLOBALS['egw_info']['apps']))))
1413
+				else if (($list = explode('-', $cfs[$field]['type']) && in_array($list[0], array_keys($GLOBALS['egw_info']['apps']))))
1415 1414
 				{
1416 1415
 					// Sub-type - use app
1417 1416
 					$field_app = $list[0];
@@ -1422,7 +1421,7 @@  discard block
 block discarded – undo
1422 1421
 				}
1423 1422
 
1424 1423
 				// Get replacements for that application
1425
-				if(!$app_replacements[$field])
1424
+				if (!$app_replacements[$field])
1426 1425
 				{
1427 1426
 					$classname = "{$field_app}_merge";
1428 1427
 					$class = new $classname();
@@ -1451,33 +1450,33 @@  discard block
 block discarded – undo
1451 1450
 	 */
1452 1451
 	private function process_commands($content, $replacements)
1453 1452
 	{
1454
-		if (strpos($content,'$$IF') !== false)
1453
+		if (strpos($content, '$$IF') !== false)
1455 1454
 		{	//Example use to use: $$IF n_prefix~Herr~Sehr geehrter~Sehr geehrte$$
1456
-			$this->replacements =& $replacements;
1457
-			$content = preg_replace_callback('/\$\$IF ([#0-9a-z_\/-]+)~(.*)~(.*)~(.*)\$\$/imU',Array($this,'replace_callback'),$content);
1455
+			$this->replacements = & $replacements;
1456
+			$content = preg_replace_callback('/\$\$IF ([#0-9a-z_\/-]+)~(.*)~(.*)~(.*)\$\$/imU', Array($this, 'replace_callback'), $content);
1458 1457
 			unset($this->replacements);
1459 1458
 		}
1460
-		if (strpos($content,'$$NELF') !== false)
1459
+		if (strpos($content, '$$NELF') !== false)
1461 1460
 		{	//Example: $$NEPBR org_unit$$ sets a LF and value of org_unit, only if there is a value
1462
-			$this->replacements =& $replacements;
1463
-			$content = preg_replace_callback('/\$\$NELF ([#0-9a-z_\/-]+)\$\$/imU',Array($this,'replace_callback'),$content);
1461
+			$this->replacements = & $replacements;
1462
+			$content = preg_replace_callback('/\$\$NELF ([#0-9a-z_\/-]+)\$\$/imU', Array($this, 'replace_callback'), $content);
1464 1463
 			unset($this->replacements);
1465 1464
 		}
1466
-		if (strpos($content,'$$NENVLF') !== false)
1465
+		if (strpos($content, '$$NENVLF') !== false)
1467 1466
 		{	//Example: $$NEPBRNV org_unit$$ sets only a LF if there is a value for org_units, but did not add any value
1468
-			$this->replacements =& $replacements;
1469
-			$content = preg_replace_callback('/\$\$NENVLF ([#0-9a-z_\/-]+)\$\$/imU',Array($this,'replace_callback'),$content);
1467
+			$this->replacements = & $replacements;
1468
+			$content = preg_replace_callback('/\$\$NENVLF ([#0-9a-z_\/-]+)\$\$/imU', Array($this, 'replace_callback'), $content);
1470 1469
 			unset($this->replacements);
1471 1470
 		}
1472
-		if (strpos($content,'$$LETTERPREFIX$$') !== false)
1471
+		if (strpos($content, '$$LETTERPREFIX$$') !== false)
1473 1472
 		{	//Example use to use: $$LETTERPREFIX$$
1474 1473
 			$LETTERPREFIXCUSTOM = '$$LETTERPREFIXCUSTOM n_prefix title n_family$$';
1475
-			$content = str_replace('$$LETTERPREFIX$$',$LETTERPREFIXCUSTOM,$content);
1474
+			$content = str_replace('$$LETTERPREFIX$$', $LETTERPREFIXCUSTOM, $content);
1476 1475
 		}
1477
-		if (strpos($content,'$$LETTERPREFIXCUSTOM') !== false)
1476
+		if (strpos($content, '$$LETTERPREFIXCUSTOM') !== false)
1478 1477
 		{	//Example use to use for a custom Letter Prefix: $$LETTERPREFIX n_prefix title n_family$$
1479
-			$this->replacements =& $replacements;
1480
-			$content = preg_replace_callback('/\$\$LETTERPREFIXCUSTOM ([#0-9a-z_-]+)(.*)\$\$/imU',Array($this,'replace_callback'),$content);
1478
+			$this->replacements = & $replacements;
1479
+			$content = preg_replace_callback('/\$\$LETTERPREFIXCUSTOM ([#0-9a-z_-]+)(.*)\$\$/imU', Array($this, 'replace_callback'), $content);
1481 1480
 			unset($this->replacements);
1482 1481
 		}
1483 1482
 		return $content;
@@ -1491,16 +1490,16 @@  discard block
 block discarded – undo
1491 1490
 	 */
1492 1491
 	private function replace_callback($param)
1493 1492
 	{
1494
-		if (array_key_exists('$$'.$param[4].'$$',$this->replacements)) $param[4] = $this->replacements['$$'.$param[4].'$$'];
1495
-		if (array_key_exists('$$'.$param[3].'$$',$this->replacements)) $param[3] = $this->replacements['$$'.$param[3].'$$'];
1493
+		if (array_key_exists('$$'.$param[4].'$$', $this->replacements)) $param[4] = $this->replacements['$$'.$param[4].'$$'];
1494
+		if (array_key_exists('$$'.$param[3].'$$', $this->replacements)) $param[3] = $this->replacements['$$'.$param[3].'$$'];
1496 1495
 
1497 1496
 		$pattern = '/'.preg_quote($param[2], '/').'/';
1498
-		if (strpos($param[0],'$$IF') === 0 && (trim($param[2]) == "EMPTY" || $param[2] === ''))
1497
+		if (strpos($param[0], '$$IF') === 0 && (trim($param[2]) == "EMPTY" || $param[2] === ''))
1499 1498
 		{
1500 1499
 			$pattern = '/^$/';
1501 1500
 		}
1502
-		$replace = preg_match($pattern,$this->replacements['$$'.$param[1].'$$']) ? $param[3] : $param[4];
1503
-		switch($this->mimetype)
1501
+		$replace = preg_match($pattern, $this->replacements['$$'.$param[1].'$$']) ? $param[3] : $param[4];
1502
+		switch ($this->mimetype)
1504 1503
 		{
1505 1504
 			case 'application/vnd.oasis.opendocument.text':		// open office
1506 1505
 			case 'application/vnd.oasis.opendocument.spreadsheet':
@@ -1515,14 +1514,14 @@  discard block
 block discarded – undo
1515 1514
 				break;
1516 1515
 		}
1517 1516
 
1518
-		switch($this->mimetype)
1517
+		switch ($this->mimetype)
1519 1518
 			{
1520 1519
 				case 'application/rtf':
1521 1520
 				case 'text/rtf':
1522 1521
 					$LF = '}\par \pard\plain{';
1523 1522
 					break;
1524 1523
 				case 'application/vnd.oasis.opendocument.text':
1525
-					$LF ='<text:line-break/>';
1524
+					$LF = '<text:line-break/>';
1526 1525
 					break;
1527 1526
 				case 'application/vnd.oasis.opendocument.spreadsheet':		// open office calc
1528 1527
 					$LF = '</text:p><text:p>';
@@ -1534,10 +1533,10 @@  discard block
 block discarded – undo
1534 1533
 				case 'application/vnd.ms-word.document.macroenabled.12':
1535 1534
 				case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
1536 1535
 				case 'application/vnd.ms-excel.sheet.macroenabled.12':
1537
-					$LF ='</w:t></w:r></w:p><w:p><w:r><w:t>';
1536
+					$LF = '</w:t></w:r></w:p><w:p><w:r><w:t>';
1538 1537
 					break;
1539 1538
 				case 'application/xml';
1540
-					$LF ='</w:t></w:r><w:r><w:br w:type="text-wrapping" w:clear="all"/></w:r><w:r><w:t>';
1539
+					$LF = '</w:t></w:r><w:r><w:br w:type="text-wrapping" w:clear="all"/></w:r><w:r><w:t>';
1541 1540
 					break;
1542 1541
 				case 'text/html':
1543 1542
 					$LF = "<br/>";
@@ -1545,27 +1544,27 @@  discard block
 block discarded – undo
1545 1544
 				default:
1546 1545
 					$LF = "\n";
1547 1546
 			}
1548
-		if($is_xml) {
1549
-			$this->replacements = str_replace(array('&','&amp;amp;','<','>',"\r","\n"),array('&amp;','&amp;','&lt;','&gt;','',$LF),$this->replacements);
1547
+		if ($is_xml) {
1548
+			$this->replacements = str_replace(array('&', '&amp;amp;', '<', '>', "\r", "\n"), array('&amp;', '&amp;', '&lt;', '&gt;', '', $LF), $this->replacements);
1550 1549
 		}
1551
-		if (strpos($param[0],'$$NELF') === 0)
1550
+		if (strpos($param[0], '$$NELF') === 0)
1552 1551
 		{	//sets a Pagebreak and value, only if the field has a value
1553
-			if ($this->replacements['$$'.$param[1].'$$'] !='') $replace = $LF.$this->replacements['$$'.$param[1].'$$'];
1552
+			if ($this->replacements['$$'.$param[1].'$$'] != '') $replace = $LF.$this->replacements['$$'.$param[1].'$$'];
1554 1553
 		}
1555
-		if (strpos($param[0],'$$NENVLF') === 0)
1554
+		if (strpos($param[0], '$$NENVLF') === 0)
1556 1555
 		{	//sets a Pagebreak without any value, only if the field has a value
1557
-			if ($this->replacements['$$'.$param[1].'$$'] !='') $replace = $LF;
1556
+			if ($this->replacements['$$'.$param[1].'$$'] != '') $replace = $LF;
1558 1557
 		}
1559
-		if (strpos($param[0],'$$LETTERPREFIXCUSTOM') === 0)
1558
+		if (strpos($param[0], '$$LETTERPREFIXCUSTOM') === 0)
1560 1559
 		{	//sets a Letterprefix
1561 1560
 			$replaceprefixsort = array();
1562 1561
 			// ToDo Stefan: $contentstart is NOT defined here!!!
1563
-			$replaceprefix = explode(' ',substr($param[0],21,-2));
1562
+			$replaceprefix = explode(' ', substr($param[0], 21, -2));
1564 1563
 			foreach ($replaceprefix as $nameprefix)
1565 1564
 			{
1566
-				if ($this->replacements['$$'.$nameprefix.'$$'] !='') $replaceprefixsort[] = $this->replacements['$$'.$nameprefix.'$$'];
1565
+				if ($this->replacements['$$'.$nameprefix.'$$'] != '') $replaceprefixsort[] = $this->replacements['$$'.$nameprefix.'$$'];
1567 1566
 			}
1568
-			$replace = implode($replaceprefixsort,' ');
1567
+			$replace = implode($replaceprefixsort, ' ');
1569 1568
 		}
1570 1569
 		return $replace;
1571 1570
 	}
@@ -1579,7 +1578,7 @@  discard block
 block discarded – undo
1579 1578
 	 * @param string $dirs comma or whitespace separated directories, used if $document is a relative path
1580 1579
 	 * @return string with error-message on error, otherwise it does NOT return
1581 1580
 	 */
1582
-	public function download($document, $ids, $name='', $dirs='')
1581
+	public function download($document, $ids, $name = '', $dirs = '')
1583 1582
 	{
1584 1583
 		//error_log(__METHOD__."('$document', ".array2string($ids).", '$name', dirs='$dirs') ->".function_backtrace());
1585 1584
 		if (($error = $this->check_document($document, $dirs)))
@@ -1595,7 +1594,7 @@  discard block
 block discarded – undo
1595 1594
 				$mail_bo->openConnection();
1596 1595
 				try
1597 1596
 				{
1598
-					$msgs = $mail_bo->importMessageToMergeAndSend($this, $content_url, $ids, $_folder='');
1597
+					$msgs = $mail_bo->importMessageToMergeAndSend($this, $content_url, $ids, $_folder = '');
1599 1598
 				}
1600 1599
 				catch (Api\Exception\WrongUserinput $e)
1601 1600
 				{
@@ -1604,19 +1603,19 @@  discard block
 block discarded – undo
1604 1603
 				}
1605 1604
 				//error_log(__METHOD__.__LINE__.' Message after importMessageToMergeAndSend:'.array2string($msgs));
1606 1605
 				$retString = '';
1607
-				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']);
1606
+				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']);
1608 1607
 				//if (strlen($retString)>0) $retString .= '<br />';
1609
-				foreach($msgs['failed'] as $c =>$e)
1608
+				foreach ($msgs['failed'] as $c =>$e)
1610 1609
 				{
1611 1610
 					$errorString .= lang('contact').' '.lang('id').':'.$c.'->'.$e.'.';
1612 1611
 				}
1613
-				if (count($msgs['failed'])>0) $retString .= count($msgs['failed']).' '.lang('Message(s) send failed!').'=>'.$errorString;
1612
+				if (count($msgs['failed']) > 0) $retString .= count($msgs['failed']).' '.lang('Message(s) send failed!').'=>'.$errorString;
1614 1613
 				return $retString;
1615 1614
 			case 'application/vnd.oasis.opendocument.text':
1616 1615
 			case 'application/vnd.oasis.opendocument.spreadsheet':
1617 1616
 				$ext = $mimetype == 'application/vnd.oasis.opendocument.text' ? '.odt' : '.ods';
1618
-				$archive = tempnam($GLOBALS['egw_info']['server']['temp_dir'], basename($document,$ext).'-').$ext;
1619
-				copy($content_url,$archive);
1617
+				$archive = tempnam($GLOBALS['egw_info']['server']['temp_dir'], basename($document, $ext).'-').$ext;
1618
+				copy($content_url, $archive);
1620 1619
 				$content_url = 'zip://'.$archive.'#'.($content_file = 'content.xml');
1621 1620
 				$this->parse_html_styles = true;
1622 1621
 				break;
@@ -1624,20 +1623,20 @@  discard block
 block discarded – undo
1624 1623
 				$mimetype = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
1625 1624
 			case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
1626 1625
 			case 'application/vnd.ms-word.document.macroenabled.12':
1627
-				$archive = tempnam($GLOBALS['egw_info']['server']['temp_dir'], basename($document,'.docx').'-').'.docx';
1628
-				copy($content_url,$archive);
1626
+				$archive = tempnam($GLOBALS['egw_info']['server']['temp_dir'], basename($document, '.docx').'-').'.docx';
1627
+				copy($content_url, $archive);
1629 1628
 				$content_url = 'zip://'.$archive.'#'.($content_file = 'word/document.xml');
1630 1629
 				$fix = array(		// regular expression to fix garbled placeholders
1631
-					'/'.preg_quote('$$</w:t></w:r><w:proofErr w:type="spellStart"/><w:r><w:t>','/').'([a-z0-9_]+)'.
1632
-						preg_quote('</w:t></w:r><w:proofErr w:type="spellEnd"/><w:r><w:t>','/').'/i' => '$$\\1$$',
1633
-					'/'.preg_quote('$$</w:t></w:r><w:proofErr w:type="spellStart"/><w:r><w:rPr><w:lang w:val="','/').
1634
-						'([a-z]{2}-[A-Z]{2})'.preg_quote('"/></w:rPr><w:t>','/').'([a-z0-9_]+)'.
1635
-						preg_quote('</w:t></w:r><w:proofErr w:type="spellEnd"/><w:r><w:rPr><w:lang w:val="','/').
1636
-						'([a-z]{2}-[A-Z]{2})'.preg_quote('"/></w:rPr><w:t>$$','/').'/i' => '$$\\2$$',
1637
-					'/'.preg_quote('$</w:t></w:r><w:proofErr w:type="spellStart"/><w:r><w:t>','/').'([a-z0-9_]+)'.
1638
-						preg_quote('</w:t></w:r><w:proofErr w:type="spellEnd"/><w:r><w:t>','/').'/i' => '$\\1$',
1639
-					'/'.preg_quote('$ $</w:t></w:r><w:proofErr w:type="spellStart"/><w:r><w:t>','/').'([a-z0-9_]+)'.
1640
-						preg_quote('</w:t></w:r><w:proofErr w:type="spellEnd"/><w:r><w:t>','/').'/i' => '$ $\\1$ $',
1630
+					'/'.preg_quote('$$</w:t></w:r><w:proofErr w:type="spellStart"/><w:r><w:t>', '/').'([a-z0-9_]+)'.
1631
+						preg_quote('</w:t></w:r><w:proofErr w:type="spellEnd"/><w:r><w:t>', '/').'/i' => '$$\\1$$',
1632
+					'/'.preg_quote('$$</w:t></w:r><w:proofErr w:type="spellStart"/><w:r><w:rPr><w:lang w:val="', '/').
1633
+						'([a-z]{2}-[A-Z]{2})'.preg_quote('"/></w:rPr><w:t>', '/').'([a-z0-9_]+)'.
1634
+						preg_quote('</w:t></w:r><w:proofErr w:type="spellEnd"/><w:r><w:rPr><w:lang w:val="', '/').
1635
+						'([a-z]{2}-[A-Z]{2})'.preg_quote('"/></w:rPr><w:t>$$', '/').'/i' => '$$\\2$$',
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:t>', '/').'([a-z0-9_]+)'.
1639
+						preg_quote('</w:t></w:r><w:proofErr w:type="spellEnd"/><w:r><w:t>', '/').'/i' => '$ $\\1$ $',
1641 1640
 				);
1642 1641
 				break;
1643 1642
 			case 'application/xml':
@@ -1652,13 +1651,13 @@  discard block
 block discarded – undo
1652 1651
 				$fix = array(	// hack to get Excel 2007 to display additional rows in tables
1653 1652
 					'/ss:ExpandedRowCount="\d+"/' => 'ss:ExpandedRowCount="9999"',
1654 1653
 				);
1655
-				$archive = tempnam($GLOBALS['egw_info']['server']['temp_dir'], basename($document,'.xlsx').'-').'.xlsx';
1656
-				copy($content_url,$archive);
1654
+				$archive = tempnam($GLOBALS['egw_info']['server']['temp_dir'], basename($document, '.xlsx').'-').'.xlsx';
1655
+				copy($content_url, $archive);
1657 1656
 				$content_url = 'zip://'.$archive.'#'.($content_file = 'xl/sharedStrings.xml');
1658 1657
 				break;
1659 1658
 		}
1660 1659
 		$err = null;
1661
-		if (!($merged =& $this->merge($content_url,$ids,$err,$mimetype,$fix)))
1660
+		if (!($merged = & $this->merge($content_url, $ids, $err, $mimetype, $fix)))
1662 1661
 		{
1663 1662
 			//error_log(__METHOD__."() !this->merge() err=$err");
1664 1663
 			return $err;
@@ -1675,22 +1674,22 @@  discard block
 block discarded – undo
1675 1674
 			{
1676 1675
 				// Error converting HTML styles over
1677 1676
 				error_log($e->getMessage());
1678
-				error_log("Target document: $content_url, IDs: ". array2string($ids));
1677
+				error_log("Target document: $content_url, IDs: ".array2string($ids));
1679 1678
 
1680 1679
 				// Try again, but strip HTML so user gets something
1681 1680
 				$this->parse_html_styles = false;
1682
-				if (!($merged =& $this->merge($content_url,$ids,$err,$mimetype,$fix)))
1681
+				if (!($merged = & $this->merge($content_url, $ids, $err, $mimetype, $fix)))
1683 1682
 				{
1684 1683
 					return $err;
1685 1684
 				}
1686 1685
 			}
1687 1686
 			if ($this->report_memory_usage) error_log(__METHOD__."() after HTML processing ".Api\Vfs::hsize(memory_get_peak_usage(true)));
1688 1687
 		}
1689
-		if(!empty($name))
1688
+		if (!empty($name))
1690 1689
 		{
1691
-			if(empty($ext))
1690
+			if (empty($ext))
1692 1691
 			{
1693
-				$ext = '.'.pathinfo($document,PATHINFO_EXTENSION);
1692
+				$ext = '.'.pathinfo($document, PATHINFO_EXTENSION);
1694 1693
 			}
1695 1694
 			$name .= $ext;
1696 1695
 		}
@@ -1706,25 +1705,25 @@  discard block
 block discarded – undo
1706 1705
 				error_log(__METHOD__.__LINE__." !ZipArchive::open('$archive',ZIPARCHIVE"."::CHECKCONS) failed. Trying open without validating");
1707 1706
 				if ($zip->open($archive) !== true) throw new Api\Exception("!ZipArchive::open('$archive',|ZIPARCHIVE::CHECKCONS)");
1708 1707
 			}
1709
-			if ($zip->addFromString($content_file,$merged) !== true) throw new Api\Exception("!ZipArchive::addFromString('$content_file',\$merged)");
1708
+			if ($zip->addFromString($content_file, $merged) !== true) throw new Api\Exception("!ZipArchive::addFromString('$content_file',\$merged)");
1710 1709
 			if ($zip->close() !== true) throw new Api\Exception("!ZipArchive::close()");
1711 1710
 			unset($zip);
1712 1711
 			unset($merged);
1713 1712
 			if ($this->report_memory_usage) error_log(__METHOD__."() after ZIP processing ".Api\Vfs::hsize(memory_get_peak_usage(true)));
1714
-			Api\Header\Content::type($name,$mimetype,filesize($archive));
1715
-			readfile($archive,'r');
1713
+			Api\Header\Content::type($name, $mimetype, filesize($archive));
1714
+			readfile($archive, 'r');
1716 1715
 		}
1717 1716
 		else
1718 1717
 		{
1719 1718
 			if ($mimetype == 'application/xml')
1720 1719
 			{
1721
-				if (strpos($merged,'<?mso-application progid="Word.Document"?>') !== false)
1720
+				if (strpos($merged, '<?mso-application progid="Word.Document"?>') !== false)
1722 1721
 				{
1723
-					$mimetype = 'application/msword';	// to open it automatically in word or oowriter
1722
+					$mimetype = 'application/msword'; // to open it automatically in word or oowriter
1724 1723
 				}
1725
-				elseif (strpos($merged,'<?mso-application progid="Excel.Sheet"?>') !== false)
1724
+				elseif (strpos($merged, '<?mso-application progid="Excel.Sheet"?>') !== false)
1726 1725
 				{
1727
-					$mimetype = 'application/vnd.ms-excel';	// to open it automatically in excel or oocalc
1726
+					$mimetype = 'application/vnd.ms-excel'; // to open it automatically in excel or oocalc
1728 1727
 				}
1729 1728
 			}
1730 1729
 			Api\Header\Content::type($name, $mimetype);
@@ -1745,13 +1744,13 @@  discard block
 block discarded – undo
1745 1744
 	 */
1746 1745
 	public function download_by_request()
1747 1746
 	{
1748
-		if(empty($_POST['data_document_name'])) return false;
1749
-		if(empty($_POST['data_document_dir'])) return false;
1750
-		if(empty($_POST['data_checked'])) return false;
1747
+		if (empty($_POST['data_document_name'])) return false;
1748
+		if (empty($_POST['data_document_dir'])) return false;
1749
+		if (empty($_POST['data_checked'])) return false;
1751 1750
 
1752 1751
 		return $this->download(
1753 1752
 			$_POST['data_document_name'],
1754
-			explode(',',$_POST['data_checked']),
1753
+			explode(',', $_POST['data_checked']),
1755 1754
 			'',
1756 1755
 			$_POST['data_document_dir']
1757 1756
 		);
@@ -1765,18 +1764,18 @@  discard block
 block discarded – undo
1765 1764
 	 * @param array|string $mime_filter=null allowed mime type(s), default all, negative filter if $mime_filter[0] === '!'
1766 1765
 	 * @return array List of documents, suitable for a selectbox.  The key is document_<filename>.
1767 1766
 	 */
1768
-	public static function get_documents($dirs, $prefix='document_', $mime_filter=null, $app='')
1767
+	public static function get_documents($dirs, $prefix = 'document_', $mime_filter = null, $app = '')
1769 1768
 	{
1770
-		$export_limit=self::getExportLimit($app);
1771
-		if (!$dirs || (!self::hasExportLimit($export_limit,'ISALLOWED') && !self::is_export_limit_excepted())) return array();
1769
+		$export_limit = self::getExportLimit($app);
1770
+		if (!$dirs || (!self::hasExportLimit($export_limit, 'ISALLOWED') && !self::is_export_limit_excepted())) return array();
1772 1771
 
1773 1772
 		// split multiple comma or whitespace separated directories
1774 1773
 		// to still allow space or comma in dirnames, we also use the trailing slash of all pathes to split
1775 1774
 		if (count($dirs = preg_split('/[,\s]+\//', $dirs)) > 1)
1776 1775
 		{
1777
-			foreach($dirs as $n => &$d)
1776
+			foreach ($dirs as $n => &$d)
1778 1777
 			{
1779
-				if ($n) $d = '/'.$d;	// re-adding trailing slash removed by split
1778
+				if ($n) $d = '/'.$d; // re-adding trailing slash removed by split
1780 1779
 			}
1781 1780
 		}
1782 1781
 		if ($mime_filter && ($negativ_filter = $mime_filter[0] === '!'))
@@ -1791,15 +1790,15 @@  discard block
 block discarded – undo
1791 1790
 			}
1792 1791
 		}
1793 1792
 		$list = array();
1794
-		foreach($dirs as $dir)
1793
+		foreach ($dirs as $dir)
1795 1794
 		{
1796
-			if (($files = Api\Vfs::find($dir,array('need_mime'=>true),true)))
1795
+			if (($files = Api\Vfs::find($dir, array('need_mime'=>true), true)))
1797 1796
 			{
1798
-				foreach($files as $file)
1797
+				foreach ($files as $file)
1799 1798
 				{
1800 1799
 					// return only the mime-types we support
1801
-					$parts = explode('.',$file['name']);
1802
-					if (!self::is_implemented($file['mime'],'.'.array_pop($parts))) continue;
1800
+					$parts = explode('.', $file['name']);
1801
+					if (!self::is_implemented($file['mime'], '.'.array_pop($parts))) continue;
1803 1802
 					if ($mime_filter && $negativ_filter === in_array($file['mime'], (array)$mime_filter)) continue;
1804 1803
 					$list[$prefix.$file['name']] = Api\Vfs::decodePath($file['name']);
1805 1804
 				}
@@ -1826,14 +1825,14 @@  discard block
 block discarded – undo
1826 1825
 	 * @param int|string $export_limit =null export-limit, default $GLOBALS['egw_info']['server']['export_limit']
1827 1826
 	 * @return array see nextmatch_widget::egw_actions
1828 1827
 	 */
1829
-	public static function document_action($dirs, $group=0, $caption='Insert in document', $prefix='document_', $default_doc='',
1830
-		$export_limit=null)
1828
+	public static function document_action($dirs, $group = 0, $caption = 'Insert in document', $prefix = 'document_', $default_doc = '',
1829
+		$export_limit = null)
1831 1830
 	{
1832 1831
 		$documents = array();
1833 1832
 		if ($export_limit == null) $export_limit = self::getExportLimit(); // check if there is a globalsetting
1834 1833
 		if ($default_doc && ($file = Api\Vfs::stat($default_doc)))	// put default document on top
1835 1834
 		{
1836
-			if(!$file['mime'])
1835
+			if (!$file['mime'])
1837 1836
 			{
1838 1837
 				$file['mime'] = Api\Vfs::mime_content_type($default_doc);
1839 1838
 				$file['path'] = $default_doc;
@@ -1842,7 +1841,7 @@  discard block
 block discarded – undo
1842 1841
 				'icon' => Api\Vfs::mime_icon($file['mime']),
1843 1842
 				'caption' => Api\Vfs::decodePath(Api\Vfs::basename($default_doc)),
1844 1843
 				'group' => 1,
1845
-				'postSubmit' => true,	// download needs post submit (not Ajax) to work
1844
+				'postSubmit' => true, // download needs post submit (not Ajax) to work
1846 1845
 			);
1847 1846
 			if ($file['mime'] == 'message/rfc822')
1848 1847
 			{
@@ -1857,28 +1856,28 @@  discard block
 block discarded – undo
1857 1856
 			// to still allow space or comma in dirnames, we also use the trailing slash of all pathes to split
1858 1857
 			if (count($dirs = preg_split('/[,\s]+\//', $dirs)) > 1)
1859 1858
 			{
1860
-				foreach($dirs as $n => &$d)
1859
+				foreach ($dirs as $n => &$d)
1861 1860
 				{
1862
-					if ($n) $d = '/'.$d;	// re-adding trailing slash removed by split
1861
+					if ($n) $d = '/'.$d; // re-adding trailing slash removed by split
1863 1862
 				}
1864 1863
 			}
1865
-			foreach($dirs as $dir)
1864
+			foreach ($dirs as $dir)
1866 1865
 			{
1867
-				$files += Api\Vfs::find($dir,array(
1866
+				$files += Api\Vfs::find($dir, array(
1868 1867
 					'need_mime' => true,
1869 1868
 					'order' => 'fs_name',
1870 1869
 					'sort' => 'ASC',
1871
-				),true);
1870
+				), true);
1872 1871
 			}
1873 1872
 		}
1874 1873
 
1875 1874
 		$dircount = array();
1876
-		foreach($files as $key => $file)
1875
+		foreach ($files as $key => $file)
1877 1876
 		{
1878 1877
 			// use only the mime-types we support
1879
-			$parts = explode('.',$file['name']);
1880
-			if (!self::is_implemented($file['mime'],'.'.array_pop($parts)) ||
1881
-				!Api\Vfs::check_access($file['path'], Api\Vfs::READABLE, $file) ||	// remove files not readable by user
1878
+			$parts = explode('.', $file['name']);
1879
+			if (!self::is_implemented($file['mime'], '.'.array_pop($parts)) ||
1880
+				!Api\Vfs::check_access($file['path'], Api\Vfs::READABLE, $file) || // remove files not readable by user
1882 1881
 				$file['path'] === $default_doc)	// default doc already added
1883 1882
 			{
1884 1883
 				unset($files[$key]);
@@ -1886,40 +1885,40 @@  discard block
 block discarded – undo
1886 1885
 			else
1887 1886
 			{
1888 1887
 				$dirname = Api\Vfs::dirname($file['path']);
1889
-				if(!isset($dircount[$dirname]))
1888
+				if (!isset($dircount[$dirname]))
1890 1889
 				{
1891 1890
 					$dircount[$dirname] = 1;
1892 1891
 				}
1893 1892
 				else
1894 1893
 				{
1895
-					$dircount[$dirname] ++;
1894
+					$dircount[$dirname]++;
1896 1895
 				}
1897 1896
 			}
1898 1897
 		}
1899
-		foreach($files as $file)
1898
+		foreach ($files as $file)
1900 1899
 		{
1901 1900
 			if (count($dircount) > 1)
1902 1901
 			{
1903 1902
 				$name_arr = explode('/', $file['name']);
1904 1903
 				$current_level = &$documents;
1905
-				for($count = 0; $count < count($name_arr); $count++)
1904
+				for ($count = 0; $count < count($name_arr); $count++)
1906 1905
 				{
1907
-					if($count == 0)
1906
+					if ($count == 0)
1908 1907
 					{
1909 1908
 						$current_level = &$documents;
1910 1909
 					}
1911 1910
 					else
1912 1911
 					{
1913
-						$current_level = &$current_level[$prefix.$name_arr[($count-1)]]['children'];
1912
+						$current_level = &$current_level[$prefix.$name_arr[($count - 1)]]['children'];
1914 1913
 					}
1915
-					switch($count)
1914
+					switch ($count)
1916 1915
 					{
1917
-						case (count($name_arr)-1):
1916
+						case (count($name_arr) - 1):
1918 1917
 							$current_level[$prefix.$file['name']] = array(
1919 1918
 								'icon'		=> Api\Vfs::mime_icon($file['mime']),
1920 1919
 								'caption'	=> Api\Vfs::decodePath($name_arr[$count]),
1921 1920
 								'group'		=> 2,
1922
-								'postSubmit' => true,	// download needs post submit (not Ajax) to work
1921
+								'postSubmit' => true, // download needs post submit (not Ajax) to work
1923 1922
 							);
1924 1923
 							if ($file['mime'] == 'message/rfc822')
1925 1924
 							{
@@ -1928,7 +1927,7 @@  discard block
 block discarded – undo
1928 1927
 							break;
1929 1928
 
1930 1929
 						default:
1931
-							if(!is_array($current_level[$prefix.$name_arr[$count]]))
1930
+							if (!is_array($current_level[$prefix.$name_arr[$count]]))
1932 1931
 							{
1933 1932
 								// create parent folder
1934 1933
 								$current_level[$prefix.$name_arr[$count]] = array(
@@ -1955,7 +1954,7 @@  discard block
 block discarded – undo
1955 1954
 				}
1956 1955
 				$documents[$file['mime']]['children'][$prefix.$file['name']] = array(
1957 1956
 					'caption' => Api\Vfs::decodePath($file['name']),
1958
-					'postSubmit' => true,	// download needs post submit (not Ajax) to work
1957
+					'postSubmit' => true, // download needs post submit (not Ajax) to work
1959 1958
 				);
1960 1959
 				if ($file['mime'] == 'message/rfc822')
1961 1960
 				{
@@ -1968,7 +1967,7 @@  discard block
 block discarded – undo
1968 1967
 					'icon' => Api\Vfs::mime_icon($file['mime']),
1969 1968
 					'caption' => Api\Vfs::decodePath($file['name']),
1970 1969
 					'group' => 2,
1971
-					'postSubmit' => true,	// download needs post submit (not Ajax) to work
1970
+					'postSubmit' => true, // download needs post submit (not Ajax) to work
1972 1971
 				);
1973 1972
 				if ($file['mime'] == 'message/rfc822')
1974 1973
 				{
@@ -1982,8 +1981,8 @@  discard block
 block discarded – undo
1982 1981
 			'caption' => $caption,
1983 1982
 			'children' => $documents,
1984 1983
 			// disable action if no document or export completly forbidden for non-admins
1985
-			'enabled' => (boolean)$documents && (self::hasExportLimit($export_limit,'ISALLOWED') || self::is_export_limit_excepted()),
1986
-			'hideOnDisabled' => true,	// do not show 'Insert in document', if no documents defined or no export allowed
1984
+			'enabled' => (boolean)$documents && (self::hasExportLimit($export_limit, 'ISALLOWED') || self::is_export_limit_excepted()),
1985
+			'hideOnDisabled' => true, // do not show 'Insert in document', if no documents defined or no export allowed
1987 1986
 			'group' => $group,
1988 1987
 		);
1989 1988
 	}
@@ -2014,14 +2013,14 @@  discard block
 block discarded – undo
2014 2013
 		);
2015 2014
 
2016 2015
 		// egw.open() used if only 1 row selected
2017
-		$action['egw_open'] = 'edit-mail--'.implode('&',$extra);
2018
-		$action['target'] = 'compose_' .$file['path'];
2016
+		$action['egw_open'] = 'edit-mail--'.implode('&', $extra);
2017
+		$action['target'] = 'compose_'.$file['path'];
2019 2018
 
2020 2019
 		// long_task runs menuaction once for each selected row
2021 2020
 		$action['nm_action'] = 'long_task';
2022 2021
 		$action['popup'] = Api\Link::get_registry('mail', 'edit_popup');
2023
-		$action['message'] = lang('insert in %1',Api\Vfs::decodePath($file['name']));
2024
-		$action['menuaction'] = 'mail.mail_compose.ajax_merge&document='.$file['path'].'&merge='. get_called_class();
2022
+		$action['message'] = lang('insert in %1', Api\Vfs::decodePath($file['name']));
2023
+		$action['menuaction'] = 'mail.mail_compose.ajax_merge&document='.$file['path'].'&merge='.get_called_class();
2025 2024
 	}
2026 2025
 
2027 2026
 	/**
@@ -2033,15 +2032,15 @@  discard block
 block discarded – undo
2033 2032
 	 */
2034 2033
 	public static function check_document(&$document, $dirs)
2035 2034
 	{
2036
-		if($document[0] !== '/')
2035
+		if ($document[0] !== '/')
2037 2036
 		{
2038 2037
 			// split multiple comma or whitespace separated directories
2039 2038
 			// to still allow space or comma in dirnames, we also use the trailing slash of all pathes to split
2040 2039
 			if ($dirs && ($dirs = preg_split('/[,\s]+\//', $dirs)))
2041 2040
 			{
2042
-				foreach($dirs as $n => $dir)
2041
+				foreach ($dirs as $n => $dir)
2043 2042
 				{
2044
-					if ($n) $dir = '/'.$dir;	// re-adding trailing slash removed by split
2043
+					if ($n) $dir = '/'.$dir; // re-adding trailing slash removed by split
2045 2044
 					if (Api\Vfs::stat($dir.'/'.$document) && Api\Vfs::is_readable($dir.'/'.$document))
2046 2045
 					{
2047 2046
 						$document = $dir.'/'.$document;
@@ -2055,7 +2054,7 @@  discard block
 block discarded – undo
2055 2054
 			return false;
2056 2055
 		}
2057 2056
 		//error_log(__METHOD__."('$document', dirs='$dirs') returning 'Document '$document' does not exist or is not readable for you!'");
2058
-		return lang("Document '%1' does not exist or is not readable for you!",$document);
2057
+		return lang("Document '%1' does not exist or is not readable for you!", $document);
2059 2058
 	}
2060 2059
 
2061 2060
 	/**
@@ -2076,16 +2075,16 @@  discard block
 block discarded – undo
2076 2075
 	 * @param string $_mimetype =''
2077 2076
 	 * @return string
2078 2077
 	 */
2079
-	static public function number_format($number,$num_decimal_places=2,$_mimetype='')
2078
+	static public function number_format($number, $num_decimal_places = 2, $_mimetype = '')
2080 2079
 	{
2081 2080
 		if ((string)$number === '') return '';
2082 2081
 		//error_log(__METHOD__.$_mimetype);
2083
-		switch($_mimetype)
2082
+		switch ($_mimetype)
2084 2083
 		{
2085 2084
 			case 'application/xml':	// Excel 2003
2086 2085
 			case 'application/vnd.oasis.opendocument.spreadsheet': // OO.o spreadsheet
2087
-				return number_format(str_replace(' ','',$number),$num_decimal_places,'.','');
2086
+				return number_format(str_replace(' ', '', $number), $num_decimal_places, '.', '');
2088 2087
 		}
2089
-		return Api\Etemplate::number_format($number,$num_decimal_places);
2088
+		return Api\Etemplate::number_format($number, $num_decimal_places);
2090 2089
 	}
2091 2090
 }
Please login to merge, or discard this patch.
Braces   +274 added lines, -76 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(
@@ -1296,8 +1391,12 @@  discard block
 block discarded – undo
1296 1391
 								$values[$key],
1297 1392
 								Api\DateTime::$user_timezone
1298 1393
 							);
1299
-							if($date) break;
1300
-						} catch (\Exception $e) {
1394
+							if($date)
1395
+							{
1396
+								break;
1397
+							}
1398
+						}
1399
+						catch (\Exception $e) {
1301 1400
 
1302 1401
 						}
1303 1402
 					}
@@ -1314,9 +1413,12 @@  discard block
 block discarded – undo
1314 1413
 					$date = new Api\DateTime($values[$key]);
1315 1414
 				}
1316 1415
 				if($mimetype == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ||
1317
-					$mimetype == 'application/vnd.ms-excel.sheet.macroenabled.12')//Excel WTF
1416
+					$mimetype == 'application/vnd.ms-excel.sheet.macroenabled.12')
1417
+				{
1418
+					//Excel WTF
1318 1419
 				{
1319 1420
 					$interval = $date->diff(new Api\DateTime('1900-01-00 0:00'));
1421
+				}
1320 1422
 					$values[$key] = $interval->format('%a')+1;// 1900-02-29 did not exist
1321 1423
 					// 1440 minutes in a day - fractional part
1322 1424
 					$values[$key] += ($date->format('H') * 60 + $date->format('i'))/1440;
@@ -1359,7 +1461,11 @@  discard block
 block discarded – undo
1359 1461
 			// try to increase/double pcre.backtrack_limit failure
1360 1462
 			while(preg_last_error() == PREG_BACKTRACK_LIMIT_ERROR && self::increase_backtrack_limit());
1361 1463
 
1362
-			if ($result) $content = $result;  // On failure $result would be NULL
1464
+			if ($result)
1465
+			{
1466
+				$content = $result;
1467
+			}
1468
+			// On failure $result would be NULL
1363 1469
 		}
1364 1470
 	}
1365 1471
 
@@ -1436,7 +1542,10 @@  discard block
 block discarded – undo
1436 1542
 			}
1437 1543
 			else
1438 1544
 			{
1439
-				if ($cfs[$field]['type'] == 'date' || $cfs[$field]['type'] == 'date-time') $this->date_fields[] = '#'.$field;
1545
+				if ($cfs[$field]['type'] == 'date' || $cfs[$field]['type'] == 'date-time')
1546
+				{
1547
+					$this->date_fields[] = '#'.$field;
1548
+				}
1440 1549
 			}
1441 1550
 		}
1442 1551
 	}
@@ -1452,30 +1561,35 @@  discard block
 block discarded – undo
1452 1561
 	private function process_commands($content, $replacements)
1453 1562
 	{
1454 1563
 		if (strpos($content,'$$IF') !== false)
1455
-		{	//Example use to use: $$IF n_prefix~Herr~Sehr geehrter~Sehr geehrte$$
1564
+		{
1565
+//Example use to use: $$IF n_prefix~Herr~Sehr geehrter~Sehr geehrte$$
1456 1566
 			$this->replacements =& $replacements;
1457 1567
 			$content = preg_replace_callback('/\$\$IF ([#0-9a-z_\/-]+)~(.*)~(.*)~(.*)\$\$/imU',Array($this,'replace_callback'),$content);
1458 1568
 			unset($this->replacements);
1459 1569
 		}
1460 1570
 		if (strpos($content,'$$NELF') !== false)
1461
-		{	//Example: $$NEPBR org_unit$$ sets a LF and value of org_unit, only if there is a value
1571
+		{
1572
+//Example: $$NEPBR org_unit$$ sets a LF and value of org_unit, only if there is a value
1462 1573
 			$this->replacements =& $replacements;
1463 1574
 			$content = preg_replace_callback('/\$\$NELF ([#0-9a-z_\/-]+)\$\$/imU',Array($this,'replace_callback'),$content);
1464 1575
 			unset($this->replacements);
1465 1576
 		}
1466 1577
 		if (strpos($content,'$$NENVLF') !== false)
1467
-		{	//Example: $$NEPBRNV org_unit$$ sets only a LF if there is a value for org_units, but did not add any value
1578
+		{
1579
+//Example: $$NEPBRNV org_unit$$ sets only a LF if there is a value for org_units, but did not add any value
1468 1580
 			$this->replacements =& $replacements;
1469 1581
 			$content = preg_replace_callback('/\$\$NENVLF ([#0-9a-z_\/-]+)\$\$/imU',Array($this,'replace_callback'),$content);
1470 1582
 			unset($this->replacements);
1471 1583
 		}
1472 1584
 		if (strpos($content,'$$LETTERPREFIX$$') !== false)
1473
-		{	//Example use to use: $$LETTERPREFIX$$
1585
+		{
1586
+//Example use to use: $$LETTERPREFIX$$
1474 1587
 			$LETTERPREFIXCUSTOM = '$$LETTERPREFIXCUSTOM n_prefix title n_family$$';
1475 1588
 			$content = str_replace('$$LETTERPREFIX$$',$LETTERPREFIXCUSTOM,$content);
1476 1589
 		}
1477 1590
 		if (strpos($content,'$$LETTERPREFIXCUSTOM') !== false)
1478
-		{	//Example use to use for a custom Letter Prefix: $$LETTERPREFIX n_prefix title n_family$$
1591
+		{
1592
+//Example use to use for a custom Letter Prefix: $$LETTERPREFIX n_prefix title n_family$$
1479 1593
 			$this->replacements =& $replacements;
1480 1594
 			$content = preg_replace_callback('/\$\$LETTERPREFIXCUSTOM ([#0-9a-z_-]+)(.*)\$\$/imU',Array($this,'replace_callback'),$content);
1481 1595
 			unset($this->replacements);
@@ -1491,8 +1605,14 @@  discard block
 block discarded – undo
1491 1605
 	 */
1492 1606
 	private function replace_callback($param)
1493 1607
 	{
1494
-		if (array_key_exists('$$'.$param[4].'$$',$this->replacements)) $param[4] = $this->replacements['$$'.$param[4].'$$'];
1495
-		if (array_key_exists('$$'.$param[3].'$$',$this->replacements)) $param[3] = $this->replacements['$$'.$param[3].'$$'];
1608
+		if (array_key_exists('$$'.$param[4].'$$',$this->replacements))
1609
+		{
1610
+			$param[4] = $this->replacements['$$'.$param[4].'$$'];
1611
+		}
1612
+		if (array_key_exists('$$'.$param[3].'$$',$this->replacements))
1613
+		{
1614
+			$param[3] = $this->replacements['$$'.$param[3].'$$'];
1615
+		}
1496 1616
 
1497 1617
 		$pattern = '/'.preg_quote($param[2], '/').'/';
1498 1618
 		if (strpos($param[0],'$$IF') === 0 && (trim($param[2]) == "EMPTY" || $param[2] === ''))
@@ -1516,7 +1636,7 @@  discard block
 block discarded – undo
1516 1636
 		}
1517 1637
 
1518 1638
 		switch($this->mimetype)
1519
-			{
1639
+		{
1520 1640
 				case 'application/rtf':
1521 1641
 				case 'text/rtf':
1522 1642
 					$LF = '}\par \pard\plain{';
@@ -1545,25 +1665,38 @@  discard block
 block discarded – undo
1545 1665
 				default:
1546 1666
 					$LF = "\n";
1547 1667
 			}
1548
-		if($is_xml) {
1668
+		if($is_xml)
1669
+		{
1549 1670
 			$this->replacements = str_replace(array('&','&amp;amp;','<','>',"\r","\n"),array('&amp;','&amp;','&lt;','&gt;','',$LF),$this->replacements);
1550 1671
 		}
1551 1672
 		if (strpos($param[0],'$$NELF') === 0)
1552
-		{	//sets a Pagebreak and value, only if the field has a value
1553
-			if ($this->replacements['$$'.$param[1].'$$'] !='') $replace = $LF.$this->replacements['$$'.$param[1].'$$'];
1673
+		{
1674
+//sets a Pagebreak and value, only if the field has a value
1675
+			if ($this->replacements['$$'.$param[1].'$$'] !='')
1676
+			{
1677
+				$replace = $LF.$this->replacements['$$'.$param[1].'$$'];
1678
+			}
1554 1679
 		}
1555 1680
 		if (strpos($param[0],'$$NENVLF') === 0)
1556
-		{	//sets a Pagebreak without any value, only if the field has a value
1557
-			if ($this->replacements['$$'.$param[1].'$$'] !='') $replace = $LF;
1681
+		{
1682
+//sets a Pagebreak without any value, only if the field has a value
1683
+			if ($this->replacements['$$'.$param[1].'$$'] !='')
1684
+			{
1685
+				$replace = $LF;
1686
+			}
1558 1687
 		}
1559 1688
 		if (strpos($param[0],'$$LETTERPREFIXCUSTOM') === 0)
1560
-		{	//sets a Letterprefix
1689
+		{
1690
+//sets a Letterprefix
1561 1691
 			$replaceprefixsort = array();
1562 1692
 			// ToDo Stefan: $contentstart is NOT defined here!!!
1563 1693
 			$replaceprefix = explode(' ',substr($param[0],21,-2));
1564 1694
 			foreach ($replaceprefix as $nameprefix)
1565 1695
 			{
1566
-				if ($this->replacements['$$'.$nameprefix.'$$'] !='') $replaceprefixsort[] = $this->replacements['$$'.$nameprefix.'$$'];
1696
+				if ($this->replacements['$$'.$nameprefix.'$$'] !='')
1697
+				{
1698
+					$replaceprefixsort[] = $this->replacements['$$'.$nameprefix.'$$'];
1699
+				}
1567 1700
 			}
1568 1701
 			$replace = implode($replaceprefixsort,' ');
1569 1702
 		}
@@ -1604,13 +1737,20 @@  discard block
 block discarded – undo
1604 1737
 				}
1605 1738
 				//error_log(__METHOD__.__LINE__.' Message after importMessageToMergeAndSend:'.array2string($msgs));
1606 1739
 				$retString = '';
1607
-				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']);
1740
+				if (count($msgs['success'])>0)
1741
+				{
1742
+					$retString .= count($msgs['success']).' '.(count($msgs['success'])+count($msgs['failed'])==1?lang('Message prepared for sending.'):lang('Message(s) send ok.'));
1743
+				}
1744
+				//implode('<br />',$msgs['success']);
1608 1745
 				//if (strlen($retString)>0) $retString .= '<br />';
1609 1746
 				foreach($msgs['failed'] as $c =>$e)
1610 1747
 				{
1611 1748
 					$errorString .= lang('contact').' '.lang('id').':'.$c.'->'.$e.'.';
1612 1749
 				}
1613
-				if (count($msgs['failed'])>0) $retString .= count($msgs['failed']).' '.lang('Message(s) send failed!').'=>'.$errorString;
1750
+				if (count($msgs['failed'])>0)
1751
+				{
1752
+					$retString .= count($msgs['failed']).' '.lang('Message(s) send failed!').'=>'.$errorString;
1753
+				}
1614 1754
 				return $retString;
1615 1755
 			case 'application/vnd.oasis.opendocument.text':
1616 1756
 			case 'application/vnd.oasis.opendocument.spreadsheet':
@@ -1684,7 +1824,10 @@  discard block
 block discarded – undo
1684 1824
 					return $err;
1685 1825
 				}
1686 1826
 			}
1687
-			if ($this->report_memory_usage) error_log(__METHOD__."() after HTML processing ".Api\Vfs::hsize(memory_get_peak_usage(true)));
1827
+			if ($this->report_memory_usage)
1828
+			{
1829
+				error_log(__METHOD__."() after HTML processing ".Api\Vfs::hsize(memory_get_peak_usage(true)));
1830
+			}
1688 1831
 		}
1689 1832
 		if(!empty($name))
1690 1833
 		{
@@ -1704,13 +1847,25 @@  discard block
 block discarded – undo
1704 1847
 			if ($zip->open($archive, ZipArchive::CHECKCONS) !== true)
1705 1848
 			{
1706 1849
 				error_log(__METHOD__.__LINE__." !ZipArchive::open('$archive',ZIPARCHIVE"."::CHECKCONS) failed. Trying open without validating");
1707
-				if ($zip->open($archive) !== true) throw new Api\Exception("!ZipArchive::open('$archive',|ZIPARCHIVE::CHECKCONS)");
1850
+				if ($zip->open($archive) !== true)
1851
+				{
1852
+					throw new Api\Exception("!ZipArchive::open('$archive',|ZIPARCHIVE::CHECKCONS)");
1853
+				}
1854
+			}
1855
+			if ($zip->addFromString($content_file,$merged) !== true)
1856
+			{
1857
+				throw new Api\Exception("!ZipArchive::addFromString('$content_file',\$merged)");
1858
+			}
1859
+			if ($zip->close() !== true)
1860
+			{
1861
+				throw new Api\Exception("!ZipArchive::close()");
1708 1862
 			}
1709
-			if ($zip->addFromString($content_file,$merged) !== true) throw new Api\Exception("!ZipArchive::addFromString('$content_file',\$merged)");
1710
-			if ($zip->close() !== true) throw new Api\Exception("!ZipArchive::close()");
1711 1863
 			unset($zip);
1712 1864
 			unset($merged);
1713
-			if ($this->report_memory_usage) error_log(__METHOD__."() after ZIP processing ".Api\Vfs::hsize(memory_get_peak_usage(true)));
1865
+			if ($this->report_memory_usage)
1866
+			{
1867
+				error_log(__METHOD__."() after ZIP processing ".Api\Vfs::hsize(memory_get_peak_usage(true)));
1868
+			}
1714 1869
 			Api\Header\Content::type($name,$mimetype,filesize($archive));
1715 1870
 			readfile($archive,'r');
1716 1871
 		}
@@ -1745,9 +1900,18 @@  discard block
 block discarded – undo
1745 1900
 	 */
1746 1901
 	public function download_by_request()
1747 1902
 	{
1748
-		if(empty($_POST['data_document_name'])) return false;
1749
-		if(empty($_POST['data_document_dir'])) return false;
1750
-		if(empty($_POST['data_checked'])) return false;
1903
+		if(empty($_POST['data_document_name']))
1904
+		{
1905
+			return false;
1906
+		}
1907
+		if(empty($_POST['data_document_dir']))
1908
+		{
1909
+			return false;
1910
+		}
1911
+		if(empty($_POST['data_checked']))
1912
+		{
1913
+			return false;
1914
+		}
1751 1915
 
1752 1916
 		return $this->download(
1753 1917
 			$_POST['data_document_name'],
@@ -1768,7 +1932,10 @@  discard block
 block discarded – undo
1768 1932
 	public static function get_documents($dirs, $prefix='document_', $mime_filter=null, $app='')
1769 1933
 	{
1770 1934
 		$export_limit=self::getExportLimit($app);
1771
-		if (!$dirs || (!self::hasExportLimit($export_limit,'ISALLOWED') && !self::is_export_limit_excepted())) return array();
1935
+		if (!$dirs || (!self::hasExportLimit($export_limit,'ISALLOWED') && !self::is_export_limit_excepted()))
1936
+		{
1937
+			return array();
1938
+		}
1772 1939
 
1773 1940
 		// split multiple comma or whitespace separated directories
1774 1941
 		// to still allow space or comma in dirnames, we also use the trailing slash of all pathes to split
@@ -1776,7 +1943,11 @@  discard block
 block discarded – undo
1776 1943
 		{
1777 1944
 			foreach($dirs as $n => &$d)
1778 1945
 			{
1779
-				if ($n) $d = '/'.$d;	// re-adding trailing slash removed by split
1946
+				if ($n)
1947
+				{
1948
+					$d = '/'.$d;
1949
+				}
1950
+				// re-adding trailing slash removed by split
1780 1951
 			}
1781 1952
 		}
1782 1953
 		if ($mime_filter && ($negativ_filter = $mime_filter[0] === '!'))
@@ -1799,8 +1970,14 @@  discard block
 block discarded – undo
1799 1970
 				{
1800 1971
 					// return only the mime-types we support
1801 1972
 					$parts = explode('.',$file['name']);
1802
-					if (!self::is_implemented($file['mime'],'.'.array_pop($parts))) continue;
1803
-					if ($mime_filter && $negativ_filter === in_array($file['mime'], (array)$mime_filter)) continue;
1973
+					if (!self::is_implemented($file['mime'],'.'.array_pop($parts)))
1974
+					{
1975
+						continue;
1976
+					}
1977
+					if ($mime_filter && $negativ_filter === in_array($file['mime'], (array)$mime_filter))
1978
+					{
1979
+						continue;
1980
+					}
1804 1981
 					$list[$prefix.$file['name']] = Api\Vfs::decodePath($file['name']);
1805 1982
 				}
1806 1983
 			}
@@ -1830,12 +2007,19 @@  discard block
 block discarded – undo
1830 2007
 		$export_limit=null)
1831 2008
 	{
1832 2009
 		$documents = array();
1833
-		if ($export_limit == null) $export_limit = self::getExportLimit(); // check if there is a globalsetting
1834
-		if ($default_doc && ($file = Api\Vfs::stat($default_doc)))	// put default document on top
2010
+		if ($export_limit == null)
2011
+		{
2012
+			$export_limit = self::getExportLimit();
2013
+		}
2014
+		// check if there is a globalsetting
2015
+		if ($default_doc && ($file = Api\Vfs::stat($default_doc)))
2016
+		{
2017
+			// put default document on top
1835 2018
 		{
1836 2019
 			if(!$file['mime'])
1837 2020
 			{
1838 2021
 				$file['mime'] = Api\Vfs::mime_content_type($default_doc);
2022
+		}
1839 2023
 				$file['path'] = $default_doc;
1840 2024
 			}
1841 2025
 			$documents['document'] = array(
@@ -1859,7 +2043,11 @@  discard block
 block discarded – undo
1859 2043
 			{
1860 2044
 				foreach($dirs as $n => &$d)
1861 2045
 				{
1862
-					if ($n) $d = '/'.$d;	// re-adding trailing slash removed by split
2046
+					if ($n)
2047
+					{
2048
+						$d = '/'.$d;
2049
+					}
2050
+					// re-adding trailing slash removed by split
1863 2051
 				}
1864 2052
 			}
1865 2053
 			foreach($dirs as $dir)
@@ -1879,10 +2067,13 @@  discard block
 block discarded – undo
1879 2067
 			$parts = explode('.',$file['name']);
1880 2068
 			if (!self::is_implemented($file['mime'],'.'.array_pop($parts)) ||
1881 2069
 				!Api\Vfs::check_access($file['path'], Api\Vfs::READABLE, $file) ||	// remove files not readable by user
1882
-				$file['path'] === $default_doc)	// default doc already added
2070
+				$file['path'] === $default_doc)
2071
+			{
2072
+				// default doc already added
1883 2073
 			{
1884 2074
 				unset($files[$key]);
1885 2075
 			}
2076
+			}
1886 2077
 			else
1887 2078
 			{
1888 2079
 				$dirname = Api\Vfs::dirname($file['path']);
@@ -2041,7 +2232,11 @@  discard block
 block discarded – undo
2041 2232
 			{
2042 2233
 				foreach($dirs as $n => $dir)
2043 2234
 				{
2044
-					if ($n) $dir = '/'.$dir;	// re-adding trailing slash removed by split
2235
+					if ($n)
2236
+					{
2237
+						$dir = '/'.$dir;
2238
+					}
2239
+					// re-adding trailing slash removed by split
2045 2240
 					if (Api\Vfs::stat($dir.'/'.$document) && Api\Vfs::is_readable($dir.'/'.$document))
2046 2241
 					{
2047 2242
 						$document = $dir.'/'.$document;
@@ -2078,7 +2273,10 @@  discard block
 block discarded – undo
2078 2273
 	 */
2079 2274
 	static public function number_format($number,$num_decimal_places=2,$_mimetype='')
2080 2275
 	{
2081
-		if ((string)$number === '') return '';
2276
+		if ((string)$number === '')
2277
+		{
2278
+			return '';
2279
+		}
2082 2280
 		//error_log(__METHOD__.$_mimetype);
2083 2281
 		switch($_mimetype)
2084 2282
 		{
Please login to merge, or discard this patch.
doc/rpm-build/checkout-build-archives.php 1 patch
Spacing   +179 added lines, -179 removed lines patch added patch discarded remove patch
@@ -14,15 +14,15 @@  discard block
 block discarded – undo
14 14
 {
15 15
 	die('<h1>checkout-build-archives.php must NOT be called as web-page --> exiting !!!</h1>');
16 16
 }
17
-date_default_timezone_set('Europe/Berlin');	// to get ride of 5.3 warnings
17
+date_default_timezone_set('Europe/Berlin'); // to get ride of 5.3 warnings
18 18
 
19 19
 $verbose = 0;
20 20
 $config = array(
21 21
 	'packagename' => 'egroupware-epl',
22
-	'version' => '16.1',        // '14.3'
22
+	'version' => '16.1', // '14.3'
23 23
 	'packaging' => date('Ymd'), // '20160520'
24
-	'branch'  => 'master',        // checked out branch
25
-	'tag' => '$version.$packaging',	// name of tag
24
+	'branch'  => 'master', // checked out branch
25
+	'tag' => '$version.$packaging', // name of tag
26 26
 	'checkoutdir' => realpath(__DIR__.'/../..'),
27 27
 	'egw_buildroot' => '/tmp/build_root/epl_16.1_buildroot',
28 28
 	'sourcedir' => '/home/download/stylite-epl/egroupware-epl-16.1',
@@ -34,11 +34,11 @@  discard block
 block discarded – undo
34 34
 	'svnalias' => 'aliases/default-ssh',    // default alias
35 35
 	'extra' => array('$stylitebase/$svnbranch/stylite', '$stylitebase/$svnbranch/esyncpro', '$stylitebase/trunk/archive'),//, '$stylitebase/$svnbranch/groups'), //,'svn+ssh://[email protected]/stylite/trunk/eventmgr'),
36 36
 	*/
37
-	'extra' => array('stylite', 'esyncpro', 'archive',	// create an extra archive for given apps
37
+	'extra' => array('stylite', 'esyncpro', 'archive', // create an extra archive for given apps
38 38
 		// these apps are placed in egroupware-epl-contrib archive
39 39
 		'contrib' => array('phpgwapi', 'etemplate', 'jdots', 'phpbrain', 'wiki', 'sambaadmin', 'sitemgr', 'phpfreechat')),
40
-	'aliasdir' => 'egroupware',             // directory created by the alias
41
-	'types' => array('tar.bz2','tar.gz','zip','all.tar.bz2'),
40
+	'aliasdir' => 'egroupware', // directory created by the alias
41
+	'types' => array('tar.bz2', 'tar.gz', 'zip', 'all.tar.bz2'),
42 42
 	// add given extra-apps or (uncompressed!) archives to above all.tar.bz2 archive
43 43
 	'all-add' => array('contrib', '/home/stylite/epl-16.1/phpfreechat_data_public.tar'),
44 44
 	// diverse binaries we need
@@ -55,12 +55,12 @@  discard block
 block discarded – undo
55 55
 	'gpg' => trim(`which gpg`),
56 56
 	'editor' => trim(`which vi`),
57 57
 	'rsync' => trim(`which rsync`).' --progress -e ssh --exclude "*-stylite-*" --exclude "*-esyncpro-*"',
58
-	'composer' => ($composer=trim(`which composer.phar`)) ? $composer.' install --ignore-platform-reqs --no-dev' : '',
58
+	'composer' => ($composer = trim(`which composer.phar`)) ? $composer.' install --ignore-platform-reqs --no-dev' : '',
59 59
 	'after-checkout' => 'rm -rf */source */templates/*/source',
60 60
 	'packager' => '[email protected]',
61 61
 	'obs' => '/home/stylite/obs/stylite-epl',
62
-	'obs_package_alias' => '',	// name used in obs package, if different from packagename
63
-	'changelog' => false,   // eg. '* 1. Zeile\n* 2. Zeile' for debian.changes
62
+	'obs_package_alias' => '', // name used in obs package, if different from packagename
63
+	'changelog' => false, // eg. '* 1. Zeile\n* 2. Zeile' for debian.changes
64 64
 	'changelog_packager' => 'Ralf Becker <[email protected]>',
65 65
 	'editchangelog' => '* ',
66 66
 	//'sfuser' => 'ralfbecker',
@@ -69,23 +69,23 @@  discard block
 block discarded – undo
69 69
 	'upload' => '$sourcedir/*egroupware-epl{,-contrib}-$version.$packaging*',
70 70
 	'copychangelog' => '$sourcedir/README', //'$sfuser,[email protected]:/home/frs/project/e/eg/egroupware/README',
71 71
 	'skip' => array(),
72
-	'run' => array('checkout','editchangelog','tag','copy','virusscan','create','sign','obs','copychangelog'),
72
+	'run' => array('checkout', 'editchangelog', 'tag', 'copy', 'virusscan', 'create', 'sign', 'obs', 'copychangelog'),
73 73
 	'patchCmd' => '# run cmd after copy eg. "cd $egw_buildroot; patch -p1 /path/to/patch"',
74
-	'github_user' => 'ralfbecker',	// Github user for following token
75
-	'github_token' => '',	// Github repo personal access token from above user
74
+	'github_user' => 'ralfbecker', // Github user for following token
75
+	'github_token' => '', // Github repo personal access token from above user
76 76
 );
77 77
 
78 78
 // process config from command line
79 79
 $argv = $_SERVER['argv'];
80 80
 $prog = array_shift($argv);
81 81
 
82
-while(($arg = array_shift($argv)))
82
+while (($arg = array_shift($argv)))
83 83
 {
84 84
 	if ($arg == '-v' || $arg == '--verbose')
85 85
 	{
86 86
 		++$verbose;
87 87
 	}
88
-	elseif($arg == '-h' || $arg == '--help')
88
+	elseif ($arg == '-h' || $arg == '--help')
89 89
 	{
90 90
 		if (in_array('editchangelog', $config['skip']) || !in_array('editchangelog', $config['run']))
91 91
 		{
@@ -93,10 +93,10 @@  discard block
 block discarded – undo
93 93
 		}
94 94
 		usage();
95 95
 	}
96
-	elseif(substr($arg,0,2) == '--' && isset($config[$name=substr($arg,2)]))
96
+	elseif (substr($arg, 0, 2) == '--' && isset($config[$name = substr($arg, 2)]))
97 97
 	{
98 98
 		$value = array_shift($argv);
99
-		switch($name)
99
+		switch ($name)
100 100
 		{
101 101
 			case 'extra':	// stored as array and allow to add/delete items with +/- prefix
102 102
 			case 'types':
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 				{
120 120
 					$value = array_unique(preg_split('/[ ,]+/', $value));
121 121
 				}
122
-				switch($op)
122
+				switch ($op)
123 123
 				{
124 124
 					case '+':
125 125
 						$config[$name] = array_unique(array_merge($config[$name], $value));
@@ -137,14 +137,14 @@  discard block
 block discarded – undo
137 137
 			case 'release':
138 138
 			case 'copychangelog':
139 139
 				$config[$name] = $value;
140
-				if ($value) array_unshift($config['run'],$name);
140
+				if ($value) array_unshift($config['run'], $name);
141 141
 				break;
142 142
 
143 143
 			case 'editchangelog':
144 144
 				$config[$name] = $value ? $value : true;
145
-				if (!in_array('editchangelog',$config['run']))
145
+				if (!in_array('editchangelog', $config['run']))
146 146
 				{
147
-					array_unshift($config['run'],'editchangelog');
147
+					array_unshift($config['run'], 'editchangelog');
148 148
 				}
149 149
 				break;
150 150
 
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 				{
154 154
 					usage("Path '$value' not found!");
155 155
 				}
156
-				if (!in_array('obs',$config['run'])) $config['run'][] = 'obs';
156
+				if (!in_array('obs', $config['run'])) $config['run'][] = 'obs';
157 157
 				// fall through
158 158
 			default:
159 159
 				$config[$name] = $value;
@@ -171,16 +171,16 @@  discard block
 block discarded – undo
171 171
 }
172 172
 $svn = $config['svn'];
173 173
 
174
-$run = array_diff($config['run'],$config['skip']);
174
+$run = array_diff($config['run'], $config['skip']);
175 175
 
176 176
 // if we dont edit the changelog, set packaging from changelog
177 177
 if (!in_array('editchangelog', $run))
178 178
 {
179 179
 	parse_current_changelog(true);
180 180
 }
181
-foreach($run as $func)
181
+foreach ($run as $func)
182 182
 {
183
-	chdir(dirname(__FILE__));	// make relative filenames work, if other command changes dir
183
+	chdir(dirname(__FILE__)); // make relative filenames work, if other command changes dir
184 184
 	call_user_func('do_'.$func);
185 185
 }
186 186
 
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
  * @param string $prefix ='* ' prefix, which if not presend should be added to all log messages
196 196
  * @return string with changelog
197 197
  */
198
-function get_changelog_from_git($_path, $log_pattern=null, &$last_tag=null, $prefix='* ')
198
+function get_changelog_from_git($_path, $log_pattern = null, &$last_tag = null, $prefix = '* ')
199 199
 {
200 200
 	//echo __FUNCTION__."('$branch_url','$log_pattern','$revision','$prefix')\n";
201 201
 	global $config;
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
 	run_cmd($cmd, $output);
217 217
 
218 218
 	$changelog = '';
219
-	foreach($output as $line)
219
+	foreach ($output as $line)
220 220
 	{
221 221
 		if (substr($line, 0, 4) == "    " && ($msg = _match_log_pattern(substr($line, 4), $log_pattern, $prefix)))
222 222
 		{
@@ -248,13 +248,13 @@  discard block
 block discarded – undo
248 248
 	{
249 249
 		throw new Exception("checkout directory '{$config['checkoutdir']} does NOT exists or is NO directory!");
250 250
 	}
251
-	if (!($mrconfig = file_get_contents($path=$config['checkoutdir'].'/.mrconfig')))
251
+	if (!($mrconfig = file_get_contents($path = $config['checkoutdir'].'/.mrconfig')))
252 252
 	{
253 253
 		throw new Exception("$path not found!");
254 254
 	}
255 255
 	$module = $baseurl = null;
256 256
 	$modules = array();
257
-	foreach(explode("\n", $mrconfig) as $line)
257
+	foreach (explode("\n", $mrconfig) as $line)
258 258
 	{
259 259
 		$matches = null;
260 260
 		if (isset($baseurl))
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
 		$cmd = $config['git'].' clone '.(!empty($config['branch']) ? ' -b '.$config['branch'] : '').
320 320
 			' [email protected]:EGroupware/egroupware.git '.$config['checkoutdir'];
321 321
 		run_cmd($cmd);
322
-		run_cmd('mr up');	// need to run mr up twice for new checkout, because chained .mrconfig wont run first time (because not there yet!)
322
+		run_cmd('mr up'); // need to run mr up twice for new checkout, because chained .mrconfig wont run first time (because not there yet!)
323 323
 	}
324 324
 	elseif (!is_dir($config['checkoutdir']) || !is_writable($config['checkoutdir']))
325 325
 	{
@@ -343,9 +343,9 @@  discard block
 block discarded – undo
343 343
 	}
344 344
 	chdir($config['checkoutdir']);
345 345
 
346
-	$config['tag'] = config_translate('tag');	// allow to use config vars like $version in tag
346
+	$config['tag'] = config_translate('tag'); // allow to use config vars like $version in tag
347 347
 
348
-	if (empty($config['tag'])) return;	// otherwise we copy everything in svn root!
348
+	if (empty($config['tag'])) return; // otherwise we copy everything in svn root!
349 349
 
350 350
 	echo "Creating tag $config[tag]\n";
351 351
 
@@ -358,16 +358,16 @@  discard block
 block discarded – undo
358 358
  */
359 359
 function do_release()
360 360
 {
361
-	global $config,$verbose;
361
+	global $config, $verbose;
362 362
 
363 363
 	// push local changes to Github incl. tags
364 364
 	if ($verbose) echo "Pushing changes and tags\n";
365 365
 	chdir($config['checkoutdir']);
366
-	run_cmd($config['mr']. ' up');		// in case someone else pushed something
366
+	run_cmd($config['mr'].' up'); // in case someone else pushed something
367 367
 	chdir($config['checkoutdir']);
368
-	run_cmd($config['git'].' push');	// regular commits like changelog
368
+	run_cmd($config['git'].' push'); // regular commits like changelog
369 369
 	$tag = config_translate('tag');
370
-	run_cmd($config['mr']. ' push origin '.$tag);	// pushing tags in all apps
370
+	run_cmd($config['mr'].' push origin '.$tag); // pushing tags in all apps
371 371
 
372 372
 	if (empty($config['github_user']) || empty($config['github_token']))
373 373
 	{
@@ -384,7 +384,7 @@  discard block
 block discarded – undo
384 384
 		'body' => $config['changelog'],
385 385
 	);
386 386
 	$response = github_api("/repos/EGroupware/egroupware/releases", $data);
387
-	$config['upload_url'] = preg_replace('/{\?[^}]+}$/', '', $response['upload_url']);	// remove {?name,label} template
387
+	$config['upload_url'] = preg_replace('/{\?[^}]+}$/', '', $response['upload_url']); // remove {?name,label} template
388 388
 
389 389
 	do_upload();
390 390
 }
@@ -394,33 +394,33 @@  discard block
 block discarded – undo
394 394
  */
395 395
 function do_upload()
396 396
 {
397
-	global $config,$verbose;
397
+	global $config, $verbose;
398 398
 
399 399
 	if (empty($config['upload_url']))
400 400
 	{
401 401
 		$response = github_api("/repos/EGroupware/egroupware/releases", array(), 'GET');
402
-		$config['upload_url'] = preg_replace('/{\?[^}]+}$/', '', $response[0]['upload_url']);	// remove {?name,label} template
402
+		$config['upload_url'] = preg_replace('/{\?[^}]+}$/', '', $response[0]['upload_url']); // remove {?name,label} template
403 403
 	}
404 404
 
405 405
 	$archives = config_translate('upload');
406 406
 	echo "Uploading $archives to $config[upload_url]\n";
407 407
 
408
-	foreach(glob($archives, GLOB_BRACE) as $path)
408
+	foreach (glob($archives, GLOB_BRACE) as $path)
409 409
 	{
410 410
 		$label = null;
411 411
 		if (substr($path, -4) == '.zip')
412 412
 		{
413 413
 			$content_type = 'application/zip';
414 414
 		}
415
-		elseif(substr($path, -7) == '.tar.gz')
415
+		elseif (substr($path, -7) == '.tar.gz')
416 416
 		{
417 417
 			$content_type = 'application/x-gzip';
418 418
 		}
419
-		elseif(substr($path, -8) == '.tar.bz2')
419
+		elseif (substr($path, -8) == '.tar.bz2')
420 420
 		{
421 421
 			$content_type = 'application/x-bzip2';
422 422
 		}
423
-		elseif(substr($path, -8) == '.txt.asc')
423
+		elseif (substr($path, -8) == '.txt.asc')
424 424
 		{
425 425
 			$content_type = 'text/plain';
426 426
 			$label = 'Signed hashes of downloads';
@@ -439,7 +439,7 @@  discard block
 block discarded – undo
439 439
 
440 440
 	if (!empty($config['release']))
441 441
 	{
442
-		$target = config_translate('release');	// allow to use config vars like $svnbranch in module
442
+		$target = config_translate('release'); // allow to use config vars like $svnbranch in module
443 443
 		$cmd = $config['rsync'].' '.$archives.' '.$target;
444 444
 		if ($verbose) echo $cmd."\n";
445 445
 		passthru($cmd);
@@ -457,7 +457,7 @@  discard block
 block discarded – undo
457 457
  * @throws Exception
458 458
  * @return array with response
459 459
  */
460
-function github_api($_url, $data, $method='POST', $upload=null, $content_type=null)
460
+function github_api($_url, $data, $method = 'POST', $upload = null, $content_type = null)
461 461
 {
462 462
 	global $config, $verbose;
463 463
 
@@ -470,7 +470,7 @@  discard block
 block discarded – undo
470 470
 	curl_setopt($c, CURLOPT_TIMEOUT, 240);
471 471
 	curl_setopt($c, CURLOPT_FOLLOWLOCATION, true);
472 472
 
473
-	switch($method)
473
+	switch ($method)
474 474
 	{
475 475
 		case 'POST':
476 476
 			curl_setopt($c, CURLOPT_POST, true);
@@ -478,13 +478,13 @@  discard block
 block discarded – undo
478 478
 			curl_setopt($c, CURLOPT_POSTFIELDS, $data);
479 479
 			break;
480 480
 		case 'GET':
481
-			if(count($data)) $url .= '?' . http_build_query($data);
481
+			if (count($data)) $url .= '?'.http_build_query($data);
482 482
 			break;
483 483
 		case 'FILE':
484 484
 			curl_setopt($c, CURLOPT_HTTPHEADER, array("Content-type: $content_type"));
485 485
 			curl_setopt($c, CURLOPT_POST, true);
486 486
 			curl_setopt($c, CURLOPT_POSTFIELDS, file_get_contents($upload));
487
-			if(count($data)) $url .= '?' . http_build_query($data);
487
+			if (count($data)) $url .= '?'.http_build_query($data);
488 488
 			break;
489 489
 		default:
490 490
 			throw new Exception(__FUNCTION__.": Unknown/unimplemented method=$method!");
@@ -492,7 +492,7 @@  discard block
 block discarded – undo
492 492
 	curl_setopt($c, CURLOPT_URL, $url);
493 493
 
494 494
 	if (is_string($data)) $short_data = strlen($data) > 100 ? substr($data, 0, 100).' ...' : $data;
495
-	if ($verbose) echo "Sending $method request to $url ".(isset($short_data)&&$method!='GET'?$short_data:'')."\n";
495
+	if ($verbose) echo "Sending $method request to $url ".(isset($short_data) && $method != 'GET' ? $short_data : '')."\n";
496 496
 
497 497
 	if (($response = curl_exec($c)) === false)
498 498
 	{
@@ -500,7 +500,7 @@  discard block
 block discarded – undo
500 500
 		curl_setopt($c, CURLOPT_HEADER, true);
501 501
 		curl_setopt($c, CURLOPT_RETURNTRANSFER, false);
502 502
 		curl_exec($c);
503
-		throw new Exception("$method request to $url failed ".(isset($short_data)&&$method!='GET'?$short_data:''));
503
+		throw new Exception("$method request to $url failed ".(isset($short_data) && $method != 'GET' ? $short_data : ''));
504 504
 	}
505 505
 
506 506
 	if ($verbose) echo (strlen($response) > 200 ? substr($response, 0, 200).' ...' : $response)."\n";
@@ -516,7 +516,7 @@  discard block
 block discarded – undo
516 516
  * @param string $name
517 517
  * @param string $value =null value to use, default $config[$name]
518 518
  */
519
-function config_translate($name, $value=null)
519
+function config_translate($name, $value = null)
520 520
 {
521 521
 	global $config;
522 522
 
@@ -524,7 +524,7 @@  discard block
 block discarded – undo
524 524
 	if (is_string($value) && strpos($value, '$') !== false)
525 525
 	{
526 526
 		$translate = array();
527
-		foreach($config as $n => $val)
527
+		foreach ($config as $n => $val)
528 528
 		{
529 529
 			if (is_string($val)) $translate['$'.$n] = $val;
530 530
 		}
@@ -550,7 +550,7 @@  discard block
 block discarded – undo
550 550
  */
551 551
 function do_editchangelog()
552 552
 {
553
-	global $config,$svn;
553
+	global $config, $svn;
554 554
 
555 555
 	echo "Querying changelog from Git/SVN\n";
556 556
 	if (!isset($config['modules']))
@@ -560,7 +560,7 @@  discard block
 block discarded – undo
560 560
 	// query changelog per repo
561 561
 	$changelog = '';
562 562
 	$last_tag = null;
563
-	foreach($config['modules'] as $branch_url => $modules)
563
+	foreach ($config['modules'] as $branch_url => $modules)
564 564
 	{
565 565
 		$revision = null;
566 566
 		if (substr($branch_url, -4) == '.git')
@@ -573,15 +573,15 @@  discard block
 block discarded – undo
573 573
 			$changelog .= get_changelog_from_svn($branch_url, $config['editchangelog'], $revision);
574 574
 		}
575 575
 	}
576
-	$logfile = tempnam('/tmp','checkout-build-archives');
577
-	file_put_contents($logfile,$changelog);
576
+	$logfile = tempnam('/tmp', 'checkout-build-archives');
577
+	file_put_contents($logfile, $changelog);
578 578
 	$cmd = $config['editor'].' '.escapeshellarg($logfile);
579 579
 	passthru($cmd);
580 580
 	$config['changelog'] = file_get_contents($logfile);
581 581
 	// remove trailing newlines
582
-	while (substr($config['changelog'],-1) == "\n")
582
+	while (substr($config['changelog'], -1) == "\n")
583 583
 	{
584
-		$config['changelog'] = substr($config['changelog'],0,-1);
584
+		$config['changelog'] = substr($config['changelog'], 0, -1);
585 585
 	}
586 586
 	// allow user to abort, by deleting the changelog
587 587
 	if (strlen($config['changelog']) <= 2)
@@ -596,7 +596,7 @@  discard block
 block discarded – undo
596 596
 	}
597 597
 	file_put_contents($changelog, update_changelog(file_get_contents($changelog)));
598 598
 
599
-	update_api_setup($api_setup=$config['checkoutdir'].'/api/setup/setup.inc.php');
599
+	update_api_setup($api_setup = $config['checkoutdir'].'/api/setup/setup.inc.php');
600 600
 
601 601
 	if (file_exists($config['checkoutdir'].'/.git'))
602 602
 	{
@@ -609,7 +609,7 @@  discard block
 block discarded – undo
609 609
 	run_cmd($cmd);
610 610
 
611 611
 	// update obs changelogs (so all changlogs are updated in case of a later error and changelog step can be skiped)
612
-	do_obs(true);	// true: only update debian.changes in obs checkouts
612
+	do_obs(true); // true: only update debian.changes in obs checkouts
613 613
 }
614 614
 
615 615
 /**
@@ -623,41 +623,41 @@  discard block
 block discarded – undo
623 623
  * @param string $prefix ='* ' prefix, which if not presend should be added to all log messages
624 624
  * @return string with changelog
625 625
  */
626
-function get_changelog_from_svn($branch_url, $log_pattern=null, &$revision=null, $prefix='* ')
626
+function get_changelog_from_svn($branch_url, $log_pattern = null, &$revision = null, $prefix = '* ')
627 627
 {
628 628
 	//echo __FUNCTION__."('$branch_url','$log_pattern','$revision','$prefix')\n";
629
-	global $config,$verbose,$svn;
629
+	global $config, $verbose, $svn;
630 630
 
631 631
 	if (is_null($revision))
632 632
 	{
633
-		list($tags_url,$branch) = preg_split('#/(branches/|trunk)#',$branch_url);
633
+		list($tags_url, $branch) = preg_split('#/(branches/|trunk)#', $branch_url);
634 634
 		if (empty($branch)) $branch = $config['version'];
635 635
 		$tags_url .= '/tags';
636
-		$pattern='|/tags/('.preg_quote($config['version'], '|').'\.[0-9.]+)|';
636
+		$pattern = '|/tags/('.preg_quote($config['version'], '|').'\.[0-9.]+)|';
637 637
 		$matches = null;
638
-		$revision = get_last_svn_tag($tags_url,$pattern,$matches);
638
+		$revision = get_last_svn_tag($tags_url, $pattern, $matches);
639 639
 		$tag = $matches[1];
640 640
 	}
641
-	elseif(!is_numeric($revision))
641
+	elseif (!is_numeric($revision))
642 642
 	{
643
-		$revision = get_last_svn_tag($tags_url,$tag=$revision);
643
+		$revision = get_last_svn_tag($tags_url, $tag = $revision);
644 644
 	}
645 645
 	$cmd = $svn.' log --xml -r '.escapeshellarg($revision.':HEAD').' '.escapeshellarg($branch_url);
646 646
 	if (($v = $verbose))
647 647
 	{
648 648
 		echo "Querying SVN for log from r$revision".($tag ? " ($tag)" : '').":\n$cmd\n";
649
-		$verbose = false;	// otherwise no $output!
649
+		$verbose = false; // otherwise no $output!
650 650
 	}
651 651
 	$output = array();
652
-	run_cmd($cmd,$output);
652
+	run_cmd($cmd, $output);
653 653
 	$verbose = $v;
654
-	array_shift($output);	// remove the command
654
+	array_shift($output); // remove the command
655 655
 
656
-	$xml = simplexml_load_string($output=implode("\n",$output));
656
+	$xml = simplexml_load_string($output = implode("\n", $output));
657 657
 	$message = '';
658
-	foreach($xml as $log)
658
+	foreach ($xml as $log)
659 659
 	{
660
-		if (!($msg = _match_log_pattern($log->msg, $log_pattern, $prefix))) continue;	// no match --> ignore
660
+		if (!($msg = _match_log_pattern($log->msg, $log_pattern, $prefix))) continue; // no match --> ignore
661 661
 
662 662
 		$message .= $msg."\n";
663 663
 	}
@@ -674,25 +674,25 @@  discard block
 block discarded – undo
674 674
  * @param string $prefix ='* '
675 675
  * @return string
676 676
  */
677
-function _match_log_pattern($msg, $log_pattern, $prefix='* ')
677
+function _match_log_pattern($msg, $log_pattern, $prefix = '* ')
678 678
 {
679 679
 	$pattern_len = strlen($log_pattern);
680 680
 	$prefix_len = strlen($prefix);
681 681
 
682 682
 	$matches = null;
683
-	if ($log_pattern[0] == '/' && preg_match($log_pattern,$msg,$matches))
683
+	if ($log_pattern[0] == '/' && preg_match($log_pattern, $msg, $matches))
684 684
 	{
685 685
 		$msg = $matches[1];
686 686
 	}
687
-	elseif($log_pattern && $log_pattern[0] != '/' && substr($msg,0,$pattern_len) == $log_pattern)
687
+	elseif ($log_pattern && $log_pattern[0] != '/' && substr($msg, 0, $pattern_len) == $log_pattern)
688 688
 	{
689
-		list($msg) = explode("\n",$msg);
689
+		list($msg) = explode("\n", $msg);
690 690
 	}
691
-	elseif($log_pattern)
691
+	elseif ($log_pattern)
692 692
 	{
693 693
 		return null;
694 694
 	}
695
-	if ($prefix_len && substr($msg,0,$prefix_len) != $prefix) $msg = $prefix.$msg;
695
+	if ($prefix_len && substr($msg, 0, $prefix_len) != $prefix) $msg = $prefix.$msg;
696 696
 
697 697
 	return $msg;
698 698
 }
@@ -706,30 +706,30 @@  discard block
 block discarded – undo
706 706
  * @param array &$matches=null on return matches of preg_match
707 707
  * @return int revision of last svn tag matching pattern
708 708
  */
709
-function get_last_svn_tag($tags_url,$pattern,&$matches=null)
709
+function get_last_svn_tag($tags_url, $pattern, &$matches = null)
710 710
 {
711
-	global $verbose,$svn;
711
+	global $verbose, $svn;
712 712
 
713 713
 	$cmd = $svn.' log --xml --limit 40 -v '.escapeshellarg($tags_url);
714 714
 	if (($v = $verbose))
715 715
 	{
716 716
 		echo "Querying SVN for last tags\n$cmd\n";
717
-		$verbose = false;	// otherwise no $output!
717
+		$verbose = false; // otherwise no $output!
718 718
 	}
719 719
 	$output = array();
720
-	run_cmd($cmd,$output);
720
+	run_cmd($cmd, $output);
721 721
 	$verbose = $v;
722
-	array_shift($output);	// remove the command
722
+	array_shift($output); // remove the command
723 723
 
724
-	$xml = simplexml_load_string($output=implode("\n",$output));
724
+	$xml = simplexml_load_string($output = implode("\n", $output));
725 725
 	$is_regexp = $pattern[0] == substr($pattern, -1);
726
-	foreach($xml as $log)
726
+	foreach ($xml as $log)
727 727
 	{
728 728
 		//print_r($log);
729 729
 		if (!$is_regexp && strpos($log->paths->path, $pattern) !== false ||
730 730
 			$is_regexp && preg_match($pattern, $log->paths->path, $matches))
731 731
 		{
732
-			if ($verbose) echo "Revision {$log['revision']} matches".($matches?': '.$matches[1] : '')."\n";
732
+			if ($verbose) echo "Revision {$log['revision']} matches".($matches ? ': '.$matches[1] : '')."\n";
733 733
 			return (int)$log['revision'];
734 734
 		}
735 735
 	}
@@ -741,9 +741,9 @@  discard block
 block discarded – undo
741 741
  *
742 742
  * @param boolean $only_update_changelog =false true update debian.changes, but nothing else, nor commit it
743 743
  */
744
-function do_obs($only_update_changelog=false)
744
+function do_obs($only_update_changelog = false)
745 745
 {
746
-	global $config,$verbose;
746
+	global $config, $verbose;
747 747
 
748 748
 	if (!is_dir($config['obs']))
749 749
 	{
@@ -753,25 +753,25 @@  discard block
 block discarded – undo
753 753
 	run_cmd('osc up '.$config['obs']);
754 754
 
755 755
 	$n = 0;
756
-	foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($config['obs'])) as $path)
756
+	foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($config['obs'])) as $path)
757 757
 	{
758 758
 		if (basename(dirname($path)) == '.osc' ||
759 759
 			!preg_match('/\/('.preg_quote($config['packagename']).
760 760
 				($config['obs_package_alias'] ? '|'.preg_quote($config['obs_package_alias']) : '').
761
-				')[a-z-]*-('.preg_quote($config['version']).'|trunk)/',$path))
761
+				')[a-z-]*-('.preg_quote($config['version']).'|trunk)/', $path))
762 762
 		{
763 763
 			continue;
764 764
 		}
765 765
 		$matches = null;
766
-		if (preg_match('/\/('.preg_quote($config['packagename']).'[a-z-]*)-'.preg_quote($config['version']).'\.[0-9.]+[0-9](\.tar\.(gz|bz2))$/',$path,$matches) &&
767
-			file_exists($new_name=$config['sourcedir'].'/'.$matches[1].'-'.$config['version'].'.'.$config['packaging'].$matches[2]))
766
+		if (preg_match('/\/('.preg_quote($config['packagename']).'[a-z-]*)-'.preg_quote($config['version']).'\.[0-9.]+[0-9](\.tar\.(gz|bz2))$/', $path, $matches) &&
767
+			file_exists($new_name = $config['sourcedir'].'/'.$matches[1].'-'.$config['version'].'.'.$config['packaging'].$matches[2]))
768 768
 		{
769 769
 			if (basename($path) != basename($new_name))
770 770
 			{
771 771
 				unlink($path);
772 772
 				if ($verbose) echo "rm $path\n";
773 773
 			}
774
-			copy($new_name,dirname($path).'/'.basename($new_name));
774
+			copy($new_name, dirname($path).'/'.basename($new_name));
775 775
 			if ($verbose) echo "cp $new_name ".dirname($path)."/\n";
776 776
 			++$n;
777 777
 		}
@@ -781,35 +781,35 @@  discard block
 block discarded – undo
781 781
 			$config['changelog'] = parse_current_changelog();
782 782
 		}
783 783
 		// updating dsc, spec and changelog files
784
-		if (!$only_update_changelog && (substr($path,-4) == '.dsc' || substr($path,-5) == '.spec') ||
784
+		if (!$only_update_changelog && (substr($path, -4) == '.dsc' || substr($path, -5) == '.spec') ||
785 785
 			!empty($config['changelog']) && basename($path) == 'debian.changes')
786 786
 		{
787 787
 			$content = $content_was = file_get_contents($path);
788 788
 
789
-			if (substr($path,-4) == '.dsc' || substr($path,-5) == '.spec')
789
+			if (substr($path, -4) == '.dsc' || substr($path, -5) == '.spec')
790 790
 			{
791
-				$content = preg_replace('/^Version: '.preg_quote($config['version']).'\.[0-9.]+[0-9]/m','Version: '.$config['version'].'.'.$config['packaging'],$content);
791
+				$content = preg_replace('/^Version: '.preg_quote($config['version']).'\.[0-9.]+[0-9]/m', 'Version: '.$config['version'].'.'.$config['packaging'], $content);
792 792
 			}
793
-			if (substr($path,-4) == '.dsc')
793
+			if (substr($path, -4) == '.dsc')
794 794
 			{
795 795
 				$content = preg_replace('/^(Debtransform-Tar: '.preg_quote($config['packagename']).'[a-z-]*)-'.
796 796
 					preg_quote($config['version']).'\.[0-9.]+[0-9](\.tar\.(gz|bz2))$/m',
797
-					'\\1-'.$config['version'].'.'.$config['packaging'].'\\2',$content);
797
+					'\\1-'.$config['version'].'.'.$config['packaging'].'\\2', $content);
798 798
 			}
799
-			if (basename($path) == 'debian.changes' && strpos($content,$config['version'].'.'.$config['packaging']) === false)
799
+			if (basename($path) == 'debian.changes' && strpos($content, $config['version'].'.'.$config['packaging']) === false)
800 800
 			{
801 801
 				$content = update_changelog($content);
802 802
 			}
803
-			if (!empty($config['changelog']) && substr($path,-5) == '.spec' &&
804
-				($pos_changelog = strpos($content,'%changelog')) !== false)
803
+			if (!empty($config['changelog']) && substr($path, -5) == '.spec' &&
804
+				($pos_changelog = strpos($content, '%changelog')) !== false)
805 805
 			{
806 806
 				$pos_changelog += strlen("%changelog\n");
807
-				$content = substr($content,0,$pos_changelog).' *'.date('D M d Y').' '.$config['changelog_packager']."\n".
808
-					$config['changelog']."\n".substr($content,$pos_changelog);
807
+				$content = substr($content, 0, $pos_changelog).' *'.date('D M d Y').' '.$config['changelog_packager']."\n".
808
+					$config['changelog']."\n".substr($content, $pos_changelog);
809 809
 			}
810 810
 			if ($content != $content_was)
811 811
 			{
812
-				file_put_contents($path,$content);
812
+				file_put_contents($path, $content);
813 813
 				if ($verbose) echo "Updated $path\n";
814 814
 				++$n;
815 815
 			}
@@ -830,33 +830,33 @@  discard block
 block discarded – undo
830 830
  * @param boolean $set_packaging =false true: set packaging from last changelog entry
831 831
  * @return string changelog entries without header and footer lines
832 832
  */
833
-function parse_current_changelog($set_packaging=false)
833
+function parse_current_changelog($set_packaging = false)
834 834
 {
835 835
 	global $config;
836 836
 
837 837
 	$changelog = file_get_contents($config['checkoutdir'].'/doc/rpm-build/debian.changes');
838 838
 	$lines = explode("\n", $changelog, 100);
839 839
 	$matches = null;
840
-	foreach($lines as $n => $line)
840
+	foreach ($lines as $n => $line)
841 841
 	{
842
-		if (preg_match($preg='/^'.preg_quote($config['packagename']).' \('.preg_quote($config['version']).'\.'.
842
+		if (preg_match($preg = '/^'.preg_quote($config['packagename']).' \('.preg_quote($config['version']).'\.'.
843 843
 			($set_packaging ? '([0-9]+)' : preg_quote($config['packaging'])).'/', $line, $matches))
844 844
 		{
845 845
 			if ($set_packaging)
846 846
 			{
847 847
 				$config['packaging'] = $matches[1];
848 848
 			}
849
-			$n += empty($lines[$n+1]) ? 2 : 1;	// overead empty line behind header
849
+			$n += empty($lines[$n + 1]) ? 2 : 1; // overead empty line behind header
850 850
 			$logentry = '';
851
-			while($lines[$n])	// entry is terminated by empty line
851
+			while ($lines[$n])	// entry is terminated by empty line
852 852
 			{
853 853
 				$logentry .= (substr($lines[$n], 0, 2) == '  ' ? substr($lines[$n], 2) : $lines[$n])."\n";
854 854
 				++$n;
855 855
 			}
856
-			return substr($logentry, 0, -1);	// remove training "\n"
856
+			return substr($logentry, 0, -1); // remove training "\n"
857 857
 		}
858 858
 	}
859
-	return null;	// paragraph for current version NOT found
859
+	return null; // paragraph for current version NOT found
860 860
 }
861 861
 
862 862
 /**
@@ -870,8 +870,8 @@  discard block
 block discarded – undo
870 870
 	global $config;
871 871
 
872 872
 	list($header) = explode("\n", $content);
873
-	$new_header = preg_replace('/\('.preg_quote($config['version']).'\.[0-9.]+[0-9](.*)\)/','('.$config['version'].'.'.$config['packaging'].'\\1)', $header);
874
-	if (substr($config['changelog'],0,2) != '  ') $config['changelog'] = '  '.implode("\n  ",explode("\n",$config['changelog']));
873
+	$new_header = preg_replace('/\('.preg_quote($config['version']).'\.[0-9.]+[0-9](.*)\)/', '('.$config['version'].'.'.$config['packaging'].'\\1)', $header);
874
+	if (substr($config['changelog'], 0, 2) != '  ') $config['changelog'] = '  '.implode("\n  ", explode("\n", $config['changelog']));
875 875
 	$content = $new_header."\n\n".$config['changelog'].
876 876
 		"\n\n -- ".$config['changelog_packager'].'  '.date('r')."\n\n".$content;
877 877
 
@@ -909,9 +909,9 @@  discard block
 block discarded – undo
909 909
 {
910 910
 	global $config;
911 911
 
912
-	if (substr($config['sourcedir'],0,2) == '~/')	// sha1_file cant deal with '~/rpm'
912
+	if (substr($config['sourcedir'], 0, 2) == '~/')	// sha1_file cant deal with '~/rpm'
913 913
 	{
914
-		$config['sourcedir'] = getenv('HOME').substr($config['sourcedir'],1);
914
+		$config['sourcedir'] = getenv('HOME').substr($config['sourcedir'], 1);
915 915
 	}
916 916
 	$sumsfile = $config['sourcedir'].'/sha1sum-'.$config['packagename'].'-'.$config['version'].'.'.$config['packaging'].'.txt';
917 917
 
@@ -930,7 +930,7 @@  discard block
 block discarded – undo
930 930
 	if (file_exists($sumsfile.'.asc')) unlink($sumsfile.'.asc');
931 931
 	$cmd = $config['gpg'].' --local-user '.$config['packager'].' --clearsign '.$sumsfile;
932 932
 	run_cmd($cmd);
933
-	unlink($sumsfile);	// delete the unsigned file
933
+	unlink($sumsfile); // delete the unsigned file
934 934
 }
935 935
 
936 936
 /**
@@ -940,22 +940,22 @@  discard block
 block discarded – undo
940 940
 {
941 941
 	global $config;
942 942
 
943
-	if (!file_exists($config['sourcedir'])) mkdir($config['sourcedir'],0755,true);
944
-	if (substr($config['sourcedir'],0,2) == '~/')	// sha1_file cant deal with '~/rpm'
943
+	if (!file_exists($config['sourcedir'])) mkdir($config['sourcedir'], 0755, true);
944
+	if (substr($config['sourcedir'], 0, 2) == '~/')	// sha1_file cant deal with '~/rpm'
945 945
 	{
946
-		$config['sourcedir'] = getenv('HOME').substr($config['sourcedir'],1);
946
+		$config['sourcedir'] = getenv('HOME').substr($config['sourcedir'], 1);
947 947
 	}
948 948
 	$sumsfile = $config['sourcedir'].'/sha1sum-'.$config['packagename'].'-'.$config['version'].'.'.$config['packaging'].'.txt';
949 949
 	$sums = '';
950 950
 
951 951
 	chdir($config['egw_buildroot']);
952 952
 
953
-	if($config['extra'])
953
+	if ($config['extra'])
954 954
 	{
955 955
 		$exclude = $exclude_all = array();
956
-		foreach($config['extra'] as $name => $modules)
956
+		foreach ($config['extra'] as $name => $modules)
957 957
 		{
958
-			foreach((array)$modules as $module)
958
+			foreach ((array)$modules as $module)
959 959
 			{
960 960
 				$exclude[] = basename($module);
961 961
 				if (!empty($config['all-add']) && !in_array($module, $config['all-add']) && (is_int($name) || !in_array($name, $config['all-add'])))
@@ -965,24 +965,24 @@  discard block
 block discarded – undo
965 965
 			}
966 966
 		}
967 967
 		$exclude_extra = ' --exclude=egroupware/'.implode(' --exclude=egroupware/', $exclude);
968
-		$exclude_all_extra =  $exclude_all ? ' --exclude=egroupware/'.implode(' --exclude=egroupware/', $exclude_all) : '';
968
+		$exclude_all_extra = $exclude_all ? ' --exclude=egroupware/'.implode(' --exclude=egroupware/', $exclude_all) : '';
969 969
 	}
970
-	foreach($config['types'] as $type)
970
+	foreach ($config['types'] as $type)
971 971
 	{
972 972
 		echo "Creating $type archives\n";
973 973
 		$tar_type = $type == 'tar.bz2' ? 'j' : 'z';
974 974
 
975 975
 		$file = $config['sourcedir'].'/'.$config['packagename'].'-'.$config['version'].'.'.$config['packaging'].'.'.$type;
976
-		switch($type)
976
+		switch ($type)
977 977
 		{
978 978
 			case 'all.tar.bz2':	// single tar-ball for debian builds not easily supporting to use multiple
979 979
 				$file = $config['sourcedir'].'/'.$config['packagename'].'-all-'.$config['version'].'.'.$config['packaging'].'.tar';
980 980
 				$cmd = $config['tar'].' --owner=root --group=root -cf '.$file.$exclude_all_extra.' egroupware';
981 981
 				if (!empty($config['all-add']))
982 982
 				{
983
-					foreach((array)$config['all-add'] as $add)
983
+					foreach ((array)$config['all-add'] as $add)
984 984
 					{
985
-						if (substr($add, -4) != '.tar') continue;	// probably a module
985
+						if (substr($add, -4) != '.tar') continue; // probably a module
986 986
 						if (!($tar = realpath($add))) throw new Exception("File '$add' not found!");
987 987
 						$cmd .= '; '.$config['tar'].' --owner=root --group=root -Af '.$file.' '.$tar;
988 988
 					}
@@ -1006,15 +1006,15 @@  discard block
 block discarded – undo
1006 1006
 		run_cmd($cmd);
1007 1007
 		$sums .= sha1_file($file)."\t".basename($file)."\n";
1008 1008
 
1009
-		foreach($config['extra'] as $name => $modules)
1009
+		foreach ($config['extra'] as $name => $modules)
1010 1010
 		{
1011 1011
 			if (is_numeric($name)) $name = $modules;
1012 1012
 			$dirs = ' egroupware/'.implode(' egroupware/', (array)$modules);
1013 1013
 			$file = $config['sourcedir'].'/'.$config['packagename'].'-'.$name.'-'.$config['version'].'.'.$config['packaging'].'.'.$type;
1014
-			switch($type)
1014
+			switch ($type)
1015 1015
 			{
1016 1016
 				case 'all.tar.bz2':
1017
-					break;	// nothing to do
1017
+					break; // nothing to do
1018 1018
 				case 'tar.bz2':
1019 1019
 				case 'tar.gz':
1020 1020
 					$cmd = $config['tar'].' --owner=root --group=root -c'.$tar_type.'f '.$file.$dirs;
@@ -1029,7 +1029,7 @@  discard block
 block discarded – undo
1029 1029
 		}
1030 1030
 	}
1031 1031
 	// writing sha1sum file
1032
-	file_put_contents($sumsfile,$sums);
1032
+	file_put_contents($sumsfile, $sums);
1033 1033
 }
1034 1034
 
1035 1035
 /**
@@ -1037,7 +1037,7 @@  discard block
 block discarded – undo
1037 1037
  */
1038 1038
 function do_virusscan()
1039 1039
 {
1040
-	global $config,$verbose;
1040
+	global $config, $verbose;
1041 1041
 
1042 1042
 	if (!file_exists($config['clamscan']) || !is_executable($config['clamscan']))
1043 1043
 	{
@@ -1051,7 +1051,7 @@  discard block
 block discarded – undo
1051 1051
 		$cmd = '/usr/bin/sudo '.$config['freshclam'];
1052 1052
 		if (!$verbose && function_exists('posix_getuid') && posix_getuid()) echo $cmd."\n";
1053 1053
 		$output = null;
1054
-		run_cmd($cmd,$output,1);	// 1 = ignore already up to date database
1054
+		run_cmd($cmd, $output, 1); // 1 = ignore already up to date database
1055 1055
 	}
1056 1056
 	echo "Starting virusscan\n";
1057 1057
 	$cmd = $config['clamscan'].' --quiet -r '.$config['egw_buildroot'];
@@ -1108,12 +1108,12 @@  discard block
 block discarded – undo
1108 1108
  */
1109 1109
 function do_svncheckout()
1110 1110
 {
1111
-	global $config,$svn;
1111
+	global $config, $svn;
1112 1112
 
1113 1113
 	echo "Starting svn checkout/update\n";
1114 1114
 	if (!file_exists($config['checkoutdir']))
1115 1115
 	{
1116
-		mkdir($config['checkoutdir'],0755,true);
1116
+		mkdir($config['checkoutdir'], 0755, true);
1117 1117
 	}
1118 1118
 	elseif (!is_dir($config['checkoutdir']) || !is_writable($config['checkoutdir']))
1119 1119
 	{
@@ -1128,17 +1128,17 @@  discard block
 block discarded – undo
1128 1128
 		{
1129 1129
 			get_modules_per_repo();
1130 1130
 		}
1131
-		$config['svntag'] = config_translate('svntag');	// in case svntag command did not run, translate tag name
1131
+		$config['svntag'] = config_translate('svntag'); // in case svntag command did not run, translate tag name
1132 1132
 
1133 1133
 		if (file_exists($config['aliasdir']))
1134 1134
 		{
1135
-			system('/bin/rm -rf .svn '.$config['aliasdir']);	// --> remove the whole checkout, as we dont implement switching tags
1135
+			system('/bin/rm -rf .svn '.$config['aliasdir']); // --> remove the whole checkout, as we dont implement switching tags
1136 1136
 			clearstatcache();
1137 1137
 		}
1138
-		foreach($config['modules'] as $repo => $modules)
1138
+		foreach ($config['modules'] as $repo => $modules)
1139 1139
 		{
1140 1140
 			$cmd = $svn.' co ';
1141
-			foreach($modules as $path => $url)
1141
+			foreach ($modules as $path => $url)
1142 1142
 			{
1143 1143
 				if ($path == $config['aliasdir'])
1144 1144
 				{
@@ -1148,7 +1148,7 @@  discard block
 block discarded – undo
1148 1148
 					$cmd = $svn.' co ';
1149 1149
 					continue;
1150 1150
 				}
1151
-				if(file_exists($config['aliasdir']))
1151
+				if (file_exists($config['aliasdir']))
1152 1152
 				{
1153 1153
 					die("'egroupware' applications must be first one in externals!\n");
1154 1154
 				}
@@ -1166,16 +1166,16 @@  discard block
 block discarded – undo
1166 1166
 			// check if correct branch
1167 1167
 			$cmd = 'LANG=C '.$svn.' info';
1168 1168
 			$output = $ret = null;
1169
-			exec($cmd,$output,$ret);
1170
-			foreach($output as $line)
1169
+			exec($cmd, $output, $ret);
1170
+			foreach ($output as $line)
1171 1171
 			{
1172
-				if ($ret || substr($line,0,5) == 'URL: ')
1172
+				if ($ret || substr($line, 0, 5) == 'URL: ')
1173 1173
 				{
1174
-					$url = substr($line,5);
1175
-					if ($ret || substr($url,0,strlen($svnbranch)) != $svnbranch)	// wrong branch (or no svn dir)
1174
+					$url = substr($line, 5);
1175
+					if ($ret || substr($url, 0, strlen($svnbranch)) != $svnbranch)	// wrong branch (or no svn dir)
1176 1176
 					{
1177 1177
 						echo "Checkout is of wrong branch --> deleting it\n";
1178
-						system('/bin/rm -rf .svn '.$config['aliasdir']);	// --> remove the whole checkout
1178
+						system('/bin/rm -rf .svn '.$config['aliasdir']); // --> remove the whole checkout
1179 1179
 						clearstatcache();
1180 1180
 					}
1181 1181
 					break;
@@ -1187,10 +1187,10 @@  discard block
 block discarded – undo
1187 1187
 		run_cmd($cmd);
1188 1188
 
1189 1189
 		chdir($config['aliasdir']);
1190
-		foreach($config['extra'] as $module)
1190
+		foreach ($config['extra'] as $module)
1191 1191
 		{
1192
-			$module = config_translate(null, $module);	// allow to use config vars like $svnbranch in module
1193
-			$url = strpos($module,'://') === false ? $svnbranch.'/' : '';
1192
+			$module = config_translate(null, $module); // allow to use config vars like $svnbranch in module
1193
+			$url = strpos($module, '://') === false ? $svnbranch.'/' : '';
1194 1194
 			$url .= $module;
1195 1195
 			$cmd = $svn.' co '.$url;
1196 1196
 			run_cmd($cmd);
@@ -1215,7 +1215,7 @@  discard block
 block discarded – undo
1215 1215
  */
1216 1216
 function get_modules_per_svn_repo()
1217 1217
 {
1218
-	global $config,$svn,$verbose;
1218
+	global $config, $svn, $verbose;
1219 1219
 
1220 1220
 	// process alias/externals
1221 1221
 	$svnbranch = $config['svnbase'].'/'.$config['svnbranch'];
@@ -1223,27 +1223,27 @@  discard block
 block discarded – undo
1223 1223
 	$cmd = $svn.' propget svn:externals --strict '.$url;
1224 1224
 	if ($verbose) echo $cmd."\n";
1225 1225
 	$output = $ret = null;
1226
-	exec($cmd,$output,$ret);
1226
+	exec($cmd, $output, $ret);
1227 1227
 	$config['modules'] = array();
1228
-	foreach($output as $line)
1228
+	foreach ($output as $line)
1229 1229
 	{
1230 1230
 		$line = trim($line);
1231 1231
 		if (empty($line) || $line[0] == '#') continue;
1232
-		list($path,$url) = preg_split('/[ \t\r\n]+/',$line);
1232
+		list($path, $url) = preg_split('/[ \t\r\n]+/', $line);
1233 1233
 		$matches = null;
1234
-		if (!preg_match('/([a-z+]+:\/\/[a-z@.]+\/[a-z]+)\/(branches|tags|trunk)/',$url,$matches)) die("Invalid SVN URL: $url\n");
1234
+		if (!preg_match('/([a-z+]+:\/\/[a-z@.]+\/[a-z]+)\/(branches|tags|trunk)/', $url, $matches)) die("Invalid SVN URL: $url\n");
1235 1235
 		$repo = $matches[1];
1236 1236
 		if ($repo == 'http://svn.egroupware.org/egroupware') $repo = 'svn+ssh://[email protected]/egroupware';
1237 1237
 		$config['modules'][$repo][$path] = $url;
1238 1238
 	}
1239 1239
 	// process extra modules
1240
-	foreach($config['extra'] as $module)
1240
+	foreach ($config['extra'] as $module)
1241 1241
 	{
1242
-		$module = config_translate(null, $module);	// allow to use config vars like $svnbranch in module
1243
-		$url = strpos($module,'://') === false ? $svnbranch.'/' : '';
1242
+		$module = config_translate(null, $module); // allow to use config vars like $svnbranch in module
1243
+		$url = strpos($module, '://') === false ? $svnbranch.'/' : '';
1244 1244
 		$url .= $module;
1245
-		if (strpos($module,'://') !== false) $module = basename($module);
1246
-		if (!preg_match('/([a-z+]+:\/\/[a-z@.]+\/[a-z]+)\/(branches|tags|trunk)/',$url,$matches)) die("Invalid SVN URL: $url\n");
1245
+		if (strpos($module, '://') !== false) $module = basename($module);
1246
+		if (!preg_match('/([a-z+]+:\/\/[a-z@.]+\/[a-z]+)\/(branches|tags|trunk)/', $url, $matches)) die("Invalid SVN URL: $url\n");
1247 1247
 		$repo = $matches[1];
1248 1248
 		if ($repo == 'http://svn.egroupware.org/egroupware') $repo = 'svn+ssh://[email protected]/egroupware';
1249 1249
 		$config['modules'][$repo][$config['aliasdir'].'/'.$module] = $url;
@@ -1257,11 +1257,11 @@  discard block
 block discarded – undo
1257 1257
  */
1258 1258
 function do_svntag()
1259 1259
 {
1260
-	global $config,$svn;
1260
+	global $config, $svn;
1261 1261
 
1262
-	if (empty($config['svntag'])) return;	// otherwise we copy everything in svn root!
1262
+	if (empty($config['svntag'])) return; // otherwise we copy everything in svn root!
1263 1263
 
1264
-	$config['svntag'] = config_translate('svntag');	// allow to use config vars like $version in tag
1264
+	$config['svntag'] = config_translate('svntag'); // allow to use config vars like $version in tag
1265 1265
 
1266 1266
 	echo "Creating SVN tag $config[svntag]\n";
1267 1267
 	if (!isset($config['modules']))
@@ -1269,9 +1269,9 @@  discard block
 block discarded – undo
1269 1269
 		get_modules_per_repo();
1270 1270
 	}
1271 1271
 	// create tags (per repo)
1272
-	foreach($config['modules'] as $repo => $modules)
1272
+	foreach ($config['modules'] as $repo => $modules)
1273 1273
 	{
1274
-		$cmd = $svn.' cp --parents -m '.escapeshellarg('Creating '.$config['svntag']).' '.implode(' ',$modules).' '.$repo.'/'.$config['svntag'].'/';
1274
+		$cmd = $svn.' cp --parents -m '.escapeshellarg('Creating '.$config['svntag']).' '.implode(' ', $modules).' '.$repo.'/'.$config['svntag'].'/';
1275 1275
 		run_cmd($cmd);
1276 1276
 	}
1277 1277
 }
@@ -1284,7 +1284,7 @@  discard block
 block discarded – undo
1284 1284
  * @param int|array $no_bailout =null exit code(s) to NOT bail out
1285 1285
  * @return int exit code of $cmd
1286 1286
  */
1287
-function run_cmd($cmd,array &$output=null,$no_bailout=null)
1287
+function run_cmd($cmd, array &$output = null, $no_bailout = null)
1288 1288
 {
1289 1289
 	global $verbose;
1290 1290
 
@@ -1292,18 +1292,18 @@  discard block
 block discarded – undo
1292 1292
 	{
1293 1293
 		echo $cmd."\n";
1294 1294
 		$ret = null;
1295
-		system($cmd,$ret);
1295
+		system($cmd, $ret);
1296 1296
 	}
1297 1297
 	else
1298 1298
 	{
1299 1299
 		$output[] = $cmd;
1300
-		exec($cmd,$output,$ret);
1301
-		if ($verbose) echo implode("\n",$output)."\n";
1300
+		exec($cmd, $output, $ret);
1301
+		if ($verbose) echo implode("\n", $output)."\n";
1302 1302
 	}
1303
-	if ($ret && !in_array($ret,(array)$no_bailout))
1303
+	if ($ret && !in_array($ret, (array)$no_bailout))
1304 1304
 	{
1305
-		if (!$verbose) echo implode("\n",$output)."\n";
1306
-		throw new Exception("Error during '$cmd' --> aborting",$ret);
1305
+		if (!$verbose) echo implode("\n", $output)."\n";
1306
+		throw new Exception("Error during '$cmd' --> aborting", $ret);
1307 1307
 	}
1308 1308
 	return $ret;
1309 1309
 }
@@ -1330,7 +1330,7 @@  discard block
 block discarded – undo
1330 1330
 			return 'NULL';
1331 1331
 		case 'object':
1332 1332
 		case 'array':
1333
-			return str_replace(array("\n",'    '/*,'Array'*/),'',print_r($var,true));
1333
+			return str_replace(array("\n", '    '/*,'Array'*/), '', print_r($var, true));
1334 1334
 	}
1335 1335
 	return 'UNKNOWN TYPE!';
1336 1336
 }
@@ -1340,9 +1340,9 @@  discard block
 block discarded – undo
1340 1340
  *
1341 1341
  * @param string $error =null optional error-message
1342 1342
  */
1343
-function usage($error=null)
1343
+function usage($error = null)
1344 1344
 {
1345
-	global $prog,$config,$verbose;
1345
+	global $prog, $config, $verbose;
1346 1346
 
1347 1347
 	echo "Usage: $prog [-h|--help] [-v|--verbose] [options, ...]\n\n";
1348 1348
 	echo "options and their defaults:\n";
@@ -1352,12 +1352,12 @@  discard block
 block discarded – undo
1352 1352
 	}
1353 1353
 	else
1354 1354
 	{
1355
-		unset($config['modules']);	// they give an error, because of nested array and are quite lengthy
1355
+		unset($config['modules']); // they give an error, because of nested array and are quite lengthy
1356 1356
 	}
1357
-	foreach($config as $name => $default)
1357
+	foreach ($config as $name => $default)
1358 1358
 	{
1359
-		if (is_array($default)) $default = json_encode ($default, JSON_UNESCAPED_SLASHES);
1360
-		echo '--'.str_pad($name,20).$default."\n";
1359
+		if (is_array($default)) $default = json_encode($default, JSON_UNESCAPED_SLASHES);
1360
+		echo '--'.str_pad($name, 20).$default."\n";
1361 1361
 	}
1362 1362
 	if ($error)
1363 1363
 	{
Please login to merge, or discard this patch.