Completed
Push — 17.1 ( 8c3b94...29ee37 )
by Ralf
20:39 queued 11:58
created
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.
Braces   +146 added lines, -38 removed lines patch added patch discarded remove patch
@@ -109,9 +109,18 @@  discard block
 block discarded – undo
109 109
 	function run($html2check, $Config=null, $Spec=array())
110 110
 	{
111 111
 		//error_log(__METHOD__.__LINE__.' Input:'.$html2check);
112
-		if (is_array($Config) && is_array($this->Configuration)) $Config = array_merge($this->Configuration, $Config);
113
-		if (empty($Config)) $Config = $this->Configuration;
114
-		if (empty($Spec)) $Spec = $this->Spec;
112
+		if (is_array($Config) && is_array($this->Configuration))
113
+		{
114
+			$Config = array_merge($this->Configuration, $Config);
115
+		}
116
+		if (empty($Config))
117
+		{
118
+			$Config = $this->Configuration;
119
+		}
120
+		if (empty($Spec))
121
+		{
122
+			$Spec = $this->Spec;
123
+		}
115 124
 		// If we are processing mails, we take out stuff in <style> stuff </style> tags and
116 125
 		// put it back in after purifying; styles are processed for known security risks
117 126
 		// in self::getStyles
@@ -139,7 +148,10 @@  discard block
 block discarded – undo
139 148
 	{
140 149
 		$ct=0;
141 150
 		$newStyle = null;
142
-		if (stripos($html,'<style')!==false)  $ct = preg_match_all('#<style(?:\s.*)?>(.+)</style>#isU', $html, $newStyle);
151
+		if (stripos($html,'<style')!==false)
152
+		{
153
+			$ct = preg_match_all('#<style(?:\s.*)?>(.+)</style>#isU', $html, $newStyle);
154
+		}
143 155
 		if ($ct>0)
144 156
 		{
145 157
 			//error_log(__METHOD__.__LINE__.array2string($newStyle[0]));
@@ -173,7 +185,11 @@  discard block
 block discarded – undo
173 185
 		// CSS Security
174 186
 		// http://code.google.com/p/browsersec/wiki/Part1#Cascading_stylesheets
175 187
 		$css = preg_replace('/(javascript|expession|-moz-binding)/i','',$style);
176
-		if (stripos($css,'script')!==false) Api\Mail\Html::replaceTagsCompletley($css,'script'); // Strip out script that may be included
188
+		if (stripos($css,'script')!==false)
189
+		{
190
+			Api\Mail\Html::replaceTagsCompletley($css,'script');
191
+		}
192
+		// Strip out script that may be included
177 193
 		// we need this, as styledefinitions are enclosed with curly brackets; and template stuff tries to replace everything between curly brackets that is having no horizontal whitespace
178 194
 		// as the comments as <!-- styledefinition --> in stylesheet are outdated, and ck-editor does not understand it, we remove it
179 195
 		$css_no_comment = str_replace(array(':','<!--','-->'),array(': ','',''),$css);
@@ -199,12 +215,19 @@  discard block
 block discarded – undo
199 215
 	{
200 216
 		$defaultConfig = array('valid_xhtml'=>1,'safe'=>1);
201 217
 
202
-		if (empty($html)) return $html;	// no need to process further
218
+		if (empty($html))
219
+		{
220
+			return $html;
221
+		}
222
+		// no need to process further
203 223
 		if (!empty($config) && is_string($config))
204 224
 		{
205 225
 			//error_log(__METHOD__.__LINE__.$config);
206 226
 			$config = json_decode($config,true);
207
-			if (is_null($config)) error_log(__METHOD__.__LINE__." decoding of config failed; standard will be applied");
227
+			if (is_null($config))
228
+			{
229
+				error_log(__METHOD__.__LINE__." decoding of config failed; standard will be applied");
230
+			}
208 231
 		}
209 232
 
210 233
 		// User preferences
@@ -218,8 +241,14 @@  discard block
 block discarded – undo
218 241
 			return '';
219 242
 		}
220 243
 		$htmLawed = new HtmLawed();
221
-		if (is_array($config) && $_force===false) $config = array_merge($defaultConfig, $config);
222
-		if (empty($config)) $config = $defaultConfig;
244
+		if (is_array($config) && $_force===false)
245
+		{
246
+			$config = array_merge($defaultConfig, $config);
247
+		}
248
+		if (empty($config))
249
+		{
250
+			$config = $defaultConfig;
251
+		}
223 252
 		//error_log(__METHOD__.__LINE__.array2string($config));
224 253
 		return $htmLawed->run($html,$config,$spec);
225 254
 	}
@@ -236,7 +265,8 @@  discard block
 block discarded – undo
236 265
 function hl_my_tag_transform($element, $attribute_array=0)
237 266
 {
238 267
 	// If second argument is not received, it means a closing tag is being handled
239
-	if(is_numeric($attribute_array)){
268
+	if(is_numeric($attribute_array))
269
+	{
240 270
 		return "</$element>";
241 271
 	}
242 272
 
@@ -258,18 +288,30 @@  discard block
 block discarded – undo
258 288
 	if($element == 'img')
259 289
 	{
260 290
 		// Re-build 'alt'
261
-		if (isset($attribute_array['alt'])) $attribute_array['alt'] = ($attribute_array['alt']=='image'?'':$attribute_array['alt']);
262
-		if (isset($attribute_array['alt'])&&strpos($attribute_array['alt'],'@')!==false) $attribute_array['alt']=str_replace('@','(at)',$attribute_array['alt']);
291
+		if (isset($attribute_array['alt']))
292
+		{
293
+			$attribute_array['alt'] = ($attribute_array['alt']=='image'?'':$attribute_array['alt']);
294
+		}
295
+		if (isset($attribute_array['alt'])&&strpos($attribute_array['alt'],'@')!==false)
296
+		{
297
+			$attribute_array['alt']=str_replace('@','(at)',$attribute_array['alt']);
298
+		}
263 299
 	}
264 300
 	if (isset($attribute_array['title']))
265 301
 	{
266
-		if (strpos($attribute_array['title'],'@')!==false) $attribute_array['title']=str_replace('@','(at)',$attribute_array['title']);
302
+		if (strpos($attribute_array['title'],'@')!==false)
303
+		{
304
+			$attribute_array['title']=str_replace('@','(at)',$attribute_array['title']);
305
+		}
267 306
 	}
268 307
 	if ($element == 'blockquote')
269 308
 	{
270 309
 		if (isset($attribute_array['cite']))
271 310
 		{
272
-			if (strpos($attribute_array['cite'],'@')!==false) $attribute_array['cite']=str_replace('@','(at)',$attribute_array['cite']);
311
+			if (strpos($attribute_array['cite'],'@')!==false)
312
+			{
313
+				$attribute_array['cite']=str_replace('@','(at)',$attribute_array['cite']);
314
+			}
273 315
 		}
274 316
 	}
275 317
 	/*
@@ -301,7 +343,10 @@  discard block
 block discarded – undo
301 343
 		$attribute_array['style'] = implode('; ', $style);
302 344
 	}
303 345
 	*/
304
-	if (isset($attribute_array['style']) && stripos($attribute_array['style'],'script')!==false) $attribute_array['style'] = str_ireplace('script','',$attribute_array['style']);
346
+	if (isset($attribute_array['style']) && stripos($attribute_array['style'],'script')!==false)
347
+	{
348
+		$attribute_array['style'] = str_ireplace('script','',$attribute_array['style']);
349
+	}
305 350
 	if($element == 'a')
306 351
 	{
307 352
 		//error_log(__METHOD__.__LINE__.array2string($attribute_array));
@@ -314,12 +359,16 @@  discard block
 block discarded – undo
314 359
 		{
315 360
 			$attribute_array['href']=str_ireplace("');",'',str_ireplace("javascript:GoToAnchor('","#",$attribute_array['href']));
316 361
 		}
317
-		if (strpos($attribute_array['href'],'denied:javascript')===0) $attribute_array['href']='';
362
+		if (strpos($attribute_array['href'],'denied:javascript')===0)
363
+		{
364
+			$attribute_array['href']='';
365
+		}
318 366
 	}
319 367
 
320 368
 	// Build the attributes string
321 369
 	$attributes = '';
322
-	foreach($attribute_array as $k=>$v){
370
+	foreach($attribute_array as $k=>$v)
371
+	{
323 372
 		$attributes .= " {$k}=\"{$v}\"";
324 373
 	}
325 374
 
@@ -344,27 +393,52 @@  discard block
 block discarded – undo
344 393
 	//error_log(__METHOD__.__LINE__.$element.'=>'.array2string($attribute_array));
345 394
 	static $lastelement = null;
346 395
 	static $throwawaycounter = null;
347
-	if (is_null($lastelement)) $lastelement='';
348
-	if (is_null($throwawaycounter)) $throwawaycounter = 0;
396
+	if (is_null($lastelement))
397
+	{
398
+		$lastelement='';
399
+	}
400
+	if (is_null($throwawaycounter))
401
+	{
402
+		$throwawaycounter = 0;
403
+	}
349 404
 	//if ($throwawaycounter>1) error_log(__METHOD__.__LINE__.' '.$throwawaycounter.$element.array2string($attribute_array));
350 405
 	if ($element=='div' && $element==$lastelement && ($attribute_array==0 || empty($attribute_array)))
351 406
 	{
352
-		if (is_array($attribute_array)) $throwawaycounter++;
353
-		if ($attribute_array==0 && $throwawaycounter>0) $throwawaycounter--;
354
-		if ($throwawaycounter>1) return '';
407
+		if (is_array($attribute_array))
408
+		{
409
+			$throwawaycounter++;
410
+		}
411
+		if ($attribute_array==0 && $throwawaycounter>0)
412
+		{
413
+			$throwawaycounter--;
414
+		}
415
+		if ($throwawaycounter>1)
416
+		{
417
+			return '';
418
+		}
419
+	}
420
+	if ($lastelement=='div' && $element!=$lastelement && is_array($attribute_array))
421
+	{
422
+		$throwawaycounter = 0;
355 423
 	}
356
-	if ($lastelement=='div' && $element!=$lastelement && is_array($attribute_array)) $throwawaycounter = 0;
357 424
 	if (is_array($attribute_array) && !empty($attribute_array) && $element=='div')
358 425
 	{
359 426
 		$lastelement = 'div_with_attr';
360 427
 	}
361 428
 	else
362 429
 	{
363
-		if (is_array($attribute_array)) $lastelement = $element;
430
+		if (is_array($attribute_array))
431
+		{
432
+			$lastelement = $element;
433
+		}
364 434
 	}
365 435
 	// If second argument is not received, it means a closing tag is being handled
366
-	if(is_numeric($attribute_array)){
367
-		if($element==$lastelement) $lastelement='';
436
+	if(is_numeric($attribute_array))
437
+	{
438
+		if($element==$lastelement)
439
+		{
440
+			$lastelement='';
441
+		}
368 442
 		return "</$element>";
369 443
 	}
370 444
 
@@ -386,15 +460,24 @@  discard block
 block discarded – undo
386 460
 	if($element == 'img')
387 461
 	{
388 462
 		// Re-build 'alt'
389
-		if (isset($attribute_array['alt'])) $attribute_array['alt'] = ($attribute_array['alt']=='image'?'':$attribute_array['alt']);
390
-		if (isset($attribute_array['alt'])&&strpos($attribute_array['alt'],'@')!==false) $attribute_array['alt']=str_replace('@','(at)',$attribute_array['alt']);
463
+		if (isset($attribute_array['alt']))
464
+		{
465
+			$attribute_array['alt'] = ($attribute_array['alt']=='image'?'':$attribute_array['alt']);
466
+		}
467
+		if (isset($attribute_array['alt'])&&strpos($attribute_array['alt'],'@')!==false)
468
+		{
469
+			$attribute_array['alt']=str_replace('@','(at)',$attribute_array['alt']);
470
+		}
391 471
 		// $GLOBALS['egw_info']['user']['preferences']['mail']['allowExternalIMGs'] ? '' : 'match' => '/^cid:.*/'),
392 472
 		if (isset($attribute_array['src']))
393 473
 		{
394 474
 			if (!(strlen($attribute_array['src'])>4 && strlen($attribute_array['src']<400)))
395 475
 			{
396 476
 					$attribute_array['alt']= $attribute_array['alt'].' [blocked (reason: url length):'.$attribute_array['src'].']';
397
-					if (!isset($attribute_array['title'])) $attribute_array['title']=$attribute_array['alt'];
477
+					if (!isset($attribute_array['title']))
478
+					{
479
+						$attribute_array['title']=$attribute_array['alt'];
480
+					}
398 481
 					$attribute_array['src']=Api\Image::find('api','error');
399 482
 			}
400 483
 			if (!preg_match('/^cid:.*/',$attribute_array['src']))
@@ -407,36 +490,60 @@  discard block
 block discarded – undo
407 490
 					if (empty($GLOBALS['egw_info']['server']['webserver_url'])||!preg_match("$^".$GLOBALS['egw_info']['server']['webserver_url'].".*$",$attribute_array['src']))
408 491
 					{
409 492
 						$attribute_array['alt']= $attribute_array['alt'].' [blocked external image:'.$attribute_array['src'].']';
410
-						if (!isset($attribute_array['title'])) $attribute_array['title']=$attribute_array['alt'];
493
+						if (!isset($attribute_array['title']))
494
+						{
495
+							$attribute_array['title']=$attribute_array['alt'];
496
+						}
411 497
 						$attribute_array['src']=Api\Image::find('mail','no-image-shown');
412 498
 						$attribute_array['border'] = 1;
413 499
 						if ($attribute_array['style'])
414 500
 						{
415
-							if (stripos($attribute_array['style'],'border')!==false) $attribute_array['style'] = preg_replace('~border(:|-left:|-right:|-bottom:|-top:)+ (0px)+ (none)+;~si','',$attribute_array['style']);
501
+							if (stripos($attribute_array['style'],'border')!==false)
502
+							{
503
+								$attribute_array['style'] = preg_replace('~border(:|-left:|-right:|-bottom:|-top:)+ (0px)+ (none)+;~si','',$attribute_array['style']);
504
+							}
416 505
 						}
417 506
 					}
418 507
 				}
419 508
 			}
420 509
 		}
421 510
 	}
422
-	if (isset($attribute_array['style']) && stripos($attribute_array['style'],'script')!==false) $attribute_array['style'] = str_ireplace('script','',$attribute_array['style']);
511
+	if (isset($attribute_array['style']) && stripos($attribute_array['style'],'script')!==false)
512
+	{
513
+		$attribute_array['style'] = str_ireplace('script','',$attribute_array['style']);
514
+	}
423 515
 	if (isset($attribute_array['title']))
424 516
 	{
425
-		if (strpos($attribute_array['title'],'@')!==false) $attribute_array['title']=str_replace('@','(at)',$attribute_array['title']);
517
+		if (strpos($attribute_array['title'],'@')!==false)
518
+		{
519
+			$attribute_array['title']=str_replace('@','(at)',$attribute_array['title']);
520
+		}
426 521
 	}
427 522
 	if ($element == 'blockquote')
428 523
 	{
429 524
 		if (isset($attribute_array['cite']))
430 525
 		{
431
-			if (strpos($attribute_array['cite'],'@')!==false) $attribute_array['cite']=str_replace('@','(at)',$attribute_array['cite']);
526
+			if (strpos($attribute_array['cite'],'@')!==false)
527
+			{
528
+				$attribute_array['cite']=str_replace('@','(at)',$attribute_array['cite']);
529
+			}
432 530
 		}
433 531
 	}
434 532
 	if($element == 'a')
435 533
 	{
436 534
 		//error_log(__METHOD__.__LINE__.array2string($attribute_array));
437
-		if (strpos($attribute_array['href'],'denied:javascript')===0) $attribute_array['href']='';
438
-		if (isset($attribute_array['name']) && isset($attribute_array['id'])) $attribute_array['id'] = $attribute_array['name'];
439
-		if (strpos($attribute_array['href'],'@')!==false) $attribute_array['href'] = str_replace('@','%40',$attribute_array['href']);
535
+		if (strpos($attribute_array['href'],'denied:javascript')===0)
536
+		{
537
+			$attribute_array['href']='';
538
+		}
539
+		if (isset($attribute_array['name']) && isset($attribute_array['id']))
540
+		{
541
+			$attribute_array['id'] = $attribute_array['name'];
542
+		}
543
+		if (strpos($attribute_array['href'],'@')!==false)
544
+		{
545
+			$attribute_array['href'] = str_replace('@','%40',$attribute_array['href']);
546
+		}
440 547
 		if (strpos($attribute_array['href'],'#')===0 && (isset(Api\Mail::$htmLawed_config['transform_anchor']) && Api\Mail::$htmLawed_config['transform_anchor']===true))
441 548
 		{
442 549
 			$attribute_array['href'] = "javascript:GoToAnchor('".trim(substr($attribute_array['href'],1))."');";
@@ -446,7 +553,8 @@  discard block
 block discarded – undo
446 553
 
447 554
 	// Build the attributes string
448 555
 	$attributes = '';
449
-	foreach($attribute_array as $k=>$v){
556
+	foreach($attribute_array as $k=>$v)
557
+	{
450 558
 		$attributes .= " {$k}=\"{$v}\"";
451 559
 	}
452 560
 
Please login to merge, or discard this patch.
Spacing   +80 added lines, -81 removed lines patch added patch discarded remove patch
@@ -85,8 +85,8 @@  discard block
 block discarded – undo
85 85
 		*/
86 86
 
87 87
 		$this->Configuration = array('comment'=>1, //remove comments
88
-			'make_tag_strict'=>3,//3 is a new own config value, to indicate that transformation is to be performed, but don't transform font, as size transformation of numeric sizes to keywords alters the intended result too much
89
-			'balance'=>0,//turn off tag-balancing (config['balance']=>0). That will not introduce any security risk; only standards-compliant tag nesting check/filtering will be turned off (basic tag-balance will remain; i.e., there won't be any unclosed tag, etc., after filtering)
88
+			'make_tag_strict'=>3, //3 is a new own config value, to indicate that transformation is to be performed, but don't transform font, as size transformation of numeric sizes to keywords alters the intended result too much
89
+			'balance'=>0, //turn off tag-balancing (config['balance']=>0). That will not introduce any security risk; only standards-compliant tag nesting check/filtering will be turned off (basic tag-balance will remain; i.e., there won't be any unclosed tag, etc., after filtering)
90 90
 			// tidy eats away even some wanted whitespace, so we switch it off;
91 91
 			// we used it for its compacting and beautifying capabilities, which resulted in better html for further processing
92 92
 			'tidy'=>0,
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 	 * @param mixed $Spec =text or array; The '$spec' argument can be used to disallow an otherwise legal attribute for an element
107 107
 	 * @return varchar cleaned/fixed html
108 108
 	 */
109
-	function run($html2check, $Config=null, $Spec=array())
109
+	function run($html2check, $Config = null, $Spec = array())
110 110
 	{
111 111
 		//error_log(__METHOD__.__LINE__.' Input:'.$html2check);
112 112
 		if (is_array($Config) && is_array($this->Configuration)) $Config = array_merge($this->Configuration, $Config);
@@ -121,11 +121,11 @@  discard block
 block discarded – undo
121 121
 		//error_log(__METHOD__.__LINE__.' Config:'.array2string($Config));
122 122
 
123 123
 		// mind our namespace when defining a function as hook. we handle our own defined hooks here.
124
-		if ($Config['hook_tag']=="hl_my_tag_transform" || $Config['hook_tag']=="hl_email_tag_transform")
124
+		if ($Config['hook_tag'] == "hl_my_tag_transform" || $Config['hook_tag'] == "hl_email_tag_transform")
125 125
 		{
126
-			$Config['hook_tag']=__NAMESPACE__.'\\'.$Config['hook_tag'];
126
+			$Config['hook_tag'] = __NAMESPACE__.'\\'.$Config['hook_tag'];
127 127
 		}
128
-		return ($styles?$styles:'').htmLawed($html2check, $Config, $Spec);
128
+		return ($styles ? $styles : '').htmLawed($html2check, $Config, $Spec);
129 129
 	}
130 130
 
131 131
 	/**
@@ -137,16 +137,16 @@  discard block
 block discarded – undo
137 137
 	 */
138 138
 	static function getStyles(&$html)
139 139
 	{
140
-		$ct=0;
140
+		$ct = 0;
141 141
 		$newStyle = null;
142
-		if (stripos($html,'<style')!==false)  $ct = preg_match_all('#<style(?:\s.*)?>(.+)</style>#isU', $html, $newStyle);
143
-		if ($ct>0)
142
+		if (stripos($html, '<style') !== false)  $ct = preg_match_all('#<style(?:\s.*)?>(.+)</style>#isU', $html, $newStyle);
143
+		if ($ct > 0)
144 144
 		{
145 145
 			//error_log(__METHOD__.__LINE__.array2string($newStyle[0]));
146
-			$style2buffer = implode('',$newStyle[0]);
146
+			$style2buffer = implode('', $newStyle[0]);
147 147
 			// only replace what we have found, we use it here, as we use the same routine in Api\Mail\Html::replaceTagsCompletley
148 148
 			// no need to do the extra routine
149
-			$html = str_ireplace($newStyle[0],'',$html);
149
+			$html = str_ireplace($newStyle[0], '', $html);
150 150
 		}
151 151
 		if ($style2buffer)
152 152
 		{
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 			$test = json_encode($style2buffer);
155 155
 			//error_log(__METHOD__.__LINE__.'#'.$test.'# ->'.strlen($style2buffer).' Error:'.json_last_error());
156 156
 			//if (json_last_error() != JSON_ERROR_NONE && strlen($style2buffer)>0)
157
-			if ($test=="null" && strlen($style2buffer)>0)
157
+			if ($test == "null" && strlen($style2buffer) > 0)
158 158
 			{
159 159
 				// this should not be needed, unless something fails with charset detection/ wrong charset passed
160 160
 				error_log(__METHOD__.__LINE__.' Found Invalid sequence for utf-8 in CSS:'.$style2buffer.' Carset Detected:'.Api\Translation::detect_encoding($style2buffer));
@@ -164,19 +164,19 @@  discard block
 block discarded – undo
164 164
 		$style .= $style2buffer;
165 165
 		// clean out comments and stuff
166 166
 		$search = array(
167
-			'@url\(http:\/\/[^\)].*?\)@si',  // url calls e.g. in style definitions
167
+			'@url\(http:\/\/[^\)].*?\)@si', // url calls e.g. in style definitions
168 168
 //			'@<!--[\s\S]*?[ \t\n\r]*-->@',   // Strip multi-line comments including CDATA
169 169
 //			'@<!--[\s\S]*?[ \t\n\r]*--@',    // Strip broken multi-line comments including CDATA
170 170
 		);
171
-		$style = preg_replace($search,"",$style);
171
+		$style = preg_replace($search, "", $style);
172 172
 
173 173
 		// CSS Security
174 174
 		// http://code.google.com/p/browsersec/wiki/Part1#Cascading_stylesheets
175
-		$css = preg_replace('/(javascript|expession|-moz-binding)/i','',$style);
176
-		if (stripos($css,'script')!==false) Api\Mail\Html::replaceTagsCompletley($css,'script'); // Strip out script that may be included
175
+		$css = preg_replace('/(javascript|expession|-moz-binding)/i', '', $style);
176
+		if (stripos($css, 'script') !== false) Api\Mail\Html::replaceTagsCompletley($css, 'script'); // Strip out script that may be included
177 177
 		// we need this, as styledefinitions are enclosed with curly brackets; and template stuff tries to replace everything between curly brackets that is having no horizontal whitespace
178 178
 		// as the comments as <!-- styledefinition --> in stylesheet are outdated, and ck-editor does not understand it, we remove it
179
-		$css_no_comment = str_replace(array(':','<!--','-->'),array(': ','',''),$css);
179
+		$css_no_comment = str_replace(array(':', '<!--', '-->'), array(': ', '', ''), $css);
180 180
 		//error_log(__METHOD__.__LINE__.$css);
181 181
 		// we already removed what we have found, above, as we used pretty much the same routine as in Api\Mail\Html::replaceTagsCompletley
182 182
 		// no need to do the extra routine
@@ -195,15 +195,15 @@  discard block
 block discarded – undo
195 195
 	 *		or to restrict the attribute's values
196 196
 	 * @param boolean $_force =null - force the config passed to be used without merging to the default
197 197
 	 */
198
-	static function purify($html,$config=null,$spec=array(),$_force=false)
198
+	static function purify($html, $config = null, $spec = array(), $_force = false)
199 199
 	{
200
-		$defaultConfig = array('valid_xhtml'=>1,'safe'=>1);
200
+		$defaultConfig = array('valid_xhtml'=>1, 'safe'=>1);
201 201
 
202
-		if (empty($html)) return $html;	// no need to process further
202
+		if (empty($html)) return $html; // no need to process further
203 203
 		if (!empty($config) && is_string($config))
204 204
 		{
205 205
 			//error_log(__METHOD__.__LINE__.$config);
206
-			$config = json_decode($config,true);
206
+			$config = json_decode($config, true);
207 207
 			if (is_null($config)) error_log(__METHOD__.__LINE__." decoding of config failed; standard will be applied");
208 208
 		}
209 209
 
@@ -213,15 +213,15 @@  discard block
 block discarded – undo
213 213
 
214 214
 		// Check for "blank" = just user preference span - for some reason we can't match on the entity, so approximate
215 215
 		$regex = '#^<span style="[^"]*font-family:'.$font.'; font-size:'.$font_size.'pt;[^"]*">.?</span>$#us';
216
-		if(preg_match($regex,$html))
216
+		if (preg_match($regex, $html))
217 217
 		{
218 218
 			return '';
219 219
 		}
220 220
 		$htmLawed = new HtmLawed();
221
-		if (is_array($config) && $_force===false) $config = array_merge($defaultConfig, $config);
221
+		if (is_array($config) && $_force === false) $config = array_merge($defaultConfig, $config);
222 222
 		if (empty($config)) $config = $defaultConfig;
223 223
 		//error_log(__METHOD__.__LINE__.array2string($config));
224
-		return $htmLawed->run($html,$config,$spec);
224
+		return $htmLawed->run($html, $config, $spec);
225 225
 	}
226 226
 }
227 227
 
@@ -233,17 +233,17 @@  discard block
 block discarded – undo
233 233
  * 						a checking for title, replacing @
234 234
  * 						blockquote checking for cite, replacing @
235 235
  */
236
-function hl_my_tag_transform($element, $attribute_array=0)
236
+function hl_my_tag_transform($element, $attribute_array = 0)
237 237
 {
238 238
 	// If second argument is not received, it means a closing tag is being handled
239
-	if(is_numeric($attribute_array)){
239
+	if (is_numeric($attribute_array)) {
240 240
 		return "</$element>";
241 241
 	}
242 242
 
243 243
 	//if ($element=='img') error_log(__METHOD__.__LINE__." ".$element.'->'.array2string($attribute_array));
244
-	if ($element=='td' && isset($attribute_array['background']))
244
+	if ($element == 'td' && isset($attribute_array['background']))
245 245
 	{
246
-		if (is_object($GLOBALS['egw']) && stripos($attribute_array['background'],$GLOBALS['egw']->link('/index.php'))!==false)
246
+		if (is_object($GLOBALS['egw']) && stripos($attribute_array['background'], $GLOBALS['egw']->link('/index.php')) !== false)
247 247
 		{
248 248
 			//error_log(__METHOD__.__LINE__.array2string($attribute_array));
249 249
 			//$attribute_array['background'] = 'url('.$attribute_array['background'].');';
@@ -251,25 +251,25 @@  discard block
 block discarded – undo
251 251
 		else
252 252
 		{
253 253
 			// $attribute_array['background']='denied:'.$attribute_array['background'];
254
-			unset($attribute_array['background']);// only internal background images are allowed
254
+			unset($attribute_array['background']); // only internal background images are allowed
255 255
 		}
256 256
 	}
257 257
 	// Elements other than 'img' or 'img' without a 'img' attribute are returned unchanged
258
-	if($element == 'img')
258
+	if ($element == 'img')
259 259
 	{
260 260
 		// Re-build 'alt'
261
-		if (isset($attribute_array['alt'])) $attribute_array['alt'] = ($attribute_array['alt']=='image'?'':$attribute_array['alt']);
262
-		if (isset($attribute_array['alt'])&&strpos($attribute_array['alt'],'@')!==false) $attribute_array['alt']=str_replace('@','(at)',$attribute_array['alt']);
261
+		if (isset($attribute_array['alt'])) $attribute_array['alt'] = ($attribute_array['alt'] == 'image' ? '' : $attribute_array['alt']);
262
+		if (isset($attribute_array['alt']) && strpos($attribute_array['alt'], '@') !== false) $attribute_array['alt'] = str_replace('@', '(at)', $attribute_array['alt']);
263 263
 	}
264 264
 	if (isset($attribute_array['title']))
265 265
 	{
266
-		if (strpos($attribute_array['title'],'@')!==false) $attribute_array['title']=str_replace('@','(at)',$attribute_array['title']);
266
+		if (strpos($attribute_array['title'], '@') !== false) $attribute_array['title'] = str_replace('@', '(at)', $attribute_array['title']);
267 267
 	}
268 268
 	if ($element == 'blockquote')
269 269
 	{
270 270
 		if (isset($attribute_array['cite']))
271 271
 		{
272
-			if (strpos($attribute_array['cite'],'@')!==false) $attribute_array['cite']=str_replace('@','(at)',$attribute_array['cite']);
272
+			if (strpos($attribute_array['cite'], '@') !== false) $attribute_array['cite'] = str_replace('@', '(at)', $attribute_array['cite']);
273 273
 		}
274 274
 	}
275 275
 	/*
@@ -301,31 +301,31 @@  discard block
 block discarded – undo
301 301
 		$attribute_array['style'] = implode('; ', $style);
302 302
 	}
303 303
 	*/
304
-	if (isset($attribute_array['style']) && stripos($attribute_array['style'],'script')!==false) $attribute_array['style'] = str_ireplace('script','',$attribute_array['style']);
305
-	if($element == 'a')
304
+	if (isset($attribute_array['style']) && stripos($attribute_array['style'], 'script') !== false) $attribute_array['style'] = str_ireplace('script', '', $attribute_array['style']);
305
+	if ($element == 'a')
306 306
 	{
307 307
 		//error_log(__METHOD__.__LINE__.array2string($attribute_array));
308 308
 		// rebuild Anchors, if processed by hl_email_tag_transform
309
-		if (strpos($attribute_array['href'],"denied:javascript:GoToAnchor('")===0)
309
+		if (strpos($attribute_array['href'], "denied:javascript:GoToAnchor('") === 0)
310 310
 		{
311
-			$attribute_array['href']=str_ireplace("');",'',str_ireplace("denied:javascript:GoToAnchor('","#",$attribute_array['href']));
311
+			$attribute_array['href'] = str_ireplace("');", '', str_ireplace("denied:javascript:GoToAnchor('", "#", $attribute_array['href']));
312 312
 		}
313
-		if (strpos($attribute_array['href'],"javascript:GoToAnchor('")===0)
313
+		if (strpos($attribute_array['href'], "javascript:GoToAnchor('") === 0)
314 314
 		{
315
-			$attribute_array['href']=str_ireplace("');",'',str_ireplace("javascript:GoToAnchor('","#",$attribute_array['href']));
315
+			$attribute_array['href'] = str_ireplace("');", '', str_ireplace("javascript:GoToAnchor('", "#", $attribute_array['href']));
316 316
 		}
317
-		if (strpos($attribute_array['href'],'denied:javascript')===0) $attribute_array['href']='';
317
+		if (strpos($attribute_array['href'], 'denied:javascript') === 0) $attribute_array['href'] = '';
318 318
 	}
319 319
 
320 320
 	// Build the attributes string
321 321
 	$attributes = '';
322
-	foreach($attribute_array as $k=>$v){
322
+	foreach ($attribute_array as $k=>$v) {
323 323
 		$attributes .= " {$k}=\"{$v}\"";
324 324
 	}
325 325
 
326 326
 	// Return the opening tag with attributes
327 327
 	static $empty_elements = array('area'=>1, 'br'=>1, 'col'=>1, 'embed'=>1, 'hr'=>1, 'img'=>1, 'input'=>1, 'isindex'=>1, 'param'=>1);
328
-	return "<{$element}{$attributes}". (isset($empty_elements[$element]) ? ' /' : ''). '>';
328
+	return "<{$element}{$attributes}".(isset($empty_elements[$element]) ? ' /' : '').'>';
329 329
 }
330 330
 
331 331
 /**
@@ -339,22 +339,22 @@  discard block
 block discarded – undo
339 339
  * 						blockquote -checking for cite, replacing @
340 340
  * 						throwing away excess div elements, that carry no style or class or id info
341 341
  */
342
-function hl_email_tag_transform($element, $attribute_array=0)
342
+function hl_email_tag_transform($element, $attribute_array = 0)
343 343
 {
344 344
 	//error_log(__METHOD__.__LINE__.$element.'=>'.array2string($attribute_array));
345 345
 	static $lastelement = null;
346 346
 	static $throwawaycounter = null;
347
-	if (is_null($lastelement)) $lastelement='';
347
+	if (is_null($lastelement)) $lastelement = '';
348 348
 	if (is_null($throwawaycounter)) $throwawaycounter = 0;
349 349
 	//if ($throwawaycounter>1) error_log(__METHOD__.__LINE__.' '.$throwawaycounter.$element.array2string($attribute_array));
350
-	if ($element=='div' && $element==$lastelement && ($attribute_array==0 || empty($attribute_array)))
350
+	if ($element == 'div' && $element == $lastelement && ($attribute_array == 0 || empty($attribute_array)))
351 351
 	{
352 352
 		if (is_array($attribute_array)) $throwawaycounter++;
353
-		if ($attribute_array==0 && $throwawaycounter>0) $throwawaycounter--;
354
-		if ($throwawaycounter>1) return '';
353
+		if ($attribute_array == 0 && $throwawaycounter > 0) $throwawaycounter--;
354
+		if ($throwawaycounter > 1) return '';
355 355
 	}
356
-	if ($lastelement=='div' && $element!=$lastelement && is_array($attribute_array)) $throwawaycounter = 0;
357
-	if (is_array($attribute_array) && !empty($attribute_array) && $element=='div')
356
+	if ($lastelement == 'div' && $element != $lastelement && is_array($attribute_array)) $throwawaycounter = 0;
357
+	if (is_array($attribute_array) && !empty($attribute_array) && $element == 'div')
358 358
 	{
359 359
 		$lastelement = 'div_with_attr';
360 360
 	}
@@ -363,15 +363,15 @@  discard block
 block discarded – undo
363 363
 		if (is_array($attribute_array)) $lastelement = $element;
364 364
 	}
365 365
 	// If second argument is not received, it means a closing tag is being handled
366
-	if(is_numeric($attribute_array)){
367
-		if($element==$lastelement) $lastelement='';
366
+	if (is_numeric($attribute_array)) {
367
+		if ($element == $lastelement) $lastelement = '';
368 368
 		return "</$element>";
369 369
 	}
370 370
 
371 371
 	//if ($element=='a') error_log(__METHOD__.__LINE__." ".$element.'->'.array2string($attribute_array));
372
-	if ($element=='td' && isset($attribute_array['background']))
372
+	if ($element == 'td' && isset($attribute_array['background']))
373 373
 	{
374
-		if (stripos($attribute_array['background'],'cid:')!==false)
374
+		if (stripos($attribute_array['background'], 'cid:') !== false)
375 375
 		{
376 376
 			//error_log(__METHOD__.__LINE__.array2string($attribute_array));
377 377
 			//$attribute_array['background'] = 'url('.$attribute_array['background'].');';
@@ -379,82 +379,81 @@  discard block
 block discarded – undo
379 379
 		else
380 380
 		{
381 381
 			// $attribute_array['background']='denied:'.$attribute_array['background'];
382
-			unset($attribute_array['background']);// only cid style background images are allowed
382
+			unset($attribute_array['background']); // only cid style background images are allowed
383 383
 		}
384 384
 	}
385 385
 	// Elements other than 'img' or 'img' without a 'img' attribute are returned unchanged
386
-	if($element == 'img')
386
+	if ($element == 'img')
387 387
 	{
388 388
 		// Re-build 'alt'
389
-		if (isset($attribute_array['alt'])) $attribute_array['alt'] = ($attribute_array['alt']=='image'?'':$attribute_array['alt']);
390
-		if (isset($attribute_array['alt'])&&strpos($attribute_array['alt'],'@')!==false) $attribute_array['alt']=str_replace('@','(at)',$attribute_array['alt']);
389
+		if (isset($attribute_array['alt'])) $attribute_array['alt'] = ($attribute_array['alt'] == 'image' ? '' : $attribute_array['alt']);
390
+		if (isset($attribute_array['alt']) && strpos($attribute_array['alt'], '@') !== false) $attribute_array['alt'] = str_replace('@', '(at)', $attribute_array['alt']);
391 391
 		// $GLOBALS['egw_info']['user']['preferences']['mail']['allowExternalIMGs'] ? '' : 'match' => '/^cid:.*/'),
392 392
 		if (isset($attribute_array['src']))
393 393
 		{
394
-			if (!(strlen($attribute_array['src'])>4 && strlen($attribute_array['src']<400)))
394
+			if (!(strlen($attribute_array['src']) > 4 && strlen($attribute_array['src'] < 400)))
395 395
 			{
396
-					$attribute_array['alt']= $attribute_array['alt'].' [blocked (reason: url length):'.$attribute_array['src'].']';
397
-					if (!isset($attribute_array['title'])) $attribute_array['title']=$attribute_array['alt'];
398
-					$attribute_array['src']=Api\Image::find('api','error');
396
+					$attribute_array['alt'] = $attribute_array['alt'].' [blocked (reason: url length):'.$attribute_array['src'].']';
397
+					if (!isset($attribute_array['title'])) $attribute_array['title'] = $attribute_array['alt'];
398
+					$attribute_array['src'] = Api\Image::find('api', 'error');
399 399
 			}
400
-			if (!preg_match('/^cid:.*/',$attribute_array['src']))
400
+			if (!preg_match('/^cid:.*/', $attribute_array['src']))
401 401
 			{
402
-				$url = explode('/', preg_replace('/^(http|https):\/\//','',$attribute_array['src']));
402
+				$url = explode('/', preg_replace('/^(http|https):\/\//', '', $attribute_array['src']));
403 403
 				$domains = is_array($GLOBALS['egw_info']['user']['preferences']['mail']['allowExternalDomains']) ?
404
-						$GLOBALS['egw_info']['user']['preferences']['mail']['allowExternalDomains'] :
405
-						array();
404
+						$GLOBALS['egw_info']['user']['preferences']['mail']['allowExternalDomains'] : array();
406 405
 				if ($GLOBALS['egw_info']['user']['preferences']['mail']['allowExternalIMGs'] != 1
407 406
 						&& !in_array($url[0], $domains))
408 407
 				{
409 408
 					//the own webserver url is not external, so it should be allowed
410
-					if (empty($GLOBALS['egw_info']['server']['webserver_url'])||!preg_match("$^".$GLOBALS['egw_info']['server']['webserver_url'].".*$",$attribute_array['src']))
409
+					if (empty($GLOBALS['egw_info']['server']['webserver_url']) || !preg_match("$^".$GLOBALS['egw_info']['server']['webserver_url'].".*$", $attribute_array['src']))
411 410
 					{
412
-						$attribute_array['alt']= $attribute_array['alt'].' [blocked external image:'.$attribute_array['src'].']';
413
-						if (!isset($attribute_array['title'])) $attribute_array['title']=$attribute_array['alt'];
414
-						$attribute_array['src']=Api\Image::find('mail','no-image-shown');
411
+						$attribute_array['alt'] = $attribute_array['alt'].' [blocked external image:'.$attribute_array['src'].']';
412
+						if (!isset($attribute_array['title'])) $attribute_array['title'] = $attribute_array['alt'];
413
+						$attribute_array['src'] = Api\Image::find('mail', 'no-image-shown');
415 414
 						$attribute_array['border'] = 1;
416 415
 						if ($attribute_array['style'])
417 416
 						{
418
-							if (stripos($attribute_array['style'],'border')!==false) $attribute_array['style'] = preg_replace('~border(:|-left:|-right:|-bottom:|-top:)+ (0px)+ (none)+;~si','',$attribute_array['style']);
417
+							if (stripos($attribute_array['style'], 'border') !== false) $attribute_array['style'] = preg_replace('~border(:|-left:|-right:|-bottom:|-top:)+ (0px)+ (none)+;~si', '', $attribute_array['style']);
419 418
 						}
420 419
 					}
421 420
 				}
422 421
 			}
423 422
 		}
424 423
 	}
425
-	if (isset($attribute_array['style']) && stripos($attribute_array['style'],'script')!==false) $attribute_array['style'] = str_ireplace('script','',$attribute_array['style']);
424
+	if (isset($attribute_array['style']) && stripos($attribute_array['style'], 'script') !== false) $attribute_array['style'] = str_ireplace('script', '', $attribute_array['style']);
426 425
 	if (isset($attribute_array['title']))
427 426
 	{
428
-		if (strpos($attribute_array['title'],'@')!==false) $attribute_array['title']=str_replace('@','(at)',$attribute_array['title']);
427
+		if (strpos($attribute_array['title'], '@') !== false) $attribute_array['title'] = str_replace('@', '(at)', $attribute_array['title']);
429 428
 	}
430 429
 	if ($element == 'blockquote')
431 430
 	{
432 431
 		if (isset($attribute_array['cite']))
433 432
 		{
434
-			if (strpos($attribute_array['cite'],'@')!==false) $attribute_array['cite']=str_replace('@','(at)',$attribute_array['cite']);
433
+			if (strpos($attribute_array['cite'], '@') !== false) $attribute_array['cite'] = str_replace('@', '(at)', $attribute_array['cite']);
435 434
 		}
436 435
 	}
437
-	if($element == 'a')
436
+	if ($element == 'a')
438 437
 	{
439 438
 		//error_log(__METHOD__.__LINE__.array2string($attribute_array));
440
-		if (strpos($attribute_array['href'],'denied:javascript')===0) $attribute_array['href']='';
439
+		if (strpos($attribute_array['href'], 'denied:javascript') === 0) $attribute_array['href'] = '';
441 440
 		if (isset($attribute_array['name']) && isset($attribute_array['id'])) $attribute_array['id'] = $attribute_array['name'];
442
-		if (strpos($attribute_array['href'],'@')!==false) $attribute_array['href'] = str_replace('@','%40',$attribute_array['href']);
443
-		if (strpos($attribute_array['href'],'#')===0 && (isset(Api\Mail::$htmLawed_config['transform_anchor']) && Api\Mail::$htmLawed_config['transform_anchor']===true))
441
+		if (strpos($attribute_array['href'], '@') !== false) $attribute_array['href'] = str_replace('@', '%40', $attribute_array['href']);
442
+		if (strpos($attribute_array['href'], '#') === 0 && (isset(Api\Mail::$htmLawed_config['transform_anchor']) && Api\Mail::$htmLawed_config['transform_anchor'] === true))
444 443
 		{
445
-			$attribute_array['href'] = "javascript:GoToAnchor('".trim(substr($attribute_array['href'],1))."');";
444
+			$attribute_array['href'] = "javascript:GoToAnchor('".trim(substr($attribute_array['href'], 1))."');";
446 445
 		}
447 446
 
448 447
 	}
449 448
 
450 449
 	// Build the attributes string
451 450
 	$attributes = '';
452
-	foreach($attribute_array as $k=>$v){
451
+	foreach ($attribute_array as $k=>$v) {
453 452
 		$attributes .= " {$k}=\"{$v}\"";
454 453
 	}
455 454
 
456 455
 	// Return the opening tag with attributes
457 456
 	static $empty_elements = array('area'=>1, 'br'=>1, 'col'=>1, 'embed'=>1, 'hr'=>1, 'img'=>1, 'input'=>1, 'isindex'=>1, 'param'=>1);
458
-	return "<{$element}{$attributes}". (isset($empty_elements[$element]) ? ' /' : ''). '>';
457
+	return "<{$element}{$attributes}".(isset($empty_elements[$element]) ? ' /' : '').'>';
459 458
 }
460 459
 
Please login to merge, or discard this patch.
api/src/Html/htmLawed/htmLawed.php 4 patches
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -625,6 +625,10 @@
 block discarded – undo
625 625
 // eof
626 626
 }
627 627
 
628
+/**
629
+ * @param string $e
630
+ * @param string $a
631
+ */
628 632
 function hl_tag2(&$e, &$a, $t=1){
629 633
 // transform tag
630 634
 if($e == 'center'){$e = 'div'; return 'text-align: center;';}
Please login to merge, or discard this patch.
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -132,13 +132,13 @@  discard block
 block discarded – undo
132 132
    break; case 'match': if(!preg_match($v, $tv)){$o = 0;}
133 133
    break; case 'nomatch': if(preg_match($v, $tv)){$o = 0;}
134 134
    break; case 'oneof':
135
-    $m = 0;
136
-    foreach(explode('|', $v) as $n){if($tv == $n){$m = 1; break;}}
137
-    $o = $m;
135
+	$m = 0;
136
+	foreach(explode('|', $v) as $n){if($tv == $n){$m = 1; break;}}
137
+	$o = $m;
138 138
    break; case 'noneof':
139
-    $m = 1;
140
-    foreach(explode('|', $v) as $n){if($tv == $n){$m = 0; break;}}
141
-    $o = $m;
139
+	$m = 1;
140
+	foreach(explode('|', $v) as $n){if($tv == $n){$m = 0; break;}}
141
+	$o = $m;
142 142
    break; default:
143 143
    break;
144 144
   }
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
   elseif($do < 3 or isset($ok['#pcdata'])){echo $x;}
213 213
   elseif(strpos($x, "\x02\x04")){
214 214
    foreach(preg_split('`(\x01\x02[^\x01\x02]+\x02\x01)`', $x, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY) as $v){
215
-    echo (substr($v, 0, 2) == "\x01\x02" ? $v : ($do > 4 ? preg_replace('`\S`', '', $v) : ''));
215
+	echo (substr($v, 0, 2) == "\x01\x02" ? $v : ($do > 4 ? preg_replace('`\S`', '', $v) : ''));
216 216
    }
217 217
   }elseif($do > 4){echo preg_replace('`\S`', '', $x);}
218 218
  }
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
    preg_match('`^([a-zA-Z\d\-+.]+://[^/]+)(.*)`', $C['base_url'], $m);
366 366
    $p = preg_replace('`(?<=/)\./`', '', $m[2]. $p);
367 367
    while(preg_match('`(?<=/)([^/]{3,}|[^/.]+?|\.[^/.]|[^/.]\.)/\.\./`', $p)){
368
-    $p = preg_replace('`(?<=/)([^/]{3,}|[^/.]+?|\.[^/.]|[^/.]\.)/\.\./`', '', $p);
368
+	$p = preg_replace('`(?<=/)([^/]{3,}|[^/.]+?|\.[^/.]|[^/.]\.)/\.\./`', '', $p);
369 369
    }
370 370
    $p = $m[1]. $p;
371 371
   }
@@ -478,20 +478,20 @@  discard block
 block discarded – undo
478 478
  switch($mode){
479 479
   case 0: // Name
480 480
    if(preg_match('`^[a-zA-Z][\-a-zA-Z:]+`', $a, $m)){
481
-    $nm = strtolower($m[0]);
482
-    $w = $mode = 1; $a = ltrim(substr_replace($a, '', 0, strlen($m[0])));
481
+	$nm = strtolower($m[0]);
482
+	$w = $mode = 1; $a = ltrim(substr_replace($a, '', 0, strlen($m[0])));
483 483
    }
484 484
   break; case 1:
485 485
    if($a[0] == '='){ // =
486
-    $w = 1; $mode = 2; $a = ltrim($a, '= ');
486
+	$w = 1; $mode = 2; $a = ltrim($a, '= ');
487 487
    }else{ // No val
488
-    $w = 1; $mode = 0; $a = ltrim($a);
489
-    $aA[$nm] = '';
488
+	$w = 1; $mode = 0; $a = ltrim($a);
489
+	$aA[$nm] = '';
490 490
    }
491 491
   break; case 2: // Val
492 492
    if(preg_match('`^((?:"[^"]*")|(?:\'[^\']*\')|(?:\s*[^\s"\']+))(.*)`', $a, $m)){
493
-    $a = ltrim($m[2]); $m = $m[1]; $w = 1; $mode = 0;
494
-    $aA[$nm] = trim(str_replace('<', '&lt;', ($m[0] == '"' or $m[0] == '\'') ? substr($m, 1, -1) : $m));
493
+	$a = ltrim($m[2]); $m = $m[1]; $w = 1; $mode = 0;
494
+	$aA[$nm] = trim(str_replace('<', '&lt;', ($m[0] == '"' or $m[0] == '\'') ? substr($m, 1, -1) : $m));
495 495
    }
496 496
   break;
497 497
  }
@@ -514,8 +514,8 @@  discard block
 block discarded – undo
514 514
   }
515 515
   if($k == 'style' && !$C['style_pass']){
516 516
    if(false !== strpos($v, '&#')){
517
-    static $sC = array('&#x20;'=>' ', '&#32;'=>' ', '&#x45;'=>'e', '&#69;'=>'e', '&#x65;'=>'e', '&#101;'=>'e', '&#x58;'=>'x', '&#88;'=>'x', '&#x78;'=>'x', '&#120;'=>'x', '&#x50;'=>'p', '&#80;'=>'p', '&#x70;'=>'p', '&#112;'=>'p', '&#x53;'=>'s', '&#83;'=>'s', '&#x73;'=>'s', '&#115;'=>'s', '&#x49;'=>'i', '&#73;'=>'i', '&#x69;'=>'i', '&#105;'=>'i', '&#x4f;'=>'o', '&#79;'=>'o', '&#x6f;'=>'o', '&#111;'=>'o', '&#x4e;'=>'n', '&#78;'=>'n', '&#x6e;'=>'n', '&#110;'=>'n', '&#x55;'=>'u', '&#85;'=>'u', '&#x75;'=>'u', '&#117;'=>'u', '&#x52;'=>'r', '&#82;'=>'r', '&#x72;'=>'r', '&#114;'=>'r', '&#x4c;'=>'l', '&#76;'=>'l', '&#x6c;'=>'l', '&#108;'=>'l', '&#x28;'=>'(', '&#40;'=>'(', '&#x29;'=>')', '&#41;'=>')', '&#x20;'=>':', '&#32;'=>':', '&#x22;'=>'"', '&#34;'=>'"', '&#x27;'=>"'", '&#39;'=>"'", '&#x2f;'=>'/', '&#47;'=>'/', '&#x2a;'=>'*', '&#42;'=>'*', '&#x5c;'=>'\\', '&#92;'=>'\\');
518
-    $v = strtr($v, $sC);
517
+	static $sC = array('&#x20;'=>' ', '&#32;'=>' ', '&#x45;'=>'e', '&#69;'=>'e', '&#x65;'=>'e', '&#101;'=>'e', '&#x58;'=>'x', '&#88;'=>'x', '&#x78;'=>'x', '&#120;'=>'x', '&#x50;'=>'p', '&#80;'=>'p', '&#x70;'=>'p', '&#112;'=>'p', '&#x53;'=>'s', '&#83;'=>'s', '&#x73;'=>'s', '&#115;'=>'s', '&#x49;'=>'i', '&#73;'=>'i', '&#x69;'=>'i', '&#105;'=>'i', '&#x4f;'=>'o', '&#79;'=>'o', '&#x6f;'=>'o', '&#111;'=>'o', '&#x4e;'=>'n', '&#78;'=>'n', '&#x6e;'=>'n', '&#110;'=>'n', '&#x55;'=>'u', '&#85;'=>'u', '&#x75;'=>'u', '&#117;'=>'u', '&#x52;'=>'r', '&#82;'=>'r', '&#x72;'=>'r', '&#114;'=>'r', '&#x4c;'=>'l', '&#76;'=>'l', '&#x6c;'=>'l', '&#108;'=>'l', '&#x28;'=>'(', '&#40;'=>'(', '&#x29;'=>')', '&#41;'=>')', '&#x20;'=>':', '&#32;'=>':', '&#x22;'=>'"', '&#34;'=>'"', '&#x27;'=>"'", '&#39;'=>"'", '&#x2f;'=>'/', '&#47;'=>'/', '&#x2a;'=>'*', '&#42;'=>'*', '&#x5c;'=>'\\', '&#92;'=>'\\');
518
+	$v = strtr($v, $sC);
519 519
    }
520 520
    $v = preg_replace_callback('`(url(?:\()(?: )*(?:\'|"|&(?:quot|apos);)?)(.+?)((?:\'|"|&(?:quot|apos);)?(?: )*(?:\)))`iS', 'hl_prot', $v);
521 521
    $v = !$C['css_expression'] ? preg_replace('`expression`i', ' ', preg_replace('`\\\\\S|(/|(%2f))(\*|(%2a))`i', ' ', $v)) : $v;
@@ -523,20 +523,20 @@  discard block
 block discarded – undo
523 523
    $v = str_replace("­", ' ', (strpos($v, '&') !== false ? str_replace(array('&#xad;', '&#173;', '&shy;'), ' ', $v) : $v)); # double-quoted char is soft-hyphen; appears here as "­" or hyphen or something else depending on viewing software
524 524
    $v = hl_prot($v, $k);
525 525
    if($k == 'href'){ // X-spam
526
-    if($C['anti_mail_spam'] && strpos($v, 'mailto:') === 0){
527
-     $v = str_replace('@', htmlspecialchars($C['anti_mail_spam']), $v);
528
-    }elseif($C['anti_link_spam']){
529
-     $r1 = $C['anti_link_spam'][1];
530
-     if(!empty($r1) && preg_match($r1, $v)){continue;}
531
-     $r0 = $C['anti_link_spam'][0];
532
-     if(!empty($r0) && preg_match($r0, $v)){
533
-      if(isset($a['rel'])){
534
-       if(!preg_match('`\bnofollow\b`i', $a['rel'])){$a['rel'] .= ' nofollow';}
535
-      }elseif(isset($aA['rel'])){
536
-       if(!preg_match('`\bnofollow\b`i', $aA['rel'])){$nfr = 1;}
537
-      }else{$a['rel'] = 'nofollow';}
538
-     }
539
-    }
526
+	if($C['anti_mail_spam'] && strpos($v, 'mailto:') === 0){
527
+	 $v = str_replace('@', htmlspecialchars($C['anti_mail_spam']), $v);
528
+	}elseif($C['anti_link_spam']){
529
+	 $r1 = $C['anti_link_spam'][1];
530
+	 if(!empty($r1) && preg_match($r1, $v)){continue;}
531
+	 $r0 = $C['anti_link_spam'][0];
532
+	 if(!empty($r0) && preg_match($r0, $v)){
533
+	  if(isset($a['rel'])){
534
+	   if(!preg_match('`\bnofollow\b`i', $a['rel'])){$a['rel'] .= ' nofollow';}
535
+	  }elseif(isset($aA['rel'])){
536
+	   if(!preg_match('`\bnofollow\b`i', $aA['rel'])){$nfr = 1;}
537
+	  }else{$a['rel'] = 'nofollow';}
538
+	 }
539
+	}
540 540
    }
541 541
   }
542 542
   if(isset($rl[$k]) && is_array($rl[$k]) && ($v = hl_attrval($k, $v, $rl[$k])) === 0){continue;}
@@ -685,8 +685,8 @@  discard block
 block discarded – undo
685 685
   $e = "<$e>";
686 686
   if(isset($d[$y])){
687 687
    if(!$x){
688
-    if($n){echo "\n", str_repeat($s, --$n), "$e\n", str_repeat($s, $n);}
689
-    else{++$N; ob_end_clean(); continue 2;}
688
+	if($n){echo "\n", str_repeat($s, --$n), "$e\n", str_repeat($s, $n);}
689
+	else{++$N; ob_end_clean(); continue 2;}
690 690
    }
691 691
    else{echo "\n", str_repeat($s, $n), "$e\n", str_repeat($s, ($x != 1 ? ++$n : $n));}
692 692
    echo $r; continue;
Please login to merge, or discard this patch.
Braces   +706 added lines, -262 removed lines patch added patch discarded remove patch
@@ -9,28 +9,44 @@  discard block
 block discarded – undo
9 9
 See htmLawed_README.txt/htm
10 10
 */
11 11
 
12
-function htmLawed($t, $C=1, $S=array()){
12
+function htmLawed($t, $C=1, $S=array())
13
+{
13 14
 $C = is_array($C) ? $C : array();
14
-if(!empty($C['valid_xhtml'])){
15
+if(!empty($C['valid_xhtml']))
16
+{
15 17
  $C['elements'] = empty($C['elements']) ? '*-center-dir-font-isindex-menu-s-strike-u' : $C['elements'];
16 18
  $C['make_tag_strict'] = isset($C['make_tag_strict']) ? $C['make_tag_strict'] : 2;
17 19
  $C['xml:lang'] = isset($C['xml:lang']) ? $C['xml:lang'] : 2;
18 20
 }
19 21
 // config eles
20 22
 $e = array('a'=>1, 'abbr'=>1, 'acronym'=>1, 'address'=>1, 'applet'=>1, 'area'=>1, 'b'=>1, 'bdo'=>1, 'big'=>1, 'blockquote'=>1, 'br'=>1, 'button'=>1, 'caption'=>1, 'center'=>1, 'cite'=>1, 'code'=>1, 'col'=>1, 'colgroup'=>1, 'dd'=>1, 'del'=>1, 'dfn'=>1, 'dir'=>1, 'div'=>1, 'dl'=>1, 'dt'=>1, 'em'=>1, 'embed'=>1, 'fieldset'=>1, 'font'=>1, 'form'=>1, 'h1'=>1, 'h2'=>1, 'h3'=>1, 'h4'=>1, 'h5'=>1, 'h6'=>1, 'hr'=>1, 'i'=>1, 'iframe'=>1, 'img'=>1, 'input'=>1, 'ins'=>1, 'isindex'=>1, 'kbd'=>1, 'label'=>1, 'legend'=>1, 'li'=>1, 'map'=>1, 'menu'=>1, 'noscript'=>1, 'object'=>1, 'ol'=>1, 'optgroup'=>1, 'option'=>1, 'p'=>1, 'param'=>1, 'pre'=>1, 'q'=>1, 'rb'=>1, 'rbc'=>1, 'rp'=>1, 'rt'=>1, 'rtc'=>1, 'ruby'=>1, 's'=>1, 'samp'=>1, 'script'=>1, 'select'=>1, 'small'=>1, 'span'=>1, 'strike'=>1, 'strong'=>1, 'sub'=>1, 'sup'=>1, 'table'=>1, 'tbody'=>1, 'td'=>1, 'textarea'=>1, 'tfoot'=>1, 'th'=>1, 'thead'=>1, 'tr'=>1, 'tt'=>1, 'u'=>1, 'ul'=>1, 'var'=>1); // 86/deprecated+embed+ruby
21
-if(!empty($C['safe'])){
23
+if(!empty($C['safe']))
24
+{
22 25
  unset($e['applet'], $e['embed'], $e['iframe'], $e['object'], $e['script']);
23 26
 }
24 27
 $x = !empty($C['elements']) ? str_replace(array("\n", "\r", "\t", ' '), '', $C['elements']) : '*';
25
-if($x == '-*'){$e = array();}
26
-elseif(strpos($x, '*') === false){$e = array_flip(explode(',', $x));}
27
-else{
28
- if(isset($x[1])){
28
+if($x == '-*')
29
+{
30
+$e = array();}
31
+elseif(strpos($x, '*') === false)
32
+{
33
+$e = array_flip(explode(',', $x));}
34
+else
35
+{
36
+ if(isset($x[1]))
37
+ {
29 38
   preg_match_all('`(?:^|-|\+)[^\-+]+?(?=-|\+|$)`', $x, $m, PREG_SET_ORDER);
30
-  for($i=count($m); --$i>=0;){$m[$i] = $m[$i][0];}
31
-  foreach($m as $v){
32
-   if($v[0] == '+'){$e[substr($v, 1)] = 1;}
33
-   if($v[0] == '-' && isset($e[($v = substr($v, 1))]) && !in_array('+'. $v, $m)){unset($e[$v]);}
39
+  for($i=count($m); --$i>=0;)
40
+  {
41
+$m[$i] = $m[$i][0];}
42
+  foreach($m as $v)
43
+  {
44
+   if($v[0] == '+')
45
+   {
46
+$e[substr($v, 1)] = 1;}
47
+   if($v[0] == '-' && isset($e[($v = substr($v, 1))]) && !in_array('+'. $v, $m))
48
+   {
49
+unset($e[$v]);}
34 50
   }
35 51
  }
36 52
 }
@@ -38,7 +54,8 @@  discard block
 block discarded – undo
38 54
 // config attrs
39 55
 $x = !empty($C['deny_attribute']) ? str_replace(array("\n", "\r", "\t", ' '), '', $C['deny_attribute']) : '';
40 56
 $x = array_flip((isset($x[0]) && $x[0] == '*') ? explode('-', $x) : explode(',', $x. (!empty($C['safe']) ? ',on*' : '')));
41
-if(isset($x['on*'])){
57
+if(isset($x['on*']))
58
+{
42 59
  unset($x['on*']);
43 60
  $x += array('onblur'=>1, 'onchange'=>1, 'onclick'=>1, 'ondblclick'=>1, 'onfocus'=>1, 'onkeydown'=>1, 'onkeypress'=>1, 'onkeyup'=>1, 'onmousedown'=>1, 'onmousemove'=>1, 'onmouseout'=>1, 'onmouseover'=>1, 'onmouseup'=>1, 'onreset'=>1, 'onselect'=>1, 'onsubmit'=>1);
44 61
 }
@@ -46,14 +63,22 @@  discard block
 block discarded – undo
46 63
 // config URL
47 64
 $x = (isset($C['schemes'][2]) && strpos($C['schemes'], ':')) ? strtolower($C['schemes']) : 'href: aim, feed, file, ftp, gopher, http, https, irc, mailto, news, nntp, sftp, ssh, telnet; *:file, http, https';
48 65
 $C['schemes'] = array();
49
-foreach(explode(';', str_replace(array(' ', "\t", "\r", "\n"), '', $x)) as $v){
66
+foreach(explode(';', str_replace(array(' ', "\t", "\r", "\n"), '', $x)) as $v)
67
+{
50 68
  $x = $x2 = null; list($x, $x2) = explode(':', $v, 2);
51
- if($x2){$C['schemes'][$x] = array_flip(explode(',', $x2));}
69
+ if($x2)
70
+ {
71
+$C['schemes'][$x] = array_flip(explode(',', $x2));}
52 72
 }
53
-if(!isset($C['schemes']['*'])){$C['schemes']['*'] = array('file'=>1, 'http'=>1, 'https'=>1,);}
54
-if(!empty($C['safe']) && empty($C['schemes']['style'])){$C['schemes']['style'] = array('!'=>1);}
73
+if(!isset($C['schemes']['*']))
74
+{
75
+$C['schemes']['*'] = array('file'=>1, 'http'=>1, 'https'=>1,);}
76
+if(!empty($C['safe']) && empty($C['schemes']['style']))
77
+{
78
+$C['schemes']['style'] = array('!'=>1);}
55 79
 $C['abs_url'] = isset($C['abs_url']) ? $C['abs_url'] : 0;
56
-if(!isset($C['base_url']) or !preg_match('`^[a-zA-Z\d.+\-]+://[^/]+/(.+?/)?$`', $C['base_url'])){
80
+if(!isset($C['base_url']) or !preg_match('`^[a-zA-Z\d.+\-]+://[^/]+/(.+?/)?$`', $C['base_url']))
81
+{
57 82
  $C['base_url'] = $C['abs_url'] = 0;
58 83
 }
59 84
 // config rest
@@ -84,23 +109,35 @@  discard block
 block discarded – undo
84 109
 // block elements allowed for nesting when only inline is allowed; Example span does not allow block elements as table; table is the only element tested so far
85 110
 $C['allow_for_inline'] = isset($C['allow_for_inline'])?$C['allow_for_inline']:0;
86 111
 
87
-if(isset($GLOBALS['C'])){$reC = $GLOBALS['C'];}
112
+if(isset($GLOBALS['C']))
113
+{
114
+$reC = $GLOBALS['C'];}
88 115
 $GLOBALS['C'] = $C;
89 116
 $S = is_array($S) ? $S : hl_spec($S);
90
-if(isset($GLOBALS['S'])){$reS = $GLOBALS['S'];}
117
+if(isset($GLOBALS['S']))
118
+{
119
+$reS = $GLOBALS['S'];}
91 120
 $GLOBALS['S'] = $S;
92 121
 
93 122
 $t = preg_replace('`[\x00-\x08\x0b-\x0c\x0e-\x1f]`', '', $t);
94
-if($C['clean_ms_char']){
123
+if($C['clean_ms_char'])
124
+{
95 125
  $x = array("\x7f"=>'', "\x80"=>'&#8364;', "\x81"=>'', "\x83"=>'&#402;', "\x85"=>'&#8230;', "\x86"=>'&#8224;', "\x87"=>'&#8225;', "\x88"=>'&#710;', "\x89"=>'&#8240;', "\x8a"=>'&#352;', "\x8b"=>'&#8249;', "\x8c"=>'&#338;', "\x8d"=>'', "\x8e"=>'&#381;', "\x8f"=>'', "\x90"=>'', "\x95"=>'&#8226;', "\x96"=>'&#8211;', "\x97"=>'&#8212;', "\x98"=>'&#732;', "\x99"=>'&#8482;', "\x9a"=>'&#353;', "\x9b"=>'&#8250;', "\x9c"=>'&#339;', "\x9d"=>'', "\x9e"=>'&#382;', "\x9f"=>'&#376;');
96 126
  $x = $x + ($C['clean_ms_char'] == 1 ? array("\x82"=>'&#8218;', "\x84"=>'&#8222;', "\x91"=>'&#8216;', "\x92"=>'&#8217;', "\x93"=>'&#8220;', "\x94"=>'&#8221;') : array("\x82"=>'\'', "\x84"=>'"', "\x91"=>'\'', "\x92"=>'\'', "\x93"=>'"', "\x94"=>'"'));
97 127
  $t = strtr($t, $x);
98 128
 }
99
-if($C['cdata'] or $C['comment']){$t = preg_replace_callback('`<!(?:(?:--.*?--)|(?:\[CDATA\[.*?\]\]))>`sm', 'hl_cmtcd', $t);}
129
+if($C['cdata'] or $C['comment'])
130
+{
131
+$t = preg_replace_callback('`<!(?:(?:--.*?--)|(?:\[CDATA\[.*?\]\]))>`sm', 'hl_cmtcd', $t);}
100 132
 $t = preg_replace_callback('`&amp;([A-Za-z][A-Za-z0-9]{1,30}|#(?:[0-9]{1,8}|[Xx][0-9A-Fa-f]{1,7}));`', 'hl_ent', str_replace('&', '&amp;', $t));
101
-if($C['unique_ids'] && !isset($GLOBALS['hl_Ids'])){$GLOBALS['hl_Ids'] = array();}
102
-if($C['hook']){$t = $C['hook']($t, $C, $S);}
103
-if($C['show_setting'] && preg_match('`^[a-z][a-z0-9_]*$`i', $C['show_setting'])){
133
+if($C['unique_ids'] && !isset($GLOBALS['hl_Ids']))
134
+{
135
+$GLOBALS['hl_Ids'] = array();}
136
+if($C['hook'])
137
+{
138
+$t = $C['hook']($t, $C, $S);}
139
+if($C['show_setting'] && preg_match('`^[a-z][a-z0-9_]*$`i', $C['show_setting']))
140
+{
104 141
  $GLOBALS[$C['show_setting']] = array('config'=>$C, 'spec'=>$S, 'time'=>microtime());
105 142
 }
106 143
 // main
@@ -109,49 +146,82 @@  discard block
 block discarded – undo
109 146
 $t = (($C['cdata'] or $C['comment']) && strpos($t, "\x01") !== false) ? str_replace(array("\x01", "\x02", "\x03", "\x04", "\x05"), array('', '', '&', '<', '>'), $t) : $t;
110 147
 $t = $C['tidy'] ? hl_tidy($t, $C['tidy'], $C['parent']) : $t;
111 148
 unset($C, $e);
112
-if(isset($reC)){$GLOBALS['C'] = $reC;}
113
-if(isset($reS)){$GLOBALS['S'] = $reS;}
149
+if(isset($reC))
150
+{
151
+$GLOBALS['C'] = $reC;}
152
+if(isset($reS))
153
+{
154
+$GLOBALS['S'] = $reS;}
114 155
 return $t;
115 156
 // eof
116 157
 }
117 158
 
118
-function hl_attrval($a, $t, $p){
159
+function hl_attrval($a, $t, $p)
160
+{
119 161
 // check attr val against $S
120 162
 static $ma = array('accesskey', 'class', 'rel');
121 163
 $s = in_array($a, $ma) ? ' ' : '';
122 164
 $r = array();
123 165
 $t = !empty($s) ? explode($s, $t) : array($t);
124
-foreach($t as $tk=>$tv){
166
+foreach($t as $tk=>$tv)
167
+{
125 168
  $o = 1; $l = strlen($tv);
126
- foreach($p as $k=>$v){
127
-  switch($k){
128
-   case 'maxlen': if($l > $v){$o = 0;}
129
-   break; case 'minlen': if($l < $v){$o = 0;}
130
-   break; case 'maxval': if((float)($tv) > $v){$o = 0;}
131
-   break; case 'minval': if((float)($tv) < $v){$o = 0;}
132
-   break; case 'match': if(!preg_match($v, $tv)){$o = 0;}
133
-   break; case 'nomatch': if(preg_match($v, $tv)){$o = 0;}
169
+ foreach($p as $k=>$v)
170
+ {
171
+  switch($k)
172
+  {
173
+   case 'maxlen': if($l > $v)
174
+   {
175
+$o = 0;}
176
+   break; case 'minlen': if($l < $v)
177
+   {
178
+$o = 0;}
179
+   break; case 'maxval': if((float)($tv) > $v)
180
+   {
181
+$o = 0;}
182
+   break; case 'minval': if((float)($tv) < $v)
183
+   {
184
+$o = 0;}
185
+   break; case 'match': if(!preg_match($v, $tv))
186
+   {
187
+$o = 0;}
188
+   break; case 'nomatch': if(preg_match($v, $tv))
189
+   {
190
+$o = 0;}
134 191
    break; case 'oneof':
135 192
     $m = 0;
136
-    foreach(explode('|', $v) as $n){if($tv == $n){$m = 1; break;}}
193
+    foreach(explode('|', $v) as $n)
194
+    {
195
+if($tv == $n)
196
+    {
197
+$m = 1; break;}}
137 198
     $o = $m;
138 199
    break; case 'noneof':
139 200
     $m = 1;
140
-    foreach(explode('|', $v) as $n){if($tv == $n){$m = 0; break;}}
201
+    foreach(explode('|', $v) as $n)
202
+    {
203
+if($tv == $n)
204
+    {
205
+$m = 0; break;}}
141 206
     $o = $m;
142 207
    break; default:
143 208
    break;
144 209
   }
145
-  if(!$o){break;}
210
+  if(!$o)
211
+  {
212
+break;}
146 213
  }
147
- if($o){$r[] = $tv;}
214
+ if($o)
215
+ {
216
+$r[] = $tv;}
148 217
 }
149 218
 $r = implode($s, $r);
150 219
 return (isset($r[0]) ? $r : (isset($p['default']) ? $p['default'] : 0));
151 220
 // eof
152 221
 }
153 222
 
154
-function hl_bal($t, $do=1, $in='div'){
223
+function hl_bal($t, $do=1, $in='div')
224
+{
155 225
 // balance tags
156 226
 // by content
157 227
 $cB = array('blockquote'=>1, 'form'=>1, 'map'=>1, 'noscript'=>1); // Block
@@ -162,209 +232,359 @@  discard block
 block discarded – undo
162 232
 $cN2 = array_keys($cN);
163 233
 $cR = array('blockquote'=>1, 'dir'=>1, 'dl'=>1, 'form'=>1, 'map'=>1, 'menu'=>1, 'noscript'=>1, 'ol'=>1, 'optgroup'=>1, 'rbc'=>1, 'rtc'=>1, 'ruby'=>1, 'select'=>1, 'table'=>1, 'tbody'=>1, 'tfoot'=>1, 'thead'=>1, 'tr'=>1, 'ul'=>1);
164 234
 $cS = array('colgroup'=>array('col'=>1), 'dir'=>array('li'=>1), 'dl'=>array('dd'=>1, 'dt'=>1), 'menu'=>array('li'=>1), 'ol'=>array('li'=>1), 'optgroup'=>array('option'=>1), 'option'=>array('#pcdata'=>1), 'rbc'=>array('rb'=>1), 'rp'=>array('#pcdata'=>1), 'rtc'=>array('rt'=>1), 'ruby'=>array('rb'=>1, 'rbc'=>1, 'rp'=>1, 'rt'=>1, 'rtc'=>1), 'select'=>array('optgroup'=>1, 'option'=>1), 'script'=>array('#pcdata'=>1), 'table'=>array('caption'=>1, 'col'=>1, 'colgroup'=>1, 'tfoot'=>1, 'tbody'=>1, 'tr'=>1, 'thead'=>1), 'tbody'=>array('tr'=>1), 'tfoot'=>array('tr'=>1), 'textarea'=>array('#pcdata'=>1), 'thead'=>array('tr'=>1), 'tr'=>array('td'=>1, 'th'=>1), 'ul'=>array('li'=>1)); // Specific - immediate parent-child
165
-if($GLOBALS['C']['direct_list_nest']){$cS['ol'] = $cS['ul'] += array('ol'=>1, 'ul'=>1);}
235
+if($GLOBALS['C']['direct_list_nest'])
236
+{
237
+$cS['ol'] = $cS['ul'] += array('ol'=>1, 'ul'=>1);}
166 238
 $cO = array('address'=>array('p'=>1), 'applet'=>array('param'=>1), 'blockquote'=>array('script'=>1), 'fieldset'=>array('legend'=>1, '#pcdata'=>1), 'form'=>array('script'=>1), 'map'=>array('area'=>1), 'object'=>array('param'=>1, 'embed'=>1)); // Other
167 239
 $cT = array('colgroup'=>1, 'dd'=>1, 'dt'=>1, 'li'=>1, 'option'=>1, 'p'=>1, 'td'=>1, 'tfoot'=>1, 'th'=>1, 'thead'=>1, 'tr'=>1); // Omitable closing
168 240
 // block/inline type; ins & del both type; #pcdata: text
169 241
 $eB = array('address'=>1, 'blockquote'=>1, 'center'=>1, 'del'=>1, 'dir'=>1, 'dl'=>1, 'div'=>1, 'fieldset'=>1, 'form'=>1, 'ins'=>1, 'h1'=>1, 'h2'=>1, 'h3'=>1, 'h4'=>1, 'h5'=>1, 'h6'=>1, 'hr'=>1, 'isindex'=>1, 'menu'=>1, 'noscript'=>1, 'ol'=>1, 'p'=>1, 'pre'=>1, 'table'=>1, 'ul'=>1);
170 242
 $eI = array('#pcdata'=>1, 'a'=>1, 'abbr'=>1, 'acronym'=>1, 'applet'=>1, 'b'=>1, 'bdo'=>1, 'big'=>1, 'br'=>1, 'button'=>1, 'cite'=>1, 'code'=>1, 'del'=>1, 'dfn'=>1, 'em'=>1, 'embed'=>1, 'font'=>1, 'i'=>1, 'iframe'=>1, 'img'=>1, 'input'=>1, 'ins'=>1, 'kbd'=>1, 'label'=>1, 'map'=>1, 'object'=>1, 'q'=>1, 'ruby'=>1, 's'=>1, 'samp'=>1, 'select'=>1, 'script'=>1, 'small'=>1, 'span'=>1, 'strike'=>1, 'strong'=>1, 'sub'=>1, 'sup'=>1, 'textarea'=>1, 'tt'=>1, 'u'=>1, 'var'=>1);
171
-if($GLOBALS['C']['allow_for_inline'] && is_array($GLOBALS['C']['allow_for_inline'])) foreach($GLOBALS['C']['allow_for_inline'] as $khai => $vhai) {$eI[$vhai]=1;}//allow table as if it was an inline element as <span> some Text <table>...</table> more text</span> is quite common
243
+if($GLOBALS['C']['allow_for_inline'] && is_array($GLOBALS['C']['allow_for_inline']))
244
+{
245
+	foreach($GLOBALS['C']['allow_for_inline'] as $khai => $vhai) {$eI[$vhai]=1;
246
+}
247
+}//allow table as if it was an inline element as <span> some Text <table>...</table> more text</span> is quite common
172 248
 $eN = array('a'=>1, 'big'=>1, 'button'=>1, 'fieldset'=>1, 'font'=>1, 'form'=>1, 'iframe'=>1, 'img'=>1, 'input'=>1, 'label'=>1, 'object'=>1, 'ruby'=>1, 'script'=>1, 'select'=>1, 'small'=>1, 'sub'=>1, 'sup'=>1, 'textarea'=>1); // Exclude from specific ele; $cN values
173 249
 $eO = array('area'=>1, 'caption'=>1, 'col'=>1, 'colgroup'=>1, 'dd'=>1, 'dt'=>1, 'legend'=>1, 'li'=>1, 'optgroup'=>1, 'option'=>1, 'param'=>1, 'rb'=>1, 'rbc'=>1, 'rp'=>1, 'rt'=>1, 'rtc'=>1, 'script'=>1, 'tbody'=>1, 'td'=>1, 'tfoot'=>1, 'thead'=>1, 'th'=>1, 'tr'=>1); // Missing in $eB & $eI
174 250
 $eF = $eB + $eI;
175 251
 
176 252
 // $in sets allowed child
177 253
 $in = ((isset($eF[$in]) && $in != '#pcdata') or isset($eO[$in])) ? $in : 'div';
178
-if(isset($cE[$in])){
254
+if(isset($cE[$in]))
255
+{
179 256
  return (!$do ? '' : str_replace(array('<', '>'), array('&lt;', '&gt;'), $t));
180 257
 }
181
-if(isset($cS[$in])){$inOk = $cS[$in];}
182
-elseif(isset($cI[$in])){$inOk = $eI; $cI['del'] = 1; $cI['ins'] = 1;}
183
-elseif(isset($cF[$in])){$inOk = $eF; unset($cI['del'], $cI['ins']);}
184
-elseif(isset($cB[$in])){$inOk = $eB; unset($cI['del'], $cI['ins']);}
185
-if(isset($cO[$in])){$inOk = $inOk + $cO[$in];}
186
-if(isset($cN[$in])){$inOk = array_diff_assoc($inOk, $cN[$in]);}
258
+if(isset($cS[$in]))
259
+{
260
+$inOk = $cS[$in];}
261
+elseif(isset($cI[$in]))
262
+{
263
+$inOk = $eI; $cI['del'] = 1; $cI['ins'] = 1;}
264
+elseif(isset($cF[$in]))
265
+{
266
+$inOk = $eF; unset($cI['del'], $cI['ins']);}
267
+elseif(isset($cB[$in]))
268
+{
269
+$inOk = $eB; unset($cI['del'], $cI['ins']);}
270
+if(isset($cO[$in]))
271
+{
272
+$inOk = $inOk + $cO[$in];}
273
+if(isset($cN[$in]))
274
+{
275
+$inOk = array_diff_assoc($inOk, $cN[$in]);}
187 276
 
188 277
 $t = explode('<', $t);
189 278
 $ok = $q = array(); // $q seq list of open non-empty ele
190 279
 ob_start();
191 280
 
192
-for($i=-1, $ci=count($t); ++$i<$ci;){
281
+for($i=-1, $ci=count($t); ++$i<$ci;)
282
+{
193 283
  // allowed $ok in parent $p
194
- if($ql = count($q)){
284
+ if($ql = count($q))
285
+ {
195 286
   $p = array_pop($q);
196 287
   $q[] = $p;
197
-  if(isset($cS[$p])){$ok = $cS[$p];}
198
-  elseif(isset($cI[$p])){$ok = $eI; $cI['del'] = 1; $cI['ins'] = 1;}
199
-  elseif(isset($cF[$p])){$ok = $eF; unset($cI['del'], $cI['ins']);}
200
-  elseif(isset($cB[$p])){$ok = $eB; unset($cI['del'], $cI['ins']);}
201
-  if(isset($cO[$p])){$ok = $ok + $cO[$p];}
202
-  if(isset($cN[$p])){$ok = array_diff_assoc($ok, $cN[$p]);}
203
- }else{$ok = $inOk; unset($cI['del'], $cI['ins']);}
288
+  if(isset($cS[$p]))
289
+  {
290
+$ok = $cS[$p];}
291
+  elseif(isset($cI[$p]))
292
+  {
293
+$ok = $eI; $cI['del'] = 1; $cI['ins'] = 1;}
294
+  elseif(isset($cF[$p]))
295
+  {
296
+$ok = $eF; unset($cI['del'], $cI['ins']);}
297
+  elseif(isset($cB[$p]))
298
+  {
299
+$ok = $eB; unset($cI['del'], $cI['ins']);}
300
+  if(isset($cO[$p]))
301
+  {
302
+$ok = $ok + $cO[$p];}
303
+  if(isset($cN[$p]))
304
+  {
305
+$ok = array_diff_assoc($ok, $cN[$p]);}
306
+ }
307
+ else
308
+ {
309
+$ok = $inOk; unset($cI['del'], $cI['ins']);}
204 310
  // bad tags, & ele content
205
- if(isset($e) && ($do == 1 or (isset($ok['#pcdata']) && ($do == 3 or $do == 5)))){
311
+ if(isset($e) && ($do == 1 or (isset($ok['#pcdata']) && ($do == 3 or $do == 5))))
312
+ {
206 313
   echo '&lt;', $s, $e, $a, '&gt;';
207 314
  }
208
- if(isset($x[0])){
209
-  if(strlen(trim($x)) && (($ql && isset($cB[$p])) or (isset($cB[$in]) && !$ql))){
315
+ if(isset($x[0]))
316
+ {
317
+  if(strlen(trim($x)) && (($ql && isset($cB[$p])) or (isset($cB[$in]) && !$ql)))
318
+  {
210 319
    echo '<div>', $x, '</div>';
211 320
   }
212
-  elseif($do < 3 or isset($ok['#pcdata'])){echo $x;}
213
-  elseif(strpos($x, "\x02\x04")){
214
-   foreach(preg_split('`(\x01\x02[^\x01\x02]+\x02\x01)`', $x, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY) as $v){
321
+  elseif($do < 3 or isset($ok['#pcdata']))
322
+  {
323
+echo $x;}
324
+  elseif(strpos($x, "\x02\x04"))
325
+  {
326
+   foreach(preg_split('`(\x01\x02[^\x01\x02]+\x02\x01)`', $x, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY) as $v)
327
+   {
215 328
     echo (substr($v, 0, 2) == "\x01\x02" ? $v : ($do > 4 ? preg_replace('`\S`', '', $v) : ''));
216 329
    }
217
-  }elseif($do > 4){echo preg_replace('`\S`', '', $x);}
330
+  }
331
+  elseif($do > 4)
332
+  {
333
+echo preg_replace('`\S`', '', $x);}
218 334
  }
219 335
  // get markup
220
- if(!preg_match('`^(/?)([a-z1-6]+)([^>]*)>(.*)`sm', $t[$i], $r)){$x = $t[$i]; continue;}
336
+ if(!preg_match('`^(/?)([a-z1-6]+)([^>]*)>(.*)`sm', $t[$i], $r))
337
+ {
338
+$x = $t[$i]; continue;}
221 339
  $s = null; $e = null; $a = null; $x = null; list($all, $s, $e, $a, $x) = $r;
222 340
  // close tag
223
- if($s){
224
-  if(isset($cE[$e]) or !in_array($e, $q)){continue;} // Empty/unopen
225
-  if($p == $e){array_pop($q); echo '</', $e, '>'; unset($e); continue;} // Last open
341
+ if($s)
342
+ {
343
+  if(isset($cE[$e]) or !in_array($e, $q))
344
+  {
345
+continue;} // Empty/unopen
346
+  if($p == $e)
347
+  {
348
+array_pop($q); echo '</', $e, '>'; unset($e); continue;} // Last open
226 349
   $add = ''; // Nesting - close open tags that need to be
227
-  for($j=-1, $cj=count($q); ++$j<$cj;){
228
-   if(($d = array_pop($q)) == $e){break;}
229
-   else{$add .= "</{$d}>";}
350
+  for($j=-1, $cj=count($q); ++$j<$cj;)
351
+  {
352
+   if(($d = array_pop($q)) == $e)
353
+   {
354
+break;}
355
+   else
356
+   {
357
+$add .= "</{$d}>";}
230 358
   }
231 359
   echo $add, '</', $e, '>'; unset($e); continue;
232 360
  }
233 361
  // open tag
234 362
  // $cB ele needs $eB ele as child
235
- if(isset($cB[$e]) && strlen(trim($x))){
363
+ if(isset($cB[$e]) && strlen(trim($x)))
364
+ {
236 365
   $t[$i] = "{$e}{$a}>";
237 366
   array_splice($t, $i+1, 0, 'div>'. $x); unset($e, $x); ++$ci; --$i; continue;
238 367
  }
239
- if((($ql && isset($cB[$p])) or (isset($cB[$in]) && !$ql)) && !isset($eB[$e]) && !isset($ok[$e])){
368
+ if((($ql && isset($cB[$p])) or (isset($cB[$in]) && !$ql)) && !isset($eB[$e]) && !isset($ok[$e]))
369
+ {
240 370
   array_splice($t, $i, 0, 'div>'); unset($e, $x); ++$ci; --$i; continue;
241 371
  }
242
- if($e == 'div' && !isset($ok['div']) && strpos($a, '-htmlawed-transform')){
372
+ if($e == 'div' && !isset($ok['div']) && strpos($a, '-htmlawed-transform'))
373
+ {
243 374
   $t[$i] = "span{$a}>{$x}"; unset($e, $x); --$i; continue;
244 375
  }
245 376
  // if no open ele, $in = parent; mostly immediate parent-child relation should hold
246
- if(!$ql or !isset($eN[$e]) or !array_intersect($q, $cN2)){
247
-  if(!isset($ok[$e])){
248
-   if($ql && isset($cT[$p])){echo '</', array_pop($q), '>'; unset($e, $x); --$i;}
377
+ if(!$ql or !isset($eN[$e]) or !array_intersect($q, $cN2))
378
+ {
379
+  if(!isset($ok[$e]))
380
+  {
381
+   if($ql && isset($cT[$p]))
382
+   {
383
+echo '</', array_pop($q), '>'; unset($e, $x); --$i;}
249 384
    continue;
250 385
   }
251
-  if(!isset($cE[$e])){$q[] = $e;}
386
+  if(!isset($cE[$e]))
387
+  {
388
+$q[] = $e;}
252 389
   echo '<', $e, $a, '>'; unset($e); continue;
253 390
  }
254 391
  // specific parent-child
255
- if(isset($cS[$p][$e])){
256
-  if(!isset($cE[$e])){$q[] = $e;}
392
+ if(isset($cS[$p][$e]))
393
+ {
394
+  if(!isset($cE[$e]))
395
+  {
396
+$q[] = $e;}
257 397
   echo '<', $e, $a, '>'; unset($e); continue;
258 398
  }
259 399
  // nesting
260 400
  $add = '';
261 401
  $q2 = array();
262
- for($k=-1, $kc=count($q); ++$k<$kc;){
402
+ for($k=-1, $kc=count($q); ++$k<$kc;)
403
+ {
263 404
   $d = $q[$k];
264 405
   $ok2 = array();
265
-  if(isset($cS[$d])){$q2[] = $d; continue;}
406
+  if(isset($cS[$d]))
407
+  {
408
+$q2[] = $d; continue;}
266 409
   $ok2 = isset($cI[$d]) ? $eI : $eF;
267
-  if(isset($cO[$d])){$ok2 = $ok2 + $cO[$d];}
268
-  if(isset($cN[$d])){$ok2 = array_diff_assoc($ok2, $cN[$d]);}
269
-  if(!isset($ok2[$e])){
270
-   if(!$k && !isset($inOk[$e])){continue 2;}
410
+  if(isset($cO[$d]))
411
+  {
412
+$ok2 = $ok2 + $cO[$d];}
413
+  if(isset($cN[$d]))
414
+  {
415
+$ok2 = array_diff_assoc($ok2, $cN[$d]);}
416
+  if(!isset($ok2[$e]))
417
+  {
418
+   if(!$k && !isset($inOk[$e]))
419
+   {
420
+continue 2;}
271 421
    $add = "</{$d}>";
272
-   for(;++$k<$kc;){$add = "</{$q[$k]}>{$add}";}
422
+   for(;++$k<$kc;)
423
+   {
424
+$add = "</{$q[$k]}>{$add}";}
273 425
    break;
274 426
   }
275
-  else{$q2[] = $d;}
427
+  else
428
+  {
429
+$q2[] = $d;}
276 430
  }
277 431
  $q = $q2;
278
- if(!isset($cE[$e])){$q[] = $e;}
432
+ if(!isset($cE[$e]))
433
+ {
434
+$q[] = $e;}
279 435
  echo $add, '<', $e, $a, '>'; unset($e); continue;
280 436
 }
281 437
 
282 438
 // end
283
-if($ql = count($q)){
439
+if($ql = count($q))
440
+{
284 441
  $p = array_pop($q);
285 442
  $q[] = $p;
286
- if(isset($cS[$p])){$ok = $cS[$p];}
287
- elseif(isset($cI[$p])){$ok = $eI; $cI['del'] = 1; $cI['ins'] = 1;}
288
- elseif(isset($cF[$p])){$ok = $eF; unset($cI['del'], $cI['ins']);}
289
- elseif(isset($cB[$p])){$ok = $eB; unset($cI['del'], $cI['ins']);}
290
- if(isset($cO[$p])){$ok = $ok + $cO[$p];}
291
- if(isset($cN[$p])){$ok = array_diff_assoc($ok, $cN[$p]);}
292
-}else{$ok = $inOk; unset($cI['del'], $cI['ins']);}
293
-if(isset($e) && ($do == 1 or (isset($ok['#pcdata']) && ($do == 3 or $do == 5)))){
443
+ if(isset($cS[$p]))
444
+ {
445
+$ok = $cS[$p];}
446
+ elseif(isset($cI[$p]))
447
+ {
448
+$ok = $eI; $cI['del'] = 1; $cI['ins'] = 1;}
449
+ elseif(isset($cF[$p]))
450
+ {
451
+$ok = $eF; unset($cI['del'], $cI['ins']);}
452
+ elseif(isset($cB[$p]))
453
+ {
454
+$ok = $eB; unset($cI['del'], $cI['ins']);}
455
+ if(isset($cO[$p]))
456
+ {
457
+$ok = $ok + $cO[$p];}
458
+ if(isset($cN[$p]))
459
+ {
460
+$ok = array_diff_assoc($ok, $cN[$p]);}
461
+}
462
+else
463
+{
464
+$ok = $inOk; unset($cI['del'], $cI['ins']);}
465
+if(isset($e) && ($do == 1 or (isset($ok['#pcdata']) && ($do == 3 or $do == 5))))
466
+{
294 467
  echo '&lt;', $s, $e, $a, '&gt;';
295 468
 }
296
-if(isset($x[0])){
297
- if(strlen(trim($x)) && (($ql && isset($cB[$p])) or (isset($cB[$in]) && !$ql))){
469
+if(isset($x[0]))
470
+{
471
+ if(strlen(trim($x)) && (($ql && isset($cB[$p])) or (isset($cB[$in]) && !$ql)))
472
+ {
298 473
   echo '<div>', $x, '</div>';
299 474
  }
300
- elseif($do < 3 or isset($ok['#pcdata'])){echo $x;}
301
- elseif(strpos($x, "\x02\x04")){
302
-  foreach(preg_split('`(\x01\x02[^\x01\x02]+\x02\x01)`', $x, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY) as $v){
475
+ elseif($do < 3 or isset($ok['#pcdata']))
476
+ {
477
+echo $x;}
478
+ elseif(strpos($x, "\x02\x04"))
479
+ {
480
+  foreach(preg_split('`(\x01\x02[^\x01\x02]+\x02\x01)`', $x, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY) as $v)
481
+  {
303 482
    echo (substr($v, 0, 2) == "\x01\x02" ? $v : ($do > 4 ? preg_replace('`\S`', '', $v) : ''));
304 483
   }
305
- }elseif($do > 4){echo preg_replace('`\S`', '', $x);}
484
+ }
485
+ elseif($do > 4)
486
+ {
487
+echo preg_replace('`\S`', '', $x);}
306 488
 }
307
-while(!empty($q) && ($e = array_pop($q))){echo '</', $e, '>';}
489
+while(!empty($q) && ($e = array_pop($q)))
490
+{
491
+echo '</', $e, '>';}
308 492
 $o = ob_get_contents();
309 493
 ob_end_clean();
310 494
 return $o;
311 495
 // eof
312 496
 }
313 497
 
314
-function hl_cmtcd($t){
498
+function hl_cmtcd($t)
499
+{
315 500
 // comment/CDATA sec handler
316 501
 $t = $t[0];
317 502
 global $C;
318
-if(!($v = $C[$n = $t[3] == '-' ? 'comment' : 'cdata'])){return $t;}
319
-if($v == 1){return '';}
320
-if($n == 'comment'){
321
- if(substr(($t = preg_replace('`--+`', '-', substr($t, 4, -3))), -1) != ' '){$t .= ' ';}
503
+if(!($v = $C[$n = $t[3] == '-' ? 'comment' : 'cdata']))
504
+{
505
+return $t;}
506
+if($v == 1)
507
+{
508
+return '';}
509
+if($n == 'comment')
510
+{
511
+ if(substr(($t = preg_replace('`--+`', '-', substr($t, 4, -3))), -1) != ' ')
512
+ {
513
+$t .= ' ';}
322 514
 }
323
-else{$t = substr($t, 1, -1);}
515
+else
516
+{
517
+$t = substr($t, 1, -1);}
324 518
 $t = $v == 2 ? str_replace(array('&', '<', '>'), array('&amp;', '&lt;', '&gt;'), $t) : $t;
325 519
 return str_replace(array('&', '<', '>'), array("\x03", "\x04", "\x05"), ($n == 'comment' ? "\x01\x02\x04!--$t--\x05\x02\x01" : "\x01\x01\x04$t\x05\x01\x01"));
326 520
 // eof
327 521
 }
328 522
 
329
-function hl_ent($t){
523
+function hl_ent($t)
524
+{
330 525
 // entitity handler
331 526
 global $C;
332 527
 $t = $t[1];
333 528
 static $U = array('quot'=>1,'amp'=>1,'lt'=>1,'gt'=>1);
334 529
 static $N = array('fnof'=>'402', 'Alpha'=>'913', 'Beta'=>'914', 'Gamma'=>'915', 'Delta'=>'916', 'Epsilon'=>'917', 'Zeta'=>'918', 'Eta'=>'919', 'Theta'=>'920', 'Iota'=>'921', 'Kappa'=>'922', 'Lambda'=>'923', 'Mu'=>'924', 'Nu'=>'925', 'Xi'=>'926', 'Omicron'=>'927', 'Pi'=>'928', 'Rho'=>'929', 'Sigma'=>'931', 'Tau'=>'932', 'Upsilon'=>'933', 'Phi'=>'934', 'Chi'=>'935', 'Psi'=>'936', 'Omega'=>'937', 'alpha'=>'945', 'beta'=>'946', 'gamma'=>'947', 'delta'=>'948', 'epsilon'=>'949', 'zeta'=>'950', 'eta'=>'951', 'theta'=>'952', 'iota'=>'953', 'kappa'=>'954', 'lambda'=>'955', 'mu'=>'956', 'nu'=>'957', 'xi'=>'958', 'omicron'=>'959', 'pi'=>'960', 'rho'=>'961', 'sigmaf'=>'962', 'sigma'=>'963', 'tau'=>'964', 'upsilon'=>'965', 'phi'=>'966', 'chi'=>'967', 'psi'=>'968', 'omega'=>'969', 'thetasym'=>'977', 'upsih'=>'978', 'piv'=>'982', 'bull'=>'8226', 'hellip'=>'8230', 'prime'=>'8242', 'Prime'=>'8243', 'oline'=>'8254', 'frasl'=>'8260', 'weierp'=>'8472', 'image'=>'8465', 'real'=>'8476', 'trade'=>'8482', 'alefsym'=>'8501', 'larr'=>'8592', 'uarr'=>'8593', 'rarr'=>'8594', 'darr'=>'8595', 'harr'=>'8596', 'crarr'=>'8629', 'lArr'=>'8656', 'uArr'=>'8657', 'rArr'=>'8658', 'dArr'=>'8659', 'hArr'=>'8660', 'forall'=>'8704', 'part'=>'8706', 'exist'=>'8707', 'empty'=>'8709', 'nabla'=>'8711', 'isin'=>'8712', 'notin'=>'8713', 'ni'=>'8715', 'prod'=>'8719', 'sum'=>'8721', 'minus'=>'8722', 'lowast'=>'8727', 'radic'=>'8730', 'prop'=>'8733', 'infin'=>'8734', 'ang'=>'8736', 'and'=>'8743', 'or'=>'8744', 'cap'=>'8745', 'cup'=>'8746', 'int'=>'8747', 'there4'=>'8756', 'sim'=>'8764', 'cong'=>'8773', 'asymp'=>'8776', 'ne'=>'8800', 'equiv'=>'8801', 'le'=>'8804', 'ge'=>'8805', 'sub'=>'8834', 'sup'=>'8835', 'nsub'=>'8836', 'sube'=>'8838', 'supe'=>'8839', 'oplus'=>'8853', 'otimes'=>'8855', 'perp'=>'8869', 'sdot'=>'8901', 'lceil'=>'8968', 'rceil'=>'8969', 'lfloor'=>'8970', 'rfloor'=>'8971', 'lang'=>'9001', 'rang'=>'9002', 'loz'=>'9674', 'spades'=>'9824', 'clubs'=>'9827', 'hearts'=>'9829', 'diams'=>'9830', 'apos'=>'39',  'OElig'=>'338', 'oelig'=>'339', 'Scaron'=>'352', 'scaron'=>'353', 'Yuml'=>'376', 'circ'=>'710', 'tilde'=>'732', 'ensp'=>'8194', 'emsp'=>'8195', 'thinsp'=>'8201', 'zwnj'=>'8204', 'zwj'=>'8205', 'lrm'=>'8206', 'rlm'=>'8207', 'ndash'=>'8211', 'mdash'=>'8212', 'lsquo'=>'8216', 'rsquo'=>'8217', 'sbquo'=>'8218', 'ldquo'=>'8220', 'rdquo'=>'8221', 'bdquo'=>'8222', 'dagger'=>'8224', 'Dagger'=>'8225', 'permil'=>'8240', 'lsaquo'=>'8249', 'rsaquo'=>'8250', 'euro'=>'8364', 'nbsp'=>'160', 'iexcl'=>'161', 'cent'=>'162', 'pound'=>'163', 'curren'=>'164', 'yen'=>'165', 'brvbar'=>'166', 'sect'=>'167', 'uml'=>'168', 'copy'=>'169', 'ordf'=>'170', 'laquo'=>'171', 'not'=>'172', 'shy'=>'173', 'reg'=>'174', 'macr'=>'175', 'deg'=>'176', 'plusmn'=>'177', 'sup2'=>'178', 'sup3'=>'179', 'acute'=>'180', 'micro'=>'181', 'para'=>'182', 'middot'=>'183', 'cedil'=>'184', 'sup1'=>'185', 'ordm'=>'186', 'raquo'=>'187', 'frac14'=>'188', 'frac12'=>'189', 'frac34'=>'190', 'iquest'=>'191', 'Agrave'=>'192', 'Aacute'=>'193', 'Acirc'=>'194', 'Atilde'=>'195', 'Auml'=>'196', 'Aring'=>'197', 'AElig'=>'198', 'Ccedil'=>'199', 'Egrave'=>'200', 'Eacute'=>'201', 'Ecirc'=>'202', 'Euml'=>'203', 'Igrave'=>'204', 'Iacute'=>'205', 'Icirc'=>'206', 'Iuml'=>'207', 'ETH'=>'208', 'Ntilde'=>'209', 'Ograve'=>'210', 'Oacute'=>'211', 'Ocirc'=>'212', 'Otilde'=>'213', 'Ouml'=>'214', 'times'=>'215', 'Oslash'=>'216', 'Ugrave'=>'217', 'Uacute'=>'218', 'Ucirc'=>'219', 'Uuml'=>'220', 'Yacute'=>'221', 'THORN'=>'222', 'szlig'=>'223', 'agrave'=>'224', 'aacute'=>'225', 'acirc'=>'226', 'atilde'=>'227', 'auml'=>'228', 'aring'=>'229', 'aelig'=>'230', 'ccedil'=>'231', 'egrave'=>'232', 'eacute'=>'233', 'ecirc'=>'234', 'euml'=>'235', 'igrave'=>'236', 'iacute'=>'237', 'icirc'=>'238', 'iuml'=>'239', 'eth'=>'240', 'ntilde'=>'241', 'ograve'=>'242', 'oacute'=>'243', 'ocirc'=>'244', 'otilde'=>'245', 'ouml'=>'246', 'divide'=>'247', 'oslash'=>'248', 'ugrave'=>'249', 'uacute'=>'250', 'ucirc'=>'251', 'uuml'=>'252', 'yacute'=>'253', 'thorn'=>'254', 'yuml'=>'255');
335
-if($t[0] != '#'){
530
+if($t[0] != '#')
531
+{
336 532
  return ($C['and_mark'] ? "\x06" : '&'). (isset($U[$t]) ? $t : (isset($N[$t]) ? (!$C['named_entity'] ? '#'. ($C['hexdec_entity'] > 1 ? 'x'. dechex($N[$t]) : $N[$t]) : $t) : 'amp;'. $t)). ';';
337 533
 }
338
-if(($n = ctype_digit($t = substr($t, 1)) ? intval($t) : hexdec(substr($t, 1))) < 9 or ($n > 13 && $n < 32) or $n == 11 or $n == 12 or ($n > 126 && $n < 160 && $n != 133) or ($n > 55295 && ($n < 57344 or ($n > 64975 && $n < 64992) or $n == 65534 or $n == 65535 or $n > 1114111))){
534
+if(($n = ctype_digit($t = substr($t, 1)) ? intval($t) : hexdec(substr($t, 1))) < 9 or ($n > 13 && $n < 32) or $n == 11 or $n == 12 or ($n > 126 && $n < 160 && $n != 133) or ($n > 55295 && ($n < 57344 or ($n > 64975 && $n < 64992) or $n == 65534 or $n == 65535 or $n > 1114111)))
535
+{
339 536
  return ($C['and_mark'] ? "\x06" : '&'). "amp;#{$t};";
340 537
 }
341 538
 return ($C['and_mark'] ? "\x06" : '&'). '#'. (((ctype_digit($t) && $C['hexdec_entity'] < 2) or !$C['hexdec_entity']) ? $n : 'x'. dechex($n)). ';';
342 539
 // eof
343 540
 }
344 541
 
345
-function hl_prot($p, $c=null){
542
+function hl_prot($p, $c=null)
543
+{
346 544
 // check URL scheme
347 545
 global $C;
348 546
 $b = $a = '';
349
-if($c == null){$c = 'style'; $b = $p[1]; $a = $p[3]; $p = trim($p[2]);}
547
+if($c == null)
548
+{
549
+$c = 'style'; $b = $p[1]; $a = $p[3]; $p = trim($p[2]);}
350 550
 $c = isset($C['schemes'][$c]) ? $C['schemes'][$c] : $C['schemes']['*'];
351 551
 static $d = 'denied:';
352
-if(isset($c['!']) && substr($p, 0, 7) != $d){$p = "$d$p";}
353
-if(isset($c['*']) or !strcspn($p, '#?;') or (substr($p, 0, 7) == $d)){return "{$b}{$p}{$a}";} // All ok, frag, query, param
354
-if(preg_match('`^([^:?[@!$()*,=/\'\]]+?)(:|&#(58|x3a);|%3a|\\\\0{0,4}3a).`i', $p, $m) && !isset($c[strtolower($m[1])])){ // Denied prot
552
+if(isset($c['!']) && substr($p, 0, 7) != $d)
553
+{
554
+$p = "$d$p";}
555
+if(isset($c['*']) or !strcspn($p, '#?;') or (substr($p, 0, 7) == $d))
556
+{
557
+return "{$b}{$p}{$a}";} // All ok, frag, query, param
558
+if(preg_match('`^([^:?[@!$()*,=/\'\]]+?)(:|&#(58|x3a);|%3a|\\\\0{0,4}3a).`i', $p, $m) && !isset($c[strtolower($m[1])]))
559
+{
560
+// Denied prot
355 561
  return "{$b}{$d}{$p}{$a}";
356 562
 }
357
-if($C['abs_url']){
358
- if($C['abs_url'] == -1 && strpos($p, $C['base_url']) === 0){ // Make url rel
563
+if($C['abs_url'])
564
+{
565
+ if($C['abs_url'] == -1 && strpos($p, $C['base_url']) === 0)
566
+ {
567
+// Make url rel
359 568
   $p = substr($p, strlen($C['base_url']));
360
- }elseif(empty($m[1])){ // Make URL abs
361
-  if(substr($p, 0, 2) == '//'){$p = substr($C['base_url'], 0, strpos($C['base_url'], ':')+1). $p;}
362
-  elseif($p[0] == '/'){$p = preg_replace('`(^.+?://[^/]+)(.*)`', '$1', $C['base_url']). $p;}
363
-  elseif(strcspn($p, './')){$p = $C['base_url']. $p;}
364
-  else{
569
+ }
570
+ elseif(empty($m[1]))
571
+ {
572
+// Make URL abs
573
+  if(substr($p, 0, 2) == '//')
574
+  {
575
+$p = substr($C['base_url'], 0, strpos($C['base_url'], ':')+1). $p;}
576
+  elseif($p[0] == '/')
577
+  {
578
+$p = preg_replace('`(^.+?://[^/]+)(.*)`', '$1', $C['base_url']). $p;}
579
+  elseif(strcspn($p, './'))
580
+  {
581
+$p = $C['base_url']. $p;}
582
+  else
583
+  {
365 584
    preg_match('`^([a-zA-Z\d\-+.]+://[^/]+)(.*)`', $C['base_url'], $m);
366 585
    $p = preg_replace('`(?<=/)\./`', '', $m[2]. $p);
367
-   while(preg_match('`(?<=/)([^/]{3,}|[^/.]+?|\.[^/.]|[^/.]\.)/\.\./`', $p)){
586
+   while(preg_match('`(?<=/)([^/]{3,}|[^/.]+?|\.[^/.]|[^/.]\.)/\.\./`', $p))
587
+   {
368 588
     $p = preg_replace('`(?<=/)([^/]{3,}|[^/.]+?|\.[^/.]|[^/.]\.)/\.\./`', '', $p);
369 589
    }
370 590
    $p = $m[1]. $p;
@@ -375,77 +595,133 @@  discard block
 block discarded – undo
375 595
 // eof
376 596
 }
377 597
 
378
-function hl_regex($p){
598
+function hl_regex($p)
599
+{
379 600
 // ?regex
380
-if(empty($p)){return 0;}
381
-if($t = ini_get('track_errors')){$o = isset($php_errormsg) ? $php_errormsg : null;}
382
-else{ini_set('track_errors', 1);}
601
+if(empty($p))
602
+{
603
+return 0;}
604
+if($t = ini_get('track_errors'))
605
+{
606
+$o = isset($php_errormsg) ? $php_errormsg : null;}
607
+else
608
+{
609
+ini_set('track_errors', 1);}
383 610
 unset($php_errormsg);
384
-if(($d = ini_get('display_errors'))){ini_set('display_errors', 0);}
611
+if(($d = ini_get('display_errors')))
612
+{
613
+ini_set('display_errors', 0);}
385 614
 preg_match($p, '');
386
-if($d){ini_set('display_errors', 1);}
615
+if($d)
616
+{
617
+ini_set('display_errors', 1);}
387 618
 $r = isset($php_errormsg) ? 0 : 1;
388
-if($t){$php_errormsg = isset($o) ? $o : null;}
389
-else{ini_set('track_errors', 0);}
619
+if($t)
620
+{
621
+$php_errormsg = isset($o) ? $o : null;}
622
+else
623
+{
624
+ini_set('track_errors', 0);}
390 625
 return $r;
391 626
 // eof
392 627
 }
393 628
 
394
-function hl_spec($t){
629
+function hl_spec($t)
630
+{
395 631
 // final $spec
396 632
 $s = array();
397 633
 $t = str_replace(array("\t", "\r", "\n", ' '), '', preg_replace_callback('/"(?>(`.|[^"])*)"/sm', create_function('$m', 'return substr(str_replace(array(";", "|", "~", " ", ",", "/", "(", ")", \'`"\'), array("\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07", "\x08", "\""), $m[0]), 1, -1);'), trim($t)));
398
-for($i = count(($t = explode(';', $t))); --$i>=0;){
634
+for($i = count(($t = explode(';', $t))); --$i>=0;)
635
+{
399 636
  $w = $t[$i];
400
- if(empty($w) or ($e = strpos($w, '=')) === false or !strlen(($a =  substr($w, $e+1)))){continue;}
637
+ if(empty($w) or ($e = strpos($w, '=')) === false or !strlen(($a =  substr($w, $e+1))))
638
+ {
639
+continue;}
401 640
  $y = $n = array();
402
- foreach(explode(',', $a) as $v){
403
-  if(!preg_match('`^([a-z:\-\*]+)(?:\((.*?)\))?`i', $v, $m)){continue;}
404
-  if(($x = strtolower($m[1])) == '-*'){$n['*'] = 1; continue;}
405
-  if($x[0] == '-'){$n[substr($x, 1)] = 1; continue;}
406
-  if(!isset($m[2])){$y[$x] = 1; continue;}
407
-  foreach(explode('/', $m[2]) as $m){
408
-   if(empty($m) or ($p = strpos($m, '=')) == 0 or $p < 5){$y[$x] = 1; continue;}
641
+ foreach(explode(',', $a) as $v)
642
+ {
643
+  if(!preg_match('`^([a-z:\-\*]+)(?:\((.*?)\))?`i', $v, $m))
644
+  {
645
+continue;}
646
+  if(($x = strtolower($m[1])) == '-*')
647
+  {
648
+$n['*'] = 1; continue;}
649
+  if($x[0] == '-')
650
+  {
651
+$n[substr($x, 1)] = 1; continue;}
652
+  if(!isset($m[2]))
653
+  {
654
+$y[$x] = 1; continue;}
655
+  foreach(explode('/', $m[2]) as $m)
656
+  {
657
+   if(empty($m) or ($p = strpos($m, '=')) == 0 or $p < 5)
658
+   {
659
+$y[$x] = 1; continue;}
409 660
    $y[$x][strtolower(substr($m, 0, $p))] = str_replace(array("\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07", "\x08"), array(";", "|", "~", " ", ",", "/", "(", ")"), substr($m, $p+1));
410 661
   }
411
-  if(isset($y[$x]['match']) && !hl_regex($y[$x]['match'])){unset($y[$x]['match']);}
412
-  if(isset($y[$x]['nomatch']) && !hl_regex($y[$x]['nomatch'])){unset($y[$x]['nomatch']);}
662
+  if(isset($y[$x]['match']) && !hl_regex($y[$x]['match']))
663
+  {
664
+unset($y[$x]['match']);}
665
+  if(isset($y[$x]['nomatch']) && !hl_regex($y[$x]['nomatch']))
666
+  {
667
+unset($y[$x]['nomatch']);}
413 668
  }
414
- if(!count($y) && !count($n)){continue;}
415
- foreach(explode(',', substr($w, 0, $e)) as $v){
416
-  if(!strlen(($v = strtolower($v)))){continue;}
417
-  if(count($y)){$s[$v] = $y;}
418
-  if(count($n)){$s[$v]['n'] = $n;}
669
+ if(!count($y) && !count($n))
670
+ {
671
+continue;}
672
+ foreach(explode(',', substr($w, 0, $e)) as $v)
673
+ {
674
+  if(!strlen(($v = strtolower($v))))
675
+  {
676
+continue;}
677
+  if(count($y))
678
+  {
679
+$s[$v] = $y;}
680
+  if(count($n))
681
+  {
682
+$s[$v]['n'] = $n;}
419 683
  }
420 684
 }
421 685
 return $s;
422 686
 // eof
423 687
 }
424 688
 
425
-function hl_tag($t){
689
+function hl_tag($t)
690
+{
426 691
 // tag/attribute handler
427 692
 global $C;
428 693
 $t = $t[0];
429 694
 // invalid < >
430
-if($t == '< '){return '&lt; ';}
431
-if($t == '>'){return '&gt;';}
432
-if(!preg_match('`^<(/?)([a-zA-Z][a-zA-Z1-6]*)([^>]*?)\s?>$`m', $t, $m)){
695
+if($t == '< ')
696
+{
697
+return '&lt; ';}
698
+if($t == '>')
699
+{
700
+return '&gt;';}
701
+if(!preg_match('`^<(/?)([a-zA-Z][a-zA-Z1-6]*)([^>]*?)\s?>$`m', $t, $m))
702
+{
433 703
  //return str_replace(array('<', '>'), array('&lt;', '&gt;'), $t);
434 704
  return (($C['keep_bad']%2) ? str_replace(array('<', '>'), array('&lt;', '&gt;'), $t) : '');
435
-}elseif(!isset($C['elements'][($e = strtolower($m[2]))])){
705
+}
706
+elseif(!isset($C['elements'][($e = strtolower($m[2]))]))
707
+{
436 708
  return (($C['keep_bad']%2) ? str_replace(array('<', '>'), array('&lt;', '&gt;'), $t) : '');
437 709
 }
438 710
 // attr string
439 711
 $a = str_replace(array("\n", "\r", "\t"), ' ', trim($m[3]));
440 712
 // tag transform
441 713
 static $eD = array('applet'=>1, 'center'=>1, 'dir'=>1, 'embed'=>1, 'font'=>1, 'isindex'=>1, 'menu'=>1, 's'=>1, 'strike'=>1, 'u'=>1); // Deprecated
442
-if($C['make_tag_strict'] && isset($eD[$e])){
714
+if($C['make_tag_strict'] && isset($eD[$e]))
715
+{
443 716
  $trt = hl_tag2($e, $a, $C['make_tag_strict']);
444
- if(!$e){return (($C['keep_bad']%2) ? str_replace(array('<', '>'), array('&lt;', '&gt;'), $t) : '');}
717
+ if(!$e)
718
+ {
719
+return (($C['keep_bad']%2) ? str_replace(array('<', '>'), array('&lt;', '&gt;'), $t) : '');}
445 720
 }
446 721
 // close tag
447 722
 static $eE = array('area'=>1, 'br'=>1, 'col'=>1, 'embed'=>1, 'hr'=>1, 'img'=>1, 'input'=>1, 'isindex'=>1, 'param'=>1); // Empty ele
448
-if(!empty($m[1])){
723
+if(!empty($m[1]))
724
+{
449 725
  return (!isset($eE[$e]) ? (empty($C['hook_tag']) ? "</$e>" : $C['hook_tag']($e)) : (($C['keep_bad'])%2 ? str_replace(array('<', '>'), array('&lt;', '&gt;'), $t) : ''));
450 726
 }
451 727
 // open tag & attr
@@ -455,7 +731,8 @@  discard block
 block discarded – undo
455 731
 static $aNP = array('action'=>1, 'cite'=>1, 'classid'=>1, 'codebase'=>1, 'data'=>1, 'href'=>1, 'longdesc'=>1, 'model'=>1, 'pluginspage'=>1, 'pluginurl'=>1, 'usemap'=>1); // Need scheme check; excludes style, on* & src
456 732
 static $aNU = array('class'=>array('param'=>1, 'script'=>1), 'dir'=>array('applet'=>1, 'bdo'=>1, 'br'=>1, 'iframe'=>1, 'param'=>1, 'script'=>1), 'id'=>array('script'=>1), 'lang'=>array('applet'=>1, 'br'=>1, 'iframe'=>1, 'param'=>1, 'script'=>1), 'xml:lang'=>array('applet'=>1, 'br'=>1, 'iframe'=>1, 'param'=>1, 'script'=>1), 'onclick'=>array('applet'=>1, 'bdo'=>1, 'br'=>1, 'font'=>1, 'iframe'=>1, 'isindex'=>1, 'param'=>1, 'script'=>1), 'ondblclick'=>array('applet'=>1, 'bdo'=>1, 'br'=>1, 'font'=>1, 'iframe'=>1, 'isindex'=>1, 'param'=>1, 'script'=>1), 'onkeydown'=>array('applet'=>1, 'bdo'=>1, 'br'=>1, 'font'=>1, 'iframe'=>1, 'isindex'=>1, 'param'=>1, 'script'=>1), 'onkeypress'=>array('applet'=>1, 'bdo'=>1, 'br'=>1, 'font'=>1, 'iframe'=>1, 'isindex'=>1, 'param'=>1, 'script'=>1), 'onkeyup'=>array('applet'=>1, 'bdo'=>1, 'br'=>1, 'font'=>1, 'iframe'=>1, 'isindex'=>1, 'param'=>1, 'script'=>1), 'onmousedown'=>array('applet'=>1, 'bdo'=>1, 'br'=>1, 'font'=>1, 'iframe'=>1, 'isindex'=>1, 'param'=>1, 'script'=>1), 'onmousemove'=>array('applet'=>1, 'bdo'=>1, 'br'=>1, 'font'=>1, 'iframe'=>1, 'isindex'=>1, 'param'=>1, 'script'=>1), 'onmouseout'=>array('applet'=>1, 'bdo'=>1, 'br'=>1, 'font'=>1, 'iframe'=>1, 'isindex'=>1, 'param'=>1, 'script'=>1), 'onmouseover'=>array('applet'=>1, 'bdo'=>1, 'br'=>1, 'font'=>1, 'iframe'=>1, 'isindex'=>1, 'param'=>1, 'script'=>1), 'onmouseup'=>array('applet'=>1, 'bdo'=>1, 'br'=>1, 'font'=>1, 'iframe'=>1, 'isindex'=>1, 'param'=>1, 'script'=>1), 'style'=>array('param'=>1, 'script'=>1), 'title'=>array('param'=>1, 'script'=>1)); // Univ & exceptions
457 733
 
458
-if($C['lc_std_val']){
734
+if($C['lc_std_val'])
735
+{
459 736
  // predef attr vals for $eAL & $aNE ele
460 737
  static $aNL = array('all'=>1, 'baseline'=>1, 'bottom'=>1, 'button'=>1, 'center'=>1, 'char'=>1, 'checkbox'=>1, 'circle'=>1, 'col'=>1, 'colgroup'=>1, 'cols'=>1, 'data'=>1, 'default'=>1, 'file'=>1, 'get'=>1, 'groups'=>1, 'hidden'=>1, 'image'=>1, 'justify'=>1, 'left'=>1, 'ltr'=>1, 'middle'=>1, 'none'=>1, 'object'=>1, 'password'=>1, 'poly'=>1, 'post'=>1, 'preserve'=>1, 'radio'=>1, 'rect'=>1, 'ref'=>1, 'reset'=>1, 'right'=>1, 'row'=>1, 'rowgroup'=>1, 'rows'=>1, 'rtl'=>1, 'submit'=>1, 'text'=>1, 'top'=>1);
461 738
  static $eAL = array('a'=>1, 'area'=>1, 'bdo'=>1, 'button'=>1, 'col'=>1, 'form'=>1, 'img'=>1, 'input'=>1, 'object'=>1, 'optgroup'=>1, 'option'=>1, 'param'=>1, 'script'=>1, 'select'=>1, 'table'=>1, 'td'=>1, 'tfoot'=>1, 'th'=>1, 'thead'=>1, 'tr'=>1, 'xml:space'=>1);
@@ -463,7 +740,8 @@  discard block
 block discarded – undo
463 740
 }
464 741
 
465 742
 $depTr = 0;
466
-if($C['no_deprecated_attr']){
743
+if($C['no_deprecated_attr'])
744
+{
467 745
  // dep attr:applicable ele
468 746
  static $aND = array('align'=>array('caption'=>1, 'div'=>1, 'h1'=>1, 'h2'=>1, 'h3'=>1, 'h4'=>1, 'h5'=>1, 'h6'=>1, 'hr'=>1, 'img'=>1, 'input'=>1, 'legend'=>1, 'object'=>1, 'p'=>1, 'table'=>1), 'bgcolor'=>array('table'=>1, 'td'=>1, 'th'=>1, 'tr'=>1), 'border'=>array('img'=>1, 'object'=>1), 'bordercolor'=>array('table'=>1, 'td'=>1, 'tr'=>1), 'clear'=>array('br'=>1), 'compact'=>array('dl'=>1, 'ol'=>1, 'ul'=>1), 'height'=>array('td'=>1, 'th'=>1), 'hspace'=>array('img'=>1, 'object'=>1), 'language'=>array('script'=>1), 'name'=>array('a'=>1, 'form'=>1, 'iframe'=>1, 'img'=>1, 'map'=>1), 'noshade'=>array('hr'=>1), 'nowrap'=>array('td'=>1, 'th'=>1), 'size'=>array('hr'=>1), 'start'=>array('ol'=>1), 'type'=>array('li'=>1, 'ol'=>1, 'ul'=>1), 'value'=>array('li'=>1), 'vspace'=>array('img'=>1, 'object'=>1), 'width'=>array('hr'=>1, 'pre'=>1, 'td'=>1, 'th'=>1));
469 747
  static $eAD = array('a'=>1, 'br'=>1, 'caption'=>1, 'div'=>1, 'dl'=>1, 'form'=>1, 'h1'=>1, 'h2'=>1, 'h3'=>1, 'h4'=>1, 'h5'=>1, 'h6'=>1, 'hr'=>1, 'iframe'=>1, 'img'=>1, 'input'=>1, 'legend'=>1, 'li'=>1, 'map'=>1, 'object'=>1, 'ol'=>1, 'p'=>1, 'pre'=>1, 'script'=>1, 'table'=>1, 'td'=>1, 'th'=>1, 'tr'=>1, 'ul'=>1);
@@ -471,196 +749,328 @@  discard block
 block discarded – undo
471 749
 }
472 750
 
473 751
 // attr name-vals
474
-if(strpos($a, "\x01") !== false){$a = preg_replace('`\x01[^\x01]*\x01`', '', $a);} // No comment/CDATA sec
752
+if(strpos($a, "\x01") !== false)
753
+{
754
+$a = preg_replace('`\x01[^\x01]*\x01`', '', $a);} // No comment/CDATA sec
475 755
 $mode = 0; $a = trim($a, ' /'); $aA = array();
476
-while(strlen($a)){
756
+while(strlen($a))
757
+{
477 758
  $w = 0;
478
- switch($mode){
759
+ switch($mode)
760
+ {
479 761
   case 0: // Name
480
-   if(preg_match('`^[a-zA-Z][\-a-zA-Z:]+`', $a, $m)){
762
+   if(preg_match('`^[a-zA-Z][\-a-zA-Z:]+`', $a, $m))
763
+   {
481 764
     $nm = strtolower($m[0]);
482 765
     $w = $mode = 1; $a = ltrim(substr_replace($a, '', 0, strlen($m[0])));
483 766
    }
484 767
   break; case 1:
485
-   if($a[0] == '='){ // =
768
+   if($a[0] == '=')
769
+   {
770
+// =
486 771
     $w = 1; $mode = 2; $a = ltrim($a, '= ');
487
-   }else{ // No val
772
+   }
773
+   else
774
+   {
775
+// No val
488 776
     $w = 1; $mode = 0; $a = ltrim($a);
489 777
     $aA[$nm] = '';
490 778
    }
491 779
   break; case 2: // Val
492
-   if(preg_match('`^((?:"[^"]*")|(?:\'[^\']*\')|(?:\s*[^\s"\']+))(.*)`', $a, $m)){
780
+   if(preg_match('`^((?:"[^"]*")|(?:\'[^\']*\')|(?:\s*[^\s"\']+))(.*)`', $a, $m))
781
+   {
493 782
     $a = ltrim($m[2]); $m = $m[1]; $w = 1; $mode = 0;
494 783
     $aA[$nm] = trim(str_replace('<', '&lt;', ($m[0] == '"' or $m[0] == '\'') ? substr($m, 1, -1) : $m));
495 784
    }
496 785
   break;
497 786
  }
498
- if($w == 0){ // Parse errs, deal with space, " & '
787
+ if($w == 0)
788
+ {
789
+// Parse errs, deal with space, " & '
499 790
   $a = preg_replace('`^(?:"[^"]*("|$)|\'[^\']*(\'|$)|\S)*\s*`', '', $a);
500 791
   $mode = 0;
501 792
  }
502 793
 }
503
-if($mode == 1){$aA[$nm] = '';}
794
+if($mode == 1)
795
+{
796
+$aA[$nm] = '';}
504 797
 
505 798
 // clean attrs
506 799
 global $S;
507 800
 $rl = isset($S[$e]) ? $S[$e] : array();
508 801
 $a = array(); $nfr = 0;
509
-foreach($aA as $k=>$v){
510
-  if(((isset($C['deny_attribute']['*']) ? isset($C['deny_attribute'][$k]) : !isset($C['deny_attribute'][$k])) && (isset($aN[$k][$e]) or (isset($aNU[$k]) && !isset($aNU[$k][$e]))) && !isset($rl['n'][$k]) && !isset($rl['n']['*'])) or isset($rl[$k])){
511
-  if(isset($aNE[$k])){$v = $k;}
512
-  elseif(!empty($lcase) && (($e != 'button' or $e != 'input') or $k == 'type')){ // Rather loose but ?not cause issues
802
+foreach($aA as $k=>$v)
803
+{
804
+  if(((isset($C['deny_attribute']['*']) ? isset($C['deny_attribute'][$k]) : !isset($C['deny_attribute'][$k])) && (isset($aN[$k][$e]) or (isset($aNU[$k]) && !isset($aNU[$k][$e]))) && !isset($rl['n'][$k]) && !isset($rl['n']['*'])) or isset($rl[$k]))
805
+  {
806
+  if(isset($aNE[$k]))
807
+  {
808
+$v = $k;}
809
+  elseif(!empty($lcase) && (($e != 'button' or $e != 'input') or $k == 'type'))
810
+  {
811
+// Rather loose but ?not cause issues
513 812
    $v = (isset($aNL[($v2 = strtolower($v))])) ? $v2 : $v;
514 813
   }
515
-  if($k == 'style' && !$C['style_pass']){
516
-   if(false !== strpos($v, '&#')){
814
+  if($k == 'style' && !$C['style_pass'])
815
+  {
816
+   if(false !== strpos($v, '&#'))
817
+   {
517 818
     static $sC = array('&#x20;'=>' ', '&#32;'=>' ', '&#x45;'=>'e', '&#69;'=>'e', '&#x65;'=>'e', '&#101;'=>'e', '&#x58;'=>'x', '&#88;'=>'x', '&#x78;'=>'x', '&#120;'=>'x', '&#x50;'=>'p', '&#80;'=>'p', '&#x70;'=>'p', '&#112;'=>'p', '&#x53;'=>'s', '&#83;'=>'s', '&#x73;'=>'s', '&#115;'=>'s', '&#x49;'=>'i', '&#73;'=>'i', '&#x69;'=>'i', '&#105;'=>'i', '&#x4f;'=>'o', '&#79;'=>'o', '&#x6f;'=>'o', '&#111;'=>'o', '&#x4e;'=>'n', '&#78;'=>'n', '&#x6e;'=>'n', '&#110;'=>'n', '&#x55;'=>'u', '&#85;'=>'u', '&#x75;'=>'u', '&#117;'=>'u', '&#x52;'=>'r', '&#82;'=>'r', '&#x72;'=>'r', '&#114;'=>'r', '&#x4c;'=>'l', '&#76;'=>'l', '&#x6c;'=>'l', '&#108;'=>'l', '&#x28;'=>'(', '&#40;'=>'(', '&#x29;'=>')', '&#41;'=>')', '&#x20;'=>':', '&#32;'=>':', '&#x22;'=>'"', '&#34;'=>'"', '&#x27;'=>"'", '&#39;'=>"'", '&#x2f;'=>'/', '&#47;'=>'/', '&#x2a;'=>'*', '&#42;'=>'*', '&#x5c;'=>'\\', '&#92;'=>'\\');
518 819
     $v = strtr($v, $sC);
519 820
    }
520 821
    $v = preg_replace_callback('`(url(?:\()(?: )*(?:\'|"|&(?:quot|apos);)?)(.+?)((?:\'|"|&(?:quot|apos);)?(?: )*(?:\)))`iS', 'hl_prot', $v);
521 822
    $v = !$C['css_expression'] ? preg_replace('`expression`i', ' ', preg_replace('`\\\\\S|(/|(%2f))(\*|(%2a))`i', ' ', $v)) : $v;
522
-  }elseif(isset($aNP[$k]) or strpos($k, 'src') !== false or $k[0] == 'o'){
823
+  }
824
+  elseif(isset($aNP[$k]) or strpos($k, 'src') !== false or $k[0] == 'o')
825
+  {
523 826
    $v = str_replace("­", ' ', (strpos($v, '&') !== false ? str_replace(array('&#xad;', '&#173;', '&shy;'), ' ', $v) : $v)); # double-quoted char is soft-hyphen; appears here as "­" or hyphen or something else depending on viewing software
524 827
    $v = hl_prot($v, $k);
525
-   if($k == 'href'){ // X-spam
526
-    if($C['anti_mail_spam'] && strpos($v, 'mailto:') === 0){
828
+   if($k == 'href')
829
+   {
830
+// X-spam
831
+    if($C['anti_mail_spam'] && strpos($v, 'mailto:') === 0)
832
+    {
527 833
      $v = str_replace('@', htmlspecialchars($C['anti_mail_spam']), $v);
528
-    }elseif($C['anti_link_spam']){
834
+    }
835
+    elseif($C['anti_link_spam'])
836
+    {
529 837
      $r1 = $C['anti_link_spam'][1];
530
-     if(!empty($r1) && preg_match($r1, $v)){continue;}
838
+     if(!empty($r1) && preg_match($r1, $v))
839
+     {
840
+continue;}
531 841
      $r0 = $C['anti_link_spam'][0];
532
-     if(!empty($r0) && preg_match($r0, $v)){
533
-      if(isset($a['rel'])){
534
-       if(!preg_match('`\bnofollow\b`i', $a['rel'])){$a['rel'] .= ' nofollow';}
535
-      }elseif(isset($aA['rel'])){
536
-       if(!preg_match('`\bnofollow\b`i', $aA['rel'])){$nfr = 1;}
537
-      }else{$a['rel'] = 'nofollow';}
842
+     if(!empty($r0) && preg_match($r0, $v))
843
+     {
844
+      if(isset($a['rel']))
845
+      {
846
+       if(!preg_match('`\bnofollow\b`i', $a['rel']))
847
+       {
848
+$a['rel'] .= ' nofollow';}
849
+      }
850
+      elseif(isset($aA['rel']))
851
+      {
852
+       if(!preg_match('`\bnofollow\b`i', $aA['rel']))
853
+       {
854
+$nfr = 1;}
855
+      }
856
+      else
857
+      {
858
+$a['rel'] = 'nofollow';}
538 859
      }
539 860
     }
540 861
    }
541 862
   }
542
-  if(isset($rl[$k]) && is_array($rl[$k]) && ($v = hl_attrval($k, $v, $rl[$k])) === 0){continue;}
863
+  if(isset($rl[$k]) && is_array($rl[$k]) && ($v = hl_attrval($k, $v, $rl[$k])) === 0)
864
+  {
865
+continue;}
543 866
   $a[$k] = str_replace('"', '&quot;', $v);
544 867
  }
545 868
 }
546
-if($nfr){$a['rel'] = isset($a['rel']) ? $a['rel']. ' nofollow' : 'nofollow';}
869
+if($nfr)
870
+{
871
+$a['rel'] = isset($a['rel']) ? $a['rel']. ' nofollow' : 'nofollow';}
547 872
 
548 873
 // rqd attr
549 874
 static $eAR = array('area'=>array('alt'=>'area'), 'bdo'=>array('dir'=>'ltr'), 'form'=>array('action'=>''), 'img'=>array('src'=>'', 'alt'=>'image'), 'map'=>array('name'=>''), 'optgroup'=>array('label'=>''), 'param'=>array('name'=>''), 'script'=>array('type'=>'text/javascript'), 'textarea'=>array('rows'=>'10', 'cols'=>'50'));
550
-if(isset($eAR[$e])){
551
- foreach($eAR[$e] as $k=>$v){
552
-  if(!isset($a[$k])){$a[$k] = isset($v[0]) ? $v : $k;}
875
+if(isset($eAR[$e]))
876
+{
877
+ foreach($eAR[$e] as $k=>$v)
878
+ {
879
+  if(!isset($a[$k]))
880
+  {
881
+$a[$k] = isset($v[0]) ? $v : $k;}
553 882
  }
554 883
 }
555 884
 
556 885
 // depr attrs
557
-if($depTr){
886
+if($depTr)
887
+{
558 888
  $c = array();
559
- foreach($a as $k=>$v){
560
-  if($k == 'style' or !isset($aND[$k][$e])){continue;}
561
-  if($k == 'align'){
889
+ foreach($a as $k=>$v)
890
+ {
891
+  if($k == 'style' or !isset($aND[$k][$e]))
892
+  {
893
+continue;}
894
+  if($k == 'align')
895
+  {
562 896
    unset($a['align']);
563
-   if($e == 'img' && ($v == 'left' or $v == 'right')){$c[] = 'float: '. $v;}
564
-   elseif(($e == 'div' or $e == 'table') && $v == 'center'){$c[] = 'margin: auto';}
565
-   else{$c[] = 'text-align: '. $v;}
566
-  }elseif($k == 'bgcolor'){
897
+   if($e == 'img' && ($v == 'left' or $v == 'right'))
898
+   {
899
+$c[] = 'float: '. $v;}
900
+   elseif(($e == 'div' or $e == 'table') && $v == 'center')
901
+   {
902
+$c[] = 'margin: auto';}
903
+   else
904
+   {
905
+$c[] = 'text-align: '. $v;}
906
+  }
907
+  elseif($k == 'bgcolor')
908
+  {
567 909
    unset($a['bgcolor']);
568 910
    $c[] = 'background-color: '. $v;
569
-  }elseif($k == 'border'){
911
+  }
912
+  elseif($k == 'border')
913
+  {
570 914
    unset($a['border']); $c[] = "border: {$v}px";
571
-  }elseif($k == 'bordercolor'){
915
+  }
916
+  elseif($k == 'bordercolor')
917
+  {
572 918
    unset($a['bordercolor']); $c[] = 'border-color: '. $v;
573
-  }elseif($k == 'clear'){
919
+  }
920
+  elseif($k == 'clear')
921
+  {
574 922
    unset($a['clear']); $c[] = 'clear: '. ($v != 'all' ? $v : 'both');
575
-  }elseif($k == 'compact'){
923
+  }
924
+  elseif($k == 'compact')
925
+  {
576 926
    unset($a['compact']); $c[] = 'font-size: 85%';
577
-  }elseif($k == 'height' or $k == 'width'){
927
+  }
928
+  elseif($k == 'height' or $k == 'width')
929
+  {
578 930
    unset($a[$k]); $c[] = $k. ': '. ($v[0] != '*' ? $v. (ctype_digit($v) ? 'px' : '') : 'auto');
579
-  }elseif($k == 'hspace'){
931
+  }
932
+  elseif($k == 'hspace')
933
+  {
580 934
    unset($a['hspace']); $c[] = "margin-left: {$v}px; margin-right: {$v}px";
581
-  }elseif($k == 'language' && !isset($a['type'])){
935
+  }
936
+  elseif($k == 'language' && !isset($a['type']))
937
+  {
582 938
    unset($a['language']);
583 939
    $a['type'] = 'text/'. strtolower($v);
584
-  }elseif($k == 'name'){
585
-   if($C['no_deprecated_attr'] == 2 or ($e != 'a' && $e != 'map')){unset($a['name']);}
586
-   if(!isset($a['id']) && preg_match('`[a-zA-Z][a-zA-Z\d.:_\-]*`', $v)){$a['id'] = $v;}
587
-  }elseif($k == 'noshade'){
940
+  }
941
+  elseif($k == 'name')
942
+  {
943
+   if($C['no_deprecated_attr'] == 2 or ($e != 'a' && $e != 'map'))
944
+   {
945
+unset($a['name']);}
946
+   if(!isset($a['id']) && preg_match('`[a-zA-Z][a-zA-Z\d.:_\-]*`', $v))
947
+   {
948
+$a['id'] = $v;}
949
+  }
950
+  elseif($k == 'noshade')
951
+  {
588 952
    unset($a['noshade']); $c[] = 'border-style: none; border: 0; background-color: gray; color: gray';
589
-  }elseif($k == 'nowrap'){
953
+  }
954
+  elseif($k == 'nowrap')
955
+  {
590 956
    unset($a['nowrap']); $c[] = 'white-space: nowrap';
591
-  }elseif($k == 'size'){
957
+  }
958
+  elseif($k == 'size')
959
+  {
592 960
    unset($a['size']); $c[] = 'size: '. $v. 'px';
593
-  }elseif($k == 'start' or $k == 'value'){
961
+  }
962
+  elseif($k == 'start' or $k == 'value')
963
+  {
594 964
    unset($a[$k]);
595
-  }elseif($k == 'type'){
965
+  }
966
+  elseif($k == 'type')
967
+  {
596 968
    unset($a['type']);
597 969
    static $ol_type = array('i'=>'lower-roman', 'I'=>'upper-roman', 'a'=>'lower-latin', 'A'=>'upper-latin', '1'=>'decimal');
598 970
    $c[] = 'list-style-type: '. (isset($ol_type[$v]) ? $ol_type[$v] : 'decimal');
599
-  }elseif($k == 'vspace'){
971
+  }
972
+  elseif($k == 'vspace')
973
+  {
600 974
    unset($a['vspace']); $c[] = "margin-top: {$v}px; margin-bottom: {$v}px";
601 975
   }
602 976
  }
603
- if(count($c)){
977
+ if(count($c))
978
+ {
604 979
   $c = implode('; ', $c);
605 980
   $a['style'] = isset($a['style']) ? rtrim($a['style'], ' ;'). '; '. $c. ';': $c. ';';
606 981
  }
607 982
 }
608 983
 // unique ID
609
-if($C['unique_ids'] && isset($a['id'])){
610
- if(!preg_match('`^[A-Za-z][A-Za-z0-9_\-.:]*$`', ($id = $a['id'])) or (isset($GLOBALS['hl_Ids'][$id]) && $C['unique_ids'] == 1)){unset($a['id']);
611
- }else{
612
-  while(isset($GLOBALS['hl_Ids'][$id])){$id = $C['unique_ids']. $id;}
984
+if($C['unique_ids'] && isset($a['id']))
985
+{
986
+ if(!preg_match('`^[A-Za-z][A-Za-z0-9_\-.:]*$`', ($id = $a['id'])) or (isset($GLOBALS['hl_Ids'][$id]) && $C['unique_ids'] == 1))
987
+ {
988
+unset($a['id']);
989
+ }
990
+ else
991
+ {
992
+  while(isset($GLOBALS['hl_Ids'][$id]))
993
+  {
994
+$id = $C['unique_ids']. $id;}
613 995
   $GLOBALS['hl_Ids'][($a['id'] = $id)] = 1;
614 996
  }
615 997
 }
616 998
 // xml:lang
617
-if($C['xml:lang'] && isset($a['lang'])){
999
+if($C['xml:lang'] && isset($a['lang']))
1000
+{
618 1001
  $a['xml:lang'] = isset($a['xml:lang']) ? $a['xml:lang'] : $a['lang'];
619
- if($C['xml:lang'] == 2){unset($a['lang']);}
1002
+ if($C['xml:lang'] == 2)
1003
+ {
1004
+unset($a['lang']);}
620 1005
 }
621 1006
 // for transformed tag
622
-if(!empty($trt)){
1007
+if(!empty($trt))
1008
+{
623 1009
  $a['style'] = isset($a['style']) ? rtrim($a['style'], ' ;'). '; '. $trt : $trt;
624 1010
 }
625 1011
 // return with empty ele /
626
-if(empty($C['hook_tag'])){
1012
+if(empty($C['hook_tag']))
1013
+{
627 1014
  $aA = '';
628
- foreach($a as $k=>$v){$aA .= " {$k}=\"{$v}\"";}
1015
+ foreach($a as $k=>$v)
1016
+ {
1017
+$aA .= " {$k}=\"{$v}\"";}
629 1018
  return "<{$e}{$aA}". (isset($eE[$e]) ? ' /' : ''). '>';
630 1019
 }
631
-else{return $C['hook_tag']($e, $a);}
1020
+else
1021
+{
1022
+return $C['hook_tag']($e, $a);}
632 1023
 // eof
633 1024
 }
634 1025
 
635
-function hl_tag2(&$e, &$a, $t=1){
1026
+function hl_tag2(&$e, &$a, $t=1)
1027
+{
636 1028
 // transform tag
637
-if($e == 'center'){$e = 'div'; return 'text-align: center;';}
638
-if($e == 'dir' or $e == 'menu'){$e = 'ul'; return '';}
639
-if($e == 's' or $e == 'strike'){$e = 'span'; return 'text-decoration: line-through;';}
640
-if($e == 'u'){$e = 'span'; return 'text-decoration: underline;';}
1029
+if($e == 'center')
1030
+{
1031
+$e = 'div'; return 'text-align: center;';}
1032
+if($e == 'dir' or $e == 'menu')
1033
+{
1034
+$e = 'ul'; return '';}
1035
+if($e == 's' or $e == 'strike')
1036
+{
1037
+$e = 'span'; return 'text-decoration: line-through;';}
1038
+if($e == 'u')
1039
+{
1040
+$e = 'span'; return 'text-decoration: underline;';}
641 1041
 static $fs = array('0'=>'xx-small', '1'=>'xx-small', '2'=>'small', '3'=>'medium', '4'=>'large', '5'=>'x-large', '6'=>'xx-large', '7'=>'300%', '-1'=>'smaller', '-2'=>'60%', '+1'=>'larger', '+2'=>'150%', '+3'=>'200%', '+4'=>'300%');
642
-if($e == 'font' && $t !=3){//3 is a new make_tag_strict config value, to indicate that transformation is to be performed, but don't transform font, as size transformation of numeric sizes to keywords alters the intended result too much
1042
+if($e == 'font' && $t !=3)
1043
+{
1044
+//3 is a new make_tag_strict config value, to indicate that transformation is to be performed, but don't transform font, as size transformation of numeric sizes to keywords alters the intended result too much
643 1045
  $a2 = '';
644
- while(preg_match('`(^|\s)(color|size)\s*=\s*(\'|")?(.+?)(\\3|\s|$)`i', $a, $m)){
1046
+ while(preg_match('`(^|\s)(color|size)\s*=\s*(\'|")?(.+?)(\\3|\s|$)`i', $a, $m))
1047
+ {
645 1048
   $a = str_replace($m[0], ' ', $a);
646 1049
   $a2 .= strtolower($m[2]) == 'color' ? (' color: '. str_replace('"', '\'', trim($m[4])). ';') : (isset($fs[($m = trim($m[4]))]) ? ($a2 .= ' font-size: '. str_replace('"', '\'', $fs[$m]). ';') : '');
647 1050
  }
648
- while(preg_match('`(^|\s)face\s*=\s*(\'|")?([^=]+?)\\2`i', $a, $m) or preg_match('`(^|\s)face\s*=(\s*)(\S+)`i', $a, $m)){
1051
+ while(preg_match('`(^|\s)face\s*=\s*(\'|")?([^=]+?)\\2`i', $a, $m) or preg_match('`(^|\s)face\s*=(\s*)(\S+)`i', $a, $m))
1052
+ {
649 1053
   $a = str_replace($m[0], ' ', $a);
650 1054
   $a2 .= ' font-family: '. str_replace('"', '\'', trim($m[3])). ';';
651 1055
  }
652 1056
  $e = 'span'; return ltrim(str_replace('<', '', $a2));
653 1057
 }
654
-if($t == 2){$e = 0; return 0;}
1058
+if($t == 2)
1059
+{
1060
+$e = 0; return 0;}
655 1061
 return '';
656 1062
 // eof
657 1063
 }
658 1064
 
659
-function hl_tidy($t, $w, $p){
1065
+function hl_tidy($t, $w, $p)
1066
+{
660 1067
 // Tidy/compact HTM
661
-if(strpos(' pre,script,textarea', "$p,")){return $t;}
1068
+if(strpos(' pre,script,textarea', "$p,"))
1069
+{
1070
+return $t;}
662 1071
 $t = preg_replace('`\s+`', ' ', preg_replace_callback(array('`(<(!\[CDATA\[))(.+?)(\]\]>)`sm', '`(<(!--))(.+?)(-->)`sm', '`(<(pre|script|textarea)[^>]*?>)(.+?)(</\2>)`sm'), create_function('$m', 'return $m[1]. str_replace(array("<", ">", "\n", "\r", "\t", " "), array("\x01", "\x02", "\x03", "\x04", "\x05", "\x07"), $m[3]). $m[4];'), $t));
663
-if(($w = strtolower($w)) == -1){
1072
+if(($w = strtolower($w)) == -1)
1073
+{
664 1074
  return str_replace(array("\x01", "\x02", "\x03", "\x04", "\x05", "\x07"), array('<', '>', "\n", "\r", "\t", ' '), $t);
665 1075
 }
666 1076
 $s = strpos(" $w", 't') ? "\t" : ' ';
@@ -672,54 +1082,87 @@  discard block
 block discarded – undo
672 1082
 $d = array('address'=>1, 'blockquote'=>1, 'center'=>1, 'colgroup'=>1, 'dir'=>1, 'div'=>1, 'dl'=>1, 'fieldset'=>1, 'form'=>1, 'hr'=>1, 'iframe'=>1, 'map'=>1, 'menu'=>1, 'noscript'=>1, 'ol'=>1, 'optgroup'=>1, 'rbc'=>1, 'rtc'=>1, 'ruby'=>1, 'script'=>1, 'select'=>1, 'table'=>1, 'tbody'=>1, 'tfoot'=>1, 'thead'=>1, 'tr'=>1, 'ul'=>1);
673 1083
 $T = explode('<', $t);
674 1084
 $X = 1;
675
-while($X){
1085
+while($X)
1086
+{
676 1087
  $n = $N;
677 1088
  $t = $T;
678 1089
  ob_start();
679
- if(isset($d[$p])){echo str_repeat($s, ++$n);}
1090
+ if(isset($d[$p]))
1091
+ {
1092
+echo str_repeat($s, ++$n);}
680 1093
  echo ltrim(array_shift($t));
681
- for($i=-1, $j=count($t); ++$i<$j;){
1094
+ for($i=-1, $j=count($t); ++$i<$j;)
1095
+ {
682 1096
   $r = ''; list($e, $r) = explode('>', $t[$i]);
683 1097
   $x = $e[0] == '/' ? 0 : (substr($e, -1) == '/' ? 1 : ($e[0] != '!' ? 2 : -1));
684 1098
   $y = !$x ? ltrim($e, '/') : ($x > 0 ? substr($e, 0, strcspn($e, ' ')) : 0);
685 1099
   $e = "<$e>";
686
-  if(isset($d[$y])){
687
-   if(!$x){
688
-    if($n){echo "\n", str_repeat($s, --$n), "$e\n", str_repeat($s, $n);}
689
-    else{++$N; ob_end_clean(); continue 2;}
1100
+  if(isset($d[$y]))
1101
+  {
1102
+   if(!$x)
1103
+   {
1104
+    if($n)
1105
+    {
1106
+echo "\n", str_repeat($s, --$n), "$e\n", str_repeat($s, $n);}
1107
+    else
1108
+    {
1109
+++$N; ob_end_clean(); continue 2;}
690 1110
    }
691
-   else{echo "\n", str_repeat($s, $n), "$e\n", str_repeat($s, ($x != 1 ? ++$n : $n));}
1111
+   else
1112
+   {
1113
+echo "\n", str_repeat($s, $n), "$e\n", str_repeat($s, ($x != 1 ? ++$n : $n));}
692 1114
    echo $r; continue;
693 1115
   }
694 1116
   $f = "\n". str_repeat($s, $n);
695
-  if(isset($c[$y])){
696
-   if(!$x){echo $e, $f, $r;}
697
-   else{echo $f, $e, $r;}
698
-  }elseif(isset($b[$y])){echo $f, $e, $r;
699
-  }elseif(isset($a[$y])){echo $e, $f, $r;
700
-  }elseif(!$y){echo $f, $e, $f, $r;
701
-  }else{echo $e, $r;}
1117
+  if(isset($c[$y]))
1118
+  {
1119
+   if(!$x)
1120
+   {
1121
+echo $e, $f, $r;}
1122
+   else
1123
+   {
1124
+echo $f, $e, $r;}
1125
+  }
1126
+  elseif(isset($b[$y]))
1127
+  {
1128
+echo $f, $e, $r;
1129
+  }
1130
+  elseif(isset($a[$y]))
1131
+  {
1132
+echo $e, $f, $r;
1133
+  }
1134
+  elseif(!$y)
1135
+  {
1136
+echo $f, $e, $f, $r;
1137
+  }
1138
+  else
1139
+  {
1140
+echo $e, $r;}
702 1141
  }
703 1142
  $X = 0;
704 1143
 }
705 1144
 $t = str_replace(array("\n ", " \n"), "\n", preg_replace('`[\n]\s*?[\n]+`', "\n", ob_get_contents()));
706 1145
 ob_end_clean();
707
-if(($l = strpos(" $w", 'r') ? (strpos(" $w", 'n') ? "\r\n" : "\r") : 0)){
1146
+if(($l = strpos(" $w", 'r') ? (strpos(" $w", 'n') ? "\r\n" : "\r") : 0))
1147
+{
708 1148
  $t = str_replace("\n", $l, $t);
709 1149
 }
710 1150
 return str_replace(array("\x01", "\x02", "\x03", "\x04", "\x05", "\x07"), array('<', '>', "\n", "\r", "\t", ' '), $t);
711 1151
 // eof
712 1152
 }
713 1153
 
714
-function hl_version(){
1154
+function hl_version()
1155
+{
715 1156
 // rel
716 1157
 return '1.1.22';
717 1158
 // eof
718 1159
 }
719 1160
 
720
-function kses($t, $h, $p=array('http', 'https', 'ftp', 'news', 'nntp', 'telnet', 'gopher', 'mailto')){
1161
+function kses($t, $h, $p=array('http', 'https', 'ftp', 'news', 'nntp', 'telnet', 'gopher', 'mailto'))
1162
+{
721 1163
 // kses compat
722
-foreach($h as $k=>$v){
1164
+foreach($h as $k=>$v)
1165
+{
723 1166
  $h[$k]['n']['*'] = 1;
724 1167
 }
725 1168
 $C['cdata'] = $C['comment'] = $C['make_tag_strict'] = $C['no_deprecated_attr'] = $C['unique_ids'] = 0;
@@ -731,7 +1174,8 @@  discard block
 block discarded – undo
731 1174
 // eof
732 1175
 }
733 1176
 
734
-function kses_hook($t, &$C, &$S){
1177
+function kses_hook($t, &$C, &$S)
1178
+{
735 1179
 // kses compat
736 1180
 return $t;
737 1181
 // eof
Please login to merge, or discard this patch.
Spacing   +292 added lines, -292 removed lines patch added patch discarded remove patch
@@ -9,36 +9,36 @@  discard block
 block discarded – undo
9 9
 See htmLawed_README.txt/htm
10 10
 */
11 11
 
12
-function htmLawed($t, $C=1, $S=array()){
12
+function htmLawed($t, $C = 1, $S = array()) {
13 13
 $C = is_array($C) ? $C : array();
14
-if(!empty($C['valid_xhtml'])){
14
+if (!empty($C['valid_xhtml'])) {
15 15
  $C['elements'] = empty($C['elements']) ? '*-center-dir-font-isindex-menu-s-strike-u' : $C['elements'];
16 16
  $C['make_tag_strict'] = isset($C['make_tag_strict']) ? $C['make_tag_strict'] : 2;
17 17
  $C['xml:lang'] = isset($C['xml:lang']) ? $C['xml:lang'] : 2;
18 18
 }
19 19
 // config eles
20 20
 $e = array('a'=>1, 'abbr'=>1, 'acronym'=>1, 'address'=>1, 'applet'=>1, 'area'=>1, 'b'=>1, 'bdo'=>1, 'big'=>1, 'blockquote'=>1, 'br'=>1, 'button'=>1, 'caption'=>1, 'center'=>1, 'cite'=>1, 'code'=>1, 'col'=>1, 'colgroup'=>1, 'dd'=>1, 'del'=>1, 'dfn'=>1, 'dir'=>1, 'div'=>1, 'dl'=>1, 'dt'=>1, 'em'=>1, 'embed'=>1, 'fieldset'=>1, 'font'=>1, 'form'=>1, 'h1'=>1, 'h2'=>1, 'h3'=>1, 'h4'=>1, 'h5'=>1, 'h6'=>1, 'hr'=>1, 'i'=>1, 'iframe'=>1, 'img'=>1, 'input'=>1, 'ins'=>1, 'isindex'=>1, 'kbd'=>1, 'label'=>1, 'legend'=>1, 'li'=>1, 'map'=>1, 'menu'=>1, 'noscript'=>1, 'object'=>1, 'ol'=>1, 'optgroup'=>1, 'option'=>1, 'p'=>1, 'param'=>1, 'pre'=>1, 'q'=>1, 'rb'=>1, 'rbc'=>1, 'rp'=>1, 'rt'=>1, 'rtc'=>1, 'ruby'=>1, 's'=>1, 'samp'=>1, 'script'=>1, 'select'=>1, 'small'=>1, 'span'=>1, 'strike'=>1, 'strong'=>1, 'sub'=>1, 'sup'=>1, 'table'=>1, 'tbody'=>1, 'td'=>1, 'textarea'=>1, 'tfoot'=>1, 'th'=>1, 'thead'=>1, 'tr'=>1, 'tt'=>1, 'u'=>1, 'ul'=>1, 'var'=>1); // 86/deprecated+embed+ruby
21
-if(!empty($C['safe'])){
21
+if (!empty($C['safe'])) {
22 22
  unset($e['applet'], $e['embed'], $e['iframe'], $e['object'], $e['script']);
23 23
 }
24 24
 $x = !empty($C['elements']) ? str_replace(array("\n", "\r", "\t", ' '), '', $C['elements']) : '*';
25
-if($x == '-*'){$e = array();}
26
-elseif(strpos($x, '*') === false){$e = array_flip(explode(',', $x));}
27
-else{
28
- if(isset($x[1])){
25
+if ($x == '-*') {$e = array(); }
26
+elseif (strpos($x, '*') === false) {$e = array_flip(explode(',', $x)); }
27
+else {
28
+ if (isset($x[1])) {
29 29
   preg_match_all('`(?:^|-|\+)[^\-+]+?(?=-|\+|$)`', $x, $m, PREG_SET_ORDER);
30
-  for($i=count($m); --$i>=0;){$m[$i] = $m[$i][0];}
31
-  foreach($m as $v){
32
-   if($v[0] == '+'){$e[substr($v, 1)] = 1;}
33
-   if($v[0] == '-' && isset($e[($v = substr($v, 1))]) && !in_array('+'. $v, $m)){unset($e[$v]);}
30
+  for ($i = count($m); --$i >= 0;) {$m[$i] = $m[$i][0]; }
31
+  foreach ($m as $v) {
32
+   if ($v[0] == '+') {$e[substr($v, 1)] = 1; }
33
+   if ($v[0] == '-' && isset($e[($v = substr($v, 1))]) && !in_array('+'.$v, $m)) {unset($e[$v]); }
34 34
   }
35 35
  }
36 36
 }
37
-$C['elements'] =& $e;
37
+$C['elements'] = & $e;
38 38
 // config attrs
39 39
 $x = !empty($C['deny_attribute']) ? str_replace(array("\n", "\r", "\t", ' '), '', $C['deny_attribute']) : '';
40
-$x = array_flip((isset($x[0]) && $x[0] == '*') ? explode('-', $x) : explode(',', $x. (!empty($C['safe']) ? ',on*' : '')));
41
-if(isset($x['on*'])){
40
+$x = array_flip((isset($x[0]) && $x[0] == '*') ? explode('-', $x) : explode(',', $x.(!empty($C['safe']) ? ',on*' : '')));
41
+if (isset($x['on*'])) {
42 42
  unset($x['on*']);
43 43
  $x += array('onblur'=>1, 'onchange'=>1, 'onclick'=>1, 'ondblclick'=>1, 'onfocus'=>1, 'onkeydown'=>1, 'onkeypress'=>1, 'onkeyup'=>1, 'onmousedown'=>1, 'onmousemove'=>1, 'onmouseout'=>1, 'onmouseover'=>1, 'onmouseup'=>1, 'onreset'=>1, 'onselect'=>1, 'onsubmit'=>1);
44 44
 }
@@ -46,14 +46,14 @@  discard block
 block discarded – undo
46 46
 // config URL
47 47
 $x = (isset($C['schemes'][2]) && strpos($C['schemes'], ':')) ? strtolower($C['schemes']) : 'href: aim, feed, file, ftp, gopher, http, https, irc, mailto, news, nntp, sftp, ssh, telnet; *:file, http, https';
48 48
 $C['schemes'] = array();
49
-foreach(explode(';', str_replace(array(' ', "\t", "\r", "\n"), '', $x)) as $v){
49
+foreach (explode(';', str_replace(array(' ', "\t", "\r", "\n"), '', $x)) as $v) {
50 50
  $x = $x2 = null; list($x, $x2) = explode(':', $v, 2);
51
- if($x2){$C['schemes'][$x] = array_flip(explode(',', $x2));}
51
+ if ($x2) {$C['schemes'][$x] = array_flip(explode(',', $x2)); }
52 52
 }
53
-if(!isset($C['schemes']['*'])){$C['schemes']['*'] = array('file'=>1, 'http'=>1, 'https'=>1,);}
54
-if(!empty($C['safe']) && empty($C['schemes']['style'])){$C['schemes']['style'] = array('!'=>1);}
53
+if (!isset($C['schemes']['*'])) {$C['schemes']['*'] = array('file'=>1, 'http'=>1, 'https'=>1,); }
54
+if (!empty($C['safe']) && empty($C['schemes']['style'])) {$C['schemes']['style'] = array('!'=>1); }
55 55
 $C['abs_url'] = isset($C['abs_url']) ? $C['abs_url'] : 0;
56
-if(!isset($C['base_url']) or !preg_match('`^[a-zA-Z\d.+\-]+://[^/]+/(.+?/)?$`', $C['base_url'])){
56
+if (!isset($C['base_url']) or !preg_match('`^[a-zA-Z\d.+\-]+://[^/]+/(.+?/)?$`', $C['base_url'])) {
57 57
  $C['base_url'] = $C['abs_url'] = 0;
58 58
 }
59 59
 // config rest
@@ -82,25 +82,25 @@  discard block
 block discarded – undo
82 82
 $C['xml:lang'] = isset($C['xml:lang']) ? $C['xml:lang'] : 0;
83 83
 // own config options
84 84
 // block elements allowed for nesting when only inline is allowed; Example span does not allow block elements as table; table is the only element tested so far
85
-$C['allow_for_inline'] = isset($C['allow_for_inline'])?$C['allow_for_inline']:0;
85
+$C['allow_for_inline'] = isset($C['allow_for_inline']) ? $C['allow_for_inline'] : 0;
86 86
 
87
-if(isset($GLOBALS['C'])){$reC = $GLOBALS['C'];}
87
+if (isset($GLOBALS['C'])) {$reC = $GLOBALS['C']; }
88 88
 $GLOBALS['C'] = $C;
89 89
 $S = is_array($S) ? $S : hl_spec($S);
90
-if(isset($GLOBALS['S'])){$reS = $GLOBALS['S'];}
90
+if (isset($GLOBALS['S'])) {$reS = $GLOBALS['S']; }
91 91
 $GLOBALS['S'] = $S;
92 92
 
93 93
 $t = preg_replace('`[\x00-\x08\x0b-\x0c\x0e-\x1f]`', '', $t);
94
-if($C['clean_ms_char']){
94
+if ($C['clean_ms_char']) {
95 95
  $x = array("\x7f"=>'', "\x80"=>'&#8364;', "\x81"=>'', "\x83"=>'&#402;', "\x85"=>'&#8230;', "\x86"=>'&#8224;', "\x87"=>'&#8225;', "\x88"=>'&#710;', "\x89"=>'&#8240;', "\x8a"=>'&#352;', "\x8b"=>'&#8249;', "\x8c"=>'&#338;', "\x8d"=>'', "\x8e"=>'&#381;', "\x8f"=>'', "\x90"=>'', "\x95"=>'&#8226;', "\x96"=>'&#8211;', "\x97"=>'&#8212;', "\x98"=>'&#732;', "\x99"=>'&#8482;', "\x9a"=>'&#353;', "\x9b"=>'&#8250;', "\x9c"=>'&#339;', "\x9d"=>'', "\x9e"=>'&#382;', "\x9f"=>'&#376;');
96 96
  $x = $x + ($C['clean_ms_char'] == 1 ? array("\x82"=>'&#8218;', "\x84"=>'&#8222;', "\x91"=>'&#8216;', "\x92"=>'&#8217;', "\x93"=>'&#8220;', "\x94"=>'&#8221;') : array("\x82"=>'\'', "\x84"=>'"', "\x91"=>'\'', "\x92"=>'\'', "\x93"=>'"', "\x94"=>'"'));
97 97
  $t = strtr($t, $x);
98 98
 }
99
-if($C['cdata'] or $C['comment']){$t = preg_replace_callback('`<!(?:(?:--.*?--)|(?:\[CDATA\[.*?\]\]))>`sm', 'hl_cmtcd', $t);}
99
+if ($C['cdata'] or $C['comment']) {$t = preg_replace_callback('`<!(?:(?:--.*?--)|(?:\[CDATA\[.*?\]\]))>`sm', 'hl_cmtcd', $t); }
100 100
 $t = preg_replace_callback('`&amp;([A-Za-z][A-Za-z0-9]{1,30}|#(?:[0-9]{1,8}|[Xx][0-9A-Fa-f]{1,7}));`', 'hl_ent', str_replace('&', '&amp;', $t));
101
-if($C['unique_ids'] && !isset($GLOBALS['hl_Ids'])){$GLOBALS['hl_Ids'] = array();}
102
-if($C['hook']){$t = $C['hook']($t, $C, $S);}
103
-if($C['show_setting'] && preg_match('`^[a-z][a-z0-9_]*$`i', $C['show_setting'])){
101
+if ($C['unique_ids'] && !isset($GLOBALS['hl_Ids'])) {$GLOBALS['hl_Ids'] = array(); }
102
+if ($C['hook']) {$t = $C['hook']($t, $C, $S); }
103
+if ($C['show_setting'] && preg_match('`^[a-z][a-z0-9_]*$`i', $C['show_setting'])) {
104 104
  $GLOBALS[$C['show_setting']] = array('config'=>$C, 'spec'=>$S, 'time'=>microtime());
105 105
 }
106 106
 // main
@@ -109,49 +109,49 @@  discard block
 block discarded – undo
109 109
 $t = (($C['cdata'] or $C['comment']) && strpos($t, "\x01") !== false) ? str_replace(array("\x01", "\x02", "\x03", "\x04", "\x05"), array('', '', '&', '<', '>'), $t) : $t;
110 110
 $t = $C['tidy'] ? hl_tidy($t, $C['tidy'], $C['parent']) : $t;
111 111
 unset($C, $e);
112
-if(isset($reC)){$GLOBALS['C'] = $reC;}
113
-if(isset($reS)){$GLOBALS['S'] = $reS;}
112
+if (isset($reC)) {$GLOBALS['C'] = $reC; }
113
+if (isset($reS)) {$GLOBALS['S'] = $reS; }
114 114
 return $t;
115 115
 // eof
116 116
 }
117 117
 
118
-function hl_attrval($a, $t, $p){
118
+function hl_attrval($a, $t, $p) {
119 119
 // check attr val against $S
120 120
 static $ma = array('accesskey', 'class', 'rel');
121 121
 $s = in_array($a, $ma) ? ' ' : '';
122 122
 $r = array();
123 123
 $t = !empty($s) ? explode($s, $t) : array($t);
124
-foreach($t as $tk=>$tv){
124
+foreach ($t as $tk=>$tv) {
125 125
  $o = 1; $l = strlen($tv);
126
- foreach($p as $k=>$v){
127
-  switch($k){
128
-   case 'maxlen': if($l > $v){$o = 0;}
129
-   break; case 'minlen': if($l < $v){$o = 0;}
130
-   break; case 'maxval': if((float)($tv) > $v){$o = 0;}
131
-   break; case 'minval': if((float)($tv) < $v){$o = 0;}
132
-   break; case 'match': if(!preg_match($v, $tv)){$o = 0;}
133
-   break; case 'nomatch': if(preg_match($v, $tv)){$o = 0;}
126
+ foreach ($p as $k=>$v) {
127
+  switch ($k) {
128
+   case 'maxlen': if ($l > $v) {$o = 0; }
129
+   break; case 'minlen': if ($l < $v) {$o = 0; }
130
+   break; case 'maxval': if ((float)($tv) > $v) {$o = 0; }
131
+   break; case 'minval': if ((float)($tv) < $v) {$o = 0; }
132
+   break; case 'match': if (!preg_match($v, $tv)) {$o = 0; }
133
+   break; case 'nomatch': if (preg_match($v, $tv)) {$o = 0; }
134 134
    break; case 'oneof':
135 135
     $m = 0;
136
-    foreach(explode('|', $v) as $n){if($tv == $n){$m = 1; break;}}
136
+    foreach (explode('|', $v) as $n) {if ($tv == $n) {$m = 1; break; }}
137 137
     $o = $m;
138 138
    break; case 'noneof':
139 139
     $m = 1;
140
-    foreach(explode('|', $v) as $n){if($tv == $n){$m = 0; break;}}
140
+    foreach (explode('|', $v) as $n) {if ($tv == $n) {$m = 0; break; }}
141 141
     $o = $m;
142 142
    break; default:
143 143
    break;
144 144
   }
145
-  if(!$o){break;}
145
+  if (!$o) {break; }
146 146
  }
147
- if($o){$r[] = $tv;}
147
+ if ($o) {$r[] = $tv; }
148 148
 }
149 149
 $r = implode($s, $r);
150 150
 return (isset($r[0]) ? $r : (isset($p['default']) ? $p['default'] : 0));
151 151
 // eof
152 152
 }
153 153
 
154
-function hl_bal($t, $do=1, $in='div'){
154
+function hl_bal($t, $do = 1, $in = 'div') {
155 155
 // balance tags
156 156
 // by content
157 157
 $cB = array('blockquote'=>1, 'form'=>1, 'map'=>1, 'noscript'=>1); // Block
@@ -162,212 +162,212 @@  discard block
 block discarded – undo
162 162
 $cN2 = array_keys($cN);
163 163
 $cR = array('blockquote'=>1, 'dir'=>1, 'dl'=>1, 'form'=>1, 'map'=>1, 'menu'=>1, 'noscript'=>1, 'ol'=>1, 'optgroup'=>1, 'rbc'=>1, 'rtc'=>1, 'ruby'=>1, 'select'=>1, 'table'=>1, 'tbody'=>1, 'tfoot'=>1, 'thead'=>1, 'tr'=>1, 'ul'=>1);
164 164
 $cS = array('colgroup'=>array('col'=>1), 'dir'=>array('li'=>1), 'dl'=>array('dd'=>1, 'dt'=>1), 'menu'=>array('li'=>1), 'ol'=>array('li'=>1), 'optgroup'=>array('option'=>1), 'option'=>array('#pcdata'=>1), 'rbc'=>array('rb'=>1), 'rp'=>array('#pcdata'=>1), 'rtc'=>array('rt'=>1), 'ruby'=>array('rb'=>1, 'rbc'=>1, 'rp'=>1, 'rt'=>1, 'rtc'=>1), 'select'=>array('optgroup'=>1, 'option'=>1), 'script'=>array('#pcdata'=>1), 'table'=>array('caption'=>1, 'col'=>1, 'colgroup'=>1, 'tfoot'=>1, 'tbody'=>1, 'tr'=>1, 'thead'=>1), 'tbody'=>array('tr'=>1), 'tfoot'=>array('tr'=>1), 'textarea'=>array('#pcdata'=>1), 'thead'=>array('tr'=>1), 'tr'=>array('td'=>1, 'th'=>1), 'ul'=>array('li'=>1)); // Specific - immediate parent-child
165
-if($GLOBALS['C']['direct_list_nest']){$cS['ol'] = $cS['ul'] += array('ol'=>1, 'ul'=>1);}
165
+if ($GLOBALS['C']['direct_list_nest']) {$cS['ol'] = $cS['ul'] += array('ol'=>1, 'ul'=>1); }
166 166
 $cO = array('address'=>array('p'=>1), 'applet'=>array('param'=>1), 'blockquote'=>array('script'=>1), 'fieldset'=>array('legend'=>1, '#pcdata'=>1), 'form'=>array('script'=>1), 'map'=>array('area'=>1), 'object'=>array('param'=>1, 'embed'=>1)); // Other
167 167
 $cT = array('colgroup'=>1, 'dd'=>1, 'dt'=>1, 'li'=>1, 'option'=>1, 'p'=>1, 'td'=>1, 'tfoot'=>1, 'th'=>1, 'thead'=>1, 'tr'=>1); // Omitable closing
168 168
 // block/inline type; ins & del both type; #pcdata: text
169 169
 $eB = array('address'=>1, 'blockquote'=>1, 'center'=>1, 'del'=>1, 'dir'=>1, 'dl'=>1, 'div'=>1, 'fieldset'=>1, 'form'=>1, 'ins'=>1, 'h1'=>1, 'h2'=>1, 'h3'=>1, 'h4'=>1, 'h5'=>1, 'h6'=>1, 'hr'=>1, 'isindex'=>1, 'menu'=>1, 'noscript'=>1, 'ol'=>1, 'p'=>1, 'pre'=>1, 'table'=>1, 'ul'=>1);
170 170
 $eI = array('#pcdata'=>1, 'a'=>1, 'abbr'=>1, 'acronym'=>1, 'applet'=>1, 'b'=>1, 'bdo'=>1, 'big'=>1, 'br'=>1, 'button'=>1, 'cite'=>1, 'code'=>1, 'del'=>1, 'dfn'=>1, 'em'=>1, 'embed'=>1, 'font'=>1, 'i'=>1, 'iframe'=>1, 'img'=>1, 'input'=>1, 'ins'=>1, 'kbd'=>1, 'label'=>1, 'map'=>1, 'object'=>1, 'q'=>1, 'ruby'=>1, 's'=>1, 'samp'=>1, 'select'=>1, 'script'=>1, 'small'=>1, 'span'=>1, 'strike'=>1, 'strong'=>1, 'sub'=>1, 'sup'=>1, 'textarea'=>1, 'tt'=>1, 'u'=>1, 'var'=>1);
171
-if($GLOBALS['C']['allow_for_inline'] && is_array($GLOBALS['C']['allow_for_inline'])) foreach($GLOBALS['C']['allow_for_inline'] as $khai => $vhai) {$eI[$vhai]=1;}//allow table as if it was an inline element as <span> some Text <table>...</table> more text</span> is quite common
171
+if ($GLOBALS['C']['allow_for_inline'] && is_array($GLOBALS['C']['allow_for_inline'])) foreach ($GLOBALS['C']['allow_for_inline'] as $khai => $vhai) {$eI[$vhai] = 1; }//allow table as if it was an inline element as <span> some Text <table>...</table> more text</span> is quite common
172 172
 $eN = array('a'=>1, 'big'=>1, 'button'=>1, 'fieldset'=>1, 'font'=>1, 'form'=>1, 'iframe'=>1, 'img'=>1, 'input'=>1, 'label'=>1, 'object'=>1, 'ruby'=>1, 'script'=>1, 'select'=>1, 'small'=>1, 'sub'=>1, 'sup'=>1, 'textarea'=>1); // Exclude from specific ele; $cN values
173 173
 $eO = array('area'=>1, 'caption'=>1, 'col'=>1, 'colgroup'=>1, 'dd'=>1, 'dt'=>1, 'legend'=>1, 'li'=>1, 'optgroup'=>1, 'option'=>1, 'param'=>1, 'rb'=>1, 'rbc'=>1, 'rp'=>1, 'rt'=>1, 'rtc'=>1, 'script'=>1, 'tbody'=>1, 'td'=>1, 'tfoot'=>1, 'thead'=>1, 'th'=>1, 'tr'=>1); // Missing in $eB & $eI
174 174
 $eF = $eB + $eI;
175 175
 
176 176
 // $in sets allowed child
177 177
 $in = ((isset($eF[$in]) && $in != '#pcdata') or isset($eO[$in])) ? $in : 'div';
178
-if(isset($cE[$in])){
178
+if (isset($cE[$in])) {
179 179
  return (!$do ? '' : str_replace(array('<', '>'), array('&lt;', '&gt;'), $t));
180 180
 }
181
-if(isset($cS[$in])){$inOk = $cS[$in];}
182
-elseif(isset($cI[$in])){$inOk = $eI; $cI['del'] = 1; $cI['ins'] = 1;}
183
-elseif(isset($cF[$in])){$inOk = $eF; unset($cI['del'], $cI['ins']);}
184
-elseif(isset($cB[$in])){$inOk = $eB; unset($cI['del'], $cI['ins']);}
185
-if(isset($cO[$in])){$inOk = $inOk + $cO[$in];}
186
-if(isset($cN[$in])){$inOk = array_diff_assoc($inOk, $cN[$in]);}
181
+if (isset($cS[$in])) {$inOk = $cS[$in]; }
182
+elseif (isset($cI[$in])) {$inOk = $eI; $cI['del'] = 1; $cI['ins'] = 1; }
183
+elseif (isset($cF[$in])) {$inOk = $eF; unset($cI['del'], $cI['ins']); }
184
+elseif (isset($cB[$in])) {$inOk = $eB; unset($cI['del'], $cI['ins']); }
185
+if (isset($cO[$in])) {$inOk = $inOk + $cO[$in]; }
186
+if (isset($cN[$in])) {$inOk = array_diff_assoc($inOk, $cN[$in]); }
187 187
 
188 188
 $t = explode('<', $t);
189 189
 $ok = $q = array(); // $q seq list of open non-empty ele
190 190
 ob_start();
191 191
 
192
-for($i=-1, $ci=count($t); ++$i<$ci;){
192
+for ($i = -1, $ci = count($t); ++$i < $ci;) {
193 193
  // allowed $ok in parent $p
194
- if($ql = count($q)){
194
+ if ($ql = count($q)) {
195 195
   $p = array_pop($q);
196 196
   $q[] = $p;
197
-  if(isset($cS[$p])){$ok = $cS[$p];}
198
-  elseif(isset($cI[$p])){$ok = $eI; $cI['del'] = 1; $cI['ins'] = 1;}
199
-  elseif(isset($cF[$p])){$ok = $eF; unset($cI['del'], $cI['ins']);}
200
-  elseif(isset($cB[$p])){$ok = $eB; unset($cI['del'], $cI['ins']);}
201
-  if(isset($cO[$p])){$ok = $ok + $cO[$p];}
202
-  if(isset($cN[$p])){$ok = array_diff_assoc($ok, $cN[$p]);}
203
- }else{$ok = $inOk; unset($cI['del'], $cI['ins']);}
197
+  if (isset($cS[$p])) {$ok = $cS[$p]; }
198
+  elseif (isset($cI[$p])) {$ok = $eI; $cI['del'] = 1; $cI['ins'] = 1; }
199
+  elseif (isset($cF[$p])) {$ok = $eF; unset($cI['del'], $cI['ins']); }
200
+  elseif (isset($cB[$p])) {$ok = $eB; unset($cI['del'], $cI['ins']); }
201
+  if (isset($cO[$p])) {$ok = $ok + $cO[$p]; }
202
+  if (isset($cN[$p])) {$ok = array_diff_assoc($ok, $cN[$p]); }
203
+ } else {$ok = $inOk; unset($cI['del'], $cI['ins']); }
204 204
  // bad tags, & ele content
205
- if(isset($e) && ($do == 1 or (isset($ok['#pcdata']) && ($do == 3 or $do == 5)))){
205
+ if (isset($e) && ($do == 1 or (isset($ok['#pcdata']) && ($do == 3 or $do == 5)))) {
206 206
   echo '&lt;', $s, $e, $a, '&gt;';
207 207
  }
208
- if(isset($x[0])){
209
-  if(strlen(trim($x)) && (($ql && isset($cB[$p])) or (isset($cB[$in]) && !$ql))){
208
+ if (isset($x[0])) {
209
+  if (strlen(trim($x)) && (($ql && isset($cB[$p])) or (isset($cB[$in]) && !$ql))) {
210 210
    echo '<div>', $x, '</div>';
211 211
   }
212
-  elseif($do < 3 or isset($ok['#pcdata'])){echo $x;}
213
-  elseif(strpos($x, "\x02\x04")){
214
-   foreach(preg_split('`(\x01\x02[^\x01\x02]+\x02\x01)`', $x, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY) as $v){
212
+  elseif ($do < 3 or isset($ok['#pcdata'])) {echo $x; }
213
+  elseif (strpos($x, "\x02\x04")) {
214
+   foreach (preg_split('`(\x01\x02[^\x01\x02]+\x02\x01)`', $x, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY) as $v) {
215 215
     echo (substr($v, 0, 2) == "\x01\x02" ? $v : ($do > 4 ? preg_replace('`\S`', '', $v) : ''));
216 216
    }
217
-  }elseif($do > 4){echo preg_replace('`\S`', '', $x);}
217
+  }elseif ($do > 4) {echo preg_replace('`\S`', '', $x); }
218 218
  }
219 219
  // get markup
220
- if(!preg_match('`^(/?)([a-z1-6]+)([^>]*)>(.*)`sm', $t[$i], $r)){$x = $t[$i]; continue;}
220
+ if (!preg_match('`^(/?)([a-z1-6]+)([^>]*)>(.*)`sm', $t[$i], $r)) {$x = $t[$i]; continue; }
221 221
  $s = null; $e = null; $a = null; $x = null; list($all, $s, $e, $a, $x) = $r;
222 222
  // close tag
223
- if($s){
224
-  if(isset($cE[$e]) or !in_array($e, $q)){continue;} // Empty/unopen
225
-  if($p == $e){array_pop($q); echo '</', $e, '>'; unset($e); continue;} // Last open
223
+ if ($s) {
224
+  if (isset($cE[$e]) or !in_array($e, $q)) {continue; } // Empty/unopen
225
+  if ($p == $e) {array_pop($q); echo '</', $e, '>'; unset($e); continue; } // Last open
226 226
   $add = ''; // Nesting - close open tags that need to be
227
-  for($j=-1, $cj=count($q); ++$j<$cj;){
228
-   if(($d = array_pop($q)) == $e){break;}
229
-   else{$add .= "</{$d}>";}
227
+  for ($j = -1, $cj = count($q); ++$j < $cj;) {
228
+   if (($d = array_pop($q)) == $e) {break; }
229
+   else {$add .= "</{$d}>"; }
230 230
   }
231 231
   echo $add, '</', $e, '>'; unset($e); continue;
232 232
  }
233 233
  // open tag
234 234
  // $cB ele needs $eB ele as child
235
- if(isset($cB[$e]) && strlen(trim($x))){
235
+ if (isset($cB[$e]) && strlen(trim($x))) {
236 236
   $t[$i] = "{$e}{$a}>";
237
-  array_splice($t, $i+1, 0, 'div>'. $x); unset($e, $x); ++$ci; --$i; continue;
237
+  array_splice($t, $i + 1, 0, 'div>'.$x); unset($e, $x); ++$ci; --$i; continue;
238 238
  }
239
- if((($ql && isset($cB[$p])) or (isset($cB[$in]) && !$ql)) && !isset($eB[$e]) && !isset($ok[$e])){
239
+ if ((($ql && isset($cB[$p])) or (isset($cB[$in]) && !$ql)) && !isset($eB[$e]) && !isset($ok[$e])) {
240 240
   array_splice($t, $i, 0, 'div>'); unset($e, $x); ++$ci; --$i; continue;
241 241
  }
242
- if($e == 'div' && !isset($ok['div']) && strpos($a, '-htmlawed-transform')){
242
+ if ($e == 'div' && !isset($ok['div']) && strpos($a, '-htmlawed-transform')) {
243 243
   $t[$i] = "span{$a}>{$x}"; unset($e, $x); --$i; continue;
244 244
  }
245 245
  // if no open ele, $in = parent; mostly immediate parent-child relation should hold
246
- if(!$ql or !isset($eN[$e]) or !array_intersect($q, $cN2)){
247
-  if(!isset($ok[$e])){
248
-   if($ql && isset($cT[$p])){echo '</', array_pop($q), '>'; unset($e, $x); --$i;}
246
+ if (!$ql or !isset($eN[$e]) or !array_intersect($q, $cN2)) {
247
+  if (!isset($ok[$e])) {
248
+   if ($ql && isset($cT[$p])) {echo '</', array_pop($q), '>'; unset($e, $x); --$i; }
249 249
    continue;
250 250
   }
251
-  if(!isset($cE[$e])){$q[] = $e;}
251
+  if (!isset($cE[$e])) {$q[] = $e; }
252 252
   echo '<', $e, $a, '>'; unset($e); continue;
253 253
  }
254 254
  // specific parent-child
255
- if(isset($cS[$p][$e])){
256
-  if(!isset($cE[$e])){$q[] = $e;}
255
+ if (isset($cS[$p][$e])) {
256
+  if (!isset($cE[$e])) {$q[] = $e; }
257 257
   echo '<', $e, $a, '>'; unset($e); continue;
258 258
  }
259 259
  // nesting
260 260
  $add = '';
261 261
  $q2 = array();
262
- for($k=-1, $kc=count($q); ++$k<$kc;){
262
+ for ($k = -1, $kc = count($q); ++$k < $kc;) {
263 263
   $d = $q[$k];
264 264
   $ok2 = array();
265
-  if(isset($cS[$d])){$q2[] = $d; continue;}
265
+  if (isset($cS[$d])) {$q2[] = $d; continue; }
266 266
   $ok2 = isset($cI[$d]) ? $eI : $eF;
267
-  if(isset($cO[$d])){$ok2 = $ok2 + $cO[$d];}
268
-  if(isset($cN[$d])){$ok2 = array_diff_assoc($ok2, $cN[$d]);}
269
-  if(!isset($ok2[$e])){
270
-   if(!$k && !isset($inOk[$e])){continue 2;}
267
+  if (isset($cO[$d])) {$ok2 = $ok2 + $cO[$d]; }
268
+  if (isset($cN[$d])) {$ok2 = array_diff_assoc($ok2, $cN[$d]); }
269
+  if (!isset($ok2[$e])) {
270
+   if (!$k && !isset($inOk[$e])) {continue 2; }
271 271
    $add = "</{$d}>";
272
-   for(;++$k<$kc;){$add = "</{$q[$k]}>{$add}";}
272
+   for (;++$k < $kc;) {$add = "</{$q[$k]}>{$add}"; }
273 273
    break;
274 274
   }
275
-  else{$q2[] = $d;}
275
+  else {$q2[] = $d; }
276 276
  }
277 277
  $q = $q2;
278
- if(!isset($cE[$e])){$q[] = $e;}
278
+ if (!isset($cE[$e])) {$q[] = $e; }
279 279
  echo $add, '<', $e, $a, '>'; unset($e); continue;
280 280
 }
281 281
 
282 282
 // end
283
-if($ql = count($q)){
283
+if ($ql = count($q)) {
284 284
  $p = array_pop($q);
285 285
  $q[] = $p;
286
- if(isset($cS[$p])){$ok = $cS[$p];}
287
- elseif(isset($cI[$p])){$ok = $eI; $cI['del'] = 1; $cI['ins'] = 1;}
288
- elseif(isset($cF[$p])){$ok = $eF; unset($cI['del'], $cI['ins']);}
289
- elseif(isset($cB[$p])){$ok = $eB; unset($cI['del'], $cI['ins']);}
290
- if(isset($cO[$p])){$ok = $ok + $cO[$p];}
291
- if(isset($cN[$p])){$ok = array_diff_assoc($ok, $cN[$p]);}
292
-}else{$ok = $inOk; unset($cI['del'], $cI['ins']);}
293
-if(isset($e) && ($do == 1 or (isset($ok['#pcdata']) && ($do == 3 or $do == 5)))){
286
+ if (isset($cS[$p])) {$ok = $cS[$p]; }
287
+ elseif (isset($cI[$p])) {$ok = $eI; $cI['del'] = 1; $cI['ins'] = 1; }
288
+ elseif (isset($cF[$p])) {$ok = $eF; unset($cI['del'], $cI['ins']); }
289
+ elseif (isset($cB[$p])) {$ok = $eB; unset($cI['del'], $cI['ins']); }
290
+ if (isset($cO[$p])) {$ok = $ok + $cO[$p]; }
291
+ if (isset($cN[$p])) {$ok = array_diff_assoc($ok, $cN[$p]); }
292
+} else {$ok = $inOk; unset($cI['del'], $cI['ins']); }
293
+if (isset($e) && ($do == 1 or (isset($ok['#pcdata']) && ($do == 3 or $do == 5)))) {
294 294
  echo '&lt;', $s, $e, $a, '&gt;';
295 295
 }
296
-if(isset($x[0])){
297
- if(strlen(trim($x)) && (($ql && isset($cB[$p])) or (isset($cB[$in]) && !$ql))){
296
+if (isset($x[0])) {
297
+ if (strlen(trim($x)) && (($ql && isset($cB[$p])) or (isset($cB[$in]) && !$ql))) {
298 298
   echo '<div>', $x, '</div>';
299 299
  }
300
- elseif($do < 3 or isset($ok['#pcdata'])){echo $x;}
301
- elseif(strpos($x, "\x02\x04")){
302
-  foreach(preg_split('`(\x01\x02[^\x01\x02]+\x02\x01)`', $x, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY) as $v){
300
+ elseif ($do < 3 or isset($ok['#pcdata'])) {echo $x; }
301
+ elseif (strpos($x, "\x02\x04")) {
302
+  foreach (preg_split('`(\x01\x02[^\x01\x02]+\x02\x01)`', $x, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY) as $v) {
303 303
    echo (substr($v, 0, 2) == "\x01\x02" ? $v : ($do > 4 ? preg_replace('`\S`', '', $v) : ''));
304 304
   }
305
- }elseif($do > 4){echo preg_replace('`\S`', '', $x);}
305
+ }elseif ($do > 4) {echo preg_replace('`\S`', '', $x); }
306 306
 }
307
-while(!empty($q) && ($e = array_pop($q))){echo '</', $e, '>';}
307
+while (!empty($q) && ($e = array_pop($q))) {echo '</', $e, '>'; }
308 308
 $o = ob_get_contents();
309 309
 ob_end_clean();
310 310
 return $o;
311 311
 // eof
312 312
 }
313 313
 
314
-function hl_cmtcd($t){
314
+function hl_cmtcd($t) {
315 315
 // comment/CDATA sec handler
316 316
 $t = $t[0];
317 317
 global $C;
318
-if(!($v = $C[$n = $t[3] == '-' ? 'comment' : 'cdata'])){return $t;}
319
-if($v == 1){return '';}
320
-if($n == 'comment'){
321
- if(substr(($t = preg_replace('`--+`', '-', substr($t, 4, -3))), -1) != ' '){$t .= ' ';}
318
+if (!($v = $C[$n = $t[3] == '-' ? 'comment' : 'cdata'])) {return $t; }
319
+if ($v == 1) {return ''; }
320
+if ($n == 'comment') {
321
+ if (substr(($t = preg_replace('`--+`', '-', substr($t, 4, -3))), -1) != ' ') {$t .= ' '; }
322 322
 }
323
-else{$t = substr($t, 1, -1);}
323
+else {$t = substr($t, 1, -1); }
324 324
 $t = $v == 2 ? str_replace(array('&', '<', '>'), array('&amp;', '&lt;', '&gt;'), $t) : $t;
325 325
 return str_replace(array('&', '<', '>'), array("\x03", "\x04", "\x05"), ($n == 'comment' ? "\x01\x02\x04!--$t--\x05\x02\x01" : "\x01\x01\x04$t\x05\x01\x01"));
326 326
 // eof
327 327
 }
328 328
 
329
-function hl_ent($t){
329
+function hl_ent($t) {
330 330
 // entitity handler
331 331
 global $C;
332 332
 $t = $t[1];
333
-static $U = array('quot'=>1,'amp'=>1,'lt'=>1,'gt'=>1);
334
-static $N = array('fnof'=>'402', 'Alpha'=>'913', 'Beta'=>'914', 'Gamma'=>'915', 'Delta'=>'916', 'Epsilon'=>'917', 'Zeta'=>'918', 'Eta'=>'919', 'Theta'=>'920', 'Iota'=>'921', 'Kappa'=>'922', 'Lambda'=>'923', 'Mu'=>'924', 'Nu'=>'925', 'Xi'=>'926', 'Omicron'=>'927', 'Pi'=>'928', 'Rho'=>'929', 'Sigma'=>'931', 'Tau'=>'932', 'Upsilon'=>'933', 'Phi'=>'934', 'Chi'=>'935', 'Psi'=>'936', 'Omega'=>'937', 'alpha'=>'945', 'beta'=>'946', 'gamma'=>'947', 'delta'=>'948', 'epsilon'=>'949', 'zeta'=>'950', 'eta'=>'951', 'theta'=>'952', 'iota'=>'953', 'kappa'=>'954', 'lambda'=>'955', 'mu'=>'956', 'nu'=>'957', 'xi'=>'958', 'omicron'=>'959', 'pi'=>'960', 'rho'=>'961', 'sigmaf'=>'962', 'sigma'=>'963', 'tau'=>'964', 'upsilon'=>'965', 'phi'=>'966', 'chi'=>'967', 'psi'=>'968', 'omega'=>'969', 'thetasym'=>'977', 'upsih'=>'978', 'piv'=>'982', 'bull'=>'8226', 'hellip'=>'8230', 'prime'=>'8242', 'Prime'=>'8243', 'oline'=>'8254', 'frasl'=>'8260', 'weierp'=>'8472', 'image'=>'8465', 'real'=>'8476', 'trade'=>'8482', 'alefsym'=>'8501', 'larr'=>'8592', 'uarr'=>'8593', 'rarr'=>'8594', 'darr'=>'8595', 'harr'=>'8596', 'crarr'=>'8629', 'lArr'=>'8656', 'uArr'=>'8657', 'rArr'=>'8658', 'dArr'=>'8659', 'hArr'=>'8660', 'forall'=>'8704', 'part'=>'8706', 'exist'=>'8707', 'empty'=>'8709', 'nabla'=>'8711', 'isin'=>'8712', 'notin'=>'8713', 'ni'=>'8715', 'prod'=>'8719', 'sum'=>'8721', 'minus'=>'8722', 'lowast'=>'8727', 'radic'=>'8730', 'prop'=>'8733', 'infin'=>'8734', 'ang'=>'8736', 'and'=>'8743', 'or'=>'8744', 'cap'=>'8745', 'cup'=>'8746', 'int'=>'8747', 'there4'=>'8756', 'sim'=>'8764', 'cong'=>'8773', 'asymp'=>'8776', 'ne'=>'8800', 'equiv'=>'8801', 'le'=>'8804', 'ge'=>'8805', 'sub'=>'8834', 'sup'=>'8835', 'nsub'=>'8836', 'sube'=>'8838', 'supe'=>'8839', 'oplus'=>'8853', 'otimes'=>'8855', 'perp'=>'8869', 'sdot'=>'8901', 'lceil'=>'8968', 'rceil'=>'8969', 'lfloor'=>'8970', 'rfloor'=>'8971', 'lang'=>'9001', 'rang'=>'9002', 'loz'=>'9674', 'spades'=>'9824', 'clubs'=>'9827', 'hearts'=>'9829', 'diams'=>'9830', 'apos'=>'39',  'OElig'=>'338', 'oelig'=>'339', 'Scaron'=>'352', 'scaron'=>'353', 'Yuml'=>'376', 'circ'=>'710', 'tilde'=>'732', 'ensp'=>'8194', 'emsp'=>'8195', 'thinsp'=>'8201', 'zwnj'=>'8204', 'zwj'=>'8205', 'lrm'=>'8206', 'rlm'=>'8207', 'ndash'=>'8211', 'mdash'=>'8212', 'lsquo'=>'8216', 'rsquo'=>'8217', 'sbquo'=>'8218', 'ldquo'=>'8220', 'rdquo'=>'8221', 'bdquo'=>'8222', 'dagger'=>'8224', 'Dagger'=>'8225', 'permil'=>'8240', 'lsaquo'=>'8249', 'rsaquo'=>'8250', 'euro'=>'8364', 'nbsp'=>'160', 'iexcl'=>'161', 'cent'=>'162', 'pound'=>'163', 'curren'=>'164', 'yen'=>'165', 'brvbar'=>'166', 'sect'=>'167', 'uml'=>'168', 'copy'=>'169', 'ordf'=>'170', 'laquo'=>'171', 'not'=>'172', 'shy'=>'173', 'reg'=>'174', 'macr'=>'175', 'deg'=>'176', 'plusmn'=>'177', 'sup2'=>'178', 'sup3'=>'179', 'acute'=>'180', 'micro'=>'181', 'para'=>'182', 'middot'=>'183', 'cedil'=>'184', 'sup1'=>'185', 'ordm'=>'186', 'raquo'=>'187', 'frac14'=>'188', 'frac12'=>'189', 'frac34'=>'190', 'iquest'=>'191', 'Agrave'=>'192', 'Aacute'=>'193', 'Acirc'=>'194', 'Atilde'=>'195', 'Auml'=>'196', 'Aring'=>'197', 'AElig'=>'198', 'Ccedil'=>'199', 'Egrave'=>'200', 'Eacute'=>'201', 'Ecirc'=>'202', 'Euml'=>'203', 'Igrave'=>'204', 'Iacute'=>'205', 'Icirc'=>'206', 'Iuml'=>'207', 'ETH'=>'208', 'Ntilde'=>'209', 'Ograve'=>'210', 'Oacute'=>'211', 'Ocirc'=>'212', 'Otilde'=>'213', 'Ouml'=>'214', 'times'=>'215', 'Oslash'=>'216', 'Ugrave'=>'217', 'Uacute'=>'218', 'Ucirc'=>'219', 'Uuml'=>'220', 'Yacute'=>'221', 'THORN'=>'222', 'szlig'=>'223', 'agrave'=>'224', 'aacute'=>'225', 'acirc'=>'226', 'atilde'=>'227', 'auml'=>'228', 'aring'=>'229', 'aelig'=>'230', 'ccedil'=>'231', 'egrave'=>'232', 'eacute'=>'233', 'ecirc'=>'234', 'euml'=>'235', 'igrave'=>'236', 'iacute'=>'237', 'icirc'=>'238', 'iuml'=>'239', 'eth'=>'240', 'ntilde'=>'241', 'ograve'=>'242', 'oacute'=>'243', 'ocirc'=>'244', 'otilde'=>'245', 'ouml'=>'246', 'divide'=>'247', 'oslash'=>'248', 'ugrave'=>'249', 'uacute'=>'250', 'ucirc'=>'251', 'uuml'=>'252', 'yacute'=>'253', 'thorn'=>'254', 'yuml'=>'255');
335
-if($t[0] != '#'){
336
- return ($C['and_mark'] ? "\x06" : '&'). (isset($U[$t]) ? $t : (isset($N[$t]) ? (!$C['named_entity'] ? '#'. ($C['hexdec_entity'] > 1 ? 'x'. dechex($N[$t]) : $N[$t]) : $t) : 'amp;'. $t)). ';';
333
+static $U = array('quot'=>1, 'amp'=>1, 'lt'=>1, 'gt'=>1);
334
+static $N = array('fnof'=>'402', 'Alpha'=>'913', 'Beta'=>'914', 'Gamma'=>'915', 'Delta'=>'916', 'Epsilon'=>'917', 'Zeta'=>'918', 'Eta'=>'919', 'Theta'=>'920', 'Iota'=>'921', 'Kappa'=>'922', 'Lambda'=>'923', 'Mu'=>'924', 'Nu'=>'925', 'Xi'=>'926', 'Omicron'=>'927', 'Pi'=>'928', 'Rho'=>'929', 'Sigma'=>'931', 'Tau'=>'932', 'Upsilon'=>'933', 'Phi'=>'934', 'Chi'=>'935', 'Psi'=>'936', 'Omega'=>'937', 'alpha'=>'945', 'beta'=>'946', 'gamma'=>'947', 'delta'=>'948', 'epsilon'=>'949', 'zeta'=>'950', 'eta'=>'951', 'theta'=>'952', 'iota'=>'953', 'kappa'=>'954', 'lambda'=>'955', 'mu'=>'956', 'nu'=>'957', 'xi'=>'958', 'omicron'=>'959', 'pi'=>'960', 'rho'=>'961', 'sigmaf'=>'962', 'sigma'=>'963', 'tau'=>'964', 'upsilon'=>'965', 'phi'=>'966', 'chi'=>'967', 'psi'=>'968', 'omega'=>'969', 'thetasym'=>'977', 'upsih'=>'978', 'piv'=>'982', 'bull'=>'8226', 'hellip'=>'8230', 'prime'=>'8242', 'Prime'=>'8243', 'oline'=>'8254', 'frasl'=>'8260', 'weierp'=>'8472', 'image'=>'8465', 'real'=>'8476', 'trade'=>'8482', 'alefsym'=>'8501', 'larr'=>'8592', 'uarr'=>'8593', 'rarr'=>'8594', 'darr'=>'8595', 'harr'=>'8596', 'crarr'=>'8629', 'lArr'=>'8656', 'uArr'=>'8657', 'rArr'=>'8658', 'dArr'=>'8659', 'hArr'=>'8660', 'forall'=>'8704', 'part'=>'8706', 'exist'=>'8707', 'empty'=>'8709', 'nabla'=>'8711', 'isin'=>'8712', 'notin'=>'8713', 'ni'=>'8715', 'prod'=>'8719', 'sum'=>'8721', 'minus'=>'8722', 'lowast'=>'8727', 'radic'=>'8730', 'prop'=>'8733', 'infin'=>'8734', 'ang'=>'8736', 'and'=>'8743', 'or'=>'8744', 'cap'=>'8745', 'cup'=>'8746', 'int'=>'8747', 'there4'=>'8756', 'sim'=>'8764', 'cong'=>'8773', 'asymp'=>'8776', 'ne'=>'8800', 'equiv'=>'8801', 'le'=>'8804', 'ge'=>'8805', 'sub'=>'8834', 'sup'=>'8835', 'nsub'=>'8836', 'sube'=>'8838', 'supe'=>'8839', 'oplus'=>'8853', 'otimes'=>'8855', 'perp'=>'8869', 'sdot'=>'8901', 'lceil'=>'8968', 'rceil'=>'8969', 'lfloor'=>'8970', 'rfloor'=>'8971', 'lang'=>'9001', 'rang'=>'9002', 'loz'=>'9674', 'spades'=>'9824', 'clubs'=>'9827', 'hearts'=>'9829', 'diams'=>'9830', 'apos'=>'39', 'OElig'=>'338', 'oelig'=>'339', 'Scaron'=>'352', 'scaron'=>'353', 'Yuml'=>'376', 'circ'=>'710', 'tilde'=>'732', 'ensp'=>'8194', 'emsp'=>'8195', 'thinsp'=>'8201', 'zwnj'=>'8204', 'zwj'=>'8205', 'lrm'=>'8206', 'rlm'=>'8207', 'ndash'=>'8211', 'mdash'=>'8212', 'lsquo'=>'8216', 'rsquo'=>'8217', 'sbquo'=>'8218', 'ldquo'=>'8220', 'rdquo'=>'8221', 'bdquo'=>'8222', 'dagger'=>'8224', 'Dagger'=>'8225', 'permil'=>'8240', 'lsaquo'=>'8249', 'rsaquo'=>'8250', 'euro'=>'8364', 'nbsp'=>'160', 'iexcl'=>'161', 'cent'=>'162', 'pound'=>'163', 'curren'=>'164', 'yen'=>'165', 'brvbar'=>'166', 'sect'=>'167', 'uml'=>'168', 'copy'=>'169', 'ordf'=>'170', 'laquo'=>'171', 'not'=>'172', 'shy'=>'173', 'reg'=>'174', 'macr'=>'175', 'deg'=>'176', 'plusmn'=>'177', 'sup2'=>'178', 'sup3'=>'179', 'acute'=>'180', 'micro'=>'181', 'para'=>'182', 'middot'=>'183', 'cedil'=>'184', 'sup1'=>'185', 'ordm'=>'186', 'raquo'=>'187', 'frac14'=>'188', 'frac12'=>'189', 'frac34'=>'190', 'iquest'=>'191', 'Agrave'=>'192', 'Aacute'=>'193', 'Acirc'=>'194', 'Atilde'=>'195', 'Auml'=>'196', 'Aring'=>'197', 'AElig'=>'198', 'Ccedil'=>'199', 'Egrave'=>'200', 'Eacute'=>'201', 'Ecirc'=>'202', 'Euml'=>'203', 'Igrave'=>'204', 'Iacute'=>'205', 'Icirc'=>'206', 'Iuml'=>'207', 'ETH'=>'208', 'Ntilde'=>'209', 'Ograve'=>'210', 'Oacute'=>'211', 'Ocirc'=>'212', 'Otilde'=>'213', 'Ouml'=>'214', 'times'=>'215', 'Oslash'=>'216', 'Ugrave'=>'217', 'Uacute'=>'218', 'Ucirc'=>'219', 'Uuml'=>'220', 'Yacute'=>'221', 'THORN'=>'222', 'szlig'=>'223', 'agrave'=>'224', 'aacute'=>'225', 'acirc'=>'226', 'atilde'=>'227', 'auml'=>'228', 'aring'=>'229', 'aelig'=>'230', 'ccedil'=>'231', 'egrave'=>'232', 'eacute'=>'233', 'ecirc'=>'234', 'euml'=>'235', 'igrave'=>'236', 'iacute'=>'237', 'icirc'=>'238', 'iuml'=>'239', 'eth'=>'240', 'ntilde'=>'241', 'ograve'=>'242', 'oacute'=>'243', 'ocirc'=>'244', 'otilde'=>'245', 'ouml'=>'246', 'divide'=>'247', 'oslash'=>'248', 'ugrave'=>'249', 'uacute'=>'250', 'ucirc'=>'251', 'uuml'=>'252', 'yacute'=>'253', 'thorn'=>'254', 'yuml'=>'255');
335
+if ($t[0] != '#') {
336
+ return ($C['and_mark'] ? "\x06" : '&').(isset($U[$t]) ? $t : (isset($N[$t]) ? (!$C['named_entity'] ? '#'.($C['hexdec_entity'] > 1 ? 'x'.dechex($N[$t]) : $N[$t]) : $t) : 'amp;'.$t)).';';
337 337
 }
338
-if(($n = ctype_digit($t = substr($t, 1)) ? intval($t) : hexdec(substr($t, 1))) < 9 or ($n > 13 && $n < 32) or $n == 11 or $n == 12 or ($n > 126 && $n < 160 && $n != 133) or ($n > 55295 && ($n < 57344 or ($n > 64975 && $n < 64992) or $n == 65534 or $n == 65535 or $n > 1114111))){
339
- return ($C['and_mark'] ? "\x06" : '&'). "amp;#{$t};";
338
+if (($n = ctype_digit($t = substr($t, 1)) ? intval($t) : hexdec(substr($t, 1))) < 9 or ($n > 13 && $n < 32) or $n == 11 or $n == 12 or ($n > 126 && $n < 160 && $n != 133) or ($n > 55295 && ($n < 57344 or ($n > 64975 && $n < 64992) or $n == 65534 or $n == 65535 or $n > 1114111))) {
339
+ return ($C['and_mark'] ? "\x06" : '&')."amp;#{$t};";
340 340
 }
341
-return ($C['and_mark'] ? "\x06" : '&'). '#'. (((ctype_digit($t) && $C['hexdec_entity'] < 2) or !$C['hexdec_entity']) ? $n : 'x'. dechex($n)). ';';
341
+return ($C['and_mark'] ? "\x06" : '&').'#'.(((ctype_digit($t) && $C['hexdec_entity'] < 2) or !$C['hexdec_entity']) ? $n : 'x'.dechex($n)).';';
342 342
 // eof
343 343
 }
344 344
 
345
-function hl_prot($p, $c=null){
345
+function hl_prot($p, $c = null) {
346 346
 // check URL scheme
347 347
 global $C;
348 348
 $b = $a = '';
349
-if($c == null){$c = 'style'; $b = $p[1]; $a = $p[3]; $p = trim($p[2]);}
349
+if ($c == null) {$c = 'style'; $b = $p[1]; $a = $p[3]; $p = trim($p[2]); }
350 350
 $c = isset($C['schemes'][$c]) ? $C['schemes'][$c] : $C['schemes']['*'];
351 351
 static $d = 'denied:';
352
-if(isset($c['!']) && substr($p, 0, 7) != $d){$p = "$d$p";}
353
-if(isset($c['*']) or !strcspn($p, '#?;') or (substr($p, 0, 7) == $d)){return "{$b}{$p}{$a}";} // All ok, frag, query, param
354
-if(preg_match('`^([^:?[@!$()*,=/\'\]]+?)(:|&#(58|x3a);|%3a|\\\\0{0,4}3a).`i', $p, $m) && !isset($c[strtolower($m[1])])){ // Denied prot
352
+if (isset($c['!']) && substr($p, 0, 7) != $d) {$p = "$d$p"; }
353
+if (isset($c['*']) or !strcspn($p, '#?;') or (substr($p, 0, 7) == $d)) {return "{$b}{$p}{$a}"; } // All ok, frag, query, param
354
+if (preg_match('`^([^:?[@!$()*,=/\'\]]+?)(:|&#(58|x3a);|%3a|\\\\0{0,4}3a).`i', $p, $m) && !isset($c[strtolower($m[1])])) { // Denied prot
355 355
  return "{$b}{$d}{$p}{$a}";
356 356
 }
357
-if($C['abs_url']){
358
- if($C['abs_url'] == -1 && strpos($p, $C['base_url']) === 0){ // Make url rel
357
+if ($C['abs_url']) {
358
+ if ($C['abs_url'] == -1 && strpos($p, $C['base_url']) === 0) { // Make url rel
359 359
   $p = substr($p, strlen($C['base_url']));
360
- }elseif(empty($m[1])){ // Make URL abs
361
-  if(substr($p, 0, 2) == '//'){$p = substr($C['base_url'], 0, strpos($C['base_url'], ':')+1). $p;}
362
-  elseif($p[0] == '/'){$p = preg_replace('`(^.+?://[^/]+)(.*)`', '$1', $C['base_url']). $p;}
363
-  elseif(strcspn($p, './')){$p = $C['base_url']. $p;}
364
-  else{
360
+ }elseif (empty($m[1])) { // Make URL abs
361
+  if (substr($p, 0, 2) == '//') {$p = substr($C['base_url'], 0, strpos($C['base_url'], ':') + 1).$p; }
362
+  elseif ($p[0] == '/') {$p = preg_replace('`(^.+?://[^/]+)(.*)`', '$1', $C['base_url']).$p; }
363
+  elseif (strcspn($p, './')) {$p = $C['base_url'].$p; }
364
+  else {
365 365
    preg_match('`^([a-zA-Z\d\-+.]+://[^/]+)(.*)`', $C['base_url'], $m);
366
-   $p = preg_replace('`(?<=/)\./`', '', $m[2]. $p);
367
-   while(preg_match('`(?<=/)([^/]{3,}|[^/.]+?|\.[^/.]|[^/.]\.)/\.\./`', $p)){
366
+   $p = preg_replace('`(?<=/)\./`', '', $m[2].$p);
367
+   while (preg_match('`(?<=/)([^/]{3,}|[^/.]+?|\.[^/.]|[^/.]\.)/\.\./`', $p)) {
368 368
     $p = preg_replace('`(?<=/)([^/]{3,}|[^/.]+?|\.[^/.]|[^/.]\.)/\.\./`', '', $p);
369 369
    }
370
-   $p = $m[1]. $p;
370
+   $p = $m[1].$p;
371 371
   }
372 372
  }
373 373
 }
@@ -375,87 +375,87 @@  discard block
 block discarded – undo
375 375
 // eof
376 376
 }
377 377
 
378
-function hl_regex($p){
378
+function hl_regex($p) {
379 379
 // ?regex
380
-if(empty($p)){return 0;}
381
-if($t = ini_get('track_errors')){$o = isset($php_errormsg) ? $php_errormsg : null;}
382
-else{ini_set('track_errors', 1);}
380
+if (empty($p)) {return 0; }
381
+if ($t = ini_get('track_errors')) {$o = isset($php_errormsg) ? $php_errormsg : null; }
382
+else {ini_set('track_errors', 1); }
383 383
 unset($php_errormsg);
384
-if(($d = ini_get('display_errors'))){ini_set('display_errors', 0);}
384
+if (($d = ini_get('display_errors'))) {ini_set('display_errors', 0); }
385 385
 preg_match($p, '');
386
-if($d){ini_set('display_errors', 1);}
386
+if ($d) {ini_set('display_errors', 1); }
387 387
 $r = isset($php_errormsg) ? 0 : 1;
388
-if($t){$php_errormsg = isset($o) ? $o : null;}
389
-else{ini_set('track_errors', 0);}
388
+if ($t) {$php_errormsg = isset($o) ? $o : null; }
389
+else {ini_set('track_errors', 0); }
390 390
 return $r;
391 391
 // eof
392 392
 }
393 393
 
394
-function hl_spec($t){
394
+function hl_spec($t) {
395 395
 // final $spec
396 396
 $s = array();
397 397
 $t = str_replace(array("\t", "\r", "\n", ' '), '', preg_replace_callback('/"(?>(`.|[^"])*)"/sm', create_function('$m', 'return substr(str_replace(array(";", "|", "~", " ", ",", "/", "(", ")", \'`"\'), array("\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07", "\x08", "\""), $m[0]), 1, -1);'), trim($t)));
398
-for($i = count(($t = explode(';', $t))); --$i>=0;){
398
+for ($i = count(($t = explode(';', $t))); --$i >= 0;) {
399 399
  $w = $t[$i];
400
- if(empty($w) or ($e = strpos($w, '=')) === false or !strlen(($a =  substr($w, $e+1)))){continue;}
400
+ if (empty($w) or ($e = strpos($w, '=')) === false or !strlen(($a = substr($w, $e + 1)))) {continue; }
401 401
  $y = $n = array();
402
- foreach(explode(',', $a) as $v){
403
-  if(!preg_match('`^([a-z:\-\*]+)(?:\((.*?)\))?`i', $v, $m)){continue;}
404
-  if(($x = strtolower($m[1])) == '-*'){$n['*'] = 1; continue;}
405
-  if($x[0] == '-'){$n[substr($x, 1)] = 1; continue;}
406
-  if(!isset($m[2])){$y[$x] = 1; continue;}
407
-  foreach(explode('/', $m[2]) as $m){
408
-   if(empty($m) or ($p = strpos($m, '=')) == 0 or $p < 5){$y[$x] = 1; continue;}
409
-   $y[$x][strtolower(substr($m, 0, $p))] = str_replace(array("\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07", "\x08"), array(";", "|", "~", " ", ",", "/", "(", ")"), substr($m, $p+1));
402
+ foreach (explode(',', $a) as $v) {
403
+  if (!preg_match('`^([a-z:\-\*]+)(?:\((.*?)\))?`i', $v, $m)) {continue; }
404
+  if (($x = strtolower($m[1])) == '-*') {$n['*'] = 1; continue; }
405
+  if ($x[0] == '-') {$n[substr($x, 1)] = 1; continue; }
406
+  if (!isset($m[2])) {$y[$x] = 1; continue; }
407
+  foreach (explode('/', $m[2]) as $m) {
408
+   if (empty($m) or ($p = strpos($m, '=')) == 0 or $p < 5) {$y[$x] = 1; continue; }
409
+   $y[$x][strtolower(substr($m, 0, $p))] = str_replace(array("\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07", "\x08"), array(";", "|", "~", " ", ",", "/", "(", ")"), substr($m, $p + 1));
410 410
   }
411
-  if(isset($y[$x]['match']) && !hl_regex($y[$x]['match'])){unset($y[$x]['match']);}
412
-  if(isset($y[$x]['nomatch']) && !hl_regex($y[$x]['nomatch'])){unset($y[$x]['nomatch']);}
411
+  if (isset($y[$x]['match']) && !hl_regex($y[$x]['match'])) {unset($y[$x]['match']); }
412
+  if (isset($y[$x]['nomatch']) && !hl_regex($y[$x]['nomatch'])) {unset($y[$x]['nomatch']); }
413 413
  }
414
- if(!count($y) && !count($n)){continue;}
415
- foreach(explode(',', substr($w, 0, $e)) as $v){
416
-  if(!strlen(($v = strtolower($v)))){continue;}
417
-  if(count($y)){$s[$v] = $y;}
418
-  if(count($n)){$s[$v]['n'] = $n;}
414
+ if (!count($y) && !count($n)) {continue; }
415
+ foreach (explode(',', substr($w, 0, $e)) as $v) {
416
+  if (!strlen(($v = strtolower($v)))) {continue; }
417
+  if (count($y)) {$s[$v] = $y; }
418
+  if (count($n)) {$s[$v]['n'] = $n; }
419 419
  }
420 420
 }
421 421
 return $s;
422 422
 // eof
423 423
 }
424 424
 
425
-function hl_tag($t){
425
+function hl_tag($t) {
426 426
 // tag/attribute handler
427 427
 global $C;
428 428
 $t = $t[0];
429 429
 // invalid < >
430
-if($t == '< '){return '&lt; ';}
431
-if($t == '>'){return '&gt;';}
432
-if(!preg_match('`^<(/?)([a-zA-Z][a-zA-Z1-6]*)([^>]*?)\s?>$`m', $t, $m)){
430
+if ($t == '< ') {return '&lt; '; }
431
+if ($t == '>') {return '&gt;'; }
432
+if (!preg_match('`^<(/?)([a-zA-Z][a-zA-Z1-6]*)([^>]*?)\s?>$`m', $t, $m)) {
433 433
  //return str_replace(array('<', '>'), array('&lt;', '&gt;'), $t);
434
- return (($C['keep_bad']%2) ? str_replace(array('<', '>'), array('&lt;', '&gt;'), $t) : '');
435
-}elseif(!isset($C['elements'][($e = strtolower($m[2]))])){
436
- return (($C['keep_bad']%2) ? str_replace(array('<', '>'), array('&lt;', '&gt;'), $t) : '');
434
+ return (($C['keep_bad'] % 2) ? str_replace(array('<', '>'), array('&lt;', '&gt;'), $t) : '');
435
+}elseif (!isset($C['elements'][($e = strtolower($m[2]))])) {
436
+ return (($C['keep_bad'] % 2) ? str_replace(array('<', '>'), array('&lt;', '&gt;'), $t) : '');
437 437
 }
438 438
 // attr string
439 439
 $a = str_replace(array("\n", "\r", "\t"), ' ', trim($m[3]));
440 440
 // tag transform
441 441
 static $eD = array('applet'=>1, 'center'=>1, 'dir'=>1, 'embed'=>1, 'font'=>1, 'isindex'=>1, 'menu'=>1, 's'=>1, 'strike'=>1, 'u'=>1); // Deprecated
442
-if($C['make_tag_strict'] && isset($eD[$e])){
442
+if ($C['make_tag_strict'] && isset($eD[$e])) {
443 443
  $trt = hl_tag2($e, $a, $C['make_tag_strict']);
444
- if(!$e){return (($C['keep_bad']%2) ? str_replace(array('<', '>'), array('&lt;', '&gt;'), $t) : '');}
444
+ if (!$e) {return (($C['keep_bad'] % 2) ? str_replace(array('<', '>'), array('&lt;', '&gt;'), $t) : ''); }
445 445
 }
446 446
 // close tag
447 447
 static $eE = array('area'=>1, 'br'=>1, 'col'=>1, 'embed'=>1, 'hr'=>1, 'img'=>1, 'input'=>1, 'isindex'=>1, 'param'=>1); // Empty ele
448
-if(!empty($m[1])){
449
- return (!isset($eE[$e]) ? (empty($C['hook_tag']) ? "</$e>" : $C['hook_tag']($e)) : (($C['keep_bad'])%2 ? str_replace(array('<', '>'), array('&lt;', '&gt;'), $t) : ''));
448
+if (!empty($m[1])) {
449
+ return (!isset($eE[$e]) ? (empty($C['hook_tag']) ? "</$e>" : $C['hook_tag']($e)) : (($C['keep_bad']) % 2 ? str_replace(array('<', '>'), array('&lt;', '&gt;'), $t) : ''));
450 450
 }
451 451
 // open tag & attr
452 452
 static $aN = array('abbr'=>array('td'=>1, 'th'=>1), 'accept-charset'=>array('form'=>1), 'accept'=>array('form'=>1, 'input'=>1), 'accesskey'=>array('a'=>1, 'area'=>1, 'button'=>1, 'input'=>1, 'label'=>1, 'legend'=>1, 'textarea'=>1), 'action'=>array('form'=>1), 'align'=>array('caption'=>1, 'embed'=>1, 'applet'=>1, 'iframe'=>1, 'img'=>1, 'input'=>1, 'object'=>1, 'legend'=>1, 'table'=>1, 'hr'=>1, 'div'=>1, 'h1'=>1, 'h2'=>1, 'h3'=>1, 'h4'=>1, 'h5'=>1, 'h6'=>1, 'p'=>1, 'col'=>1, 'colgroup'=>1, 'tbody'=>1, 'td'=>1, 'tfoot'=>1, 'th'=>1, 'thead'=>1, 'tr'=>1), 'allowfullscreen'=>array('iframe'=>1), 'alt'=>array('applet'=>1, 'area'=>1, 'img'=>1, 'input'=>1), 'archive'=>array('applet'=>1, 'object'=>1), 'axis'=>array('td'=>1, 'th'=>1), 'bgcolor'=>array('embed'=>1, 'table'=>1, 'tr'=>1, 'td'=>1, 'th'=>1), 'border'=>array('table'=>1, 'img'=>1, 'object'=>1), 'bordercolor'=>array('table'=>1, 'td'=>1, 'tr'=>1), 'cellpadding'=>array('table'=>1), 'cellspacing'=>array('table'=>1), 'char'=>array('col'=>1, 'colgroup'=>1, 'tbody'=>1, 'td'=>1, 'tfoot'=>1, 'th'=>1, 'thead'=>1, 'tr'=>1), 'charoff'=>array('col'=>1, 'colgroup'=>1, 'tbody'=>1, 'td'=>1, 'tfoot'=>1, 'th'=>1, 'thead'=>1, 'tr'=>1), 'charset'=>array('a'=>1, 'script'=>1), 'checked'=>array('input'=>1), 'cite'=>array('blockquote'=>1, 'q'=>1, 'del'=>1, 'ins'=>1), 'classid'=>array('object'=>1), 'clear'=>array('br'=>1), 'code'=>array('applet'=>1), 'codebase'=>array('object'=>1, 'applet'=>1), 'codetype'=>array('object'=>1), 'color'=>array('font'=>1), 'cols'=>array('textarea'=>1), 'colspan'=>array('td'=>1, 'th'=>1), 'compact'=>array('dir'=>1, 'dl'=>1, 'menu'=>1, 'ol'=>1, 'ul'=>1), 'coords'=>array('area'=>1, 'a'=>1), 'data'=>array('object'=>1), 'datetime'=>array('del'=>1, 'ins'=>1), 'declare'=>array('object'=>1), 'defer'=>array('script'=>1), 'dir'=>array('bdo'=>1), 'disabled'=>array('button'=>1, 'input'=>1, 'optgroup'=>1, 'option'=>1, 'select'=>1, 'textarea'=>1), 'enctype'=>array('form'=>1), 'face'=>array('font'=>1), 'flashvars'=>array('embed'=>1), 'for'=>array('label'=>1), 'frame'=>array('table'=>1), 'frameborder'=>array('iframe'=>1), 'headers'=>array('td'=>1, 'th'=>1), 'height'=>array('embed'=>1, 'iframe'=>1, 'td'=>1, 'th'=>1, 'img'=>1, 'object'=>1, 'applet'=>1), 'href'=>array('a'=>1, 'area'=>1), 'hreflang'=>array('a'=>1), 'hspace'=>array('applet'=>1, 'img'=>1, 'object'=>1), 'ismap'=>array('img'=>1, 'input'=>1), 'label'=>array('option'=>1, 'optgroup'=>1), 'language'=>array('script'=>1), 'longdesc'=>array('img'=>1, 'iframe'=>1), 'marginheight'=>array('iframe'=>1), 'marginwidth'=>array('iframe'=>1), 'maxlength'=>array('input'=>1), 'method'=>array('form'=>1), 'model'=>array('embed'=>1), 'multiple'=>array('select'=>1), 'name'=>array('button'=>1, 'embed'=>1, 'textarea'=>1, 'applet'=>1, 'select'=>1, 'form'=>1, 'iframe'=>1, 'img'=>1, 'a'=>1, 'input'=>1, 'object'=>1, 'map'=>1, 'param'=>1), 'nohref'=>array('area'=>1), 'noshade'=>array('hr'=>1), 'nowrap'=>array('td'=>1, 'th'=>1), 'object'=>array('applet'=>1), 'onblur'=>array('a'=>1, 'area'=>1, 'button'=>1, 'input'=>1, 'label'=>1, 'select'=>1, 'textarea'=>1), 'onchange'=>array('input'=>1, 'select'=>1, 'textarea'=>1), 'onfocus'=>array('a'=>1, 'area'=>1, 'button'=>1, 'input'=>1, 'label'=>1, 'select'=>1, 'textarea'=>1), 'onreset'=>array('form'=>1), 'onselect'=>array('input'=>1, 'textarea'=>1), 'onsubmit'=>array('form'=>1), 'pluginspage'=>array('embed'=>1), 'pluginurl'=>array('embed'=>1), 'prompt'=>array('isindex'=>1), 'readonly'=>array('textarea'=>1, 'input'=>1), 'rel'=>array('a'=>1), 'rev'=>array('a'=>1), 'rows'=>array('textarea'=>1), 'rowspan'=>array('td'=>1, 'th'=>1), 'rules'=>array('table'=>1), 'scope'=>array('td'=>1, 'th'=>1), 'scrolling'=>array('iframe'=>1), 'selected'=>array('option'=>1), 'shape'=>array('area'=>1, 'a'=>1), 'size'=>array('hr'=>1, 'font'=>1, 'input'=>1, 'select'=>1), 'span'=>array('col'=>1, 'colgroup'=>1), 'src'=>array('embed'=>1, 'script'=>1, 'input'=>1, 'iframe'=>1, 'img'=>1), 'standby'=>array('object'=>1), 'start'=>array('ol'=>1), 'summary'=>array('table'=>1), 'tabindex'=>array('a'=>1, 'area'=>1, 'button'=>1, 'input'=>1, 'object'=>1, 'select'=>1, 'textarea'=>1), 'target'=>array('a'=>1, 'area'=>1, 'form'=>1), 'type'=>array('a'=>1, 'embed'=>1, 'object'=>1, 'param'=>1, 'script'=>1, 'input'=>1, 'li'=>1, 'ol'=>1, 'ul'=>1, 'button'=>1), 'usemap'=>array('img'=>1, 'input'=>1, 'object'=>1), 'valign'=>array('col'=>1, 'colgroup'=>1, 'tbody'=>1, 'td'=>1, 'tfoot'=>1, 'th'=>1, 'thead'=>1, 'tr'=>1), 'value'=>array('input'=>1, 'option'=>1, 'param'=>1, 'button'=>1, 'li'=>1), 'valuetype'=>array('param'=>1), 'vspace'=>array('applet'=>1, 'img'=>1, 'object'=>1), 'width'=>array('embed'=>1, 'hr'=>1, 'iframe'=>1, 'img'=>1, 'object'=>1, 'table'=>1, 'td'=>1, 'th'=>1, 'applet'=>1, 'col'=>1, 'colgroup'=>1, 'pre'=>1), 'wmode'=>array('embed'=>1), 'xml:space'=>array('pre'=>1, 'script'=>1, 'style'=>1)); // Ele-specific
453
-$aN['background']=(isset($aN['background'])?array_merge($aN['background'],array('td'=>1)):array('td'=>1));//allow attribute background for (additional) elements, its not allowed by HTML Standards exept for body, but used anyway; one should check for the url to be allowed by application means
453
+$aN['background'] = (isset($aN['background']) ?array_merge($aN['background'], array('td'=>1)) : array('td'=>1)); //allow attribute background for (additional) elements, its not allowed by HTML Standards exept for body, but used anyway; one should check for the url to be allowed by application means
454 454
 static $aNE = array('allowfullscreen'=>1, 'checked'=>1, 'compact'=>1, 'declare'=>1, 'defer'=>1, 'disabled'=>1, 'ismap'=>1, 'multiple'=>1, 'nohref'=>1, 'noresize'=>1, 'noshade'=>1, 'nowrap'=>1, 'readonly'=>1, 'selected'=>1); // Empty
455 455
 static $aNP = array('action'=>1, 'cite'=>1, 'classid'=>1, 'codebase'=>1, 'data'=>1, 'href'=>1, 'longdesc'=>1, 'model'=>1, 'pluginspage'=>1, 'pluginurl'=>1, 'usemap'=>1); // Need scheme check; excludes style, on* & src
456 456
 static $aNU = array('class'=>array('param'=>1, 'script'=>1), 'dir'=>array('applet'=>1, 'bdo'=>1, 'br'=>1, 'iframe'=>1, 'param'=>1, 'script'=>1), 'id'=>array('script'=>1), 'lang'=>array('applet'=>1, 'br'=>1, 'iframe'=>1, 'param'=>1, 'script'=>1), 'xml:lang'=>array('applet'=>1, 'br'=>1, 'iframe'=>1, 'param'=>1, 'script'=>1), 'onclick'=>array('applet'=>1, 'bdo'=>1, 'br'=>1, 'font'=>1, 'iframe'=>1, 'isindex'=>1, 'param'=>1, 'script'=>1), 'ondblclick'=>array('applet'=>1, 'bdo'=>1, 'br'=>1, 'font'=>1, 'iframe'=>1, 'isindex'=>1, 'param'=>1, 'script'=>1), 'onkeydown'=>array('applet'=>1, 'bdo'=>1, 'br'=>1, 'font'=>1, 'iframe'=>1, 'isindex'=>1, 'param'=>1, 'script'=>1), 'onkeypress'=>array('applet'=>1, 'bdo'=>1, 'br'=>1, 'font'=>1, 'iframe'=>1, 'isindex'=>1, 'param'=>1, 'script'=>1), 'onkeyup'=>array('applet'=>1, 'bdo'=>1, 'br'=>1, 'font'=>1, 'iframe'=>1, 'isindex'=>1, 'param'=>1, 'script'=>1), 'onmousedown'=>array('applet'=>1, 'bdo'=>1, 'br'=>1, 'font'=>1, 'iframe'=>1, 'isindex'=>1, 'param'=>1, 'script'=>1), 'onmousemove'=>array('applet'=>1, 'bdo'=>1, 'br'=>1, 'font'=>1, 'iframe'=>1, 'isindex'=>1, 'param'=>1, 'script'=>1), 'onmouseout'=>array('applet'=>1, 'bdo'=>1, 'br'=>1, 'font'=>1, 'iframe'=>1, 'isindex'=>1, 'param'=>1, 'script'=>1), 'onmouseover'=>array('applet'=>1, 'bdo'=>1, 'br'=>1, 'font'=>1, 'iframe'=>1, 'isindex'=>1, 'param'=>1, 'script'=>1), 'onmouseup'=>array('applet'=>1, 'bdo'=>1, 'br'=>1, 'font'=>1, 'iframe'=>1, 'isindex'=>1, 'param'=>1, 'script'=>1), 'style'=>array('param'=>1, 'script'=>1), 'title'=>array('param'=>1, 'script'=>1)); // Univ & exceptions
457 457
 
458
-if($C['lc_std_val']){
458
+if ($C['lc_std_val']) {
459 459
  // predef attr vals for $eAL & $aNE ele
460 460
  static $aNL = array('all'=>1, 'baseline'=>1, 'bottom'=>1, 'button'=>1, 'center'=>1, 'char'=>1, 'checkbox'=>1, 'circle'=>1, 'col'=>1, 'colgroup'=>1, 'cols'=>1, 'data'=>1, 'default'=>1, 'file'=>1, 'get'=>1, 'groups'=>1, 'hidden'=>1, 'image'=>1, 'justify'=>1, 'left'=>1, 'ltr'=>1, 'middle'=>1, 'none'=>1, 'object'=>1, 'password'=>1, 'poly'=>1, 'post'=>1, 'preserve'=>1, 'radio'=>1, 'rect'=>1, 'ref'=>1, 'reset'=>1, 'right'=>1, 'row'=>1, 'rowgroup'=>1, 'rows'=>1, 'rtl'=>1, 'submit'=>1, 'text'=>1, 'top'=>1);
461 461
  static $eAL = array('a'=>1, 'area'=>1, 'bdo'=>1, 'button'=>1, 'col'=>1, 'form'=>1, 'img'=>1, 'input'=>1, 'object'=>1, 'optgroup'=>1, 'option'=>1, 'param'=>1, 'script'=>1, 'select'=>1, 'table'=>1, 'td'=>1, 'tfoot'=>1, 'th'=>1, 'thead'=>1, 'tr'=>1, 'xml:space'=>1);
@@ -463,7 +463,7 @@  discard block
 block discarded – undo
463 463
 }
464 464
 
465 465
 $depTr = 0;
466
-if($C['no_deprecated_attr']){
466
+if ($C['no_deprecated_attr']) {
467 467
  // dep attr:applicable ele
468 468
  static $aND = array('align'=>array('caption'=>1, 'div'=>1, 'h1'=>1, 'h2'=>1, 'h3'=>1, 'h4'=>1, 'h5'=>1, 'h6'=>1, 'hr'=>1, 'img'=>1, 'input'=>1, 'legend'=>1, 'object'=>1, 'p'=>1, 'table'=>1), 'bgcolor'=>array('table'=>1, 'td'=>1, 'th'=>1, 'tr'=>1), 'border'=>array('img'=>1, 'object'=>1), 'bordercolor'=>array('table'=>1, 'td'=>1, 'tr'=>1), 'clear'=>array('br'=>1), 'compact'=>array('dl'=>1, 'ol'=>1, 'ul'=>1), 'height'=>array('td'=>1, 'th'=>1), 'hspace'=>array('img'=>1, 'object'=>1), 'language'=>array('script'=>1), 'name'=>array('a'=>1, 'form'=>1, 'iframe'=>1, 'img'=>1, 'map'=>1), 'noshade'=>array('hr'=>1), 'nowrap'=>array('td'=>1, 'th'=>1), 'size'=>array('hr'=>1), 'start'=>array('ol'=>1), 'type'=>array('li'=>1, 'ol'=>1, 'ul'=>1), 'value'=>array('li'=>1), 'vspace'=>array('img'=>1, 'object'=>1), 'width'=>array('hr'=>1, 'pre'=>1, 'td'=>1, 'th'=>1));
469 469
  static $eAD = array('a'=>1, 'br'=>1, 'caption'=>1, 'div'=>1, 'dl'=>1, 'form'=>1, 'h1'=>1, 'h2'=>1, 'h3'=>1, 'h4'=>1, 'h5'=>1, 'h6'=>1, 'hr'=>1, 'iframe'=>1, 'img'=>1, 'input'=>1, 'legend'=>1, 'li'=>1, 'map'=>1, 'object'=>1, 'ol'=>1, 'p'=>1, 'pre'=>1, 'script'=>1, 'table'=>1, 'td'=>1, 'th'=>1, 'tr'=>1, 'ul'=>1);
@@ -471,196 +471,196 @@  discard block
 block discarded – undo
471 471
 }
472 472
 
473 473
 // attr name-vals
474
-if(strpos($a, "\x01") !== false){$a = preg_replace('`\x01[^\x01]*\x01`', '', $a);} // No comment/CDATA sec
474
+if (strpos($a, "\x01") !== false) {$a = preg_replace('`\x01[^\x01]*\x01`', '', $a); } // No comment/CDATA sec
475 475
 $mode = 0; $a = trim($a, ' /'); $aA = array();
476
-while(strlen($a)){
476
+while (strlen($a)) {
477 477
  $w = 0;
478
- switch($mode){
478
+ switch ($mode) {
479 479
   case 0: // Name
480
-   if(preg_match('`^[a-zA-Z][\-a-zA-Z:]+`', $a, $m)){
480
+   if (preg_match('`^[a-zA-Z][\-a-zA-Z:]+`', $a, $m)) {
481 481
     $nm = strtolower($m[0]);
482 482
     $w = $mode = 1; $a = ltrim(substr_replace($a, '', 0, strlen($m[0])));
483 483
    }
484 484
   break; case 1:
485
-   if($a[0] == '='){ // =
485
+   if ($a[0] == '=') { // =
486 486
     $w = 1; $mode = 2; $a = ltrim($a, '= ');
487
-   }else{ // No val
487
+   } else { // No val
488 488
     $w = 1; $mode = 0; $a = ltrim($a);
489 489
     $aA[$nm] = '';
490 490
    }
491 491
   break; case 2: // Val
492
-   if(preg_match('`^((?:"[^"]*")|(?:\'[^\']*\')|(?:\s*[^\s"\']+))(.*)`', $a, $m)){
492
+   if (preg_match('`^((?:"[^"]*")|(?:\'[^\']*\')|(?:\s*[^\s"\']+))(.*)`', $a, $m)) {
493 493
     $a = ltrim($m[2]); $m = $m[1]; $w = 1; $mode = 0;
494 494
     $aA[$nm] = trim(str_replace('<', '&lt;', ($m[0] == '"' or $m[0] == '\'') ? substr($m, 1, -1) : $m));
495 495
    }
496 496
   break;
497 497
  }
498
- if($w == 0){ // Parse errs, deal with space, " & '
498
+ if ($w == 0) { // Parse errs, deal with space, " & '
499 499
   $a = preg_replace('`^(?:"[^"]*("|$)|\'[^\']*(\'|$)|\S)*\s*`', '', $a);
500 500
   $mode = 0;
501 501
  }
502 502
 }
503
-if($mode == 1){$aA[$nm] = '';}
503
+if ($mode == 1) {$aA[$nm] = ''; }
504 504
 
505 505
 // clean attrs
506 506
 global $S;
507 507
 $rl = isset($S[$e]) ? $S[$e] : array();
508 508
 $a = array(); $nfr = 0;
509
-foreach($aA as $k=>$v){
510
-  if(((isset($C['deny_attribute']['*']) ? isset($C['deny_attribute'][$k]) : !isset($C['deny_attribute'][$k])) && (isset($aN[$k][$e]) or (isset($aNU[$k]) && !isset($aNU[$k][$e]))) && !isset($rl['n'][$k]) && !isset($rl['n']['*'])) or isset($rl[$k])){
511
-  if(isset($aNE[$k])){$v = $k;}
512
-  elseif(!empty($lcase) && (($e != 'button' or $e != 'input') or $k == 'type')){ // Rather loose but ?not cause issues
509
+foreach ($aA as $k=>$v) {
510
+  if (((isset($C['deny_attribute']['*']) ? isset($C['deny_attribute'][$k]) : !isset($C['deny_attribute'][$k])) && (isset($aN[$k][$e]) or (isset($aNU[$k]) && !isset($aNU[$k][$e]))) && !isset($rl['n'][$k]) && !isset($rl['n']['*'])) or isset($rl[$k])) {
511
+  if (isset($aNE[$k])) {$v = $k; }
512
+  elseif (!empty($lcase) && (($e != 'button' or $e != 'input') or $k == 'type')) { // Rather loose but ?not cause issues
513 513
    $v = (isset($aNL[($v2 = strtolower($v))])) ? $v2 : $v;
514 514
   }
515
-  if($k == 'style' && !$C['style_pass']){
516
-   if(false !== strpos($v, '&#')){
515
+  if ($k == 'style' && !$C['style_pass']) {
516
+   if (false !== strpos($v, '&#')) {
517 517
     static $sC = array('&#x20;'=>' ', '&#32;'=>' ', '&#x45;'=>'e', '&#69;'=>'e', '&#x65;'=>'e', '&#101;'=>'e', '&#x58;'=>'x', '&#88;'=>'x', '&#x78;'=>'x', '&#120;'=>'x', '&#x50;'=>'p', '&#80;'=>'p', '&#x70;'=>'p', '&#112;'=>'p', '&#x53;'=>'s', '&#83;'=>'s', '&#x73;'=>'s', '&#115;'=>'s', '&#x49;'=>'i', '&#73;'=>'i', '&#x69;'=>'i', '&#105;'=>'i', '&#x4f;'=>'o', '&#79;'=>'o', '&#x6f;'=>'o', '&#111;'=>'o', '&#x4e;'=>'n', '&#78;'=>'n', '&#x6e;'=>'n', '&#110;'=>'n', '&#x55;'=>'u', '&#85;'=>'u', '&#x75;'=>'u', '&#117;'=>'u', '&#x52;'=>'r', '&#82;'=>'r', '&#x72;'=>'r', '&#114;'=>'r', '&#x4c;'=>'l', '&#76;'=>'l', '&#x6c;'=>'l', '&#108;'=>'l', '&#x28;'=>'(', '&#40;'=>'(', '&#x29;'=>')', '&#41;'=>')', '&#x20;'=>':', '&#32;'=>':', '&#x22;'=>'"', '&#34;'=>'"', '&#x27;'=>"'", '&#39;'=>"'", '&#x2f;'=>'/', '&#47;'=>'/', '&#x2a;'=>'*', '&#42;'=>'*', '&#x5c;'=>'\\', '&#92;'=>'\\');
518 518
     $v = strtr($v, $sC);
519 519
    }
520 520
    $v = preg_replace_callback('`(url(?:\()(?: )*(?:\'|"|&(?:quot|apos);)?)(.+?)((?:\'|"|&(?:quot|apos);)?(?: )*(?:\)))`iS', 'hl_prot', $v);
521 521
    $v = !$C['css_expression'] ? preg_replace('`expression`i', ' ', preg_replace('`\\\\\S|(/|(%2f))(\*|(%2a))`i', ' ', $v)) : $v;
522
-  }elseif(isset($aNP[$k]) or strpos($k, 'src') !== false or $k[0] == 'o'){
522
+  }elseif (isset($aNP[$k]) or strpos($k, 'src') !== false or $k[0] == 'o') {
523 523
    $v = str_replace("­", ' ', (strpos($v, '&') !== false ? str_replace(array('&#xad;', '&#173;', '&shy;'), ' ', $v) : $v)); # double-quoted char is soft-hyphen; appears here as "­" or hyphen or something else depending on viewing software
524 524
    $v = hl_prot($v, $k);
525
-   if($k == 'href'){ // X-spam
526
-    if($C['anti_mail_spam'] && strpos($v, 'mailto:') === 0){
525
+   if ($k == 'href') { // X-spam
526
+    if ($C['anti_mail_spam'] && strpos($v, 'mailto:') === 0) {
527 527
      $v = str_replace('@', htmlspecialchars($C['anti_mail_spam']), $v);
528
-    }elseif($C['anti_link_spam']){
528
+    }elseif ($C['anti_link_spam']) {
529 529
      $r1 = $C['anti_link_spam'][1];
530
-     if(!empty($r1) && preg_match($r1, $v)){continue;}
530
+     if (!empty($r1) && preg_match($r1, $v)) {continue; }
531 531
      $r0 = $C['anti_link_spam'][0];
532
-     if(!empty($r0) && preg_match($r0, $v)){
533
-      if(isset($a['rel'])){
534
-       if(!preg_match('`\bnofollow\b`i', $a['rel'])){$a['rel'] .= ' nofollow';}
535
-      }elseif(isset($aA['rel'])){
536
-       if(!preg_match('`\bnofollow\b`i', $aA['rel'])){$nfr = 1;}
537
-      }else{$a['rel'] = 'nofollow';}
532
+     if (!empty($r0) && preg_match($r0, $v)) {
533
+      if (isset($a['rel'])) {
534
+       if (!preg_match('`\bnofollow\b`i', $a['rel'])) {$a['rel'] .= ' nofollow'; }
535
+      }elseif (isset($aA['rel'])) {
536
+       if (!preg_match('`\bnofollow\b`i', $aA['rel'])) {$nfr = 1; }
537
+      } else {$a['rel'] = 'nofollow'; }
538 538
      }
539 539
     }
540 540
    }
541 541
   }
542
-  if(isset($rl[$k]) && is_array($rl[$k]) && ($v = hl_attrval($k, $v, $rl[$k])) === 0){continue;}
542
+  if (isset($rl[$k]) && is_array($rl[$k]) && ($v = hl_attrval($k, $v, $rl[$k])) === 0) {continue; }
543 543
   $a[$k] = str_replace('"', '&quot;', $v);
544 544
  }
545 545
 }
546
-if($nfr){$a['rel'] = isset($a['rel']) ? $a['rel']. ' nofollow' : 'nofollow';}
546
+if ($nfr) {$a['rel'] = isset($a['rel']) ? $a['rel'].' nofollow' : 'nofollow'; }
547 547
 
548 548
 // rqd attr
549 549
 static $eAR = array('area'=>array('alt'=>'area'), 'bdo'=>array('dir'=>'ltr'), 'form'=>array('action'=>''), 'img'=>array('src'=>'', 'alt'=>'image'), 'map'=>array('name'=>''), 'optgroup'=>array('label'=>''), 'param'=>array('name'=>''), 'script'=>array('type'=>'text/javascript'), 'textarea'=>array('rows'=>'10', 'cols'=>'50'));
550
-if(isset($eAR[$e])){
551
- foreach($eAR[$e] as $k=>$v){
552
-  if(!isset($a[$k])){$a[$k] = isset($v[0]) ? $v : $k;}
550
+if (isset($eAR[$e])) {
551
+ foreach ($eAR[$e] as $k=>$v) {
552
+  if (!isset($a[$k])) {$a[$k] = isset($v[0]) ? $v : $k; }
553 553
  }
554 554
 }
555 555
 
556 556
 // depr attrs
557
-if($depTr){
557
+if ($depTr) {
558 558
  $c = array();
559
- foreach($a as $k=>$v){
560
-  if($k == 'style' or !isset($aND[$k][$e])){continue;}
561
-  if($k == 'align'){
559
+ foreach ($a as $k=>$v) {
560
+  if ($k == 'style' or !isset($aND[$k][$e])) {continue; }
561
+  if ($k == 'align') {
562 562
    unset($a['align']);
563
-   if($e == 'img' && ($v == 'left' or $v == 'right')){$c[] = 'float: '. $v;}
564
-   elseif(($e == 'div' or $e == 'table') && $v == 'center'){$c[] = 'margin: auto';}
565
-   else{$c[] = 'text-align: '. $v;}
566
-  }elseif($k == 'bgcolor'){
563
+   if ($e == 'img' && ($v == 'left' or $v == 'right')) {$c[] = 'float: '.$v; }
564
+   elseif (($e == 'div' or $e == 'table') && $v == 'center') {$c[] = 'margin: auto'; }
565
+   else {$c[] = 'text-align: '.$v; }
566
+  }elseif ($k == 'bgcolor') {
567 567
    unset($a['bgcolor']);
568
-   $c[] = 'background-color: '. $v;
569
-  }elseif($k == 'border'){
568
+   $c[] = 'background-color: '.$v;
569
+  }elseif ($k == 'border') {
570 570
    unset($a['border']); $c[] = "border: {$v}px";
571
-  }elseif($k == 'bordercolor'){
572
-   unset($a['bordercolor']); $c[] = 'border-color: '. $v;
573
-  }elseif($k == 'clear'){
574
-   unset($a['clear']); $c[] = 'clear: '. ($v != 'all' ? $v : 'both');
575
-  }elseif($k == 'compact'){
571
+  }elseif ($k == 'bordercolor') {
572
+   unset($a['bordercolor']); $c[] = 'border-color: '.$v;
573
+  }elseif ($k == 'clear') {
574
+   unset($a['clear']); $c[] = 'clear: '.($v != 'all' ? $v : 'both');
575
+  }elseif ($k == 'compact') {
576 576
    unset($a['compact']); $c[] = 'font-size: 85%';
577
-  }elseif($k == 'height' or $k == 'width'){
578
-   unset($a[$k]); $c[] = $k. ': '. ($v[0] != '*' ? $v. (ctype_digit($v) ? 'px' : '') : 'auto');
579
-  }elseif($k == 'hspace'){
577
+  }elseif ($k == 'height' or $k == 'width') {
578
+   unset($a[$k]); $c[] = $k.': '.($v[0] != '*' ? $v.(ctype_digit($v) ? 'px' : '') : 'auto');
579
+  }elseif ($k == 'hspace') {
580 580
    unset($a['hspace']); $c[] = "margin-left: {$v}px; margin-right: {$v}px";
581
-  }elseif($k == 'language' && !isset($a['type'])){
581
+  }elseif ($k == 'language' && !isset($a['type'])) {
582 582
    unset($a['language']);
583
-   $a['type'] = 'text/'. strtolower($v);
584
-  }elseif($k == 'name'){
585
-   if($C['no_deprecated_attr'] == 2 or ($e != 'a' && $e != 'map')){unset($a['name']);}
586
-   if(!isset($a['id']) && preg_match('`[a-zA-Z][a-zA-Z\d.:_\-]*`', $v)){$a['id'] = $v;}
587
-  }elseif($k == 'noshade'){
583
+   $a['type'] = 'text/'.strtolower($v);
584
+  }elseif ($k == 'name') {
585
+   if ($C['no_deprecated_attr'] == 2 or ($e != 'a' && $e != 'map')) {unset($a['name']); }
586
+   if (!isset($a['id']) && preg_match('`[a-zA-Z][a-zA-Z\d.:_\-]*`', $v)) {$a['id'] = $v; }
587
+  }elseif ($k == 'noshade') {
588 588
    unset($a['noshade']); $c[] = 'border-style: none; border: 0; background-color: gray; color: gray';
589
-  }elseif($k == 'nowrap'){
589
+  }elseif ($k == 'nowrap') {
590 590
    unset($a['nowrap']); $c[] = 'white-space: nowrap';
591
-  }elseif($k == 'size'){
592
-   unset($a['size']); $c[] = 'size: '. $v. 'px';
593
-  }elseif($k == 'start' or $k == 'value'){
591
+  }elseif ($k == 'size') {
592
+   unset($a['size']); $c[] = 'size: '.$v.'px';
593
+  }elseif ($k == 'start' or $k == 'value') {
594 594
    unset($a[$k]);
595
-  }elseif($k == 'type'){
595
+  }elseif ($k == 'type') {
596 596
    unset($a['type']);
597 597
    static $ol_type = array('i'=>'lower-roman', 'I'=>'upper-roman', 'a'=>'lower-latin', 'A'=>'upper-latin', '1'=>'decimal');
598
-   $c[] = 'list-style-type: '. (isset($ol_type[$v]) ? $ol_type[$v] : 'decimal');
599
-  }elseif($k == 'vspace'){
598
+   $c[] = 'list-style-type: '.(isset($ol_type[$v]) ? $ol_type[$v] : 'decimal');
599
+  }elseif ($k == 'vspace') {
600 600
    unset($a['vspace']); $c[] = "margin-top: {$v}px; margin-bottom: {$v}px";
601 601
   }
602 602
  }
603
- if(count($c)){
603
+ if (count($c)) {
604 604
   $c = implode('; ', $c);
605
-  $a['style'] = isset($a['style']) ? rtrim($a['style'], ' ;'). '; '. $c. ';': $c. ';';
605
+  $a['style'] = isset($a['style']) ? rtrim($a['style'], ' ;').'; '.$c.';' : $c.';';
606 606
  }
607 607
 }
608 608
 // unique ID
609
-if($C['unique_ids'] && isset($a['id'])){
610
- if(!preg_match('`^[A-Za-z][A-Za-z0-9_\-.:]*$`', ($id = $a['id'])) or (isset($GLOBALS['hl_Ids'][$id]) && $C['unique_ids'] == 1)){unset($a['id']);
611
- }else{
612
-  while(isset($GLOBALS['hl_Ids'][$id])){$id = $C['unique_ids']. $id;}
609
+if ($C['unique_ids'] && isset($a['id'])) {
610
+ if (!preg_match('`^[A-Za-z][A-Za-z0-9_\-.:]*$`', ($id = $a['id'])) or (isset($GLOBALS['hl_Ids'][$id]) && $C['unique_ids'] == 1)) {unset($a['id']);
611
+ } else {
612
+  while (isset($GLOBALS['hl_Ids'][$id])) {$id = $C['unique_ids'].$id; }
613 613
   $GLOBALS['hl_Ids'][($a['id'] = $id)] = 1;
614 614
  }
615 615
 }
616 616
 // xml:lang
617
-if($C['xml:lang'] && isset($a['lang'])){
617
+if ($C['xml:lang'] && isset($a['lang'])) {
618 618
  $a['xml:lang'] = isset($a['xml:lang']) ? $a['xml:lang'] : $a['lang'];
619
- if($C['xml:lang'] == 2){unset($a['lang']);}
619
+ if ($C['xml:lang'] == 2) {unset($a['lang']); }
620 620
 }
621 621
 // for transformed tag
622
-if(!empty($trt)){
623
- $a['style'] = isset($a['style']) ? rtrim($a['style'], ' ;'). '; '. $trt : $trt;
622
+if (!empty($trt)) {
623
+ $a['style'] = isset($a['style']) ? rtrim($a['style'], ' ;').'; '.$trt : $trt;
624 624
 }
625 625
 // return with empty ele /
626
-if(empty($C['hook_tag'])){
626
+if (empty($C['hook_tag'])) {
627 627
  $aA = '';
628
- foreach($a as $k=>$v){$aA .= " {$k}=\"{$v}\"";}
629
- return "<{$e}{$aA}". (isset($eE[$e]) ? ' /' : ''). '>';
628
+ foreach ($a as $k=>$v) {$aA .= " {$k}=\"{$v}\""; }
629
+ return "<{$e}{$aA}".(isset($eE[$e]) ? ' /' : '').'>';
630 630
 }
631
-else{return $C['hook_tag']($e, $a);}
631
+else {return $C['hook_tag']($e, $a); }
632 632
 // eof
633 633
 }
634 634
 
635
-function hl_tag2(&$e, &$a, $t=1){
635
+function hl_tag2(&$e, &$a, $t = 1) {
636 636
 // transform tag
637
-if($e == 'center'){$e = 'div'; return 'text-align: center;';}
638
-if($e == 'dir' or $e == 'menu'){$e = 'ul'; return '';}
639
-if($e == 's' or $e == 'strike'){$e = 'span'; return 'text-decoration: line-through;';}
640
-if($e == 'u'){$e = 'span'; return 'text-decoration: underline;';}
637
+if ($e == 'center') {$e = 'div'; return 'text-align: center;'; }
638
+if ($e == 'dir' or $e == 'menu') {$e = 'ul'; return ''; }
639
+if ($e == 's' or $e == 'strike') {$e = 'span'; return 'text-decoration: line-through;'; }
640
+if ($e == 'u') {$e = 'span'; return 'text-decoration: underline;'; }
641 641
 static $fs = array('0'=>'xx-small', '1'=>'xx-small', '2'=>'small', '3'=>'medium', '4'=>'large', '5'=>'x-large', '6'=>'xx-large', '7'=>'300%', '-1'=>'smaller', '-2'=>'60%', '+1'=>'larger', '+2'=>'150%', '+3'=>'200%', '+4'=>'300%');
642
-if($e == 'font' && $t !=3){//3 is a new make_tag_strict config value, to indicate that transformation is to be performed, but don't transform font, as size transformation of numeric sizes to keywords alters the intended result too much
642
+if ($e == 'font' && $t != 3) {//3 is a new make_tag_strict config value, to indicate that transformation is to be performed, but don't transform font, as size transformation of numeric sizes to keywords alters the intended result too much
643 643
  $a2 = '';
644
- while(preg_match('`(^|\s)(color|size)\s*=\s*(\'|")?(.+?)(\\3|\s|$)`i', $a, $m)){
644
+ while (preg_match('`(^|\s)(color|size)\s*=\s*(\'|")?(.+?)(\\3|\s|$)`i', $a, $m)) {
645 645
   $a = str_replace($m[0], ' ', $a);
646
-  $a2 .= strtolower($m[2]) == 'color' ? (' color: '. str_replace('"', '\'', trim($m[4])). ';') : (isset($fs[($m = trim($m[4]))]) ? ($a2 .= ' font-size: '. str_replace('"', '\'', $fs[$m]). ';') : '');
646
+  $a2 .= strtolower($m[2]) == 'color' ? (' color: '.str_replace('"', '\'', trim($m[4])).';') : (isset($fs[($m = trim($m[4]))]) ? ($a2 .= ' font-size: '.str_replace('"', '\'', $fs[$m]).';') : '');
647 647
  }
648
- while(preg_match('`(^|\s)face\s*=\s*(\'|")?([^=]+?)\\2`i', $a, $m) or preg_match('`(^|\s)face\s*=(\s*)(\S+)`i', $a, $m)){
648
+ while (preg_match('`(^|\s)face\s*=\s*(\'|")?([^=]+?)\\2`i', $a, $m) or preg_match('`(^|\s)face\s*=(\s*)(\S+)`i', $a, $m)) {
649 649
   $a = str_replace($m[0], ' ', $a);
650
-  $a2 .= ' font-family: '. str_replace('"', '\'', trim($m[3])). ';';
650
+  $a2 .= ' font-family: '.str_replace('"', '\'', trim($m[3])).';';
651 651
  }
652 652
  $e = 'span'; return ltrim(str_replace('<', '', $a2));
653 653
 }
654
-if($t == 2){$e = 0; return 0;}
654
+if ($t == 2) {$e = 0; return 0; }
655 655
 return '';
656 656
 // eof
657 657
 }
658 658
 
659
-function hl_tidy($t, $w, $p){
659
+function hl_tidy($t, $w, $p) {
660 660
 // Tidy/compact HTM
661
-if(strpos(' pre,script,textarea', "$p,")){return $t;}
661
+if (strpos(' pre,script,textarea', "$p,")) {return $t; }
662 662
 $t = preg_replace('`\s+`', ' ', preg_replace_callback(array('`(<(!\[CDATA\[))(.+?)(\]\]>)`sm', '`(<(!--))(.+?)(-->)`sm', '`(<(pre|script|textarea)[^>]*?>)(.+?)(</\2>)`sm'), create_function('$m', 'return $m[1]. str_replace(array("<", ">", "\n", "\r", "\t", " "), array("\x01", "\x02", "\x03", "\x04", "\x05", "\x07"), $m[3]). $m[4];'), $t));
663
-if(($w = strtolower($w)) == -1){
663
+if (($w = strtolower($w)) == -1) {
664 664
  return str_replace(array("\x01", "\x02", "\x03", "\x04", "\x05", "\x07"), array('<', '>', "\n", "\r", "\t", ' '), $t);
665 665
 }
666 666
 $s = strpos(" $w", 't') ? "\t" : ' ';
@@ -672,66 +672,66 @@  discard block
 block discarded – undo
672 672
 $d = array('address'=>1, 'blockquote'=>1, 'center'=>1, 'colgroup'=>1, 'dir'=>1, 'div'=>1, 'dl'=>1, 'fieldset'=>1, 'form'=>1, 'hr'=>1, 'iframe'=>1, 'map'=>1, 'menu'=>1, 'noscript'=>1, 'ol'=>1, 'optgroup'=>1, 'rbc'=>1, 'rtc'=>1, 'ruby'=>1, 'script'=>1, 'select'=>1, 'table'=>1, 'tbody'=>1, 'tfoot'=>1, 'thead'=>1, 'tr'=>1, 'ul'=>1);
673 673
 $T = explode('<', $t);
674 674
 $X = 1;
675
-while($X){
675
+while ($X) {
676 676
  $n = $N;
677 677
  $t = $T;
678 678
  ob_start();
679
- if(isset($d[$p])){echo str_repeat($s, ++$n);}
679
+ if (isset($d[$p])) {echo str_repeat($s, ++$n); }
680 680
  echo ltrim(array_shift($t));
681
- for($i=-1, $j=count($t); ++$i<$j;){
681
+ for ($i = -1, $j = count($t); ++$i < $j;) {
682 682
   $r = ''; list($e, $r) = explode('>', $t[$i]);
683 683
   $x = $e[0] == '/' ? 0 : (substr($e, -1) == '/' ? 1 : ($e[0] != '!' ? 2 : -1));
684 684
   $y = !$x ? ltrim($e, '/') : ($x > 0 ? substr($e, 0, strcspn($e, ' ')) : 0);
685 685
   $e = "<$e>";
686
-  if(isset($d[$y])){
687
-   if(!$x){
688
-    if($n){echo "\n", str_repeat($s, --$n), "$e\n", str_repeat($s, $n);}
689
-    else{++$N; ob_end_clean(); continue 2;}
686
+  if (isset($d[$y])) {
687
+   if (!$x) {
688
+    if ($n) {echo "\n", str_repeat($s, --$n), "$e\n", str_repeat($s, $n); }
689
+    else {++$N; ob_end_clean(); continue 2; }
690 690
    }
691
-   else{echo "\n", str_repeat($s, $n), "$e\n", str_repeat($s, ($x != 1 ? ++$n : $n));}
691
+   else {echo "\n", str_repeat($s, $n), "$e\n", str_repeat($s, ($x != 1 ? ++$n : $n)); }
692 692
    echo $r; continue;
693 693
   }
694
-  $f = "\n". str_repeat($s, $n);
695
-  if(isset($c[$y])){
696
-   if(!$x){echo $e, $f, $r;}
697
-   else{echo $f, $e, $r;}
698
-  }elseif(isset($b[$y])){echo $f, $e, $r;
699
-  }elseif(isset($a[$y])){echo $e, $f, $r;
700
-  }elseif(!$y){echo $f, $e, $f, $r;
701
-  }else{echo $e, $r;}
694
+  $f = "\n".str_repeat($s, $n);
695
+  if (isset($c[$y])) {
696
+   if (!$x) {echo $e, $f, $r; }
697
+   else {echo $f, $e, $r; }
698
+  }elseif (isset($b[$y])) {echo $f, $e, $r;
699
+  }elseif (isset($a[$y])) {echo $e, $f, $r;
700
+  }elseif (!$y) {echo $f, $e, $f, $r;
701
+  } else {echo $e, $r; }
702 702
  }
703 703
  $X = 0;
704 704
 }
705 705
 $t = str_replace(array("\n ", " \n"), "\n", preg_replace('`[\n]\s*?[\n]+`', "\n", ob_get_contents()));
706 706
 ob_end_clean();
707
-if(($l = strpos(" $w", 'r') ? (strpos(" $w", 'n') ? "\r\n" : "\r") : 0)){
707
+if (($l = strpos(" $w", 'r') ? (strpos(" $w", 'n') ? "\r\n" : "\r") : 0)) {
708 708
  $t = str_replace("\n", $l, $t);
709 709
 }
710 710
 return str_replace(array("\x01", "\x02", "\x03", "\x04", "\x05", "\x07"), array('<', '>', "\n", "\r", "\t", ' '), $t);
711 711
 // eof
712 712
 }
713 713
 
714
-function hl_version(){
714
+function hl_version() {
715 715
 // rel
716 716
 return '1.1.22';
717 717
 // eof
718 718
 }
719 719
 
720
-function kses($t, $h, $p=array('http', 'https', 'ftp', 'news', 'nntp', 'telnet', 'gopher', 'mailto')){
720
+function kses($t, $h, $p = array('http', 'https', 'ftp', 'news', 'nntp', 'telnet', 'gopher', 'mailto')) {
721 721
 // kses compat
722
-foreach($h as $k=>$v){
722
+foreach ($h as $k=>$v) {
723 723
  $h[$k]['n']['*'] = 1;
724 724
 }
725 725
 $C['cdata'] = $C['comment'] = $C['make_tag_strict'] = $C['no_deprecated_attr'] = $C['unique_ids'] = 0;
726 726
 $C['keep_bad'] = 1;
727 727
 $C['elements'] = count($h) ? strtolower(implode(',', array_keys($h))) : '-*';
728 728
 $C['hook'] = 'kses_hook';
729
-$C['schemes'] = '*:'. implode(',', $p);
729
+$C['schemes'] = '*:'.implode(',', $p);
730 730
 return htmLawed($t, $C, $h);
731 731
 // eof
732 732
 }
733 733
 
734
-function kses_hook($t, &$C, &$S){
734
+function kses_hook($t, &$C, &$S) {
735 735
 // kses compat
736 736
 return $t;
737 737
 // eof
Please login to merge, or discard this patch.
api/src/Json/Msg.php 2 patches
Doc Comments   +5 added lines, -3 removed lines patch added patch discarded remove patch
@@ -82,8 +82,7 @@  discard block
 block discarded – undo
82 82
 	/**
83 83
 	 * Allows to call a global javascript function with given parameters: window[$func].call(window[, $param1[, ...]])
84 84
 	 *
85
-	 * @param string $func name of the global (window) javascript function to call
86
-	 * @param mixed $parameters variable number of parameters
85
+	 * @param string $function
87 86
 	 */
88 87
 	public function call($function)
89 88
 	{
@@ -108,7 +107,7 @@  discard block
 block discarded – undo
108 107
 	 *
109 108
 	 * @param string $selector jquery selector
110 109
 	 * @param string $method name of the jquery to call
111
-	 * @param array $parameters =array()
110
+	 * @param string[] $parameters =array()
112 111
 	 */
113 112
 	public function jquery($selector,$method,array $parameters=array())
114 113
 	{
@@ -126,6 +125,9 @@  discard block
 block discarded – undo
126 125
 		}
127 126
 	}
128 127
 
128
+	/**
129
+	 * @param string $type
130
+	 */
129 131
 	public function generic($type, array $parameters = array())
130 132
 	{
131 133
 		if (is_string($type))
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 	 * @param string $function name of the global (window) javascript function to call
65 65
 	 * @param array $parameters =array()
66 66
 	 */
67
-	public function apply($function,array $parameters=array())
67
+	public function apply($function, array $parameters = array())
68 68
 	{
69 69
 		if (is_string($function))
70 70
 		{
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 	public function call($function)
89 89
 	{
90 90
 		$parameters = func_get_args();
91
-		array_shift($parameters);	// shift off $function
91
+		array_shift($parameters); // shift off $function
92 92
 
93 93
 		if (is_string($function))
94 94
 		{
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 	 * @param string $method name of the jquery to call
111 111
 	 * @param array $parameters =array()
112 112
 	 */
113
-	public function jquery($selector,$method,array $parameters=array())
113
+	public function jquery($selector, $method, array $parameters = array())
114 114
 	{
115 115
 		if (is_string($selector) && is_string($method))
116 116
 		{
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
 	 * @param string $app =null default current app from flags
170 170
 	 * or only the current application
171 171
 	 */
172
-	public function redirect($url, $global = false, $app=null)
172
+	public function redirect($url, $global = false, $app = null)
173 173
 	{
174 174
 		if (is_string($url) && is_bool($global))
175 175
 		{
Please login to merge, or discard this patch.
api/src/Json/Response.php 4 patches
Doc Comments   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -180,7 +180,6 @@  discard block
 block discarded – undo
180 180
 	/**
181 181
 	 * Init responseArray
182 182
 	 *
183
-	 * @param array $arr
184 183
 	 * @return array previous content
185 184
 	 */
186 185
 	public function initResponseArray()
@@ -264,7 +263,7 @@  discard block
 block discarded – undo
264 263
 	 *
265 264
 	 * @param midex $var
266 265
 	 * @param string $prefix =''
267
-	 * @return mixed
266
+	 * @return midex|null
268 267
 	 */
269 268
 	public static function fix_content($var, $prefix='')
270 269
 	{
Please login to merge, or discard this patch.
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -242,13 +242,13 @@
 block discarded – undo
242 242
 		if ($ret === false && ($err = json_last_error()))
243 243
 		{
244 244
 			static $json_err2str = array(
245
-	        	JSON_ERROR_NONE => 'No errors',
246
-	        	JSON_ERROR_DEPTH => 'Maximum stack depth exceeded',
247
-	        	JSON_ERROR_STATE_MISMATCH => 'Underflow or the modes mismatch',
248
-	        	JSON_ERROR_CTRL_CHAR => 'Unexpected control character found',
249
-	        	JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON',
250
-	        	JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded',
251
-	        );
245
+				JSON_ERROR_NONE => 'No errors',
246
+				JSON_ERROR_DEPTH => 'Maximum stack depth exceeded',
247
+				JSON_ERROR_STATE_MISMATCH => 'Underflow or the modes mismatch',
248
+				JSON_ERROR_CTRL_CHAR => 'Unexpected control character found',
249
+				JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON',
250
+				JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded',
251
+			);
252 252
 			error_log(__METHOD__.'('.array2string($var).') json_last_error()='.$err.'='.$json_err2str[$err]);
253 253
 
254 254
 			if (($var = self::fix_content($var)))
Please login to merge, or discard this patch.
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -268,7 +268,10 @@
 block discarded – undo
268 268
 	 */
269 269
 	public static function fix_content($var, $prefix='')
270 270
 	{
271
-		if (json_encode($var) !== false) return $var;
271
+		if (json_encode($var) !== false)
272
+		{
273
+			return $var;
274
+		}
272 275
 
273 276
 		if (is_scalar($var))
274 277
 		{
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -226,9 +226,9 @@  discard block
 block discarded – undo
226 226
 		// Wrap the result array into a parent "response" Object
227 227
 		$res = array(
228 228
 			'response' => $inst->responseArray,
229
-		)+Api\Framework::get_page_generation_time();
229
+		) + Api\Framework::get_page_generation_time();
230 230
 
231
-		return self::json_encode($res);	//PHP5.3+, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP);
231
+		return self::json_encode($res); //PHP5.3+, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP);
232 232
 	}
233 233
 
234 234
 	/**
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
 	 * @param string $prefix =''
269 269
 	 * @return mixed
270 270
 	 */
271
-	public static function fix_content($var, $prefix='')
271
+	public static function fix_content($var, $prefix = '')
272 272
 	{
273 273
 		if (json_encode($var) !== false) return $var;
274 274
 
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
 		}
280 280
 		else
281 281
 		{
282
-			foreach($var as $name => &$value)
282
+			foreach ($var as $name => &$value)
283 283
 			{
284 284
 				$value = self::fix_content($value, $prefix ? $prefix.'['.$name.']' : $name);
285 285
 			}
Please login to merge, or discard this patch.
api/src/Ldap/ServerInfo.php 4 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 	/**
82 82
 	* gets the version
83 83
 	*
84
-	* @return integer the supported ldap version
84
+	* @return string the supported ldap version
85 85
 	*/
86 86
 	function getVersion()
87 87
 	{
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 	 * @param resource $ds
160 160
 	 * @param string $host
161 161
 	 * @param int $version 2 or 3
162
-	 * @return ldapserverinfo
162
+	 * @return ServerInfo
163 163
 	 */
164 164
 	public static function get($ds, $host, $version=3)
165 165
 	{
Please login to merge, or discard this patch.
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -32,33 +32,33 @@  discard block
 block discarded – undo
32 32
 	const SAMBA4 = 2;
33 33
 
34 34
 	/**
35
-	* @var array $namingContext holds the supported namingcontexts
36
-	*/
35
+	 * @var array $namingContext holds the supported namingcontexts
36
+	 */
37 37
 	var $namingContext = array();
38 38
 
39 39
 	/**
40
-	* @var string $version holds the LDAP server version
41
-	*/
40
+	 * @var string $version holds the LDAP server version
41
+	 */
42 42
 	var $version = 2;
43 43
 
44 44
 	/**
45
-	* @var integer $serverType holds the type of LDAP server(OpenLDAP, ADS, NDS, ...)
46
-	*/
45
+	 * @var integer $serverType holds the type of LDAP server(OpenLDAP, ADS, NDS, ...)
46
+	 */
47 47
 	var $serverType = 0;
48 48
 
49 49
 	/**
50
-	* @var string $_subSchemaEntry the subschema entry DN
51
-	*/
50
+	 * @var string $_subSchemaEntry the subschema entry DN
51
+	 */
52 52
 	var $subSchemaEntry = '';
53 53
 
54 54
 	/**
55
-	* @var array $supportedObjectClasses the supported objectclasses
56
-	*/
55
+	 * @var array $supportedObjectClasses the supported objectclasses
56
+	 */
57 57
 	var $supportedObjectClasses = array();
58 58
 
59 59
 	/**
60
-	* @var array $supportedOIDs the supported OIDs
61
-	*/
60
+	 * @var array $supportedOIDs the supported OIDs
61
+	 */
62 62
 	var $supportedOIDs = array();
63 63
 
64 64
 	/**
@@ -79,50 +79,50 @@  discard block
 block discarded – undo
79 79
 	}
80 80
 
81 81
 	/**
82
-	* gets the version
83
-	*
84
-	* @return integer the supported ldap version
85
-	*/
82
+	 * gets the version
83
+	 *
84
+	 * @return integer the supported ldap version
85
+	 */
86 86
 	function getVersion()
87 87
 	{
88 88
 		return $this->version;
89 89
 	}
90 90
 
91 91
 	/**
92
-	* sets the namingcontexts
93
-	*
94
-	* @param array $_namingContext the supported namingcontexts
95
-	*/
92
+	 * sets the namingcontexts
93
+	 *
94
+	 * @param array $_namingContext the supported namingcontexts
95
+	 */
96 96
 	function setNamingContexts($_namingContext)
97 97
 	{
98 98
 		$this->namingContext = $_namingContext;
99 99
 	}
100 100
 
101 101
 	/**
102
-	* sets the type of the ldap server(OpenLDAP, ADS, NDS, ...)
103
-	*
104
-	* @param integer $_serverType the type of ldap server
105
-	*/
102
+	 * sets the type of the ldap server(OpenLDAP, ADS, NDS, ...)
103
+	 *
104
+	 * @param integer $_serverType the type of ldap server
105
+	 */
106 106
 	function setServerType($_serverType)
107 107
 	{
108 108
 		$this->serverType = $_serverType;
109 109
 	}
110 110
 
111 111
 	/**
112
-	* sets the DN for the subschema entry
113
-	*
114
-	* @param string $_subSchemaEntry the subschema entry DN
115
-	*/
112
+	 * sets the DN for the subschema entry
113
+	 *
114
+	 * @param string $_subSchemaEntry the subschema entry DN
115
+	 */
116 116
 	function setSubSchemaEntry($_subSchemaEntry)
117 117
 	{
118 118
 		$this->subSchemaEntry = $_subSchemaEntry;
119 119
 	}
120 120
 
121 121
 	/**
122
-	* sets the supported objectclasses
123
-	*
124
-	* @param array $_supportedObjectClasses the supported objectclasses
125
-	*/
122
+	 * sets the supported objectclasses
123
+	 *
124
+	 * @param array $_supportedObjectClasses the supported objectclasses
125
+	 */
126 126
 	function setSupportedObjectClasses($_supportedObjectClasses)
127 127
 	{
128 128
 		$this->supportedOIDs = $_supportedObjectClasses;
@@ -130,20 +130,20 @@  discard block
 block discarded – undo
130 130
 	}
131 131
 
132 132
 	/**
133
-	* sets the version
134
-	*
135
-	* @param integer $_version the supported ldap version
136
-	*/
133
+	 * sets the version
134
+	 *
135
+	 * @param integer $_version the supported ldap version
136
+	 */
137 137
 	function setVersion($_version)
138 138
 	{
139 139
 		$this->version = $_version;
140 140
 	}
141 141
 
142 142
 	/**
143
-	* checks for supported objectclasses
144
-	*
145
-	* @return bool returns true if the ldap server supports this objectclass
146
-	*/
143
+	 * checks for supported objectclasses
144
+	 *
145
+	 * @return bool returns true if the ldap server supports this objectclass
146
+	 */
147 147
 	function supportsObjectClass($_objectClass)
148 148
 	{
149 149
 		if($this->supportedObjectClasses[strtolower($_objectClass)])
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -218,7 +218,8 @@
 block discarded – undo
218 218
 					{
219 219
 						if(($info = ldap_get_entries($ds, $sr)))
220 220
 						{
221
-							if($info[0]['objectclasses']) {
221
+							if($info[0]['objectclasses'])
222
+							{
222 223
 								for($i=0; $i<$info[0]['objectclasses']['count']; $i++)
223 224
 								{
224 225
 									$matches = null;
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 	*/
146 146
 	function supportsObjectClass($_objectClass)
147 147
 	{
148
-		if($this->supportedObjectClasses[strtolower($_objectClass)])
148
+		if ($this->supportedObjectClasses[strtolower($_objectClass)])
149 149
 		{
150 150
 			return true;
151 151
 		}
@@ -160,21 +160,21 @@  discard block
 block discarded – undo
160 160
 	 * @param int $version 2 or 3
161 161
 	 * @return ldapserverinfo
162 162
 	 */
163
-	public static function get($ds, $host, $version=3)
163
+	public static function get($ds, $host, $version = 3)
164 164
 	{
165
-		$filter='(objectclass=*)';
166
-		$justthese = array('structuralObjectClass','namingContexts','supportedLDAPVersion','subschemaSubentry','vendorname');
167
-		if(($sr = @ldap_read($ds, '', $filter, $justthese)))
165
+		$filter = '(objectclass=*)';
166
+		$justthese = array('structuralObjectClass', 'namingContexts', 'supportedLDAPVersion', 'subschemaSubentry', 'vendorname');
167
+		if (($sr = @ldap_read($ds, '', $filter, $justthese)))
168 168
 		{
169
-			if(($info = ldap_get_entries($ds, $sr)))
169
+			if (($info = ldap_get_entries($ds, $sr)))
170 170
 			{
171 171
 				$ldapServerInfo = new ServerInfo($host);
172 172
 				$ldapServerInfo->setVersion($version);
173 173
 
174 174
 				// check for naming contexts
175
-				if($info[0]['namingcontexts'])
175
+				if ($info[0]['namingcontexts'])
176 176
 				{
177
-					for($i=0; $i<$info[0]['namingcontexts']['count']; $i++)
177
+					for ($i = 0; $i < $info[0]['namingcontexts']['count']; $i++)
178 178
 					{
179 179
 						$namingcontexts[] = $info[0]['namingcontexts'][$i];
180 180
 					}
@@ -182,9 +182,9 @@  discard block
 block discarded – undo
182 182
 				}
183 183
 
184 184
 				// check for ldap server type
185
-				if($info[0]['structuralobjectclass'])
185
+				if ($info[0]['structuralobjectclass'])
186 186
 				{
187
-					switch($info[0]['structuralobjectclass'][0])
187
+					switch ($info[0]['structuralobjectclass'][0])
188 188
 					{
189 189
 						case 'OpenLDAProotDSE':
190 190
 							$ldapServerType = self::OPENLDAP;
@@ -201,30 +201,30 @@  discard block
 block discarded – undo
201 201
 				}
202 202
 
203 203
 				// check for subschema entry dn
204
-				if($info[0]['subschemasubentry'])
204
+				if ($info[0]['subschemasubentry'])
205 205
 				{
206 206
 					$subschemasubentry = $info[0]['subschemasubentry'][0];
207 207
 					$ldapServerInfo->setSubSchemaEntry($subschemasubentry);
208 208
 				}
209 209
 
210 210
 				// create list of supported objetclasses
211
-				if(!empty($subschemasubentry))
211
+				if (!empty($subschemasubentry))
212 212
 				{
213
-					$filter='(objectclass=*)';
213
+					$filter = '(objectclass=*)';
214 214
 					$justthese = array('objectClasses');
215 215
 
216
-					if(($sr = ldap_read($ds, $subschemasubentry, $filter, $justthese)))
216
+					if (($sr = ldap_read($ds, $subschemasubentry, $filter, $justthese)))
217 217
 					{
218
-						if(($info = ldap_get_entries($ds, $sr)))
218
+						if (($info = ldap_get_entries($ds, $sr)))
219 219
 						{
220
-							if($info[0]['objectclasses']) {
221
-								for($i=0; $i<$info[0]['objectclasses']['count']; $i++)
220
+							if ($info[0]['objectclasses']) {
221
+								for ($i = 0; $i < $info[0]['objectclasses']['count']; $i++)
222 222
 								{
223 223
 									$matches = null;
224
-									if(preg_match('/^\( (.*) NAME \'(\w*)\' /', $info[0]['objectclasses'][$i], $matches))
224
+									if (preg_match('/^\( (.*) NAME \'(\w*)\' /', $info[0]['objectclasses'][$i], $matches))
225 225
 									{
226 226
 										#_debug_array($matches);
227
-										if(count($matches) == 3)
227
+										if (count($matches) == 3)
228 228
 										{
229 229
 											$supportedObjectClasses[$matches[1]] = strtolower($matches[2]);
230 230
 										}
Please login to merge, or discard this patch.
api/src/Link/Storage.php 5 patches
Doc Comments   +6 added lines, -1 removed lines patch added patch discarded remove patch
@@ -176,6 +176,11 @@  discard block
 block discarded – undo
176 176
 		return is_array($id) ? $links : ($links[$id] ? $links[$id] : array());
177 177
 	}
178 178
 
179
+	/**
180
+	 * @param boolean $left
181
+	 * @param string $only_app
182
+	 * @param boolean $not_only
183
+	 */
179 184
 	private static function _add2links($row,$left,$only_app,$not_only,array &$links)
180 185
 	{
181 186
 		$linked_app = $left ? $row['link_app2'] : $row['link_app1'];
@@ -206,7 +211,7 @@  discard block
 block discarded – undo
206 211
 	 * @param string $id ='' id in $app, if no integer link_id given in $app_link_id
207 212
 	 * @param string $app2 ='' appname of 2. endpoint of the link, if no integer link_id given in $app_link_id
208 213
 	 * @param string $id2 ='' id in $app2, if no integer link_id given in $app_link_id
209
-	 * @return array with link-data or False
214
+	 * @return string with link-data or False
210 215
 	 */
211 216
 	static function get_link($app_link_id,$id='',$app2='',$id2='')
212 217
 	{
Please login to merge, or discard this patch.
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 			echo "<p>solink.link('$app1',$id1,'$app2',$id2,'$remark',$owner)</p>\n";
67 67
 		}
68 68
 		if ($app1 == $app2 && $id1 == $id2 ||
69
-		    $id1 == '' || $id2 == '' || $app1 == '' || $app2 == '')
69
+			$id1 == '' || $id2 == '' || $app1 == '' || $app2 == '')
70 70
 		{
71 71
 			return False;	// dont link to self or other nosense
72 72
 		}
@@ -412,26 +412,26 @@  discard block
 block discarded – undo
412 412
 			array('table'=>self::TABLE,
413 413
 				'cols'=>'c.*,b.link_app1 AS app3,b.link_id1 AS id3,b.link_id AS link3',
414 414
 				'where'=>'a.link_app1='.self::$db->quote($app).' AND c.link_app2='.self::$db->quote($target_app).
415
-                        		(!$target_id ? '' : self::$db->expression(self::TABLE,' AND c.',array('link_id2' => $target_id))),
416
-                        	'join'=>" a
415
+								(!$target_id ? '' : self::$db->expression(self::TABLE,' AND c.',array('link_id2' => $target_id))),
416
+							'join'=>" a
417 417
                         		JOIN $table b ON a.link_id2=b.link_id1 AND a.link_app2=b.link_app1
418 418
                        			JOIN $table c ON a.link_id1=c.link_id1 AND a.link_app1=c.link_app1 AND a.link_id!=c.link_id AND c.link_app2=b.link_app2 AND c.link_id2=b.link_id2",
419 419
 			),
420 420
 			// retrieve the type of links, where the relation is realized as timesheet->infolog/tracker and projectmanager->timesheet
421 421
 			array('table'=>self::TABLE,
422 422
 				'cols'=>'b.link_id, b.link_app2 as app1, b.link_id2 as id1, b.link_app1 as app2, b.link_id1 as id2, b.link_remark,b.link_lastmod,b.link_owner,b.deleted,c.link_app1 AS app3,c.link_id1 AS id3,c.link_id AS link3',
423
-                       		'where'=>'a.link_app1='.self::$db->quote($app).' AND b.link_app1='.self::$db->quote($target_app).
424
-                        		(!$target_id ? '' : self::$db->expression(self::TABLE,' AND b.',array('link_id1' => $target_id))),
425
-                        	'join'=>" a
423
+					   		'where'=>'a.link_app1='.self::$db->quote($app).' AND b.link_app1='.self::$db->quote($target_app).
424
+								(!$target_id ? '' : self::$db->expression(self::TABLE,' AND b.',array('link_id1' => $target_id))),
425
+							'join'=>" a
426 426
                         		JOIN $table b ON a.link_id1=b.link_id2 AND a.link_app1=b.link_app2
427 427
                         		JOIN $table c ON a.link_id2=c.link_id1 AND a.link_app2=c.link_app1 AND a.link_id!=c.link_id AND c.link_app2=b.link_app1 AND c.link_id2=b.link_id1",
428 428
 			),
429 429
 			// retrieve the type of links, where the relation is realized as timesheet->projectmanager and infolog->timesheet
430 430
 			array('table'=>self::TABLE,
431 431
 				'cols'=>'a.*,c.link_app1 AS app3,c.link_id1 AS id3,c.link_id AS link3',
432
-                     		'where'=>'a.link_app1='.self::$db->quote($app).' AND a.link_app2='.self::$db->quote($target_app).
433
-                        		(!$target_id ? '' : self::$db->expression(self::TABLE,' AND a.',array('link_id2' => $target_id))),
434
-                       		'join'=>" a
432
+					 		'where'=>'a.link_app1='.self::$db->quote($app).' AND a.link_app2='.self::$db->quote($target_app).
433
+								(!$target_id ? '' : self::$db->expression(self::TABLE,' AND a.',array('link_id2' => $target_id))),
434
+					   		'join'=>" a
435 435
                        			JOIN $table b ON a.link_id1=b.link_id2 AND a.link_app1=b.link_app2
436 436
                         		JOIN $table c ON a.link_id2=c.link_id2 AND a.link_app2=c.link_app2 AND a.link_id!=c.link_id AND c.link_app1=b.link_app1 AND c.link_id1=b.link_id1",
437 437
 			),
Please login to merge, or discard this patch.
Spacing   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 	 * @param int $lastmod =0 timestamp of last modification (defaults to now=time())
60 60
 	 * @return int/boolean False (for db or param-error) or on success link_id (Please not the return-value of $id1)
61 61
 	 */
62
-	static function link( $app1,&$id1,$app2,$id2='',$remark='',$owner=0,$lastmod=0 )
62
+	static function link($app1, &$id1, $app2, $id2 = '', $remark = '', $owner = 0, $lastmod = 0)
63 63
 	{
64 64
 		if (self::DEBUG)
65 65
 		{
@@ -68,21 +68,21 @@  discard block
 block discarded – undo
68 68
 		if ($app1 == $app2 && $id1 == $id2 ||
69 69
 		    $id1 == '' || $id2 == '' || $app1 == '' || $app2 == '')
70 70
 		{
71
-			return False;	// dont link to self or other nosense
71
+			return False; // dont link to self or other nosense
72 72
 		}
73
-		if (($link = self::get_link($app1,$id1,$app2,$id2)))
73
+		if (($link = self::get_link($app1, $id1, $app2, $id2)))
74 74
 		{
75 75
 			if ($link['link_remark'] != $remark)
76 76
 			{
77
-				self::update_remark($link['link_id'],$remark);
77
+				self::update_remark($link['link_id'], $remark);
78 78
 			}
79
-			return $link['link_id'];	// link alread exist
79
+			return $link['link_id']; // link alread exist
80 80
 		}
81 81
 		if (!$owner)
82 82
 		{
83 83
 			$owner = $GLOBALS['egw_info']['user']['account_id'];
84 84
 		}
85
-		return self::$db->insert(self::TABLE,array(
85
+		return self::$db->insert(self::TABLE, array(
86 86
 				'link_app1'		=> $app1,
87 87
 				'link_id1'		=> $id1,
88 88
 				'link_app2'		=> $app2,
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 				'link_remark'	=> $remark,
91 91
 				'link_lastmod'	=> $lastmod ? $lastmod : time(),
92 92
 				'link_owner'	=> $owner,
93
-			),False,__LINE__,__FILE__) ? self::$db->get_last_insert_id(self::TABLE,'link_id') : false;
93
+			), False, __LINE__, __FILE__) ? self::$db->get_last_insert_id(self::TABLE, 'link_id') : false;
94 94
 	}
95 95
 
96 96
 	/**
@@ -100,14 +100,14 @@  discard block
 block discarded – undo
100 100
 	 * @param string $remark new text for the remark
101 101
 	 * @return boolean true on success, else false
102 102
 	 */
103
-	static function update_remark($link_id,$remark)
103
+	static function update_remark($link_id, $remark)
104 104
 	{
105
-		return self::$db->update(self::TABLE,array(
105
+		return self::$db->update(self::TABLE, array(
106 106
 				'link_remark'	=> $remark,
107 107
 				'link_lastmod'	=> time(),
108
-			),array(
108
+			), array(
109 109
 				'link_id'	=> $link_id,
110
-			),__LINE__,__FILE__);
110
+			), __LINE__, __FILE__);
111 111
 	}
112 112
 
113 113
 	/**
@@ -121,15 +121,15 @@  discard block
 block discarded – undo
121 121
 	 * @param int|array $limit =null number of entries to return, default null = all or array(offset, num_rows) to return num_rows starting from offset
122 122
 	 * @return array id => links pairs if $id is an array or just the links (only_app: ids) or empty array if no matching links found
123 123
 	 */
124
-	static function get_links($app, $id, $only_app='', $order='link_lastmod DESC', $deleted=false, $limit=null)
124
+	static function get_links($app, $id, $only_app = '', $order = 'link_lastmod DESC', $deleted = false, $limit = null)
125 125
 	{
126 126
 		if (self::DEBUG)
127 127
 		{
128
-			echo "<p>solink.get_links($app,".print_r($id,true).",$only_app,$order,$deleted)</p>\n";
128
+			echo "<p>solink.get_links($app,".print_r($id, true).",$only_app,$order,$deleted)</p>\n";
129 129
 		}
130 130
 		if (($not_only = $only_app[0] == '!'))
131 131
 		{
132
-			$only_app = substr($only_app,1);
132
+			$only_app = substr($only_app, 1);
133 133
 		}
134 134
 
135 135
 		$offset = false;
@@ -137,32 +137,32 @@  discard block
 block discarded – undo
137 137
 		{
138 138
 			list($offset, $limit) = $limit;
139 139
 		}
140
-		elseif($limit)
140
+		elseif ($limit)
141 141
 		{
142 142
 			$offset = 0;
143 143
 		}
144 144
 
145 145
 		$links = array();
146 146
 		try {
147
-			foreach(self::$db->select(self::TABLE, '*', self::$db->expression(self::TABLE, '((', array(
147
+			foreach (self::$db->select(self::TABLE, '*', self::$db->expression(self::TABLE, '((', array(
148 148
 						'link_app1'	=> $app,
149 149
 						'link_id1'	=> $id,
150
-					),') OR (',array(
150
+					), ') OR (', array(
151 151
 						'link_app2'	=> $app,
152 152
 						'link_id2'	=> $id,
153
-					),'))',
153
+					), '))',
154 154
 					$deleted ? '' : ' AND deleted IS NULL'
155 155
 				), __LINE__, __FILE__, $offset, $order ? " ORDER BY $order" : '', 'phpgwapi', $limit) as $row)
156 156
 			{
157 157
 				// check if left side (1) is one of our targets --> add it
158
-				if ($row['link_app1'] == $app && in_array($row['link_id1'],(array)$id))
158
+				if ($row['link_app1'] == $app && in_array($row['link_id1'], (array)$id))
159 159
 				{
160
-					self::_add2links($row,true,$only_app,$not_only,$links);
160
+					self::_add2links($row, true, $only_app, $not_only, $links);
161 161
 				}
162 162
 				// check if right side (2) is one of our targets --> add it (both can be true for multiple targets!)
163
-				if ($row['link_app2'] == $app && in_array($row['link_id2'],(array)$id))
163
+				if ($row['link_app2'] == $app && in_array($row['link_id2'], (array)$id))
164 164
 				{
165
-					self::_add2links($row,false,$only_app,$not_only,$links);
165
+					self::_add2links($row, false, $only_app, $not_only, $links);
166 166
 				}
167 167
 			}
168 168
 			// if query returns exactly limit rows, we assume there are more and therefore set self::$limit_exceeded
@@ -170,18 +170,18 @@  discard block
 block discarded – undo
170 170
 		}
171 171
 		// catch Illegal mix of collations (ascii_general_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '=' (1267)
172 172
 		// caused by non-ascii chars compared with ascii field uid
173
-		catch(Api\Db\Exception $e) {
173
+		catch (Api\Db\Exception $e) {
174 174
 			_egw_log_exception($e);
175 175
 		}
176 176
 		return is_array($id) ? $links : ($links[$id] ? $links[$id] : array());
177 177
 	}
178 178
 
179
-	private static function _add2links($row,$left,$only_app,$not_only,array &$links)
179
+	private static function _add2links($row, $left, $only_app, $not_only, array &$links)
180 180
 	{
181 181
 		$linked_app = $left ? $row['link_app2'] : $row['link_app1'];
182 182
 		$linked_id  = $left ? $row['link_id2'] : $row['link_id1'];
183 183
 		$app_id = $left ? $row['link_id1'] : $row['link_id2'];
184
-		list($app) = explode('-',$linked_app);
184
+		list($app) = explode('-', $linked_app);
185 185
 		if ($only_app && $not_only == ($linked_app == $only_app) || !$GLOBALS['egw_info']['user']['apps'][$app])
186 186
 		{
187 187
 			#echo "$linked_app == $only_app, ";var_dump($linked_app == $only_app);echo "	->dont return a link<br>";
@@ -208,13 +208,13 @@  discard block
 block discarded – undo
208 208
 	 * @param string $id2 ='' id in $app2, if no integer link_id given in $app_link_id
209 209
 	 * @return array with link-data or False
210 210
 	 */
211
-	static function get_link($app_link_id,$id='',$app2='',$id2='')
211
+	static function get_link($app_link_id, $id = '', $app2 = '', $id2 = '')
212 212
 	{
213 213
 		if (self::DEBUG)
214 214
 		{
215 215
 			echo "<p>solink.get_link('$app_link_id',$id,'$app2','$id2')</p>\n";
216 216
 		}
217
-		if ((int) $app_link_id > 0)
217
+		if ((int)$app_link_id > 0)
218 218
 		{
219 219
 			$where = array('link_id' => $app_link_id);
220 220
 		}
@@ -224,24 +224,24 @@  discard block
 block discarded – undo
224 224
 			{
225 225
 				return False;
226 226
 			}
227
-			$where = self::$db->expression(self::TABLE,'(',array(
227
+			$where = self::$db->expression(self::TABLE, '(', array(
228 228
 					'link_app1'	=> $app_link_id,
229 229
 					'link_id1'	=> $id,
230 230
 					'link_app2'	=> $app2,
231 231
 					'link_id2'	=> $id2,
232
-				),') OR (',array(
232
+				), ') OR (', array(
233 233
 					'link_app2'	=> $app_link_id,
234 234
 					'link_id2'	=> $id,
235 235
 					'link_app1'	=> $app2,
236 236
 					'link_id1'	=> $id2,
237
-				),')');
237
+				), ')');
238 238
 		}
239 239
 		try {
240
-			return self::$db->select(self::TABLE,'*',$where,__LINE__,__FILE__)->fetch(ADODB_FETCH_ASSOC);
240
+			return self::$db->select(self::TABLE, '*', $where, __LINE__, __FILE__)->fetch(ADODB_FETCH_ASSOC);
241 241
 		}
242 242
 		// catch Illegal mix of collations (ascii_general_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '=' (1267)
243 243
 		// caused by non-ascii chars compared with ascii field uid
244
-		catch(Api\Db\Exception $e) {
244
+		catch (Api\Db\Exception $e) {
245 245
 			_egw_log_exception($e);
246 246
 		}
247 247
 		return false;
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
 	 * @param boolean $hold_for_purge Don't really delete the link, just mark it as deleted and wait for final delete of linked entry
260 260
 	 * @return array with deleted links
261 261
 	 */
262
-	static function unlink($link_id,$app='',$id='',$owner=0,$app2='',$id2='',$hold_for_purge=false)
262
+	static function unlink($link_id, $app = '', $id = '', $owner = 0, $app2 = '', $id2 = '', $hold_for_purge = false)
263 263
 	{
264 264
 		if (self::DEBUG)
265 265
 		{
@@ -284,21 +284,21 @@  discard block
 block discarded – undo
284 284
 					$check1['link_id1'] = $id;
285 285
 					$check2['link_id2'] = $id;
286 286
 				}
287
-				$where = self::$db->expression(self::TABLE,'((',$check1,') OR (',$check2,'))');
287
+				$where = self::$db->expression(self::TABLE, '((', $check1, ') OR (', $check2, '))');
288 288
 			}
289 289
 			elseif ($app != '' && $app2 != '')
290 290
 			{
291
-				$where = self::$db->expression(self::TABLE,'(',array(
291
+				$where = self::$db->expression(self::TABLE, '(', array(
292 292
 						'link_app1'	=> $app,
293 293
 						'link_id1'	=> $id,
294 294
 						'link_app2'	=> $app2,
295 295
 						'link_id2'	=> $id2,
296
-					),') OR (',array(
296
+					), ') OR (', array(
297 297
 						'link_app1'	=> $app2,
298 298
 						'link_id1'	=> $id2,
299 299
 						'link_app2'	=> $app,
300 300
 						'link_id2'	=> $id,
301
-					),')');
301
+					), ')');
302 302
 			}
303 303
 			if ($owner)
304 304
 			{
@@ -308,25 +308,25 @@  discard block
 block discarded – undo
308 308
 		}
309 309
 		$deleted = array();
310 310
 		try {
311
-			foreach(self::$db->select(self::TABLE,'*',$where,__LINE__,__FILE__) as $row)
311
+			foreach (self::$db->select(self::TABLE, '*', $where, __LINE__, __FILE__) as $row)
312 312
 			{
313 313
 				$deleted[] = $row;
314 314
 			}
315
-			if($hold_for_purge)
315
+			if ($hold_for_purge)
316 316
 			{
317
-				self::$db->update(self::TABLE,array(
317
+				self::$db->update(self::TABLE, array(
318 318
 					'deleted' => time(),
319 319
 					'link_lastmod' => time(),
320
-				), $where, __LINE__,__FILE__);
320
+				), $where, __LINE__, __FILE__);
321 321
 			}
322 322
 			else
323 323
 			{
324
-				self::$db->delete(self::TABLE,$where,__LINE__,__FILE__);
324
+				self::$db->delete(self::TABLE, $where, __LINE__, __FILE__);
325 325
 			}
326 326
 		}
327 327
 		// catch Illegal mix of collations (ascii_general_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '=' (1267)
328 328
 		// caused by non-ascii chars compared with ascii field uid
329
-		catch(Api\Db\Exception $e) {
329
+		catch (Api\Db\Exception $e) {
330 330
 			_egw_log_exception($e);
331 331
 		}
332 332
 
@@ -357,8 +357,8 @@  discard block
 block discarded – undo
357 357
 			$check1['link_id1'] = $id;
358 358
 			$check2['link_id2'] = $id;
359 359
 		}
360
-		$where = self::$db->expression(self::TABLE,'((',$check1,') OR (',$check2,'))');
361
-		self::$db->update(self::TABLE,array('deleted'=> null), $where, __LINE__,__FILE__);
360
+		$where = self::$db->expression(self::TABLE, '((', $check1, ') OR (', $check2, '))');
361
+		self::$db->update(self::TABLE, array('deleted'=> null), $where, __LINE__, __FILE__);
362 362
 	}
363 363
 
364 364
 	/**
@@ -371,13 +371,13 @@  discard block
 block discarded – undo
371 371
 	 * @param int $new_owner account_id of new owner
372 372
 	 * @return int number of links changed
373 373
 	 */
374
-	static function chown($owner,$new_owner)
374
+	static function chown($owner, $new_owner)
375 375
 	{
376
-		if ((int)$owner <= 0 || (int) $new_owner <= 0)
376
+		if ((int)$owner <= 0 || (int)$new_owner <= 0)
377 377
 		{
378 378
 			return 0;
379 379
 		}
380
-		self::$db->update(self::TABLE,array('owner'=>$new_owner),array('owner'=>$owner),__LINE__,__FILE__);
380
+		self::$db->update(self::TABLE, array('owner'=>$new_owner), array('owner'=>$owner), __LINE__, __FILE__);
381 381
 
382 382
 		return self::$db->affected_rows();
383 383
 	}
@@ -404,15 +404,15 @@  discard block
 block discarded – undo
404 404
 	 * @param int|array $limit =null number of entries to return, default null = all or array(offset, num_rows) to return num_rows starting from offset
405 405
 	 * @return array with links from entries from $app to $target_app/$target_id plus the other (b) link_id/app/id in the keys 'link3'/'app3'/'id3'
406 406
 	 */
407
-	static function get_3links($app, $target_app, $target_id=null, $just_app_ids=false, $order='link_lastmod DESC', $limit=null)
407
+	static function get_3links($app, $target_app, $target_id = null, $just_app_ids = false, $order = 'link_lastmod DESC', $limit = null)
408 408
 	{
409 409
 		$table = self::TABLE;
410
-		$arrayofselects=array(
410
+		$arrayofselects = array(
411 411
 			// retrieve the type of links, where the relation is realized as timesheet->infolog/tracker via infolog->projectmanager to timesheet->projectmanager
412 412
 			array('table'=>self::TABLE,
413 413
 				'cols'=>'c.*,b.link_app1 AS app3,b.link_id1 AS id3,b.link_id AS link3',
414 414
 				'where'=>'a.link_app1='.self::$db->quote($app).' AND c.link_app2='.self::$db->quote($target_app).
415
-                        		(!$target_id ? '' : self::$db->expression(self::TABLE,' AND c.',array('link_id2' => $target_id))),
415
+                        		(!$target_id ? '' : self::$db->expression(self::TABLE, ' AND c.', array('link_id2' => $target_id))),
416 416
                         	'join'=>" a
417 417
                         		JOIN $table b ON a.link_id2=b.link_id1 AND a.link_app2=b.link_app1
418 418
                        			JOIN $table c ON a.link_id1=c.link_id1 AND a.link_app1=c.link_app1 AND a.link_id!=c.link_id AND c.link_app2=b.link_app2 AND c.link_id2=b.link_id2",
@@ -421,7 +421,7 @@  discard block
 block discarded – undo
421 421
 			array('table'=>self::TABLE,
422 422
 				'cols'=>'b.link_id, b.link_app2 as app1, b.link_id2 as id1, b.link_app1 as app2, b.link_id1 as id2, b.link_remark,b.link_lastmod,b.link_owner,b.deleted,c.link_app1 AS app3,c.link_id1 AS id3,c.link_id AS link3',
423 423
                        		'where'=>'a.link_app1='.self::$db->quote($app).' AND b.link_app1='.self::$db->quote($target_app).
424
-                        		(!$target_id ? '' : self::$db->expression(self::TABLE,' AND b.',array('link_id1' => $target_id))),
424
+                        		(!$target_id ? '' : self::$db->expression(self::TABLE, ' AND b.', array('link_id1' => $target_id))),
425 425
                         	'join'=>" a
426 426
                         		JOIN $table b ON a.link_id1=b.link_id2 AND a.link_app1=b.link_app2
427 427
                         		JOIN $table c ON a.link_id2=c.link_id1 AND a.link_app2=c.link_app1 AND a.link_id!=c.link_id AND c.link_app2=b.link_app1 AND c.link_id2=b.link_id1",
@@ -430,7 +430,7 @@  discard block
 block discarded – undo
430 430
 			array('table'=>self::TABLE,
431 431
 				'cols'=>'a.*,c.link_app1 AS app3,c.link_id1 AS id3,c.link_id AS link3',
432 432
                      		'where'=>'a.link_app1='.self::$db->quote($app).' AND a.link_app2='.self::$db->quote($target_app).
433
-                        		(!$target_id ? '' : self::$db->expression(self::TABLE,' AND a.',array('link_id2' => $target_id))),
433
+                        		(!$target_id ? '' : self::$db->expression(self::TABLE, ' AND a.', array('link_id2' => $target_id))),
434 434
                        		'join'=>" a
435 435
                        			JOIN $table b ON a.link_id1=b.link_id2 AND a.link_app1=b.link_app2
436 436
                         		JOIN $table c ON a.link_id2=c.link_id2 AND a.link_app2=c.link_app2 AND a.link_id!=c.link_id AND c.link_app1=b.link_app1 AND c.link_id1=b.link_id1",
@@ -442,17 +442,17 @@  discard block
 block discarded – undo
442 442
 		{
443 443
 			list($offset, $limit) = $limit;
444 444
 		}
445
-		elseif($limit)
445
+		elseif ($limit)
446 446
 		{
447 447
 			$offset = 0;
448 448
 		}
449 449
 
450 450
 		$links = array();
451
-		foreach(self::$db->union($arrayofselects, __LINE__, __FILE__, $order, $offset, $limit) as $row)
451
+		foreach (self::$db->union($arrayofselects, __LINE__, __FILE__, $order, $offset, $limit) as $row)
452 452
 		{
453 453
 			if ($just_app_ids)
454 454
 			{
455
-				if ($row['link_app1'] == $target_app && (is_null($target_id) || in_array($row['link_id1'],(array)$target_id)))
455
+				if ($row['link_app1'] == $target_app && (is_null($target_id) || in_array($row['link_id1'], (array)$target_id)))
456 456
 				{
457 457
 					$links[$row['link_id']] = $row['link_id2'];
458 458
 				}
@@ -463,7 +463,7 @@  discard block
 block discarded – undo
463 463
 			}
464 464
 			else
465 465
 			{
466
-				$links[] = Api\Db::strip_array_keys($row,'link_');
466
+				$links[] = Api\Db::strip_array_keys($row, 'link_');
467 467
 			}
468 468
 		}
469 469
 		// if query returns exactly limit rows, we assume there are more and therefore set self::$limit_exceeded
@@ -477,7 +477,7 @@  discard block
 block discarded – undo
477 477
 	 */
478 478
 	static function init_static( )
479 479
 	{
480
-		self::$db     = $GLOBALS['egw']->db;
480
+		self::$db = $GLOBALS['egw']->db;
481 481
 	}
482 482
 }
483 483
 Storage::init_static();
Please login to merge, or discard this patch.
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -302,7 +302,10 @@
 block discarded – undo
302 302
 			}
303 303
 			if ($owner)
304 304
 			{
305
-				if ($app) $where = array($where);
305
+				if ($app)
306
+				{
307
+					$where = array($where);
308
+				}
306 309
 				$where['link_owner'] = $owner;
307 310
 			}
308 311
 		}
Please login to merge, or discard this patch.
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -269,7 +269,7 @@
 block discarded – undo
269 269
 		{
270 270
 			$where = array('link_id' => $link_id);
271 271
 		}
272
-		elseif ($app == '' AND $owner == '')
272
+		elseif ($app == '' and $owner == '')
273 273
 		{
274 274
 			return 0;
275 275
 		}
Please login to merge, or discard this patch.
api/src/Mail/Account.php 3 patches
Doc Comments   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -486,7 +486,7 @@  discard block
 block discarded – undo
486 486
 	 * @param boolean $replace_placeholders =false should placeholders like {{n_fn}} be replaced
487 487
 	 * @param string $field ='name' what to return as value: "ident_(realname|org|email|signature)" or default "name"=result from identity_name
488 488
 	 * @param int $user =null account_id to use if not current user
489
-	 * @return Iterator ident_id => identity_name of identity
489
+	 * @return Api\Db\CallbackIterator ident_id => identity_name of identity
490 490
 	 */
491 491
 	public static function identities($account, $replace_placeholders=true, $field='name', $user=null)
492 492
 	{
@@ -795,7 +795,7 @@  discard block
 block discarded – undo
795 795
 	 *
796 796
 	 * To get $this->params you need to call getUserData before! It is never automatically loaded.
797 797
 	 *
798
-	 * @param type $name
798
+	 * @param string $name
799 799
 	 * @return mixed
800 800
 	 */
801 801
 	public function __get($name)
@@ -819,8 +819,8 @@  discard block
 block discarded – undo
819 819
 	/**
820 820
 	 * Give read access to protected parameters in $this->params
821 821
 	 *
822
-	 * @param type $name
823
-	 * @return mixed
822
+	 * @param string $name
823
+	 * @return boolean
824 824
 	 */
825 825
 	public function __isset($name)
826 826
 	{
@@ -1340,10 +1340,10 @@  discard block
 block discarded – undo
1340 1340
 	 * @param boolean|string $just_name =true true: return self::identity_name, false: return Account objects,
1341 1341
 	 *	string with attribute-name: return that attribute, eg. acc_imap_host or 'params' to return all attributes as array
1342 1342
 	 * @param string $order_by ='acc_name ASC'
1343
-	 * @param int|boolean $offset =false offset or false to return all
1343
+	 * @param boolean $offset =false offset or false to return all
1344 1344
 	 * @param int $num_rows =0 number of rows to return, 0=default from prefs (if $offset !== false)
1345 1345
 	 * @param boolean $replace_placeholders =true should placeholders like {{n_fn}} be replaced
1346
-	 * @return Iterator with acc_id => acc_name or Account objects
1346
+	 * @return Api\Db\CallbackIterator with acc_id => acc_name or Account objects
1347 1347
 	 */
1348 1348
 	public static function search($only_current_user=true, $just_name=true, $order_by=null, $offset=false, $num_rows=0, $replace_placeholders=true)
1349 1349
 	{
Please login to merge, or discard this patch.
Braces   +95 added lines, -24 removed lines patch added patch discarded remove patch
@@ -360,8 +360,14 @@  discard block
 block discarded – undo
360 360
 		{
361 361
 			// make sure mbstring.func_overload=0
362 362
 			static $func_overload = null;
363
-			if (is_null($func_overload)) $func_overload = extension_loaded('mbstring') ? ini_get('mbstring.func_overload') : 0;
364
-			if ($func_overload) throw new Api\Exception\AssertionFailed('Fatal Error: EGroupware requires mbstring.func_overload=0 set in your php.ini!');
363
+			if (is_null($func_overload))
364
+			{
365
+				$func_overload = extension_loaded('mbstring') ? ini_get('mbstring.func_overload') : 0;
366
+			}
367
+			if ($func_overload)
368
+			{
369
+				throw new Api\Exception\AssertionFailed('Fatal Error: EGroupware requires mbstring.func_overload=0 set in your php.ini!');
370
+			}
365 371
 
366 372
 			$class = $this->params['acc_imap_type'];
367 373
 			$this->imapServer = new $class($this->params, $_adminConnection, $_timeout);
@@ -490,7 +496,10 @@  discard block
 block discarded – undo
490 496
 	 */
491 497
 	public static function identities($account, $replace_placeholders=true, $field='name', $user=null)
492 498
 	{
493
-		if (!isset($user)) $user = $GLOBALS['egw_info']['user']['account_id'];
499
+		if (!isset($user))
500
+		{
501
+			$user = $GLOBALS['egw_info']['user']['account_id'];
502
+		}
494 503
 		$acc_id = is_scalar($account) ? $account : $account['acc_id'];
495 504
 
496 505
 		$cols = array('ident_id', 'ident_name', 'ident_realname', 'ident_org', 'ident_email', 'ident_signature', 'acc_id', 'acc_imap_username', 'acc_imap_logintype', 'acc_domain');
@@ -528,8 +537,14 @@  discard block
 block discarded – undo
528 537
 				// fill an empty ident_realname or ident_email of current user with data from user account
529 538
 				if ($replace_placeholders && (!isset($user) || $user == $GLOBALS['egw_info']['user']['acount_id']))
530 539
 				{
531
-					if (empty($row['ident_realname'])) $row['ident_realname'] = $GLOBALS['egw_info']['user']['account_fullname'];
532
-					if (empty($row['ident_email'])) $row['ident_email'] = $GLOBALS['egw_info']['user']['account_email'];
540
+					if (empty($row['ident_realname']))
541
+					{
542
+						$row['ident_realname'] = $GLOBALS['egw_info']['user']['account_fullname'];
543
+					}
544
+					if (empty($row['ident_email']))
545
+					{
546
+						$row['ident_email'] = $GLOBALS['egw_info']['user']['account_email'];
547
+					}
533 548
 				}
534 549
 				if ($field != 'name')
535 550
 				{
@@ -538,7 +553,9 @@  discard block
 block discarded – undo
538 553
 				}
539 554
 				return self::identity_name($row, $replace_placeholders);
540 555
 			}, array(),
541
-			function($row) { return $row['ident_id'];});
556
+			function($row)
557
+			{
558
+return $row['ident_id'];});
542 559
 	}
543 560
 
544 561
 	/**
@@ -554,10 +571,13 @@  discard block
 block discarded – undo
554 571
 		{
555 572
 			$address .= ($address && $identity['ident_org'] ? ' ' : '').$identity['ident_org'];
556 573
 		}
557
-		if (strpos($address, ',') !== false)	// need to quote comma
574
+		if (strpos($address, ',') !== false)
575
+		{
576
+			// need to quote comma
558 577
 		{
559 578
 			$address = '"'.str_replace('"', '\\"', $address).'"';
560 579
 		}
580
+		}
561 581
 		if (!strpos($identity['ident_email'], '@'))
562 582
 		{
563 583
 			$address = null;
@@ -661,8 +681,14 @@  discard block
 block discarded – undo
661 681
 		if ($to_replace)
662 682
 		{
663 683
 			static $merge=null;
664
-			if (!isset($merge)) $merge = new Api\Contacts\Merge();
665
-			if (!isset($account_id)) $account_id = $GLOBALS['egw_info']['user']['account_id'];
684
+			if (!isset($merge))
685
+			{
686
+				$merge = new Api\Contacts\Merge();
687
+			}
688
+			if (!isset($account_id))
689
+			{
690
+				$account_id = $GLOBALS['egw_info']['user']['account_id'];
691
+			}
666 692
 			foreach($to_replace as $name => &$value)
667 693
 			{
668 694
 				$err = null;
@@ -1083,7 +1109,10 @@  discard block
 block discarded – undo
1083 1109
 				}
1084 1110
 
1085 1111
 				// fetch the IMAP / incomming server data
1086
-				if (!class_exists($data['acc_smtp_type'])) $data['acc_smtp_type'] = __NAMESPACE__.'\\Smtp';
1112
+				if (!class_exists($data['acc_smtp_type']))
1113
+				{
1114
+					$data['acc_smtp_type'] = __NAMESPACE__.'\\Smtp';
1115
+				}
1087 1116
 			}
1088 1117
 		}
1089 1118
 		return $data;
@@ -1115,7 +1144,10 @@  discard block
 block discarded – undo
1115 1144
 		}
1116 1145
 
1117 1146
 		// fetch the IMAP / incomming server data
1118
-		if (!class_exists($imap_type)) $imap_type = __NAMESPACE__.'\\Imap';
1147
+		if (!class_exists($imap_type))
1148
+		{
1149
+			$imap_type = __NAMESPACE__.'\\Imap';
1150
+		}
1119 1151
 
1120 1152
 		return $imap_type;
1121 1153
 	}
@@ -1168,7 +1200,10 @@  discard block
 block discarded – undo
1168 1200
 			$data['acc_id'] = self::$db->get_last_insert_id(self::TABLE, 'acc_id');
1169 1201
 		}
1170 1202
 		// restore namespace in class-names
1171
-		if ($backup) $data = array_merge($data, $backup);
1203
+		if ($backup)
1204
+		{
1205
+			$data = array_merge($data, $backup);
1206
+		}
1172 1207
 
1173 1208
 		// store identity
1174 1209
 		$new_ident_id = self::save_identity($data);
@@ -1279,7 +1314,10 @@  discard block
 block discarded – undo
1279 1314
 	 */
1280 1315
 	protected static function credentials_valid_for($account, $account_id=null)
1281 1316
 	{
1282
-		if (!isset($account_id)) $account_id = $GLOBALS['egw_info']['user']['account_id'];
1317
+		if (!isset($account_id))
1318
+		{
1319
+			$account_id = $GLOBALS['egw_info']['user']['account_id'];
1320
+		}
1283 1321
 
1284 1322
 		// if account valid for multiple users
1285 1323
 		if (self::is_multiple($account))
@@ -1398,9 +1436,12 @@  discard block
 block discarded – undo
1398 1436
 				$cols[] = $valid_account_id_sql.' AS account_id';
1399 1437
 				$join .= ' '.self::ALL_VALID_JOIN;
1400 1438
 			}
1401
-			if ($just_name == 'params')	// join in acc_imap_admin_username
1439
+			if ($just_name == 'params')
1440
+			{
1441
+				// join in acc_imap_admin_username
1402 1442
 			{
1403 1443
 				$cols[] = self::ADMIN_COL;
1444
+			}
1404 1445
 				$join .= ' '.self::ADMIN_JOIN;
1405 1446
 			}
1406 1447
 			$rs = self::$db->select(self::TABLE, $cols,	$where, __LINE__, __FILE__,
@@ -1434,7 +1475,10 @@  discard block
 block discarded – undo
1434 1475
 				}
1435 1476
 			}
1436 1477
 		}
1437
-		if (is_null(self::$search_cache[$cache_key])) self::$search_cache[$cache_key]=array();
1478
+		if (is_null(self::$search_cache[$cache_key]))
1479
+		{
1480
+			self::$search_cache[$cache_key]=array();
1481
+		}
1438 1482
 		return new Api\Db\CallbackIterator(new \ArrayIterator(self::$search_cache[$cache_key]),
1439 1483
 			// process each row
1440 1484
 			function($row) use ($just_name, $replace_placeholders, $account_id)
@@ -1476,12 +1520,18 @@  discard block
 block discarded – undo
1476 1520
 			{
1477 1521
 				if ($smtp)
1478 1522
 				{
1479
-					if (!$params['acc_smtp_host'] || !$params['acc_smtp_port']) continue;
1523
+					if (!$params['acc_smtp_host'] || !$params['acc_smtp_port'])
1524
+					{
1525
+						continue;
1526
+					}
1480 1527
 					// check requirement of session, which is not available in async service!
1481 1528
 					if (isset($GLOBALS['egw_info']['flags']['async-service']) ||
1482
-						empty($GLOBALS['egw_info']['user']['account_id']))	// happens during login when notifying about blocked accounts
1529
+						empty($GLOBALS['egw_info']['user']['account_id']))
1530
+					{
1531
+						// happens during login when notifying about blocked accounts
1483 1532
 					{
1484 1533
 						if ($params['acc_smtp_auth_session']) continue;
1534
+					}
1485 1535
 						// may fail because of smtp only profile, or no session password, etc
1486 1536
 						try
1487 1537
 						{
@@ -1492,15 +1542,24 @@  discard block
 block discarded – undo
1492 1542
 							unset($x);
1493 1543
 							continue;
1494 1544
 						}
1495
-						if (Credentials::isUser($account->acc_smtp_pw_enc)) continue;
1545
+						if (Credentials::isUser($account->acc_smtp_pw_enc))
1546
+						{
1547
+							continue;
1548
+						}
1496 1549
 					}
1497 1550
 				}
1498 1551
 				else
1499 1552
 				{
1500
-					if (!$params['acc_imap_host'] || !$params['acc_imap_port']) continue;
1553
+					if (!$params['acc_imap_host'] || !$params['acc_imap_port'])
1554
+					{
1555
+						continue;
1556
+					}
1501 1557
 					$account = new Account($params);
1502 1558
 					// continue if we have either no imap username or password
1503
-					if (!$account->is_imap()) continue;
1559
+					if (!$account->is_imap())
1560
+					{
1561
+						continue;
1562
+					}
1504 1563
 				}
1505 1564
 				return $return_id ? $acc_id : (isset($account) && $account->acc_id == $acc_id ?
1506 1565
 					$account : new Account($params));
@@ -1508,7 +1567,10 @@  discard block
 block discarded – undo
1508 1567
 		}
1509 1568
 		catch (\Exception $e)
1510 1569
 		{
1511
-			if ($log_no_default) error_log(__METHOD__.__LINE__.' Error no Default available.'.$e->getMessage());
1570
+			if ($log_no_default)
1571
+			{
1572
+				error_log(__METHOD__.__LINE__.' Error no Default available.'.$e->getMessage());
1573
+			}
1512 1574
 		}
1513 1575
 		return null;
1514 1576
 	}
@@ -1570,8 +1632,14 @@  discard block
 block discarded – undo
1570 1632
 				// fill an empty ident_realname or ident_email of current user with data from user account
1571 1633
 				if ($replace_placeholders && (!isset($account_id) || $account_id == $GLOBALS['egw_info']['user']['acount_id']))
1572 1634
 				{
1573
-					if (empty($account['ident_realname'])) $account['ident_realname'] = $GLOBALS['egw_info']['user']['account_fullname'];
1574
-					if (empty($account['ident_email'])) $account['ident_email'] = $GLOBALS['egw_info']['user']['account_email'];
1635
+					if (empty($account['ident_realname']))
1636
+					{
1637
+						$account['ident_realname'] = $GLOBALS['egw_info']['user']['account_fullname'];
1638
+					}
1639
+					if (empty($account['ident_email']))
1640
+					{
1641
+						$account['ident_email'] = $GLOBALS['egw_info']['user']['account_email'];
1642
+					}
1575 1643
 				}
1576 1644
 				if (empty($account['ident_email']) && !empty($account['acc_imap_username']) && strpos($account['acc_imap_username'], '@') !== false)
1577 1645
 				{
@@ -1642,7 +1710,10 @@  discard block
 block discarded – undo
1642 1710
 	 */
1643 1711
 	protected static function memberships($user=null)
1644 1712
 	{
1645
-		if (!$user) $user = $GLOBALS['egw_info']['user']['account_id'];
1713
+		if (!$user)
1714
+		{
1715
+			$user = $GLOBALS['egw_info']['user']['account_id'];
1716
+		}
1646 1717
 
1647 1718
 		$memberships = $GLOBALS['egw']->accounts->memberships($user, true);
1648 1719
 		$memberships[] = $user;
Please login to merge, or discard this patch.
Spacing   +69 added lines, -72 removed lines patch added patch discarded remove patch
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
 	/**
198 198
 	 * Path to log smtp comunication to or null to not log
199 199
 	 */
200
-	const SMTP_DEBUG_LOG = null;//'/tmp/smtp.log';
200
+	const SMTP_DEBUG_LOG = null; //'/tmp/smtp.log';
201 201
 
202 202
 	/**
203 203
 	 * Instanciated account object by acc_id, read acts as singelton
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
 	 * @param int $called_for=null if set access to given user (without smtp credentials!),
253 253
 	 *	default current user AND read username/password from current users session
254 254
 	 */
255
-	/*protected*/ function __construct(array $params, $called_for=null)
255
+	/*protected*/ function __construct(array $params, $called_for = null)
256 256
 	{
257 257
 		// read credentials from database
258 258
 		$params += Credentials::read($params['acc_id'], null, $called_for ? array(0, $called_for) : $called_for, $this->on_login);
@@ -281,16 +281,16 @@  discard block
 block discarded – undo
281 281
 	public static function ssl2secure($ssl)
282 282
 	{
283 283
 		$secure = false;
284
-		switch($ssl & ~self::SSL_VERIFY)
284
+		switch ($ssl&~self::SSL_VERIFY)
285 285
 		{
286 286
 			case self::SSL_STARTTLS:
287
-				$secure = 'tls';	// Horde uses 'tls' for STARTTLS, not ssl connection with tls version >= 1 and no sslv2/3
287
+				$secure = 'tls'; // Horde uses 'tls' for STARTTLS, not ssl connection with tls version >= 1 and no sslv2/3
288 288
 				break;
289 289
 			case self::SSL_SSL:
290 290
 				$secure = 'ssl';
291 291
 				break;
292 292
 			case self::SSL_TLS:
293
-				$secure = 'tlsv1';	// since Horde_Imap_Client-1.16.0 requiring Horde_Socket_Client-1.1.0
293
+				$secure = 'tlsv1'; // since Horde_Imap_Client-1.16.0 requiring Horde_Socket_Client-1.1.0
294 294
 				break;
295 295
 		}
296 296
 		return $secure;
@@ -324,15 +324,15 @@  discard block
 block discarded – undo
324 324
 				$this->params = array_merge($this->params, $data);
325 325
 			}
326 326
 		}
327
-		catch(Horde_Imap_Client_Exception $e) {
327
+		catch (Horde_Imap_Client_Exception $e) {
328 328
 			unset($e);
329 329
 			// ignore eg. connection errors
330 330
 		}
331
-		catch(\InvalidArgumentException $e) {
331
+		catch (\InvalidArgumentException $e) {
332 332
 			unset($e);
333 333
 			// ignore eg. missing admin user
334 334
 		}
335
-		$this->params += array_fill_keys(self::$user_data, null);	// make sure all keys exist now
335
+		$this->params += array_fill_keys(self::$user_data, null); // make sure all keys exist now
336 336
 
337 337
 		return (array)$data + (array)$smtp_data;
338 338
 	}
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
 	 */
345 345
 	public function saveUserData($user, array $data)
346 346
 	{
347
-		$data += $this->params;	// in case only user-data has been specified
347
+		$data += $this->params; // in case only user-data has been specified
348 348
 
349 349
 		// store account-information of managed mail server
350 350
 		if ($user > 0 && $data['acc_smtp_type'] && $data['acc_smtp_type'] != __NAMESPACE__.'\\Smtp')
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
 	 * @param int $_timeout =null timeout in secs, if none given fmail pref or default of 20 is used
369 369
 	 * @return Imap
370 370
 	 */
371
-	public function imapServer($_adminConnection=false, $_timeout=null)
371
+	public function imapServer($_adminConnection = false, $_timeout = null)
372 372
 	{
373 373
 		if (!isset($this->imapServer) || $this->imapServer->isAdminConnection !== $_adminConnection)
374 374
 		{
@@ -400,11 +400,11 @@  discard block
 block discarded – undo
400 400
 	 *	(matters only for imap servers managed by EGroupware!)
401 401
 	 * @return boolean
402 402
 	 */
403
-	public function is_imap($try_connect=true)
403
+	public function is_imap($try_connect = true)
404 404
 	{
405
-		if (empty($this->acc_imap_host) || ( empty($this->acc_imap_username) && empty($this->acc_imap_password) ) )
405
+		if (empty($this->acc_imap_host) || (empty($this->acc_imap_username) && empty($this->acc_imap_password)))
406 406
 		{
407
-			return false;	// no imap host or credentials
407
+			return false; // no imap host or credentials
408 408
 		}
409 409
 		// if we are not managing the mail-server, we do NOT need to check deliveryMode and accountStatus
410 410
 		if ($this->acc_smtp_type == __NAMESPACE__.'\\Smtp')
@@ -441,7 +441,7 @@  discard block
 block discarded – undo
441 441
 			$this->smtpServer->editForwardingAddress = false;
442 442
 			$this->smtpServer->host = $this->params['acc_smtp_host'];
443 443
 			$this->smtpServer->port = $this->params['acc_smtp_port'];
444
-			switch($this->params['acc_smtp_ssl'])
444
+			switch ($this->params['acc_smtp_ssl'])
445 445
 			{
446 446
 				case self::SSL_TLS:
447 447
 					$this->smtpServer->host = 'tlsv1://'.$this->smtpServer->host;
@@ -471,16 +471,16 @@  discard block
 block discarded – undo
471 471
 		if (!isset($this->smtpTransport))
472 472
 		{
473 473
 			$secure = false;
474
-			switch($this->acc_smtp_ssl & ~self::SSL_VERIFY)
474
+			switch ($this->acc_smtp_ssl & ~self::SSL_VERIFY)
475 475
 			{
476 476
 				case self::SSL_STARTTLS:
477
-					$secure = 'tls';	// Horde uses 'tls' for STARTTLS, not ssl connection with tls version >= 1 and no sslv2/3
477
+					$secure = 'tls'; // Horde uses 'tls' for STARTTLS, not ssl connection with tls version >= 1 and no sslv2/3
478 478
 					break;
479 479
 				case self::SSL_SSL:
480 480
 					$secure = 'ssl';
481 481
 					break;
482 482
 				case self::SSL_TLS:
483
-					$secure = 'tlsv1';	// since Horde_Smtp-1.3.0 requiring Horde_Socket_Client-1.1.0
483
+					$secure = 'tlsv1'; // since Horde_Smtp-1.3.0 requiring Horde_Socket_Client-1.1.0
484 484
 					break;
485 485
 			}
486 486
 			// Horde use locale for translation of error messages
@@ -510,7 +510,7 @@  discard block
 block discarded – undo
510 510
 	 * @param int $user =null account_id to use if not current user
511 511
 	 * @return Iterator ident_id => identity_name of identity
512 512
 	 */
513
-	public static function identities($account, $replace_placeholders=true, $field='name', $user=null)
513
+	public static function identities($account, $replace_placeholders = true, $field = 'name', $user = null)
514 514
 	{
515 515
 		if (!isset($user)) $user = $GLOBALS['egw_info']['user']['account_id'];
516 516
 		$acc_id = is_scalar($account) ? $account : $account['acc_id'];
@@ -560,7 +560,7 @@  discard block
 block discarded – undo
560 560
 				}
561 561
 				return self::identity_name($row, $replace_placeholders);
562 562
 			}, array(),
563
-			function($row) { return $row['ident_id'];});
563
+			function($row) { return $row['ident_id']; });
564 564
 	}
565 565
 
566 566
 	/**
@@ -603,17 +603,17 @@  discard block
 block discarded – undo
603 603
 	 * @return array acc_id:ident_id:email => rfc822 address pairs, eg. '1:1:[email protected]' => 'Ralf Becker Stylite AG <[email protected]>'
604 604
 	 * @todo add aliases for manged mail servers
605 605
 	 */
606
-	public static function rfc822_addresses($formatter=null)
606
+	public static function rfc822_addresses($formatter = null)
607 607
 	{
608 608
 		if (!$formatter || !is_callable($formatter))
609 609
 		{
610 610
 			$formatter = 'self::rfc822';
611 611
 		}
612 612
 		$addresses = array();
613
-		foreach(self::search(true, false) as $acc_id => $account)
613
+		foreach (self::search(true, false) as $acc_id => $account)
614 614
 		{
615
-			$added = false;	// make sure each account get's at least added once, even if it uses an identical email address
616
-			foreach(self::identities($account, true, 'params') as $identity)
615
+			$added = false; // make sure each account get's at least added once, even if it uses an identical email address
616
+			foreach (self::identities($account, true, 'params') as $identity)
617 617
 			{
618 618
 				if (($address = call_user_func($formatter, $identity)) && (!$added || !in_array($address, $addresses)))
619 619
 				{
@@ -647,7 +647,7 @@  discard block
 block discarded – undo
647 647
 			}
648 648
 			return $cmp;
649 649
 		});
650
-		foreach($identities as &$identity)
650
+		foreach ($identities as &$identity)
651 651
 		{
652 652
 			$identity = self::identity_name($identity);
653 653
 		}
@@ -664,16 +664,16 @@  discard block
 block discarded – undo
664 664
 	 * @param int $account_id =null account_id of user, or current user
665 665
 	 * @return array with modified fields
666 666
 	 */
667
-	public static function replace_placeholders($identity, $account_id=null)
667
+	public static function replace_placeholders($identity, $account_id = null)
668 668
 	{
669
-		static $fields = array('ident_name','ident_realname','ident_org','ident_email','ident_signature');
669
+		static $fields = array('ident_name', 'ident_realname', 'ident_org', 'ident_email', 'ident_signature');
670 670
 
671 671
 		if (!is_array($identity) && !is_a($identity, 'Account'))
672 672
 		{
673 673
 			throw new Api\Exception\WrongParameter(__METHOD__."() requires an identity or account as first parameter!");
674 674
 		}
675 675
 		$to_replace = array();
676
-		foreach($fields as $name)
676
+		foreach ($fields as $name)
677 677
 		{
678 678
 			if (strpos($identity[$name], '{{') !== false || strpos($identity[$name], '$$') !== false)
679 679
 			{
@@ -682,10 +682,10 @@  discard block
 block discarded – undo
682 682
 		}
683 683
 		if ($to_replace)
684 684
 		{
685
-			static $merge=null;
685
+			static $merge = null;
686 686
 			if (!isset($merge)) $merge = new Api\Contacts\Merge();
687 687
 			if (!isset($account_id)) $account_id = $GLOBALS['egw_info']['user']['account_id'];
688
-			foreach($to_replace as $name => &$value)
688
+			foreach ($to_replace as $name => &$value)
689 689
 			{
690 690
 				$err = null;
691 691
 				$value = $merge->merge_string($value,
@@ -707,7 +707,7 @@  discard block
 block discarded – undo
707 707
 	 * @return array
708 708
 	 * @throws Api\Exception\NotFound
709 709
 	 */
710
-	public static function read_identity($ident_id, $replace_placeholders=false, $user=null, $account=null)
710
+	public static function read_identity($ident_id, $replace_placeholders = false, $user = null, $account = null)
711 711
 	{
712 712
 		if (($account && $account['ident_id'] == $ident_id))
713 713
 		{
@@ -777,8 +777,7 @@  discard block
 block discarded – undo
777 777
 			'ident_org' => $identity['ident_org'],
778 778
 			'ident_email' => $identity['ident_email'],
779 779
 			'ident_signature' => $identity['ident_signature'],
780
-			'account_id' => self::is_multiple($identity) ? 0 :
781
-				(is_array($identity['account_id']) ? $identity['account_id'][0] : $identity['account_id']),
780
+			'account_id' => self::is_multiple($identity) ? 0 : (is_array($identity['account_id']) ? $identity['account_id'][0] : $identity['account_id']),
782 781
 		);
783 782
 		if ($identity['ident_id'] > 0)
784 783
 		{
@@ -822,7 +821,7 @@  discard block
 block discarded – undo
822 821
 	 */
823 822
 	public function __get($name)
824 823
 	{
825
-		switch($name)
824
+		switch ($name)
826 825
 		{
827 826
 			case 'acc_imap_administration':	// no longer stored in database
828 827
 				return !empty($this->params['acc_imap_admin_username']);
@@ -846,7 +845,7 @@  discard block
 block discarded – undo
846 845
 	 */
847 846
 	public function __isset($name)
848 847
 	{
849
-		switch($name)
848
+		switch ($name)
850 849
 		{
851 850
 			case 'acc_imap_administration':	// no longer stored in database
852 851
 				return true;
@@ -936,11 +935,11 @@  discard block
 block discarded – undo
936 935
 		{
937 936
 			// check if account is for current user, if not deny access
938 937
 			$memberships = self::memberships();
939
-			$memberships[] = '';	// edit uses '' for everyone
938
+			$memberships[] = ''; // edit uses '' for everyone
940 939
 
941 940
 			if (array_intersect((array)$account['account_id'], $memberships))
942 941
 			{
943
-				switch($rights)
942
+				switch ($rights)
944 943
 				{
945 944
 					case Api\Acl::READ:
946 945
 						$access = true;
@@ -985,7 +984,7 @@  discard block
 block discarded – undo
985 984
 	 * @return email_account
986 985
 	 * @throws Api\Exception\NotFound if account was not found (or not valid for current user)
987 986
 	 */
988
-	public static function read($acc_id, $called_for=null)
987
+	public static function read($acc_id, $called_for = null)
989 988
 	{
990 989
 		//error_log(__METHOD__."($acc_id, ".array2string($called_for).")");
991 990
 		// some caching, but only for regular usage/users
@@ -1003,7 +1002,7 @@  discard block
 block discarded – undo
1003 1002
 				//error_log(__METHOD__."($acc_id) created instance from cached data");
1004 1003
 				return self::$instances[$acc_id] = new Account(self::$cache[$acc_id]);
1005 1004
 			}
1006
-			$data =& self::$cache[$acc_id];
1005
+			$data = & self::$cache[$acc_id];
1007 1006
 		}
1008 1007
 		$where = array(self::TABLE.'.acc_id='.(int)$acc_id);
1009 1008
 		if (!isset($called_for) || $called_for !== '0')
@@ -1027,7 +1026,7 @@  discard block
 block discarded – undo
1027 1026
 		if (!$valid_account_id_sql)
1028 1027
 		{
1029 1028
 			$data['account_id'] = array();
1030
-			foreach(self::$db->select(self::VALID_TABLE, 'account_id', array('acc_id' => $acc_id),
1029
+			foreach (self::$db->select(self::VALID_TABLE, 'account_id', array('acc_id' => $acc_id),
1031 1030
 				__LINE__, __FILE__, false, '', self::APP) as $row)
1032 1031
 			{
1033 1032
 				$data['account_id'][] = $row['account_id'];
@@ -1039,7 +1038,7 @@  discard block
 block discarded – undo
1039 1038
 		if (!isset($called_for))
1040 1039
 		{
1041 1040
 			//error_log(__METHOD__."($acc_id) creating instance and caching data read from db");
1042
-			$ret =& self::$instances[$acc_id];
1041
+			$ret = & self::$instances[$acc_id];
1043 1042
 		}
1044 1043
 		return $ret = new Account($data, $called_for);
1045 1044
 	}
@@ -1052,7 +1051,7 @@  discard block
 block discarded – undo
1052 1051
 	 */
1053 1052
 	protected static function db2data(array $data)
1054 1053
 	{
1055
-		foreach(array('acc_sieve_enabled','acc_user_editable','acc_smtp_auth_session','acc_user_forward') as $name)
1054
+		foreach (array('acc_sieve_enabled', 'acc_user_editable', 'acc_smtp_auth_session', 'acc_user_forward') as $name)
1056 1055
 		{
1057 1056
 			if (isset($data[$name]))
1058 1057
 			{
@@ -1151,16 +1150,16 @@  discard block
 block discarded – undo
1151 1150
 	 * @throws Api\Exception\WrongParameter if called static without data-array
1152 1151
 	 * @throws Api\Db\Exception
1153 1152
 	 */
1154
-	public static function write(array $data, $user=null)
1153
+	public static function write(array $data, $user = null)
1155 1154
 	{
1156 1155
 		//error_log(__METHOD__."(".array2string($data).")");
1157 1156
 		$data['acc_modifier'] = $GLOBALS['egw_info']['user']['account_id'];
1158 1157
 		$data['acc_modified'] = time();
1159 1158
 
1160 1159
 		// remove redundant namespace to fit into column
1161
-		$ns_len = strlen(__NAMESPACE__)+1;
1160
+		$ns_len = strlen(__NAMESPACE__) + 1;
1162 1161
 		$backup = array();
1163
-		foreach(array('acc_smtp_type', 'acc_imap_type') as $attr)
1162
+		foreach (array('acc_smtp_type', 'acc_imap_type') as $attr)
1164 1163
 		{
1165 1164
 			if (substr($data[$attr], 0, $ns_len) == __NAMESPACE__.'\\')
1166 1165
 			{
@@ -1174,7 +1173,7 @@  discard block
 block discarded – undo
1174 1173
 		{
1175 1174
 			// set not set values which, are NOT NULL and therefore would give an SQL error
1176 1175
 			$td = self::$db->get_table_definitions('api', self::TABLE);
1177
-			foreach($td['fd'] as $col => $def)
1176
+			foreach ($td['fd'] as $col => $def)
1178 1177
 			{
1179 1178
 				if (!isset($data[$col]) && $def['nullable'] === false && !isset($def['default']))
1180 1179
 				{
@@ -1211,19 +1210,19 @@  discard block
 block discarded – undo
1211 1210
 		$old_account_ids = array();
1212 1211
 		if ($where)
1213 1212
 		{
1214
-			foreach(self::$db->select(self::VALID_TABLE, 'account_id', $where,
1213
+			foreach (self::$db->select(self::VALID_TABLE, 'account_id', $where,
1215 1214
 				__LINE__, __FILE__, false, '', self::APP) as $row)
1216 1215
 			{
1217 1216
 				$old_account_ids[] = $row['account_id'];
1218 1217
 			}
1219 1218
 			if (($ids_to_remove = array_diff($old_account_ids, (array)$data['account_id'])))
1220 1219
 			{
1221
-				self::$db->delete(self::VALID_TABLE, $where+array(
1220
+				self::$db->delete(self::VALID_TABLE, $where + array(
1222 1221
 					'account_id' => $ids_to_remove,
1223 1222
 				), __LINE__, __FILE__, self::APP);
1224 1223
 			}
1225 1224
 		}
1226
-		foreach((array)$data['account_id'] as $account_id)
1225
+		foreach ((array)$data['account_id'] as $account_id)
1227 1226
 		{
1228 1227
 			if (!in_array($account_id, $old_account_ids))
1229 1228
 			{
@@ -1273,8 +1272,7 @@  discard block
 block discarded – undo
1273 1272
 		}
1274 1273
 
1275 1274
 		// store notification folders
1276
-		Notifications::write($data['acc_id'], $data['notify_save_default'] ? 0 :
1277
-			($data['called_for'] ? $data['called_for'] : $GLOBALS['egw_info']['user']['account_id']),
1275
+		Notifications::write($data['acc_id'], $data['notify_save_default'] ? 0 : ($data['called_for'] ? $data['called_for'] : $GLOBALS['egw_info']['user']['account_id']),
1278 1276
 			(array)$data['notify_folders']);
1279 1277
 
1280 1278
 		// store domain of an account for all user like before as "mail_suffix" config
@@ -1300,7 +1298,7 @@  discard block
 block discarded – undo
1300 1298
 	 * @param int $account_id =null
1301 1299
 	 * @return int account_id for whom credentials are valid or 0 for all
1302 1300
 	 */
1303
-	protected static function credentials_valid_for($account, $account_id=null)
1301
+	protected static function credentials_valid_for($account, $account_id = null)
1304 1302
 	{
1305 1303
 		if (!isset($account_id)) $account_id = $GLOBALS['egw_info']['user']['account_id'];
1306 1304
 
@@ -1326,7 +1324,7 @@  discard block
 block discarded – undo
1326 1324
 	 * @param int $account_id =null user or group
1327 1325
 	 * @return int number of deleted mail accounts or null if only user-data was deleted and no full mail accounts
1328 1326
 	 */
1329
-	public static function delete($acc_id, $account_id=null)
1327
+	public static function delete($acc_id, $account_id = null)
1330 1328
 	{
1331 1329
 		if (is_array($acc_id) || $acc_id > 0)
1332 1330
 		{
@@ -1337,7 +1335,7 @@  discard block
 block discarded – undo
1337 1335
 			self::$db->delete(self::TABLE, array('acc_id' => $acc_id), __LINE__, __FILE__, self::APP);
1338 1336
 
1339 1337
 			// invalidate caches
1340
-			foreach((array)$acc_id as $acc_id)
1338
+			foreach ((array)$acc_id as $acc_id)
1341 1339
 			{
1342 1340
 				self::cache_invalidate($acc_id);
1343 1341
 			}
@@ -1356,7 +1354,7 @@  discard block
 block discarded – undo
1356 1354
 		self::$db->delete(self::IDENTITIES_TABLE, array('account_id' => $account_id), __LINE__, __FILE__, self::APP);
1357 1355
 		// find profiles not belonging to anyone else and delete them
1358 1356
 		$acc_ids = array();
1359
-		foreach(self::$db->select(self::TABLE, self::TABLE.'.acc_id', 'account_id IS NULL', __LINE__, __FILE__,
1357
+		foreach (self::$db->select(self::TABLE, self::TABLE.'.acc_id', 'account_id IS NULL', __LINE__, __FILE__,
1360 1358
 			false, 'GROUP BY '.self::TABLE.'.acc_id', self::APP, 0, 'LEFT '.self::VALID_JOIN) as $row)
1361 1359
 		{
1362 1360
 			$acc_ids[] = $row['acc_id'];
@@ -1380,7 +1378,7 @@  discard block
 block discarded – undo
1380 1378
 	 * @param boolean $replace_placeholders =true should placeholders like {{n_fn}} be replaced
1381 1379
 	 * @return Iterator with acc_id => acc_name or Account objects
1382 1380
 	 */
1383
-	public static function search($only_current_user=true, $just_name=true, $order_by=null, $offset=false, $num_rows=0, $replace_placeholders=true)
1381
+	public static function search($only_current_user = true, $just_name = true, $order_by = null, $offset = false, $num_rows = 0, $replace_placeholders = true)
1384 1382
 	{
1385 1383
 		//error_log(__METHOD__."($only_current_user, $just_name, '$order_by', $offset, $num_rows)");
1386 1384
 		$where = array();
@@ -1426,19 +1424,19 @@  discard block
 block discarded – undo
1426 1424
 				$cols[] = self::ADMIN_COL;
1427 1425
 				$join .= ' '.self::ADMIN_JOIN;
1428 1426
 			}
1429
-			$rs = self::$db->select(self::TABLE, $cols,	$where, __LINE__, __FILE__,
1427
+			$rs = self::$db->select(self::TABLE, $cols, $where, __LINE__, __FILE__,
1430 1428
 				$offset, Api\Storage::fix_group_by_columns($group_by, $cols, self::TABLE, 'acc_id').' ORDER BY '.$order_by,
1431 1429
 				self::APP, $num_rows, $join);
1432 1430
 
1433 1431
 			$ids = array();
1434
-			foreach($rs as $row)
1432
+			foreach ($rs as $row)
1435 1433
 			{
1436 1434
 				$row = self::db2data($row);
1437 1435
 
1438 1436
 				if ($only_current_user === true)
1439 1437
 				{
1440 1438
 					//error_log(__METHOD__."(TRUE, $just_name) caching data for acc_id=$row[acc_id]");
1441
-					self::$search_cache[$cache_key][$row['acc_id']] =& self::$cache[$row['acc_id']];
1439
+					self::$search_cache[$cache_key][$row['acc_id']] = & self::$cache[$row['acc_id']];
1442 1440
 					self::$cache[$row['acc_id']] = $row;
1443 1441
 				}
1444 1442
 				else
@@ -1450,14 +1448,14 @@  discard block
 block discarded – undo
1450 1448
 			// fetch valid_id, if not yet fetched
1451 1449
 			if (!$valid_account_id_sql && $ids)
1452 1450
 			{
1453
-				foreach(self::$db->select(self::VALID_TABLE, 'account_id', array('acc_id' => $ids),
1451
+				foreach (self::$db->select(self::VALID_TABLE, 'account_id', array('acc_id' => $ids),
1454 1452
 					__LINE__, __FILE__, false, '', self::APP) as $row)
1455 1453
 				{
1456 1454
 					self::$cache[$row['acc_id']]['account_id'][] = $row['account_id'];
1457 1455
 				}
1458 1456
 			}
1459 1457
 		}
1460
-		if (is_null(self::$search_cache[$cache_key])) self::$search_cache[$cache_key]=array();
1458
+		if (is_null(self::$search_cache[$cache_key])) self::$search_cache[$cache_key] = array();
1461 1459
 		return new Api\Db\CallbackIterator(new \ArrayIterator(self::$search_cache[$cache_key]),
1462 1460
 			// process each row
1463 1461
 			function($row) use ($just_name, $replace_placeholders, $account_id)
@@ -1491,11 +1489,11 @@  discard block
 block discarded – undo
1491 1489
 	 * @param boolean $log_no_default =true true: error_log if no default found, false be silent
1492 1490
 	 * @return Account|null
1493 1491
 	 */
1494
-	static function get_default($smtp=false, $return_id=false, $log_no_default=true)
1492
+	static function get_default($smtp = false, $return_id = false, $log_no_default = true)
1495 1493
 	{
1496 1494
 		try
1497 1495
 		{
1498
-			foreach(self::search(true, 'params') as $acc_id => $params)
1496
+			foreach (self::search(true, 'params') as $acc_id => $params)
1499 1497
 			{
1500 1498
 				if ($smtp)
1501 1499
 				{
@@ -1542,7 +1540,7 @@  discard block
 block discarded – undo
1542 1540
 	 * @param boolean $smtp =false false: usable for IMAP, true: usable for SMTP
1543 1541
 	 * @return int
1544 1542
 	 */
1545
-	static function get_default_acc_id($smtp=false)
1543
+	static function get_default_acc_id($smtp = false)
1546 1544
 	{
1547 1545
 		return self::get_default($smtp, true);
1548 1546
 	}
@@ -1555,7 +1553,7 @@  discard block
 block discarded – undo
1555 1553
 	 * @param int $account_id =null account_id of user we are called for
1556 1554
 	 * @return string|array with htmlencoded angle brackets, returns account details as array if return_array is true
1557 1555
 	 */
1558
-	public static function identity_name($account, $replace_placeholders=true, $account_id=null, $return_array=false)
1556
+	public static function identity_name($account, $replace_placeholders = true, $account_id = null, $return_array = false)
1559 1557
 	{
1560 1558
 		if ($replace_placeholders)
1561 1559
 		{
@@ -1582,7 +1580,7 @@  discard block
 block discarded – undo
1582 1580
 				{
1583 1581
 					if (!isset($account['acc_imap_username']))
1584 1582
 					{
1585
-						$account += Credentials::read($account['acc_id'], null, ($account_id?array($account_id, 0):null));
1583
+						$account += Credentials::read($account['acc_id'], null, ($account_id ? array($account_id, 0) : null));
1586 1584
 					}
1587 1585
 					if (empty($account['acc_imap_username']) && $account['acc_imap_logintype'] &&
1588 1586
 						(!isset($account_id) || $account_id == $GLOBALS['egw_info']['user']['account_id']))
@@ -1601,7 +1599,7 @@  discard block
 block discarded – undo
1601 1599
 					$account['ident_email'] = $account['acc_imap_username'];
1602 1600
 				}
1603 1601
 			}
1604
-			catch(\Exception $e) {
1602
+			catch (\Exception $e) {
1605 1603
 				_egw_log_exception($e);
1606 1604
 			}
1607 1605
 		}
@@ -1617,11 +1615,11 @@  discard block
 block discarded – undo
1617 1615
 		{
1618 1616
 			$name = $account['acc_name'];
1619 1617
 		}
1620
-		if (strpos($account['ident_email'], '@') !== false || trim($account['ident_email']) !='')
1618
+		if (strpos($account['ident_email'], '@') !== false || trim($account['ident_email']) != '')
1621 1619
 		{
1622 1620
 			$name .= ' <'.$account['ident_email'].'>';
1623 1621
 		}
1624
-		elseif(strpos($account['acc_imap_username'], '@') !== false || trim($account['acc_imap_username']) !='')
1622
+		elseif (strpos($account['acc_imap_username'], '@') !== false || trim($account['acc_imap_username']) != '')
1625 1623
 		{
1626 1624
 			$name .= ' <'.$account['acc_imap_username'].'>';
1627 1625
 		}
@@ -1644,8 +1642,7 @@  discard block
 block discarded – undo
1644 1642
 	 */
1645 1643
 	public static function is_multiple($account)
1646 1644
 	{
1647
-		$is_multiple = !is_array($account['account_id']) ? $account['account_id'] <= 0 :
1648
-			(count($account['account_id']) > 1 || $account['account_id'][0] <= 0);
1645
+		$is_multiple = !is_array($account['account_id']) ? $account['account_id'] <= 0 : (count($account['account_id']) > 1 || $account['account_id'][0] <= 0);
1649 1646
 		//error_log(__METHOD__."(account_id=".array2string($account['account_id']).") returning ".array2string($is_multiple));
1650 1647
 		return $is_multiple;
1651 1648
 	}
@@ -1666,13 +1663,13 @@  discard block
 block discarded – undo
1666 1663
 	 * @param type $user
1667 1664
 	 * @return array
1668 1665
 	 */
1669
-	protected static function memberships($user=null)
1666
+	protected static function memberships($user = null)
1670 1667
 	{
1671 1668
 		if (!$user) $user = $GLOBALS['egw_info']['user']['account_id'];
1672 1669
 
1673 1670
 		$memberships = $GLOBALS['egw']->accounts->memberships($user, true);
1674 1671
 		$memberships[] = $user;
1675
-		$memberships[] = 0;	// marks accounts valid for everyone
1672
+		$memberships[] = 0; // marks accounts valid for everyone
1676 1673
 
1677 1674
 		return $memberships;
1678 1675
 	}
Please login to merge, or discard this patch.
api/src/Mail/Hooks.php 4 patches
Doc Comments   -8 removed lines patch added patch discarded remove patch
@@ -36,9 +36,6 @@  discard block
 block discarded – undo
36 36
      * Hook called before an account get deleted
37 37
      *
38 38
      * @param array $data
39
-     * @param int $data['account_id'] numerical id
40
-     * @param string $data['account_lid'] account-name
41
-     * @param int $data['new_owner'] account-id of new owner, or false if data should get deleted
42 39
      */
43 40
 	static function deleteaccount(array $data)
44 41
 	{
@@ -52,8 +49,6 @@  discard block
 block discarded – undo
52 49
      * Hook called before a group get deleted
53 50
      *
54 51
      * @param array $data
55
-     * @param int $data['account_id'] numerical id
56
-     * @param string $data['account_name'] account-name
57 52
      */
58 53
 	static function deletegroup(array $data)
59 54
 	{
@@ -64,9 +59,6 @@  discard block
 block discarded – undo
64 59
      * Hook called when an account get added or edited
65 60
      *
66 61
      * @param array $data
67
-     * @param int $data['account_id'] numerical id
68
-     * @param string $data['account_lid'] account-name
69
-     * @param string $data['account_email'] email
70 62
 	 */
71 63
 	static function addaccount(array $data)
72 64
 	{
Please login to merge, or discard this patch.
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -32,14 +32,14 @@  discard block
 block discarded – undo
32 32
 		}
33 33
 	}
34 34
 
35
-    /**
36
-     * Hook called before an account get deleted
37
-     *
38
-     * @param array $data
39
-     * @param int $data['account_id'] numerical id
40
-     * @param string $data['account_lid'] account-name
41
-     * @param int $data['new_owner'] account-id of new owner, or false if data should get deleted
42
-     */
35
+	/**
36
+	 * Hook called before an account get deleted
37
+	 *
38
+	 * @param array $data
39
+	 * @param int $data['account_id'] numerical id
40
+	 * @param string $data['account_lid'] account-name
41
+	 * @param int $data['new_owner'] account-id of new owner, or false if data should get deleted
42
+	 */
43 43
 	static function deleteaccount(array $data)
44 44
 	{
45 45
 		self::run_plugin_hooks('deleteAccount', $data);
@@ -48,25 +48,25 @@  discard block
 block discarded – undo
48 48
 		Account::delete(0, $data['account_id']);
49 49
 	}
50 50
 
51
-    /**
52
-     * Hook called before a group get deleted
53
-     *
54
-     * @param array $data
55
-     * @param int $data['account_id'] numerical id
56
-     * @param string $data['account_name'] account-name
57
-     */
51
+	/**
52
+	 * Hook called before a group get deleted
53
+	 *
54
+	 * @param array $data
55
+	 * @param int $data['account_id'] numerical id
56
+	 * @param string $data['account_name'] account-name
57
+	 */
58 58
 	static function deletegroup(array $data)
59 59
 	{
60 60
 		Account::delete(0, $data['account_id']);
61 61
 	}
62 62
 
63 63
 	/**
64
-     * Hook called when an account get added or edited
65
-     *
66
-     * @param array $data
67
-     * @param int $data['account_id'] numerical id
68
-     * @param string $data['account_lid'] account-name
69
-     * @param string $data['account_email'] email
64
+	 * Hook called when an account get added or edited
65
+	 *
66
+	 * @param array $data
67
+	 * @param int $data['account_id'] numerical id
68
+	 * @param string $data['account_lid'] account-name
69
+	 * @param string $data['account_email'] email
70 70
 	 */
71 71
 	static function addaccount(array $data)
72 72
 	{
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -82,9 +82,9 @@  discard block
 block discarded – undo
82 82
 	 */
83 83
 	protected static function run_plugin_hooks($method, array $data)
84 84
 	{
85
-		foreach(Account::search((int)$data['account_id'], 'params') as $params)
85
+		foreach (Account::search((int)$data['account_id'], 'params') as $params)
86 86
 		{
87
-			if (!Account::is_multiple($params)) continue;	// no need to waste time on personal accounts
87
+			if (!Account::is_multiple($params)) continue; // no need to waste time on personal accounts
88 88
 
89 89
 			try {
90 90
 				$account = new Account($params);
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 					$imap->$method($data);
101 101
 				}
102 102
 			}
103
-			catch(\Exception $e) {
103
+			catch (\Exception $e) {
104 104
 				_egw_log_exception($e);
105 105
 				// ignore exception, without stalling other hooks
106 106
 			}
Please login to merge, or discard this patch.
Braces   +5 added lines, -1 removed lines patch added patch discarded remove patch
@@ -84,7 +84,11 @@
 block discarded – undo
84 84
 	{
85 85
 		foreach(Account::search((int)$data['account_id'], 'params') as $params)
86 86
 		{
87
-			if (!Account::is_multiple($params)) continue;	// no need to waste time on personal accounts
87
+			if (!Account::is_multiple($params))
88
+			{
89
+				continue;
90
+			}
91
+			// no need to waste time on personal accounts
88 92
 
89 93
 			try {
90 94
 				$account = new Account($params);
Please login to merge, or discard this patch.
api/src/Mail/Imap/Iface.php 2 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -121,6 +121,7 @@
 block discarded – undo
121 121
 	 * @param bool $_adminConnection create admin connection if true
122 122
 	 * @param int $_timeout =null timeout in secs, if none given fmail pref or default of 20 is used
123 123
 	 * @throws Exception on error
124
+	 * @return void
124 125
 	 */
125 126
 	function openConnection($_adminConnection=false, $_timeout=null);
126 127
 
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -14,9 +14,9 @@  discard block
 block discarded – undo
14 14
 namespace EGroupware\Api\Mail\Imap;
15 15
 
16 16
 define('IMAP_NAMESPACE_PERSONAL', 'personal');
17
-define('IMAP_NAMESPACE_OTHERS'	, 'others');
18
-define('IMAP_NAMESPACE_SHARED'	, 'shared');
19
-define('IMAP_NAMESPACE_ALL'	, 'all');
17
+define('IMAP_NAMESPACE_OTHERS', 'others');
18
+define('IMAP_NAMESPACE_SHARED', 'shared');
19
+define('IMAP_NAMESPACE_ALL', 'all');
20 20
 
21 21
 /**
22 22
  * This class holds all information about the imap connection.
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 	 * @param string $_folderName=''
88 88
 	 * @return string utf-7 encoded (done in getMailboxName)
89 89
 	 */
90
-	function getUserMailboxString($_username, $_folderName='');
90
+	function getUserMailboxString($_username, $_folderName = '');
91 91
 
92 92
 	/**
93 93
 	 * get list of namespaces
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
 	 * @param string $_what - what to retrieve either QMAX, USED or ALL is supported
104 104
 	 * @return mixed the quota for specified user (by what) or array with all available Quota Information, or false
105 105
 	 */
106
-	function getQuotaByUser($_username, $_what='QMAX');
106
+	function getQuotaByUser($_username, $_what = 'QMAX');
107 107
 
108 108
 	/**
109 109
 	 * returns information about a user
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 	 * @param int $_timeout =null timeout in secs, if none given fmail pref or default of 20 is used
123 123
 	 * @throws Exception on error
124 124
 	 */
125
-	function openConnection($_adminConnection=false, $_timeout=null);
125
+	function openConnection($_adminConnection = false, $_timeout = null);
126 126
 
127 127
 	/**
128 128
 	 * set userdata
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
 	 * @param string $_scriptName =null
150 150
 	 * @return boolean
151 151
 	 */
152
-	public function setVacationUser($_euser, array $_vacation, $_scriptName=null);
152
+	public function setVacationUser($_euser, array $_vacation, $_scriptName = null);
153 153
 
154 154
 	/**
155 155
 	 * Get vacation message for given user
@@ -159,5 +159,5 @@  discard block
 block discarded – undo
159 159
 	 * @throws Exception on connection error or authentication failure
160 160
 	 * @return array
161 161
 	 */
162
-	public function getVacationUser($_euser, $_scriptName=null);
162
+	public function getVacationUser($_euser, $_scriptName = null);
163 163
 }
Please login to merge, or discard this patch.