Completed
Push — master ( aa44e9...fa84e5 )
by Ralf
90:14 queued 73:21
created
api/src/Framework/Template.php 3 patches
Doc Comments   +7 added lines, -2 removed lines patch added patch discarded remove patch
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
 	 * @param string $parent name of tempalte containing $handle
157 157
 	 * @param string $handle name of part
158 158
 	 * @param string $name name of variable/placeholder
159
-	 * @return boolean
159
+	 * @return false|null
160 160
 	 */
161 161
 	function set_block($parent, $handle, $name = '')
162 162
 	{
@@ -311,6 +311,8 @@  discard block
 block discarded – undo
311 311
 
312 312
 	/**
313 313
 	 * This is short for finish parse
314
+	 * @param string $target
315
+	 * @param string $handle
314 316
 	 */
315 317
 	function fp($target, $handle, $append = False)
316 318
 	{
@@ -319,6 +321,8 @@  discard block
 block discarded – undo
319 321
 
320 322
 	/**
321 323
 	 * This is a short cut for print finish parse
324
+	 * @param string $target
325
+	 * @param string $handle
322 326
 	 */
323 327
 	function pfp($target, $handle, $append = False)
324 328
 	{
@@ -365,6 +369,7 @@  discard block
 block discarded – undo
365 369
 	 * Return undefined variables/placeholders of a handle
366 370
 	 *
367 371
 	 * @param string handle handle of a template
372
+	 * @param string $handle
368 373
 	 * @return array|boolean array with undefined variables as key and value, or false if none
369 374
 	 */
370 375
 	function get_undefined($handle)
@@ -564,7 +569,7 @@  discard block
 block discarded – undo
564 569
 	 * get template dir of an application
565 570
 	 *
566 571
 	 * @param $appname appication name optional can be derived from $GLOBALS['egw_info']['flags']['currentapp'];
567
-	 * @return string|boolean dir or false if no dir is found
572
+	 * @return string|false dir or false if no dir is found
568 573
 	 */
569 574
 	static function get_dir($appname = '')
570 575
 	{
Please login to merge, or discard this patch.
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
 	 *	- function-name like set_var to get eg. all assignments or
33 33
 	 *	- handle- / variable-names - if you are only interested in some variables ;-)
34 34
 	 */
35
-	var $debug = False;	// array('cat_list','cat_list_t');
35
+	var $debug = False; // array('cat_list','cat_list_t');
36 36
 
37 37
 	/**
38 38
 	 * $file[handle] = 'filename';
@@ -128,9 +128,9 @@  discard block
 block discarded – undo
128 128
 	 */
129 129
 	function set_file($handle, $filename = '')
130 130
 	{
131
-		if ($this->debug && $this->check_debug('set_file',$handle,$filename))
131
+		if ($this->debug && $this->check_debug('set_file', $handle, $filename))
132 132
 		{
133
-			echo "<p>Template::set_file('".print_r($handle,true)."','$filename')</p>\n";
133
+			echo "<p>Template::set_file('".print_r($handle, true)."','$filename')</p>\n";
134 134
 		}
135 135
 		if (!is_array($handle))
136 136
 		{
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
 		}
144 144
 		else
145 145
 		{
146
-			foreach($handle as $h => $f)
146
+			foreach ($handle as $h => $f)
147 147
 			{
148 148
 				$this->file[$h] = $this->filename($f);
149 149
 			}
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 	 */
161 161
 	function set_block($parent, $handle, $name = '')
162 162
 	{
163
-		if ($this->debug && $this->check_debug('set_block',$parent,$handle,$name))
163
+		if ($this->debug && $this->check_debug('set_block', $parent, $handle, $name))
164 164
 		{
165 165
 			echo "<p>Template::set_block('$parent','$handle','$name')</p>\n";
166 166
 		}
@@ -177,14 +177,14 @@  discard block
 block discarded – undo
177 177
 		$qhandle = preg_quote($handle);
178 178
 		$reg = "/<!--\\s+BEGIN $qhandle\\s+-->(.*)\n\\s*<!--\\s+END $qhandle\\s+-->/s";
179 179
 		$match = null;
180
-		if (!preg_match($reg,$str,$match))
180
+		if (!preg_match($reg, $str, $match))
181 181
 		{
182 182
 			// unfortunaly some apps set non-existing blocks, therefor I have to disable this diagnostics again for now
183 183
 			$this->halt("set_block: unable to find block '$handle' in '$parent'=<pre>".htmlspecialchars($str)."</pre> this->root=$this->root");
184 184
 			// return False;
185 185
 		}
186
-		$this->set_var($handle,$match[1]);
187
-		$this->set_var($parent,preg_replace($reg, '{' . "$name}",$str));
186
+		$this->set_var($handle, $match[1]);
187
+		$this->set_var($parent, preg_replace($reg, '{'."$name}", $str));
188 188
 	}
189 189
 
190 190
 	/* public: set_var(array $values)
@@ -205,18 +205,18 @@  discard block
 block discarded – undo
205 205
 				$varname => $value
206 206
 			);
207 207
 		}
208
-		foreach($varname as $k => $v)
208
+		foreach ($varname as $k => $v)
209 209
 		{
210 210
 			if (!empty($k))
211 211
 			{
212
-				if ($this->debug && $this->check_debug('set_var',$k))
212
+				if ($this->debug && $this->check_debug('set_var', $k))
213 213
 				{
214 214
 					echo "<p>Template::set_var('$k','$v')</p>\n";
215 215
 				}
216 216
 				$this->varkeys[$k] = $this->varname($k);
217 217
 				$this->varvals[$k] = $this->egroupware_hack ? str_replace(
218
-					array('phpGroupWare','www.phpgroupware.org'),
219
-					array('eGroupWare','www.eGroupWare.org'),$v
218
+					array('phpGroupWare', 'www.phpgroupware.org'),
219
+					array('eGroupWare', 'www.eGroupWare.org'), $v
220 220
 				) : $v;
221 221
 			}
222 222
 		}
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
 	 */
231 231
 	function subst($handle)
232 232
 	{
233
-		if ($this->debug && $this->check_debug('subst',$handle))
233
+		if ($this->debug && $this->check_debug('subst', $handle))
234 234
 		{
235 235
 			echo "<p>Template::subst('$handle')</p>\n";
236 236
 		}
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
 		}
242 242
 
243 243
 		$str = $this->get_var($handle);
244
-		foreach($this->varkeys as $k => $v)
244
+		foreach ($this->varkeys as $k => $v)
245 245
 		{
246 246
 			$str = str_replace($v, $this->varvals[$k], $str);
247 247
 		}
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
 			$str = $this->subst($handle);
277 277
 			if ($append)
278 278
 			{
279
-				$this->set_var($target, $this->get_var($target) . $str);
279
+				$this->set_var($target, $this->get_var($target).$str);
280 280
 			}
281 281
 			else
282 282
 			{
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
 		}
286 286
 		else
287 287
 		{
288
-			foreach($handle as $h)
288
+			foreach ($handle as $h)
289 289
 			{
290 290
 				$str = $this->subst($h);
291 291
 				$this->set_var($target, $str);
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
 	 */
333 333
 	function get_vars()
334 334
 	{
335
-		foreach(array_keys($this->varkeys) as $k)
335
+		foreach (array_keys($this->varkeys) as $k)
336 336
 		{
337 337
 			$result[$k] = $this->varvals[$k];
338 338
 		}
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
 		}
354 354
 		else
355 355
 		{
356
-			foreach(array_keys($varname) as $k)
356
+			foreach (array_keys($varname) as $k)
357 357
 			{
358 358
 				$result[$k] = $this->varvals[$k];
359 359
 			}
@@ -382,7 +382,7 @@  discard block
 block discarded – undo
382 382
 		{
383 383
 			return false;
384 384
 		}
385
-		foreach($m as $v)
385
+		foreach ($m as $v)
386 386
 		{
387 387
 			if (!isset($this->varkeys[$v]))
388 388
 			{
@@ -448,15 +448,15 @@  discard block
 block discarded – undo
448 448
 	 * @param string $root ='' default $this->root
449 449
 	 * @param int $time =1
450 450
 	 */
451
-	protected function filename($filename,$root='',$time=1)
451
+	protected function filename($filename, $root = '', $time = 1)
452 452
 	{
453
-		if($root == '')
453
+		if ($root == '')
454 454
 		{
455 455
 			$root = $this->root;
456 456
 		}
457
-		if(substr($filename, 0, 1) != '/')
457
+		if (substr($filename, 0, 1) != '/')
458 458
 		{
459
-			$new_filename = $root . '/' . $filename;
459
+			$new_filename = $root.'/'.$filename;
460 460
 		}
461 461
 		else
462 462
 		{
@@ -465,14 +465,14 @@  discard block
 block discarded – undo
465 465
 
466 466
 		if (!file_exists($new_filename))
467 467
 		{
468
-			if($time==2)
468
+			if ($time == 2)
469 469
 			{
470 470
 				$this->halt("filename: file $new_filename does not exist.");
471 471
 			}
472 472
 			else
473 473
 			{
474
-				$new_root = dirname($root) . DIRECTORY_SEPARATOR . 'default';
475
-				$new_filename = $this->filename(str_replace($root.'/','',$new_filename),$new_root,2);
474
+				$new_root = dirname($root).DIRECTORY_SEPARATOR.'default';
475
+				$new_filename = $this->filename(str_replace($root.'/', '', $new_filename), $new_root, 2);
476 476
 			}
477 477
 		}
478 478
 		return $new_filename;
@@ -491,9 +491,9 @@  discard block
 block discarded – undo
491 491
 	 */
492 492
 	function loadfile($handle)
493 493
 	{
494
-		if ($this->debug && $this->check_debug('loadfile',$handle))
494
+		if ($this->debug && $this->check_debug('loadfile', $handle))
495 495
 		{
496
-			echo "<p>Template::loadfile('$handle') file=<pre>\n".print_r($this->file,True)."</pre>\n";
496
+			echo "<p>Template::loadfile('$handle') file=<pre>\n".print_r($this->file, True)."</pre>\n";
497 497
 			echo "<p>backtrace: ".function_backtrace()."</p>\n";
498 498
 		}
499 499
 		if (isset($this->varkeys[$handle]) && !empty($this->varvals[$handle]))
@@ -502,9 +502,9 @@  discard block
 block discarded – undo
502 502
 		}
503 503
 		if (!isset($this->file[$handle]))
504 504
 		{
505
-			if ($this->debug && $this->check_debug('loadfile',$handle))
505
+			if ($this->debug && $this->check_debug('loadfile', $handle))
506 506
 			{
507
-				echo "varkeys =<pre>".print_r($this->varkeys,True)."</pre>varvals =<pre>".print_r($this->varvals,True)."</pre>\n";
507
+				echo "varkeys =<pre>".print_r($this->varkeys, True)."</pre>varvals =<pre>".print_r($this->varvals, True)."</pre>\n";
508 508
 			}
509 509
 			$this->halt("loadfile: $handle is not a valid handle.");
510 510
 			return false;
@@ -549,10 +549,10 @@  discard block
 block discarded – undo
549 549
 	{
550 550
 		if (!$this->debug) return False;
551 551
 
552
-		foreach(func_get_args() as $arg)
552
+		foreach (func_get_args() as $arg)
553 553
 		{
554 554
 			if (!is_array($this->debug) && $this->debug === $arg ||
555
-				(is_array($this->debug) && (@$this->debug[$arg] || in_array($arg,$this->debug,True))))
555
+				(is_array($this->debug) && (@$this->debug[$arg] || in_array($arg, $this->debug, True))))
556 556
 			{
557 557
 				return True;
558 558
 			}
@@ -601,8 +601,8 @@  discard block
 block discarded – undo
601 601
 		{
602 602
 			$GLOBALS['egw_info']['server']['template_set'] = 'idots';
603 603
 		}
604
-		$tpldir         = EGW_SERVER_ROOT . '/' . $appname . '/templates/' . $GLOBALS['egw_info']['server']['template_set'];
605
-		$tpldir_default = EGW_SERVER_ROOT . '/' . $appname . '/templates/default';
604
+		$tpldir         = EGW_SERVER_ROOT.'/'.$appname.'/templates/'.$GLOBALS['egw_info']['server']['template_set'];
605
+		$tpldir_default = EGW_SERVER_ROOT.'/'.$appname.'/templates/default';
606 606
 
607 607
 		if (@is_dir($tpldir))
608 608
 		{
Please login to merge, or discard this patch.
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -547,7 +547,10 @@
 block discarded – undo
547 547
 
548 548
 	function check_debug()
549 549
 	{
550
-		if (!$this->debug) return False;
550
+		if (!$this->debug)
551
+		{
552
+			return False;
553
+		}
551 554
 
552 555
 		foreach(func_get_args() as $arg)
553 556
 		{
Please login to merge, or discard this patch.
api/src/Framework/Updates.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@
 block discarded – undo
38 38
 	/**
39 39
 	 * Get versions of available updates
40 40
 	 *
41
-	 * @return array verions for keys "current" and "security"
41
+	 * @return string verions for keys "current" and "security"
42 42
 	 */
43 43
 	public static function available()
44 44
 	{
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -51,8 +51,8 @@  discard block
 block discarded – undo
51 51
 				list($current, $security) = explode("\n", $remote);
52 52
 				if (empty($security)) $security = $current;
53 53
 				$versions = array(
54
-					'current'  => $current,		// last maintenance update
55
-					'security' => $security,	// last security update
54
+					'current'  => $current, // last maintenance update
55
+					'security' => $security, // last security update
56 56
 				);
57 57
 			}
58 58
 			return $versions;
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 	 */
114 114
 	protected static function update_older($version, $days)
115 115
 	{
116
-		list(,,$date) = explode('.', $version);
116
+		list(,, $date) = explode('.', $version);
117 117
 		if ($date < 20140000) return false;
118 118
 		$version_timestamp = mktime(0, 0, 0, (int)substr($date, 4, 2), (int)substr($date, -2), (int)substr($date, 0, 4));
119 119
 
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 	 * @param string &$changelog on return path to changelog
127 127
 	 * @return string
128 128
 	 */
129
-	public static function api_version(&$changelog=null)
129
+	public static function api_version(&$changelog = null)
130 130
 	{
131 131
 		$changelog = EGW_SERVER_ROOT.'/doc/rpm-build/debian.changes';
132 132
 
Please login to merge, or discard this patch.
Braces   +8 added lines, -2 removed lines patch added patch discarded remove patch
@@ -49,7 +49,10 @@  discard block
 block discarded – undo
49 49
 			if (($remote = file_get_contents(self::CURRENT_VERSION_URL, false, Api\Framework::proxy_context())))
50 50
 			{
51 51
 				list($current, $security) = explode("\n", $remote);
52
-				if (empty($security)) $security = $current;
52
+				if (empty($security))
53
+				{
54
+					$security = $current;
55
+				}
53 56
 				$versions = array(
54 57
 					'current'  => $current,		// last maintenance update
55 58
 					'security' => $security,	// last security update
@@ -114,7 +117,10 @@  discard block
 block discarded – undo
114 117
 	protected static function update_older($version, $days)
115 118
 	{
116 119
 		list(,,$date) = explode('.', $version);
117
-		if ($date < 20140000) return false;
120
+		if ($date < 20140000)
121
+		{
122
+			return false;
123
+		}
118 124
 		$version_timestamp = mktime(0, 0, 0, (int)substr($date, 4, 2), (int)substr($date, -2), (int)substr($date, 0, 4));
119 125
 
120 126
 		return (time() - $version_timestamp) / 86400 > $days;
Please login to merge, or discard this patch.
api/src/Header/Authenticate.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -234,7 +234,7 @@
 block discarded – undo
234 234
 	 * @param string $realm
235 235
 	 * @param string $username
236 236
 	 * @param string &$password=null password to use or if null, on return stored password
237
-	 * @return string|boolean false if $password not given and can NOT be read
237
+	 * @return false|string false if $password not given and can NOT be read
238 238
 	 */
239 239
 	static private function get_digest_A1($realm,$username,&$password=null)
240 240
 	{
Please login to merge, or discard this patch.
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -255,20 +255,20 @@
 block discarded – undo
255 255
 	 */
256 256
 	static public function parse_digest($txt)
257 257
 	{
258
-	    // protect against missing data
259
-	    $needed_parts = array('nonce'=>1, 'nc'=>1, 'cnonce'=>1, 'qop'=>1, 'username'=>1, 'uri'=>1, 'response'=>1);
260
-	    $data = array();
261
-	    $keys = implode('|', array_keys($needed_parts));
258
+		// protect against missing data
259
+		$needed_parts = array('nonce'=>1, 'nc'=>1, 'cnonce'=>1, 'qop'=>1, 'username'=>1, 'uri'=>1, 'response'=>1);
260
+		$data = array();
261
+		$keys = implode('|', array_keys($needed_parts));
262 262
 
263 263
 		$matches = null;
264
-	    preg_match_all('@(' . $keys . ')=(?:([\'"])([^\2]+?)\2|([^\s,]+))@', $txt, $matches, PREG_SET_ORDER);
264
+		preg_match_all('@(' . $keys . ')=(?:([\'"])([^\2]+?)\2|([^\s,]+))@', $txt, $matches, PREG_SET_ORDER);
265 265
 
266
-	    foreach ($matches as $m)
267
-	    {
268
-	        $data[$m[1]] = $m[3] ? $m[3] : $m[4];
269
-	        unset($needed_parts[$m[1]]);
270
-	    }
271
-	    //error_log(__METHOD__."('$txt') returning ".array2string($needed_parts ? false : $data));
272
-	    return $needed_parts ? false : $data;
266
+		foreach ($matches as $m)
267
+		{
268
+			$data[$m[1]] = $m[3] ? $m[3] : $m[4];
269
+			unset($needed_parts[$m[1]]);
270
+		}
271
+		//error_log(__METHOD__."('$txt') returning ".array2string($needed_parts ? false : $data));
272
+		return $needed_parts ? false : $data;
273 273
 	}
274 274
 }
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 	 */
76 76
 	static public function autocreate_session_callback(&$account)
77 77
 	{
78
-		unset($account);	// not used, but required by function signature
78
+		unset($account); // not used, but required by function signature
79 79
 		if (self::ERROR_LOG)
80 80
 		{
81 81
 			$pw = self::ERROR_LOG > 1 ? $_SERVER['PHP_AUTH_PW'] : '**********';
@@ -86,15 +86,15 @@  discard block
 block discarded – undo
86 86
 
87 87
 		$username = $_SERVER['PHP_AUTH_USER']; $password = $_SERVER['PHP_AUTH_PW'];
88 88
 		// Support for basic auth when using PHP CGI (what about digest auth?)
89
-		if (!isset($username) && !empty($_SERVER['REDIRECT_HTTP_AUTHORIZATION']) && strpos($_SERVER['REDIRECT_HTTP_AUTHORIZATION'],'Basic ') === 0)
89
+		if (!isset($username) && !empty($_SERVER['REDIRECT_HTTP_AUTHORIZATION']) && strpos($_SERVER['REDIRECT_HTTP_AUTHORIZATION'], 'Basic ') === 0)
90 90
 		{
91
-			$hash = base64_decode(substr($_SERVER['REDIRECT_HTTP_AUTHORIZATION'],6));
91
+			$hash = base64_decode(substr($_SERVER['REDIRECT_HTTP_AUTHORIZATION'], 6));
92 92
 			if (strpos($hash, ':') !== false)
93 93
 			{
94 94
 				list($username, $password) = explode(':', $hash, 2);
95 95
 			}
96 96
 		}
97
-		elseif (isset($_SERVER['PHP_AUTH_DIGEST']) && !self::is_valid($realm,$_SERVER['PHP_AUTH_DIGEST'],$username,$password))
97
+		elseif (isset($_SERVER['PHP_AUTH_DIGEST']) && !self::is_valid($realm, $_SERVER['PHP_AUTH_DIGEST'], $username, $password))
98 98
 		{
99 99
 			unset($password);
100 100
 		}
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
 			// if the session class gives a reason why the login failed --> append it to the REALM
112 112
 			if ($GLOBALS['egw']->session->reason) $realm .= ': '.$GLOBALS['egw']->session->reason;
113 113
 
114
-			header('WWW-Authenticate: Basic realm="'.$realm.'"');// draft-reschke-basicauth-enc-06 adds, accept-charset="'.translation::charset().'"');
114
+			header('WWW-Authenticate: Basic realm="'.$realm.'"'); // draft-reschke-basicauth-enc-06 adds, accept-charset="'.translation::charset().'"');
115 115
 			self::digest_header($realm);
116 116
 			header('HTTP/1.1 401 Unauthorized');
117 117
 			header('X-WebDAV-Status: 401 Unauthorized', true);
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
 			// replace \x encoded non-ascii chars in password, as they are used eg. by Thunderbird for German umlauts
136 136
 			if (strpos($password, '\\x') !== false)
137 137
 			{
138
-				$password = preg_replace_callback('/\\\\x([0-9A-F]{2})/i', function($matches){
138
+				$password = preg_replace_callback('/\\\\x([0-9A-F]{2})/i', function($matches) {
139 139
 					return chr(hexdec($matches[1]));
140 140
 				}, $password);
141 141
 			}
@@ -157,24 +157,24 @@  discard block
 block discarded – undo
157 157
 	 * @param string &$user_pw =null stored cleartext password, if $username given AND function returns true
158 158
 	 * @return boolean true if digest auth is available, false otherwise
159 159
 	 */
160
-	static public function digest_auth_available($realm,$username=null,&$user_pw=null)
160
+	static public function digest_auth_available($realm, $username = null, &$user_pw = null)
161 161
 	{
162 162
 		// we currently require plaintext passwords!
163 163
 		if (!($GLOBALS['egw_info']['server']['auth_type'] == 'sql' && $GLOBALS['egw_info']['server']['sql_encryption_type'] == 'plain') ||
164 164
 			  $GLOBALS['egw_info']['server']['auth_type'] == 'ldap' && $GLOBALS['egw_info']['server']['ldap_encryption_type'] == 'plain')
165 165
 		{
166 166
 			if (self::ERROR_LOG) error_log(__METHOD__."('$username') return false (no plaintext passwords used)");
167
-			return false;	// no plain-text passwords used
167
+			return false; // no plain-text passwords used
168 168
 		}
169 169
 		// check for specific user, if given
170
-		if (!is_null($username) && !(($user_pw = $GLOBALS['egw']->accounts->id2name($username,'account_pwd','u')) ||
171
-			$GLOBALS['egw_info']['server']['auth_type'] == 'sql' && substr($user_pw,0,7) != '{PLAIN}'))
170
+		if (!is_null($username) && !(($user_pw = $GLOBALS['egw']->accounts->id2name($username, 'account_pwd', 'u')) ||
171
+			$GLOBALS['egw_info']['server']['auth_type'] == 'sql' && substr($user_pw, 0, 7) != '{PLAIN}'))
172 172
 		{
173 173
 			unset($user_pw);
174 174
 			if (self::ERROR_LOG) error_log(__METHOD__."('$realm','$username') return false (unknown user or NO plaintext password for user)");
175
-			return false;	// user does NOT exist, or has no plaintext passwords (ldap server requires real root_dn or special ACL!)
175
+			return false; // user does NOT exist, or has no plaintext passwords (ldap server requires real root_dn or special ACL!)
176 176
 		}
177
-		if (substr($user_pw,0,7) == '{PLAIN}') $user_pw = substr($user_pw,7);
177
+		if (substr($user_pw, 0, 7) == '{PLAIN}') $user_pw = substr($user_pw, 7);
178 178
 
179 179
 		if (self::ERROR_LOG)
180 180
 		{
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
 	 * @param string $realm
191 191
 	 * @param string &$nonce=null on return
192 192
 	 */
193
-	static public function digest_header($realm,&$nonce=null)
193
+	static public function digest_header($realm, &$nonce = null)
194 194
 	{
195 195
 		if (self::digest_auth_available($realm))
196 196
 		{
@@ -209,13 +209,13 @@  discard block
 block discarded – undo
209 209
 	 * @param string &$password on return cleartext password
210 210
 	 * @return boolean true if digest is correct, false otherwise
211 211
 	 */
212
-	static public function is_valid($realm,$auth_digest=null,&$username=null,&$password=null)
212
+	static public function is_valid($realm, $auth_digest = null, &$username = null, &$password = null)
213 213
 	{
214 214
 		if (is_null($auth_digest)) $auth_digest = $_SERVER['PHP_AUTH_DIGEST'];
215 215
 
216 216
 		$data = self::parse_digest($auth_digest);
217 217
 
218
-		if (!$data || !($A1 = self::get_digest_A1($realm,$username=$data['username'],$password=null)))
218
+		if (!$data || !($A1 = self::get_digest_A1($realm, $username = $data['username'], $password = null)))
219 219
 		{
220 220
 			error_log(__METHOD__."('$realm','$auth_digest','$username') returning FALSE");
221 221
 			return false;
@@ -236,16 +236,16 @@  discard block
 block discarded – undo
236 236
 	 * @param string &$password=null password to use or if null, on return stored password
237 237
 	 * @return string|boolean false if $password not given and can NOT be read
238 238
 	 */
239
-	static private function get_digest_A1($realm,$username,&$password=null)
239
+	static private function get_digest_A1($realm, $username, &$password = null)
240 240
 	{
241 241
 		$user_pw = null;
242
-		if (empty($username) || empty($realm) || !self::digest_auth_available($realm,$username,$user_pw))
242
+		if (empty($username) || empty($realm) || !self::digest_auth_available($realm, $username, $user_pw))
243 243
 		{
244 244
 			return false;
245 245
 		}
246 246
 		if (is_null($password)) $password = $user_pw;
247 247
 
248
-		$A1 = md5($username . ':' . $realm . ':' . $password);
248
+		$A1 = md5($username.':'.$realm.':'.$password);
249 249
 		if (self::ERROR_LOG > 1) error_log(__METHOD__."('$realm','$username','$password') returning ".array2string($A1));
250 250
 		return $A1;
251 251
 	}
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
 	    $keys = implode('|', array_keys($needed_parts));
262 262
 
263 263
 		$matches = null;
264
-	    preg_match_all('@(' . $keys . ')=(?:([\'"])([^\2]+?)\2|([^\s,]+))@', $txt, $matches, PREG_SET_ORDER);
264
+	    preg_match_all('@('.$keys.')=(?:([\'"])([^\2]+?)\2|([^\s,]+))@', $txt, $matches, PREG_SET_ORDER);
265 265
 
266 266
 	    foreach ($matches as $m)
267 267
 	    {
Please login to merge, or discard this patch.
Braces   +42 added lines, -11 removed lines patch added patch discarded remove patch
@@ -82,7 +82,10 @@  discard block
 block discarded – undo
82 82
 			error_log(__METHOD__.'() PHP_AUTH_USER='.array2string($_SERVER['PHP_AUTH_USER']).', PHP_AUTH_PW='.array2string($pw).', PHP_AUTH_DIGEST='.array2string($_SERVER['PHP_AUTH_DIGEST']));
83 83
 		}
84 84
 		$realm = $GLOBALS['egw_info']['flags']['auth_realm'];
85
-		if (empty($realm)) $realm = 'EGroupware';
85
+		if (empty($realm))
86
+		{
87
+			$realm = 'EGroupware';
88
+		}
86 89
 
87 90
 		$username = $_SERVER['PHP_AUTH_USER']; $password = $_SERVER['PHP_AUTH_PW'];
88 91
 		// Support for basic auth when using PHP CGI (what about digest auth?)
@@ -109,7 +112,10 @@  discard block
 block discarded – undo
109 112
 		if (!isset($username) || !($sessionid = $GLOBALS['egw']->session->create($username, $password, 'text', true)))
110 113
 		{
111 114
 			// if the session class gives a reason why the login failed --> append it to the REALM
112
-			if ($GLOBALS['egw']->session->reason) $realm .= ': '.$GLOBALS['egw']->session->reason;
115
+			if ($GLOBALS['egw']->session->reason)
116
+			{
117
+				$realm .= ': '.$GLOBALS['egw']->session->reason;
118
+			}
113 119
 
114 120
 			header('WWW-Authenticate: Basic realm="'.$realm.'"');// draft-reschke-basicauth-enc-06 adds, accept-charset="'.translation::charset().'"');
115 121
 			self::digest_header($realm);
@@ -135,7 +141,8 @@  discard block
 block discarded – undo
135 141
 			// replace \x encoded non-ascii chars in password, as they are used eg. by Thunderbird for German umlauts
136 142
 			if (strpos($password, '\\x') !== false)
137 143
 			{
138
-				$password = preg_replace_callback('/\\\\x([0-9A-F]{2})/i', function($matches){
144
+				$password = preg_replace_callback('/\\\\x([0-9A-F]{2})/i', function($matches)
145
+				{
139 146
 					return chr(hexdec($matches[1]));
140 147
 				}, $password);
141 148
 			}
@@ -163,7 +170,10 @@  discard block
 block discarded – undo
163 170
 		if (!($GLOBALS['egw_info']['server']['auth_type'] == 'sql' && $GLOBALS['egw_info']['server']['sql_encryption_type'] == 'plain') ||
164 171
 			  $GLOBALS['egw_info']['server']['auth_type'] == 'ldap' && $GLOBALS['egw_info']['server']['ldap_encryption_type'] == 'plain')
165 172
 		{
166
-			if (self::ERROR_LOG) error_log(__METHOD__."('$username') return false (no plaintext passwords used)");
173
+			if (self::ERROR_LOG)
174
+			{
175
+				error_log(__METHOD__."('$username') return false (no plaintext passwords used)");
176
+			}
167 177
 			return false;	// no plain-text passwords used
168 178
 		}
169 179
 		// check for specific user, if given
@@ -171,10 +181,16 @@  discard block
 block discarded – undo
171 181
 			$GLOBALS['egw_info']['server']['auth_type'] == 'sql' && substr($user_pw,0,7) != '{PLAIN}'))
172 182
 		{
173 183
 			unset($user_pw);
174
-			if (self::ERROR_LOG) error_log(__METHOD__."('$realm','$username') return false (unknown user or NO plaintext password for user)");
184
+			if (self::ERROR_LOG)
185
+			{
186
+				error_log(__METHOD__."('$realm','$username') return false (unknown user or NO plaintext password for user)");
187
+			}
175 188
 			return false;	// user does NOT exist, or has no plaintext passwords (ldap server requires real root_dn or special ACL!)
176 189
 		}
177
-		if (substr($user_pw,0,7) == '{PLAIN}') $user_pw = substr($user_pw,7);
190
+		if (substr($user_pw,0,7) == '{PLAIN}')
191
+		{
192
+			$user_pw = substr($user_pw,7);
193
+		}
178 194
 
179 195
 		if (self::ERROR_LOG)
180 196
 		{
@@ -196,7 +212,10 @@  discard block
 block discarded – undo
196 212
 		{
197 213
 			$nonce = uniqid();
198 214
    			header('WWW-Authenticate: Digest realm="'.$realm.'",qop="auth",nonce="'.$nonce.'",opaque="'.md5($realm).'"');
199
-			if (self::ERROR_LOG) error_log(__METHOD__."() offering digest auth for realm '$realm' using nonce='$nonce'");
215
+			if (self::ERROR_LOG)
216
+			{
217
+				error_log(__METHOD__."() offering digest auth for realm '$realm' using nonce='$nonce'");
218
+			}
200 219
 		}
201 220
 	}
202 221
 
@@ -211,7 +230,10 @@  discard block
 block discarded – undo
211 230
 	 */
212 231
 	static public function is_valid($realm,$auth_digest=null,&$username=null,&$password=null)
213 232
 	{
214
-		if (is_null($auth_digest)) $auth_digest = $_SERVER['PHP_AUTH_DIGEST'];
233
+		if (is_null($auth_digest))
234
+		{
235
+			$auth_digest = $_SERVER['PHP_AUTH_DIGEST'];
236
+		}
215 237
 
216 238
 		$data = self::parse_digest($auth_digest);
217 239
 
@@ -224,7 +246,10 @@  discard block
 block discarded – undo
224 246
 
225 247
 		$valid_response = md5($A1.':'.$data['nonce'].':'.$data['nc'].':'.$data['cnonce'].':'.$data['qop'].':'.$A2);
226 248
 
227
-		if (self::ERROR_LOG) error_log(__METHOD__."('$realm','$auth_digest','$username') response='$data[response]', valid_response='$valid_response' returning ".array2string($data['response'] === $valid_response));
249
+		if (self::ERROR_LOG)
250
+		{
251
+			error_log(__METHOD__."('$realm','$auth_digest','$username') response='$data[response]', valid_response='$valid_response' returning ".array2string($data['response'] === $valid_response));
252
+		}
228 253
 		return $data['response'] === $valid_response;
229 254
 	}
230 255
 
@@ -243,10 +268,16 @@  discard block
 block discarded – undo
243 268
 		{
244 269
 			return false;
245 270
 		}
246
-		if (is_null($password)) $password = $user_pw;
271
+		if (is_null($password))
272
+		{
273
+			$password = $user_pw;
274
+		}
247 275
 
248 276
 		$A1 = md5($username . ':' . $realm . ':' . $password);
249
-		if (self::ERROR_LOG > 1) error_log(__METHOD__."('$realm','$username','$password') returning ".array2string($A1));
277
+		if (self::ERROR_LOG > 1)
278
+		{
279
+			error_log(__METHOD__."('$realm','$username','$password') returning ".array2string($A1));
280
+		}
250 281
 		return $A1;
251 282
 	}
252 283
 
Please login to merge, or discard this patch.
api/src/Header/ContentSecurityPolicy.php 3 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -41,7 +41,6 @@
 block discarded – undo
41 41
 	 *
42 42
 	 * Calling this method with an empty array for frame-src, sets no defaults but "'self'"!
43 43
 	 *
44
-	 * @param string|array $set =array() URL (incl. protocol!)
45 44
 	 * @param string $source valid CSP source types like 'script-src', 'style-src', 'connect-src', 'frame-src', ...
46 45
 	 * @param string|array $attrs 'unsafe-eval' and/or 'unsafe-inline' (without quotes!) or URL (incl. protocol!)
47 46
 	 */
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 		'script-src'  => array("'unsafe-eval'"),
34 34
 		'style-src'   => array("'unsafe-inline'"),
35 35
 		'connect-src' => array(),
36
-		'frame-src'   => null,	// NOT array(), to allow setting no default frame-src!
36
+		'frame-src'   => null, // NOT array(), to allow setting no default frame-src!
37 37
 	);
38 38
 
39 39
 	/**
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 				$attrs = array('www.egroupware.org');
56 56
 				if (($app_additional = Api\Hooks::process('csp-frame-src')))
57 57
 				{
58
-					foreach($app_additional as $addtional)
58
+					foreach ($app_additional as $addtional)
59 59
 					{
60 60
 						if ($addtional) $attrs = array_unique(array_merge($attrs, $addtional));
61 61
 					}
@@ -63,11 +63,11 @@  discard block
 block discarded – undo
63 63
 			}
64 64
 			self::$sources[$source] = array();
65 65
 		}
66
-		foreach((array)$attrs as $attr)
66
+		foreach ((array)$attrs as $attr)
67 67
 		{
68 68
 			if (in_array($attr, array('none', 'self', 'unsafe-eval', 'unsafe-inline')))
69 69
 			{
70
-				$attr = "'$attr'";	// automatic add quotes
70
+				$attr = "'$attr'"; // automatic add quotes
71 71
 			}
72 72
 			if (!in_array($attr, self::$sources[$source]))
73 73
 			{
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 	 *
89 89
 	 * @param string|array $set =array() 'unsafe-eval' and/or 'unsafe-inline' (without quotes!) or URL (incl. protocol!)
90 90
 	 */
91
-	public static function add_script_src($set=null)
91
+	public static function add_script_src($set = null)
92 92
 	{
93 93
 		self::add('script-src', $set);
94 94
 	}
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 	 *
101 101
 	 * @param string|array $set =array() 'unsafe-inline' (without quotes!) and/or URL (incl. protocol!)
102 102
 	 */
103
-	public static function add_style_src($set=null)
103
+	public static function add_style_src($set = null)
104 104
 	{
105 105
 		self::add('style-src', $set);
106 106
 	}
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 	 *
111 111
 	 * @param string|array $set =array() URL (incl. protocol!)
112 112
 	 */
113
-	public static function add_connect_src($set=null)
113
+	public static function add_connect_src($set = null)
114 114
 	{
115 115
 		self::add('connect-src', $set);
116 116
 	}
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
 	 * @param string|array $set =array() URL (incl. protocol!)
124 124
 	 * @return string with attributes eg. "'unsafe-inline'"
125 125
 	 */
126
-	public static function add_frame_src($set=null)
126
+	public static function add_frame_src($set = null)
127 127
 	{
128 128
 		self::add('frame-src', $set);
129 129
 	}
@@ -135,10 +135,10 @@  discard block
 block discarded – undo
135 135
 	 */
136 136
 	public static function send()
137 137
 	{
138
-		self::add('frame-src', null);	// set defaults for frame-src
138
+		self::add('frame-src', null); // set defaults for frame-src
139 139
 
140 140
 		$policies = array();
141
-		foreach(self::$sources as $source => $urls)
141
+		foreach (self::$sources as $source => $urls)
142 142
 		{
143 143
 			$policies[] = "$source 'self' ".implode(' ', $urls);
144 144
 		}
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
 		// recommendaton ist to not send regular AND deprecated headers together, as they can cause unexpected behavior
153 153
 		if ($user_agent == 'chrome' && $version < 25 || $user_agent == 'safari' && $version < 7)
154 154
 		{
155
-			header("X-Webkit-CSP: $csp");	// Chrome: <= 24, Safari incl. iOS
155
+			header("X-Webkit-CSP: $csp"); // Chrome: <= 24, Safari incl. iOS
156 156
 		}
157 157
 		elseif ($user_agent == 'firefox' && $version < 23 || $user_agent == 'msie')	// Edge is reported as 'edge'!
158 158
 		{
Please login to merge, or discard this patch.
Braces   +8 added lines, -2 removed lines patch added patch discarded remove patch
@@ -57,7 +57,10 @@  discard block
 block discarded – undo
57 57
 				{
58 58
 					foreach($app_additional as $addtional)
59 59
 					{
60
-						if ($addtional) $attrs = array_unique(array_merge($attrs, $addtional));
60
+						if ($addtional)
61
+						{
62
+							$attrs = array_unique(array_merge($attrs, $addtional));
63
+						}
61 64
 					}
62 65
 				}
63 66
 			}
@@ -154,10 +157,13 @@  discard block
 block discarded – undo
154 157
 		{
155 158
 			header("X-Webkit-CSP: $csp");	// Chrome: <= 24, Safari incl. iOS
156 159
 		}
157
-		elseif ($user_agent == 'firefox' && $version < 23 || $user_agent == 'msie')	// Edge is reported as 'edge'!
160
+		elseif ($user_agent == 'firefox' && $version < 23 || $user_agent == 'msie')
161
+		{
162
+			// Edge is reported as 'edge'!
158 163
 		{
159 164
 			header("X-Content-Security-Policy: $csp");
160 165
 		}
166
+		}
161 167
 		else
162 168
 		{
163 169
 			header("Content-Security-Policy: $csp");
Please login to merge, or discard this patch.
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.
Spacing   +14 added lines, -14 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
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
 		}
150 150
 
151 151
 		// hooks only existing in filesystem used by setup
152
-		if (!$ret && $try_unregistered && file_exists(EGW_SERVER_ROOT.($hook='/'.$appname.'/inc/hook_'.$location.'.inc.php')))
152
+		if (!$ret && $try_unregistered && file_exists(EGW_SERVER_ROOT.($hook = '/'.$appname.'/inc/hook_'.$location.'.inc.php')))
153 153
 		{
154 154
 			include(EGW_SERVER_ROOT.$hook);
155 155
 			return true;
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 	 * @param boolean $return_methods =false true: return hook-method(s)
182 182
 	 * @return int|array the number of found hooks or for $return_methods array with methods
183 183
 	 */
184
-	public static function exists($location, $app, $return_methods=false)
184
+	public static function exists($location, $app, $return_methods = false)
185 185
 	{
186 186
 		if (!isset(self::$locations)) self::read();
187 187
 
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
 	 *
209 209
 	 * @param boolan $force_rescan =false true: do not use instance cache
210 210
 	 */
211
-	public static function read($force_rescan=false)
211
+	public static function read($force_rescan = false)
212 212
 	{
213 213
 		//$starttime = microtime(true);
214 214
 		if ($force_rescan) Cache::unsetInstance(__CLASS__, 'locations');
@@ -224,18 +224,18 @@  discard block
 block discarded – undo
224 224
 
225 225
 			// read all apps using just filesystem data
226 226
 			$locations = array();
227
-			foreach(array_merge(array('api'), array_keys($GLOBALS['egw_info']['apps'])) as $appname)
227
+			foreach (array_merge(array('api'), array_keys($GLOBALS['egw_info']['apps'])) as $appname)
228 228
 			{
229 229
 				if ($appname[0] == '.' || !is_dir(EGW_SERVER_ROOT.'/'.$appname)) continue;
230 230
 
231
-				$f = EGW_SERVER_ROOT . '/' . $appname . '/setup/setup.inc.php';
231
+				$f = EGW_SERVER_ROOT.'/'.$appname.'/setup/setup.inc.php';
232 232
 				$setup_info = array($appname => array());
233
-				if(@file_exists($f)) include($f);
233
+				if (@file_exists($f)) include($f);
234 234
 
235 235
 				// some apps have setup_info for more then themselfs (eg. api for groupdav)
236
-				foreach($setup_info as $appname => $data)
236
+				foreach ($setup_info as $appname => $data)
237 237
 				{
238
-					foreach((array)$data['hooks'] as $location => $methods)
238
+					foreach ((array)$data['hooks'] as $location => $methods)
239 239
 					{
240 240
 						if (is_int($location))
241 241
 						{
Please login to merge, or discard this patch.
Braces   +53 added lines, -13 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
@@ -155,7 +171,10 @@  discard block
 block discarded – undo
155 171
 			return true;
156 172
 		}
157 173
 
158
-		if (!$ret) return false;
174
+		if (!$ret)
175
+		{
176
+			return false;
177
+		}
159 178
 
160 179
 		return count($ret) == 1 ? $ret[0] : $ret;
161 180
 	}
@@ -168,7 +187,10 @@  discard block
 block discarded – undo
168 187
 	 */
169 188
 	public static function count($location)
170 189
 	{
171
-		if (!isset(self::$locations)) self::read();
190
+		if (!isset(self::$locations))
191
+		{
192
+			self::read();
193
+		}
172 194
 
173 195
 		return count(self::$locations[$location]);
174 196
 	}
@@ -183,7 +205,10 @@  discard block
 block discarded – undo
183 205
 	 */
184 206
 	public static function exists($location, $app, $return_methods=false)
185 207
 	{
186
-		if (!isset(self::$locations)) self::read();
208
+		if (!isset(self::$locations))
209
+		{
210
+			self::read();
211
+		}
187 212
 
188 213
 		//error_log(__METHOD__.__LINE__.array2string(self::$locations[$location]));
189 214
 		return $return_methods ? self::$locations[$location][$app] : count(self::$locations[$location][$app]);
@@ -197,7 +222,10 @@  discard block
 block discarded – undo
197 222
 	 */
198 223
 	public static function implemented($location)
199 224
 	{
200
-		if (!isset(self::$locations)) self::read();
225
+		if (!isset(self::$locations))
226
+		{
227
+			self::read();
228
+		}
201 229
 
202 230
 		//error_log(__METHOD__.__LINE__.array2string(self::$locations[$location]));
203 231
 		return isset(self::$locations[$location]) ? array_keys(self::$locations[$location]) : array();
@@ -211,7 +239,10 @@  discard block
 block discarded – undo
211 239
 	public static function read($force_rescan=false)
212 240
 	{
213 241
 		//$starttime = microtime(true);
214
-		if ($force_rescan) Cache::unsetInstance(__CLASS__, 'locations');
242
+		if ($force_rescan)
243
+		{
244
+			Cache::unsetInstance(__CLASS__, 'locations');
245
+		}
215 246
 
216 247
 		self::$locations = Cache::getInstance(__CLASS__, 'locations', function()
217 248
 		{
@@ -226,11 +257,17 @@  discard block
 block discarded – undo
226 257
 			$locations = array();
227 258
 			foreach(array_merge(array('api'), array_keys($GLOBALS['egw_info']['apps'])) as $appname)
228 259
 			{
229
-				if ($appname[0] == '.' || !is_dir(EGW_SERVER_ROOT.'/'.$appname)) continue;
260
+				if ($appname[0] == '.' || !is_dir(EGW_SERVER_ROOT.'/'.$appname))
261
+				{
262
+					continue;
263
+				}
230 264
 
231 265
 				$f = EGW_SERVER_ROOT . '/' . $appname . '/setup/setup.inc.php';
232 266
 				$setup_info = array($appname => array());
233
-				if(@file_exists($f)) include($f);
267
+				if(@file_exists($f))
268
+				{
269
+					include($f);
270
+				}
234 271
 
235 272
 				// some apps have setup_info for more then themselfs (eg. api for groupdav)
236 273
 				foreach($setup_info as $appname => $data)
@@ -258,7 +295,10 @@  discard block
 block discarded – undo
258 295
 	 */
259 296
 	public static function pgp_encryption_menu($appname)
260 297
 	{
261
-		if (Header\UserAgent::mobile()) return;
298
+		if (Header\UserAgent::mobile())
299
+		{
300
+			return;
301
+		}
262 302
 
263 303
 		// PGP Encryption (Mailvelope plugin) restore/backup menu
264 304
 		$file = Array(
Please login to merge, or discard this patch.
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -464,7 +464,7 @@
 block discarded – undo
464 464
 	{
465 465
 		unset($args);	// unused, but required by function signature
466 466
 		$appname = 'preferences';
467
-		$file = Array(
467
+		$file = array(
468 468
 			'Site configuration' => Egw::link('/index.php','menuaction=admin.admin_config.index&appname=' . $appname.'&ajax=true'),
469 469
 		);
470 470
 		display_section($appname, $file);
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   +179 added lines, -179 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() {\$j(function() {if(\$j().chosen) \$j('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,16 +439,16 @@  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
451
-		Framework::includeJS('ckeditor','ckeditor','phpgwapi');
451
+		Framework::includeJS('ckeditor', 'ckeditor', 'phpgwapi');
452 452
 
453 453
 		// run content through htmlpurifier
454 454
 		if ($_purify && !empty($_content))
@@ -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'].'/api/js/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,11 +865,11 @@  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
 
@@ -879,7 +879,7 @@  discard block
 block discarded – undo
879 879
 		}
880 880
 		return '<div class="onlyPrint">'.$title.'</div><div class="noPrint" title="'.$title.'" '.$options.
881 881
 			' style="height: '.$height.'; width: '.$width.'; border: 1px solid black; padding: 1px; text-align: left;'.
882
-			(@stristr($options,'onclick="') ? ' cursor: pointer;' : '').'">'."\n\t".
882
+			(@stristr($options, 'onclick="') ? ' cursor: pointer;' : '').'">'."\n\t".
883 883
 			'<div style="height: '.$height.'; width: '.$percent.'%; background: '.$color.';"></div>'."\n</div>\n";
884 884
 	}
885 885
 
@@ -897,32 +897,32 @@  discard block
 block discarded – undo
897 897
 	 * @param string $options further options for the tag, default '' = none
898 898
 	 * @return string the html
899 899
 	 */
900
-	static function image( $app,$name,$title='',$options='' )
900
+	static function image($app, $name, $title = '', $options = '')
901 901
 	{
902 902
 		if (is_array($name))	// menuaction and other get-vars
903 903
 		{
904
-			$name = $GLOBALS['egw']->link('/index.php',$name);
904
+			$name = $GLOBALS['egw']->link('/index.php', $name);
905 905
 		}
906
-		if (substr($name,0,5) == 'vfs:/')	// vfs pseudo protocoll
906
+		if (substr($name, 0, 5) == 'vfs:/')	// vfs pseudo protocoll
907 907
 		{
908
-			$name = Framework::link(Vfs::download_url(substr($name,4)));
908
+			$name = Framework::link(Vfs::download_url(substr($name, 4)));
909 909
 		}
910
-		if ($name[0] == '/' || substr($name,0,7) == 'http://' || substr($name,0,8) == 'https://' || stripos($name,'api/thumbnail.php') )
910
+		if ($name[0] == '/' || substr($name, 0, 7) == 'http://' || substr($name, 0, 8) == 'https://' || stripos($name, 'api/thumbnail.php'))
911 911
 		{
912
-			if (!($name[0] == '/' || substr($name,0,7) == 'http://' || substr($name,0,8) == 'https://')) $name = '/'.$name;
912
+			if (!($name[0] == '/' || substr($name, 0, 7) == 'http://' || substr($name, 0, 8) == 'https://')) $name = '/'.$name;
913 913
 			$url = $name;
914 914
 		}
915 915
 		else	// no URL, so try searching the image
916 916
 		{
917
-			$name = str_replace(array('.gif','.GIF','.png','.PNG'),'',$name);
917
+			$name = str_replace(array('.gif', '.GIF', '.png', '.PNG'), '', $name);
918 918
 
919
-			if (!($url = Image::find($app,$name)))
919
+			if (!($url = Image::find($app, $name)))
920 920
 			{
921
-				$url = $name;		// name may already contain absolut path
921
+				$url = $name; // name may already contain absolut path
922 922
 			}
923
-			if($GLOBALS['egw_info']['server']['webserver_url'])
923
+			if ($GLOBALS['egw_info']['server']['webserver_url'])
924 924
 			{
925
-				list(,$path) = explode($GLOBALS['egw_info']['server']['webserver_url'],$url);
925
+				list(,$path) = explode($GLOBALS['egw_info']['server']['webserver_url'], $url);
926 926
 
927 927
 				if (!is_null($path)) $path = EGW_SERVER_ROOT.$path;
928 928
 			}
@@ -931,12 +931,12 @@  discard block
 block discarded – undo
931 931
 				$path = EGW_SERVER_ROOT.$url;
932 932
 			}
933 933
 
934
-			if (is_null($path) || (!@is_readable($path) && stripos($path,'webdav.php')===false))
934
+			if (is_null($path) || (!@is_readable($path) && stripos($path, 'webdav.php') === false))
935 935
 			{
936 936
 				// if the image-name is a percentage, use a progressbar
937
-				if (substr($name,-1) == '%' && is_numeric($percent = substr($name,0,-1)))
937
+				if (substr($name, -1) == '%' && is_numeric($percent = substr($name, 0, -1)))
938 938
 				{
939
-					return self::progressbar($percent,$title);
939
+					return self::progressbar($percent, $title);
940 940
 				}
941 941
 				return $title;
942 942
 			}
@@ -947,12 +947,12 @@  discard block
 block discarded – undo
947 947
 		}
948 948
 
949 949
 		// This block makes pngfix.js useless, adding a check on disable_pngfix to have pngfix.js do its thing
950
-		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'])))
950
+		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'])))
951 951
 		{
952 952
 			$extra_styles = "display: inline-block; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='$url',sizingMethod='image'); width: 1px; height: 1px;";
953
-			if (false!==strpos($options,'style="'))
953
+			if (false !== strpos($options, 'style="'))
954 954
 			{
955
-				$options = str_replace('style="','style="'.$extra_styles, $options);
955
+				$options = str_replace('style="', 'style="'.$extra_styles, $options);
956 956
 			}
957 957
 			else
958 958
 			{
@@ -972,24 +972,24 @@  discard block
 block discarded – undo
972 972
 	 * @param string $options attributes for the tag, default ''=none
973 973
 	 * @return string the html
974 974
 	 */
975
-	static function a_href( $content,$url,$vars='',$options='')
975
+	static function a_href($content, $url, $vars = '', $options = '')
976 976
 	{
977 977
 		if (is_array($url))
978 978
 		{
979 979
 			$vars = $url;
980 980
 			$url = '/index.php';
981 981
 		}
982
-		elseif (strpos($url,'/')===false &&
983
-			count(explode('.',$url)) >= 3 &&
984
-			!(strpos($url,'mailto:')!==false ||
985
-			strpos($url,'://')!==false ||
986
-			strpos($url,'javascript:')!==false))
982
+		elseif (strpos($url, '/') === false &&
983
+			count(explode('.', $url)) >= 3 &&
984
+			!(strpos($url, 'mailto:') !== false ||
985
+			strpos($url, '://') !== false ||
986
+			strpos($url, 'javascript:') !== false))
987 987
 		{
988 988
 			$url = "/index.php?menuaction=$url";
989 989
 		}
990 990
 		if ($url[0] == '/')		// link relative to eGW
991 991
 		{
992
-			$url = self::link($url,$vars);
992
+			$url = self::link($url, $vars);
993 993
 		}
994 994
 		//echo "<p>self::a_href('".self::htmlspecialchars($content)."','$url',".print_r($vars,True).") = ".self::link($url,$vars)."</p>";
995 995
 		return '<a href="'.self::htmlspecialchars($url).'" '.$options.'>'.$content.'</a>';
@@ -1003,7 +1003,7 @@  discard block
 block discarded – undo
1003 1003
 	 */
1004 1004
 	static function bold($content)
1005 1005
 	{
1006
-		return '<b>'.($content?$content.'</b>':'');
1006
+		return '<b>'.($content ? $content.'</b>' : '');
1007 1007
 	}
1008 1008
 
1009 1009
 	/**
@@ -1013,7 +1013,7 @@  discard block
 block discarded – undo
1013 1013
 	 * @param string $options attributes for the tag, default ''=none
1014 1014
 	 * @return string the html
1015 1015
 	 */
1016
-	static function hr($width='',$options='')
1016
+	static function hr($width = '', $options = '')
1017 1017
 	{
1018 1018
 		if ($width) $options .= " width=\"$width\"";
1019 1019
 
@@ -1029,12 +1029,12 @@  discard block
 block discarded – undo
1029 1029
 	 * @param mixed $names String (or Array) with the option-names eg. 'WIDTH,HEIGHT,BORDER'
1030 1030
 	 * @return string with options/attributes
1031 1031
 	 */
1032
-	static function formatOptions($options,$names)
1032
+	static function formatOptions($options, $names)
1033 1033
 	{
1034
-		if (!is_array($options)) $options = explode(',',$options);
1035
-		if (!is_array($names))   $names   = explode(',',$names);
1034
+		if (!is_array($options)) $options = explode(',', $options);
1035
+		if (!is_array($names))   $names   = explode(',', $names);
1036 1036
 
1037
-		foreach($options as $n => $val)
1037
+		foreach ($options as $n => $val)
1038 1038
 		{
1039 1039
 			if ($val != '' && $names[$n] != '')
1040 1040
 			{
@@ -1064,7 +1064,7 @@  discard block
 block discarded – undo
1064 1064
 	 * @param string $options attributes for the tag, default ''=none
1065 1065
 	 * @return string the html
1066 1066
 	 */
1067
-	static function label($content,$id='',$accesskey='',$options='')
1067
+	static function label($content, $id = '', $accesskey = '', $options = '')
1068 1068
 	{
1069 1069
 		if ($id != '')
1070 1070
 		{
@@ -1085,7 +1085,7 @@  discard block
 block discarded – undo
1085 1085
 	 * @param string $options attributes for the tag, default ''=none
1086 1086
 	 * @return string the html
1087 1087
 	 */
1088
-	static function fieldset($content,$legend='',$options='')
1088
+	static function fieldset($content, $legend = '', $options = '')
1089 1089
 	{
1090 1090
 		$html = "<fieldset $options>".($legend ? '<legend>'.self::htmlspecialchars($legend).'</legend>' : '')."\n";
1091 1091
 
@@ -1119,9 +1119,9 @@  discard block
 block discarded – undo
1119 1119
 	 *
1120 1120
 	 * @return string the html code, to be added into the template
1121 1121
 	 */
1122
-	static function tree($_folders,$_selected,$_topFolder=false,$_onNodeSelect="null",$tree='foldertree',$_divClass='',
1123
-		$_leafImage='',$_onCheckHandler=false,$delimiter='/',$folderImageDir=null,$autoLoading=null,$dataMode='JSON',
1124
-		$dragndrop=false)
1122
+	static function tree($_folders, $_selected, $_topFolder = false, $_onNodeSelect = "null", $tree = 'foldertree', $_divClass = '',
1123
+		$_leafImage = '', $_onCheckHandler = false, $delimiter = '/', $folderImageDir = null, $autoLoading = null, $dataMode = 'JSON',
1124
+		$dragndrop = false)
1125 1125
 	{
1126 1126
 		$webserver_url = $GLOBALS['egw_info']['server']['webserver_url'];
1127 1127
 		if (empty($folderImageDir))
@@ -1144,7 +1144,7 @@  discard block
 block discarded – undo
1144 1144
 			//error_log(__METHOD__."() setting templated image-path: $folderImageDir");
1145 1145
 		}
1146 1146
 
1147
-		static $tree_initialised=false;
1147
+		static $tree_initialised = false;
1148 1148
 		if (!$tree_initialised)
1149 1149
 		{
1150 1150
 			Framework::includeCSS('/api/js/dhtmlxtree/codebase/dhtmlxtree.css');
@@ -1154,16 +1154,16 @@  discard block
 block discarded – undo
1154 1154
 			$tree_initialised = true;
1155 1155
 			if (!$_folders && !$autoLoading) return null;
1156 1156
 		}
1157
-		$html = self::div("\n",'id="'.$tree.'"',$_divClass).$html;
1157
+		$html = self::div("\n", 'id="'.$tree.'"', $_divClass).$html;
1158 1158
 		$html .= "<script type='text/javascript'>\n";
1159 1159
 		$html .= "var $tree;";
1160 1160
 		$html .= "egw_LAB.wait(function() {";
1161 1161
 		$html .= "$tree = new"." dhtmlXTreeObject('$tree','100%','100%',0);\n";
1162
-		$html .= "$tree.parentObject.style.overflow='auto';\n";	// dhtmlXTree constructor has hidden hardcoded
1162
+		$html .= "$tree.parentObject.style.overflow='auto';\n"; // dhtmlXTree constructor has hidden hardcoded
1163 1163
 		if (Translation::charset() == 'utf-8') $html .= "if ($tree.setEscapingMode) $tree.setEscapingMode('utf8');\n";
1164 1164
 		$html .= "$tree.setImagePath('$folderImageDir/dhtmlxtree/');\n";
1165 1165
 
1166
-		if($_onCheckHandler)
1166
+		if ($_onCheckHandler)
1167 1167
 		{
1168 1168
 			$html .= "$tree.enableCheckBoxes(1);\n";
1169 1169
 			$html .= "$tree.setOnCheckHandler('$_onCheckHandler');\n";
@@ -1174,7 +1174,7 @@  discard block
 block discarded – undo
1174 1174
 		if ($autoLoading)
1175 1175
 		{
1176 1176
 			$autoLoading = is_array($autoLoading) ?
1177
-				Framework::link('/index.php',$autoLoading) : Framework::link($autoLoading);
1177
+				Framework::link('/index.php', $autoLoading) : Framework::link($autoLoading);
1178 1178
 			$html .= "$tree.setXMLAutoLoading('$autoLoading');\n";
1179 1179
 			if ($dataMode != 'XML') $html .= "$tree.setDataMode('$dataMode');\n";
1180 1180
 
@@ -1215,7 +1215,7 @@  discard block
 block discarded – undo
1215 1215
 		}
1216 1216
 		if (is_string($_folders))
1217 1217
 		{
1218
-			switch($dataMode)
1218
+			switch ($dataMode)
1219 1219
 			{
1220 1220
 				case 'JSON':
1221 1221
 					$html .= "$tree.loadJSONObject($_folders);\n"; break;
@@ -1226,10 +1226,10 @@  discard block
 block discarded – undo
1226 1226
 		else
1227 1227
 		{
1228 1228
 			// evtl. remove leading delimiter
1229
-			if ($_selected[0] == $delimiter) $_selected = substr($_selected,1);
1229
+			if ($_selected[0] == $delimiter) $_selected = substr($_selected, 1);
1230 1230
 
1231 1231
 			$n = 0;
1232
-			foreach($_folders as $path => $data)
1232
+			foreach ($_folders as $path => $data)
1233 1233
 			{
1234 1234
 				if (!is_array($data))
1235 1235
 				{
@@ -1241,10 +1241,10 @@  discard block
 block discarded – undo
1241 1241
 				if ($_leafImage)
1242 1242
 				{
1243 1243
 					$image1 = $image2 = $image3 = "'".$_leafImage."'";
1244
-					if (($next_item = array_slice($_folders, $n+1, 1, true)))
1244
+					if (($next_item = array_slice($_folders, $n + 1, 1, true)))
1245 1245
 					{
1246 1246
 						list($next_path) = each($next_item);
1247
-						if (substr($next_path,0,strlen($path)+1) == $path.'/')
1247
+						if (substr($next_path, 0, strlen($path) + 1) == $path.'/')
1248 1248
 						{
1249 1249
 							$image1 = $image2 = $image3 = '0';
1250 1250
 						}
@@ -1255,22 +1255,22 @@  discard block
 block discarded – undo
1255 1255
 					$image1 = $image2 = $image3 = "'".$data['image']."'";
1256 1256
 				}
1257 1257
 				// evtl. remove leading delimiter
1258
-				if ($path[0] == $delimiter) $path = substr($path,1);
1259
-				$folderParts = explode($delimiter,$path);
1258
+				if ($path[0] == $delimiter) $path = substr($path, 1);
1259
+				$folderParts = explode($delimiter, $path);
1260 1260
 
1261 1261
 				//get rightmost folderpart
1262 1262
 				$label = array_pop($folderParts);
1263 1263
 				if (isset($data['label'])) $label = $data['label'];
1264 1264
 
1265 1265
 				// the rest of the array is the name of the parent
1266
-				$parentName = implode((array)$folderParts,$delimiter);
1267
-				if(empty($parentName)) $parentName = $top;
1266
+				$parentName = implode((array)$folderParts, $delimiter);
1267
+				if (empty($parentName)) $parentName = $top;
1268 1268
 
1269 1269
 				$entryOptions = !isset($data['child']) || $data['child'] ? 'CHILD' : '';
1270 1270
 				if ($_onCheckHandler && $_selected)	// check selected items on multi selection
1271 1271
 				{
1272
-					if (!is_array($_selected)) $_selected = explode(',',$_selected);
1273
-					if (array_search("$path",$_selected)!==false) $entryOptions .= ',CHECKED';
1272
+					if (!is_array($_selected)) $_selected = explode(',', $_selected);
1273
+					if (array_search("$path", $_selected) !== false) $entryOptions .= ',CHECKED';
1274 1274
 					//echo "<p>path=$path, _selected=".print_r($_selected,true).": $entryOptions</p>\n";
1275 1275
 				}
1276 1276
 				// highlight current item
@@ -1290,7 +1290,7 @@  discard block
 block discarded – undo
1290 1290
 		$html .= "$tree.closeAllItems(0);\n";
1291 1291
 		if ($_selected)
1292 1292
 		{
1293
-			foreach(is_array($_selected)?$_selected:array($_selected) as $path)
1293
+			foreach (is_array($_selected) ? $_selected : array($_selected) as $path)
1294 1294
 			{
1295 1295
 				$html .= "$tree.openItem('".addslashes($path)."');\n";
1296 1296
 			}
@@ -1315,7 +1315,7 @@  discard block
 block discarded – undo
1315 1315
 	 *		or to restrict the attribute's values
1316 1316
 	 * @param boolean $_force =null - force the config passed to be used without merging to the default
1317 1317
 	 */
1318
-	static function purify($html,$config=null,$spec=array(),$_force=false)
1318
+	static function purify($html, $config = null, $spec = array(), $_force = false)
1319 1319
 	{
1320 1320
 		return Html\HtmLawed::purify($html, $config, $spec, $_force);
1321 1321
 	}
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() {\$j(function() {if(\$j().chosen) \$j('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
 		if (self::$netscape4)
@@ -899,17 +975,26 @@  discard block
 block discarded – undo
899 975
 	 */
900 976
 	static function image( $app,$name,$title='',$options='' )
901 977
 	{
902
-		if (is_array($name))	// menuaction and other get-vars
978
+		if (is_array($name))
979
+		{
980
+			// menuaction and other get-vars
903 981
 		{
904 982
 			$name = $GLOBALS['egw']->link('/index.php',$name);
905 983
 		}
906
-		if (substr($name,0,5) == 'vfs:/')	// vfs pseudo protocoll
984
+		}
985
+		if (substr($name,0,5) == 'vfs:/')
986
+		{
987
+			// vfs pseudo protocoll
907 988
 		{
908 989
 			$name = Framework::link(Vfs::download_url(substr($name,4)));
909 990
 		}
991
+		}
910 992
 		if ($name[0] == '/' || substr($name,0,7) == 'http://' || substr($name,0,8) == 'https://' || stripos($name,'api/thumbnail.php') )
911 993
 		{
912
-			if (!($name[0] == '/' || substr($name,0,7) == 'http://' || substr($name,0,8) == 'https://')) $name = '/'.$name;
994
+			if (!($name[0] == '/' || substr($name,0,7) == 'http://' || substr($name,0,8) == 'https://'))
995
+			{
996
+				$name = '/'.$name;
997
+			}
913 998
 			$url = $name;
914 999
 		}
915 1000
 		else	// no URL, so try searching the image
@@ -924,7 +1009,10 @@  discard block
 block discarded – undo
924 1009
 			{
925 1010
 				list(,$path) = explode($GLOBALS['egw_info']['server']['webserver_url'],$url);
926 1011
 
927
-				if (!is_null($path)) $path = EGW_SERVER_ROOT.$path;
1012
+				if (!is_null($path))
1013
+				{
1014
+					$path = EGW_SERVER_ROOT.$path;
1015
+				}
928 1016
 			}
929 1017
 			else
930 1018
 			{
@@ -987,10 +1075,13 @@  discard block
 block discarded – undo
987 1075
 		{
988 1076
 			$url = "/index.php?menuaction=$url";
989 1077
 		}
990
-		if ($url[0] == '/')		// link relative to eGW
1078
+		if ($url[0] == '/')
1079
+		{
1080
+			// link relative to eGW
991 1081
 		{
992 1082
 			$url = self::link($url,$vars);
993 1083
 		}
1084
+		}
994 1085
 		//echo "<p>self::a_href('".self::htmlspecialchars($content)."','$url',".print_r($vars,True).") = ".self::link($url,$vars)."</p>";
995 1086
 		return '<a href="'.self::htmlspecialchars($url).'" '.$options.'>'.$content.'</a>';
996 1087
 	}
@@ -1015,7 +1106,10 @@  discard block
 block discarded – undo
1015 1106
 	 */
1016 1107
 	static function hr($width='',$options='')
1017 1108
 	{
1018
-		if ($width) $options .= " width=\"$width\"";
1109
+		if ($width)
1110
+		{
1111
+			$options .= " width=\"$width\"";
1112
+		}
1019 1113
 
1020 1114
 		return "<hr $options />\n";
1021 1115
 	}
@@ -1031,8 +1125,14 @@  discard block
 block discarded – undo
1031 1125
 	 */
1032 1126
 	static function formatOptions($options,$names)
1033 1127
 	{
1034
-		if (!is_array($options)) $options = explode(',',$options);
1035
-		if (!is_array($names))   $names   = explode(',',$names);
1128
+		if (!is_array($options))
1129
+		{
1130
+			$options = explode(',',$options);
1131
+		}
1132
+		if (!is_array($names))
1133
+		{
1134
+			$names   = explode(',',$names);
1135
+		}
1036 1136
 
1037 1137
 		foreach($options as $n => $val)
1038 1138
 		{
@@ -1150,9 +1250,15 @@  discard block
 block discarded – undo
1150 1250
 			Framework::includeCSS('/api/js/dhtmlxtree/codebase/dhtmlxtree.css');
1151 1251
 			Framework::includeJS('/api/js/dhtmlxtree/codebase/dhtmlxcommon.js');
1152 1252
 			Framework::includeJS('/api/js/dhtmlxtree/sources/dhtmlxtree.js');
1153
-			if ($autoLoading && $dataMode != 'XML') Framework::includeJS('/api/js/dhtmlxtree/sources/ext/dhtmlxtree_json.js');
1253
+			if ($autoLoading && $dataMode != 'XML')
1254
+			{
1255
+				Framework::includeJS('/api/js/dhtmlxtree/sources/ext/dhtmlxtree_json.js');
1256
+			}
1154 1257
 			$tree_initialised = true;
1155
-			if (!$_folders && !$autoLoading) return null;
1258
+			if (!$_folders && !$autoLoading)
1259
+			{
1260
+				return null;
1261
+			}
1156 1262
 		}
1157 1263
 		$html = self::div("\n",'id="'.$tree.'"',$_divClass).$html;
1158 1264
 		$html .= "<script type='text/javascript'>\n";
@@ -1160,7 +1266,10 @@  discard block
 block discarded – undo
1160 1266
 		$html .= "egw_LAB.wait(function() {";
1161 1267
 		$html .= "$tree = new"." dhtmlXTreeObject('$tree','100%','100%',0);\n";
1162 1268
 		$html .= "$tree.parentObject.style.overflow='auto';\n";	// dhtmlXTree constructor has hidden hardcoded
1163
-		if (Translation::charset() == 'utf-8') $html .= "if ($tree.setEscapingMode) $tree.setEscapingMode('utf8');\n";
1269
+		if (Translation::charset() == 'utf-8')
1270
+		{
1271
+			$html .= "if ($tree.setEscapingMode) $tree.setEscapingMode('utf8');\n";
1272
+		}
1164 1273
 		$html .= "$tree.setImagePath('$folderImageDir/dhtmlxtree/');\n";
1165 1274
 
1166 1275
 		if($_onCheckHandler)
@@ -1169,19 +1278,28 @@  discard block
 block discarded – undo
1169 1278
 			$html .= "$tree.setOnCheckHandler('$_onCheckHandler');\n";
1170 1279
 		}
1171 1280
 
1172
-		if ($dragndrop) $html .= "$tree.enableDragAndDrop(true);\n";
1281
+		if ($dragndrop)
1282
+		{
1283
+			$html .= "$tree.enableDragAndDrop(true);\n";
1284
+		}
1173 1285
 
1174 1286
 		if ($autoLoading)
1175 1287
 		{
1176 1288
 			$autoLoading = is_array($autoLoading) ?
1177 1289
 				Framework::link('/index.php',$autoLoading) : Framework::link($autoLoading);
1178 1290
 			$html .= "$tree.setXMLAutoLoading('$autoLoading');\n";
1179
-			if ($dataMode != 'XML') $html .= "$tree.setDataMode('$dataMode');\n";
1291
+			if ($dataMode != 'XML')
1292
+			{
1293
+				$html .= "$tree.setDataMode('$dataMode');\n";
1294
+			}
1180 1295
 
1181 1296
 			// if no folders given, use xml url to load root, incl. setting of selected folder
1182 1297
 			if (!$_folders)
1183 1298
 			{
1184
-				if ($_selected) $autoLoading .= '&selected='.urlencode($_selected);
1299
+				if ($_selected)
1300
+				{
1301
+					$autoLoading .= '&selected='.urlencode($_selected);
1302
+				}
1185 1303
 				unset($_selected);
1186 1304
 				$html .= "$tree.loadXML('$autoLoading');\n";
1187 1305
 				$html .= "});";
@@ -1226,7 +1344,10 @@  discard block
 block discarded – undo
1226 1344
 		else
1227 1345
 		{
1228 1346
 			// evtl. remove leading delimiter
1229
-			if ($_selected[0] == $delimiter) $_selected = substr($_selected,1);
1347
+			if ($_selected[0] == $delimiter)
1348
+			{
1349
+				$_selected = substr($_selected,1);
1350
+			}
1230 1351
 
1231 1352
 			$n = 0;
1232 1353
 			foreach($_folders as $path => $data)
@@ -1255,22 +1376,37 @@  discard block
 block discarded – undo
1255 1376
 					$image1 = $image2 = $image3 = "'".$data['image']."'";
1256 1377
 				}
1257 1378
 				// evtl. remove leading delimiter
1258
-				if ($path[0] == $delimiter) $path = substr($path,1);
1379
+				if ($path[0] == $delimiter)
1380
+				{
1381
+					$path = substr($path,1);
1382
+				}
1259 1383
 				$folderParts = explode($delimiter,$path);
1260 1384
 
1261 1385
 				//get rightmost folderpart
1262 1386
 				$label = array_pop($folderParts);
1263
-				if (isset($data['label'])) $label = $data['label'];
1387
+				if (isset($data['label']))
1388
+				{
1389
+					$label = $data['label'];
1390
+				}
1264 1391
 
1265 1392
 				// the rest of the array is the name of the parent
1266 1393
 				$parentName = implode((array)$folderParts,$delimiter);
1267
-				if(empty($parentName)) $parentName = $top;
1394
+				if(empty($parentName))
1395
+				{
1396
+					$parentName = $top;
1397
+				}
1268 1398
 
1269 1399
 				$entryOptions = !isset($data['child']) || $data['child'] ? 'CHILD' : '';
1270
-				if ($_onCheckHandler && $_selected)	// check selected items on multi selection
1400
+				if ($_onCheckHandler && $_selected)
1401
+				{
1402
+					// check selected items on multi selection
1271 1403
 				{
1272 1404
 					if (!is_array($_selected)) $_selected = explode(',',$_selected);
1273
-					if (array_search("$path",$_selected)!==false) $entryOptions .= ',CHECKED';
1405
+				}
1406
+					if (array_search("$path",$_selected)!==false)
1407
+					{
1408
+						$entryOptions .= ',CHECKED';
1409
+					}
1274 1410
 					//echo "<p>path=$path, _selected=".print_r($_selected,true).": $entryOptions</p>\n";
1275 1411
 				}
1276 1412
 				// 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.
Spacing   +39 added lines, -41 removed lines patch added patch discarded remove patch
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 		);
76 76
 		$skins = array();
77 77
 
78
-		foreach(scandir(EGW_SERVER_ROOT.'/api/js/ckeditor/skins') as $skin)
78
+		foreach (scandir(EGW_SERVER_ROOT.'/api/js/ckeditor/skins') as $skin)
79 79
 		{
80 80
 			if ($skin[0] == '.') continue;
81 81
 
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 		if (!\EGroupware\Api\Header\UserAgent::mobile()) unset($skins['flat']);
96 96
 
97 97
 		// return our default "moono" first
98
-		return isset($skins['moono']) ? array('moono' => $skins['moono'])+$skins : $skins;
98
+		return isset($skins['moono']) ? array('moono' => $skins['moono']) + $skins : $skins;
99 99
 	}
100 100
 
101 101
 	/**
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 	 * @param string &$unit =null on return just unit
107 107
 	 * @return string font-size including unit
108 108
 	 */
109
-	public static function font_size_from_prefs(array $prefs=null, &$size=null, &$unit=null)
109
+	public static function font_size_from_prefs(array $prefs = null, &$size = null, &$unit = null)
110 110
 	{
111 111
 		if (is_null($prefs)) $prefs = $GLOBALS['egw_info']['user']['preferences'];
112 112
 
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 			$unit = 'px';
118 118
 			$size = (string)(int)$size;
119 119
 		}
120
-		return $size.($size?$unit:'');
120
+		return $size.($size ? $unit : '');
121 121
 	}
122 122
 
123 123
 	/**
@@ -128,12 +128,11 @@  discard block
 block discarded – undo
128 128
 	{
129 129
 		//use the lang and country information to construct a possible lang info for CKEditor UI and scayt_slang
130 130
 		self::$lang = ($GLOBALS['egw_info']['user']['preferences']['common']['spellchecker_lang'] ?
131
-			$GLOBALS['egw_info']['user']['preferences']['common']['spellchecker_lang']:
132
-			$GLOBALS['egw_info']['user']['preferences']['common']['lang']);
131
+			$GLOBALS['egw_info']['user']['preferences']['common']['spellchecker_lang'] : $GLOBALS['egw_info']['user']['preferences']['common']['lang']);
133 132
 
134 133
 		self::$country = $GLOBALS['egw_info']['user']['preferences']['common']['country'];
135 134
 
136
-		if (!(strpos(self::$lang, '-')===false))
135
+		if (!(strpos(self::$lang, '-') === false))
137 136
 			list(self::$lang, self::$country) = explode('-', self::$lang);
138 137
 	}
139 138
 
@@ -238,7 +237,7 @@  discard block
 block discarded – undo
238 237
 				$skin = "moono"; //this is the basic skin for ckeditor
239 238
 			}
240 239
 			// Skin used for mobile template
241
-			self::$skin = \EGroupware\Api\Header\UserAgent::mobile()?'flat':$skin;
240
+			self::$skin = \EGroupware\Api\Header\UserAgent::mobile() ? 'flat' : $skin;
242 241
 		}
243 242
 
244 243
 		return self::$skin;
@@ -279,8 +278,7 @@  discard block
 block discarded – undo
279 278
 		$config['removePlugins'] = 'elementspath';
280 279
 
281 280
 		$config['toolbarCanCollapse'] = true;
282
-		$config['toolbarStartupExpanded'] = is_bool($expanded_toolbar) ? $expanded_toolbar :
283
-			($expanded_toolbar === 'false' ? false : (boolean)$expanded_toolbar);
281
+		$config['toolbarStartupExpanded'] = is_bool($expanded_toolbar) ? $expanded_toolbar : ($expanded_toolbar === 'false' ? false : (boolean)$expanded_toolbar);
284 282
 
285 283
 		$config['filebrowserBrowseUrl'] = self::get_filebrowserBrowseUrl($start_path);
286 284
 		$config['filebrowserWindowHeight'] = 640;
@@ -293,7 +291,7 @@  discard block
 block discarded – undo
293 291
 		$config['fontSize_sizes'] = '';
294 292
 		$unit = $GLOBALS['egw_info']['user']['preferences']['common']['rte_font_unit'];
295 293
 		if (empty($unit)) $unit = 'px';
296
-		foreach(self::$font_size_options as $k => $v)
294
+		foreach (self::$font_size_options as $k => $v)
297 295
 		{
298 296
 			$config['fontSize_sizes'] .= $v.$unit.'/'.$k.$unit.';';
299 297
 		}
@@ -350,48 +348,48 @@  discard block
 block discarded – undo
350 348
 	 * Writes the toolbar configuration to the options which depends on the chosen
351 349
 	 * mode and the spellchecker_button written by the add_spellchecker_options button
352 350
 	 */
353
-	private static function add_toolbar_options(&$config, $mode, $spellchecker_button, $scayt_button=false)
351
+	private static function add_toolbar_options(&$config, $mode, $spellchecker_button, $scayt_button = false)
354 352
 	{
355 353
 		$config['toolbar'] = array();
356 354
 		switch ($mode)
357 355
 		{
358 356
 			case 'advanced':
359
-				$config['toolbar'][] = array('name' => 'document', 'items' => array('Source','DocProps','-','Preview','-','Templates'));
360
-				$config['toolbar'][] = array('name' => 'clipboard', 'items' => array('Cut','Copy','Paste','PasteText','PasteFromWord','-','Print'));
361
-				if ($spellchecker_button||$scayt_button)
357
+				$config['toolbar'][] = array('name' => 'document', 'items' => array('Source', 'DocProps', '-', 'Preview', '-', 'Templates'));
358
+				$config['toolbar'][] = array('name' => 'clipboard', 'items' => array('Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Print'));
359
+				if ($spellchecker_button || $scayt_button)
362 360
 				{
363 361
 					$configArray = array();
364 362
 					if ($spellchecker_button) $configArray[] = $spellchecker_button;
365 363
 					if ($scayt_button) $configArray[] = $scayt_button;
366 364
 					$config['toolbar'][] = array('name' => 'tools', 'items' => $configArray);
367 365
 				}
368
-				$config['toolbar'][] = array('name' => 'edit', 'items' => array('Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'));
366
+				$config['toolbar'][] = array('name' => 'edit', 'items' => array('Undo', 'Redo', '-', 'Find', 'Replace', '-', 'SelectAll', 'RemoveFormat'));
369 367
 
370 368
 				$config['toolbar'][] = '/';
371 369
 
372
-				$config['toolbar'][] = array('name' => 'basicstyles', 'items' => array('Bold','Italic','Underline','Strike','-','Subscript','Superscript'));
373
-				$config['toolbar'][] = array('name' => 'justify', 'items' => array('JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'));
374
-				$config['toolbar'][] = array('name' => 'paragraph', 'items' => array('BulletedList','NumberedList','-','Outdent','Indent'));
375
-				$config['toolbar'][] = array('name' => 'links', 'items' => array('Link','Unlink','Anchor'));
376
-				$config['toolbar'][] = array('name' => 'insert', 'items' => array('Maximize','Image','Table','HorizontalRule','SpecialChar'/*,'Smiley'*/));
370
+				$config['toolbar'][] = array('name' => 'basicstyles', 'items' => array('Bold', 'Italic', 'Underline', 'Strike', '-', 'Subscript', 'Superscript'));
371
+				$config['toolbar'][] = array('name' => 'justify', 'items' => array('JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'));
372
+				$config['toolbar'][] = array('name' => 'paragraph', 'items' => array('BulletedList', 'NumberedList', '-', 'Outdent', 'Indent'));
373
+				$config['toolbar'][] = array('name' => 'links', 'items' => array('Link', 'Unlink', 'Anchor'));
374
+				$config['toolbar'][] = array('name' => 'insert', 'items' => array('Maximize', 'Image', 'Table', 'HorizontalRule', 'SpecialChar'/*,'Smiley'*/));
377 375
 
378 376
 				$config['toolbar'][] = '/';
379 377
 
380
-				$config['toolbar'][] = array('name' => 'styles', 'items' => array('Style','Format','Font','FontSize'));
381
-				$config['toolbar'][] = array('name' => 'colors', 'items' => array('TextColor','BGColor'));
382
-				$config['toolbar'][] = array('name' => 'tools', 'items' => array('ShowBlocks','-','About'));
378
+				$config['toolbar'][] = array('name' => 'styles', 'items' => array('Style', 'Format', 'Font', 'FontSize'));
379
+				$config['toolbar'][] = array('name' => 'colors', 'items' => array('TextColor', 'BGColor'));
380
+				$config['toolbar'][] = array('name' => 'tools', 'items' => array('ShowBlocks', '-', 'About'));
383 381
 				break;
384 382
 
385 383
 			case 'extended': default:
386
-				$config['toolbar'][] = array('name' => 'clipboard', 'items' => array('Bold','Italic','Underline'));
387
-				$config['toolbar'][] = array('name' => 'justify', 'items' => array('JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'));
388
-				$config['toolbar'][] = array('name' => 'paragraph', 'items' => array('BulletedList','NumberedList'/*,'Smiley'*/,'Outdent','Indent','Undo','Redo'));
389
-				$config['toolbar'][] = array('name' => 'clipboard', 'items' => array('Cut','Copy','Paste','PasteText','PasteFromWord','-','Print'));
384
+				$config['toolbar'][] = array('name' => 'clipboard', 'items' => array('Bold', 'Italic', 'Underline'));
385
+				$config['toolbar'][] = array('name' => 'justify', 'items' => array('JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'));
386
+				$config['toolbar'][] = array('name' => 'paragraph', 'items' => array('BulletedList', 'NumberedList'/*,'Smiley'*/, 'Outdent', 'Indent', 'Undo', 'Redo'));
387
+				$config['toolbar'][] = array('name' => 'clipboard', 'items' => array('Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Print'));
390 388
 
391 389
 				if ($mode == 'extended')
392 390
 				{
393
-					$config['toolbar'][] = array('name' => 'insert', 'items' => array('Image','Link','Unlink','Anchor'));
394
-					if ($spellchecker_button||$scayt_button)
391
+					$config['toolbar'][] = array('name' => 'insert', 'items' => array('Image', 'Link', 'Unlink', 'Anchor'));
392
+					if ($spellchecker_button || $scayt_button)
395 393
 					{
396 394
 						$configArray = array('Maximize');
397 395
 						if ($spellchecker_button) $configArray[] = $spellchecker_button;
@@ -399,13 +397,13 @@  discard block
 block discarded – undo
399 397
 						$config['toolbar'][] = array('name' => 'tools', 'items' => $configArray);
400 398
 					}
401 399
 					else
402
-						$config['toolbar'][] = array('name' => 'insert', 'items' => array('Maximize'));//, 'Image', 'Table');
400
+						$config['toolbar'][] = array('name' => 'insert', 'items' => array('Maximize')); //, 'Image', 'Table');
403 401
 
404 402
 					$config['toolbar'][count($config['toolbar']) - 1][] = array('name' => 'insert', 'items' => array('Image', 'Table'));
405 403
 				}
406 404
 				else
407 405
 				{
408
-					if ($spellchecker_button||$scayt_button)
406
+					if ($spellchecker_button || $scayt_button)
409 407
 					{
410 408
 						$configArray = array('Maximize');
411 409
 						if ($spellchecker_button) $configArray[] = $spellchecker_button;
@@ -417,11 +415,11 @@  discard block
 block discarded – undo
417 415
 				}
418 416
 
419 417
 				$config['toolbar'][] = '/';
420
-				$config['toolbar'][] = array('name' => 'edit', 'items' => array('Find','Replace','-','SelectAll','RemoveFormat'));
421
-				if ($mode == 'simple-withimage') $config['toolbar'][] = array('name' => 'links', 'items' => array('Image','Link','Unlink'));
422
-				$config['toolbar'][] = array('name' => 'styles', 'items' => array('Format','Font','FontSize'));
423
-				$config['toolbar'][] = array('name' => 'colors', 'items' => array('TextColor','BGColor'));
424
-				$config['toolbar'][] = array('name' => 'tools', 'items' => array('ShowBlocks','-','About'));
418
+				$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'));
420
+				$config['toolbar'][] = array('name' => 'styles', 'items' => array('Format', 'Font', 'FontSize'));
421
+				$config['toolbar'][] = array('name' => 'colors', 'items' => array('TextColor', 'BGColor'));
422
+				$config['toolbar'][] = array('name' => 'tools', 'items' => array('ShowBlocks', '-', 'About'));
425 423
 		}
426 424
 	}
427 425
 
@@ -434,7 +432,7 @@  discard block
 block discarded – undo
434 432
 		self::set_csp_script_src_attrs();
435 433
 
436 434
 		// If not explicitly set, use preference for toolbar mode
437
-		if(!$mode || trim($mode) == '') $mode = $GLOBALS['egw_info']['user']['preferences']['common']['rte_features'];
435
+		if (!$mode || trim($mode) == '') $mode = $GLOBALS['egw_info']['user']['preferences']['common']['rte_features'];
438 436
 		$config = array();
439 437
 		$spellchecker_button = null;
440 438
 
@@ -444,7 +442,7 @@  discard block
 block discarded – undo
444 442
 		self::add_toolbar_options($config, $mode, $spellchecker_button, $scayt_button);
445 443
 		//error_log(__METHOD__."('$mode', $height, ".array2string($expanded_toolbar).") returning ".array2string($config));
446 444
 		// Add extra plugins
447
-		self::append_extraPlugins_config_array($config, array('uploadimage','uploadwidget','widget','notification','notificationaggregator','lineutils'));
445
+		self::append_extraPlugins_config_array($config, array('uploadimage', 'uploadwidget', 'widget', 'notification', 'notificationaggregator', 'lineutils'));
448 446
 		return $config;
449 447
 	}
450 448
 
@@ -453,7 +451,7 @@  discard block
 block discarded – undo
453 451
 	 * @param array $config
454 452
 	 * @param array $plugins plugins name which needs to be appended into extraPlugins
455 453
 	 */
456
-	public static function append_extraPlugins_config_array (&$config, $plugins)
454
+	public static function append_extraPlugins_config_array(&$config, $plugins)
457 455
 	{
458 456
 		if (is_array($plugins))
459 457
 		{
@@ -461,7 +459,7 @@  discard block
 block discarded – undo
461 459
 			{
462 460
 				if (!empty($config['extraPlugins']) && $config['extraPlugins'] !== '')
463 461
 				{
464
-					$config['extraPlugins'] .= ',' . $plugin;
462
+					$config['extraPlugins'] .= ','.$plugin;
465 463
 				}
466 464
 				else
467 465
 				{
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.'/api/js/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'];
@@ -134,7 +143,9 @@  discard block
 block discarded – undo
134 143
 		self::$country = $GLOBALS['egw_info']['user']['preferences']['common']['country'];
135 144
 
136 145
 		if (!(strpos(self::$lang, '-')===false))
137
-			list(self::$lang, self::$country) = explode('-', self::$lang);
146
+		{
147
+					list(self::$lang, self::$country) = explode('-', self::$lang);
148
+		}
138 149
 	}
139 150
 
140 151
 	/**
@@ -143,7 +154,9 @@  discard block
 block discarded – undo
143 154
 	private static function get_lang()
144 155
 	{
145 156
 		if (self::$lang == null || self::$country == null)
146
-			self::read_lang_country();
157
+		{
158
+					self::read_lang_country();
159
+		}
147 160
 
148 161
 		return self::$lang;
149 162
 	}
@@ -154,7 +167,9 @@  discard block
 block discarded – undo
154 167
 	private static function get_country()
155 168
 	{
156 169
 		if (self::$lang == null || self::$country == null)
157
-			self::read_lang_country();
170
+		{
171
+					self::read_lang_country();
172
+		}
158 173
 
159 174
 		return strtoupper(self::$country);
160 175
 	}
@@ -292,7 +307,10 @@  discard block
 block discarded – undo
292 307
 
293 308
 		$config['fontSize_sizes'] = '';
294 309
 		$unit = $GLOBALS['egw_info']['user']['preferences']['common']['rte_font_unit'];
295
-		if (empty($unit)) $unit = 'px';
310
+		if (empty($unit))
311
+		{
312
+			$unit = 'px';
313
+		}
296 314
 		foreach(self::$font_size_options as $k => $v)
297 315
 		{
298 316
 			$config['fontSize_sizes'] .= $v.$unit.'/'.$k.$unit.';';
@@ -361,8 +379,14 @@  discard block
 block discarded – undo
361 379
 				if ($spellchecker_button||$scayt_button)
362 380
 				{
363 381
 					$configArray = array();
364
-					if ($spellchecker_button) $configArray[] = $spellchecker_button;
365
-					if ($scayt_button) $configArray[] = $scayt_button;
382
+					if ($spellchecker_button)
383
+					{
384
+						$configArray[] = $spellchecker_button;
385
+					}
386
+					if ($scayt_button)
387
+					{
388
+						$configArray[] = $scayt_button;
389
+					}
366 390
 					$config['toolbar'][] = array('name' => 'tools', 'items' => $configArray);
367 391
 				}
368 392
 				$config['toolbar'][] = array('name' => 'edit', 'items' => array('Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'));
@@ -394,12 +418,20 @@  discard block
 block discarded – undo
394 418
 					if ($spellchecker_button||$scayt_button)
395 419
 					{
396 420
 						$configArray = array('Maximize');
397
-						if ($spellchecker_button) $configArray[] = $spellchecker_button;
398
-						if ($scayt_button) $configArray[] = $scayt_button;
421
+						if ($spellchecker_button)
422
+						{
423
+							$configArray[] = $spellchecker_button;
424
+						}
425
+						if ($scayt_button)
426
+						{
427
+							$configArray[] = $scayt_button;
428
+						}
399 429
 						$config['toolbar'][] = array('name' => 'tools', 'items' => $configArray);
400 430
 					}
401
-					else
402
-						$config['toolbar'][] = array('name' => 'insert', 'items' => array('Maximize'));//, 'Image', 'Table');
431
+					else {
432
+											$config['toolbar'][] = array('name' => 'insert', 'items' => array('Maximize'));
433
+					}
434
+					//, 'Image', 'Table');
403 435
 
404 436
 					$config['toolbar'][count($config['toolbar']) - 1][] = array('name' => 'insert', 'items' => array('Image', 'Table'));
405 437
 				}
@@ -408,17 +440,27 @@  discard block
 block discarded – undo
408 440
 					if ($spellchecker_button||$scayt_button)
409 441
 					{
410 442
 						$configArray = array('Maximize');
411
-						if ($spellchecker_button) $configArray[] = $spellchecker_button;
412
-						if ($scayt_button) $configArray[] = $scayt_button;
443
+						if ($spellchecker_button)
444
+						{
445
+							$configArray[] = $spellchecker_button;
446
+						}
447
+						if ($scayt_button)
448
+						{
449
+							$configArray[] = $scayt_button;
450
+						}
413 451
 						$config['toolbar'][] = array('name' => 'tools', 'items' => $configArray);
414 452
 					}
415
-					else
416
-						$config['toolbar'][] = array('name' => 'tools', 'items' => array('Maximize'));
453
+					else {
454
+											$config['toolbar'][] = array('name' => 'tools', 'items' => array('Maximize'));
455
+					}
417 456
 				}
418 457
 
419 458
 				$config['toolbar'][] = '/';
420 459
 				$config['toolbar'][] = array('name' => 'edit', 'items' => array('Find','Replace','-','SelectAll','RemoveFormat'));
421
-				if ($mode == 'simple-withimage') $config['toolbar'][] = array('name' => 'links', 'items' => array('Image','Link','Unlink'));
460
+				if ($mode == 'simple-withimage')
461
+				{
462
+					$config['toolbar'][] = array('name' => 'links', 'items' => array('Image','Link','Unlink'));
463
+				}
422 464
 				$config['toolbar'][] = array('name' => 'styles', 'items' => array('Format','Font','FontSize'));
423 465
 				$config['toolbar'][] = array('name' => 'colors', 'items' => array('TextColor','BGColor'));
424 466
 				$config['toolbar'][] = array('name' => 'tools', 'items' => array('ShowBlocks','-','About'));
@@ -434,7 +476,10 @@  discard block
 block discarded – undo
434 476
 		self::set_csp_script_src_attrs();
435 477
 
436 478
 		// If not explicitly set, use preference for toolbar mode
437
-		if(!$mode || trim($mode) == '') $mode = $GLOBALS['egw_info']['user']['preferences']['common']['rte_features'];
479
+		if(!$mode || trim($mode) == '')
480
+		{
481
+			$mode = $GLOBALS['egw_info']['user']['preferences']['common']['rte_features'];
482
+		}
438 483
 		$config = array();
439 484
 		$spellchecker_button = null;
440 485
 
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   +78 added lines, -78 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.';">.?</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,77 +379,77 @@  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('phpgwapi','dialog_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('phpgwapi', 'dialog_error');
399 399
 			}
400
-			if (!preg_match('/^cid:.*/',$attribute_array['src']))
400
+			if (!preg_match('/^cid:.*/', $attribute_array['src']))
401 401
 			{
402 402
 				if (!$GLOBALS['egw_info']['user']['preferences']['mail']['allowExternalIMGs'])
403 403
 				{
404 404
 					//the own webserver url is not external, so it should be allowed
405
-					if (empty($GLOBALS['egw_info']['server']['webserver_url'])||!preg_match("$^".$GLOBALS['egw_info']['server']['webserver_url'].".*$",$attribute_array['src']))
405
+					if (empty($GLOBALS['egw_info']['server']['webserver_url']) || !preg_match("$^".$GLOBALS['egw_info']['server']['webserver_url'].".*$", $attribute_array['src']))
406 406
 					{
407
-						$attribute_array['alt']= $attribute_array['alt'].' [blocked external image:'.$attribute_array['src'].']';
408
-						if (!isset($attribute_array['title'])) $attribute_array['title']=$attribute_array['alt'];
409
-						$attribute_array['src']=Api\Image::find('mail','no-image-shown');
407
+						$attribute_array['alt'] = $attribute_array['alt'].' [blocked external image:'.$attribute_array['src'].']';
408
+						if (!isset($attribute_array['title'])) $attribute_array['title'] = $attribute_array['alt'];
409
+						$attribute_array['src'] = Api\Image::find('mail', 'no-image-shown');
410 410
 						$attribute_array['border'] = 1;
411 411
 						if ($attribute_array['style'])
412 412
 						{
413
-							if (stripos($attribute_array['style'],'border')!==false) $attribute_array['style'] = preg_replace('~border(:|-left:|-right:|-bottom:|-top:)+ (0px)+ (none)+;~si','',$attribute_array['style']);
413
+							if (stripos($attribute_array['style'], 'border') !== false) $attribute_array['style'] = preg_replace('~border(:|-left:|-right:|-bottom:|-top:)+ (0px)+ (none)+;~si', '', $attribute_array['style']);
414 414
 						}
415 415
 					}
416 416
 				}
417 417
 			}
418 418
 		}
419 419
 	}
420
-	if (isset($attribute_array['style']) && stripos($attribute_array['style'],'script')!==false) $attribute_array['style'] = str_ireplace('script','',$attribute_array['style']);
420
+	if (isset($attribute_array['style']) && stripos($attribute_array['style'], 'script') !== false) $attribute_array['style'] = str_ireplace('script', '', $attribute_array['style']);
421 421
 	if (isset($attribute_array['title']))
422 422
 	{
423
-		if (strpos($attribute_array['title'],'@')!==false) $attribute_array['title']=str_replace('@','(at)',$attribute_array['title']);
423
+		if (strpos($attribute_array['title'], '@') !== false) $attribute_array['title'] = str_replace('@', '(at)', $attribute_array['title']);
424 424
 	}
425 425
 	if ($element == 'blockquote')
426 426
 	{
427 427
 		if (isset($attribute_array['cite']))
428 428
 		{
429
-			if (strpos($attribute_array['cite'],'@')!==false) $attribute_array['cite']=str_replace('@','(at)',$attribute_array['cite']);
429
+			if (strpos($attribute_array['cite'], '@') !== false) $attribute_array['cite'] = str_replace('@', '(at)', $attribute_array['cite']);
430 430
 		}
431 431
 	}
432
-	if($element == 'a')
432
+	if ($element == 'a')
433 433
 	{
434 434
 		//error_log(__METHOD__.__LINE__.array2string($attribute_array));
435
-		if (strpos($attribute_array['href'],'denied:javascript')===0) $attribute_array['href']='';
435
+		if (strpos($attribute_array['href'], 'denied:javascript') === 0) $attribute_array['href'] = '';
436 436
 		if (isset($attribute_array['name']) && isset($attribute_array['id'])) $attribute_array['id'] = $attribute_array['name'];
437
-		if (strpos($attribute_array['href'],'@')!==false) $attribute_array['href'] = str_replace('@','%40',$attribute_array['href']);
438
-		if (strpos($attribute_array['href'],'#')===0 && (isset(Api\Mail::$htmLawed_config['transform_anchor']) && Api\Mail::$htmLawed_config['transform_anchor']===true))
437
+		if (strpos($attribute_array['href'], '@') !== false) $attribute_array['href'] = str_replace('@', '%40', $attribute_array['href']);
438
+		if (strpos($attribute_array['href'], '#') === 0 && (isset(Api\Mail::$htmLawed_config['transform_anchor']) && Api\Mail::$htmLawed_config['transform_anchor'] === true))
439 439
 		{
440
-			$attribute_array['href'] = "javascript:GoToAnchor('".trim(substr($attribute_array['href'],1))."');";
440
+			$attribute_array['href'] = "javascript:GoToAnchor('".trim(substr($attribute_array['href'], 1))."');";
441 441
 		}
442 442
 
443 443
 	}
444 444
 
445 445
 	// Build the attributes string
446 446
 	$attributes = '';
447
-	foreach($attribute_array as $k=>$v){
447
+	foreach ($attribute_array as $k=>$v) {
448 448
 		$attributes .= " {$k}=\"{$v}\"";
449 449
 	}
450 450
 
451 451
 	// Return the opening tag with attributes
452 452
 	static $empty_elements = array('area'=>1, 'br'=>1, 'col'=>1, 'embed'=>1, 'hr'=>1, 'img'=>1, 'input'=>1, 'isindex'=>1, 'param'=>1);
453
-	return "<{$element}{$attributes}". (isset($empty_elements[$element]) ? ' /' : ''). '>';
453
+	return "<{$element}{$attributes}".(isset($empty_elements[$element]) ? ' /' : '').'>';
454 454
 }
455 455
 
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('phpgwapi','dialog_error');
399 482
 			}
400 483
 			if (!preg_match('/^cid:.*/',$attribute_array['src']))
@@ -405,36 +488,60 @@  discard block
 block discarded – undo
405 488
 					if (empty($GLOBALS['egw_info']['server']['webserver_url'])||!preg_match("$^".$GLOBALS['egw_info']['server']['webserver_url'].".*$",$attribute_array['src']))
406 489
 					{
407 490
 						$attribute_array['alt']= $attribute_array['alt'].' [blocked external image:'.$attribute_array['src'].']';
408
-						if (!isset($attribute_array['title'])) $attribute_array['title']=$attribute_array['alt'];
491
+						if (!isset($attribute_array['title']))
492
+						{
493
+							$attribute_array['title']=$attribute_array['alt'];
494
+						}
409 495
 						$attribute_array['src']=Api\Image::find('mail','no-image-shown');
410 496
 						$attribute_array['border'] = 1;
411 497
 						if ($attribute_array['style'])
412 498
 						{
413
-							if (stripos($attribute_array['style'],'border')!==false) $attribute_array['style'] = preg_replace('~border(:|-left:|-right:|-bottom:|-top:)+ (0px)+ (none)+;~si','',$attribute_array['style']);
499
+							if (stripos($attribute_array['style'],'border')!==false)
500
+							{
501
+								$attribute_array['style'] = preg_replace('~border(:|-left:|-right:|-bottom:|-top:)+ (0px)+ (none)+;~si','',$attribute_array['style']);
502
+							}
414 503
 						}
415 504
 					}
416 505
 				}
417 506
 			}
418 507
 		}
419 508
 	}
420
-	if (isset($attribute_array['style']) && stripos($attribute_array['style'],'script')!==false) $attribute_array['style'] = str_ireplace('script','',$attribute_array['style']);
509
+	if (isset($attribute_array['style']) && stripos($attribute_array['style'],'script')!==false)
510
+	{
511
+		$attribute_array['style'] = str_ireplace('script','',$attribute_array['style']);
512
+	}
421 513
 	if (isset($attribute_array['title']))
422 514
 	{
423
-		if (strpos($attribute_array['title'],'@')!==false) $attribute_array['title']=str_replace('@','(at)',$attribute_array['title']);
515
+		if (strpos($attribute_array['title'],'@')!==false)
516
+		{
517
+			$attribute_array['title']=str_replace('@','(at)',$attribute_array['title']);
518
+		}
424 519
 	}
425 520
 	if ($element == 'blockquote')
426 521
 	{
427 522
 		if (isset($attribute_array['cite']))
428 523
 		{
429
-			if (strpos($attribute_array['cite'],'@')!==false) $attribute_array['cite']=str_replace('@','(at)',$attribute_array['cite']);
524
+			if (strpos($attribute_array['cite'],'@')!==false)
525
+			{
526
+				$attribute_array['cite']=str_replace('@','(at)',$attribute_array['cite']);
527
+			}
430 528
 		}
431 529
 	}
432 530
 	if($element == 'a')
433 531
 	{
434 532
 		//error_log(__METHOD__.__LINE__.array2string($attribute_array));
435
-		if (strpos($attribute_array['href'],'denied:javascript')===0) $attribute_array['href']='';
436
-		if (isset($attribute_array['name']) && isset($attribute_array['id'])) $attribute_array['id'] = $attribute_array['name'];
437
-		if (strpos($attribute_array['href'],'@')!==false) $attribute_array['href'] = str_replace('@','%40',$attribute_array['href']);
533
+		if (strpos($attribute_array['href'],'denied:javascript')===0)
534
+		{
535
+			$attribute_array['href']='';
536
+		}
537
+		if (isset($attribute_array['name']) && isset($attribute_array['id']))
538
+		{
539
+			$attribute_array['id'] = $attribute_array['name'];
540
+		}
541
+		if (strpos($attribute_array['href'],'@')!==false)
542
+		{
543
+			$attribute_array['href'] = str_replace('@','%40',$attribute_array['href']);
544
+		}
438 545
 		if (strpos($attribute_array['href'],'#')===0 && (isset(Api\Mail::$htmLawed_config['transform_anchor']) && Api\Mail::$htmLawed_config['transform_anchor']===true))
439 546
 		{
440 547
 			$attribute_array['href'] = "javascript:GoToAnchor('".trim(substr($attribute_array['href'],1))."');";
@@ -444,7 +551,8 @@  discard block
 block discarded – undo
444 551
 
445 552
 	// Build the attributes string
446 553
 	$attributes = '';
447
-	foreach($attribute_array as $k=>$v){
554
+	foreach($attribute_array as $k=>$v)
555
+	{
448 556
 		$attributes .= " {$k}=\"{$v}\"";
449 557
 	}
450 558
 
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   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
   elseif($do < 3 or isset($ok['#pcdata'])){echo $x;}
205 205
   elseif(strpos($x, "\x02\x04")){
206 206
    foreach(preg_split('`(\x01\x02[^\x01\x02]+\x02\x01)`', $x, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY) as $v){
207
-    echo (substr($v, 0, 2) == "\x01\x02" ? $v : ($do > 4 ? preg_replace('`\S`', '', $v) : ''));
207
+	echo (substr($v, 0, 2) == "\x01\x02" ? $v : ($do > 4 ? preg_replace('`\S`', '', $v) : ''));
208 208
    }
209 209
   }elseif($do > 4){echo preg_replace('`\S`', '', $x);}
210 210
  }
@@ -357,7 +357,7 @@  discard block
 block discarded – undo
357 357
    preg_match('`^([a-zA-Z\d\-+.]+://[^/]+)(.*)`', $C['base_url'], $m);
358 358
    $p = preg_replace('`(?<=/)\./`', '', $m[2]. $p);
359 359
    while(preg_match('`(?<=/)([^/]{3,}|[^/.]+?|\.[^/.]|[^/.]\.)/\.\./`', $p)){
360
-    $p = preg_replace('`(?<=/)([^/]{3,}|[^/.]+?|\.[^/.]|[^/.]\.)/\.\./`', '', $p);
360
+	$p = preg_replace('`(?<=/)([^/]{3,}|[^/.]+?|\.[^/.]|[^/.]\.)/\.\./`', '', $p);
361 361
    }
362 362
    $p = $m[1]. $p;
363 363
   }
@@ -471,20 +471,20 @@  discard block
 block discarded – undo
471 471
  switch($mode){
472 472
   case 0: // Name
473 473
    if(preg_match('`^[a-zA-Z][\-a-zA-Z:]+`', $a, $m)){
474
-    $nm = strtolower($m[0]);
475
-    $w = $mode = 1; $a = ltrim(substr_replace($a, '', 0, strlen($m[0])));
474
+	$nm = strtolower($m[0]);
475
+	$w = $mode = 1; $a = ltrim(substr_replace($a, '', 0, strlen($m[0])));
476 476
    }
477 477
   break; case 1:
478 478
    if($a[0] == '='){ // =
479
-    $w = 1; $mode = 2; $a = ltrim($a, '= ');
479
+	$w = 1; $mode = 2; $a = ltrim($a, '= ');
480 480
    }else{ // No val
481
-    $w = 1; $mode = 0; $a = ltrim($a);
482
-    $aA[$nm] = '';
481
+	$w = 1; $mode = 0; $a = ltrim($a);
482
+	$aA[$nm] = '';
483 483
    }
484 484
   break; case 2: // Val
485 485
    if(preg_match('`^((?:"[^"]*")|(?:\'[^\']*\')|(?:\s*[^\s"\']+))(.*)`', $a, $m)){
486
-    $a = ltrim($m[2]); $m = $m[1]; $w = 1; $mode = 0;
487
-    $aA[$nm] = trim(($m[0] == '"' or $m[0] == '\'') ? substr($m, 1, -1) : $m);
486
+	$a = ltrim($m[2]); $m = $m[1]; $w = 1; $mode = 0;
487
+	$aA[$nm] = trim(($m[0] == '"' or $m[0] == '\'') ? substr($m, 1, -1) : $m);
488 488
    }
489 489
   break;
490 490
  }
@@ -507,8 +507,8 @@  discard block
 block discarded – undo
507 507
   }
508 508
   if($k == 'style' && !$C['style_pass']){
509 509
    if(false !== strpos($v, '&#')){
510
-    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;'=>'\\');
511
-    $v = strtr($v, $sC);
510
+	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;'=>'\\');
511
+	$v = strtr($v, $sC);
512 512
    }
513 513
    $v = preg_replace_callback('`(url(?:\()(?: )*(?:\'|"|&(?:quot|apos);)?)(.+?)((?:\'|"|&(?:quot|apos);)?(?: )*(?:\)))`iS', 'hl_prot', $v);
514 514
    $v = !$C['css_expression'] ? preg_replace('`expression`i', ' ', preg_replace('`\\\\\S|(/|(%2f))(\*|(%2a))`i', ' ', $v)) : $v;
@@ -516,20 +516,20 @@  discard block
 block discarded – undo
516 516
    $v = str_replace("\xad", ' ', (strpos($v, '&') !== false ? str_replace(array('&#xad;', '&#173;', '&shy;'), ' ', $v) : $v));
517 517
    $v = hl_prot($v, $k);
518 518
    if($k == 'href'){ // X-spam
519
-    if($C['anti_mail_spam'] && strpos($v, 'mailto:') === 0){
520
-     $v = str_replace('@', htmlspecialchars($C['anti_mail_spam']), $v);
521
-    }elseif($C['anti_link_spam']){
522
-     $r1 = $C['anti_link_spam'][1];
523
-     if(!empty($r1) && preg_match($r1, $v)){continue;}
524
-     $r0 = $C['anti_link_spam'][0];
525
-     if(!empty($r0) && preg_match($r0, $v)){
526
-      if(isset($a['rel'])){
527
-       if(!preg_match('`\bnofollow\b`i', $a['rel'])){$a['rel'] .= ' nofollow';}
528
-      }elseif(isset($aA['rel'])){
529
-       if(!preg_match('`\bnofollow\b`i', $aA['rel'])){$nfr = 1;}
530
-      }else{$a['rel'] = 'nofollow';}
531
-     }
532
-    }
519
+	if($C['anti_mail_spam'] && strpos($v, 'mailto:') === 0){
520
+	 $v = str_replace('@', htmlspecialchars($C['anti_mail_spam']), $v);
521
+	}elseif($C['anti_link_spam']){
522
+	 $r1 = $C['anti_link_spam'][1];
523
+	 if(!empty($r1) && preg_match($r1, $v)){continue;}
524
+	 $r0 = $C['anti_link_spam'][0];
525
+	 if(!empty($r0) && preg_match($r0, $v)){
526
+	  if(isset($a['rel'])){
527
+	   if(!preg_match('`\bnofollow\b`i', $a['rel'])){$a['rel'] .= ' nofollow';}
528
+	  }elseif(isset($aA['rel'])){
529
+	   if(!preg_match('`\bnofollow\b`i', $aA['rel'])){$nfr = 1;}
530
+	  }else{$a['rel'] = 'nofollow';}
531
+	 }
532
+	}
533 533
    }
534 534
   }
535 535
   if(isset($rl[$k]) && is_array($rl[$k]) && ($v = hl_attrval($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.
Spacing   +295 added lines, -295 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,41 +109,41 @@  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($t, $p){
118
+function hl_attrval($t, $p) {
119 119
 // check attr val against $S
120 120
 $o = 1; $l = strlen($t);
121
-foreach($p as $k=>$v){
122
- switch($k){
123
-  case 'maxlen':if($l > $v){$o = 0;}
124
-  break; case 'minlen': if($l < $v){$o = 0;}
125
-  break; case 'maxval': if((float)($t) > $v){$o = 0;}
126
-  break; case 'minval': if((float)($t) < $v){$o = 0;}
127
-  break; case 'match': if(!preg_match($v, $t)){$o = 0;}
128
-  break; case 'nomatch': if(preg_match($v, $t)){$o = 0;}
121
+foreach ($p as $k=>$v) {
122
+ switch ($k) {
123
+  case 'maxlen':if ($l > $v) {$o = 0; }
124
+  break; case 'minlen': if ($l < $v) {$o = 0; }
125
+  break; case 'maxval': if ((float)($t) > $v) {$o = 0; }
126
+  break; case 'minval': if ((float)($t) < $v) {$o = 0; }
127
+  break; case 'match': if (!preg_match($v, $t)) {$o = 0; }
128
+  break; case 'nomatch': if (preg_match($v, $t)) {$o = 0; }
129 129
   break; case 'oneof':
130 130
    $m = 0;
131
-   foreach(explode('|', $v) as $n){if($t == $n){$m = 1; break;}}
131
+   foreach (explode('|', $v) as $n) {if ($t == $n) {$m = 1; break; }}
132 132
    $o = $m;
133 133
   break; case 'noneof':
134 134
    $m = 1;
135
-   foreach(explode('|', $v) as $n){if($t == $n){$m = 0; break;}}
135
+   foreach (explode('|', $v) as $n) {if ($t == $n) {$m = 0; break; }}
136 136
    $o = $m;
137 137
   break; default:
138 138
   break;
139 139
  }
140
- if(!$o){break;}
140
+ if (!$o) {break; }
141 141
 }
142 142
 return ($o ? $t : (isset($p['default']) ? $p['default'] : 0));
143 143
 // eof
144 144
 }
145 145
 
146
-function hl_bal($t, $do=1, $in='div'){
146
+function hl_bal($t, $do = 1, $in = 'div') {
147 147
 // balance tags
148 148
 // by content
149 149
 $cB = array('blockquote'=>1, 'form'=>1, 'map'=>1, 'noscript'=>1); // Block
@@ -154,212 +154,212 @@  discard block
 block discarded – undo
154 154
 $cN2 = array_keys($cN);
155 155
 $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);
156 156
 $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
157
-if($GLOBALS['C']['direct_list_nest']){$cS['ol'] = $cS['ul'] += array('ol'=>1, 'ul'=>1);}
157
+if ($GLOBALS['C']['direct_list_nest']) {$cS['ol'] = $cS['ul'] += array('ol'=>1, 'ul'=>1); }
158 158
 $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
159 159
 $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
160 160
 // block/inline type; ins & del both type; #pcdata: text
161 161
 $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);
162 162
 $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);
163
-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
163
+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
164 164
 $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
165 165
 $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
166 166
 $eF = $eB + $eI;
167 167
 
168 168
 // $in sets allowed child
169 169
 $in = ((isset($eF[$in]) && $in != '#pcdata') or isset($eO[$in])) ? $in : 'div';
170
-if(isset($cE[$in])){
170
+if (isset($cE[$in])) {
171 171
  return (!$do ? '' : str_replace(array('<', '>'), array('&lt;', '&gt;'), $t));
172 172
 }
173
-if(isset($cS[$in])){$inOk = $cS[$in];}
174
-elseif(isset($cI[$in])){$inOk = $eI; $cI['del'] = 1; $cI['ins'] = 1;}
175
-elseif(isset($cF[$in])){$inOk = $eF; unset($cI['del'], $cI['ins']);}
176
-elseif(isset($cB[$in])){$inOk = $eB; unset($cI['del'], $cI['ins']);}
177
-if(isset($cO[$in])){$inOk = $inOk + $cO[$in];}
178
-if(isset($cN[$in])){$inOk = array_diff_assoc($inOk, $cN[$in]);}
173
+if (isset($cS[$in])) {$inOk = $cS[$in]; }
174
+elseif (isset($cI[$in])) {$inOk = $eI; $cI['del'] = 1; $cI['ins'] = 1; }
175
+elseif (isset($cF[$in])) {$inOk = $eF; unset($cI['del'], $cI['ins']); }
176
+elseif (isset($cB[$in])) {$inOk = $eB; unset($cI['del'], $cI['ins']); }
177
+if (isset($cO[$in])) {$inOk = $inOk + $cO[$in]; }
178
+if (isset($cN[$in])) {$inOk = array_diff_assoc($inOk, $cN[$in]); }
179 179
 
180 180
 $t = explode('<', $t);
181 181
 $ok = $q = array(); // $q seq list of open non-empty ele
182 182
 ob_start();
183 183
 
184
-for($i=-1, $ci=count($t); ++$i<$ci;){
184
+for ($i = -1, $ci = count($t); ++$i < $ci;) {
185 185
  // allowed $ok in parent $p
186
- if($ql = count($q)){
186
+ if ($ql = count($q)) {
187 187
   $p = array_pop($q);
188 188
   $q[] = $p;
189
-  if(isset($cS[$p])){$ok = $cS[$p];}
190
-  elseif(isset($cI[$p])){$ok = $eI; $cI['del'] = 1; $cI['ins'] = 1;}
191
-  elseif(isset($cF[$p])){$ok = $eF; unset($cI['del'], $cI['ins']);}
192
-  elseif(isset($cB[$p])){$ok = $eB; unset($cI['del'], $cI['ins']);}
193
-  if(isset($cO[$p])){$ok = $ok + $cO[$p];}
194
-  if(isset($cN[$p])){$ok = array_diff_assoc($ok, $cN[$p]);}
195
- }else{$ok = $inOk; unset($cI['del'], $cI['ins']);}
189
+  if (isset($cS[$p])) {$ok = $cS[$p]; }
190
+  elseif (isset($cI[$p])) {$ok = $eI; $cI['del'] = 1; $cI['ins'] = 1; }
191
+  elseif (isset($cF[$p])) {$ok = $eF; unset($cI['del'], $cI['ins']); }
192
+  elseif (isset($cB[$p])) {$ok = $eB; unset($cI['del'], $cI['ins']); }
193
+  if (isset($cO[$p])) {$ok = $ok + $cO[$p]; }
194
+  if (isset($cN[$p])) {$ok = array_diff_assoc($ok, $cN[$p]); }
195
+ } else {$ok = $inOk; unset($cI['del'], $cI['ins']); }
196 196
  // bad tags, & ele content
197
- if(isset($e) && ($do == 1 or (isset($ok['#pcdata']) && ($do == 3 or $do == 5)))){
197
+ if (isset($e) && ($do == 1 or (isset($ok['#pcdata']) && ($do == 3 or $do == 5)))) {
198 198
   echo '&lt;', $s, $e, $a, '&gt;';
199 199
  }
200
- if(isset($x[0])){
201
-  if(strlen(trim($x)) && (($ql && isset($cB[$p])) or (isset($cB[$in]) && !$ql))){
200
+ if (isset($x[0])) {
201
+  if (strlen(trim($x)) && (($ql && isset($cB[$p])) or (isset($cB[$in]) && !$ql))) {
202 202
    echo '<div>', $x, '</div>';
203 203
   }
204
-  elseif($do < 3 or isset($ok['#pcdata'])){echo $x;}
205
-  elseif(strpos($x, "\x02\x04")){
206
-   foreach(preg_split('`(\x01\x02[^\x01\x02]+\x02\x01)`', $x, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY) as $v){
204
+  elseif ($do < 3 or isset($ok['#pcdata'])) {echo $x; }
205
+  elseif (strpos($x, "\x02\x04")) {
206
+   foreach (preg_split('`(\x01\x02[^\x01\x02]+\x02\x01)`', $x, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY) as $v) {
207 207
     echo (substr($v, 0, 2) == "\x01\x02" ? $v : ($do > 4 ? preg_replace('`\S`', '', $v) : ''));
208 208
    }
209
-  }elseif($do > 4){echo preg_replace('`\S`', '', $x);}
209
+  }elseif ($do > 4) {echo preg_replace('`\S`', '', $x); }
210 210
  }
211 211
  // get markup
212
- if(!preg_match('`^(/?)([a-z1-6]+)([^>]*)>(.*)`sm', $t[$i], $r)){$x = $t[$i]; continue;}
212
+ if (!preg_match('`^(/?)([a-z1-6]+)([^>]*)>(.*)`sm', $t[$i], $r)) {$x = $t[$i]; continue; }
213 213
  $s = null; $e = null; $a = null; $x = null; list($all, $s, $e, $a, $x) = $r;
214 214
  // close tag
215
- if($s){
216
-  if(isset($cE[$e]) or !in_array($e, $q)){continue;} // Empty/unopen
217
-  if($p == $e){array_pop($q); echo '</', $e, '>'; unset($e); continue;} // Last open
215
+ if ($s) {
216
+  if (isset($cE[$e]) or !in_array($e, $q)) {continue; } // Empty/unopen
217
+  if ($p == $e) {array_pop($q); echo '</', $e, '>'; unset($e); continue; } // Last open
218 218
   $add = ''; // Nesting - close open tags that need to be
219
-  for($j=-1, $cj=count($q); ++$j<$cj;){
220
-   if(($d = array_pop($q)) == $e){break;}
221
-   else{$add .= "</{$d}>";}
219
+  for ($j = -1, $cj = count($q); ++$j < $cj;) {
220
+   if (($d = array_pop($q)) == $e) {break; }
221
+   else {$add .= "</{$d}>"; }
222 222
   }
223 223
   echo $add, '</', $e, '>'; unset($e); continue;
224 224
  }
225 225
  // open tag
226 226
  // $cB ele needs $eB ele as child
227
- if(isset($cB[$e]) && strlen(trim($x))){
227
+ if (isset($cB[$e]) && strlen(trim($x))) {
228 228
   $t[$i] = "{$e}{$a}>";
229
-  array_splice($t, $i+1, 0, 'div>'. $x); unset($e, $x); ++$ci; --$i; continue;
229
+  array_splice($t, $i + 1, 0, 'div>'.$x); unset($e, $x); ++$ci; --$i; continue;
230 230
  }
231
- if((($ql && isset($cB[$p])) or (isset($cB[$in]) && !$ql)) && !isset($eB[$e]) && !isset($ok[$e])){
231
+ if ((($ql && isset($cB[$p])) or (isset($cB[$in]) && !$ql)) && !isset($eB[$e]) && !isset($ok[$e])) {
232 232
   array_splice($t, $i, 0, 'div>'); unset($e, $x); ++$ci; --$i; continue;
233 233
  }
234
- if($e == 'div' && !isset($ok['div']) && strpos($a, '-htmlawed-transform')){
234
+ if ($e == 'div' && !isset($ok['div']) && strpos($a, '-htmlawed-transform')) {
235 235
   $t[$i] = "span{$a}>{$x}"; unset($e, $x); --$i; continue;
236 236
  }
237 237
  // if no open ele, $in = parent; mostly immediate parent-child relation should hold
238
- if(!$ql or !isset($eN[$e]) or !array_intersect($q, $cN2)){
239
-  if(!isset($ok[$e])){
240
-   if($ql && isset($cT[$p])){echo '</', array_pop($q), '>'; unset($e, $x); --$i;}
238
+ if (!$ql or !isset($eN[$e]) or !array_intersect($q, $cN2)) {
239
+  if (!isset($ok[$e])) {
240
+   if ($ql && isset($cT[$p])) {echo '</', array_pop($q), '>'; unset($e, $x); --$i; }
241 241
    continue;
242 242
   }
243
-  if(!isset($cE[$e])){$q[] = $e;}
243
+  if (!isset($cE[$e])) {$q[] = $e; }
244 244
   echo '<', $e, $a, '>'; unset($e); continue;
245 245
  }
246 246
  // specific parent-child
247
- if(isset($cS[$p][$e])){
248
-  if(!isset($cE[$e])){$q[] = $e;}
247
+ if (isset($cS[$p][$e])) {
248
+  if (!isset($cE[$e])) {$q[] = $e; }
249 249
   echo '<', $e, $a, '>'; unset($e); continue;
250 250
  }
251 251
  // nesting
252 252
  $add = '';
253 253
  $q2 = array();
254
- for($k=-1, $kc=count($q); ++$k<$kc;){
254
+ for ($k = -1, $kc = count($q); ++$k < $kc;) {
255 255
   $d = $q[$k];
256 256
   $ok2 = array();
257
-  if(isset($cS[$d])){$q2[] = $d; continue;}
257
+  if (isset($cS[$d])) {$q2[] = $d; continue; }
258 258
   $ok2 = isset($cI[$d]) ? $eI : $eF;
259
-  if(isset($cO[$d])){$ok2 = $ok2 + $cO[$d];}
260
-  if(isset($cN[$d])){$ok2 = array_diff_assoc($ok2, $cN[$d]);}
261
-  if(!isset($ok2[$e])){
262
-   if(!$k && !isset($inOk[$e])){continue 2;}
259
+  if (isset($cO[$d])) {$ok2 = $ok2 + $cO[$d]; }
260
+  if (isset($cN[$d])) {$ok2 = array_diff_assoc($ok2, $cN[$d]); }
261
+  if (!isset($ok2[$e])) {
262
+   if (!$k && !isset($inOk[$e])) {continue 2; }
263 263
    $add = "</{$d}>";
264
-   for(;++$k<$kc;){$add = "</{$q[$k]}>{$add}";}
264
+   for (;++$k < $kc;) {$add = "</{$q[$k]}>{$add}"; }
265 265
    break;
266 266
   }
267
-  else{$q2[] = $d;}
267
+  else {$q2[] = $d; }
268 268
  }
269 269
  $q = $q2;
270
- if(!isset($cE[$e])){$q[] = $e;}
270
+ if (!isset($cE[$e])) {$q[] = $e; }
271 271
  echo $add, '<', $e, $a, '>'; unset($e); continue;
272 272
 }
273 273
 
274 274
 // end
275
-if($ql = count($q)){
275
+if ($ql = count($q)) {
276 276
  $p = array_pop($q);
277 277
  $q[] = $p;
278
- if(isset($cS[$p])){$ok = $cS[$p];}
279
- elseif(isset($cI[$p])){$ok = $eI; $cI['del'] = 1; $cI['ins'] = 1;}
280
- elseif(isset($cF[$p])){$ok = $eF; unset($cI['del'], $cI['ins']);}
281
- elseif(isset($cB[$p])){$ok = $eB; unset($cI['del'], $cI['ins']);}
282
- if(isset($cO[$p])){$ok = $ok + $cO[$p];}
283
- if(isset($cN[$p])){$ok = array_diff_assoc($ok, $cN[$p]);}
284
-}else{$ok = $inOk; unset($cI['del'], $cI['ins']);}
285
-if(isset($e) && ($do == 1 or (isset($ok['#pcdata']) && ($do == 3 or $do == 5)))){
278
+ if (isset($cS[$p])) {$ok = $cS[$p]; }
279
+ elseif (isset($cI[$p])) {$ok = $eI; $cI['del'] = 1; $cI['ins'] = 1; }
280
+ elseif (isset($cF[$p])) {$ok = $eF; unset($cI['del'], $cI['ins']); }
281
+ elseif (isset($cB[$p])) {$ok = $eB; unset($cI['del'], $cI['ins']); }
282
+ if (isset($cO[$p])) {$ok = $ok + $cO[$p]; }
283
+ if (isset($cN[$p])) {$ok = array_diff_assoc($ok, $cN[$p]); }
284
+} else {$ok = $inOk; unset($cI['del'], $cI['ins']); }
285
+if (isset($e) && ($do == 1 or (isset($ok['#pcdata']) && ($do == 3 or $do == 5)))) {
286 286
  echo '&lt;', $s, $e, $a, '&gt;';
287 287
 }
288
-if(isset($x[0])){
289
- if(strlen(trim($x)) && (($ql && isset($cB[$p])) or (isset($cB[$in]) && !$ql))){
288
+if (isset($x[0])) {
289
+ if (strlen(trim($x)) && (($ql && isset($cB[$p])) or (isset($cB[$in]) && !$ql))) {
290 290
   echo '<div>', $x, '</div>';
291 291
  }
292
- elseif($do < 3 or isset($ok['#pcdata'])){echo $x;}
293
- elseif(strpos($x, "\x02\x04")){
294
-  foreach(preg_split('`(\x01\x02[^\x01\x02]+\x02\x01)`', $x, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY) as $v){
292
+ elseif ($do < 3 or isset($ok['#pcdata'])) {echo $x; }
293
+ elseif (strpos($x, "\x02\x04")) {
294
+  foreach (preg_split('`(\x01\x02[^\x01\x02]+\x02\x01)`', $x, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY) as $v) {
295 295
    echo (substr($v, 0, 2) == "\x01\x02" ? $v : ($do > 4 ? preg_replace('`\S`', '', $v) : ''));
296 296
   }
297
- }elseif($do > 4){echo preg_replace('`\S`', '', $x);}
297
+ }elseif ($do > 4) {echo preg_replace('`\S`', '', $x); }
298 298
 }
299
-while(!empty($q) && ($e = array_pop($q))){echo '</', $e, '>';}
299
+while (!empty($q) && ($e = array_pop($q))) {echo '</', $e, '>'; }
300 300
 $o = ob_get_contents();
301 301
 ob_end_clean();
302 302
 return $o;
303 303
 // eof
304 304
 }
305 305
 
306
-function hl_cmtcd($t){
306
+function hl_cmtcd($t) {
307 307
 // comment/CDATA sec handler
308 308
 $t = $t[0];
309 309
 global $C;
310
-if(!($v = $C[$n = $t[3] == '-' ? 'comment' : 'cdata'])){return $t;}
311
-if($v == 1){return '';}
312
-if($n == 'comment'){
313
- if(substr(($t = preg_replace('`--+`', '-', substr($t, 4, -3))), -1) != ' '){$t .= ' ';}
310
+if (!($v = $C[$n = $t[3] == '-' ? 'comment' : 'cdata'])) {return $t; }
311
+if ($v == 1) {return ''; }
312
+if ($n == 'comment') {
313
+ if (substr(($t = preg_replace('`--+`', '-', substr($t, 4, -3))), -1) != ' ') {$t .= ' '; }
314 314
 }
315
-else{$t = substr($t, 1, -1);}
315
+else {$t = substr($t, 1, -1); }
316 316
 $t = $v == 2 ? str_replace(array('&', '<', '>'), array('&amp;', '&lt;', '&gt;'), $t) : $t;
317 317
 return str_replace(array('&', '<', '>'), array("\x03", "\x04", "\x05"), ($n == 'comment' ? "\x01\x02\x04!--$t--\x05\x02\x01" : "\x01\x01\x04$t\x05\x01\x01"));
318 318
 // eof
319 319
 }
320 320
 
321
-function hl_ent($t){
321
+function hl_ent($t) {
322 322
 // entitity handler
323 323
 global $C;
324 324
 $t = $t[1];
325
-static $U = array('quot'=>1,'amp'=>1,'lt'=>1,'gt'=>1);
326
-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');
327
-if($t[0] != '#'){
328
- 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)). ';';
325
+static $U = array('quot'=>1, 'amp'=>1, 'lt'=>1, 'gt'=>1);
326
+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');
327
+if ($t[0] != '#') {
328
+ 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)).';';
329 329
 }
330
-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))){
331
- return ($C['and_mark'] ? "\x06" : '&'). "amp;#{$t};";
330
+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))) {
331
+ return ($C['and_mark'] ? "\x06" : '&')."amp;#{$t};";
332 332
 }
333
-return ($C['and_mark'] ? "\x06" : '&'). '#'. (((ctype_digit($t) && $C['hexdec_entity'] < 2) or !$C['hexdec_entity']) ? $n : 'x'. dechex($n)). ';';
333
+return ($C['and_mark'] ? "\x06" : '&').'#'.(((ctype_digit($t) && $C['hexdec_entity'] < 2) or !$C['hexdec_entity']) ? $n : 'x'.dechex($n)).';';
334 334
 // eof
335 335
 }
336 336
 
337
-function hl_prot($p, $c=null){
337
+function hl_prot($p, $c = null) {
338 338
 // check URL scheme
339 339
 global $C;
340 340
 $b = $a = '';
341
-if($c == null){$c = 'style'; $b = $p[1]; $a = $p[3]; $p = trim($p[2]);}
341
+if ($c == null) {$c = 'style'; $b = $p[1]; $a = $p[3]; $p = trim($p[2]); }
342 342
 $c = isset($C['schemes'][$c]) ? $C['schemes'][$c] : $C['schemes']['*'];
343 343
 static $d = 'denied:';
344
-if(isset($c['!']) && substr($p, 0, 7) != $d){$p = "$d$p";}
345
-if(isset($c['*']) or !strcspn($p, '#?;') or (substr($p, 0, 7) == $d)){return "{$b}{$p}{$a}";} // All ok, frag, query, param
346
-if(preg_match('`^([^:?[@!$()*,=/\'\]]+?)(:|&#(58|x3a);|%3a|\\\\0{0,4}3a).`i', $p, $m) && !isset($c[strtolower($m[1])])){ // Denied prot
344
+if (isset($c['!']) && substr($p, 0, 7) != $d) {$p = "$d$p"; }
345
+if (isset($c['*']) or !strcspn($p, '#?;') or (substr($p, 0, 7) == $d)) {return "{$b}{$p}{$a}"; } // All ok, frag, query, param
346
+if (preg_match('`^([^:?[@!$()*,=/\'\]]+?)(:|&#(58|x3a);|%3a|\\\\0{0,4}3a).`i', $p, $m) && !isset($c[strtolower($m[1])])) { // Denied prot
347 347
  return "{$b}{$d}{$p}{$a}";
348 348
 }
349
-if($C['abs_url']){
350
- if($C['abs_url'] == -1 && strpos($p, $C['base_url']) === 0){ // Make url rel
349
+if ($C['abs_url']) {
350
+ if ($C['abs_url'] == -1 && strpos($p, $C['base_url']) === 0) { // Make url rel
351 351
   $p = substr($p, strlen($C['base_url']));
352
- }elseif(empty($m[1])){ // Make URL abs
353
-  if(substr($p, 0, 2) == '//'){$p = substr($C['base_url'], 0, strpos($C['base_url'], ':')+1). $p;}
354
-  elseif($p[0] == '/'){$p = preg_replace('`(^.+?://[^/]+)(.*)`', '$1', $C['base_url']). $p;}
355
-  elseif(strcspn($p, './')){$p = $C['base_url']. $p;}
356
-  else{
352
+ }elseif (empty($m[1])) { // Make URL abs
353
+  if (substr($p, 0, 2) == '//') {$p = substr($C['base_url'], 0, strpos($C['base_url'], ':') + 1).$p; }
354
+  elseif ($p[0] == '/') {$p = preg_replace('`(^.+?://[^/]+)(.*)`', '$1', $C['base_url']).$p; }
355
+  elseif (strcspn($p, './')) {$p = $C['base_url'].$p; }
356
+  else {
357 357
    preg_match('`^([a-zA-Z\d\-+.]+://[^/]+)(.*)`', $C['base_url'], $m);
358
-   $p = preg_replace('`(?<=/)\./`', '', $m[2]. $p);
359
-   while(preg_match('`(?<=/)([^/]{3,}|[^/.]+?|\.[^/.]|[^/.]\.)/\.\./`', $p)){
358
+   $p = preg_replace('`(?<=/)\./`', '', $m[2].$p);
359
+   while (preg_match('`(?<=/)([^/]{3,}|[^/.]+?|\.[^/.]|[^/.]\.)/\.\./`', $p)) {
360 360
     $p = preg_replace('`(?<=/)([^/]{3,}|[^/.]+?|\.[^/.]|[^/.]\.)/\.\./`', '', $p);
361 361
    }
362
-   $p = $m[1]. $p;
362
+   $p = $m[1].$p;
363 363
   }
364 364
  }
365 365
 }
@@ -367,88 +367,88 @@  discard block
 block discarded – undo
367 367
 // eof
368 368
 }
369 369
 
370
-function hl_regex($p){
370
+function hl_regex($p) {
371 371
 // ?regex
372
-if(empty($p)){return 0;}
373
-if($t = ini_get('track_errors')){$o = isset($php_errormsg) ? $php_errormsg : null;}
374
-else{ini_set('track_errors', 1);}
372
+if (empty($p)) {return 0; }
373
+if ($t = ini_get('track_errors')) {$o = isset($php_errormsg) ? $php_errormsg : null; }
374
+else {ini_set('track_errors', 1); }
375 375
 unset($php_errormsg);
376
-if(($d = ini_get('display_errors'))){ini_set('display_errors', 0);}
376
+if (($d = ini_get('display_errors'))) {ini_set('display_errors', 0); }
377 377
 preg_match($p, '');
378
-if($d){ini_set('display_errors', 1);}
378
+if ($d) {ini_set('display_errors', 1); }
379 379
 $r = isset($php_errormsg) ? 0 : 1;
380
-if($t){$php_errormsg = isset($o) ? $o : null;}
381
-else{ini_set('track_errors', 0);}
380
+if ($t) {$php_errormsg = isset($o) ? $o : null; }
381
+else {ini_set('track_errors', 0); }
382 382
 return $r;
383 383
 // eof
384 384
 }
385 385
 
386
-function hl_spec($t){
386
+function hl_spec($t) {
387 387
 // final $spec
388 388
 $s = array();
389 389
 $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)));
390
-for($i = count(($t = explode(';', $t))); --$i>=0;){
390
+for ($i = count(($t = explode(';', $t))); --$i >= 0;) {
391 391
  $w = $t[$i];
392
- if(empty($w) or ($e = strpos($w, '=')) === false or !strlen(($a =  substr($w, $e+1)))){continue;}
392
+ if (empty($w) or ($e = strpos($w, '=')) === false or !strlen(($a = substr($w, $e + 1)))) {continue; }
393 393
  $y = $n = array();
394
- foreach(explode(',', $a) as $v){
395
-  if(!preg_match('`^([a-z:\-\*]+)(?:\((.*?)\))?`i', $v, $m)){continue;}
396
-  if(($x = strtolower($m[1])) == '-*'){$n['*'] = 1; continue;}
397
-  if($x[0] == '-'){$n[substr($x, 1)] = 1; continue;}
398
-  if(!isset($m[2])){$y[$x] = 1; continue;}
399
-  foreach(explode('/', $m[2]) as $m){
400
-   if(empty($m) or ($p = strpos($m, '=')) == 0 or $p < 5){$y[$x] = 1; continue;}
401
-   $y[$x][strtolower(substr($m, 0, $p))] = str_replace(array("\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07", "\x08"), array(";", "|", "~", " ", ",", "/", "(", ")"), substr($m, $p+1));
394
+ foreach (explode(',', $a) as $v) {
395
+  if (!preg_match('`^([a-z:\-\*]+)(?:\((.*?)\))?`i', $v, $m)) {continue; }
396
+  if (($x = strtolower($m[1])) == '-*') {$n['*'] = 1; continue; }
397
+  if ($x[0] == '-') {$n[substr($x, 1)] = 1; continue; }
398
+  if (!isset($m[2])) {$y[$x] = 1; continue; }
399
+  foreach (explode('/', $m[2]) as $m) {
400
+   if (empty($m) or ($p = strpos($m, '=')) == 0 or $p < 5) {$y[$x] = 1; continue; }
401
+   $y[$x][strtolower(substr($m, 0, $p))] = str_replace(array("\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07", "\x08"), array(";", "|", "~", " ", ",", "/", "(", ")"), substr($m, $p + 1));
402 402
   }
403
-  if(isset($y[$x]['match']) && !hl_regex($y[$x]['match'])){unset($y[$x]['match']);}
404
-  if(isset($y[$x]['nomatch']) && !hl_regex($y[$x]['nomatch'])){unset($y[$x]['nomatch']);}
403
+  if (isset($y[$x]['match']) && !hl_regex($y[$x]['match'])) {unset($y[$x]['match']); }
404
+  if (isset($y[$x]['nomatch']) && !hl_regex($y[$x]['nomatch'])) {unset($y[$x]['nomatch']); }
405 405
  }
406
- if(!count($y) && !count($n)){continue;}
407
- foreach(explode(',', substr($w, 0, $e)) as $v){
408
-  if(!strlen(($v = strtolower($v)))){continue;}
409
-  if(count($y)){$s[$v] = $y;}
410
-  if(count($n)){$s[$v]['n'] = $n;}
406
+ if (!count($y) && !count($n)) {continue; }
407
+ foreach (explode(',', substr($w, 0, $e)) as $v) {
408
+  if (!strlen(($v = strtolower($v)))) {continue; }
409
+  if (count($y)) {$s[$v] = $y; }
410
+  if (count($n)) {$s[$v]['n'] = $n; }
411 411
  }
412 412
 }
413 413
 return $s;
414 414
 // eof
415 415
 }
416 416
 
417
-function hl_tag($t){
417
+function hl_tag($t) {
418 418
 // tag/attribute handler
419 419
 global $C;
420 420
 $t = $t[0];
421 421
 // invalid < >
422
-if($t == '< '){return '&lt; ';}
423
-if($t == '>'){return '&gt;';}
424
-if(!preg_match('`^<(/?)([a-zA-Z][a-zA-Z1-6]*)([^>]*?)\s?>$`m', $t, $m)){
422
+if ($t == '< ') {return '&lt; '; }
423
+if ($t == '>') {return '&gt;'; }
424
+if (!preg_match('`^<(/?)([a-zA-Z][a-zA-Z1-6]*)([^>]*?)\s?>$`m', $t, $m)) {
425 425
  //return str_replace(array('<', '>'), array('&lt;', '&gt;'), $t);
426
- return (($C['keep_bad']%2) ? str_replace(array('<', '>'), array('&lt;', '&gt;'), $t) : '');
427
-}elseif(!isset($C['elements'][($e = strtolower($m[2]))])){
428
- return (($C['keep_bad']%2) ? str_replace(array('<', '>'), array('&lt;', '&gt;'), $t) : '');
426
+ return (($C['keep_bad'] % 2) ? str_replace(array('<', '>'), array('&lt;', '&gt;'), $t) : '');
427
+}elseif (!isset($C['elements'][($e = strtolower($m[2]))])) {
428
+ return (($C['keep_bad'] % 2) ? str_replace(array('<', '>'), array('&lt;', '&gt;'), $t) : '');
429 429
 }
430 430
 // attr string
431 431
 $a = str_replace(array("\n", "\r", "\t"), ' ', trim($m[3]));
432 432
 // tag transform
433 433
 static $eD = array('applet'=>1, 'center'=>1, 'dir'=>1, 'embed'=>1, 'font'=>1, 'isindex'=>1, 'menu'=>1, 's'=>1, 'strike'=>1, 'u'=>1); // Deprecated
434
-if($C['make_tag_strict'] && isset($eD[$e])){
434
+if ($C['make_tag_strict'] && isset($eD[$e])) {
435 435
  $trt = hl_tag2($e, $a, $C['make_tag_strict']);
436
- if(!$e){return (($C['keep_bad']%2) ? str_replace(array('<', '>'), array('&lt;', '&gt;'), $t) : '');}
436
+ if (!$e) {return (($C['keep_bad'] % 2) ? str_replace(array('<', '>'), array('&lt;', '&gt;'), $t) : ''); }
437 437
 }
438 438
 // close tag
439 439
 static $eE = array('area'=>1, 'br'=>1, 'col'=>1, 'embed'=>1, 'hr'=>1, 'img'=>1, 'input'=>1, 'isindex'=>1, 'param'=>1); // Empty ele
440
-if(!empty($m[1])){
441
- return (!isset($eE[$e]) ? (empty($C['hook_tag']) ? "</$e>" : $C['hook_tag']($e)) : (($C['keep_bad'])%2 ? str_replace(array('<', '>'), array('&lt;', '&gt;'), $t) : ''));
440
+if (!empty($m[1])) {
441
+ return (!isset($eE[$e]) ? (empty($C['hook_tag']) ? "</$e>" : $C['hook_tag']($e)) : (($C['keep_bad']) % 2 ? str_replace(array('<', '>'), array('&lt;', '&gt;'), $t) : ''));
442 442
 }
443 443
 
444 444
 // open tag & attr
445 445
 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), '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
446
-$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
446
+$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
447 447
 static $aNE = array('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
448 448
 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
449 449
 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
450 450
 
451
-if($C['lc_std_val']){
451
+if ($C['lc_std_val']) {
452 452
  // predef attr vals for $eAL & $aNE ele
453 453
  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);
454 454
  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);
@@ -456,7 +456,7 @@  discard block
 block discarded – undo
456 456
 }
457 457
 
458 458
 $depTr = 0;
459
-if($C['no_deprecated_attr']){
459
+if ($C['no_deprecated_attr']) {
460 460
  // dep attr:applicable ele
461 461
  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));
462 462
  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);
@@ -464,203 +464,203 @@  discard block
 block discarded – undo
464 464
 }
465 465
 
466 466
 // attr name-vals
467
-if(strpos($a, "\x01") !== false){$a = preg_replace('`\x01[^\x01]*\x01`', '', $a);} // No comment/CDATA sec
467
+if (strpos($a, "\x01") !== false) {$a = preg_replace('`\x01[^\x01]*\x01`', '', $a); } // No comment/CDATA sec
468 468
 $mode = 0; $a = trim($a, ' /'); $aA = array();
469
-while(strlen($a)){
469
+while (strlen($a)) {
470 470
  $w = 0;
471
- switch($mode){
471
+ switch ($mode) {
472 472
   case 0: // Name
473
-   if(preg_match('`^[a-zA-Z][\-a-zA-Z:]+`', $a, $m)){
473
+   if (preg_match('`^[a-zA-Z][\-a-zA-Z:]+`', $a, $m)) {
474 474
     $nm = strtolower($m[0]);
475 475
     $w = $mode = 1; $a = ltrim(substr_replace($a, '', 0, strlen($m[0])));
476 476
    }
477 477
   break; case 1:
478
-   if($a[0] == '='){ // =
478
+   if ($a[0] == '=') { // =
479 479
     $w = 1; $mode = 2; $a = ltrim($a, '= ');
480
-   }else{ // No val
480
+   } else { // No val
481 481
     $w = 1; $mode = 0; $a = ltrim($a);
482 482
     $aA[$nm] = '';
483 483
    }
484 484
   break; case 2: // Val
485
-   if(preg_match('`^((?:"[^"]*")|(?:\'[^\']*\')|(?:\s*[^\s"\']+))(.*)`', $a, $m)){
485
+   if (preg_match('`^((?:"[^"]*")|(?:\'[^\']*\')|(?:\s*[^\s"\']+))(.*)`', $a, $m)) {
486 486
     $a = ltrim($m[2]); $m = $m[1]; $w = 1; $mode = 0;
487 487
     $aA[$nm] = trim(($m[0] == '"' or $m[0] == '\'') ? substr($m, 1, -1) : $m);
488 488
    }
489 489
   break;
490 490
  }
491
- if($w == 0){ // Parse errs, deal with space, " & '
491
+ if ($w == 0) { // Parse errs, deal with space, " & '
492 492
   $a = preg_replace('`^(?:"[^"]*("|$)|\'[^\']*(\'|$)|\S)*\s*`', '', $a);
493 493
   $mode = 0;
494 494
  }
495 495
 }
496
-if($mode == 1){$aA[$nm] = '';}
496
+if ($mode == 1) {$aA[$nm] = ''; }
497 497
 
498 498
 // clean attrs
499 499
 global $S;
500 500
 $rl = isset($S[$e]) ? $S[$e] : array();
501 501
 $a = array(); $nfr = 0;
502
-foreach($aA as $k=>$v){
503
-  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])){
504
-  if(isset($aNE[$k])){$v = $k;}
505
-  elseif(!empty($lcase) && (($e != 'button' or $e != 'input') or $k == 'type')){ // Rather loose but ?not cause issues
502
+foreach ($aA as $k=>$v) {
503
+  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])) {
504
+  if (isset($aNE[$k])) {$v = $k; }
505
+  elseif (!empty($lcase) && (($e != 'button' or $e != 'input') or $k == 'type')) { // Rather loose but ?not cause issues
506 506
    $v = (isset($aNL[($v2 = strtolower($v))])) ? $v2 : $v;
507 507
   }
508
-  if($k == 'style' && !$C['style_pass']){
509
-   if(false !== strpos($v, '&#')){
508
+  if ($k == 'style' && !$C['style_pass']) {
509
+   if (false !== strpos($v, '&#')) {
510 510
     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;'=>'\\');
511 511
     $v = strtr($v, $sC);
512 512
    }
513 513
    $v = preg_replace_callback('`(url(?:\()(?: )*(?:\'|"|&(?:quot|apos);)?)(.+?)((?:\'|"|&(?:quot|apos);)?(?: )*(?:\)))`iS', 'hl_prot', $v);
514 514
    $v = !$C['css_expression'] ? preg_replace('`expression`i', ' ', preg_replace('`\\\\\S|(/|(%2f))(\*|(%2a))`i', ' ', $v)) : $v;
515
-  }elseif(isset($aNP[$k]) or strpos($k, 'src') !== false or $k[0] == 'o'){
515
+  }elseif (isset($aNP[$k]) or strpos($k, 'src') !== false or $k[0] == 'o') {
516 516
    $v = str_replace("\xad", ' ', (strpos($v, '&') !== false ? str_replace(array('&#xad;', '&#173;', '&shy;'), ' ', $v) : $v));
517 517
    $v = hl_prot($v, $k);
518
-   if($k == 'href'){ // X-spam
519
-    if($C['anti_mail_spam'] && strpos($v, 'mailto:') === 0){
518
+   if ($k == 'href') { // X-spam
519
+    if ($C['anti_mail_spam'] && strpos($v, 'mailto:') === 0) {
520 520
      $v = str_replace('@', htmlspecialchars($C['anti_mail_spam']), $v);
521
-    }elseif($C['anti_link_spam']){
521
+    }elseif ($C['anti_link_spam']) {
522 522
      $r1 = $C['anti_link_spam'][1];
523
-     if(!empty($r1) && preg_match($r1, $v)){continue;}
523
+     if (!empty($r1) && preg_match($r1, $v)) {continue; }
524 524
      $r0 = $C['anti_link_spam'][0];
525
-     if(!empty($r0) && preg_match($r0, $v)){
526
-      if(isset($a['rel'])){
527
-       if(!preg_match('`\bnofollow\b`i', $a['rel'])){$a['rel'] .= ' nofollow';}
528
-      }elseif(isset($aA['rel'])){
529
-       if(!preg_match('`\bnofollow\b`i', $aA['rel'])){$nfr = 1;}
530
-      }else{$a['rel'] = 'nofollow';}
525
+     if (!empty($r0) && preg_match($r0, $v)) {
526
+      if (isset($a['rel'])) {
527
+       if (!preg_match('`\bnofollow\b`i', $a['rel'])) {$a['rel'] .= ' nofollow'; }
528
+      }elseif (isset($aA['rel'])) {
529
+       if (!preg_match('`\bnofollow\b`i', $aA['rel'])) {$nfr = 1; }
530
+      } else {$a['rel'] = 'nofollow'; }
531 531
      }
532 532
     }
533 533
    }
534 534
   }
535
-  if(isset($rl[$k]) && is_array($rl[$k]) && ($v = hl_attrval($v, $rl[$k])) === 0){continue;}
535
+  if (isset($rl[$k]) && is_array($rl[$k]) && ($v = hl_attrval($v, $rl[$k])) === 0) {continue; }
536 536
   $a[$k] = str_replace('"', '&quot;', $v);
537 537
  }
538 538
 }
539
-if($nfr){$a['rel'] = isset($a['rel']) ? $a['rel']. ' nofollow' : 'nofollow';}
539
+if ($nfr) {$a['rel'] = isset($a['rel']) ? $a['rel'].' nofollow' : 'nofollow'; }
540 540
 
541 541
 // rqd attr
542 542
 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'));
543
-if(isset($eAR[$e])){
544
- foreach($eAR[$e] as $k=>$v){
545
-  if(!isset($a[$k])){$a[$k] = isset($v[0]) ? $v : $k;}
543
+if (isset($eAR[$e])) {
544
+ foreach ($eAR[$e] as $k=>$v) {
545
+  if (!isset($a[$k])) {$a[$k] = isset($v[0]) ? $v : $k; }
546 546
  }
547 547
 }
548 548
 
549 549
 // depr attrs
550
-if($depTr){
550
+if ($depTr) {
551 551
  $c = array();
552
- foreach($a as $k=>$v){
553
-  if($k == 'style' or !isset($aND[$k][$e])){continue;}
554
-  if($k == 'align'){
552
+ foreach ($a as $k=>$v) {
553
+  if ($k == 'style' or !isset($aND[$k][$e])) {continue; }
554
+  if ($k == 'align') {
555 555
    unset($a['align']);
556
-   if($e == 'img' && ($v == 'left' or $v == 'right')){$c[] = 'float: '. $v;}
557
-   elseif(($e == 'div' or $e == 'table') && $v == 'center'){$c[] = 'margin: auto';}
558
-   else{$c[] = 'text-align: '. $v;}
559
-  }elseif($k == 'bgcolor'){
556
+   if ($e == 'img' && ($v == 'left' or $v == 'right')) {$c[] = 'float: '.$v; }
557
+   elseif (($e == 'div' or $e == 'table') && $v == 'center') {$c[] = 'margin: auto'; }
558
+   else {$c[] = 'text-align: '.$v; }
559
+  }elseif ($k == 'bgcolor') {
560 560
    unset($a['bgcolor']);
561
-   $c[] = 'background-color: '. $v;
562
-  }elseif($k == 'border'){
561
+   $c[] = 'background-color: '.$v;
562
+  }elseif ($k == 'border') {
563 563
    unset($a['border']); $c[] = "border: {$v}px";
564
-  }elseif($k == 'bordercolor'){
565
-   unset($a['bordercolor']); $c[] = 'border-color: '. $v;
566
-  }elseif($k == 'clear'){
567
-   unset($a['clear']); $c[] = 'clear: '. ($v != 'all' ? $v : 'both');
568
-  }elseif($k == 'compact'){
564
+  }elseif ($k == 'bordercolor') {
565
+   unset($a['bordercolor']); $c[] = 'border-color: '.$v;
566
+  }elseif ($k == 'clear') {
567
+   unset($a['clear']); $c[] = 'clear: '.($v != 'all' ? $v : 'both');
568
+  }elseif ($k == 'compact') {
569 569
    unset($a['compact']); $c[] = 'font-size: 85%';
570
-  }elseif($k == 'height' or $k == 'width'){
571
-   unset($a[$k]); $c[] = $k. ': '. ($v[0] != '*' ? $v. (ctype_digit($v) ? 'px' : '') : 'auto');
572
-  }elseif($k == 'hspace'){
570
+  }elseif ($k == 'height' or $k == 'width') {
571
+   unset($a[$k]); $c[] = $k.': '.($v[0] != '*' ? $v.(ctype_digit($v) ? 'px' : '') : 'auto');
572
+  }elseif ($k == 'hspace') {
573 573
    unset($a['hspace']); $c[] = "margin-left: {$v}px; margin-right: {$v}px";
574
-  }elseif($k == 'language' && !isset($a['type'])){
574
+  }elseif ($k == 'language' && !isset($a['type'])) {
575 575
    unset($a['language']);
576
-   $a['type'] = 'text/'. strtolower($v);
577
-  }elseif($k == 'name'){
578
-   if($C['no_deprecated_attr'] == 2 or ($e != 'a' && $e != 'map')){unset($a['name']);}
579
-   if(!isset($a['id']) && preg_match('`[a-zA-Z][a-zA-Z\d.:_\-]*`', $v)){$a['id'] = $v;}
580
-  }elseif($k == 'noshade'){
576
+   $a['type'] = 'text/'.strtolower($v);
577
+  }elseif ($k == 'name') {
578
+   if ($C['no_deprecated_attr'] == 2 or ($e != 'a' && $e != 'map')) {unset($a['name']); }
579
+   if (!isset($a['id']) && preg_match('`[a-zA-Z][a-zA-Z\d.:_\-]*`', $v)) {$a['id'] = $v; }
580
+  }elseif ($k == 'noshade') {
581 581
    unset($a['noshade']); $c[] = 'border-style: none; border: 0; background-color: gray; color: gray';
582
-  }elseif($k == 'nowrap'){
582
+  }elseif ($k == 'nowrap') {
583 583
    unset($a['nowrap']); $c[] = 'white-space: nowrap';
584
-  }elseif($k == 'size'){
585
-   unset($a['size']); $c[] = 'size: '. $v. 'px';
586
-  }elseif($k == 'start' or $k == 'value'){
584
+  }elseif ($k == 'size') {
585
+   unset($a['size']); $c[] = 'size: '.$v.'px';
586
+  }elseif ($k == 'start' or $k == 'value') {
587 587
    unset($a[$k]);
588
-  }elseif($k == 'type'){
588
+  }elseif ($k == 'type') {
589 589
    unset($a['type']);
590 590
    static $ol_type = array('i'=>'lower-roman', 'I'=>'upper-roman', 'a'=>'lower-latin', 'A'=>'upper-latin', '1'=>'decimal');
591
-   $c[] = 'list-style-type: '. (isset($ol_type[$v]) ? $ol_type[$v] : 'decimal');
592
-  }elseif($k == 'vspace'){
591
+   $c[] = 'list-style-type: '.(isset($ol_type[$v]) ? $ol_type[$v] : 'decimal');
592
+  }elseif ($k == 'vspace') {
593 593
    unset($a['vspace']); $c[] = "margin-top: {$v}px; margin-bottom: {$v}px";
594 594
   }
595 595
  }
596
- if(count($c)){
596
+ if (count($c)) {
597 597
   $c = implode('; ', $c);
598
-  $a['style'] = isset($a['style']) ? rtrim($a['style'], ' ;'). '; '. $c. ';': $c. ';';
598
+  $a['style'] = isset($a['style']) ? rtrim($a['style'], ' ;').'; '.$c.';' : $c.';';
599 599
  }
600 600
 }
601 601
 // unique ID
602
-if($C['unique_ids'] && isset($a['id'])){
603
- 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']);
604
- }else{
605
-  while(isset($GLOBALS['hl_Ids'][$id])){$id = $C['unique_ids']. $id;}
602
+if ($C['unique_ids'] && isset($a['id'])) {
603
+ 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']);
604
+ } else {
605
+  while (isset($GLOBALS['hl_Ids'][$id])) {$id = $C['unique_ids'].$id; }
606 606
   $GLOBALS['hl_Ids'][($a['id'] = $id)] = 1;
607 607
  }
608 608
 }
609 609
 // xml:lang
610
-if($C['xml:lang'] && isset($a['lang'])){
610
+if ($C['xml:lang'] && isset($a['lang'])) {
611 611
  $a['xml:lang'] = isset($a['xml:lang']) ? $a['xml:lang'] : $a['lang'];
612
- if($C['xml:lang'] == 2){unset($a['lang']);}
612
+ if ($C['xml:lang'] == 2) {unset($a['lang']); }
613 613
 }
614 614
 // for transformed tag
615
-if(!empty($trt)){
616
- $a['style'] = isset($a['style']) ? rtrim($a['style'], ' ;'). '; '. $trt : $trt;
615
+if (!empty($trt)) {
616
+ $a['style'] = isset($a['style']) ? rtrim($a['style'], ' ;').'; '.$trt : $trt;
617 617
 }
618 618
 // return with empty ele /
619
-if(empty($C['hook_tag'])){
619
+if (empty($C['hook_tag'])) {
620 620
  $aA = '';
621
- foreach($a as $k=>$v){$aA .= " {$k}=\"{$v}\"";}
622
- return "<{$e}{$aA}". (isset($eE[$e]) ? ' /' : ''). '>';
621
+ foreach ($a as $k=>$v) {$aA .= " {$k}=\"{$v}\""; }
622
+ return "<{$e}{$aA}".(isset($eE[$e]) ? ' /' : '').'>';
623 623
 }
624
-else{return $C['hook_tag']($e, $a);}
624
+else {return $C['hook_tag']($e, $a); }
625 625
 // eof
626 626
 }
627 627
 
628
-function hl_tag2(&$e, &$a, $t=1){
628
+function hl_tag2(&$e, &$a, $t = 1) {
629 629
 // transform tag
630
-if($e == 'center'){$e = 'div'; return 'text-align: center;';}
631
-if($e == 'dir' or $e == 'menu'){$e = 'ul'; return '';}
632
-if($e == 's' or $e == 'strike'){$e = 'span'; return 'text-decoration: line-through;';}
633
-if($e == 'u'){$e = 'span'; return 'text-decoration: underline;';}
630
+if ($e == 'center') {$e = 'div'; return 'text-align: center;'; }
631
+if ($e == 'dir' or $e == 'menu') {$e = 'ul'; return ''; }
632
+if ($e == 's' or $e == 'strike') {$e = 'span'; return 'text-decoration: line-through;'; }
633
+if ($e == 'u') {$e = 'span'; return 'text-decoration: underline;'; }
634 634
 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%');
635
-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
635
+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
636 636
  $a2 = '';
637
- if(preg_match('`face\s*=\s*(\'|")([^=]+?)\\1`i', $a, $m) or preg_match('`face\s*=(\s*)(\S+)`i', $a, $m)){
638
-  $a2 .= ' font-family: '. str_replace('"', '\'', trim($m[2])). ';';
637
+ if (preg_match('`face\s*=\s*(\'|")([^=]+?)\\1`i', $a, $m) or preg_match('`face\s*=(\s*)(\S+)`i', $a, $m)) {
638
+  $a2 .= ' font-family: '.str_replace('"', '\'', trim($m[2])).';';
639 639
  }
640
- if(preg_match('`color\s*=\s*(\'|")?(.+?)(\\1|\s|$)`i', $a, $m)){
641
-  $a2 .= ' color: '. trim($m[2]). ';';
640
+ if (preg_match('`color\s*=\s*(\'|")?(.+?)(\\1|\s|$)`i', $a, $m)) {
641
+  $a2 .= ' color: '.trim($m[2]).';';
642 642
  }
643
- if(preg_match('`size\s*=\s*(\'|")?(.+?)(\\1|\s|$)`i', $a, $m) && isset($fs[($m = trim($m[2]))])){
644
-  $a2 .= ' font-size: '. $fs[$m]. ';';
643
+ if (preg_match('`size\s*=\s*(\'|")?(.+?)(\\1|\s|$)`i', $a, $m) && isset($fs[($m = trim($m[2]))])) {
644
+  $a2 .= ' font-size: '.$fs[$m].';';
645 645
  }
646 646
 // $e = 'span'; return ltrim($a2);
647 647
 // replace the above with following
648
- if($GLOBALS['C']['balance']){
649
-  $e = 'div'; return 'display: inline; -htmlawed-transform: 1; '. ltrim($a2);
650
- }else{
648
+ if ($GLOBALS['C']['balance']) {
649
+  $e = 'div'; return 'display: inline; -htmlawed-transform: 1; '.ltrim($a2);
650
+ } else {
651 651
   $e = 'span'; return ltrim($a2);
652 652
  }
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.17';
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.
Braces   +708 added lines, -263 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,41 +146,71 @@  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($t, $p){
159
+function hl_attrval($t, $p)
160
+{
119 161
 // check attr val against $S
120 162
 $o = 1; $l = strlen($t);
121
-foreach($p as $k=>$v){
122
- switch($k){
123
-  case 'maxlen':if($l > $v){$o = 0;}
124
-  break; case 'minlen': if($l < $v){$o = 0;}
125
-  break; case 'maxval': if((float)($t) > $v){$o = 0;}
126
-  break; case 'minval': if((float)($t) < $v){$o = 0;}
127
-  break; case 'match': if(!preg_match($v, $t)){$o = 0;}
128
-  break; case 'nomatch': if(preg_match($v, $t)){$o = 0;}
163
+foreach($p as $k=>$v)
164
+{
165
+ switch($k)
166
+ {
167
+  case 'maxlen':if($l > $v)
168
+  {
169
+$o = 0;}
170
+  break; case 'minlen': if($l < $v)
171
+  {
172
+$o = 0;}
173
+  break; case 'maxval': if((float)($t) > $v)
174
+  {
175
+$o = 0;}
176
+  break; case 'minval': if((float)($t) < $v)
177
+  {
178
+$o = 0;}
179
+  break; case 'match': if(!preg_match($v, $t))
180
+  {
181
+$o = 0;}
182
+  break; case 'nomatch': if(preg_match($v, $t))
183
+  {
184
+$o = 0;}
129 185
   break; case 'oneof':
130 186
    $m = 0;
131
-   foreach(explode('|', $v) as $n){if($t == $n){$m = 1; break;}}
187
+   foreach(explode('|', $v) as $n)
188
+   {
189
+if($t == $n)
190
+   {
191
+$m = 1; break;}}
132 192
    $o = $m;
133 193
   break; case 'noneof':
134 194
    $m = 1;
135
-   foreach(explode('|', $v) as $n){if($t == $n){$m = 0; break;}}
195
+   foreach(explode('|', $v) as $n)
196
+   {
197
+if($t == $n)
198
+   {
199
+$m = 0; break;}}
136 200
    $o = $m;
137 201
   break; default:
138 202
   break;
139 203
  }
140
- if(!$o){break;}
204
+ if(!$o)
205
+ {
206
+break;}
141 207
 }
142 208
 return ($o ? $t : (isset($p['default']) ? $p['default'] : 0));
143 209
 // eof
144 210
 }
145 211
 
146
-function hl_bal($t, $do=1, $in='div'){
212
+function hl_bal($t, $do=1, $in='div')
213
+{
147 214
 // balance tags
148 215
 // by content
149 216
 $cB = array('blockquote'=>1, 'form'=>1, 'map'=>1, 'noscript'=>1); // Block
@@ -154,209 +221,359 @@  discard block
 block discarded – undo
154 221
 $cN2 = array_keys($cN);
155 222
 $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);
156 223
 $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
157
-if($GLOBALS['C']['direct_list_nest']){$cS['ol'] = $cS['ul'] += array('ol'=>1, 'ul'=>1);}
224
+if($GLOBALS['C']['direct_list_nest'])
225
+{
226
+$cS['ol'] = $cS['ul'] += array('ol'=>1, 'ul'=>1);}
158 227
 $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
159 228
 $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
160 229
 // block/inline type; ins & del both type; #pcdata: text
161 230
 $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);
162 231
 $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);
163
-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
232
+if($GLOBALS['C']['allow_for_inline'] && is_array($GLOBALS['C']['allow_for_inline']))
233
+{
234
+	foreach($GLOBALS['C']['allow_for_inline'] as $khai => $vhai) {$eI[$vhai]=1;
235
+}
236
+}//allow table as if it was an inline element as <span> some Text <table>...</table> more text</span> is quite common
164 237
 $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
165 238
 $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
166 239
 $eF = $eB + $eI;
167 240
 
168 241
 // $in sets allowed child
169 242
 $in = ((isset($eF[$in]) && $in != '#pcdata') or isset($eO[$in])) ? $in : 'div';
170
-if(isset($cE[$in])){
243
+if(isset($cE[$in]))
244
+{
171 245
  return (!$do ? '' : str_replace(array('<', '>'), array('&lt;', '&gt;'), $t));
172 246
 }
173
-if(isset($cS[$in])){$inOk = $cS[$in];}
174
-elseif(isset($cI[$in])){$inOk = $eI; $cI['del'] = 1; $cI['ins'] = 1;}
175
-elseif(isset($cF[$in])){$inOk = $eF; unset($cI['del'], $cI['ins']);}
176
-elseif(isset($cB[$in])){$inOk = $eB; unset($cI['del'], $cI['ins']);}
177
-if(isset($cO[$in])){$inOk = $inOk + $cO[$in];}
178
-if(isset($cN[$in])){$inOk = array_diff_assoc($inOk, $cN[$in]);}
247
+if(isset($cS[$in]))
248
+{
249
+$inOk = $cS[$in];}
250
+elseif(isset($cI[$in]))
251
+{
252
+$inOk = $eI; $cI['del'] = 1; $cI['ins'] = 1;}
253
+elseif(isset($cF[$in]))
254
+{
255
+$inOk = $eF; unset($cI['del'], $cI['ins']);}
256
+elseif(isset($cB[$in]))
257
+{
258
+$inOk = $eB; unset($cI['del'], $cI['ins']);}
259
+if(isset($cO[$in]))
260
+{
261
+$inOk = $inOk + $cO[$in];}
262
+if(isset($cN[$in]))
263
+{
264
+$inOk = array_diff_assoc($inOk, $cN[$in]);}
179 265
 
180 266
 $t = explode('<', $t);
181 267
 $ok = $q = array(); // $q seq list of open non-empty ele
182 268
 ob_start();
183 269
 
184
-for($i=-1, $ci=count($t); ++$i<$ci;){
270
+for($i=-1, $ci=count($t); ++$i<$ci;)
271
+{
185 272
  // allowed $ok in parent $p
186
- if($ql = count($q)){
273
+ if($ql = count($q))
274
+ {
187 275
   $p = array_pop($q);
188 276
   $q[] = $p;
189
-  if(isset($cS[$p])){$ok = $cS[$p];}
190
-  elseif(isset($cI[$p])){$ok = $eI; $cI['del'] = 1; $cI['ins'] = 1;}
191
-  elseif(isset($cF[$p])){$ok = $eF; unset($cI['del'], $cI['ins']);}
192
-  elseif(isset($cB[$p])){$ok = $eB; unset($cI['del'], $cI['ins']);}
193
-  if(isset($cO[$p])){$ok = $ok + $cO[$p];}
194
-  if(isset($cN[$p])){$ok = array_diff_assoc($ok, $cN[$p]);}
195
- }else{$ok = $inOk; unset($cI['del'], $cI['ins']);}
277
+  if(isset($cS[$p]))
278
+  {
279
+$ok = $cS[$p];}
280
+  elseif(isset($cI[$p]))
281
+  {
282
+$ok = $eI; $cI['del'] = 1; $cI['ins'] = 1;}
283
+  elseif(isset($cF[$p]))
284
+  {
285
+$ok = $eF; unset($cI['del'], $cI['ins']);}
286
+  elseif(isset($cB[$p]))
287
+  {
288
+$ok = $eB; unset($cI['del'], $cI['ins']);}
289
+  if(isset($cO[$p]))
290
+  {
291
+$ok = $ok + $cO[$p];}
292
+  if(isset($cN[$p]))
293
+  {
294
+$ok = array_diff_assoc($ok, $cN[$p]);}
295
+ }
296
+ else
297
+ {
298
+$ok = $inOk; unset($cI['del'], $cI['ins']);}
196 299
  // bad tags, & ele content
197
- if(isset($e) && ($do == 1 or (isset($ok['#pcdata']) && ($do == 3 or $do == 5)))){
300
+ if(isset($e) && ($do == 1 or (isset($ok['#pcdata']) && ($do == 3 or $do == 5))))
301
+ {
198 302
   echo '&lt;', $s, $e, $a, '&gt;';
199 303
  }
200
- if(isset($x[0])){
201
-  if(strlen(trim($x)) && (($ql && isset($cB[$p])) or (isset($cB[$in]) && !$ql))){
304
+ if(isset($x[0]))
305
+ {
306
+  if(strlen(trim($x)) && (($ql && isset($cB[$p])) or (isset($cB[$in]) && !$ql)))
307
+  {
202 308
    echo '<div>', $x, '</div>';
203 309
   }
204
-  elseif($do < 3 or isset($ok['#pcdata'])){echo $x;}
205
-  elseif(strpos($x, "\x02\x04")){
206
-   foreach(preg_split('`(\x01\x02[^\x01\x02]+\x02\x01)`', $x, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY) as $v){
310
+  elseif($do < 3 or isset($ok['#pcdata']))
311
+  {
312
+echo $x;}
313
+  elseif(strpos($x, "\x02\x04"))
314
+  {
315
+   foreach(preg_split('`(\x01\x02[^\x01\x02]+\x02\x01)`', $x, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY) as $v)
316
+   {
207 317
     echo (substr($v, 0, 2) == "\x01\x02" ? $v : ($do > 4 ? preg_replace('`\S`', '', $v) : ''));
208 318
    }
209
-  }elseif($do > 4){echo preg_replace('`\S`', '', $x);}
319
+  }
320
+  elseif($do > 4)
321
+  {
322
+echo preg_replace('`\S`', '', $x);}
210 323
  }
211 324
  // get markup
212
- if(!preg_match('`^(/?)([a-z1-6]+)([^>]*)>(.*)`sm', $t[$i], $r)){$x = $t[$i]; continue;}
325
+ if(!preg_match('`^(/?)([a-z1-6]+)([^>]*)>(.*)`sm', $t[$i], $r))
326
+ {
327
+$x = $t[$i]; continue;}
213 328
  $s = null; $e = null; $a = null; $x = null; list($all, $s, $e, $a, $x) = $r;
214 329
  // close tag
215
- if($s){
216
-  if(isset($cE[$e]) or !in_array($e, $q)){continue;} // Empty/unopen
217
-  if($p == $e){array_pop($q); echo '</', $e, '>'; unset($e); continue;} // Last open
330
+ if($s)
331
+ {
332
+  if(isset($cE[$e]) or !in_array($e, $q))
333
+  {
334
+continue;} // Empty/unopen
335
+  if($p == $e)
336
+  {
337
+array_pop($q); echo '</', $e, '>'; unset($e); continue;} // Last open
218 338
   $add = ''; // Nesting - close open tags that need to be
219
-  for($j=-1, $cj=count($q); ++$j<$cj;){
220
-   if(($d = array_pop($q)) == $e){break;}
221
-   else{$add .= "</{$d}>";}
339
+  for($j=-1, $cj=count($q); ++$j<$cj;)
340
+  {
341
+   if(($d = array_pop($q)) == $e)
342
+   {
343
+break;}
344
+   else
345
+   {
346
+$add .= "</{$d}>";}
222 347
   }
223 348
   echo $add, '</', $e, '>'; unset($e); continue;
224 349
  }
225 350
  // open tag
226 351
  // $cB ele needs $eB ele as child
227
- if(isset($cB[$e]) && strlen(trim($x))){
352
+ if(isset($cB[$e]) && strlen(trim($x)))
353
+ {
228 354
   $t[$i] = "{$e}{$a}>";
229 355
   array_splice($t, $i+1, 0, 'div>'. $x); unset($e, $x); ++$ci; --$i; continue;
230 356
  }
231
- if((($ql && isset($cB[$p])) or (isset($cB[$in]) && !$ql)) && !isset($eB[$e]) && !isset($ok[$e])){
357
+ if((($ql && isset($cB[$p])) or (isset($cB[$in]) && !$ql)) && !isset($eB[$e]) && !isset($ok[$e]))
358
+ {
232 359
   array_splice($t, $i, 0, 'div>'); unset($e, $x); ++$ci; --$i; continue;
233 360
  }
234
- if($e == 'div' && !isset($ok['div']) && strpos($a, '-htmlawed-transform')){
361
+ if($e == 'div' && !isset($ok['div']) && strpos($a, '-htmlawed-transform'))
362
+ {
235 363
   $t[$i] = "span{$a}>{$x}"; unset($e, $x); --$i; continue;
236 364
  }
237 365
  // if no open ele, $in = parent; mostly immediate parent-child relation should hold
238
- if(!$ql or !isset($eN[$e]) or !array_intersect($q, $cN2)){
239
-  if(!isset($ok[$e])){
240
-   if($ql && isset($cT[$p])){echo '</', array_pop($q), '>'; unset($e, $x); --$i;}
366
+ if(!$ql or !isset($eN[$e]) or !array_intersect($q, $cN2))
367
+ {
368
+  if(!isset($ok[$e]))
369
+  {
370
+   if($ql && isset($cT[$p]))
371
+   {
372
+echo '</', array_pop($q), '>'; unset($e, $x); --$i;}
241 373
    continue;
242 374
   }
243
-  if(!isset($cE[$e])){$q[] = $e;}
375
+  if(!isset($cE[$e]))
376
+  {
377
+$q[] = $e;}
244 378
   echo '<', $e, $a, '>'; unset($e); continue;
245 379
  }
246 380
  // specific parent-child
247
- if(isset($cS[$p][$e])){
248
-  if(!isset($cE[$e])){$q[] = $e;}
381
+ if(isset($cS[$p][$e]))
382
+ {
383
+  if(!isset($cE[$e]))
384
+  {
385
+$q[] = $e;}
249 386
   echo '<', $e, $a, '>'; unset($e); continue;
250 387
  }
251 388
  // nesting
252 389
  $add = '';
253 390
  $q2 = array();
254
- for($k=-1, $kc=count($q); ++$k<$kc;){
391
+ for($k=-1, $kc=count($q); ++$k<$kc;)
392
+ {
255 393
   $d = $q[$k];
256 394
   $ok2 = array();
257
-  if(isset($cS[$d])){$q2[] = $d; continue;}
395
+  if(isset($cS[$d]))
396
+  {
397
+$q2[] = $d; continue;}
258 398
   $ok2 = isset($cI[$d]) ? $eI : $eF;
259
-  if(isset($cO[$d])){$ok2 = $ok2 + $cO[$d];}
260
-  if(isset($cN[$d])){$ok2 = array_diff_assoc($ok2, $cN[$d]);}
261
-  if(!isset($ok2[$e])){
262
-   if(!$k && !isset($inOk[$e])){continue 2;}
399
+  if(isset($cO[$d]))
400
+  {
401
+$ok2 = $ok2 + $cO[$d];}
402
+  if(isset($cN[$d]))
403
+  {
404
+$ok2 = array_diff_assoc($ok2, $cN[$d]);}
405
+  if(!isset($ok2[$e]))
406
+  {
407
+   if(!$k && !isset($inOk[$e]))
408
+   {
409
+continue 2;}
263 410
    $add = "</{$d}>";
264
-   for(;++$k<$kc;){$add = "</{$q[$k]}>{$add}";}
411
+   for(;++$k<$kc;)
412
+   {
413
+$add = "</{$q[$k]}>{$add}";}
265 414
    break;
266 415
   }
267
-  else{$q2[] = $d;}
416
+  else
417
+  {
418
+$q2[] = $d;}
268 419
  }
269 420
  $q = $q2;
270
- if(!isset($cE[$e])){$q[] = $e;}
421
+ if(!isset($cE[$e]))
422
+ {
423
+$q[] = $e;}
271 424
  echo $add, '<', $e, $a, '>'; unset($e); continue;
272 425
 }
273 426
 
274 427
 // end
275
-if($ql = count($q)){
428
+if($ql = count($q))
429
+{
276 430
  $p = array_pop($q);
277 431
  $q[] = $p;
278
- if(isset($cS[$p])){$ok = $cS[$p];}
279
- elseif(isset($cI[$p])){$ok = $eI; $cI['del'] = 1; $cI['ins'] = 1;}
280
- elseif(isset($cF[$p])){$ok = $eF; unset($cI['del'], $cI['ins']);}
281
- elseif(isset($cB[$p])){$ok = $eB; unset($cI['del'], $cI['ins']);}
282
- if(isset($cO[$p])){$ok = $ok + $cO[$p];}
283
- if(isset($cN[$p])){$ok = array_diff_assoc($ok, $cN[$p]);}
284
-}else{$ok = $inOk; unset($cI['del'], $cI['ins']);}
285
-if(isset($e) && ($do == 1 or (isset($ok['#pcdata']) && ($do == 3 or $do == 5)))){
432
+ if(isset($cS[$p]))
433
+ {
434
+$ok = $cS[$p];}
435
+ elseif(isset($cI[$p]))
436
+ {
437
+$ok = $eI; $cI['del'] = 1; $cI['ins'] = 1;}
438
+ elseif(isset($cF[$p]))
439
+ {
440
+$ok = $eF; unset($cI['del'], $cI['ins']);}
441
+ elseif(isset($cB[$p]))
442
+ {
443
+$ok = $eB; unset($cI['del'], $cI['ins']);}
444
+ if(isset($cO[$p]))
445
+ {
446
+$ok = $ok + $cO[$p];}
447
+ if(isset($cN[$p]))
448
+ {
449
+$ok = array_diff_assoc($ok, $cN[$p]);}
450
+}
451
+else
452
+{
453
+$ok = $inOk; unset($cI['del'], $cI['ins']);}
454
+if(isset($e) && ($do == 1 or (isset($ok['#pcdata']) && ($do == 3 or $do == 5))))
455
+{
286 456
  echo '&lt;', $s, $e, $a, '&gt;';
287 457
 }
288
-if(isset($x[0])){
289
- if(strlen(trim($x)) && (($ql && isset($cB[$p])) or (isset($cB[$in]) && !$ql))){
458
+if(isset($x[0]))
459
+{
460
+ if(strlen(trim($x)) && (($ql && isset($cB[$p])) or (isset($cB[$in]) && !$ql)))
461
+ {
290 462
   echo '<div>', $x, '</div>';
291 463
  }
292
- elseif($do < 3 or isset($ok['#pcdata'])){echo $x;}
293
- elseif(strpos($x, "\x02\x04")){
294
-  foreach(preg_split('`(\x01\x02[^\x01\x02]+\x02\x01)`', $x, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY) as $v){
464
+ elseif($do < 3 or isset($ok['#pcdata']))
465
+ {
466
+echo $x;}
467
+ elseif(strpos($x, "\x02\x04"))
468
+ {
469
+  foreach(preg_split('`(\x01\x02[^\x01\x02]+\x02\x01)`', $x, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY) as $v)
470
+  {
295 471
    echo (substr($v, 0, 2) == "\x01\x02" ? $v : ($do > 4 ? preg_replace('`\S`', '', $v) : ''));
296 472
   }
297
- }elseif($do > 4){echo preg_replace('`\S`', '', $x);}
473
+ }
474
+ elseif($do > 4)
475
+ {
476
+echo preg_replace('`\S`', '', $x);}
298 477
 }
299
-while(!empty($q) && ($e = array_pop($q))){echo '</', $e, '>';}
478
+while(!empty($q) && ($e = array_pop($q)))
479
+{
480
+echo '</', $e, '>';}
300 481
 $o = ob_get_contents();
301 482
 ob_end_clean();
302 483
 return $o;
303 484
 // eof
304 485
 }
305 486
 
306
-function hl_cmtcd($t){
487
+function hl_cmtcd($t)
488
+{
307 489
 // comment/CDATA sec handler
308 490
 $t = $t[0];
309 491
 global $C;
310
-if(!($v = $C[$n = $t[3] == '-' ? 'comment' : 'cdata'])){return $t;}
311
-if($v == 1){return '';}
312
-if($n == 'comment'){
313
- if(substr(($t = preg_replace('`--+`', '-', substr($t, 4, -3))), -1) != ' '){$t .= ' ';}
492
+if(!($v = $C[$n = $t[3] == '-' ? 'comment' : 'cdata']))
493
+{
494
+return $t;}
495
+if($v == 1)
496
+{
497
+return '';}
498
+if($n == 'comment')
499
+{
500
+ if(substr(($t = preg_replace('`--+`', '-', substr($t, 4, -3))), -1) != ' ')
501
+ {
502
+$t .= ' ';}
314 503
 }
315
-else{$t = substr($t, 1, -1);}
504
+else
505
+{
506
+$t = substr($t, 1, -1);}
316 507
 $t = $v == 2 ? str_replace(array('&', '<', '>'), array('&amp;', '&lt;', '&gt;'), $t) : $t;
317 508
 return str_replace(array('&', '<', '>'), array("\x03", "\x04", "\x05"), ($n == 'comment' ? "\x01\x02\x04!--$t--\x05\x02\x01" : "\x01\x01\x04$t\x05\x01\x01"));
318 509
 // eof
319 510
 }
320 511
 
321
-function hl_ent($t){
512
+function hl_ent($t)
513
+{
322 514
 // entitity handler
323 515
 global $C;
324 516
 $t = $t[1];
325 517
 static $U = array('quot'=>1,'amp'=>1,'lt'=>1,'gt'=>1);
326 518
 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');
327
-if($t[0] != '#'){
519
+if($t[0] != '#')
520
+{
328 521
  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)). ';';
329 522
 }
330
-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))){
523
+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)))
524
+{
331 525
  return ($C['and_mark'] ? "\x06" : '&'). "amp;#{$t};";
332 526
 }
333 527
 return ($C['and_mark'] ? "\x06" : '&'). '#'. (((ctype_digit($t) && $C['hexdec_entity'] < 2) or !$C['hexdec_entity']) ? $n : 'x'. dechex($n)). ';';
334 528
 // eof
335 529
 }
336 530
 
337
-function hl_prot($p, $c=null){
531
+function hl_prot($p, $c=null)
532
+{
338 533
 // check URL scheme
339 534
 global $C;
340 535
 $b = $a = '';
341
-if($c == null){$c = 'style'; $b = $p[1]; $a = $p[3]; $p = trim($p[2]);}
536
+if($c == null)
537
+{
538
+$c = 'style'; $b = $p[1]; $a = $p[3]; $p = trim($p[2]);}
342 539
 $c = isset($C['schemes'][$c]) ? $C['schemes'][$c] : $C['schemes']['*'];
343 540
 static $d = 'denied:';
344
-if(isset($c['!']) && substr($p, 0, 7) != $d){$p = "$d$p";}
345
-if(isset($c['*']) or !strcspn($p, '#?;') or (substr($p, 0, 7) == $d)){return "{$b}{$p}{$a}";} // All ok, frag, query, param
346
-if(preg_match('`^([^:?[@!$()*,=/\'\]]+?)(:|&#(58|x3a);|%3a|\\\\0{0,4}3a).`i', $p, $m) && !isset($c[strtolower($m[1])])){ // Denied prot
541
+if(isset($c['!']) && substr($p, 0, 7) != $d)
542
+{
543
+$p = "$d$p";}
544
+if(isset($c['*']) or !strcspn($p, '#?;') or (substr($p, 0, 7) == $d))
545
+{
546
+return "{$b}{$p}{$a}";} // All ok, frag, query, param
547
+if(preg_match('`^([^:?[@!$()*,=/\'\]]+?)(:|&#(58|x3a);|%3a|\\\\0{0,4}3a).`i', $p, $m) && !isset($c[strtolower($m[1])]))
548
+{
549
+// Denied prot
347 550
  return "{$b}{$d}{$p}{$a}";
348 551
 }
349
-if($C['abs_url']){
350
- if($C['abs_url'] == -1 && strpos($p, $C['base_url']) === 0){ // Make url rel
552
+if($C['abs_url'])
553
+{
554
+ if($C['abs_url'] == -1 && strpos($p, $C['base_url']) === 0)
555
+ {
556
+// Make url rel
351 557
   $p = substr($p, strlen($C['base_url']));
352
- }elseif(empty($m[1])){ // Make URL abs
353
-  if(substr($p, 0, 2) == '//'){$p = substr($C['base_url'], 0, strpos($C['base_url'], ':')+1). $p;}
354
-  elseif($p[0] == '/'){$p = preg_replace('`(^.+?://[^/]+)(.*)`', '$1', $C['base_url']). $p;}
355
-  elseif(strcspn($p, './')){$p = $C['base_url']. $p;}
356
-  else{
558
+ }
559
+ elseif(empty($m[1]))
560
+ {
561
+// Make URL abs
562
+  if(substr($p, 0, 2) == '//')
563
+  {
564
+$p = substr($C['base_url'], 0, strpos($C['base_url'], ':')+1). $p;}
565
+  elseif($p[0] == '/')
566
+  {
567
+$p = preg_replace('`(^.+?://[^/]+)(.*)`', '$1', $C['base_url']). $p;}
568
+  elseif(strcspn($p, './'))
569
+  {
570
+$p = $C['base_url']. $p;}
571
+  else
572
+  {
357 573
    preg_match('`^([a-zA-Z\d\-+.]+://[^/]+)(.*)`', $C['base_url'], $m);
358 574
    $p = preg_replace('`(?<=/)\./`', '', $m[2]. $p);
359
-   while(preg_match('`(?<=/)([^/]{3,}|[^/.]+?|\.[^/.]|[^/.]\.)/\.\./`', $p)){
575
+   while(preg_match('`(?<=/)([^/]{3,}|[^/.]+?|\.[^/.]|[^/.]\.)/\.\./`', $p))
576
+   {
360 577
     $p = preg_replace('`(?<=/)([^/]{3,}|[^/.]+?|\.[^/.]|[^/.]\.)/\.\./`', '', $p);
361 578
    }
362 579
    $p = $m[1]. $p;
@@ -367,77 +584,133 @@  discard block
 block discarded – undo
367 584
 // eof
368 585
 }
369 586
 
370
-function hl_regex($p){
587
+function hl_regex($p)
588
+{
371 589
 // ?regex
372
-if(empty($p)){return 0;}
373
-if($t = ini_get('track_errors')){$o = isset($php_errormsg) ? $php_errormsg : null;}
374
-else{ini_set('track_errors', 1);}
590
+if(empty($p))
591
+{
592
+return 0;}
593
+if($t = ini_get('track_errors'))
594
+{
595
+$o = isset($php_errormsg) ? $php_errormsg : null;}
596
+else
597
+{
598
+ini_set('track_errors', 1);}
375 599
 unset($php_errormsg);
376
-if(($d = ini_get('display_errors'))){ini_set('display_errors', 0);}
600
+if(($d = ini_get('display_errors')))
601
+{
602
+ini_set('display_errors', 0);}
377 603
 preg_match($p, '');
378
-if($d){ini_set('display_errors', 1);}
604
+if($d)
605
+{
606
+ini_set('display_errors', 1);}
379 607
 $r = isset($php_errormsg) ? 0 : 1;
380
-if($t){$php_errormsg = isset($o) ? $o : null;}
381
-else{ini_set('track_errors', 0);}
608
+if($t)
609
+{
610
+$php_errormsg = isset($o) ? $o : null;}
611
+else
612
+{
613
+ini_set('track_errors', 0);}
382 614
 return $r;
383 615
 // eof
384 616
 }
385 617
 
386
-function hl_spec($t){
618
+function hl_spec($t)
619
+{
387 620
 // final $spec
388 621
 $s = array();
389 622
 $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)));
390
-for($i = count(($t = explode(';', $t))); --$i>=0;){
623
+for($i = count(($t = explode(';', $t))); --$i>=0;)
624
+{
391 625
  $w = $t[$i];
392
- if(empty($w) or ($e = strpos($w, '=')) === false or !strlen(($a =  substr($w, $e+1)))){continue;}
626
+ if(empty($w) or ($e = strpos($w, '=')) === false or !strlen(($a =  substr($w, $e+1))))
627
+ {
628
+continue;}
393 629
  $y = $n = array();
394
- foreach(explode(',', $a) as $v){
395
-  if(!preg_match('`^([a-z:\-\*]+)(?:\((.*?)\))?`i', $v, $m)){continue;}
396
-  if(($x = strtolower($m[1])) == '-*'){$n['*'] = 1; continue;}
397
-  if($x[0] == '-'){$n[substr($x, 1)] = 1; continue;}
398
-  if(!isset($m[2])){$y[$x] = 1; continue;}
399
-  foreach(explode('/', $m[2]) as $m){
400
-   if(empty($m) or ($p = strpos($m, '=')) == 0 or $p < 5){$y[$x] = 1; continue;}
630
+ foreach(explode(',', $a) as $v)
631
+ {
632
+  if(!preg_match('`^([a-z:\-\*]+)(?:\((.*?)\))?`i', $v, $m))
633
+  {
634
+continue;}
635
+  if(($x = strtolower($m[1])) == '-*')
636
+  {
637
+$n['*'] = 1; continue;}
638
+  if($x[0] == '-')
639
+  {
640
+$n[substr($x, 1)] = 1; continue;}
641
+  if(!isset($m[2]))
642
+  {
643
+$y[$x] = 1; continue;}
644
+  foreach(explode('/', $m[2]) as $m)
645
+  {
646
+   if(empty($m) or ($p = strpos($m, '=')) == 0 or $p < 5)
647
+   {
648
+$y[$x] = 1; continue;}
401 649
    $y[$x][strtolower(substr($m, 0, $p))] = str_replace(array("\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07", "\x08"), array(";", "|", "~", " ", ",", "/", "(", ")"), substr($m, $p+1));
402 650
   }
403
-  if(isset($y[$x]['match']) && !hl_regex($y[$x]['match'])){unset($y[$x]['match']);}
404
-  if(isset($y[$x]['nomatch']) && !hl_regex($y[$x]['nomatch'])){unset($y[$x]['nomatch']);}
651
+  if(isset($y[$x]['match']) && !hl_regex($y[$x]['match']))
652
+  {
653
+unset($y[$x]['match']);}
654
+  if(isset($y[$x]['nomatch']) && !hl_regex($y[$x]['nomatch']))
655
+  {
656
+unset($y[$x]['nomatch']);}
405 657
  }
406
- if(!count($y) && !count($n)){continue;}
407
- foreach(explode(',', substr($w, 0, $e)) as $v){
408
-  if(!strlen(($v = strtolower($v)))){continue;}
409
-  if(count($y)){$s[$v] = $y;}
410
-  if(count($n)){$s[$v]['n'] = $n;}
658
+ if(!count($y) && !count($n))
659
+ {
660
+continue;}
661
+ foreach(explode(',', substr($w, 0, $e)) as $v)
662
+ {
663
+  if(!strlen(($v = strtolower($v))))
664
+  {
665
+continue;}
666
+  if(count($y))
667
+  {
668
+$s[$v] = $y;}
669
+  if(count($n))
670
+  {
671
+$s[$v]['n'] = $n;}
411 672
  }
412 673
 }
413 674
 return $s;
414 675
 // eof
415 676
 }
416 677
 
417
-function hl_tag($t){
678
+function hl_tag($t)
679
+{
418 680
 // tag/attribute handler
419 681
 global $C;
420 682
 $t = $t[0];
421 683
 // invalid < >
422
-if($t == '< '){return '&lt; ';}
423
-if($t == '>'){return '&gt;';}
424
-if(!preg_match('`^<(/?)([a-zA-Z][a-zA-Z1-6]*)([^>]*?)\s?>$`m', $t, $m)){
684
+if($t == '< ')
685
+{
686
+return '&lt; ';}
687
+if($t == '>')
688
+{
689
+return '&gt;';}
690
+if(!preg_match('`^<(/?)([a-zA-Z][a-zA-Z1-6]*)([^>]*?)\s?>$`m', $t, $m))
691
+{
425 692
  //return str_replace(array('<', '>'), array('&lt;', '&gt;'), $t);
426 693
  return (($C['keep_bad']%2) ? str_replace(array('<', '>'), array('&lt;', '&gt;'), $t) : '');
427
-}elseif(!isset($C['elements'][($e = strtolower($m[2]))])){
694
+}
695
+elseif(!isset($C['elements'][($e = strtolower($m[2]))]))
696
+{
428 697
  return (($C['keep_bad']%2) ? str_replace(array('<', '>'), array('&lt;', '&gt;'), $t) : '');
429 698
 }
430 699
 // attr string
431 700
 $a = str_replace(array("\n", "\r", "\t"), ' ', trim($m[3]));
432 701
 // tag transform
433 702
 static $eD = array('applet'=>1, 'center'=>1, 'dir'=>1, 'embed'=>1, 'font'=>1, 'isindex'=>1, 'menu'=>1, 's'=>1, 'strike'=>1, 'u'=>1); // Deprecated
434
-if($C['make_tag_strict'] && isset($eD[$e])){
703
+if($C['make_tag_strict'] && isset($eD[$e]))
704
+{
435 705
  $trt = hl_tag2($e, $a, $C['make_tag_strict']);
436
- if(!$e){return (($C['keep_bad']%2) ? str_replace(array('<', '>'), array('&lt;', '&gt;'), $t) : '');}
706
+ if(!$e)
707
+ {
708
+return (($C['keep_bad']%2) ? str_replace(array('<', '>'), array('&lt;', '&gt;'), $t) : '');}
437 709
 }
438 710
 // close tag
439 711
 static $eE = array('area'=>1, 'br'=>1, 'col'=>1, 'embed'=>1, 'hr'=>1, 'img'=>1, 'input'=>1, 'isindex'=>1, 'param'=>1); // Empty ele
440
-if(!empty($m[1])){
712
+if(!empty($m[1]))
713
+{
441 714
  return (!isset($eE[$e]) ? (empty($C['hook_tag']) ? "</$e>" : $C['hook_tag']($e)) : (($C['keep_bad'])%2 ? str_replace(array('<', '>'), array('&lt;', '&gt;'), $t) : ''));
442 715
 }
443 716
 
@@ -448,7 +721,8 @@  discard block
 block discarded – undo
448 721
 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
449 722
 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
450 723
 
451
-if($C['lc_std_val']){
724
+if($C['lc_std_val'])
725
+{
452 726
  // predef attr vals for $eAL & $aNE ele
453 727
  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);
454 728
  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);
@@ -456,7 +730,8 @@  discard block
 block discarded – undo
456 730
 }
457 731
 
458 732
 $depTr = 0;
459
-if($C['no_deprecated_attr']){
733
+if($C['no_deprecated_attr'])
734
+{
460 735
  // dep attr:applicable ele
461 736
  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));
462 737
  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);
@@ -464,203 +739,339 @@  discard block
 block discarded – undo
464 739
 }
465 740
 
466 741
 // attr name-vals
467
-if(strpos($a, "\x01") !== false){$a = preg_replace('`\x01[^\x01]*\x01`', '', $a);} // No comment/CDATA sec
742
+if(strpos($a, "\x01") !== false)
743
+{
744
+$a = preg_replace('`\x01[^\x01]*\x01`', '', $a);} // No comment/CDATA sec
468 745
 $mode = 0; $a = trim($a, ' /'); $aA = array();
469
-while(strlen($a)){
746
+while(strlen($a))
747
+{
470 748
  $w = 0;
471
- switch($mode){
749
+ switch($mode)
750
+ {
472 751
   case 0: // Name
473
-   if(preg_match('`^[a-zA-Z][\-a-zA-Z:]+`', $a, $m)){
752
+   if(preg_match('`^[a-zA-Z][\-a-zA-Z:]+`', $a, $m))
753
+   {
474 754
     $nm = strtolower($m[0]);
475 755
     $w = $mode = 1; $a = ltrim(substr_replace($a, '', 0, strlen($m[0])));
476 756
    }
477 757
   break; case 1:
478
-   if($a[0] == '='){ // =
758
+   if($a[0] == '=')
759
+   {
760
+// =
479 761
     $w = 1; $mode = 2; $a = ltrim($a, '= ');
480
-   }else{ // No val
762
+   }
763
+   else
764
+   {
765
+// No val
481 766
     $w = 1; $mode = 0; $a = ltrim($a);
482 767
     $aA[$nm] = '';
483 768
    }
484 769
   break; case 2: // Val
485
-   if(preg_match('`^((?:"[^"]*")|(?:\'[^\']*\')|(?:\s*[^\s"\']+))(.*)`', $a, $m)){
770
+   if(preg_match('`^((?:"[^"]*")|(?:\'[^\']*\')|(?:\s*[^\s"\']+))(.*)`', $a, $m))
771
+   {
486 772
     $a = ltrim($m[2]); $m = $m[1]; $w = 1; $mode = 0;
487 773
     $aA[$nm] = trim(($m[0] == '"' or $m[0] == '\'') ? substr($m, 1, -1) : $m);
488 774
    }
489 775
   break;
490 776
  }
491
- if($w == 0){ // Parse errs, deal with space, " & '
777
+ if($w == 0)
778
+ {
779
+// Parse errs, deal with space, " & '
492 780
   $a = preg_replace('`^(?:"[^"]*("|$)|\'[^\']*(\'|$)|\S)*\s*`', '', $a);
493 781
   $mode = 0;
494 782
  }
495 783
 }
496
-if($mode == 1){$aA[$nm] = '';}
784
+if($mode == 1)
785
+{
786
+$aA[$nm] = '';}
497 787
 
498 788
 // clean attrs
499 789
 global $S;
500 790
 $rl = isset($S[$e]) ? $S[$e] : array();
501 791
 $a = array(); $nfr = 0;
502
-foreach($aA as $k=>$v){
503
-  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])){
504
-  if(isset($aNE[$k])){$v = $k;}
505
-  elseif(!empty($lcase) && (($e != 'button' or $e != 'input') or $k == 'type')){ // Rather loose but ?not cause issues
792
+foreach($aA as $k=>$v)
793
+{
794
+  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]))
795
+  {
796
+  if(isset($aNE[$k]))
797
+  {
798
+$v = $k;}
799
+  elseif(!empty($lcase) && (($e != 'button' or $e != 'input') or $k == 'type'))
800
+  {
801
+// Rather loose but ?not cause issues
506 802
    $v = (isset($aNL[($v2 = strtolower($v))])) ? $v2 : $v;
507 803
   }
508
-  if($k == 'style' && !$C['style_pass']){
509
-   if(false !== strpos($v, '&#')){
804
+  if($k == 'style' && !$C['style_pass'])
805
+  {
806
+   if(false !== strpos($v, '&#'))
807
+   {
510 808
     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;'=>'\\');
511 809
     $v = strtr($v, $sC);
512 810
    }
513 811
    $v = preg_replace_callback('`(url(?:\()(?: )*(?:\'|"|&(?:quot|apos);)?)(.+?)((?:\'|"|&(?:quot|apos);)?(?: )*(?:\)))`iS', 'hl_prot', $v);
514 812
    $v = !$C['css_expression'] ? preg_replace('`expression`i', ' ', preg_replace('`\\\\\S|(/|(%2f))(\*|(%2a))`i', ' ', $v)) : $v;
515
-  }elseif(isset($aNP[$k]) or strpos($k, 'src') !== false or $k[0] == 'o'){
813
+  }
814
+  elseif(isset($aNP[$k]) or strpos($k, 'src') !== false or $k[0] == 'o')
815
+  {
516 816
    $v = str_replace("\xad", ' ', (strpos($v, '&') !== false ? str_replace(array('&#xad;', '&#173;', '&shy;'), ' ', $v) : $v));
517 817
    $v = hl_prot($v, $k);
518
-   if($k == 'href'){ // X-spam
519
-    if($C['anti_mail_spam'] && strpos($v, 'mailto:') === 0){
818
+   if($k == 'href')
819
+   {
820
+// X-spam
821
+    if($C['anti_mail_spam'] && strpos($v, 'mailto:') === 0)
822
+    {
520 823
      $v = str_replace('@', htmlspecialchars($C['anti_mail_spam']), $v);
521
-    }elseif($C['anti_link_spam']){
824
+    }
825
+    elseif($C['anti_link_spam'])
826
+    {
522 827
      $r1 = $C['anti_link_spam'][1];
523
-     if(!empty($r1) && preg_match($r1, $v)){continue;}
828
+     if(!empty($r1) && preg_match($r1, $v))
829
+     {
830
+continue;}
524 831
      $r0 = $C['anti_link_spam'][0];
525
-     if(!empty($r0) && preg_match($r0, $v)){
526
-      if(isset($a['rel'])){
527
-       if(!preg_match('`\bnofollow\b`i', $a['rel'])){$a['rel'] .= ' nofollow';}
528
-      }elseif(isset($aA['rel'])){
529
-       if(!preg_match('`\bnofollow\b`i', $aA['rel'])){$nfr = 1;}
530
-      }else{$a['rel'] = 'nofollow';}
832
+     if(!empty($r0) && preg_match($r0, $v))
833
+     {
834
+      if(isset($a['rel']))
835
+      {
836
+       if(!preg_match('`\bnofollow\b`i', $a['rel']))
837
+       {
838
+$a['rel'] .= ' nofollow';}
839
+      }
840
+      elseif(isset($aA['rel']))
841
+      {
842
+       if(!preg_match('`\bnofollow\b`i', $aA['rel']))
843
+       {
844
+$nfr = 1;}
845
+      }
846
+      else
847
+      {
848
+$a['rel'] = 'nofollow';}
531 849
      }
532 850
     }
533 851
    }
534 852
   }
535
-  if(isset($rl[$k]) && is_array($rl[$k]) && ($v = hl_attrval($v, $rl[$k])) === 0){continue;}
853
+  if(isset($rl[$k]) && is_array($rl[$k]) && ($v = hl_attrval($v, $rl[$k])) === 0)
854
+  {
855
+continue;}
536 856
   $a[$k] = str_replace('"', '&quot;', $v);
537 857
  }
538 858
 }
539
-if($nfr){$a['rel'] = isset($a['rel']) ? $a['rel']. ' nofollow' : 'nofollow';}
859
+if($nfr)
860
+{
861
+$a['rel'] = isset($a['rel']) ? $a['rel']. ' nofollow' : 'nofollow';}
540 862
 
541 863
 // rqd attr
542 864
 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'));
543
-if(isset($eAR[$e])){
544
- foreach($eAR[$e] as $k=>$v){
545
-  if(!isset($a[$k])){$a[$k] = isset($v[0]) ? $v : $k;}
865
+if(isset($eAR[$e]))
866
+{
867
+ foreach($eAR[$e] as $k=>$v)
868
+ {
869
+  if(!isset($a[$k]))
870
+  {
871
+$a[$k] = isset($v[0]) ? $v : $k;}
546 872
  }
547 873
 }
548 874
 
549 875
 // depr attrs
550
-if($depTr){
876
+if($depTr)
877
+{
551 878
  $c = array();
552
- foreach($a as $k=>$v){
553
-  if($k == 'style' or !isset($aND[$k][$e])){continue;}
554
-  if($k == 'align'){
879
+ foreach($a as $k=>$v)
880
+ {
881
+  if($k == 'style' or !isset($aND[$k][$e]))
882
+  {
883
+continue;}
884
+  if($k == 'align')
885
+  {
555 886
    unset($a['align']);
556
-   if($e == 'img' && ($v == 'left' or $v == 'right')){$c[] = 'float: '. $v;}
557
-   elseif(($e == 'div' or $e == 'table') && $v == 'center'){$c[] = 'margin: auto';}
558
-   else{$c[] = 'text-align: '. $v;}
559
-  }elseif($k == 'bgcolor'){
887
+   if($e == 'img' && ($v == 'left' or $v == 'right'))
888
+   {
889
+$c[] = 'float: '. $v;}
890
+   elseif(($e == 'div' or $e == 'table') && $v == 'center')
891
+   {
892
+$c[] = 'margin: auto';}
893
+   else
894
+   {
895
+$c[] = 'text-align: '. $v;}
896
+  }
897
+  elseif($k == 'bgcolor')
898
+  {
560 899
    unset($a['bgcolor']);
561 900
    $c[] = 'background-color: '. $v;
562
-  }elseif($k == 'border'){
901
+  }
902
+  elseif($k == 'border')
903
+  {
563 904
    unset($a['border']); $c[] = "border: {$v}px";
564
-  }elseif($k == 'bordercolor'){
905
+  }
906
+  elseif($k == 'bordercolor')
907
+  {
565 908
    unset($a['bordercolor']); $c[] = 'border-color: '. $v;
566
-  }elseif($k == 'clear'){
909
+  }
910
+  elseif($k == 'clear')
911
+  {
567 912
    unset($a['clear']); $c[] = 'clear: '. ($v != 'all' ? $v : 'both');
568
-  }elseif($k == 'compact'){
913
+  }
914
+  elseif($k == 'compact')
915
+  {
569 916
    unset($a['compact']); $c[] = 'font-size: 85%';
570
-  }elseif($k == 'height' or $k == 'width'){
917
+  }
918
+  elseif($k == 'height' or $k == 'width')
919
+  {
571 920
    unset($a[$k]); $c[] = $k. ': '. ($v[0] != '*' ? $v. (ctype_digit($v) ? 'px' : '') : 'auto');
572
-  }elseif($k == 'hspace'){
921
+  }
922
+  elseif($k == 'hspace')
923
+  {
573 924
    unset($a['hspace']); $c[] = "margin-left: {$v}px; margin-right: {$v}px";
574
-  }elseif($k == 'language' && !isset($a['type'])){
925
+  }
926
+  elseif($k == 'language' && !isset($a['type']))
927
+  {
575 928
    unset($a['language']);
576 929
    $a['type'] = 'text/'. strtolower($v);
577
-  }elseif($k == 'name'){
578
-   if($C['no_deprecated_attr'] == 2 or ($e != 'a' && $e != 'map')){unset($a['name']);}
579
-   if(!isset($a['id']) && preg_match('`[a-zA-Z][a-zA-Z\d.:_\-]*`', $v)){$a['id'] = $v;}
580
-  }elseif($k == 'noshade'){
930
+  }
931
+  elseif($k == 'name')
932
+  {
933
+   if($C['no_deprecated_attr'] == 2 or ($e != 'a' && $e != 'map'))
934
+   {
935
+unset($a['name']);}
936
+   if(!isset($a['id']) && preg_match('`[a-zA-Z][a-zA-Z\d.:_\-]*`', $v))
937
+   {
938
+$a['id'] = $v;}
939
+  }
940
+  elseif($k == 'noshade')
941
+  {
581 942
    unset($a['noshade']); $c[] = 'border-style: none; border: 0; background-color: gray; color: gray';
582
-  }elseif($k == 'nowrap'){
943
+  }
944
+  elseif($k == 'nowrap')
945
+  {
583 946
    unset($a['nowrap']); $c[] = 'white-space: nowrap';
584
-  }elseif($k == 'size'){
947
+  }
948
+  elseif($k == 'size')
949
+  {
585 950
    unset($a['size']); $c[] = 'size: '. $v. 'px';
586
-  }elseif($k == 'start' or $k == 'value'){
951
+  }
952
+  elseif($k == 'start' or $k == 'value')
953
+  {
587 954
    unset($a[$k]);
588
-  }elseif($k == 'type'){
955
+  }
956
+  elseif($k == 'type')
957
+  {
589 958
    unset($a['type']);
590 959
    static $ol_type = array('i'=>'lower-roman', 'I'=>'upper-roman', 'a'=>'lower-latin', 'A'=>'upper-latin', '1'=>'decimal');
591 960
    $c[] = 'list-style-type: '. (isset($ol_type[$v]) ? $ol_type[$v] : 'decimal');
592
-  }elseif($k == 'vspace'){
961
+  }
962
+  elseif($k == 'vspace')
963
+  {
593 964
    unset($a['vspace']); $c[] = "margin-top: {$v}px; margin-bottom: {$v}px";
594 965
   }
595 966
  }
596
- if(count($c)){
967
+ if(count($c))
968
+ {
597 969
   $c = implode('; ', $c);
598 970
   $a['style'] = isset($a['style']) ? rtrim($a['style'], ' ;'). '; '. $c. ';': $c. ';';
599 971
  }
600 972
 }
601 973
 // unique ID
602
-if($C['unique_ids'] && isset($a['id'])){
603
- 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']);
604
- }else{
605
-  while(isset($GLOBALS['hl_Ids'][$id])){$id = $C['unique_ids']. $id;}
974
+if($C['unique_ids'] && isset($a['id']))
975
+{
976
+ if(!preg_match('`^[A-Za-z][A-Za-z0-9_\-.:]*$`', ($id = $a['id'])) or (isset($GLOBALS['hl_Ids'][$id]) && $C['unique_ids'] == 1))
977
+ {
978
+unset($a['id']);
979
+ }
980
+ else
981
+ {
982
+  while(isset($GLOBALS['hl_Ids'][$id]))
983
+  {
984
+$id = $C['unique_ids']. $id;}
606 985
   $GLOBALS['hl_Ids'][($a['id'] = $id)] = 1;
607 986
  }
608 987
 }
609 988
 // xml:lang
610
-if($C['xml:lang'] && isset($a['lang'])){
989
+if($C['xml:lang'] && isset($a['lang']))
990
+{
611 991
  $a['xml:lang'] = isset($a['xml:lang']) ? $a['xml:lang'] : $a['lang'];
612
- if($C['xml:lang'] == 2){unset($a['lang']);}
992
+ if($C['xml:lang'] == 2)
993
+ {
994
+unset($a['lang']);}
613 995
 }
614 996
 // for transformed tag
615
-if(!empty($trt)){
997
+if(!empty($trt))
998
+{
616 999
  $a['style'] = isset($a['style']) ? rtrim($a['style'], ' ;'). '; '. $trt : $trt;
617 1000
 }
618 1001
 // return with empty ele /
619
-if(empty($C['hook_tag'])){
1002
+if(empty($C['hook_tag']))
1003
+{
620 1004
  $aA = '';
621
- foreach($a as $k=>$v){$aA .= " {$k}=\"{$v}\"";}
1005
+ foreach($a as $k=>$v)
1006
+ {
1007
+$aA .= " {$k}=\"{$v}\"";}
622 1008
  return "<{$e}{$aA}". (isset($eE[$e]) ? ' /' : ''). '>';
623 1009
 }
624
-else{return $C['hook_tag']($e, $a);}
1010
+else
1011
+{
1012
+return $C['hook_tag']($e, $a);}
625 1013
 // eof
626 1014
 }
627 1015
 
628
-function hl_tag2(&$e, &$a, $t=1){
1016
+function hl_tag2(&$e, &$a, $t=1)
1017
+{
629 1018
 // transform tag
630
-if($e == 'center'){$e = 'div'; return 'text-align: center;';}
631
-if($e == 'dir' or $e == 'menu'){$e = 'ul'; return '';}
632
-if($e == 's' or $e == 'strike'){$e = 'span'; return 'text-decoration: line-through;';}
633
-if($e == 'u'){$e = 'span'; return 'text-decoration: underline;';}
1019
+if($e == 'center')
1020
+{
1021
+$e = 'div'; return 'text-align: center;';}
1022
+if($e == 'dir' or $e == 'menu')
1023
+{
1024
+$e = 'ul'; return '';}
1025
+if($e == 's' or $e == 'strike')
1026
+{
1027
+$e = 'span'; return 'text-decoration: line-through;';}
1028
+if($e == 'u')
1029
+{
1030
+$e = 'span'; return 'text-decoration: underline;';}
634 1031
 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%');
635
-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
1032
+if($e == 'font' && $t !=3)
1033
+{
1034
+//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
636 1035
  $a2 = '';
637
- if(preg_match('`face\s*=\s*(\'|")([^=]+?)\\1`i', $a, $m) or preg_match('`face\s*=(\s*)(\S+)`i', $a, $m)){
1036
+ if(preg_match('`face\s*=\s*(\'|")([^=]+?)\\1`i', $a, $m) or preg_match('`face\s*=(\s*)(\S+)`i', $a, $m))
1037
+ {
638 1038
   $a2 .= ' font-family: '. str_replace('"', '\'', trim($m[2])). ';';
639 1039
  }
640
- if(preg_match('`color\s*=\s*(\'|")?(.+?)(\\1|\s|$)`i', $a, $m)){
1040
+ if(preg_match('`color\s*=\s*(\'|")?(.+?)(\\1|\s|$)`i', $a, $m))
1041
+ {
641 1042
   $a2 .= ' color: '. trim($m[2]). ';';
642 1043
  }
643
- if(preg_match('`size\s*=\s*(\'|")?(.+?)(\\1|\s|$)`i', $a, $m) && isset($fs[($m = trim($m[2]))])){
1044
+ if(preg_match('`size\s*=\s*(\'|")?(.+?)(\\1|\s|$)`i', $a, $m) && isset($fs[($m = trim($m[2]))]))
1045
+ {
644 1046
   $a2 .= ' font-size: '. $fs[$m]. ';';
645 1047
  }
646 1048
 // $e = 'span'; return ltrim($a2);
647 1049
 // replace the above with following
648
- if($GLOBALS['C']['balance']){
1050
+ if($GLOBALS['C']['balance'])
1051
+ {
649 1052
   $e = 'div'; return 'display: inline; -htmlawed-transform: 1; '. ltrim($a2);
650
- }else{
1053
+ }
1054
+ else
1055
+ {
651 1056
   $e = 'span'; return ltrim($a2);
652 1057
  }
653 1058
 }
654
-if($t == 2){$e = 0; return 0;}
1059
+if($t == 2)
1060
+{
1061
+$e = 0; return 0;}
655 1062
 return '';
656 1063
 // eof
657 1064
 }
658 1065
 
659
-function hl_tidy($t, $w, $p){
1066
+function hl_tidy($t, $w, $p)
1067
+{
660 1068
 // Tidy/compact HTM
661
-if(strpos(' pre,script,textarea', "$p,")){return $t;}
1069
+if(strpos(' pre,script,textarea', "$p,"))
1070
+{
1071
+return $t;}
662 1072
 $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){
1073
+if(($w = strtolower($w)) == -1)
1074
+{
664 1075
  return str_replace(array("\x01", "\x02", "\x03", "\x04", "\x05", "\x07"), array('<', '>', "\n", "\r", "\t", ' '), $t);
665 1076
 }
666 1077
 $s = strpos(" $w", 't') ? "\t" : ' ';
@@ -672,54 +1083,87 @@  discard block
 block discarded – undo
672 1083
 $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 1084
 $T = explode('<', $t);
674 1085
 $X = 1;
675
-while($X){
1086
+while($X)
1087
+{
676 1088
  $n = $N;
677 1089
  $t = $T;
678 1090
  ob_start();
679
- if(isset($d[$p])){echo str_repeat($s, ++$n);}
1091
+ if(isset($d[$p]))
1092
+ {
1093
+echo str_repeat($s, ++$n);}
680 1094
  echo ltrim(array_shift($t));
681
- for($i=-1, $j=count($t); ++$i<$j;){
1095
+ for($i=-1, $j=count($t); ++$i<$j;)
1096
+ {
682 1097
   $r = ''; list($e, $r) = explode('>', $t[$i]);
683 1098
   $x = $e[0] == '/' ? 0 : (substr($e, -1) == '/' ? 1 : ($e[0] != '!' ? 2 : -1));
684 1099
   $y = !$x ? ltrim($e, '/') : ($x > 0 ? substr($e, 0, strcspn($e, ' ')) : 0);
685 1100
   $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;}
1101
+  if(isset($d[$y]))
1102
+  {
1103
+   if(!$x)
1104
+   {
1105
+    if($n)
1106
+    {
1107
+echo "\n", str_repeat($s, --$n), "$e\n", str_repeat($s, $n);}
1108
+    else
1109
+    {
1110
+++$N; ob_end_clean(); continue 2;}
690 1111
    }
691
-   else{echo "\n", str_repeat($s, $n), "$e\n", str_repeat($s, ($x != 1 ? ++$n : $n));}
1112
+   else
1113
+   {
1114
+echo "\n", str_repeat($s, $n), "$e\n", str_repeat($s, ($x != 1 ? ++$n : $n));}
692 1115
    echo $r; continue;
693 1116
   }
694 1117
   $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;}
1118
+  if(isset($c[$y]))
1119
+  {
1120
+   if(!$x)
1121
+   {
1122
+echo $e, $f, $r;}
1123
+   else
1124
+   {
1125
+echo $f, $e, $r;}
1126
+  }
1127
+  elseif(isset($b[$y]))
1128
+  {
1129
+echo $f, $e, $r;
1130
+  }
1131
+  elseif(isset($a[$y]))
1132
+  {
1133
+echo $e, $f, $r;
1134
+  }
1135
+  elseif(!$y)
1136
+  {
1137
+echo $f, $e, $f, $r;
1138
+  }
1139
+  else
1140
+  {
1141
+echo $e, $r;}
702 1142
  }
703 1143
  $X = 0;
704 1144
 }
705 1145
 $t = str_replace(array("\n ", " \n"), "\n", preg_replace('`[\n]\s*?[\n]+`', "\n", ob_get_contents()));
706 1146
 ob_end_clean();
707
-if(($l = strpos(" $w", 'r') ? (strpos(" $w", 'n') ? "\r\n" : "\r") : 0)){
1147
+if(($l = strpos(" $w", 'r') ? (strpos(" $w", 'n') ? "\r\n" : "\r") : 0))
1148
+{
708 1149
  $t = str_replace("\n", $l, $t);
709 1150
 }
710 1151
 return str_replace(array("\x01", "\x02", "\x03", "\x04", "\x05", "\x07"), array('<', '>', "\n", "\r", "\t", ' '), $t);
711 1152
 // eof
712 1153
 }
713 1154
 
714
-function hl_version(){
1155
+function hl_version()
1156
+{
715 1157
 // rel
716 1158
 return '1.1.17';
717 1159
 // eof
718 1160
 }
719 1161
 
720
-function kses($t, $h, $p=array('http', 'https', 'ftp', 'news', 'nntp', 'telnet', 'gopher', 'mailto')){
1162
+function kses($t, $h, $p=array('http', 'https', 'ftp', 'news', 'nntp', 'telnet', 'gopher', 'mailto'))
1163
+{
721 1164
 // kses compat
722
-foreach($h as $k=>$v){
1165
+foreach($h as $k=>$v)
1166
+{
723 1167
  $h[$k]['n']['*'] = 1;
724 1168
 }
725 1169
 $C['cdata'] = $C['comment'] = $C['make_tag_strict'] = $C['no_deprecated_attr'] = $C['unique_ids'] = 0;
@@ -731,7 +1175,8 @@  discard block
 block discarded – undo
731 1175
 // eof
732 1176
 }
733 1177
 
734
-function kses_hook($t, &$C, &$S){
1178
+function kses_hook($t, &$C, &$S)
1179
+{
735 1180
 // kses compat
736 1181
 return $t;
737 1182
 // eof
Please login to merge, or discard this patch.