Passed
Pull Request — master (#46)
by Neo
33:01
created
api/src/Hooks.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -254,7 +254,7 @@
 block discarded – undo
254 254
 
255 255
 	/**
256 256
 	 * Static function to build pgp encryption sidebox menu
257
-	 * @param type $appname application name
257
+	 * @param string $appname application name
258 258
 	 */
259 259
 	public static function pgp_encryption_menu($appname)
260 260
 	{
Please login to merge, or discard this patch.
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -278,7 +278,7 @@
 block discarded – undo
278 278
 		if (Header\UserAgent::mobile()) return;
279 279
 
280 280
 		// PGP Encryption (Mailvelope plugin) restore/backup menu
281
-		$file = Array(
281
+		$file = array(
282 282
 			'Backup/Restore ...' => 'javascript:app.'.$appname.'.mailvelopeCreateBackupRestoreDialog();',
283 283
 			'sendToBottom' => true
284 284
 		);
Please login to merge, or discard this patch.
Spacing   +15 added lines, -16 removed lines patch added patch discarded remove patch
@@ -64,22 +64,22 @@  discard block
 block discarded – undo
64 64
 
65 65
 		if (!isset(self::$locations)) self::read();
66 66
 		$hooks = self::$locations[$location];
67
-		if (!isset($hooks) || empty($hooks)) return array();	// not a single app implements that hook
67
+		if (!isset($hooks) || empty($hooks)) return array(); // not a single app implements that hook
68 68
 
69 69
 		$apps = array_keys($hooks);
70 70
 		if (!$no_permission_check)
71 71
 		{
72 72
 			// on install of a new egroupware both hook-apps and user apps may be empty/not set
73
-			$apps = array_intersect((array)$apps,array_keys((array)$GLOBALS['egw_info']['user']['apps']));
73
+			$apps = array_intersect((array)$apps, array_keys((array)$GLOBALS['egw_info']['user']['apps']));
74 74
 		}
75 75
 		if ($order)
76 76
 		{
77
-			$apps = array_unique(array_merge((array)$order,$apps));
77
+			$apps = array_unique(array_merge((array)$order, $apps));
78 78
 		}
79 79
 		$results = array();
80
-		foreach((array)$apps as $appname)
80
+		foreach ((array)$apps as $appname)
81 81
 		{
82
-			$results[$appname] = self::single($args,$appname,$no_permission_check);
82
+			$results[$appname] = self::single($args, $appname, $no_permission_check);
83 83
 		}
84 84
 		return $results;
85 85
 	}
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
 		}
116 116
 
117 117
 		$ret = array();
118
-		foreach((array)self::$locations[$location][$appname] as $hook)
118
+		foreach ((array)self::$locations[$location][$appname] as $hook)
119 119
 		{
120 120
 			try {
121 121
 				// old style file hook
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
 		}
158 158
 
159 159
 		// hooks only existing in filesystem used by setup
160
-		if (!$ret && $try_unregistered && file_exists(EGW_SERVER_ROOT.($hook='/'.$appname.'/inc/hook_'.$location.'.inc.php')))
160
+		if (!$ret && $try_unregistered && file_exists(EGW_SERVER_ROOT.($hook = '/'.$appname.'/inc/hook_'.$location.'.inc.php')))
161 161
 		{
162 162
 			include(EGW_SERVER_ROOT.$hook);
163 163
 			return true;
@@ -189,13 +189,12 @@  discard block
 block discarded – undo
189 189
 	 * @param boolean $return_methods =false true: return hook-method(s)
190 190
 	 * @return int|array the number of found hooks or for $return_methods array with methods
191 191
 	 */
192
-	public static function exists($location, $app, $return_methods=false)
192
+	public static function exists($location, $app, $return_methods = false)
193 193
 	{
194 194
 		if (!isset(self::$locations)) self::read();
195 195
 
196 196
 		//error_log(__METHOD__.__LINE__.array2string(self::$locations[$location]));
197
-		return $return_methods ? self::$locations[$location][$app] :
198
-			(empty(self::$locations[$location][$app]) ? 0 : count(self::$locations[$location][$app]));
197
+		return $return_methods ? self::$locations[$location][$app] : (empty(self::$locations[$location][$app]) ? 0 : count(self::$locations[$location][$app]));
199 198
 	}
200 199
 
201 200
 	/**
@@ -234,7 +233,7 @@  discard block
 block discarded – undo
234 233
 	 *
235 234
 	 * @param boolan $force_rescan =false true: do not use instance cache
236 235
 	 */
237
-	public static function read($force_rescan=false)
236
+	public static function read($force_rescan = false)
238 237
 	{
239 238
 		//$starttime = microtime(true);
240 239
 		if ($force_rescan) Cache::unsetInstance(__CLASS__, 'locations');
@@ -250,18 +249,18 @@  discard block
 block discarded – undo
250 249
 
251 250
 			// read all apps using just filesystem data
252 251
 			$locations = array();
253
-			foreach(array_merge(array('api'), array_keys($GLOBALS['egw_info']['apps'])) as $appname)
252
+			foreach (array_merge(array('api'), array_keys($GLOBALS['egw_info']['apps'])) as $appname)
254 253
 			{
255 254
 				if ($appname[0] == '.' || !is_dir(EGW_SERVER_ROOT.'/'.$appname)) continue;
256 255
 
257
-				$f = EGW_SERVER_ROOT . '/' . $appname . '/setup/setup.inc.php';
256
+				$f = EGW_SERVER_ROOT.'/'.$appname.'/setup/setup.inc.php';
258 257
 				$setup_info = array($appname => array());
259
-				if(@file_exists($f)) include($f);
258
+				if (@file_exists($f)) include($f);
260 259
 
261 260
 				// some apps have setup_info for more then themselfs (eg. api for groupdav)
262
-				foreach($setup_info as $appname => $data)
261
+				foreach ($setup_info as $appname => $data)
263 262
 				{
264
-					foreach((array)$data['hooks'] as $location => $methods)
263
+					foreach ((array)$data['hooks'] as $location => $methods)
265 264
 					{
266 265
 						if (is_int($location))
267 266
 						{
Please login to merge, or discard this patch.
Braces   +57 added lines, -14 removed lines patch added patch discarded remove patch
@@ -62,9 +62,16 @@  discard block
 block discarded – undo
62 62
 		//echo "<p>".__METHOD__.'('.array2string($args).','.array2string($order).','.array2string($no_permission_check).")</p>\n";
63 63
 		$location = is_array($args) ? (isset($args['hook_location']) ? $args['hook_location'] : $args['location']) : $args;
64 64
 
65
-		if (!isset(self::$locations)) self::read();
65
+		if (!isset(self::$locations))
66
+		{
67
+			self::read();
68
+		}
66 69
 		$hooks = self::$locations[$location];
67
-		if (!isset($hooks) || empty($hooks)) return array();	// not a single app implements that hook
70
+		if (!isset($hooks) || empty($hooks))
71
+		{
72
+			return array();
73
+		}
74
+		// not a single app implements that hook
68 75
 
69 76
 		$apps = array_keys($hooks);
70 77
 		if (!$no_permission_check)
@@ -99,9 +106,15 @@  discard block
 block discarded – undo
99 106
 	{
100 107
 		//error_log(__METHOD__."(".array2string($args).",'$appname','$no_permission_check','$try_unregistered')");
101 108
 
102
-		if (!isset(self::$locations)) self::read();
109
+		if (!isset(self::$locations))
110
+		{
111
+			self::read();
112
+		}
103 113
 
104
-		if (!is_array($args)) $args = array('location' => $args);
114
+		if (!is_array($args))
115
+		{
116
+			$args = array('location' => $args);
117
+		}
105 118
 		$location = isset($args['hook_location']) ? $args['hook_location'] : $args['location'];
106 119
 
107 120
 		if (!$appname)
@@ -135,7 +148,10 @@  discard block
 block discarded – undo
135 148
 				// static method of an autoloadable class
136 149
 				if (isset($method) && class_exists($class))
137 150
 				{
138
-					if (is_callable($hook)) $ret[] = call_user_func($hook, $args);
151
+					if (is_callable($hook))
152
+					{
153
+						$ret[] = call_user_func($hook, $args);
154
+					}
139 155
 				}
140 156
 				// app.class.method or not autoloadable class
141 157
 				else
@@ -163,7 +179,10 @@  discard block
 block discarded – undo
163 179
 			return true;
164 180
 		}
165 181
 
166
-		if (!$ret) return false;
182
+		if (!$ret)
183
+		{
184
+			return false;
185
+		}
167 186
 
168 187
 		return count($ret) == 1 ? $ret[0] : $ret;
169 188
 	}
@@ -176,7 +195,10 @@  discard block
 block discarded – undo
176 195
 	 */
177 196
 	public static function count($location)
178 197
 	{
179
-		if (!isset(self::$locations)) self::read();
198
+		if (!isset(self::$locations))
199
+		{
200
+			self::read();
201
+		}
180 202
 
181 203
 		return count(self::$locations[$location]);
182 204
 	}
@@ -191,7 +213,10 @@  discard block
 block discarded – undo
191 213
 	 */
192 214
 	public static function exists($location, $app, $return_methods=false)
193 215
 	{
194
-		if (!isset(self::$locations)) self::read();
216
+		if (!isset(self::$locations))
217
+		{
218
+			self::read();
219
+		}
195 220
 
196 221
 		//error_log(__METHOD__.__LINE__.array2string(self::$locations[$location]));
197 222
 		return $return_methods ? self::$locations[$location][$app] :
@@ -206,7 +231,10 @@  discard block
 block discarded – undo
206 231
 	 */
207 232
 	public static function implemented($location)
208 233
 	{
209
-		if (!isset(self::$locations)) self::read();
234
+		if (!isset(self::$locations))
235
+		{
236
+			self::read();
237
+		}
210 238
 
211 239
 		//error_log(__METHOD__.__LINE__.array2string(self::$locations[$location]));
212 240
 		return isset(self::$locations[$location]) ? array_keys(self::$locations[$location]) : array();
@@ -220,7 +248,10 @@  discard block
 block discarded – undo
220 248
 	 */
221 249
 	static public function disable($hook)
222 250
 	{
223
-		if (!isset(self::$locations)) self::read();
251
+		if (!isset(self::$locations))
252
+		{
253
+			self::read();
254
+		}
224 255
 
225 256
 		$ret = isset(self::$locations[$hook]);
226 257
 
@@ -237,7 +268,10 @@  discard block
 block discarded – undo
237 268
 	public static function read($force_rescan=false)
238 269
 	{
239 270
 		//$starttime = microtime(true);
240
-		if ($force_rescan) Cache::unsetInstance(__CLASS__, 'locations');
271
+		if ($force_rescan)
272
+		{
273
+			Cache::unsetInstance(__CLASS__, 'locations');
274
+		}
241 275
 
242 276
 		self::$locations = Cache::getInstance(__CLASS__, 'locations', function()
243 277
 		{
@@ -252,11 +286,17 @@  discard block
 block discarded – undo
252 286
 			$locations = array();
253 287
 			foreach(array_merge(array('api'), array_keys($GLOBALS['egw_info']['apps'])) as $appname)
254 288
 			{
255
-				if ($appname[0] == '.' || !is_dir(EGW_SERVER_ROOT.'/'.$appname)) continue;
289
+				if ($appname[0] == '.' || !is_dir(EGW_SERVER_ROOT.'/'.$appname))
290
+				{
291
+					continue;
292
+				}
256 293
 
257 294
 				$f = EGW_SERVER_ROOT . '/' . $appname . '/setup/setup.inc.php';
258 295
 				$setup_info = array($appname => array());
259
-				if(@file_exists($f)) include($f);
296
+				if(@file_exists($f))
297
+				{
298
+					include($f);
299
+				}
260 300
 
261 301
 				// some apps have setup_info for more then themselfs (eg. api for groupdav)
262 302
 				foreach($setup_info as $appname => $data)
@@ -284,7 +324,10 @@  discard block
 block discarded – undo
284 324
 	 */
285 325
 	public static function pgp_encryption_menu($appname)
286 326
 	{
287
-		if (Header\UserAgent::mobile()) return;
327
+		if (Header\UserAgent::mobile())
328
+		{
329
+			return;
330
+		}
288 331
 
289 332
 		// PGP Encryption (Mailvelope plugin) restore/backup menu
290 333
 		$file = Array(
Please login to merge, or discard this patch.
api/src/Html.php 4 patches
Doc Comments   +3 added lines, -5 removed lines patch added patch discarded remove patch
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
 	 *
140 140
 	 * @param string $name	string with name of the submitted var which holds the key of the selected item form array
141 141
 	 * @param string|array $key key(s) of already selected item(s) from $arr, eg. '1' or '1,2' or array with keys
142
-	 * @param array $arr array with items to select, eg. $arr = array ( 'y' => 'yes','n' => 'no','m' => 'maybe');
142
+	 * @param integer $arr array with items to select, eg. $arr = array ( 'y' => 'yes','n' => 'no','m' => 'maybe');
143 143
 	 * @param boolean $no_lang NOT run the labels of the options through lang(), default false=use lang()
144 144
 	 * @param string $options additional options (e.g. 'width')
145 145
 	 * @param int $multiple number of lines for a multiselect, default 0 = no multiselect, < 0 sets size without multiple
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 	 *
228 228
 	 * @param string $name	string with name of the submitted var which holds the key of the selected item form array
229 229
 	 * @param string|array $key key(s) of already selected item(s) from $arr, eg. '1' or '1,2' or array with keys
230
-	 * @param array $arr array with items to select, eg. $arr = array ( 'y' => 'yes','n' => 'no','m' => 'maybe');
230
+	 * @param integer $arr array with items to select, eg. $arr = array ( 'y' => 'yes','n' => 'no','m' => 'maybe');
231 231
 	 * @param boolean $no_lang NOT run the labels of the options through lang(), default false=use lang()
232 232
 	 * @param string $options additional options (e.g. 'width')
233 233
 	 * @param int $multiple number of lines for a multiselect, default 3
@@ -313,7 +313,7 @@  discard block
 block discarded – undo
313 313
 	 * @param string $value value
314 314
 	 * @param string $label label
315 315
 	 * @param mixed $selected value or array of values of options to mark as selected
316
-	 * @param boolean $no_lang NOT running the label through lang(), default false=use lang()
316
+	 * @param integer $no_lang NOT running the label through lang(), default false=use lang()
317 317
 	 * @param string $extra extra text, e.g.: style="", default: ''
318 318
 	 * @return string html
319 319
 	 */
@@ -386,7 +386,6 @@  discard block
 block discarded – undo
386 386
 	 *
387 387
 	 * @param string $name name attr. of the tag
388 388
 	 * @param string $value default
389
-	 * @param boolean $ignore_empty if true all empty, zero (!) or unset values, plus filer=none
390 389
 	 * @param boolean $double_encoding =false do we want double encoding or not, default no
391 390
 	 * @param string html
392 391
 	 */
@@ -741,7 +740,6 @@  discard block
 block discarded – undo
741 740
 	 * @param array $hidden_vars array with name-value pairs for hidden input fields
742 741
 	 * @param string $url eGW relative URL, will be run through the link function
743 742
 	 * @param string|array $url_vars parameters for the URL, send to link static function too
744
-	 * @param string $options attributes for the tag, default ''=none
745 743
 	 * @param string $form_name name of the form, defaul ''=none
746 744
 	 * @param string $method method of the form, default 'POST'
747 745
 	 * @return string html
Please login to merge, or discard this patch.
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -425,20 +425,20 @@  discard block
 block discarded – undo
425 425
 	}
426 426
 
427 427
 	/**
428
-	* this static function is a wrapper for fckEditor to create some reuseable layouts
429
-	*
430
-	* @param string $_name name and id of the input-field
431
-	* @param string $_content of the tinymce (will be run through htmlspecialchars !!!), default ''
432
-	* @param string $_mode display mode of the tinymce editor can be: simple, extended or advanced
433
-	* @param array  $_options (toolbar_expanded true/false)
434
-	* @param string $_height ='400px'
435
-	* @param string $_width ='100%'
436
-	* @param string $_start_path ='' if passed activates the browser for image at absolute path passed
437
-	* @param boolean $_purify =true run $_content through htmlpurifier before handing it to fckEditor
438
-	* @param mixed (boolean/string) $_focusToBody=false USED only for CKEDIOR true means yes, focus on top, you may specify TOP or BOTTOM (to focus on the end of the editor area)
439
-	* @param string $_executeJSAfterInit ='' Javascript to be executed after InstanceReady of CKEditor
440
-	* @return string the necessary html for the textarea
441
-	*/
428
+	 * this static function is a wrapper for fckEditor to create some reuseable layouts
429
+	 *
430
+	 * @param string $_name name and id of the input-field
431
+	 * @param string $_content of the tinymce (will be run through htmlspecialchars !!!), default ''
432
+	 * @param string $_mode display mode of the tinymce editor can be: simple, extended or advanced
433
+	 * @param array  $_options (toolbar_expanded true/false)
434
+	 * @param string $_height ='400px'
435
+	 * @param string $_width ='100%'
436
+	 * @param string $_start_path ='' if passed activates the browser for image at absolute path passed
437
+	 * @param boolean $_purify =true run $_content through htmlpurifier before handing it to fckEditor
438
+	 * @param mixed (boolean/string) $_focusToBody=false USED only for CKEDIOR true means yes, focus on top, you may specify TOP or BOTTOM (to focus on the end of the editor area)
439
+	 * @param string $_executeJSAfterInit ='' Javascript to be executed after InstanceReady of CKEditor
440
+	 * @return string the necessary html for the textarea
441
+	 */
442 442
 	static function fckEditor($_name, $_content, $_mode, $_options=array('toolbar_expanded' =>'true'),
443 443
 		$_height='400px', $_width='100%',$_start_path='',$_purify=true, $_focusToBody=false, $_executeJSAfterInit='')
444 444
 	{
@@ -509,21 +509,21 @@  discard block
 block discarded – undo
509 509
 	}
510 510
 
511 511
 	/**
512
-	* this static function is a wrapper for tinymce to create some reuseable layouts
513
-	*
514
-	* Please note: if you did not run init_tinymce already you this static function need to be called before the call to phpgw_header() !!!
515
-	*
516
-	* @param string $_name name and id of the input-field
517
-	* @param string $_mode display mode of the tinymce editor can be: simple, extended or advanced
518
-	* @param string $_content ='' of the tinymce (will be run through htmlspecialchars !!!), default ''
519
-	* @param string $_height ='400px'
520
-	* @param string $_width ='100%'
521
-	* @param boolean $_purify =true
522
-	* @param string $_border ='0px' NOT used for CKEditor
523
-	* @param mixed (boolean/string) $_focusToBody=false USED only for CKEDIOR true means yes, focus on top, you may specify TOP or BOTTOM (to focus on the end of the editor area)
524
-	* @param string $_executeJSAfterInit ='' Javascript to be executed after InstanceReady of CKEditor
525
-	* @return string the necessary html for the textarea
526
-	*/
512
+	 * this static function is a wrapper for tinymce to create some reuseable layouts
513
+	 *
514
+	 * Please note: if you did not run init_tinymce already you this static function need to be called before the call to phpgw_header() !!!
515
+	 *
516
+	 * @param string $_name name and id of the input-field
517
+	 * @param string $_mode display mode of the tinymce editor can be: simple, extended or advanced
518
+	 * @param string $_content ='' of the tinymce (will be run through htmlspecialchars !!!), default ''
519
+	 * @param string $_height ='400px'
520
+	 * @param string $_width ='100%'
521
+	 * @param boolean $_purify =true
522
+	 * @param string $_border ='0px' NOT used for CKEditor
523
+	 * @param mixed (boolean/string) $_focusToBody=false USED only for CKEDIOR true means yes, focus on top, you may specify TOP or BOTTOM (to focus on the end of the editor area)
524
+	 * @param string $_executeJSAfterInit ='' Javascript to be executed after InstanceReady of CKEditor
525
+	 * @return string the necessary html for the textarea
526
+	 */
527 527
 	static function fckEditorQuick($_name, $_mode, $_content='', $_height='400px', $_width='100%',$_purify=true, $_border='0px',$_focusToBody=false,$_executeJSAfterInit='')
528 528
 	{
529 529
 		if (!self::htmlarea_availible() || $_mode == 'ascii')
Please login to merge, or discard this patch.
Spacing   +178 added lines, -178 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 	 */
35 35
 	static function activate_links($content)
36 36
 	{
37
-		if (!$content || strlen($content) < 20) return $content;	// performance
37
+		if (!$content || strlen($content) < 20) return $content; // performance
38 38
 
39 39
 		// Exclude everything which is already a link
40 40
 		$NotAnchor = '(?<!"|href=|href\s=\s|href=\s|href\s=)';
@@ -46,73 +46,73 @@  discard block
 block discarded – undo
46 46
 
47 47
 		//  First match things beginning with http:// (or other protocols)
48 48
 		$optBracket0 = '(<|&lt;)';
49
-		$Protocol = '(http:\/\/|(ftp:\/\/|https:\/\/))';	// only http:// gets removed, other protocolls are shown
49
+		$Protocol = '(http:\/\/|(ftp:\/\/|https:\/\/))'; // only http:// gets removed, other protocolls are shown
50 50
 		$Domain = '([\w-]+\.[\w-.]+)';
51 51
 		$Subdir = '([\w\-\.,@?^=%&;:\/~\+#]*[\w\-\@?^=%&\/~\+#])?';
52 52
 		$optBracket = '(>|&gt;)';
53
-		$Expr = '/' .$optBracket0. $NotAnchor . $Protocol . $Domain . $Subdir . $optBracket . '/i';
53
+		$Expr = '/'.$optBracket0.$NotAnchor.$Protocol.$Domain.$Subdir.$optBracket.'/i';
54 54
 		// use preg_replace_callback as we experienced problems with https links
55
-		$result2 = preg_replace_callback($Expr, function ($match)
55
+		$result2 = preg_replace_callback($Expr, function($match)
56 56
 		{
57
-			return $match[1]."<a href=\"".($match[2]&&!$match[3]?$match[2]:'').($match[3]?$match[3]:'').$match[4].$match[5]."\" target=\"_blank\">".$match[4].$match[5]."</a>".$match[6];
57
+			return $match[1]."<a href=\"".($match[2] && !$match[3] ? $match[2] : '').($match[3] ? $match[3] : '').$match[4].$match[5]."\" target=\"_blank\">".$match[4].$match[5]."</a>".$match[6];
58 58
 		}, $result);
59 59
 
60 60
 		if (true)	// hack to keep IDE from complaing about double assignments
61 61
 		{
62 62
 			//  First match things beginning with http:// (or other protocols)
63
-			$Protocol = '(http:\/\/|(ftp:\/\/|https:\/\/))';	// only http:// gets removed, other protocolls are shown
63
+			$Protocol = '(http:\/\/|(ftp:\/\/|https:\/\/))'; // only http:// gets removed, other protocolls are shown
64 64
 			$Domain = '([\w-]+\.[\w-.]+)';
65 65
 			$Subdir = '([\w\-\.,@?^=%&;:\/~\+#]*[\w\-\@?^=%&\/~\+#])?';
66 66
 			$optStuff = '(&quot;|&quot|;)?';
67
-			$Expr = '/' . $NotAnchor . $Protocol . $Domain . $Subdir . $optStuff . '/i';
67
+			$Expr = '/'.$NotAnchor.$Protocol.$Domain.$Subdir.$optStuff.'/i';
68 68
 			// use preg_replace_callback as we experienced problems with https links
69
-			$result3 = preg_replace_callback($Expr, function ($match)
69
+			$result3 = preg_replace_callback($Expr, function($match)
70 70
 			{
71
-				$additionalQuote="";//at the end, ...
71
+				$additionalQuote = ""; //at the end, ...
72 72
 				// only one &quot at the end is found. chance is, it is not belonging to the URL
73
-				if ($match[5]==';' && (strlen($match[4])-6) >=0 && strpos($match[4],'&quot',strlen($match[4])-6)!==false && strpos(substr($match[4],0,strlen($match[4])-6),'&quot')===false)
73
+				if ($match[5] == ';' && (strlen($match[4]) - 6) >= 0 && strpos($match[4], '&quot', strlen($match[4]) - 6) !== false && strpos(substr($match[4], 0, strlen($match[4]) - 6), '&quot') === false)
74 74
 				{
75
-					$match[4] = substr($match[4],0,strpos($match[4],'&quot',strlen($match[4])-6));
75
+					$match[4] = substr($match[4], 0, strpos($match[4], '&quot', strlen($match[4]) - 6));
76 76
 					$additionalQuote = "&quot;";
77 77
 				}
78 78
 				// if there is quoted stuff within the URL then we have at least one more &quot; in match[4], so chance is the last &quot is matched by the one within
79
-				if ($match[5]==';' && (strlen($match[4])-6) >=0 && strpos($match[4],'&quot',strlen($match[4])-6)!==false && strpos(substr($match[4],0,strlen($match[4])-6),'&quot')!==false)
79
+				if ($match[5] == ';' && (strlen($match[4]) - 6) >= 0 && strpos($match[4], '&quot', strlen($match[4]) - 6) !== false && strpos(substr($match[4], 0, strlen($match[4]) - 6), '&quot') !== false)
80 80
 				{
81 81
 					$match[4] .= $match[5];
82 82
 				}
83
-				if ($match[5]==';'&&$match[4]=="&quot")
83
+				if ($match[5] == ';' && $match[4] == "&quot")
84 84
 				{
85
-					$match[4] ='';
85
+					$match[4] = '';
86 86
 					$additionalQuote = "&quot;";
87 87
 				}
88 88
 				//error_log(__METHOD__.__LINE__.array2string($match));
89
-				return "<a href=\"".($match[1]&&!$match[2]?$match[1]:'').($match[2]?$match[2]:'').$match[3].$match[4]."\" target=\"_blank\">".$match[3].$match[4]."</a>$additionalQuote";
89
+				return "<a href=\"".($match[1] && !$match[2] ? $match[1] : '').($match[2] ? $match[2] : '').$match[3].$match[4]."\" target=\"_blank\">".$match[3].$match[4]."</a>$additionalQuote";
90 90
 			}, $result2);
91 91
 
92 92
 			//  Now match things beginning with www.
93 93
 			$optBracket0 = '(<|&lt;)?';
94
-			$NotHTTP = '(?<!:\/\/|" target=\"_blank\">)';	//	avoid running again on http://www links already handled above
94
+			$NotHTTP = '(?<!:\/\/|" target=\"_blank\">)'; //	avoid running again on http://www links already handled above
95 95
 			$Domain2 = 'www(\.[\w-.]+)';
96 96
 			$Subdir2 = '([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?';
97 97
 			$optBracket = '(>|&gt;|&gt|;)?';
98
-			$Expr = '/' .$optBracket0. $NotAnchor . $NotHTTP . $Domain2 . $Subdir2 .$optBracket. '/i';
98
+			$Expr = '/'.$optBracket0.$NotAnchor.$NotHTTP.$Domain2.$Subdir2.$optBracket.'/i';
99 99
 			//$Expr = '/' . $NotAnchor . $NotHTTP . $Domain . $Subdir . $optBracket . '/i';
100 100
 			// use preg_replace_callback as we experienced problems with links such as <www.example.tld/pfad/zu/einer/pdf-Datei.pdf>
101
-			$result4 = preg_replace_callback( $Expr, function ($match) {
101
+			$result4 = preg_replace_callback($Expr, function($match) {
102 102
 					//error_log(__METHOD__.__LINE__.array2string($match));
103
-					if ($match[4]==';' && (strlen($match[3])-4) >=0 && strpos($match[3],'&gt',strlen($match[3])-4)!==false)
103
+					if ($match[4] == ';' && (strlen($match[3]) - 4) >= 0 && strpos($match[3], '&gt', strlen($match[3]) - 4) !== false)
104 104
 					{
105
-						$match[3] = substr($match[3],0,strpos($match[3],'&gt',strlen($match[3])-4));
105
+						$match[3] = substr($match[3], 0, strpos($match[3], '&gt', strlen($match[3]) - 4));
106 106
 						$match[4] = "&gt;";
107 107
 					}
108
-					if ($match[4]==';'&&$match[3]=="&gt")
108
+					if ($match[4] == ';' && $match[3] == "&gt")
109 109
 					{
110
-						$match[3] ='';
110
+						$match[3] = '';
111 111
 						$match[4] = "&gt;";
112 112
 					}
113 113
 					//error_log(__METHOD__.__LINE__.array2string($match));
114 114
 					return $match[1]."<a href=\"http://www".$match[2].$match[3]."\" target=\"_blank\">"."www".$match[2].$match[3]."</a>".$match[4];
115
-				}, $result3 );
115
+				}, $result3);
116 116
 		}
117 117
 		return $result4;
118 118
 	}
@@ -129,9 +129,9 @@  discard block
 block discarded – undo
129 129
 	 * @param boolean $double_encoding =false do we want double encoding or not, default no
130 130
 	 * @return string
131 131
 	 */
132
-	static function htmlspecialchars($str, $double_encoding=false)
132
+	static function htmlspecialchars($str, $double_encoding = false)
133 133
 	{
134
-		return htmlspecialchars($str,ENT_COMPAT,Translation::charset(),$double_encoding);
134
+		return htmlspecialchars($str, ENT_COMPAT, Translation::charset(), $double_encoding);
135 135
 	}
136 136
 
137 137
 	/**
@@ -146,36 +146,36 @@  discard block
 block discarded – undo
146 146
 	 * @param boolean $enhanced Use enhanced selectbox with search.  Null for default yes if more than 12 options.
147 147
 	 * @return string to set for a template or to echo into html page
148 148
 	 */
149
-	static function select($name, $key, $arr=0,$no_lang=false,$options='',$multiple=0,$enhanced=null)
149
+	static function select($name, $key, $arr = 0, $no_lang = false, $options = '', $multiple = 0, $enhanced = null)
150 150
 	{
151
-		if(is_null($enhanced)) $enhanced = false;	//disabled by default (count($arr) > self::SELECT_ENHANCED_ROW_COUNT);
151
+		if (is_null($enhanced)) $enhanced = false; //disabled by default (count($arr) > self::SELECT_ENHANCED_ROW_COUNT);
152 152
 
153 153
 		if (!is_array($arr))
154 154
 		{
155
-			$arr = array('no','yes');
155
+			$arr = array('no', 'yes');
156 156
 		}
157 157
 		if ((int)$multiple > 0)
158 158
 		{
159 159
 			$options .= ' multiple="1" size="'.(int)$multiple.'"';
160
-			if (substr($name,-2) != '[]')
160
+			if (substr($name, -2) != '[]')
161 161
 			{
162 162
 				$name .= '[]';
163 163
 			}
164 164
 		}
165
-		elseif($multiple < 0)
165
+		elseif ($multiple < 0)
166 166
 		{
167 167
 			$options .= ' size="'.abs($multiple).'"';
168 168
 		}
169 169
 		// fix width for MSIE < 9 in/for selectboxes
170 170
 		if (Header\UserAgent::type() == 'msie' && Header\UserAgent::version() < 9)
171 171
 		{
172
-			if (stripos($options,'onfocus="') === false)
172
+			if (stripos($options, 'onfocus="') === false)
173 173
 			{
174 174
 				$options .= ' onfocus="window.dropdown_menu_hack(this);" ';
175 175
 			}
176 176
 			else
177 177
 			{
178
-				$options = str_ireplace('onfocus="','onfocus="window.dropdown_menu_hack(this);',$options);
178
+				$options = str_ireplace('onfocus="', 'onfocus="window.dropdown_menu_hack(this);', $options);
179 179
 			}
180 180
 		}
181 181
 		$out = "<select name=\"$name\" $options>\n";
@@ -183,14 +183,14 @@  discard block
 block discarded – undo
183 183
 		if (!is_array($key))
184 184
 		{
185 185
 			// explode on ',' only if multiple values expected and the key contains just numbers and commas
186
-			$key = $multiple > 0 && preg_match('/^[,0-9]+$/',$key) ? explode(',',$key) : array($key);
186
+			$key = $multiple > 0 && preg_match('/^[,0-9]+$/', $key) ? explode(',', $key) : array($key);
187 187
 		}
188
-		foreach($arr as $k => $data)
188
+		foreach ($arr as $k => $data)
189 189
 		{
190 190
 			if (!is_array($data) || count($data) == 2 && isset($data['label']) && isset($data['title']))
191 191
 			{
192
-				$out .= self::select_option($k,is_array($data)?$data['label']:$data,$key,$no_lang,
193
-					is_array($data)?$data['title']:'');
192
+				$out .= self::select_option($k, is_array($data) ? $data['label'] : $data, $key, $no_lang,
193
+					is_array($data) ? $data['title'] : '');
194 194
 			}
195 195
 			else
196 196
 			{
@@ -201,19 +201,19 @@  discard block
 block discarded – undo
201 201
 				}
202 202
 				$out .= '<optgroup label="'.self::htmlspecialchars($no_lang || $k == '' ? $k : lang($k))."\">\n";
203 203
 
204
-				foreach($data as $k => $label)
204
+				foreach ($data as $k => $label)
205 205
 				{
206
-					$out .= self::select_option($k,is_array($label)?$label['label']:$label,$key,$no_lang,
207
-						is_array($label)?$label['title']:'');
206
+					$out .= self::select_option($k, is_array($label) ? $label['label'] : $label, $key, $no_lang,
207
+						is_array($label) ? $label['title'] : '');
208 208
 				}
209 209
 				$out .= "</optgroup>\n";
210 210
 			}
211 211
 		}
212 212
 		$out .= "</select>\n";
213 213
 
214
-		if($enhanced) {
214
+		if ($enhanced) {
215 215
 			Framework::includeJS('/api/js/jquery/chosen/chosen.jquery.js');
216
-			Framework::includeCSS('/api/js/jquery/chosen/chosen.css',null,false);
216
+			Framework::includeCSS('/api/js/jquery/chosen/chosen.css', null, false);
217 217
 			$out .= "<script>var lab = egw_LAB || \$LAB; lab.wait(function() {jQuery(function() {if(jQuery().chosen) jQuery('select[name=\"$name\"]').chosen({width: '100%'});});})</script>\n";
218 218
 		}
219 219
 		return $out;
@@ -235,39 +235,39 @@  discard block
 block discarded – undo
235 235
 	 * @param string $style ='' extra style settings like "width: 100%", default '' none
236 236
 	 * @return string to set for a template or to echo into html page
237 237
 	 */
238
-	static function checkbox_multiselect($name, $key, $arr=0,$no_lang=false,$options='',$multiple=3,$selected_first=true,$style='',$enhanced = null)
238
+	static function checkbox_multiselect($name, $key, $arr = 0, $no_lang = false, $options = '', $multiple = 3, $selected_first = true, $style = '', $enhanced = null)
239 239
 	{
240 240
 		//echo "<p align=right>checkbox_multiselect('$name',".array2string($key).",".array2string($arr).",$no_lang,'$options',$multiple,$selected_first,'$style')</p>\n";
241
-		if(is_null($enhanced)) $enhanced = (count($arr) > self::SELECT_ENHANCED_ROW_COUNT);
241
+		if (is_null($enhanced)) $enhanced = (count($arr) > self::SELECT_ENHANCED_ROW_COUNT);
242 242
 
243 243
 		if (!is_array($arr))
244 244
 		{
245
-			$arr = array('no','yes');
245
+			$arr = array('no', 'yes');
246 246
 		}
247 247
 		if ((int)$multiple <= 0) $multiple = 1;
248 248
 
249
-		if (substr($name,-2) != '[]')
249
+		if (substr($name, -2) != '[]')
250 250
 		{
251 251
 			$name .= '[]';
252 252
 		}
253
-		$base_name = substr($name,0,-2);
253
+		$base_name = substr($name, 0, -2);
254 254
 
255
-		if($enhanced) return self::select($name, $key, $arr,$no_lang,$options." style=\"$style\" ",$multiple,$enhanced);
255
+		if ($enhanced) return self::select($name, $key, $arr, $no_lang, $options." style=\"$style\" ", $multiple, $enhanced);
256 256
 
257 257
 		if (!is_array($key))
258 258
 		{
259 259
 			// explode on ',' only if multiple values expected and the key contains just numbers and commas
260
-			$key = preg_match('/^[,0-9]+$/',$key) ? explode(',',$key) : array($key);
260
+			$key = preg_match('/^[,0-9]+$/', $key) ? explode(',', $key) : array($key);
261 261
 		}
262 262
 		$html = '';
263
-		$options_no_id = preg_replace('/id="[^"]+"/i','',$options);
263
+		$options_no_id = preg_replace('/id="[^"]+"/i', '', $options);
264 264
 
265 265
 		if ($selected_first)
266 266
 		{
267 267
 			$selected = $not_selected = array();
268
-			foreach($arr as $val => $label)
268
+			foreach ($arr as $val => $label)
269 269
 			{
270
-				if (in_array((string)$val,$key))
270
+				if (in_array((string)$val, $key))
271 271
 				{
272 272
 					$selected[$val] = $label;
273 273
 				}
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
 			$arr = $selected + $not_selected;
280 280
 		}
281 281
 		$max_len = 0;
282
-		foreach($arr as $val => $label)
282
+		foreach ($arr as $val => $label)
283 283
 		{
284 284
 			if (is_array($label))
285 285
 			{
@@ -295,16 +295,16 @@  discard block
 block discarded – undo
295 295
 
296 296
 			if (strlen($label) > $max_len) $max_len = strlen($label);
297 297
 
298
-			$html .= self::label(self::checkbox($name,in_array((string)$val,$key),$val,$options_no_id.
298
+			$html .= self::label(self::checkbox($name, in_array((string)$val, $key), $val, $options_no_id.
299 299
 				' id="'.$base_name.'['.$val.']'.'"').self::htmlspecialchars($label),
300
-				$base_name.'['.$val.']','',($title ? 'title="'.self::htmlspecialchars($title).'" ':''))."<br />\n";
300
+				$base_name.'['.$val.']', '', ($title ? 'title="'.self::htmlspecialchars($title).'" ' : ''))."<br />\n";
301 301
 		}
302
-		if ($style && substr($style,-1) != ';') $style .= '; ';
303
-		if (strpos($style,'height')===false) $style .= 'height: '.(1.7*$multiple).'em; ';
304
-		if (strpos($style,'width')===false)  $style .= 'width: '.(4+$max_len*($max_len < 15 ? 0.65 : 0.6)).'em; ';
302
+		if ($style && substr($style, -1) != ';') $style .= '; ';
303
+		if (strpos($style, 'height') === false) $style .= 'height: '.(1.7 * $multiple).'em; ';
304
+		if (strpos($style, 'width') === false)  $style .= 'width: '.(4 + $max_len * ($max_len < 15 ? 0.65 : 0.6)).'em; ';
305 305
 		$style .= 'background-color: white; overflow: auto; border: lightgray 2px inset; text-align: left;';
306 306
 
307
-		return self::div($html,$options,'',$style);
307
+		return self::div($html, $options, '', $style);
308 308
 	}
309 309
 
310 310
 	/**
@@ -317,23 +317,23 @@  discard block
 block discarded – undo
317 317
 	 * @param string $extra extra text, e.g.: style="", default: ''
318 318
 	 * @return string html
319 319
 	 */
320
-	static function select_option($value,$label,$selected,$no_lang=0,$title='',$extra='')
320
+	static function select_option($value, $label, $selected, $no_lang = 0, $title = '', $extra = '')
321 321
 	{
322 322
 		// the following compares strict as strings, to archive: '0' == 0 != ''
323 323
 		// the first non-strict search via array_search, is for performance reasons, to not always search the whole array with php
324
-		if (($found = ($key = array_search($value,$selected)) !== false) && (string) $value !== (string) $selected[$key])
324
+		if (($found = ($key = array_search($value, $selected)) !== false) && (string)$value !== (string)$selected[$key])
325 325
 		{
326 326
 			$found = false;
327
-			foreach($selected as $sel)
327
+			foreach ($selected as $sel)
328 328
 			{
329
-				if (($found = (((string) $value) === ((string) $selected[$key])))) break;
329
+				if (($found = (((string)$value) === ((string)$selected[$key])))) break;
330 330
 			}
331 331
 			unset($sel);
332 332
 		}
333
-		return '<option value="'.self::htmlspecialchars($value).'"'.($found  ? ' selected="selected"' : '') .
334
-			($title ? ' title="'.self::htmlspecialchars($no_lang ? $title : lang($title)).'"' : '') .
335
-			($extra ? ' ' . $extra : '') . '>'.
336
-			self::htmlspecialchars($no_lang || $label == '' ? $label : lang($label)) . "</option>\n";
333
+		return '<option value="'.self::htmlspecialchars($value).'"'.($found ? ' selected="selected"' : '').
334
+			($title ? ' title="'.self::htmlspecialchars($no_lang ? $title : lang($title)).'"' : '').
335
+			($extra ? ' '.$extra : '').'>'.
336
+			self::htmlspecialchars($no_lang || $label == '' ? $label : lang($label))."</option>\n";
337 337
 	}
338 338
 
339 339
 	/**
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
 	 * @param string $style css-styles attribute, default ''=none
346 346
 	 * @return string html
347 347
 	 */
348
-	static function div($content,$options='',$class='',$style='')
348
+	static function div($content, $options = '', $class = '', $style = '')
349 349
 	{
350 350
 		if ($class) $options .= ' class="'.$class.'"';
351 351
 		if ($style) $options .= ' style="'.$style.'"';
@@ -361,13 +361,13 @@  discard block
 block discarded – undo
361 361
 	 * @param boolean $ignore_empty if true all empty, zero (!) or unset values, plus filer=none
362 362
 	 * @param string html
363 363
 	 */
364
-	static function input_hidden($vars,$value='',$ignore_empty=True)
364
+	static function input_hidden($vars, $value = '', $ignore_empty = True)
365 365
 	{
366 366
 		if (!is_array($vars))
367 367
 		{
368
-			$vars = array( $vars => $value );
368
+			$vars = array($vars => $value);
369 369
 		}
370
-		foreach($vars as $name => $value)
370
+		foreach ($vars as $name => $value)
371 371
 		{
372 372
 			if (is_array($value))
373 373
 			{
@@ -390,9 +390,9 @@  discard block
 block discarded – undo
390 390
 	 * @param boolean $double_encoding =false do we want double encoding or not, default no
391 391
 	 * @param string html
392 392
 	 */
393
-	static function textarea($name,$value='',$options='',$double_encoding=false)
393
+	static function textarea($name, $value = '', $options = '', $double_encoding = false)
394 394
 	{
395
-		return "<textarea name=\"$name\" $options>".self::htmlspecialchars($value,$double_encoding)."</textarea>\n";
395
+		return "<textarea name=\"$name\" $options>".self::htmlspecialchars($value, $double_encoding)."</textarea>\n";
396 396
 	}
397 397
 
398 398
 	/**
@@ -415,7 +415,7 @@  discard block
 block discarded – undo
415 415
 	 *
416 416
 	 * creates a textarea inputfield for the htmlarea js-widget (returns the necessary html and js)
417 417
 	 */
418
-	static function htmlarea($name,$content='',$style='',$base_href=''/*,$plugins='',$custom_toolbar='',$set_width_height_in_config=false*/)
418
+	static function htmlarea($name, $content = '', $style = '', $base_href = ''/*,$plugins='',$custom_toolbar='',$set_width_height_in_config=false*/)
419 419
 	{
420 420
 		/*if (!self::htmlarea_availible())
421 421
 		{
@@ -439,12 +439,12 @@  discard block
 block discarded – undo
439 439
 	* @param string $_executeJSAfterInit ='' Javascript to be executed after InstanceReady of CKEditor
440 440
 	* @return string the necessary html for the textarea
441 441
 	*/
442
-	static function fckEditor($_name, $_content, $_mode, $_options=array('toolbar_expanded' =>'true'),
443
-		$_height='400px', $_width='100%',$_start_path='',$_purify=true, $_focusToBody=false, $_executeJSAfterInit='')
442
+	static function fckEditor($_name, $_content, $_mode, $_options = array('toolbar_expanded' =>'true'),
443
+		$_height = '400px', $_width = '100%', $_start_path = '', $_purify = true, $_focusToBody = false, $_executeJSAfterInit = '')
444 444
 	{
445 445
 		if (!self::htmlarea_availible() || $_mode == 'ascii')
446 446
 		{
447
-			return self::textarea($_name,$_content,'style="width: '.$_width.'; height: '.$_height.';" id="'.htmlspecialchars($_name).'"');
447
+			return self::textarea($_name, $_content, 'style="width: '.$_width.'; height: '.$_height.';" id="'.htmlspecialchars($_name).'"');
448 448
 		}
449 449
 
450 450
 		//include the ckeditor js file
@@ -465,13 +465,13 @@  discard block
 block discarded – undo
465 465
 		// User preferences
466 466
 		$font = $GLOBALS['egw_info']['user']['preferences']['common']['rte_font'];
467 467
 		$font_size = Html\CkEditorConfig::font_size_from_prefs();
468
-		$font_span = '<span '.($font||$font_size?'style=\"':'').($font?'font-family:'.$font.'; ':'').($font_size?'font-size:'.$font_size.'; ':'').'\">';
468
+		$font_span = '<span '.($font || $font_size ? 'style=\"' : '').($font ? 'font-family:'.$font.'; ' : '').($font_size ? 'font-size:'.$font_size.'; ' : '').'\">';
469 469
 		if (empty($font) && empty($font_size)) $font_span = '';
470 470
 
471 471
 		// we need to enable double encoding here, as ckEditor has to undo one level of encoding
472 472
 		// otherwise < and > chars eg. from html markup entered in regular (not source) input, will turn into html!
473 473
 		//error_log(__METHOD__.__LINE__.' '.Header\UserAgent::type().','.Header\UserAgent::version());
474
-		return self::textarea($_name,$_content,'id="'.htmlspecialchars($_name).'"',true).	// true = double encoding
474
+		return self::textarea($_name, $_content, 'id="'.htmlspecialchars($_name).'"', true).// true = double encoding
475 475
 '
476 476
 <script type="text/javascript">
477 477
 window.CKEDITOR_BASEPATH="'.$GLOBALS['egw_info']['server']['webserver_url'].'/vendor/egroupware/ckeditor/";
@@ -484,22 +484,22 @@  discard block
 block discarded – undo
484 484
 		function (ev)
485 485
 		{
486 486
 			//alert("CKEditorLoad:"+"'.$_focusToBody.'");
487
-'.($_focusToBody?'
487
+'.($_focusToBody ? '
488 488
 			ev.editor.focus();':'').'
489 489
 			var d = ev.editor.document;
490 490
 			var r = new CKEDITOR.dom.range(d);
491 491
 			r.collapse(true);
492 492
 			r.selectNodeContents(d.getBody());
493
-			r.collapse('.($_focusToBody==='BOTTOM'?'false':'true').');
494
-			r.select();'.($font_span?'
493
+			r.collapse('.($_focusToBody === 'BOTTOM' ? 'false' : 'true').');
494
+			r.select();'.($font_span ? '
495 495
 			//this stuff is needed, as the above places the caret just before the span tag
496 496
 			var sN = r.startContainer.getNextSourceNode();
497 497
 			//FF is selecting the span with getNextSourceNode, other browsers need to fetch it with getNext
498 498
 			r.selectNodeContents(((typeof sN.getName==="function") && sN.getName()=="span"?r.startContainer.getNextSourceNode():r.startContainer.getNextSourceNode().getNext()));
499 499
 			r.collapse(true);
500
-			r.select();'.'':'').'
500
+			r.select();'.'' : '').'
501 501
 			ev.editor.resize("100%", '.str_replace('px', '', $pxheight).');
502
-'.($_executeJSAfterInit?$_executeJSAfterInit:'').'
502
+'.($_executeJSAfterInit ? $_executeJSAfterInit : '').'
503 503
 		}
504 504
 	);'.
505 505
 	(trim($_content) == '' && $font_span ? 'CKEDITOR.instances["'.$_name.'"].setData("'.$font_span.'&#8203;</span>");' : '').
@@ -524,16 +524,16 @@  discard block
 block discarded – undo
524 524
 	* @param string $_executeJSAfterInit ='' Javascript to be executed after InstanceReady of CKEditor
525 525
 	* @return string the necessary html for the textarea
526 526
 	*/
527
-	static function fckEditorQuick($_name, $_mode, $_content='', $_height='400px', $_width='100%',$_purify=true, $_border='0px',$_focusToBody=false,$_executeJSAfterInit='')
527
+	static function fckEditorQuick($_name, $_mode, $_content = '', $_height = '400px', $_width = '100%', $_purify = true, $_border = '0px', $_focusToBody = false, $_executeJSAfterInit = '')
528 528
 	{
529 529
 		if (!self::htmlarea_availible() || $_mode == 'ascii')
530 530
 		{
531 531
 			//TODO: use self::textarea
532
-			return "<textarea name=\"$_name\" style=\"".($_width?" width:".$_width.';':" width:100%;").($_height?" height:".$_height.';':" height:400px;").($_border?" border:".$_border.';':" border:0px;")."\">$_content</textarea>";
532
+			return "<textarea name=\"$_name\" style=\"".($_width ? " width:".$_width.';' : " width:100%;").($_height ? " height:".$_height.';' : " height:400px;").($_border ? " border:".$_border.';' : " border:0px;")."\">$_content</textarea>";
533 533
 		}
534 534
 		else
535 535
 		{
536
-			return self::fckEditor($_name, $_content, $_mode, array(), $_height, $_width,'',$_purify,$_focusToBody,$_executeJSAfterInit);
536
+			return self::fckEditor($_name, $_content, $_mode, array(), $_height, $_width, '', $_purify, $_focusToBody, $_executeJSAfterInit);
537 537
 		}
538 538
 	}
539 539
 
@@ -545,7 +545,7 @@  discard block
 block discarded – undo
545 545
 	 * @param string $type type, default ''=not specified = text
546 546
 	 * @param string $options attributes for the tag, default ''=none
547 547
 	 */
548
-	static function input($name,$value='',$type='',$options='' )
548
+	static function input($name, $value = '', $type = '', $options = '')
549 549
 	{
550 550
 		switch ((string)$type)
551 551
 		{
@@ -572,12 +572,12 @@  discard block
 block discarded – undo
572 572
 		'cancelled' => '/no(&|\]|$)/',
573 573
 		'ok'     => '/ok(&|\]|$)/',
574 574
 		'close'  => '/close(&|\]|$)/',
575
-		'add'    => '/(add(&|\]|$)|create)/',	// customfields use create*
575
+		'add'    => '/(add(&|\]|$)|create)/', // customfields use create*
576 576
 	);
577 577
 
578 578
 	static protected $default_classes = array(
579
-		'et2_button_cancel'   => '/cancel(&|\]|$)/',	// yellow
580
-		'et2_button_question' => '/(yes|no)(&|\]|$)/',	// yellow
579
+		'et2_button_cancel'   => '/cancel(&|\]|$)/', // yellow
580
+		'et2_button_question' => '/(yes|no)(&|\]|$)/', // yellow
581 581
 		'et2_button_delete'   => '/delete(&|\]|$)/'		// red
582 582
 	);
583 583
 
@@ -594,7 +594,7 @@  discard block
 block discarded – undo
594 594
 	 * @param string $buttontype which type of html button (button|submit), default ='submit'
595 595
 	 * @return string html
596 596
 	 */
597
-	static function submit_button($name,$label,$onClick='',$no_lang=false,$options='',$image='',$app='phpgwapi', $buttontype='submit')
597
+	static function submit_button($name, $label, $onClick = '', $no_lang = false, $options = '', $image = '', $app = 'phpgwapi', $buttontype = 'submit')
598 598
 	{
599 599
 		// workaround for idots and IE button problem (wrong cursor-image)
600 600
 		if (Header\UserAgent::type() == 'msie')
@@ -606,11 +606,11 @@  discard block
 block discarded – undo
606 606
 
607 607
 		if ($image != '')
608 608
 		{
609
-			$image = str_replace(array('.gif','.GIF','.png','.PNG'),'',$image);
609
+			$image = str_replace(array('.gif', '.GIF', '.png', '.PNG'), '', $image);
610 610
 
611 611
 			if (!($path = Image::find($app, $image)))
612 612
 			{
613
-				$path = $image;		// name may already contain absolut path
613
+				$path = $image; // name may already contain absolut path
614 614
 			}
615 615
 			$image = ' src="'.$path.'"';
616 616
 			$classes[] = 'image_button';
@@ -619,11 +619,11 @@  discard block
 block discarded – undo
619 619
 		{
620 620
 			$label = lang($label);
621 621
 		}
622
-		if (($accesskey = @strstr($label,'&')) && $accesskey[1] != ' ' &&
623
-			(($pos = strpos($accesskey,';')) === false || $pos > 5))
622
+		if (($accesskey = @strstr($label, '&')) && $accesskey[1] != ' ' &&
623
+			(($pos = strpos($accesskey, ';')) === false || $pos > 5))
624 624
 		{
625
-			$label_u = str_replace('&'.$accesskey[1],'<u>'.$accesskey[1].'</u>',$label);
626
-			$label = str_replace('&','',$label);
625
+			$label_u = str_replace('&'.$accesskey[1], '<u>'.$accesskey[1].'</u>', $label);
626
+			$label = str_replace('&', '', $label);
627 627
 			$options .= ' accesskey="'.$accesskey[1].'" '.$options;
628 628
 		}
629 629
 		else
@@ -631,10 +631,10 @@  discard block
 block discarded – undo
631 631
 			$accesskey = '';
632 632
 			$label_u = $label;
633 633
 		}
634
-		if ($onClick) $options .= ' onclick="'.str_replace('"','\\"',$onClick).'"';
634
+		if ($onClick) $options .= ' onclick="'.str_replace('"', '\\"', $onClick).'"';
635 635
 
636 636
 		// add default background-image to get et2 like buttons
637
-		foreach(self::$default_background_images as $img => $reg_exp)
637
+		foreach (self::$default_background_images as $img => $reg_exp)
638 638
 		{
639 639
 			if (preg_match($reg_exp, $name) && ($url = Image::find($GLOBALS['egw_info']['flags']['currentapp'], $img)))
640 640
 			{
@@ -644,7 +644,7 @@  discard block
 block discarded – undo
644 644
 			}
645 645
 		}
646 646
 		// add default class for cancel, delete or yes/no buttons
647
-		foreach(self::$default_classes as $class => $reg_exp)
647
+		foreach (self::$default_classes as $class => $reg_exp)
648 648
 		{
649 649
 			if (preg_match($reg_exp, $name))
650 650
 			{
@@ -678,19 +678,19 @@  discard block
 block discarded – undo
678 678
 	 * @param array|string $vars query or array ('name' => 'value', ...) with query
679 679
 	 * @return string absolut link already run through $phpgw->link
680 680
 	 */
681
-	static function link($_url,$vars='')
681
+	static function link($_url, $vars = '')
682 682
 	{
683 683
 		if (!is_array($vars))
684 684
 		{
685
-			parse_str($vars,$vars);
685
+			parse_str($vars, $vars);
686 686
 		}
687
-		list($url,$v) = explode('?', $_url);	// url may contain additional vars
687
+		list($url, $v) = explode('?', $_url); // url may contain additional vars
688 688
 		if ($v)
689 689
 		{
690
-			parse_str($v,$v);
690
+			parse_str($v, $v);
691 691
 			$vars += $v;
692 692
 		}
693
-		return Framework::link($url,$vars);
693
+		return Framework::link($url, $vars);
694 694
 	}
695 695
 
696 696
 	/**
@@ -702,9 +702,9 @@  discard block
 block discarded – undo
702 702
 	 * @param string $options attributes for the tag, default ''=none
703 703
 	 * @return string html
704 704
 	 */
705
-	static function checkbox($name,$checked=false,$value='True',$options='')
705
+	static function checkbox($name, $checked = false, $value = 'True', $options = '')
706 706
 	{
707
-		return '<input type="checkbox" name="'.$name.'" value="'.self::htmlspecialchars($value).'"' .($checked ? ' checked="1"' : '') . "$options />\n";
707
+		return '<input type="checkbox" name="'.$name.'" value="'.self::htmlspecialchars($value).'"'.($checked ? ' checked="1"' : '')."$options />\n";
708 708
 	}
709 709
 
710 710
 	/**
@@ -719,7 +719,7 @@  discard block
 block discarded – undo
719 719
 	 * @param string $method method of the form, default 'POST'
720 720
 	 * @return string html
721 721
 	 */
722
-	static function form($content,$hidden_vars,$_url,$url_vars='',$name='',$options='',$method='POST')
722
+	static function form($content, $hidden_vars, $_url, $url_vars = '', $name = '', $options = '', $method = 'POST')
723 723
 	{
724 724
 		$url = $_url ? self::link($_url, $url_vars) : $_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'];
725 725
 		$html = "<form method=\"$method\" ".($name != '' ? "name=\"$name\" " : '')."action=\"$url\" $options>\n";
@@ -746,9 +746,9 @@  discard block
 block discarded – undo
746 746
 	 * @param string $method method of the form, default 'POST'
747 747
 	 * @return string html
748 748
 	 */
749
-	static function form_1button($name,$label,$hidden_vars,$url,$url_vars='',$form_name='',$method='POST')
749
+	static function form_1button($name, $label, $hidden_vars, $url, $url_vars = '', $form_name = '', $method = 'POST')
750 750
 	{
751
-		return self::form(self::submit_button($name,$label),$hidden_vars,$url,$url_vars,$form_name,' style="display: inline-block"',$method);
751
+		return self::form(self::submit_button($name, $label), $hidden_vars, $url, $url_vars, $form_name, ' style="display: inline-block"', $method);
752 752
 	}
753 753
 
754 754
 	const THEAD = 1;
@@ -781,34 +781,34 @@  discard block
 block discarded – undo
781 781
 	 * @param boolean $no_table_tr dont return the table- and outmost tr-tabs, default false=return table+tr
782 782
 	 * @return string with html-code of the table
783 783
 	 */
784
-	static function table($rows,$options = '',$no_table_tr=False)
784
+	static function table($rows, $options = '', $no_table_tr = False)
785 785
 	{
786 786
 		$html = $no_table_tr ? '' : "<table $options>\n";
787 787
 
788 788
 		$part = 0;
789
-		foreach($rows as $key => $row)
789
+		foreach ($rows as $key => $row)
790 790
 		{
791 791
 			if (!is_array($row))
792 792
 			{
793
-				continue;					// parameter
793
+				continue; // parameter
794 794
 			}
795 795
 			// get the current part from the optional 'h' or 'f' prefix of the key
796 796
 			$p = $key[0] == 'h' ? self::THEAD : ($key[0] == 'f' ? self::TFOOT : self::TBODY);
797 797
 			if ($part < $p && ($part || $p < self::TBODY))	// add only allowed and neccessary transitions
798 798
 			{
799 799
 				if ($part) $html .= '</'.self::$part2tag[$part].">\n";
800
-				$html .= '<'.self::$part2tag[$part=$p].">\n";
800
+				$html .= '<'.self::$part2tag[$part = $p].">\n";
801 801
 			}
802 802
 			$html .= $no_table_tr && $key == 1 ? '' : "\t<tr ".$rows['.'.$key].">\n";
803 803
 
804
-			foreach($row as $key => $cell)
804
+			foreach ($row as $key => $cell)
805 805
 			{
806 806
 				if ($key[0] == '.')
807 807
 				{
808
-					continue;				// parameter
808
+					continue; // parameter
809 809
 				}
810
-				$table_pos = strpos($cell,'<table');
811
-				$td_pos = strpos($cell,'<td');
810
+				$table_pos = strpos($cell, '<table');
811
+				$td_pos = strpos($cell, '<td');
812 812
 				if ($td_pos !== False && ($table_pos === False || $td_pos < $table_pos))
813 813
 				{
814 814
 					$html .= $cell;
@@ -832,7 +832,7 @@  discard block
 block discarded – undo
832 832
 
833 833
 		if ($no_table_tr)
834 834
 		{
835
-			$html = substr($html,0,-16);
835
+			$html = substr($html, 0, -16);
836 836
 		}
837 837
 		return $html;
838 838
 	}
@@ -844,12 +844,12 @@  discard block
 block discarded – undo
844 844
 	 * @param boolean $no_script if true generate a submit-button if javascript is off
845 845
 	 * @return string html
846 846
 	 */
847
-	static function sbox_submit( $sbox,$no_script=false )
847
+	static function sbox_submit($sbox, $no_script = false)
848 848
 	{
849
-		$html = str_replace('<select','<select onchange="this.form.submit()" ',$sbox);
849
+		$html = str_replace('<select', '<select onchange="this.form.submit()" ', $sbox);
850 850
 		if ($no_script)
851 851
 		{
852
-			$html .= '<noscript>'.self::submit_button('send','>').'</noscript>';
852
+			$html .= '<noscript>'.self::submit_button('send', '>').'</noscript>';
853 853
 		}
854 854
 		return $html;
855 855
 	}
@@ -865,17 +865,17 @@  discard block
 block discarded – undo
865 865
 	 * @param string $height height, default 5px
866 866
 	 * @return string html
867 867
 	 */
868
-	static function progressbar($_percent, $_title='',$options='',$width='',$color='',$height='' )
868
+	static function progressbar($_percent, $_title = '', $options = '', $width = '', $color = '', $height = '')
869 869
 	{
870 870
 		$percent = (int)$_percent;
871 871
 		if (!$width) $width = '30px';
872
-		if (!$height)$height= '5px';
872
+		if (!$height)$height = '5px';
873 873
 		if (!$color) $color = '#D00000';
874 874
 		$title = $_title ? self::htmlspecialchars($_title) : $percent.'%';
875 875
 
876 876
 		return '<div class="onlyPrint">'.$title.'</div><div class="noPrint" title="'.$title.'" '.$options.
877 877
 			' style="height: '.$height.'; width: '.$width.'; border: 1px solid black; padding: 1px; text-align: left;'.
878
-			(@stristr($options,'onclick="') ? ' cursor: pointer;' : '').'">'."\n\t".
878
+			(@stristr($options, 'onclick="') ? ' cursor: pointer;' : '').'">'."\n\t".
879 879
 			'<div style="height: '.$height.'; width: '.$percent.'%; background: '.$color.';"></div>'."\n</div>\n";
880 880
 	}
881 881
 
@@ -893,32 +893,32 @@  discard block
 block discarded – undo
893 893
 	 * @param string $options further options for the tag, default '' = none
894 894
 	 * @return string the html
895 895
 	 */
896
-	static function image( $app,$name,$title='',$options='' )
896
+	static function image($app, $name, $title = '', $options = '')
897 897
 	{
898 898
 		if (is_array($name))	// menuaction and other get-vars
899 899
 		{
900
-			$name = $GLOBALS['egw']->link('/index.php',$name);
900
+			$name = $GLOBALS['egw']->link('/index.php', $name);
901 901
 		}
902
-		if (substr($name,0,5) == 'vfs:/')	// vfs pseudo protocoll
902
+		if (substr($name, 0, 5) == 'vfs:/')	// vfs pseudo protocoll
903 903
 		{
904
-			$name = Framework::link(Vfs::download_url(substr($name,4)));
904
+			$name = Framework::link(Vfs::download_url(substr($name, 4)));
905 905
 		}
906
-		if ($name[0] == '/' || substr($name,0,7) == 'http://' || substr($name,0,8) == 'https://' || stripos($name,'api/thumbnail.php') )
906
+		if ($name[0] == '/' || substr($name, 0, 7) == 'http://' || substr($name, 0, 8) == 'https://' || stripos($name, 'api/thumbnail.php'))
907 907
 		{
908
-			if (!($name[0] == '/' || substr($name,0,7) == 'http://' || substr($name,0,8) == 'https://')) $name = '/'.$name;
908
+			if (!($name[0] == '/' || substr($name, 0, 7) == 'http://' || substr($name, 0, 8) == 'https://')) $name = '/'.$name;
909 909
 			$url = $name;
910 910
 		}
911 911
 		else	// no URL, so try searching the image
912 912
 		{
913
-			$name = str_replace(array('.gif','.GIF','.png','.PNG'),'',$name);
913
+			$name = str_replace(array('.gif', '.GIF', '.png', '.PNG'), '', $name);
914 914
 
915
-			if (!($url = Image::find($app,$name)))
915
+			if (!($url = Image::find($app, $name)))
916 916
 			{
917
-				$url = $name;		// name may already contain absolut path
917
+				$url = $name; // name may already contain absolut path
918 918
 			}
919
-			if($GLOBALS['egw_info']['server']['webserver_url'])
919
+			if ($GLOBALS['egw_info']['server']['webserver_url'])
920 920
 			{
921
-				list(,$path) = explode($GLOBALS['egw_info']['server']['webserver_url'],$url);
921
+				list(,$path) = explode($GLOBALS['egw_info']['server']['webserver_url'], $url);
922 922
 
923 923
 				if (!is_null($path)) $path = EGW_SERVER_ROOT.$path;
924 924
 			}
@@ -927,12 +927,12 @@  discard block
 block discarded – undo
927 927
 				$path = EGW_SERVER_ROOT.$url;
928 928
 			}
929 929
 
930
-			if (is_null($path) || (!@is_readable($path) && stripos($path,'webdav.php')===false))
930
+			if (is_null($path) || (!@is_readable($path) && stripos($path, 'webdav.php') === false))
931 931
 			{
932 932
 				// if the image-name is a percentage, use a progressbar
933
-				if (substr($name,-1) == '%' && is_numeric($percent = substr($name,0,-1)))
933
+				if (substr($name, -1) == '%' && is_numeric($percent = substr($name, 0, -1)))
934 934
 				{
935
-					return self::progressbar($percent,$title);
935
+					return self::progressbar($percent, $title);
936 936
 				}
937 937
 				return $title;
938 938
 			}
@@ -943,12 +943,12 @@  discard block
 block discarded – undo
943 943
 		}
944 944
 
945 945
 		// This block makes pngfix.js useless, adding a check on disable_pngfix to have pngfix.js do its thing
946
-		if (Header\UserAgent::type() == 'msie' && Header\UserAgent::version() < 7.0 && substr($url,-4) == '.png' && ($GLOBALS['egw_info']['user']['preferences']['common']['disable_pngfix'] || !isset($GLOBALS['egw_info']['user']['preferences']['common']['disable_pngfix'])))
946
+		if (Header\UserAgent::type() == 'msie' && Header\UserAgent::version() < 7.0 && substr($url, -4) == '.png' && ($GLOBALS['egw_info']['user']['preferences']['common']['disable_pngfix'] || !isset($GLOBALS['egw_info']['user']['preferences']['common']['disable_pngfix'])))
947 947
 		{
948 948
 			$extra_styles = "display: inline-block; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='$url',sizingMethod='image'); width: 1px; height: 1px;";
949
-			if (false!==strpos($options,'style="'))
949
+			if (false !== strpos($options, 'style="'))
950 950
 			{
951
-				$options = str_replace('style="','style="'.$extra_styles, $options);
951
+				$options = str_replace('style="', 'style="'.$extra_styles, $options);
952 952
 			}
953 953
 			else
954 954
 			{
@@ -968,24 +968,24 @@  discard block
 block discarded – undo
968 968
 	 * @param string $options attributes for the tag, default ''=none
969 969
 	 * @return string the html
970 970
 	 */
971
-	static function a_href( $content,$url,$vars='',$options='')
971
+	static function a_href($content, $url, $vars = '', $options = '')
972 972
 	{
973 973
 		if (is_array($url))
974 974
 		{
975 975
 			$vars = $url;
976 976
 			$url = '/index.php';
977 977
 		}
978
-		elseif (strpos($url,'/')===false &&
979
-			count(explode('.',$url)) >= 3 &&
980
-			!(strpos($url,'mailto:')!==false ||
981
-			strpos($url,'://')!==false ||
982
-			strpos($url,'javascript:')!==false))
978
+		elseif (strpos($url, '/') === false &&
979
+			count(explode('.', $url)) >= 3 &&
980
+			!(strpos($url, 'mailto:') !== false ||
981
+			strpos($url, '://') !== false ||
982
+			strpos($url, 'javascript:') !== false))
983 983
 		{
984 984
 			$url = "/index.php?menuaction=$url";
985 985
 		}
986 986
 		if ($url[0] == '/')		// link relative to eGW
987 987
 		{
988
-			$url = self::link($url,$vars);
988
+			$url = self::link($url, $vars);
989 989
 		}
990 990
 		//echo "<p>self::a_href('".self::htmlspecialchars($content)."','$url',".print_r($vars,True).") = ".self::link($url,$vars)."</p>";
991 991
 		return '<a href="'.self::htmlspecialchars($url).'" '.$options.'>'.$content.'</a>';
@@ -999,7 +999,7 @@  discard block
 block discarded – undo
999 999
 	 */
1000 1000
 	static function bold($content)
1001 1001
 	{
1002
-		return '<b>'.($content?$content.'</b>':'');
1002
+		return '<b>'.($content ? $content.'</b>' : '');
1003 1003
 	}
1004 1004
 
1005 1005
 	/**
@@ -1009,7 +1009,7 @@  discard block
 block discarded – undo
1009 1009
 	 * @param string $options attributes for the tag, default ''=none
1010 1010
 	 * @return string the html
1011 1011
 	 */
1012
-	static function hr($width='',$options='')
1012
+	static function hr($width = '', $options = '')
1013 1013
 	{
1014 1014
 		if ($width) $options .= " width=\"$width\"";
1015 1015
 
@@ -1025,12 +1025,12 @@  discard block
 block discarded – undo
1025 1025
 	 * @param mixed $names String (or Array) with the option-names eg. 'WIDTH,HEIGHT,BORDER'
1026 1026
 	 * @return string with options/attributes
1027 1027
 	 */
1028
-	static function formatOptions($options,$names)
1028
+	static function formatOptions($options, $names)
1029 1029
 	{
1030
-		if (!is_array($options)) $options = explode(',',$options);
1031
-		if (!is_array($names))   $names   = explode(',',$names);
1030
+		if (!is_array($options)) $options = explode(',', $options);
1031
+		if (!is_array($names))   $names   = explode(',', $names);
1032 1032
 
1033
-		foreach($options as $n => $val)
1033
+		foreach ($options as $n => $val)
1034 1034
 		{
1035 1035
 			if ($val != '' && $names[$n] != '')
1036 1036
 			{
@@ -1060,7 +1060,7 @@  discard block
 block discarded – undo
1060 1060
 	 * @param string $options attributes for the tag, default ''=none
1061 1061
 	 * @return string the html
1062 1062
 	 */
1063
-	static function label($content,$id='',$accesskey='',$options='')
1063
+	static function label($content, $id = '', $accesskey = '', $options = '')
1064 1064
 	{
1065 1065
 		if ($id != '')
1066 1066
 		{
@@ -1081,7 +1081,7 @@  discard block
 block discarded – undo
1081 1081
 	 * @param string $options attributes for the tag, default ''=none
1082 1082
 	 * @return string the html
1083 1083
 	 */
1084
-	static function fieldset($content,$legend='',$options='')
1084
+	static function fieldset($content, $legend = '', $options = '')
1085 1085
 	{
1086 1086
 		$html = "<fieldset $options>".($legend ? '<legend>'.self::htmlspecialchars($legend).'</legend>' : '')."\n";
1087 1087
 
@@ -1115,9 +1115,9 @@  discard block
 block discarded – undo
1115 1115
 	 *
1116 1116
 	 * @return string the html code, to be added into the template
1117 1117
 	 */
1118
-	static function tree($_folders,$_selected,$_topFolder=false,$_onNodeSelect="null",$tree='foldertree',$_divClass='',
1119
-		$_leafImage='',$_onCheckHandler=false,$delimiter='/',$folderImageDir=null,$autoLoading=null,$dataMode='JSON',
1120
-		$dragndrop=false)
1118
+	static function tree($_folders, $_selected, $_topFolder = false, $_onNodeSelect = "null", $tree = 'foldertree', $_divClass = '',
1119
+		$_leafImage = '', $_onCheckHandler = false, $delimiter = '/', $folderImageDir = null, $autoLoading = null, $dataMode = 'JSON',
1120
+		$dragndrop = false)
1121 1121
 	{
1122 1122
 		$webserver_url = $GLOBALS['egw_info']['server']['webserver_url'];
1123 1123
 		if (empty($folderImageDir))
@@ -1140,7 +1140,7 @@  discard block
 block discarded – undo
1140 1140
 			//error_log(__METHOD__."() setting templated image-path: $folderImageDir");
1141 1141
 		}
1142 1142
 
1143
-		static $tree_initialised=false;
1143
+		static $tree_initialised = false;
1144 1144
 		if (!$tree_initialised)
1145 1145
 		{
1146 1146
 			Framework::includeCSS('/api/js/dhtmlxtree/codebase/dhtmlxtree.css');
@@ -1150,16 +1150,16 @@  discard block
 block discarded – undo
1150 1150
 			$tree_initialised = true;
1151 1151
 			if (!$_folders && !$autoLoading) return null;
1152 1152
 		}
1153
-		$html = self::div("\n",'id="'.$tree.'"',$_divClass).$html;
1153
+		$html = self::div("\n", 'id="'.$tree.'"', $_divClass).$html;
1154 1154
 		$html .= "<script type='text/javascript'>\n";
1155 1155
 		$html .= "var $tree;";
1156 1156
 		$html .= "egw_LAB.wait(function() {";
1157 1157
 		$html .= "$tree = new"." dhtmlXTreeObject('$tree','100%','100%',0);\n";
1158
-		$html .= "$tree.parentObject.style.overflow='auto';\n";	// dhtmlXTree constructor has hidden hardcoded
1158
+		$html .= "$tree.parentObject.style.overflow='auto';\n"; // dhtmlXTree constructor has hidden hardcoded
1159 1159
 		if (Translation::charset() == 'utf-8') $html .= "if ($tree.setEscapingMode) $tree.setEscapingMode('utf8');\n";
1160 1160
 		$html .= "$tree.setImagePath('$folderImageDir/dhtmlxtree/');\n";
1161 1161
 
1162
-		if($_onCheckHandler)
1162
+		if ($_onCheckHandler)
1163 1163
 		{
1164 1164
 			$html .= "$tree.enableCheckBoxes(1);\n";
1165 1165
 			$html .= "$tree.setOnCheckHandler('$_onCheckHandler');\n";
@@ -1170,7 +1170,7 @@  discard block
 block discarded – undo
1170 1170
 		if ($autoLoading)
1171 1171
 		{
1172 1172
 			$autoLoading = is_array($autoLoading) ?
1173
-				Framework::link('/index.php',$autoLoading) : Framework::link($autoLoading);
1173
+				Framework::link('/index.php', $autoLoading) : Framework::link($autoLoading);
1174 1174
 			$html .= "$tree.setXMLAutoLoading('$autoLoading');\n";
1175 1175
 			if ($dataMode != 'XML') $html .= "$tree.setDataMode('$dataMode');\n";
1176 1176
 
@@ -1211,7 +1211,7 @@  discard block
 block discarded – undo
1211 1211
 		}
1212 1212
 		if (is_string($_folders))
1213 1213
 		{
1214
-			switch($dataMode)
1214
+			switch ($dataMode)
1215 1215
 			{
1216 1216
 				case 'JSON':
1217 1217
 					$html .= "$tree.loadJSONObject($_folders);\n"; break;
@@ -1222,10 +1222,10 @@  discard block
 block discarded – undo
1222 1222
 		else
1223 1223
 		{
1224 1224
 			// evtl. remove leading delimiter
1225
-			if ($_selected[0] == $delimiter) $_selected = substr($_selected,1);
1225
+			if ($_selected[0] == $delimiter) $_selected = substr($_selected, 1);
1226 1226
 
1227 1227
 			$n = 0;
1228
-			foreach($_folders as $path => $data)
1228
+			foreach ($_folders as $path => $data)
1229 1229
 			{
1230 1230
 				if (!is_array($data))
1231 1231
 				{
@@ -1237,10 +1237,10 @@  discard block
 block discarded – undo
1237 1237
 				if ($_leafImage)
1238 1238
 				{
1239 1239
 					$image1 = $image2 = $image3 = "'".$_leafImage."'";
1240
-					if (($next_item = array_slice($_folders, $n+1, 1, true)))
1240
+					if (($next_item = array_slice($_folders, $n + 1, 1, true)))
1241 1241
 					{
1242 1242
 						list($next_path) = each($next_item);
1243
-						if (substr($next_path,0,strlen($path)+1) == $path.'/')
1243
+						if (substr($next_path, 0, strlen($path) + 1) == $path.'/')
1244 1244
 						{
1245 1245
 							$image1 = $image2 = $image3 = '0';
1246 1246
 						}
@@ -1251,22 +1251,22 @@  discard block
 block discarded – undo
1251 1251
 					$image1 = $image2 = $image3 = "'".$data['image']."'";
1252 1252
 				}
1253 1253
 				// evtl. remove leading delimiter
1254
-				if ($path[0] == $delimiter) $path = substr($path,1);
1255
-				$folderParts = explode($delimiter,$path);
1254
+				if ($path[0] == $delimiter) $path = substr($path, 1);
1255
+				$folderParts = explode($delimiter, $path);
1256 1256
 
1257 1257
 				//get rightmost folderpart
1258 1258
 				$label = array_pop($folderParts);
1259 1259
 				if (isset($data['label'])) $label = $data['label'];
1260 1260
 
1261 1261
 				// the rest of the array is the name of the parent
1262
-				$parentName = implode((array)$folderParts,$delimiter);
1263
-				if(empty($parentName)) $parentName = $top;
1262
+				$parentName = implode((array)$folderParts, $delimiter);
1263
+				if (empty($parentName)) $parentName = $top;
1264 1264
 
1265 1265
 				$entryOptions = !isset($data['child']) || $data['child'] ? 'CHILD' : '';
1266 1266
 				if ($_onCheckHandler && $_selected)	// check selected items on multi selection
1267 1267
 				{
1268
-					if (!is_array($_selected)) $_selected = explode(',',$_selected);
1269
-					if (array_search("$path",$_selected)!==false) $entryOptions .= ',CHECKED';
1268
+					if (!is_array($_selected)) $_selected = explode(',', $_selected);
1269
+					if (array_search("$path", $_selected) !== false) $entryOptions .= ',CHECKED';
1270 1270
 					//echo "<p>path=$path, _selected=".print_r($_selected,true).": $entryOptions</p>\n";
1271 1271
 				}
1272 1272
 				// highlight current item
@@ -1286,7 +1286,7 @@  discard block
 block discarded – undo
1286 1286
 		$html .= "$tree.closeAllItems(0);\n";
1287 1287
 		if ($_selected)
1288 1288
 		{
1289
-			foreach(is_array($_selected)?$_selected:array($_selected) as $path)
1289
+			foreach (is_array($_selected) ? $_selected : array($_selected) as $path)
1290 1290
 			{
1291 1291
 				$html .= "$tree.openItem('".addslashes($path)."');\n";
1292 1292
 			}
@@ -1311,7 +1311,7 @@  discard block
 block discarded – undo
1311 1311
 	 *		or to restrict the attribute's values
1312 1312
 	 * @param boolean $_force =null - force the config passed to be used without merging to the default
1313 1313
 	 */
1314
-	static function purify($html,$config=null,$spec=array(),$_force=false)
1314
+	static function purify($html, $config = null, $spec = array(), $_force = false)
1315 1315
 	{
1316 1316
 		return Html\HtmLawed::purify($html, $config, $spec, $_force);
1317 1317
 	}
Please login to merge, or discard this patch.
Braces   +183 added lines, -47 removed lines patch added patch discarded remove patch
@@ -34,7 +34,11 @@  discard block
 block discarded – undo
34 34
 	 */
35 35
 	static function activate_links($content)
36 36
 	{
37
-		if (!$content || strlen($content) < 20) return $content;	// performance
37
+		if (!$content || strlen($content) < 20)
38
+		{
39
+			return $content;
40
+		}
41
+		// performance
38 42
 
39 43
 		// Exclude everything which is already a link
40 44
 		$NotAnchor = '(?<!"|href=|href\s=\s|href=\s|href\s=)';
@@ -57,10 +61,14 @@  discard block
 block discarded – undo
57 61
 			return $match[1]."<a href=\"".($match[2]&&!$match[3]?$match[2]:'').($match[3]?$match[3]:'').$match[4].$match[5]."\" target=\"_blank\">".$match[4].$match[5]."</a>".$match[6];
58 62
 		}, $result);
59 63
 
60
-		if (true)	// hack to keep IDE from complaing about double assignments
64
+		if (true)
65
+		{
66
+			// hack to keep IDE from complaing about double assignments
61 67
 		{
62 68
 			//  First match things beginning with http:// (or other protocols)
63
-			$Protocol = '(http:\/\/|(ftp:\/\/|https:\/\/))';	// only http:// gets removed, other protocolls are shown
69
+			$Protocol = '(http:\/\/|(ftp:\/\/|https:\/\/))';
70
+		}
71
+		// only http:// gets removed, other protocolls are shown
64 72
 			$Domain = '([\w-]+\.[\w-.]+)';
65 73
 			$Subdir = '([\w\-\.,@?^=%&;:\/~\+#]*[\w\-\@?^=%&\/~\+#])?';
66 74
 			$optStuff = '(&quot;|&quot|;)?';
@@ -98,7 +106,8 @@  discard block
 block discarded – undo
98 106
 			$Expr = '/' .$optBracket0. $NotAnchor . $NotHTTP . $Domain2 . $Subdir2 .$optBracket. '/i';
99 107
 			//$Expr = '/' . $NotAnchor . $NotHTTP . $Domain . $Subdir . $optBracket . '/i';
100 108
 			// use preg_replace_callback as we experienced problems with links such as <www.example.tld/pfad/zu/einer/pdf-Datei.pdf>
101
-			$result4 = preg_replace_callback( $Expr, function ($match) {
109
+			$result4 = preg_replace_callback( $Expr, function ($match)
110
+			{
102 111
 					//error_log(__METHOD__.__LINE__.array2string($match));
103 112
 					if ($match[4]==';' && (strlen($match[3])-4) >=0 && strpos($match[3],'&gt',strlen($match[3])-4)!==false)
104 113
 					{
@@ -148,7 +157,11 @@  discard block
 block discarded – undo
148 157
 	 */
149 158
 	static function select($name, $key, $arr=0,$no_lang=false,$options='',$multiple=0,$enhanced=null)
150 159
 	{
151
-		if(is_null($enhanced)) $enhanced = false;	//disabled by default (count($arr) > self::SELECT_ENHANCED_ROW_COUNT);
160
+		if(is_null($enhanced))
161
+		{
162
+			$enhanced = false;
163
+		}
164
+		//disabled by default (count($arr) > self::SELECT_ENHANCED_ROW_COUNT);
152 165
 
153 166
 		if (!is_array($arr))
154 167
 		{
@@ -211,7 +224,8 @@  discard block
 block discarded – undo
211 224
 		}
212 225
 		$out .= "</select>\n";
213 226
 
214
-		if($enhanced) {
227
+		if($enhanced)
228
+		{
215 229
 			Framework::includeJS('/api/js/jquery/chosen/chosen.jquery.js');
216 230
 			Framework::includeCSS('/api/js/jquery/chosen/chosen.css',null,false);
217 231
 			$out .= "<script>var lab = egw_LAB || \$LAB; lab.wait(function() {jQuery(function() {if(jQuery().chosen) jQuery('select[name=\"$name\"]').chosen({width: '100%'});});})</script>\n";
@@ -238,13 +252,19 @@  discard block
 block discarded – undo
238 252
 	static function checkbox_multiselect($name, $key, $arr=0,$no_lang=false,$options='',$multiple=3,$selected_first=true,$style='',$enhanced = null)
239 253
 	{
240 254
 		//echo "<p align=right>checkbox_multiselect('$name',".array2string($key).",".array2string($arr).",$no_lang,'$options',$multiple,$selected_first,'$style')</p>\n";
241
-		if(is_null($enhanced)) $enhanced = (count($arr) > self::SELECT_ENHANCED_ROW_COUNT);
255
+		if(is_null($enhanced))
256
+		{
257
+			$enhanced = (count($arr) > self::SELECT_ENHANCED_ROW_COUNT);
258
+		}
242 259
 
243 260
 		if (!is_array($arr))
244 261
 		{
245 262
 			$arr = array('no','yes');
246 263
 		}
247
-		if ((int)$multiple <= 0) $multiple = 1;
264
+		if ((int)$multiple <= 0)
265
+		{
266
+			$multiple = 1;
267
+		}
248 268
 
249 269
 		if (substr($name,-2) != '[]')
250 270
 		{
@@ -252,7 +272,10 @@  discard block
 block discarded – undo
252 272
 		}
253 273
 		$base_name = substr($name,0,-2);
254 274
 
255
-		if($enhanced) return self::select($name, $key, $arr,$no_lang,$options." style=\"$style\" ",$multiple,$enhanced);
275
+		if($enhanced)
276
+		{
277
+			return self::select($name, $key, $arr,$no_lang,$options." style=\"$style\" ",$multiple,$enhanced);
278
+		}
256 279
 
257 280
 		if (!is_array($key))
258 281
 		{
@@ -290,18 +313,36 @@  discard block
 block discarded – undo
290 313
 			{
291 314
 				$title = '';
292 315
 			}
293
-			if ($label && !$no_lang) $label = lang($label);
294
-			if ($title && !$no_lang) $title = lang($title);
316
+			if ($label && !$no_lang)
317
+			{
318
+				$label = lang($label);
319
+			}
320
+			if ($title && !$no_lang)
321
+			{
322
+				$title = lang($title);
323
+			}
295 324
 
296
-			if (strlen($label) > $max_len) $max_len = strlen($label);
325
+			if (strlen($label) > $max_len)
326
+			{
327
+				$max_len = strlen($label);
328
+			}
297 329
 
298 330
 			$html .= self::label(self::checkbox($name,in_array((string)$val,$key),$val,$options_no_id.
299 331
 				' id="'.$base_name.'['.$val.']'.'"').self::htmlspecialchars($label),
300 332
 				$base_name.'['.$val.']','',($title ? 'title="'.self::htmlspecialchars($title).'" ':''))."<br />\n";
301 333
 		}
302
-		if ($style && substr($style,-1) != ';') $style .= '; ';
303
-		if (strpos($style,'height')===false) $style .= 'height: '.(1.7*$multiple).'em; ';
304
-		if (strpos($style,'width')===false)  $style .= 'width: '.(4+$max_len*($max_len < 15 ? 0.65 : 0.6)).'em; ';
334
+		if ($style && substr($style,-1) != ';')
335
+		{
336
+			$style .= '; ';
337
+		}
338
+		if (strpos($style,'height')===false)
339
+		{
340
+			$style .= 'height: '.(1.7*$multiple).'em; ';
341
+		}
342
+		if (strpos($style,'width')===false)
343
+		{
344
+			$style .= 'width: '.(4+$max_len*($max_len < 15 ? 0.65 : 0.6)).'em; ';
345
+		}
305 346
 		$style .= 'background-color: white; overflow: auto; border: lightgray 2px inset; text-align: left;';
306 347
 
307 348
 		return self::div($html,$options,'',$style);
@@ -326,7 +367,10 @@  discard block
 block discarded – undo
326 367
 			$found = false;
327 368
 			foreach($selected as $sel)
328 369
 			{
329
-				if (($found = (((string) $value) === ((string) $selected[$key])))) break;
370
+				if (($found = (((string) $value) === ((string) $selected[$key]))))
371
+				{
372
+					break;
373
+				}
330 374
 			}
331 375
 			unset($sel);
332 376
 		}
@@ -347,8 +391,14 @@  discard block
 block discarded – undo
347 391
 	 */
348 392
 	static function div($content,$options='',$class='',$style='')
349 393
 	{
350
-		if ($class) $options .= ' class="'.$class.'"';
351
-		if ($style) $options .= ' style="'.$style.'"';
394
+		if ($class)
395
+		{
396
+			$options .= ' class="'.$class.'"';
397
+		}
398
+		if ($style)
399
+		{
400
+			$options .= ' style="'.$style.'"';
401
+		}
352 402
 
353 403
 		return "<div $options>\n".($content ? "$content</div>\n" : '');
354 404
 	}
@@ -373,10 +423,13 @@  discard block
 block discarded – undo
373 423
 			{
374 424
 				$value = json_encode($value);
375 425
 			}
376
-			if (!$ignore_empty || $value && !($name == 'filter' && $value == 'none'))	// dont need to send all the empty vars
426
+			if (!$ignore_empty || $value && !($name == 'filter' && $value == 'none'))
427
+			{
428
+				// dont need to send all the empty vars
377 429
 			{
378 430
 				$html .= "<input type=\"hidden\" name=\"$name\" value=\"".self::htmlspecialchars($value)."\" />\n";
379 431
 			}
432
+			}
380 433
 		}
381 434
 		return $html;
382 435
 	}
@@ -452,7 +505,9 @@  discard block
 block discarded – undo
452 505
 
453 506
 		// run content through htmlpurifier
454 507
 		if ($_purify && !empty($_content))
455
-			$_content = self::purify($_content);
508
+		{
509
+					$_content = self::purify($_content);
510
+		}
456 511
 
457 512
 		// By default the editor start expanded
458 513
 		$expanded = isset($_options['toolbar_expanded']) ?
@@ -466,7 +521,10 @@  discard block
 block discarded – undo
466 521
 		$font = $GLOBALS['egw_info']['user']['preferences']['common']['rte_font'];
467 522
 		$font_size = Html\CkEditorConfig::font_size_from_prefs();
468 523
 		$font_span = '<span '.($font||$font_size?'style=\"':'').($font?'font-family:'.$font.'; ':'').($font_size?'font-size:'.$font_size.'; ':'').'\">';
469
-		if (empty($font) && empty($font_size)) $font_span = '';
524
+		if (empty($font) && empty($font_size))
525
+		{
526
+			$font_span = '';
527
+		}
470 528
 
471 529
 		// we need to enable double encoding here, as ckEditor has to undo one level of encoding
472 530
 		// otherwise < and > chars eg. from html markup entered in regular (not source) input, will turn into html!
@@ -631,7 +689,10 @@  discard block
 block discarded – undo
631 689
 			$accesskey = '';
632 690
 			$label_u = $label;
633 691
 		}
634
-		if ($onClick) $options .= ' onclick="'.str_replace('"','\\"',$onClick).'"';
692
+		if ($onClick)
693
+		{
694
+			$options .= ' onclick="'.str_replace('"','\\"',$onClick).'"';
695
+		}
635 696
 
636 697
 		// add default background-image to get et2 like buttons
637 698
 		foreach(self::$default_background_images as $img => $reg_exp)
@@ -794,9 +855,12 @@  discard block
 block discarded – undo
794 855
 			}
795 856
 			// get the current part from the optional 'h' or 'f' prefix of the key
796 857
 			$p = $key[0] == 'h' ? self::THEAD : ($key[0] == 'f' ? self::TFOOT : self::TBODY);
797
-			if ($part < $p && ($part || $p < self::TBODY))	// add only allowed and neccessary transitions
858
+			if ($part < $p && ($part || $p < self::TBODY))
859
+			{
860
+				// add only allowed and neccessary transitions
798 861
 			{
799 862
 				if ($part) $html .= '</'.self::$part2tag[$part].">\n";
863
+			}
800 864
 				$html .= '<'.self::$part2tag[$part=$p].">\n";
801 865
 			}
802 866
 			$html .= $no_table_tr && $key == 1 ? '' : "\t<tr ".$rows['.'.$key].">\n";
@@ -824,10 +888,13 @@  discard block
 block discarded – undo
824 888
 		{
825 889
 			echo "<p>".function_backtrace()."</p>\n";
826 890
 		}
827
-		if ($part)	// close current part
891
+		if ($part)
892
+		{
893
+			// close current part
828 894
 		{
829 895
 			$html .= "</".self::$part2tag[$part].">\n";
830 896
 		}
897
+		}
831 898
 		$html .= "</table>\n";
832 899
 
833 900
 		if ($no_table_tr)
@@ -868,9 +935,18 @@  discard block
 block discarded – undo
868 935
 	static function progressbar($_percent, $_title='',$options='',$width='',$color='',$height='' )
869 936
 	{
870 937
 		$percent = (int)$_percent;
871
-		if (!$width) $width = '30px';
872
-		if (!$height)$height= '5px';
873
-		if (!$color) $color = '#D00000';
938
+		if (!$width)
939
+		{
940
+			$width = '30px';
941
+		}
942
+		if (!$height)
943
+		{
944
+			$height= '5px';
945
+		}
946
+		if (!$color)
947
+		{
948
+			$color = '#D00000';
949
+		}
874 950
 		$title = $_title ? self::htmlspecialchars($_title) : $percent.'%';
875 951
 
876 952
 		return '<div class="onlyPrint">'.$title.'</div><div class="noPrint" title="'.$title.'" '.$options.
@@ -895,17 +971,26 @@  discard block
 block discarded – undo
895 971
 	 */
896 972
 	static function image( $app,$name,$title='',$options='' )
897 973
 	{
898
-		if (is_array($name))	// menuaction and other get-vars
974
+		if (is_array($name))
975
+		{
976
+			// menuaction and other get-vars
899 977
 		{
900 978
 			$name = $GLOBALS['egw']->link('/index.php',$name);
901 979
 		}
902
-		if (substr($name,0,5) == 'vfs:/')	// vfs pseudo protocoll
980
+		}
981
+		if (substr($name,0,5) == 'vfs:/')
982
+		{
983
+			// vfs pseudo protocoll
903 984
 		{
904 985
 			$name = Framework::link(Vfs::download_url(substr($name,4)));
905 986
 		}
987
+		}
906 988
 		if ($name[0] == '/' || substr($name,0,7) == 'http://' || substr($name,0,8) == 'https://' || stripos($name,'api/thumbnail.php') )
907 989
 		{
908
-			if (!($name[0] == '/' || substr($name,0,7) == 'http://' || substr($name,0,8) == 'https://')) $name = '/'.$name;
990
+			if (!($name[0] == '/' || substr($name,0,7) == 'http://' || substr($name,0,8) == 'https://'))
991
+			{
992
+				$name = '/'.$name;
993
+			}
909 994
 			$url = $name;
910 995
 		}
911 996
 		else	// no URL, so try searching the image
@@ -920,7 +1005,10 @@  discard block
 block discarded – undo
920 1005
 			{
921 1006
 				list(,$path) = explode($GLOBALS['egw_info']['server']['webserver_url'],$url);
922 1007
 
923
-				if (!is_null($path)) $path = EGW_SERVER_ROOT.$path;
1008
+				if (!is_null($path))
1009
+				{
1010
+					$path = EGW_SERVER_ROOT.$path;
1011
+				}
924 1012
 			}
925 1013
 			else
926 1014
 			{
@@ -983,10 +1071,13 @@  discard block
 block discarded – undo
983 1071
 		{
984 1072
 			$url = "/index.php?menuaction=$url";
985 1073
 		}
986
-		if ($url[0] == '/')		// link relative to eGW
1074
+		if ($url[0] == '/')
1075
+		{
1076
+			// link relative to eGW
987 1077
 		{
988 1078
 			$url = self::link($url,$vars);
989 1079
 		}
1080
+		}
990 1081
 		//echo "<p>self::a_href('".self::htmlspecialchars($content)."','$url',".print_r($vars,True).") = ".self::link($url,$vars)."</p>";
991 1082
 		return '<a href="'.self::htmlspecialchars($url).'" '.$options.'>'.$content.'</a>';
992 1083
 	}
@@ -1011,7 +1102,10 @@  discard block
 block discarded – undo
1011 1102
 	 */
1012 1103
 	static function hr($width='',$options='')
1013 1104
 	{
1014
-		if ($width) $options .= " width=\"$width\"";
1105
+		if ($width)
1106
+		{
1107
+			$options .= " width=\"$width\"";
1108
+		}
1015 1109
 
1016 1110
 		return "<hr $options />\n";
1017 1111
 	}
@@ -1027,8 +1121,14 @@  discard block
 block discarded – undo
1027 1121
 	 */
1028 1122
 	static function formatOptions($options,$names)
1029 1123
 	{
1030
-		if (!is_array($options)) $options = explode(',',$options);
1031
-		if (!is_array($names))   $names   = explode(',',$names);
1124
+		if (!is_array($options))
1125
+		{
1126
+			$options = explode(',',$options);
1127
+		}
1128
+		if (!is_array($names))
1129
+		{
1130
+			$names   = explode(',',$names);
1131
+		}
1032 1132
 
1033 1133
 		foreach($options as $n => $val)
1034 1134
 		{
@@ -1146,9 +1246,15 @@  discard block
 block discarded – undo
1146 1246
 			Framework::includeCSS('/api/js/dhtmlxtree/codebase/dhtmlxtree.css');
1147 1247
 			Framework::includeJS('/api/js/dhtmlxtree/codebase/dhtmlxcommon.js');
1148 1248
 			Framework::includeJS('/api/js/dhtmlxtree/sources/dhtmlxtree.js');
1149
-			if ($autoLoading && $dataMode != 'XML') Framework::includeJS('/api/js/dhtmlxtree/sources/ext/dhtmlxtree_json.js');
1249
+			if ($autoLoading && $dataMode != 'XML')
1250
+			{
1251
+				Framework::includeJS('/api/js/dhtmlxtree/sources/ext/dhtmlxtree_json.js');
1252
+			}
1150 1253
 			$tree_initialised = true;
1151
-			if (!$_folders && !$autoLoading) return null;
1254
+			if (!$_folders && !$autoLoading)
1255
+			{
1256
+				return null;
1257
+			}
1152 1258
 		}
1153 1259
 		$html = self::div("\n",'id="'.$tree.'"',$_divClass).$html;
1154 1260
 		$html .= "<script type='text/javascript'>\n";
@@ -1156,7 +1262,10 @@  discard block
 block discarded – undo
1156 1262
 		$html .= "egw_LAB.wait(function() {";
1157 1263
 		$html .= "$tree = new"." dhtmlXTreeObject('$tree','100%','100%',0);\n";
1158 1264
 		$html .= "$tree.parentObject.style.overflow='auto';\n";	// dhtmlXTree constructor has hidden hardcoded
1159
-		if (Translation::charset() == 'utf-8') $html .= "if ($tree.setEscapingMode) $tree.setEscapingMode('utf8');\n";
1265
+		if (Translation::charset() == 'utf-8')
1266
+		{
1267
+			$html .= "if ($tree.setEscapingMode) $tree.setEscapingMode('utf8');\n";
1268
+		}
1160 1269
 		$html .= "$tree.setImagePath('$folderImageDir/dhtmlxtree/');\n";
1161 1270
 
1162 1271
 		if($_onCheckHandler)
@@ -1165,19 +1274,28 @@  discard block
 block discarded – undo
1165 1274
 			$html .= "$tree.setOnCheckHandler('$_onCheckHandler');\n";
1166 1275
 		}
1167 1276
 
1168
-		if ($dragndrop) $html .= "$tree.enableDragAndDrop(true);\n";
1277
+		if ($dragndrop)
1278
+		{
1279
+			$html .= "$tree.enableDragAndDrop(true);\n";
1280
+		}
1169 1281
 
1170 1282
 		if ($autoLoading)
1171 1283
 		{
1172 1284
 			$autoLoading = is_array($autoLoading) ?
1173 1285
 				Framework::link('/index.php',$autoLoading) : Framework::link($autoLoading);
1174 1286
 			$html .= "$tree.setXMLAutoLoading('$autoLoading');\n";
1175
-			if ($dataMode != 'XML') $html .= "$tree.setDataMode('$dataMode');\n";
1287
+			if ($dataMode != 'XML')
1288
+			{
1289
+				$html .= "$tree.setDataMode('$dataMode');\n";
1290
+			}
1176 1291
 
1177 1292
 			// if no folders given, use xml url to load root, incl. setting of selected folder
1178 1293
 			if (!$_folders)
1179 1294
 			{
1180
-				if ($_selected) $autoLoading .= '&selected='.urlencode($_selected);
1295
+				if ($_selected)
1296
+				{
1297
+					$autoLoading .= '&selected='.urlencode($_selected);
1298
+				}
1181 1299
 				unset($_selected);
1182 1300
 				$html .= "$tree.loadXML('$autoLoading');\n";
1183 1301
 				$html .= "});";
@@ -1222,7 +1340,10 @@  discard block
 block discarded – undo
1222 1340
 		else
1223 1341
 		{
1224 1342
 			// evtl. remove leading delimiter
1225
-			if ($_selected[0] == $delimiter) $_selected = substr($_selected,1);
1343
+			if ($_selected[0] == $delimiter)
1344
+			{
1345
+				$_selected = substr($_selected,1);
1346
+			}
1226 1347
 
1227 1348
 			$n = 0;
1228 1349
 			foreach($_folders as $path => $data)
@@ -1251,22 +1372,37 @@  discard block
 block discarded – undo
1251 1372
 					$image1 = $image2 = $image3 = "'".$data['image']."'";
1252 1373
 				}
1253 1374
 				// evtl. remove leading delimiter
1254
-				if ($path[0] == $delimiter) $path = substr($path,1);
1375
+				if ($path[0] == $delimiter)
1376
+				{
1377
+					$path = substr($path,1);
1378
+				}
1255 1379
 				$folderParts = explode($delimiter,$path);
1256 1380
 
1257 1381
 				//get rightmost folderpart
1258 1382
 				$label = array_pop($folderParts);
1259
-				if (isset($data['label'])) $label = $data['label'];
1383
+				if (isset($data['label']))
1384
+				{
1385
+					$label = $data['label'];
1386
+				}
1260 1387
 
1261 1388
 				// the rest of the array is the name of the parent
1262 1389
 				$parentName = implode((array)$folderParts,$delimiter);
1263
-				if(empty($parentName)) $parentName = $top;
1390
+				if(empty($parentName))
1391
+				{
1392
+					$parentName = $top;
1393
+				}
1264 1394
 
1265 1395
 				$entryOptions = !isset($data['child']) || $data['child'] ? 'CHILD' : '';
1266
-				if ($_onCheckHandler && $_selected)	// check selected items on multi selection
1396
+				if ($_onCheckHandler && $_selected)
1397
+				{
1398
+					// check selected items on multi selection
1267 1399
 				{
1268 1400
 					if (!is_array($_selected)) $_selected = explode(',',$_selected);
1269
-					if (array_search("$path",$_selected)!==false) $entryOptions .= ',CHECKED';
1401
+				}
1402
+					if (array_search("$path",$_selected)!==false)
1403
+					{
1404
+						$entryOptions .= ',CHECKED';
1405
+					}
1270 1406
 					//echo "<p>path=$path, _selected=".print_r($_selected,true).": $entryOptions</p>\n";
1271 1407
 				}
1272 1408
 				// highlight current item
Please login to merge, or discard this patch.
api/src/Html/CkEditorConfig.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 	 *
66 66
 	 * Only return skins existing in filesystem, as we disable / remove them if not compatible with supported browsers.
67 67
 	 *
68
-	 * @return array skin => label pairs alphabetical sorted with default moono first
68
+	 * @return string skin => label pairs alphabetical sorted with default moono first
69 69
 	 */
70 70
 	public static function getAvailableCKEditorSkins()
71 71
 	{
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
 	 * Adds all "easy to write" options to the configuration
260 260
 	 *
261 261
 	 * @param array& $config array were config get's added to
262
-	 * @param int|string $height integer height in pixel or string with css unit
262
+	 * @param integer $height integer height in pixel or string with css unit
263 263
 	 * @param boolean|string $expanded_toolbar show toolbar expanded, boolean value, string "false", or string casted to boolean
264 264
 	 * @param string $start_path start path for file browser
265 265
 	 */
@@ -451,7 +451,7 @@  discard block
 block discarded – undo
451 451
 	/**
452 452
 	 * Adds extra
453 453
 	 * @param array $config
454
-	 * @param array $plugins plugins name which needs to be appended into extraPlugins
454
+	 * @param string[] $plugins plugins name which needs to be appended into extraPlugins
455 455
 	 */
456 456
 	public static function append_extraPlugins_config_array (&$config, $plugins)
457 457
 	{
Please login to merge, or discard this patch.
Braces   +64 added lines, -19 removed lines patch added patch discarded remove patch
@@ -77,7 +77,10 @@  discard block
 block discarded – undo
77 77
 
78 78
 		foreach(scandir(EGW_SERVER_ROOT.'/vendor/egroupware/ckeditor/skins') as $skin)
79 79
 		{
80
-			if ($skin[0] == '.') continue;
80
+			if ($skin[0] == '.')
81
+			{
82
+				continue;
83
+			}
81 84
 
82 85
 			if (isset($labels[$skin]))
83 86
 			{
@@ -92,7 +95,10 @@  discard block
 block discarded – undo
92 95
 
93 96
 		// flat skin is reserved for mobile template, although we are not
94 97
 		// supporting it on desktop (becuase FF has problem with action icons)
95
-		if (!\EGroupware\Api\Header\UserAgent::mobile()) unset($skins['flat']);
98
+		if (!\EGroupware\Api\Header\UserAgent::mobile())
99
+		{
100
+			unset($skins['flat']);
101
+		}
96 102
 
97 103
 		// return our default "moono" first
98 104
 		return isset($skins['moono']) ? array('moono' => $skins['moono'])+$skins : $skins;
@@ -108,7 +114,10 @@  discard block
 block discarded – undo
108 114
 	 */
109 115
 	public static function font_size_from_prefs(array $prefs=null, &$size=null, &$unit=null)
110 116
 	{
111
-		if (is_null($prefs)) $prefs = $GLOBALS['egw_info']['user']['preferences'];
117
+		if (is_null($prefs))
118
+		{
119
+			$prefs = $GLOBALS['egw_info']['user']['preferences'];
120
+		}
112 121
 
113 122
 		$size = $prefs['common']['rte_font_size'];
114 123
 		$unit = $prefs['common']['rte_font_unit'];
@@ -132,7 +141,9 @@  discard block
 block discarded – undo
132 141
 		self::$country = $GLOBALS['egw_info']['user']['preferences']['common']['country'];
133 142
 
134 143
 		if (!(strpos(self::$lang, '-')===false))
135
-			list(self::$lang, self::$country) = explode('-', self::$lang);
144
+		{
145
+					list(self::$lang, self::$country) = explode('-', self::$lang);
146
+		}
136 147
 	}
137 148
 
138 149
 	/**
@@ -141,7 +152,9 @@  discard block
 block discarded – undo
141 152
 	private static function get_lang()
142 153
 	{
143 154
 		if (self::$lang == null || self::$country == null)
144
-			self::read_lang_country();
155
+		{
156
+					self::read_lang_country();
157
+		}
145 158
 
146 159
 		return self::$lang;
147 160
 	}
@@ -152,7 +165,9 @@  discard block
 block discarded – undo
152 165
 	private static function get_country()
153 166
 	{
154 167
 		if (self::$lang == null || self::$country == null)
155
-			self::read_lang_country();
168
+		{
169
+					self::read_lang_country();
170
+		}
156 171
 
157 172
 		return strtoupper(self::$country);
158 173
 	}
@@ -290,7 +305,10 @@  discard block
 block discarded – undo
290 305
 
291 306
 		$config['fontSize_sizes'] = '';
292 307
 		$unit = $GLOBALS['egw_info']['user']['preferences']['common']['rte_font_unit'];
293
-		if (empty($unit)) $unit = 'px';
308
+		if (empty($unit))
309
+		{
310
+			$unit = 'px';
311
+		}
294 312
 		foreach(self::$font_size_options as $k => $v)
295 313
 		{
296 314
 			$config['fontSize_sizes'] .= $v.$unit.'/'.$k.$unit.';';
@@ -359,8 +377,14 @@  discard block
 block discarded – undo
359 377
 				if ($spellchecker_button||$scayt_button)
360 378
 				{
361 379
 					$configArray = array();
362
-					if ($spellchecker_button) $configArray[] = $spellchecker_button;
363
-					if ($scayt_button) $configArray[] = $scayt_button;
380
+					if ($spellchecker_button)
381
+					{
382
+						$configArray[] = $spellchecker_button;
383
+					}
384
+					if ($scayt_button)
385
+					{
386
+						$configArray[] = $scayt_button;
387
+					}
364 388
 					$config['toolbar'][] = array('name' => 'tools', 'items' => $configArray);
365 389
 				}
366 390
 				$config['toolbar'][] = array('name' => 'edit', 'items' => array('Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'));
@@ -392,12 +416,20 @@  discard block
 block discarded – undo
392 416
 					if ($spellchecker_button||$scayt_button)
393 417
 					{
394 418
 						$configArray = array('Maximize');
395
-						if ($spellchecker_button) $configArray[] = $spellchecker_button;
396
-						if ($scayt_button) $configArray[] = $scayt_button;
419
+						if ($spellchecker_button)
420
+						{
421
+							$configArray[] = $spellchecker_button;
422
+						}
423
+						if ($scayt_button)
424
+						{
425
+							$configArray[] = $scayt_button;
426
+						}
397 427
 						$config['toolbar'][] = array('name' => 'tools', 'items' => $configArray);
398 428
 					}
399
-					else
400
-						$config['toolbar'][] = array('name' => 'insert', 'items' => array('Maximize'));//, 'Image', 'Table');
429
+					else {
430
+											$config['toolbar'][] = array('name' => 'insert', 'items' => array('Maximize'));
431
+					}
432
+					//, 'Image', 'Table');
401 433
 
402 434
 					$config['toolbar'][count($config['toolbar']) - 1][] = array('name' => 'insert', 'items' => array('Image', 'Table'));
403 435
 				}
@@ -406,17 +438,27 @@  discard block
 block discarded – undo
406 438
 					if ($spellchecker_button||$scayt_button)
407 439
 					{
408 440
 						$configArray = array('Maximize');
409
-						if ($spellchecker_button) $configArray[] = $spellchecker_button;
410
-						if ($scayt_button) $configArray[] = $scayt_button;
441
+						if ($spellchecker_button)
442
+						{
443
+							$configArray[] = $spellchecker_button;
444
+						}
445
+						if ($scayt_button)
446
+						{
447
+							$configArray[] = $scayt_button;
448
+						}
411 449
 						$config['toolbar'][] = array('name' => 'tools', 'items' => $configArray);
412 450
 					}
413
-					else
414
-						$config['toolbar'][] = array('name' => 'tools', 'items' => array('Maximize'));
451
+					else {
452
+											$config['toolbar'][] = array('name' => 'tools', 'items' => array('Maximize'));
453
+					}
415 454
 				}
416 455
 
417 456
 				$config['toolbar'][] = '/';
418 457
 				$config['toolbar'][] = array('name' => 'edit', 'items' => array('Find','Replace','-','SelectAll','RemoveFormat'));
419
-				if ($mode == 'simple-withimage') $config['toolbar'][] = array('name' => 'links', 'items' => array('Image','Link','Unlink'));
458
+				if ($mode == 'simple-withimage')
459
+				{
460
+					$config['toolbar'][] = array('name' => 'links', 'items' => array('Image','Link','Unlink'));
461
+				}
420 462
 				$config['toolbar'][] = array('name' => 'styles', 'items' => array('Format','Font','FontSize'));
421 463
 				$config['toolbar'][] = array('name' => 'colors', 'items' => array('TextColor','BGColor'));
422 464
 				$config['toolbar'][] = array('name' => 'tools', 'items' => array('ShowBlocks','-','About'));
@@ -432,7 +474,10 @@  discard block
 block discarded – undo
432 474
 		self::set_csp_script_src_attrs();
433 475
 
434 476
 		// If not explicitly set, use preference for toolbar mode
435
-		if(!$mode || trim($mode) == '') $mode = $GLOBALS['egw_info']['user']['preferences']['common']['rte_features'];
477
+		if(!$mode || trim($mode) == '')
478
+		{
479
+			$mode = $GLOBALS['egw_info']['user']['preferences']['common']['rte_features'];
480
+		}
436 481
 		$config = array();
437 482
 		$spellchecker_button = null;
438 483
 
Please login to merge, or discard this patch.
Spacing   +40 added lines, -41 removed lines patch added patch discarded remove patch
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 		);
85 85
 		$skins = array();
86 86
 
87
-		foreach(scandir(EGW_SERVER_ROOT.'/vendor/egroupware/ckeditor/skins') as $skin)
87
+		foreach (scandir(EGW_SERVER_ROOT.'/vendor/egroupware/ckeditor/skins') as $skin)
88 88
 		{
89 89
 			if ($skin[0] == '.') continue;
90 90
 
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 		if (!\EGroupware\Api\Header\UserAgent::mobile()) unset($skins['flat']);
105 105
 
106 106
 		// return our default "moono" first
107
-		return isset($skins['moono']) ? array('moono' => $skins['moono'])+$skins : $skins;
107
+		return isset($skins['moono']) ? array('moono' => $skins['moono']) + $skins : $skins;
108 108
 	}
109 109
 
110 110
 	/**
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
 	 * @param string &$unit =null on return just unit
116 116
 	 * @return string font-size including unit
117 117
 	 */
118
-	public static function font_size_from_prefs(array $prefs=null, &$size=null, &$unit=null)
118
+	public static function font_size_from_prefs(array $prefs = null, &$size = null, &$unit = null)
119 119
 	{
120 120
 		if (is_null($prefs)) $prefs = $GLOBALS['egw_info']['user']['preferences'];
121 121
 
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 			$unit = 'px';
127 127
 			$size = (string)(int)$size;
128 128
 		}
129
-		return $size.($size?$unit:'');
129
+		return $size.($size ? $unit : '');
130 130
 	}
131 131
 
132 132
 	/**
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 
141 141
 		self::$country = $GLOBALS['egw_info']['user']['preferences']['common']['country'];
142 142
 
143
-		if (!(strpos(self::$lang, '-')===false))
143
+		if (!(strpos(self::$lang, '-') === false))
144 144
 			list(self::$lang, self::$country) = explode('-', self::$lang);
145 145
 	}
146 146
 
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
 				$skin = "moono"; //this is the basic skin for ckeditor
246 246
 			}
247 247
 			// Skin used for mobile template
248
-			self::$skin = \EGroupware\Api\Header\UserAgent::mobile()?'flat':$skin;
248
+			self::$skin = \EGroupware\Api\Header\UserAgent::mobile() ? 'flat' : $skin;
249 249
 		}
250 250
 
251 251
 		return self::$skin;
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
 			.($start_path != '' ? '&path='.$start_path : '');
267 267
 		}
268 268
 
269
-		return \EGroupware\Api\Egw::link('/index.php',array(
269
+		return \EGroupware\Api\Egw::link('/index.php', array(
270 270
 			'menuaction' => 'api.EGroupware\\Api\\Html\\CkEditorConfig.vfsSelectHelper',
271 271
 			'path' => $start_path
272 272
 		));
@@ -296,8 +296,7 @@  discard block
 block discarded – undo
296 296
 		$config['removePlugins'] = 'elementspath';
297 297
 
298 298
 		$config['toolbarCanCollapse'] = true;
299
-		$config['toolbarStartupExpanded'] = is_bool($expanded_toolbar) ? $expanded_toolbar :
300
-			($expanded_toolbar === 'false' ? false : (boolean)$expanded_toolbar);
299
+		$config['toolbarStartupExpanded'] = is_bool($expanded_toolbar) ? $expanded_toolbar : ($expanded_toolbar === 'false' ? false : (boolean)$expanded_toolbar);
301 300
 
302 301
 		$config['filebrowserBrowseUrl'] = self::get_filebrowserBrowseUrl($start_path);
303 302
 		$config['filebrowserWindowHeight'] = 640;
@@ -310,7 +309,7 @@  discard block
 block discarded – undo
310 309
 		$config['fontSize_sizes'] = '';
311 310
 		$unit = $GLOBALS['egw_info']['user']['preferences']['common']['rte_font_unit'];
312 311
 		if (empty($unit)) $unit = 'px';
313
-		foreach(self::$font_size_options as $k => $v)
312
+		foreach (self::$font_size_options as $k => $v)
314 313
 		{
315 314
 			$config['fontSize_sizes'] .= $v.$unit.'/'.$k.$unit.';';
316 315
 		}
@@ -367,48 +366,48 @@  discard block
 block discarded – undo
367 366
 	 * Writes the toolbar configuration to the options which depends on the chosen
368 367
 	 * mode and the spellchecker_button written by the add_spellchecker_options button
369 368
 	 */
370
-	private static function add_toolbar_options(&$config, $mode, $spellchecker_button, $scayt_button=false)
369
+	private static function add_toolbar_options(&$config, $mode, $spellchecker_button, $scayt_button = false)
371 370
 	{
372 371
 		$config['toolbar'] = array();
373 372
 		switch ($mode)
374 373
 		{
375 374
 			case 'advanced':
376
-				$config['toolbar'][] = array('name' => 'document', 'items' => array('Source','DocProps','-','Preview','-','Templates'));
377
-				$config['toolbar'][] = array('name' => 'clipboard', 'items' => array('Cut','Copy','Paste','PasteText','PasteFromWord','-','Print'));
378
-				if ($spellchecker_button||$scayt_button)
375
+				$config['toolbar'][] = array('name' => 'document', 'items' => array('Source', 'DocProps', '-', 'Preview', '-', 'Templates'));
376
+				$config['toolbar'][] = array('name' => 'clipboard', 'items' => array('Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Print'));
377
+				if ($spellchecker_button || $scayt_button)
379 378
 				{
380 379
 					$configArray = array();
381 380
 					if ($spellchecker_button) $configArray[] = $spellchecker_button;
382 381
 					if ($scayt_button) $configArray[] = $scayt_button;
383 382
 					$config['toolbar'][] = array('name' => 'tools', 'items' => $configArray);
384 383
 				}
385
-				$config['toolbar'][] = array('name' => 'edit', 'items' => array('Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'));
384
+				$config['toolbar'][] = array('name' => 'edit', 'items' => array('Undo', 'Redo', '-', 'Find', 'Replace', '-', 'SelectAll', 'RemoveFormat'));
386 385
 
387 386
 				$config['toolbar'][] = '/';
388 387
 
389
-				$config['toolbar'][] = array('name' => 'basicstyles', 'items' => array('Bold','Italic','Underline','Strike','-','Subscript','Superscript'));
390
-				$config['toolbar'][] = array('name' => 'justify', 'items' => array('JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'));
391
-				$config['toolbar'][] = array('name' => 'paragraph', 'items' => array('BulletedList','NumberedList','-','Outdent','Indent'));
392
-				$config['toolbar'][] = array('name' => 'links', 'items' => array('Link','Unlink','Anchor'));
393
-				$config['toolbar'][] = array('name' => 'insert', 'items' => array('Maximize','Image','Table','HorizontalRule','SpecialChar'/*,'Smiley'*/));
388
+				$config['toolbar'][] = array('name' => 'basicstyles', 'items' => array('Bold', 'Italic', 'Underline', 'Strike', '-', 'Subscript', 'Superscript'));
389
+				$config['toolbar'][] = array('name' => 'justify', 'items' => array('JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'));
390
+				$config['toolbar'][] = array('name' => 'paragraph', 'items' => array('BulletedList', 'NumberedList', '-', 'Outdent', 'Indent'));
391
+				$config['toolbar'][] = array('name' => 'links', 'items' => array('Link', 'Unlink', 'Anchor'));
392
+				$config['toolbar'][] = array('name' => 'insert', 'items' => array('Maximize', 'Image', 'Table', 'HorizontalRule', 'SpecialChar'/*,'Smiley'*/));
394 393
 
395 394
 				$config['toolbar'][] = '/';
396 395
 
397
-				$config['toolbar'][] = array('name' => 'styles', 'items' => array('Style','Format','Font','FontSize'));
398
-				$config['toolbar'][] = array('name' => 'colors', 'items' => array('TextColor','BGColor'));
399
-				$config['toolbar'][] = array('name' => 'tools', 'items' => array('ShowBlocks','-','About'));
396
+				$config['toolbar'][] = array('name' => 'styles', 'items' => array('Style', 'Format', 'Font', 'FontSize'));
397
+				$config['toolbar'][] = array('name' => 'colors', 'items' => array('TextColor', 'BGColor'));
398
+				$config['toolbar'][] = array('name' => 'tools', 'items' => array('ShowBlocks', '-', 'About'));
400 399
 				break;
401 400
 
402 401
 			case 'extended': default:
403
-				$config['toolbar'][] = array('name' => 'clipboard', 'items' => array('Bold','Italic','Underline'));
404
-				$config['toolbar'][] = array('name' => 'justify', 'items' => array('JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'));
405
-				$config['toolbar'][] = array('name' => 'paragraph', 'items' => array('BulletedList','NumberedList'/*,'Smiley'*/,'Outdent','Indent','Undo','Redo'));
406
-				$config['toolbar'][] = array('name' => 'clipboard', 'items' => array('Cut','Copy','Paste','PasteText','PasteFromWord','-','Print'));
402
+				$config['toolbar'][] = array('name' => 'clipboard', 'items' => array('Bold', 'Italic', 'Underline'));
403
+				$config['toolbar'][] = array('name' => 'justify', 'items' => array('JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'));
404
+				$config['toolbar'][] = array('name' => 'paragraph', 'items' => array('BulletedList', 'NumberedList'/*,'Smiley'*/, 'Outdent', 'Indent', 'Undo', 'Redo'));
405
+				$config['toolbar'][] = array('name' => 'clipboard', 'items' => array('Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Print'));
407 406
 
408 407
 				if ($mode == 'extended')
409 408
 				{
410
-					$config['toolbar'][] = array('name' => 'insert', 'items' => array('Image','Link','Unlink','Anchor'));
411
-					if ($spellchecker_button||$scayt_button)
409
+					$config['toolbar'][] = array('name' => 'insert', 'items' => array('Image', 'Link', 'Unlink', 'Anchor'));
410
+					if ($spellchecker_button || $scayt_button)
412 411
 					{
413 412
 						$configArray = array('Maximize');
414 413
 						if ($spellchecker_button) $configArray[] = $spellchecker_button;
@@ -416,13 +415,13 @@  discard block
 block discarded – undo
416 415
 						$config['toolbar'][] = array('name' => 'tools', 'items' => $configArray);
417 416
 					}
418 417
 					else
419
-						$config['toolbar'][] = array('name' => 'insert', 'items' => array('Maximize'));//, 'Image', 'Table');
418
+						$config['toolbar'][] = array('name' => 'insert', 'items' => array('Maximize')); //, 'Image', 'Table');
420 419
 
421 420
 					$config['toolbar'][count($config['toolbar']) - 1][] = array('name' => 'insert', 'items' => array('Image', 'Table'));
422 421
 				}
423 422
 				else
424 423
 				{
425
-					if ($spellchecker_button||$scayt_button)
424
+					if ($spellchecker_button || $scayt_button)
426 425
 					{
427 426
 						$configArray = array('Maximize');
428 427
 						if ($spellchecker_button) $configArray[] = $spellchecker_button;
@@ -434,11 +433,11 @@  discard block
 block discarded – undo
434 433
 				}
435 434
 
436 435
 				$config['toolbar'][] = '/';
437
-				$config['toolbar'][] = array('name' => 'edit', 'items' => array('Find','Replace','-','SelectAll','RemoveFormat'));
438
-				if ($mode == 'simple-withimage') $config['toolbar'][] = array('name' => 'links', 'items' => array('Image','Link','Unlink'));
439
-				$config['toolbar'][] = array('name' => 'styles', 'items' => array('Format','Font','FontSize'));
440
-				$config['toolbar'][] = array('name' => 'colors', 'items' => array('TextColor','BGColor'));
441
-				$config['toolbar'][] = array('name' => 'tools', 'items' => array('ShowBlocks','-','About'));
436
+				$config['toolbar'][] = array('name' => 'edit', 'items' => array('Find', 'Replace', '-', 'SelectAll', 'RemoveFormat'));
437
+				if ($mode == 'simple-withimage') $config['toolbar'][] = array('name' => 'links', 'items' => array('Image', 'Link', 'Unlink'));
438
+				$config['toolbar'][] = array('name' => 'styles', 'items' => array('Format', 'Font', 'FontSize'));
439
+				$config['toolbar'][] = array('name' => 'colors', 'items' => array('TextColor', 'BGColor'));
440
+				$config['toolbar'][] = array('name' => 'tools', 'items' => array('ShowBlocks', '-', 'About'));
442 441
 		}
443 442
 	}
444 443
 
@@ -451,7 +450,7 @@  discard block
 block discarded – undo
451 450
 		self::set_csp_script_src_attrs();
452 451
 
453 452
 		// If not explicitly set, use preference for toolbar mode
454
-		if(!$mode || trim($mode) == '') $mode = $GLOBALS['egw_info']['user']['preferences']['common']['rte_features'];
453
+		if (!$mode || trim($mode) == '') $mode = $GLOBALS['egw_info']['user']['preferences']['common']['rte_features'];
455 454
 		$config = array();
456 455
 		$spellchecker_button = null;
457 456
 
@@ -461,7 +460,7 @@  discard block
 block discarded – undo
461 460
 		self::add_toolbar_options($config, $mode, $spellchecker_button, $scayt_button);
462 461
 		//error_log(__METHOD__."('$mode', $height, ".array2string($expanded_toolbar).") returning ".array2string($config));
463 462
 		// Add extra plugins
464
-		self::append_extraPlugins_config_array($config, array('uploadimage','uploadwidget','widget','notification','notificationaggregator','lineutils'));
463
+		self::append_extraPlugins_config_array($config, array('uploadimage', 'uploadwidget', 'widget', 'notification', 'notificationaggregator', 'lineutils'));
465 464
 		return $config;
466 465
 	}
467 466
 
@@ -470,7 +469,7 @@  discard block
 block discarded – undo
470 469
 	 * @param array $config
471 470
 	 * @param array $plugins plugins name which needs to be appended into extraPlugins
472 471
 	 */
473
-	public static function append_extraPlugins_config_array (&$config, $plugins)
472
+	public static function append_extraPlugins_config_array(&$config, $plugins)
474 473
 	{
475 474
 		if (is_array($plugins))
476 475
 		{
@@ -478,7 +477,7 @@  discard block
 block discarded – undo
478 477
 			{
479 478
 				if (!empty($config['extraPlugins']) && $config['extraPlugins'] !== '')
480 479
 				{
481
-					$config['extraPlugins'] .= ',' . $plugin;
480
+					$config['extraPlugins'] .= ','.$plugin;
482 481
 				}
483 482
 				else
484 483
 				{
@@ -531,6 +530,6 @@  discard block
 block discarded – undo
531 530
 		$response->call('window.opener.et2_htmlarea.buildVfsSelectForCKEditor',
532 531
 				array('funcNum' => $_GET['CKEditorFuncNum']));
533 532
 		$response->call('window.close');
534
-		$tmp->exec('',array());
533
+		$tmp->exec('', array());
535 534
 	}
536 535
 }
Please login to merge, or discard this patch.
api/src/Html/HtmLawed.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -104,7 +104,7 @@
 block discarded – undo
104 104
 	 * @param varchar $html2check =text input Text to check
105 105
 	 * @param mixed $Config = text or array
106 106
 	 * @param mixed $Spec =text or array; The '$spec' argument can be used to disallow an otherwise legal attribute for an element
107
-	 * @return varchar cleaned/fixed html
107
+	 * @return string cleaned/fixed html
108 108
 	 */
109 109
 	function run($html2check, $Config=null, $Spec=array())
110 110
 	{
Please login to merge, or discard this patch.
Spacing   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -85,8 +85,8 @@  discard block
 block discarded – undo
85 85
 		*/
86 86
 
87 87
 		$this->Configuration = array('comment'=>1, //remove comments
88
-			'make_tag_strict'=>3,//3 is a new own config value, to indicate that transformation is to be performed, but don't transform font, as size transformation of numeric sizes to keywords alters the intended result too much
89
-			'balance'=>0,//turn off tag-balancing (config['balance']=>0). That will not introduce any security risk; only standards-compliant tag nesting check/filtering will be turned off (basic tag-balance will remain; i.e., there won't be any unclosed tag, etc., after filtering)
88
+			'make_tag_strict'=>3, //3 is a new own config value, to indicate that transformation is to be performed, but don't transform font, as size transformation of numeric sizes to keywords alters the intended result too much
89
+			'balance'=>0, //turn off tag-balancing (config['balance']=>0). That will not introduce any security risk; only standards-compliant tag nesting check/filtering will be turned off (basic tag-balance will remain; i.e., there won't be any unclosed tag, etc., after filtering)
90 90
 			// tidy eats away even some wanted whitespace, so we switch it off;
91 91
 			// we used it for its compacting and beautifying capabilities, which resulted in better html for further processing
92 92
 			'tidy'=>0,
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 	 * @param mixed $Spec =text or array; The '$spec' argument can be used to disallow an otherwise legal attribute for an element
107 107
 	 * @return varchar cleaned/fixed html
108 108
 	 */
109
-	function run($html2check, $Config=null, $Spec=array())
109
+	function run($html2check, $Config = null, $Spec = array())
110 110
 	{
111 111
 		//error_log(__METHOD__.__LINE__.' Input:'.$html2check);
112 112
 		if (is_array($Config) && is_array($this->Configuration)) $Config = array_merge($this->Configuration, $Config);
@@ -121,11 +121,11 @@  discard block
 block discarded – undo
121 121
 		//error_log(__METHOD__.__LINE__.' Config:'.array2string($Config));
122 122
 
123 123
 		// mind our namespace when defining a function as hook. we handle our own defined hooks here.
124
-		if ($Config['hook_tag']=="hl_my_tag_transform" || $Config['hook_tag']=="hl_email_tag_transform")
124
+		if ($Config['hook_tag'] == "hl_my_tag_transform" || $Config['hook_tag'] == "hl_email_tag_transform")
125 125
 		{
126
-			$Config['hook_tag']=__NAMESPACE__.'\\'.$Config['hook_tag'];
126
+			$Config['hook_tag'] = __NAMESPACE__.'\\'.$Config['hook_tag'];
127 127
 		}
128
-		return ($styles?$styles:'').htmLawed($html2check, $Config, $Spec);
128
+		return ($styles ? $styles : '').htmLawed($html2check, $Config, $Spec);
129 129
 	}
130 130
 
131 131
 	/**
@@ -137,16 +137,16 @@  discard block
 block discarded – undo
137 137
 	 */
138 138
 	static function getStyles(&$html)
139 139
 	{
140
-		$ct=0;
140
+		$ct = 0;
141 141
 		$newStyle = null;
142
-		if (stripos($html,'<style')!==false)  $ct = preg_match_all('#<style(?:\s.*)?>(.+)</style>#isU', $html, $newStyle);
143
-		if ($ct>0)
142
+		if (stripos($html, '<style') !== false)  $ct = preg_match_all('#<style(?:\s.*)?>(.+)</style>#isU', $html, $newStyle);
143
+		if ($ct > 0)
144 144
 		{
145 145
 			//error_log(__METHOD__.__LINE__.array2string($newStyle[0]));
146
-			$style2buffer = implode('',$newStyle[0]);
146
+			$style2buffer = implode('', $newStyle[0]);
147 147
 			// only replace what we have found, we use it here, as we use the same routine in Api\Mail\Html::replaceTagsCompletley
148 148
 			// no need to do the extra routine
149
-			$html = str_ireplace($newStyle[0],'',$html);
149
+			$html = str_ireplace($newStyle[0], '', $html);
150 150
 		}
151 151
 		if ($style2buffer)
152 152
 		{
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 			$test = json_encode($style2buffer);
155 155
 			//error_log(__METHOD__.__LINE__.'#'.$test.'# ->'.strlen($style2buffer).' Error:'.json_last_error());
156 156
 			//if (json_last_error() != JSON_ERROR_NONE && strlen($style2buffer)>0)
157
-			if ($test=="null" && strlen($style2buffer)>0)
157
+			if ($test == "null" && strlen($style2buffer) > 0)
158 158
 			{
159 159
 				// this should not be needed, unless something fails with charset detection/ wrong charset passed
160 160
 				error_log(__METHOD__.__LINE__.' Found Invalid sequence for utf-8 in CSS:'.$style2buffer.' Carset Detected:'.Api\Translation::detect_encoding($style2buffer));
@@ -164,19 +164,19 @@  discard block
 block discarded – undo
164 164
 		$style .= $style2buffer;
165 165
 		// clean out comments and stuff
166 166
 		$search = array(
167
-			'@url\(http:\/\/[^\)].*?\)@si',  // url calls e.g. in style definitions
167
+			'@url\(http:\/\/[^\)].*?\)@si', // url calls e.g. in style definitions
168 168
 //			'@<!--[\s\S]*?[ \t\n\r]*-->@',   // Strip multi-line comments including CDATA
169 169
 //			'@<!--[\s\S]*?[ \t\n\r]*--@',    // Strip broken multi-line comments including CDATA
170 170
 		);
171
-		$style = preg_replace($search,"",$style);
171
+		$style = preg_replace($search, "", $style);
172 172
 
173 173
 		// CSS Security
174 174
 		// http://code.google.com/p/browsersec/wiki/Part1#Cascading_stylesheets
175
-		$css = preg_replace('/(javascript|expession|-moz-binding)/i','',$style);
176
-		if (stripos($css,'script')!==false) Api\Mail\Html::replaceTagsCompletley($css,'script'); // Strip out script that may be included
175
+		$css = preg_replace('/(javascript|expession|-moz-binding)/i', '', $style);
176
+		if (stripos($css, 'script') !== false) Api\Mail\Html::replaceTagsCompletley($css, 'script'); // Strip out script that may be included
177 177
 		// we need this, as styledefinitions are enclosed with curly brackets; and template stuff tries to replace everything between curly brackets that is having no horizontal whitespace
178 178
 		// as the comments as <!-- styledefinition --> in stylesheet are outdated, and ck-editor does not understand it, we remove it
179
-		$css_no_comment = str_replace(array(':','<!--','-->'),array(': ','',''),$css);
179
+		$css_no_comment = str_replace(array(':', '<!--', '-->'), array(': ', '', ''), $css);
180 180
 		//error_log(__METHOD__.__LINE__.$css);
181 181
 		// we already removed what we have found, above, as we used pretty much the same routine as in Api\Mail\Html::replaceTagsCompletley
182 182
 		// no need to do the extra routine
@@ -195,15 +195,15 @@  discard block
 block discarded – undo
195 195
 	 *		or to restrict the attribute's values
196 196
 	 * @param boolean $_force =null - force the config passed to be used without merging to the default
197 197
 	 */
198
-	static function purify($html,$config=null,$spec=array(),$_force=false)
198
+	static function purify($html, $config = null, $spec = array(), $_force = false)
199 199
 	{
200
-		$defaultConfig = array('valid_xhtml'=>1,'safe'=>1);
200
+		$defaultConfig = array('valid_xhtml'=>1, 'safe'=>1);
201 201
 
202
-		if (empty($html)) return $html;	// no need to process further
202
+		if (empty($html)) return $html; // no need to process further
203 203
 		if (!empty($config) && is_string($config))
204 204
 		{
205 205
 			//error_log(__METHOD__.__LINE__.$config);
206
-			$config = json_decode($config,true);
206
+			$config = json_decode($config, true);
207 207
 			if (is_null($config)) error_log(__METHOD__.__LINE__." decoding of config failed; standard will be applied");
208 208
 		}
209 209
 
@@ -213,15 +213,15 @@  discard block
 block discarded – undo
213 213
 
214 214
 		// Check for "blank" = just user preference span - for some reason we can't match on the entity, so approximate
215 215
 		$regex = '#^<span style="[^"]*font-family:'.$font.'; font-size:'.$font_size.'pt;[^"]*">.?</span>$#us';
216
-		if(preg_match($regex,$html))
216
+		if (preg_match($regex, $html))
217 217
 		{
218 218
 			return '';
219 219
 		}
220 220
 		$htmLawed = new HtmLawed();
221
-		if (is_array($config) && $_force===false) $config = array_merge($defaultConfig, $config);
221
+		if (is_array($config) && $_force === false) $config = array_merge($defaultConfig, $config);
222 222
 		if (empty($config)) $config = $defaultConfig;
223 223
 		//error_log(__METHOD__.__LINE__.array2string($config));
224
-		return $htmLawed->run($html,$config,$spec);
224
+		return $htmLawed->run($html, $config, $spec);
225 225
 	}
226 226
 }
227 227
 
@@ -233,17 +233,17 @@  discard block
 block discarded – undo
233 233
  * 						a checking for title, replacing @
234 234
  * 						blockquote checking for cite, replacing @
235 235
  */
236
-function hl_my_tag_transform($element, $attribute_array=0)
236
+function hl_my_tag_transform($element, $attribute_array = 0)
237 237
 {
238 238
 	// If second argument is not received, it means a closing tag is being handled
239
-	if(is_numeric($attribute_array)){
239
+	if (is_numeric($attribute_array)) {
240 240
 		return "</$element>";
241 241
 	}
242 242
 
243 243
 	//if ($element=='img') error_log(__METHOD__.__LINE__." ".$element.'->'.array2string($attribute_array));
244
-	if ($element=='td' && isset($attribute_array['background']))
244
+	if ($element == 'td' && isset($attribute_array['background']))
245 245
 	{
246
-		if (is_object($GLOBALS['egw']) && stripos($attribute_array['background'],$GLOBALS['egw']->link('/index.php'))!==false)
246
+		if (is_object($GLOBALS['egw']) && stripos($attribute_array['background'], $GLOBALS['egw']->link('/index.php')) !== false)
247 247
 		{
248 248
 			//error_log(__METHOD__.__LINE__.array2string($attribute_array));
249 249
 			//$attribute_array['background'] = 'url('.$attribute_array['background'].');';
@@ -251,25 +251,25 @@  discard block
 block discarded – undo
251 251
 		else
252 252
 		{
253 253
 			// $attribute_array['background']='denied:'.$attribute_array['background'];
254
-			unset($attribute_array['background']);// only internal background images are allowed
254
+			unset($attribute_array['background']); // only internal background images are allowed
255 255
 		}
256 256
 	}
257 257
 	// Elements other than 'img' or 'img' without a 'img' attribute are returned unchanged
258
-	if($element == 'img')
258
+	if ($element == 'img')
259 259
 	{
260 260
 		// Re-build 'alt'
261
-		if (isset($attribute_array['alt'])) $attribute_array['alt'] = ($attribute_array['alt']=='image'?'':$attribute_array['alt']);
262
-		if (isset($attribute_array['alt'])&&strpos($attribute_array['alt'],'@')!==false) $attribute_array['alt']=str_replace('@','(at)',$attribute_array['alt']);
261
+		if (isset($attribute_array['alt'])) $attribute_array['alt'] = ($attribute_array['alt'] == 'image' ? '' : $attribute_array['alt']);
262
+		if (isset($attribute_array['alt']) && strpos($attribute_array['alt'], '@') !== false) $attribute_array['alt'] = str_replace('@', '(at)', $attribute_array['alt']);
263 263
 	}
264 264
 	if (isset($attribute_array['title']))
265 265
 	{
266
-		if (strpos($attribute_array['title'],'@')!==false) $attribute_array['title']=str_replace('@','(at)',$attribute_array['title']);
266
+		if (strpos($attribute_array['title'], '@') !== false) $attribute_array['title'] = str_replace('@', '(at)', $attribute_array['title']);
267 267
 	}
268 268
 	if ($element == 'blockquote')
269 269
 	{
270 270
 		if (isset($attribute_array['cite']))
271 271
 		{
272
-			if (strpos($attribute_array['cite'],'@')!==false) $attribute_array['cite']=str_replace('@','(at)',$attribute_array['cite']);
272
+			if (strpos($attribute_array['cite'], '@') !== false) $attribute_array['cite'] = str_replace('@', '(at)', $attribute_array['cite']);
273 273
 		}
274 274
 	}
275 275
 	/*
@@ -301,31 +301,31 @@  discard block
 block discarded – undo
301 301
 		$attribute_array['style'] = implode('; ', $style);
302 302
 	}
303 303
 	*/
304
-	if (isset($attribute_array['style']) && stripos($attribute_array['style'],'script')!==false) $attribute_array['style'] = str_ireplace('script','',$attribute_array['style']);
305
-	if($element == 'a')
304
+	if (isset($attribute_array['style']) && stripos($attribute_array['style'], 'script') !== false) $attribute_array['style'] = str_ireplace('script', '', $attribute_array['style']);
305
+	if ($element == 'a')
306 306
 	{
307 307
 		//error_log(__METHOD__.__LINE__.array2string($attribute_array));
308 308
 		// rebuild Anchors, if processed by hl_email_tag_transform
309
-		if (strpos($attribute_array['href'],"denied:javascript:GoToAnchor('")===0)
309
+		if (strpos($attribute_array['href'], "denied:javascript:GoToAnchor('") === 0)
310 310
 		{
311
-			$attribute_array['href']=str_ireplace("');",'',str_ireplace("denied:javascript:GoToAnchor('","#",$attribute_array['href']));
311
+			$attribute_array['href'] = str_ireplace("');", '', str_ireplace("denied:javascript:GoToAnchor('", "#", $attribute_array['href']));
312 312
 		}
313
-		if (strpos($attribute_array['href'],"javascript:GoToAnchor('")===0)
313
+		if (strpos($attribute_array['href'], "javascript:GoToAnchor('") === 0)
314 314
 		{
315
-			$attribute_array['href']=str_ireplace("');",'',str_ireplace("javascript:GoToAnchor('","#",$attribute_array['href']));
315
+			$attribute_array['href'] = str_ireplace("');", '', str_ireplace("javascript:GoToAnchor('", "#", $attribute_array['href']));
316 316
 		}
317
-		if (strpos($attribute_array['href'],'denied:javascript')===0) $attribute_array['href']='';
317
+		if (strpos($attribute_array['href'], 'denied:javascript') === 0) $attribute_array['href'] = '';
318 318
 	}
319 319
 
320 320
 	// Build the attributes string
321 321
 	$attributes = '';
322
-	foreach($attribute_array as $k=>$v){
322
+	foreach ($attribute_array as $k=>$v) {
323 323
 		$attributes .= " {$k}=\"{$v}\"";
324 324
 	}
325 325
 
326 326
 	// Return the opening tag with attributes
327 327
 	static $empty_elements = array('area'=>1, 'br'=>1, 'col'=>1, 'embed'=>1, 'hr'=>1, 'img'=>1, 'input'=>1, 'isindex'=>1, 'param'=>1);
328
-	return "<{$element}{$attributes}". (isset($empty_elements[$element]) ? ' /' : ''). '>';
328
+	return "<{$element}{$attributes}".(isset($empty_elements[$element]) ? ' /' : '').'>';
329 329
 }
330 330
 
331 331
 /**
@@ -339,22 +339,22 @@  discard block
 block discarded – undo
339 339
  * 						blockquote -checking for cite, replacing @
340 340
  * 						throwing away excess div elements, that carry no style or class or id info
341 341
  */
342
-function hl_email_tag_transform($element, $attribute_array=0)
342
+function hl_email_tag_transform($element, $attribute_array = 0)
343 343
 {
344 344
 	//error_log(__METHOD__.__LINE__.$element.'=>'.array2string($attribute_array));
345 345
 	static $lastelement = null;
346 346
 	static $throwawaycounter = null;
347
-	if (is_null($lastelement)) $lastelement='';
347
+	if (is_null($lastelement)) $lastelement = '';
348 348
 	if (is_null($throwawaycounter)) $throwawaycounter = 0;
349 349
 	//if ($throwawaycounter>1) error_log(__METHOD__.__LINE__.' '.$throwawaycounter.$element.array2string($attribute_array));
350
-	if ($element=='div' && $element==$lastelement && ($attribute_array==0 || empty($attribute_array)))
350
+	if ($element == 'div' && $element == $lastelement && ($attribute_array == 0 || empty($attribute_array)))
351 351
 	{
352 352
 		if (is_array($attribute_array)) $throwawaycounter++;
353
-		if ($attribute_array==0 && $throwawaycounter>0) $throwawaycounter--;
354
-		if ($throwawaycounter>1) return '';
353
+		if ($attribute_array == 0 && $throwawaycounter > 0) $throwawaycounter--;
354
+		if ($throwawaycounter > 1) return '';
355 355
 	}
356
-	if ($lastelement=='div' && $element!=$lastelement && is_array($attribute_array)) $throwawaycounter = 0;
357
-	if (is_array($attribute_array) && !empty($attribute_array) && $element=='div')
356
+	if ($lastelement == 'div' && $element != $lastelement && is_array($attribute_array)) $throwawaycounter = 0;
357
+	if (is_array($attribute_array) && !empty($attribute_array) && $element == 'div')
358 358
 	{
359 359
 		$lastelement = 'div_with_attr';
360 360
 	}
@@ -363,15 +363,15 @@  discard block
 block discarded – undo
363 363
 		if (is_array($attribute_array)) $lastelement = $element;
364 364
 	}
365 365
 	// If second argument is not received, it means a closing tag is being handled
366
-	if(is_numeric($attribute_array)){
367
-		if($element==$lastelement) $lastelement='';
366
+	if (is_numeric($attribute_array)) {
367
+		if ($element == $lastelement) $lastelement = '';
368 368
 		return "</$element>";
369 369
 	}
370 370
 
371 371
 	//if ($element=='a') error_log(__METHOD__.__LINE__." ".$element.'->'.array2string($attribute_array));
372
-	if ($element=='td' && isset($attribute_array['background']))
372
+	if ($element == 'td' && isset($attribute_array['background']))
373 373
 	{
374
-		if (stripos($attribute_array['background'],'cid:')!==false)
374
+		if (stripos($attribute_array['background'], 'cid:') !== false)
375 375
 		{
376 376
 			//error_log(__METHOD__.__LINE__.array2string($attribute_array));
377 377
 			//$attribute_array['background'] = 'url('.$attribute_array['background'].');';
@@ -379,79 +379,79 @@  discard block
 block discarded – undo
379 379
 		else
380 380
 		{
381 381
 			// $attribute_array['background']='denied:'.$attribute_array['background'];
382
-			unset($attribute_array['background']);// only cid style background images are allowed
382
+			unset($attribute_array['background']); // only cid style background images are allowed
383 383
 		}
384 384
 	}
385 385
 	// Elements other than 'img' or 'img' without a 'img' attribute are returned unchanged
386
-	if($element == 'img')
386
+	if ($element == 'img')
387 387
 	{
388 388
 		// Re-build 'alt'
389
-		if (isset($attribute_array['alt'])) $attribute_array['alt'] = ($attribute_array['alt']=='image'?'':$attribute_array['alt']);
390
-		if (isset($attribute_array['alt'])&&strpos($attribute_array['alt'],'@')!==false) $attribute_array['alt']=str_replace('@','(at)',$attribute_array['alt']);
389
+		if (isset($attribute_array['alt'])) $attribute_array['alt'] = ($attribute_array['alt'] == 'image' ? '' : $attribute_array['alt']);
390
+		if (isset($attribute_array['alt']) && strpos($attribute_array['alt'], '@') !== false) $attribute_array['alt'] = str_replace('@', '(at)', $attribute_array['alt']);
391 391
 		// $GLOBALS['egw_info']['user']['preferences']['mail']['allowExternalIMGs'] ? '' : 'match' => '/^cid:.*/'),
392 392
 		if (isset($attribute_array['src']))
393 393
 		{
394
-			if (!(strlen($attribute_array['src'])>4 && strlen($attribute_array['src']<400)))
394
+			if (!(strlen($attribute_array['src']) > 4 && strlen($attribute_array['src'] < 400)))
395 395
 			{
396
-					$attribute_array['alt']= $attribute_array['alt'].' [blocked (reason: url length):'.$attribute_array['src'].']';
397
-					if (!isset($attribute_array['title'])) $attribute_array['title']=$attribute_array['alt'];
398
-					$attribute_array['src']=Api\Image::find('api','error');
396
+					$attribute_array['alt'] = $attribute_array['alt'].' [blocked (reason: url length):'.$attribute_array['src'].']';
397
+					if (!isset($attribute_array['title'])) $attribute_array['title'] = $attribute_array['alt'];
398
+					$attribute_array['src'] = Api\Image::find('api', 'error');
399 399
 			}
400
-			if (!preg_match('/^cid:.*/',$attribute_array['src']))
400
+			if (!preg_match('/^cid:.*/', $attribute_array['src']))
401 401
 			{
402
-				$url = explode('/', preg_replace('/^(http|https):\/\//','',$attribute_array['src']));
402
+				$url = explode('/', preg_replace('/^(http|https):\/\//', '', $attribute_array['src']));
403 403
 				if ($GLOBALS['egw_info']['user']['preferences']['mail']['allowExternalIMGs'] != 1
404 404
 						&& !in_array($url[0], $GLOBALS['egw_info']['user']['preferences']['mail']['allowExternalDomains']))
405 405
 				{
406 406
 					//the own webserver url is not external, so it should be allowed
407
-					if (empty($GLOBALS['egw_info']['server']['webserver_url'])||!preg_match("$^".$GLOBALS['egw_info']['server']['webserver_url'].".*$",$attribute_array['src']))
407
+					if (empty($GLOBALS['egw_info']['server']['webserver_url']) || !preg_match("$^".$GLOBALS['egw_info']['server']['webserver_url'].".*$", $attribute_array['src']))
408 408
 					{
409
-						$attribute_array['alt']= $attribute_array['alt'].' [blocked external image:'.$attribute_array['src'].']';
410
-						if (!isset($attribute_array['title'])) $attribute_array['title']=$attribute_array['alt'];
411
-						$attribute_array['src']=Api\Image::find('mail','no-image-shown');
409
+						$attribute_array['alt'] = $attribute_array['alt'].' [blocked external image:'.$attribute_array['src'].']';
410
+						if (!isset($attribute_array['title'])) $attribute_array['title'] = $attribute_array['alt'];
411
+						$attribute_array['src'] = Api\Image::find('mail', 'no-image-shown');
412 412
 						$attribute_array['border'] = 1;
413 413
 						if ($attribute_array['style'])
414 414
 						{
415
-							if (stripos($attribute_array['style'],'border')!==false) $attribute_array['style'] = preg_replace('~border(:|-left:|-right:|-bottom:|-top:)+ (0px)+ (none)+;~si','',$attribute_array['style']);
415
+							if (stripos($attribute_array['style'], 'border') !== false) $attribute_array['style'] = preg_replace('~border(:|-left:|-right:|-bottom:|-top:)+ (0px)+ (none)+;~si', '', $attribute_array['style']);
416 416
 						}
417 417
 					}
418 418
 				}
419 419
 			}
420 420
 		}
421 421
 	}
422
-	if (isset($attribute_array['style']) && stripos($attribute_array['style'],'script')!==false) $attribute_array['style'] = str_ireplace('script','',$attribute_array['style']);
422
+	if (isset($attribute_array['style']) && stripos($attribute_array['style'], 'script') !== false) $attribute_array['style'] = str_ireplace('script', '', $attribute_array['style']);
423 423
 	if (isset($attribute_array['title']))
424 424
 	{
425
-		if (strpos($attribute_array['title'],'@')!==false) $attribute_array['title']=str_replace('@','(at)',$attribute_array['title']);
425
+		if (strpos($attribute_array['title'], '@') !== false) $attribute_array['title'] = str_replace('@', '(at)', $attribute_array['title']);
426 426
 	}
427 427
 	if ($element == 'blockquote')
428 428
 	{
429 429
 		if (isset($attribute_array['cite']))
430 430
 		{
431
-			if (strpos($attribute_array['cite'],'@')!==false) $attribute_array['cite']=str_replace('@','(at)',$attribute_array['cite']);
431
+			if (strpos($attribute_array['cite'], '@') !== false) $attribute_array['cite'] = str_replace('@', '(at)', $attribute_array['cite']);
432 432
 		}
433 433
 	}
434
-	if($element == 'a')
434
+	if ($element == 'a')
435 435
 	{
436 436
 		//error_log(__METHOD__.__LINE__.array2string($attribute_array));
437
-		if (strpos($attribute_array['href'],'denied:javascript')===0) $attribute_array['href']='';
437
+		if (strpos($attribute_array['href'], 'denied:javascript') === 0) $attribute_array['href'] = '';
438 438
 		if (isset($attribute_array['name']) && isset($attribute_array['id'])) $attribute_array['id'] = $attribute_array['name'];
439
-		if (strpos($attribute_array['href'],'@')!==false) $attribute_array['href'] = str_replace('@','%40',$attribute_array['href']);
440
-		if (strpos($attribute_array['href'],'#')===0 && (isset(Api\Mail::$htmLawed_config['transform_anchor']) && Api\Mail::$htmLawed_config['transform_anchor']===true))
439
+		if (strpos($attribute_array['href'], '@') !== false) $attribute_array['href'] = str_replace('@', '%40', $attribute_array['href']);
440
+		if (strpos($attribute_array['href'], '#') === 0 && (isset(Api\Mail::$htmLawed_config['transform_anchor']) && Api\Mail::$htmLawed_config['transform_anchor'] === true))
441 441
 		{
442
-			$attribute_array['href'] = "javascript:GoToAnchor('".trim(substr($attribute_array['href'],1))."');";
442
+			$attribute_array['href'] = "javascript:GoToAnchor('".trim(substr($attribute_array['href'], 1))."');";
443 443
 		}
444 444
 
445 445
 	}
446 446
 
447 447
 	// Build the attributes string
448 448
 	$attributes = '';
449
-	foreach($attribute_array as $k=>$v){
449
+	foreach ($attribute_array as $k=>$v) {
450 450
 		$attributes .= " {$k}=\"{$v}\"";
451 451
 	}
452 452
 
453 453
 	// Return the opening tag with attributes
454 454
 	static $empty_elements = array('area'=>1, 'br'=>1, 'col'=>1, 'embed'=>1, 'hr'=>1, 'img'=>1, 'input'=>1, 'isindex'=>1, 'param'=>1);
455
-	return "<{$element}{$attributes}". (isset($empty_elements[$element]) ? ' /' : ''). '>';
455
+	return "<{$element}{$attributes}".(isset($empty_elements[$element]) ? ' /' : '').'>';
456 456
 }
457 457
 
Please login to merge, or discard this patch.
Braces   +146 added lines, -38 removed lines patch added patch discarded remove patch
@@ -109,9 +109,18 @@  discard block
 block discarded – undo
109 109
 	function run($html2check, $Config=null, $Spec=array())
110 110
 	{
111 111
 		//error_log(__METHOD__.__LINE__.' Input:'.$html2check);
112
-		if (is_array($Config) && is_array($this->Configuration)) $Config = array_merge($this->Configuration, $Config);
113
-		if (empty($Config)) $Config = $this->Configuration;
114
-		if (empty($Spec)) $Spec = $this->Spec;
112
+		if (is_array($Config) && is_array($this->Configuration))
113
+		{
114
+			$Config = array_merge($this->Configuration, $Config);
115
+		}
116
+		if (empty($Config))
117
+		{
118
+			$Config = $this->Configuration;
119
+		}
120
+		if (empty($Spec))
121
+		{
122
+			$Spec = $this->Spec;
123
+		}
115 124
 		// If we are processing mails, we take out stuff in <style> stuff </style> tags and
116 125
 		// put it back in after purifying; styles are processed for known security risks
117 126
 		// in self::getStyles
@@ -139,7 +148,10 @@  discard block
 block discarded – undo
139 148
 	{
140 149
 		$ct=0;
141 150
 		$newStyle = null;
142
-		if (stripos($html,'<style')!==false)  $ct = preg_match_all('#<style(?:\s.*)?>(.+)</style>#isU', $html, $newStyle);
151
+		if (stripos($html,'<style')!==false)
152
+		{
153
+			$ct = preg_match_all('#<style(?:\s.*)?>(.+)</style>#isU', $html, $newStyle);
154
+		}
143 155
 		if ($ct>0)
144 156
 		{
145 157
 			//error_log(__METHOD__.__LINE__.array2string($newStyle[0]));
@@ -173,7 +185,11 @@  discard block
 block discarded – undo
173 185
 		// CSS Security
174 186
 		// http://code.google.com/p/browsersec/wiki/Part1#Cascading_stylesheets
175 187
 		$css = preg_replace('/(javascript|expession|-moz-binding)/i','',$style);
176
-		if (stripos($css,'script')!==false) Api\Mail\Html::replaceTagsCompletley($css,'script'); // Strip out script that may be included
188
+		if (stripos($css,'script')!==false)
189
+		{
190
+			Api\Mail\Html::replaceTagsCompletley($css,'script');
191
+		}
192
+		// Strip out script that may be included
177 193
 		// we need this, as styledefinitions are enclosed with curly brackets; and template stuff tries to replace everything between curly brackets that is having no horizontal whitespace
178 194
 		// as the comments as <!-- styledefinition --> in stylesheet are outdated, and ck-editor does not understand it, we remove it
179 195
 		$css_no_comment = str_replace(array(':','<!--','-->'),array(': ','',''),$css);
@@ -199,12 +215,19 @@  discard block
 block discarded – undo
199 215
 	{
200 216
 		$defaultConfig = array('valid_xhtml'=>1,'safe'=>1);
201 217
 
202
-		if (empty($html)) return $html;	// no need to process further
218
+		if (empty($html))
219
+		{
220
+			return $html;
221
+		}
222
+		// no need to process further
203 223
 		if (!empty($config) && is_string($config))
204 224
 		{
205 225
 			//error_log(__METHOD__.__LINE__.$config);
206 226
 			$config = json_decode($config,true);
207
-			if (is_null($config)) error_log(__METHOD__.__LINE__." decoding of config failed; standard will be applied");
227
+			if (is_null($config))
228
+			{
229
+				error_log(__METHOD__.__LINE__." decoding of config failed; standard will be applied");
230
+			}
208 231
 		}
209 232
 
210 233
 		// User preferences
@@ -218,8 +241,14 @@  discard block
 block discarded – undo
218 241
 			return '';
219 242
 		}
220 243
 		$htmLawed = new HtmLawed();
221
-		if (is_array($config) && $_force===false) $config = array_merge($defaultConfig, $config);
222
-		if (empty($config)) $config = $defaultConfig;
244
+		if (is_array($config) && $_force===false)
245
+		{
246
+			$config = array_merge($defaultConfig, $config);
247
+		}
248
+		if (empty($config))
249
+		{
250
+			$config = $defaultConfig;
251
+		}
223 252
 		//error_log(__METHOD__.__LINE__.array2string($config));
224 253
 		return $htmLawed->run($html,$config,$spec);
225 254
 	}
@@ -236,7 +265,8 @@  discard block
 block discarded – undo
236 265
 function hl_my_tag_transform($element, $attribute_array=0)
237 266
 {
238 267
 	// If second argument is not received, it means a closing tag is being handled
239
-	if(is_numeric($attribute_array)){
268
+	if(is_numeric($attribute_array))
269
+	{
240 270
 		return "</$element>";
241 271
 	}
242 272
 
@@ -258,18 +288,30 @@  discard block
 block discarded – undo
258 288
 	if($element == 'img')
259 289
 	{
260 290
 		// Re-build 'alt'
261
-		if (isset($attribute_array['alt'])) $attribute_array['alt'] = ($attribute_array['alt']=='image'?'':$attribute_array['alt']);
262
-		if (isset($attribute_array['alt'])&&strpos($attribute_array['alt'],'@')!==false) $attribute_array['alt']=str_replace('@','(at)',$attribute_array['alt']);
291
+		if (isset($attribute_array['alt']))
292
+		{
293
+			$attribute_array['alt'] = ($attribute_array['alt']=='image'?'':$attribute_array['alt']);
294
+		}
295
+		if (isset($attribute_array['alt'])&&strpos($attribute_array['alt'],'@')!==false)
296
+		{
297
+			$attribute_array['alt']=str_replace('@','(at)',$attribute_array['alt']);
298
+		}
263 299
 	}
264 300
 	if (isset($attribute_array['title']))
265 301
 	{
266
-		if (strpos($attribute_array['title'],'@')!==false) $attribute_array['title']=str_replace('@','(at)',$attribute_array['title']);
302
+		if (strpos($attribute_array['title'],'@')!==false)
303
+		{
304
+			$attribute_array['title']=str_replace('@','(at)',$attribute_array['title']);
305
+		}
267 306
 	}
268 307
 	if ($element == 'blockquote')
269 308
 	{
270 309
 		if (isset($attribute_array['cite']))
271 310
 		{
272
-			if (strpos($attribute_array['cite'],'@')!==false) $attribute_array['cite']=str_replace('@','(at)',$attribute_array['cite']);
311
+			if (strpos($attribute_array['cite'],'@')!==false)
312
+			{
313
+				$attribute_array['cite']=str_replace('@','(at)',$attribute_array['cite']);
314
+			}
273 315
 		}
274 316
 	}
275 317
 	/*
@@ -301,7 +343,10 @@  discard block
 block discarded – undo
301 343
 		$attribute_array['style'] = implode('; ', $style);
302 344
 	}
303 345
 	*/
304
-	if (isset($attribute_array['style']) && stripos($attribute_array['style'],'script')!==false) $attribute_array['style'] = str_ireplace('script','',$attribute_array['style']);
346
+	if (isset($attribute_array['style']) && stripos($attribute_array['style'],'script')!==false)
347
+	{
348
+		$attribute_array['style'] = str_ireplace('script','',$attribute_array['style']);
349
+	}
305 350
 	if($element == 'a')
306 351
 	{
307 352
 		//error_log(__METHOD__.__LINE__.array2string($attribute_array));
@@ -314,12 +359,16 @@  discard block
 block discarded – undo
314 359
 		{
315 360
 			$attribute_array['href']=str_ireplace("');",'',str_ireplace("javascript:GoToAnchor('","#",$attribute_array['href']));
316 361
 		}
317
-		if (strpos($attribute_array['href'],'denied:javascript')===0) $attribute_array['href']='';
362
+		if (strpos($attribute_array['href'],'denied:javascript')===0)
363
+		{
364
+			$attribute_array['href']='';
365
+		}
318 366
 	}
319 367
 
320 368
 	// Build the attributes string
321 369
 	$attributes = '';
322
-	foreach($attribute_array as $k=>$v){
370
+	foreach($attribute_array as $k=>$v)
371
+	{
323 372
 		$attributes .= " {$k}=\"{$v}\"";
324 373
 	}
325 374
 
@@ -344,27 +393,52 @@  discard block
 block discarded – undo
344 393
 	//error_log(__METHOD__.__LINE__.$element.'=>'.array2string($attribute_array));
345 394
 	static $lastelement = null;
346 395
 	static $throwawaycounter = null;
347
-	if (is_null($lastelement)) $lastelement='';
348
-	if (is_null($throwawaycounter)) $throwawaycounter = 0;
396
+	if (is_null($lastelement))
397
+	{
398
+		$lastelement='';
399
+	}
400
+	if (is_null($throwawaycounter))
401
+	{
402
+		$throwawaycounter = 0;
403
+	}
349 404
 	//if ($throwawaycounter>1) error_log(__METHOD__.__LINE__.' '.$throwawaycounter.$element.array2string($attribute_array));
350 405
 	if ($element=='div' && $element==$lastelement && ($attribute_array==0 || empty($attribute_array)))
351 406
 	{
352
-		if (is_array($attribute_array)) $throwawaycounter++;
353
-		if ($attribute_array==0 && $throwawaycounter>0) $throwawaycounter--;
354
-		if ($throwawaycounter>1) return '';
407
+		if (is_array($attribute_array))
408
+		{
409
+			$throwawaycounter++;
410
+		}
411
+		if ($attribute_array==0 && $throwawaycounter>0)
412
+		{
413
+			$throwawaycounter--;
414
+		}
415
+		if ($throwawaycounter>1)
416
+		{
417
+			return '';
418
+		}
419
+	}
420
+	if ($lastelement=='div' && $element!=$lastelement && is_array($attribute_array))
421
+	{
422
+		$throwawaycounter = 0;
355 423
 	}
356
-	if ($lastelement=='div' && $element!=$lastelement && is_array($attribute_array)) $throwawaycounter = 0;
357 424
 	if (is_array($attribute_array) && !empty($attribute_array) && $element=='div')
358 425
 	{
359 426
 		$lastelement = 'div_with_attr';
360 427
 	}
361 428
 	else
362 429
 	{
363
-		if (is_array($attribute_array)) $lastelement = $element;
430
+		if (is_array($attribute_array))
431
+		{
432
+			$lastelement = $element;
433
+		}
364 434
 	}
365 435
 	// If second argument is not received, it means a closing tag is being handled
366
-	if(is_numeric($attribute_array)){
367
-		if($element==$lastelement) $lastelement='';
436
+	if(is_numeric($attribute_array))
437
+	{
438
+		if($element==$lastelement)
439
+		{
440
+			$lastelement='';
441
+		}
368 442
 		return "</$element>";
369 443
 	}
370 444
 
@@ -386,15 +460,24 @@  discard block
 block discarded – undo
386 460
 	if($element == 'img')
387 461
 	{
388 462
 		// Re-build 'alt'
389
-		if (isset($attribute_array['alt'])) $attribute_array['alt'] = ($attribute_array['alt']=='image'?'':$attribute_array['alt']);
390
-		if (isset($attribute_array['alt'])&&strpos($attribute_array['alt'],'@')!==false) $attribute_array['alt']=str_replace('@','(at)',$attribute_array['alt']);
463
+		if (isset($attribute_array['alt']))
464
+		{
465
+			$attribute_array['alt'] = ($attribute_array['alt']=='image'?'':$attribute_array['alt']);
466
+		}
467
+		if (isset($attribute_array['alt'])&&strpos($attribute_array['alt'],'@')!==false)
468
+		{
469
+			$attribute_array['alt']=str_replace('@','(at)',$attribute_array['alt']);
470
+		}
391 471
 		// $GLOBALS['egw_info']['user']['preferences']['mail']['allowExternalIMGs'] ? '' : 'match' => '/^cid:.*/'),
392 472
 		if (isset($attribute_array['src']))
393 473
 		{
394 474
 			if (!(strlen($attribute_array['src'])>4 && strlen($attribute_array['src']<400)))
395 475
 			{
396 476
 					$attribute_array['alt']= $attribute_array['alt'].' [blocked (reason: url length):'.$attribute_array['src'].']';
397
-					if (!isset($attribute_array['title'])) $attribute_array['title']=$attribute_array['alt'];
477
+					if (!isset($attribute_array['title']))
478
+					{
479
+						$attribute_array['title']=$attribute_array['alt'];
480
+					}
398 481
 					$attribute_array['src']=Api\Image::find('api','error');
399 482
 			}
400 483
 			if (!preg_match('/^cid:.*/',$attribute_array['src']))
@@ -407,36 +490,60 @@  discard block
 block discarded – undo
407 490
 					if (empty($GLOBALS['egw_info']['server']['webserver_url'])||!preg_match("$^".$GLOBALS['egw_info']['server']['webserver_url'].".*$",$attribute_array['src']))
408 491
 					{
409 492
 						$attribute_array['alt']= $attribute_array['alt'].' [blocked external image:'.$attribute_array['src'].']';
410
-						if (!isset($attribute_array['title'])) $attribute_array['title']=$attribute_array['alt'];
493
+						if (!isset($attribute_array['title']))
494
+						{
495
+							$attribute_array['title']=$attribute_array['alt'];
496
+						}
411 497
 						$attribute_array['src']=Api\Image::find('mail','no-image-shown');
412 498
 						$attribute_array['border'] = 1;
413 499
 						if ($attribute_array['style'])
414 500
 						{
415
-							if (stripos($attribute_array['style'],'border')!==false) $attribute_array['style'] = preg_replace('~border(:|-left:|-right:|-bottom:|-top:)+ (0px)+ (none)+;~si','',$attribute_array['style']);
501
+							if (stripos($attribute_array['style'],'border')!==false)
502
+							{
503
+								$attribute_array['style'] = preg_replace('~border(:|-left:|-right:|-bottom:|-top:)+ (0px)+ (none)+;~si','',$attribute_array['style']);
504
+							}
416 505
 						}
417 506
 					}
418 507
 				}
419 508
 			}
420 509
 		}
421 510
 	}
422
-	if (isset($attribute_array['style']) && stripos($attribute_array['style'],'script')!==false) $attribute_array['style'] = str_ireplace('script','',$attribute_array['style']);
511
+	if (isset($attribute_array['style']) && stripos($attribute_array['style'],'script')!==false)
512
+	{
513
+		$attribute_array['style'] = str_ireplace('script','',$attribute_array['style']);
514
+	}
423 515
 	if (isset($attribute_array['title']))
424 516
 	{
425
-		if (strpos($attribute_array['title'],'@')!==false) $attribute_array['title']=str_replace('@','(at)',$attribute_array['title']);
517
+		if (strpos($attribute_array['title'],'@')!==false)
518
+		{
519
+			$attribute_array['title']=str_replace('@','(at)',$attribute_array['title']);
520
+		}
426 521
 	}
427 522
 	if ($element == 'blockquote')
428 523
 	{
429 524
 		if (isset($attribute_array['cite']))
430 525
 		{
431
-			if (strpos($attribute_array['cite'],'@')!==false) $attribute_array['cite']=str_replace('@','(at)',$attribute_array['cite']);
526
+			if (strpos($attribute_array['cite'],'@')!==false)
527
+			{
528
+				$attribute_array['cite']=str_replace('@','(at)',$attribute_array['cite']);
529
+			}
432 530
 		}
433 531
 	}
434 532
 	if($element == 'a')
435 533
 	{
436 534
 		//error_log(__METHOD__.__LINE__.array2string($attribute_array));
437
-		if (strpos($attribute_array['href'],'denied:javascript')===0) $attribute_array['href']='';
438
-		if (isset($attribute_array['name']) && isset($attribute_array['id'])) $attribute_array['id'] = $attribute_array['name'];
439
-		if (strpos($attribute_array['href'],'@')!==false) $attribute_array['href'] = str_replace('@','%40',$attribute_array['href']);
535
+		if (strpos($attribute_array['href'],'denied:javascript')===0)
536
+		{
537
+			$attribute_array['href']='';
538
+		}
539
+		if (isset($attribute_array['name']) && isset($attribute_array['id']))
540
+		{
541
+			$attribute_array['id'] = $attribute_array['name'];
542
+		}
543
+		if (strpos($attribute_array['href'],'@')!==false)
544
+		{
545
+			$attribute_array['href'] = str_replace('@','%40',$attribute_array['href']);
546
+		}
440 547
 		if (strpos($attribute_array['href'],'#')===0 && (isset(Api\Mail::$htmLawed_config['transform_anchor']) && Api\Mail::$htmLawed_config['transform_anchor']===true))
441 548
 		{
442 549
 			$attribute_array['href'] = "javascript:GoToAnchor('".trim(substr($attribute_array['href'],1))."');";
@@ -446,7 +553,8 @@  discard block
 block discarded – undo
446 553
 
447 554
 	// Build the attributes string
448 555
 	$attributes = '';
449
-	foreach($attribute_array as $k=>$v){
556
+	foreach($attribute_array as $k=>$v)
557
+	{
450 558
 		$attributes .= " {$k}=\"{$v}\"";
451 559
 	}
452 560
 
Please login to merge, or discard this patch.
api/src/Html/htmLawed/htmLawed.php 4 patches
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -625,6 +625,10 @@
 block discarded – undo
625 625
 // eof
626 626
 }
627 627
 
628
+/**
629
+ * @param string $e
630
+ * @param string $a
631
+ */
628 632
 function hl_tag2(&$e, &$a, $t=1){
629 633
 // transform tag
630 634
 if($e == 'center'){$e = 'div'; return 'text-align: center;';}
Please login to merge, or discard this patch.
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -132,13 +132,13 @@  discard block
 block discarded – undo
132 132
    break; case 'match': if(!preg_match($v, $tv)){$o = 0;}
133 133
    break; case 'nomatch': if(preg_match($v, $tv)){$o = 0;}
134 134
    break; case 'oneof':
135
-    $m = 0;
136
-    foreach(explode('|', $v) as $n){if($tv == $n){$m = 1; break;}}
137
-    $o = $m;
135
+	$m = 0;
136
+	foreach(explode('|', $v) as $n){if($tv == $n){$m = 1; break;}}
137
+	$o = $m;
138 138
    break; case 'noneof':
139
-    $m = 1;
140
-    foreach(explode('|', $v) as $n){if($tv == $n){$m = 0; break;}}
141
-    $o = $m;
139
+	$m = 1;
140
+	foreach(explode('|', $v) as $n){if($tv == $n){$m = 0; break;}}
141
+	$o = $m;
142 142
    break; default:
143 143
    break;
144 144
   }
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
   elseif($do < 3 or isset($ok['#pcdata'])){echo $x;}
213 213
   elseif(strpos($x, "\x02\x04")){
214 214
    foreach(preg_split('`(\x01\x02[^\x01\x02]+\x02\x01)`', $x, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY) as $v){
215
-    echo (substr($v, 0, 2) == "\x01\x02" ? $v : ($do > 4 ? preg_replace('`\S`', '', $v) : ''));
215
+	echo (substr($v, 0, 2) == "\x01\x02" ? $v : ($do > 4 ? preg_replace('`\S`', '', $v) : ''));
216 216
    }
217 217
   }elseif($do > 4){echo preg_replace('`\S`', '', $x);}
218 218
  }
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
    preg_match('`^([a-zA-Z\d\-+.]+://[^/]+)(.*)`', $C['base_url'], $m);
366 366
    $p = preg_replace('`(?<=/)\./`', '', $m[2]. $p);
367 367
    while(preg_match('`(?<=/)([^/]{3,}|[^/.]+?|\.[^/.]|[^/.]\.)/\.\./`', $p)){
368
-    $p = preg_replace('`(?<=/)([^/]{3,}|[^/.]+?|\.[^/.]|[^/.]\.)/\.\./`', '', $p);
368
+	$p = preg_replace('`(?<=/)([^/]{3,}|[^/.]+?|\.[^/.]|[^/.]\.)/\.\./`', '', $p);
369 369
    }
370 370
    $p = $m[1]. $p;
371 371
   }
@@ -478,20 +478,20 @@  discard block
 block discarded – undo
478 478
  switch($mode){
479 479
   case 0: // Name
480 480
    if(preg_match('`^[a-zA-Z][\-a-zA-Z:]+`', $a, $m)){
481
-    $nm = strtolower($m[0]);
482
-    $w = $mode = 1; $a = ltrim(substr_replace($a, '', 0, strlen($m[0])));
481
+	$nm = strtolower($m[0]);
482
+	$w = $mode = 1; $a = ltrim(substr_replace($a, '', 0, strlen($m[0])));
483 483
    }
484 484
   break; case 1:
485 485
    if($a[0] == '='){ // =
486
-    $w = 1; $mode = 2; $a = ltrim($a, '= ');
486
+	$w = 1; $mode = 2; $a = ltrim($a, '= ');
487 487
    }else{ // No val
488
-    $w = 1; $mode = 0; $a = ltrim($a);
489
-    $aA[$nm] = '';
488
+	$w = 1; $mode = 0; $a = ltrim($a);
489
+	$aA[$nm] = '';
490 490
    }
491 491
   break; case 2: // Val
492 492
    if(preg_match('`^((?:"[^"]*")|(?:\'[^\']*\')|(?:\s*[^\s"\']+))(.*)`', $a, $m)){
493
-    $a = ltrim($m[2]); $m = $m[1]; $w = 1; $mode = 0;
494
-    $aA[$nm] = trim(str_replace('<', '&lt;', ($m[0] == '"' or $m[0] == '\'') ? substr($m, 1, -1) : $m));
493
+	$a = ltrim($m[2]); $m = $m[1]; $w = 1; $mode = 0;
494
+	$aA[$nm] = trim(str_replace('<', '&lt;', ($m[0] == '"' or $m[0] == '\'') ? substr($m, 1, -1) : $m));
495 495
    }
496 496
   break;
497 497
  }
@@ -514,8 +514,8 @@  discard block
 block discarded – undo
514 514
   }
515 515
   if($k == 'style' && !$C['style_pass']){
516 516
    if(false !== strpos($v, '&#')){
517
-    static $sC = array('&#x20;'=>' ', '&#32;'=>' ', '&#x45;'=>'e', '&#69;'=>'e', '&#x65;'=>'e', '&#101;'=>'e', '&#x58;'=>'x', '&#88;'=>'x', '&#x78;'=>'x', '&#120;'=>'x', '&#x50;'=>'p', '&#80;'=>'p', '&#x70;'=>'p', '&#112;'=>'p', '&#x53;'=>'s', '&#83;'=>'s', '&#x73;'=>'s', '&#115;'=>'s', '&#x49;'=>'i', '&#73;'=>'i', '&#x69;'=>'i', '&#105;'=>'i', '&#x4f;'=>'o', '&#79;'=>'o', '&#x6f;'=>'o', '&#111;'=>'o', '&#x4e;'=>'n', '&#78;'=>'n', '&#x6e;'=>'n', '&#110;'=>'n', '&#x55;'=>'u', '&#85;'=>'u', '&#x75;'=>'u', '&#117;'=>'u', '&#x52;'=>'r', '&#82;'=>'r', '&#x72;'=>'r', '&#114;'=>'r', '&#x4c;'=>'l', '&#76;'=>'l', '&#x6c;'=>'l', '&#108;'=>'l', '&#x28;'=>'(', '&#40;'=>'(', '&#x29;'=>')', '&#41;'=>')', '&#x20;'=>':', '&#32;'=>':', '&#x22;'=>'"', '&#34;'=>'"', '&#x27;'=>"'", '&#39;'=>"'", '&#x2f;'=>'/', '&#47;'=>'/', '&#x2a;'=>'*', '&#42;'=>'*', '&#x5c;'=>'\\', '&#92;'=>'\\');
518
-    $v = strtr($v, $sC);
517
+	static $sC = array('&#x20;'=>' ', '&#32;'=>' ', '&#x45;'=>'e', '&#69;'=>'e', '&#x65;'=>'e', '&#101;'=>'e', '&#x58;'=>'x', '&#88;'=>'x', '&#x78;'=>'x', '&#120;'=>'x', '&#x50;'=>'p', '&#80;'=>'p', '&#x70;'=>'p', '&#112;'=>'p', '&#x53;'=>'s', '&#83;'=>'s', '&#x73;'=>'s', '&#115;'=>'s', '&#x49;'=>'i', '&#73;'=>'i', '&#x69;'=>'i', '&#105;'=>'i', '&#x4f;'=>'o', '&#79;'=>'o', '&#x6f;'=>'o', '&#111;'=>'o', '&#x4e;'=>'n', '&#78;'=>'n', '&#x6e;'=>'n', '&#110;'=>'n', '&#x55;'=>'u', '&#85;'=>'u', '&#x75;'=>'u', '&#117;'=>'u', '&#x52;'=>'r', '&#82;'=>'r', '&#x72;'=>'r', '&#114;'=>'r', '&#x4c;'=>'l', '&#76;'=>'l', '&#x6c;'=>'l', '&#108;'=>'l', '&#x28;'=>'(', '&#40;'=>'(', '&#x29;'=>')', '&#41;'=>')', '&#x20;'=>':', '&#32;'=>':', '&#x22;'=>'"', '&#34;'=>'"', '&#x27;'=>"'", '&#39;'=>"'", '&#x2f;'=>'/', '&#47;'=>'/', '&#x2a;'=>'*', '&#42;'=>'*', '&#x5c;'=>'\\', '&#92;'=>'\\');
518
+	$v = strtr($v, $sC);
519 519
    }
520 520
    $v = preg_replace_callback('`(url(?:\()(?: )*(?:\'|"|&(?:quot|apos);)?)(.+?)((?:\'|"|&(?:quot|apos);)?(?: )*(?:\)))`iS', 'hl_prot', $v);
521 521
    $v = !$C['css_expression'] ? preg_replace('`expression`i', ' ', preg_replace('`\\\\\S|(/|(%2f))(\*|(%2a))`i', ' ', $v)) : $v;
@@ -523,20 +523,20 @@  discard block
 block discarded – undo
523 523
    $v = str_replace("­", ' ', (strpos($v, '&') !== false ? str_replace(array('&#xad;', '&#173;', '&shy;'), ' ', $v) : $v)); # double-quoted char is soft-hyphen; appears here as "­" or hyphen or something else depending on viewing software
524 524
    $v = hl_prot($v, $k);
525 525
    if($k == 'href'){ // X-spam
526
-    if($C['anti_mail_spam'] && strpos($v, 'mailto:') === 0){
527
-     $v = str_replace('@', htmlspecialchars($C['anti_mail_spam']), $v);
528
-    }elseif($C['anti_link_spam']){
529
-     $r1 = $C['anti_link_spam'][1];
530
-     if(!empty($r1) && preg_match($r1, $v)){continue;}
531
-     $r0 = $C['anti_link_spam'][0];
532
-     if(!empty($r0) && preg_match($r0, $v)){
533
-      if(isset($a['rel'])){
534
-       if(!preg_match('`\bnofollow\b`i', $a['rel'])){$a['rel'] .= ' nofollow';}
535
-      }elseif(isset($aA['rel'])){
536
-       if(!preg_match('`\bnofollow\b`i', $aA['rel'])){$nfr = 1;}
537
-      }else{$a['rel'] = 'nofollow';}
538
-     }
539
-    }
526
+	if($C['anti_mail_spam'] && strpos($v, 'mailto:') === 0){
527
+	 $v = str_replace('@', htmlspecialchars($C['anti_mail_spam']), $v);
528
+	}elseif($C['anti_link_spam']){
529
+	 $r1 = $C['anti_link_spam'][1];
530
+	 if(!empty($r1) && preg_match($r1, $v)){continue;}
531
+	 $r0 = $C['anti_link_spam'][0];
532
+	 if(!empty($r0) && preg_match($r0, $v)){
533
+	  if(isset($a['rel'])){
534
+	   if(!preg_match('`\bnofollow\b`i', $a['rel'])){$a['rel'] .= ' nofollow';}
535
+	  }elseif(isset($aA['rel'])){
536
+	   if(!preg_match('`\bnofollow\b`i', $aA['rel'])){$nfr = 1;}
537
+	  }else{$a['rel'] = 'nofollow';}
538
+	 }
539
+	}
540 540
    }
541 541
   }
542 542
   if(isset($rl[$k]) && is_array($rl[$k]) && ($v = hl_attrval($k, $v, $rl[$k])) === 0){continue;}
@@ -685,8 +685,8 @@  discard block
 block discarded – undo
685 685
   $e = "<$e>";
686 686
   if(isset($d[$y])){
687 687
    if(!$x){
688
-    if($n){echo "\n", str_repeat($s, --$n), "$e\n", str_repeat($s, $n);}
689
-    else{++$N; ob_end_clean(); continue 2;}
688
+	if($n){echo "\n", str_repeat($s, --$n), "$e\n", str_repeat($s, $n);}
689
+	else{++$N; ob_end_clean(); continue 2;}
690 690
    }
691 691
    else{echo "\n", str_repeat($s, $n), "$e\n", str_repeat($s, ($x != 1 ? ++$n : $n));}
692 692
    echo $r; continue;
Please login to merge, or discard this patch.
Braces   +706 added lines, -262 removed lines patch added patch discarded remove patch
@@ -9,28 +9,44 @@  discard block
 block discarded – undo
9 9
 See htmLawed_README.txt/htm
10 10
 */
11 11
 
12
-function htmLawed($t, $C=1, $S=array()){
12
+function htmLawed($t, $C=1, $S=array())
13
+{
13 14
 $C = is_array($C) ? $C : array();
14
-if(!empty($C['valid_xhtml'])){
15
+if(!empty($C['valid_xhtml']))
16
+{
15 17
  $C['elements'] = empty($C['elements']) ? '*-center-dir-font-isindex-menu-s-strike-u' : $C['elements'];
16 18
  $C['make_tag_strict'] = isset($C['make_tag_strict']) ? $C['make_tag_strict'] : 2;
17 19
  $C['xml:lang'] = isset($C['xml:lang']) ? $C['xml:lang'] : 2;
18 20
 }
19 21
 // config eles
20 22
 $e = array('a'=>1, 'abbr'=>1, 'acronym'=>1, 'address'=>1, 'applet'=>1, 'area'=>1, 'b'=>1, 'bdo'=>1, 'big'=>1, 'blockquote'=>1, 'br'=>1, 'button'=>1, 'caption'=>1, 'center'=>1, 'cite'=>1, 'code'=>1, 'col'=>1, 'colgroup'=>1, 'dd'=>1, 'del'=>1, 'dfn'=>1, 'dir'=>1, 'div'=>1, 'dl'=>1, 'dt'=>1, 'em'=>1, 'embed'=>1, 'fieldset'=>1, 'font'=>1, 'form'=>1, 'h1'=>1, 'h2'=>1, 'h3'=>1, 'h4'=>1, 'h5'=>1, 'h6'=>1, 'hr'=>1, 'i'=>1, 'iframe'=>1, 'img'=>1, 'input'=>1, 'ins'=>1, 'isindex'=>1, 'kbd'=>1, 'label'=>1, 'legend'=>1, 'li'=>1, 'map'=>1, 'menu'=>1, 'noscript'=>1, 'object'=>1, 'ol'=>1, 'optgroup'=>1, 'option'=>1, 'p'=>1, 'param'=>1, 'pre'=>1, 'q'=>1, 'rb'=>1, 'rbc'=>1, 'rp'=>1, 'rt'=>1, 'rtc'=>1, 'ruby'=>1, 's'=>1, 'samp'=>1, 'script'=>1, 'select'=>1, 'small'=>1, 'span'=>1, 'strike'=>1, 'strong'=>1, 'sub'=>1, 'sup'=>1, 'table'=>1, 'tbody'=>1, 'td'=>1, 'textarea'=>1, 'tfoot'=>1, 'th'=>1, 'thead'=>1, 'tr'=>1, 'tt'=>1, 'u'=>1, 'ul'=>1, 'var'=>1); // 86/deprecated+embed+ruby
21
-if(!empty($C['safe'])){
23
+if(!empty($C['safe']))
24
+{
22 25
  unset($e['applet'], $e['embed'], $e['iframe'], $e['object'], $e['script']);
23 26
 }
24 27
 $x = !empty($C['elements']) ? str_replace(array("\n", "\r", "\t", ' '), '', $C['elements']) : '*';
25
-if($x == '-*'){$e = array();}
26
-elseif(strpos($x, '*') === false){$e = array_flip(explode(',', $x));}
27
-else{
28
- if(isset($x[1])){
28
+if($x == '-*')
29
+{
30
+$e = array();}
31
+elseif(strpos($x, '*') === false)
32
+{
33
+$e = array_flip(explode(',', $x));}
34
+else
35
+{
36
+ if(isset($x[1]))
37
+ {
29 38
   preg_match_all('`(?:^|-|\+)[^\-+]+?(?=-|\+|$)`', $x, $m, PREG_SET_ORDER);
30
-  for($i=count($m); --$i>=0;){$m[$i] = $m[$i][0];}
31
-  foreach($m as $v){
32
-   if($v[0] == '+'){$e[substr($v, 1)] = 1;}
33
-   if($v[0] == '-' && isset($e[($v = substr($v, 1))]) && !in_array('+'. $v, $m)){unset($e[$v]);}
39
+  for($i=count($m); --$i>=0;)
40
+  {
41
+$m[$i] = $m[$i][0];}
42
+  foreach($m as $v)
43
+  {
44
+   if($v[0] == '+')
45
+   {
46
+$e[substr($v, 1)] = 1;}
47
+   if($v[0] == '-' && isset($e[($v = substr($v, 1))]) && !in_array('+'. $v, $m))
48
+   {
49
+unset($e[$v]);}
34 50
   }
35 51
  }
36 52
 }
@@ -38,7 +54,8 @@  discard block
 block discarded – undo
38 54
 // config attrs
39 55
 $x = !empty($C['deny_attribute']) ? str_replace(array("\n", "\r", "\t", ' '), '', $C['deny_attribute']) : '';
40 56
 $x = array_flip((isset($x[0]) && $x[0] == '*') ? explode('-', $x) : explode(',', $x. (!empty($C['safe']) ? ',on*' : '')));
41
-if(isset($x['on*'])){
57
+if(isset($x['on*']))
58
+{
42 59
  unset($x['on*']);
43 60
  $x += array('onblur'=>1, 'onchange'=>1, 'onclick'=>1, 'ondblclick'=>1, 'onfocus'=>1, 'onkeydown'=>1, 'onkeypress'=>1, 'onkeyup'=>1, 'onmousedown'=>1, 'onmousemove'=>1, 'onmouseout'=>1, 'onmouseover'=>1, 'onmouseup'=>1, 'onreset'=>1, 'onselect'=>1, 'onsubmit'=>1);
44 61
 }
@@ -46,14 +63,22 @@  discard block
 block discarded – undo
46 63
 // config URL
47 64
 $x = (isset($C['schemes'][2]) && strpos($C['schemes'], ':')) ? strtolower($C['schemes']) : 'href: aim, feed, file, ftp, gopher, http, https, irc, mailto, news, nntp, sftp, ssh, telnet; *:file, http, https';
48 65
 $C['schemes'] = array();
49
-foreach(explode(';', str_replace(array(' ', "\t", "\r", "\n"), '', $x)) as $v){
66
+foreach(explode(';', str_replace(array(' ', "\t", "\r", "\n"), '', $x)) as $v)
67
+{
50 68
  $x = $x2 = null; list($x, $x2) = explode(':', $v, 2);
51
- if($x2){$C['schemes'][$x] = array_flip(explode(',', $x2));}
69
+ if($x2)
70
+ {
71
+$C['schemes'][$x] = array_flip(explode(',', $x2));}
52 72
 }
53
-if(!isset($C['schemes']['*'])){$C['schemes']['*'] = array('file'=>1, 'http'=>1, 'https'=>1,);}
54
-if(!empty($C['safe']) && empty($C['schemes']['style'])){$C['schemes']['style'] = array('!'=>1);}
73
+if(!isset($C['schemes']['*']))
74
+{
75
+$C['schemes']['*'] = array('file'=>1, 'http'=>1, 'https'=>1,);}
76
+if(!empty($C['safe']) && empty($C['schemes']['style']))
77
+{
78
+$C['schemes']['style'] = array('!'=>1);}
55 79
 $C['abs_url'] = isset($C['abs_url']) ? $C['abs_url'] : 0;
56
-if(!isset($C['base_url']) or !preg_match('`^[a-zA-Z\d.+\-]+://[^/]+/(.+?/)?$`', $C['base_url'])){
80
+if(!isset($C['base_url']) or !preg_match('`^[a-zA-Z\d.+\-]+://[^/]+/(.+?/)?$`', $C['base_url']))
81
+{
57 82
  $C['base_url'] = $C['abs_url'] = 0;
58 83
 }
59 84
 // config rest
@@ -84,23 +109,35 @@  discard block
 block discarded – undo
84 109
 // block elements allowed for nesting when only inline is allowed; Example span does not allow block elements as table; table is the only element tested so far
85 110
 $C['allow_for_inline'] = isset($C['allow_for_inline'])?$C['allow_for_inline']:0;
86 111
 
87
-if(isset($GLOBALS['C'])){$reC = $GLOBALS['C'];}
112
+if(isset($GLOBALS['C']))
113
+{
114
+$reC = $GLOBALS['C'];}
88 115
 $GLOBALS['C'] = $C;
89 116
 $S = is_array($S) ? $S : hl_spec($S);
90
-if(isset($GLOBALS['S'])){$reS = $GLOBALS['S'];}
117
+if(isset($GLOBALS['S']))
118
+{
119
+$reS = $GLOBALS['S'];}
91 120
 $GLOBALS['S'] = $S;
92 121
 
93 122
 $t = preg_replace('`[\x00-\x08\x0b-\x0c\x0e-\x1f]`', '', $t);
94
-if($C['clean_ms_char']){
123
+if($C['clean_ms_char'])
124
+{
95 125
  $x = array("\x7f"=>'', "\x80"=>'&#8364;', "\x81"=>'', "\x83"=>'&#402;', "\x85"=>'&#8230;', "\x86"=>'&#8224;', "\x87"=>'&#8225;', "\x88"=>'&#710;', "\x89"=>'&#8240;', "\x8a"=>'&#352;', "\x8b"=>'&#8249;', "\x8c"=>'&#338;', "\x8d"=>'', "\x8e"=>'&#381;', "\x8f"=>'', "\x90"=>'', "\x95"=>'&#8226;', "\x96"=>'&#8211;', "\x97"=>'&#8212;', "\x98"=>'&#732;', "\x99"=>'&#8482;', "\x9a"=>'&#353;', "\x9b"=>'&#8250;', "\x9c"=>'&#339;', "\x9d"=>'', "\x9e"=>'&#382;', "\x9f"=>'&#376;');
96 126
  $x = $x + ($C['clean_ms_char'] == 1 ? array("\x82"=>'&#8218;', "\x84"=>'&#8222;', "\x91"=>'&#8216;', "\x92"=>'&#8217;', "\x93"=>'&#8220;', "\x94"=>'&#8221;') : array("\x82"=>'\'', "\x84"=>'"', "\x91"=>'\'', "\x92"=>'\'', "\x93"=>'"', "\x94"=>'"'));
97 127
  $t = strtr($t, $x);
98 128
 }
99
-if($C['cdata'] or $C['comment']){$t = preg_replace_callback('`<!(?:(?:--.*?--)|(?:\[CDATA\[.*?\]\]))>`sm', 'hl_cmtcd', $t);}
129
+if($C['cdata'] or $C['comment'])
130
+{
131
+$t = preg_replace_callback('`<!(?:(?:--.*?--)|(?:\[CDATA\[.*?\]\]))>`sm', 'hl_cmtcd', $t);}
100 132
 $t = preg_replace_callback('`&amp;([A-Za-z][A-Za-z0-9]{1,30}|#(?:[0-9]{1,8}|[Xx][0-9A-Fa-f]{1,7}));`', 'hl_ent', str_replace('&', '&amp;', $t));
101
-if($C['unique_ids'] && !isset($GLOBALS['hl_Ids'])){$GLOBALS['hl_Ids'] = array();}
102
-if($C['hook']){$t = $C['hook']($t, $C, $S);}
103
-if($C['show_setting'] && preg_match('`^[a-z][a-z0-9_]*$`i', $C['show_setting'])){
133
+if($C['unique_ids'] && !isset($GLOBALS['hl_Ids']))
134
+{
135
+$GLOBALS['hl_Ids'] = array();}
136
+if($C['hook'])
137
+{
138
+$t = $C['hook']($t, $C, $S);}
139
+if($C['show_setting'] && preg_match('`^[a-z][a-z0-9_]*$`i', $C['show_setting']))
140
+{
104 141
  $GLOBALS[$C['show_setting']] = array('config'=>$C, 'spec'=>$S, 'time'=>microtime());
105 142
 }
106 143
 // main
@@ -109,49 +146,82 @@  discard block
 block discarded – undo
109 146
 $t = (($C['cdata'] or $C['comment']) && strpos($t, "\x01") !== false) ? str_replace(array("\x01", "\x02", "\x03", "\x04", "\x05"), array('', '', '&', '<', '>'), $t) : $t;
110 147
 $t = $C['tidy'] ? hl_tidy($t, $C['tidy'], $C['parent']) : $t;
111 148
 unset($C, $e);
112
-if(isset($reC)){$GLOBALS['C'] = $reC;}
113
-if(isset($reS)){$GLOBALS['S'] = $reS;}
149
+if(isset($reC))
150
+{
151
+$GLOBALS['C'] = $reC;}
152
+if(isset($reS))
153
+{
154
+$GLOBALS['S'] = $reS;}
114 155
 return $t;
115 156
 // eof
116 157
 }
117 158
 
118
-function hl_attrval($a, $t, $p){
159
+function hl_attrval($a, $t, $p)
160
+{
119 161
 // check attr val against $S
120 162
 static $ma = array('accesskey', 'class', 'rel');
121 163
 $s = in_array($a, $ma) ? ' ' : '';
122 164
 $r = array();
123 165
 $t = !empty($s) ? explode($s, $t) : array($t);
124
-foreach($t as $tk=>$tv){
166
+foreach($t as $tk=>$tv)
167
+{
125 168
  $o = 1; $l = strlen($tv);
126
- foreach($p as $k=>$v){
127
-  switch($k){
128
-   case 'maxlen': if($l > $v){$o = 0;}
129
-   break; case 'minlen': if($l < $v){$o = 0;}
130
-   break; case 'maxval': if((float)($tv) > $v){$o = 0;}
131
-   break; case 'minval': if((float)($tv) < $v){$o = 0;}
132
-   break; case 'match': if(!preg_match($v, $tv)){$o = 0;}
133
-   break; case 'nomatch': if(preg_match($v, $tv)){$o = 0;}
169
+ foreach($p as $k=>$v)
170
+ {
171
+  switch($k)
172
+  {
173
+   case 'maxlen': if($l > $v)
174
+   {
175
+$o = 0;}
176
+   break; case 'minlen': if($l < $v)
177
+   {
178
+$o = 0;}
179
+   break; case 'maxval': if((float)($tv) > $v)
180
+   {
181
+$o = 0;}
182
+   break; case 'minval': if((float)($tv) < $v)
183
+   {
184
+$o = 0;}
185
+   break; case 'match': if(!preg_match($v, $tv))
186
+   {
187
+$o = 0;}
188
+   break; case 'nomatch': if(preg_match($v, $tv))
189
+   {
190
+$o = 0;}
134 191
    break; case 'oneof':
135 192
     $m = 0;
136
-    foreach(explode('|', $v) as $n){if($tv == $n){$m = 1; break;}}
193
+    foreach(explode('|', $v) as $n)
194
+    {
195
+if($tv == $n)
196
+    {
197
+$m = 1; break;}}
137 198
     $o = $m;
138 199
    break; case 'noneof':
139 200
     $m = 1;
140
-    foreach(explode('|', $v) as $n){if($tv == $n){$m = 0; break;}}
201
+    foreach(explode('|', $v) as $n)
202
+    {
203
+if($tv == $n)
204
+    {
205
+$m = 0; break;}}
141 206
     $o = $m;
142 207
    break; default:
143 208
    break;
144 209
   }
145
-  if(!$o){break;}
210
+  if(!$o)
211
+  {
212
+break;}
146 213
  }
147
- if($o){$r[] = $tv;}
214
+ if($o)
215
+ {
216
+$r[] = $tv;}
148 217
 }
149 218
 $r = implode($s, $r);
150 219
 return (isset($r[0]) ? $r : (isset($p['default']) ? $p['default'] : 0));
151 220
 // eof
152 221
 }
153 222
 
154
-function hl_bal($t, $do=1, $in='div'){
223
+function hl_bal($t, $do=1, $in='div')
224
+{
155 225
 // balance tags
156 226
 // by content
157 227
 $cB = array('blockquote'=>1, 'form'=>1, 'map'=>1, 'noscript'=>1); // Block
@@ -162,209 +232,359 @@  discard block
 block discarded – undo
162 232
 $cN2 = array_keys($cN);
163 233
 $cR = array('blockquote'=>1, 'dir'=>1, 'dl'=>1, 'form'=>1, 'map'=>1, 'menu'=>1, 'noscript'=>1, 'ol'=>1, 'optgroup'=>1, 'rbc'=>1, 'rtc'=>1, 'ruby'=>1, 'select'=>1, 'table'=>1, 'tbody'=>1, 'tfoot'=>1, 'thead'=>1, 'tr'=>1, 'ul'=>1);
164 234
 $cS = array('colgroup'=>array('col'=>1), 'dir'=>array('li'=>1), 'dl'=>array('dd'=>1, 'dt'=>1), 'menu'=>array('li'=>1), 'ol'=>array('li'=>1), 'optgroup'=>array('option'=>1), 'option'=>array('#pcdata'=>1), 'rbc'=>array('rb'=>1), 'rp'=>array('#pcdata'=>1), 'rtc'=>array('rt'=>1), 'ruby'=>array('rb'=>1, 'rbc'=>1, 'rp'=>1, 'rt'=>1, 'rtc'=>1), 'select'=>array('optgroup'=>1, 'option'=>1), 'script'=>array('#pcdata'=>1), 'table'=>array('caption'=>1, 'col'=>1, 'colgroup'=>1, 'tfoot'=>1, 'tbody'=>1, 'tr'=>1, 'thead'=>1), 'tbody'=>array('tr'=>1), 'tfoot'=>array('tr'=>1), 'textarea'=>array('#pcdata'=>1), 'thead'=>array('tr'=>1), 'tr'=>array('td'=>1, 'th'=>1), 'ul'=>array('li'=>1)); // Specific - immediate parent-child
165
-if($GLOBALS['C']['direct_list_nest']){$cS['ol'] = $cS['ul'] += array('ol'=>1, 'ul'=>1);}
235
+if($GLOBALS['C']['direct_list_nest'])
236
+{
237
+$cS['ol'] = $cS['ul'] += array('ol'=>1, 'ul'=>1);}
166 238
 $cO = array('address'=>array('p'=>1), 'applet'=>array('param'=>1), 'blockquote'=>array('script'=>1), 'fieldset'=>array('legend'=>1, '#pcdata'=>1), 'form'=>array('script'=>1), 'map'=>array('area'=>1), 'object'=>array('param'=>1, 'embed'=>1)); // Other
167 239
 $cT = array('colgroup'=>1, 'dd'=>1, 'dt'=>1, 'li'=>1, 'option'=>1, 'p'=>1, 'td'=>1, 'tfoot'=>1, 'th'=>1, 'thead'=>1, 'tr'=>1); // Omitable closing
168 240
 // block/inline type; ins & del both type; #pcdata: text
169 241
 $eB = array('address'=>1, 'blockquote'=>1, 'center'=>1, 'del'=>1, 'dir'=>1, 'dl'=>1, 'div'=>1, 'fieldset'=>1, 'form'=>1, 'ins'=>1, 'h1'=>1, 'h2'=>1, 'h3'=>1, 'h4'=>1, 'h5'=>1, 'h6'=>1, 'hr'=>1, 'isindex'=>1, 'menu'=>1, 'noscript'=>1, 'ol'=>1, 'p'=>1, 'pre'=>1, 'table'=>1, 'ul'=>1);
170 242
 $eI = array('#pcdata'=>1, 'a'=>1, 'abbr'=>1, 'acronym'=>1, 'applet'=>1, 'b'=>1, 'bdo'=>1, 'big'=>1, 'br'=>1, 'button'=>1, 'cite'=>1, 'code'=>1, 'del'=>1, 'dfn'=>1, 'em'=>1, 'embed'=>1, 'font'=>1, 'i'=>1, 'iframe'=>1, 'img'=>1, 'input'=>1, 'ins'=>1, 'kbd'=>1, 'label'=>1, 'map'=>1, 'object'=>1, 'q'=>1, 'ruby'=>1, 's'=>1, 'samp'=>1, 'select'=>1, 'script'=>1, 'small'=>1, 'span'=>1, 'strike'=>1, 'strong'=>1, 'sub'=>1, 'sup'=>1, 'textarea'=>1, 'tt'=>1, 'u'=>1, 'var'=>1);
171
-if($GLOBALS['C']['allow_for_inline'] && is_array($GLOBALS['C']['allow_for_inline'])) foreach($GLOBALS['C']['allow_for_inline'] as $khai => $vhai) {$eI[$vhai]=1;}//allow table as if it was an inline element as <span> some Text <table>...</table> more text</span> is quite common
243
+if($GLOBALS['C']['allow_for_inline'] && is_array($GLOBALS['C']['allow_for_inline']))
244
+{
245
+	foreach($GLOBALS['C']['allow_for_inline'] as $khai => $vhai) {$eI[$vhai]=1;
246
+}
247
+}//allow table as if it was an inline element as <span> some Text <table>...</table> more text</span> is quite common
172 248
 $eN = array('a'=>1, 'big'=>1, 'button'=>1, 'fieldset'=>1, 'font'=>1, 'form'=>1, 'iframe'=>1, 'img'=>1, 'input'=>1, 'label'=>1, 'object'=>1, 'ruby'=>1, 'script'=>1, 'select'=>1, 'small'=>1, 'sub'=>1, 'sup'=>1, 'textarea'=>1); // Exclude from specific ele; $cN values
173 249
 $eO = array('area'=>1, 'caption'=>1, 'col'=>1, 'colgroup'=>1, 'dd'=>1, 'dt'=>1, 'legend'=>1, 'li'=>1, 'optgroup'=>1, 'option'=>1, 'param'=>1, 'rb'=>1, 'rbc'=>1, 'rp'=>1, 'rt'=>1, 'rtc'=>1, 'script'=>1, 'tbody'=>1, 'td'=>1, 'tfoot'=>1, 'thead'=>1, 'th'=>1, 'tr'=>1); // Missing in $eB & $eI
174 250
 $eF = $eB + $eI;
175 251
 
176 252
 // $in sets allowed child
177 253
 $in = ((isset($eF[$in]) && $in != '#pcdata') or isset($eO[$in])) ? $in : 'div';
178
-if(isset($cE[$in])){
254
+if(isset($cE[$in]))
255
+{
179 256
  return (!$do ? '' : str_replace(array('<', '>'), array('&lt;', '&gt;'), $t));
180 257
 }
181
-if(isset($cS[$in])){$inOk = $cS[$in];}
182
-elseif(isset($cI[$in])){$inOk = $eI; $cI['del'] = 1; $cI['ins'] = 1;}
183
-elseif(isset($cF[$in])){$inOk = $eF; unset($cI['del'], $cI['ins']);}
184
-elseif(isset($cB[$in])){$inOk = $eB; unset($cI['del'], $cI['ins']);}
185
-if(isset($cO[$in])){$inOk = $inOk + $cO[$in];}
186
-if(isset($cN[$in])){$inOk = array_diff_assoc($inOk, $cN[$in]);}
258
+if(isset($cS[$in]))
259
+{
260
+$inOk = $cS[$in];}
261
+elseif(isset($cI[$in]))
262
+{
263
+$inOk = $eI; $cI['del'] = 1; $cI['ins'] = 1;}
264
+elseif(isset($cF[$in]))
265
+{
266
+$inOk = $eF; unset($cI['del'], $cI['ins']);}
267
+elseif(isset($cB[$in]))
268
+{
269
+$inOk = $eB; unset($cI['del'], $cI['ins']);}
270
+if(isset($cO[$in]))
271
+{
272
+$inOk = $inOk + $cO[$in];}
273
+if(isset($cN[$in]))
274
+{
275
+$inOk = array_diff_assoc($inOk, $cN[$in]);}
187 276
 
188 277
 $t = explode('<', $t);
189 278
 $ok = $q = array(); // $q seq list of open non-empty ele
190 279
 ob_start();
191 280
 
192
-for($i=-1, $ci=count($t); ++$i<$ci;){
281
+for($i=-1, $ci=count($t); ++$i<$ci;)
282
+{
193 283
  // allowed $ok in parent $p
194
- if($ql = count($q)){
284
+ if($ql = count($q))
285
+ {
195 286
   $p = array_pop($q);
196 287
   $q[] = $p;
197
-  if(isset($cS[$p])){$ok = $cS[$p];}
198
-  elseif(isset($cI[$p])){$ok = $eI; $cI['del'] = 1; $cI['ins'] = 1;}
199
-  elseif(isset($cF[$p])){$ok = $eF; unset($cI['del'], $cI['ins']);}
200
-  elseif(isset($cB[$p])){$ok = $eB; unset($cI['del'], $cI['ins']);}
201
-  if(isset($cO[$p])){$ok = $ok + $cO[$p];}
202
-  if(isset($cN[$p])){$ok = array_diff_assoc($ok, $cN[$p]);}
203
- }else{$ok = $inOk; unset($cI['del'], $cI['ins']);}
288
+  if(isset($cS[$p]))
289
+  {
290
+$ok = $cS[$p];}
291
+  elseif(isset($cI[$p]))
292
+  {
293
+$ok = $eI; $cI['del'] = 1; $cI['ins'] = 1;}
294
+  elseif(isset($cF[$p]))
295
+  {
296
+$ok = $eF; unset($cI['del'], $cI['ins']);}
297
+  elseif(isset($cB[$p]))
298
+  {
299
+$ok = $eB; unset($cI['del'], $cI['ins']);}
300
+  if(isset($cO[$p]))
301
+  {
302
+$ok = $ok + $cO[$p];}
303
+  if(isset($cN[$p]))
304
+  {
305
+$ok = array_diff_assoc($ok, $cN[$p]);}
306
+ }
307
+ else
308
+ {
309
+$ok = $inOk; unset($cI['del'], $cI['ins']);}
204 310
  // bad tags, & ele content
205
- if(isset($e) && ($do == 1 or (isset($ok['#pcdata']) && ($do == 3 or $do == 5)))){
311
+ if(isset($e) && ($do == 1 or (isset($ok['#pcdata']) && ($do == 3 or $do == 5))))
312
+ {
206 313
   echo '&lt;', $s, $e, $a, '&gt;';
207 314
  }
208
- if(isset($x[0])){
209
-  if(strlen(trim($x)) && (($ql && isset($cB[$p])) or (isset($cB[$in]) && !$ql))){
315
+ if(isset($x[0]))
316
+ {
317
+  if(strlen(trim($x)) && (($ql && isset($cB[$p])) or (isset($cB[$in]) && !$ql)))
318
+  {
210 319
    echo '<div>', $x, '</div>';
211 320
   }
212
-  elseif($do < 3 or isset($ok['#pcdata'])){echo $x;}
213
-  elseif(strpos($x, "\x02\x04")){
214
-   foreach(preg_split('`(\x01\x02[^\x01\x02]+\x02\x01)`', $x, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY) as $v){
321
+  elseif($do < 3 or isset($ok['#pcdata']))
322
+  {
323
+echo $x;}
324
+  elseif(strpos($x, "\x02\x04"))
325
+  {
326
+   foreach(preg_split('`(\x01\x02[^\x01\x02]+\x02\x01)`', $x, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY) as $v)
327
+   {
215 328
     echo (substr($v, 0, 2) == "\x01\x02" ? $v : ($do > 4 ? preg_replace('`\S`', '', $v) : ''));
216 329
    }
217
-  }elseif($do > 4){echo preg_replace('`\S`', '', $x);}
330
+  }
331
+  elseif($do > 4)
332
+  {
333
+echo preg_replace('`\S`', '', $x);}
218 334
  }
219 335
  // get markup
220
- if(!preg_match('`^(/?)([a-z1-6]+)([^>]*)>(.*)`sm', $t[$i], $r)){$x = $t[$i]; continue;}
336
+ if(!preg_match('`^(/?)([a-z1-6]+)([^>]*)>(.*)`sm', $t[$i], $r))
337
+ {
338
+$x = $t[$i]; continue;}
221 339
  $s = null; $e = null; $a = null; $x = null; list($all, $s, $e, $a, $x) = $r;
222 340
  // close tag
223
- if($s){
224
-  if(isset($cE[$e]) or !in_array($e, $q)){continue;} // Empty/unopen
225
-  if($p == $e){array_pop($q); echo '</', $e, '>'; unset($e); continue;} // Last open
341
+ if($s)
342
+ {
343
+  if(isset($cE[$e]) or !in_array($e, $q))
344
+  {
345
+continue;} // Empty/unopen
346
+  if($p == $e)
347
+  {
348
+array_pop($q); echo '</', $e, '>'; unset($e); continue;} // Last open
226 349
   $add = ''; // Nesting - close open tags that need to be
227
-  for($j=-1, $cj=count($q); ++$j<$cj;){
228
-   if(($d = array_pop($q)) == $e){break;}
229
-   else{$add .= "</{$d}>";}
350
+  for($j=-1, $cj=count($q); ++$j<$cj;)
351
+  {
352
+   if(($d = array_pop($q)) == $e)
353
+   {
354
+break;}
355
+   else
356
+   {
357
+$add .= "</{$d}>";}
230 358
   }
231 359
   echo $add, '</', $e, '>'; unset($e); continue;
232 360
  }
233 361
  // open tag
234 362
  // $cB ele needs $eB ele as child
235
- if(isset($cB[$e]) && strlen(trim($x))){
363
+ if(isset($cB[$e]) && strlen(trim($x)))
364
+ {
236 365
   $t[$i] = "{$e}{$a}>";
237 366
   array_splice($t, $i+1, 0, 'div>'. $x); unset($e, $x); ++$ci; --$i; continue;
238 367
  }
239
- if((($ql && isset($cB[$p])) or (isset($cB[$in]) && !$ql)) && !isset($eB[$e]) && !isset($ok[$e])){
368
+ if((($ql && isset($cB[$p])) or (isset($cB[$in]) && !$ql)) && !isset($eB[$e]) && !isset($ok[$e]))
369
+ {
240 370
   array_splice($t, $i, 0, 'div>'); unset($e, $x); ++$ci; --$i; continue;
241 371
  }
242
- if($e == 'div' && !isset($ok['div']) && strpos($a, '-htmlawed-transform')){
372
+ if($e == 'div' && !isset($ok['div']) && strpos($a, '-htmlawed-transform'))
373
+ {
243 374
   $t[$i] = "span{$a}>{$x}"; unset($e, $x); --$i; continue;
244 375
  }
245 376
  // if no open ele, $in = parent; mostly immediate parent-child relation should hold
246
- if(!$ql or !isset($eN[$e]) or !array_intersect($q, $cN2)){
247
-  if(!isset($ok[$e])){
248
-   if($ql && isset($cT[$p])){echo '</', array_pop($q), '>'; unset($e, $x); --$i;}
377
+ if(!$ql or !isset($eN[$e]) or !array_intersect($q, $cN2))
378
+ {
379
+  if(!isset($ok[$e]))
380
+  {
381
+   if($ql && isset($cT[$p]))
382
+   {
383
+echo '</', array_pop($q), '>'; unset($e, $x); --$i;}
249 384
    continue;
250 385
   }
251
-  if(!isset($cE[$e])){$q[] = $e;}
386
+  if(!isset($cE[$e]))
387
+  {
388
+$q[] = $e;}
252 389
   echo '<', $e, $a, '>'; unset($e); continue;
253 390
  }
254 391
  // specific parent-child
255
- if(isset($cS[$p][$e])){
256
-  if(!isset($cE[$e])){$q[] = $e;}
392
+ if(isset($cS[$p][$e]))
393
+ {
394
+  if(!isset($cE[$e]))
395
+  {
396
+$q[] = $e;}
257 397
   echo '<', $e, $a, '>'; unset($e); continue;
258 398
  }
259 399
  // nesting
260 400
  $add = '';
261 401
  $q2 = array();
262
- for($k=-1, $kc=count($q); ++$k<$kc;){
402
+ for($k=-1, $kc=count($q); ++$k<$kc;)
403
+ {
263 404
   $d = $q[$k];
264 405
   $ok2 = array();
265
-  if(isset($cS[$d])){$q2[] = $d; continue;}
406
+  if(isset($cS[$d]))
407
+  {
408
+$q2[] = $d; continue;}
266 409
   $ok2 = isset($cI[$d]) ? $eI : $eF;
267
-  if(isset($cO[$d])){$ok2 = $ok2 + $cO[$d];}
268
-  if(isset($cN[$d])){$ok2 = array_diff_assoc($ok2, $cN[$d]);}
269
-  if(!isset($ok2[$e])){
270
-   if(!$k && !isset($inOk[$e])){continue 2;}
410
+  if(isset($cO[$d]))
411
+  {
412
+$ok2 = $ok2 + $cO[$d];}
413
+  if(isset($cN[$d]))
414
+  {
415
+$ok2 = array_diff_assoc($ok2, $cN[$d]);}
416
+  if(!isset($ok2[$e]))
417
+  {
418
+   if(!$k && !isset($inOk[$e]))
419
+   {
420
+continue 2;}
271 421
    $add = "</{$d}>";
272
-   for(;++$k<$kc;){$add = "</{$q[$k]}>{$add}";}
422
+   for(;++$k<$kc;)
423
+   {
424
+$add = "</{$q[$k]}>{$add}";}
273 425
    break;
274 426
   }
275
-  else{$q2[] = $d;}
427
+  else
428
+  {
429
+$q2[] = $d;}
276 430
  }
277 431
  $q = $q2;
278
- if(!isset($cE[$e])){$q[] = $e;}
432
+ if(!isset($cE[$e]))
433
+ {
434
+$q[] = $e;}
279 435
  echo $add, '<', $e, $a, '>'; unset($e); continue;
280 436
 }
281 437
 
282 438
 // end
283
-if($ql = count($q)){
439
+if($ql = count($q))
440
+{
284 441
  $p = array_pop($q);
285 442
  $q[] = $p;
286
- if(isset($cS[$p])){$ok = $cS[$p];}
287
- elseif(isset($cI[$p])){$ok = $eI; $cI['del'] = 1; $cI['ins'] = 1;}
288
- elseif(isset($cF[$p])){$ok = $eF; unset($cI['del'], $cI['ins']);}
289
- elseif(isset($cB[$p])){$ok = $eB; unset($cI['del'], $cI['ins']);}
290
- if(isset($cO[$p])){$ok = $ok + $cO[$p];}
291
- if(isset($cN[$p])){$ok = array_diff_assoc($ok, $cN[$p]);}
292
-}else{$ok = $inOk; unset($cI['del'], $cI['ins']);}
293
-if(isset($e) && ($do == 1 or (isset($ok['#pcdata']) && ($do == 3 or $do == 5)))){
443
+ if(isset($cS[$p]))
444
+ {
445
+$ok = $cS[$p];}
446
+ elseif(isset($cI[$p]))
447
+ {
448
+$ok = $eI; $cI['del'] = 1; $cI['ins'] = 1;}
449
+ elseif(isset($cF[$p]))
450
+ {
451
+$ok = $eF; unset($cI['del'], $cI['ins']);}
452
+ elseif(isset($cB[$p]))
453
+ {
454
+$ok = $eB; unset($cI['del'], $cI['ins']);}
455
+ if(isset($cO[$p]))
456
+ {
457
+$ok = $ok + $cO[$p];}
458
+ if(isset($cN[$p]))
459
+ {
460
+$ok = array_diff_assoc($ok, $cN[$p]);}
461
+}
462
+else
463
+{
464
+$ok = $inOk; unset($cI['del'], $cI['ins']);}
465
+if(isset($e) && ($do == 1 or (isset($ok['#pcdata']) && ($do == 3 or $do == 5))))
466
+{
294 467
  echo '&lt;', $s, $e, $a, '&gt;';
295 468
 }
296
-if(isset($x[0])){
297
- if(strlen(trim($x)) && (($ql && isset($cB[$p])) or (isset($cB[$in]) && !$ql))){
469
+if(isset($x[0]))
470
+{
471
+ if(strlen(trim($x)) && (($ql && isset($cB[$p])) or (isset($cB[$in]) && !$ql)))
472
+ {
298 473
   echo '<div>', $x, '</div>';
299 474
  }
300
- elseif($do < 3 or isset($ok['#pcdata'])){echo $x;}
301
- elseif(strpos($x, "\x02\x04")){
302
-  foreach(preg_split('`(\x01\x02[^\x01\x02]+\x02\x01)`', $x, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY) as $v){
475
+ elseif($do < 3 or isset($ok['#pcdata']))
476
+ {
477
+echo $x;}
478
+ elseif(strpos($x, "\x02\x04"))
479
+ {
480
+  foreach(preg_split('`(\x01\x02[^\x01\x02]+\x02\x01)`', $x, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY) as $v)
481
+  {
303 482
    echo (substr($v, 0, 2) == "\x01\x02" ? $v : ($do > 4 ? preg_replace('`\S`', '', $v) : ''));
304 483
   }
305
- }elseif($do > 4){echo preg_replace('`\S`', '', $x);}
484
+ }
485
+ elseif($do > 4)
486
+ {
487
+echo preg_replace('`\S`', '', $x);}
306 488
 }
307
-while(!empty($q) && ($e = array_pop($q))){echo '</', $e, '>';}
489
+while(!empty($q) && ($e = array_pop($q)))
490
+{
491
+echo '</', $e, '>';}
308 492
 $o = ob_get_contents();
309 493
 ob_end_clean();
310 494
 return $o;
311 495
 // eof
312 496
 }
313 497
 
314
-function hl_cmtcd($t){
498
+function hl_cmtcd($t)
499
+{
315 500
 // comment/CDATA sec handler
316 501
 $t = $t[0];
317 502
 global $C;
318
-if(!($v = $C[$n = $t[3] == '-' ? 'comment' : 'cdata'])){return $t;}
319
-if($v == 1){return '';}
320
-if($n == 'comment'){
321
- if(substr(($t = preg_replace('`--+`', '-', substr($t, 4, -3))), -1) != ' '){$t .= ' ';}
503
+if(!($v = $C[$n = $t[3] == '-' ? 'comment' : 'cdata']))
504
+{
505
+return $t;}
506
+if($v == 1)
507
+{
508
+return '';}
509
+if($n == 'comment')
510
+{
511
+ if(substr(($t = preg_replace('`--+`', '-', substr($t, 4, -3))), -1) != ' ')
512
+ {
513
+$t .= ' ';}
322 514
 }
323
-else{$t = substr($t, 1, -1);}
515
+else
516
+{
517
+$t = substr($t, 1, -1);}
324 518
 $t = $v == 2 ? str_replace(array('&', '<', '>'), array('&amp;', '&lt;', '&gt;'), $t) : $t;
325 519
 return str_replace(array('&', '<', '>'), array("\x03", "\x04", "\x05"), ($n == 'comment' ? "\x01\x02\x04!--$t--\x05\x02\x01" : "\x01\x01\x04$t\x05\x01\x01"));
326 520
 // eof
327 521
 }
328 522
 
329
-function hl_ent($t){
523
+function hl_ent($t)
524
+{
330 525
 // entitity handler
331 526
 global $C;
332 527
 $t = $t[1];
333 528
 static $U = array('quot'=>1,'amp'=>1,'lt'=>1,'gt'=>1);
334 529
 static $N = array('fnof'=>'402', 'Alpha'=>'913', 'Beta'=>'914', 'Gamma'=>'915', 'Delta'=>'916', 'Epsilon'=>'917', 'Zeta'=>'918', 'Eta'=>'919', 'Theta'=>'920', 'Iota'=>'921', 'Kappa'=>'922', 'Lambda'=>'923', 'Mu'=>'924', 'Nu'=>'925', 'Xi'=>'926', 'Omicron'=>'927', 'Pi'=>'928', 'Rho'=>'929', 'Sigma'=>'931', 'Tau'=>'932', 'Upsilon'=>'933', 'Phi'=>'934', 'Chi'=>'935', 'Psi'=>'936', 'Omega'=>'937', 'alpha'=>'945', 'beta'=>'946', 'gamma'=>'947', 'delta'=>'948', 'epsilon'=>'949', 'zeta'=>'950', 'eta'=>'951', 'theta'=>'952', 'iota'=>'953', 'kappa'=>'954', 'lambda'=>'955', 'mu'=>'956', 'nu'=>'957', 'xi'=>'958', 'omicron'=>'959', 'pi'=>'960', 'rho'=>'961', 'sigmaf'=>'962', 'sigma'=>'963', 'tau'=>'964', 'upsilon'=>'965', 'phi'=>'966', 'chi'=>'967', 'psi'=>'968', 'omega'=>'969', 'thetasym'=>'977', 'upsih'=>'978', 'piv'=>'982', 'bull'=>'8226', 'hellip'=>'8230', 'prime'=>'8242', 'Prime'=>'8243', 'oline'=>'8254', 'frasl'=>'8260', 'weierp'=>'8472', 'image'=>'8465', 'real'=>'8476', 'trade'=>'8482', 'alefsym'=>'8501', 'larr'=>'8592', 'uarr'=>'8593', 'rarr'=>'8594', 'darr'=>'8595', 'harr'=>'8596', 'crarr'=>'8629', 'lArr'=>'8656', 'uArr'=>'8657', 'rArr'=>'8658', 'dArr'=>'8659', 'hArr'=>'8660', 'forall'=>'8704', 'part'=>'8706', 'exist'=>'8707', 'empty'=>'8709', 'nabla'=>'8711', 'isin'=>'8712', 'notin'=>'8713', 'ni'=>'8715', 'prod'=>'8719', 'sum'=>'8721', 'minus'=>'8722', 'lowast'=>'8727', 'radic'=>'8730', 'prop'=>'8733', 'infin'=>'8734', 'ang'=>'8736', 'and'=>'8743', 'or'=>'8744', 'cap'=>'8745', 'cup'=>'8746', 'int'=>'8747', 'there4'=>'8756', 'sim'=>'8764', 'cong'=>'8773', 'asymp'=>'8776', 'ne'=>'8800', 'equiv'=>'8801', 'le'=>'8804', 'ge'=>'8805', 'sub'=>'8834', 'sup'=>'8835', 'nsub'=>'8836', 'sube'=>'8838', 'supe'=>'8839', 'oplus'=>'8853', 'otimes'=>'8855', 'perp'=>'8869', 'sdot'=>'8901', 'lceil'=>'8968', 'rceil'=>'8969', 'lfloor'=>'8970', 'rfloor'=>'8971', 'lang'=>'9001', 'rang'=>'9002', 'loz'=>'9674', 'spades'=>'9824', 'clubs'=>'9827', 'hearts'=>'9829', 'diams'=>'9830', 'apos'=>'39',  'OElig'=>'338', 'oelig'=>'339', 'Scaron'=>'352', 'scaron'=>'353', 'Yuml'=>'376', 'circ'=>'710', 'tilde'=>'732', 'ensp'=>'8194', 'emsp'=>'8195', 'thinsp'=>'8201', 'zwnj'=>'8204', 'zwj'=>'8205', 'lrm'=>'8206', 'rlm'=>'8207', 'ndash'=>'8211', 'mdash'=>'8212', 'lsquo'=>'8216', 'rsquo'=>'8217', 'sbquo'=>'8218', 'ldquo'=>'8220', 'rdquo'=>'8221', 'bdquo'=>'8222', 'dagger'=>'8224', 'Dagger'=>'8225', 'permil'=>'8240', 'lsaquo'=>'8249', 'rsaquo'=>'8250', 'euro'=>'8364', 'nbsp'=>'160', 'iexcl'=>'161', 'cent'=>'162', 'pound'=>'163', 'curren'=>'164', 'yen'=>'165', 'brvbar'=>'166', 'sect'=>'167', 'uml'=>'168', 'copy'=>'169', 'ordf'=>'170', 'laquo'=>'171', 'not'=>'172', 'shy'=>'173', 'reg'=>'174', 'macr'=>'175', 'deg'=>'176', 'plusmn'=>'177', 'sup2'=>'178', 'sup3'=>'179', 'acute'=>'180', 'micro'=>'181', 'para'=>'182', 'middot'=>'183', 'cedil'=>'184', 'sup1'=>'185', 'ordm'=>'186', 'raquo'=>'187', 'frac14'=>'188', 'frac12'=>'189', 'frac34'=>'190', 'iquest'=>'191', 'Agrave'=>'192', 'Aacute'=>'193', 'Acirc'=>'194', 'Atilde'=>'195', 'Auml'=>'196', 'Aring'=>'197', 'AElig'=>'198', 'Ccedil'=>'199', 'Egrave'=>'200', 'Eacute'=>'201', 'Ecirc'=>'202', 'Euml'=>'203', 'Igrave'=>'204', 'Iacute'=>'205', 'Icirc'=>'206', 'Iuml'=>'207', 'ETH'=>'208', 'Ntilde'=>'209', 'Ograve'=>'210', 'Oacute'=>'211', 'Ocirc'=>'212', 'Otilde'=>'213', 'Ouml'=>'214', 'times'=>'215', 'Oslash'=>'216', 'Ugrave'=>'217', 'Uacute'=>'218', 'Ucirc'=>'219', 'Uuml'=>'220', 'Yacute'=>'221', 'THORN'=>'222', 'szlig'=>'223', 'agrave'=>'224', 'aacute'=>'225', 'acirc'=>'226', 'atilde'=>'227', 'auml'=>'228', 'aring'=>'229', 'aelig'=>'230', 'ccedil'=>'231', 'egrave'=>'232', 'eacute'=>'233', 'ecirc'=>'234', 'euml'=>'235', 'igrave'=>'236', 'iacute'=>'237', 'icirc'=>'238', 'iuml'=>'239', 'eth'=>'240', 'ntilde'=>'241', 'ograve'=>'242', 'oacute'=>'243', 'ocirc'=>'244', 'otilde'=>'245', 'ouml'=>'246', 'divide'=>'247', 'oslash'=>'248', 'ugrave'=>'249', 'uacute'=>'250', 'ucirc'=>'251', 'uuml'=>'252', 'yacute'=>'253', 'thorn'=>'254', 'yuml'=>'255');
335
-if($t[0] != '#'){
530
+if($t[0] != '#')
531
+{
336 532
  return ($C['and_mark'] ? "\x06" : '&'). (isset($U[$t]) ? $t : (isset($N[$t]) ? (!$C['named_entity'] ? '#'. ($C['hexdec_entity'] > 1 ? 'x'. dechex($N[$t]) : $N[$t]) : $t) : 'amp;'. $t)). ';';
337 533
 }
338
-if(($n = ctype_digit($t = substr($t, 1)) ? intval($t) : hexdec(substr($t, 1))) < 9 or ($n > 13 && $n < 32) or $n == 11 or $n == 12 or ($n > 126 && $n < 160 && $n != 133) or ($n > 55295 && ($n < 57344 or ($n > 64975 && $n < 64992) or $n == 65534 or $n == 65535 or $n > 1114111))){
534
+if(($n = ctype_digit($t = substr($t, 1)) ? intval($t) : hexdec(substr($t, 1))) < 9 or ($n > 13 && $n < 32) or $n == 11 or $n == 12 or ($n > 126 && $n < 160 && $n != 133) or ($n > 55295 && ($n < 57344 or ($n > 64975 && $n < 64992) or $n == 65534 or $n == 65535 or $n > 1114111)))
535
+{
339 536
  return ($C['and_mark'] ? "\x06" : '&'). "amp;#{$t};";
340 537
 }
341 538
 return ($C['and_mark'] ? "\x06" : '&'). '#'. (((ctype_digit($t) && $C['hexdec_entity'] < 2) or !$C['hexdec_entity']) ? $n : 'x'. dechex($n)). ';';
342 539
 // eof
343 540
 }
344 541
 
345
-function hl_prot($p, $c=null){
542
+function hl_prot($p, $c=null)
543
+{
346 544
 // check URL scheme
347 545
 global $C;
348 546
 $b = $a = '';
349
-if($c == null){$c = 'style'; $b = $p[1]; $a = $p[3]; $p = trim($p[2]);}
547
+if($c == null)
548
+{
549
+$c = 'style'; $b = $p[1]; $a = $p[3]; $p = trim($p[2]);}
350 550
 $c = isset($C['schemes'][$c]) ? $C['schemes'][$c] : $C['schemes']['*'];
351 551
 static $d = 'denied:';
352
-if(isset($c['!']) && substr($p, 0, 7) != $d){$p = "$d$p";}
353
-if(isset($c['*']) or !strcspn($p, '#?;') or (substr($p, 0, 7) == $d)){return "{$b}{$p}{$a}";} // All ok, frag, query, param
354
-if(preg_match('`^([^:?[@!$()*,=/\'\]]+?)(:|&#(58|x3a);|%3a|\\\\0{0,4}3a).`i', $p, $m) && !isset($c[strtolower($m[1])])){ // Denied prot
552
+if(isset($c['!']) && substr($p, 0, 7) != $d)
553
+{
554
+$p = "$d$p";}
555
+if(isset($c['*']) or !strcspn($p, '#?;') or (substr($p, 0, 7) == $d))
556
+{
557
+return "{$b}{$p}{$a}";} // All ok, frag, query, param
558
+if(preg_match('`^([^:?[@!$()*,=/\'\]]+?)(:|&#(58|x3a);|%3a|\\\\0{0,4}3a).`i', $p, $m) && !isset($c[strtolower($m[1])]))
559
+{
560
+// Denied prot
355 561
  return "{$b}{$d}{$p}{$a}";
356 562
 }
357
-if($C['abs_url']){
358
- if($C['abs_url'] == -1 && strpos($p, $C['base_url']) === 0){ // Make url rel
563
+if($C['abs_url'])
564
+{
565
+ if($C['abs_url'] == -1 && strpos($p, $C['base_url']) === 0)
566
+ {
567
+// Make url rel
359 568
   $p = substr($p, strlen($C['base_url']));
360
- }elseif(empty($m[1])){ // Make URL abs
361
-  if(substr($p, 0, 2) == '//'){$p = substr($C['base_url'], 0, strpos($C['base_url'], ':')+1). $p;}
362
-  elseif($p[0] == '/'){$p = preg_replace('`(^.+?://[^/]+)(.*)`', '$1', $C['base_url']). $p;}
363
-  elseif(strcspn($p, './')){$p = $C['base_url']. $p;}
364
-  else{
569
+ }
570
+ elseif(empty($m[1]))
571
+ {
572
+// Make URL abs
573
+  if(substr($p, 0, 2) == '//')
574
+  {
575
+$p = substr($C['base_url'], 0, strpos($C['base_url'], ':')+1). $p;}
576
+  elseif($p[0] == '/')
577
+  {
578
+$p = preg_replace('`(^.+?://[^/]+)(.*)`', '$1', $C['base_url']). $p;}
579
+  elseif(strcspn($p, './'))
580
+  {
581
+$p = $C['base_url']. $p;}
582
+  else
583
+  {
365 584
    preg_match('`^([a-zA-Z\d\-+.]+://[^/]+)(.*)`', $C['base_url'], $m);
366 585
    $p = preg_replace('`(?<=/)\./`', '', $m[2]. $p);
367
-   while(preg_match('`(?<=/)([^/]{3,}|[^/.]+?|\.[^/.]|[^/.]\.)/\.\./`', $p)){
586
+   while(preg_match('`(?<=/)([^/]{3,}|[^/.]+?|\.[^/.]|[^/.]\.)/\.\./`', $p))
587
+   {
368 588
     $p = preg_replace('`(?<=/)([^/]{3,}|[^/.]+?|\.[^/.]|[^/.]\.)/\.\./`', '', $p);
369 589
    }
370 590
    $p = $m[1]. $p;
@@ -375,77 +595,133 @@  discard block
 block discarded – undo
375 595
 // eof
376 596
 }
377 597
 
378
-function hl_regex($p){
598
+function hl_regex($p)
599
+{
379 600
 // ?regex
380
-if(empty($p)){return 0;}
381
-if($t = ini_get('track_errors')){$o = isset($php_errormsg) ? $php_errormsg : null;}
382
-else{ini_set('track_errors', 1);}
601
+if(empty($p))
602
+{
603
+return 0;}
604
+if($t = ini_get('track_errors'))
605
+{
606
+$o = isset($php_errormsg) ? $php_errormsg : null;}
607
+else
608
+{
609
+ini_set('track_errors', 1);}
383 610
 unset($php_errormsg);
384
-if(($d = ini_get('display_errors'))){ini_set('display_errors', 0);}
611
+if(($d = ini_get('display_errors')))
612
+{
613
+ini_set('display_errors', 0);}
385 614
 preg_match($p, '');
386
-if($d){ini_set('display_errors', 1);}
615
+if($d)
616
+{
617
+ini_set('display_errors', 1);}
387 618
 $r = isset($php_errormsg) ? 0 : 1;
388
-if($t){$php_errormsg = isset($o) ? $o : null;}
389
-else{ini_set('track_errors', 0);}
619
+if($t)
620
+{
621
+$php_errormsg = isset($o) ? $o : null;}
622
+else
623
+{
624
+ini_set('track_errors', 0);}
390 625
 return $r;
391 626
 // eof
392 627
 }
393 628
 
394
-function hl_spec($t){
629
+function hl_spec($t)
630
+{
395 631
 // final $spec
396 632
 $s = array();
397 633
 $t = str_replace(array("\t", "\r", "\n", ' '), '', preg_replace_callback('/"(?>(`.|[^"])*)"/sm', create_function('$m', 'return substr(str_replace(array(";", "|", "~", " ", ",", "/", "(", ")", \'`"\'), array("\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07", "\x08", "\""), $m[0]), 1, -1);'), trim($t)));
398
-for($i = count(($t = explode(';', $t))); --$i>=0;){
634
+for($i = count(($t = explode(';', $t))); --$i>=0;)
635
+{
399 636
  $w = $t[$i];
400
- if(empty($w) or ($e = strpos($w, '=')) === false or !strlen(($a =  substr($w, $e+1)))){continue;}
637
+ if(empty($w) or ($e = strpos($w, '=')) === false or !strlen(($a =  substr($w, $e+1))))
638
+ {
639
+continue;}
401 640
  $y = $n = array();
402
- foreach(explode(',', $a) as $v){
403
-  if(!preg_match('`^([a-z:\-\*]+)(?:\((.*?)\))?`i', $v, $m)){continue;}
404
-  if(($x = strtolower($m[1])) == '-*'){$n['*'] = 1; continue;}
405
-  if($x[0] == '-'){$n[substr($x, 1)] = 1; continue;}
406
-  if(!isset($m[2])){$y[$x] = 1; continue;}
407
-  foreach(explode('/', $m[2]) as $m){
408
-   if(empty($m) or ($p = strpos($m, '=')) == 0 or $p < 5){$y[$x] = 1; continue;}
641
+ foreach(explode(',', $a) as $v)
642
+ {
643
+  if(!preg_match('`^([a-z:\-\*]+)(?:\((.*?)\))?`i', $v, $m))
644
+  {
645
+continue;}
646
+  if(($x = strtolower($m[1])) == '-*')
647
+  {
648
+$n['*'] = 1; continue;}
649
+  if($x[0] == '-')
650
+  {
651
+$n[substr($x, 1)] = 1; continue;}
652
+  if(!isset($m[2]))
653
+  {
654
+$y[$x] = 1; continue;}
655
+  foreach(explode('/', $m[2]) as $m)
656
+  {
657
+   if(empty($m) or ($p = strpos($m, '=')) == 0 or $p < 5)
658
+   {
659
+$y[$x] = 1; continue;}
409 660
    $y[$x][strtolower(substr($m, 0, $p))] = str_replace(array("\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07", "\x08"), array(";", "|", "~", " ", ",", "/", "(", ")"), substr($m, $p+1));
410 661
   }
411
-  if(isset($y[$x]['match']) && !hl_regex($y[$x]['match'])){unset($y[$x]['match']);}
412
-  if(isset($y[$x]['nomatch']) && !hl_regex($y[$x]['nomatch'])){unset($y[$x]['nomatch']);}
662
+  if(isset($y[$x]['match']) && !hl_regex($y[$x]['match']))
663
+  {
664
+unset($y[$x]['match']);}
665
+  if(isset($y[$x]['nomatch']) && !hl_regex($y[$x]['nomatch']))
666
+  {
667
+unset($y[$x]['nomatch']);}
413 668
  }
414
- if(!count($y) && !count($n)){continue;}
415
- foreach(explode(',', substr($w, 0, $e)) as $v){
416
-  if(!strlen(($v = strtolower($v)))){continue;}
417
-  if(count($y)){$s[$v] = $y;}
418
-  if(count($n)){$s[$v]['n'] = $n;}
669
+ if(!count($y) && !count($n))
670
+ {
671
+continue;}
672
+ foreach(explode(',', substr($w, 0, $e)) as $v)
673
+ {
674
+  if(!strlen(($v = strtolower($v))))
675
+  {
676
+continue;}
677
+  if(count($y))
678
+  {
679
+$s[$v] = $y;}
680
+  if(count($n))
681
+  {
682
+$s[$v]['n'] = $n;}
419 683
  }
420 684
 }
421 685
 return $s;
422 686
 // eof
423 687
 }
424 688
 
425
-function hl_tag($t){
689
+function hl_tag($t)
690
+{
426 691
 // tag/attribute handler
427 692
 global $C;
428 693
 $t = $t[0];
429 694
 // invalid < >
430
-if($t == '< '){return '&lt; ';}
431
-if($t == '>'){return '&gt;';}
432
-if(!preg_match('`^<(/?)([a-zA-Z][a-zA-Z1-6]*)([^>]*?)\s?>$`m', $t, $m)){
695
+if($t == '< ')
696
+{
697
+return '&lt; ';}
698
+if($t == '>')
699
+{
700
+return '&gt;';}
701
+if(!preg_match('`^<(/?)([a-zA-Z][a-zA-Z1-6]*)([^>]*?)\s?>$`m', $t, $m))
702
+{
433 703
  //return str_replace(array('<', '>'), array('&lt;', '&gt;'), $t);
434 704
  return (($C['keep_bad']%2) ? str_replace(array('<', '>'), array('&lt;', '&gt;'), $t) : '');
435
-}elseif(!isset($C['elements'][($e = strtolower($m[2]))])){
705
+}
706
+elseif(!isset($C['elements'][($e = strtolower($m[2]))]))
707
+{
436 708
  return (($C['keep_bad']%2) ? str_replace(array('<', '>'), array('&lt;', '&gt;'), $t) : '');
437 709
 }
438 710
 // attr string
439 711
 $a = str_replace(array("\n", "\r", "\t"), ' ', trim($m[3]));
440 712
 // tag transform
441 713
 static $eD = array('applet'=>1, 'center'=>1, 'dir'=>1, 'embed'=>1, 'font'=>1, 'isindex'=>1, 'menu'=>1, 's'=>1, 'strike'=>1, 'u'=>1); // Deprecated
442
-if($C['make_tag_strict'] && isset($eD[$e])){
714
+if($C['make_tag_strict'] && isset($eD[$e]))
715
+{
443 716
  $trt = hl_tag2($e, $a, $C['make_tag_strict']);
444
- if(!$e){return (($C['keep_bad']%2) ? str_replace(array('<', '>'), array('&lt;', '&gt;'), $t) : '');}
717
+ if(!$e)
718
+ {
719
+return (($C['keep_bad']%2) ? str_replace(array('<', '>'), array('&lt;', '&gt;'), $t) : '');}
445 720
 }
446 721
 // close tag
447 722
 static $eE = array('area'=>1, 'br'=>1, 'col'=>1, 'embed'=>1, 'hr'=>1, 'img'=>1, 'input'=>1, 'isindex'=>1, 'param'=>1); // Empty ele
448
-if(!empty($m[1])){
723
+if(!empty($m[1]))
724
+{
449 725
  return (!isset($eE[$e]) ? (empty($C['hook_tag']) ? "</$e>" : $C['hook_tag']($e)) : (($C['keep_bad'])%2 ? str_replace(array('<', '>'), array('&lt;', '&gt;'), $t) : ''));
450 726
 }
451 727
 // open tag & attr
@@ -455,7 +731,8 @@  discard block
 block discarded – undo
455 731
 static $aNP = array('action'=>1, 'cite'=>1, 'classid'=>1, 'codebase'=>1, 'data'=>1, 'href'=>1, 'longdesc'=>1, 'model'=>1, 'pluginspage'=>1, 'pluginurl'=>1, 'usemap'=>1); // Need scheme check; excludes style, on* & src
456 732
 static $aNU = array('class'=>array('param'=>1, 'script'=>1), 'dir'=>array('applet'=>1, 'bdo'=>1, 'br'=>1, 'iframe'=>1, 'param'=>1, 'script'=>1), 'id'=>array('script'=>1), 'lang'=>array('applet'=>1, 'br'=>1, 'iframe'=>1, 'param'=>1, 'script'=>1), 'xml:lang'=>array('applet'=>1, 'br'=>1, 'iframe'=>1, 'param'=>1, 'script'=>1), 'onclick'=>array('applet'=>1, 'bdo'=>1, 'br'=>1, 'font'=>1, 'iframe'=>1, 'isindex'=>1, 'param'=>1, 'script'=>1), 'ondblclick'=>array('applet'=>1, 'bdo'=>1, 'br'=>1, 'font'=>1, 'iframe'=>1, 'isindex'=>1, 'param'=>1, 'script'=>1), 'onkeydown'=>array('applet'=>1, 'bdo'=>1, 'br'=>1, 'font'=>1, 'iframe'=>1, 'isindex'=>1, 'param'=>1, 'script'=>1), 'onkeypress'=>array('applet'=>1, 'bdo'=>1, 'br'=>1, 'font'=>1, 'iframe'=>1, 'isindex'=>1, 'param'=>1, 'script'=>1), 'onkeyup'=>array('applet'=>1, 'bdo'=>1, 'br'=>1, 'font'=>1, 'iframe'=>1, 'isindex'=>1, 'param'=>1, 'script'=>1), 'onmousedown'=>array('applet'=>1, 'bdo'=>1, 'br'=>1, 'font'=>1, 'iframe'=>1, 'isindex'=>1, 'param'=>1, 'script'=>1), 'onmousemove'=>array('applet'=>1, 'bdo'=>1, 'br'=>1, 'font'=>1, 'iframe'=>1, 'isindex'=>1, 'param'=>1, 'script'=>1), 'onmouseout'=>array('applet'=>1, 'bdo'=>1, 'br'=>1, 'font'=>1, 'iframe'=>1, 'isindex'=>1, 'param'=>1, 'script'=>1), 'onmouseover'=>array('applet'=>1, 'bdo'=>1, 'br'=>1, 'font'=>1, 'iframe'=>1, 'isindex'=>1, 'param'=>1, 'script'=>1), 'onmouseup'=>array('applet'=>1, 'bdo'=>1, 'br'=>1, 'font'=>1, 'iframe'=>1, 'isindex'=>1, 'param'=>1, 'script'=>1), 'style'=>array('param'=>1, 'script'=>1), 'title'=>array('param'=>1, 'script'=>1)); // Univ & exceptions
457 733
 
458
-if($C['lc_std_val']){
734
+if($C['lc_std_val'])
735
+{
459 736
  // predef attr vals for $eAL & $aNE ele
460 737
  static $aNL = array('all'=>1, 'baseline'=>1, 'bottom'=>1, 'button'=>1, 'center'=>1, 'char'=>1, 'checkbox'=>1, 'circle'=>1, 'col'=>1, 'colgroup'=>1, 'cols'=>1, 'data'=>1, 'default'=>1, 'file'=>1, 'get'=>1, 'groups'=>1, 'hidden'=>1, 'image'=>1, 'justify'=>1, 'left'=>1, 'ltr'=>1, 'middle'=>1, 'none'=>1, 'object'=>1, 'password'=>1, 'poly'=>1, 'post'=>1, 'preserve'=>1, 'radio'=>1, 'rect'=>1, 'ref'=>1, 'reset'=>1, 'right'=>1, 'row'=>1, 'rowgroup'=>1, 'rows'=>1, 'rtl'=>1, 'submit'=>1, 'text'=>1, 'top'=>1);
461 738
  static $eAL = array('a'=>1, 'area'=>1, 'bdo'=>1, 'button'=>1, 'col'=>1, 'form'=>1, 'img'=>1, 'input'=>1, 'object'=>1, 'optgroup'=>1, 'option'=>1, 'param'=>1, 'script'=>1, 'select'=>1, 'table'=>1, 'td'=>1, 'tfoot'=>1, 'th'=>1, 'thead'=>1, 'tr'=>1, 'xml:space'=>1);
@@ -463,7 +740,8 @@  discard block
 block discarded – undo
463 740
 }
464 741
 
465 742
 $depTr = 0;
466
-if($C['no_deprecated_attr']){
743
+if($C['no_deprecated_attr'])
744
+{
467 745
  // dep attr:applicable ele
468 746
  static $aND = array('align'=>array('caption'=>1, 'div'=>1, 'h1'=>1, 'h2'=>1, 'h3'=>1, 'h4'=>1, 'h5'=>1, 'h6'=>1, 'hr'=>1, 'img'=>1, 'input'=>1, 'legend'=>1, 'object'=>1, 'p'=>1, 'table'=>1), 'bgcolor'=>array('table'=>1, 'td'=>1, 'th'=>1, 'tr'=>1), 'border'=>array('img'=>1, 'object'=>1), 'bordercolor'=>array('table'=>1, 'td'=>1, 'tr'=>1), 'clear'=>array('br'=>1), 'compact'=>array('dl'=>1, 'ol'=>1, 'ul'=>1), 'height'=>array('td'=>1, 'th'=>1), 'hspace'=>array('img'=>1, 'object'=>1), 'language'=>array('script'=>1), 'name'=>array('a'=>1, 'form'=>1, 'iframe'=>1, 'img'=>1, 'map'=>1), 'noshade'=>array('hr'=>1), 'nowrap'=>array('td'=>1, 'th'=>1), 'size'=>array('hr'=>1), 'start'=>array('ol'=>1), 'type'=>array('li'=>1, 'ol'=>1, 'ul'=>1), 'value'=>array('li'=>1), 'vspace'=>array('img'=>1, 'object'=>1), 'width'=>array('hr'=>1, 'pre'=>1, 'td'=>1, 'th'=>1));
469 747
  static $eAD = array('a'=>1, 'br'=>1, 'caption'=>1, 'div'=>1, 'dl'=>1, 'form'=>1, 'h1'=>1, 'h2'=>1, 'h3'=>1, 'h4'=>1, 'h5'=>1, 'h6'=>1, 'hr'=>1, 'iframe'=>1, 'img'=>1, 'input'=>1, 'legend'=>1, 'li'=>1, 'map'=>1, 'object'=>1, 'ol'=>1, 'p'=>1, 'pre'=>1, 'script'=>1, 'table'=>1, 'td'=>1, 'th'=>1, 'tr'=>1, 'ul'=>1);
@@ -471,196 +749,328 @@  discard block
 block discarded – undo
471 749
 }
472 750
 
473 751
 // attr name-vals
474
-if(strpos($a, "\x01") !== false){$a = preg_replace('`\x01[^\x01]*\x01`', '', $a);} // No comment/CDATA sec
752
+if(strpos($a, "\x01") !== false)
753
+{
754
+$a = preg_replace('`\x01[^\x01]*\x01`', '', $a);} // No comment/CDATA sec
475 755
 $mode = 0; $a = trim($a, ' /'); $aA = array();
476
-while(strlen($a)){
756
+while(strlen($a))
757
+{
477 758
  $w = 0;
478
- switch($mode){
759
+ switch($mode)
760
+ {
479 761
   case 0: // Name
480
-   if(preg_match('`^[a-zA-Z][\-a-zA-Z:]+`', $a, $m)){
762
+   if(preg_match('`^[a-zA-Z][\-a-zA-Z:]+`', $a, $m))
763
+   {
481 764
     $nm = strtolower($m[0]);
482 765
     $w = $mode = 1; $a = ltrim(substr_replace($a, '', 0, strlen($m[0])));
483 766
    }
484 767
   break; case 1:
485
-   if($a[0] == '='){ // =
768
+   if($a[0] == '=')
769
+   {
770
+// =
486 771
     $w = 1; $mode = 2; $a = ltrim($a, '= ');
487
-   }else{ // No val
772
+   }
773
+   else
774
+   {
775
+// No val
488 776
     $w = 1; $mode = 0; $a = ltrim($a);
489 777
     $aA[$nm] = '';
490 778
    }
491 779
   break; case 2: // Val
492
-   if(preg_match('`^((?:"[^"]*")|(?:\'[^\']*\')|(?:\s*[^\s"\']+))(.*)`', $a, $m)){
780
+   if(preg_match('`^((?:"[^"]*")|(?:\'[^\']*\')|(?:\s*[^\s"\']+))(.*)`', $a, $m))
781
+   {
493 782
     $a = ltrim($m[2]); $m = $m[1]; $w = 1; $mode = 0;
494 783
     $aA[$nm] = trim(str_replace('<', '&lt;', ($m[0] == '"' or $m[0] == '\'') ? substr($m, 1, -1) : $m));
495 784
    }
496 785
   break;
497 786
  }
498
- if($w == 0){ // Parse errs, deal with space, " & '
787
+ if($w == 0)
788
+ {
789
+// Parse errs, deal with space, " & '
499 790
   $a = preg_replace('`^(?:"[^"]*("|$)|\'[^\']*(\'|$)|\S)*\s*`', '', $a);
500 791
   $mode = 0;
501 792
  }
502 793
 }
503
-if($mode == 1){$aA[$nm] = '';}
794
+if($mode == 1)
795
+{
796
+$aA[$nm] = '';}
504 797
 
505 798
 // clean attrs
506 799
 global $S;
507 800
 $rl = isset($S[$e]) ? $S[$e] : array();
508 801
 $a = array(); $nfr = 0;
509
-foreach($aA as $k=>$v){
510
-  if(((isset($C['deny_attribute']['*']) ? isset($C['deny_attribute'][$k]) : !isset($C['deny_attribute'][$k])) && (isset($aN[$k][$e]) or (isset($aNU[$k]) && !isset($aNU[$k][$e]))) && !isset($rl['n'][$k]) && !isset($rl['n']['*'])) or isset($rl[$k])){
511
-  if(isset($aNE[$k])){$v = $k;}
512
-  elseif(!empty($lcase) && (($e != 'button' or $e != 'input') or $k == 'type')){ // Rather loose but ?not cause issues
802
+foreach($aA as $k=>$v)
803
+{
804
+  if(((isset($C['deny_attribute']['*']) ? isset($C['deny_attribute'][$k]) : !isset($C['deny_attribute'][$k])) && (isset($aN[$k][$e]) or (isset($aNU[$k]) && !isset($aNU[$k][$e]))) && !isset($rl['n'][$k]) && !isset($rl['n']['*'])) or isset($rl[$k]))
805
+  {
806
+  if(isset($aNE[$k]))
807
+  {
808
+$v = $k;}
809
+  elseif(!empty($lcase) && (($e != 'button' or $e != 'input') or $k == 'type'))
810
+  {
811
+// Rather loose but ?not cause issues
513 812
    $v = (isset($aNL[($v2 = strtolower($v))])) ? $v2 : $v;
514 813
   }
515
-  if($k == 'style' && !$C['style_pass']){
516
-   if(false !== strpos($v, '&#')){
814
+  if($k == 'style' && !$C['style_pass'])
815
+  {
816
+   if(false !== strpos($v, '&#'))
817
+   {
517 818
     static $sC = array('&#x20;'=>' ', '&#32;'=>' ', '&#x45;'=>'e', '&#69;'=>'e', '&#x65;'=>'e', '&#101;'=>'e', '&#x58;'=>'x', '&#88;'=>'x', '&#x78;'=>'x', '&#120;'=>'x', '&#x50;'=>'p', '&#80;'=>'p', '&#x70;'=>'p', '&#112;'=>'p', '&#x53;'=>'s', '&#83;'=>'s', '&#x73;'=>'s', '&#115;'=>'s', '&#x49;'=>'i', '&#73;'=>'i', '&#x69;'=>'i', '&#105;'=>'i', '&#x4f;'=>'o', '&#79;'=>'o', '&#x6f;'=>'o', '&#111;'=>'o', '&#x4e;'=>'n', '&#78;'=>'n', '&#x6e;'=>'n', '&#110;'=>'n', '&#x55;'=>'u', '&#85;'=>'u', '&#x75;'=>'u', '&#117;'=>'u', '&#x52;'=>'r', '&#82;'=>'r', '&#x72;'=>'r', '&#114;'=>'r', '&#x4c;'=>'l', '&#76;'=>'l', '&#x6c;'=>'l', '&#108;'=>'l', '&#x28;'=>'(', '&#40;'=>'(', '&#x29;'=>')', '&#41;'=>')', '&#x20;'=>':', '&#32;'=>':', '&#x22;'=>'"', '&#34;'=>'"', '&#x27;'=>"'", '&#39;'=>"'", '&#x2f;'=>'/', '&#47;'=>'/', '&#x2a;'=>'*', '&#42;'=>'*', '&#x5c;'=>'\\', '&#92;'=>'\\');
518 819
     $v = strtr($v, $sC);
519 820
    }
520 821
    $v = preg_replace_callback('`(url(?:\()(?: )*(?:\'|"|&(?:quot|apos);)?)(.+?)((?:\'|"|&(?:quot|apos);)?(?: )*(?:\)))`iS', 'hl_prot', $v);
521 822
    $v = !$C['css_expression'] ? preg_replace('`expression`i', ' ', preg_replace('`\\\\\S|(/|(%2f))(\*|(%2a))`i', ' ', $v)) : $v;
522
-  }elseif(isset($aNP[$k]) or strpos($k, 'src') !== false or $k[0] == 'o'){
823
+  }
824
+  elseif(isset($aNP[$k]) or strpos($k, 'src') !== false or $k[0] == 'o')
825
+  {
523 826
    $v = str_replace("­", ' ', (strpos($v, '&') !== false ? str_replace(array('&#xad;', '&#173;', '&shy;'), ' ', $v) : $v)); # double-quoted char is soft-hyphen; appears here as "­" or hyphen or something else depending on viewing software
524 827
    $v = hl_prot($v, $k);
525
-   if($k == 'href'){ // X-spam
526
-    if($C['anti_mail_spam'] && strpos($v, 'mailto:') === 0){
828
+   if($k == 'href')
829
+   {
830
+// X-spam
831
+    if($C['anti_mail_spam'] && strpos($v, 'mailto:') === 0)
832
+    {
527 833
      $v = str_replace('@', htmlspecialchars($C['anti_mail_spam']), $v);
528
-    }elseif($C['anti_link_spam']){
834
+    }
835
+    elseif($C['anti_link_spam'])
836
+    {
529 837
      $r1 = $C['anti_link_spam'][1];
530
-     if(!empty($r1) && preg_match($r1, $v)){continue;}
838
+     if(!empty($r1) && preg_match($r1, $v))
839
+     {
840
+continue;}
531 841
      $r0 = $C['anti_link_spam'][0];
532
-     if(!empty($r0) && preg_match($r0, $v)){
533
-      if(isset($a['rel'])){
534
-       if(!preg_match('`\bnofollow\b`i', $a['rel'])){$a['rel'] .= ' nofollow';}
535
-      }elseif(isset($aA['rel'])){
536
-       if(!preg_match('`\bnofollow\b`i', $aA['rel'])){$nfr = 1;}
537
-      }else{$a['rel'] = 'nofollow';}
842
+     if(!empty($r0) && preg_match($r0, $v))
843
+     {
844
+      if(isset($a['rel']))
845
+      {
846
+       if(!preg_match('`\bnofollow\b`i', $a['rel']))
847
+       {
848
+$a['rel'] .= ' nofollow';}
849
+      }
850
+      elseif(isset($aA['rel']))
851
+      {
852
+       if(!preg_match('`\bnofollow\b`i', $aA['rel']))
853
+       {
854
+$nfr = 1;}
855
+      }
856
+      else
857
+      {
858
+$a['rel'] = 'nofollow';}
538 859
      }
539 860
     }
540 861
    }
541 862
   }
542
-  if(isset($rl[$k]) && is_array($rl[$k]) && ($v = hl_attrval($k, $v, $rl[$k])) === 0){continue;}
863
+  if(isset($rl[$k]) && is_array($rl[$k]) && ($v = hl_attrval($k, $v, $rl[$k])) === 0)
864
+  {
865
+continue;}
543 866
   $a[$k] = str_replace('"', '&quot;', $v);
544 867
  }
545 868
 }
546
-if($nfr){$a['rel'] = isset($a['rel']) ? $a['rel']. ' nofollow' : 'nofollow';}
869
+if($nfr)
870
+{
871
+$a['rel'] = isset($a['rel']) ? $a['rel']. ' nofollow' : 'nofollow';}
547 872
 
548 873
 // rqd attr
549 874
 static $eAR = array('area'=>array('alt'=>'area'), 'bdo'=>array('dir'=>'ltr'), 'form'=>array('action'=>''), 'img'=>array('src'=>'', 'alt'=>'image'), 'map'=>array('name'=>''), 'optgroup'=>array('label'=>''), 'param'=>array('name'=>''), 'script'=>array('type'=>'text/javascript'), 'textarea'=>array('rows'=>'10', 'cols'=>'50'));
550
-if(isset($eAR[$e])){
551
- foreach($eAR[$e] as $k=>$v){
552
-  if(!isset($a[$k])){$a[$k] = isset($v[0]) ? $v : $k;}
875
+if(isset($eAR[$e]))
876
+{
877
+ foreach($eAR[$e] as $k=>$v)
878
+ {
879
+  if(!isset($a[$k]))
880
+  {
881
+$a[$k] = isset($v[0]) ? $v : $k;}
553 882
  }
554 883
 }
555 884
 
556 885
 // depr attrs
557
-if($depTr){
886
+if($depTr)
887
+{
558 888
  $c = array();
559
- foreach($a as $k=>$v){
560
-  if($k == 'style' or !isset($aND[$k][$e])){continue;}
561
-  if($k == 'align'){
889
+ foreach($a as $k=>$v)
890
+ {
891
+  if($k == 'style' or !isset($aND[$k][$e]))
892
+  {
893
+continue;}
894
+  if($k == 'align')
895
+  {
562 896
    unset($a['align']);
563
-   if($e == 'img' && ($v == 'left' or $v == 'right')){$c[] = 'float: '. $v;}
564
-   elseif(($e == 'div' or $e == 'table') && $v == 'center'){$c[] = 'margin: auto';}
565
-   else{$c[] = 'text-align: '. $v;}
566
-  }elseif($k == 'bgcolor'){
897
+   if($e == 'img' && ($v == 'left' or $v == 'right'))
898
+   {
899
+$c[] = 'float: '. $v;}
900
+   elseif(($e == 'div' or $e == 'table') && $v == 'center')
901
+   {
902
+$c[] = 'margin: auto';}
903
+   else
904
+   {
905
+$c[] = 'text-align: '. $v;}
906
+  }
907
+  elseif($k == 'bgcolor')
908
+  {
567 909
    unset($a['bgcolor']);
568 910
    $c[] = 'background-color: '. $v;
569
-  }elseif($k == 'border'){
911
+  }
912
+  elseif($k == 'border')
913
+  {
570 914
    unset($a['border']); $c[] = "border: {$v}px";
571
-  }elseif($k == 'bordercolor'){
915
+  }
916
+  elseif($k == 'bordercolor')
917
+  {
572 918
    unset($a['bordercolor']); $c[] = 'border-color: '. $v;
573
-  }elseif($k == 'clear'){
919
+  }
920
+  elseif($k == 'clear')
921
+  {
574 922
    unset($a['clear']); $c[] = 'clear: '. ($v != 'all' ? $v : 'both');
575
-  }elseif($k == 'compact'){
923
+  }
924
+  elseif($k == 'compact')
925
+  {
576 926
    unset($a['compact']); $c[] = 'font-size: 85%';
577
-  }elseif($k == 'height' or $k == 'width'){
927
+  }
928
+  elseif($k == 'height' or $k == 'width')
929
+  {
578 930
    unset($a[$k]); $c[] = $k. ': '. ($v[0] != '*' ? $v. (ctype_digit($v) ? 'px' : '') : 'auto');
579
-  }elseif($k == 'hspace'){
931
+  }
932
+  elseif($k == 'hspace')
933
+  {
580 934
    unset($a['hspace']); $c[] = "margin-left: {$v}px; margin-right: {$v}px";
581
-  }elseif($k == 'language' && !isset($a['type'])){
935
+  }
936
+  elseif($k == 'language' && !isset($a['type']))
937
+  {
582 938
    unset($a['language']);
583 939
    $a['type'] = 'text/'. strtolower($v);
584
-  }elseif($k == 'name'){
585
-   if($C['no_deprecated_attr'] == 2 or ($e != 'a' && $e != 'map')){unset($a['name']);}
586
-   if(!isset($a['id']) && preg_match('`[a-zA-Z][a-zA-Z\d.:_\-]*`', $v)){$a['id'] = $v;}
587
-  }elseif($k == 'noshade'){
940
+  }
941
+  elseif($k == 'name')
942
+  {
943
+   if($C['no_deprecated_attr'] == 2 or ($e != 'a' && $e != 'map'))
944
+   {
945
+unset($a['name']);}
946
+   if(!isset($a['id']) && preg_match('`[a-zA-Z][a-zA-Z\d.:_\-]*`', $v))
947
+   {
948
+$a['id'] = $v;}
949
+  }
950
+  elseif($k == 'noshade')
951
+  {
588 952
    unset($a['noshade']); $c[] = 'border-style: none; border: 0; background-color: gray; color: gray';
589
-  }elseif($k == 'nowrap'){
953
+  }
954
+  elseif($k == 'nowrap')
955
+  {
590 956
    unset($a['nowrap']); $c[] = 'white-space: nowrap';
591
-  }elseif($k == 'size'){
957
+  }
958
+  elseif($k == 'size')
959
+  {
592 960
    unset($a['size']); $c[] = 'size: '. $v. 'px';
593
-  }elseif($k == 'start' or $k == 'value'){
961
+  }
962
+  elseif($k == 'start' or $k == 'value')
963
+  {
594 964
    unset($a[$k]);
595
-  }elseif($k == 'type'){
965
+  }
966
+  elseif($k == 'type')
967
+  {
596 968
    unset($a['type']);
597 969
    static $ol_type = array('i'=>'lower-roman', 'I'=>'upper-roman', 'a'=>'lower-latin', 'A'=>'upper-latin', '1'=>'decimal');
598 970
    $c[] = 'list-style-type: '. (isset($ol_type[$v]) ? $ol_type[$v] : 'decimal');
599
-  }elseif($k == 'vspace'){
971
+  }
972
+  elseif($k == 'vspace')
973
+  {
600 974
    unset($a['vspace']); $c[] = "margin-top: {$v}px; margin-bottom: {$v}px";
601 975
   }
602 976
  }
603
- if(count($c)){
977
+ if(count($c))
978
+ {
604 979
   $c = implode('; ', $c);
605 980
   $a['style'] = isset($a['style']) ? rtrim($a['style'], ' ;'). '; '. $c. ';': $c. ';';
606 981
  }
607 982
 }
608 983
 // unique ID
609
-if($C['unique_ids'] && isset($a['id'])){
610
- if(!preg_match('`^[A-Za-z][A-Za-z0-9_\-.:]*$`', ($id = $a['id'])) or (isset($GLOBALS['hl_Ids'][$id]) && $C['unique_ids'] == 1)){unset($a['id']);
611
- }else{
612
-  while(isset($GLOBALS['hl_Ids'][$id])){$id = $C['unique_ids']. $id;}
984
+if($C['unique_ids'] && isset($a['id']))
985
+{
986
+ if(!preg_match('`^[A-Za-z][A-Za-z0-9_\-.:]*$`', ($id = $a['id'])) or (isset($GLOBALS['hl_Ids'][$id]) && $C['unique_ids'] == 1))
987
+ {
988
+unset($a['id']);
989
+ }
990
+ else
991
+ {
992
+  while(isset($GLOBALS['hl_Ids'][$id]))
993
+  {
994
+$id = $C['unique_ids']. $id;}
613 995
   $GLOBALS['hl_Ids'][($a['id'] = $id)] = 1;
614 996
  }
615 997
 }
616 998
 // xml:lang
617
-if($C['xml:lang'] && isset($a['lang'])){
999
+if($C['xml:lang'] && isset($a['lang']))
1000
+{
618 1001
  $a['xml:lang'] = isset($a['xml:lang']) ? $a['xml:lang'] : $a['lang'];
619
- if($C['xml:lang'] == 2){unset($a['lang']);}
1002
+ if($C['xml:lang'] == 2)
1003
+ {
1004
+unset($a['lang']);}
620 1005
 }
621 1006
 // for transformed tag
622
-if(!empty($trt)){
1007
+if(!empty($trt))
1008
+{
623 1009
  $a['style'] = isset($a['style']) ? rtrim($a['style'], ' ;'). '; '. $trt : $trt;
624 1010
 }
625 1011
 // return with empty ele /
626
-if(empty($C['hook_tag'])){
1012
+if(empty($C['hook_tag']))
1013
+{
627 1014
  $aA = '';
628
- foreach($a as $k=>$v){$aA .= " {$k}=\"{$v}\"";}
1015
+ foreach($a as $k=>$v)
1016
+ {
1017
+$aA .= " {$k}=\"{$v}\"";}
629 1018
  return "<{$e}{$aA}". (isset($eE[$e]) ? ' /' : ''). '>';
630 1019
 }
631
-else{return $C['hook_tag']($e, $a);}
1020
+else
1021
+{
1022
+return $C['hook_tag']($e, $a);}
632 1023
 // eof
633 1024
 }
634 1025
 
635
-function hl_tag2(&$e, &$a, $t=1){
1026
+function hl_tag2(&$e, &$a, $t=1)
1027
+{
636 1028
 // transform tag
637
-if($e == 'center'){$e = 'div'; return 'text-align: center;';}
638
-if($e == 'dir' or $e == 'menu'){$e = 'ul'; return '';}
639
-if($e == 's' or $e == 'strike'){$e = 'span'; return 'text-decoration: line-through;';}
640
-if($e == 'u'){$e = 'span'; return 'text-decoration: underline;';}
1029
+if($e == 'center')
1030
+{
1031
+$e = 'div'; return 'text-align: center;';}
1032
+if($e == 'dir' or $e == 'menu')
1033
+{
1034
+$e = 'ul'; return '';}
1035
+if($e == 's' or $e == 'strike')
1036
+{
1037
+$e = 'span'; return 'text-decoration: line-through;';}
1038
+if($e == 'u')
1039
+{
1040
+$e = 'span'; return 'text-decoration: underline;';}
641 1041
 static $fs = array('0'=>'xx-small', '1'=>'xx-small', '2'=>'small', '3'=>'medium', '4'=>'large', '5'=>'x-large', '6'=>'xx-large', '7'=>'300%', '-1'=>'smaller', '-2'=>'60%', '+1'=>'larger', '+2'=>'150%', '+3'=>'200%', '+4'=>'300%');
642
-if($e == 'font' && $t !=3){//3 is a new make_tag_strict config value, to indicate that transformation is to be performed, but don't transform font, as size transformation of numeric sizes to keywords alters the intended result too much
1042
+if($e == 'font' && $t !=3)
1043
+{
1044
+//3 is a new make_tag_strict config value, to indicate that transformation is to be performed, but don't transform font, as size transformation of numeric sizes to keywords alters the intended result too much
643 1045
  $a2 = '';
644
- while(preg_match('`(^|\s)(color|size)\s*=\s*(\'|")?(.+?)(\\3|\s|$)`i', $a, $m)){
1046
+ while(preg_match('`(^|\s)(color|size)\s*=\s*(\'|")?(.+?)(\\3|\s|$)`i', $a, $m))
1047
+ {
645 1048
   $a = str_replace($m[0], ' ', $a);
646 1049
   $a2 .= strtolower($m[2]) == 'color' ? (' color: '. str_replace('"', '\'', trim($m[4])). ';') : (isset($fs[($m = trim($m[4]))]) ? ($a2 .= ' font-size: '. str_replace('"', '\'', $fs[$m]). ';') : '');
647 1050
  }
648
- while(preg_match('`(^|\s)face\s*=\s*(\'|")?([^=]+?)\\2`i', $a, $m) or preg_match('`(^|\s)face\s*=(\s*)(\S+)`i', $a, $m)){
1051
+ while(preg_match('`(^|\s)face\s*=\s*(\'|")?([^=]+?)\\2`i', $a, $m) or preg_match('`(^|\s)face\s*=(\s*)(\S+)`i', $a, $m))
1052
+ {
649 1053
   $a = str_replace($m[0], ' ', $a);
650 1054
   $a2 .= ' font-family: '. str_replace('"', '\'', trim($m[3])). ';';
651 1055
  }
652 1056
  $e = 'span'; return ltrim(str_replace('<', '', $a2));
653 1057
 }
654
-if($t == 2){$e = 0; return 0;}
1058
+if($t == 2)
1059
+{
1060
+$e = 0; return 0;}
655 1061
 return '';
656 1062
 // eof
657 1063
 }
658 1064
 
659
-function hl_tidy($t, $w, $p){
1065
+function hl_tidy($t, $w, $p)
1066
+{
660 1067
 // Tidy/compact HTM
661
-if(strpos(' pre,script,textarea', "$p,")){return $t;}
1068
+if(strpos(' pre,script,textarea', "$p,"))
1069
+{
1070
+return $t;}
662 1071
 $t = preg_replace('`\s+`', ' ', preg_replace_callback(array('`(<(!\[CDATA\[))(.+?)(\]\]>)`sm', '`(<(!--))(.+?)(-->)`sm', '`(<(pre|script|textarea)[^>]*?>)(.+?)(</\2>)`sm'), create_function('$m', 'return $m[1]. str_replace(array("<", ">", "\n", "\r", "\t", " "), array("\x01", "\x02", "\x03", "\x04", "\x05", "\x07"), $m[3]). $m[4];'), $t));
663
-if(($w = strtolower($w)) == -1){
1072
+if(($w = strtolower($w)) == -1)
1073
+{
664 1074
  return str_replace(array("\x01", "\x02", "\x03", "\x04", "\x05", "\x07"), array('<', '>', "\n", "\r", "\t", ' '), $t);
665 1075
 }
666 1076
 $s = strpos(" $w", 't') ? "\t" : ' ';
@@ -672,54 +1082,87 @@  discard block
 block discarded – undo
672 1082
 $d = array('address'=>1, 'blockquote'=>1, 'center'=>1, 'colgroup'=>1, 'dir'=>1, 'div'=>1, 'dl'=>1, 'fieldset'=>1, 'form'=>1, 'hr'=>1, 'iframe'=>1, 'map'=>1, 'menu'=>1, 'noscript'=>1, 'ol'=>1, 'optgroup'=>1, 'rbc'=>1, 'rtc'=>1, 'ruby'=>1, 'script'=>1, 'select'=>1, 'table'=>1, 'tbody'=>1, 'tfoot'=>1, 'thead'=>1, 'tr'=>1, 'ul'=>1);
673 1083
 $T = explode('<', $t);
674 1084
 $X = 1;
675
-while($X){
1085
+while($X)
1086
+{
676 1087
  $n = $N;
677 1088
  $t = $T;
678 1089
  ob_start();
679
- if(isset($d[$p])){echo str_repeat($s, ++$n);}
1090
+ if(isset($d[$p]))
1091
+ {
1092
+echo str_repeat($s, ++$n);}
680 1093
  echo ltrim(array_shift($t));
681
- for($i=-1, $j=count($t); ++$i<$j;){
1094
+ for($i=-1, $j=count($t); ++$i<$j;)
1095
+ {
682 1096
   $r = ''; list($e, $r) = explode('>', $t[$i]);
683 1097
   $x = $e[0] == '/' ? 0 : (substr($e, -1) == '/' ? 1 : ($e[0] != '!' ? 2 : -1));
684 1098
   $y = !$x ? ltrim($e, '/') : ($x > 0 ? substr($e, 0, strcspn($e, ' ')) : 0);
685 1099
   $e = "<$e>";
686
-  if(isset($d[$y])){
687
-   if(!$x){
688
-    if($n){echo "\n", str_repeat($s, --$n), "$e\n", str_repeat($s, $n);}
689
-    else{++$N; ob_end_clean(); continue 2;}
1100
+  if(isset($d[$y]))
1101
+  {
1102
+   if(!$x)
1103
+   {
1104
+    if($n)
1105
+    {
1106
+echo "\n", str_repeat($s, --$n), "$e\n", str_repeat($s, $n);}
1107
+    else
1108
+    {
1109
+++$N; ob_end_clean(); continue 2;}
690 1110
    }
691
-   else{echo "\n", str_repeat($s, $n), "$e\n", str_repeat($s, ($x != 1 ? ++$n : $n));}
1111
+   else
1112
+   {
1113
+echo "\n", str_repeat($s, $n), "$e\n", str_repeat($s, ($x != 1 ? ++$n : $n));}
692 1114
    echo $r; continue;
693 1115
   }
694 1116
   $f = "\n". str_repeat($s, $n);
695
-  if(isset($c[$y])){
696
-   if(!$x){echo $e, $f, $r;}
697
-   else{echo $f, $e, $r;}
698
-  }elseif(isset($b[$y])){echo $f, $e, $r;
699
-  }elseif(isset($a[$y])){echo $e, $f, $r;
700
-  }elseif(!$y){echo $f, $e, $f, $r;
701
-  }else{echo $e, $r;}
1117
+  if(isset($c[$y]))
1118
+  {
1119
+   if(!$x)
1120
+   {
1121
+echo $e, $f, $r;}
1122
+   else
1123
+   {
1124
+echo $f, $e, $r;}
1125
+  }
1126
+  elseif(isset($b[$y]))
1127
+  {
1128
+echo $f, $e, $r;
1129
+  }
1130
+  elseif(isset($a[$y]))
1131
+  {
1132
+echo $e, $f, $r;
1133
+  }
1134
+  elseif(!$y)
1135
+  {
1136
+echo $f, $e, $f, $r;
1137
+  }
1138
+  else
1139
+  {
1140
+echo $e, $r;}
702 1141
  }
703 1142
  $X = 0;
704 1143
 }
705 1144
 $t = str_replace(array("\n ", " \n"), "\n", preg_replace('`[\n]\s*?[\n]+`', "\n", ob_get_contents()));
706 1145
 ob_end_clean();
707
-if(($l = strpos(" $w", 'r') ? (strpos(" $w", 'n') ? "\r\n" : "\r") : 0)){
1146
+if(($l = strpos(" $w", 'r') ? (strpos(" $w", 'n') ? "\r\n" : "\r") : 0))
1147
+{
708 1148
  $t = str_replace("\n", $l, $t);
709 1149
 }
710 1150
 return str_replace(array("\x01", "\x02", "\x03", "\x04", "\x05", "\x07"), array('<', '>', "\n", "\r", "\t", ' '), $t);
711 1151
 // eof
712 1152
 }
713 1153
 
714
-function hl_version(){
1154
+function hl_version()
1155
+{
715 1156
 // rel
716 1157
 return '1.1.22';
717 1158
 // eof
718 1159
 }
719 1160
 
720
-function kses($t, $h, $p=array('http', 'https', 'ftp', 'news', 'nntp', 'telnet', 'gopher', 'mailto')){
1161
+function kses($t, $h, $p=array('http', 'https', 'ftp', 'news', 'nntp', 'telnet', 'gopher', 'mailto'))
1162
+{
721 1163
 // kses compat
722
-foreach($h as $k=>$v){
1164
+foreach($h as $k=>$v)
1165
+{
723 1166
  $h[$k]['n']['*'] = 1;
724 1167
 }
725 1168
 $C['cdata'] = $C['comment'] = $C['make_tag_strict'] = $C['no_deprecated_attr'] = $C['unique_ids'] = 0;
@@ -731,7 +1174,8 @@  discard block
 block discarded – undo
731 1174
 // eof
732 1175
 }
733 1176
 
734
-function kses_hook($t, &$C, &$S){
1177
+function kses_hook($t, &$C, &$S)
1178
+{
735 1179
 // kses compat
736 1180
 return $t;
737 1181
 // eof
Please login to merge, or discard this patch.
Spacing   +292 added lines, -292 removed lines patch added patch discarded remove patch
@@ -9,36 +9,36 @@  discard block
 block discarded – undo
9 9
 See htmLawed_README.txt/htm
10 10
 */
11 11
 
12
-function htmLawed($t, $C=1, $S=array()){
12
+function htmLawed($t, $C = 1, $S = array()) {
13 13
 $C = is_array($C) ? $C : array();
14
-if(!empty($C['valid_xhtml'])){
14
+if (!empty($C['valid_xhtml'])) {
15 15
  $C['elements'] = empty($C['elements']) ? '*-center-dir-font-isindex-menu-s-strike-u' : $C['elements'];
16 16
  $C['make_tag_strict'] = isset($C['make_tag_strict']) ? $C['make_tag_strict'] : 2;
17 17
  $C['xml:lang'] = isset($C['xml:lang']) ? $C['xml:lang'] : 2;
18 18
 }
19 19
 // config eles
20 20
 $e = array('a'=>1, 'abbr'=>1, 'acronym'=>1, 'address'=>1, 'applet'=>1, 'area'=>1, 'b'=>1, 'bdo'=>1, 'big'=>1, 'blockquote'=>1, 'br'=>1, 'button'=>1, 'caption'=>1, 'center'=>1, 'cite'=>1, 'code'=>1, 'col'=>1, 'colgroup'=>1, 'dd'=>1, 'del'=>1, 'dfn'=>1, 'dir'=>1, 'div'=>1, 'dl'=>1, 'dt'=>1, 'em'=>1, 'embed'=>1, 'fieldset'=>1, 'font'=>1, 'form'=>1, 'h1'=>1, 'h2'=>1, 'h3'=>1, 'h4'=>1, 'h5'=>1, 'h6'=>1, 'hr'=>1, 'i'=>1, 'iframe'=>1, 'img'=>1, 'input'=>1, 'ins'=>1, 'isindex'=>1, 'kbd'=>1, 'label'=>1, 'legend'=>1, 'li'=>1, 'map'=>1, 'menu'=>1, 'noscript'=>1, 'object'=>1, 'ol'=>1, 'optgroup'=>1, 'option'=>1, 'p'=>1, 'param'=>1, 'pre'=>1, 'q'=>1, 'rb'=>1, 'rbc'=>1, 'rp'=>1, 'rt'=>1, 'rtc'=>1, 'ruby'=>1, 's'=>1, 'samp'=>1, 'script'=>1, 'select'=>1, 'small'=>1, 'span'=>1, 'strike'=>1, 'strong'=>1, 'sub'=>1, 'sup'=>1, 'table'=>1, 'tbody'=>1, 'td'=>1, 'textarea'=>1, 'tfoot'=>1, 'th'=>1, 'thead'=>1, 'tr'=>1, 'tt'=>1, 'u'=>1, 'ul'=>1, 'var'=>1); // 86/deprecated+embed+ruby
21
-if(!empty($C['safe'])){
21
+if (!empty($C['safe'])) {
22 22
  unset($e['applet'], $e['embed'], $e['iframe'], $e['object'], $e['script']);
23 23
 }
24 24
 $x = !empty($C['elements']) ? str_replace(array("\n", "\r", "\t", ' '), '', $C['elements']) : '*';
25
-if($x == '-*'){$e = array();}
26
-elseif(strpos($x, '*') === false){$e = array_flip(explode(',', $x));}
27
-else{
28
- if(isset($x[1])){
25
+if ($x == '-*') {$e = array(); }
26
+elseif (strpos($x, '*') === false) {$e = array_flip(explode(',', $x)); }
27
+else {
28
+ if (isset($x[1])) {
29 29
   preg_match_all('`(?:^|-|\+)[^\-+]+?(?=-|\+|$)`', $x, $m, PREG_SET_ORDER);
30
-  for($i=count($m); --$i>=0;){$m[$i] = $m[$i][0];}
31
-  foreach($m as $v){
32
-   if($v[0] == '+'){$e[substr($v, 1)] = 1;}
33
-   if($v[0] == '-' && isset($e[($v = substr($v, 1))]) && !in_array('+'. $v, $m)){unset($e[$v]);}
30
+  for ($i = count($m); --$i >= 0;) {$m[$i] = $m[$i][0]; }
31
+  foreach ($m as $v) {
32
+   if ($v[0] == '+') {$e[substr($v, 1)] = 1; }
33
+   if ($v[0] == '-' && isset($e[($v = substr($v, 1))]) && !in_array('+'.$v, $m)) {unset($e[$v]); }
34 34
   }
35 35
  }
36 36
 }
37
-$C['elements'] =& $e;
37
+$C['elements'] = & $e;
38 38
 // config attrs
39 39
 $x = !empty($C['deny_attribute']) ? str_replace(array("\n", "\r", "\t", ' '), '', $C['deny_attribute']) : '';
40
-$x = array_flip((isset($x[0]) && $x[0] == '*') ? explode('-', $x) : explode(',', $x. (!empty($C['safe']) ? ',on*' : '')));
41
-if(isset($x['on*'])){
40
+$x = array_flip((isset($x[0]) && $x[0] == '*') ? explode('-', $x) : explode(',', $x.(!empty($C['safe']) ? ',on*' : '')));
41
+if (isset($x['on*'])) {
42 42
  unset($x['on*']);
43 43
  $x += array('onblur'=>1, 'onchange'=>1, 'onclick'=>1, 'ondblclick'=>1, 'onfocus'=>1, 'onkeydown'=>1, 'onkeypress'=>1, 'onkeyup'=>1, 'onmousedown'=>1, 'onmousemove'=>1, 'onmouseout'=>1, 'onmouseover'=>1, 'onmouseup'=>1, 'onreset'=>1, 'onselect'=>1, 'onsubmit'=>1);
44 44
 }
@@ -46,14 +46,14 @@  discard block
 block discarded – undo
46 46
 // config URL
47 47
 $x = (isset($C['schemes'][2]) && strpos($C['schemes'], ':')) ? strtolower($C['schemes']) : 'href: aim, feed, file, ftp, gopher, http, https, irc, mailto, news, nntp, sftp, ssh, telnet; *:file, http, https';
48 48
 $C['schemes'] = array();
49
-foreach(explode(';', str_replace(array(' ', "\t", "\r", "\n"), '', $x)) as $v){
49
+foreach (explode(';', str_replace(array(' ', "\t", "\r", "\n"), '', $x)) as $v) {
50 50
  $x = $x2 = null; list($x, $x2) = explode(':', $v, 2);
51
- if($x2){$C['schemes'][$x] = array_flip(explode(',', $x2));}
51
+ if ($x2) {$C['schemes'][$x] = array_flip(explode(',', $x2)); }
52 52
 }
53
-if(!isset($C['schemes']['*'])){$C['schemes']['*'] = array('file'=>1, 'http'=>1, 'https'=>1,);}
54
-if(!empty($C['safe']) && empty($C['schemes']['style'])){$C['schemes']['style'] = array('!'=>1);}
53
+if (!isset($C['schemes']['*'])) {$C['schemes']['*'] = array('file'=>1, 'http'=>1, 'https'=>1,); }
54
+if (!empty($C['safe']) && empty($C['schemes']['style'])) {$C['schemes']['style'] = array('!'=>1); }
55 55
 $C['abs_url'] = isset($C['abs_url']) ? $C['abs_url'] : 0;
56
-if(!isset($C['base_url']) or !preg_match('`^[a-zA-Z\d.+\-]+://[^/]+/(.+?/)?$`', $C['base_url'])){
56
+if (!isset($C['base_url']) or !preg_match('`^[a-zA-Z\d.+\-]+://[^/]+/(.+?/)?$`', $C['base_url'])) {
57 57
  $C['base_url'] = $C['abs_url'] = 0;
58 58
 }
59 59
 // config rest
@@ -82,25 +82,25 @@  discard block
 block discarded – undo
82 82
 $C['xml:lang'] = isset($C['xml:lang']) ? $C['xml:lang'] : 0;
83 83
 // own config options
84 84
 // block elements allowed for nesting when only inline is allowed; Example span does not allow block elements as table; table is the only element tested so far
85
-$C['allow_for_inline'] = isset($C['allow_for_inline'])?$C['allow_for_inline']:0;
85
+$C['allow_for_inline'] = isset($C['allow_for_inline']) ? $C['allow_for_inline'] : 0;
86 86
 
87
-if(isset($GLOBALS['C'])){$reC = $GLOBALS['C'];}
87
+if (isset($GLOBALS['C'])) {$reC = $GLOBALS['C']; }
88 88
 $GLOBALS['C'] = $C;
89 89
 $S = is_array($S) ? $S : hl_spec($S);
90
-if(isset($GLOBALS['S'])){$reS = $GLOBALS['S'];}
90
+if (isset($GLOBALS['S'])) {$reS = $GLOBALS['S']; }
91 91
 $GLOBALS['S'] = $S;
92 92
 
93 93
 $t = preg_replace('`[\x00-\x08\x0b-\x0c\x0e-\x1f]`', '', $t);
94
-if($C['clean_ms_char']){
94
+if ($C['clean_ms_char']) {
95 95
  $x = array("\x7f"=>'', "\x80"=>'&#8364;', "\x81"=>'', "\x83"=>'&#402;', "\x85"=>'&#8230;', "\x86"=>'&#8224;', "\x87"=>'&#8225;', "\x88"=>'&#710;', "\x89"=>'&#8240;', "\x8a"=>'&#352;', "\x8b"=>'&#8249;', "\x8c"=>'&#338;', "\x8d"=>'', "\x8e"=>'&#381;', "\x8f"=>'', "\x90"=>'', "\x95"=>'&#8226;', "\x96"=>'&#8211;', "\x97"=>'&#8212;', "\x98"=>'&#732;', "\x99"=>'&#8482;', "\x9a"=>'&#353;', "\x9b"=>'&#8250;', "\x9c"=>'&#339;', "\x9d"=>'', "\x9e"=>'&#382;', "\x9f"=>'&#376;');
96 96
  $x = $x + ($C['clean_ms_char'] == 1 ? array("\x82"=>'&#8218;', "\x84"=>'&#8222;', "\x91"=>'&#8216;', "\x92"=>'&#8217;', "\x93"=>'&#8220;', "\x94"=>'&#8221;') : array("\x82"=>'\'', "\x84"=>'"', "\x91"=>'\'', "\x92"=>'\'', "\x93"=>'"', "\x94"=>'"'));
97 97
  $t = strtr($t, $x);
98 98
 }
99
-if($C['cdata'] or $C['comment']){$t = preg_replace_callback('`<!(?:(?:--.*?--)|(?:\[CDATA\[.*?\]\]))>`sm', 'hl_cmtcd', $t);}
99
+if ($C['cdata'] or $C['comment']) {$t = preg_replace_callback('`<!(?:(?:--.*?--)|(?:\[CDATA\[.*?\]\]))>`sm', 'hl_cmtcd', $t); }
100 100
 $t = preg_replace_callback('`&amp;([A-Za-z][A-Za-z0-9]{1,30}|#(?:[0-9]{1,8}|[Xx][0-9A-Fa-f]{1,7}));`', 'hl_ent', str_replace('&', '&amp;', $t));
101
-if($C['unique_ids'] && !isset($GLOBALS['hl_Ids'])){$GLOBALS['hl_Ids'] = array();}
102
-if($C['hook']){$t = $C['hook']($t, $C, $S);}
103
-if($C['show_setting'] && preg_match('`^[a-z][a-z0-9_]*$`i', $C['show_setting'])){
101
+if ($C['unique_ids'] && !isset($GLOBALS['hl_Ids'])) {$GLOBALS['hl_Ids'] = array(); }
102
+if ($C['hook']) {$t = $C['hook']($t, $C, $S); }
103
+if ($C['show_setting'] && preg_match('`^[a-z][a-z0-9_]*$`i', $C['show_setting'])) {
104 104
  $GLOBALS[$C['show_setting']] = array('config'=>$C, 'spec'=>$S, 'time'=>microtime());
105 105
 }
106 106
 // main
@@ -109,49 +109,49 @@  discard block
 block discarded – undo
109 109
 $t = (($C['cdata'] or $C['comment']) && strpos($t, "\x01") !== false) ? str_replace(array("\x01", "\x02", "\x03", "\x04", "\x05"), array('', '', '&', '<', '>'), $t) : $t;
110 110
 $t = $C['tidy'] ? hl_tidy($t, $C['tidy'], $C['parent']) : $t;
111 111
 unset($C, $e);
112
-if(isset($reC)){$GLOBALS['C'] = $reC;}
113
-if(isset($reS)){$GLOBALS['S'] = $reS;}
112
+if (isset($reC)) {$GLOBALS['C'] = $reC; }
113
+if (isset($reS)) {$GLOBALS['S'] = $reS; }
114 114
 return $t;
115 115
 // eof
116 116
 }
117 117
 
118
-function hl_attrval($a, $t, $p){
118
+function hl_attrval($a, $t, $p) {
119 119
 // check attr val against $S
120 120
 static $ma = array('accesskey', 'class', 'rel');
121 121
 $s = in_array($a, $ma) ? ' ' : '';
122 122
 $r = array();
123 123
 $t = !empty($s) ? explode($s, $t) : array($t);
124
-foreach($t as $tk=>$tv){
124
+foreach ($t as $tk=>$tv) {
125 125
  $o = 1; $l = strlen($tv);
126
- foreach($p as $k=>$v){
127
-  switch($k){
128
-   case 'maxlen': if($l > $v){$o = 0;}
129
-   break; case 'minlen': if($l < $v){$o = 0;}
130
-   break; case 'maxval': if((float)($tv) > $v){$o = 0;}
131
-   break; case 'minval': if((float)($tv) < $v){$o = 0;}
132
-   break; case 'match': if(!preg_match($v, $tv)){$o = 0;}
133
-   break; case 'nomatch': if(preg_match($v, $tv)){$o = 0;}
126
+ foreach ($p as $k=>$v) {
127
+  switch ($k) {
128
+   case 'maxlen': if ($l > $v) {$o = 0; }
129
+   break; case 'minlen': if ($l < $v) {$o = 0; }
130
+   break; case 'maxval': if ((float)($tv) > $v) {$o = 0; }
131
+   break; case 'minval': if ((float)($tv) < $v) {$o = 0; }
132
+   break; case 'match': if (!preg_match($v, $tv)) {$o = 0; }
133
+   break; case 'nomatch': if (preg_match($v, $tv)) {$o = 0; }
134 134
    break; case 'oneof':
135 135
     $m = 0;
136
-    foreach(explode('|', $v) as $n){if($tv == $n){$m = 1; break;}}
136
+    foreach (explode('|', $v) as $n) {if ($tv == $n) {$m = 1; break; }}
137 137
     $o = $m;
138 138
    break; case 'noneof':
139 139
     $m = 1;
140
-    foreach(explode('|', $v) as $n){if($tv == $n){$m = 0; break;}}
140
+    foreach (explode('|', $v) as $n) {if ($tv == $n) {$m = 0; break; }}
141 141
     $o = $m;
142 142
    break; default:
143 143
    break;
144 144
   }
145
-  if(!$o){break;}
145
+  if (!$o) {break; }
146 146
  }
147
- if($o){$r[] = $tv;}
147
+ if ($o) {$r[] = $tv; }
148 148
 }
149 149
 $r = implode($s, $r);
150 150
 return (isset($r[0]) ? $r : (isset($p['default']) ? $p['default'] : 0));
151 151
 // eof
152 152
 }
153 153
 
154
-function hl_bal($t, $do=1, $in='div'){
154
+function hl_bal($t, $do = 1, $in = 'div') {
155 155
 // balance tags
156 156
 // by content
157 157
 $cB = array('blockquote'=>1, 'form'=>1, 'map'=>1, 'noscript'=>1); // Block
@@ -162,212 +162,212 @@  discard block
 block discarded – undo
162 162
 $cN2 = array_keys($cN);
163 163
 $cR = array('blockquote'=>1, 'dir'=>1, 'dl'=>1, 'form'=>1, 'map'=>1, 'menu'=>1, 'noscript'=>1, 'ol'=>1, 'optgroup'=>1, 'rbc'=>1, 'rtc'=>1, 'ruby'=>1, 'select'=>1, 'table'=>1, 'tbody'=>1, 'tfoot'=>1, 'thead'=>1, 'tr'=>1, 'ul'=>1);
164 164
 $cS = array('colgroup'=>array('col'=>1), 'dir'=>array('li'=>1), 'dl'=>array('dd'=>1, 'dt'=>1), 'menu'=>array('li'=>1), 'ol'=>array('li'=>1), 'optgroup'=>array('option'=>1), 'option'=>array('#pcdata'=>1), 'rbc'=>array('rb'=>1), 'rp'=>array('#pcdata'=>1), 'rtc'=>array('rt'=>1), 'ruby'=>array('rb'=>1, 'rbc'=>1, 'rp'=>1, 'rt'=>1, 'rtc'=>1), 'select'=>array('optgroup'=>1, 'option'=>1), 'script'=>array('#pcdata'=>1), 'table'=>array('caption'=>1, 'col'=>1, 'colgroup'=>1, 'tfoot'=>1, 'tbody'=>1, 'tr'=>1, 'thead'=>1), 'tbody'=>array('tr'=>1), 'tfoot'=>array('tr'=>1), 'textarea'=>array('#pcdata'=>1), 'thead'=>array('tr'=>1), 'tr'=>array('td'=>1, 'th'=>1), 'ul'=>array('li'=>1)); // Specific - immediate parent-child
165
-if($GLOBALS['C']['direct_list_nest']){$cS['ol'] = $cS['ul'] += array('ol'=>1, 'ul'=>1);}
165
+if ($GLOBALS['C']['direct_list_nest']) {$cS['ol'] = $cS['ul'] += array('ol'=>1, 'ul'=>1); }
166 166
 $cO = array('address'=>array('p'=>1), 'applet'=>array('param'=>1), 'blockquote'=>array('script'=>1), 'fieldset'=>array('legend'=>1, '#pcdata'=>1), 'form'=>array('script'=>1), 'map'=>array('area'=>1), 'object'=>array('param'=>1, 'embed'=>1)); // Other
167 167
 $cT = array('colgroup'=>1, 'dd'=>1, 'dt'=>1, 'li'=>1, 'option'=>1, 'p'=>1, 'td'=>1, 'tfoot'=>1, 'th'=>1, 'thead'=>1, 'tr'=>1); // Omitable closing
168 168
 // block/inline type; ins & del both type; #pcdata: text
169 169
 $eB = array('address'=>1, 'blockquote'=>1, 'center'=>1, 'del'=>1, 'dir'=>1, 'dl'=>1, 'div'=>1, 'fieldset'=>1, 'form'=>1, 'ins'=>1, 'h1'=>1, 'h2'=>1, 'h3'=>1, 'h4'=>1, 'h5'=>1, 'h6'=>1, 'hr'=>1, 'isindex'=>1, 'menu'=>1, 'noscript'=>1, 'ol'=>1, 'p'=>1, 'pre'=>1, 'table'=>1, 'ul'=>1);
170 170
 $eI = array('#pcdata'=>1, 'a'=>1, 'abbr'=>1, 'acronym'=>1, 'applet'=>1, 'b'=>1, 'bdo'=>1, 'big'=>1, 'br'=>1, 'button'=>1, 'cite'=>1, 'code'=>1, 'del'=>1, 'dfn'=>1, 'em'=>1, 'embed'=>1, 'font'=>1, 'i'=>1, 'iframe'=>1, 'img'=>1, 'input'=>1, 'ins'=>1, 'kbd'=>1, 'label'=>1, 'map'=>1, 'object'=>1, 'q'=>1, 'ruby'=>1, 's'=>1, 'samp'=>1, 'select'=>1, 'script'=>1, 'small'=>1, 'span'=>1, 'strike'=>1, 'strong'=>1, 'sub'=>1, 'sup'=>1, 'textarea'=>1, 'tt'=>1, 'u'=>1, 'var'=>1);
171
-if($GLOBALS['C']['allow_for_inline'] && is_array($GLOBALS['C']['allow_for_inline'])) foreach($GLOBALS['C']['allow_for_inline'] as $khai => $vhai) {$eI[$vhai]=1;}//allow table as if it was an inline element as <span> some Text <table>...</table> more text</span> is quite common
171
+if ($GLOBALS['C']['allow_for_inline'] && is_array($GLOBALS['C']['allow_for_inline'])) foreach ($GLOBALS['C']['allow_for_inline'] as $khai => $vhai) {$eI[$vhai] = 1; }//allow table as if it was an inline element as <span> some Text <table>...</table> more text</span> is quite common
172 172
 $eN = array('a'=>1, 'big'=>1, 'button'=>1, 'fieldset'=>1, 'font'=>1, 'form'=>1, 'iframe'=>1, 'img'=>1, 'input'=>1, 'label'=>1, 'object'=>1, 'ruby'=>1, 'script'=>1, 'select'=>1, 'small'=>1, 'sub'=>1, 'sup'=>1, 'textarea'=>1); // Exclude from specific ele; $cN values
173 173
 $eO = array('area'=>1, 'caption'=>1, 'col'=>1, 'colgroup'=>1, 'dd'=>1, 'dt'=>1, 'legend'=>1, 'li'=>1, 'optgroup'=>1, 'option'=>1, 'param'=>1, 'rb'=>1, 'rbc'=>1, 'rp'=>1, 'rt'=>1, 'rtc'=>1, 'script'=>1, 'tbody'=>1, 'td'=>1, 'tfoot'=>1, 'thead'=>1, 'th'=>1, 'tr'=>1); // Missing in $eB & $eI
174 174
 $eF = $eB + $eI;
175 175
 
176 176
 // $in sets allowed child
177 177
 $in = ((isset($eF[$in]) && $in != '#pcdata') or isset($eO[$in])) ? $in : 'div';
178
-if(isset($cE[$in])){
178
+if (isset($cE[$in])) {
179 179
  return (!$do ? '' : str_replace(array('<', '>'), array('&lt;', '&gt;'), $t));
180 180
 }
181
-if(isset($cS[$in])){$inOk = $cS[$in];}
182
-elseif(isset($cI[$in])){$inOk = $eI; $cI['del'] = 1; $cI['ins'] = 1;}
183
-elseif(isset($cF[$in])){$inOk = $eF; unset($cI['del'], $cI['ins']);}
184
-elseif(isset($cB[$in])){$inOk = $eB; unset($cI['del'], $cI['ins']);}
185
-if(isset($cO[$in])){$inOk = $inOk + $cO[$in];}
186
-if(isset($cN[$in])){$inOk = array_diff_assoc($inOk, $cN[$in]);}
181
+if (isset($cS[$in])) {$inOk = $cS[$in]; }
182
+elseif (isset($cI[$in])) {$inOk = $eI; $cI['del'] = 1; $cI['ins'] = 1; }
183
+elseif (isset($cF[$in])) {$inOk = $eF; unset($cI['del'], $cI['ins']); }
184
+elseif (isset($cB[$in])) {$inOk = $eB; unset($cI['del'], $cI['ins']); }
185
+if (isset($cO[$in])) {$inOk = $inOk + $cO[$in]; }
186
+if (isset($cN[$in])) {$inOk = array_diff_assoc($inOk, $cN[$in]); }
187 187
 
188 188
 $t = explode('<', $t);
189 189
 $ok = $q = array(); // $q seq list of open non-empty ele
190 190
 ob_start();
191 191
 
192
-for($i=-1, $ci=count($t); ++$i<$ci;){
192
+for ($i = -1, $ci = count($t); ++$i < $ci;) {
193 193
  // allowed $ok in parent $p
194
- if($ql = count($q)){
194
+ if ($ql = count($q)) {
195 195
   $p = array_pop($q);
196 196
   $q[] = $p;
197
-  if(isset($cS[$p])){$ok = $cS[$p];}
198
-  elseif(isset($cI[$p])){$ok = $eI; $cI['del'] = 1; $cI['ins'] = 1;}
199
-  elseif(isset($cF[$p])){$ok = $eF; unset($cI['del'], $cI['ins']);}
200
-  elseif(isset($cB[$p])){$ok = $eB; unset($cI['del'], $cI['ins']);}
201
-  if(isset($cO[$p])){$ok = $ok + $cO[$p];}
202
-  if(isset($cN[$p])){$ok = array_diff_assoc($ok, $cN[$p]);}
203
- }else{$ok = $inOk; unset($cI['del'], $cI['ins']);}
197
+  if (isset($cS[$p])) {$ok = $cS[$p]; }
198
+  elseif (isset($cI[$p])) {$ok = $eI; $cI['del'] = 1; $cI['ins'] = 1; }
199
+  elseif (isset($cF[$p])) {$ok = $eF; unset($cI['del'], $cI['ins']); }
200
+  elseif (isset($cB[$p])) {$ok = $eB; unset($cI['del'], $cI['ins']); }
201
+  if (isset($cO[$p])) {$ok = $ok + $cO[$p]; }
202
+  if (isset($cN[$p])) {$ok = array_diff_assoc($ok, $cN[$p]); }
203
+ } else {$ok = $inOk; unset($cI['del'], $cI['ins']); }
204 204
  // bad tags, & ele content
205
- if(isset($e) && ($do == 1 or (isset($ok['#pcdata']) && ($do == 3 or $do == 5)))){
205
+ if (isset($e) && ($do == 1 or (isset($ok['#pcdata']) && ($do == 3 or $do == 5)))) {
206 206
   echo '&lt;', $s, $e, $a, '&gt;';
207 207
  }
208
- if(isset($x[0])){
209
-  if(strlen(trim($x)) && (($ql && isset($cB[$p])) or (isset($cB[$in]) && !$ql))){
208
+ if (isset($x[0])) {
209
+  if (strlen(trim($x)) && (($ql && isset($cB[$p])) or (isset($cB[$in]) && !$ql))) {
210 210
    echo '<div>', $x, '</div>';
211 211
   }
212
-  elseif($do < 3 or isset($ok['#pcdata'])){echo $x;}
213
-  elseif(strpos($x, "\x02\x04")){
214
-   foreach(preg_split('`(\x01\x02[^\x01\x02]+\x02\x01)`', $x, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY) as $v){
212
+  elseif ($do < 3 or isset($ok['#pcdata'])) {echo $x; }
213
+  elseif (strpos($x, "\x02\x04")) {
214
+   foreach (preg_split('`(\x01\x02[^\x01\x02]+\x02\x01)`', $x, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY) as $v) {
215 215
     echo (substr($v, 0, 2) == "\x01\x02" ? $v : ($do > 4 ? preg_replace('`\S`', '', $v) : ''));
216 216
    }
217
-  }elseif($do > 4){echo preg_replace('`\S`', '', $x);}
217
+  }elseif ($do > 4) {echo preg_replace('`\S`', '', $x); }
218 218
  }
219 219
  // get markup
220
- if(!preg_match('`^(/?)([a-z1-6]+)([^>]*)>(.*)`sm', $t[$i], $r)){$x = $t[$i]; continue;}
220
+ if (!preg_match('`^(/?)([a-z1-6]+)([^>]*)>(.*)`sm', $t[$i], $r)) {$x = $t[$i]; continue; }
221 221
  $s = null; $e = null; $a = null; $x = null; list($all, $s, $e, $a, $x) = $r;
222 222
  // close tag
223
- if($s){
224
-  if(isset($cE[$e]) or !in_array($e, $q)){continue;} // Empty/unopen
225
-  if($p == $e){array_pop($q); echo '</', $e, '>'; unset($e); continue;} // Last open
223
+ if ($s) {
224
+  if (isset($cE[$e]) or !in_array($e, $q)) {continue; } // Empty/unopen
225
+  if ($p == $e) {array_pop($q); echo '</', $e, '>'; unset($e); continue; } // Last open
226 226
   $add = ''; // Nesting - close open tags that need to be
227
-  for($j=-1, $cj=count($q); ++$j<$cj;){
228
-   if(($d = array_pop($q)) == $e){break;}
229
-   else{$add .= "</{$d}>";}
227
+  for ($j = -1, $cj = count($q); ++$j < $cj;) {
228
+   if (($d = array_pop($q)) == $e) {break; }
229
+   else {$add .= "</{$d}>"; }
230 230
   }
231 231
   echo $add, '</', $e, '>'; unset($e); continue;
232 232
  }
233 233
  // open tag
234 234
  // $cB ele needs $eB ele as child
235
- if(isset($cB[$e]) && strlen(trim($x))){
235
+ if (isset($cB[$e]) && strlen(trim($x))) {
236 236
   $t[$i] = "{$e}{$a}>";
237
-  array_splice($t, $i+1, 0, 'div>'. $x); unset($e, $x); ++$ci; --$i; continue;
237
+  array_splice($t, $i + 1, 0, 'div>'.$x); unset($e, $x); ++$ci; --$i; continue;
238 238
  }
239
- if((($ql && isset($cB[$p])) or (isset($cB[$in]) && !$ql)) && !isset($eB[$e]) && !isset($ok[$e])){
239
+ if ((($ql && isset($cB[$p])) or (isset($cB[$in]) && !$ql)) && !isset($eB[$e]) && !isset($ok[$e])) {
240 240
   array_splice($t, $i, 0, 'div>'); unset($e, $x); ++$ci; --$i; continue;
241 241
  }
242
- if($e == 'div' && !isset($ok['div']) && strpos($a, '-htmlawed-transform')){
242
+ if ($e == 'div' && !isset($ok['div']) && strpos($a, '-htmlawed-transform')) {
243 243
   $t[$i] = "span{$a}>{$x}"; unset($e, $x); --$i; continue;
244 244
  }
245 245
  // if no open ele, $in = parent; mostly immediate parent-child relation should hold
246
- if(!$ql or !isset($eN[$e]) or !array_intersect($q, $cN2)){
247
-  if(!isset($ok[$e])){
248
-   if($ql && isset($cT[$p])){echo '</', array_pop($q), '>'; unset($e, $x); --$i;}
246
+ if (!$ql or !isset($eN[$e]) or !array_intersect($q, $cN2)) {
247
+  if (!isset($ok[$e])) {
248
+   if ($ql && isset($cT[$p])) {echo '</', array_pop($q), '>'; unset($e, $x); --$i; }
249 249
    continue;
250 250
   }
251
-  if(!isset($cE[$e])){$q[] = $e;}
251
+  if (!isset($cE[$e])) {$q[] = $e; }
252 252
   echo '<', $e, $a, '>'; unset($e); continue;
253 253
  }
254 254
  // specific parent-child
255
- if(isset($cS[$p][$e])){
256
-  if(!isset($cE[$e])){$q[] = $e;}
255
+ if (isset($cS[$p][$e])) {
256
+  if (!isset($cE[$e])) {$q[] = $e; }
257 257
   echo '<', $e, $a, '>'; unset($e); continue;
258 258
  }
259 259
  // nesting
260 260
  $add = '';
261 261
  $q2 = array();
262
- for($k=-1, $kc=count($q); ++$k<$kc;){
262
+ for ($k = -1, $kc = count($q); ++$k < $kc;) {
263 263
   $d = $q[$k];
264 264
   $ok2 = array();
265
-  if(isset($cS[$d])){$q2[] = $d; continue;}
265
+  if (isset($cS[$d])) {$q2[] = $d; continue; }
266 266
   $ok2 = isset($cI[$d]) ? $eI : $eF;
267
-  if(isset($cO[$d])){$ok2 = $ok2 + $cO[$d];}
268
-  if(isset($cN[$d])){$ok2 = array_diff_assoc($ok2, $cN[$d]);}
269
-  if(!isset($ok2[$e])){
270
-   if(!$k && !isset($inOk[$e])){continue 2;}
267
+  if (isset($cO[$d])) {$ok2 = $ok2 + $cO[$d]; }
268
+  if (isset($cN[$d])) {$ok2 = array_diff_assoc($ok2, $cN[$d]); }
269
+  if (!isset($ok2[$e])) {
270
+   if (!$k && !isset($inOk[$e])) {continue 2; }
271 271
    $add = "</{$d}>";
272
-   for(;++$k<$kc;){$add = "</{$q[$k]}>{$add}";}
272
+   for (;++$k < $kc;) {$add = "</{$q[$k]}>{$add}"; }
273 273
    break;
274 274
   }
275
-  else{$q2[] = $d;}
275
+  else {$q2[] = $d; }
276 276
  }
277 277
  $q = $q2;
278
- if(!isset($cE[$e])){$q[] = $e;}
278
+ if (!isset($cE[$e])) {$q[] = $e; }
279 279
  echo $add, '<', $e, $a, '>'; unset($e); continue;
280 280
 }
281 281
 
282 282
 // end
283
-if($ql = count($q)){
283
+if ($ql = count($q)) {
284 284
  $p = array_pop($q);
285 285
  $q[] = $p;
286
- if(isset($cS[$p])){$ok = $cS[$p];}
287
- elseif(isset($cI[$p])){$ok = $eI; $cI['del'] = 1; $cI['ins'] = 1;}
288
- elseif(isset($cF[$p])){$ok = $eF; unset($cI['del'], $cI['ins']);}
289
- elseif(isset($cB[$p])){$ok = $eB; unset($cI['del'], $cI['ins']);}
290
- if(isset($cO[$p])){$ok = $ok + $cO[$p];}
291
- if(isset($cN[$p])){$ok = array_diff_assoc($ok, $cN[$p]);}
292
-}else{$ok = $inOk; unset($cI['del'], $cI['ins']);}
293
-if(isset($e) && ($do == 1 or (isset($ok['#pcdata']) && ($do == 3 or $do == 5)))){
286
+ if (isset($cS[$p])) {$ok = $cS[$p]; }
287
+ elseif (isset($cI[$p])) {$ok = $eI; $cI['del'] = 1; $cI['ins'] = 1; }
288
+ elseif (isset($cF[$p])) {$ok = $eF; unset($cI['del'], $cI['ins']); }
289
+ elseif (isset($cB[$p])) {$ok = $eB; unset($cI['del'], $cI['ins']); }
290
+ if (isset($cO[$p])) {$ok = $ok + $cO[$p]; }
291
+ if (isset($cN[$p])) {$ok = array_diff_assoc($ok, $cN[$p]); }
292
+} else {$ok = $inOk; unset($cI['del'], $cI['ins']); }
293
+if (isset($e) && ($do == 1 or (isset($ok['#pcdata']) && ($do == 3 or $do == 5)))) {
294 294
  echo '&lt;', $s, $e, $a, '&gt;';
295 295
 }
296
-if(isset($x[0])){
297
- if(strlen(trim($x)) && (($ql && isset($cB[$p])) or (isset($cB[$in]) && !$ql))){
296
+if (isset($x[0])) {
297
+ if (strlen(trim($x)) && (($ql && isset($cB[$p])) or (isset($cB[$in]) && !$ql))) {
298 298
   echo '<div>', $x, '</div>';
299 299
  }
300
- elseif($do < 3 or isset($ok['#pcdata'])){echo $x;}
301
- elseif(strpos($x, "\x02\x04")){
302
-  foreach(preg_split('`(\x01\x02[^\x01\x02]+\x02\x01)`', $x, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY) as $v){
300
+ elseif ($do < 3 or isset($ok['#pcdata'])) {echo $x; }
301
+ elseif (strpos($x, "\x02\x04")) {
302
+  foreach (preg_split('`(\x01\x02[^\x01\x02]+\x02\x01)`', $x, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY) as $v) {
303 303
    echo (substr($v, 0, 2) == "\x01\x02" ? $v : ($do > 4 ? preg_replace('`\S`', '', $v) : ''));
304 304
   }
305
- }elseif($do > 4){echo preg_replace('`\S`', '', $x);}
305
+ }elseif ($do > 4) {echo preg_replace('`\S`', '', $x); }
306 306
 }
307
-while(!empty($q) && ($e = array_pop($q))){echo '</', $e, '>';}
307
+while (!empty($q) && ($e = array_pop($q))) {echo '</', $e, '>'; }
308 308
 $o = ob_get_contents();
309 309
 ob_end_clean();
310 310
 return $o;
311 311
 // eof
312 312
 }
313 313
 
314
-function hl_cmtcd($t){
314
+function hl_cmtcd($t) {
315 315
 // comment/CDATA sec handler
316 316
 $t = $t[0];
317 317
 global $C;
318
-if(!($v = $C[$n = $t[3] == '-' ? 'comment' : 'cdata'])){return $t;}
319
-if($v == 1){return '';}
320
-if($n == 'comment'){
321
- if(substr(($t = preg_replace('`--+`', '-', substr($t, 4, -3))), -1) != ' '){$t .= ' ';}
318
+if (!($v = $C[$n = $t[3] == '-' ? 'comment' : 'cdata'])) {return $t; }
319
+if ($v == 1) {return ''; }
320
+if ($n == 'comment') {
321
+ if (substr(($t = preg_replace('`--+`', '-', substr($t, 4, -3))), -1) != ' ') {$t .= ' '; }
322 322
 }
323
-else{$t = substr($t, 1, -1);}
323
+else {$t = substr($t, 1, -1); }
324 324
 $t = $v == 2 ? str_replace(array('&', '<', '>'), array('&amp;', '&lt;', '&gt;'), $t) : $t;
325 325
 return str_replace(array('&', '<', '>'), array("\x03", "\x04", "\x05"), ($n == 'comment' ? "\x01\x02\x04!--$t--\x05\x02\x01" : "\x01\x01\x04$t\x05\x01\x01"));
326 326
 // eof
327 327
 }
328 328
 
329
-function hl_ent($t){
329
+function hl_ent($t) {
330 330
 // entitity handler
331 331
 global $C;
332 332
 $t = $t[1];
333
-static $U = array('quot'=>1,'amp'=>1,'lt'=>1,'gt'=>1);
334
-static $N = array('fnof'=>'402', 'Alpha'=>'913', 'Beta'=>'914', 'Gamma'=>'915', 'Delta'=>'916', 'Epsilon'=>'917', 'Zeta'=>'918', 'Eta'=>'919', 'Theta'=>'920', 'Iota'=>'921', 'Kappa'=>'922', 'Lambda'=>'923', 'Mu'=>'924', 'Nu'=>'925', 'Xi'=>'926', 'Omicron'=>'927', 'Pi'=>'928', 'Rho'=>'929', 'Sigma'=>'931', 'Tau'=>'932', 'Upsilon'=>'933', 'Phi'=>'934', 'Chi'=>'935', 'Psi'=>'936', 'Omega'=>'937', 'alpha'=>'945', 'beta'=>'946', 'gamma'=>'947', 'delta'=>'948', 'epsilon'=>'949', 'zeta'=>'950', 'eta'=>'951', 'theta'=>'952', 'iota'=>'953', 'kappa'=>'954', 'lambda'=>'955', 'mu'=>'956', 'nu'=>'957', 'xi'=>'958', 'omicron'=>'959', 'pi'=>'960', 'rho'=>'961', 'sigmaf'=>'962', 'sigma'=>'963', 'tau'=>'964', 'upsilon'=>'965', 'phi'=>'966', 'chi'=>'967', 'psi'=>'968', 'omega'=>'969', 'thetasym'=>'977', 'upsih'=>'978', 'piv'=>'982', 'bull'=>'8226', 'hellip'=>'8230', 'prime'=>'8242', 'Prime'=>'8243', 'oline'=>'8254', 'frasl'=>'8260', 'weierp'=>'8472', 'image'=>'8465', 'real'=>'8476', 'trade'=>'8482', 'alefsym'=>'8501', 'larr'=>'8592', 'uarr'=>'8593', 'rarr'=>'8594', 'darr'=>'8595', 'harr'=>'8596', 'crarr'=>'8629', 'lArr'=>'8656', 'uArr'=>'8657', 'rArr'=>'8658', 'dArr'=>'8659', 'hArr'=>'8660', 'forall'=>'8704', 'part'=>'8706', 'exist'=>'8707', 'empty'=>'8709', 'nabla'=>'8711', 'isin'=>'8712', 'notin'=>'8713', 'ni'=>'8715', 'prod'=>'8719', 'sum'=>'8721', 'minus'=>'8722', 'lowast'=>'8727', 'radic'=>'8730', 'prop'=>'8733', 'infin'=>'8734', 'ang'=>'8736', 'and'=>'8743', 'or'=>'8744', 'cap'=>'8745', 'cup'=>'8746', 'int'=>'8747', 'there4'=>'8756', 'sim'=>'8764', 'cong'=>'8773', 'asymp'=>'8776', 'ne'=>'8800', 'equiv'=>'8801', 'le'=>'8804', 'ge'=>'8805', 'sub'=>'8834', 'sup'=>'8835', 'nsub'=>'8836', 'sube'=>'8838', 'supe'=>'8839', 'oplus'=>'8853', 'otimes'=>'8855', 'perp'=>'8869', 'sdot'=>'8901', 'lceil'=>'8968', 'rceil'=>'8969', 'lfloor'=>'8970', 'rfloor'=>'8971', 'lang'=>'9001', 'rang'=>'9002', 'loz'=>'9674', 'spades'=>'9824', 'clubs'=>'9827', 'hearts'=>'9829', 'diams'=>'9830', 'apos'=>'39',  'OElig'=>'338', 'oelig'=>'339', 'Scaron'=>'352', 'scaron'=>'353', 'Yuml'=>'376', 'circ'=>'710', 'tilde'=>'732', 'ensp'=>'8194', 'emsp'=>'8195', 'thinsp'=>'8201', 'zwnj'=>'8204', 'zwj'=>'8205', 'lrm'=>'8206', 'rlm'=>'8207', 'ndash'=>'8211', 'mdash'=>'8212', 'lsquo'=>'8216', 'rsquo'=>'8217', 'sbquo'=>'8218', 'ldquo'=>'8220', 'rdquo'=>'8221', 'bdquo'=>'8222', 'dagger'=>'8224', 'Dagger'=>'8225', 'permil'=>'8240', 'lsaquo'=>'8249', 'rsaquo'=>'8250', 'euro'=>'8364', 'nbsp'=>'160', 'iexcl'=>'161', 'cent'=>'162', 'pound'=>'163', 'curren'=>'164', 'yen'=>'165', 'brvbar'=>'166', 'sect'=>'167', 'uml'=>'168', 'copy'=>'169', 'ordf'=>'170', 'laquo'=>'171', 'not'=>'172', 'shy'=>'173', 'reg'=>'174', 'macr'=>'175', 'deg'=>'176', 'plusmn'=>'177', 'sup2'=>'178', 'sup3'=>'179', 'acute'=>'180', 'micro'=>'181', 'para'=>'182', 'middot'=>'183', 'cedil'=>'184', 'sup1'=>'185', 'ordm'=>'186', 'raquo'=>'187', 'frac14'=>'188', 'frac12'=>'189', 'frac34'=>'190', 'iquest'=>'191', 'Agrave'=>'192', 'Aacute'=>'193', 'Acirc'=>'194', 'Atilde'=>'195', 'Auml'=>'196', 'Aring'=>'197', 'AElig'=>'198', 'Ccedil'=>'199', 'Egrave'=>'200', 'Eacute'=>'201', 'Ecirc'=>'202', 'Euml'=>'203', 'Igrave'=>'204', 'Iacute'=>'205', 'Icirc'=>'206', 'Iuml'=>'207', 'ETH'=>'208', 'Ntilde'=>'209', 'Ograve'=>'210', 'Oacute'=>'211', 'Ocirc'=>'212', 'Otilde'=>'213', 'Ouml'=>'214', 'times'=>'215', 'Oslash'=>'216', 'Ugrave'=>'217', 'Uacute'=>'218', 'Ucirc'=>'219', 'Uuml'=>'220', 'Yacute'=>'221', 'THORN'=>'222', 'szlig'=>'223', 'agrave'=>'224', 'aacute'=>'225', 'acirc'=>'226', 'atilde'=>'227', 'auml'=>'228', 'aring'=>'229', 'aelig'=>'230', 'ccedil'=>'231', 'egrave'=>'232', 'eacute'=>'233', 'ecirc'=>'234', 'euml'=>'235', 'igrave'=>'236', 'iacute'=>'237', 'icirc'=>'238', 'iuml'=>'239', 'eth'=>'240', 'ntilde'=>'241', 'ograve'=>'242', 'oacute'=>'243', 'ocirc'=>'244', 'otilde'=>'245', 'ouml'=>'246', 'divide'=>'247', 'oslash'=>'248', 'ugrave'=>'249', 'uacute'=>'250', 'ucirc'=>'251', 'uuml'=>'252', 'yacute'=>'253', 'thorn'=>'254', 'yuml'=>'255');
335
-if($t[0] != '#'){
336
- return ($C['and_mark'] ? "\x06" : '&'). (isset($U[$t]) ? $t : (isset($N[$t]) ? (!$C['named_entity'] ? '#'. ($C['hexdec_entity'] > 1 ? 'x'. dechex($N[$t]) : $N[$t]) : $t) : 'amp;'. $t)). ';';
333
+static $U = array('quot'=>1, 'amp'=>1, 'lt'=>1, 'gt'=>1);
334
+static $N = array('fnof'=>'402', 'Alpha'=>'913', 'Beta'=>'914', 'Gamma'=>'915', 'Delta'=>'916', 'Epsilon'=>'917', 'Zeta'=>'918', 'Eta'=>'919', 'Theta'=>'920', 'Iota'=>'921', 'Kappa'=>'922', 'Lambda'=>'923', 'Mu'=>'924', 'Nu'=>'925', 'Xi'=>'926', 'Omicron'=>'927', 'Pi'=>'928', 'Rho'=>'929', 'Sigma'=>'931', 'Tau'=>'932', 'Upsilon'=>'933', 'Phi'=>'934', 'Chi'=>'935', 'Psi'=>'936', 'Omega'=>'937', 'alpha'=>'945', 'beta'=>'946', 'gamma'=>'947', 'delta'=>'948', 'epsilon'=>'949', 'zeta'=>'950', 'eta'=>'951', 'theta'=>'952', 'iota'=>'953', 'kappa'=>'954', 'lambda'=>'955', 'mu'=>'956', 'nu'=>'957', 'xi'=>'958', 'omicron'=>'959', 'pi'=>'960', 'rho'=>'961', 'sigmaf'=>'962', 'sigma'=>'963', 'tau'=>'964', 'upsilon'=>'965', 'phi'=>'966', 'chi'=>'967', 'psi'=>'968', 'omega'=>'969', 'thetasym'=>'977', 'upsih'=>'978', 'piv'=>'982', 'bull'=>'8226', 'hellip'=>'8230', 'prime'=>'8242', 'Prime'=>'8243', 'oline'=>'8254', 'frasl'=>'8260', 'weierp'=>'8472', 'image'=>'8465', 'real'=>'8476', 'trade'=>'8482', 'alefsym'=>'8501', 'larr'=>'8592', 'uarr'=>'8593', 'rarr'=>'8594', 'darr'=>'8595', 'harr'=>'8596', 'crarr'=>'8629', 'lArr'=>'8656', 'uArr'=>'8657', 'rArr'=>'8658', 'dArr'=>'8659', 'hArr'=>'8660', 'forall'=>'8704', 'part'=>'8706', 'exist'=>'8707', 'empty'=>'8709', 'nabla'=>'8711', 'isin'=>'8712', 'notin'=>'8713', 'ni'=>'8715', 'prod'=>'8719', 'sum'=>'8721', 'minus'=>'8722', 'lowast'=>'8727', 'radic'=>'8730', 'prop'=>'8733', 'infin'=>'8734', 'ang'=>'8736', 'and'=>'8743', 'or'=>'8744', 'cap'=>'8745', 'cup'=>'8746', 'int'=>'8747', 'there4'=>'8756', 'sim'=>'8764', 'cong'=>'8773', 'asymp'=>'8776', 'ne'=>'8800', 'equiv'=>'8801', 'le'=>'8804', 'ge'=>'8805', 'sub'=>'8834', 'sup'=>'8835', 'nsub'=>'8836', 'sube'=>'8838', 'supe'=>'8839', 'oplus'=>'8853', 'otimes'=>'8855', 'perp'=>'8869', 'sdot'=>'8901', 'lceil'=>'8968', 'rceil'=>'8969', 'lfloor'=>'8970', 'rfloor'=>'8971', 'lang'=>'9001', 'rang'=>'9002', 'loz'=>'9674', 'spades'=>'9824', 'clubs'=>'9827', 'hearts'=>'9829', 'diams'=>'9830', 'apos'=>'39', 'OElig'=>'338', 'oelig'=>'339', 'Scaron'=>'352', 'scaron'=>'353', 'Yuml'=>'376', 'circ'=>'710', 'tilde'=>'732', 'ensp'=>'8194', 'emsp'=>'8195', 'thinsp'=>'8201', 'zwnj'=>'8204', 'zwj'=>'8205', 'lrm'=>'8206', 'rlm'=>'8207', 'ndash'=>'8211', 'mdash'=>'8212', 'lsquo'=>'8216', 'rsquo'=>'8217', 'sbquo'=>'8218', 'ldquo'=>'8220', 'rdquo'=>'8221', 'bdquo'=>'8222', 'dagger'=>'8224', 'Dagger'=>'8225', 'permil'=>'8240', 'lsaquo'=>'8249', 'rsaquo'=>'8250', 'euro'=>'8364', 'nbsp'=>'160', 'iexcl'=>'161', 'cent'=>'162', 'pound'=>'163', 'curren'=>'164', 'yen'=>'165', 'brvbar'=>'166', 'sect'=>'167', 'uml'=>'168', 'copy'=>'169', 'ordf'=>'170', 'laquo'=>'171', 'not'=>'172', 'shy'=>'173', 'reg'=>'174', 'macr'=>'175', 'deg'=>'176', 'plusmn'=>'177', 'sup2'=>'178', 'sup3'=>'179', 'acute'=>'180', 'micro'=>'181', 'para'=>'182', 'middot'=>'183', 'cedil'=>'184', 'sup1'=>'185', 'ordm'=>'186', 'raquo'=>'187', 'frac14'=>'188', 'frac12'=>'189', 'frac34'=>'190', 'iquest'=>'191', 'Agrave'=>'192', 'Aacute'=>'193', 'Acirc'=>'194', 'Atilde'=>'195', 'Auml'=>'196', 'Aring'=>'197', 'AElig'=>'198', 'Ccedil'=>'199', 'Egrave'=>'200', 'Eacute'=>'201', 'Ecirc'=>'202', 'Euml'=>'203', 'Igrave'=>'204', 'Iacute'=>'205', 'Icirc'=>'206', 'Iuml'=>'207', 'ETH'=>'208', 'Ntilde'=>'209', 'Ograve'=>'210', 'Oacute'=>'211', 'Ocirc'=>'212', 'Otilde'=>'213', 'Ouml'=>'214', 'times'=>'215', 'Oslash'=>'216', 'Ugrave'=>'217', 'Uacute'=>'218', 'Ucirc'=>'219', 'Uuml'=>'220', 'Yacute'=>'221', 'THORN'=>'222', 'szlig'=>'223', 'agrave'=>'224', 'aacute'=>'225', 'acirc'=>'226', 'atilde'=>'227', 'auml'=>'228', 'aring'=>'229', 'aelig'=>'230', 'ccedil'=>'231', 'egrave'=>'232', 'eacute'=>'233', 'ecirc'=>'234', 'euml'=>'235', 'igrave'=>'236', 'iacute'=>'237', 'icirc'=>'238', 'iuml'=>'239', 'eth'=>'240', 'ntilde'=>'241', 'ograve'=>'242', 'oacute'=>'243', 'ocirc'=>'244', 'otilde'=>'245', 'ouml'=>'246', 'divide'=>'247', 'oslash'=>'248', 'ugrave'=>'249', 'uacute'=>'250', 'ucirc'=>'251', 'uuml'=>'252', 'yacute'=>'253', 'thorn'=>'254', 'yuml'=>'255');
335
+if ($t[0] != '#') {
336
+ return ($C['and_mark'] ? "\x06" : '&').(isset($U[$t]) ? $t : (isset($N[$t]) ? (!$C['named_entity'] ? '#'.($C['hexdec_entity'] > 1 ? 'x'.dechex($N[$t]) : $N[$t]) : $t) : 'amp;'.$t)).';';
337 337
 }
338
-if(($n = ctype_digit($t = substr($t, 1)) ? intval($t) : hexdec(substr($t, 1))) < 9 or ($n > 13 && $n < 32) or $n == 11 or $n == 12 or ($n > 126 && $n < 160 && $n != 133) or ($n > 55295 && ($n < 57344 or ($n > 64975 && $n < 64992) or $n == 65534 or $n == 65535 or $n > 1114111))){
339
- return ($C['and_mark'] ? "\x06" : '&'). "amp;#{$t};";
338
+if (($n = ctype_digit($t = substr($t, 1)) ? intval($t) : hexdec(substr($t, 1))) < 9 or ($n > 13 && $n < 32) or $n == 11 or $n == 12 or ($n > 126 && $n < 160 && $n != 133) or ($n > 55295 && ($n < 57344 or ($n > 64975 && $n < 64992) or $n == 65534 or $n == 65535 or $n > 1114111))) {
339
+ return ($C['and_mark'] ? "\x06" : '&')."amp;#{$t};";
340 340
 }
341
-return ($C['and_mark'] ? "\x06" : '&'). '#'. (((ctype_digit($t) && $C['hexdec_entity'] < 2) or !$C['hexdec_entity']) ? $n : 'x'. dechex($n)). ';';
341
+return ($C['and_mark'] ? "\x06" : '&').'#'.(((ctype_digit($t) && $C['hexdec_entity'] < 2) or !$C['hexdec_entity']) ? $n : 'x'.dechex($n)).';';
342 342
 // eof
343 343
 }
344 344
 
345
-function hl_prot($p, $c=null){
345
+function hl_prot($p, $c = null) {
346 346
 // check URL scheme
347 347
 global $C;
348 348
 $b = $a = '';
349
-if($c == null){$c = 'style'; $b = $p[1]; $a = $p[3]; $p = trim($p[2]);}
349
+if ($c == null) {$c = 'style'; $b = $p[1]; $a = $p[3]; $p = trim($p[2]); }
350 350
 $c = isset($C['schemes'][$c]) ? $C['schemes'][$c] : $C['schemes']['*'];
351 351
 static $d = 'denied:';
352
-if(isset($c['!']) && substr($p, 0, 7) != $d){$p = "$d$p";}
353
-if(isset($c['*']) or !strcspn($p, '#?;') or (substr($p, 0, 7) == $d)){return "{$b}{$p}{$a}";} // All ok, frag, query, param
354
-if(preg_match('`^([^:?[@!$()*,=/\'\]]+?)(:|&#(58|x3a);|%3a|\\\\0{0,4}3a).`i', $p, $m) && !isset($c[strtolower($m[1])])){ // Denied prot
352
+if (isset($c['!']) && substr($p, 0, 7) != $d) {$p = "$d$p"; }
353
+if (isset($c['*']) or !strcspn($p, '#?;') or (substr($p, 0, 7) == $d)) {return "{$b}{$p}{$a}"; } // All ok, frag, query, param
354
+if (preg_match('`^([^:?[@!$()*,=/\'\]]+?)(:|&#(58|x3a);|%3a|\\\\0{0,4}3a).`i', $p, $m) && !isset($c[strtolower($m[1])])) { // Denied prot
355 355
  return "{$b}{$d}{$p}{$a}";
356 356
 }
357
-if($C['abs_url']){
358
- if($C['abs_url'] == -1 && strpos($p, $C['base_url']) === 0){ // Make url rel
357
+if ($C['abs_url']) {
358
+ if ($C['abs_url'] == -1 && strpos($p, $C['base_url']) === 0) { // Make url rel
359 359
   $p = substr($p, strlen($C['base_url']));
360
- }elseif(empty($m[1])){ // Make URL abs
361
-  if(substr($p, 0, 2) == '//'){$p = substr($C['base_url'], 0, strpos($C['base_url'], ':')+1). $p;}
362
-  elseif($p[0] == '/'){$p = preg_replace('`(^.+?://[^/]+)(.*)`', '$1', $C['base_url']). $p;}
363
-  elseif(strcspn($p, './')){$p = $C['base_url']. $p;}
364
-  else{
360
+ }elseif (empty($m[1])) { // Make URL abs
361
+  if (substr($p, 0, 2) == '//') {$p = substr($C['base_url'], 0, strpos($C['base_url'], ':') + 1).$p; }
362
+  elseif ($p[0] == '/') {$p = preg_replace('`(^.+?://[^/]+)(.*)`', '$1', $C['base_url']).$p; }
363
+  elseif (strcspn($p, './')) {$p = $C['base_url'].$p; }
364
+  else {
365 365
    preg_match('`^([a-zA-Z\d\-+.]+://[^/]+)(.*)`', $C['base_url'], $m);
366
-   $p = preg_replace('`(?<=/)\./`', '', $m[2]. $p);
367
-   while(preg_match('`(?<=/)([^/]{3,}|[^/.]+?|\.[^/.]|[^/.]\.)/\.\./`', $p)){
366
+   $p = preg_replace('`(?<=/)\./`', '', $m[2].$p);
367
+   while (preg_match('`(?<=/)([^/]{3,}|[^/.]+?|\.[^/.]|[^/.]\.)/\.\./`', $p)) {
368 368
     $p = preg_replace('`(?<=/)([^/]{3,}|[^/.]+?|\.[^/.]|[^/.]\.)/\.\./`', '', $p);
369 369
    }
370
-   $p = $m[1]. $p;
370
+   $p = $m[1].$p;
371 371
   }
372 372
  }
373 373
 }
@@ -375,87 +375,87 @@  discard block
 block discarded – undo
375 375
 // eof
376 376
 }
377 377
 
378
-function hl_regex($p){
378
+function hl_regex($p) {
379 379
 // ?regex
380
-if(empty($p)){return 0;}
381
-if($t = ini_get('track_errors')){$o = isset($php_errormsg) ? $php_errormsg : null;}
382
-else{ini_set('track_errors', 1);}
380
+if (empty($p)) {return 0; }
381
+if ($t = ini_get('track_errors')) {$o = isset($php_errormsg) ? $php_errormsg : null; }
382
+else {ini_set('track_errors', 1); }
383 383
 unset($php_errormsg);
384
-if(($d = ini_get('display_errors'))){ini_set('display_errors', 0);}
384
+if (($d = ini_get('display_errors'))) {ini_set('display_errors', 0); }
385 385
 preg_match($p, '');
386
-if($d){ini_set('display_errors', 1);}
386
+if ($d) {ini_set('display_errors', 1); }
387 387
 $r = isset($php_errormsg) ? 0 : 1;
388
-if($t){$php_errormsg = isset($o) ? $o : null;}
389
-else{ini_set('track_errors', 0);}
388
+if ($t) {$php_errormsg = isset($o) ? $o : null; }
389
+else {ini_set('track_errors', 0); }
390 390
 return $r;
391 391
 // eof
392 392
 }
393 393
 
394
-function hl_spec($t){
394
+function hl_spec($t) {
395 395
 // final $spec
396 396
 $s = array();
397 397
 $t = str_replace(array("\t", "\r", "\n", ' '), '', preg_replace_callback('/"(?>(`.|[^"])*)"/sm', create_function('$m', 'return substr(str_replace(array(";", "|", "~", " ", ",", "/", "(", ")", \'`"\'), array("\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07", "\x08", "\""), $m[0]), 1, -1);'), trim($t)));
398
-for($i = count(($t = explode(';', $t))); --$i>=0;){
398
+for ($i = count(($t = explode(';', $t))); --$i >= 0;) {
399 399
  $w = $t[$i];
400
- if(empty($w) or ($e = strpos($w, '=')) === false or !strlen(($a =  substr($w, $e+1)))){continue;}
400
+ if (empty($w) or ($e = strpos($w, '=')) === false or !strlen(($a = substr($w, $e + 1)))) {continue; }
401 401
  $y = $n = array();
402
- foreach(explode(',', $a) as $v){
403
-  if(!preg_match('`^([a-z:\-\*]+)(?:\((.*?)\))?`i', $v, $m)){continue;}
404
-  if(($x = strtolower($m[1])) == '-*'){$n['*'] = 1; continue;}
405
-  if($x[0] == '-'){$n[substr($x, 1)] = 1; continue;}
406
-  if(!isset($m[2])){$y[$x] = 1; continue;}
407
-  foreach(explode('/', $m[2]) as $m){
408
-   if(empty($m) or ($p = strpos($m, '=')) == 0 or $p < 5){$y[$x] = 1; continue;}
409
-   $y[$x][strtolower(substr($m, 0, $p))] = str_replace(array("\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07", "\x08"), array(";", "|", "~", " ", ",", "/", "(", ")"), substr($m, $p+1));
402
+ foreach (explode(',', $a) as $v) {
403
+  if (!preg_match('`^([a-z:\-\*]+)(?:\((.*?)\))?`i', $v, $m)) {continue; }
404
+  if (($x = strtolower($m[1])) == '-*') {$n['*'] = 1; continue; }
405
+  if ($x[0] == '-') {$n[substr($x, 1)] = 1; continue; }
406
+  if (!isset($m[2])) {$y[$x] = 1; continue; }
407
+  foreach (explode('/', $m[2]) as $m) {
408
+   if (empty($m) or ($p = strpos($m, '=')) == 0 or $p < 5) {$y[$x] = 1; continue; }
409
+   $y[$x][strtolower(substr($m, 0, $p))] = str_replace(array("\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07", "\x08"), array(";", "|", "~", " ", ",", "/", "(", ")"), substr($m, $p + 1));
410 410
   }
411
-  if(isset($y[$x]['match']) && !hl_regex($y[$x]['match'])){unset($y[$x]['match']);}
412
-  if(isset($y[$x]['nomatch']) && !hl_regex($y[$x]['nomatch'])){unset($y[$x]['nomatch']);}
411
+  if (isset($y[$x]['match']) && !hl_regex($y[$x]['match'])) {unset($y[$x]['match']); }
412
+  if (isset($y[$x]['nomatch']) && !hl_regex($y[$x]['nomatch'])) {unset($y[$x]['nomatch']); }
413 413
  }
414
- if(!count($y) && !count($n)){continue;}
415
- foreach(explode(',', substr($w, 0, $e)) as $v){
416
-  if(!strlen(($v = strtolower($v)))){continue;}
417
-  if(count($y)){$s[$v] = $y;}
418
-  if(count($n)){$s[$v]['n'] = $n;}
414
+ if (!count($y) && !count($n)) {continue; }
415
+ foreach (explode(',', substr($w, 0, $e)) as $v) {
416
+  if (!strlen(($v = strtolower($v)))) {continue; }
417
+  if (count($y)) {$s[$v] = $y; }
418
+  if (count($n)) {$s[$v]['n'] = $n; }
419 419
  }
420 420
 }
421 421
 return $s;
422 422
 // eof
423 423
 }
424 424
 
425
-function hl_tag($t){
425
+function hl_tag($t) {
426 426
 // tag/attribute handler
427 427
 global $C;
428 428
 $t = $t[0];
429 429
 // invalid < >
430
-if($t == '< '){return '&lt; ';}
431
-if($t == '>'){return '&gt;';}
432
-if(!preg_match('`^<(/?)([a-zA-Z][a-zA-Z1-6]*)([^>]*?)\s?>$`m', $t, $m)){
430
+if ($t == '< ') {return '&lt; '; }
431
+if ($t == '>') {return '&gt;'; }
432
+if (!preg_match('`^<(/?)([a-zA-Z][a-zA-Z1-6]*)([^>]*?)\s?>$`m', $t, $m)) {
433 433
  //return str_replace(array('<', '>'), array('&lt;', '&gt;'), $t);
434
- return (($C['keep_bad']%2) ? str_replace(array('<', '>'), array('&lt;', '&gt;'), $t) : '');
435
-}elseif(!isset($C['elements'][($e = strtolower($m[2]))])){
436
- return (($C['keep_bad']%2) ? str_replace(array('<', '>'), array('&lt;', '&gt;'), $t) : '');
434
+ return (($C['keep_bad'] % 2) ? str_replace(array('<', '>'), array('&lt;', '&gt;'), $t) : '');
435
+}elseif (!isset($C['elements'][($e = strtolower($m[2]))])) {
436
+ return (($C['keep_bad'] % 2) ? str_replace(array('<', '>'), array('&lt;', '&gt;'), $t) : '');
437 437
 }
438 438
 // attr string
439 439
 $a = str_replace(array("\n", "\r", "\t"), ' ', trim($m[3]));
440 440
 // tag transform
441 441
 static $eD = array('applet'=>1, 'center'=>1, 'dir'=>1, 'embed'=>1, 'font'=>1, 'isindex'=>1, 'menu'=>1, 's'=>1, 'strike'=>1, 'u'=>1); // Deprecated
442
-if($C['make_tag_strict'] && isset($eD[$e])){
442
+if ($C['make_tag_strict'] && isset($eD[$e])) {
443 443
  $trt = hl_tag2($e, $a, $C['make_tag_strict']);
444
- if(!$e){return (($C['keep_bad']%2) ? str_replace(array('<', '>'), array('&lt;', '&gt;'), $t) : '');}
444
+ if (!$e) {return (($C['keep_bad'] % 2) ? str_replace(array('<', '>'), array('&lt;', '&gt;'), $t) : ''); }
445 445
 }
446 446
 // close tag
447 447
 static $eE = array('area'=>1, 'br'=>1, 'col'=>1, 'embed'=>1, 'hr'=>1, 'img'=>1, 'input'=>1, 'isindex'=>1, 'param'=>1); // Empty ele
448
-if(!empty($m[1])){
449
- return (!isset($eE[$e]) ? (empty($C['hook_tag']) ? "</$e>" : $C['hook_tag']($e)) : (($C['keep_bad'])%2 ? str_replace(array('<', '>'), array('&lt;', '&gt;'), $t) : ''));
448
+if (!empty($m[1])) {
449
+ return (!isset($eE[$e]) ? (empty($C['hook_tag']) ? "</$e>" : $C['hook_tag']($e)) : (($C['keep_bad']) % 2 ? str_replace(array('<', '>'), array('&lt;', '&gt;'), $t) : ''));
450 450
 }
451 451
 // open tag & attr
452 452
 static $aN = array('abbr'=>array('td'=>1, 'th'=>1), 'accept-charset'=>array('form'=>1), 'accept'=>array('form'=>1, 'input'=>1), 'accesskey'=>array('a'=>1, 'area'=>1, 'button'=>1, 'input'=>1, 'label'=>1, 'legend'=>1, 'textarea'=>1), 'action'=>array('form'=>1), 'align'=>array('caption'=>1, 'embed'=>1, 'applet'=>1, 'iframe'=>1, 'img'=>1, 'input'=>1, 'object'=>1, 'legend'=>1, 'table'=>1, 'hr'=>1, 'div'=>1, 'h1'=>1, 'h2'=>1, 'h3'=>1, 'h4'=>1, 'h5'=>1, 'h6'=>1, 'p'=>1, 'col'=>1, 'colgroup'=>1, 'tbody'=>1, 'td'=>1, 'tfoot'=>1, 'th'=>1, 'thead'=>1, 'tr'=>1), 'allowfullscreen'=>array('iframe'=>1), 'alt'=>array('applet'=>1, 'area'=>1, 'img'=>1, 'input'=>1), 'archive'=>array('applet'=>1, 'object'=>1), 'axis'=>array('td'=>1, 'th'=>1), 'bgcolor'=>array('embed'=>1, 'table'=>1, 'tr'=>1, 'td'=>1, 'th'=>1), 'border'=>array('table'=>1, 'img'=>1, 'object'=>1), 'bordercolor'=>array('table'=>1, 'td'=>1, 'tr'=>1), 'cellpadding'=>array('table'=>1), 'cellspacing'=>array('table'=>1), 'char'=>array('col'=>1, 'colgroup'=>1, 'tbody'=>1, 'td'=>1, 'tfoot'=>1, 'th'=>1, 'thead'=>1, 'tr'=>1), 'charoff'=>array('col'=>1, 'colgroup'=>1, 'tbody'=>1, 'td'=>1, 'tfoot'=>1, 'th'=>1, 'thead'=>1, 'tr'=>1), 'charset'=>array('a'=>1, 'script'=>1), 'checked'=>array('input'=>1), 'cite'=>array('blockquote'=>1, 'q'=>1, 'del'=>1, 'ins'=>1), 'classid'=>array('object'=>1), 'clear'=>array('br'=>1), 'code'=>array('applet'=>1), 'codebase'=>array('object'=>1, 'applet'=>1), 'codetype'=>array('object'=>1), 'color'=>array('font'=>1), 'cols'=>array('textarea'=>1), 'colspan'=>array('td'=>1, 'th'=>1), 'compact'=>array('dir'=>1, 'dl'=>1, 'menu'=>1, 'ol'=>1, 'ul'=>1), 'coords'=>array('area'=>1, 'a'=>1), 'data'=>array('object'=>1), 'datetime'=>array('del'=>1, 'ins'=>1), 'declare'=>array('object'=>1), 'defer'=>array('script'=>1), 'dir'=>array('bdo'=>1), 'disabled'=>array('button'=>1, 'input'=>1, 'optgroup'=>1, 'option'=>1, 'select'=>1, 'textarea'=>1), 'enctype'=>array('form'=>1), 'face'=>array('font'=>1), 'flashvars'=>array('embed'=>1), 'for'=>array('label'=>1), 'frame'=>array('table'=>1), 'frameborder'=>array('iframe'=>1), 'headers'=>array('td'=>1, 'th'=>1), 'height'=>array('embed'=>1, 'iframe'=>1, 'td'=>1, 'th'=>1, 'img'=>1, 'object'=>1, 'applet'=>1), 'href'=>array('a'=>1, 'area'=>1), 'hreflang'=>array('a'=>1), 'hspace'=>array('applet'=>1, 'img'=>1, 'object'=>1), 'ismap'=>array('img'=>1, 'input'=>1), 'label'=>array('option'=>1, 'optgroup'=>1), 'language'=>array('script'=>1), 'longdesc'=>array('img'=>1, 'iframe'=>1), 'marginheight'=>array('iframe'=>1), 'marginwidth'=>array('iframe'=>1), 'maxlength'=>array('input'=>1), 'method'=>array('form'=>1), 'model'=>array('embed'=>1), 'multiple'=>array('select'=>1), 'name'=>array('button'=>1, 'embed'=>1, 'textarea'=>1, 'applet'=>1, 'select'=>1, 'form'=>1, 'iframe'=>1, 'img'=>1, 'a'=>1, 'input'=>1, 'object'=>1, 'map'=>1, 'param'=>1), 'nohref'=>array('area'=>1), 'noshade'=>array('hr'=>1), 'nowrap'=>array('td'=>1, 'th'=>1), 'object'=>array('applet'=>1), 'onblur'=>array('a'=>1, 'area'=>1, 'button'=>1, 'input'=>1, 'label'=>1, 'select'=>1, 'textarea'=>1), 'onchange'=>array('input'=>1, 'select'=>1, 'textarea'=>1), 'onfocus'=>array('a'=>1, 'area'=>1, 'button'=>1, 'input'=>1, 'label'=>1, 'select'=>1, 'textarea'=>1), 'onreset'=>array('form'=>1), 'onselect'=>array('input'=>1, 'textarea'=>1), 'onsubmit'=>array('form'=>1), 'pluginspage'=>array('embed'=>1), 'pluginurl'=>array('embed'=>1), 'prompt'=>array('isindex'=>1), 'readonly'=>array('textarea'=>1, 'input'=>1), 'rel'=>array('a'=>1), 'rev'=>array('a'=>1), 'rows'=>array('textarea'=>1), 'rowspan'=>array('td'=>1, 'th'=>1), 'rules'=>array('table'=>1), 'scope'=>array('td'=>1, 'th'=>1), 'scrolling'=>array('iframe'=>1), 'selected'=>array('option'=>1), 'shape'=>array('area'=>1, 'a'=>1), 'size'=>array('hr'=>1, 'font'=>1, 'input'=>1, 'select'=>1), 'span'=>array('col'=>1, 'colgroup'=>1), 'src'=>array('embed'=>1, 'script'=>1, 'input'=>1, 'iframe'=>1, 'img'=>1), 'standby'=>array('object'=>1), 'start'=>array('ol'=>1), 'summary'=>array('table'=>1), 'tabindex'=>array('a'=>1, 'area'=>1, 'button'=>1, 'input'=>1, 'object'=>1, 'select'=>1, 'textarea'=>1), 'target'=>array('a'=>1, 'area'=>1, 'form'=>1), 'type'=>array('a'=>1, 'embed'=>1, 'object'=>1, 'param'=>1, 'script'=>1, 'input'=>1, 'li'=>1, 'ol'=>1, 'ul'=>1, 'button'=>1), 'usemap'=>array('img'=>1, 'input'=>1, 'object'=>1), 'valign'=>array('col'=>1, 'colgroup'=>1, 'tbody'=>1, 'td'=>1, 'tfoot'=>1, 'th'=>1, 'thead'=>1, 'tr'=>1), 'value'=>array('input'=>1, 'option'=>1, 'param'=>1, 'button'=>1, 'li'=>1), 'valuetype'=>array('param'=>1), 'vspace'=>array('applet'=>1, 'img'=>1, 'object'=>1), 'width'=>array('embed'=>1, 'hr'=>1, 'iframe'=>1, 'img'=>1, 'object'=>1, 'table'=>1, 'td'=>1, 'th'=>1, 'applet'=>1, 'col'=>1, 'colgroup'=>1, 'pre'=>1), 'wmode'=>array('embed'=>1), 'xml:space'=>array('pre'=>1, 'script'=>1, 'style'=>1)); // Ele-specific
453
-$aN['background']=(isset($aN['background'])?array_merge($aN['background'],array('td'=>1)):array('td'=>1));//allow attribute background for (additional) elements, its not allowed by HTML Standards exept for body, but used anyway; one should check for the url to be allowed by application means
453
+$aN['background'] = (isset($aN['background']) ?array_merge($aN['background'], array('td'=>1)) : array('td'=>1)); //allow attribute background for (additional) elements, its not allowed by HTML Standards exept for body, but used anyway; one should check for the url to be allowed by application means
454 454
 static $aNE = array('allowfullscreen'=>1, 'checked'=>1, 'compact'=>1, 'declare'=>1, 'defer'=>1, 'disabled'=>1, 'ismap'=>1, 'multiple'=>1, 'nohref'=>1, 'noresize'=>1, 'noshade'=>1, 'nowrap'=>1, 'readonly'=>1, 'selected'=>1); // Empty
455 455
 static $aNP = array('action'=>1, 'cite'=>1, 'classid'=>1, 'codebase'=>1, 'data'=>1, 'href'=>1, 'longdesc'=>1, 'model'=>1, 'pluginspage'=>1, 'pluginurl'=>1, 'usemap'=>1); // Need scheme check; excludes style, on* & src
456 456
 static $aNU = array('class'=>array('param'=>1, 'script'=>1), 'dir'=>array('applet'=>1, 'bdo'=>1, 'br'=>1, 'iframe'=>1, 'param'=>1, 'script'=>1), 'id'=>array('script'=>1), 'lang'=>array('applet'=>1, 'br'=>1, 'iframe'=>1, 'param'=>1, 'script'=>1), 'xml:lang'=>array('applet'=>1, 'br'=>1, 'iframe'=>1, 'param'=>1, 'script'=>1), 'onclick'=>array('applet'=>1, 'bdo'=>1, 'br'=>1, 'font'=>1, 'iframe'=>1, 'isindex'=>1, 'param'=>1, 'script'=>1), 'ondblclick'=>array('applet'=>1, 'bdo'=>1, 'br'=>1, 'font'=>1, 'iframe'=>1, 'isindex'=>1, 'param'=>1, 'script'=>1), 'onkeydown'=>array('applet'=>1, 'bdo'=>1, 'br'=>1, 'font'=>1, 'iframe'=>1, 'isindex'=>1, 'param'=>1, 'script'=>1), 'onkeypress'=>array('applet'=>1, 'bdo'=>1, 'br'=>1, 'font'=>1, 'iframe'=>1, 'isindex'=>1, 'param'=>1, 'script'=>1), 'onkeyup'=>array('applet'=>1, 'bdo'=>1, 'br'=>1, 'font'=>1, 'iframe'=>1, 'isindex'=>1, 'param'=>1, 'script'=>1), 'onmousedown'=>array('applet'=>1, 'bdo'=>1, 'br'=>1, 'font'=>1, 'iframe'=>1, 'isindex'=>1, 'param'=>1, 'script'=>1), 'onmousemove'=>array('applet'=>1, 'bdo'=>1, 'br'=>1, 'font'=>1, 'iframe'=>1, 'isindex'=>1, 'param'=>1, 'script'=>1), 'onmouseout'=>array('applet'=>1, 'bdo'=>1, 'br'=>1, 'font'=>1, 'iframe'=>1, 'isindex'=>1, 'param'=>1, 'script'=>1), 'onmouseover'=>array('applet'=>1, 'bdo'=>1, 'br'=>1, 'font'=>1, 'iframe'=>1, 'isindex'=>1, 'param'=>1, 'script'=>1), 'onmouseup'=>array('applet'=>1, 'bdo'=>1, 'br'=>1, 'font'=>1, 'iframe'=>1, 'isindex'=>1, 'param'=>1, 'script'=>1), 'style'=>array('param'=>1, 'script'=>1), 'title'=>array('param'=>1, 'script'=>1)); // Univ & exceptions
457 457
 
458
-if($C['lc_std_val']){
458
+if ($C['lc_std_val']) {
459 459
  // predef attr vals for $eAL & $aNE ele
460 460
  static $aNL = array('all'=>1, 'baseline'=>1, 'bottom'=>1, 'button'=>1, 'center'=>1, 'char'=>1, 'checkbox'=>1, 'circle'=>1, 'col'=>1, 'colgroup'=>1, 'cols'=>1, 'data'=>1, 'default'=>1, 'file'=>1, 'get'=>1, 'groups'=>1, 'hidden'=>1, 'image'=>1, 'justify'=>1, 'left'=>1, 'ltr'=>1, 'middle'=>1, 'none'=>1, 'object'=>1, 'password'=>1, 'poly'=>1, 'post'=>1, 'preserve'=>1, 'radio'=>1, 'rect'=>1, 'ref'=>1, 'reset'=>1, 'right'=>1, 'row'=>1, 'rowgroup'=>1, 'rows'=>1, 'rtl'=>1, 'submit'=>1, 'text'=>1, 'top'=>1);
461 461
  static $eAL = array('a'=>1, 'area'=>1, 'bdo'=>1, 'button'=>1, 'col'=>1, 'form'=>1, 'img'=>1, 'input'=>1, 'object'=>1, 'optgroup'=>1, 'option'=>1, 'param'=>1, 'script'=>1, 'select'=>1, 'table'=>1, 'td'=>1, 'tfoot'=>1, 'th'=>1, 'thead'=>1, 'tr'=>1, 'xml:space'=>1);
@@ -463,7 +463,7 @@  discard block
 block discarded – undo
463 463
 }
464 464
 
465 465
 $depTr = 0;
466
-if($C['no_deprecated_attr']){
466
+if ($C['no_deprecated_attr']) {
467 467
  // dep attr:applicable ele
468 468
  static $aND = array('align'=>array('caption'=>1, 'div'=>1, 'h1'=>1, 'h2'=>1, 'h3'=>1, 'h4'=>1, 'h5'=>1, 'h6'=>1, 'hr'=>1, 'img'=>1, 'input'=>1, 'legend'=>1, 'object'=>1, 'p'=>1, 'table'=>1), 'bgcolor'=>array('table'=>1, 'td'=>1, 'th'=>1, 'tr'=>1), 'border'=>array('img'=>1, 'object'=>1), 'bordercolor'=>array('table'=>1, 'td'=>1, 'tr'=>1), 'clear'=>array('br'=>1), 'compact'=>array('dl'=>1, 'ol'=>1, 'ul'=>1), 'height'=>array('td'=>1, 'th'=>1), 'hspace'=>array('img'=>1, 'object'=>1), 'language'=>array('script'=>1), 'name'=>array('a'=>1, 'form'=>1, 'iframe'=>1, 'img'=>1, 'map'=>1), 'noshade'=>array('hr'=>1), 'nowrap'=>array('td'=>1, 'th'=>1), 'size'=>array('hr'=>1), 'start'=>array('ol'=>1), 'type'=>array('li'=>1, 'ol'=>1, 'ul'=>1), 'value'=>array('li'=>1), 'vspace'=>array('img'=>1, 'object'=>1), 'width'=>array('hr'=>1, 'pre'=>1, 'td'=>1, 'th'=>1));
469 469
  static $eAD = array('a'=>1, 'br'=>1, 'caption'=>1, 'div'=>1, 'dl'=>1, 'form'=>1, 'h1'=>1, 'h2'=>1, 'h3'=>1, 'h4'=>1, 'h5'=>1, 'h6'=>1, 'hr'=>1, 'iframe'=>1, 'img'=>1, 'input'=>1, 'legend'=>1, 'li'=>1, 'map'=>1, 'object'=>1, 'ol'=>1, 'p'=>1, 'pre'=>1, 'script'=>1, 'table'=>1, 'td'=>1, 'th'=>1, 'tr'=>1, 'ul'=>1);
@@ -471,196 +471,196 @@  discard block
 block discarded – undo
471 471
 }
472 472
 
473 473
 // attr name-vals
474
-if(strpos($a, "\x01") !== false){$a = preg_replace('`\x01[^\x01]*\x01`', '', $a);} // No comment/CDATA sec
474
+if (strpos($a, "\x01") !== false) {$a = preg_replace('`\x01[^\x01]*\x01`', '', $a); } // No comment/CDATA sec
475 475
 $mode = 0; $a = trim($a, ' /'); $aA = array();
476
-while(strlen($a)){
476
+while (strlen($a)) {
477 477
  $w = 0;
478
- switch($mode){
478
+ switch ($mode) {
479 479
   case 0: // Name
480
-   if(preg_match('`^[a-zA-Z][\-a-zA-Z:]+`', $a, $m)){
480
+   if (preg_match('`^[a-zA-Z][\-a-zA-Z:]+`', $a, $m)) {
481 481
     $nm = strtolower($m[0]);
482 482
     $w = $mode = 1; $a = ltrim(substr_replace($a, '', 0, strlen($m[0])));
483 483
    }
484 484
   break; case 1:
485
-   if($a[0] == '='){ // =
485
+   if ($a[0] == '=') { // =
486 486
     $w = 1; $mode = 2; $a = ltrim($a, '= ');
487
-   }else{ // No val
487
+   } else { // No val
488 488
     $w = 1; $mode = 0; $a = ltrim($a);
489 489
     $aA[$nm] = '';
490 490
    }
491 491
   break; case 2: // Val
492
-   if(preg_match('`^((?:"[^"]*")|(?:\'[^\']*\')|(?:\s*[^\s"\']+))(.*)`', $a, $m)){
492
+   if (preg_match('`^((?:"[^"]*")|(?:\'[^\']*\')|(?:\s*[^\s"\']+))(.*)`', $a, $m)) {
493 493
     $a = ltrim($m[2]); $m = $m[1]; $w = 1; $mode = 0;
494 494
     $aA[$nm] = trim(str_replace('<', '&lt;', ($m[0] == '"' or $m[0] == '\'') ? substr($m, 1, -1) : $m));
495 495
    }
496 496
   break;
497 497
  }
498
- if($w == 0){ // Parse errs, deal with space, " & '
498
+ if ($w == 0) { // Parse errs, deal with space, " & '
499 499
   $a = preg_replace('`^(?:"[^"]*("|$)|\'[^\']*(\'|$)|\S)*\s*`', '', $a);
500 500
   $mode = 0;
501 501
  }
502 502
 }
503
-if($mode == 1){$aA[$nm] = '';}
503
+if ($mode == 1) {$aA[$nm] = ''; }
504 504
 
505 505
 // clean attrs
506 506
 global $S;
507 507
 $rl = isset($S[$e]) ? $S[$e] : array();
508 508
 $a = array(); $nfr = 0;
509
-foreach($aA as $k=>$v){
510
-  if(((isset($C['deny_attribute']['*']) ? isset($C['deny_attribute'][$k]) : !isset($C['deny_attribute'][$k])) && (isset($aN[$k][$e]) or (isset($aNU[$k]) && !isset($aNU[$k][$e]))) && !isset($rl['n'][$k]) && !isset($rl['n']['*'])) or isset($rl[$k])){
511
-  if(isset($aNE[$k])){$v = $k;}
512
-  elseif(!empty($lcase) && (($e != 'button' or $e != 'input') or $k == 'type')){ // Rather loose but ?not cause issues
509
+foreach ($aA as $k=>$v) {
510
+  if (((isset($C['deny_attribute']['*']) ? isset($C['deny_attribute'][$k]) : !isset($C['deny_attribute'][$k])) && (isset($aN[$k][$e]) or (isset($aNU[$k]) && !isset($aNU[$k][$e]))) && !isset($rl['n'][$k]) && !isset($rl['n']['*'])) or isset($rl[$k])) {
511
+  if (isset($aNE[$k])) {$v = $k; }
512
+  elseif (!empty($lcase) && (($e != 'button' or $e != 'input') or $k == 'type')) { // Rather loose but ?not cause issues
513 513
    $v = (isset($aNL[($v2 = strtolower($v))])) ? $v2 : $v;
514 514
   }
515
-  if($k == 'style' && !$C['style_pass']){
516
-   if(false !== strpos($v, '&#')){
515
+  if ($k == 'style' && !$C['style_pass']) {
516
+   if (false !== strpos($v, '&#')) {
517 517
     static $sC = array('&#x20;'=>' ', '&#32;'=>' ', '&#x45;'=>'e', '&#69;'=>'e', '&#x65;'=>'e', '&#101;'=>'e', '&#x58;'=>'x', '&#88;'=>'x', '&#x78;'=>'x', '&#120;'=>'x', '&#x50;'=>'p', '&#80;'=>'p', '&#x70;'=>'p', '&#112;'=>'p', '&#x53;'=>'s', '&#83;'=>'s', '&#x73;'=>'s', '&#115;'=>'s', '&#x49;'=>'i', '&#73;'=>'i', '&#x69;'=>'i', '&#105;'=>'i', '&#x4f;'=>'o', '&#79;'=>'o', '&#x6f;'=>'o', '&#111;'=>'o', '&#x4e;'=>'n', '&#78;'=>'n', '&#x6e;'=>'n', '&#110;'=>'n', '&#x55;'=>'u', '&#85;'=>'u', '&#x75;'=>'u', '&#117;'=>'u', '&#x52;'=>'r', '&#82;'=>'r', '&#x72;'=>'r', '&#114;'=>'r', '&#x4c;'=>'l', '&#76;'=>'l', '&#x6c;'=>'l', '&#108;'=>'l', '&#x28;'=>'(', '&#40;'=>'(', '&#x29;'=>')', '&#41;'=>')', '&#x20;'=>':', '&#32;'=>':', '&#x22;'=>'"', '&#34;'=>'"', '&#x27;'=>"'", '&#39;'=>"'", '&#x2f;'=>'/', '&#47;'=>'/', '&#x2a;'=>'*', '&#42;'=>'*', '&#x5c;'=>'\\', '&#92;'=>'\\');
518 518
     $v = strtr($v, $sC);
519 519
    }
520 520
    $v = preg_replace_callback('`(url(?:\()(?: )*(?:\'|"|&(?:quot|apos);)?)(.+?)((?:\'|"|&(?:quot|apos);)?(?: )*(?:\)))`iS', 'hl_prot', $v);
521 521
    $v = !$C['css_expression'] ? preg_replace('`expression`i', ' ', preg_replace('`\\\\\S|(/|(%2f))(\*|(%2a))`i', ' ', $v)) : $v;
522
-  }elseif(isset($aNP[$k]) or strpos($k, 'src') !== false or $k[0] == 'o'){
522
+  }elseif (isset($aNP[$k]) or strpos($k, 'src') !== false or $k[0] == 'o') {
523 523
    $v = str_replace("­", ' ', (strpos($v, '&') !== false ? str_replace(array('&#xad;', '&#173;', '&shy;'), ' ', $v) : $v)); # double-quoted char is soft-hyphen; appears here as "­" or hyphen or something else depending on viewing software
524 524
    $v = hl_prot($v, $k);
525
-   if($k == 'href'){ // X-spam
526
-    if($C['anti_mail_spam'] && strpos($v, 'mailto:') === 0){
525
+   if ($k == 'href') { // X-spam
526
+    if ($C['anti_mail_spam'] && strpos($v, 'mailto:') === 0) {
527 527
      $v = str_replace('@', htmlspecialchars($C['anti_mail_spam']), $v);
528
-    }elseif($C['anti_link_spam']){
528
+    }elseif ($C['anti_link_spam']) {
529 529
      $r1 = $C['anti_link_spam'][1];
530
-     if(!empty($r1) && preg_match($r1, $v)){continue;}
530
+     if (!empty($r1) && preg_match($r1, $v)) {continue; }
531 531
      $r0 = $C['anti_link_spam'][0];
532
-     if(!empty($r0) && preg_match($r0, $v)){
533
-      if(isset($a['rel'])){
534
-       if(!preg_match('`\bnofollow\b`i', $a['rel'])){$a['rel'] .= ' nofollow';}
535
-      }elseif(isset($aA['rel'])){
536
-       if(!preg_match('`\bnofollow\b`i', $aA['rel'])){$nfr = 1;}
537
-      }else{$a['rel'] = 'nofollow';}
532
+     if (!empty($r0) && preg_match($r0, $v)) {
533
+      if (isset($a['rel'])) {
534
+       if (!preg_match('`\bnofollow\b`i', $a['rel'])) {$a['rel'] .= ' nofollow'; }
535
+      }elseif (isset($aA['rel'])) {
536
+       if (!preg_match('`\bnofollow\b`i', $aA['rel'])) {$nfr = 1; }
537
+      } else {$a['rel'] = 'nofollow'; }
538 538
      }
539 539
     }
540 540
    }
541 541
   }
542
-  if(isset($rl[$k]) && is_array($rl[$k]) && ($v = hl_attrval($k, $v, $rl[$k])) === 0){continue;}
542
+  if (isset($rl[$k]) && is_array($rl[$k]) && ($v = hl_attrval($k, $v, $rl[$k])) === 0) {continue; }
543 543
   $a[$k] = str_replace('"', '&quot;', $v);
544 544
  }
545 545
 }
546
-if($nfr){$a['rel'] = isset($a['rel']) ? $a['rel']. ' nofollow' : 'nofollow';}
546
+if ($nfr) {$a['rel'] = isset($a['rel']) ? $a['rel'].' nofollow' : 'nofollow'; }
547 547
 
548 548
 // rqd attr
549 549
 static $eAR = array('area'=>array('alt'=>'area'), 'bdo'=>array('dir'=>'ltr'), 'form'=>array('action'=>''), 'img'=>array('src'=>'', 'alt'=>'image'), 'map'=>array('name'=>''), 'optgroup'=>array('label'=>''), 'param'=>array('name'=>''), 'script'=>array('type'=>'text/javascript'), 'textarea'=>array('rows'=>'10', 'cols'=>'50'));
550
-if(isset($eAR[$e])){
551
- foreach($eAR[$e] as $k=>$v){
552
-  if(!isset($a[$k])){$a[$k] = isset($v[0]) ? $v : $k;}
550
+if (isset($eAR[$e])) {
551
+ foreach ($eAR[$e] as $k=>$v) {
552
+  if (!isset($a[$k])) {$a[$k] = isset($v[0]) ? $v : $k; }
553 553
  }
554 554
 }
555 555
 
556 556
 // depr attrs
557
-if($depTr){
557
+if ($depTr) {
558 558
  $c = array();
559
- foreach($a as $k=>$v){
560
-  if($k == 'style' or !isset($aND[$k][$e])){continue;}
561
-  if($k == 'align'){
559
+ foreach ($a as $k=>$v) {
560
+  if ($k == 'style' or !isset($aND[$k][$e])) {continue; }
561
+  if ($k == 'align') {
562 562
    unset($a['align']);
563
-   if($e == 'img' && ($v == 'left' or $v == 'right')){$c[] = 'float: '. $v;}
564
-   elseif(($e == 'div' or $e == 'table') && $v == 'center'){$c[] = 'margin: auto';}
565
-   else{$c[] = 'text-align: '. $v;}
566
-  }elseif($k == 'bgcolor'){
563
+   if ($e == 'img' && ($v == 'left' or $v == 'right')) {$c[] = 'float: '.$v; }
564
+   elseif (($e == 'div' or $e == 'table') && $v == 'center') {$c[] = 'margin: auto'; }
565
+   else {$c[] = 'text-align: '.$v; }
566
+  }elseif ($k == 'bgcolor') {
567 567
    unset($a['bgcolor']);
568
-   $c[] = 'background-color: '. $v;
569
-  }elseif($k == 'border'){
568
+   $c[] = 'background-color: '.$v;
569
+  }elseif ($k == 'border') {
570 570
    unset($a['border']); $c[] = "border: {$v}px";
571
-  }elseif($k == 'bordercolor'){
572
-   unset($a['bordercolor']); $c[] = 'border-color: '. $v;
573
-  }elseif($k == 'clear'){
574
-   unset($a['clear']); $c[] = 'clear: '. ($v != 'all' ? $v : 'both');
575
-  }elseif($k == 'compact'){
571
+  }elseif ($k == 'bordercolor') {
572
+   unset($a['bordercolor']); $c[] = 'border-color: '.$v;
573
+  }elseif ($k == 'clear') {
574
+   unset($a['clear']); $c[] = 'clear: '.($v != 'all' ? $v : 'both');
575
+  }elseif ($k == 'compact') {
576 576
    unset($a['compact']); $c[] = 'font-size: 85%';
577
-  }elseif($k == 'height' or $k == 'width'){
578
-   unset($a[$k]); $c[] = $k. ': '. ($v[0] != '*' ? $v. (ctype_digit($v) ? 'px' : '') : 'auto');
579
-  }elseif($k == 'hspace'){
577
+  }elseif ($k == 'height' or $k == 'width') {
578
+   unset($a[$k]); $c[] = $k.': '.($v[0] != '*' ? $v.(ctype_digit($v) ? 'px' : '') : 'auto');
579
+  }elseif ($k == 'hspace') {
580 580
    unset($a['hspace']); $c[] = "margin-left: {$v}px; margin-right: {$v}px";
581
-  }elseif($k == 'language' && !isset($a['type'])){
581
+  }elseif ($k == 'language' && !isset($a['type'])) {
582 582
    unset($a['language']);
583
-   $a['type'] = 'text/'. strtolower($v);
584
-  }elseif($k == 'name'){
585
-   if($C['no_deprecated_attr'] == 2 or ($e != 'a' && $e != 'map')){unset($a['name']);}
586
-   if(!isset($a['id']) && preg_match('`[a-zA-Z][a-zA-Z\d.:_\-]*`', $v)){$a['id'] = $v;}
587
-  }elseif($k == 'noshade'){
583
+   $a['type'] = 'text/'.strtolower($v);
584
+  }elseif ($k == 'name') {
585
+   if ($C['no_deprecated_attr'] == 2 or ($e != 'a' && $e != 'map')) {unset($a['name']); }
586
+   if (!isset($a['id']) && preg_match('`[a-zA-Z][a-zA-Z\d.:_\-]*`', $v)) {$a['id'] = $v; }
587
+  }elseif ($k == 'noshade') {
588 588
    unset($a['noshade']); $c[] = 'border-style: none; border: 0; background-color: gray; color: gray';
589
-  }elseif($k == 'nowrap'){
589
+  }elseif ($k == 'nowrap') {
590 590
    unset($a['nowrap']); $c[] = 'white-space: nowrap';
591
-  }elseif($k == 'size'){
592
-   unset($a['size']); $c[] = 'size: '. $v. 'px';
593
-  }elseif($k == 'start' or $k == 'value'){
591
+  }elseif ($k == 'size') {
592
+   unset($a['size']); $c[] = 'size: '.$v.'px';
593
+  }elseif ($k == 'start' or $k == 'value') {
594 594
    unset($a[$k]);
595
-  }elseif($k == 'type'){
595
+  }elseif ($k == 'type') {
596 596
    unset($a['type']);
597 597
    static $ol_type = array('i'=>'lower-roman', 'I'=>'upper-roman', 'a'=>'lower-latin', 'A'=>'upper-latin', '1'=>'decimal');
598
-   $c[] = 'list-style-type: '. (isset($ol_type[$v]) ? $ol_type[$v] : 'decimal');
599
-  }elseif($k == 'vspace'){
598
+   $c[] = 'list-style-type: '.(isset($ol_type[$v]) ? $ol_type[$v] : 'decimal');
599
+  }elseif ($k == 'vspace') {
600 600
    unset($a['vspace']); $c[] = "margin-top: {$v}px; margin-bottom: {$v}px";
601 601
   }
602 602
  }
603
- if(count($c)){
603
+ if (count($c)) {
604 604
   $c = implode('; ', $c);
605
-  $a['style'] = isset($a['style']) ? rtrim($a['style'], ' ;'). '; '. $c. ';': $c. ';';
605
+  $a['style'] = isset($a['style']) ? rtrim($a['style'], ' ;').'; '.$c.';' : $c.';';
606 606
  }
607 607
 }
608 608
 // unique ID
609
-if($C['unique_ids'] && isset($a['id'])){
610
- if(!preg_match('`^[A-Za-z][A-Za-z0-9_\-.:]*$`', ($id = $a['id'])) or (isset($GLOBALS['hl_Ids'][$id]) && $C['unique_ids'] == 1)){unset($a['id']);
611
- }else{
612
-  while(isset($GLOBALS['hl_Ids'][$id])){$id = $C['unique_ids']. $id;}
609
+if ($C['unique_ids'] && isset($a['id'])) {
610
+ if (!preg_match('`^[A-Za-z][A-Za-z0-9_\-.:]*$`', ($id = $a['id'])) or (isset($GLOBALS['hl_Ids'][$id]) && $C['unique_ids'] == 1)) {unset($a['id']);
611
+ } else {
612
+  while (isset($GLOBALS['hl_Ids'][$id])) {$id = $C['unique_ids'].$id; }
613 613
   $GLOBALS['hl_Ids'][($a['id'] = $id)] = 1;
614 614
  }
615 615
 }
616 616
 // xml:lang
617
-if($C['xml:lang'] && isset($a['lang'])){
617
+if ($C['xml:lang'] && isset($a['lang'])) {
618 618
  $a['xml:lang'] = isset($a['xml:lang']) ? $a['xml:lang'] : $a['lang'];
619
- if($C['xml:lang'] == 2){unset($a['lang']);}
619
+ if ($C['xml:lang'] == 2) {unset($a['lang']); }
620 620
 }
621 621
 // for transformed tag
622
-if(!empty($trt)){
623
- $a['style'] = isset($a['style']) ? rtrim($a['style'], ' ;'). '; '. $trt : $trt;
622
+if (!empty($trt)) {
623
+ $a['style'] = isset($a['style']) ? rtrim($a['style'], ' ;').'; '.$trt : $trt;
624 624
 }
625 625
 // return with empty ele /
626
-if(empty($C['hook_tag'])){
626
+if (empty($C['hook_tag'])) {
627 627
  $aA = '';
628
- foreach($a as $k=>$v){$aA .= " {$k}=\"{$v}\"";}
629
- return "<{$e}{$aA}". (isset($eE[$e]) ? ' /' : ''). '>';
628
+ foreach ($a as $k=>$v) {$aA .= " {$k}=\"{$v}\""; }
629
+ return "<{$e}{$aA}".(isset($eE[$e]) ? ' /' : '').'>';
630 630
 }
631
-else{return $C['hook_tag']($e, $a);}
631
+else {return $C['hook_tag']($e, $a); }
632 632
 // eof
633 633
 }
634 634
 
635
-function hl_tag2(&$e, &$a, $t=1){
635
+function hl_tag2(&$e, &$a, $t = 1) {
636 636
 // transform tag
637
-if($e == 'center'){$e = 'div'; return 'text-align: center;';}
638
-if($e == 'dir' or $e == 'menu'){$e = 'ul'; return '';}
639
-if($e == 's' or $e == 'strike'){$e = 'span'; return 'text-decoration: line-through;';}
640
-if($e == 'u'){$e = 'span'; return 'text-decoration: underline;';}
637
+if ($e == 'center') {$e = 'div'; return 'text-align: center;'; }
638
+if ($e == 'dir' or $e == 'menu') {$e = 'ul'; return ''; }
639
+if ($e == 's' or $e == 'strike') {$e = 'span'; return 'text-decoration: line-through;'; }
640
+if ($e == 'u') {$e = 'span'; return 'text-decoration: underline;'; }
641 641
 static $fs = array('0'=>'xx-small', '1'=>'xx-small', '2'=>'small', '3'=>'medium', '4'=>'large', '5'=>'x-large', '6'=>'xx-large', '7'=>'300%', '-1'=>'smaller', '-2'=>'60%', '+1'=>'larger', '+2'=>'150%', '+3'=>'200%', '+4'=>'300%');
642
-if($e == 'font' && $t !=3){//3 is a new make_tag_strict config value, to indicate that transformation is to be performed, but don't transform font, as size transformation of numeric sizes to keywords alters the intended result too much
642
+if ($e == 'font' && $t != 3) {//3 is a new make_tag_strict config value, to indicate that transformation is to be performed, but don't transform font, as size transformation of numeric sizes to keywords alters the intended result too much
643 643
  $a2 = '';
644
- while(preg_match('`(^|\s)(color|size)\s*=\s*(\'|")?(.+?)(\\3|\s|$)`i', $a, $m)){
644
+ while (preg_match('`(^|\s)(color|size)\s*=\s*(\'|")?(.+?)(\\3|\s|$)`i', $a, $m)) {
645 645
   $a = str_replace($m[0], ' ', $a);
646
-  $a2 .= strtolower($m[2]) == 'color' ? (' color: '. str_replace('"', '\'', trim($m[4])). ';') : (isset($fs[($m = trim($m[4]))]) ? ($a2 .= ' font-size: '. str_replace('"', '\'', $fs[$m]). ';') : '');
646
+  $a2 .= strtolower($m[2]) == 'color' ? (' color: '.str_replace('"', '\'', trim($m[4])).';') : (isset($fs[($m = trim($m[4]))]) ? ($a2 .= ' font-size: '.str_replace('"', '\'', $fs[$m]).';') : '');
647 647
  }
648
- while(preg_match('`(^|\s)face\s*=\s*(\'|")?([^=]+?)\\2`i', $a, $m) or preg_match('`(^|\s)face\s*=(\s*)(\S+)`i', $a, $m)){
648
+ while (preg_match('`(^|\s)face\s*=\s*(\'|")?([^=]+?)\\2`i', $a, $m) or preg_match('`(^|\s)face\s*=(\s*)(\S+)`i', $a, $m)) {
649 649
   $a = str_replace($m[0], ' ', $a);
650
-  $a2 .= ' font-family: '. str_replace('"', '\'', trim($m[3])). ';';
650
+  $a2 .= ' font-family: '.str_replace('"', '\'', trim($m[3])).';';
651 651
  }
652 652
  $e = 'span'; return ltrim(str_replace('<', '', $a2));
653 653
 }
654
-if($t == 2){$e = 0; return 0;}
654
+if ($t == 2) {$e = 0; return 0; }
655 655
 return '';
656 656
 // eof
657 657
 }
658 658
 
659
-function hl_tidy($t, $w, $p){
659
+function hl_tidy($t, $w, $p) {
660 660
 // Tidy/compact HTM
661
-if(strpos(' pre,script,textarea', "$p,")){return $t;}
661
+if (strpos(' pre,script,textarea', "$p,")) {return $t; }
662 662
 $t = preg_replace('`\s+`', ' ', preg_replace_callback(array('`(<(!\[CDATA\[))(.+?)(\]\]>)`sm', '`(<(!--))(.+?)(-->)`sm', '`(<(pre|script|textarea)[^>]*?>)(.+?)(</\2>)`sm'), create_function('$m', 'return $m[1]. str_replace(array("<", ">", "\n", "\r", "\t", " "), array("\x01", "\x02", "\x03", "\x04", "\x05", "\x07"), $m[3]). $m[4];'), $t));
663
-if(($w = strtolower($w)) == -1){
663
+if (($w = strtolower($w)) == -1) {
664 664
  return str_replace(array("\x01", "\x02", "\x03", "\x04", "\x05", "\x07"), array('<', '>', "\n", "\r", "\t", ' '), $t);
665 665
 }
666 666
 $s = strpos(" $w", 't') ? "\t" : ' ';
@@ -672,66 +672,66 @@  discard block
 block discarded – undo
672 672
 $d = array('address'=>1, 'blockquote'=>1, 'center'=>1, 'colgroup'=>1, 'dir'=>1, 'div'=>1, 'dl'=>1, 'fieldset'=>1, 'form'=>1, 'hr'=>1, 'iframe'=>1, 'map'=>1, 'menu'=>1, 'noscript'=>1, 'ol'=>1, 'optgroup'=>1, 'rbc'=>1, 'rtc'=>1, 'ruby'=>1, 'script'=>1, 'select'=>1, 'table'=>1, 'tbody'=>1, 'tfoot'=>1, 'thead'=>1, 'tr'=>1, 'ul'=>1);
673 673
 $T = explode('<', $t);
674 674
 $X = 1;
675
-while($X){
675
+while ($X) {
676 676
  $n = $N;
677 677
  $t = $T;
678 678
  ob_start();
679
- if(isset($d[$p])){echo str_repeat($s, ++$n);}
679
+ if (isset($d[$p])) {echo str_repeat($s, ++$n); }
680 680
  echo ltrim(array_shift($t));
681
- for($i=-1, $j=count($t); ++$i<$j;){
681
+ for ($i = -1, $j = count($t); ++$i < $j;) {
682 682
   $r = ''; list($e, $r) = explode('>', $t[$i]);
683 683
   $x = $e[0] == '/' ? 0 : (substr($e, -1) == '/' ? 1 : ($e[0] != '!' ? 2 : -1));
684 684
   $y = !$x ? ltrim($e, '/') : ($x > 0 ? substr($e, 0, strcspn($e, ' ')) : 0);
685 685
   $e = "<$e>";
686
-  if(isset($d[$y])){
687
-   if(!$x){
688
-    if($n){echo "\n", str_repeat($s, --$n), "$e\n", str_repeat($s, $n);}
689
-    else{++$N; ob_end_clean(); continue 2;}
686
+  if (isset($d[$y])) {
687
+   if (!$x) {
688
+    if ($n) {echo "\n", str_repeat($s, --$n), "$e\n", str_repeat($s, $n); }
689
+    else {++$N; ob_end_clean(); continue 2; }
690 690
    }
691
-   else{echo "\n", str_repeat($s, $n), "$e\n", str_repeat($s, ($x != 1 ? ++$n : $n));}
691
+   else {echo "\n", str_repeat($s, $n), "$e\n", str_repeat($s, ($x != 1 ? ++$n : $n)); }
692 692
    echo $r; continue;
693 693
   }
694
-  $f = "\n". str_repeat($s, $n);
695
-  if(isset($c[$y])){
696
-   if(!$x){echo $e, $f, $r;}
697
-   else{echo $f, $e, $r;}
698
-  }elseif(isset($b[$y])){echo $f, $e, $r;
699
-  }elseif(isset($a[$y])){echo $e, $f, $r;
700
-  }elseif(!$y){echo $f, $e, $f, $r;
701
-  }else{echo $e, $r;}
694
+  $f = "\n".str_repeat($s, $n);
695
+  if (isset($c[$y])) {
696
+   if (!$x) {echo $e, $f, $r; }
697
+   else {echo $f, $e, $r; }
698
+  }elseif (isset($b[$y])) {echo $f, $e, $r;
699
+  }elseif (isset($a[$y])) {echo $e, $f, $r;
700
+  }elseif (!$y) {echo $f, $e, $f, $r;
701
+  } else {echo $e, $r; }
702 702
  }
703 703
  $X = 0;
704 704
 }
705 705
 $t = str_replace(array("\n ", " \n"), "\n", preg_replace('`[\n]\s*?[\n]+`', "\n", ob_get_contents()));
706 706
 ob_end_clean();
707
-if(($l = strpos(" $w", 'r') ? (strpos(" $w", 'n') ? "\r\n" : "\r") : 0)){
707
+if (($l = strpos(" $w", 'r') ? (strpos(" $w", 'n') ? "\r\n" : "\r") : 0)) {
708 708
  $t = str_replace("\n", $l, $t);
709 709
 }
710 710
 return str_replace(array("\x01", "\x02", "\x03", "\x04", "\x05", "\x07"), array('<', '>', "\n", "\r", "\t", ' '), $t);
711 711
 // eof
712 712
 }
713 713
 
714
-function hl_version(){
714
+function hl_version() {
715 715
 // rel
716 716
 return '1.1.22';
717 717
 // eof
718 718
 }
719 719
 
720
-function kses($t, $h, $p=array('http', 'https', 'ftp', 'news', 'nntp', 'telnet', 'gopher', 'mailto')){
720
+function kses($t, $h, $p = array('http', 'https', 'ftp', 'news', 'nntp', 'telnet', 'gopher', 'mailto')) {
721 721
 // kses compat
722
-foreach($h as $k=>$v){
722
+foreach ($h as $k=>$v) {
723 723
  $h[$k]['n']['*'] = 1;
724 724
 }
725 725
 $C['cdata'] = $C['comment'] = $C['make_tag_strict'] = $C['no_deprecated_attr'] = $C['unique_ids'] = 0;
726 726
 $C['keep_bad'] = 1;
727 727
 $C['elements'] = count($h) ? strtolower(implode(',', array_keys($h))) : '-*';
728 728
 $C['hook'] = 'kses_hook';
729
-$C['schemes'] = '*:'. implode(',', $p);
729
+$C['schemes'] = '*:'.implode(',', $p);
730 730
 return htmLawed($t, $C, $h);
731 731
 // eof
732 732
 }
733 733
 
734
-function kses_hook($t, &$C, &$S){
734
+function kses_hook($t, &$C, &$S) {
735 735
 // kses compat
736 736
 return $t;
737 737
 // eof
Please login to merge, or discard this patch.
api/src/Json/Msg.php 2 patches
Doc Comments   +5 added lines, -3 removed lines patch added patch discarded remove patch
@@ -82,8 +82,7 @@  discard block
 block discarded – undo
82 82
 	/**
83 83
 	 * Allows to call a global javascript function with given parameters: window[$func].call(window[, $param1[, ...]])
84 84
 	 *
85
-	 * @param string $func name of the global (window) javascript function to call
86
-	 * @param mixed $parameters variable number of parameters
85
+	 * @param string $function
87 86
 	 */
88 87
 	public function call($function)
89 88
 	{
@@ -108,7 +107,7 @@  discard block
 block discarded – undo
108 107
 	 *
109 108
 	 * @param string $selector jquery selector
110 109
 	 * @param string $method name of the jquery to call
111
-	 * @param array $parameters =array()
110
+	 * @param string[] $parameters =array()
112 111
 	 */
113 112
 	public function jquery($selector,$method,array $parameters=array())
114 113
 	{
@@ -126,6 +125,9 @@  discard block
 block discarded – undo
126 125
 		}
127 126
 	}
128 127
 
128
+	/**
129
+	 * @param string $type
130
+	 */
129 131
 	public function generic($type, array $parameters = array())
130 132
 	{
131 133
 		if (is_string($type))
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 	 * @param string $function name of the global (window) javascript function to call
65 65
 	 * @param array $parameters =array()
66 66
 	 */
67
-	public function apply($function,array $parameters=array())
67
+	public function apply($function, array $parameters = array())
68 68
 	{
69 69
 		if (is_string($function))
70 70
 		{
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 	public function call($function)
89 89
 	{
90 90
 		$parameters = func_get_args();
91
-		array_shift($parameters);	// shift off $function
91
+		array_shift($parameters); // shift off $function
92 92
 
93 93
 		if (is_string($function))
94 94
 		{
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 	 * @param string $method name of the jquery to call
111 111
 	 * @param array $parameters =array()
112 112
 	 */
113
-	public function jquery($selector,$method,array $parameters=array())
113
+	public function jquery($selector, $method, array $parameters = array())
114 114
 	{
115 115
 		if (is_string($selector) && is_string($method))
116 116
 		{
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
 	 * @param string $app =null default current app from flags
170 170
 	 * or only the current application
171 171
 	 */
172
-	public function redirect($url, $global = false, $app=null)
172
+	public function redirect($url, $global = false, $app = null)
173 173
 	{
174 174
 		if (is_string($url) && is_bool($global))
175 175
 		{
Please login to merge, or discard this patch.
api/src/Ldap/ServerInfo.php 4 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 	/**
82 82
 	* gets the version
83 83
 	*
84
-	* @return integer the supported ldap version
84
+	* @return string the supported ldap version
85 85
 	*/
86 86
 	function getVersion()
87 87
 	{
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 	 * @param resource $ds
160 160
 	 * @param string $host
161 161
 	 * @param int $version 2 or 3
162
-	 * @return ldapserverinfo
162
+	 * @return ServerInfo
163 163
 	 */
164 164
 	public static function get($ds, $host, $version=3)
165 165
 	{
Please login to merge, or discard this patch.
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -32,33 +32,33 @@  discard block
 block discarded – undo
32 32
 	const SAMBA4 = 2;
33 33
 
34 34
 	/**
35
-	* @var array $namingContext holds the supported namingcontexts
36
-	*/
35
+	 * @var array $namingContext holds the supported namingcontexts
36
+	 */
37 37
 	var $namingContext = array();
38 38
 
39 39
 	/**
40
-	* @var string $version holds the LDAP server version
41
-	*/
40
+	 * @var string $version holds the LDAP server version
41
+	 */
42 42
 	var $version = 2;
43 43
 
44 44
 	/**
45
-	* @var integer $serverType holds the type of LDAP server(OpenLDAP, ADS, NDS, ...)
46
-	*/
45
+	 * @var integer $serverType holds the type of LDAP server(OpenLDAP, ADS, NDS, ...)
46
+	 */
47 47
 	var $serverType = 0;
48 48
 
49 49
 	/**
50
-	* @var string $_subSchemaEntry the subschema entry DN
51
-	*/
50
+	 * @var string $_subSchemaEntry the subschema entry DN
51
+	 */
52 52
 	var $subSchemaEntry = '';
53 53
 
54 54
 	/**
55
-	* @var array $supportedObjectClasses the supported objectclasses
56
-	*/
55
+	 * @var array $supportedObjectClasses the supported objectclasses
56
+	 */
57 57
 	var $supportedObjectClasses = array();
58 58
 
59 59
 	/**
60
-	* @var array $supportedOIDs the supported OIDs
61
-	*/
60
+	 * @var array $supportedOIDs the supported OIDs
61
+	 */
62 62
 	var $supportedOIDs = array();
63 63
 
64 64
 	/**
@@ -79,50 +79,50 @@  discard block
 block discarded – undo
79 79
 	}
80 80
 
81 81
 	/**
82
-	* gets the version
83
-	*
84
-	* @return integer the supported ldap version
85
-	*/
82
+	 * gets the version
83
+	 *
84
+	 * @return integer the supported ldap version
85
+	 */
86 86
 	function getVersion()
87 87
 	{
88 88
 		return $this->version;
89 89
 	}
90 90
 
91 91
 	/**
92
-	* sets the namingcontexts
93
-	*
94
-	* @param array $_namingContext the supported namingcontexts
95
-	*/
92
+	 * sets the namingcontexts
93
+	 *
94
+	 * @param array $_namingContext the supported namingcontexts
95
+	 */
96 96
 	function setNamingContexts($_namingContext)
97 97
 	{
98 98
 		$this->namingContext = $_namingContext;
99 99
 	}
100 100
 
101 101
 	/**
102
-	* sets the type of the ldap server(OpenLDAP, ADS, NDS, ...)
103
-	*
104
-	* @param integer $_serverType the type of ldap server
105
-	*/
102
+	 * sets the type of the ldap server(OpenLDAP, ADS, NDS, ...)
103
+	 *
104
+	 * @param integer $_serverType the type of ldap server
105
+	 */
106 106
 	function setServerType($_serverType)
107 107
 	{
108 108
 		$this->serverType = $_serverType;
109 109
 	}
110 110
 
111 111
 	/**
112
-	* sets the DN for the subschema entry
113
-	*
114
-	* @param string $_subSchemaEntry the subschema entry DN
115
-	*/
112
+	 * sets the DN for the subschema entry
113
+	 *
114
+	 * @param string $_subSchemaEntry the subschema entry DN
115
+	 */
116 116
 	function setSubSchemaEntry($_subSchemaEntry)
117 117
 	{
118 118
 		$this->subSchemaEntry = $_subSchemaEntry;
119 119
 	}
120 120
 
121 121
 	/**
122
-	* sets the supported objectclasses
123
-	*
124
-	* @param array $_supportedObjectClasses the supported objectclasses
125
-	*/
122
+	 * sets the supported objectclasses
123
+	 *
124
+	 * @param array $_supportedObjectClasses the supported objectclasses
125
+	 */
126 126
 	function setSupportedObjectClasses($_supportedObjectClasses)
127 127
 	{
128 128
 		$this->supportedOIDs = $_supportedObjectClasses;
@@ -130,20 +130,20 @@  discard block
 block discarded – undo
130 130
 	}
131 131
 
132 132
 	/**
133
-	* sets the version
134
-	*
135
-	* @param integer $_version the supported ldap version
136
-	*/
133
+	 * sets the version
134
+	 *
135
+	 * @param integer $_version the supported ldap version
136
+	 */
137 137
 	function setVersion($_version)
138 138
 	{
139 139
 		$this->version = $_version;
140 140
 	}
141 141
 
142 142
 	/**
143
-	* checks for supported objectclasses
144
-	*
145
-	* @return bool returns true if the ldap server supports this objectclass
146
-	*/
143
+	 * checks for supported objectclasses
144
+	 *
145
+	 * @return bool returns true if the ldap server supports this objectclass
146
+	 */
147 147
 	function supportsObjectClass($_objectClass)
148 148
 	{
149 149
 		if($this->supportedObjectClasses[strtolower($_objectClass)])
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
 	*/
147 147
 	function supportsObjectClass($_objectClass)
148 148
 	{
149
-		if($this->supportedObjectClasses[strtolower($_objectClass)])
149
+		if ($this->supportedObjectClasses[strtolower($_objectClass)])
150 150
 		{
151 151
 			return true;
152 152
 		}
@@ -161,21 +161,21 @@  discard block
 block discarded – undo
161 161
 	 * @param int $version 2 or 3
162 162
 	 * @return ldapserverinfo
163 163
 	 */
164
-	public static function get($ds, $host, $version=3)
164
+	public static function get($ds, $host, $version = 3)
165 165
 	{
166
-		$filter='(objectclass=*)';
167
-		$justthese = array('structuralObjectClass','namingContexts','supportedLDAPVersion','subschemaSubentry','vendorname');
168
-		if(($sr = @ldap_read($ds, '', $filter, $justthese)))
166
+		$filter = '(objectclass=*)';
167
+		$justthese = array('structuralObjectClass', 'namingContexts', 'supportedLDAPVersion', 'subschemaSubentry', 'vendorname');
168
+		if (($sr = @ldap_read($ds, '', $filter, $justthese)))
169 169
 		{
170
-			if(($info = ldap_get_entries($ds, $sr)))
170
+			if (($info = ldap_get_entries($ds, $sr)))
171 171
 			{
172 172
 				$ldapServerInfo = new ServerInfo($host);
173 173
 				$ldapServerInfo->setVersion($version);
174 174
 
175 175
 				// check for naming contexts
176
-				if($info[0]['namingcontexts'])
176
+				if ($info[0]['namingcontexts'])
177 177
 				{
178
-					for($i=0; $i<$info[0]['namingcontexts']['count']; $i++)
178
+					for ($i = 0; $i < $info[0]['namingcontexts']['count']; $i++)
179 179
 					{
180 180
 						$namingcontexts[] = $info[0]['namingcontexts'][$i];
181 181
 					}
@@ -183,9 +183,9 @@  discard block
 block discarded – undo
183 183
 				}
184 184
 
185 185
 				// check for ldap server type
186
-				if($info[0]['structuralobjectclass'])
186
+				if ($info[0]['structuralobjectclass'])
187 187
 				{
188
-					switch($info[0]['structuralobjectclass'][0])
188
+					switch ($info[0]['structuralobjectclass'][0])
189 189
 					{
190 190
 						case 'OpenLDAProotDSE':
191 191
 							$ldapServerType = OPENLDAP_LDAPSERVER;
@@ -202,30 +202,30 @@  discard block
 block discarded – undo
202 202
 				}
203 203
 
204 204
 				// check for subschema entry dn
205
-				if($info[0]['subschemasubentry'])
205
+				if ($info[0]['subschemasubentry'])
206 206
 				{
207 207
 					$subschemasubentry = $info[0]['subschemasubentry'][0];
208 208
 					$ldapServerInfo->setSubSchemaEntry($subschemasubentry);
209 209
 				}
210 210
 
211 211
 				// create list of supported objetclasses
212
-				if(!empty($subschemasubentry))
212
+				if (!empty($subschemasubentry))
213 213
 				{
214
-					$filter='(objectclass=*)';
214
+					$filter = '(objectclass=*)';
215 215
 					$justthese = array('objectClasses');
216 216
 
217
-					if(($sr = ldap_read($ds, $subschemasubentry, $filter, $justthese)))
217
+					if (($sr = ldap_read($ds, $subschemasubentry, $filter, $justthese)))
218 218
 					{
219
-						if(($info = ldap_get_entries($ds, $sr)))
219
+						if (($info = ldap_get_entries($ds, $sr)))
220 220
 						{
221
-							if($info[0]['objectclasses']) {
222
-								for($i=0; $i<$info[0]['objectclasses']['count']; $i++)
221
+							if ($info[0]['objectclasses']) {
222
+								for ($i = 0; $i < $info[0]['objectclasses']['count']; $i++)
223 223
 								{
224 224
 									$matches = null;
225
-									if(preg_match('/^\( (.*) NAME \'(\w*)\' /', $info[0]['objectclasses'][$i], $matches))
225
+									if (preg_match('/^\( (.*) NAME \'(\w*)\' /', $info[0]['objectclasses'][$i], $matches))
226 226
 									{
227 227
 										#_debug_array($matches);
228
-										if(count($matches) == 3)
228
+										if (count($matches) == 3)
229 229
 										{
230 230
 											$supportedObjectClasses[$matches[1]] = strtolower($matches[2]);
231 231
 										}
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -218,7 +218,8 @@
 block discarded – undo
218 218
 					{
219 219
 						if(($info = ldap_get_entries($ds, $sr)))
220 220
 						{
221
-							if($info[0]['objectclasses']) {
221
+							if($info[0]['objectclasses'])
222
+							{
222 223
 								for($i=0; $i<$info[0]['objectclasses']['count']; $i++)
223 224
 								{
224 225
 									$matches = null;
Please login to merge, or discard this patch.
api/src/Link/Storage.php 5 patches
Doc Comments   +6 added lines, -1 removed lines patch added patch discarded remove patch
@@ -176,6 +176,11 @@  discard block
 block discarded – undo
176 176
 		return is_array($id) ? $links : ($links[$id] ? $links[$id] : array());
177 177
 	}
178 178
 
179
+	/**
180
+	 * @param boolean $left
181
+	 * @param string $only_app
182
+	 * @param boolean $not_only
183
+	 */
179 184
 	private static function _add2links($row,$left,$only_app,$not_only,array &$links)
180 185
 	{
181 186
 		$linked_app = $left ? $row['link_app2'] : $row['link_app1'];
@@ -206,7 +211,7 @@  discard block
 block discarded – undo
206 211
 	 * @param string $id ='' id in $app, if no integer link_id given in $app_link_id
207 212
 	 * @param string $app2 ='' appname of 2. endpoint of the link, if no integer link_id given in $app_link_id
208 213
 	 * @param string $id2 ='' id in $app2, if no integer link_id given in $app_link_id
209
-	 * @return array with link-data or False
214
+	 * @return string with link-data or False
210 215
 	 */
211 216
 	static function get_link($app_link_id,$id='',$app2='',$id2='')
212 217
 	{
Please login to merge, or discard this patch.
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 			echo "<p>solink.link('$app1',$id1,'$app2',$id2,'$remark',$owner)</p>\n";
67 67
 		}
68 68
 		if ($app1 == $app2 && $id1 == $id2 ||
69
-		    $id1 == '' || $id2 == '' || $app1 == '' || $app2 == '')
69
+			$id1 == '' || $id2 == '' || $app1 == '' || $app2 == '')
70 70
 		{
71 71
 			return False;	// dont link to self or other nosense
72 72
 		}
@@ -412,26 +412,26 @@  discard block
 block discarded – undo
412 412
 			array('table'=>self::TABLE,
413 413
 				'cols'=>'c.*,b.link_app1 AS app3,b.link_id1 AS id3,b.link_id AS link3',
414 414
 				'where'=>'a.link_app1='.self::$db->quote($app).' AND c.link_app2='.self::$db->quote($target_app).
415
-                        		(!$target_id ? '' : self::$db->expression(self::TABLE,' AND c.',array('link_id2' => $target_id))),
416
-                        	'join'=>" a
415
+								(!$target_id ? '' : self::$db->expression(self::TABLE,' AND c.',array('link_id2' => $target_id))),
416
+							'join'=>" a
417 417
                         		JOIN $table b ON a.link_id2=b.link_id1 AND a.link_app2=b.link_app1
418 418
                        			JOIN $table c ON a.link_id1=c.link_id1 AND a.link_app1=c.link_app1 AND a.link_id!=c.link_id AND c.link_app2=b.link_app2 AND c.link_id2=b.link_id2",
419 419
 			),
420 420
 			// retrieve the type of links, where the relation is realized as timesheet->infolog/tracker and projectmanager->timesheet
421 421
 			array('table'=>self::TABLE,
422 422
 				'cols'=>'b.link_id, b.link_app2 as app1, b.link_id2 as id1, b.link_app1 as app2, b.link_id1 as id2, b.link_remark,b.link_lastmod,b.link_owner,b.deleted,c.link_app1 AS app3,c.link_id1 AS id3,c.link_id AS link3',
423
-                       		'where'=>'a.link_app1='.self::$db->quote($app).' AND b.link_app1='.self::$db->quote($target_app).
424
-                        		(!$target_id ? '' : self::$db->expression(self::TABLE,' AND b.',array('link_id1' => $target_id))),
425
-                        	'join'=>" a
423
+					   		'where'=>'a.link_app1='.self::$db->quote($app).' AND b.link_app1='.self::$db->quote($target_app).
424
+								(!$target_id ? '' : self::$db->expression(self::TABLE,' AND b.',array('link_id1' => $target_id))),
425
+							'join'=>" a
426 426
                         		JOIN $table b ON a.link_id1=b.link_id2 AND a.link_app1=b.link_app2
427 427
                         		JOIN $table c ON a.link_id2=c.link_id1 AND a.link_app2=c.link_app1 AND a.link_id!=c.link_id AND c.link_app2=b.link_app1 AND c.link_id2=b.link_id1",
428 428
 			),
429 429
 			// retrieve the type of links, where the relation is realized as timesheet->projectmanager and infolog->timesheet
430 430
 			array('table'=>self::TABLE,
431 431
 				'cols'=>'a.*,c.link_app1 AS app3,c.link_id1 AS id3,c.link_id AS link3',
432
-                     		'where'=>'a.link_app1='.self::$db->quote($app).' AND a.link_app2='.self::$db->quote($target_app).
433
-                        		(!$target_id ? '' : self::$db->expression(self::TABLE,' AND a.',array('link_id2' => $target_id))),
434
-                       		'join'=>" a
432
+					 		'where'=>'a.link_app1='.self::$db->quote($app).' AND a.link_app2='.self::$db->quote($target_app).
433
+								(!$target_id ? '' : self::$db->expression(self::TABLE,' AND a.',array('link_id2' => $target_id))),
434
+					   		'join'=>" a
435 435
                        			JOIN $table b ON a.link_id1=b.link_id2 AND a.link_app1=b.link_app2
436 436
                         		JOIN $table c ON a.link_id2=c.link_id2 AND a.link_app2=c.link_app2 AND a.link_id!=c.link_id AND c.link_app1=b.link_app1 AND c.link_id1=b.link_id1",
437 437
 			),
Please login to merge, or discard this patch.
Spacing   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 	 * @param int $lastmod =0 timestamp of last modification (defaults to now=time())
60 60
 	 * @return int/boolean False (for db or param-error) or on success link_id (Please not the return-value of $id1)
61 61
 	 */
62
-	static function link( $app1,&$id1,$app2,$id2='',$remark='',$owner=0,$lastmod=0 )
62
+	static function link($app1, &$id1, $app2, $id2 = '', $remark = '', $owner = 0, $lastmod = 0)
63 63
 	{
64 64
 		if (self::DEBUG)
65 65
 		{
@@ -68,21 +68,21 @@  discard block
 block discarded – undo
68 68
 		if ($app1 == $app2 && $id1 == $id2 ||
69 69
 		    $id1 == '' || $id2 == '' || $app1 == '' || $app2 == '')
70 70
 		{
71
-			return False;	// dont link to self or other nosense
71
+			return False; // dont link to self or other nosense
72 72
 		}
73
-		if (($link = self::get_link($app1,$id1,$app2,$id2)))
73
+		if (($link = self::get_link($app1, $id1, $app2, $id2)))
74 74
 		{
75 75
 			if ($link['link_remark'] != $remark)
76 76
 			{
77
-				self::update_remark($link['link_id'],$remark);
77
+				self::update_remark($link['link_id'], $remark);
78 78
 			}
79
-			return $link['link_id'];	// link alread exist
79
+			return $link['link_id']; // link alread exist
80 80
 		}
81 81
 		if (!$owner)
82 82
 		{
83 83
 			$owner = $GLOBALS['egw_info']['user']['account_id'];
84 84
 		}
85
-		return self::$db->insert(self::TABLE,array(
85
+		return self::$db->insert(self::TABLE, array(
86 86
 				'link_app1'		=> $app1,
87 87
 				'link_id1'		=> $id1,
88 88
 				'link_app2'		=> $app2,
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 				'link_remark'	=> $remark,
91 91
 				'link_lastmod'	=> $lastmod ? $lastmod : time(),
92 92
 				'link_owner'	=> $owner,
93
-			),False,__LINE__,__FILE__) ? self::$db->get_last_insert_id(self::TABLE,'link_id') : false;
93
+			), False, __LINE__, __FILE__) ? self::$db->get_last_insert_id(self::TABLE, 'link_id') : false;
94 94
 	}
95 95
 
96 96
 	/**
@@ -100,14 +100,14 @@  discard block
 block discarded – undo
100 100
 	 * @param string $remark new text for the remark
101 101
 	 * @return boolean true on success, else false
102 102
 	 */
103
-	static function update_remark($link_id,$remark)
103
+	static function update_remark($link_id, $remark)
104 104
 	{
105
-		return self::$db->update(self::TABLE,array(
105
+		return self::$db->update(self::TABLE, array(
106 106
 				'link_remark'	=> $remark,
107 107
 				'link_lastmod'	=> time(),
108
-			),array(
108
+			), array(
109 109
 				'link_id'	=> $link_id,
110
-			),__LINE__,__FILE__);
110
+			), __LINE__, __FILE__);
111 111
 	}
112 112
 
113 113
 	/**
@@ -121,15 +121,15 @@  discard block
 block discarded – undo
121 121
 	 * @param int|array $limit =null number of entries to return, default null = all or array(offset, num_rows) to return num_rows starting from offset
122 122
 	 * @return array id => links pairs if $id is an array or just the links (only_app: ids) or empty array if no matching links found
123 123
 	 */
124
-	static function get_links($app, $id, $only_app='', $order='link_lastmod DESC', $deleted=false, $limit=null)
124
+	static function get_links($app, $id, $only_app = '', $order = 'link_lastmod DESC', $deleted = false, $limit = null)
125 125
 	{
126 126
 		if (self::DEBUG)
127 127
 		{
128
-			echo "<p>solink.get_links($app,".print_r($id,true).",$only_app,$order,$deleted)</p>\n";
128
+			echo "<p>solink.get_links($app,".print_r($id, true).",$only_app,$order,$deleted)</p>\n";
129 129
 		}
130 130
 		if (($not_only = $only_app[0] == '!'))
131 131
 		{
132
-			$only_app = substr($only_app,1);
132
+			$only_app = substr($only_app, 1);
133 133
 		}
134 134
 
135 135
 		$offset = false;
@@ -137,32 +137,32 @@  discard block
 block discarded – undo
137 137
 		{
138 138
 			list($offset, $limit) = $limit;
139 139
 		}
140
-		elseif($limit)
140
+		elseif ($limit)
141 141
 		{
142 142
 			$offset = 0;
143 143
 		}
144 144
 
145 145
 		$links = array();
146 146
 		try {
147
-			foreach(self::$db->select(self::TABLE, '*', self::$db->expression(self::TABLE, '((', array(
147
+			foreach (self::$db->select(self::TABLE, '*', self::$db->expression(self::TABLE, '((', array(
148 148
 						'link_app1'	=> $app,
149 149
 						'link_id1'	=> $id,
150
-					),') OR (',array(
150
+					), ') OR (', array(
151 151
 						'link_app2'	=> $app,
152 152
 						'link_id2'	=> $id,
153
-					),'))',
153
+					), '))',
154 154
 					$deleted ? '' : ' AND deleted IS NULL'
155 155
 				), __LINE__, __FILE__, $offset, $order ? " ORDER BY $order" : '', 'phpgwapi', $limit) as $row)
156 156
 			{
157 157
 				// check if left side (1) is one of our targets --> add it
158
-				if ($row['link_app1'] == $app && in_array($row['link_id1'],(array)$id))
158
+				if ($row['link_app1'] == $app && in_array($row['link_id1'], (array)$id))
159 159
 				{
160
-					self::_add2links($row,true,$only_app,$not_only,$links);
160
+					self::_add2links($row, true, $only_app, $not_only, $links);
161 161
 				}
162 162
 				// check if right side (2) is one of our targets --> add it (both can be true for multiple targets!)
163
-				if ($row['link_app2'] == $app && in_array($row['link_id2'],(array)$id))
163
+				if ($row['link_app2'] == $app && in_array($row['link_id2'], (array)$id))
164 164
 				{
165
-					self::_add2links($row,false,$only_app,$not_only,$links);
165
+					self::_add2links($row, false, $only_app, $not_only, $links);
166 166
 				}
167 167
 			}
168 168
 			// if query returns exactly limit rows, we assume there are more and therefore set self::$limit_exceeded
@@ -170,18 +170,18 @@  discard block
 block discarded – undo
170 170
 		}
171 171
 		// catch Illegal mix of collations (ascii_general_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '=' (1267)
172 172
 		// caused by non-ascii chars compared with ascii field uid
173
-		catch(Api\Db\Exception $e) {
173
+		catch (Api\Db\Exception $e) {
174 174
 			_egw_log_exception($e);
175 175
 		}
176 176
 		return is_array($id) ? $links : ($links[$id] ? $links[$id] : array());
177 177
 	}
178 178
 
179
-	private static function _add2links($row,$left,$only_app,$not_only,array &$links)
179
+	private static function _add2links($row, $left, $only_app, $not_only, array &$links)
180 180
 	{
181 181
 		$linked_app = $left ? $row['link_app2'] : $row['link_app1'];
182 182
 		$linked_id  = $left ? $row['link_id2'] : $row['link_id1'];
183 183
 		$app_id = $left ? $row['link_id1'] : $row['link_id2'];
184
-		list($app) = explode('-',$linked_app);
184
+		list($app) = explode('-', $linked_app);
185 185
 		if ($only_app && $not_only == ($linked_app == $only_app) || !$GLOBALS['egw_info']['user']['apps'][$app])
186 186
 		{
187 187
 			#echo "$linked_app == $only_app, ";var_dump($linked_app == $only_app);echo "	->dont return a link<br>";
@@ -208,13 +208,13 @@  discard block
 block discarded – undo
208 208
 	 * @param string $id2 ='' id in $app2, if no integer link_id given in $app_link_id
209 209
 	 * @return array with link-data or False
210 210
 	 */
211
-	static function get_link($app_link_id,$id='',$app2='',$id2='')
211
+	static function get_link($app_link_id, $id = '', $app2 = '', $id2 = '')
212 212
 	{
213 213
 		if (self::DEBUG)
214 214
 		{
215 215
 			echo "<p>solink.get_link('$app_link_id',$id,'$app2','$id2')</p>\n";
216 216
 		}
217
-		if ((int) $app_link_id > 0)
217
+		if ((int)$app_link_id > 0)
218 218
 		{
219 219
 			$where = array('link_id' => $app_link_id);
220 220
 		}
@@ -224,24 +224,24 @@  discard block
 block discarded – undo
224 224
 			{
225 225
 				return False;
226 226
 			}
227
-			$where = self::$db->expression(self::TABLE,'(',array(
227
+			$where = self::$db->expression(self::TABLE, '(', array(
228 228
 					'link_app1'	=> $app_link_id,
229 229
 					'link_id1'	=> $id,
230 230
 					'link_app2'	=> $app2,
231 231
 					'link_id2'	=> $id2,
232
-				),') OR (',array(
232
+				), ') OR (', array(
233 233
 					'link_app2'	=> $app_link_id,
234 234
 					'link_id2'	=> $id,
235 235
 					'link_app1'	=> $app2,
236 236
 					'link_id1'	=> $id2,
237
-				),')');
237
+				), ')');
238 238
 		}
239 239
 		try {
240
-			return self::$db->select(self::TABLE,'*',$where,__LINE__,__FILE__)->fetch(ADODB_FETCH_ASSOC);
240
+			return self::$db->select(self::TABLE, '*', $where, __LINE__, __FILE__)->fetch(ADODB_FETCH_ASSOC);
241 241
 		}
242 242
 		// catch Illegal mix of collations (ascii_general_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '=' (1267)
243 243
 		// caused by non-ascii chars compared with ascii field uid
244
-		catch(Api\Db\Exception $e) {
244
+		catch (Api\Db\Exception $e) {
245 245
 			_egw_log_exception($e);
246 246
 		}
247 247
 		return false;
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
 	 * @param boolean $hold_for_purge Don't really delete the link, just mark it as deleted and wait for final delete of linked entry
260 260
 	 * @return array with deleted links
261 261
 	 */
262
-	static function unlink($link_id,$app='',$id='',$owner=0,$app2='',$id2='',$hold_for_purge=false)
262
+	static function unlink($link_id, $app = '', $id = '', $owner = 0, $app2 = '', $id2 = '', $hold_for_purge = false)
263 263
 	{
264 264
 		if (self::DEBUG)
265 265
 		{
@@ -284,21 +284,21 @@  discard block
 block discarded – undo
284 284
 					$check1['link_id1'] = $id;
285 285
 					$check2['link_id2'] = $id;
286 286
 				}
287
-				$where = self::$db->expression(self::TABLE,'((',$check1,') OR (',$check2,'))');
287
+				$where = self::$db->expression(self::TABLE, '((', $check1, ') OR (', $check2, '))');
288 288
 			}
289 289
 			elseif ($app != '' && $app2 != '')
290 290
 			{
291
-				$where = self::$db->expression(self::TABLE,'(',array(
291
+				$where = self::$db->expression(self::TABLE, '(', array(
292 292
 						'link_app1'	=> $app,
293 293
 						'link_id1'	=> $id,
294 294
 						'link_app2'	=> $app2,
295 295
 						'link_id2'	=> $id2,
296
-					),') OR (',array(
296
+					), ') OR (', array(
297 297
 						'link_app1'	=> $app2,
298 298
 						'link_id1'	=> $id2,
299 299
 						'link_app2'	=> $app,
300 300
 						'link_id2'	=> $id,
301
-					),')');
301
+					), ')');
302 302
 			}
303 303
 			if ($owner)
304 304
 			{
@@ -308,25 +308,25 @@  discard block
 block discarded – undo
308 308
 		}
309 309
 		$deleted = array();
310 310
 		try {
311
-			foreach(self::$db->select(self::TABLE,'*',$where,__LINE__,__FILE__) as $row)
311
+			foreach (self::$db->select(self::TABLE, '*', $where, __LINE__, __FILE__) as $row)
312 312
 			{
313 313
 				$deleted[] = $row;
314 314
 			}
315
-			if($hold_for_purge)
315
+			if ($hold_for_purge)
316 316
 			{
317
-				self::$db->update(self::TABLE,array(
317
+				self::$db->update(self::TABLE, array(
318 318
 					'deleted' => time(),
319 319
 					'link_lastmod' => time(),
320
-				), $where, __LINE__,__FILE__);
320
+				), $where, __LINE__, __FILE__);
321 321
 			}
322 322
 			else
323 323
 			{
324
-				self::$db->delete(self::TABLE,$where,__LINE__,__FILE__);
324
+				self::$db->delete(self::TABLE, $where, __LINE__, __FILE__);
325 325
 			}
326 326
 		}
327 327
 		// catch Illegal mix of collations (ascii_general_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '=' (1267)
328 328
 		// caused by non-ascii chars compared with ascii field uid
329
-		catch(Api\Db\Exception $e) {
329
+		catch (Api\Db\Exception $e) {
330 330
 			_egw_log_exception($e);
331 331
 		}
332 332
 
@@ -357,8 +357,8 @@  discard block
 block discarded – undo
357 357
 			$check1['link_id1'] = $id;
358 358
 			$check2['link_id2'] = $id;
359 359
 		}
360
-		$where = self::$db->expression(self::TABLE,'((',$check1,') OR (',$check2,'))');
361
-		self::$db->update(self::TABLE,array('deleted'=> null), $where, __LINE__,__FILE__);
360
+		$where = self::$db->expression(self::TABLE, '((', $check1, ') OR (', $check2, '))');
361
+		self::$db->update(self::TABLE, array('deleted'=> null), $where, __LINE__, __FILE__);
362 362
 	}
363 363
 
364 364
 	/**
@@ -371,13 +371,13 @@  discard block
 block discarded – undo
371 371
 	 * @param int $new_owner account_id of new owner
372 372
 	 * @return int number of links changed
373 373
 	 */
374
-	static function chown($owner,$new_owner)
374
+	static function chown($owner, $new_owner)
375 375
 	{
376
-		if ((int)$owner <= 0 || (int) $new_owner <= 0)
376
+		if ((int)$owner <= 0 || (int)$new_owner <= 0)
377 377
 		{
378 378
 			return 0;
379 379
 		}
380
-		self::$db->update(self::TABLE,array('owner'=>$new_owner),array('owner'=>$owner),__LINE__,__FILE__);
380
+		self::$db->update(self::TABLE, array('owner'=>$new_owner), array('owner'=>$owner), __LINE__, __FILE__);
381 381
 
382 382
 		return self::$db->affected_rows();
383 383
 	}
@@ -404,15 +404,15 @@  discard block
 block discarded – undo
404 404
 	 * @param int|array $limit =null number of entries to return, default null = all or array(offset, num_rows) to return num_rows starting from offset
405 405
 	 * @return array with links from entries from $app to $target_app/$target_id plus the other (b) link_id/app/id in the keys 'link3'/'app3'/'id3'
406 406
 	 */
407
-	static function get_3links($app, $target_app, $target_id=null, $just_app_ids=false, $order='link_lastmod DESC', $limit=null)
407
+	static function get_3links($app, $target_app, $target_id = null, $just_app_ids = false, $order = 'link_lastmod DESC', $limit = null)
408 408
 	{
409 409
 		$table = self::TABLE;
410
-		$arrayofselects=array(
410
+		$arrayofselects = array(
411 411
 			// retrieve the type of links, where the relation is realized as timesheet->infolog/tracker via infolog->projectmanager to timesheet->projectmanager
412 412
 			array('table'=>self::TABLE,
413 413
 				'cols'=>'c.*,b.link_app1 AS app3,b.link_id1 AS id3,b.link_id AS link3',
414 414
 				'where'=>'a.link_app1='.self::$db->quote($app).' AND c.link_app2='.self::$db->quote($target_app).
415
-                        		(!$target_id ? '' : self::$db->expression(self::TABLE,' AND c.',array('link_id2' => $target_id))),
415
+                        		(!$target_id ? '' : self::$db->expression(self::TABLE, ' AND c.', array('link_id2' => $target_id))),
416 416
                         	'join'=>" a
417 417
                         		JOIN $table b ON a.link_id2=b.link_id1 AND a.link_app2=b.link_app1
418 418
                        			JOIN $table c ON a.link_id1=c.link_id1 AND a.link_app1=c.link_app1 AND a.link_id!=c.link_id AND c.link_app2=b.link_app2 AND c.link_id2=b.link_id2",
@@ -421,7 +421,7 @@  discard block
 block discarded – undo
421 421
 			array('table'=>self::TABLE,
422 422
 				'cols'=>'b.link_id, b.link_app2 as app1, b.link_id2 as id1, b.link_app1 as app2, b.link_id1 as id2, b.link_remark,b.link_lastmod,b.link_owner,b.deleted,c.link_app1 AS app3,c.link_id1 AS id3,c.link_id AS link3',
423 423
                        		'where'=>'a.link_app1='.self::$db->quote($app).' AND b.link_app1='.self::$db->quote($target_app).
424
-                        		(!$target_id ? '' : self::$db->expression(self::TABLE,' AND b.',array('link_id1' => $target_id))),
424
+                        		(!$target_id ? '' : self::$db->expression(self::TABLE, ' AND b.', array('link_id1' => $target_id))),
425 425
                         	'join'=>" a
426 426
                         		JOIN $table b ON a.link_id1=b.link_id2 AND a.link_app1=b.link_app2
427 427
                         		JOIN $table c ON a.link_id2=c.link_id1 AND a.link_app2=c.link_app1 AND a.link_id!=c.link_id AND c.link_app2=b.link_app1 AND c.link_id2=b.link_id1",
@@ -430,7 +430,7 @@  discard block
 block discarded – undo
430 430
 			array('table'=>self::TABLE,
431 431
 				'cols'=>'a.*,c.link_app1 AS app3,c.link_id1 AS id3,c.link_id AS link3',
432 432
                      		'where'=>'a.link_app1='.self::$db->quote($app).' AND a.link_app2='.self::$db->quote($target_app).
433
-                        		(!$target_id ? '' : self::$db->expression(self::TABLE,' AND a.',array('link_id2' => $target_id))),
433
+                        		(!$target_id ? '' : self::$db->expression(self::TABLE, ' AND a.', array('link_id2' => $target_id))),
434 434
                        		'join'=>" a
435 435
                        			JOIN $table b ON a.link_id1=b.link_id2 AND a.link_app1=b.link_app2
436 436
                         		JOIN $table c ON a.link_id2=c.link_id2 AND a.link_app2=c.link_app2 AND a.link_id!=c.link_id AND c.link_app1=b.link_app1 AND c.link_id1=b.link_id1",
@@ -442,17 +442,17 @@  discard block
 block discarded – undo
442 442
 		{
443 443
 			list($offset, $limit) = $limit;
444 444
 		}
445
-		elseif($limit)
445
+		elseif ($limit)
446 446
 		{
447 447
 			$offset = 0;
448 448
 		}
449 449
 
450 450
 		$links = array();
451
-		foreach(self::$db->union($arrayofselects, __LINE__, __FILE__, $order, $offset, $limit) as $row)
451
+		foreach (self::$db->union($arrayofselects, __LINE__, __FILE__, $order, $offset, $limit) as $row)
452 452
 		{
453 453
 			if ($just_app_ids)
454 454
 			{
455
-				if ($row['link_app1'] == $target_app && (is_null($target_id) || in_array($row['link_id1'],(array)$target_id)))
455
+				if ($row['link_app1'] == $target_app && (is_null($target_id) || in_array($row['link_id1'], (array)$target_id)))
456 456
 				{
457 457
 					$links[$row['link_id']] = $row['link_id2'];
458 458
 				}
@@ -463,7 +463,7 @@  discard block
 block discarded – undo
463 463
 			}
464 464
 			else
465 465
 			{
466
-				$links[] = Api\Db::strip_array_keys($row,'link_');
466
+				$links[] = Api\Db::strip_array_keys($row, 'link_');
467 467
 			}
468 468
 		}
469 469
 		// if query returns exactly limit rows, we assume there are more and therefore set self::$limit_exceeded
@@ -477,7 +477,7 @@  discard block
 block discarded – undo
477 477
 	 */
478 478
 	static function init_static( )
479 479
 	{
480
-		self::$db     = $GLOBALS['egw']->db;
480
+		self::$db = $GLOBALS['egw']->db;
481 481
 	}
482 482
 }
483 483
 Storage::init_static();
Please login to merge, or discard this patch.
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -302,7 +302,10 @@
 block discarded – undo
302 302
 			}
303 303
 			if ($owner)
304 304
 			{
305
-				if ($app) $where = array($where);
305
+				if ($app)
306
+				{
307
+					$where = array($where);
308
+				}
306 309
 				$where['link_owner'] = $owner;
307 310
 			}
308 311
 		}
Please login to merge, or discard this patch.
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -269,7 +269,7 @@
 block discarded – undo
269 269
 		{
270 270
 			$where = array('link_id' => $link_id);
271 271
 		}
272
-		elseif ($app == '' AND $owner == '')
272
+		elseif ($app == '' and $owner == '')
273 273
 		{
274 274
 			return 0;
275 275
 		}
Please login to merge, or discard this patch.
api/src/Mail/Account.php 3 patches
Doc Comments   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -486,7 +486,7 @@  discard block
 block discarded – undo
486 486
 	 * @param boolean $replace_placeholders =false should placeholders like {{n_fn}} be replaced
487 487
 	 * @param string $field ='name' what to return as value: "ident_(realname|org|email|signature)" or default "name"=result from identity_name
488 488
 	 * @param int $user =null account_id to use if not current user
489
-	 * @return Iterator ident_id => identity_name of identity
489
+	 * @return Api\Db\CallbackIterator ident_id => identity_name of identity
490 490
 	 */
491 491
 	public static function identities($account, $replace_placeholders=true, $field='name', $user=null)
492 492
 	{
@@ -795,7 +795,7 @@  discard block
 block discarded – undo
795 795
 	 *
796 796
 	 * To get $this->params you need to call getUserData before! It is never automatically loaded.
797 797
 	 *
798
-	 * @param type $name
798
+	 * @param string $name
799 799
 	 * @return mixed
800 800
 	 */
801 801
 	public function __get($name)
@@ -819,8 +819,8 @@  discard block
 block discarded – undo
819 819
 	/**
820 820
 	 * Give read access to protected parameters in $this->params
821 821
 	 *
822
-	 * @param type $name
823
-	 * @return mixed
822
+	 * @param string $name
823
+	 * @return boolean
824 824
 	 */
825 825
 	public function __isset($name)
826 826
 	{
@@ -1340,10 +1340,10 @@  discard block
 block discarded – undo
1340 1340
 	 * @param boolean|string $just_name =true true: return self::identity_name, false: return Account objects,
1341 1341
 	 *	string with attribute-name: return that attribute, eg. acc_imap_host or 'params' to return all attributes as array
1342 1342
 	 * @param string $order_by ='acc_name ASC'
1343
-	 * @param int|boolean $offset =false offset or false to return all
1343
+	 * @param boolean $offset =false offset or false to return all
1344 1344
 	 * @param int $num_rows =0 number of rows to return, 0=default from prefs (if $offset !== false)
1345 1345
 	 * @param boolean $replace_placeholders =true should placeholders like {{n_fn}} be replaced
1346
-	 * @return Iterator with acc_id => acc_name or Account objects
1346
+	 * @return Api\Db\CallbackIterator with acc_id => acc_name or Account objects
1347 1347
 	 */
1348 1348
 	public static function search($only_current_user=true, $just_name=true, $order_by=null, $offset=false, $num_rows=0, $replace_placeholders=true)
1349 1349
 	{
Please login to merge, or discard this patch.
Braces   +95 added lines, -24 removed lines patch added patch discarded remove patch
@@ -360,8 +360,14 @@  discard block
 block discarded – undo
360 360
 		{
361 361
 			// make sure mbstring.func_overload=0
362 362
 			static $func_overload = null;
363
-			if (is_null($func_overload)) $func_overload = extension_loaded('mbstring') ? ini_get('mbstring.func_overload') : 0;
364
-			if ($func_overload) throw new Api\Exception\AssertionFailed('Fatal Error: EGroupware requires mbstring.func_overload=0 set in your php.ini!');
363
+			if (is_null($func_overload))
364
+			{
365
+				$func_overload = extension_loaded('mbstring') ? ini_get('mbstring.func_overload') : 0;
366
+			}
367
+			if ($func_overload)
368
+			{
369
+				throw new Api\Exception\AssertionFailed('Fatal Error: EGroupware requires mbstring.func_overload=0 set in your php.ini!');
370
+			}
365 371
 
366 372
 			$class = $this->params['acc_imap_type'];
367 373
 			$this->imapServer = new $class($this->params, $_adminConnection, $_timeout);
@@ -490,7 +496,10 @@  discard block
 block discarded – undo
490 496
 	 */
491 497
 	public static function identities($account, $replace_placeholders=true, $field='name', $user=null)
492 498
 	{
493
-		if (!isset($user)) $user = $GLOBALS['egw_info']['user']['account_id'];
499
+		if (!isset($user))
500
+		{
501
+			$user = $GLOBALS['egw_info']['user']['account_id'];
502
+		}
494 503
 		$acc_id = is_scalar($account) ? $account : $account['acc_id'];
495 504
 
496 505
 		$cols = array('ident_id', 'ident_name', 'ident_realname', 'ident_org', 'ident_email', 'ident_signature', 'acc_id', 'acc_imap_username', 'acc_imap_logintype', 'acc_domain');
@@ -528,8 +537,14 @@  discard block
 block discarded – undo
528 537
 				// fill an empty ident_realname or ident_email of current user with data from user account
529 538
 				if ($replace_placeholders && (!isset($user) || $user == $GLOBALS['egw_info']['user']['acount_id']))
530 539
 				{
531
-					if (empty($row['ident_realname'])) $row['ident_realname'] = $GLOBALS['egw_info']['user']['account_fullname'];
532
-					if (empty($row['ident_email'])) $row['ident_email'] = $GLOBALS['egw_info']['user']['account_email'];
540
+					if (empty($row['ident_realname']))
541
+					{
542
+						$row['ident_realname'] = $GLOBALS['egw_info']['user']['account_fullname'];
543
+					}
544
+					if (empty($row['ident_email']))
545
+					{
546
+						$row['ident_email'] = $GLOBALS['egw_info']['user']['account_email'];
547
+					}
533 548
 				}
534 549
 				if ($field != 'name')
535 550
 				{
@@ -538,7 +553,9 @@  discard block
 block discarded – undo
538 553
 				}
539 554
 				return self::identity_name($row, $replace_placeholders);
540 555
 			}, array(),
541
-			function($row) { return $row['ident_id'];});
556
+			function($row)
557
+			{
558
+return $row['ident_id'];});
542 559
 	}
543 560
 
544 561
 	/**
@@ -554,10 +571,13 @@  discard block
 block discarded – undo
554 571
 		{
555 572
 			$address .= ($address && $identity['ident_org'] ? ' ' : '').$identity['ident_org'];
556 573
 		}
557
-		if (strpos($address, ',') !== false)	// need to quote comma
574
+		if (strpos($address, ',') !== false)
575
+		{
576
+			// need to quote comma
558 577
 		{
559 578
 			$address = '"'.str_replace('"', '\\"', $address).'"';
560 579
 		}
580
+		}
561 581
 		if (!strpos($identity['ident_email'], '@'))
562 582
 		{
563 583
 			$address = null;
@@ -661,8 +681,14 @@  discard block
 block discarded – undo
661 681
 		if ($to_replace)
662 682
 		{
663 683
 			static $merge=null;
664
-			if (!isset($merge)) $merge = new Api\Contacts\Merge();
665
-			if (!isset($account_id)) $account_id = $GLOBALS['egw_info']['user']['account_id'];
684
+			if (!isset($merge))
685
+			{
686
+				$merge = new Api\Contacts\Merge();
687
+			}
688
+			if (!isset($account_id))
689
+			{
690
+				$account_id = $GLOBALS['egw_info']['user']['account_id'];
691
+			}
666 692
 			foreach($to_replace as $name => &$value)
667 693
 			{
668 694
 				$err = null;
@@ -1083,7 +1109,10 @@  discard block
 block discarded – undo
1083 1109
 				}
1084 1110
 
1085 1111
 				// fetch the IMAP / incomming server data
1086
-				if (!class_exists($data['acc_smtp_type'])) $data['acc_smtp_type'] = __NAMESPACE__.'\\Smtp';
1112
+				if (!class_exists($data['acc_smtp_type']))
1113
+				{
1114
+					$data['acc_smtp_type'] = __NAMESPACE__.'\\Smtp';
1115
+				}
1087 1116
 			}
1088 1117
 		}
1089 1118
 		return $data;
@@ -1115,7 +1144,10 @@  discard block
 block discarded – undo
1115 1144
 		}
1116 1145
 
1117 1146
 		// fetch the IMAP / incomming server data
1118
-		if (!class_exists($imap_type)) $imap_type = __NAMESPACE__.'\\Imap';
1147
+		if (!class_exists($imap_type))
1148
+		{
1149
+			$imap_type = __NAMESPACE__.'\\Imap';
1150
+		}
1119 1151
 
1120 1152
 		return $imap_type;
1121 1153
 	}
@@ -1168,7 +1200,10 @@  discard block
 block discarded – undo
1168 1200
 			$data['acc_id'] = self::$db->get_last_insert_id(self::TABLE, 'acc_id');
1169 1201
 		}
1170 1202
 		// restore namespace in class-names
1171
-		if ($backup) $data = array_merge($data, $backup);
1203
+		if ($backup)
1204
+		{
1205
+			$data = array_merge($data, $backup);
1206
+		}
1172 1207
 
1173 1208
 		// store identity
1174 1209
 		$new_ident_id = self::save_identity($data);
@@ -1279,7 +1314,10 @@  discard block
 block discarded – undo
1279 1314
 	 */
1280 1315
 	protected static function credentials_valid_for($account, $account_id=null)
1281 1316
 	{
1282
-		if (!isset($account_id)) $account_id = $GLOBALS['egw_info']['user']['account_id'];
1317
+		if (!isset($account_id))
1318
+		{
1319
+			$account_id = $GLOBALS['egw_info']['user']['account_id'];
1320
+		}
1283 1321
 
1284 1322
 		// if account valid for multiple users
1285 1323
 		if (self::is_multiple($account))
@@ -1398,9 +1436,12 @@  discard block
 block discarded – undo
1398 1436
 				$cols[] = $valid_account_id_sql.' AS account_id';
1399 1437
 				$join .= ' '.self::ALL_VALID_JOIN;
1400 1438
 			}
1401
-			if ($just_name == 'params')	// join in acc_imap_admin_username
1439
+			if ($just_name == 'params')
1440
+			{
1441
+				// join in acc_imap_admin_username
1402 1442
 			{
1403 1443
 				$cols[] = self::ADMIN_COL;
1444
+			}
1404 1445
 				$join .= ' '.self::ADMIN_JOIN;
1405 1446
 			}
1406 1447
 			$rs = self::$db->select(self::TABLE, $cols,	$where, __LINE__, __FILE__,
@@ -1434,7 +1475,10 @@  discard block
 block discarded – undo
1434 1475
 				}
1435 1476
 			}
1436 1477
 		}
1437
-		if (is_null(self::$search_cache[$cache_key])) self::$search_cache[$cache_key]=array();
1478
+		if (is_null(self::$search_cache[$cache_key]))
1479
+		{
1480
+			self::$search_cache[$cache_key]=array();
1481
+		}
1438 1482
 		return new Api\Db\CallbackIterator(new \ArrayIterator(self::$search_cache[$cache_key]),
1439 1483
 			// process each row
1440 1484
 			function($row) use ($just_name, $replace_placeholders, $account_id)
@@ -1476,12 +1520,18 @@  discard block
 block discarded – undo
1476 1520
 			{
1477 1521
 				if ($smtp)
1478 1522
 				{
1479
-					if (!$params['acc_smtp_host'] || !$params['acc_smtp_port']) continue;
1523
+					if (!$params['acc_smtp_host'] || !$params['acc_smtp_port'])
1524
+					{
1525
+						continue;
1526
+					}
1480 1527
 					// check requirement of session, which is not available in async service!
1481 1528
 					if (isset($GLOBALS['egw_info']['flags']['async-service']) ||
1482
-						empty($GLOBALS['egw_info']['user']['account_id']))	// happens during login when notifying about blocked accounts
1529
+						empty($GLOBALS['egw_info']['user']['account_id']))
1530
+					{
1531
+						// happens during login when notifying about blocked accounts
1483 1532
 					{
1484 1533
 						if ($params['acc_smtp_auth_session']) continue;
1534
+					}
1485 1535
 						// may fail because of smtp only profile, or no session password, etc
1486 1536
 						try
1487 1537
 						{
@@ -1492,15 +1542,24 @@  discard block
 block discarded – undo
1492 1542
 							unset($x);
1493 1543
 							continue;
1494 1544
 						}
1495
-						if (Credentials::isUser($account->acc_smtp_pw_enc)) continue;
1545
+						if (Credentials::isUser($account->acc_smtp_pw_enc))
1546
+						{
1547
+							continue;
1548
+						}
1496 1549
 					}
1497 1550
 				}
1498 1551
 				else
1499 1552
 				{
1500
-					if (!$params['acc_imap_host'] || !$params['acc_imap_port']) continue;
1553
+					if (!$params['acc_imap_host'] || !$params['acc_imap_port'])
1554
+					{
1555
+						continue;
1556
+					}
1501 1557
 					$account = new Account($params);
1502 1558
 					// continue if we have either no imap username or password
1503
-					if (!$account->is_imap()) continue;
1559
+					if (!$account->is_imap())
1560
+					{
1561
+						continue;
1562
+					}
1504 1563
 				}
1505 1564
 				return $return_id ? $acc_id : (isset($account) && $account->acc_id == $acc_id ?
1506 1565
 					$account : new Account($params));
@@ -1508,7 +1567,10 @@  discard block
 block discarded – undo
1508 1567
 		}
1509 1568
 		catch (\Exception $e)
1510 1569
 		{
1511
-			if ($log_no_default) error_log(__METHOD__.__LINE__.' Error no Default available.'.$e->getMessage());
1570
+			if ($log_no_default)
1571
+			{
1572
+				error_log(__METHOD__.__LINE__.' Error no Default available.'.$e->getMessage());
1573
+			}
1512 1574
 		}
1513 1575
 		return null;
1514 1576
 	}
@@ -1570,8 +1632,14 @@  discard block
 block discarded – undo
1570 1632
 				// fill an empty ident_realname or ident_email of current user with data from user account
1571 1633
 				if ($replace_placeholders && (!isset($account_id) || $account_id == $GLOBALS['egw_info']['user']['acount_id']))
1572 1634
 				{
1573
-					if (empty($account['ident_realname'])) $account['ident_realname'] = $GLOBALS['egw_info']['user']['account_fullname'];
1574
-					if (empty($account['ident_email'])) $account['ident_email'] = $GLOBALS['egw_info']['user']['account_email'];
1635
+					if (empty($account['ident_realname']))
1636
+					{
1637
+						$account['ident_realname'] = $GLOBALS['egw_info']['user']['account_fullname'];
1638
+					}
1639
+					if (empty($account['ident_email']))
1640
+					{
1641
+						$account['ident_email'] = $GLOBALS['egw_info']['user']['account_email'];
1642
+					}
1575 1643
 				}
1576 1644
 				if (empty($account['ident_email']) && !empty($account['acc_imap_username']) && strpos($account['acc_imap_username'], '@') !== false)
1577 1645
 				{
@@ -1642,7 +1710,10 @@  discard block
 block discarded – undo
1642 1710
 	 */
1643 1711
 	protected static function memberships($user=null)
1644 1712
 	{
1645
-		if (!$user) $user = $GLOBALS['egw_info']['user']['account_id'];
1713
+		if (!$user)
1714
+		{
1715
+			$user = $GLOBALS['egw_info']['user']['account_id'];
1716
+		}
1646 1717
 
1647 1718
 		$memberships = $GLOBALS['egw']->accounts->memberships($user, true);
1648 1719
 		$memberships[] = $user;
Please login to merge, or discard this patch.
Spacing   +69 added lines, -72 removed lines patch added patch discarded remove patch
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
 	/**
198 198
 	 * Path to log smtp comunication to or null to not log
199 199
 	 */
200
-	const SMTP_DEBUG_LOG = null;//'/tmp/smtp.log';
200
+	const SMTP_DEBUG_LOG = null; //'/tmp/smtp.log';
201 201
 
202 202
 	/**
203 203
 	 * Instanciated account object by acc_id, read acts as singelton
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
 	 * @param int $called_for=null if set access to given user (without smtp credentials!),
253 253
 	 *	default current user AND read username/password from current users session
254 254
 	 */
255
-	/*protected*/ function __construct(array $params, $called_for=null)
255
+	/*protected*/ function __construct(array $params, $called_for = null)
256 256
 	{
257 257
 		// read credentials from database
258 258
 		$params += Credentials::read($params['acc_id'], null, $called_for ? array(0, $called_for) : $called_for, $this->on_login);
@@ -281,16 +281,16 @@  discard block
 block discarded – undo
281 281
 	public static function ssl2secure($ssl)
282 282
 	{
283 283
 		$secure = false;
284
-		switch($ssl & ~self::SSL_VERIFY)
284
+		switch ($ssl&~self::SSL_VERIFY)
285 285
 		{
286 286
 			case self::SSL_STARTTLS:
287
-				$secure = 'tls';	// Horde uses 'tls' for STARTTLS, not ssl connection with tls version >= 1 and no sslv2/3
287
+				$secure = 'tls'; // Horde uses 'tls' for STARTTLS, not ssl connection with tls version >= 1 and no sslv2/3
288 288
 				break;
289 289
 			case self::SSL_SSL:
290 290
 				$secure = 'ssl';
291 291
 				break;
292 292
 			case self::SSL_TLS:
293
-				$secure = 'tlsv1';	// since Horde_Imap_Client-1.16.0 requiring Horde_Socket_Client-1.1.0
293
+				$secure = 'tlsv1'; // since Horde_Imap_Client-1.16.0 requiring Horde_Socket_Client-1.1.0
294 294
 				break;
295 295
 		}
296 296
 		return $secure;
@@ -324,15 +324,15 @@  discard block
 block discarded – undo
324 324
 				$this->params = array_merge($this->params, $data);
325 325
 			}
326 326
 		}
327
-		catch(Horde_Imap_Client_Exception $e) {
327
+		catch (Horde_Imap_Client_Exception $e) {
328 328
 			unset($e);
329 329
 			// ignore eg. connection errors
330 330
 		}
331
-		catch(\InvalidArgumentException $e) {
331
+		catch (\InvalidArgumentException $e) {
332 332
 			unset($e);
333 333
 			// ignore eg. missing admin user
334 334
 		}
335
-		$this->params += array_fill_keys(self::$user_data, null);	// make sure all keys exist now
335
+		$this->params += array_fill_keys(self::$user_data, null); // make sure all keys exist now
336 336
 
337 337
 		return (array)$data + (array)$smtp_data;
338 338
 	}
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
 	 */
345 345
 	public function saveUserData($user, array $data)
346 346
 	{
347
-		$data += $this->params;	// in case only user-data has been specified
347
+		$data += $this->params; // in case only user-data has been specified
348 348
 
349 349
 		// store account-information of managed mail server
350 350
 		if ($user > 0 && $data['acc_smtp_type'] && $data['acc_smtp_type'] != __NAMESPACE__.'\\Smtp')
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
 	 * @param int $_timeout =null timeout in secs, if none given fmail pref or default of 20 is used
369 369
 	 * @return Imap
370 370
 	 */
371
-	public function imapServer($_adminConnection=false, $_timeout=null)
371
+	public function imapServer($_adminConnection = false, $_timeout = null)
372 372
 	{
373 373
 		if (!isset($this->imapServer) || $this->imapServer->isAdminConnection !== $_adminConnection)
374 374
 		{
@@ -400,11 +400,11 @@  discard block
 block discarded – undo
400 400
 	 *	(matters only for imap servers managed by EGroupware!)
401 401
 	 * @return boolean
402 402
 	 */
403
-	public function is_imap($try_connect=true)
403
+	public function is_imap($try_connect = true)
404 404
 	{
405
-		if (empty($this->acc_imap_host) || ( empty($this->acc_imap_username) && empty($this->acc_imap_password) ) )
405
+		if (empty($this->acc_imap_host) || (empty($this->acc_imap_username) && empty($this->acc_imap_password)))
406 406
 		{
407
-			return false;	// no imap host or credentials
407
+			return false; // no imap host or credentials
408 408
 		}
409 409
 		// if we are not managing the mail-server, we do NOT need to check deliveryMode and accountStatus
410 410
 		if ($this->acc_smtp_type == __NAMESPACE__.'\\Smtp')
@@ -441,7 +441,7 @@  discard block
 block discarded – undo
441 441
 			$this->smtpServer->editForwardingAddress = false;
442 442
 			$this->smtpServer->host = $this->params['acc_smtp_host'];
443 443
 			$this->smtpServer->port = $this->params['acc_smtp_port'];
444
-			switch($this->params['acc_smtp_ssl'])
444
+			switch ($this->params['acc_smtp_ssl'])
445 445
 			{
446 446
 				case self::SSL_TLS:
447 447
 					$this->smtpServer->host = 'tlsv1://'.$this->smtpServer->host;
@@ -471,16 +471,16 @@  discard block
 block discarded – undo
471 471
 		if (!isset($this->smtpTransport))
472 472
 		{
473 473
 			$secure = false;
474
-			switch($this->acc_smtp_ssl & ~self::SSL_VERIFY)
474
+			switch ($this->acc_smtp_ssl & ~self::SSL_VERIFY)
475 475
 			{
476 476
 				case self::SSL_STARTTLS:
477
-					$secure = 'tls';	// Horde uses 'tls' for STARTTLS, not ssl connection with tls version >= 1 and no sslv2/3
477
+					$secure = 'tls'; // Horde uses 'tls' for STARTTLS, not ssl connection with tls version >= 1 and no sslv2/3
478 478
 					break;
479 479
 				case self::SSL_SSL:
480 480
 					$secure = 'ssl';
481 481
 					break;
482 482
 				case self::SSL_TLS:
483
-					$secure = 'tlsv1';	// since Horde_Smtp-1.3.0 requiring Horde_Socket_Client-1.1.0
483
+					$secure = 'tlsv1'; // since Horde_Smtp-1.3.0 requiring Horde_Socket_Client-1.1.0
484 484
 					break;
485 485
 			}
486 486
 			// Horde use locale for translation of error messages
@@ -510,7 +510,7 @@  discard block
 block discarded – undo
510 510
 	 * @param int $user =null account_id to use if not current user
511 511
 	 * @return Iterator ident_id => identity_name of identity
512 512
 	 */
513
-	public static function identities($account, $replace_placeholders=true, $field='name', $user=null)
513
+	public static function identities($account, $replace_placeholders = true, $field = 'name', $user = null)
514 514
 	{
515 515
 		if (!isset($user)) $user = $GLOBALS['egw_info']['user']['account_id'];
516 516
 		$acc_id = is_scalar($account) ? $account : $account['acc_id'];
@@ -560,7 +560,7 @@  discard block
 block discarded – undo
560 560
 				}
561 561
 				return self::identity_name($row, $replace_placeholders);
562 562
 			}, array(),
563
-			function($row) { return $row['ident_id'];});
563
+			function($row) { return $row['ident_id']; });
564 564
 	}
565 565
 
566 566
 	/**
@@ -603,17 +603,17 @@  discard block
 block discarded – undo
603 603
 	 * @return array acc_id:ident_id:email => rfc822 address pairs, eg. '1:1:[email protected]' => 'Ralf Becker Stylite AG <[email protected]>'
604 604
 	 * @todo add aliases for manged mail servers
605 605
 	 */
606
-	public static function rfc822_addresses($formatter=null)
606
+	public static function rfc822_addresses($formatter = null)
607 607
 	{
608 608
 		if (!$formatter || !is_callable($formatter))
609 609
 		{
610 610
 			$formatter = 'self::rfc822';
611 611
 		}
612 612
 		$addresses = array();
613
-		foreach(self::search(true, false) as $acc_id => $account)
613
+		foreach (self::search(true, false) as $acc_id => $account)
614 614
 		{
615
-			$added = false;	// make sure each account get's at least added once, even if it uses an identical email address
616
-			foreach(self::identities($account, true, 'params') as $identity)
615
+			$added = false; // make sure each account get's at least added once, even if it uses an identical email address
616
+			foreach (self::identities($account, true, 'params') as $identity)
617 617
 			{
618 618
 				if (($address = call_user_func($formatter, $identity)) && (!$added || !in_array($address, $addresses)))
619 619
 				{
@@ -647,7 +647,7 @@  discard block
 block discarded – undo
647 647
 			}
648 648
 			return $cmp;
649 649
 		});
650
-		foreach($identities as &$identity)
650
+		foreach ($identities as &$identity)
651 651
 		{
652 652
 			$identity = self::identity_name($identity);
653 653
 		}
@@ -664,16 +664,16 @@  discard block
 block discarded – undo
664 664
 	 * @param int $account_id =null account_id of user, or current user
665 665
 	 * @return array with modified fields
666 666
 	 */
667
-	public static function replace_placeholders($identity, $account_id=null)
667
+	public static function replace_placeholders($identity, $account_id = null)
668 668
 	{
669
-		static $fields = array('ident_name','ident_realname','ident_org','ident_email','ident_signature');
669
+		static $fields = array('ident_name', 'ident_realname', 'ident_org', 'ident_email', 'ident_signature');
670 670
 
671 671
 		if (!is_array($identity) && !is_a($identity, 'Account'))
672 672
 		{
673 673
 			throw new Api\Exception\WrongParameter(__METHOD__."() requires an identity or account as first parameter!");
674 674
 		}
675 675
 		$to_replace = array();
676
-		foreach($fields as $name)
676
+		foreach ($fields as $name)
677 677
 		{
678 678
 			if (strpos($identity[$name], '{{') !== false || strpos($identity[$name], '$$') !== false)
679 679
 			{
@@ -682,10 +682,10 @@  discard block
 block discarded – undo
682 682
 		}
683 683
 		if ($to_replace)
684 684
 		{
685
-			static $merge=null;
685
+			static $merge = null;
686 686
 			if (!isset($merge)) $merge = new Api\Contacts\Merge();
687 687
 			if (!isset($account_id)) $account_id = $GLOBALS['egw_info']['user']['account_id'];
688
-			foreach($to_replace as $name => &$value)
688
+			foreach ($to_replace as $name => &$value)
689 689
 			{
690 690
 				$err = null;
691 691
 				$value = $merge->merge_string($value,
@@ -707,7 +707,7 @@  discard block
 block discarded – undo
707 707
 	 * @return array
708 708
 	 * @throws Api\Exception\NotFound
709 709
 	 */
710
-	public static function read_identity($ident_id, $replace_placeholders=false, $user=null, $account=null)
710
+	public static function read_identity($ident_id, $replace_placeholders = false, $user = null, $account = null)
711 711
 	{
712 712
 		if (($account && $account['ident_id'] == $ident_id))
713 713
 		{
@@ -777,8 +777,7 @@  discard block
 block discarded – undo
777 777
 			'ident_org' => $identity['ident_org'],
778 778
 			'ident_email' => $identity['ident_email'],
779 779
 			'ident_signature' => $identity['ident_signature'],
780
-			'account_id' => self::is_multiple($identity) ? 0 :
781
-				(is_array($identity['account_id']) ? $identity['account_id'][0] : $identity['account_id']),
780
+			'account_id' => self::is_multiple($identity) ? 0 : (is_array($identity['account_id']) ? $identity['account_id'][0] : $identity['account_id']),
782 781
 		);
783 782
 		if ($identity['ident_id'] > 0)
784 783
 		{
@@ -822,7 +821,7 @@  discard block
 block discarded – undo
822 821
 	 */
823 822
 	public function __get($name)
824 823
 	{
825
-		switch($name)
824
+		switch ($name)
826 825
 		{
827 826
 			case 'acc_imap_administration':	// no longer stored in database
828 827
 				return !empty($this->params['acc_imap_admin_username']);
@@ -846,7 +845,7 @@  discard block
 block discarded – undo
846 845
 	 */
847 846
 	public function __isset($name)
848 847
 	{
849
-		switch($name)
848
+		switch ($name)
850 849
 		{
851 850
 			case 'acc_imap_administration':	// no longer stored in database
852 851
 				return true;
@@ -936,11 +935,11 @@  discard block
 block discarded – undo
936 935
 		{
937 936
 			// check if account is for current user, if not deny access
938 937
 			$memberships = self::memberships();
939
-			$memberships[] = '';	// edit uses '' for everyone
938
+			$memberships[] = ''; // edit uses '' for everyone
940 939
 
941 940
 			if (array_intersect((array)$account['account_id'], $memberships))
942 941
 			{
943
-				switch($rights)
942
+				switch ($rights)
944 943
 				{
945 944
 					case Api\Acl::READ:
946 945
 						$access = true;
@@ -985,7 +984,7 @@  discard block
 block discarded – undo
985 984
 	 * @return email_account
986 985
 	 * @throws Api\Exception\NotFound if account was not found (or not valid for current user)
987 986
 	 */
988
-	public static function read($acc_id, $called_for=null)
987
+	public static function read($acc_id, $called_for = null)
989 988
 	{
990 989
 		//error_log(__METHOD__."($acc_id, ".array2string($called_for).")");
991 990
 		// some caching, but only for regular usage/users
@@ -1003,7 +1002,7 @@  discard block
 block discarded – undo
1003 1002
 				//error_log(__METHOD__."($acc_id) created instance from cached data");
1004 1003
 				return self::$instances[$acc_id] = new Account(self::$cache[$acc_id]);
1005 1004
 			}
1006
-			$data =& self::$cache[$acc_id];
1005
+			$data = & self::$cache[$acc_id];
1007 1006
 		}
1008 1007
 		$where = array(self::TABLE.'.acc_id='.(int)$acc_id);
1009 1008
 		if (!isset($called_for) || $called_for !== '0')
@@ -1027,7 +1026,7 @@  discard block
 block discarded – undo
1027 1026
 		if (!$valid_account_id_sql)
1028 1027
 		{
1029 1028
 			$data['account_id'] = array();
1030
-			foreach(self::$db->select(self::VALID_TABLE, 'account_id', array('acc_id' => $acc_id),
1029
+			foreach (self::$db->select(self::VALID_TABLE, 'account_id', array('acc_id' => $acc_id),
1031 1030
 				__LINE__, __FILE__, false, '', self::APP) as $row)
1032 1031
 			{
1033 1032
 				$data['account_id'][] = $row['account_id'];
@@ -1039,7 +1038,7 @@  discard block
 block discarded – undo
1039 1038
 		if (!isset($called_for))
1040 1039
 		{
1041 1040
 			//error_log(__METHOD__."($acc_id) creating instance and caching data read from db");
1042
-			$ret =& self::$instances[$acc_id];
1041
+			$ret = & self::$instances[$acc_id];
1043 1042
 		}
1044 1043
 		return $ret = new Account($data, $called_for);
1045 1044
 	}
@@ -1052,7 +1051,7 @@  discard block
 block discarded – undo
1052 1051
 	 */
1053 1052
 	protected static function db2data(array $data)
1054 1053
 	{
1055
-		foreach(array('acc_sieve_enabled','acc_user_editable','acc_smtp_auth_session','acc_user_forward') as $name)
1054
+		foreach (array('acc_sieve_enabled', 'acc_user_editable', 'acc_smtp_auth_session', 'acc_user_forward') as $name)
1056 1055
 		{
1057 1056
 			if (isset($data[$name]))
1058 1057
 			{
@@ -1151,16 +1150,16 @@  discard block
 block discarded – undo
1151 1150
 	 * @throws Api\Exception\WrongParameter if called static without data-array
1152 1151
 	 * @throws Api\Db\Exception
1153 1152
 	 */
1154
-	public static function write(array $data, $user=null)
1153
+	public static function write(array $data, $user = null)
1155 1154
 	{
1156 1155
 		//error_log(__METHOD__."(".array2string($data).")");
1157 1156
 		$data['acc_modifier'] = $GLOBALS['egw_info']['user']['account_id'];
1158 1157
 		$data['acc_modified'] = time();
1159 1158
 
1160 1159
 		// remove redundant namespace to fit into column
1161
-		$ns_len = strlen(__NAMESPACE__)+1;
1160
+		$ns_len = strlen(__NAMESPACE__) + 1;
1162 1161
 		$backup = array();
1163
-		foreach(array('acc_smtp_type', 'acc_imap_type') as $attr)
1162
+		foreach (array('acc_smtp_type', 'acc_imap_type') as $attr)
1164 1163
 		{
1165 1164
 			if (substr($data[$attr], 0, $ns_len) == __NAMESPACE__.'\\')
1166 1165
 			{
@@ -1174,7 +1173,7 @@  discard block
 block discarded – undo
1174 1173
 		{
1175 1174
 			// set not set values which, are NOT NULL and therefore would give an SQL error
1176 1175
 			$td = self::$db->get_table_definitions('api', self::TABLE);
1177
-			foreach($td['fd'] as $col => $def)
1176
+			foreach ($td['fd'] as $col => $def)
1178 1177
 			{
1179 1178
 				if (!isset($data[$col]) && $def['nullable'] === false && !isset($def['default']))
1180 1179
 				{
@@ -1211,19 +1210,19 @@  discard block
 block discarded – undo
1211 1210
 		$old_account_ids = array();
1212 1211
 		if ($where)
1213 1212
 		{
1214
-			foreach(self::$db->select(self::VALID_TABLE, 'account_id', $where,
1213
+			foreach (self::$db->select(self::VALID_TABLE, 'account_id', $where,
1215 1214
 				__LINE__, __FILE__, false, '', self::APP) as $row)
1216 1215
 			{
1217 1216
 				$old_account_ids[] = $row['account_id'];
1218 1217
 			}
1219 1218
 			if (($ids_to_remove = array_diff($old_account_ids, (array)$data['account_id'])))
1220 1219
 			{
1221
-				self::$db->delete(self::VALID_TABLE, $where+array(
1220
+				self::$db->delete(self::VALID_TABLE, $where + array(
1222 1221
 					'account_id' => $ids_to_remove,
1223 1222
 				), __LINE__, __FILE__, self::APP);
1224 1223
 			}
1225 1224
 		}
1226
-		foreach((array)$data['account_id'] as $account_id)
1225
+		foreach ((array)$data['account_id'] as $account_id)
1227 1226
 		{
1228 1227
 			if (!in_array($account_id, $old_account_ids))
1229 1228
 			{
@@ -1285,8 +1284,7 @@  discard block
 block discarded – undo
1285 1284
 		}
1286 1285
 
1287 1286
 		// store notification folders
1288
-		Notifications::write($data['acc_id'], $data['notify_save_default'] ? 0 :
1289
-			($data['called_for'] ? $data['called_for'] : $GLOBALS['egw_info']['user']['account_id']),
1287
+		Notifications::write($data['acc_id'], $data['notify_save_default'] ? 0 : ($data['called_for'] ? $data['called_for'] : $GLOBALS['egw_info']['user']['account_id']),
1290 1288
 			(array)$data['notify_folders']);
1291 1289
 
1292 1290
 		// store domain of an account for all user like before as "mail_suffix" config
@@ -1312,7 +1310,7 @@  discard block
 block discarded – undo
1312 1310
 	 * @param int $account_id =null
1313 1311
 	 * @return int account_id for whom credentials are valid or 0 for all
1314 1312
 	 */
1315
-	protected static function credentials_valid_for($account, $account_id=null)
1313
+	protected static function credentials_valid_for($account, $account_id = null)
1316 1314
 	{
1317 1315
 		if (!isset($account_id)) $account_id = $GLOBALS['egw_info']['user']['account_id'];
1318 1316
 
@@ -1338,7 +1336,7 @@  discard block
 block discarded – undo
1338 1336
 	 * @param int $account_id =null user or group
1339 1337
 	 * @return int number of deleted mail accounts or null if only user-data was deleted and no full mail accounts
1340 1338
 	 */
1341
-	public static function delete($acc_id, $account_id=null)
1339
+	public static function delete($acc_id, $account_id = null)
1342 1340
 	{
1343 1341
 		if (is_array($acc_id) || $acc_id > 0)
1344 1342
 		{
@@ -1349,7 +1347,7 @@  discard block
 block discarded – undo
1349 1347
 			self::$db->delete(self::TABLE, array('acc_id' => $acc_id), __LINE__, __FILE__, self::APP);
1350 1348
 
1351 1349
 			// invalidate caches
1352
-			foreach((array)$acc_id as $acc_id)
1350
+			foreach ((array)$acc_id as $acc_id)
1353 1351
 			{
1354 1352
 				self::cache_invalidate($acc_id);
1355 1353
 			}
@@ -1368,7 +1366,7 @@  discard block
 block discarded – undo
1368 1366
 		self::$db->delete(self::IDENTITIES_TABLE, array('account_id' => $account_id), __LINE__, __FILE__, self::APP);
1369 1367
 		// find profiles not belonging to anyone else and delete them
1370 1368
 		$acc_ids = array();
1371
-		foreach(self::$db->select(self::TABLE, self::TABLE.'.acc_id', 'account_id IS NULL', __LINE__, __FILE__,
1369
+		foreach (self::$db->select(self::TABLE, self::TABLE.'.acc_id', 'account_id IS NULL', __LINE__, __FILE__,
1372 1370
 			false, 'GROUP BY '.self::TABLE.'.acc_id', self::APP, 0, 'LEFT '.self::VALID_JOIN) as $row)
1373 1371
 		{
1374 1372
 			$acc_ids[] = $row['acc_id'];
@@ -1392,7 +1390,7 @@  discard block
 block discarded – undo
1392 1390
 	 * @param boolean $replace_placeholders =true should placeholders like {{n_fn}} be replaced
1393 1391
 	 * @return Iterator with acc_id => acc_name or Account objects
1394 1392
 	 */
1395
-	public static function search($only_current_user=true, $just_name=true, $order_by=null, $offset=false, $num_rows=0, $replace_placeholders=true)
1393
+	public static function search($only_current_user = true, $just_name = true, $order_by = null, $offset = false, $num_rows = 0, $replace_placeholders = true)
1396 1394
 	{
1397 1395
 		//error_log(__METHOD__."($only_current_user, $just_name, '$order_by', $offset, $num_rows)");
1398 1396
 		$where = array();
@@ -1438,19 +1436,19 @@  discard block
 block discarded – undo
1438 1436
 				$cols[] = self::ADMIN_COL;
1439 1437
 				$join .= ' '.self::ADMIN_JOIN;
1440 1438
 			}
1441
-			$rs = self::$db->select(self::TABLE, $cols,	$where, __LINE__, __FILE__,
1439
+			$rs = self::$db->select(self::TABLE, $cols, $where, __LINE__, __FILE__,
1442 1440
 				$offset, Api\Storage::fix_group_by_columns($group_by, $cols, self::TABLE, 'acc_id').' ORDER BY '.$order_by,
1443 1441
 				self::APP, $num_rows, $join);
1444 1442
 
1445 1443
 			$ids = array();
1446
-			foreach($rs as $row)
1444
+			foreach ($rs as $row)
1447 1445
 			{
1448 1446
 				$row = self::db2data($row);
1449 1447
 
1450 1448
 				if ($only_current_user === true)
1451 1449
 				{
1452 1450
 					//error_log(__METHOD__."(TRUE, $just_name) caching data for acc_id=$row[acc_id]");
1453
-					self::$search_cache[$cache_key][$row['acc_id']] =& self::$cache[$row['acc_id']];
1451
+					self::$search_cache[$cache_key][$row['acc_id']] = & self::$cache[$row['acc_id']];
1454 1452
 					self::$cache[$row['acc_id']] = $row;
1455 1453
 				}
1456 1454
 				else
@@ -1462,14 +1460,14 @@  discard block
 block discarded – undo
1462 1460
 			// fetch valid_id, if not yet fetched
1463 1461
 			if (!$valid_account_id_sql && $ids)
1464 1462
 			{
1465
-				foreach(self::$db->select(self::VALID_TABLE, 'account_id', array('acc_id' => $ids),
1463
+				foreach (self::$db->select(self::VALID_TABLE, 'account_id', array('acc_id' => $ids),
1466 1464
 					__LINE__, __FILE__, false, '', self::APP) as $row)
1467 1465
 				{
1468 1466
 					self::$cache[$row['acc_id']]['account_id'][] = $row['account_id'];
1469 1467
 				}
1470 1468
 			}
1471 1469
 		}
1472
-		if (is_null(self::$search_cache[$cache_key])) self::$search_cache[$cache_key]=array();
1470
+		if (is_null(self::$search_cache[$cache_key])) self::$search_cache[$cache_key] = array();
1473 1471
 		return new Api\Db\CallbackIterator(new \ArrayIterator(self::$search_cache[$cache_key]),
1474 1472
 			// process each row
1475 1473
 			function($row) use ($just_name, $replace_placeholders, $account_id)
@@ -1503,11 +1501,11 @@  discard block
 block discarded – undo
1503 1501
 	 * @param boolean $log_no_default =true true: error_log if no default found, false be silent
1504 1502
 	 * @return Account|null
1505 1503
 	 */
1506
-	static function get_default($smtp=false, $return_id=false, $log_no_default=true)
1504
+	static function get_default($smtp = false, $return_id = false, $log_no_default = true)
1507 1505
 	{
1508 1506
 		try
1509 1507
 		{
1510
-			foreach(self::search(true, 'params') as $acc_id => $params)
1508
+			foreach (self::search(true, 'params') as $acc_id => $params)
1511 1509
 			{
1512 1510
 				if ($smtp)
1513 1511
 				{
@@ -1554,7 +1552,7 @@  discard block
 block discarded – undo
1554 1552
 	 * @param boolean $smtp =false false: usable for IMAP, true: usable for SMTP
1555 1553
 	 * @return int
1556 1554
 	 */
1557
-	static function get_default_acc_id($smtp=false)
1555
+	static function get_default_acc_id($smtp = false)
1558 1556
 	{
1559 1557
 		return self::get_default($smtp, true);
1560 1558
 	}
@@ -1567,7 +1565,7 @@  discard block
 block discarded – undo
1567 1565
 	 * @param int $account_id =null account_id of user we are called for
1568 1566
 	 * @return string with htmlencoded angle brackets
1569 1567
 	 */
1570
-	public static function identity_name($account, $replace_placeholders=true, $account_id=null)
1568
+	public static function identity_name($account, $replace_placeholders = true, $account_id = null)
1571 1569
 	{
1572 1570
 		if ($replace_placeholders)
1573 1571
 		{
@@ -1594,7 +1592,7 @@  discard block
 block discarded – undo
1594 1592
 				{
1595 1593
 					if (!isset($account['acc_imap_username']))
1596 1594
 					{
1597
-						$account += Credentials::read($account['acc_id'], null, ($account_id?array($account_id, 0):null));
1595
+						$account += Credentials::read($account['acc_id'], null, ($account_id ? array($account_id, 0) : null));
1598 1596
 					}
1599 1597
 					if (empty($account['acc_imap_username']) && $account['acc_imap_logintype'] &&
1600 1598
 						(!isset($account_id) || $account_id == $GLOBALS['egw_info']['user']['account_id']))
@@ -1613,7 +1611,7 @@  discard block
 block discarded – undo
1613 1611
 					$account['ident_email'] = $account['acc_imap_username'];
1614 1612
 				}
1615 1613
 			}
1616
-			catch(\Exception $e) {
1614
+			catch (\Exception $e) {
1617 1615
 				_egw_log_exception($e);
1618 1616
 			}
1619 1617
 		}
@@ -1625,11 +1623,11 @@  discard block
 block discarded – undo
1625 1623
 		{
1626 1624
 			$name = $account['acc_name'];
1627 1625
 		}
1628
-		if (strpos($account['ident_email'], '@') !== false || trim($account['ident_email']) !='')
1626
+		if (strpos($account['ident_email'], '@') !== false || trim($account['ident_email']) != '')
1629 1627
 		{
1630 1628
 			$name .= ' <'.$account['ident_email'].'>';
1631 1629
 		}
1632
-		elseif(strpos($account['acc_imap_username'], '@') !== false || trim($account['acc_imap_username']) !='')
1630
+		elseif (strpos($account['acc_imap_username'], '@') !== false || trim($account['acc_imap_username']) != '')
1633 1631
 		{
1634 1632
 			$name .= ' <'.$account['acc_imap_username'].'>';
1635 1633
 		}
@@ -1652,8 +1650,7 @@  discard block
 block discarded – undo
1652 1650
 	 */
1653 1651
 	public static function is_multiple($account)
1654 1652
 	{
1655
-		$is_multiple = !is_array($account['account_id']) ? $account['account_id'] <= 0 :
1656
-			(count($account['account_id']) > 1 || $account['account_id'][0] <= 0);
1653
+		$is_multiple = !is_array($account['account_id']) ? $account['account_id'] <= 0 : (count($account['account_id']) > 1 || $account['account_id'][0] <= 0);
1657 1654
 		//error_log(__METHOD__."(account_id=".array2string($account['account_id']).") returning ".array2string($is_multiple));
1658 1655
 		return $is_multiple;
1659 1656
 	}
@@ -1674,13 +1671,13 @@  discard block
 block discarded – undo
1674 1671
 	 * @param type $user
1675 1672
 	 * @return array
1676 1673
 	 */
1677
-	protected static function memberships($user=null)
1674
+	protected static function memberships($user = null)
1678 1675
 	{
1679 1676
 		if (!$user) $user = $GLOBALS['egw_info']['user']['account_id'];
1680 1677
 
1681 1678
 		$memberships = $GLOBALS['egw']->accounts->memberships($user, true);
1682 1679
 		$memberships[] = $user;
1683
-		$memberships[] = 0;	// marks accounts valid for everyone
1680
+		$memberships[] = 0; // marks accounts valid for everyone
1684 1681
 
1685 1682
 		return $memberships;
1686 1683
 	}
Please login to merge, or discard this patch.