@@ -128,7 +128,7 @@ |
||
128 | 128 | /** |
129 | 129 | * Constructor function |
130 | 130 | * |
131 | - * @return void |
|
131 | + * @return string |
|
132 | 132 | */ |
133 | 133 | function Mail() |
134 | 134 | { |
@@ -151,8 +151,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -1,7 +1,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
@@ -112,7 +112,7 @@ discard block |
||
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 |
||
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); |
@@ -59,10 +59,10 @@ |
||
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; |
@@ -35,7 +35,7 @@ discard block |
||
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,10 +43,10 @@ discard block |
||
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 | - if($logged_info->is_admin != "Y") |
|
49 | + if ($logged_info->is_admin != "Y") |
|
50 | 50 | { |
51 | 51 | $this->error = 'msg_invalid_request'; |
52 | 52 | return; |
@@ -59,26 +59,26 @@ discard block |
||
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')) |
|
62 | + if ($entry = Context::get('entry')) |
|
63 | 63 | { |
64 | 64 | $this->entry = Context::convertEncodingStr($entry); |
65 | 65 | } |
66 | 66 | |
67 | 67 | // Validate variables to prevent XSS |
68 | 68 | $isInvalid = NULL; |
69 | - if($this->module && !preg_match("/^([a-z0-9\_\-]+)$/i", $this->module)) |
|
69 | + if ($this->module && !preg_match("/^([a-z0-9\_\-]+)$/i", $this->module)) |
|
70 | 70 | { |
71 | 71 | $isInvalid = TRUE; |
72 | 72 | } |
73 | - if($this->mid && !preg_match("/^([a-z0-9\_\-]+)$/i", $this->mid)) |
|
73 | + if ($this->mid && !preg_match("/^([a-z0-9\_\-]+)$/i", $this->mid)) |
|
74 | 74 | { |
75 | 75 | $isInvalid = TRUE; |
76 | 76 | } |
77 | - if($this->act && !preg_match("/^([a-z0-9\_\-]+)$/i", $this->act)) |
|
77 | + if ($this->act && !preg_match("/^([a-z0-9\_\-]+)$/i", $this->act)) |
|
78 | 78 | { |
79 | 79 | $isInvalid = TRUE; |
80 | 80 | } |
81 | - if($isInvalid) |
|
81 | + if ($isInvalid) |
|
82 | 82 | { |
83 | 83 | htmlHeader(); |
84 | 84 | echo Context::getLang("msg_invalid_request"); |
@@ -87,14 +87,14 @@ discard block |
||
87 | 87 | exit; |
88 | 88 | } |
89 | 89 | |
90 | - if(isset($this->act) && (strlen($this->act) >= 4 && substr_compare($this->act, 'disp', 0, 4) === 0)) |
|
90 | + if (isset($this->act) && (strlen($this->act) >= 4 && substr_compare($this->act, 'disp', 0, 4) === 0)) |
|
91 | 91 | { |
92 | - if(Context::get('_use_ssl') == 'optional' && Context::isExistsSSLAction($this->act) && $_SERVER['HTTPS'] != 'on') |
|
92 | + if (Context::get('_use_ssl') == 'optional' && Context::isExistsSSLAction($this->act) && $_SERVER['HTTPS'] != 'on') |
|
93 | 93 | { |
94 | - if(Context::get('_https_port')!=null) { |
|
95 | - header('location:https://' . $_SERVER['HTTP_HOST'] . ':' . Context::get('_https_port') . $_SERVER['REQUEST_URI']); |
|
94 | + if (Context::get('_https_port') != null) { |
|
95 | + header('location:https://'.$_SERVER['HTTP_HOST'].':'.Context::get('_https_port').$_SERVER['REQUEST_URI']); |
|
96 | 96 | } else { |
97 | - header('location:https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); |
|
97 | + header('location:https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); |
|
98 | 98 | } |
99 | 99 | return; |
100 | 100 | } |
@@ -102,9 +102,9 @@ discard block |
||
102 | 102 | |
103 | 103 | // call a trigger before moduleHandler init |
104 | 104 | ModuleHandler::triggerCall('moduleHandler.init', 'before', $this); |
105 | - if(__ERROR_LOG__ == 1 && __DEBUG_OUTPUT__ == 0) |
|
105 | + if (__ERROR_LOG__ == 1 && __DEBUG_OUTPUT__ == 0) |
|
106 | 106 | { |
107 | - if(__DEBUG_PROTECT__ === 0 || __DEBUG_PROTECT__ === 1 && __DEBUG_PROTECT_IP__ == $_SERVER['REMOTE_ADDR']) |
|
107 | + if (__DEBUG_PROTECT__ === 0 || __DEBUG_PROTECT__ === 1 && __DEBUG_PROTECT_IP__ == $_SERVER['REMOTE_ADDR']) |
|
108 | 108 | { |
109 | 109 | set_error_handler(array($this, 'xeErrorLog'), E_WARNING); |
110 | 110 | register_shutdown_function(array($this, 'shutdownHandler')); |
@@ -115,40 +115,40 @@ discard block |
||
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)) include($addon_file); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | public static function xeErrorLog($errnumber, $errormassage, $errorfile, $errorline, $errorcontext) |
122 | 122 | { |
123 | - if(($errnumber & 3) == 0 || error_reporting() == 0) |
|
123 | + if (($errnumber & 3) == 0 || error_reporting() == 0) |
|
124 | 124 | { |
125 | 125 | return false; |
126 | 126 | } |
127 | 127 | |
128 | 128 | set_error_handler(function() { }, ~0); |
129 | 129 | |
130 | - $debug_file = _XE_PATH_ . 'files/_debug_message.php'; |
|
131 | - if(!file_exists($debug_file)) |
|
130 | + $debug_file = _XE_PATH_.'files/_debug_message.php'; |
|
131 | + if (!file_exists($debug_file)) |
|
132 | 132 | { |
133 | 133 | $print[] = '<?php exit() ?>'; |
134 | 134 | } |
135 | 135 | |
136 | 136 | $errorname = self::getErrorType($errnumber); |
137 | - $print[] = '['.date('Y-m-d H:i:s').'] ' . $errorname . ' : ' . $errormassage; |
|
137 | + $print[] = '['.date('Y-m-d H:i:s').'] '.$errorname.' : '.$errormassage; |
|
138 | 138 | $backtrace_args = defined('DEBUG_BACKTRACE_IGNORE_ARGS') ? \DEBUG_BACKTRACE_IGNORE_ARGS : 0; |
139 | 139 | $backtrace = debug_backtrace($backtrace_args); |
140 | - if(count($backtrace) > 1 && $backtrace[1]['function'] === 'xeErrorLog' && !$backtrace[1]['class']) |
|
140 | + if (count($backtrace) > 1 && $backtrace[1]['function'] === 'xeErrorLog' && !$backtrace[1]['class']) |
|
141 | 141 | { |
142 | 142 | array_shift($backtrace); |
143 | 143 | } |
144 | 144 | |
145 | - foreach($backtrace as $key => $value) |
|
145 | + foreach ($backtrace as $key => $value) |
|
146 | 146 | { |
147 | - $message = ' - ' . $value['file'] . ' : ' . $value['line']; |
|
147 | + $message = ' - '.$value['file'].' : '.$value['line']; |
|
148 | 148 | $print[] = $message; |
149 | 149 | } |
150 | 150 | $print[] = PHP_EOL; |
151 | - @file_put_contents($debug_file, implode(PHP_EOL, $print), FILE_APPEND|LOCK_EX); |
|
151 | + @file_put_contents($debug_file, implode(PHP_EOL, $print), FILE_APPEND | LOCK_EX); |
|
152 | 152 | restore_error_handler(); |
153 | 153 | |
154 | 154 | return true; |
@@ -164,21 +164,21 @@ discard block |
||
164 | 164 | |
165 | 165 | set_error_handler(function() { }, ~0); |
166 | 166 | |
167 | - $debug_file = _XE_PATH_ . 'files/_debug_message.php'; |
|
168 | - if(!file_exists($debug_file)) |
|
167 | + $debug_file = _XE_PATH_.'files/_debug_message.php'; |
|
168 | + if (!file_exists($debug_file)) |
|
169 | 169 | { |
170 | 170 | $print[] = '<?php exit() ?>'; |
171 | 171 | } |
172 | 172 | |
173 | 173 | $errorname = self::getErrorType($errinfo['type']); |
174 | 174 | $print[] = '['.date('Y-m-d H:i:s').']'; |
175 | - $print[] = $errorname . ' : ' . $errinfo['message']; |
|
175 | + $print[] = $errorname.' : '.$errinfo['message']; |
|
176 | 176 | |
177 | - $message = ' - ' . $errinfo['file'] . ' : ' . $errinfo['line']; |
|
177 | + $message = ' - '.$errinfo['file'].' : '.$errinfo['line']; |
|
178 | 178 | $print[] = $message; |
179 | 179 | |
180 | 180 | $print[] = PHP_EOL; |
181 | - @file_put_contents($debug_file, implode(PHP_EOL, $print), FILE_APPEND|LOCK_EX); |
|
181 | + @file_put_contents($debug_file, implode(PHP_EOL, $print), FILE_APPEND | LOCK_EX); |
|
182 | 182 | set_error_handler(array($this, 'dummyHandler'), ~0); |
183 | 183 | |
184 | 184 | return true; |
@@ -222,9 +222,9 @@ discard block |
||
222 | 222 | $defaultUrlInfo = parse_url($dbInfo->default_url); |
223 | 223 | $defaultHost = $defaultUrlInfo['host']; |
224 | 224 | |
225 | - foreach($urls as $url) |
|
225 | + foreach ($urls as $url) |
|
226 | 226 | { |
227 | - if(empty($url)) |
|
227 | + if (empty($url)) |
|
228 | 228 | { |
229 | 229 | continue; |
230 | 230 | } |
@@ -232,29 +232,29 @@ discard block |
||
232 | 232 | $urlInfo = parse_url($url); |
233 | 233 | $host = $urlInfo['host']; |
234 | 234 | |
235 | - if($host && ($host != $defaultHost && $host != $site_module_info->domain)) |
|
235 | + if ($host && ($host != $defaultHost && $host != $site_module_info->domain)) |
|
236 | 236 | { |
237 | 237 | throw new Exception('msg_default_url_is_null'); |
238 | 238 | } |
239 | 239 | } |
240 | 240 | |
241 | - if(!$this->document_srl && $this->mid && $this->entry) |
|
241 | + if (!$this->document_srl && $this->mid && $this->entry) |
|
242 | 242 | { |
243 | 243 | $oDocumentModel = getModel('document'); |
244 | 244 | $this->document_srl = $oDocumentModel->getDocumentSrlByAlias($this->mid, $this->entry); |
245 | - if($this->document_srl) |
|
245 | + if ($this->document_srl) |
|
246 | 246 | { |
247 | 247 | Context::set('document_srl', $this->document_srl); |
248 | 248 | } |
249 | 249 | } |
250 | 250 | |
251 | 251 | // Get module's information based on document_srl, if it's specified |
252 | - if($this->document_srl) |
|
252 | + if ($this->document_srl) |
|
253 | 253 | { |
254 | 254 | |
255 | 255 | $module_info = $oModuleModel->getModuleInfoByDocumentSrl($this->document_srl); |
256 | 256 | // If the document does not exist, remove document_srl |
257 | - if(!$module_info) |
|
257 | + if (!$module_info) |
|
258 | 258 | { |
259 | 259 | unset($this->document_srl); |
260 | 260 | } |
@@ -262,13 +262,13 @@ discard block |
||
262 | 262 | { |
263 | 263 | // If it exists, compare mid based on the module information |
264 | 264 | // if mids are not matching, set it as the document's mid |
265 | - if(!$this->mid || ($this->mid != $module_info->mid)) |
|
265 | + if (!$this->mid || ($this->mid != $module_info->mid)) |
|
266 | 266 | { |
267 | 267 | |
268 | - if(Context::getRequestMethod() == 'GET') |
|
268 | + if (Context::getRequestMethod() == 'GET') |
|
269 | 269 | { |
270 | 270 | $this->mid = $module_info->mid; |
271 | - header('location:' . getNotEncodedSiteUrl($site_module_info->domain, 'mid', $this->mid, 'document_srl', $this->document_srl)); |
|
271 | + header('location:'.getNotEncodedSiteUrl($site_module_info->domain, 'mid', $this->mid, 'document_srl', $this->document_srl)); |
|
272 | 272 | return FALSE; |
273 | 273 | } |
274 | 274 | else |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | |
280 | 280 | } |
281 | 281 | // if requested module is different from one of the document, remove the module information retrieved based on the document number |
282 | - if($this->module && $module_info->module != $this->module) |
|
282 | + if ($this->module && $module_info->module != $this->module) |
|
283 | 283 | { |
284 | 284 | unset($module_info); |
285 | 285 | } |
@@ -288,36 +288,36 @@ discard block |
||
288 | 288 | } |
289 | 289 | |
290 | 290 | // If module_info is not set yet, and there exists mid information, get module information based on the mid |
291 | - if(!$module_info && $this->mid) |
|
291 | + if (!$module_info && $this->mid) |
|
292 | 292 | { |
293 | 293 | $module_info = $oModuleModel->getModuleInfoByMid($this->mid, $site_module_info->site_srl); |
294 | 294 | //if($this->module && $module_info->module != $this->module) unset($module_info); |
295 | 295 | } |
296 | 296 | |
297 | 297 | // redirect, if module_site_srl and site_srl are different |
298 | - if(!$this->module && !$module_info && $site_module_info->site_srl == 0 && $site_module_info->module_site_srl > 0) |
|
298 | + if (!$this->module && !$module_info && $site_module_info->site_srl == 0 && $site_module_info->module_site_srl > 0) |
|
299 | 299 | { |
300 | 300 | $site_info = $oModuleModel->getSiteInfo($site_module_info->module_site_srl); |
301 | - header("location:" . getNotEncodedSiteUrl($site_info->domain, 'mid', $site_module_info->mid)); |
|
301 | + header("location:".getNotEncodedSiteUrl($site_info->domain, 'mid', $site_module_info->mid)); |
|
302 | 302 | return FALSE; |
303 | 303 | } |
304 | 304 | |
305 | 305 | // If module_info is not set still, and $module does not exist, find the default module |
306 | - if(!$module_info && !$this->module && !$this->mid) |
|
306 | + if (!$module_info && !$this->module && !$this->mid) |
|
307 | 307 | { |
308 | 308 | $module_info = $site_module_info; |
309 | 309 | } |
310 | 310 | |
311 | - if(!$module_info && !$this->module && $site_module_info->module_site_srl) |
|
311 | + if (!$module_info && !$this->module && $site_module_info->module_site_srl) |
|
312 | 312 | { |
313 | 313 | $module_info = $site_module_info; |
314 | 314 | } |
315 | 315 | |
316 | 316 | // redirect, if site_srl of module_info is different from one of site's module_info |
317 | - if($module_info && $module_info->site_srl != $site_module_info->site_srl && !isCrawler()) |
|
317 | + if ($module_info && $module_info->site_srl != $site_module_info->site_srl && !isCrawler()) |
|
318 | 318 | { |
319 | 319 | // If the module is of virtual site |
320 | - if($module_info->site_srl) |
|
320 | + if ($module_info->site_srl) |
|
321 | 321 | { |
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')); |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | else |
327 | 327 | { |
328 | 328 | $db_info = Context::getDBInfo(); |
329 | - if(!$db_info->default_url) |
|
329 | + if (!$db_info->default_url) |
|
330 | 330 | { |
331 | 331 | return Context::getLang('msg_default_url_is_not_defined'); |
332 | 332 | } |
@@ -335,12 +335,12 @@ discard block |
||
335 | 335 | $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 | 336 | } |
337 | 337 | } |
338 | - header("location:" . $redirect_url); |
|
338 | + header("location:".$redirect_url); |
|
339 | 339 | return FALSE; |
340 | 340 | } |
341 | 341 | |
342 | 342 | // If module info was set, retrieve variables from the module information |
343 | - if($module_info) |
|
343 | + if ($module_info) |
|
344 | 344 | { |
345 | 345 | $this->module = $module_info->module; |
346 | 346 | $this->mid = $module_info->mid; |
@@ -351,7 +351,7 @@ discard block |
||
351 | 351 | $targetSrl = (Mobile::isFromMobilePhone()) ? 'mlayout_srl' : 'layout_srl'; |
352 | 352 | |
353 | 353 | // use the site default layout. |
354 | - if($module_info->{$targetSrl} == -1) |
|
354 | + if ($module_info->{$targetSrl} == -1) |
|
355 | 355 | { |
356 | 356 | $oLayoutAdminModel = getAdminModel('layout'); |
357 | 357 | $layoutSrl = $oLayoutAdminModel->getSiteDefaultLayout($viewType, $module_info->site_srl); |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | } |
370 | 370 | |
371 | 371 | // Set module and mid into module_info |
372 | - if(!isset($this->module_info)) |
|
372 | + if (!isset($this->module_info)) |
|
373 | 373 | { |
374 | 374 | $this->module_info = new stdClass(); |
375 | 375 | } |
@@ -380,21 +380,21 @@ discard block |
||
380 | 380 | $this->module_info->site_srl = $site_module_info->site_srl; |
381 | 381 | |
382 | 382 | // Still no module? it's an error |
383 | - if(!$this->module) |
|
383 | + if (!$this->module) |
|
384 | 384 | { |
385 | 385 | $this->error = 'msg_module_is_not_exists'; |
386 | 386 | $this->httpStatusCode = '404'; |
387 | 387 | } |
388 | 388 | |
389 | 389 | // If mid exists, set mid into context |
390 | - if($this->mid) |
|
390 | + if ($this->mid) |
|
391 | 391 | { |
392 | 392 | Context::set('mid', $this->mid, TRUE); |
393 | 393 | } |
394 | 394 | |
395 | 395 | // Call a trigger after moduleHandler init |
396 | 396 | $output = ModuleHandler::triggerCall('moduleHandler.init', 'after', $this->module_info); |
397 | - if(!$output->toBool()) |
|
397 | + if (!$output->toBool()) |
|
398 | 398 | { |
399 | 399 | $this->error = $output->getMessage(); |
400 | 400 | return TRUE; |
@@ -416,14 +416,14 @@ discard block |
||
416 | 416 | $display_mode = Mobile::isFromMobilePhone() ? 'mobile' : 'view'; |
417 | 417 | |
418 | 418 | // If error occurred while preparation, return a message instance |
419 | - if($this->error) |
|
419 | + if ($this->error) |
|
420 | 420 | { |
421 | 421 | $this->_setInputErrorToContext(); |
422 | 422 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
423 | 423 | $oMessageObject->setError(-1); |
424 | 424 | $oMessageObject->setMessage($this->error); |
425 | 425 | $oMessageObject->dispMessage(); |
426 | - if($this->httpStatusCode) |
|
426 | + if ($this->httpStatusCode) |
|
427 | 427 | { |
428 | 428 | $oMessageObject->setHttpStatusCode($this->httpStatusCode); |
429 | 429 | } |
@@ -434,22 +434,22 @@ discard block |
||
434 | 434 | $xml_info = $oModuleModel->getModuleActionXml($this->module); |
435 | 435 | |
436 | 436 | // If not installed yet, modify act |
437 | - if($this->module == "install") |
|
437 | + if ($this->module == "install") |
|
438 | 438 | { |
439 | - if(!$this->act || !$xml_info->action->{$this->act}) |
|
439 | + if (!$this->act || !$xml_info->action->{$this->act}) |
|
440 | 440 | { |
441 | 441 | $this->act = $xml_info->default_index_act; |
442 | 442 | } |
443 | 443 | } |
444 | 444 | |
445 | 445 | // if act exists, find type of the action, if not use default index act |
446 | - if(!$this->act) |
|
446 | + if (!$this->act) |
|
447 | 447 | { |
448 | 448 | $this->act = $xml_info->default_index_act; |
449 | 449 | } |
450 | 450 | |
451 | 451 | // still no act means error |
452 | - if(!$this->act) |
|
452 | + if (!$this->act) |
|
453 | 453 | { |
454 | 454 | $this->error = 'msg_module_is_not_exists'; |
455 | 455 | $this->httpStatusCode = '404'; |
@@ -459,7 +459,7 @@ discard block |
||
459 | 459 | $oMessageObject->setError(-1); |
460 | 460 | $oMessageObject->setMessage($this->error); |
461 | 461 | $oMessageObject->dispMessage(); |
462 | - if($this->httpStatusCode) |
|
462 | + if ($this->httpStatusCode) |
|
463 | 463 | { |
464 | 464 | $oMessageObject->setHttpStatusCode($this->httpStatusCode); |
465 | 465 | } |
@@ -477,17 +477,17 @@ discard block |
||
477 | 477 | Context::addMetaTag('robots', 'noindex'); |
478 | 478 | } |
479 | 479 | |
480 | - if(!$kind && $this->module == 'admin') |
|
480 | + if (!$kind && $this->module == 'admin') |
|
481 | 481 | { |
482 | 482 | $kind = 'admin'; |
483 | 483 | } |
484 | 484 | |
485 | 485 | // check REQUEST_METHOD in controller |
486 | - if($type == 'controller') |
|
486 | + if ($type == 'controller') |
|
487 | 487 | { |
488 | 488 | $allowedMethod = $xml_info->action->{$this->act}->method; |
489 | 489 | |
490 | - if(!$allowedMethod) |
|
490 | + if (!$allowedMethod) |
|
491 | 491 | { |
492 | 492 | $allowedMethodList[0] = 'POST'; |
493 | 493 | } |
@@ -496,7 +496,7 @@ discard block |
||
496 | 496 | $allowedMethodList = explode('|', strtoupper($allowedMethod)); |
497 | 497 | } |
498 | 498 | |
499 | - if(!in_array(strtoupper($_SERVER['REQUEST_METHOD']), $allowedMethodList)) |
|
499 | + if (!in_array(strtoupper($_SERVER['REQUEST_METHOD']), $allowedMethodList)) |
|
500 | 500 | { |
501 | 501 | $this->error = "msg_invalid_request"; |
502 | 502 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
@@ -507,7 +507,7 @@ discard block |
||
507 | 507 | } |
508 | 508 | } |
509 | 509 | |
510 | - if($this->module_info->use_mobile != "Y") |
|
510 | + if ($this->module_info->use_mobile != "Y") |
|
511 | 511 | { |
512 | 512 | Mobile::setMobile(FALSE); |
513 | 513 | } |
@@ -516,7 +516,7 @@ discard block |
||
516 | 516 | |
517 | 517 | // check CSRF for non-GET actions |
518 | 518 | $use_check_csrf = isset($xml_info->action->{$this->act}) && $xml_info->action->{$this->act}->check_csrf !== 'false'; |
519 | - if($use_check_csrf && $_SERVER['REQUEST_METHOD'] !== 'GET' && Context::isInstalled() && !checkCSRF()) |
|
519 | + if ($use_check_csrf && $_SERVER['REQUEST_METHOD'] !== 'GET' && Context::isInstalled() && !checkCSRF()) |
|
520 | 520 | { |
521 | 521 | $this->error = 'msg_invalid_request'; |
522 | 522 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
@@ -527,7 +527,7 @@ discard block |
||
527 | 527 | } |
528 | 528 | |
529 | 529 | // Admin ip |
530 | - if($kind == 'admin' && $_SESSION['denied_admin'] == 'Y') |
|
530 | + if ($kind == 'admin' && $_SESSION['denied_admin'] == 'Y') |
|
531 | 531 | { |
532 | 532 | $this->_setInputErrorToContext(); |
533 | 533 | $this->error = "msg_not_permitted_act"; |
@@ -539,13 +539,13 @@ discard block |
||
539 | 539 | } |
540 | 540 | |
541 | 541 | // if(type == view, and case for using mobilephone) |
542 | - if($type == "view" && Mobile::isFromMobilePhone() && Context::isInstalled()) |
|
542 | + if ($type == "view" && Mobile::isFromMobilePhone() && Context::isInstalled()) |
|
543 | 543 | { |
544 | 544 | $orig_type = "view"; |
545 | 545 | $type = "mobile"; |
546 | 546 | // create a module instance |
547 | 547 | $oModule = $this->getModuleInstance($this->module, $type, $kind); |
548 | - if(!is_object($oModule) || !method_exists($oModule, $this->act)) |
|
548 | + if (!is_object($oModule) || !method_exists($oModule, $this->act)) |
|
549 | 549 | { |
550 | 550 | $type = $orig_type; |
551 | 551 | Mobile::setMobile(FALSE); |
@@ -558,14 +558,14 @@ discard block |
||
558 | 558 | $oModule = $this->getModuleInstance($this->module, $type, $kind); |
559 | 559 | } |
560 | 560 | |
561 | - if(!is_object($oModule)) |
|
561 | + if (!is_object($oModule)) |
|
562 | 562 | { |
563 | 563 | $this->_setInputErrorToContext(); |
564 | 564 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
565 | 565 | $oMessageObject->setError(-1); |
566 | 566 | $oMessageObject->setMessage($this->error); |
567 | 567 | $oMessageObject->dispMessage(); |
568 | - if($this->httpStatusCode) |
|
568 | + if ($this->httpStatusCode) |
|
569 | 569 | { |
570 | 570 | $oMessageObject->setHttpStatusCode($this->httpStatusCode); |
571 | 571 | } |
@@ -573,10 +573,10 @@ discard block |
||
573 | 573 | } |
574 | 574 | |
575 | 575 | // If there is no such action in the module object |
576 | - if(!isset($xml_info->action->{$this->act}) || !method_exists($oModule, $this->act)) |
|
576 | + if (!isset($xml_info->action->{$this->act}) || !method_exists($oModule, $this->act)) |
|
577 | 577 | { |
578 | 578 | |
579 | - if(!Context::isInstalled()) |
|
579 | + if (!Context::isInstalled()) |
|
580 | 580 | { |
581 | 581 | $this->_setInputErrorToContext(); |
582 | 582 | $this->error = 'msg_invalid_request'; |
@@ -584,7 +584,7 @@ discard block |
||
584 | 584 | $oMessageObject->setError(-1); |
585 | 585 | $oMessageObject->setMessage($this->error); |
586 | 586 | $oMessageObject->dispMessage(); |
587 | - if($this->httpStatusCode) |
|
587 | + if ($this->httpStatusCode) |
|
588 | 588 | { |
589 | 589 | $oMessageObject->setHttpStatusCode($this->httpStatusCode); |
590 | 590 | } |
@@ -593,12 +593,12 @@ discard block |
||
593 | 593 | |
594 | 594 | $forward = NULL; |
595 | 595 | // 1. Look for the module with action name |
596 | - if(preg_match('/^([a-z]+)([A-Z])([a-z0-9\_]+)(.*)$/', $this->act, $matches)) |
|
596 | + if (preg_match('/^([a-z]+)([A-Z])([a-z0-9\_]+)(.*)$/', $this->act, $matches)) |
|
597 | 597 | { |
598 | - $module = strtolower($matches[2] . $matches[3]); |
|
598 | + $module = strtolower($matches[2].$matches[3]); |
|
599 | 599 | $xml_info = $oModuleModel->getModuleActionXml($module); |
600 | 600 | |
601 | - if($xml_info->action->{$this->act} && ((stripos($this->act, 'admin') !== FALSE) || $xml_info->action->{$this->act}->standalone != 'false')) |
|
601 | + if ($xml_info->action->{$this->act} && ((stripos($this->act, 'admin') !== FALSE) || $xml_info->action->{$this->act}->standalone != 'false')) |
|
602 | 602 | { |
603 | 603 | $forward = new stdClass(); |
604 | 604 | $forward->module = $module; |
@@ -619,12 +619,12 @@ discard block |
||
619 | 619 | } |
620 | 620 | } |
621 | 621 | |
622 | - if(!$forward) |
|
622 | + if (!$forward) |
|
623 | 623 | { |
624 | 624 | $forward = $oModuleModel->getActionForward($this->act); |
625 | 625 | } |
626 | 626 | |
627 | - if($forward->module && $forward->type && $forward->act && $forward->act == $this->act) |
|
627 | + if ($forward->module && $forward->type && $forward->act && $forward->act == $this->act) |
|
628 | 628 | { |
629 | 629 | $kind = stripos($forward->act, 'admin') !== FALSE ? 'admin' : ''; |
630 | 630 | $type = $forward->type; |
@@ -632,7 +632,7 @@ discard block |
||
632 | 632 | $tpl_path = $oModule->getTemplatePath(); |
633 | 633 | $orig_module = $oModule; |
634 | 634 | |
635 | - if($forward->meta_noindex === 'true') { |
|
635 | + if ($forward->meta_noindex === 'true') { |
|
636 | 636 | Context::addMetaTag('robots', 'noindex'); |
637 | 637 | } |
638 | 638 | |
@@ -640,7 +640,7 @@ discard block |
||
640 | 640 | |
641 | 641 | // check CSRF for non-GET actions |
642 | 642 | $use_check_csrf = isset($xml_info->action->{$this->act}) && $xml_info->action->{$this->act}->check_csrf !== 'false'; |
643 | - if($use_check_csrf && $_SERVER['REQUEST_METHOD'] !== 'GET' && Context::isInstalled() && !checkCSRF()) |
|
643 | + if ($use_check_csrf && $_SERVER['REQUEST_METHOD'] !== 'GET' && Context::isInstalled() && !checkCSRF()) |
|
644 | 644 | { |
645 | 645 | $this->error = 'msg_invalid_request'; |
646 | 646 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
@@ -652,11 +652,11 @@ discard block |
||
652 | 652 | |
653 | 653 | // SECISSUE also check foward act method |
654 | 654 | // check REQUEST_METHOD in controller |
655 | - if($type == 'controller') |
|
655 | + if ($type == 'controller') |
|
656 | 656 | { |
657 | 657 | $allowedMethod = $xml_info->action->{$forward->act}->method; |
658 | 658 | |
659 | - if(!$allowedMethod) |
|
659 | + if (!$allowedMethod) |
|
660 | 660 | { |
661 | 661 | $allowedMethodList[0] = 'POST'; |
662 | 662 | } |
@@ -665,7 +665,7 @@ discard block |
||
665 | 665 | $allowedMethodList = explode('|', strtoupper($allowedMethod)); |
666 | 666 | } |
667 | 667 | |
668 | - if(!in_array(strtoupper($_SERVER['REQUEST_METHOD']), $allowedMethodList)) |
|
668 | + if (!in_array(strtoupper($_SERVER['REQUEST_METHOD']), $allowedMethodList)) |
|
669 | 669 | { |
670 | 670 | $this->error = "msg_invalid_request"; |
671 | 671 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
@@ -676,13 +676,13 @@ discard block |
||
676 | 676 | } |
677 | 677 | } |
678 | 678 | |
679 | - if($type == "view" && Mobile::isFromMobilePhone()) |
|
679 | + if ($type == "view" && Mobile::isFromMobilePhone()) |
|
680 | 680 | { |
681 | 681 | $orig_type = "view"; |
682 | 682 | $type = "mobile"; |
683 | 683 | // create a module instance |
684 | 684 | $oModule = $this->getModuleInstance($forward->module, $type, $kind); |
685 | - if(!is_object($oModule) || !method_exists($oModule, $this->act)) |
|
685 | + if (!is_object($oModule) || !method_exists($oModule, $this->act)) |
|
686 | 686 | { |
687 | 687 | $type = $orig_type; |
688 | 688 | Mobile::setMobile(FALSE); |
@@ -694,25 +694,25 @@ discard block |
||
694 | 694 | $oModule = $this->getModuleInstance($forward->module, $type, $kind); |
695 | 695 | } |
696 | 696 | |
697 | - if(!is_object($oModule)) |
|
697 | + if (!is_object($oModule)) |
|
698 | 698 | { |
699 | 699 | $this->_setInputErrorToContext(); |
700 | 700 | $oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode); |
701 | 701 | $oMessageObject->setError(-1); |
702 | 702 | $oMessageObject->setMessage('msg_module_is_not_exists'); |
703 | 703 | $oMessageObject->dispMessage(); |
704 | - if($this->httpStatusCode) |
|
704 | + if ($this->httpStatusCode) |
|
705 | 705 | { |
706 | 706 | $oMessageObject->setHttpStatusCode($this->httpStatusCode); |
707 | 707 | } |
708 | 708 | return $oMessageObject; |
709 | 709 | } |
710 | 710 | |
711 | - if($this->module == "admin" && $type == "view") |
|
711 | + if ($this->module == "admin" && $type == "view") |
|
712 | 712 | { |
713 | - if($logged_info->is_admin == 'Y') |
|
713 | + if ($logged_info->is_admin == 'Y') |
|
714 | 714 | { |
715 | - if($this->act != 'dispLayoutAdminLayoutModify') |
|
715 | + if ($this->act != 'dispLayoutAdminLayoutModify') |
|
716 | 716 | { |
717 | 717 | $oAdminView = getAdminView('admin'); |
718 | 718 | $oAdminView->makeGnbUrl($forward->module); |
@@ -732,10 +732,10 @@ discard block |
||
732 | 732 | return $oMessageObject; |
733 | 733 | } |
734 | 734 | } |
735 | - if($kind == 'admin') |
|
735 | + if ($kind == 'admin') |
|
736 | 736 | { |
737 | 737 | $grant = $oModuleModel->getGrant($this->module_info, $logged_info); |
738 | - if(!$grant->manager) |
|
738 | + if (!$grant->manager) |
|
739 | 739 | { |
740 | 740 | $this->_setInputErrorToContext(); |
741 | 741 | $this->error = 'msg_is_not_manager'; |
@@ -747,7 +747,7 @@ discard block |
||
747 | 747 | } |
748 | 748 | else |
749 | 749 | { |
750 | - if(!$grant->is_admin && $this->module != $this->orig_module->module && $xml_info->permission->{$this->act} != 'manager') |
|
750 | + if (!$grant->is_admin && $this->module != $this->orig_module->module && $xml_info->permission->{$this->act} != 'manager') |
|
751 | 751 | { |
752 | 752 | $this->_setInputErrorToContext(); |
753 | 753 | $this->error = 'msg_is_not_administrator'; |
@@ -760,7 +760,7 @@ discard block |
||
760 | 760 | } |
761 | 761 | } |
762 | 762 | } |
763 | - else if($xml_info->default_index_act && method_exists($oModule, $xml_info->default_index_act)) |
|
763 | + else if ($xml_info->default_index_act && method_exists($oModule, $xml_info->default_index_act)) |
|
764 | 764 | { |
765 | 765 | $this->act = $xml_info->default_index_act; |
766 | 766 | } |
@@ -774,16 +774,16 @@ discard block |
||
774 | 774 | } |
775 | 775 | |
776 | 776 | // ruleset check... |
777 | - if(!empty($ruleset)) |
|
777 | + if (!empty($ruleset)) |
|
778 | 778 | { |
779 | 779 | $rulesetModule = $forward->module ? $forward->module : $this->module; |
780 | 780 | $rulesetFile = $oModuleModel->getValidatorFilePath($rulesetModule, $ruleset, $this->mid); |
781 | - if(!empty($rulesetFile)) |
|
781 | + if (!empty($rulesetFile)) |
|
782 | 782 | { |
783 | - if($_SESSION['XE_VALIDATOR_ERROR_LANG']) |
|
783 | + if ($_SESSION['XE_VALIDATOR_ERROR_LANG']) |
|
784 | 784 | { |
785 | 785 | $errorLang = $_SESSION['XE_VALIDATOR_ERROR_LANG']; |
786 | - foreach($errorLang as $key => $val) |
|
786 | + foreach ($errorLang as $key => $val) |
|
787 | 787 | { |
788 | 788 | Context::setLang($key, $val); |
789 | 789 | } |
@@ -792,7 +792,7 @@ discard block |
||
792 | 792 | |
793 | 793 | $Validator = new Validator($rulesetFile); |
794 | 794 | $result = $Validator->validate(); |
795 | - if(!$result) |
|
795 | + if (!$result) |
|
796 | 796 | { |
797 | 797 | $lastError = $Validator->getLastError(); |
798 | 798 | $returnUrl = Context::get('error_return_url'); |
@@ -824,26 +824,26 @@ discard block |
||
824 | 824 | 'dispLayoutPreviewWithModule' => 1 |
825 | 825 | ); |
826 | 826 | $db_use_mobile = Mobile::isMobileEnabled(); |
827 | - if($type == "view" && $this->module_info->use_mobile == "Y" && Mobile::isMobileCheckByAgent() && !isset($skipAct[Context::get('act')]) && $db_use_mobile === true) |
|
827 | + if ($type == "view" && $this->module_info->use_mobile == "Y" && Mobile::isMobileCheckByAgent() && !isset($skipAct[Context::get('act')]) && $db_use_mobile === true) |
|
828 | 828 | { |
829 | 829 | global $lang; |
830 | 830 | $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>'; |
831 | - $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>'; |
|
831 | + $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>'; |
|
832 | 832 | Context::addHtmlHeader($header); |
833 | 833 | Context::addHtmlFooter($footer); |
834 | 834 | } |
835 | 835 | |
836 | - if(($type == 'view' || $type == 'mobile') && $kind != 'admin') |
|
836 | + if (($type == 'view' || $type == 'mobile') && $kind != 'admin') |
|
837 | 837 | { |
838 | 838 | $module_config = $oModuleModel->getModuleConfig('module'); |
839 | - if($module_config->htmlFooter) |
|
839 | + if ($module_config->htmlFooter) |
|
840 | 840 | { |
841 | 841 | Context::addHtmlFooter($module_config->htmlFooter); |
842 | 842 | } |
843 | - if($module_config->siteTitle) |
|
843 | + if ($module_config->siteTitle) |
|
844 | 844 | { |
845 | 845 | $siteTitle = Context::getBrowserTitle(); |
846 | - if(!$siteTitle) |
|
846 | + if (!$siteTitle) |
|
847 | 847 | { |
848 | 848 | Context::setBrowserTitle($module_config->siteTitle); |
849 | 849 | } |
@@ -860,18 +860,18 @@ discard block |
||
860 | 860 | $procResult = $oModule->proc(); |
861 | 861 | |
862 | 862 | $methodList = array('XMLRPC' => 1, 'JSON' => 1, 'JS_CALLBACK' => 1); |
863 | - if(!$oModule->stop_proc && !isset($methodList[Context::getRequestMethod()])) |
|
863 | + if (!$oModule->stop_proc && !isset($methodList[Context::getRequestMethod()])) |
|
864 | 864 | { |
865 | 865 | $error = $oModule->getError(); |
866 | 866 | $message = $oModule->getMessage(); |
867 | 867 | $messageType = $oModule->getMessageType(); |
868 | 868 | $redirectUrl = $oModule->getRedirectUrl(); |
869 | - if($messageType == 'error') debugPrint($message, 'ERROR'); |
|
869 | + if ($messageType == 'error') debugPrint($message, 'ERROR'); |
|
870 | 870 | |
871 | - if(!$procResult) |
|
871 | + if (!$procResult) |
|
872 | 872 | { |
873 | 873 | $this->error = $message; |
874 | - if(!$redirectUrl && Context::get('error_return_url')) |
|
874 | + if (!$redirectUrl && Context::get('error_return_url')) |
|
875 | 875 | { |
876 | 876 | $redirectUrl = Context::get('error_return_url'); |
877 | 877 | } |
@@ -884,13 +884,13 @@ discard block |
||
884 | 884 | |
885 | 885 | $_SESSION['XE_VALIDATOR_ERROR'] = $error; |
886 | 886 | $_SESSION['XE_VALIDATOR_ID'] = Context::get('xe_validator_id'); |
887 | - if($message != 'success') |
|
887 | + if ($message != 'success') |
|
888 | 888 | { |
889 | 889 | $_SESSION['XE_VALIDATOR_MESSAGE'] = $message; |
890 | 890 | } |
891 | 891 | $_SESSION['XE_VALIDATOR_MESSAGE_TYPE'] = $messageType; |
892 | 892 | |
893 | - if(Context::get('xeVirtualRequestMethod') != 'xml') |
|
893 | + if (Context::get('xeVirtualRequestMethod') != 'xml') |
|
894 | 894 | { |
895 | 895 | $_SESSION['XE_VALIDATOR_RETURN_URL'] = $redirectUrl; |
896 | 896 | } |
@@ -906,27 +906,27 @@ discard block |
||
906 | 906 | * */ |
907 | 907 | function _setInputErrorToContext() |
908 | 908 | { |
909 | - if($_SESSION['XE_VALIDATOR_ERROR'] && !Context::get('XE_VALIDATOR_ERROR')) |
|
909 | + if ($_SESSION['XE_VALIDATOR_ERROR'] && !Context::get('XE_VALIDATOR_ERROR')) |
|
910 | 910 | { |
911 | 911 | Context::set('XE_VALIDATOR_ERROR', $_SESSION['XE_VALIDATOR_ERROR']); |
912 | 912 | } |
913 | - if($_SESSION['XE_VALIDATOR_MESSAGE'] && !Context::get('XE_VALIDATOR_MESSAGE')) |
|
913 | + if ($_SESSION['XE_VALIDATOR_MESSAGE'] && !Context::get('XE_VALIDATOR_MESSAGE')) |
|
914 | 914 | { |
915 | 915 | Context::set('XE_VALIDATOR_MESSAGE', $_SESSION['XE_VALIDATOR_MESSAGE']); |
916 | 916 | } |
917 | - if($_SESSION['XE_VALIDATOR_MESSAGE_TYPE'] && !Context::get('XE_VALIDATOR_MESSAGE_TYPE')) |
|
917 | + if ($_SESSION['XE_VALIDATOR_MESSAGE_TYPE'] && !Context::get('XE_VALIDATOR_MESSAGE_TYPE')) |
|
918 | 918 | { |
919 | 919 | Context::set('XE_VALIDATOR_MESSAGE_TYPE', $_SESSION['XE_VALIDATOR_MESSAGE_TYPE']); |
920 | 920 | } |
921 | - if($_SESSION['XE_VALIDATOR_RETURN_URL'] && !Context::get('XE_VALIDATOR_RETURN_URL')) |
|
921 | + if ($_SESSION['XE_VALIDATOR_RETURN_URL'] && !Context::get('XE_VALIDATOR_RETURN_URL')) |
|
922 | 922 | { |
923 | 923 | Context::set('XE_VALIDATOR_RETURN_URL', $_SESSION['XE_VALIDATOR_RETURN_URL']); |
924 | 924 | } |
925 | - if($_SESSION['XE_VALIDATOR_ID'] && !Context::get('XE_VALIDATOR_ID')) |
|
925 | + if ($_SESSION['XE_VALIDATOR_ID'] && !Context::get('XE_VALIDATOR_ID')) |
|
926 | 926 | { |
927 | 927 | Context::set('XE_VALIDATOR_ID', $_SESSION['XE_VALIDATOR_ID']); |
928 | 928 | } |
929 | - if(count($_SESSION['INPUT_ERROR'])) |
|
929 | + if (count($_SESSION['INPUT_ERROR'])) |
|
930 | 930 | { |
931 | 931 | Context::set('INPUT_ERROR', $_SESSION['INPUT_ERROR']); |
932 | 932 | } |
@@ -956,7 +956,7 @@ discard block |
||
956 | 956 | { |
957 | 957 | $requestVars = Context::getRequestVars(); |
958 | 958 | unset($requestVars->act, $requestVars->mid, $requestVars->vid, $requestVars->success_return_url, $requestVars->error_return_url); |
959 | - foreach($requestVars AS $key => $value) |
|
959 | + foreach ($requestVars AS $key => $value) |
|
960 | 960 | { |
961 | 961 | $_SESSION['INPUT_ERROR'][$key] = $value; |
962 | 962 | } |
@@ -970,41 +970,41 @@ discard block |
||
970 | 970 | function displayContent($oModule = NULL) |
971 | 971 | { |
972 | 972 | // If the module is not set or not an object, set error |
973 | - if(!$oModule || !is_object($oModule)) |
|
973 | + if (!$oModule || !is_object($oModule)) |
|
974 | 974 | { |
975 | 975 | $this->error = 'msg_module_is_not_exists'; |
976 | 976 | $this->httpStatusCode = '404'; |
977 | 977 | } |
978 | 978 | |
979 | 979 | // If connection to DB has a problem even though it's not install module, set error |
980 | - if($this->module != 'install' && isset($GLOBALS['__DB__']) && $GLOBALS['__DB__'][Context::getDBType()]->isConnected() == FALSE) |
|
980 | + if ($this->module != 'install' && isset($GLOBALS['__DB__']) && $GLOBALS['__DB__'][Context::getDBType()]->isConnected() == FALSE) |
|
981 | 981 | { |
982 | 982 | $this->error = 'msg_dbconnect_failed'; |
983 | 983 | } |
984 | 984 | |
985 | 985 | // Call trigger after moduleHandler proc |
986 | 986 | $output = ModuleHandler::triggerCall('moduleHandler.proc', 'after', $oModule); |
987 | - if(!$output->toBool()) |
|
987 | + if (!$output->toBool()) |
|
988 | 988 | { |
989 | 989 | $this->error = $output->getMessage(); |
990 | 990 | } |
991 | 991 | |
992 | 992 | // Use message view object, if HTML call |
993 | 993 | $methodList = array('XMLRPC' => 1, 'JSON' => 1, 'JS_CALLBACK' => 1); |
994 | - if(!isset($methodList[Context::getRequestMethod()])) |
|
994 | + if (!isset($methodList[Context::getRequestMethod()])) |
|
995 | 995 | { |
996 | 996 | |
997 | - if($_SESSION['XE_VALIDATOR_RETURN_URL']) |
|
997 | + if ($_SESSION['XE_VALIDATOR_RETURN_URL']) |
|
998 | 998 | { |
999 | 999 | $display_handler = new DisplayHandler(); |
1000 | 1000 | $display_handler->_debugOutput(); |
1001 | 1001 | |
1002 | - header('location:' . $_SESSION['XE_VALIDATOR_RETURN_URL']); |
|
1002 | + header('location:'.$_SESSION['XE_VALIDATOR_RETURN_URL']); |
|
1003 | 1003 | return; |
1004 | 1004 | } |
1005 | 1005 | |
1006 | 1006 | // If error occurred, handle it |
1007 | - if($this->error) |
|
1007 | + if ($this->error) |
|
1008 | 1008 | { |
1009 | 1009 | // display content with message module instance |
1010 | 1010 | $type = Mobile::isFromMobilePhone() ? 'mobile' : 'view'; |
@@ -1013,14 +1013,14 @@ discard block |
||
1013 | 1013 | $oMessageObject->setMessage($this->error); |
1014 | 1014 | $oMessageObject->dispMessage(); |
1015 | 1015 | |
1016 | - if($oMessageObject->getHttpStatusCode() && $oMessageObject->getHttpStatusCode() != '200') |
|
1016 | + if ($oMessageObject->getHttpStatusCode() && $oMessageObject->getHttpStatusCode() != '200') |
|
1017 | 1017 | { |
1018 | 1018 | $this->_setHttpStatusMessage($oMessageObject->getHttpStatusCode()); |
1019 | 1019 | $oMessageObject->setTemplateFile('http_status_code'); |
1020 | 1020 | } |
1021 | 1021 | |
1022 | 1022 | // If module was called normally, change the templates of the module into ones of the message view module |
1023 | - if($oModule) |
|
1023 | + if ($oModule) |
|
1024 | 1024 | { |
1025 | 1025 | $oModule->setTemplatePath($oMessageObject->getTemplatePath()); |
1026 | 1026 | $oModule->setTemplateFile($oMessageObject->getTemplateFile()); |
@@ -1035,7 +1035,7 @@ discard block |
||
1035 | 1035 | } |
1036 | 1036 | |
1037 | 1037 | // Check if layout_srl exists for the module |
1038 | - if(Mobile::isFromMobilePhone()) |
|
1038 | + if (Mobile::isFromMobilePhone()) |
|
1039 | 1039 | { |
1040 | 1040 | $layout_srl = $oModule->module_info->mlayout_srl; |
1041 | 1041 | } |
@@ -1045,58 +1045,58 @@ discard block |
||
1045 | 1045 | } |
1046 | 1046 | |
1047 | 1047 | // if layout_srl is rollback by module, set default layout |
1048 | - if($layout_srl == -1) |
|
1048 | + if ($layout_srl == -1) |
|
1049 | 1049 | { |
1050 | 1050 | $viewType = (Mobile::isFromMobilePhone()) ? 'M' : 'P'; |
1051 | 1051 | $oLayoutAdminModel = getAdminModel('layout'); |
1052 | 1052 | $layout_srl = $oLayoutAdminModel->getSiteDefaultLayout($viewType, $oModule->module_info->site_srl); |
1053 | 1053 | } |
1054 | 1054 | |
1055 | - if($layout_srl && !$oModule->getLayoutFile()) |
|
1055 | + if ($layout_srl && !$oModule->getLayoutFile()) |
|
1056 | 1056 | { |
1057 | 1057 | |
1058 | 1058 | // If layout_srl exists, get information of the layout, and set the location of layout_path/ layout_file |
1059 | 1059 | $oLayoutModel = getModel('layout'); |
1060 | 1060 | $layout_info = $oLayoutModel->getLayout($layout_srl); |
1061 | - if($layout_info) |
|
1061 | + if ($layout_info) |
|
1062 | 1062 | { |
1063 | 1063 | |
1064 | 1064 | // Input extra_vars into $layout_info |
1065 | - if($layout_info->extra_var_count) |
|
1065 | + if ($layout_info->extra_var_count) |
|
1066 | 1066 | { |
1067 | 1067 | |
1068 | - foreach($layout_info->extra_var as $var_id => $val) |
|
1068 | + foreach ($layout_info->extra_var as $var_id => $val) |
|
1069 | 1069 | { |
1070 | - if($val->type == 'image') |
|
1070 | + if ($val->type == 'image') |
|
1071 | 1071 | { |
1072 | - if(strncmp('./files/attach/images/', $val->value, 22) === 0) |
|
1072 | + if (strncmp('./files/attach/images/', $val->value, 22) === 0) |
|
1073 | 1073 | { |
1074 | - $val->value = Context::getRequestUri() . substr($val->value, 2); |
|
1074 | + $val->value = Context::getRequestUri().substr($val->value, 2); |
|
1075 | 1075 | } |
1076 | 1076 | } |
1077 | 1077 | $layout_info->{$var_id} = $val->value; |
1078 | 1078 | } |
1079 | 1079 | } |
1080 | 1080 | // Set menus into context |
1081 | - if($layout_info->menu_count) |
|
1081 | + if ($layout_info->menu_count) |
|
1082 | 1082 | { |
1083 | - foreach($layout_info->menu as $menu_id => $menu) |
|
1083 | + foreach ($layout_info->menu as $menu_id => $menu) |
|
1084 | 1084 | { |
1085 | 1085 | // set default menu set(included home menu) |
1086 | - if(!$menu->menu_srl || $menu->menu_srl == -1) |
|
1086 | + if (!$menu->menu_srl || $menu->menu_srl == -1) |
|
1087 | 1087 | { |
1088 | 1088 | $oMenuAdminController = getAdminController('menu'); |
1089 | 1089 | $homeMenuCacheFile = $oMenuAdminController->getHomeMenuCacheFile(); |
1090 | 1090 | |
1091 | - if(FileHandler::exists($homeMenuCacheFile)) |
|
1091 | + if (FileHandler::exists($homeMenuCacheFile)) |
|
1092 | 1092 | { |
1093 | 1093 | include($homeMenuCacheFile); |
1094 | 1094 | } |
1095 | 1095 | |
1096 | - if(!$menu->menu_srl) |
|
1096 | + if (!$menu->menu_srl) |
|
1097 | 1097 | { |
1098 | - $menu->xml_file = str_replace('.xml.php', $homeMenuSrl . '.xml.php', $menu->xml_file); |
|
1099 | - $menu->php_file = str_replace('.php', $homeMenuSrl . '.php', $menu->php_file); |
|
1098 | + $menu->xml_file = str_replace('.xml.php', $homeMenuSrl.'.xml.php', $menu->xml_file); |
|
1099 | + $menu->php_file = str_replace('.php', $homeMenuSrl.'.php', $menu->php_file); |
|
1100 | 1100 | $layout_info->menu->{$menu_id}->menu_srl = $homeMenuSrl; |
1101 | 1101 | } |
1102 | 1102 | else |
@@ -1107,7 +1107,7 @@ discard block |
||
1107 | 1107 | } |
1108 | 1108 | |
1109 | 1109 | $php_file = FileHandler::exists($menu->php_file); |
1110 | - if($php_file) |
|
1110 | + if ($php_file) |
|
1111 | 1111 | { |
1112 | 1112 | include($php_file); |
1113 | 1113 | } |
@@ -1123,17 +1123,17 @@ discard block |
||
1123 | 1123 | |
1124 | 1124 | // If layout was modified, use the modified version |
1125 | 1125 | $edited_layout = $oLayoutModel->getUserLayoutHtml($layout_info->layout_srl); |
1126 | - if(file_exists($edited_layout)) |
|
1126 | + if (file_exists($edited_layout)) |
|
1127 | 1127 | { |
1128 | 1128 | $oModule->setEditedLayoutFile($edited_layout); |
1129 | 1129 | } |
1130 | 1130 | } |
1131 | 1131 | } |
1132 | 1132 | $isLayoutDrop = Context::get('isLayoutDrop'); |
1133 | - if($isLayoutDrop) |
|
1133 | + if ($isLayoutDrop) |
|
1134 | 1134 | { |
1135 | 1135 | $kind = stripos($this->act, 'admin') !== FALSE ? 'admin' : ''; |
1136 | - if($kind == 'admin') |
|
1136 | + if ($kind == 'admin') |
|
1137 | 1137 | { |
1138 | 1138 | $oModule->setLayoutFile('popup_layout'); |
1139 | 1139 | } |
@@ -1171,7 +1171,7 @@ discard block |
||
1171 | 1171 | function &getModuleInstance($module, $type = 'view', $kind = '') |
1172 | 1172 | { |
1173 | 1173 | |
1174 | - if(__DEBUG__ == 3) |
|
1174 | + if (__DEBUG__ == 3) |
|
1175 | 1175 | { |
1176 | 1176 | $start_time = getMicroTime(); |
1177 | 1177 | } |
@@ -1181,51 +1181,51 @@ discard block |
||
1181 | 1181 | $type = strtolower($type); |
1182 | 1182 | |
1183 | 1183 | $kinds = array('svc' => 1, 'admin' => 1); |
1184 | - if(!isset($kinds[$kind])) |
|
1184 | + if (!isset($kinds[$kind])) |
|
1185 | 1185 | { |
1186 | 1186 | $kind = 'svc'; |
1187 | 1187 | } |
1188 | 1188 | |
1189 | - $key = $module . '.' . ($kind != 'admin' ? '' : 'admin') . '.' . $type; |
|
1189 | + $key = $module.'.'.($kind != 'admin' ? '' : 'admin').'.'.$type; |
|
1190 | 1190 | |
1191 | - if(is_array($GLOBALS['__MODULE_EXTEND__']) && array_key_exists($key, $GLOBALS['__MODULE_EXTEND__'])) |
|
1191 | + if (is_array($GLOBALS['__MODULE_EXTEND__']) && array_key_exists($key, $GLOBALS['__MODULE_EXTEND__'])) |
|
1192 | 1192 | { |
1193 | 1193 | $module = $extend_module = $GLOBALS['__MODULE_EXTEND__'][$key]; |
1194 | 1194 | } |
1195 | 1195 | |
1196 | 1196 | // if there is no instance of the module in global variable, create a new one |
1197 | - if(!isset($GLOBALS['_loaded_module'][$module][$type][$kind])) |
|
1197 | + if (!isset($GLOBALS['_loaded_module'][$module][$type][$kind])) |
|
1198 | 1198 | { |
1199 | 1199 | ModuleHandler::_getModuleFilePath($module, $type, $kind, $class_path, $high_class_file, $class_file, $instance_name); |
1200 | 1200 | |
1201 | - if($extend_module && (!is_readable($high_class_file) || !is_readable($class_file))) |
|
1201 | + if ($extend_module && (!is_readable($high_class_file) || !is_readable($class_file))) |
|
1202 | 1202 | { |
1203 | 1203 | $module = $parent_module; |
1204 | 1204 | ModuleHandler::_getModuleFilePath($module, $type, $kind, $class_path, $high_class_file, $class_file, $instance_name); |
1205 | 1205 | } |
1206 | 1206 | |
1207 | 1207 | // Check if the base class and instance class exist |
1208 | - if(!class_exists($module, true)) |
|
1208 | + if (!class_exists($module, true)) |
|
1209 | 1209 | { |
1210 | 1210 | return NULL; |
1211 | 1211 | } |
1212 | - if(!class_exists($instance_name, true)) |
|
1212 | + if (!class_exists($instance_name, true)) |
|
1213 | 1213 | { |
1214 | 1214 | return NULL; |
1215 | 1215 | } |
1216 | 1216 | |
1217 | 1217 | // Create an instance |
1218 | 1218 | $oModule = new $instance_name(); |
1219 | - if(!is_object($oModule)) |
|
1219 | + if (!is_object($oModule)) |
|
1220 | 1220 | { |
1221 | 1221 | return NULL; |
1222 | 1222 | } |
1223 | 1223 | |
1224 | 1224 | // Load language files for the class |
1225 | - Context::loadLang($class_path . 'lang'); |
|
1226 | - if($extend_module) |
|
1225 | + Context::loadLang($class_path.'lang'); |
|
1226 | + if ($extend_module) |
|
1227 | 1227 | { |
1228 | - Context::loadLang(ModuleHandler::getModulePath($parent_module) . 'lang'); |
|
1228 | + Context::loadLang(ModuleHandler::getModulePath($parent_module).'lang'); |
|
1229 | 1229 | } |
1230 | 1230 | |
1231 | 1231 | // Set variables to the instance |
@@ -1233,10 +1233,10 @@ discard block |
||
1233 | 1233 | $oModule->setModulePath($class_path); |
1234 | 1234 | |
1235 | 1235 | // If the module has a constructor, run it. |
1236 | - if(!isset($GLOBALS['_called_constructor'][$instance_name])) |
|
1236 | + if (!isset($GLOBALS['_called_constructor'][$instance_name])) |
|
1237 | 1237 | { |
1238 | 1238 | $GLOBALS['_called_constructor'][$instance_name] = TRUE; |
1239 | - if(@method_exists($oModule, $instance_name)) |
|
1239 | + if (@method_exists($oModule, $instance_name)) |
|
1240 | 1240 | { |
1241 | 1241 | $oModule->{$instance_name}(); |
1242 | 1242 | } |
@@ -1246,7 +1246,7 @@ discard block |
||
1246 | 1246 | $GLOBALS['_loaded_module'][$module][$type][$kind] = $oModule; |
1247 | 1247 | } |
1248 | 1248 | |
1249 | - if(__DEBUG__ == 3) |
|
1249 | + if (__DEBUG__ == 3) |
|
1250 | 1250 | { |
1251 | 1251 | $GLOBALS['__elapsed_class_load__'] += getMicroTime() - $start_time; |
1252 | 1252 | } |
@@ -1262,17 +1262,17 @@ discard block |
||
1262 | 1262 | $highClassFile = sprintf('%s%s%s.class.php', _XE_PATH_, $classPath, $module); |
1263 | 1263 | $highClassFile = FileHandler::getRealPath($highClassFile); |
1264 | 1264 | |
1265 | - $types = array('view','controller','model','api','wap','mobile','class'); |
|
1266 | - if(!in_array($type, $types)) |
|
1265 | + $types = array('view', 'controller', 'model', 'api', 'wap', 'mobile', 'class'); |
|
1266 | + if (!in_array($type, $types)) |
|
1267 | 1267 | { |
1268 | 1268 | $type = $types[0]; |
1269 | 1269 | } |
1270 | - if($type == 'class') |
|
1270 | + if ($type == 'class') |
|
1271 | 1271 | { |
1272 | 1272 | $instanceName = '%s'; |
1273 | 1273 | $classFile = '%s%s.%s.php'; |
1274 | 1274 | } |
1275 | - elseif($kind == 'admin' && array_search($type, $types) < 3) |
|
1275 | + elseif ($kind == 'admin' && array_search($type, $types) < 3) |
|
1276 | 1276 | { |
1277 | 1277 | $instanceName = '%sAdmin%s'; |
1278 | 1278 | $classFile = '%s%s.admin.%s.php'; |
@@ -1297,26 +1297,26 @@ discard block |
||
1297 | 1297 | function triggerCall($trigger_name, $called_position, &$obj) |
1298 | 1298 | { |
1299 | 1299 | // skip if not installed |
1300 | - if(!Context::isInstalled()) |
|
1300 | + if (!Context::isInstalled()) |
|
1301 | 1301 | { |
1302 | 1302 | return new BaseObject(); |
1303 | 1303 | } |
1304 | 1304 | |
1305 | 1305 | $oModuleModel = getModel('module'); |
1306 | 1306 | $triggers = $oModuleModel->getTriggers($trigger_name, $called_position); |
1307 | - if(!$triggers || count($triggers) < 1) |
|
1307 | + if (!$triggers || count($triggers) < 1) |
|
1308 | 1308 | { |
1309 | 1309 | return new BaseObject(); |
1310 | 1310 | } |
1311 | 1311 | |
1312 | 1312 | //store before trigger call time |
1313 | 1313 | $before_trigger_time = NULL; |
1314 | - if(__LOG_SLOW_TRIGGER__> 0) |
|
1314 | + if (__LOG_SLOW_TRIGGER__ > 0) |
|
1315 | 1315 | { |
1316 | 1316 | $before_trigger_time = microtime(true); |
1317 | 1317 | } |
1318 | 1318 | |
1319 | - foreach($triggers as $item) |
|
1319 | + foreach ($triggers as $item) |
|
1320 | 1320 | { |
1321 | 1321 | $module = $item->module; |
1322 | 1322 | $type = $item->type; |
@@ -1324,7 +1324,7 @@ discard block |
||
1324 | 1324 | |
1325 | 1325 | // todo why don't we call a normal class object ? |
1326 | 1326 | $oModule = getModule($module, $type); |
1327 | - if(!$oModule || !method_exists($oModule, $called_method)) |
|
1327 | + if (!$oModule || !method_exists($oModule, $called_method)) |
|
1328 | 1328 | { |
1329 | 1329 | continue; |
1330 | 1330 | } |
@@ -1337,12 +1337,12 @@ discard block |
||
1337 | 1337 | $elapsed_time_trigger = $after_each_trigger_time - $before_each_trigger_time; |
1338 | 1338 | |
1339 | 1339 | $slowlog = new stdClass; |
1340 | - $slowlog->caller = $trigger_name . '.' . $called_position; |
|
1341 | - $slowlog->called = $module . '.' . $called_method; |
|
1340 | + $slowlog->caller = $trigger_name.'.'.$called_position; |
|
1341 | + $slowlog->called = $module.'.'.$called_method; |
|
1342 | 1342 | $slowlog->called_extension = $module; |
1343 | - if($trigger_name != 'XE.writeSlowlog') writeSlowlog('trigger', $elapsed_time_trigger, $slowlog); |
|
1343 | + if ($trigger_name != 'XE.writeSlowlog') writeSlowlog('trigger', $elapsed_time_trigger, $slowlog); |
|
1344 | 1344 | |
1345 | - if(is_object($output) && method_exists($output, 'toBool') && !$output->toBool()) |
|
1345 | + if (is_object($output) && method_exists($output, 'toBool') && !$output->toBool()) |
|
1346 | 1346 | { |
1347 | 1347 | return $output; |
1348 | 1348 | } |
@@ -1427,9 +1427,9 @@ discard block |
||
1427 | 1427 | '511' => 'Network Authentication Required', |
1428 | 1428 | ); |
1429 | 1429 | $statusMessage = $statusMessageList[$code]; |
1430 | - if(!$statusMessage) |
|
1430 | + if (!$statusMessage) |
|
1431 | 1431 | { |
1432 | - $statusMessage = 'HTTP ' . $code; |
|
1432 | + $statusMessage = 'HTTP '.$code; |
|
1433 | 1433 | } |
1434 | 1434 | |
1435 | 1435 | Context::set('http_status_code', $code); |
@@ -115,7 +115,9 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | { |
@@ -141,7 +141,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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) |
@@ -44,9 +44,9 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -168,8 +168,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | { |
@@ -295,6 +295,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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) |
@@ -563,14 +563,12 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
664 | 664 | { |
665 | 665 | $whiteIframeUrlList[] = $value->body; |
666 | 666 | } |
667 | - } |
|
668 | - else |
|
667 | + } else |
|
669 | 668 | { |
670 | 669 | $whiteIframeUrlList[] = $patternList->body; |
671 | 670 | } |
@@ -1,7 +1,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -11,6 +11,7 @@ |
||
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; |
@@ -6,41 +6,41 @@ |
||
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 |
@@ -21,22 +21,38 @@ |
||
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(); |
@@ -9,6 +9,9 @@ |
||
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(); |
@@ -9,90 +9,90 @@ |
||
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 |
@@ -11,7 +11,9 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -16,15 +16,15 @@ discard block |
||
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 |
||
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 |
||
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 | { |
@@ -17,10 +17,12 @@ |
||
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(), |
@@ -3,100 +3,100 @@ |
||
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 |
@@ -26,9 +26,15 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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'; |
@@ -56,7 +56,7 @@ |
||
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 | } |
@@ -31,6 +31,9 @@ discard block |
||
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 |
||
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 |
||
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'); |
@@ -7,532 +7,532 @@ |
||
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 | } |
@@ -314,9 +314,15 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
@@ -132,7 +132,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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) { |
@@ -25,6 +25,9 @@ |
||
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; |
@@ -7,202 +7,202 @@ |
||
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 |
@@ -60,7 +60,9 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -26,10 +26,10 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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. |