GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — develop (#2307)
by
unknown
06:09
created
classes/mail/Mail.class.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -128,7 +128,7 @@
 block discarded – undo
128 128
 	/**
129 129
 	 * Constructor function
130 130
 	 *
131
-	 * @return void
131
+	 * @return string
132 132
 	 */
133 133
 	function Mail()
134 134
 	{
Please login to merge, or discard this patch.
Braces   +12 added lines, -24 removed lines patch added patch discarded remove patch
@@ -151,8 +151,7 @@  discard block
 block discarded – undo
151 151
 		if($this->isVaildMailAddress($account_name))
152 152
 		{
153 153
 			$this->Username = $account_name;
154
-		}
155
-		else
154
+		} else
156 155
 		{
157 156
 			$this->Username = $account_name . '@gmail.com';
158 157
 		}
@@ -190,8 +189,7 @@  discard block
 block discarded – undo
190 189
 			$this->IsSMTP();
191 190
 			$this->AltBody = "To view the message, please use an HTML compatible email viewer!";
192 191
 			return TRUE;
193
-		}
194
-		else
192
+		} else
195 193
 		{
196 194
 			$this->IsMail();
197 195
 			return FALSE;
@@ -246,8 +244,7 @@  discard block
 block discarded – undo
246 244
 		{
247 245
 			$this->sender_name = $name;
248 246
 			$this->sender_email = $email;
249
-		}
250
-		else
247
+		} else
251 248
 		{
252 249
 			$this->SetFrom($email, $name);
253 250
 		}
@@ -280,8 +277,7 @@  discard block
 block discarded – undo
280 277
 		{
281 278
 			$this->receiptor_name = $name;
282 279
 			$this->receiptor_email = $email;
283
-		}
284
-		else
280
+		} else
285 281
 		{
286 282
 			$this->AddAddress($email, $name);
287 283
 		}
@@ -312,8 +308,7 @@  discard block
 block discarded – undo
312 308
 		if($this->Mailer == "mail")
313 309
 		{
314 310
 			$this->title = $title;
315
-		}
316
-		else
311
+		} else
317 312
 		{
318 313
 			$this->Subject = $title;
319 314
 		}
@@ -340,8 +335,7 @@  discard block
 block discarded – undo
340 335
 		if($this->Mailer == "mail")
341 336
 		{
342 337
 			$this->bcc = $bcc;
343
-		}
344
-		else
338
+		} else
345 339
 		{
346 340
 			$this->AddBCC($bcc);
347 341
 		}
@@ -380,8 +374,7 @@  discard block
 block discarded – undo
380 374
 		if($this->Mailer == "mail")
381 375
 		{
382 376
 			$this->replyTo = $replyTo;
383
-		}
384
-		else
377
+		} else
385 378
 		{
386 379
 			$this->AddReplyTo($replyTo);
387 380
 		}
@@ -399,8 +392,7 @@  discard block
 block discarded – undo
399 392
 		if($this->Mailer == "mail")
400 393
 		{
401 394
 			$this->content = $content;
402
-		}
403
-		else
395
+		} else
404 396
 		{
405 397
 			$this->MsgHTML($content);
406 398
 		}
@@ -486,8 +478,7 @@  discard block
 block discarded – undo
486 478
 				$this->body = implode("", $res);
487 479
 				$this->body .= "--" . $boundary . "--";
488 480
 			}
489
-		}
490
-		else
481
+		} else
491 482
 		{
492 483
 			if(count($this->attachments) > 0)
493 484
 			{
@@ -578,8 +569,7 @@  discard block
 block discarded – undo
578 569
 				return mail($this->getReceiptor(), $this->getTitle(), $this->body, $headers, $this->additional_params);
579 570
 			}
580 571
 			return mail($this->getReceiptor(), $this->getTitle(), $this->body, $headers);
581
-		}
582
-		else
572
+		} else
583 573
 		{
584 574
 			$this->procAttachments();
585 575
 			return parent::Send();
@@ -604,8 +594,7 @@  discard block
 block discarded – undo
604 594
 			if(checkdnsrr($host, "MX") || checkdnsrr($host, "A"))
605 595
 			{
606 596
 				return TRUE;
607
-			}
608
-			else
597
+			} else
609 598
 			{
610 599
 				return FALSE;
611 600
 			}
@@ -624,8 +613,7 @@  discard block
 block discarded – undo
624 613
 		if(preg_match("/([a-z0-9\_\-\.]+)@([a-z0-9\_\-\.]+)/i", $email_address))
625 614
 		{
626 615
 			return $email_address;
627
-		}
628
-		else
616
+		} else
629 617
 		{
630 618
 			return '';
631 619
 		}
Please login to merge, or discard this patch.
Spacing   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 /* Copyright (C) NAVER <http://www.navercorp.com> */
3 3
 
4
-require_once _XE_PATH_ . "libs/phpmailer/phpmailer.php";
4
+require_once _XE_PATH_."libs/phpmailer/phpmailer.php";
5 5
 
6 6
 /**
7 7
  * Mailing class for XpressEngine
@@ -148,13 +148,13 @@  discard block
 block discarded – undo
148 148
 		$this->SMTPSecure = "tls";
149 149
 		$this->Host = 'smtp.gmail.com';
150 150
 		$this->Port = '587';
151
-		if($this->isVaildMailAddress($account_name))
151
+		if ($this->isVaildMailAddress($account_name))
152 152
 		{
153 153
 			$this->Username = $account_name;
154 154
 		}
155 155
 		else
156 156
 		{
157
-			$this->Username = $account_name . '@gmail.com';
157
+			$this->Username = $account_name.'@gmail.com';
158 158
 		}
159 159
 		$this->Password = $account_passwd;
160 160
 		$this->IsSMTP();
@@ -180,12 +180,12 @@  discard block
 block discarded – undo
180 180
 		$this->Password = $pass;
181 181
 		$this->Port = $port;
182 182
 
183
-		if($secure == 'ssl' || $secure == 'tls')
183
+		if ($secure == 'ssl' || $secure == 'tls')
184 184
 		{
185 185
 			$this->SMTPSecure = $secure;
186 186
 		}
187 187
 
188
-		if(($this->SMTPAuth !== NULL && $this->Host !== NULL && $this->Username !== NULL && $this->Password !== NULL) || ($this->SMTPAuth === NULL && $this->Host !== NULL))
188
+		if (($this->SMTPAuth !== NULL && $this->Host !== NULL && $this->Username !== NULL && $this->Password !== NULL) || ($this->SMTPAuth === NULL && $this->Host !== NULL))
189 189
 		{
190 190
 			$this->IsSMTP();
191 191
 			$this->AltBody = "To view the message, please use an HTML compatible email viewer!";
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
 	 */
243 243
 	function setSender($name, $email)
244 244
 	{
245
-		if($this->Mailer == "mail")
245
+		if ($this->Mailer == "mail")
246 246
 		{
247 247
 			$this->sender_name = $name;
248 248
 			$this->sender_email = $email;
@@ -260,9 +260,9 @@  discard block
 block discarded – undo
260 260
 	 */
261 261
 	function getSender()
262 262
 	{
263
-		if(!stristr(PHP_OS, 'win') && $this->sender_name)
263
+		if (!stristr(PHP_OS, 'win') && $this->sender_name)
264 264
 		{
265
-			return sprintf("%s <%s>", '=?utf-8?b?' . base64_encode($this->sender_name) . '?=', $this->sender_email);
265
+			return sprintf("%s <%s>", '=?utf-8?b?'.base64_encode($this->sender_name).'?=', $this->sender_email);
266 266
 		}
267 267
 		return $this->sender_email;
268 268
 	}
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
 	 */
277 277
 	function setReceiptor($name, $email)
278 278
 	{
279
-		if($this->Mailer == "mail")
279
+		if ($this->Mailer == "mail")
280 280
 		{
281 281
 			$this->receiptor_name = $name;
282 282
 			$this->receiptor_email = $email;
@@ -294,9 +294,9 @@  discard block
 block discarded – undo
294 294
 	 */
295 295
 	function getReceiptor()
296 296
 	{
297
-		if(!stristr(PHP_OS, 'win') && $this->receiptor_name && $this->receiptor_name != $this->receiptor_email)
297
+		if (!stristr(PHP_OS, 'win') && $this->receiptor_name && $this->receiptor_name != $this->receiptor_email)
298 298
 		{
299
-			return sprintf("%s <%s>", '=?utf-8?b?' . base64_encode($this->receiptor_name) . '?=', $this->receiptor_email);
299
+			return sprintf("%s <%s>", '=?utf-8?b?'.base64_encode($this->receiptor_name).'?=', $this->receiptor_email);
300 300
 		}
301 301
 		return $this->receiptor_email;
302 302
 	}
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
 	 */
310 310
 	function setTitle($title)
311 311
 	{
312
-		if($this->Mailer == "mail")
312
+		if ($this->Mailer == "mail")
313 313
 		{
314 314
 			$this->title = $title;
315 315
 		}
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
 	 */
327 327
 	function getTitle()
328 328
 	{
329
-		return '=?utf-8?b?' . base64_encode($this->title) . '?=';
329
+		return '=?utf-8?b?'.base64_encode($this->title).'?=';
330 330
 	}
331 331
 
332 332
 	/**
@@ -337,7 +337,7 @@  discard block
 block discarded – undo
337 337
 	 */
338 338
 	function setBCC($bcc)
339 339
 	{
340
-		if($this->Mailer == "mail")
340
+		if ($this->Mailer == "mail")
341 341
 		{
342 342
 			$this->bcc = $bcc;
343 343
 		}
@@ -377,7 +377,7 @@  discard block
 block discarded – undo
377 377
 	 */
378 378
 	function setReplyTo($replyTo)
379 379
 	{
380
-		if($this->Mailer == "mail")
380
+		if ($this->Mailer == "mail")
381 381
 		{
382 382
 			$this->replyTo = $replyTo;
383 383
 		}
@@ -396,7 +396,7 @@  discard block
 block discarded – undo
396 396
 	function setContent($content)
397 397
 	{
398 398
 		$content = preg_replace_callback('/<img([^>]+)>/i', array($this, 'replaceResourceRealPath'), $content);
399
-		if($this->Mailer == "mail")
399
+		if ($this->Mailer == "mail")
400 400
 		{
401 401
 			$this->content = $content;
402 402
 		}
@@ -415,7 +415,7 @@  discard block
 block discarded – undo
415 415
 	 */
416 416
 	function replaceResourceRealPath($matches)
417 417
 	{
418
-		return preg_replace('/src=(["\']?)files/i', 'src=$1' . Context::getRequestUri() . 'files', $matches[0]);
418
+		return preg_replace('/src=(["\']?)files/i', 'src=$1'.Context::getRequestUri().'files', $matches[0]);
419 419
 	}
420 420
 
421 421
 	/**
@@ -456,42 +456,42 @@  discard block
 block discarded – undo
456 456
 	 */
457 457
 	function procAttachments()
458 458
 	{
459
-		if($this->Mailer == "mail")
459
+		if ($this->Mailer == "mail")
460 460
 		{
461
-			if(count($this->attachments) > 0)
461
+			if (count($this->attachments) > 0)
462 462
 			{
463
-				$this->body = $this->header . $this->body;
464
-				$boundary = '----==' . uniqid(rand(), TRUE);
465
-				$this->header = "Content-Type: multipart/mixed;" . $this->eol . "\tboundary=\"" . $boundary . "\"" . $this->eol . $this->eol;
466
-				$this->body = "--" . $boundary . $this->eol . $this->body . $this->eol . $this->eol;
463
+				$this->body = $this->header.$this->body;
464
+				$boundary = '----=='.uniqid(rand(), TRUE);
465
+				$this->header = "Content-Type: multipart/mixed;".$this->eol."\tboundary=\"".$boundary."\"".$this->eol.$this->eol;
466
+				$this->body = "--".$boundary.$this->eol.$this->body.$this->eol.$this->eol;
467 467
 				$res = array();
468 468
 				$res[] = $this->body;
469
-				foreach($this->attachments as $filename => $attachment)
469
+				foreach ($this->attachments as $filename => $attachment)
470 470
 				{
471 471
 					$type = $this->returnMIMEType($filename);
472 472
 					$file_handler = new FileHandler();
473 473
 					$file_str = $file_handler->readFile($attachment);
474 474
 					$chunks = chunk_split(base64_encode($file_str));
475 475
 					$tempBody = sprintf(
476
-							"--" . $boundary . $this->eol .
477
-							"Content-Type: %s;" . $this->eol .
478
-							"\tname=\"%s\"" . $this->eol .
479
-							"Content-Transfer-Encoding: base64" . $this->eol .
480
-							"Content-Description: %s" . $this->eol .
481
-							"Content-Disposition: attachment;" . $this->eol .
482
-							"\tfilename=\"%s\"" . $this->eol . $this->eol .
483
-							"%s" . $this->eol . $this->eol, $type, $filename, $filename, $filename, $chunks);
476
+							"--".$boundary.$this->eol.
477
+							"Content-Type: %s;".$this->eol.
478
+							"\tname=\"%s\"".$this->eol.
479
+							"Content-Transfer-Encoding: base64".$this->eol.
480
+							"Content-Description: %s".$this->eol.
481
+							"Content-Disposition: attachment;".$this->eol.
482
+							"\tfilename=\"%s\"".$this->eol.$this->eol.
483
+							"%s".$this->eol.$this->eol, $type, $filename, $filename, $filename, $chunks);
484 484
 					$res[] = $tempBody;
485 485
 				}
486 486
 				$this->body = implode("", $res);
487
-				$this->body .= "--" . $boundary . "--";
487
+				$this->body .= "--".$boundary."--";
488 488
 			}
489 489
 		}
490 490
 		else
491 491
 		{
492
-			if(count($this->attachments) > 0)
492
+			if (count($this->attachments) > 0)
493 493
 			{
494
-				foreach($this->attachments as $filename => $attachment)
494
+				foreach ($this->attachments as $filename => $attachment)
495 495
 				{
496 496
 					parent::AddAttachment($attachment);
497 497
 				}
@@ -506,33 +506,33 @@  discard block
 block discarded – undo
506 506
 	 */
507 507
 	function procCidAttachments()
508 508
 	{
509
-		if(count($this->cidAttachments) > 0)
509
+		if (count($this->cidAttachments) > 0)
510 510
 		{
511
-			$this->body = $this->header . $this->body;
512
-			$boundary = '----==' . uniqid(rand(), TRUE);
513
-			$this->header = "Content-Type: multipart/relative;" . $this->eol . "\ttype=\"multipart/alternative\";" . $this->eol . "\tboundary=\"" . $boundary . "\"" . $this->eol . $this->eol;
514
-			$this->body = "--" . $boundary . $this->eol . $this->body . $this->eol . $this->eol;
511
+			$this->body = $this->header.$this->body;
512
+			$boundary = '----=='.uniqid(rand(), TRUE);
513
+			$this->header = "Content-Type: multipart/relative;".$this->eol."\ttype=\"multipart/alternative\";".$this->eol."\tboundary=\"".$boundary."\"".$this->eol.$this->eol;
514
+			$this->body = "--".$boundary.$this->eol.$this->body.$this->eol.$this->eol;
515 515
 			$res = array();
516 516
 			$res[] = $this->body;
517
-			foreach($this->cidAttachments as $cid => $attachment)
517
+			foreach ($this->cidAttachments as $cid => $attachment)
518 518
 			{
519 519
 				$filename = basename($attachment);
520 520
 				$type = $this->returnMIMEType(FileHandler::getRealPath($attachment));
521 521
 				$file_str = FileHandler::readFile($attachment);
522 522
 				$chunks = chunk_split(base64_encode($file_str));
523 523
 				$tempBody = sprintf(
524
-						"--" . $boundary . $this->eol .
525
-						"Content-Type: %s;" . $this->eol .
526
-						"\tname=\"%s\"" . $this->eol .
527
-						"Content-Transfer-Encoding: base64" . $this->eol .
528
-						"Content-ID: <%s>" . $this->eol .
529
-						"Content-Description: %s" . $this->eol .
530
-						"Content-Location: %s" . $this->eol . $this->eol .
531
-						"%s" . $this->eol . $this->eol, $type, $filename, $cid, $filename, $filename, $chunks);
524
+						"--".$boundary.$this->eol.
525
+						"Content-Type: %s;".$this->eol.
526
+						"\tname=\"%s\"".$this->eol.
527
+						"Content-Transfer-Encoding: base64".$this->eol.
528
+						"Content-ID: <%s>".$this->eol.
529
+						"Content-Description: %s".$this->eol.
530
+						"Content-Location: %s".$this->eol.$this->eol.
531
+						"%s".$this->eol.$this->eol, $type, $filename, $cid, $filename, $filename, $chunks);
532 532
 				$res[] = $tempBody;
533 533
 			}
534 534
 			$this->body = implode("", $res);
535
-			$this->body .= "--" . $boundary . "--";
535
+			$this->body .= "--".$boundary."--";
536 536
 		}
537 537
 	}
538 538
 
@@ -543,37 +543,37 @@  discard block
 block discarded – undo
543 543
 	 */
544 544
 	function send()
545 545
 	{
546
-		if($this->Mailer == "mail")
546
+		if ($this->Mailer == "mail")
547 547
 		{
548
-			$boundary = '----==' . uniqid(rand(), TRUE);
548
+			$boundary = '----=='.uniqid(rand(), TRUE);
549 549
 			$this->eol = $GLOBALS['_qmail_compatibility'] == "Y" ? "\n" : "\r\n";
550
-			$this->header = "Content-Type: multipart/alternative;" . $this->eol . "\tboundary=\"" . $boundary . "\"" . $this->eol . $this->eol;
550
+			$this->header = "Content-Type: multipart/alternative;".$this->eol."\tboundary=\"".$boundary."\"".$this->eol.$this->eol;
551 551
 			$this->body = sprintf(
552
-					"--%s" . $this->eol .
553
-					"Content-Type: text/plain; charset=utf-8; format=flowed" . $this->eol .
554
-					"Content-Transfer-Encoding: base64" . $this->eol .
555
-					"Content-Disposition: inline" . $this->eol . $this->eol .
556
-					"%s" .
557
-					"--%s" . $this->eol .
558
-					"Content-Type: text/html; charset=utf-8" . $this->eol .
559
-					"Content-Transfer-Encoding: base64" . $this->eol .
560
-					"Content-Disposition: inline" . $this->eol . $this->eol .
561
-					"%s" .
562
-					"--%s--" .
552
+					"--%s".$this->eol.
553
+					"Content-Type: text/plain; charset=utf-8; format=flowed".$this->eol.
554
+					"Content-Transfer-Encoding: base64".$this->eol.
555
+					"Content-Disposition: inline".$this->eol.$this->eol.
556
+					"%s".
557
+					"--%s".$this->eol.
558
+					"Content-Type: text/html; charset=utf-8".$this->eol.
559
+					"Content-Transfer-Encoding: base64".$this->eol.
560
+					"Content-Disposition: inline".$this->eol.$this->eol.
561
+					"%s".
562
+					"--%s--".
563 563
 					"", $boundary, $this->getPlainContent(), $boundary, $this->getHTMLContent(), $boundary
564 564
 			);
565 565
 			$this->procCidAttachments();
566 566
 			$this->procAttachments();
567 567
 			$headers = sprintf(
568
-					"From: %s" . $this->eol .
569
-					"%s" .
570
-					"%s" .
571
-					"%s" .
572
-					"%s" .
573
-					"MIME-Version: 1.0" . $this->eol . "", $this->getSender(), $this->messageId ? ("Message-ID: <" . $this->messageId . ">" . $this->eol) : "", $this->replyTo ? ("Reply-To: <" . $this->replyTo . ">" . $this->eol) : "", $this->bcc ? ("Bcc: " . $this->bcc . $this->eol) : "", $this->references ? ("References: <" . $this->references . ">" . $this->eol . "In-Reply-To: <" . $this->references . ">" . $this->eol) : ""
568
+					"From: %s".$this->eol.
569
+					"%s".
570
+					"%s".
571
+					"%s".
572
+					"%s".
573
+					"MIME-Version: 1.0".$this->eol."", $this->getSender(), $this->messageId ? ("Message-ID: <".$this->messageId.">".$this->eol) : "", $this->replyTo ? ("Reply-To: <".$this->replyTo.">".$this->eol) : "", $this->bcc ? ("Bcc: ".$this->bcc.$this->eol) : "", $this->references ? ("References: <".$this->references.">".$this->eol."In-Reply-To: <".$this->references.">".$this->eol) : ""
574 574
 			);
575 575
 			$headers .= $this->header;
576
-			if($this->additional_params)
576
+			if ($this->additional_params)
577 577
 			{
578 578
 				return mail($this->getReceiptor(), $this->getTitle(), $this->body, $headers, $this->additional_params);
579 579
 			}
@@ -594,14 +594,14 @@  discard block
 block discarded – undo
594 594
 	 */
595 595
 	function checkMailMX($email_address)
596 596
 	{
597
-		if(!Mail::isVaildMailAddress($email_address))
597
+		if (!Mail::isVaildMailAddress($email_address))
598 598
 		{
599 599
 			return FALSE;
600 600
 		}
601 601
 		list($user, $host) = explode("@", $email_address);
602
-		if(function_exists('checkdnsrr'))
602
+		if (function_exists('checkdnsrr'))
603 603
 		{
604
-			if(checkdnsrr($host, "MX") || checkdnsrr($host, "A"))
604
+			if (checkdnsrr($host, "MX") || checkdnsrr($host, "A"))
605 605
 			{
606 606
 				return TRUE;
607 607
 			}
@@ -621,7 +621,7 @@  discard block
 block discarded – undo
621 621
 	 */
622 622
 	function isVaildMailAddress($email_address)
623 623
 	{
624
-		if(preg_match("/([a-z0-9\_\-\.]+)@([a-z0-9\_\-\.]+)/i", $email_address))
624
+		if (preg_match("/([a-z0-9\_\-\.]+)@([a-z0-9\_\-\.]+)/i", $email_address))
625 625
 		{
626 626
 			return $email_address;
627 627
 		}
@@ -640,7 +640,7 @@  discard block
 block discarded – undo
640 640
 	function returnMIMEType($filename)
641 641
 	{
642 642
 		preg_match("|\.([a-z0-9]{2,4})$|i", $filename, $fileSuffix);
643
-		switch(strtolower($fileSuffix[1]))
643
+		switch (strtolower($fileSuffix[1]))
644 644
 		{
645 645
 			case "js" :
646 646
 				return "application/x-javascript";
@@ -654,7 +654,7 @@  discard block
 block discarded – undo
654 654
 			case "gif" :
655 655
 			case "bmp" :
656 656
 			case "tiff" :
657
-				return "image/" . strtolower($fileSuffix[1]);
657
+				return "image/".strtolower($fileSuffix[1]);
658 658
 			case "css" :
659 659
 				return "text/css";
660 660
 			case "xml" :
@@ -708,11 +708,11 @@  discard block
 block discarded – undo
708 708
 			case "swf" :
709 709
 				return "application/x-shockwave-flash";
710 710
 			default :
711
-				if(function_exists("mime_content_type"))
711
+				if (function_exists("mime_content_type"))
712 712
 				{
713 713
 					$fileSuffix = mime_content_type($filename);
714 714
 				}
715
-				return "unknown/" . trim($fileSuffix[0], ".");
715
+				return "unknown/".trim($fileSuffix[0], ".");
716 716
 		}
717 717
 	}
718 718
 
Please login to merge, or discard this patch.
classes/module/ModuleHandler.class.php 4 patches
Doc Comments   +5 added lines, -1 removed lines patch added patch discarded remove patch
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
 
113 113
 	/**
114 114
 	 * Initialization. It finds the target module based on module, mid, document_srl, and prepares to execute an action
115
-	 * @return boolean true: OK, false: redirected
115
+	 * @return string|boolean true: OK, false: redirected
116 116
 	 * */
117 117
 	function init()
118 118
 	{
@@ -1128,6 +1128,10 @@  discard block
 block discarded – undo
1128 1128
 		return $GLOBALS['_loaded_module'][$module][$type][$kind];
1129 1129
 	}
1130 1130
 
1131
+	/**
1132
+	 * @param string $type
1133
+	 * @param string $kind
1134
+	 */
1131 1135
 	function _getModuleFilePath($module, $type, $kind, &$classPath, &$highClassFile, &$classFile, &$instanceName)
1132 1136
 	{
1133 1137
 		$classPath = ModuleHandler::getModulePath($module);
Please login to merge, or discard this patch.
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -59,10 +59,10 @@
 block discarded – undo
59 59
 		$this->mid = $mid ? $mid : Context::get('mid');
60 60
 		$this->document_srl = $document_srl ? (int) $document_srl : (int) Context::get('document_srl');
61 61
 		$this->module_srl = $module_srl ? (int) $module_srl : (int) Context::get('module_srl');
62
-        if($entry = Context::get('entry'))
63
-        {
64
-            $this->entry = Context::convertEncodingStr($entry);
65
-        }
62
+		if($entry = Context::get('entry'))
63
+		{
64
+			$this->entry = Context::convertEncodingStr($entry);
65
+		}
66 66
 
67 67
 		// Validate variables to prevent XSS
68 68
 		$isInvalid = NULL;
Please login to merge, or discard this patch.
Braces   +30 added lines, -45 removed lines patch added patch discarded remove patch
@@ -115,7 +115,9 @@  discard block
 block discarded – undo
115 115
 		$called_position = 'before_module_init';
116 116
 		$oAddonController = getController('addon');
117 117
 		$addon_file = $oAddonController->getCacheFilePath(Mobile::isFromMobilePhone() ? 'mobile' : 'pc');
118
-		if(file_exists($addon_file)) include($addon_file);
118
+		if(file_exists($addon_file)) {
119
+			include($addon_file);
120
+		}
119 121
 	}
120 122
 
121 123
 	public static function xeErrorLog($errnumber, $errormassage, $errorfile, $errorline, $errorcontext)
@@ -257,8 +259,7 @@  discard block
 block discarded – undo
257 259
 			if(!$module_info)
258 260
 			{
259 261
 				unset($this->document_srl);
260
-			}
261
-			else
262
+			} else
262 263
 			{
263 264
 				// If it exists, compare mid based on the module information
264 265
 				// if mids are not matching, set it as the document's mid
@@ -270,8 +271,7 @@  discard block
 block discarded – undo
270 271
 						$this->mid = $module_info->mid;
271 272
 						header('location:' . getNotEncodedSiteUrl($site_module_info->domain, 'mid', $this->mid, 'document_srl', $this->document_srl));
272 273
 						return FALSE;
273
-					}
274
-					else
274
+					} else
275 275
 					{
276 276
 						$this->mid = $module_info->mid;
277 277
 						Context::set('mid', $this->mid);
@@ -322,15 +322,13 @@  discard block
 block discarded – undo
322 322
 				$site_info = $oModuleModel->getSiteInfo($module_info->site_srl);
323 323
 				$redirect_url = getNotEncodedSiteUrl($site_info->domain, 'mid', Context::get('mid'), 'document_srl', Context::get('document_srl'), 'module_srl', Context::get('module_srl'), 'entry', Context::get('entry'));
324 324
 				// If it's called from a virtual site, though it's not a module of the virtual site
325
-			}
326
-			else
325
+			} else
327 326
 			{
328 327
 				$db_info = Context::getDBInfo();
329 328
 				if(!$db_info->default_url)
330 329
 				{
331 330
 					return Context::getLang('msg_default_url_is_not_defined');
332
-				}
333
-				else
331
+				} else
334 332
 				{
335 333
 					$redirect_url = getNotEncodedSiteUrl($db_info->default_url, 'mid', Context::get('mid'), 'document_srl', Context::get('document_srl'), 'module_srl', Context::get('module_srl'), 'entry', Context::get('entry'));
336 334
 				}
@@ -355,8 +353,7 @@  discard block
 block discarded – undo
355 353
 			{
356 354
 				$oLayoutAdminModel = getAdminModel('layout');
357 355
 				$layoutSrl = $oLayoutAdminModel->getSiteDefaultLayout($viewType, $module_info->site_srl);
358
-			}
359
-			else
356
+			} else
360 357
 			{
361 358
 				$layoutSrl = $module_info->{$targetSrl};
362 359
 			}
@@ -490,8 +487,7 @@  discard block
 block discarded – undo
490 487
 			if(!$allowedMethod)
491 488
 			{
492 489
 				$allowedMethodList[0] = 'POST';
493
-			}
494
-			else
490
+			} else
495 491
 			{
496 492
 				$allowedMethodList = explode('|', strtoupper($allowedMethod));
497 493
 			}
@@ -551,8 +547,7 @@  discard block
 block discarded – undo
551 547
 				Mobile::setMobile(FALSE);
552 548
 				$oModule = $this->getModuleInstance($this->module, $type, $kind);
553 549
 			}
554
-		}
555
-		else
550
+		} else
556 551
 		{
557 552
 			// create a module instance
558 553
 			$oModule = $this->getModuleInstance($this->module, $type, $kind);
@@ -606,8 +601,7 @@  discard block
 block discarded – undo
606 601
 					$forward->ruleset = $xml_info->action->{$this->act}->ruleset;
607 602
 					$forward->meta_noindex = $xml_info->action->{$this->act}->meta_noindex;
608 603
 					$forward->act = $this->act;
609
-				}
610
-				else
604
+				} else
611 605
 				{
612 606
 					$this->error = 'msg_invalid_request';
613 607
 					$oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode);
@@ -659,8 +653,7 @@  discard block
 block discarded – undo
659 653
 					if(!$allowedMethod)
660 654
 					{
661 655
 						$allowedMethodList[0] = 'POST';
662
-					}
663
-					else
656
+					} else
664 657
 					{
665 658
 						$allowedMethodList = explode('|', strtoupper($allowedMethod));
666 659
 					}
@@ -688,8 +681,7 @@  discard block
 block discarded – undo
688 681
 						Mobile::setMobile(FALSE);
689 682
 						$oModule = $this->getModuleInstance($forward->module, $type, $kind);
690 683
 					}
691
-				}
692
-				else
684
+				} else
693 685
 				{
694 686
 					$oModule = $this->getModuleInstance($forward->module, $type, $kind);
695 687
 				}
@@ -719,8 +711,7 @@  discard block
 block discarded – undo
719 711
 							$oModule->setLayoutPath("./modules/admin/tpl");
720 712
 							$oModule->setLayoutFile("layout.html");
721 713
 						}
722
-					}
723
-					else
714
+					} else
724 715
 					{
725 716
 						$this->_setInputErrorToContext();
726 717
 
@@ -744,8 +735,7 @@  discard block
 block discarded – undo
744 735
 						$oMessageObject->setMessage($this->error);
745 736
 						$oMessageObject->dispMessage();
746 737
 						return $oMessageObject;
747
-					}
748
-					else
738
+					} else
749 739
 					{
750 740
 						if(!$grant->is_admin && $this->module != $this->orig_module->module && $xml_info->permission->{$this->act} != 'manager')
751 741
 						{
@@ -759,12 +749,10 @@  discard block
 block discarded – undo
759 749
 						}
760 750
 					}
761 751
 				}
762
-			}
763
-			else if($xml_info->default_index_act && method_exists($oModule, $xml_info->default_index_act))
752
+			} else if($xml_info->default_index_act && method_exists($oModule, $xml_info->default_index_act))
764 753
 			{
765 754
 				$this->act = $xml_info->default_index_act;
766
-			}
767
-			else
755
+			} else
768 756
 			{
769 757
 				$this->error = 'msg_invalid_request';
770 758
 				$oModule->setError(-1);
@@ -866,7 +854,9 @@  discard block
 block discarded – undo
866 854
 			$message = $oModule->getMessage();
867 855
 			$messageType = $oModule->getMessageType();
868 856
 			$redirectUrl = $oModule->getRedirectUrl();
869
-			if($messageType == 'error') debugPrint($message, 'ERROR');
857
+			if($messageType == 'error') {
858
+				debugPrint($message, 'ERROR');
859
+			}
870 860
 
871 861
 			if(!$procResult)
872 862
 			{
@@ -876,8 +866,7 @@  discard block
 block discarded – undo
876 866
 					$redirectUrl = Context::get('error_return_url');
877 867
 				}
878 868
 				$this->_setInputValueToSession();
879
-			}
880
-			else
869
+			} else
881 870
 			{
882 871
 
883 872
 			}
@@ -1025,8 +1014,7 @@  discard block
 block discarded – undo
1025 1014
 					$oModule->setTemplatePath($oMessageObject->getTemplatePath());
1026 1015
 					$oModule->setTemplateFile($oMessageObject->getTemplateFile());
1027 1016
 					// Otherwise, set message instance as the target module
1028
-				}
1029
-				else
1017
+				} else
1030 1018
 				{
1031 1019
 					$oModule = $oMessageObject;
1032 1020
 				}
@@ -1038,8 +1026,7 @@  discard block
 block discarded – undo
1038 1026
 			if(Mobile::isFromMobilePhone())
1039 1027
 			{
1040 1028
 				$layout_srl = $oModule->module_info->mlayout_srl;
1041
-			}
1042
-			else
1029
+			} else
1043 1030
 			{
1044 1031
 				$layout_srl = $oModule->module_info->layout_srl;
1045 1032
 			}
@@ -1098,8 +1085,7 @@  discard block
 block discarded – undo
1098 1085
 									$menu->xml_file = str_replace('.xml.php', $homeMenuSrl . '.xml.php', $menu->xml_file);
1099 1086
 									$menu->php_file = str_replace('.php', $homeMenuSrl . '.php', $menu->php_file);
1100 1087
 									$layout_info->menu->{$menu_id}->menu_srl = $homeMenuSrl;
1101
-								}
1102
-								else
1088
+								} else
1103 1089
 								{
1104 1090
 									$menu->xml_file = str_replace($menu->menu_srl, $homeMenuSrl, $menu->xml_file);
1105 1091
 									$menu->php_file = str_replace($menu->menu_srl, $homeMenuSrl, $menu->php_file);
@@ -1136,8 +1122,7 @@  discard block
 block discarded – undo
1136 1122
 				if($kind == 'admin')
1137 1123
 				{
1138 1124
 					$oModule->setLayoutFile('popup_layout');
1139
-				}
1140
-				else
1125
+				} else
1141 1126
 				{
1142 1127
 					$oModule->setLayoutPath('common/tpl');
1143 1128
 					$oModule->setLayoutFile('default_layout');
@@ -1271,13 +1256,11 @@  discard block
 block discarded – undo
1271 1256
 		{
1272 1257
 			$instanceName = '%s';
1273 1258
 			$classFile = '%s%s.%s.php';
1274
-		}
1275
-		elseif($kind == 'admin' && array_search($type, $types) < 3)
1259
+		} elseif($kind == 'admin' && array_search($type, $types) < 3)
1276 1260
 		{
1277 1261
 			$instanceName = '%sAdmin%s';
1278 1262
 			$classFile = '%s%s.admin.%s.php';
1279
-		}
1280
-		else
1263
+		} else
1281 1264
 		{
1282 1265
 			$instanceName = '%s%s';
1283 1266
 			$classFile = '%s%s.%s.php';
@@ -1340,7 +1323,9 @@  discard block
 block discarded – undo
1340 1323
 			$slowlog->caller = $trigger_name . '.' . $called_position;
1341 1324
 			$slowlog->called = $module . '.' . $called_method;
1342 1325
 			$slowlog->called_extension = $module;
1343
-			if($trigger_name != 'XE.writeSlowlog') writeSlowlog('trigger', $elapsed_time_trigger, $slowlog);
1326
+			if($trigger_name != 'XE.writeSlowlog') {
1327
+				writeSlowlog('trigger', $elapsed_time_trigger, $slowlog);
1328
+			}
1344 1329
 
1345 1330
 			if(is_object($output) && method_exists($output, 'toBool') && !$output->toBool())
1346 1331
 			{
Please login to merge, or discard this patch.
Spacing   +180 added lines, -180 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 	function ModuleHandler($module = '', $act = '', $mid = '', $document_srl = '', $module_srl = '')
36 36
 	{
37 37
 		// If XE has not installed yet, set module as install
38
-		if(!Context::isInstalled())
38
+		if (!Context::isInstalled())
39 39
 		{
40 40
 			$this->module = 'install';
41 41
 			$this->act = Context::get('act');
@@ -43,12 +43,12 @@  discard block
 block discarded – undo
43 43
 		}
44 44
 
45 45
 		$oContext = Context::getInstance();
46
-		if($oContext->isSuccessInit == FALSE)
46
+		if ($oContext->isSuccessInit == FALSE)
47 47
 		{
48 48
 			$logged_info = Context::get('logged_info');
49 49
 			$dbInfo = Context::getDBInfo();
50 50
 			// @see https://github.com/xpressengine/xe-core/issues/2304
51
-			if($dbInfo->safeguard === 'Y' || $logged_info->is_admin != "Y")
51
+			if ($dbInfo->safeguard === 'Y' || $logged_info->is_admin != "Y")
52 52
 			{
53 53
 				$this->error = 'msg_invalid_request';
54 54
 				return;
@@ -61,26 +61,26 @@  discard block
 block discarded – undo
61 61
 		$this->mid = $mid ? $mid : Context::get('mid');
62 62
 		$this->document_srl = $document_srl ? (int) $document_srl : (int) Context::get('document_srl');
63 63
 		$this->module_srl = $module_srl ? (int) $module_srl : (int) Context::get('module_srl');
64
-        if($entry = Context::get('entry'))
64
+        if ($entry = Context::get('entry'))
65 65
         {
66 66
             $this->entry = Context::convertEncodingStr($entry);
67 67
         }
68 68
 
69 69
 		// Validate variables to prevent XSS
70 70
 		$isInvalid = NULL;
71
-		if($this->module && !preg_match("/^([a-z0-9\_\-]+)$/i", $this->module))
71
+		if ($this->module && !preg_match("/^([a-z0-9\_\-]+)$/i", $this->module))
72 72
 		{
73 73
 			$isInvalid = TRUE;
74 74
 		}
75
-		if($this->mid && !preg_match("/^([a-z0-9\_\-]+)$/i", $this->mid))
75
+		if ($this->mid && !preg_match("/^([a-z0-9\_\-]+)$/i", $this->mid))
76 76
 		{
77 77
 			$isInvalid = TRUE;
78 78
 		}
79
-		if($this->act && !preg_match("/^([a-z0-9\_\-]+)$/i", $this->act))
79
+		if ($this->act && !preg_match("/^([a-z0-9\_\-]+)$/i", $this->act))
80 80
 		{
81 81
 			$isInvalid = TRUE;
82 82
 		}
83
-		if($isInvalid)
83
+		if ($isInvalid)
84 84
 		{
85 85
 			htmlHeader();
86 86
 			echo Context::getLang("msg_invalid_request");
@@ -89,14 +89,14 @@  discard block
 block discarded – undo
89 89
 			exit;
90 90
 		}
91 91
 
92
-		if(isset($this->act) && (strlen($this->act) >= 4 && substr_compare($this->act, 'disp', 0, 4) === 0))
92
+		if (isset($this->act) && (strlen($this->act) >= 4 && substr_compare($this->act, 'disp', 0, 4) === 0))
93 93
 		{
94
-			if(Context::get('_use_ssl') == 'optional' && Context::isExistsSSLAction($this->act) && $_SERVER['HTTPS'] != 'on')
94
+			if (Context::get('_use_ssl') == 'optional' && Context::isExistsSSLAction($this->act) && $_SERVER['HTTPS'] != 'on')
95 95
 			{
96
-				if(Context::get('_https_port')!=null) {
97
-					header('location:https://' . $_SERVER['HTTP_HOST'] . ':' . Context::get('_https_port') . $_SERVER['REQUEST_URI']);
96
+				if (Context::get('_https_port') != null) {
97
+					header('location:https://'.$_SERVER['HTTP_HOST'].':'.Context::get('_https_port').$_SERVER['REQUEST_URI']);
98 98
 				} else {
99
-					header('location:https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
99
+					header('location:https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
100 100
 				}
101 101
 				return;
102 102
 			}
@@ -104,9 +104,9 @@  discard block
 block discarded – undo
104 104
 
105 105
 		// call a trigger before moduleHandler init
106 106
 		ModuleHandler::triggerCall('moduleHandler.init', 'before', $this);
107
-		if(__ERROR_LOG__ == 1 && __DEBUG_OUTPUT__ == 0)
107
+		if (__ERROR_LOG__ == 1 && __DEBUG_OUTPUT__ == 0)
108 108
 		{
109
-			if(__DEBUG_PROTECT__ === 0 || __DEBUG_PROTECT__ === 1 && __DEBUG_PROTECT_IP__ == $_SERVER['REMOTE_ADDR'])
109
+			if (__DEBUG_PROTECT__ === 0 || __DEBUG_PROTECT__ === 1 && __DEBUG_PROTECT_IP__ == $_SERVER['REMOTE_ADDR'])
110 110
 			{
111 111
 				set_error_handler(array($this, 'xeErrorLog'), E_WARNING);
112 112
 				register_shutdown_function(array($this, 'shutdownHandler'));
@@ -117,40 +117,40 @@  discard block
 block discarded – undo
117 117
 		$called_position = 'before_module_init';
118 118
 		$oAddonController = getController('addon');
119 119
 		$addon_file = $oAddonController->getCacheFilePath(Mobile::isFromMobilePhone() ? 'mobile' : 'pc');
120
-		if(file_exists($addon_file)) include($addon_file);
120
+		if (file_exists($addon_file)) include($addon_file);
121 121
 	}
122 122
 
123 123
 	public static function xeErrorLog($errnumber, $errormassage, $errorfile, $errorline, $errorcontext)
124 124
 	{
125
-		if(($errnumber & 3) == 0 || error_reporting() == 0)
125
+		if (($errnumber & 3) == 0 || error_reporting() == 0)
126 126
 		{
127 127
 			return false;
128 128
 		}
129 129
 
130 130
 		set_error_handler(function() { }, ~0);
131 131
 
132
-		$debug_file = _XE_PATH_ . 'files/_debug_message.php';
133
-		if(!file_exists($debug_file))
132
+		$debug_file = _XE_PATH_.'files/_debug_message.php';
133
+		if (!file_exists($debug_file))
134 134
 		{
135 135
 			$print[] = '<?php exit() ?>';
136 136
 		}
137 137
 
138 138
 		$errorname = self::getErrorType($errnumber);
139
-		$print[] = '['.date('Y-m-d H:i:s').'] ' . $errorname . ' : ' . $errormassage;
139
+		$print[] = '['.date('Y-m-d H:i:s').'] '.$errorname.' : '.$errormassage;
140 140
 		$backtrace_args = defined('DEBUG_BACKTRACE_IGNORE_ARGS') ? \DEBUG_BACKTRACE_IGNORE_ARGS : 0;
141 141
 		$backtrace = debug_backtrace($backtrace_args);
142
-		if(count($backtrace) > 1 && $backtrace[1]['function'] === 'xeErrorLog' && !$backtrace[1]['class'])
142
+		if (count($backtrace) > 1 && $backtrace[1]['function'] === 'xeErrorLog' && !$backtrace[1]['class'])
143 143
 		{
144 144
 			array_shift($backtrace);
145 145
 		}
146 146
 
147
-		foreach($backtrace as $key => $value)
147
+		foreach ($backtrace as $key => $value)
148 148
 		{
149
-			$message = '    - ' . $value['file'] . ' : ' . $value['line'];
149
+			$message = '    - '.$value['file'].' : '.$value['line'];
150 150
 			$print[] = $message;
151 151
 		}
152 152
 		$print[] = PHP_EOL;
153
-		@file_put_contents($debug_file, implode(PHP_EOL, $print), FILE_APPEND|LOCK_EX);
153
+		@file_put_contents($debug_file, implode(PHP_EOL, $print), FILE_APPEND | LOCK_EX);
154 154
 		restore_error_handler();
155 155
 
156 156
 		return true;
@@ -166,21 +166,21 @@  discard block
 block discarded – undo
166 166
 
167 167
 		set_error_handler(function() { }, ~0);
168 168
 
169
-		$debug_file = _XE_PATH_ . 'files/_debug_message.php';
170
-		if(!file_exists($debug_file))
169
+		$debug_file = _XE_PATH_.'files/_debug_message.php';
170
+		if (!file_exists($debug_file))
171 171
 		{
172 172
 			$print[] = '<?php exit() ?>';
173 173
 		}
174 174
 
175 175
 		$errorname = self::getErrorType($errinfo['type']);
176 176
 		$print[] = '['.date('Y-m-d H:i:s').']';
177
-		$print[] = $errorname . ' : ' . $errinfo['message'];
177
+		$print[] = $errorname.' : '.$errinfo['message'];
178 178
 
179
-		$message = '    - ' . $errinfo['file'] . ' : ' . $errinfo['line'];
179
+		$message = '    - '.$errinfo['file'].' : '.$errinfo['line'];
180 180
 		$print[] = $message;
181 181
 
182 182
 		$print[] = PHP_EOL;
183
-		@file_put_contents($debug_file, implode(PHP_EOL, $print), FILE_APPEND|LOCK_EX);
183
+		@file_put_contents($debug_file, implode(PHP_EOL, $print), FILE_APPEND | LOCK_EX);
184 184
 		set_error_handler(array($this, 'dummyHandler'), ~0);
185 185
 
186 186
 		return true;
@@ -224,9 +224,9 @@  discard block
 block discarded – undo
224 224
 		$defaultUrlInfo = parse_url($dbInfo->default_url);
225 225
 		$defaultHost = $defaultUrlInfo['host'];
226 226
 
227
-		foreach($urls as $url)
227
+		foreach ($urls as $url)
228 228
 		{
229
-			if(empty($url))
229
+			if (empty($url))
230 230
 			{
231 231
 				continue;
232 232
 			}
@@ -234,29 +234,29 @@  discard block
 block discarded – undo
234 234
 			$urlInfo = parse_url($url);
235 235
 			$host = $urlInfo['host'];
236 236
 
237
-			if($host && ($host != $defaultHost && $host != $site_module_info->domain))
237
+			if ($host && ($host != $defaultHost && $host != $site_module_info->domain))
238 238
 			{
239 239
 				throw new Exception('msg_default_url_is_null');
240 240
 			}
241 241
 		}
242 242
 
243
-		if(!$this->document_srl && $this->mid && $this->entry)
243
+		if (!$this->document_srl && $this->mid && $this->entry)
244 244
 		{
245 245
 			$oDocumentModel = getModel('document');
246 246
 			$this->document_srl = $oDocumentModel->getDocumentSrlByAlias($this->mid, $this->entry);
247
-			if($this->document_srl)
247
+			if ($this->document_srl)
248 248
 			{
249 249
 				Context::set('document_srl', $this->document_srl);
250 250
 			}
251 251
 		}
252 252
 
253 253
 		// Get module's information based on document_srl, if it's specified
254
-		if($this->document_srl)
254
+		if ($this->document_srl)
255 255
 		{
256 256
 
257 257
 			$module_info = $oModuleModel->getModuleInfoByDocumentSrl($this->document_srl);
258 258
 			// If the document does not exist, remove document_srl
259
-			if(!$module_info)
259
+			if (!$module_info)
260 260
 			{
261 261
 				unset($this->document_srl);
262 262
 			}
@@ -264,13 +264,13 @@  discard block
 block discarded – undo
264 264
 			{
265 265
 				// If it exists, compare mid based on the module information
266 266
 				// if mids are not matching, set it as the document's mid
267
-				if(!$this->mid || ($this->mid != $module_info->mid))
267
+				if (!$this->mid || ($this->mid != $module_info->mid))
268 268
 				{
269 269
 
270
-					if(Context::getRequestMethod() == 'GET')
270
+					if (Context::getRequestMethod() == 'GET')
271 271
 					{
272 272
 						$this->mid = $module_info->mid;
273
-						header('location:' . getNotEncodedSiteUrl($site_module_info->domain, 'mid', $this->mid, 'document_srl', $this->document_srl));
273
+						header('location:'.getNotEncodedSiteUrl($site_module_info->domain, 'mid', $this->mid, 'document_srl', $this->document_srl));
274 274
 						return FALSE;
275 275
 					}
276 276
 					else
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
 
282 282
 				}
283 283
 				// if requested module is different from one of the document, remove the module information retrieved based on the document number
284
-				if($this->module && $module_info->module != $this->module)
284
+				if ($this->module && $module_info->module != $this->module)
285 285
 				{
286 286
 					unset($module_info);
287 287
 				}
@@ -290,36 +290,36 @@  discard block
 block discarded – undo
290 290
 		}
291 291
 
292 292
 		// If module_info is not set yet, and there exists mid information, get module information based on the mid
293
-		if(!$module_info && $this->mid)
293
+		if (!$module_info && $this->mid)
294 294
 		{
295 295
 			$module_info = $oModuleModel->getModuleInfoByMid($this->mid, $site_module_info->site_srl);
296 296
 			//if($this->module && $module_info->module != $this->module) unset($module_info);
297 297
 		}
298 298
 
299 299
 		// redirect, if module_site_srl and site_srl are different
300
-		if(!$this->module && !$module_info && $site_module_info->site_srl == 0 && $site_module_info->module_site_srl > 0)
300
+		if (!$this->module && !$module_info && $site_module_info->site_srl == 0 && $site_module_info->module_site_srl > 0)
301 301
 		{
302 302
 			$site_info = $oModuleModel->getSiteInfo($site_module_info->module_site_srl);
303
-			header("location:" . getNotEncodedSiteUrl($site_info->domain, 'mid', $site_module_info->mid));
303
+			header("location:".getNotEncodedSiteUrl($site_info->domain, 'mid', $site_module_info->mid));
304 304
 			return FALSE;
305 305
 		}
306 306
 
307 307
 		// If module_info is not set still, and $module does not exist, find the default module
308
-		if(!$module_info && !$this->module && !$this->mid)
308
+		if (!$module_info && !$this->module && !$this->mid)
309 309
 		{
310 310
 			$module_info = $site_module_info;
311 311
 		}
312 312
 
313
-		if(!$module_info && !$this->module && $site_module_info->module_site_srl)
313
+		if (!$module_info && !$this->module && $site_module_info->module_site_srl)
314 314
 		{
315 315
 			$module_info = $site_module_info;
316 316
 		}
317 317
 
318 318
 		// redirect, if site_srl of module_info is different from one of site's module_info
319
-		if($module_info && $module_info->site_srl != $site_module_info->site_srl && !isCrawler())
319
+		if ($module_info && $module_info->site_srl != $site_module_info->site_srl && !isCrawler())
320 320
 		{
321 321
 			// If the module is of virtual site
322
-			if($module_info->site_srl)
322
+			if ($module_info->site_srl)
323 323
 			{
324 324
 				$site_info = $oModuleModel->getSiteInfo($module_info->site_srl);
325 325
 				$redirect_url = getNotEncodedSiteUrl($site_info->domain, 'mid', Context::get('mid'), 'document_srl', Context::get('document_srl'), 'module_srl', Context::get('module_srl'), 'entry', Context::get('entry'));
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
 			else
329 329
 			{
330 330
 				$db_info = Context::getDBInfo();
331
-				if(!$db_info->default_url)
331
+				if (!$db_info->default_url)
332 332
 				{
333 333
 					return Context::getLang('msg_default_url_is_not_defined');
334 334
 				}
@@ -337,12 +337,12 @@  discard block
 block discarded – undo
337 337
 					$redirect_url = getNotEncodedSiteUrl($db_info->default_url, 'mid', Context::get('mid'), 'document_srl', Context::get('document_srl'), 'module_srl', Context::get('module_srl'), 'entry', Context::get('entry'));
338 338
 				}
339 339
 			}
340
-			header("location:" . $redirect_url);
340
+			header("location:".$redirect_url);
341 341
 			return FALSE;
342 342
 		}
343 343
 
344 344
 		// If module info was set, retrieve variables from the module information
345
-		if($module_info)
345
+		if ($module_info)
346 346
 		{
347 347
 			$this->module = $module_info->module;
348 348
 			$this->mid = $module_info->mid;
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
 			$targetSrl = (Mobile::isFromMobilePhone()) ? 'mlayout_srl' : 'layout_srl';
354 354
 
355 355
 			// use the site default layout.
356
-			if($module_info->{$targetSrl} == -1)
356
+			if ($module_info->{$targetSrl} == -1)
357 357
 			{
358 358
 				$oLayoutAdminModel = getAdminModel('layout');
359 359
 				$layoutSrl = $oLayoutAdminModel->getSiteDefaultLayout($viewType, $module_info->site_srl);
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
 		}
372 372
 
373 373
 		// Set module and mid into module_info
374
-		if(!isset($this->module_info))
374
+		if (!isset($this->module_info))
375 375
 		{
376 376
 			$this->module_info = new stdClass();
377 377
 		}
@@ -382,21 +382,21 @@  discard block
 block discarded – undo
382 382
 		$this->module_info->site_srl = $site_module_info->site_srl;
383 383
 
384 384
 		// Still no module? it's an error
385
-		if(!$this->module)
385
+		if (!$this->module)
386 386
 		{
387 387
 			$this->error = 'msg_module_is_not_exists';
388 388
 			$this->httpStatusCode = '404';
389 389
 		}
390 390
 
391 391
 		// If mid exists, set mid into context
392
-		if($this->mid)
392
+		if ($this->mid)
393 393
 		{
394 394
 			Context::set('mid', $this->mid, TRUE);
395 395
 		}
396 396
 
397 397
 		// Call a trigger after moduleHandler init
398 398
 		$output = ModuleHandler::triggerCall('moduleHandler.init', 'after', $this->module_info);
399
-		if(!$output->toBool())
399
+		if (!$output->toBool())
400 400
 		{
401 401
 			$this->error = $output->getMessage();
402 402
 			return TRUE;
@@ -418,14 +418,14 @@  discard block
 block discarded – undo
418 418
 		$display_mode = Mobile::isFromMobilePhone() ? 'mobile' : 'view';
419 419
 
420 420
 		// If error occurred while preparation, return a message instance
421
-		if($this->error)
421
+		if ($this->error)
422 422
 		{
423 423
 			$this->_setInputErrorToContext();
424 424
 			$oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode);
425 425
 			$oMessageObject->setError(-1);
426 426
 			$oMessageObject->setMessage($this->error);
427 427
 			$oMessageObject->dispMessage();
428
-			if($this->httpStatusCode)
428
+			if ($this->httpStatusCode)
429 429
 			{
430 430
 				$oMessageObject->setHttpStatusCode($this->httpStatusCode);
431 431
 			}
@@ -436,22 +436,22 @@  discard block
 block discarded – undo
436 436
 		$xml_info = $oModuleModel->getModuleActionXml($this->module);
437 437
 
438 438
 		// If not installed yet, modify act
439
-		if($this->module == "install")
439
+		if ($this->module == "install")
440 440
 		{
441
-			if(!$this->act || !$xml_info->action->{$this->act})
441
+			if (!$this->act || !$xml_info->action->{$this->act})
442 442
 			{
443 443
 				$this->act = $xml_info->default_index_act;
444 444
 			}
445 445
 		}
446 446
 
447 447
 		// if act exists, find type of the action, if not use default index act
448
-		if(!$this->act)
448
+		if (!$this->act)
449 449
 		{
450 450
 			$this->act = $xml_info->default_index_act;
451 451
 		}
452 452
 
453 453
 		// still no act means error
454
-		if(!$this->act)
454
+		if (!$this->act)
455 455
 		{
456 456
 			$this->error = 'msg_module_is_not_exists';
457 457
 			$this->httpStatusCode = '404';
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
 			$oMessageObject->setError(-1);
462 462
 			$oMessageObject->setMessage($this->error);
463 463
 			$oMessageObject->dispMessage();
464
-			if($this->httpStatusCode)
464
+			if ($this->httpStatusCode)
465 465
 			{
466 466
 				$oMessageObject->setHttpStatusCode($this->httpStatusCode);
467 467
 			}
@@ -479,17 +479,17 @@  discard block
 block discarded – undo
479 479
 			Context::addMetaTag('robots', 'noindex');
480 480
 		}
481 481
 
482
-		if(!$kind && $this->module == 'admin')
482
+		if (!$kind && $this->module == 'admin')
483 483
 		{
484 484
 			$kind = 'admin';
485 485
 		}
486 486
 
487 487
 		// check REQUEST_METHOD in controller
488
-		if($type == 'controller')
488
+		if ($type == 'controller')
489 489
 		{
490 490
 			$allowedMethod = $xml_info->action->{$this->act}->method;
491 491
 
492
-			if(!$allowedMethod)
492
+			if (!$allowedMethod)
493 493
 			{
494 494
 				$allowedMethodList[0] = 'POST';
495 495
 			}
@@ -498,7 +498,7 @@  discard block
 block discarded – undo
498 498
 				$allowedMethodList = explode('|', strtoupper($allowedMethod));
499 499
 			}
500 500
 
501
-			if(!in_array(strtoupper($_SERVER['REQUEST_METHOD']), $allowedMethodList))
501
+			if (!in_array(strtoupper($_SERVER['REQUEST_METHOD']), $allowedMethodList))
502 502
 			{
503 503
 				$this->error = "msg_invalid_request";
504 504
 				$oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode);
@@ -509,7 +509,7 @@  discard block
 block discarded – undo
509 509
 			}
510 510
 		}
511 511
 
512
-		if($this->module_info->use_mobile != "Y")
512
+		if ($this->module_info->use_mobile != "Y")
513 513
 		{
514 514
 			Mobile::setMobile(FALSE);
515 515
 		}
@@ -518,7 +518,7 @@  discard block
 block discarded – undo
518 518
 
519 519
 		// check CSRF for non-GET actions
520 520
 		$use_check_csrf = isset($xml_info->action->{$this->act}) && $xml_info->action->{$this->act}->check_csrf !== 'false';
521
-		if($use_check_csrf && $_SERVER['REQUEST_METHOD'] !== 'GET' && Context::isInstalled() && !checkCSRF())
521
+		if ($use_check_csrf && $_SERVER['REQUEST_METHOD'] !== 'GET' && Context::isInstalled() && !checkCSRF())
522 522
 		{
523 523
 			$this->error = 'msg_invalid_request';
524 524
 			$oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode);
@@ -529,7 +529,7 @@  discard block
 block discarded – undo
529 529
 		}
530 530
 
531 531
 		// Admin ip
532
-		if($kind == 'admin' && $_SESSION['denied_admin'] == 'Y')
532
+		if ($kind == 'admin' && $_SESSION['denied_admin'] == 'Y')
533 533
 		{
534 534
 			$this->_setInputErrorToContext();
535 535
 			$this->error = "msg_not_permitted_act";
@@ -541,13 +541,13 @@  discard block
 block discarded – undo
541 541
 		}
542 542
 
543 543
 		// if(type == view, and case for using mobilephone)
544
-		if($type == "view" && Mobile::isFromMobilePhone() && Context::isInstalled())
544
+		if ($type == "view" && Mobile::isFromMobilePhone() && Context::isInstalled())
545 545
 		{
546 546
 			$orig_type = "view";
547 547
 			$type = "mobile";
548 548
 			// create a module instance
549 549
 			$oModule = $this->getModuleInstance($this->module, $type, $kind);
550
-			if(!is_object($oModule) || !method_exists($oModule, $this->act))
550
+			if (!is_object($oModule) || !method_exists($oModule, $this->act))
551 551
 			{
552 552
 				$type = $orig_type;
553 553
 				Mobile::setMobile(FALSE);
@@ -560,14 +560,14 @@  discard block
 block discarded – undo
560 560
 			$oModule = $this->getModuleInstance($this->module, $type, $kind);
561 561
 		}
562 562
 
563
-		if(!is_object($oModule))
563
+		if (!is_object($oModule))
564 564
 		{
565 565
 			$this->_setInputErrorToContext();
566 566
 			$oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode);
567 567
 			$oMessageObject->setError(-1);
568 568
 			$oMessageObject->setMessage($this->error);
569 569
 			$oMessageObject->dispMessage();
570
-			if($this->httpStatusCode)
570
+			if ($this->httpStatusCode)
571 571
 			{
572 572
 				$oMessageObject->setHttpStatusCode($this->httpStatusCode);
573 573
 			}
@@ -575,10 +575,10 @@  discard block
 block discarded – undo
575 575
 		}
576 576
 
577 577
 		// If there is no such action in the module object
578
-		if(!isset($xml_info->action->{$this->act}) || !method_exists($oModule, $this->act))
578
+		if (!isset($xml_info->action->{$this->act}) || !method_exists($oModule, $this->act))
579 579
 		{
580 580
 
581
-			if(!Context::isInstalled())
581
+			if (!Context::isInstalled())
582 582
 			{
583 583
 				$this->_setInputErrorToContext();
584 584
 				$this->error = 'msg_invalid_request';
@@ -586,7 +586,7 @@  discard block
 block discarded – undo
586 586
 				$oMessageObject->setError(-1);
587 587
 				$oMessageObject->setMessage($this->error);
588 588
 				$oMessageObject->dispMessage();
589
-				if($this->httpStatusCode)
589
+				if ($this->httpStatusCode)
590 590
 				{
591 591
 					$oMessageObject->setHttpStatusCode($this->httpStatusCode);
592 592
 				}
@@ -595,12 +595,12 @@  discard block
 block discarded – undo
595 595
 
596 596
 			$forward = NULL;
597 597
 			// 1. Look for the module with action name
598
-			if(preg_match('/^([a-z]+)([A-Z])([a-z0-9\_]+)(.*)$/', $this->act, $matches))
598
+			if (preg_match('/^([a-z]+)([A-Z])([a-z0-9\_]+)(.*)$/', $this->act, $matches))
599 599
 			{
600
-				$module = strtolower($matches[2] . $matches[3]);
600
+				$module = strtolower($matches[2].$matches[3]);
601 601
 				$xml_info = $oModuleModel->getModuleActionXml($module);
602 602
 
603
-				if($xml_info->action->{$this->act} && ((stripos($this->act, 'admin') !== FALSE) || $xml_info->action->{$this->act}->standalone != 'false'))
603
+				if ($xml_info->action->{$this->act} && ((stripos($this->act, 'admin') !== FALSE) || $xml_info->action->{$this->act}->standalone != 'false'))
604 604
 				{
605 605
 					$forward = new stdClass();
606 606
 					$forward->module = $module;
@@ -621,12 +621,12 @@  discard block
 block discarded – undo
621 621
 				}
622 622
 			}
623 623
 
624
-			if(!$forward)
624
+			if (!$forward)
625 625
 			{
626 626
 				$forward = $oModuleModel->getActionForward($this->act);
627 627
 			}
628 628
 
629
-			if($forward->module && $forward->type && $forward->act && $forward->act == $this->act)
629
+			if ($forward->module && $forward->type && $forward->act && $forward->act == $this->act)
630 630
 			{
631 631
 				$kind = stripos($forward->act, 'admin') !== FALSE ? 'admin' : '';
632 632
 				$type = $forward->type;
@@ -634,7 +634,7 @@  discard block
 block discarded – undo
634 634
 				$tpl_path = $oModule->getTemplatePath();
635 635
 				$orig_module = $oModule;
636 636
 
637
-				if($forward->meta_noindex === 'true') {
637
+				if ($forward->meta_noindex === 'true') {
638 638
 					Context::addMetaTag('robots', 'noindex');
639 639
 				}
640 640
 
@@ -642,7 +642,7 @@  discard block
 block discarded – undo
642 642
 
643 643
 				// check CSRF for non-GET actions
644 644
 				$use_check_csrf = isset($xml_info->action->{$this->act}) && $xml_info->action->{$this->act}->check_csrf !== 'false';
645
-				if($use_check_csrf && $_SERVER['REQUEST_METHOD'] !== 'GET' && Context::isInstalled() && !checkCSRF())
645
+				if ($use_check_csrf && $_SERVER['REQUEST_METHOD'] !== 'GET' && Context::isInstalled() && !checkCSRF())
646 646
 				{
647 647
 					$this->error = 'msg_invalid_request';
648 648
 					$oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode);
@@ -654,11 +654,11 @@  discard block
 block discarded – undo
654 654
 
655 655
 				// SECISSUE also check foward act method
656 656
 				// check REQUEST_METHOD in controller
657
-				if($type == 'controller')
657
+				if ($type == 'controller')
658 658
 				{
659 659
 					$allowedMethod = $xml_info->action->{$forward->act}->method;
660 660
 
661
-					if(!$allowedMethod)
661
+					if (!$allowedMethod)
662 662
 					{
663 663
 						$allowedMethodList[0] = 'POST';
664 664
 					}
@@ -667,7 +667,7 @@  discard block
 block discarded – undo
667 667
 						$allowedMethodList = explode('|', strtoupper($allowedMethod));
668 668
 					}
669 669
 
670
-					if(!in_array(strtoupper($_SERVER['REQUEST_METHOD']), $allowedMethodList))
670
+					if (!in_array(strtoupper($_SERVER['REQUEST_METHOD']), $allowedMethodList))
671 671
 					{
672 672
 						$this->error = "msg_invalid_request";
673 673
 						$oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode);
@@ -678,13 +678,13 @@  discard block
 block discarded – undo
678 678
 					}
679 679
 				}
680 680
 
681
-				if($type == "view" && Mobile::isFromMobilePhone())
681
+				if ($type == "view" && Mobile::isFromMobilePhone())
682 682
 				{
683 683
 					$orig_type = "view";
684 684
 					$type = "mobile";
685 685
 					// create a module instance
686 686
 					$oModule = $this->getModuleInstance($forward->module, $type, $kind);
687
-					if(!is_object($oModule) || !method_exists($oModule, $this->act))
687
+					if (!is_object($oModule) || !method_exists($oModule, $this->act))
688 688
 					{
689 689
 						$type = $orig_type;
690 690
 						Mobile::setMobile(FALSE);
@@ -696,25 +696,25 @@  discard block
 block discarded – undo
696 696
 					$oModule = $this->getModuleInstance($forward->module, $type, $kind);
697 697
 				}
698 698
 
699
-				if(!is_object($oModule))
699
+				if (!is_object($oModule))
700 700
 				{
701 701
 					$this->_setInputErrorToContext();
702 702
 					$oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode);
703 703
 					$oMessageObject->setError(-1);
704 704
 					$oMessageObject->setMessage('msg_module_is_not_exists');
705 705
 					$oMessageObject->dispMessage();
706
-					if($this->httpStatusCode)
706
+					if ($this->httpStatusCode)
707 707
 					{
708 708
 						$oMessageObject->setHttpStatusCode($this->httpStatusCode);
709 709
 					}
710 710
 					return $oMessageObject;
711 711
 				}
712 712
 
713
-				if($this->module == "admin" && $type == "view")
713
+				if ($this->module == "admin" && $type == "view")
714 714
 				{
715
-					if($logged_info->is_admin == 'Y')
715
+					if ($logged_info->is_admin == 'Y')
716 716
 					{
717
-						if($this->act != 'dispLayoutAdminLayoutModify')
717
+						if ($this->act != 'dispLayoutAdminLayoutModify')
718 718
 						{
719 719
 							$oAdminView = getAdminView('admin');
720 720
 							$oAdminView->makeGnbUrl($forward->module);
@@ -734,10 +734,10 @@  discard block
 block discarded – undo
734 734
 						return $oMessageObject;
735 735
 					}
736 736
 				}
737
-				if($kind == 'admin')
737
+				if ($kind == 'admin')
738 738
 				{
739 739
 					$grant = $oModuleModel->getGrant($this->module_info, $logged_info);
740
-					if(!$grant->manager)
740
+					if (!$grant->manager)
741 741
 					{
742 742
 						$this->_setInputErrorToContext();
743 743
 						$this->error = 'msg_is_not_manager';
@@ -749,7 +749,7 @@  discard block
 block discarded – undo
749 749
 					}
750 750
 					else
751 751
 					{
752
-						if(!$grant->is_admin && $this->module != $this->orig_module->module && $xml_info->permission->{$this->act} != 'manager')
752
+						if (!$grant->is_admin && $this->module != $this->orig_module->module && $xml_info->permission->{$this->act} != 'manager')
753 753
 						{
754 754
 							$this->_setInputErrorToContext();
755 755
 							$this->error = 'msg_is_not_administrator';
@@ -762,7 +762,7 @@  discard block
 block discarded – undo
762 762
 					}
763 763
 				}
764 764
 			}
765
-			else if($xml_info->default_index_act && method_exists($oModule, $xml_info->default_index_act))
765
+			else if ($xml_info->default_index_act && method_exists($oModule, $xml_info->default_index_act))
766 766
 			{
767 767
 				$this->act = $xml_info->default_index_act;
768 768
 			}
@@ -776,16 +776,16 @@  discard block
 block discarded – undo
776 776
 		}
777 777
 
778 778
 		// ruleset check...
779
-		if(!empty($ruleset))
779
+		if (!empty($ruleset))
780 780
 		{
781 781
 			$rulesetModule = $forward->module ? $forward->module : $this->module;
782 782
 			$rulesetFile = $oModuleModel->getValidatorFilePath($rulesetModule, $ruleset, $this->mid);
783
-			if(!empty($rulesetFile))
783
+			if (!empty($rulesetFile))
784 784
 			{
785
-				if($_SESSION['XE_VALIDATOR_ERROR_LANG'])
785
+				if ($_SESSION['XE_VALIDATOR_ERROR_LANG'])
786 786
 				{
787 787
 					$errorLang = $_SESSION['XE_VALIDATOR_ERROR_LANG'];
788
-					foreach($errorLang as $key => $val)
788
+					foreach ($errorLang as $key => $val)
789 789
 					{
790 790
 						Context::setLang($key, $val);
791 791
 					}
@@ -794,7 +794,7 @@  discard block
 block discarded – undo
794 794
 
795 795
 				$Validator = new Validator($rulesetFile);
796 796
 				$result = $Validator->validate();
797
-				if(!$result)
797
+				if (!$result)
798 798
 				{
799 799
 					$lastError = $Validator->getLastError();
800 800
 					$returnUrl = Context::get('error_return_url');
@@ -826,26 +826,26 @@  discard block
 block discarded – undo
826 826
 				'dispLayoutPreviewWithModule' => 1
827 827
 		);
828 828
 		$db_use_mobile = Mobile::isMobileEnabled();
829
-		if($type == "view" && $this->module_info->use_mobile == "Y" && Mobile::isMobileCheckByAgent() && !isset($skipAct[Context::get('act')]) && $db_use_mobile === true)
829
+		if ($type == "view" && $this->module_info->use_mobile == "Y" && Mobile::isMobileCheckByAgent() && !isset($skipAct[Context::get('act')]) && $db_use_mobile === true)
830 830
 		{
831 831
 			global $lang;
832 832
 			$header = '<style>div.xe_mobile{opacity:0.7;margin:1em 0;padding:.5em;background:#333;border:1px solid #666;border-left:0;border-right:0}p.xe_mobile{text-align:center;margin:1em 0}a.xe_mobile{color:#ff0;font-weight:bold;font-size:24px}@media only screen and (min-width:500px){a.xe_mobile{font-size:15px}}</style>';
833
-			$footer = '<div class="xe_mobile"><p class="xe_mobile"><a class="xe_mobile" href="' . getUrl('m', '1') . '">' . $lang->msg_pc_to_mobile . '</a></p></div>';
833
+			$footer = '<div class="xe_mobile"><p class="xe_mobile"><a class="xe_mobile" href="'.getUrl('m', '1').'">'.$lang->msg_pc_to_mobile.'</a></p></div>';
834 834
 			Context::addHtmlHeader($header);
835 835
 			Context::addHtmlFooter($footer);
836 836
 		}
837 837
 
838
-		if(($type == 'view' || $type == 'mobile') && $kind != 'admin')
838
+		if (($type == 'view' || $type == 'mobile') && $kind != 'admin')
839 839
 		{
840 840
 			$module_config = $oModuleModel->getModuleConfig('module');
841
-			if($module_config->htmlFooter)
841
+			if ($module_config->htmlFooter)
842 842
 			{
843 843
 				Context::addHtmlFooter($module_config->htmlFooter);
844 844
 			}
845
-			if($module_config->siteTitle)
845
+			if ($module_config->siteTitle)
846 846
 			{
847 847
 				$siteTitle = Context::getBrowserTitle();
848
-				if(!$siteTitle)
848
+				if (!$siteTitle)
849 849
 				{
850 850
 					Context::setBrowserTitle($module_config->siteTitle);
851 851
 				}
@@ -862,18 +862,18 @@  discard block
 block discarded – undo
862 862
 		$procResult = $oModule->proc();
863 863
 
864 864
 		$methodList = array('XMLRPC' => 1, 'JSON' => 1, 'JS_CALLBACK' => 1);
865
-		if(!$oModule->stop_proc && !isset($methodList[Context::getRequestMethod()]))
865
+		if (!$oModule->stop_proc && !isset($methodList[Context::getRequestMethod()]))
866 866
 		{
867 867
 			$error = $oModule->getError();
868 868
 			$message = $oModule->getMessage();
869 869
 			$messageType = $oModule->getMessageType();
870 870
 			$redirectUrl = $oModule->getRedirectUrl();
871
-			if($messageType == 'error') debugPrint($message, 'ERROR');
871
+			if ($messageType == 'error') debugPrint($message, 'ERROR');
872 872
 
873
-			if(!$procResult)
873
+			if (!$procResult)
874 874
 			{
875 875
 				$this->error = $message;
876
-				if(!$redirectUrl && Context::get('error_return_url'))
876
+				if (!$redirectUrl && Context::get('error_return_url'))
877 877
 				{
878 878
 					$redirectUrl = Context::get('error_return_url');
879 879
 				}
@@ -886,13 +886,13 @@  discard block
 block discarded – undo
886 886
 
887 887
 			$_SESSION['XE_VALIDATOR_ERROR'] = $error;
888 888
 			$_SESSION['XE_VALIDATOR_ID'] = Context::get('xe_validator_id');
889
-			if($message != 'success')
889
+			if ($message != 'success')
890 890
 			{
891 891
 				$_SESSION['XE_VALIDATOR_MESSAGE'] = $message;
892 892
 			}
893 893
 			$_SESSION['XE_VALIDATOR_MESSAGE_TYPE'] = $messageType;
894 894
 
895
-			if(Context::get('xeVirtualRequestMethod') != 'xml')
895
+			if (Context::get('xeVirtualRequestMethod') != 'xml')
896 896
 			{
897 897
 				$_SESSION['XE_VALIDATOR_RETURN_URL'] = $redirectUrl;
898 898
 			}
@@ -908,27 +908,27 @@  discard block
 block discarded – undo
908 908
 	 * */
909 909
 	function _setInputErrorToContext()
910 910
 	{
911
-		if($_SESSION['XE_VALIDATOR_ERROR'] && !Context::get('XE_VALIDATOR_ERROR'))
911
+		if ($_SESSION['XE_VALIDATOR_ERROR'] && !Context::get('XE_VALIDATOR_ERROR'))
912 912
 		{
913 913
 			Context::set('XE_VALIDATOR_ERROR', $_SESSION['XE_VALIDATOR_ERROR']);
914 914
 		}
915
-		if($_SESSION['XE_VALIDATOR_MESSAGE'] && !Context::get('XE_VALIDATOR_MESSAGE'))
915
+		if ($_SESSION['XE_VALIDATOR_MESSAGE'] && !Context::get('XE_VALIDATOR_MESSAGE'))
916 916
 		{
917 917
 			Context::set('XE_VALIDATOR_MESSAGE', $_SESSION['XE_VALIDATOR_MESSAGE']);
918 918
 		}
919
-		if($_SESSION['XE_VALIDATOR_MESSAGE_TYPE'] && !Context::get('XE_VALIDATOR_MESSAGE_TYPE'))
919
+		if ($_SESSION['XE_VALIDATOR_MESSAGE_TYPE'] && !Context::get('XE_VALIDATOR_MESSAGE_TYPE'))
920 920
 		{
921 921
 			Context::set('XE_VALIDATOR_MESSAGE_TYPE', $_SESSION['XE_VALIDATOR_MESSAGE_TYPE']);
922 922
 		}
923
-		if($_SESSION['XE_VALIDATOR_RETURN_URL'] && !Context::get('XE_VALIDATOR_RETURN_URL'))
923
+		if ($_SESSION['XE_VALIDATOR_RETURN_URL'] && !Context::get('XE_VALIDATOR_RETURN_URL'))
924 924
 		{
925 925
 			Context::set('XE_VALIDATOR_RETURN_URL', $_SESSION['XE_VALIDATOR_RETURN_URL']);
926 926
 		}
927
-		if($_SESSION['XE_VALIDATOR_ID'] && !Context::get('XE_VALIDATOR_ID'))
927
+		if ($_SESSION['XE_VALIDATOR_ID'] && !Context::get('XE_VALIDATOR_ID'))
928 928
 		{
929 929
 			Context::set('XE_VALIDATOR_ID', $_SESSION['XE_VALIDATOR_ID']);
930 930
 		}
931
-		if(count($_SESSION['INPUT_ERROR']))
931
+		if (count($_SESSION['INPUT_ERROR']))
932 932
 		{
933 933
 			Context::set('INPUT_ERROR', $_SESSION['INPUT_ERROR']);
934 934
 		}
@@ -958,7 +958,7 @@  discard block
 block discarded – undo
958 958
 	{
959 959
 		$requestVars = Context::getRequestVars();
960 960
 		unset($requestVars->act, $requestVars->mid, $requestVars->vid, $requestVars->success_return_url, $requestVars->error_return_url);
961
-		foreach($requestVars AS $key => $value)
961
+		foreach ($requestVars AS $key => $value)
962 962
 		{
963 963
 			$_SESSION['INPUT_ERROR'][$key] = $value;
964 964
 		}
@@ -972,41 +972,41 @@  discard block
 block discarded – undo
972 972
 	function displayContent($oModule = NULL)
973 973
 	{
974 974
 		// If the module is not set or not an object, set error
975
-		if(!$oModule || !is_object($oModule))
975
+		if (!$oModule || !is_object($oModule))
976 976
 		{
977 977
 			$this->error = 'msg_module_is_not_exists';
978 978
 			$this->httpStatusCode = '404';
979 979
 		}
980 980
 
981 981
 		// If connection to DB has a problem even though it's not install module, set error
982
-		if($this->module != 'install' && isset($GLOBALS['__DB__']) && $GLOBALS['__DB__'][Context::getDBType()]->isConnected() == FALSE)
982
+		if ($this->module != 'install' && isset($GLOBALS['__DB__']) && $GLOBALS['__DB__'][Context::getDBType()]->isConnected() == FALSE)
983 983
 		{
984 984
 			$this->error = 'msg_dbconnect_failed';
985 985
 		}
986 986
 
987 987
 		// Call trigger after moduleHandler proc
988 988
 		$output = ModuleHandler::triggerCall('moduleHandler.proc', 'after', $oModule);
989
-		if(!$output->toBool())
989
+		if (!$output->toBool())
990 990
 		{
991 991
 			$this->error = $output->getMessage();
992 992
 		}
993 993
 
994 994
 		// Use message view object, if HTML call
995 995
 		$methodList = array('XMLRPC' => 1, 'JSON' => 1, 'JS_CALLBACK' => 1);
996
-		if(!isset($methodList[Context::getRequestMethod()]))
996
+		if (!isset($methodList[Context::getRequestMethod()]))
997 997
 		{
998 998
 
999
-			if($_SESSION['XE_VALIDATOR_RETURN_URL'])
999
+			if ($_SESSION['XE_VALIDATOR_RETURN_URL'])
1000 1000
 			{
1001 1001
 				$display_handler = new DisplayHandler();
1002 1002
 				$display_handler->_debugOutput();
1003 1003
 
1004
-				header('location:' . $_SESSION['XE_VALIDATOR_RETURN_URL']);
1004
+				header('location:'.$_SESSION['XE_VALIDATOR_RETURN_URL']);
1005 1005
 				return;
1006 1006
 			}
1007 1007
 
1008 1008
 			// If error occurred, handle it
1009
-			if($this->error)
1009
+			if ($this->error)
1010 1010
 			{
1011 1011
 				// display content with message module instance
1012 1012
 				$type = Mobile::isFromMobilePhone() ? 'mobile' : 'view';
@@ -1015,14 +1015,14 @@  discard block
 block discarded – undo
1015 1015
 				$oMessageObject->setMessage($this->error);
1016 1016
 				$oMessageObject->dispMessage();
1017 1017
 
1018
-				if($oMessageObject->getHttpStatusCode() && $oMessageObject->getHttpStatusCode() != '200')
1018
+				if ($oMessageObject->getHttpStatusCode() && $oMessageObject->getHttpStatusCode() != '200')
1019 1019
 				{
1020 1020
 					$this->_setHttpStatusMessage($oMessageObject->getHttpStatusCode());
1021 1021
 					$oMessageObject->setTemplateFile('http_status_code');
1022 1022
 				}
1023 1023
 
1024 1024
 				// If module was called normally, change the templates of the module into ones of the message view module
1025
-				if($oModule)
1025
+				if ($oModule)
1026 1026
 				{
1027 1027
 					$oModule->setTemplatePath($oMessageObject->getTemplatePath());
1028 1028
 					$oModule->setTemplateFile($oMessageObject->getTemplateFile());
@@ -1037,7 +1037,7 @@  discard block
 block discarded – undo
1037 1037
 			}
1038 1038
 
1039 1039
 			// Check if layout_srl exists for the module
1040
-			if(Mobile::isFromMobilePhone())
1040
+			if (Mobile::isFromMobilePhone())
1041 1041
 			{
1042 1042
 				$layout_srl = $oModule->module_info->mlayout_srl;
1043 1043
 			}
@@ -1047,58 +1047,58 @@  discard block
 block discarded – undo
1047 1047
 			}
1048 1048
 
1049 1049
 			// if layout_srl is rollback by module, set default layout
1050
-			if($layout_srl == -1)
1050
+			if ($layout_srl == -1)
1051 1051
 			{
1052 1052
 				$viewType = (Mobile::isFromMobilePhone()) ? 'M' : 'P';
1053 1053
 				$oLayoutAdminModel = getAdminModel('layout');
1054 1054
 				$layout_srl = $oLayoutAdminModel->getSiteDefaultLayout($viewType, $oModule->module_info->site_srl);
1055 1055
 			}
1056 1056
 
1057
-			if($layout_srl && !$oModule->getLayoutFile())
1057
+			if ($layout_srl && !$oModule->getLayoutFile())
1058 1058
 			{
1059 1059
 
1060 1060
 				// If layout_srl exists, get information of the layout, and set the location of layout_path/ layout_file
1061 1061
 				$oLayoutModel = getModel('layout');
1062 1062
 				$layout_info = $oLayoutModel->getLayout($layout_srl);
1063
-				if($layout_info)
1063
+				if ($layout_info)
1064 1064
 				{
1065 1065
 
1066 1066
 					// Input extra_vars into $layout_info
1067
-					if($layout_info->extra_var_count)
1067
+					if ($layout_info->extra_var_count)
1068 1068
 					{
1069 1069
 
1070
-						foreach($layout_info->extra_var as $var_id => $val)
1070
+						foreach ($layout_info->extra_var as $var_id => $val)
1071 1071
 						{
1072
-							if($val->type == 'image')
1072
+							if ($val->type == 'image')
1073 1073
 							{
1074
-								if(strncmp('./files/attach/images/', $val->value, 22) === 0)
1074
+								if (strncmp('./files/attach/images/', $val->value, 22) === 0)
1075 1075
 								{
1076
-									$val->value = Context::getRequestUri() . substr($val->value, 2);
1076
+									$val->value = Context::getRequestUri().substr($val->value, 2);
1077 1077
 								}
1078 1078
 							}
1079 1079
 							$layout_info->{$var_id} = $val->value;
1080 1080
 						}
1081 1081
 					}
1082 1082
 					// Set menus into context
1083
-					if($layout_info->menu_count)
1083
+					if ($layout_info->menu_count)
1084 1084
 					{
1085
-						foreach($layout_info->menu as $menu_id => $menu)
1085
+						foreach ($layout_info->menu as $menu_id => $menu)
1086 1086
 						{
1087 1087
 							// set default menu set(included home menu)
1088
-							if(!$menu->menu_srl || $menu->menu_srl == -1)
1088
+							if (!$menu->menu_srl || $menu->menu_srl == -1)
1089 1089
 							{
1090 1090
 								$oMenuAdminController = getAdminController('menu');
1091 1091
 								$homeMenuCacheFile = $oMenuAdminController->getHomeMenuCacheFile();
1092 1092
 
1093
-								if(FileHandler::exists($homeMenuCacheFile))
1093
+								if (FileHandler::exists($homeMenuCacheFile))
1094 1094
 								{
1095 1095
 									include($homeMenuCacheFile);
1096 1096
 								}
1097 1097
 
1098
-								if(!$menu->menu_srl)
1098
+								if (!$menu->menu_srl)
1099 1099
 								{
1100
-									$menu->xml_file = str_replace('.xml.php', $homeMenuSrl . '.xml.php', $menu->xml_file);
1101
-									$menu->php_file = str_replace('.php', $homeMenuSrl . '.php', $menu->php_file);
1100
+									$menu->xml_file = str_replace('.xml.php', $homeMenuSrl.'.xml.php', $menu->xml_file);
1101
+									$menu->php_file = str_replace('.php', $homeMenuSrl.'.php', $menu->php_file);
1102 1102
 									$layout_info->menu->{$menu_id}->menu_srl = $homeMenuSrl;
1103 1103
 								}
1104 1104
 								else
@@ -1109,7 +1109,7 @@  discard block
 block discarded – undo
1109 1109
 							}
1110 1110
 
1111 1111
 							$php_file = FileHandler::exists($menu->php_file);
1112
-							if($php_file)
1112
+							if ($php_file)
1113 1113
 							{
1114 1114
 								include($php_file);
1115 1115
 							}
@@ -1125,17 +1125,17 @@  discard block
 block discarded – undo
1125 1125
 
1126 1126
 					// If layout was modified, use the modified version
1127 1127
 					$edited_layout = $oLayoutModel->getUserLayoutHtml($layout_info->layout_srl);
1128
-					if(file_exists($edited_layout))
1128
+					if (file_exists($edited_layout))
1129 1129
 					{
1130 1130
 						$oModule->setEditedLayoutFile($edited_layout);
1131 1131
 					}
1132 1132
 				}
1133 1133
 			}
1134 1134
 			$isLayoutDrop = Context::get('isLayoutDrop');
1135
-			if($isLayoutDrop)
1135
+			if ($isLayoutDrop)
1136 1136
 			{
1137 1137
 				$kind = stripos($this->act, 'admin') !== FALSE ? 'admin' : '';
1138
-				if($kind == 'admin')
1138
+				if ($kind == 'admin')
1139 1139
 				{
1140 1140
 					$oModule->setLayoutFile('popup_layout');
1141 1141
 				}
@@ -1173,7 +1173,7 @@  discard block
 block discarded – undo
1173 1173
 	function &getModuleInstance($module, $type = 'view', $kind = '')
1174 1174
 	{
1175 1175
 
1176
-		if(__DEBUG__ == 3)
1176
+		if (__DEBUG__ == 3)
1177 1177
 		{
1178 1178
 			$start_time = getMicroTime();
1179 1179
 		}
@@ -1183,51 +1183,51 @@  discard block
 block discarded – undo
1183 1183
 		$type = strtolower($type);
1184 1184
 
1185 1185
 		$kinds = array('svc' => 1, 'admin' => 1);
1186
-		if(!isset($kinds[$kind]))
1186
+		if (!isset($kinds[$kind]))
1187 1187
 		{
1188 1188
 			$kind = 'svc';
1189 1189
 		}
1190 1190
 
1191
-		$key = $module . '.' . ($kind != 'admin' ? '' : 'admin') . '.' . $type;
1191
+		$key = $module.'.'.($kind != 'admin' ? '' : 'admin').'.'.$type;
1192 1192
 
1193
-		if(is_array($GLOBALS['__MODULE_EXTEND__']) && array_key_exists($key, $GLOBALS['__MODULE_EXTEND__']))
1193
+		if (is_array($GLOBALS['__MODULE_EXTEND__']) && array_key_exists($key, $GLOBALS['__MODULE_EXTEND__']))
1194 1194
 		{
1195 1195
 			$module = $extend_module = $GLOBALS['__MODULE_EXTEND__'][$key];
1196 1196
 		}
1197 1197
 
1198 1198
 		// if there is no instance of the module in global variable, create a new one
1199
-		if(!isset($GLOBALS['_loaded_module'][$module][$type][$kind]))
1199
+		if (!isset($GLOBALS['_loaded_module'][$module][$type][$kind]))
1200 1200
 		{
1201 1201
 			ModuleHandler::_getModuleFilePath($module, $type, $kind, $class_path, $high_class_file, $class_file, $instance_name);
1202 1202
 
1203
-			if($extend_module && (!is_readable($high_class_file) || !is_readable($class_file)))
1203
+			if ($extend_module && (!is_readable($high_class_file) || !is_readable($class_file)))
1204 1204
 			{
1205 1205
 				$module = $parent_module;
1206 1206
 				ModuleHandler::_getModuleFilePath($module, $type, $kind, $class_path, $high_class_file, $class_file, $instance_name);
1207 1207
 			}
1208 1208
 
1209 1209
 			// Check if the base class and instance class exist
1210
-			if(!class_exists($module, true))
1210
+			if (!class_exists($module, true))
1211 1211
 			{
1212 1212
 				return NULL;
1213 1213
 			}
1214
-			if(!class_exists($instance_name, true))
1214
+			if (!class_exists($instance_name, true))
1215 1215
 			{
1216 1216
 				return NULL;
1217 1217
 			}
1218 1218
 
1219 1219
 			// Create an instance
1220 1220
 			$oModule = new $instance_name();
1221
-			if(!is_object($oModule))
1221
+			if (!is_object($oModule))
1222 1222
 			{
1223 1223
 				return NULL;
1224 1224
 			}
1225 1225
 
1226 1226
 			// Load language files for the class
1227
-			Context::loadLang($class_path . 'lang');
1228
-			if($extend_module)
1227
+			Context::loadLang($class_path.'lang');
1228
+			if ($extend_module)
1229 1229
 			{
1230
-				Context::loadLang(ModuleHandler::getModulePath($parent_module) . 'lang');
1230
+				Context::loadLang(ModuleHandler::getModulePath($parent_module).'lang');
1231 1231
 			}
1232 1232
 
1233 1233
 			// Set variables to the instance
@@ -1235,10 +1235,10 @@  discard block
 block discarded – undo
1235 1235
 			$oModule->setModulePath($class_path);
1236 1236
 
1237 1237
 			// If the module has a constructor, run it.
1238
-			if(!isset($GLOBALS['_called_constructor'][$instance_name]))
1238
+			if (!isset($GLOBALS['_called_constructor'][$instance_name]))
1239 1239
 			{
1240 1240
 				$GLOBALS['_called_constructor'][$instance_name] = TRUE;
1241
-				if(@method_exists($oModule, $instance_name))
1241
+				if (@method_exists($oModule, $instance_name))
1242 1242
 				{
1243 1243
 					$oModule->{$instance_name}();
1244 1244
 				}
@@ -1248,7 +1248,7 @@  discard block
 block discarded – undo
1248 1248
 			$GLOBALS['_loaded_module'][$module][$type][$kind] = $oModule;
1249 1249
 		}
1250 1250
 
1251
-		if(__DEBUG__ == 3)
1251
+		if (__DEBUG__ == 3)
1252 1252
 		{
1253 1253
 			$GLOBALS['__elapsed_class_load__'] += getMicroTime() - $start_time;
1254 1254
 		}
@@ -1264,17 +1264,17 @@  discard block
 block discarded – undo
1264 1264
 		$highClassFile = sprintf('%s%s%s.class.php', _XE_PATH_, $classPath, $module);
1265 1265
 		$highClassFile = FileHandler::getRealPath($highClassFile);
1266 1266
 
1267
-		$types = array('view','controller','model','api','wap','mobile','class');
1268
-		if(!in_array($type, $types))
1267
+		$types = array('view', 'controller', 'model', 'api', 'wap', 'mobile', 'class');
1268
+		if (!in_array($type, $types))
1269 1269
 		{
1270 1270
 			$type = $types[0];
1271 1271
 		}
1272
-		if($type == 'class')
1272
+		if ($type == 'class')
1273 1273
 		{
1274 1274
 			$instanceName = '%s';
1275 1275
 			$classFile = '%s%s.%s.php';
1276 1276
 		}
1277
-		elseif($kind == 'admin' && array_search($type, $types) < 3)
1277
+		elseif ($kind == 'admin' && array_search($type, $types) < 3)
1278 1278
 		{
1279 1279
 			$instanceName = '%sAdmin%s';
1280 1280
 			$classFile = '%s%s.admin.%s.php';
@@ -1299,26 +1299,26 @@  discard block
 block discarded – undo
1299 1299
 	function triggerCall($trigger_name, $called_position, &$obj)
1300 1300
 	{
1301 1301
 		// skip if not installed
1302
-		if(!Context::isInstalled())
1302
+		if (!Context::isInstalled())
1303 1303
 		{
1304 1304
 			return new BaseObject();
1305 1305
 		}
1306 1306
 
1307 1307
 		$oModuleModel = getModel('module');
1308 1308
 		$triggers = $oModuleModel->getTriggers($trigger_name, $called_position);
1309
-		if(!$triggers || count($triggers) < 1)
1309
+		if (!$triggers || count($triggers) < 1)
1310 1310
 		{
1311 1311
 			return new BaseObject();
1312 1312
 		}
1313 1313
 
1314 1314
 		//store before trigger call time
1315 1315
 		$before_trigger_time = NULL;
1316
-		if(__LOG_SLOW_TRIGGER__> 0)
1316
+		if (__LOG_SLOW_TRIGGER__ > 0)
1317 1317
 		{
1318 1318
 			$before_trigger_time = microtime(true);
1319 1319
 		}
1320 1320
 
1321
-		foreach($triggers as $item)
1321
+		foreach ($triggers as $item)
1322 1322
 		{
1323 1323
 			$module = $item->module;
1324 1324
 			$type = $item->type;
@@ -1326,7 +1326,7 @@  discard block
 block discarded – undo
1326 1326
 
1327 1327
 			// todo why don't we call a normal class object ?
1328 1328
 			$oModule = getModule($module, $type);
1329
-			if(!$oModule || !method_exists($oModule, $called_method))
1329
+			if (!$oModule || !method_exists($oModule, $called_method))
1330 1330
 			{
1331 1331
 				continue;
1332 1332
 			}
@@ -1339,12 +1339,12 @@  discard block
 block discarded – undo
1339 1339
 			$elapsed_time_trigger = $after_each_trigger_time - $before_each_trigger_time;
1340 1340
 
1341 1341
 			$slowlog = new stdClass;
1342
-			$slowlog->caller = $trigger_name . '.' . $called_position;
1343
-			$slowlog->called = $module . '.' . $called_method;
1342
+			$slowlog->caller = $trigger_name.'.'.$called_position;
1343
+			$slowlog->called = $module.'.'.$called_method;
1344 1344
 			$slowlog->called_extension = $module;
1345
-			if($trigger_name != 'XE.writeSlowlog') writeSlowlog('trigger', $elapsed_time_trigger, $slowlog);
1345
+			if ($trigger_name != 'XE.writeSlowlog') writeSlowlog('trigger', $elapsed_time_trigger, $slowlog);
1346 1346
 
1347
-			if(is_object($output) && method_exists($output, 'toBool') && !$output->toBool())
1347
+			if (is_object($output) && method_exists($output, 'toBool') && !$output->toBool())
1348 1348
 			{
1349 1349
 				return $output;
1350 1350
 			}
@@ -1429,9 +1429,9 @@  discard block
 block discarded – undo
1429 1429
 			'511' => 'Network Authentication Required',
1430 1430
 		);
1431 1431
 		$statusMessage = $statusMessageList[$code];
1432
-		if(!$statusMessage)
1432
+		if (!$statusMessage)
1433 1433
 		{
1434
-			$statusMessage = 'HTTP ' . $code;
1434
+			$statusMessage = 'HTTP '.$code;
1435 1435
 		}
1436 1436
 
1437 1437
 		Context::set('http_status_code', $code);
Please login to merge, or discard this patch.
classes/module/ModuleObject.class.php 3 patches
Doc Comments   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
 
142 142
 	/**
143 143
 	 * sett to set module information
144
-	 * @param object $module_info object containing module information
144
+	 * @param stdClass $module_info object containing module information
145 145
 	 * @param object $xml_info object containing module description
146 146
 	 * @return void
147 147
 	 * */
@@ -247,6 +247,7 @@  discard block
 block discarded – undo
247 247
 	/**
248 248
 	 * set the file name of the template file
249 249
 	 * @param string name of file
250
+	 * @param string $filename
250 251
 	 * @return void
251 252
 	 * */
252 253
 	function setTemplateFile($filename)
@@ -270,6 +271,7 @@  discard block
 block discarded – undo
270 271
 	/**
271 272
 	 * set the directory path of the template directory
272 273
 	 * @param string path of template directory.
274
+	 * @param string $path
273 275
 	 * @return void
274 276
 	 * */
275 277
 	function setTemplatePath($path)
@@ -325,6 +327,7 @@  discard block
 block discarded – undo
325 327
 	/**
326 328
 	 * set the file name of the layout file
327 329
 	 * @param string name of file
330
+	 * @param string $filename
328 331
 	 * @return void
329 332
 	 * */
330 333
 	function setLayoutFile($filename)
Please login to merge, or discard this patch.
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -44,9 +44,9 @@  discard block
 block discarded – undo
44 44
 	 * */
45 45
 	function setModulePath($path)
46 46
 	{
47
-		if(substr_compare($path, '/', -1) !== 0)
47
+		if (substr_compare($path, '/', -1) !== 0)
48 48
 		{
49
-			$path.='/';
49
+			$path .= '/';
50 50
 		}
51 51
 		$this->module_path = $path;
52 52
 	}
@@ -60,12 +60,12 @@  discard block
 block discarded – undo
60 60
 	function setRedirectUrl($url = './', $output = NULL)
61 61
 	{
62 62
 		$ajaxRequestMethod = array_flip($this->ajaxRequestMethod);
63
-		if(!isset($ajaxRequestMethod[Context::getRequestMethod()]))
63
+		if (!isset($ajaxRequestMethod[Context::getRequestMethod()]))
64 64
 		{
65 65
 			$this->add('redirect_url', $url);
66 66
 		}
67 67
 
68
-		if($output !== NULL && is_object($output))
68
+		if ($output !== NULL && is_object($output))
69 69
 		{
70 70
 			return $output;
71 71
 		}
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 	{
111 111
 		$type = $this->get('message_type');
112 112
 		$typeList = array('error' => 1, 'info' => 1, 'update' => 1);
113
-		if(!isset($typeList[$type]))
113
+		if (!isset($typeList[$type]))
114 114
 		{
115 115
 			$type = $this->getError() ? 'error' : 'info';
116 116
 		}
@@ -161,10 +161,10 @@  discard block
 block discarded – undo
161 161
 		$oModuleModel = getModel('module');
162 162
 		// permission settings. access, manager(== is_admin) are fixed and privilege name in XE
163 163
 		$module_srl = Context::get('module_srl');
164
-		if(!$module_info->mid && !is_array($module_srl) && preg_match('/^([0-9]+)$/', $module_srl))
164
+		if (!$module_info->mid && !is_array($module_srl) && preg_match('/^([0-9]+)$/', $module_srl))
165 165
 		{
166 166
 			$request_module = $oModuleModel->getModuleInfoByModuleSrl($module_srl);
167
-			if($request_module->module_srl == $module_srl)
167
+			if ($request_module->module_srl == $module_srl)
168 168
 			{
169 169
 				$grant = $oModuleModel->getGrant($request_module, $logged_info);
170 170
 			}
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
 		{
174 174
 			$grant = $oModuleModel->getGrant($module_info, $logged_info, $xml_info);
175 175
 			// have at least access grant
176
-			if(substr_count($this->act, 'Member') || substr_count($this->act, 'Communication'))
176
+			if (substr_count($this->act, 'Member') || substr_count($this->act, 'Communication'))
177 177
 			{
178 178
 				$grant->access = 1;
179 179
 			}
@@ -181,24 +181,24 @@  discard block
 block discarded – undo
181 181
 		// display no permission if the current module doesn't have an access privilege
182 182
 		//if(!$grant->access) return $this->stop("msg_not_permitted");
183 183
 		// checks permission and action if you don't have an admin privilege
184
-		if(!$grant->manager)
184
+		if (!$grant->manager)
185 185
 		{
186 186
 			// get permission types(guest, member, manager, root) of the currently requested action
187 187
 			$permission_target = $xml_info->permission->{$this->act};
188 188
 			// check manager if a permission in module.xml otherwise action if no permission
189
-			if(!$permission_target && substr_count($this->act, 'Admin'))
189
+			if (!$permission_target && substr_count($this->act, 'Admin'))
190 190
 			{
191 191
 				$permission_target = 'manager';
192 192
 			}
193 193
 			// Check permissions
194
-			switch($permission_target)
194
+			switch ($permission_target)
195 195
 			{
196 196
 				case 'root' :
197 197
 				case 'manager' :
198 198
 					$this->stop('msg_is_not_administrator');
199 199
 					return;
200 200
 				case 'member' :
201
-					if(!$is_logged)
201
+					if (!$is_logged)
202 202
 					{
203 203
 						$this->stop('msg_not_permitted_act');
204 204
 						return;
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
 
214 214
 		$this->module_config = $oModuleModel->getModuleConfig($this->module, $module_info->site_srl);
215 215
 
216
-		if(method_exists($this, 'init'))
216
+		if (method_exists($this, 'init'))
217 217
 		{
218 218
 			$this->init();
219 219
 		}
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
 	 * */
252 252
 	function setTemplateFile($filename)
253 253
 	{
254
-		if(isset($filename) && substr_compare($filename, '.html', -5) !== 0)
254
+		if (isset($filename) && substr_compare($filename, '.html', -5) !== 0)
255 255
 		{
256 256
 			$filename .= '.html';
257 257
 		}
@@ -274,14 +274,14 @@  discard block
 block discarded – undo
274 274
 	 * */
275 275
 	function setTemplatePath($path)
276 276
 	{
277
-		if(!$path) return;
277
+		if (!$path) return;
278 278
 
279
-		if((strlen($path) >= 1 && substr_compare($path, '/', 0, 1) !== 0) && (strlen($path) >= 2 && substr_compare($path, './', 0, 2) !== 0))
279
+		if ((strlen($path) >= 1 && substr_compare($path, '/', 0, 1) !== 0) && (strlen($path) >= 2 && substr_compare($path, './', 0, 2) !== 0))
280 280
 		{
281
-			$path = './' . $path;
281
+			$path = './'.$path;
282 282
 		}
283 283
 
284
-		if(substr_compare($path, '/', -1) !== 0)
284
+		if (substr_compare($path, '/', -1) !== 0)
285 285
 		{
286 286
 			$path .= '/';
287 287
 		}
@@ -304,9 +304,9 @@  discard block
 block discarded – undo
304 304
 	 * */
305 305
 	function setEditedLayoutFile($filename)
306 306
 	{
307
-		if(!$filename) return;
307
+		if (!$filename) return;
308 308
 
309
-		if(substr_compare($filename, '.html', -5) !== 0)
309
+		if (substr_compare($filename, '.html', -5) !== 0)
310 310
 		{
311 311
 			$filename .= '.html';
312 312
 		}
@@ -329,9 +329,9 @@  discard block
 block discarded – undo
329 329
 	 * */
330 330
 	function setLayoutFile($filename)
331 331
 	{
332
-		if(!$filename) return;
332
+		if (!$filename) return;
333 333
 
334
-		if(substr_compare($filename, '.html', -5) !== 0)
334
+		if (substr_compare($filename, '.html', -5) !== 0)
335 335
 		{
336 336
 			$filename .= '.html';
337 337
 		}
@@ -353,13 +353,13 @@  discard block
 block discarded – undo
353 353
 	 * */
354 354
 	function setLayoutPath($path)
355 355
 	{
356
-		if(!$path) return;
356
+		if (!$path) return;
357 357
 
358
-		if((strlen($path) >= 1 && substr_compare($path, '/', 0, 1) !== 0) && (strlen($path) >= 2 && substr_compare($path, './', 0, 2) !== 0))
358
+		if ((strlen($path) >= 1 && substr_compare($path, '/', 0, 1) !== 0) && (strlen($path) >= 2 && substr_compare($path, './', 0, 2) !== 0))
359 359
 		{
360
-			$path = './' . $path;
360
+			$path = './'.$path;
361 361
 		}
362
-		if(substr_compare($path, '/', -1) !== 0)
362
+		if (substr_compare($path, '/', -1) !== 0)
363 363
 		{
364 364
 			$path .= '/';
365 365
 		}
@@ -382,7 +382,7 @@  discard block
 block discarded – undo
382 382
 	function proc()
383 383
 	{
384 384
 		// pass if stop_proc is true
385
-		if($this->stop_proc)
385
+		if ($this->stop_proc)
386 386
 		{
387 387
 			debugPrint($this->message, 'ERROR');
388 388
 			return FALSE;
@@ -390,7 +390,7 @@  discard block
 block discarded – undo
390 390
 
391 391
 		// trigger call
392 392
 		$triggerOutput = ModuleHandler::triggerCall('moduleObject.proc', 'before', $this);
393
-		if(!$triggerOutput->toBool())
393
+		if (!$triggerOutput->toBool())
394 394
 		{
395 395
 			$this->setError($triggerOutput->getError());
396 396
 			$this->setMessage($triggerOutput->getMessage());
@@ -401,12 +401,12 @@  discard block
 block discarded – undo
401 401
 		$called_position = 'before_module_proc';
402 402
 		$oAddonController = getController('addon');
403 403
 		$addon_file = $oAddonController->getCacheFilePath(Mobile::isFromMobilePhone() ? "mobile" : "pc");
404
-		if(FileHandler::exists($addon_file)) include($addon_file);
404
+		if (FileHandler::exists($addon_file)) include($addon_file);
405 405
 
406
-		if(isset($this->xml_info->action->{$this->act}) && method_exists($this, $this->act))
406
+		if (isset($this->xml_info->action->{$this->act}) && method_exists($this, $this->act))
407 407
 		{
408 408
 			// Check permissions
409
-			if($this->module_srl && !$this->grant->access)
409
+			if ($this->module_srl && !$this->grant->access)
410 410
 			{
411 411
 				$this->stop("msg_not_permitted_act");
412 412
 				return FALSE;
@@ -415,21 +415,21 @@  discard block
 block discarded – undo
415 415
 			// integrate skin information of the module(change to sync skin info with the target module only by seperating its table)
416 416
 			$is_default_skin = ((!Mobile::isFromMobilePhone() && $this->module_info->is_skin_fix == 'N') || (Mobile::isFromMobilePhone() && $this->module_info->is_mskin_fix == 'N'));
417 417
 			$usedSkinModule = !($this->module == 'page' && ($this->module_info->page_type == 'OUTSIDE' || $this->module_info->page_type == 'WIDGET'));
418
-			if($usedSkinModule && $is_default_skin && $this->module != 'admin' && strpos($this->act, 'Admin') === false && $this->module == $this->module_info->module)
418
+			if ($usedSkinModule && $is_default_skin && $this->module != 'admin' && strpos($this->act, 'Admin') === false && $this->module == $this->module_info->module)
419 419
 			{
420 420
 				$dir = (Mobile::isFromMobilePhone()) ? 'm.skins' : 'skins';
421 421
 				$valueName = (Mobile::isFromMobilePhone()) ? 'mskin' : 'skin';
422 422
 				$oModuleModel = getModel('module');
423 423
 				$skinType = (Mobile::isFromMobilePhone()) ? 'M' : 'P';
424 424
 				$skinName = $oModuleModel->getModuleDefaultSkin($this->module, $skinType);
425
-				if($this->module == 'page')
425
+				if ($this->module == 'page')
426 426
 				{
427 427
 					$this->module_info->{$valueName} = $skinName;
428 428
 				}
429 429
 				else
430 430
 				{
431 431
 					$isTemplatPath = (strpos($this->getTemplatePath(), '/tpl/') !== FALSE);
432
-					if(!$isTemplatPath)
432
+					if (!$isTemplatPath)
433 433
 					{
434 434
 						$this->setTemplatePath(sprintf('%s%s/%s/', $this->module_path, $dir, $skinName));
435 435
 					}
@@ -449,7 +449,7 @@  discard block
 block discarded – undo
449 449
 
450 450
 		// trigger call
451 451
 		$triggerOutput = ModuleHandler::triggerCall('moduleObject.proc', 'after', $this);
452
-		if(!$triggerOutput->toBool())
452
+		if (!$triggerOutput->toBool())
453 453
 		{
454 454
 			$this->setError($triggerOutput->getError());
455 455
 			$this->setMessage($triggerOutput->getMessage());
@@ -460,25 +460,25 @@  discard block
 block discarded – undo
460 460
 		$called_position = 'after_module_proc';
461 461
 		$oAddonController = getController('addon');
462 462
 		$addon_file = $oAddonController->getCacheFilePath(Mobile::isFromMobilePhone() ? "mobile" : "pc");
463
-		if(FileHandler::exists($addon_file)) include($addon_file);
463
+		if (FileHandler::exists($addon_file)) include($addon_file);
464 464
 
465
-		if(is_a($output, 'BaseObject') || is_subclass_of($output, 'BaseObject'))
465
+		if (is_a($output, 'BaseObject') || is_subclass_of($output, 'BaseObject'))
466 466
 		{
467 467
 			$this->setError($output->getError());
468 468
 			$this->setMessage($output->getMessage());
469 469
 
470
-			if(!$output->toBool())
470
+			if (!$output->toBool())
471 471
 			{
472 472
 				return FALSE;
473 473
 			}
474 474
 		}
475 475
 		// execute api methods of the module if view action is and result is XMLRPC or JSON
476
-		if($this->module_info->module_type == 'view' || $this->module_info->module_type == 'mobile')
476
+		if ($this->module_info->module_type == 'view' || $this->module_info->module_type == 'mobile')
477 477
 		{
478
-			if(Context::getResponseMethod() == 'XMLRPC' || Context::getResponseMethod() == 'JSON')
478
+			if (Context::getResponseMethod() == 'XMLRPC' || Context::getResponseMethod() == 'JSON')
479 479
 			{
480 480
 				$oAPI = getAPI($this->module_info->module, 'api');
481
-				if(method_exists($oAPI, $this->act))
481
+				if (method_exists($oAPI, $this->act))
482 482
 				{
483 483
 					$oAPI->{$this->act}($this);
484 484
 				}
Please login to merge, or discard this patch.
Braces   +21 added lines, -12 removed lines patch added patch discarded remove patch
@@ -168,8 +168,7 @@  discard block
 block discarded – undo
168 168
 			{
169 169
 				$grant = $oModuleModel->getGrant($request_module, $logged_info);
170 170
 			}
171
-		}
172
-		else
171
+		} else
173 172
 		{
174 173
 			$grant = $oModuleModel->getGrant($module_info, $logged_info, $xml_info);
175 174
 			// have at least access grant
@@ -274,7 +273,9 @@  discard block
 block discarded – undo
274 273
 	 * */
275 274
 	function setTemplatePath($path)
276 275
 	{
277
-		if(!$path) return;
276
+		if(!$path) {
277
+			return;
278
+		}
278 279
 
279 280
 		if((strlen($path) >= 1 && substr_compare($path, '/', 0, 1) !== 0) && (strlen($path) >= 2 && substr_compare($path, './', 0, 2) !== 0))
280 281
 		{
@@ -304,7 +305,9 @@  discard block
 block discarded – undo
304 305
 	 * */
305 306
 	function setEditedLayoutFile($filename)
306 307
 	{
307
-		if(!$filename) return;
308
+		if(!$filename) {
309
+			return;
310
+		}
308 311
 
309 312
 		if(substr_compare($filename, '.html', -5) !== 0)
310 313
 		{
@@ -329,7 +332,9 @@  discard block
 block discarded – undo
329 332
 	 * */
330 333
 	function setLayoutFile($filename)
331 334
 	{
332
-		if(!$filename) return;
335
+		if(!$filename) {
336
+			return;
337
+		}
333 338
 
334 339
 		if(substr_compare($filename, '.html', -5) !== 0)
335 340
 		{
@@ -353,7 +358,9 @@  discard block
 block discarded – undo
353 358
 	 * */
354 359
 	function setLayoutPath($path)
355 360
 	{
356
-		if(!$path) return;
361
+		if(!$path) {
362
+			return;
363
+		}
357 364
 
358 365
 		if((strlen($path) >= 1 && substr_compare($path, '/', 0, 1) !== 0) && (strlen($path) >= 2 && substr_compare($path, './', 0, 2) !== 0))
359 366
 		{
@@ -401,7 +408,9 @@  discard block
 block discarded – undo
401 408
 		$called_position = 'before_module_proc';
402 409
 		$oAddonController = getController('addon');
403 410
 		$addon_file = $oAddonController->getCacheFilePath(Mobile::isFromMobilePhone() ? "mobile" : "pc");
404
-		if(FileHandler::exists($addon_file)) include($addon_file);
411
+		if(FileHandler::exists($addon_file)) {
412
+			include($addon_file);
413
+		}
405 414
 
406 415
 		if(isset($this->xml_info->action->{$this->act}) && method_exists($this, $this->act))
407 416
 		{
@@ -425,8 +434,7 @@  discard block
 block discarded – undo
425 434
 				if($this->module == 'page')
426 435
 				{
427 436
 					$this->module_info->{$valueName} = $skinName;
428
-				}
429
-				else
437
+				} else
430 438
 				{
431 439
 					$isTemplatPath = (strpos($this->getTemplatePath(), '/tpl/') !== FALSE);
432 440
 					if(!$isTemplatPath)
@@ -441,8 +449,7 @@  discard block
 block discarded – undo
441 449
 			Context::set('module_info', $this->module_info);
442 450
 			// Run
443 451
 			$output = $this->{$this->act}();
444
-		}
445
-		else
452
+		} else
446 453
 		{
447 454
 			return FALSE;
448 455
 		}
@@ -460,7 +467,9 @@  discard block
 block discarded – undo
460 467
 		$called_position = 'after_module_proc';
461 468
 		$oAddonController = getController('addon');
462 469
 		$addon_file = $oAddonController->getCacheFilePath(Mobile::isFromMobilePhone() ? "mobile" : "pc");
463
-		if(FileHandler::exists($addon_file)) include($addon_file);
470
+		if(FileHandler::exists($addon_file)) {
471
+			include($addon_file);
472
+		}
464 473
 
465 474
 		if(is_a($output, 'BaseObject') || is_subclass_of($output, 'BaseObject'))
466 475
 		{
Please login to merge, or discard this patch.
classes/security/EmbedFilter.class.php 3 patches
Doc Comments   +5 added lines, -4 removed lines patch added patch discarded remove patch
@@ -295,6 +295,7 @@  discard block
 block discarded – undo
295 295
 
296 296
 	/**
297 297
 	 * Check the content.
298
+	 * @param string $content
298 299
 	 * @return void
299 300
 	 */
300 301
 	function check(&$content)
@@ -487,7 +488,7 @@  discard block
 block discarded – undo
487 488
 
488 489
 	/**
489 490
 	 * Check white domain in object data attribute or embed src attribute.
490
-	 * @return string
491
+	 * @return boolean
491 492
 	 */
492 493
 	function isWhiteDomain($urlAttribute)
493 494
 	{
@@ -506,7 +507,7 @@  discard block
 block discarded – undo
506 507
 
507 508
 	/**
508 509
 	 * Check white domain in iframe src attribute.
509
-	 * @return string
510
+	 * @return boolean
510 511
 	 */
511 512
 	function isWhiteIframeDomain($urlAttribute)
512 513
 	{
@@ -525,7 +526,7 @@  discard block
 block discarded – undo
525 526
 
526 527
 	/**
527 528
 	 * Check white mime type in object type attribute or embed type attribute.
528
-	 * @return string
529
+	 * @return boolean
529 530
 	 */
530 531
 	function isWhiteMimetype($mimeType)
531 532
 	{
@@ -590,7 +591,7 @@  discard block
 block discarded – undo
590 591
 
591 592
 	/**
592 593
 	 * Make white domain list cache file from xml config file.
593
-	 * @param $whitelist array
594
+	 * @param stdClass $whitelist array
594 595
 	 * @return void
595 596
 	 */
596 597
 	function _makeWhiteDomainList($whitelist = NULL)
Please login to merge, or discard this patch.
Braces   +11 added lines, -12 removed lines patch added patch discarded remove patch
@@ -563,14 +563,12 @@  discard block
 block discarded – undo
563 563
 				}
564 564
 				$this->allowscriptaccessList[count($this->allowscriptaccessList) - 1]--;
565 565
 			}
566
-		}
567
-		else if($m[1] == 'embed')
566
+		} else if($m[1] == 'embed')
568 567
 		{
569 568
 			if(stripos($m[0], 'allowscriptaccess'))
570 569
 			{
571 570
 				$m[0] = preg_replace('/always|samedomain/i', 'never', $m[0]);
572
-			}
573
-			else
571
+			} else
574 572
 			{
575 573
 				$m[0] = preg_replace('/\<embed/i', '<embed allowscriptaccess="never"', $m[0]);
576 574
 			}
@@ -627,8 +625,7 @@  discard block
 block discarded – undo
627 625
 			{
628 626
 				$whiteUrlList = $whitelist->object;
629 627
 				$whiteIframeUrlList = $whitelist->iframe;
630
-			}
631
-			else
628
+			} else
632 629
 			{
633 630
 				$xmlBuff = FileHandler::readFile($this->whiteUrlXmlFile);
634 631
 
@@ -636,8 +633,12 @@  discard block
 block discarded – undo
636 633
 				$domainListObj = $xmlParser->parse($xmlBuff);
637 634
 				$embedDomainList = $domainListObj->whiteurl->embed->domain;
638 635
 				$iframeDomainList = $domainListObj->whiteurl->iframe->domain;
639
-				if(!is_array($embedDomainList)) $embedDomainList = array();
640
-				if(!is_array($iframeDomainList)) $iframeDomainList = array();
636
+				if(!is_array($embedDomainList)) {
637
+					$embedDomainList = array();
638
+				}
639
+				if(!is_array($iframeDomainList)) {
640
+					$iframeDomainList = array();
641
+				}
641 642
 
642 643
 				foreach($embedDomainList AS $key => $value)
643 644
 				{
@@ -648,8 +649,7 @@  discard block
 block discarded – undo
648 649
 						{
649 650
 							$whiteUrlList[] = $value->body;
650 651
 						}
651
-					}
652
-					else
652
+					} else
653 653
 					{
654 654
 						$whiteUrlList[] = $patternList->body;
655 655
 					}
@@ -664,8 +664,7 @@  discard block
 block discarded – undo
664 664
 						{
665 665
 							$whiteIframeUrlList[] = $value->body;
666 666
 						}
667
-					}
668
-					else
667
+					} else
669 668
 					{
670 669
 						$whiteIframeUrlList[] = $patternList->body;
671 670
 					}
Please login to merge, or discard this patch.
Spacing   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 /* Copyright (C) NAVER <http://www.navercorp.com> */
3 3
 
4
-include _XE_PATH_ . 'classes/security/phphtmlparser/src/htmlparser.inc';
4
+include _XE_PATH_.'classes/security/phphtmlparser/src/htmlparser.inc';
5 5
 
6 6
 class EmbedFilter
7 7
 {
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
 	 */
277 277
 	function getInstance()
278 278
 	{
279
-		if(!isset($GLOBALS['__EMBEDFILTER_INSTANCE__']))
279
+		if (!isset($GLOBALS['__EMBEDFILTER_INSTANCE__']))
280 280
 		{
281 281
 			$GLOBALS['__EMBEDFILTER_INSTANCE__'] = new EmbedFilter();
282 282
 		}
@@ -316,9 +316,9 @@  discard block
 block discarded – undo
316 316
 	{
317 317
 		preg_match_all('/<\s*object\s*[^>]+(?:\/?>?)/is', $content, $m);
318 318
 		$objectTagList = $m[0];
319
-		if($objectTagList)
319
+		if ($objectTagList)
320 320
 		{
321
-			foreach($objectTagList AS $key => $objectTag)
321
+			foreach ($objectTagList AS $key => $objectTag)
322 322
 			{
323 323
 				$isWhiteDomain = true;
324 324
 				$isWhiteMimetype = true;
@@ -326,21 +326,21 @@  discard block
 block discarded – undo
326 326
 				$ext = '';
327 327
 
328 328
 				$parser = new HtmlParser($objectTag);
329
-				while($parser->parse())
329
+				while ($parser->parse())
330 330
 				{
331
-					if(is_array($parser->iNodeAttributes))
331
+					if (is_array($parser->iNodeAttributes))
332 332
 					{
333
-						foreach($parser->iNodeAttributes AS $attrName => $attrValue)
333
+						foreach ($parser->iNodeAttributes AS $attrName => $attrValue)
334 334
 						{
335 335
 							// data url check
336
-							if($attrValue && strtolower($attrName) == 'data')
336
+							if ($attrValue && strtolower($attrName) == 'data')
337 337
 							{
338 338
 								$ext = strtolower(substr(strrchr($attrValue, "."), 1));
339 339
 								$isWhiteDomain = $this->isWhiteDomain($attrValue);
340 340
 							}
341 341
 
342 342
 							// mime type check
343
-							if(strtolower($attrName) == 'type' && $attrValue)
343
+							if (strtolower($attrName) == 'type' && $attrValue)
344 344
 							{
345 345
 								$isWhiteMimetype = $this->isWhiteMimetype($attrValue);
346 346
 							}
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
 					}
349 349
 				}
350 350
 
351
-				if(!$isWhiteDomain || !$isWhiteMimetype)
351
+				if (!$isWhiteDomain || !$isWhiteMimetype)
352 352
 				{
353 353
 					$content = str_replace($objectTag, htmlspecialchars($objectTag, ENT_COMPAT | ENT_HTML401, 'UTF-8', false), $content);
354 354
 				}
@@ -364,9 +364,9 @@  discard block
 block discarded – undo
364 364
 	{
365 365
 		preg_match_all('/<\s*embed\s*[^>]+(?:\/?>?)/is', $content, $m);
366 366
 		$embedTagList = $m[0];
367
-		if($embedTagList)
367
+		if ($embedTagList)
368 368
 		{
369
-			foreach($embedTagList AS $key => $embedTag)
369
+			foreach ($embedTagList AS $key => $embedTag)
370 370
 			{
371 371
 				$isWhiteDomain = TRUE;
372 372
 				$isWhiteMimetype = TRUE;
@@ -374,21 +374,21 @@  discard block
 block discarded – undo
374 374
 				$ext = '';
375 375
 
376 376
 				$parser = new HtmlParser($embedTag);
377
-				while($parser->parse())
377
+				while ($parser->parse())
378 378
 				{
379
-					if(is_array($parser->iNodeAttributes))
379
+					if (is_array($parser->iNodeAttributes))
380 380
 					{
381
-						foreach($parser->iNodeAttributes AS $attrName => $attrValue)
381
+						foreach ($parser->iNodeAttributes AS $attrName => $attrValue)
382 382
 						{
383 383
 							// src url check
384
-							if($attrValue && strtolower($attrName) == 'src')
384
+							if ($attrValue && strtolower($attrName) == 'src')
385 385
 							{
386 386
 								$ext = strtolower(substr(strrchr($attrValue, "."), 1));
387 387
 								$isWhiteDomain = $this->isWhiteDomain($attrValue);
388 388
 							}
389 389
 
390 390
 							// mime type check
391
-							if(strtolower($attrName) == 'type' && $attrValue)
391
+							if (strtolower($attrName) == 'type' && $attrValue)
392 392
 							{
393 393
 								$isWhiteMimetype = $this->isWhiteMimetype($attrValue);
394 394
 							}
@@ -396,7 +396,7 @@  discard block
 block discarded – undo
396 396
 					}
397 397
 				}
398 398
 
399
-				if(!$isWhiteDomain || !$isWhiteMimetype)
399
+				if (!$isWhiteDomain || !$isWhiteMimetype)
400 400
 				{
401 401
 					$content = str_replace($embedTag, htmlspecialchars($embedTag, ENT_COMPAT | ENT_HTML401, 'UTF-8', false), $content);
402 402
 				}
@@ -415,22 +415,22 @@  discard block
 block discarded – undo
415 415
 
416 416
 		preg_match_all('/<\s*iframe\s*[^>]+(?:\/?>?)/is', $content, $m);
417 417
 		$iframeTagList = $m[0];
418
-		if($iframeTagList)
418
+		if ($iframeTagList)
419 419
 		{
420
-			foreach($iframeTagList AS $key => $iframeTag)
420
+			foreach ($iframeTagList AS $key => $iframeTag)
421 421
 			{
422 422
 				$isWhiteDomain = TRUE;
423 423
 				$ext = '';
424 424
 
425 425
 				$parser = new HtmlParser($iframeTag);
426
-				while($parser->parse())
426
+				while ($parser->parse())
427 427
 				{
428
-					if(is_array($parser->iNodeAttributes))
428
+					if (is_array($parser->iNodeAttributes))
429 429
 					{
430
-						foreach($parser->iNodeAttributes AS $attrName => $attrValue)
430
+						foreach ($parser->iNodeAttributes AS $attrName => $attrValue)
431 431
 						{
432 432
 							// src url check
433
-							if(strtolower($attrName) == 'src' && $attrValue)
433
+							if (strtolower($attrName) == 'src' && $attrValue)
434 434
 							{
435 435
 								$ext = strtolower(substr(strrchr($attrValue, "."), 1));
436 436
 								$isWhiteDomain = $this->isWhiteIframeDomain($attrValue);
@@ -439,7 +439,7 @@  discard block
 block discarded – undo
439 439
 					}
440 440
 				}
441 441
 
442
-				if(!$isWhiteDomain)
442
+				if (!$isWhiteDomain)
443 443
 				{
444 444
 					$content = str_replace($iframeTag, htmlspecialchars($iframeTag, ENT_COMPAT | ENT_HTML401, 'UTF-8', false), $content);
445 445
 				}
@@ -455,26 +455,26 @@  discard block
 block discarded – undo
455 455
 	{
456 456
 		preg_match_all('/<\s*param\s*[^>]+(?:\/?>?)/is', $content, $m);
457 457
 		$paramTagList = $m[0];
458
-		if($paramTagList)
458
+		if ($paramTagList)
459 459
 		{
460
-			foreach($paramTagList AS $key => $paramTag)
460
+			foreach ($paramTagList AS $key => $paramTag)
461 461
 			{
462 462
 				$isWhiteDomain = TRUE;
463 463
 				$isWhiteExt = TRUE;
464 464
 				$ext = '';
465 465
 
466 466
 				$parser = new HtmlParser($paramTag);
467
-				while($parser->parse())
467
+				while ($parser->parse())
468 468
 				{
469
-					if($parser->iNodeAttributes['name'] && $parser->iNodeAttributes['value'])
469
+					if ($parser->iNodeAttributes['name'] && $parser->iNodeAttributes['value'])
470 470
 					{
471 471
 						$name = strtolower($parser->iNodeAttributes['name']);
472
-						if($name == 'movie' || $name == 'src' || $name == 'href' || $name == 'url' || $name == 'source')
472
+						if ($name == 'movie' || $name == 'src' || $name == 'href' || $name == 'url' || $name == 'source')
473 473
 						{
474 474
 							$ext = strtolower(substr(strrchr($parser->iNodeAttributes['value'], "."), 1));
475 475
 							$isWhiteDomain = $this->isWhiteDomain($parser->iNodeAttributes['value']);
476 476
 
477
-							if(!$isWhiteDomain)
477
+							if (!$isWhiteDomain)
478 478
 							{
479 479
 								$content = str_replace($paramTag, htmlspecialchars($paramTag, ENT_COMPAT | ENT_HTML401, 'UTF-8', false), $content);
480 480
 							}
@@ -491,11 +491,11 @@  discard block
 block discarded – undo
491 491
 	 */
492 492
 	function isWhiteDomain($urlAttribute)
493 493
 	{
494
-		if(is_array($this->whiteUrlList))
494
+		if (is_array($this->whiteUrlList))
495 495
 		{
496
-			foreach($this->whiteUrlList AS $key => $value)
496
+			foreach ($this->whiteUrlList AS $key => $value)
497 497
 			{
498
-				if(preg_match('@^' . preg_quote($value) . '@i', $urlAttribute))
498
+				if (preg_match('@^'.preg_quote($value).'@i', $urlAttribute))
499 499
 				{
500 500
 					return TRUE;
501 501
 				}
@@ -510,11 +510,11 @@  discard block
 block discarded – undo
510 510
 	 */
511 511
 	function isWhiteIframeDomain($urlAttribute)
512 512
 	{
513
-		if(is_array($this->whiteIframeUrlList))
513
+		if (is_array($this->whiteIframeUrlList))
514 514
 		{
515
-			foreach($this->whiteIframeUrlList AS $key => $value)
515
+			foreach ($this->whiteIframeUrlList AS $key => $value)
516 516
 			{
517
-				if(preg_match('@^' . preg_quote($value) . '@i', $urlAttribute))
517
+				if (preg_match('@^'.preg_quote($value).'@i', $urlAttribute))
518 518
 				{
519 519
 					return TRUE;
520 520
 				}
@@ -529,7 +529,7 @@  discard block
 block discarded – undo
529 529
 	 */
530 530
 	function isWhiteMimetype($mimeType)
531 531
 	{
532
-		if(isset($this->mimeTypeList[$mimeType]))
532
+		if (isset($this->mimeTypeList[$mimeType]))
533 533
 		{
534 534
 			return TRUE;
535 535
 		}
@@ -538,7 +538,7 @@  discard block
 block discarded – undo
538 538
 
539 539
 	function isWhiteExt($ext)
540 540
 	{
541
-		if(isset($this->extList[$ext]))
541
+		if (isset($this->extList[$ext]))
542 542
 		{
543 543
 			return TRUE;
544 544
 		}
@@ -547,26 +547,26 @@  discard block
 block discarded – undo
547 547
 
548 548
 	function _checkAllowScriptAccess($m)
549 549
 	{
550
-		if($m[1] == 'object')
550
+		if ($m[1] == 'object')
551 551
 		{
552 552
 			$this->allowscriptaccessList[] = 1;
553 553
 		}
554 554
 
555
-		if($m[1] == 'param')
555
+		if ($m[1] == 'param')
556 556
 		{
557
-			if(stripos($m[0], 'allowscriptaccess'))
557
+			if (stripos($m[0], 'allowscriptaccess'))
558 558
 			{
559 559
 				$m[0] = '<param name="allowscriptaccess" value="never"';
560
-				if(substr($m[0], -1) == '/')
560
+				if (substr($m[0], -1) == '/')
561 561
 				{
562 562
 					$m[0] .= '/';
563 563
 				}
564 564
 				$this->allowscriptaccessList[count($this->allowscriptaccessList) - 1]--;
565 565
 			}
566 566
 		}
567
-		else if($m[1] == 'embed')
567
+		else if ($m[1] == 'embed')
568 568
 		{
569
-			if(stripos($m[0], 'allowscriptaccess'))
569
+			if (stripos($m[0], 'allowscriptaccess'))
570 570
 			{
571 571
 				$m[0] = preg_replace('/always|samedomain/i', 'never', $m[0]);
572 572
 			}
@@ -580,9 +580,9 @@  discard block
 block discarded – undo
580 580
 
581 581
 	function _addAllowScriptAccess($m)
582 582
 	{
583
-		if($this->allowscriptaccessList[$this->allowscriptaccessKey] == 1)
583
+		if ($this->allowscriptaccessList[$this->allowscriptaccessKey] == 1)
584 584
 		{
585
-			$m[0] = $m[0] . '<param name="allowscriptaccess" value="never"></param>';
585
+			$m[0] = $m[0].'<param name="allowscriptaccess" value="never"></param>';
586 586
 		}
587 587
 		$this->allowscriptaccessKey++;
588 588
 		return $m[0];
@@ -599,31 +599,31 @@  discard block
 block discarded – undo
599 599
 		$whiteUrlCacheFile = FileHandler::getRealPath($this->whiteUrlCacheFile);
600 600
 
601 601
 		$isMake = FALSE;
602
-		if(!file_exists($whiteUrlCacheFile))
602
+		if (!file_exists($whiteUrlCacheFile))
603 603
 		{
604 604
 			$isMake = TRUE;
605 605
 		}
606
-		if(file_exists($whiteUrlCacheFile) && filemtime($whiteUrlCacheFile) < filemtime($whiteUrlXmlFile))
606
+		if (file_exists($whiteUrlCacheFile) && filemtime($whiteUrlCacheFile) < filemtime($whiteUrlXmlFile))
607 607
 		{
608 608
 			$isMake = TRUE;
609 609
 		}
610 610
 
611
-		if(gettype($whitelist) == 'array' && gettype($whitelist['object']) == 'array' && gettype($whitelist['iframe']) == 'array')
611
+		if (gettype($whitelist) == 'array' && gettype($whitelist['object']) == 'array' && gettype($whitelist['iframe']) == 'array')
612 612
 		{
613 613
 			$isMake = FALSE;
614 614
 		}
615 615
 
616
-		if(isset($whitelist) && gettype($whitelist) == 'object')
616
+		if (isset($whitelist) && gettype($whitelist) == 'object')
617 617
 		{
618 618
 			$isMake = TRUE;
619 619
 		}
620 620
 
621
-		if($isMake)
621
+		if ($isMake)
622 622
 		{
623 623
 			$whiteUrlList = array();
624 624
 			$whiteIframeUrlList = array();
625 625
 
626
-			if(gettype($whitelist->object) == 'array' && gettype($whitelist->iframe) == 'array')
626
+			if (gettype($whitelist->object) == 'array' && gettype($whitelist->iframe) == 'array')
627 627
 			{
628 628
 				$whiteUrlList = $whitelist->object;
629 629
 				$whiteIframeUrlList = $whitelist->iframe;
@@ -636,15 +636,15 @@  discard block
 block discarded – undo
636 636
 				$domainListObj = $xmlParser->parse($xmlBuff);
637 637
 				$embedDomainList = $domainListObj->whiteurl->embed->domain;
638 638
 				$iframeDomainList = $domainListObj->whiteurl->iframe->domain;
639
-				if(!is_array($embedDomainList)) $embedDomainList = array();
640
-				if(!is_array($iframeDomainList)) $iframeDomainList = array();
639
+				if (!is_array($embedDomainList)) $embedDomainList = array();
640
+				if (!is_array($iframeDomainList)) $iframeDomainList = array();
641 641
 
642
-				foreach($embedDomainList AS $key => $value)
642
+				foreach ($embedDomainList AS $key => $value)
643 643
 				{
644 644
 					$patternList = $value->pattern;
645
-					if(is_array($patternList))
645
+					if (is_array($patternList))
646 646
 					{
647
-						foreach($patternList AS $key => $value)
647
+						foreach ($patternList AS $key => $value)
648 648
 						{
649 649
 							$whiteUrlList[] = $value->body;
650 650
 						}
@@ -655,12 +655,12 @@  discard block
 block discarded – undo
655 655
 					}
656 656
 				}
657 657
 
658
-				foreach($iframeDomainList AS $key => $value)
658
+				foreach ($iframeDomainList AS $key => $value)
659 659
 				{
660 660
 					$patternList = $value->pattern;
661
-					if(is_array($patternList))
661
+					if (is_array($patternList))
662 662
 					{
663
-						foreach($patternList AS $key => $value)
663
+						foreach ($patternList AS $key => $value)
664 664
 						{
665 665
 							$whiteIframeUrlList[] = $value->body;
666 666
 						}
@@ -674,12 +674,12 @@  discard block
 block discarded – undo
674 674
 
675 675
 			$db_info = Context::getDBInfo();
676 676
 
677
-			if($db_info->embed_white_object)
677
+			if ($db_info->embed_white_object)
678 678
 			{
679 679
 				$whiteUrlList = array_merge($whiteUrlList, $db_info->embed_white_object);
680 680
 			}
681 681
 
682
-			if($db_info->embed_white_iframe)
682
+			if ($db_info->embed_white_iframe)
683 683
 			{
684 684
 				$whiteIframeUrlList = array_merge($whiteIframeUrlList, $db_info->embed_white_iframe);
685 685
 			}
@@ -691,8 +691,8 @@  discard block
 block discarded – undo
691 691
 
692 692
 			$buff = array();
693 693
 			$buff[] = '<?php if(!defined("__XE__")) exit();';
694
-			$buff[] = '$whiteUrlList = ' . var_export($whiteUrlList, TRUE) . ';';
695
-			$buff[] = '$whiteIframeUrlList = ' . var_export($whiteIframeUrlList, TRUE) . ';';
694
+			$buff[] = '$whiteUrlList = '.var_export($whiteUrlList, TRUE).';';
695
+			$buff[] = '$whiteIframeUrlList = '.var_export($whiteIframeUrlList, TRUE).';';
696 696
 
697 697
 			FileHandler::writeFile($this->whiteUrlCacheFile, implode(PHP_EOL, $buff));
698 698
 		}
Please login to merge, or discard this patch.
classes/security/htmlpurifier/library/HTMLPurifier/AttrDef/CSS/Length.php 3 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -11,6 +11,7 @@
 block discarded – undo
11 11
     /**
12 12
      * @param HTMLPurifier_Length $max Minimum length, or null for no bound. String is also acceptable.
13 13
      * @param HTMLPurifier_Length $max Maximum length, or null for no bound. String is also acceptable.
14
+     * @param string $min
14 15
      */
15 16
     public function __construct($min = null, $max = null) {
16 17
         $this->min = $min !== null ? HTMLPurifier_Length::make($min) : null;
Please login to merge, or discard this patch.
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -6,41 +6,41 @@
 block discarded – undo
6 6
 class HTMLPurifier_AttrDef_CSS_Length extends HTMLPurifier_AttrDef
7 7
 {
8 8
 
9
-    protected $min, $max;
10
-
11
-    /**
12
-     * @param HTMLPurifier_Length $max Minimum length, or null for no bound. String is also acceptable.
13
-     * @param HTMLPurifier_Length $max Maximum length, or null for no bound. String is also acceptable.
14
-     */
15
-    public function __construct($min = null, $max = null) {
16
-        $this->min = $min !== null ? HTMLPurifier_Length::make($min) : null;
17
-        $this->max = $max !== null ? HTMLPurifier_Length::make($max) : null;
18
-    }
19
-
20
-    public function validate($string, $config, $context) {
21
-        $string = $this->parseCDATA($string);
22
-
23
-        // Optimizations
24
-        if ($string === '') return false;
25
-        if ($string === '0') return '0';
26
-        if (strlen($string) === 1) return false;
27
-
28
-        $length = HTMLPurifier_Length::make($string);
29
-        if (!$length->isValid()) return false;
30
-
31
-        if ($this->min) {
32
-            $c = $length->compareTo($this->min);
33
-            if ($c === false) return false;
34
-            if ($c < 0) return false;
35
-        }
36
-        if ($this->max) {
37
-            $c = $length->compareTo($this->max);
38
-            if ($c === false) return false;
39
-            if ($c > 0) return false;
40
-        }
41
-
42
-        return $length->toString();
43
-    }
9
+	protected $min, $max;
10
+
11
+	/**
12
+	 * @param HTMLPurifier_Length $max Minimum length, or null for no bound. String is also acceptable.
13
+	 * @param HTMLPurifier_Length $max Maximum length, or null for no bound. String is also acceptable.
14
+	 */
15
+	public function __construct($min = null, $max = null) {
16
+		$this->min = $min !== null ? HTMLPurifier_Length::make($min) : null;
17
+		$this->max = $max !== null ? HTMLPurifier_Length::make($max) : null;
18
+	}
19
+
20
+	public function validate($string, $config, $context) {
21
+		$string = $this->parseCDATA($string);
22
+
23
+		// Optimizations
24
+		if ($string === '') return false;
25
+		if ($string === '0') return '0';
26
+		if (strlen($string) === 1) return false;
27
+
28
+		$length = HTMLPurifier_Length::make($string);
29
+		if (!$length->isValid()) return false;
30
+
31
+		if ($this->min) {
32
+			$c = $length->compareTo($this->min);
33
+			if ($c === false) return false;
34
+			if ($c < 0) return false;
35
+		}
36
+		if ($this->max) {
37
+			$c = $length->compareTo($this->max);
38
+			if ($c === false) return false;
39
+			if ($c > 0) return false;
40
+		}
41
+
42
+		return $length->toString();
43
+	}
44 44
 
45 45
 }
46 46
 
Please login to merge, or discard this patch.
Braces   +24 added lines, -8 removed lines patch added patch discarded remove patch
@@ -21,22 +21,38 @@
 block discarded – undo
21 21
         $string = $this->parseCDATA($string);
22 22
 
23 23
         // Optimizations
24
-        if ($string === '') return false;
25
-        if ($string === '0') return '0';
26
-        if (strlen($string) === 1) return false;
24
+        if ($string === '') {
25
+        	return false;
26
+        }
27
+        if ($string === '0') {
28
+        	return '0';
29
+        }
30
+        if (strlen($string) === 1) {
31
+        	return false;
32
+        }
27 33
 
28 34
         $length = HTMLPurifier_Length::make($string);
29
-        if (!$length->isValid()) return false;
35
+        if (!$length->isValid()) {
36
+        	return false;
37
+        }
30 38
 
31 39
         if ($this->min) {
32 40
             $c = $length->compareTo($this->min);
33
-            if ($c === false) return false;
34
-            if ($c < 0) return false;
41
+            if ($c === false) {
42
+            	return false;
43
+            }
44
+            if ($c < 0) {
45
+            	return false;
46
+            }
35 47
         }
36 48
         if ($this->max) {
37 49
             $c = $length->compareTo($this->max);
38
-            if ($c === false) return false;
39
-            if ($c > 0) return false;
50
+            if ($c === false) {
51
+            	return false;
52
+            }
53
+            if ($c > 0) {
54
+            	return false;
55
+            }
40 56
         }
41 57
 
42 58
         return $length->toString();
Please login to merge, or discard this patch.
classes/security/htmlpurifier/library/HTMLPurifier/AttrDef/URI/IPv6.php 4 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -9,6 +9,9 @@
 block discarded – undo
9 9
 class HTMLPurifier_AttrDef_URI_IPv6 extends HTMLPurifier_AttrDef_URI_IPv4
10 10
 {
11 11
 
12
+    /**
13
+     * @param string $aIP
14
+     */
12 15
     public function validate($aIP, $config, $context) {
13 16
 
14 17
         if (!$this->ip4) $this->_loadRegex();
Please login to merge, or discard this patch.
Indentation   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -9,90 +9,90 @@
 block discarded – undo
9 9
 class HTMLPurifier_AttrDef_URI_IPv6 extends HTMLPurifier_AttrDef_URI_IPv4
10 10
 {
11 11
 
12
-    public function validate($aIP, $config, $context) {
13
-
14
-        if (!$this->ip4) $this->_loadRegex();
15
-
16
-        $original = $aIP;
17
-
18
-        $hex = '[0-9a-fA-F]';
19
-        $blk = '(?:' . $hex . '{1,4})';
20
-        $pre = '(?:/(?:12[0-8]|1[0-1][0-9]|[1-9][0-9]|[0-9]))';   // /0 - /128
21
-
22
-        //      prefix check
23
-        if (strpos($aIP, '/') !== false)
24
-        {
25
-                if (preg_match('#' . $pre . '$#s', $aIP, $find))
26
-                {
27
-                        $aIP = substr($aIP, 0, 0-strlen($find[0]));
28
-                        unset($find);
29
-                }
30
-                else
31
-                {
32
-                        return false;
33
-                }
34
-        }
35
-
36
-        //      IPv4-compatiblity check
37
-        if (preg_match('#(?<=:'.')' . $this->ip4 . '$#s', $aIP, $find))
38
-        {
39
-                $aIP = substr($aIP, 0, 0-strlen($find[0]));
40
-                $ip = explode('.', $find[0]);
41
-                $ip = array_map('dechex', $ip);
42
-                $aIP .= $ip[0] . $ip[1] . ':' . $ip[2] . $ip[3];
43
-                unset($find, $ip);
44
-        }
45
-
46
-        //      compression check
47
-        $aIP = explode('::', $aIP);
48
-        $c = count($aIP);
49
-        if ($c > 2)
50
-        {
51
-                return false;
52
-        }
53
-        elseif ($c == 2)
54
-        {
55
-                list($first, $second) = $aIP;
56
-                $first = explode(':', $first);
57
-                $second = explode(':', $second);
58
-
59
-                if (count($first) + count($second) > 8)
60
-                {
61
-                        return false;
62
-                }
63
-
64
-                while(count($first) < 8)
65
-                {
66
-                        array_push($first, '0');
67
-                }
68
-
69
-                array_splice($first, 8 - count($second), 8, $second);
70
-                $aIP = $first;
71
-                unset($first,$second);
72
-        }
73
-        else
74
-        {
75
-                $aIP = explode(':', $aIP[0]);
76
-        }
77
-        $c = count($aIP);
78
-
79
-        if ($c != 8)
80
-        {
81
-                return false;
82
-        }
83
-
84
-        //      All the pieces should be 16-bit hex strings. Are they?
85
-        foreach ($aIP as $piece)
86
-        {
87
-                if (!preg_match('#^[0-9a-fA-F]{4}$#s', sprintf('%04s', $piece)))
88
-                {
89
-                        return false;
90
-                }
91
-        }
92
-
93
-        return $original;
94
-
95
-    }
12
+	public function validate($aIP, $config, $context) {
13
+
14
+		if (!$this->ip4) $this->_loadRegex();
15
+
16
+		$original = $aIP;
17
+
18
+		$hex = '[0-9a-fA-F]';
19
+		$blk = '(?:' . $hex . '{1,4})';
20
+		$pre = '(?:/(?:12[0-8]|1[0-1][0-9]|[1-9][0-9]|[0-9]))';   // /0 - /128
21
+
22
+		//      prefix check
23
+		if (strpos($aIP, '/') !== false)
24
+		{
25
+				if (preg_match('#' . $pre . '$#s', $aIP, $find))
26
+				{
27
+						$aIP = substr($aIP, 0, 0-strlen($find[0]));
28
+						unset($find);
29
+				}
30
+				else
31
+				{
32
+						return false;
33
+				}
34
+		}
35
+
36
+		//      IPv4-compatiblity check
37
+		if (preg_match('#(?<=:'.')' . $this->ip4 . '$#s', $aIP, $find))
38
+		{
39
+				$aIP = substr($aIP, 0, 0-strlen($find[0]));
40
+				$ip = explode('.', $find[0]);
41
+				$ip = array_map('dechex', $ip);
42
+				$aIP .= $ip[0] . $ip[1] . ':' . $ip[2] . $ip[3];
43
+				unset($find, $ip);
44
+		}
45
+
46
+		//      compression check
47
+		$aIP = explode('::', $aIP);
48
+		$c = count($aIP);
49
+		if ($c > 2)
50
+		{
51
+				return false;
52
+		}
53
+		elseif ($c == 2)
54
+		{
55
+				list($first, $second) = $aIP;
56
+				$first = explode(':', $first);
57
+				$second = explode(':', $second);
58
+
59
+				if (count($first) + count($second) > 8)
60
+				{
61
+						return false;
62
+				}
63
+
64
+				while(count($first) < 8)
65
+				{
66
+						array_push($first, '0');
67
+				}
68
+
69
+				array_splice($first, 8 - count($second), 8, $second);
70
+				$aIP = $first;
71
+				unset($first,$second);
72
+		}
73
+		else
74
+		{
75
+				$aIP = explode(':', $aIP[0]);
76
+		}
77
+		$c = count($aIP);
78
+
79
+		if ($c != 8)
80
+		{
81
+				return false;
82
+		}
83
+
84
+		//      All the pieces should be 16-bit hex strings. Are they?
85
+		foreach ($aIP as $piece)
86
+		{
87
+				if (!preg_match('#^[0-9a-fA-F]{4}$#s', sprintf('%04s', $piece)))
88
+				{
89
+						return false;
90
+				}
91
+		}
92
+
93
+		return $original;
94
+
95
+	}
96 96
 
97 97
 }
98 98
 
Please login to merge, or discard this patch.
Braces   +6 added lines, -7 removed lines patch added patch discarded remove patch
@@ -11,7 +11,9 @@  discard block
 block discarded – undo
11 11
 
12 12
     public function validate($aIP, $config, $context) {
13 13
 
14
-        if (!$this->ip4) $this->_loadRegex();
14
+        if (!$this->ip4) {
15
+        	$this->_loadRegex();
16
+        }
15 17
 
16 18
         $original = $aIP;
17 19
 
@@ -26,8 +28,7 @@  discard block
 block discarded – undo
26 28
                 {
27 29
                         $aIP = substr($aIP, 0, 0-strlen($find[0]));
28 30
                         unset($find);
29
-                }
30
-                else
31
+                } else
31 32
                 {
32 33
                         return false;
33 34
                 }
@@ -49,8 +50,7 @@  discard block
 block discarded – undo
49 50
         if ($c > 2)
50 51
         {
51 52
                 return false;
52
-        }
53
-        elseif ($c == 2)
53
+        } elseif ($c == 2)
54 54
         {
55 55
                 list($first, $second) = $aIP;
56 56
                 $first = explode(':', $first);
@@ -69,8 +69,7 @@  discard block
 block discarded – undo
69 69
                 array_splice($first, 8 - count($second), 8, $second);
70 70
                 $aIP = $first;
71 71
                 unset($first,$second);
72
-        }
73
-        else
72
+        } else
74 73
         {
75 74
                 $aIP = explode(':', $aIP[0]);
76 75
         }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -16,15 +16,15 @@  discard block
 block discarded – undo
16 16
         $original = $aIP;
17 17
 
18 18
         $hex = '[0-9a-fA-F]';
19
-        $blk = '(?:' . $hex . '{1,4})';
20
-        $pre = '(?:/(?:12[0-8]|1[0-1][0-9]|[1-9][0-9]|[0-9]))';   // /0 - /128
19
+        $blk = '(?:'.$hex.'{1,4})';
20
+        $pre = '(?:/(?:12[0-8]|1[0-1][0-9]|[1-9][0-9]|[0-9]))'; // /0 - /128
21 21
 
22 22
         //      prefix check
23 23
         if (strpos($aIP, '/') !== false)
24 24
         {
25
-                if (preg_match('#' . $pre . '$#s', $aIP, $find))
25
+                if (preg_match('#'.$pre.'$#s', $aIP, $find))
26 26
                 {
27
-                        $aIP = substr($aIP, 0, 0-strlen($find[0]));
27
+                        $aIP = substr($aIP, 0, 0 - strlen($find[0]));
28 28
                         unset($find);
29 29
                 }
30 30
                 else
@@ -34,12 +34,12 @@  discard block
 block discarded – undo
34 34
         }
35 35
 
36 36
         //      IPv4-compatiblity check
37
-        if (preg_match('#(?<=:'.')' . $this->ip4 . '$#s', $aIP, $find))
37
+        if (preg_match('#(?<=:'.')'.$this->ip4.'$#s', $aIP, $find))
38 38
         {
39
-                $aIP = substr($aIP, 0, 0-strlen($find[0]));
39
+                $aIP = substr($aIP, 0, 0 - strlen($find[0]));
40 40
                 $ip = explode('.', $find[0]);
41 41
                 $ip = array_map('dechex', $ip);
42
-                $aIP .= $ip[0] . $ip[1] . ':' . $ip[2] . $ip[3];
42
+                $aIP .= $ip[0].$ip[1].':'.$ip[2].$ip[3];
43 43
                 unset($find, $ip);
44 44
         }
45 45
 
@@ -61,14 +61,14 @@  discard block
 block discarded – undo
61 61
                         return false;
62 62
                 }
63 63
 
64
-                while(count($first) < 8)
64
+                while (count($first) < 8)
65 65
                 {
66 66
                         array_push($first, '0');
67 67
                 }
68 68
 
69 69
                 array_splice($first, 8 - count($second), 8, $second);
70 70
                 $aIP = $first;
71
-                unset($first,$second);
71
+                unset($first, $second);
72 72
         }
73 73
         else
74 74
         {
Please login to merge, or discard this patch.
classes/security/htmlpurifier/library/HTMLPurifier/DoctypeRegistry.php 4 patches
Doc Comments   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -17,10 +17,12 @@
 block discarded – undo
17 17
      * Registers a doctype to the registry
18 18
      * @note Accepts a fully-formed doctype object, or the
19 19
      *       parameters for constructing a doctype object
20
-     * @param $doctype Name of doctype or literal doctype object
20
+     * @param string $doctype Name of doctype or literal doctype object
21 21
      * @param $modules Modules doctype will load
22 22
      * @param $modules_for_modes Modules doctype will load for certain modes
23 23
      * @param $aliases Alias names for doctype
24
+     * @param string $dtd_public
25
+     * @param string $dtd_system
24 26
      * @return Editable registered doctype
25 27
      */
26 28
     public function register($doctype, $xml = true, $modules = array(),
Please login to merge, or discard this patch.
Indentation   +89 added lines, -89 removed lines patch added patch discarded remove patch
@@ -3,100 +3,100 @@
 block discarded – undo
3 3
 class HTMLPurifier_DoctypeRegistry
4 4
 {
5 5
 
6
-    /**
7
-     * Hash of doctype names to doctype objects
8
-     */
9
-    protected $doctypes;
6
+	/**
7
+	 * Hash of doctype names to doctype objects
8
+	 */
9
+	protected $doctypes;
10 10
 
11
-    /**
12
-     * Lookup table of aliases to real doctype names
13
-     */
14
-    protected $aliases;
11
+	/**
12
+	 * Lookup table of aliases to real doctype names
13
+	 */
14
+	protected $aliases;
15 15
 
16
-    /**
17
-     * Registers a doctype to the registry
18
-     * @note Accepts a fully-formed doctype object, or the
19
-     *       parameters for constructing a doctype object
20
-     * @param $doctype Name of doctype or literal doctype object
21
-     * @param $modules Modules doctype will load
22
-     * @param $modules_for_modes Modules doctype will load for certain modes
23
-     * @param $aliases Alias names for doctype
24
-     * @return Editable registered doctype
25
-     */
26
-    public function register($doctype, $xml = true, $modules = array(),
27
-        $tidy_modules = array(), $aliases = array(), $dtd_public = null, $dtd_system = null
28
-    ) {
29
-        if (!is_array($modules)) $modules = array($modules);
30
-        if (!is_array($tidy_modules)) $tidy_modules = array($tidy_modules);
31
-        if (!is_array($aliases)) $aliases = array($aliases);
32
-        if (!is_object($doctype)) {
33
-            $doctype = new HTMLPurifier_Doctype(
34
-                $doctype, $xml, $modules, $tidy_modules, $aliases, $dtd_public, $dtd_system
35
-            );
36
-        }
37
-        $this->doctypes[$doctype->name] = $doctype;
38
-        $name = $doctype->name;
39
-        // hookup aliases
40
-        foreach ($doctype->aliases as $alias) {
41
-            if (isset($this->doctypes[$alias])) continue;
42
-            $this->aliases[$alias] = $name;
43
-        }
44
-        // remove old aliases
45
-        if (isset($this->aliases[$name])) unset($this->aliases[$name]);
46
-        return $doctype;
47
-    }
16
+	/**
17
+	 * Registers a doctype to the registry
18
+	 * @note Accepts a fully-formed doctype object, or the
19
+	 *       parameters for constructing a doctype object
20
+	 * @param $doctype Name of doctype or literal doctype object
21
+	 * @param $modules Modules doctype will load
22
+	 * @param $modules_for_modes Modules doctype will load for certain modes
23
+	 * @param $aliases Alias names for doctype
24
+	 * @return Editable registered doctype
25
+	 */
26
+	public function register($doctype, $xml = true, $modules = array(),
27
+		$tidy_modules = array(), $aliases = array(), $dtd_public = null, $dtd_system = null
28
+	) {
29
+		if (!is_array($modules)) $modules = array($modules);
30
+		if (!is_array($tidy_modules)) $tidy_modules = array($tidy_modules);
31
+		if (!is_array($aliases)) $aliases = array($aliases);
32
+		if (!is_object($doctype)) {
33
+			$doctype = new HTMLPurifier_Doctype(
34
+				$doctype, $xml, $modules, $tidy_modules, $aliases, $dtd_public, $dtd_system
35
+			);
36
+		}
37
+		$this->doctypes[$doctype->name] = $doctype;
38
+		$name = $doctype->name;
39
+		// hookup aliases
40
+		foreach ($doctype->aliases as $alias) {
41
+			if (isset($this->doctypes[$alias])) continue;
42
+			$this->aliases[$alias] = $name;
43
+		}
44
+		// remove old aliases
45
+		if (isset($this->aliases[$name])) unset($this->aliases[$name]);
46
+		return $doctype;
47
+	}
48 48
 
49
-    /**
50
-     * Retrieves reference to a doctype of a certain name
51
-     * @note This function resolves aliases
52
-     * @note When possible, use the more fully-featured make()
53
-     * @param $doctype Name of doctype
54
-     * @return Editable doctype object
55
-     */
56
-    public function get($doctype) {
57
-        if (isset($this->aliases[$doctype])) $doctype = $this->aliases[$doctype];
58
-        if (!isset($this->doctypes[$doctype])) {
59
-            trigger_error('Doctype ' . htmlspecialchars($doctype, ENT_COMPAT | ENT_HTML401, 'UTF-8', false) . ' does not exist', E_USER_ERROR);
60
-            $anon = new HTMLPurifier_Doctype($doctype);
61
-            return $anon;
62
-        }
63
-        return $this->doctypes[$doctype];
64
-    }
49
+	/**
50
+	 * Retrieves reference to a doctype of a certain name
51
+	 * @note This function resolves aliases
52
+	 * @note When possible, use the more fully-featured make()
53
+	 * @param $doctype Name of doctype
54
+	 * @return Editable doctype object
55
+	 */
56
+	public function get($doctype) {
57
+		if (isset($this->aliases[$doctype])) $doctype = $this->aliases[$doctype];
58
+		if (!isset($this->doctypes[$doctype])) {
59
+			trigger_error('Doctype ' . htmlspecialchars($doctype, ENT_COMPAT | ENT_HTML401, 'UTF-8', false) . ' does not exist', E_USER_ERROR);
60
+			$anon = new HTMLPurifier_Doctype($doctype);
61
+			return $anon;
62
+		}
63
+		return $this->doctypes[$doctype];
64
+	}
65 65
 
66
-    /**
67
-     * Creates a doctype based on a configuration object,
68
-     * will perform initialization on the doctype
69
-     * @note Use this function to get a copy of doctype that config
70
-     *       can hold on to (this is necessary in order to tell
71
-     *       Generator whether or not the current document is XML
72
-     *       based or not).
73
-     */
74
-    public function make($config) {
75
-        return clone $this->get($this->getDoctypeFromConfig($config));
76
-    }
66
+	/**
67
+	 * Creates a doctype based on a configuration object,
68
+	 * will perform initialization on the doctype
69
+	 * @note Use this function to get a copy of doctype that config
70
+	 *       can hold on to (this is necessary in order to tell
71
+	 *       Generator whether or not the current document is XML
72
+	 *       based or not).
73
+	 */
74
+	public function make($config) {
75
+		return clone $this->get($this->getDoctypeFromConfig($config));
76
+	}
77 77
 
78
-    /**
79
-     * Retrieves the doctype from the configuration object
80
-     */
81
-    public function getDoctypeFromConfig($config) {
82
-        // recommended test
83
-        $doctype = $config->get('HTML.Doctype');
84
-        if (!empty($doctype)) return $doctype;
85
-        $doctype = $config->get('HTML.CustomDoctype');
86
-        if (!empty($doctype)) return $doctype;
87
-        // backwards-compatibility
88
-        if ($config->get('HTML.XHTML')) {
89
-            $doctype = 'XHTML 1.0';
90
-        } else {
91
-            $doctype = 'HTML 4.01';
92
-        }
93
-        if ($config->get('HTML.Strict')) {
94
-            $doctype .= ' Strict';
95
-        } else {
96
-            $doctype .= ' Transitional';
97
-        }
98
-        return $doctype;
99
-    }
78
+	/**
79
+	 * Retrieves the doctype from the configuration object
80
+	 */
81
+	public function getDoctypeFromConfig($config) {
82
+		// recommended test
83
+		$doctype = $config->get('HTML.Doctype');
84
+		if (!empty($doctype)) return $doctype;
85
+		$doctype = $config->get('HTML.CustomDoctype');
86
+		if (!empty($doctype)) return $doctype;
87
+		// backwards-compatibility
88
+		if ($config->get('HTML.XHTML')) {
89
+			$doctype = 'XHTML 1.0';
90
+		} else {
91
+			$doctype = 'HTML 4.01';
92
+		}
93
+		if ($config->get('HTML.Strict')) {
94
+			$doctype .= ' Strict';
95
+		} else {
96
+			$doctype .= ' Transitional';
97
+		}
98
+		return $doctype;
99
+	}
100 100
 
101 101
 }
102 102
 
Please login to merge, or discard this patch.
Braces   +24 added lines, -8 removed lines patch added patch discarded remove patch
@@ -26,9 +26,15 @@  discard block
 block discarded – undo
26 26
     public function register($doctype, $xml = true, $modules = array(),
27 27
         $tidy_modules = array(), $aliases = array(), $dtd_public = null, $dtd_system = null
28 28
     ) {
29
-        if (!is_array($modules)) $modules = array($modules);
30
-        if (!is_array($tidy_modules)) $tidy_modules = array($tidy_modules);
31
-        if (!is_array($aliases)) $aliases = array($aliases);
29
+        if (!is_array($modules)) {
30
+        	$modules = array($modules);
31
+        }
32
+        if (!is_array($tidy_modules)) {
33
+        	$tidy_modules = array($tidy_modules);
34
+        }
35
+        if (!is_array($aliases)) {
36
+        	$aliases = array($aliases);
37
+        }
32 38
         if (!is_object($doctype)) {
33 39
             $doctype = new HTMLPurifier_Doctype(
34 40
                 $doctype, $xml, $modules, $tidy_modules, $aliases, $dtd_public, $dtd_system
@@ -38,11 +44,15 @@  discard block
 block discarded – undo
38 44
         $name = $doctype->name;
39 45
         // hookup aliases
40 46
         foreach ($doctype->aliases as $alias) {
41
-            if (isset($this->doctypes[$alias])) continue;
47
+            if (isset($this->doctypes[$alias])) {
48
+            	continue;
49
+            }
42 50
             $this->aliases[$alias] = $name;
43 51
         }
44 52
         // remove old aliases
45
-        if (isset($this->aliases[$name])) unset($this->aliases[$name]);
53
+        if (isset($this->aliases[$name])) {
54
+        	unset($this->aliases[$name]);
55
+        }
46 56
         return $doctype;
47 57
     }
48 58
 
@@ -54,7 +64,9 @@  discard block
 block discarded – undo
54 64
      * @return Editable doctype object
55 65
      */
56 66
     public function get($doctype) {
57
-        if (isset($this->aliases[$doctype])) $doctype = $this->aliases[$doctype];
67
+        if (isset($this->aliases[$doctype])) {
68
+        	$doctype = $this->aliases[$doctype];
69
+        }
58 70
         if (!isset($this->doctypes[$doctype])) {
59 71
             trigger_error('Doctype ' . htmlspecialchars($doctype, ENT_COMPAT | ENT_HTML401, 'UTF-8', false) . ' does not exist', E_USER_ERROR);
60 72
             $anon = new HTMLPurifier_Doctype($doctype);
@@ -81,9 +93,13 @@  discard block
 block discarded – undo
81 93
     public function getDoctypeFromConfig($config) {
82 94
         // recommended test
83 95
         $doctype = $config->get('HTML.Doctype');
84
-        if (!empty($doctype)) return $doctype;
96
+        if (!empty($doctype)) {
97
+        	return $doctype;
98
+        }
85 99
         $doctype = $config->get('HTML.CustomDoctype');
86
-        if (!empty($doctype)) return $doctype;
100
+        if (!empty($doctype)) {
101
+        	return $doctype;
102
+        }
87 103
         // backwards-compatibility
88 104
         if ($config->get('HTML.XHTML')) {
89 105
             $doctype = 'XHTML 1.0';
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -56,7 +56,7 @@
 block discarded – undo
56 56
     public function get($doctype) {
57 57
         if (isset($this->aliases[$doctype])) $doctype = $this->aliases[$doctype];
58 58
         if (!isset($this->doctypes[$doctype])) {
59
-            trigger_error('Doctype ' . htmlspecialchars($doctype, ENT_COMPAT | ENT_HTML401, 'UTF-8', false) . ' does not exist', E_USER_ERROR);
59
+            trigger_error('Doctype '.htmlspecialchars($doctype, ENT_COMPAT | ENT_HTML401, 'UTF-8', false).' does not exist', E_USER_ERROR);
60 60
             $anon = new HTMLPurifier_Doctype($doctype);
61 61
             return $anon;
62 62
         }
Please login to merge, or discard this patch.
classes/security/htmlpurifier/library/HTMLPurifier/Encoder.php 4 patches
Doc Comments   +5 added lines patch added patch discarded remove patch
@@ -31,6 +31,9 @@  discard block
 block discarded – undo
31 31
 
32 32
     /**
33 33
      * iconv wrapper which mutes errors and works around bugs.
34
+     * @param string $in
35
+     * @param string $out
36
+     * @param string $text
34 37
      */
35 38
     public static function iconv($in, $out, $text, $max_chunk_size = 8000) {
36 39
         $code = self::testIconvTruncateBug();
@@ -332,6 +335,7 @@  discard block
 block discarded – undo
332 335
 
333 336
     /**
334 337
      * Converts a string to UTF-8 based on configuration.
338
+     * @param HTMLPurifier_Context $context
335 339
      */
336 340
     public static function convertToUTF8($str, $config, $context) {
337 341
         $encoding = $config->get('Core.Encoding');
@@ -362,6 +366,7 @@  discard block
 block discarded – undo
362 366
      * Converts a string from UTF-8 based on configuration.
363 367
      * @note Currently, this is a lossy conversion, with unexpressable
364 368
      *       characters being omitted.
369
+     * @param HTMLPurifier_Context $context
365 370
      */
366 371
     public static function convertFromUTF8($str, $config, $context) {
367 372
         $encoding = $config->get('Core.Encoding');
Please login to merge, or discard this patch.
Indentation   +526 added lines, -526 removed lines patch added patch discarded remove patch
@@ -7,532 +7,532 @@
 block discarded – undo
7 7
 class HTMLPurifier_Encoder
8 8
 {
9 9
 
10
-    /**
11
-     * Constructor throws fatal error if you attempt to instantiate class
12
-     */
13
-    private function __construct() {
14
-        trigger_error('Cannot instantiate encoder, call methods statically', E_USER_ERROR);
15
-    }
16
-
17
-    /**
18
-     * Error-handler that mutes errors, alternative to shut-up operator.
19
-     */
20
-    public static function muteErrorHandler() {}
21
-
22
-    /**
23
-     * iconv wrapper which mutes errors, but doesn't work around bugs.
24
-     */
25
-    public static function unsafeIconv($in, $out, $text) {
26
-        set_error_handler(array('HTMLPurifier_Encoder', 'muteErrorHandler'));
27
-        $r = iconv($in, $out, $text);
28
-        restore_error_handler();
29
-        return $r;
30
-    }
31
-
32
-    /**
33
-     * iconv wrapper which mutes errors and works around bugs.
34
-     */
35
-    public static function iconv($in, $out, $text, $max_chunk_size = 8000) {
36
-        $code = self::testIconvTruncateBug();
37
-        if ($code == self::ICONV_OK) {
38
-            return self::unsafeIconv($in, $out, $text);
39
-        } elseif ($code == self::ICONV_TRUNCATES) {
40
-            // we can only work around this if the input character set
41
-            // is utf-8
42
-            if ($in == 'utf-8') {
43
-                if ($max_chunk_size < 4) {
44
-                    trigger_error('max_chunk_size is too small', E_USER_WARNING);
45
-                    return false;
46
-                }
47
-                // split into 8000 byte chunks, but be careful to handle
48
-                // multibyte boundaries properly
49
-                if (($c = strlen($text)) <= $max_chunk_size) {
50
-                    return self::unsafeIconv($in, $out, $text);
51
-                }
52
-                $r = '';
53
-                $i = 0;
54
-                while (true) {
55
-                    if ($i + $max_chunk_size >= $c) {
56
-                        $r .= self::unsafeIconv($in, $out, substr($text, $i));
57
-                        break;
58
-                    }
59
-                    // wibble the boundary
60
-                    if (0x80 != (0xC0 & ord($text[$i + $max_chunk_size]))) {
61
-                        $chunk_size = $max_chunk_size;
62
-                    } elseif (0x80 != (0xC0 & ord($text[$i + $max_chunk_size - 1]))) {
63
-                        $chunk_size = $max_chunk_size - 1;
64
-                    } elseif (0x80 != (0xC0 & ord($text[$i + $max_chunk_size - 2]))) {
65
-                        $chunk_size = $max_chunk_size - 2;
66
-                    } elseif (0x80 != (0xC0 & ord($text[$i + $max_chunk_size - 3]))) {
67
-                        $chunk_size = $max_chunk_size - 3;
68
-                    } else {
69
-                        return false; // rather confusing UTF-8...
70
-                    }
71
-                    $chunk = substr($text, $i, $chunk_size); // substr doesn't mind overlong lengths
72
-                    $r .= self::unsafeIconv($in, $out, $chunk);
73
-                    $i += $chunk_size;
74
-                }
75
-                return $r;
76
-            } else {
77
-                return false;
78
-            }
79
-        } else {
80
-            return false;
81
-        }
82
-    }
83
-
84
-    /**
85
-     * Cleans a UTF-8 string for well-formedness and SGML validity
86
-     *
87
-     * It will parse according to UTF-8 and return a valid UTF8 string, with
88
-     * non-SGML codepoints excluded.
89
-     *
90
-     * @note Just for reference, the non-SGML code points are 0 to 31 and
91
-     *       127 to 159, inclusive.  However, we allow code points 9, 10
92
-     *       and 13, which are the tab, line feed and carriage return
93
-     *       respectively. 128 and above the code points map to multibyte
94
-     *       UTF-8 representations.
95
-     *
96
-     * @note Fallback code adapted from utf8ToUnicode by Henri Sivonen and
97
-     *       [email protected] at <http://iki.fi/hsivonen/php-utf8/> under the
98
-     *       LGPL license.  Notes on what changed are inside, but in general,
99
-     *       the original code transformed UTF-8 text into an array of integer
100
-     *       Unicode codepoints. Understandably, transforming that back to
101
-     *       a string would be somewhat expensive, so the function was modded to
102
-     *       directly operate on the string.  However, this discourages code
103
-     *       reuse, and the logic enumerated here would be useful for any
104
-     *       function that needs to be able to understand UTF-8 characters.
105
-     *       As of right now, only smart lossless character encoding converters
106
-     *       would need that, and I'm probably not going to implement them.
107
-     *       Once again, PHP 6 should solve all our problems.
108
-     */
109
-    public static function cleanUTF8($str, $force_php = false) {
110
-
111
-        // UTF-8 validity is checked since PHP 4.3.5
112
-        // This is an optimization: if the string is already valid UTF-8, no
113
-        // need to do PHP stuff. 99% of the time, this will be the case.
114
-        // The regexp matches the XML char production, as well as well as excluding
115
-        // non-SGML codepoints U+007F to U+009F
116
-        if (preg_match('/^[\x{9}\x{A}\x{D}\x{20}-\x{7E}\x{A0}-\x{D7FF}\x{E000}-\x{FFFD}\x{10000}-\x{10FFFF}]*$/Du', $str)) {
117
-            return $str;
118
-        }
119
-
120
-        $mState = 0; // cached expected number of octets after the current octet
121
-                     // until the beginning of the next UTF8 character sequence
122
-        $mUcs4  = 0; // cached Unicode character
123
-        $mBytes = 1; // cached expected number of octets in the current sequence
124
-
125
-        // original code involved an $out that was an array of Unicode
126
-        // codepoints.  Instead of having to convert back into UTF-8, we've
127
-        // decided to directly append valid UTF-8 characters onto a string
128
-        // $out once they're done.  $char accumulates raw bytes, while $mUcs4
129
-        // turns into the Unicode code point, so there's some redundancy.
130
-
131
-        $out = '';
132
-        $char = '';
133
-
134
-        $len = strlen($str);
135
-        for($i = 0; $i < $len; $i++) {
136
-            $in = ord($str{$i});
137
-            $char .= $str[$i]; // append byte to char
138
-            if (0 == $mState) {
139
-                // When mState is zero we expect either a US-ASCII character
140
-                // or a multi-octet sequence.
141
-                if (0 == (0x80 & ($in))) {
142
-                    // US-ASCII, pass straight through.
143
-                    if (($in <= 31 || $in == 127) &&
144
-                        !($in == 9 || $in == 13 || $in == 10) // save \r\t\n
145
-                    ) {
146
-                        // control characters, remove
147
-                    } else {
148
-                        $out .= $char;
149
-                    }
150
-                    // reset
151
-                    $char = '';
152
-                    $mBytes = 1;
153
-                } elseif (0xC0 == (0xE0 & ($in))) {
154
-                    // First octet of 2 octet sequence
155
-                    $mUcs4 = ($in);
156
-                    $mUcs4 = ($mUcs4 & 0x1F) << 6;
157
-                    $mState = 1;
158
-                    $mBytes = 2;
159
-                } elseif (0xE0 == (0xF0 & ($in))) {
160
-                    // First octet of 3 octet sequence
161
-                    $mUcs4 = ($in);
162
-                    $mUcs4 = ($mUcs4 & 0x0F) << 12;
163
-                    $mState = 2;
164
-                    $mBytes = 3;
165
-                } elseif (0xF0 == (0xF8 & ($in))) {
166
-                    // First octet of 4 octet sequence
167
-                    $mUcs4 = ($in);
168
-                    $mUcs4 = ($mUcs4 & 0x07) << 18;
169
-                    $mState = 3;
170
-                    $mBytes = 4;
171
-                } elseif (0xF8 == (0xFC & ($in))) {
172
-                    // First octet of 5 octet sequence.
173
-                    //
174
-                    // This is illegal because the encoded codepoint must be
175
-                    // either:
176
-                    // (a) not the shortest form or
177
-                    // (b) outside the Unicode range of 0-0x10FFFF.
178
-                    // Rather than trying to resynchronize, we will carry on
179
-                    // until the end of the sequence and let the later error
180
-                    // handling code catch it.
181
-                    $mUcs4 = ($in);
182
-                    $mUcs4 = ($mUcs4 & 0x03) << 24;
183
-                    $mState = 4;
184
-                    $mBytes = 5;
185
-                } elseif (0xFC == (0xFE & ($in))) {
186
-                    // First octet of 6 octet sequence, see comments for 5
187
-                    // octet sequence.
188
-                    $mUcs4 = ($in);
189
-                    $mUcs4 = ($mUcs4 & 1) << 30;
190
-                    $mState = 5;
191
-                    $mBytes = 6;
192
-                } else {
193
-                    // Current octet is neither in the US-ASCII range nor a
194
-                    // legal first octet of a multi-octet sequence.
195
-                    $mState = 0;
196
-                    $mUcs4  = 0;
197
-                    $mBytes = 1;
198
-                    $char = '';
199
-                }
200
-            } else {
201
-                // When mState is non-zero, we expect a continuation of the
202
-                // multi-octet sequence
203
-                if (0x80 == (0xC0 & ($in))) {
204
-                    // Legal continuation.
205
-                    $shift = ($mState - 1) * 6;
206
-                    $tmp = $in;
207
-                    $tmp = ($tmp & 0x0000003F) << $shift;
208
-                    $mUcs4 |= $tmp;
209
-
210
-                    if (0 == --$mState) {
211
-                        // End of the multi-octet sequence. mUcs4 now contains
212
-                        // the final Unicode codepoint to be output
213
-
214
-                        // Check for illegal sequences and codepoints.
215
-
216
-                        // From Unicode 3.1, non-shortest form is illegal
217
-                        if (((2 == $mBytes) && ($mUcs4 < 0x0080)) ||
218
-                            ((3 == $mBytes) && ($mUcs4 < 0x0800)) ||
219
-                            ((4 == $mBytes) && ($mUcs4 < 0x10000)) ||
220
-                            (4 < $mBytes) ||
221
-                            // From Unicode 3.2, surrogate characters = illegal
222
-                            (($mUcs4 & 0xFFFFF800) == 0xD800) ||
223
-                            // Codepoints outside the Unicode range are illegal
224
-                            ($mUcs4 > 0x10FFFF)
225
-                        ) {
226
-
227
-                        } elseif (0xFEFF != $mUcs4 && // omit BOM
228
-                            // check for valid Char unicode codepoints
229
-                            (
230
-                                0x9 == $mUcs4 ||
231
-                                0xA == $mUcs4 ||
232
-                                0xD == $mUcs4 ||
233
-                                (0x20 <= $mUcs4 && 0x7E >= $mUcs4) ||
234
-                                // 7F-9F is not strictly prohibited by XML,
235
-                                // but it is non-SGML, and thus we don't allow it
236
-                                (0xA0 <= $mUcs4 && 0xD7FF >= $mUcs4) ||
237
-                                (0x10000 <= $mUcs4 && 0x10FFFF >= $mUcs4)
238
-                            )
239
-                        ) {
240
-                            $out .= $char;
241
-                        }
242
-                        // initialize UTF8 cache (reset)
243
-                        $mState = 0;
244
-                        $mUcs4  = 0;
245
-                        $mBytes = 1;
246
-                        $char = '';
247
-                    }
248
-                } else {
249
-                    // ((0xC0 & (*in) != 0x80) && (mState != 0))
250
-                    // Incomplete multi-octet sequence.
251
-                    // used to result in complete fail, but we'll reset
252
-                    $mState = 0;
253
-                    $mUcs4  = 0;
254
-                    $mBytes = 1;
255
-                    $char ='';
256
-                }
257
-            }
258
-        }
259
-        return $out;
260
-    }
261
-
262
-    /**
263
-     * Translates a Unicode codepoint into its corresponding UTF-8 character.
264
-     * @note Based on Feyd's function at
265
-     *       <http://forums.devnetwork.net/viewtopic.php?p=191404#191404>,
266
-     *       which is in public domain.
267
-     * @note While we're going to do code point parsing anyway, a good
268
-     *       optimization would be to refuse to translate code points that
269
-     *       are non-SGML characters.  However, this could lead to duplication.
270
-     * @note This is very similar to the unichr function in
271
-     *       maintenance/generate-entity-file.php (although this is superior,
272
-     *       due to its sanity checks).
273
-     */
274
-
275
-    // +----------+----------+----------+----------+
276
-    // | 33222222 | 22221111 | 111111   |          |
277
-    // | 10987654 | 32109876 | 54321098 | 76543210 | bit
278
-    // +----------+----------+----------+----------+
279
-    // |          |          |          | 0xxxxxxx | 1 byte 0x00000000..0x0000007F
280
-    // |          |          | 110yyyyy | 10xxxxxx | 2 byte 0x00000080..0x000007FF
281
-    // |          | 1110zzzz | 10yyyyyy | 10xxxxxx | 3 byte 0x00000800..0x0000FFFF
282
-    // | 11110www | 10wwzzzz | 10yyyyyy | 10xxxxxx | 4 byte 0x00010000..0x0010FFFF
283
-    // +----------+----------+----------+----------+
284
-    // | 00000000 | 00011111 | 11111111 | 11111111 | Theoretical upper limit of legal scalars: 2097151 (0x001FFFFF)
285
-    // | 00000000 | 00010000 | 11111111 | 11111111 | Defined upper limit of legal scalar codes
286
-    // +----------+----------+----------+----------+
287
-
288
-    public static function unichr($code) {
289
-        if($code > 1114111 or $code < 0 or
290
-          ($code >= 55296 and $code <= 57343) ) {
291
-            // bits are set outside the "valid" range as defined
292
-            // by UNICODE 4.1.0
293
-            return '';
294
-        }
295
-
296
-        $x = $y = $z = $w = 0;
297
-        if ($code < 128) {
298
-            // regular ASCII character
299
-            $x = $code;
300
-        } else {
301
-            // set up bits for UTF-8
302
-            $x = ($code & 63) | 128;
303
-            if ($code < 2048) {
304
-                $y = (($code & 2047) >> 6) | 192;
305
-            } else {
306
-                $y = (($code & 4032) >> 6) | 128;
307
-                if($code < 65536) {
308
-                    $z = (($code >> 12) & 15) | 224;
309
-                } else {
310
-                    $z = (($code >> 12) & 63) | 128;
311
-                    $w = (($code >> 18) & 7)  | 240;
312
-                }
313
-            }
314
-        }
315
-        // set up the actual character
316
-        $ret = '';
317
-        if($w) $ret .= chr($w);
318
-        if($z) $ret .= chr($z);
319
-        if($y) $ret .= chr($y);
320
-        $ret .= chr($x);
321
-
322
-        return $ret;
323
-    }
324
-
325
-    public static function iconvAvailable() {
326
-        static $iconv = null;
327
-        if ($iconv === null) {
328
-            $iconv = function_exists('iconv') && self::testIconvTruncateBug() != self::ICONV_UNUSABLE;
329
-        }
330
-        return $iconv;
331
-    }
332
-
333
-    /**
334
-     * Converts a string to UTF-8 based on configuration.
335
-     */
336
-    public static function convertToUTF8($str, $config, $context) {
337
-        $encoding = $config->get('Core.Encoding');
338
-        if ($encoding === 'utf-8') return $str;
339
-        static $iconv = null;
340
-        if ($iconv === null) $iconv = self::iconvAvailable();
341
-        if ($iconv && !$config->get('Test.ForceNoIconv')) {
342
-            // unaffected by bugs, since UTF-8 support all characters
343
-            $str = self::unsafeIconv($encoding, 'utf-8//IGNORE', $str);
344
-            if ($str === false) {
345
-                // $encoding is not a valid encoding
346
-                trigger_error('Invalid encoding ' . $encoding, E_USER_ERROR);
347
-                return '';
348
-            }
349
-            // If the string is bjorked by Shift_JIS or a similar encoding
350
-            // that doesn't support all of ASCII, convert the naughty
351
-            // characters to their true byte-wise ASCII/UTF-8 equivalents.
352
-            $str = strtr($str, self::testEncodingSupportsASCII($encoding));
353
-            return $str;
354
-        } elseif ($encoding === 'iso-8859-1') {
355
-            $str = utf8_encode($str);
356
-            return $str;
357
-        }
358
-        trigger_error('Encoding not supported, please install iconv', E_USER_ERROR);
359
-    }
360
-
361
-    /**
362
-     * Converts a string from UTF-8 based on configuration.
363
-     * @note Currently, this is a lossy conversion, with unexpressable
364
-     *       characters being omitted.
365
-     */
366
-    public static function convertFromUTF8($str, $config, $context) {
367
-        $encoding = $config->get('Core.Encoding');
368
-        if ($escape = $config->get('Core.EscapeNonASCIICharacters')) {
369
-            $str = self::convertToASCIIDumbLossless($str);
370
-        }
371
-        if ($encoding === 'utf-8') return $str;
372
-        static $iconv = null;
373
-        if ($iconv === null) $iconv = self::iconvAvailable();
374
-        if ($iconv && !$config->get('Test.ForceNoIconv')) {
375
-            // Undo our previous fix in convertToUTF8, otherwise iconv will barf
376
-            $ascii_fix = self::testEncodingSupportsASCII($encoding);
377
-            if (!$escape && !empty($ascii_fix)) {
378
-                $clear_fix = array();
379
-                foreach ($ascii_fix as $utf8 => $native) $clear_fix[$utf8] = '';
380
-                $str = strtr($str, $clear_fix);
381
-            }
382
-            $str = strtr($str, array_flip($ascii_fix));
383
-            // Normal stuff
384
-            $str = self::iconv('utf-8', $encoding . '//IGNORE', $str);
385
-            return $str;
386
-        } elseif ($encoding === 'iso-8859-1') {
387
-            $str = utf8_decode($str);
388
-            return $str;
389
-        }
390
-        trigger_error('Encoding not supported', E_USER_ERROR);
391
-        // You might be tempted to assume that the ASCII representation
392
-        // might be OK, however, this is *not* universally true over all
393
-        // encodings.  So we take the conservative route here, rather
394
-        // than forcibly turn on %Core.EscapeNonASCIICharacters
395
-    }
396
-
397
-    /**
398
-     * Lossless (character-wise) conversion of HTML to ASCII
399
-     * @param $str UTF-8 string to be converted to ASCII
400
-     * @returns ASCII encoded string with non-ASCII character entity-ized
401
-     * @warning Adapted from MediaWiki, claiming fair use: this is a common
402
-     *       algorithm. If you disagree with this license fudgery,
403
-     *       implement it yourself.
404
-     * @note Uses decimal numeric entities since they are best supported.
405
-     * @note This is a DUMB function: it has no concept of keeping
406
-     *       character entities that the projected character encoding
407
-     *       can allow. We could possibly implement a smart version
408
-     *       but that would require it to also know which Unicode
409
-     *       codepoints the charset supported (not an easy task).
410
-     * @note Sort of with cleanUTF8() but it assumes that $str is
411
-     *       well-formed UTF-8
412
-     */
413
-    public static function convertToASCIIDumbLossless($str) {
414
-        $bytesleft = 0;
415
-        $result = '';
416
-        $working = 0;
417
-        $len = strlen($str);
418
-        for( $i = 0; $i < $len; $i++ ) {
419
-            $bytevalue = ord( $str[$i] );
420
-            if( $bytevalue <= 0x7F ) { //0xxx xxxx
421
-                $result .= chr( $bytevalue );
422
-                $bytesleft = 0;
423
-            } elseif( $bytevalue <= 0xBF ) { //10xx xxxx
424
-                $working = $working << 6;
425
-                $working += ($bytevalue & 0x3F);
426
-                $bytesleft--;
427
-                if( $bytesleft <= 0 ) {
428
-                    $result .= "&#" . $working . ";";
429
-                }
430
-            } elseif( $bytevalue <= 0xDF ) { //110x xxxx
431
-                $working = $bytevalue & 0x1F;
432
-                $bytesleft = 1;
433
-            } elseif( $bytevalue <= 0xEF ) { //1110 xxxx
434
-                $working = $bytevalue & 0x0F;
435
-                $bytesleft = 2;
436
-            } else { //1111 0xxx
437
-                $working = $bytevalue & 0x07;
438
-                $bytesleft = 3;
439
-            }
440
-        }
441
-        return $result;
442
-    }
443
-
444
-    /** No bugs detected in iconv. */
445
-    const ICONV_OK = 0;
446
-
447
-    /** Iconv truncates output if converting from UTF-8 to another
448
-     *  character set with //IGNORE, and a non-encodable character is found */
449
-    const ICONV_TRUNCATES = 1;
450
-
451
-    /** Iconv does not support //IGNORE, making it unusable for
452
-     *  transcoding purposes */
453
-    const ICONV_UNUSABLE = 2;
454
-
455
-    /**
456
-     * glibc iconv has a known bug where it doesn't handle the magic
457
-     * //IGNORE stanza correctly.  In particular, rather than ignore
458
-     * characters, it will return an EILSEQ after consuming some number
459
-     * of characters, and expect you to restart iconv as if it were
460
-     * an E2BIG.  Old versions of PHP did not respect the errno, and
461
-     * returned the fragment, so as a result you would see iconv
462
-     * mysteriously truncating output. We can work around this by
463
-     * manually chopping our input into segments of about 8000
464
-     * characters, as long as PHP ignores the error code.  If PHP starts
465
-     * paying attention to the error code, iconv becomes unusable.
466
-     *
467
-     * @returns Error code indicating severity of bug.
468
-     */
469
-    public static function testIconvTruncateBug() {
470
-        static $code = null;
471
-        if ($code === null) {
472
-            // better not use iconv, otherwise infinite loop!
473
-            $r = self::unsafeIconv('utf-8', 'ascii//IGNORE', "\xCE\xB1" . str_repeat('a', 9000));
474
-            if ($r === false) {
475
-                $code = self::ICONV_UNUSABLE;
476
-            } elseif (($c = strlen($r)) < 9000) {
477
-                $code = self::ICONV_TRUNCATES;
478
-            } elseif ($c > 9000) {
479
-                trigger_error('Your copy of iconv is extremely buggy. Please notify HTML Purifier maintainers: include your iconv version as per phpversion()', E_USER_ERROR);
480
-            } else {
481
-                $code = self::ICONV_OK;
482
-            }
483
-        }
484
-        return $code;
485
-    }
486
-
487
-    /**
488
-     * This expensive function tests whether or not a given character
489
-     * encoding supports ASCII. 7/8-bit encodings like Shift_JIS will
490
-     * fail this test, and require special processing. Variable width
491
-     * encodings shouldn't ever fail.
492
-     *
493
-     * @param string $encoding Encoding name to test, as per iconv format
494
-     * @param bool $bypass Whether or not to bypass the precompiled arrays.
495
-     * @return Array of UTF-8 characters to their corresponding ASCII,
496
-     *      which can be used to "undo" any overzealous iconv action.
497
-     */
498
-    public static function testEncodingSupportsASCII($encoding, $bypass = false) {
499
-        // All calls to iconv here are unsafe, proof by case analysis:
500
-        // If ICONV_OK, no difference.
501
-        // If ICONV_TRUNCATE, all calls involve one character inputs,
502
-        // so bug is not triggered.
503
-        // If ICONV_UNUSABLE, this call is irrelevant
504
-        static $encodings = array();
505
-        if (!$bypass) {
506
-            if (isset($encodings[$encoding])) return $encodings[$encoding];
507
-            $lenc = strtolower($encoding);
508
-            switch ($lenc) {
509
-                case 'shift_jis':
510
-                    return array("\xC2\xA5" => '\\', "\xE2\x80\xBE" => '~');
511
-                case 'johab':
512
-                    return array("\xE2\x82\xA9" => '\\');
513
-            }
514
-            if (strpos($lenc, 'iso-8859-') === 0) return array();
515
-        }
516
-        $ret = array();
517
-        if (self::unsafeIconv('UTF-8', $encoding, 'a') === false) return false;
518
-        for ($i = 0x20; $i <= 0x7E; $i++) { // all printable ASCII chars
519
-            $c = chr($i); // UTF-8 char
520
-            $r = self::unsafeIconv('UTF-8', "$encoding//IGNORE", $c); // initial conversion
521
-            if (
522
-                $r === '' ||
523
-                // This line is needed for iconv implementations that do not
524
-                // omit characters that do not exist in the target character set
525
-                ($r === $c && self::unsafeIconv($encoding, 'UTF-8//IGNORE', $r) !== $c)
526
-            ) {
527
-                // Reverse engineer: what's the UTF-8 equiv of this byte
528
-                // sequence? This assumes that there's no variable width
529
-                // encoding that doesn't support ASCII.
530
-                $ret[self::unsafeIconv($encoding, 'UTF-8//IGNORE', $c)] = $c;
531
-            }
532
-        }
533
-        $encodings[$encoding] = $ret;
534
-        return $ret;
535
-    }
10
+	/**
11
+	 * Constructor throws fatal error if you attempt to instantiate class
12
+	 */
13
+	private function __construct() {
14
+		trigger_error('Cannot instantiate encoder, call methods statically', E_USER_ERROR);
15
+	}
16
+
17
+	/**
18
+	 * Error-handler that mutes errors, alternative to shut-up operator.
19
+	 */
20
+	public static function muteErrorHandler() {}
21
+
22
+	/**
23
+	 * iconv wrapper which mutes errors, but doesn't work around bugs.
24
+	 */
25
+	public static function unsafeIconv($in, $out, $text) {
26
+		set_error_handler(array('HTMLPurifier_Encoder', 'muteErrorHandler'));
27
+		$r = iconv($in, $out, $text);
28
+		restore_error_handler();
29
+		return $r;
30
+	}
31
+
32
+	/**
33
+	 * iconv wrapper which mutes errors and works around bugs.
34
+	 */
35
+	public static function iconv($in, $out, $text, $max_chunk_size = 8000) {
36
+		$code = self::testIconvTruncateBug();
37
+		if ($code == self::ICONV_OK) {
38
+			return self::unsafeIconv($in, $out, $text);
39
+		} elseif ($code == self::ICONV_TRUNCATES) {
40
+			// we can only work around this if the input character set
41
+			// is utf-8
42
+			if ($in == 'utf-8') {
43
+				if ($max_chunk_size < 4) {
44
+					trigger_error('max_chunk_size is too small', E_USER_WARNING);
45
+					return false;
46
+				}
47
+				// split into 8000 byte chunks, but be careful to handle
48
+				// multibyte boundaries properly
49
+				if (($c = strlen($text)) <= $max_chunk_size) {
50
+					return self::unsafeIconv($in, $out, $text);
51
+				}
52
+				$r = '';
53
+				$i = 0;
54
+				while (true) {
55
+					if ($i + $max_chunk_size >= $c) {
56
+						$r .= self::unsafeIconv($in, $out, substr($text, $i));
57
+						break;
58
+					}
59
+					// wibble the boundary
60
+					if (0x80 != (0xC0 & ord($text[$i + $max_chunk_size]))) {
61
+						$chunk_size = $max_chunk_size;
62
+					} elseif (0x80 != (0xC0 & ord($text[$i + $max_chunk_size - 1]))) {
63
+						$chunk_size = $max_chunk_size - 1;
64
+					} elseif (0x80 != (0xC0 & ord($text[$i + $max_chunk_size - 2]))) {
65
+						$chunk_size = $max_chunk_size - 2;
66
+					} elseif (0x80 != (0xC0 & ord($text[$i + $max_chunk_size - 3]))) {
67
+						$chunk_size = $max_chunk_size - 3;
68
+					} else {
69
+						return false; // rather confusing UTF-8...
70
+					}
71
+					$chunk = substr($text, $i, $chunk_size); // substr doesn't mind overlong lengths
72
+					$r .= self::unsafeIconv($in, $out, $chunk);
73
+					$i += $chunk_size;
74
+				}
75
+				return $r;
76
+			} else {
77
+				return false;
78
+			}
79
+		} else {
80
+			return false;
81
+		}
82
+	}
83
+
84
+	/**
85
+	 * Cleans a UTF-8 string for well-formedness and SGML validity
86
+	 *
87
+	 * It will parse according to UTF-8 and return a valid UTF8 string, with
88
+	 * non-SGML codepoints excluded.
89
+	 *
90
+	 * @note Just for reference, the non-SGML code points are 0 to 31 and
91
+	 *       127 to 159, inclusive.  However, we allow code points 9, 10
92
+	 *       and 13, which are the tab, line feed and carriage return
93
+	 *       respectively. 128 and above the code points map to multibyte
94
+	 *       UTF-8 representations.
95
+	 *
96
+	 * @note Fallback code adapted from utf8ToUnicode by Henri Sivonen and
97
+	 *       [email protected] at <http://iki.fi/hsivonen/php-utf8/> under the
98
+	 *       LGPL license.  Notes on what changed are inside, but in general,
99
+	 *       the original code transformed UTF-8 text into an array of integer
100
+	 *       Unicode codepoints. Understandably, transforming that back to
101
+	 *       a string would be somewhat expensive, so the function was modded to
102
+	 *       directly operate on the string.  However, this discourages code
103
+	 *       reuse, and the logic enumerated here would be useful for any
104
+	 *       function that needs to be able to understand UTF-8 characters.
105
+	 *       As of right now, only smart lossless character encoding converters
106
+	 *       would need that, and I'm probably not going to implement them.
107
+	 *       Once again, PHP 6 should solve all our problems.
108
+	 */
109
+	public static function cleanUTF8($str, $force_php = false) {
110
+
111
+		// UTF-8 validity is checked since PHP 4.3.5
112
+		// This is an optimization: if the string is already valid UTF-8, no
113
+		// need to do PHP stuff. 99% of the time, this will be the case.
114
+		// The regexp matches the XML char production, as well as well as excluding
115
+		// non-SGML codepoints U+007F to U+009F
116
+		if (preg_match('/^[\x{9}\x{A}\x{D}\x{20}-\x{7E}\x{A0}-\x{D7FF}\x{E000}-\x{FFFD}\x{10000}-\x{10FFFF}]*$/Du', $str)) {
117
+			return $str;
118
+		}
119
+
120
+		$mState = 0; // cached expected number of octets after the current octet
121
+					 // until the beginning of the next UTF8 character sequence
122
+		$mUcs4  = 0; // cached Unicode character
123
+		$mBytes = 1; // cached expected number of octets in the current sequence
124
+
125
+		// original code involved an $out that was an array of Unicode
126
+		// codepoints.  Instead of having to convert back into UTF-8, we've
127
+		// decided to directly append valid UTF-8 characters onto a string
128
+		// $out once they're done.  $char accumulates raw bytes, while $mUcs4
129
+		// turns into the Unicode code point, so there's some redundancy.
130
+
131
+		$out = '';
132
+		$char = '';
133
+
134
+		$len = strlen($str);
135
+		for($i = 0; $i < $len; $i++) {
136
+			$in = ord($str{$i});
137
+			$char .= $str[$i]; // append byte to char
138
+			if (0 == $mState) {
139
+				// When mState is zero we expect either a US-ASCII character
140
+				// or a multi-octet sequence.
141
+				if (0 == (0x80 & ($in))) {
142
+					// US-ASCII, pass straight through.
143
+					if (($in <= 31 || $in == 127) &&
144
+						!($in == 9 || $in == 13 || $in == 10) // save \r\t\n
145
+					) {
146
+						// control characters, remove
147
+					} else {
148
+						$out .= $char;
149
+					}
150
+					// reset
151
+					$char = '';
152
+					$mBytes = 1;
153
+				} elseif (0xC0 == (0xE0 & ($in))) {
154
+					// First octet of 2 octet sequence
155
+					$mUcs4 = ($in);
156
+					$mUcs4 = ($mUcs4 & 0x1F) << 6;
157
+					$mState = 1;
158
+					$mBytes = 2;
159
+				} elseif (0xE0 == (0xF0 & ($in))) {
160
+					// First octet of 3 octet sequence
161
+					$mUcs4 = ($in);
162
+					$mUcs4 = ($mUcs4 & 0x0F) << 12;
163
+					$mState = 2;
164
+					$mBytes = 3;
165
+				} elseif (0xF0 == (0xF8 & ($in))) {
166
+					// First octet of 4 octet sequence
167
+					$mUcs4 = ($in);
168
+					$mUcs4 = ($mUcs4 & 0x07) << 18;
169
+					$mState = 3;
170
+					$mBytes = 4;
171
+				} elseif (0xF8 == (0xFC & ($in))) {
172
+					// First octet of 5 octet sequence.
173
+					//
174
+					// This is illegal because the encoded codepoint must be
175
+					// either:
176
+					// (a) not the shortest form or
177
+					// (b) outside the Unicode range of 0-0x10FFFF.
178
+					// Rather than trying to resynchronize, we will carry on
179
+					// until the end of the sequence and let the later error
180
+					// handling code catch it.
181
+					$mUcs4 = ($in);
182
+					$mUcs4 = ($mUcs4 & 0x03) << 24;
183
+					$mState = 4;
184
+					$mBytes = 5;
185
+				} elseif (0xFC == (0xFE & ($in))) {
186
+					// First octet of 6 octet sequence, see comments for 5
187
+					// octet sequence.
188
+					$mUcs4 = ($in);
189
+					$mUcs4 = ($mUcs4 & 1) << 30;
190
+					$mState = 5;
191
+					$mBytes = 6;
192
+				} else {
193
+					// Current octet is neither in the US-ASCII range nor a
194
+					// legal first octet of a multi-octet sequence.
195
+					$mState = 0;
196
+					$mUcs4  = 0;
197
+					$mBytes = 1;
198
+					$char = '';
199
+				}
200
+			} else {
201
+				// When mState is non-zero, we expect a continuation of the
202
+				// multi-octet sequence
203
+				if (0x80 == (0xC0 & ($in))) {
204
+					// Legal continuation.
205
+					$shift = ($mState - 1) * 6;
206
+					$tmp = $in;
207
+					$tmp = ($tmp & 0x0000003F) << $shift;
208
+					$mUcs4 |= $tmp;
209
+
210
+					if (0 == --$mState) {
211
+						// End of the multi-octet sequence. mUcs4 now contains
212
+						// the final Unicode codepoint to be output
213
+
214
+						// Check for illegal sequences and codepoints.
215
+
216
+						// From Unicode 3.1, non-shortest form is illegal
217
+						if (((2 == $mBytes) && ($mUcs4 < 0x0080)) ||
218
+							((3 == $mBytes) && ($mUcs4 < 0x0800)) ||
219
+							((4 == $mBytes) && ($mUcs4 < 0x10000)) ||
220
+							(4 < $mBytes) ||
221
+							// From Unicode 3.2, surrogate characters = illegal
222
+							(($mUcs4 & 0xFFFFF800) == 0xD800) ||
223
+							// Codepoints outside the Unicode range are illegal
224
+							($mUcs4 > 0x10FFFF)
225
+						) {
226
+
227
+						} elseif (0xFEFF != $mUcs4 && // omit BOM
228
+							// check for valid Char unicode codepoints
229
+							(
230
+								0x9 == $mUcs4 ||
231
+								0xA == $mUcs4 ||
232
+								0xD == $mUcs4 ||
233
+								(0x20 <= $mUcs4 && 0x7E >= $mUcs4) ||
234
+								// 7F-9F is not strictly prohibited by XML,
235
+								// but it is non-SGML, and thus we don't allow it
236
+								(0xA0 <= $mUcs4 && 0xD7FF >= $mUcs4) ||
237
+								(0x10000 <= $mUcs4 && 0x10FFFF >= $mUcs4)
238
+							)
239
+						) {
240
+							$out .= $char;
241
+						}
242
+						// initialize UTF8 cache (reset)
243
+						$mState = 0;
244
+						$mUcs4  = 0;
245
+						$mBytes = 1;
246
+						$char = '';
247
+					}
248
+				} else {
249
+					// ((0xC0 & (*in) != 0x80) && (mState != 0))
250
+					// Incomplete multi-octet sequence.
251
+					// used to result in complete fail, but we'll reset
252
+					$mState = 0;
253
+					$mUcs4  = 0;
254
+					$mBytes = 1;
255
+					$char ='';
256
+				}
257
+			}
258
+		}
259
+		return $out;
260
+	}
261
+
262
+	/**
263
+	 * Translates a Unicode codepoint into its corresponding UTF-8 character.
264
+	 * @note Based on Feyd's function at
265
+	 *       <http://forums.devnetwork.net/viewtopic.php?p=191404#191404>,
266
+	 *       which is in public domain.
267
+	 * @note While we're going to do code point parsing anyway, a good
268
+	 *       optimization would be to refuse to translate code points that
269
+	 *       are non-SGML characters.  However, this could lead to duplication.
270
+	 * @note This is very similar to the unichr function in
271
+	 *       maintenance/generate-entity-file.php (although this is superior,
272
+	 *       due to its sanity checks).
273
+	 */
274
+
275
+	// +----------+----------+----------+----------+
276
+	// | 33222222 | 22221111 | 111111   |          |
277
+	// | 10987654 | 32109876 | 54321098 | 76543210 | bit
278
+	// +----------+----------+----------+----------+
279
+	// |          |          |          | 0xxxxxxx | 1 byte 0x00000000..0x0000007F
280
+	// |          |          | 110yyyyy | 10xxxxxx | 2 byte 0x00000080..0x000007FF
281
+	// |          | 1110zzzz | 10yyyyyy | 10xxxxxx | 3 byte 0x00000800..0x0000FFFF
282
+	// | 11110www | 10wwzzzz | 10yyyyyy | 10xxxxxx | 4 byte 0x00010000..0x0010FFFF
283
+	// +----------+----------+----------+----------+
284
+	// | 00000000 | 00011111 | 11111111 | 11111111 | Theoretical upper limit of legal scalars: 2097151 (0x001FFFFF)
285
+	// | 00000000 | 00010000 | 11111111 | 11111111 | Defined upper limit of legal scalar codes
286
+	// +----------+----------+----------+----------+
287
+
288
+	public static function unichr($code) {
289
+		if($code > 1114111 or $code < 0 or
290
+		  ($code >= 55296 and $code <= 57343) ) {
291
+			// bits are set outside the "valid" range as defined
292
+			// by UNICODE 4.1.0
293
+			return '';
294
+		}
295
+
296
+		$x = $y = $z = $w = 0;
297
+		if ($code < 128) {
298
+			// regular ASCII character
299
+			$x = $code;
300
+		} else {
301
+			// set up bits for UTF-8
302
+			$x = ($code & 63) | 128;
303
+			if ($code < 2048) {
304
+				$y = (($code & 2047) >> 6) | 192;
305
+			} else {
306
+				$y = (($code & 4032) >> 6) | 128;
307
+				if($code < 65536) {
308
+					$z = (($code >> 12) & 15) | 224;
309
+				} else {
310
+					$z = (($code >> 12) & 63) | 128;
311
+					$w = (($code >> 18) & 7)  | 240;
312
+				}
313
+			}
314
+		}
315
+		// set up the actual character
316
+		$ret = '';
317
+		if($w) $ret .= chr($w);
318
+		if($z) $ret .= chr($z);
319
+		if($y) $ret .= chr($y);
320
+		$ret .= chr($x);
321
+
322
+		return $ret;
323
+	}
324
+
325
+	public static function iconvAvailable() {
326
+		static $iconv = null;
327
+		if ($iconv === null) {
328
+			$iconv = function_exists('iconv') && self::testIconvTruncateBug() != self::ICONV_UNUSABLE;
329
+		}
330
+		return $iconv;
331
+	}
332
+
333
+	/**
334
+	 * Converts a string to UTF-8 based on configuration.
335
+	 */
336
+	public static function convertToUTF8($str, $config, $context) {
337
+		$encoding = $config->get('Core.Encoding');
338
+		if ($encoding === 'utf-8') return $str;
339
+		static $iconv = null;
340
+		if ($iconv === null) $iconv = self::iconvAvailable();
341
+		if ($iconv && !$config->get('Test.ForceNoIconv')) {
342
+			// unaffected by bugs, since UTF-8 support all characters
343
+			$str = self::unsafeIconv($encoding, 'utf-8//IGNORE', $str);
344
+			if ($str === false) {
345
+				// $encoding is not a valid encoding
346
+				trigger_error('Invalid encoding ' . $encoding, E_USER_ERROR);
347
+				return '';
348
+			}
349
+			// If the string is bjorked by Shift_JIS or a similar encoding
350
+			// that doesn't support all of ASCII, convert the naughty
351
+			// characters to their true byte-wise ASCII/UTF-8 equivalents.
352
+			$str = strtr($str, self::testEncodingSupportsASCII($encoding));
353
+			return $str;
354
+		} elseif ($encoding === 'iso-8859-1') {
355
+			$str = utf8_encode($str);
356
+			return $str;
357
+		}
358
+		trigger_error('Encoding not supported, please install iconv', E_USER_ERROR);
359
+	}
360
+
361
+	/**
362
+	 * Converts a string from UTF-8 based on configuration.
363
+	 * @note Currently, this is a lossy conversion, with unexpressable
364
+	 *       characters being omitted.
365
+	 */
366
+	public static function convertFromUTF8($str, $config, $context) {
367
+		$encoding = $config->get('Core.Encoding');
368
+		if ($escape = $config->get('Core.EscapeNonASCIICharacters')) {
369
+			$str = self::convertToASCIIDumbLossless($str);
370
+		}
371
+		if ($encoding === 'utf-8') return $str;
372
+		static $iconv = null;
373
+		if ($iconv === null) $iconv = self::iconvAvailable();
374
+		if ($iconv && !$config->get('Test.ForceNoIconv')) {
375
+			// Undo our previous fix in convertToUTF8, otherwise iconv will barf
376
+			$ascii_fix = self::testEncodingSupportsASCII($encoding);
377
+			if (!$escape && !empty($ascii_fix)) {
378
+				$clear_fix = array();
379
+				foreach ($ascii_fix as $utf8 => $native) $clear_fix[$utf8] = '';
380
+				$str = strtr($str, $clear_fix);
381
+			}
382
+			$str = strtr($str, array_flip($ascii_fix));
383
+			// Normal stuff
384
+			$str = self::iconv('utf-8', $encoding . '//IGNORE', $str);
385
+			return $str;
386
+		} elseif ($encoding === 'iso-8859-1') {
387
+			$str = utf8_decode($str);
388
+			return $str;
389
+		}
390
+		trigger_error('Encoding not supported', E_USER_ERROR);
391
+		// You might be tempted to assume that the ASCII representation
392
+		// might be OK, however, this is *not* universally true over all
393
+		// encodings.  So we take the conservative route here, rather
394
+		// than forcibly turn on %Core.EscapeNonASCIICharacters
395
+	}
396
+
397
+	/**
398
+	 * Lossless (character-wise) conversion of HTML to ASCII
399
+	 * @param $str UTF-8 string to be converted to ASCII
400
+	 * @returns ASCII encoded string with non-ASCII character entity-ized
401
+	 * @warning Adapted from MediaWiki, claiming fair use: this is a common
402
+	 *       algorithm. If you disagree with this license fudgery,
403
+	 *       implement it yourself.
404
+	 * @note Uses decimal numeric entities since they are best supported.
405
+	 * @note This is a DUMB function: it has no concept of keeping
406
+	 *       character entities that the projected character encoding
407
+	 *       can allow. We could possibly implement a smart version
408
+	 *       but that would require it to also know which Unicode
409
+	 *       codepoints the charset supported (not an easy task).
410
+	 * @note Sort of with cleanUTF8() but it assumes that $str is
411
+	 *       well-formed UTF-8
412
+	 */
413
+	public static function convertToASCIIDumbLossless($str) {
414
+		$bytesleft = 0;
415
+		$result = '';
416
+		$working = 0;
417
+		$len = strlen($str);
418
+		for( $i = 0; $i < $len; $i++ ) {
419
+			$bytevalue = ord( $str[$i] );
420
+			if( $bytevalue <= 0x7F ) { //0xxx xxxx
421
+				$result .= chr( $bytevalue );
422
+				$bytesleft = 0;
423
+			} elseif( $bytevalue <= 0xBF ) { //10xx xxxx
424
+				$working = $working << 6;
425
+				$working += ($bytevalue & 0x3F);
426
+				$bytesleft--;
427
+				if( $bytesleft <= 0 ) {
428
+					$result .= "&#" . $working . ";";
429
+				}
430
+			} elseif( $bytevalue <= 0xDF ) { //110x xxxx
431
+				$working = $bytevalue & 0x1F;
432
+				$bytesleft = 1;
433
+			} elseif( $bytevalue <= 0xEF ) { //1110 xxxx
434
+				$working = $bytevalue & 0x0F;
435
+				$bytesleft = 2;
436
+			} else { //1111 0xxx
437
+				$working = $bytevalue & 0x07;
438
+				$bytesleft = 3;
439
+			}
440
+		}
441
+		return $result;
442
+	}
443
+
444
+	/** No bugs detected in iconv. */
445
+	const ICONV_OK = 0;
446
+
447
+	/** Iconv truncates output if converting from UTF-8 to another
448
+	 *  character set with //IGNORE, and a non-encodable character is found */
449
+	const ICONV_TRUNCATES = 1;
450
+
451
+	/** Iconv does not support //IGNORE, making it unusable for
452
+	 *  transcoding purposes */
453
+	const ICONV_UNUSABLE = 2;
454
+
455
+	/**
456
+	 * glibc iconv has a known bug where it doesn't handle the magic
457
+	 * //IGNORE stanza correctly.  In particular, rather than ignore
458
+	 * characters, it will return an EILSEQ after consuming some number
459
+	 * of characters, and expect you to restart iconv as if it were
460
+	 * an E2BIG.  Old versions of PHP did not respect the errno, and
461
+	 * returned the fragment, so as a result you would see iconv
462
+	 * mysteriously truncating output. We can work around this by
463
+	 * manually chopping our input into segments of about 8000
464
+	 * characters, as long as PHP ignores the error code.  If PHP starts
465
+	 * paying attention to the error code, iconv becomes unusable.
466
+	 *
467
+	 * @returns Error code indicating severity of bug.
468
+	 */
469
+	public static function testIconvTruncateBug() {
470
+		static $code = null;
471
+		if ($code === null) {
472
+			// better not use iconv, otherwise infinite loop!
473
+			$r = self::unsafeIconv('utf-8', 'ascii//IGNORE', "\xCE\xB1" . str_repeat('a', 9000));
474
+			if ($r === false) {
475
+				$code = self::ICONV_UNUSABLE;
476
+			} elseif (($c = strlen($r)) < 9000) {
477
+				$code = self::ICONV_TRUNCATES;
478
+			} elseif ($c > 9000) {
479
+				trigger_error('Your copy of iconv is extremely buggy. Please notify HTML Purifier maintainers: include your iconv version as per phpversion()', E_USER_ERROR);
480
+			} else {
481
+				$code = self::ICONV_OK;
482
+			}
483
+		}
484
+		return $code;
485
+	}
486
+
487
+	/**
488
+	 * This expensive function tests whether or not a given character
489
+	 * encoding supports ASCII. 7/8-bit encodings like Shift_JIS will
490
+	 * fail this test, and require special processing. Variable width
491
+	 * encodings shouldn't ever fail.
492
+	 *
493
+	 * @param string $encoding Encoding name to test, as per iconv format
494
+	 * @param bool $bypass Whether or not to bypass the precompiled arrays.
495
+	 * @return Array of UTF-8 characters to their corresponding ASCII,
496
+	 *      which can be used to "undo" any overzealous iconv action.
497
+	 */
498
+	public static function testEncodingSupportsASCII($encoding, $bypass = false) {
499
+		// All calls to iconv here are unsafe, proof by case analysis:
500
+		// If ICONV_OK, no difference.
501
+		// If ICONV_TRUNCATE, all calls involve one character inputs,
502
+		// so bug is not triggered.
503
+		// If ICONV_UNUSABLE, this call is irrelevant
504
+		static $encodings = array();
505
+		if (!$bypass) {
506
+			if (isset($encodings[$encoding])) return $encodings[$encoding];
507
+			$lenc = strtolower($encoding);
508
+			switch ($lenc) {
509
+				case 'shift_jis':
510
+					return array("\xC2\xA5" => '\\', "\xE2\x80\xBE" => '~');
511
+				case 'johab':
512
+					return array("\xE2\x82\xA9" => '\\');
513
+			}
514
+			if (strpos($lenc, 'iso-8859-') === 0) return array();
515
+		}
516
+		$ret = array();
517
+		if (self::unsafeIconv('UTF-8', $encoding, 'a') === false) return false;
518
+		for ($i = 0x20; $i <= 0x7E; $i++) { // all printable ASCII chars
519
+			$c = chr($i); // UTF-8 char
520
+			$r = self::unsafeIconv('UTF-8', "$encoding//IGNORE", $c); // initial conversion
521
+			if (
522
+				$r === '' ||
523
+				// This line is needed for iconv implementations that do not
524
+				// omit characters that do not exist in the target character set
525
+				($r === $c && self::unsafeIconv($encoding, 'UTF-8//IGNORE', $r) !== $c)
526
+			) {
527
+				// Reverse engineer: what's the UTF-8 equiv of this byte
528
+				// sequence? This assumes that there's no variable width
529
+				// encoding that doesn't support ASCII.
530
+				$ret[self::unsafeIconv($encoding, 'UTF-8//IGNORE', $c)] = $c;
531
+			}
532
+		}
533
+		$encodings[$encoding] = $ret;
534
+		return $ret;
535
+	}
536 536
 
537 537
 
538 538
 }
Please login to merge, or discard this patch.
Braces   +33 added lines, -11 removed lines patch added patch discarded remove patch
@@ -314,9 +314,15 @@  discard block
 block discarded – undo
314 314
         }
315 315
         // set up the actual character
316 316
         $ret = '';
317
-        if($w) $ret .= chr($w);
318
-        if($z) $ret .= chr($z);
319
-        if($y) $ret .= chr($y);
317
+        if($w) {
318
+        	$ret .= chr($w);
319
+        }
320
+        if($z) {
321
+        	$ret .= chr($z);
322
+        }
323
+        if($y) {
324
+        	$ret .= chr($y);
325
+        }
320 326
         $ret .= chr($x);
321 327
 
322 328
         return $ret;
@@ -335,9 +341,13 @@  discard block
 block discarded – undo
335 341
      */
336 342
     public static function convertToUTF8($str, $config, $context) {
337 343
         $encoding = $config->get('Core.Encoding');
338
-        if ($encoding === 'utf-8') return $str;
344
+        if ($encoding === 'utf-8') {
345
+        	return $str;
346
+        }
339 347
         static $iconv = null;
340
-        if ($iconv === null) $iconv = self::iconvAvailable();
348
+        if ($iconv === null) {
349
+        	$iconv = self::iconvAvailable();
350
+        }
341 351
         if ($iconv && !$config->get('Test.ForceNoIconv')) {
342 352
             // unaffected by bugs, since UTF-8 support all characters
343 353
             $str = self::unsafeIconv($encoding, 'utf-8//IGNORE', $str);
@@ -368,15 +378,21 @@  discard block
 block discarded – undo
368 378
         if ($escape = $config->get('Core.EscapeNonASCIICharacters')) {
369 379
             $str = self::convertToASCIIDumbLossless($str);
370 380
         }
371
-        if ($encoding === 'utf-8') return $str;
381
+        if ($encoding === 'utf-8') {
382
+        	return $str;
383
+        }
372 384
         static $iconv = null;
373
-        if ($iconv === null) $iconv = self::iconvAvailable();
385
+        if ($iconv === null) {
386
+        	$iconv = self::iconvAvailable();
387
+        }
374 388
         if ($iconv && !$config->get('Test.ForceNoIconv')) {
375 389
             // Undo our previous fix in convertToUTF8, otherwise iconv will barf
376 390
             $ascii_fix = self::testEncodingSupportsASCII($encoding);
377 391
             if (!$escape && !empty($ascii_fix)) {
378 392
                 $clear_fix = array();
379
-                foreach ($ascii_fix as $utf8 => $native) $clear_fix[$utf8] = '';
393
+                foreach ($ascii_fix as $utf8 => $native) {
394
+                	$clear_fix[$utf8] = '';
395
+                }
380 396
                 $str = strtr($str, $clear_fix);
381 397
             }
382 398
             $str = strtr($str, array_flip($ascii_fix));
@@ -503,7 +519,9 @@  discard block
 block discarded – undo
503 519
         // If ICONV_UNUSABLE, this call is irrelevant
504 520
         static $encodings = array();
505 521
         if (!$bypass) {
506
-            if (isset($encodings[$encoding])) return $encodings[$encoding];
522
+            if (isset($encodings[$encoding])) {
523
+            	return $encodings[$encoding];
524
+            }
507 525
             $lenc = strtolower($encoding);
508 526
             switch ($lenc) {
509 527
                 case 'shift_jis':
@@ -511,10 +529,14 @@  discard block
 block discarded – undo
511 529
                 case 'johab':
512 530
                     return array("\xE2\x82\xA9" => '\\');
513 531
             }
514
-            if (strpos($lenc, 'iso-8859-') === 0) return array();
532
+            if (strpos($lenc, 'iso-8859-') === 0) {
533
+            	return array();
534
+            }
515 535
         }
516 536
         $ret = array();
517
-        if (self::unsafeIconv('UTF-8', $encoding, 'a') === false) return false;
537
+        if (self::unsafeIconv('UTF-8', $encoding, 'a') === false) {
538
+        	return false;
539
+        }
518 540
         for ($i = 0x20; $i <= 0x7E; $i++) { // all printable ASCII chars
519 541
             $c = chr($i); // UTF-8 char
520 542
             $r = self::unsafeIconv('UTF-8', "$encoding//IGNORE", $c); // initial conversion
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
         $char = '';
133 133
 
134 134
         $len = strlen($str);
135
-        for($i = 0; $i < $len; $i++) {
135
+        for ($i = 0; $i < $len; $i++) {
136 136
             $in = ord($str{$i});
137 137
             $char .= $str[$i]; // append byte to char
138 138
             if (0 == $mState) {
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
                     $mState = 0;
253 253
                     $mUcs4  = 0;
254 254
                     $mBytes = 1;
255
-                    $char ='';
255
+                    $char = '';
256 256
                 }
257 257
             }
258 258
         }
@@ -286,8 +286,8 @@  discard block
 block discarded – undo
286 286
     // +----------+----------+----------+----------+
287 287
 
288 288
     public static function unichr($code) {
289
-        if($code > 1114111 or $code < 0 or
290
-          ($code >= 55296 and $code <= 57343) ) {
289
+        if ($code > 1114111 or $code < 0 or
290
+          ($code >= 55296 and $code <= 57343)) {
291 291
             // bits are set outside the "valid" range as defined
292 292
             // by UNICODE 4.1.0
293 293
             return '';
@@ -304,19 +304,19 @@  discard block
 block discarded – undo
304 304
                 $y = (($code & 2047) >> 6) | 192;
305 305
             } else {
306 306
                 $y = (($code & 4032) >> 6) | 128;
307
-                if($code < 65536) {
307
+                if ($code < 65536) {
308 308
                     $z = (($code >> 12) & 15) | 224;
309 309
                 } else {
310 310
                     $z = (($code >> 12) & 63) | 128;
311
-                    $w = (($code >> 18) & 7)  | 240;
311
+                    $w = (($code >> 18) & 7) | 240;
312 312
                 }
313 313
             }
314 314
         }
315 315
         // set up the actual character
316 316
         $ret = '';
317
-        if($w) $ret .= chr($w);
318
-        if($z) $ret .= chr($z);
319
-        if($y) $ret .= chr($y);
317
+        if ($w) $ret .= chr($w);
318
+        if ($z) $ret .= chr($z);
319
+        if ($y) $ret .= chr($y);
320 320
         $ret .= chr($x);
321 321
 
322 322
         return $ret;
@@ -343,7 +343,7 @@  discard block
 block discarded – undo
343 343
             $str = self::unsafeIconv($encoding, 'utf-8//IGNORE', $str);
344 344
             if ($str === false) {
345 345
                 // $encoding is not a valid encoding
346
-                trigger_error('Invalid encoding ' . $encoding, E_USER_ERROR);
346
+                trigger_error('Invalid encoding '.$encoding, E_USER_ERROR);
347 347
                 return '';
348 348
             }
349 349
             // If the string is bjorked by Shift_JIS or a similar encoding
@@ -381,7 +381,7 @@  discard block
 block discarded – undo
381 381
             }
382 382
             $str = strtr($str, array_flip($ascii_fix));
383 383
             // Normal stuff
384
-            $str = self::iconv('utf-8', $encoding . '//IGNORE', $str);
384
+            $str = self::iconv('utf-8', $encoding.'//IGNORE', $str);
385 385
             return $str;
386 386
         } elseif ($encoding === 'iso-8859-1') {
387 387
             $str = utf8_decode($str);
@@ -415,22 +415,22 @@  discard block
 block discarded – undo
415 415
         $result = '';
416 416
         $working = 0;
417 417
         $len = strlen($str);
418
-        for( $i = 0; $i < $len; $i++ ) {
419
-            $bytevalue = ord( $str[$i] );
420
-            if( $bytevalue <= 0x7F ) { //0xxx xxxx
421
-                $result .= chr( $bytevalue );
418
+        for ($i = 0; $i < $len; $i++) {
419
+            $bytevalue = ord($str[$i]);
420
+            if ($bytevalue <= 0x7F) { //0xxx xxxx
421
+                $result .= chr($bytevalue);
422 422
                 $bytesleft = 0;
423
-            } elseif( $bytevalue <= 0xBF ) { //10xx xxxx
423
+            } elseif ($bytevalue <= 0xBF) { //10xx xxxx
424 424
                 $working = $working << 6;
425 425
                 $working += ($bytevalue & 0x3F);
426 426
                 $bytesleft--;
427
-                if( $bytesleft <= 0 ) {
428
-                    $result .= "&#" . $working . ";";
427
+                if ($bytesleft <= 0) {
428
+                    $result .= "&#".$working.";";
429 429
                 }
430
-            } elseif( $bytevalue <= 0xDF ) { //110x xxxx
430
+            } elseif ($bytevalue <= 0xDF) { //110x xxxx
431 431
                 $working = $bytevalue & 0x1F;
432 432
                 $bytesleft = 1;
433
-            } elseif( $bytevalue <= 0xEF ) { //1110 xxxx
433
+            } elseif ($bytevalue <= 0xEF) { //1110 xxxx
434 434
                 $working = $bytevalue & 0x0F;
435 435
                 $bytesleft = 2;
436 436
             } else { //1111 0xxx
@@ -470,7 +470,7 @@  discard block
 block discarded – undo
470 470
         static $code = null;
471 471
         if ($code === null) {
472 472
             // better not use iconv, otherwise infinite loop!
473
-            $r = self::unsafeIconv('utf-8', 'ascii//IGNORE', "\xCE\xB1" . str_repeat('a', 9000));
473
+            $r = self::unsafeIconv('utf-8', 'ascii//IGNORE', "\xCE\xB1".str_repeat('a', 9000));
474 474
             if ($r === false) {
475 475
                 $code = self::ICONV_UNUSABLE;
476 476
             } elseif (($c = strlen($r)) < 9000) {
Please login to merge, or discard this patch.
classes/security/htmlpurifier/library/HTMLPurifier/ErrorCollector.php 4 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -25,6 +25,9 @@
 block discarded – undo
25 25
 
26 26
     protected $lines = array();
27 27
 
28
+    /**
29
+     * @param HTMLPurifier_Context $context
30
+     */
28 31
     public function __construct($context) {
29 32
         $this->locale    =& $context->get('Locale');
30 33
         $this->context   = $context;
Please login to merge, or discard this patch.
Indentation   +196 added lines, -196 removed lines patch added patch discarded remove patch
@@ -7,202 +7,202 @@
 block discarded – undo
7 7
 class HTMLPurifier_ErrorCollector
8 8
 {
9 9
 
10
-    /**
11
-     * Identifiers for the returned error array. These are purposely numeric
12
-     * so list() can be used.
13
-     */
14
-    const LINENO   = 0;
15
-    const SEVERITY = 1;
16
-    const MESSAGE  = 2;
17
-    const CHILDREN = 3;
18
-
19
-    protected $errors;
20
-    protected $_current;
21
-    protected $_stacks = array(array());
22
-    protected $locale;
23
-    protected $generator;
24
-    protected $context;
25
-
26
-    protected $lines = array();
27
-
28
-    public function __construct($context) {
29
-        $this->locale    =& $context->get('Locale');
30
-        $this->context   = $context;
31
-        $this->_current  =& $this->_stacks[0];
32
-        $this->errors    =& $this->_stacks[0];
33
-    }
34
-
35
-    /**
36
-     * Sends an error message to the collector for later use
37
-     * @param $severity int Error severity, PHP error style (don't use E_USER_)
38
-     * @param $msg string Error message text
39
-     * @param $subst1 string First substitution for $msg
40
-     * @param $subst2 string ...
41
-     */
42
-    public function send($severity, $msg) {
43
-
44
-        $args = array();
45
-        if (func_num_args() > 2) {
46
-            $args = func_get_args();
47
-            array_shift($args);
48
-            unset($args[0]);
49
-        }
50
-
51
-        $token = $this->context->get('CurrentToken', true);
52
-        $line  = $token ? $token->line : $this->context->get('CurrentLine', true);
53
-        $col   = $token ? $token->col  : $this->context->get('CurrentCol',  true);
54
-        $attr  = $this->context->get('CurrentAttr', true);
55
-
56
-        // perform special substitutions, also add custom parameters
57
-        $subst = array();
58
-        if (!is_null($token)) {
59
-            $args['CurrentToken'] = $token;
60
-        }
61
-        if (!is_null($attr)) {
62
-            $subst['$CurrentAttr.Name'] = $attr;
63
-            if (isset($token->attr[$attr])) $subst['$CurrentAttr.Value'] = $token->attr[$attr];
64
-        }
65
-
66
-        if (empty($args)) {
67
-            $msg = $this->locale->getMessage($msg);
68
-        } else {
69
-            $msg = $this->locale->formatMessage($msg, $args);
70
-        }
71
-
72
-        if (!empty($subst)) $msg = strtr($msg, $subst);
73
-
74
-        // (numerically indexed)
75
-        $error = array(
76
-            self::LINENO   => $line,
77
-            self::SEVERITY => $severity,
78
-            self::MESSAGE  => $msg,
79
-            self::CHILDREN => array()
80
-        );
81
-        $this->_current[] = $error;
82
-
83
-
84
-        // NEW CODE BELOW ...
85
-
86
-        $struct = null;
87
-        // Top-level errors are either:
88
-        //  TOKEN type, if $value is set appropriately, or
89
-        //  "syntax" type, if $value is null
90
-        $new_struct = new HTMLPurifier_ErrorStruct();
91
-        $new_struct->type = HTMLPurifier_ErrorStruct::TOKEN;
92
-        if ($token) $new_struct->value = clone $token;
93
-        if (is_int($line) && is_int($col)) {
94
-            if (isset($this->lines[$line][$col])) {
95
-                $struct = $this->lines[$line][$col];
96
-            } else {
97
-                $struct = $this->lines[$line][$col] = $new_struct;
98
-            }
99
-            // These ksorts may present a performance problem
100
-            ksort($this->lines[$line], SORT_NUMERIC);
101
-        } else {
102
-            if (isset($this->lines[-1])) {
103
-                $struct = $this->lines[-1];
104
-            } else {
105
-                $struct = $this->lines[-1] = $new_struct;
106
-            }
107
-        }
108
-        ksort($this->lines, SORT_NUMERIC);
109
-
110
-        // Now, check if we need to operate on a lower structure
111
-        if (!empty($attr)) {
112
-            $struct = $struct->getChild(HTMLPurifier_ErrorStruct::ATTR, $attr);
113
-            if (!$struct->value) {
114
-                $struct->value = array($attr, 'PUT VALUE HERE');
115
-            }
116
-        }
117
-        if (!empty($cssprop)) {
118
-            $struct = $struct->getChild(HTMLPurifier_ErrorStruct::CSSPROP, $cssprop);
119
-            if (!$struct->value) {
120
-                // if we tokenize CSS this might be a little more difficult to do
121
-                $struct->value = array($cssprop, 'PUT VALUE HERE');
122
-            }
123
-        }
124
-
125
-        // Ok, structs are all setup, now time to register the error
126
-        $struct->addError($severity, $msg);
127
-    }
128
-
129
-    /**
130
-     * Retrieves raw error data for custom formatter to use
131
-     * @param List of arrays in format of array(line of error,
132
-     *        error severity, error message,
133
-     *        recursive sub-errors array)
134
-     */
135
-    public function getRaw() {
136
-        return $this->errors;
137
-    }
138
-
139
-    /**
140
-     * Default HTML formatting implementation for error messages
141
-     * @param $config Configuration array, vital for HTML output nature
142
-     * @param $errors Errors array to display; used for recursion.
143
-     */
144
-    public function getHTMLFormatted($config, $errors = null) {
145
-        $ret = array();
146
-
147
-        $this->generator = new HTMLPurifier_Generator($config, $this->context);
148
-        if ($errors === null) $errors = $this->errors;
149
-
150
-        // 'At line' message needs to be removed
151
-
152
-        // generation code for new structure goes here. It needs to be recursive.
153
-        foreach ($this->lines as $line => $col_array) {
154
-            if ($line == -1) continue;
155
-            foreach ($col_array as $col => $struct) {
156
-                $this->_renderStruct($ret, $struct, $line, $col);
157
-            }
158
-        }
159
-        if (isset($this->lines[-1])) {
160
-            $this->_renderStruct($ret, $this->lines[-1]);
161
-        }
162
-
163
-        if (empty($errors)) {
164
-            return '<p>' . $this->locale->getMessage('ErrorCollector: No errors') . '</p>';
165
-        } else {
166
-            return '<ul><li>' . implode('</li><li>', $ret) . '</li></ul>';
167
-        }
168
-
169
-    }
170
-
171
-    private function _renderStruct(&$ret, $struct, $line = null, $col = null) {
172
-        $stack = array($struct);
173
-        $context_stack = array(array());
174
-        while ($current = array_pop($stack)) {
175
-            $context = array_pop($context_stack);
176
-            foreach ($current->errors as $error) {
177
-                list($severity, $msg) = $error;
178
-                $string = '';
179
-                $string .= '<div>';
180
-                // W3C uses an icon to indicate the severity of the error.
181
-                $error = $this->locale->getErrorName($severity);
182
-                $string .= "<span class=\"error e$severity\"><strong>$error</strong></span> ";
183
-                if (!is_null($line) && !is_null($col)) {
184
-                    $string .= "<em class=\"location\">Line $line, Column $col: </em> ";
185
-                } else {
186
-                    $string .= '<em class="location">End of Document: </em> ';
187
-                }
188
-                $string .= '<strong class="description">' . $this->generator->escape($msg) . '</strong> ';
189
-                $string .= '</div>';
190
-                // Here, have a marker for the character on the column appropriate.
191
-                // Be sure to clip extremely long lines.
192
-                //$string .= '<pre>';
193
-                //$string .= '';
194
-                //$string .= '</pre>';
195
-                $ret[] = $string;
196
-            }
197
-            foreach ($current->children as $type => $array) {
198
-                $context[] = $current;
199
-                $stack = array_merge($stack, array_reverse($array, true));
200
-                for ($i = count($array); $i > 0; $i--) {
201
-                    $context_stack[] = $context;
202
-                }
203
-            }
204
-        }
205
-    }
10
+	/**
11
+	 * Identifiers for the returned error array. These are purposely numeric
12
+	 * so list() can be used.
13
+	 */
14
+	const LINENO   = 0;
15
+	const SEVERITY = 1;
16
+	const MESSAGE  = 2;
17
+	const CHILDREN = 3;
18
+
19
+	protected $errors;
20
+	protected $_current;
21
+	protected $_stacks = array(array());
22
+	protected $locale;
23
+	protected $generator;
24
+	protected $context;
25
+
26
+	protected $lines = array();
27
+
28
+	public function __construct($context) {
29
+		$this->locale    =& $context->get('Locale');
30
+		$this->context   = $context;
31
+		$this->_current  =& $this->_stacks[0];
32
+		$this->errors    =& $this->_stacks[0];
33
+	}
34
+
35
+	/**
36
+	 * Sends an error message to the collector for later use
37
+	 * @param $severity int Error severity, PHP error style (don't use E_USER_)
38
+	 * @param $msg string Error message text
39
+	 * @param $subst1 string First substitution for $msg
40
+	 * @param $subst2 string ...
41
+	 */
42
+	public function send($severity, $msg) {
43
+
44
+		$args = array();
45
+		if (func_num_args() > 2) {
46
+			$args = func_get_args();
47
+			array_shift($args);
48
+			unset($args[0]);
49
+		}
50
+
51
+		$token = $this->context->get('CurrentToken', true);
52
+		$line  = $token ? $token->line : $this->context->get('CurrentLine', true);
53
+		$col   = $token ? $token->col  : $this->context->get('CurrentCol',  true);
54
+		$attr  = $this->context->get('CurrentAttr', true);
55
+
56
+		// perform special substitutions, also add custom parameters
57
+		$subst = array();
58
+		if (!is_null($token)) {
59
+			$args['CurrentToken'] = $token;
60
+		}
61
+		if (!is_null($attr)) {
62
+			$subst['$CurrentAttr.Name'] = $attr;
63
+			if (isset($token->attr[$attr])) $subst['$CurrentAttr.Value'] = $token->attr[$attr];
64
+		}
65
+
66
+		if (empty($args)) {
67
+			$msg = $this->locale->getMessage($msg);
68
+		} else {
69
+			$msg = $this->locale->formatMessage($msg, $args);
70
+		}
71
+
72
+		if (!empty($subst)) $msg = strtr($msg, $subst);
73
+
74
+		// (numerically indexed)
75
+		$error = array(
76
+			self::LINENO   => $line,
77
+			self::SEVERITY => $severity,
78
+			self::MESSAGE  => $msg,
79
+			self::CHILDREN => array()
80
+		);
81
+		$this->_current[] = $error;
82
+
83
+
84
+		// NEW CODE BELOW ...
85
+
86
+		$struct = null;
87
+		// Top-level errors are either:
88
+		//  TOKEN type, if $value is set appropriately, or
89
+		//  "syntax" type, if $value is null
90
+		$new_struct = new HTMLPurifier_ErrorStruct();
91
+		$new_struct->type = HTMLPurifier_ErrorStruct::TOKEN;
92
+		if ($token) $new_struct->value = clone $token;
93
+		if (is_int($line) && is_int($col)) {
94
+			if (isset($this->lines[$line][$col])) {
95
+				$struct = $this->lines[$line][$col];
96
+			} else {
97
+				$struct = $this->lines[$line][$col] = $new_struct;
98
+			}
99
+			// These ksorts may present a performance problem
100
+			ksort($this->lines[$line], SORT_NUMERIC);
101
+		} else {
102
+			if (isset($this->lines[-1])) {
103
+				$struct = $this->lines[-1];
104
+			} else {
105
+				$struct = $this->lines[-1] = $new_struct;
106
+			}
107
+		}
108
+		ksort($this->lines, SORT_NUMERIC);
109
+
110
+		// Now, check if we need to operate on a lower structure
111
+		if (!empty($attr)) {
112
+			$struct = $struct->getChild(HTMLPurifier_ErrorStruct::ATTR, $attr);
113
+			if (!$struct->value) {
114
+				$struct->value = array($attr, 'PUT VALUE HERE');
115
+			}
116
+		}
117
+		if (!empty($cssprop)) {
118
+			$struct = $struct->getChild(HTMLPurifier_ErrorStruct::CSSPROP, $cssprop);
119
+			if (!$struct->value) {
120
+				// if we tokenize CSS this might be a little more difficult to do
121
+				$struct->value = array($cssprop, 'PUT VALUE HERE');
122
+			}
123
+		}
124
+
125
+		// Ok, structs are all setup, now time to register the error
126
+		$struct->addError($severity, $msg);
127
+	}
128
+
129
+	/**
130
+	 * Retrieves raw error data for custom formatter to use
131
+	 * @param List of arrays in format of array(line of error,
132
+	 *        error severity, error message,
133
+	 *        recursive sub-errors array)
134
+	 */
135
+	public function getRaw() {
136
+		return $this->errors;
137
+	}
138
+
139
+	/**
140
+	 * Default HTML formatting implementation for error messages
141
+	 * @param $config Configuration array, vital for HTML output nature
142
+	 * @param $errors Errors array to display; used for recursion.
143
+	 */
144
+	public function getHTMLFormatted($config, $errors = null) {
145
+		$ret = array();
146
+
147
+		$this->generator = new HTMLPurifier_Generator($config, $this->context);
148
+		if ($errors === null) $errors = $this->errors;
149
+
150
+		// 'At line' message needs to be removed
151
+
152
+		// generation code for new structure goes here. It needs to be recursive.
153
+		foreach ($this->lines as $line => $col_array) {
154
+			if ($line == -1) continue;
155
+			foreach ($col_array as $col => $struct) {
156
+				$this->_renderStruct($ret, $struct, $line, $col);
157
+			}
158
+		}
159
+		if (isset($this->lines[-1])) {
160
+			$this->_renderStruct($ret, $this->lines[-1]);
161
+		}
162
+
163
+		if (empty($errors)) {
164
+			return '<p>' . $this->locale->getMessage('ErrorCollector: No errors') . '</p>';
165
+		} else {
166
+			return '<ul><li>' . implode('</li><li>', $ret) . '</li></ul>';
167
+		}
168
+
169
+	}
170
+
171
+	private function _renderStruct(&$ret, $struct, $line = null, $col = null) {
172
+		$stack = array($struct);
173
+		$context_stack = array(array());
174
+		while ($current = array_pop($stack)) {
175
+			$context = array_pop($context_stack);
176
+			foreach ($current->errors as $error) {
177
+				list($severity, $msg) = $error;
178
+				$string = '';
179
+				$string .= '<div>';
180
+				// W3C uses an icon to indicate the severity of the error.
181
+				$error = $this->locale->getErrorName($severity);
182
+				$string .= "<span class=\"error e$severity\"><strong>$error</strong></span> ";
183
+				if (!is_null($line) && !is_null($col)) {
184
+					$string .= "<em class=\"location\">Line $line, Column $col: </em> ";
185
+				} else {
186
+					$string .= '<em class="location">End of Document: </em> ';
187
+				}
188
+				$string .= '<strong class="description">' . $this->generator->escape($msg) . '</strong> ';
189
+				$string .= '</div>';
190
+				// Here, have a marker for the character on the column appropriate.
191
+				// Be sure to clip extremely long lines.
192
+				//$string .= '<pre>';
193
+				//$string .= '';
194
+				//$string .= '</pre>';
195
+				$ret[] = $string;
196
+			}
197
+			foreach ($current->children as $type => $array) {
198
+				$context[] = $current;
199
+				$stack = array_merge($stack, array_reverse($array, true));
200
+				for ($i = count($array); $i > 0; $i--) {
201
+					$context_stack[] = $context;
202
+				}
203
+			}
204
+		}
205
+	}
206 206
 
207 207
 }
208 208
 
Please login to merge, or discard this patch.
Braces   +15 added lines, -5 removed lines patch added patch discarded remove patch
@@ -60,7 +60,9 @@  discard block
 block discarded – undo
60 60
         }
61 61
         if (!is_null($attr)) {
62 62
             $subst['$CurrentAttr.Name'] = $attr;
63
-            if (isset($token->attr[$attr])) $subst['$CurrentAttr.Value'] = $token->attr[$attr];
63
+            if (isset($token->attr[$attr])) {
64
+            	$subst['$CurrentAttr.Value'] = $token->attr[$attr];
65
+            }
64 66
         }
65 67
 
66 68
         if (empty($args)) {
@@ -69,7 +71,9 @@  discard block
 block discarded – undo
69 71
             $msg = $this->locale->formatMessage($msg, $args);
70 72
         }
71 73
 
72
-        if (!empty($subst)) $msg = strtr($msg, $subst);
74
+        if (!empty($subst)) {
75
+        	$msg = strtr($msg, $subst);
76
+        }
73 77
 
74 78
         // (numerically indexed)
75 79
         $error = array(
@@ -89,7 +93,9 @@  discard block
 block discarded – undo
89 93
         //  "syntax" type, if $value is null
90 94
         $new_struct = new HTMLPurifier_ErrorStruct();
91 95
         $new_struct->type = HTMLPurifier_ErrorStruct::TOKEN;
92
-        if ($token) $new_struct->value = clone $token;
96
+        if ($token) {
97
+        	$new_struct->value = clone $token;
98
+        }
93 99
         if (is_int($line) && is_int($col)) {
94 100
             if (isset($this->lines[$line][$col])) {
95 101
                 $struct = $this->lines[$line][$col];
@@ -145,13 +151,17 @@  discard block
 block discarded – undo
145 151
         $ret = array();
146 152
 
147 153
         $this->generator = new HTMLPurifier_Generator($config, $this->context);
148
-        if ($errors === null) $errors = $this->errors;
154
+        if ($errors === null) {
155
+        	$errors = $this->errors;
156
+        }
149 157
 
150 158
         // 'At line' message needs to be removed
151 159
 
152 160
         // generation code for new structure goes here. It needs to be recursive.
153 161
         foreach ($this->lines as $line => $col_array) {
154
-            if ($line == -1) continue;
162
+            if ($line == -1) {
163
+            	continue;
164
+            }
155 165
             foreach ($col_array as $col => $struct) {
156 166
                 $this->_renderStruct($ret, $struct, $line, $col);
157 167
             }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -26,10 +26,10 @@  discard block
 block discarded – undo
26 26
     protected $lines = array();
27 27
 
28 28
     public function __construct($context) {
29
-        $this->locale    =& $context->get('Locale');
29
+        $this->locale    = & $context->get('Locale');
30 30
         $this->context   = $context;
31
-        $this->_current  =& $this->_stacks[0];
32
-        $this->errors    =& $this->_stacks[0];
31
+        $this->_current  = & $this->_stacks[0];
32
+        $this->errors    = & $this->_stacks[0];
33 33
     }
34 34
 
35 35
     /**
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 
51 51
         $token = $this->context->get('CurrentToken', true);
52 52
         $line  = $token ? $token->line : $this->context->get('CurrentLine', true);
53
-        $col   = $token ? $token->col  : $this->context->get('CurrentCol',  true);
53
+        $col   = $token ? $token->col : $this->context->get('CurrentCol', true);
54 54
         $attr  = $this->context->get('CurrentAttr', true);
55 55
 
56 56
         // perform special substitutions, also add custom parameters
@@ -161,9 +161,9 @@  discard block
 block discarded – undo
161 161
         }
162 162
 
163 163
         if (empty($errors)) {
164
-            return '<p>' . $this->locale->getMessage('ErrorCollector: No errors') . '</p>';
164
+            return '<p>'.$this->locale->getMessage('ErrorCollector: No errors').'</p>';
165 165
         } else {
166
-            return '<ul><li>' . implode('</li><li>', $ret) . '</li></ul>';
166
+            return '<ul><li>'.implode('</li><li>', $ret).'</li></ul>';
167 167
         }
168 168
 
169 169
     }
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
                 } else {
186 186
                     $string .= '<em class="location">End of Document: </em> ';
187 187
                 }
188
-                $string .= '<strong class="description">' . $this->generator->escape($msg) . '</strong> ';
188
+                $string .= '<strong class="description">'.$this->generator->escape($msg).'</strong> ';
189 189
                 $string .= '</div>';
190 190
                 // Here, have a marker for the character on the column appropriate.
191 191
                 // Be sure to clip extremely long lines.
Please login to merge, or discard this patch.