@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | $sth = $this->pdo->prepare("SELECT link FROM ttrss_entries, ttrss_user_entries |
14 | 14 | WHERE id = ? AND id = ref_id AND owner_uid = ? |
15 | 15 | LIMIT 1"); |
16 | - $sth->execute([$id, $_SESSION['uid']]); |
|
16 | + $sth->execute([$id, $_SESSION['uid']]); |
|
17 | 17 | |
18 | 18 | if ($row = $sth->fetch()) { |
19 | 19 | $article_url = $row['link']; |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | |
140 | 140 | $sth = $pdo->prepare("SELECT int_id FROM ttrss_user_entries WHERE |
141 | 141 | ref_id = ? AND owner_uid = ? LIMIT 1"); |
142 | - $sth->execute([$ref_id, $owner_uid]); |
|
142 | + $sth->execute([$ref_id, $owner_uid]); |
|
143 | 143 | |
144 | 144 | if ($row = $sth->fetch()) { |
145 | 145 | $int_id = $row['int_id']; |
@@ -678,22 +678,22 @@ discard block |
||
678 | 678 | |
679 | 679 | static function purge_orphans() { |
680 | 680 | |
681 | - // purge orphaned posts in main content table |
|
681 | + // purge orphaned posts in main content table |
|
682 | 682 | |
683 | - if (DB_TYPE == "mysql") |
|
684 | - $limit_qpart = "LIMIT 5000"; |
|
685 | - else |
|
686 | - $limit_qpart = ""; |
|
683 | + if (DB_TYPE == "mysql") |
|
684 | + $limit_qpart = "LIMIT 5000"; |
|
685 | + else |
|
686 | + $limit_qpart = ""; |
|
687 | 687 | |
688 | - $pdo = Db::pdo(); |
|
689 | - $res = $pdo->query("DELETE FROM ttrss_entries WHERE |
|
688 | + $pdo = Db::pdo(); |
|
689 | + $res = $pdo->query("DELETE FROM ttrss_entries WHERE |
|
690 | 690 | NOT EXISTS (SELECT ref_id FROM ttrss_user_entries WHERE ref_id = id) $limit_qpart"); |
691 | 691 | |
692 | - if (Debug::enabled()) { |
|
693 | - $rows = $res->rowCount(); |
|
694 | - Debug::log("Purged $rows orphaned posts."); |
|
695 | - } |
|
696 | - } |
|
692 | + if (Debug::enabled()) { |
|
693 | + $rows = $res->rowCount(); |
|
694 | + Debug::log("Purged $rows orphaned posts."); |
|
695 | + } |
|
696 | + } |
|
697 | 697 | |
698 | 698 | static function catchupArticlesById($ids, $cmode, $owner_uid = false) { |
699 | 699 |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | static function create_published_article($title, $url, $content, $labels_str, |
94 | 94 | $owner_uid) { |
95 | 95 | |
96 | - $guid = 'SHA1:' . sha1("ttshared:" . $url . $owner_uid); // include owner_uid to prevent global GUID clash |
|
96 | + $guid = 'SHA1:'.sha1("ttshared:".$url.$owner_uid); // include owner_uid to prevent global GUID clash |
|
97 | 97 | |
98 | 98 | if (!$content) { |
99 | 99 | $pluginhost = new PluginHost(); |
@@ -148,12 +148,12 @@ discard block |
||
148 | 148 | content = ?, content_hash = ? WHERE id = ?"); |
149 | 149 | $sth->execute([$content, $content_hash, $ref_id]); |
150 | 150 | |
151 | - if (DB_TYPE == "pgsql"){ |
|
151 | + if (DB_TYPE == "pgsql") { |
|
152 | 152 | $sth = $pdo->prepare("UPDATE ttrss_entries |
153 | 153 | SET tsvector_combined = to_tsvector( :ts_content) |
154 | 154 | WHERE id = :id"); |
155 | 155 | $params = [ |
156 | - ":ts_content" => mb_substr(strip_tags($content ), 0, 900000), |
|
156 | + ":ts_content" => mb_substr(strip_tags($content), 0, 900000), |
|
157 | 157 | ":id" => $ref_id]; |
158 | 158 | $sth->execute($params); |
159 | 159 | } |
@@ -193,12 +193,12 @@ discard block |
||
193 | 193 | |
194 | 194 | if ($row = $sth->fetch()) { |
195 | 195 | $ref_id = $row["id"]; |
196 | - if (DB_TYPE == "pgsql"){ |
|
196 | + if (DB_TYPE == "pgsql") { |
|
197 | 197 | $sth = $pdo->prepare("UPDATE ttrss_entries |
198 | 198 | SET tsvector_combined = to_tsvector( :ts_content) |
199 | 199 | WHERE id = :id"); |
200 | 200 | $params = [ |
201 | - ":ts_content" => mb_substr(strip_tags($content ), 0, 900000), |
|
201 | + ":ts_content" => mb_substr(strip_tags($content), 0, 900000), |
|
202 | 202 | ":id" => $ref_id]; |
203 | 203 | $sth->execute($params); |
204 | 204 | } |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | print_hidden("op", "article"); |
237 | 237 | print_hidden("method", "setArticleTags"); |
238 | 238 | |
239 | - print "<header class='horizontal'>" . __("Tags for this article (separated by commas):")."</header>"; |
|
239 | + print "<header class='horizontal'>".__("Tags for this article (separated by commas):")."</header>"; |
|
240 | 240 | |
241 | 241 | print "<section>"; |
242 | 242 | print "<textarea dojoType='dijit.form.SimpleTextarea' rows='4' |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | |
258 | 258 | function setScore() { |
259 | 259 | $ids = explode(",", clean($_REQUEST['id'])); |
260 | - $score = (int)clean($_REQUEST['score']); |
|
260 | + $score = (int) clean($_REQUEST['score']); |
|
261 | 261 | |
262 | 262 | $ids_qmarks = arr_qmarks($ids); |
263 | 263 | |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | |
267 | 267 | $sth->execute(array_merge([$score], $ids, [$_SESSION['uid']])); |
268 | 268 | |
269 | - print json_encode(["id" => $ids, "score" => (int)$score]); |
|
269 | + print json_encode(["id" => $ids, "score" => (int) $score]); |
|
270 | 270 | } |
271 | 271 | |
272 | 272 | function getScore() { |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | |
279 | 279 | $score = $row['score']; |
280 | 280 | |
281 | - print json_encode(["id" => $id, "score" => (int)$score]); |
|
281 | + print json_encode(["id" => $id, "score" => (int) $score]); |
|
282 | 282 | } |
283 | 283 | |
284 | 284 | |
@@ -336,7 +336,7 @@ discard block |
||
336 | 336 | |
337 | 337 | if (!$tags_str_full) $tags_str_full = __("no tags"); |
338 | 338 | |
339 | - print json_encode(array("id" => (int)$id, |
|
339 | + print json_encode(array("id" => (int) $id, |
|
340 | 340 | "content" => $tags_str, "content_full" => $tags_str_full)); |
341 | 341 | } |
342 | 342 | |
@@ -353,7 +353,7 @@ discard block |
||
353 | 353 | |
354 | 354 | print "<ul>"; |
355 | 355 | while ($line = $sth->fetch()) { |
356 | - print "<li>" . $line["tag_name"] . "</li>"; |
|
356 | + print "<li>".$line["tag_name"]."</li>"; |
|
357 | 357 | } |
358 | 358 | print "</ul>"; |
359 | 359 | } |
@@ -492,21 +492,21 @@ discard block |
||
492 | 492 | if (!$hide_images) { |
493 | 493 | $encsize = ''; |
494 | 494 | if ($entry['height'] > 0) |
495 | - $encsize .= ' height="' . intval($entry['height']) . '"'; |
|
495 | + $encsize .= ' height="'.intval($entry['height']).'"'; |
|
496 | 496 | if ($entry['width'] > 0) |
497 | - $encsize .= ' width="' . intval($entry['width']) . '"'; |
|
497 | + $encsize .= ' width="'.intval($entry['width']).'"'; |
|
498 | 498 | $rv .= "<p><img |
499 | 499 | alt=\"".htmlspecialchars($entry["filename"])."\" |
500 | - src=\"" .htmlspecialchars($entry["url"]) . "\" |
|
501 | - " . $encsize . " /></p>"; |
|
500 | + src=\"" .htmlspecialchars($entry["url"])."\" |
|
501 | + " . $encsize." /></p>"; |
|
502 | 502 | } else { |
503 | 503 | $rv .= "<p><a target=\"_blank\" rel=\"noopener noreferrer\" |
504 | 504 | href=\"".htmlspecialchars($entry["url"])."\" |
505 | - >" .htmlspecialchars($entry["url"]) . "</a></p>"; |
|
505 | + >" .htmlspecialchars($entry["url"])."</a></p>"; |
|
506 | 506 | } |
507 | 507 | |
508 | 508 | if ($entry['title']) { |
509 | - $rv.= "<div class=\"enclosure_title\">${entry['title']}</div>"; |
|
509 | + $rv .= "<div class=\"enclosure_title\">${entry['title']}</div>"; |
|
510 | 510 | } |
511 | 511 | } |
512 | 512 | } |
@@ -521,13 +521,13 @@ discard block |
||
521 | 521 | } |
522 | 522 | |
523 | 523 | $rv .= "<div class=\"attachments\" dojoType=\"fox.form.DropDownButton\">". |
524 | - "<span>" . __('Attachments')."</span>"; |
|
524 | + "<span>".__('Attachments')."</span>"; |
|
525 | 525 | |
526 | 526 | $rv .= "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; |
527 | 527 | |
528 | 528 | foreach ($entries as $entry) { |
529 | 529 | if ($entry["title"]) |
530 | - $title = " — " . truncate_string($entry["title"], 30); |
|
530 | + $title = " — ".truncate_string($entry["title"], 30); |
|
531 | 531 | else |
532 | 532 | $title = ""; |
533 | 533 | |
@@ -537,7 +537,7 @@ discard block |
||
537 | 537 | $filename = ""; |
538 | 538 | |
539 | 539 | $rv .= "<div onclick='popupOpenUrl(\"".htmlspecialchars($entry["url"])."\")' |
540 | - dojoType=\"dijit.MenuItem\">".$filename . $title."</div>"; |
|
540 | + dojoType=\"dijit.MenuItem\">".$filename.$title."</div>"; |
|
541 | 541 | |
542 | 542 | }; |
543 | 543 | |
@@ -606,10 +606,10 @@ discard block |
||
606 | 606 | $tags_str = ""; |
607 | 607 | |
608 | 608 | for ($i = 0; $i < $maxtags; $i++) { |
609 | - $tags_str .= "<a class=\"tag\" href=\"#\" onclick=\"Feeds.open({feed:'".$tags[$i]."'})\">" . $tags[$i] . "</a>, "; |
|
609 | + $tags_str .= "<a class=\"tag\" href=\"#\" onclick=\"Feeds.open({feed:'".$tags[$i]."'})\">".$tags[$i]."</a>, "; |
|
610 | 610 | } |
611 | 611 | |
612 | - $tags_str = mb_substr($tags_str, 0, mb_strlen($tags_str)-2); |
|
612 | + $tags_str = mb_substr($tags_str, 0, mb_strlen($tags_str) - 2); |
|
613 | 613 | |
614 | 614 | if (count($tags) > $maxtags) |
615 | 615 | $tags_str .= ", …"; |
@@ -803,7 +803,7 @@ discard block |
||
803 | 803 | if (!$article_image && !$article_stream) { |
804 | 804 | $tmpdoc = new DOMDocument(); |
805 | 805 | |
806 | - if (@$tmpdoc->loadHTML('<?xml encoding="UTF-8">' . mb_substr($content, 0, 131070))) { |
|
806 | + if (@$tmpdoc->loadHTML('<?xml encoding="UTF-8">'.mb_substr($content, 0, 131070))) { |
|
807 | 807 | $tmpxpath = new DOMXPath($tmpdoc); |
808 | 808 | $elems = $tmpxpath->query('(//img[@src]|//video[@poster]|//iframe[contains(@src , "youtube.com/embed/")])'); |
809 | 809 | |
@@ -811,8 +811,8 @@ discard block |
||
811 | 811 | if ($e->nodeName == "iframe") { |
812 | 812 | $matches = []; |
813 | 813 | if ($rrr = preg_match("/\/embed\/([\w-]+)/", $e->getAttribute("src"), $matches)) { |
814 | - $article_image = "https://img.youtube.com/vi/" . $matches[1] . "/hqdefault.jpg"; |
|
815 | - $article_stream = "https://youtu.be/" . $matches[1]; |
|
814 | + $article_image = "https://img.youtube.com/vi/".$matches[1]."/hqdefault.jpg"; |
|
815 | + $article_stream = "https://youtu.be/".$matches[1]; |
|
816 | 816 | break; |
817 | 817 | } |
818 | 818 | } else if ($e->nodeName == "video") { |
@@ -120,10 +120,16 @@ discard block |
||
120 | 120 | |
121 | 121 | $rc = false; |
122 | 122 | |
123 | - if (!$title) $title = $url; |
|
124 | - if (!$title && !$url) return false; |
|
123 | + if (!$title) { |
|
124 | + $title = $url; |
|
125 | + } |
|
126 | + if (!$title && !$url) { |
|
127 | + return false; |
|
128 | + } |
|
125 | 129 | |
126 | - if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) return false; |
|
130 | + if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) { |
|
131 | + return false; |
|
132 | + } |
|
127 | 133 | |
128 | 134 | $pdo = Db::pdo(); |
129 | 135 | |
@@ -334,7 +340,9 @@ discard block |
||
334 | 340 | $tags_str = $this->format_tags_string($tags, $id); |
335 | 341 | $tags_str_full = join(", ", $tags); |
336 | 342 | |
337 | - if (!$tags_str_full) $tags_str_full = __("no tags"); |
|
343 | + if (!$tags_str_full) { |
|
344 | + $tags_str_full = __("no tags"); |
|
345 | + } |
|
338 | 346 | |
339 | 347 | print json_encode(array("id" => (int)$id, |
340 | 348 | "content" => $tags_str, "content_full" => $tags_str_full)); |
@@ -380,10 +388,11 @@ discard block |
||
380 | 388 | |
381 | 389 | foreach ($ids as $id) { |
382 | 390 | |
383 | - if ($assign) |
|
384 | - Labels::add_article($id, $label, $_SESSION["uid"]); |
|
385 | - else |
|
386 | - Labels::remove_article($id, $label, $_SESSION["uid"]); |
|
391 | + if ($assign) { |
|
392 | + Labels::add_article($id, $label, $_SESSION["uid"]); |
|
393 | + } else { |
|
394 | + Labels::remove_article($id, $label, $_SESSION["uid"]); |
|
395 | + } |
|
387 | 396 | |
388 | 397 | $labels = $this->get_article_labels($id, $_SESSION["uid"]); |
389 | 398 | |
@@ -444,14 +453,18 @@ discard block |
||
444 | 453 | $width = $line["width"]; |
445 | 454 | $height = $line["height"]; |
446 | 455 | |
447 | - if (!$ctype) $ctype = __("unknown type"); |
|
456 | + if (!$ctype) { |
|
457 | + $ctype = __("unknown type"); |
|
458 | + } |
|
448 | 459 | |
449 | 460 | //$filename = substr($url, strrpos($url, "/")+1); |
450 | 461 | $filename = basename($url); |
451 | 462 | |
452 | 463 | $player = format_inline_player($url, $ctype); |
453 | 464 | |
454 | - if ($player) array_push($entries_inline, $player); |
|
465 | + if ($player) { |
|
466 | + array_push($entries_inline, $player); |
|
467 | + } |
|
455 | 468 | |
456 | 469 | # $entry .= " <a target=\"_blank\" href=\"" . htmlspecialchars($url) . "\" rel=\"noopener noreferrer\">" . |
457 | 470 | # $filename . " (" . $ctype . ")" . "</a>"; |
@@ -479,8 +492,9 @@ discard block |
||
479 | 492 | |
480 | 493 | foreach ($entries as $entry) { |
481 | 494 | |
482 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ENCLOSURE) as $plugin) |
|
483 | - $retval = $plugin->hook_render_enclosure($entry, $hide_images); |
|
495 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ENCLOSURE) as $plugin) { |
|
496 | + $retval = $plugin->hook_render_enclosure($entry, $hide_images); |
|
497 | + } |
|
484 | 498 | |
485 | 499 | |
486 | 500 | if ($retval) { |
@@ -491,10 +505,12 @@ discard block |
||
491 | 505 | |
492 | 506 | if (!$hide_images) { |
493 | 507 | $encsize = ''; |
494 | - if ($entry['height'] > 0) |
|
495 | - $encsize .= ' height="' . intval($entry['height']) . '"'; |
|
496 | - if ($entry['width'] > 0) |
|
497 | - $encsize .= ' width="' . intval($entry['width']) . '"'; |
|
508 | + if ($entry['height'] > 0) { |
|
509 | + $encsize .= ' height="' . intval($entry['height']) . '"'; |
|
510 | + } |
|
511 | + if ($entry['width'] > 0) { |
|
512 | + $encsize .= ' width="' . intval($entry['width']) . '"'; |
|
513 | + } |
|
498 | 514 | $rv .= "<p><img |
499 | 515 | alt=\"".htmlspecialchars($entry["filename"])."\" |
500 | 516 | src=\"" .htmlspecialchars($entry["url"]) . "\" |
@@ -526,15 +542,17 @@ discard block |
||
526 | 542 | $rv .= "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; |
527 | 543 | |
528 | 544 | foreach ($entries as $entry) { |
529 | - if ($entry["title"]) |
|
530 | - $title = " — " . truncate_string($entry["title"], 30); |
|
531 | - else |
|
532 | - $title = ""; |
|
545 | + if ($entry["title"]) { |
|
546 | + $title = " — " . truncate_string($entry["title"], 30); |
|
547 | + } else { |
|
548 | + $title = ""; |
|
549 | + } |
|
533 | 550 | |
534 | - if ($entry["filename"]) |
|
535 | - $filename = truncate_middle(htmlspecialchars($entry["filename"]), 60); |
|
536 | - else |
|
537 | - $filename = ""; |
|
551 | + if ($entry["filename"]) { |
|
552 | + $filename = truncate_middle(htmlspecialchars($entry["filename"]), 60); |
|
553 | + } else { |
|
554 | + $filename = ""; |
|
555 | + } |
|
538 | 556 | |
539 | 557 | $rv .= "<div onclick='popupOpenUrl(\"".htmlspecialchars($entry["url"])."\")' |
540 | 558 | dojoType=\"dijit.MenuItem\">".$filename . $title."</div>"; |
@@ -552,7 +570,9 @@ discard block |
||
552 | 570 | |
553 | 571 | $a_id = $id; |
554 | 572 | |
555 | - if (!$owner_uid) $owner_uid = $_SESSION["uid"]; |
|
573 | + if (!$owner_uid) { |
|
574 | + $owner_uid = $_SESSION["uid"]; |
|
575 | + } |
|
556 | 576 | |
557 | 577 | $pdo = Db::pdo(); |
558 | 578 | |
@@ -570,7 +590,9 @@ discard block |
||
570 | 590 | WHERE ref_id = ? AND owner_uid = ?"); |
571 | 591 | $csth->execute([$id, $owner_uid]); |
572 | 592 | |
573 | - if ($row = $csth->fetch()) $tag_cache = $row["tag_cache"]; |
|
593 | + if ($row = $csth->fetch()) { |
|
594 | + $tag_cache = $row["tag_cache"]; |
|
595 | + } |
|
574 | 596 | } |
575 | 597 | |
576 | 598 | if ($tag_cache) { |
@@ -611,8 +633,9 @@ discard block |
||
611 | 633 | |
612 | 634 | $tags_str = mb_substr($tags_str, 0, mb_strlen($tags_str)-2); |
613 | 635 | |
614 | - if (count($tags) > $maxtags) |
|
615 | - $tags_str .= ", …"; |
|
636 | + if (count($tags) > $maxtags) { |
|
637 | + $tags_str .= ", …"; |
|
638 | + } |
|
616 | 639 | |
617 | 640 | return $tags_str; |
618 | 641 | } |
@@ -620,7 +643,9 @@ discard block |
||
620 | 643 | |
621 | 644 | static function format_article_labels($labels) { |
622 | 645 | |
623 | - if (!is_array($labels)) return ''; |
|
646 | + if (!is_array($labels)) { |
|
647 | + return ''; |
|
648 | + } |
|
624 | 649 | |
625 | 650 | $labels_str = ""; |
626 | 651 | |
@@ -680,10 +705,11 @@ discard block |
||
680 | 705 | |
681 | 706 | // purge orphaned posts in main content table |
682 | 707 | |
683 | - if (DB_TYPE == "mysql") |
|
684 | - $limit_qpart = "LIMIT 5000"; |
|
685 | - else |
|
686 | - $limit_qpart = ""; |
|
708 | + if (DB_TYPE == "mysql") { |
|
709 | + $limit_qpart = "LIMIT 5000"; |
|
710 | + } else { |
|
711 | + $limit_qpart = ""; |
|
712 | + } |
|
687 | 713 | |
688 | 714 | $pdo = Db::pdo(); |
689 | 715 | $res = $pdo->query("DELETE FROM ttrss_entries WHERE |
@@ -697,7 +723,9 @@ discard block |
||
697 | 723 | |
698 | 724 | static function catchupArticlesById($ids, $cmode, $owner_uid = false) { |
699 | 725 | |
700 | - if (!$owner_uid) $owner_uid = $_SESSION["uid"]; |
|
726 | + if (!$owner_uid) { |
|
727 | + $owner_uid = $_SESSION["uid"]; |
|
728 | + } |
|
701 | 729 | |
702 | 730 | $pdo = Db::pdo(); |
703 | 731 | |
@@ -747,7 +775,9 @@ discard block |
||
747 | 775 | static function get_article_labels($id, $owner_uid = false) { |
748 | 776 | $rv = array(); |
749 | 777 | |
750 | - if (!$owner_uid) $owner_uid = $_SESSION["uid"]; |
|
778 | + if (!$owner_uid) { |
|
779 | + $owner_uid = $_SESSION["uid"]; |
|
780 | + } |
|
751 | 781 | |
752 | 782 | $pdo = Db::pdo(); |
753 | 783 | |
@@ -761,10 +791,11 @@ discard block |
||
761 | 791 | if ($label_cache) { |
762 | 792 | $tmp = json_decode($label_cache, true); |
763 | 793 | |
764 | - if (!$tmp || $tmp["no-labels"] == 1) |
|
765 | - return $rv; |
|
766 | - else |
|
767 | - return $tmp; |
|
794 | + if (!$tmp || $tmp["no-labels"] == 1) { |
|
795 | + return $rv; |
|
796 | + } else { |
|
797 | + return $tmp; |
|
798 | + } |
|
768 | 799 | } |
769 | 800 | } |
770 | 801 | |
@@ -783,10 +814,11 @@ discard block |
||
783 | 814 | array_push($rv, $rk); |
784 | 815 | } |
785 | 816 | |
786 | - if (count($rv) > 0) |
|
787 | - Labels::update_cache($owner_uid, $id, $rv); |
|
788 | - else |
|
789 | - Labels::update_cache($owner_uid, $id, array("no-labels" => 1)); |
|
817 | + if (count($rv) > 0) { |
|
818 | + Labels::update_cache($owner_uid, $id, $rv); |
|
819 | + } else { |
|
820 | + Labels::update_cache($owner_uid, $id, array("no-labels" => 1)); |
|
821 | + } |
|
790 | 822 | |
791 | 823 | return $rv; |
792 | 824 | } |
@@ -834,28 +866,33 @@ discard block |
||
834 | 866 | } |
835 | 867 | } |
836 | 868 | |
837 | - if (!$article_image) |
|
838 | - foreach ($enclosures as $enc) { |
|
869 | + if (!$article_image) { |
|
870 | + foreach ($enclosures as $enc) { |
|
839 | 871 | if (strpos($enc["content_type"], "image/") !== FALSE) { |
840 | 872 | $article_image = $enc["content_url"]; |
873 | + } |
|
841 | 874 | break; |
842 | 875 | } |
843 | 876 | } |
844 | 877 | |
845 | - if ($article_image) |
|
846 | - $article_image = rewrite_relative_url($site_url, $article_image); |
|
878 | + if ($article_image) { |
|
879 | + $article_image = rewrite_relative_url($site_url, $article_image); |
|
880 | + } |
|
847 | 881 | |
848 | - if ($article_stream) |
|
849 | - $article_stream = rewrite_relative_url($site_url, $article_stream); |
|
882 | + if ($article_stream) { |
|
883 | + $article_stream = rewrite_relative_url($site_url, $article_stream); |
|
884 | + } |
|
850 | 885 | } |
851 | 886 | |
852 | 887 | $cache = new DiskCache("images"); |
853 | 888 | |
854 | - if ($article_image && $cache->exists(sha1($article_image))) |
|
855 | - $article_image = $cache->getUrl(sha1($article_image)); |
|
889 | + if ($article_image && $cache->exists(sha1($article_image))) { |
|
890 | + $article_image = $cache->getUrl(sha1($article_image)); |
|
891 | + } |
|
856 | 892 | |
857 | - if ($article_stream && $cache->exists(sha1($article_stream))) |
|
858 | - $article_stream = $cache->getUrl(sha1($article_stream)); |
|
893 | + if ($article_stream && $cache->exists(sha1($article_stream))) { |
|
894 | + $article_stream = $cache->getUrl(sha1($article_stream)); |
|
895 | + } |
|
859 | 896 | |
860 | 897 | return [$article_image, $article_stream]; |
861 | 898 | } |
@@ -5,9 +5,9 @@ discard block |
||
5 | 5 | const NEVER_GROUP_FEEDS = [ -6, 0 ]; |
6 | 6 | const NEVER_GROUP_BY_DATE = [ -2, -1, -3 ]; |
7 | 7 | |
8 | - private $params; |
|
8 | + private $params; |
|
9 | 9 | |
10 | - function csrf_ignore($method) { |
|
10 | + function csrf_ignore($method) { |
|
11 | 11 | $csrf_ignored = array("index", "quickaddfeed", "search"); |
12 | 12 | |
13 | 13 | return array_search($method, $csrf_ignored) !== false; |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | //$reply .= "<option value=\"catchupPage()\">".__('Mark as read')."</option>"; |
102 | 102 | |
103 | 103 | $reply .= "<option value=\"App.displayDlg('".__("Show as feed")."','generatedFeed', '$feed_id:$is_cat:$rss_link')\">". |
104 | - __('Show as feed')."</option>"; |
|
104 | + __('Show as feed')."</option>"; |
|
105 | 105 | |
106 | 106 | $reply .= "</select>"; |
107 | 107 | |
@@ -133,10 +133,10 @@ discard block |
||
133 | 133 | $method_split = explode(":", $method); |
134 | 134 | |
135 | 135 | if ($method == "ForceUpdate" && $feed > 0 && is_numeric($feed)) { |
136 | - $sth = $this->pdo->prepare("UPDATE ttrss_feeds |
|
136 | + $sth = $this->pdo->prepare("UPDATE ttrss_feeds |
|
137 | 137 | SET last_updated = '1970-01-01', last_update_started = '1970-01-01' |
138 | 138 | WHERE id = ?"); |
139 | - $sth->execute([$feed]); |
|
139 | + $sth->execute([$feed]); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | if ($method_split[0] == "MarkAllReadGR") { |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | "include_children" => $include_children, |
198 | 198 | "check_first_id" => $check_first_id, |
199 | 199 | "skip_first_id_check" => $skip_first_id_check, |
200 | - "order_by" => $order_by |
|
200 | + "order_by" => $order_by |
|
201 | 201 | ); |
202 | 202 | |
203 | 203 | $qfh_ret = $this->queryFeedHeadlines($params); |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | |
236 | 236 | $headlines_count = 0; |
237 | 237 | |
238 | - if (is_object($result)) { |
|
238 | + if (is_object($result)) { |
|
239 | 239 | while ($line = $result->fetch(PDO::FETCH_ASSOC)) { |
240 | 240 | |
241 | 241 | ++$headlines_count; |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) { |
249 | 249 | $line = $p->hook_query_headlines($line, 250, false); |
250 | 250 | } |
251 | - } |
|
251 | + } |
|
252 | 252 | |
253 | 253 | $id = $line["id"]; |
254 | 254 | |
@@ -295,53 +295,53 @@ discard block |
||
295 | 295 | |
296 | 296 | if (!$line["feed_title"]) $line["feed_title"] = ""; |
297 | 297 | |
298 | - $line["buttons_left"] = ""; |
|
299 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_LEFT_BUTTON) as $p) { |
|
300 | - $line["buttons_left"] .= $p->hook_article_left_button($line); |
|
301 | - } |
|
298 | + $line["buttons_left"] = ""; |
|
299 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_LEFT_BUTTON) as $p) { |
|
300 | + $line["buttons_left"] .= $p->hook_article_left_button($line); |
|
301 | + } |
|
302 | 302 | |
303 | - $line["buttons"] = ""; |
|
304 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_BUTTON) as $p) { |
|
305 | - $line["buttons"] .= $p->hook_article_button($line); |
|
306 | - } |
|
303 | + $line["buttons"] = ""; |
|
304 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_BUTTON) as $p) { |
|
305 | + $line["buttons"] .= $p->hook_article_button($line); |
|
306 | + } |
|
307 | 307 | |
308 | - $line["content"] = sanitize($line["content"], |
|
309 | - $line['hide_images'], false, $line["site_url"], $highlight_words, $line["id"]); |
|
308 | + $line["content"] = sanitize($line["content"], |
|
309 | + $line['hide_images'], false, $line["site_url"], $highlight_words, $line["id"]); |
|
310 | 310 | |
311 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ARTICLE_CDM) as $p) { |
|
312 | - $line = $p->hook_render_article_cdm($line); |
|
313 | - } |
|
311 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ARTICLE_CDM) as $p) { |
|
312 | + $line = $p->hook_render_article_cdm($line); |
|
313 | + } |
|
314 | 314 | |
315 | - $line['content'] = DiskCache::rewriteUrls($line['content']); |
|
315 | + $line['content'] = DiskCache::rewriteUrls($line['content']); |
|
316 | 316 | |
317 | - if ($line['note']) |
|
318 | - $line['note'] = Article::format_article_note($id, $line['note']); |
|
319 | - else |
|
320 | - $line['note'] = ""; |
|
317 | + if ($line['note']) |
|
318 | + $line['note'] = Article::format_article_note($id, $line['note']); |
|
319 | + else |
|
320 | + $line['note'] = ""; |
|
321 | 321 | |
322 | - if (!get_pref("CDM_EXPANDED")) { |
|
323 | - $line["cdm_excerpt"] = "<span class='collapse'> |
|
322 | + if (!get_pref("CDM_EXPANDED")) { |
|
323 | + $line["cdm_excerpt"] = "<span class='collapse'> |
|
324 | 324 | <i class='material-icons' onclick='return Article.cdmUnsetActive(event)' |
325 | 325 | title=\"" . __("Collapse article") . "\">remove_circle</i></span>"; |
326 | 326 | |
327 | - if (get_pref('SHOW_CONTENT_PREVIEW')) { |
|
328 | - $line["cdm_excerpt"] .= "<span class='excerpt'>" . $line["content_preview"] . "</span>"; |
|
329 | - } |
|
330 | - } |
|
327 | + if (get_pref('SHOW_CONTENT_PREVIEW')) { |
|
328 | + $line["cdm_excerpt"] .= "<span class='excerpt'>" . $line["content_preview"] . "</span>"; |
|
329 | + } |
|
330 | + } |
|
331 | 331 | |
332 | - $line["enclosures"] = Article::format_article_enclosures($id, $line["always_display_enclosures"], |
|
333 | - $line["content"], $line["hide_images"]); |
|
332 | + $line["enclosures"] = Article::format_article_enclosures($id, $line["always_display_enclosures"], |
|
333 | + $line["content"], $line["hide_images"]); |
|
334 | 334 | |
335 | - if ($line["orig_feed_id"]) { |
|
335 | + if ($line["orig_feed_id"]) { |
|
336 | 336 | |
337 | - $ofgh = $this->pdo->prepare("SELECT * FROM ttrss_archived_feeds |
|
337 | + $ofgh = $this->pdo->prepare("SELECT * FROM ttrss_archived_feeds |
|
338 | 338 | WHERE id = ? AND owner_uid = ?"); |
339 | - $ofgh->execute([$line["orig_feed_id"], $_SESSION['uid']]); |
|
339 | + $ofgh->execute([$line["orig_feed_id"], $_SESSION['uid']]); |
|
340 | 340 | |
341 | - if ($tmp_line = $ofgh->fetch()) { |
|
342 | - $line["orig_feed"] = [ $tmp_line["title"], $tmp_line["site_url"], $tmp_line["feed_url"] ]; |
|
343 | - } |
|
344 | - } |
|
341 | + if ($tmp_line = $ofgh->fetch()) { |
|
342 | + $line["orig_feed"] = [ $tmp_line["title"], $tmp_line["site_url"], $tmp_line["feed_url"] ]; |
|
343 | + } |
|
344 | + } |
|
345 | 345 | |
346 | 346 | $line["updated_long"] = make_local_datetime($line["updated"],true); |
347 | 347 | $line["updated"] = make_local_datetime($line["updated"], false, false, false, true); |
@@ -363,7 +363,7 @@ discard block |
||
363 | 363 | $line['feed_icon'] = "<i class='icon-no-feed material-icons'>rss_feed</i>"; |
364 | 364 | } |
365 | 365 | |
366 | - //setting feed headline background color, needs to change text color based on dark/light |
|
366 | + //setting feed headline background color, needs to change text color based on dark/light |
|
367 | 367 | $fav_color = $line['favicon_avg_color']; |
368 | 368 | |
369 | 369 | require_once "colors.php"; |
@@ -377,18 +377,18 @@ discard block |
||
377 | 377 | } |
378 | 378 | |
379 | 379 | if (isset($rgba_cache[$feed_id])) { |
380 | - $line['feed_bg_color'] = 'rgba(' . implode(",", $rgba_cache[$feed_id]) . ',0.3)'; |
|
381 | - } |
|
380 | + $line['feed_bg_color'] = 'rgba(' . implode(",", $rgba_cache[$feed_id]) . ',0.3)'; |
|
381 | + } |
|
382 | 382 | |
383 | 383 | /* we don't need those */ |
384 | 384 | |
385 | - foreach (["date_entered", "guid", "last_published", "last_marked", "tag_cache", "favicon_avg_color", |
|
386 | - "uuid", "label_cache", "yyiw"] as $k) |
|
387 | - unset($line[$k]); |
|
385 | + foreach (["date_entered", "guid", "last_published", "last_marked", "tag_cache", "favicon_avg_color", |
|
386 | + "uuid", "label_cache", "yyiw"] as $k) |
|
387 | + unset($line[$k]); |
|
388 | 388 | |
389 | 389 | array_push($reply['content'], $line); |
390 | 390 | } |
391 | - } |
|
391 | + } |
|
392 | 392 | |
393 | 393 | if (!$headlines_count) { |
394 | 394 | |
@@ -570,7 +570,7 @@ discard block |
||
570 | 570 | $reply['headlines']['is_cat'] = (bool) $cat_view; |
571 | 571 | |
572 | 572 | $reply['headlines-info'] = ["count" => (int) $headlines_count, |
573 | - "disable_cache" => (bool) $disable_cache]; |
|
573 | + "disable_cache" => (bool) $disable_cache]; |
|
574 | 574 | |
575 | 575 | // this is parsed by handleRpcJson() on first viewfeed() to set cdm expanded, etc |
576 | 576 | $reply['runtime-info'] = make_runtime_info(); |
@@ -578,9 +578,9 @@ discard block |
||
578 | 578 | $reply_json = json_encode($reply); |
579 | 579 | |
580 | 580 | if (!$reply_json) { |
581 | - $reply_json = json_encode(["error" => ["code" => 15, |
|
582 | - "message" => json_last_error_msg()]]); |
|
583 | - } |
|
581 | + $reply_json = json_encode(["error" => ["code" => 15, |
|
582 | + "message" => json_last_error_msg()]]); |
|
583 | + } |
|
584 | 584 | |
585 | 585 | print $reply_json; |
586 | 586 | |
@@ -780,9 +780,9 @@ discard block |
||
780 | 780 | $sth->execute([$feed_id, $_SESSION['uid']]); |
781 | 781 | |
782 | 782 | if (!$sth->fetch()) { |
783 | - print "Access denied."; |
|
784 | - return; |
|
785 | - } |
|
783 | + print "Access denied."; |
|
784 | + return; |
|
785 | + } |
|
786 | 786 | |
787 | 787 | $refetch_checked = isset($_REQUEST["force_refetch"]) ? "checked" : ""; |
788 | 788 | $rehash_checked = isset($_REQUEST["force_rehash"]) ? "checked" : ""; |
@@ -1236,7 +1236,7 @@ discard block |
||
1236 | 1236 | } else { |
1237 | 1237 | $icon = self::getIconFile($id); |
1238 | 1238 | |
1239 | - if ($icon && file_exists($icon)) { |
|
1239 | + if ($icon && file_exists($icon)) { |
|
1240 | 1240 | return ICONS_URL . "/" . basename($icon) . "?" . filemtime($icon); |
1241 | 1241 | } |
1242 | 1242 | } |
@@ -1247,7 +1247,7 @@ discard block |
||
1247 | 1247 | } |
1248 | 1248 | |
1249 | 1249 | static function getFeedTitle($id, $cat = false) { |
1250 | - $pdo = Db::pdo(); |
|
1250 | + $pdo = Db::pdo(); |
|
1251 | 1251 | |
1252 | 1252 | if ($cat) { |
1253 | 1253 | return Feeds::getCategoryTitle($id); |
@@ -1278,10 +1278,10 @@ discard block |
||
1278 | 1278 | |
1279 | 1279 | } else if (is_numeric($id) && $id > 0) { |
1280 | 1280 | |
1281 | - $sth = $pdo->prepare("SELECT title FROM ttrss_feeds WHERE id = ?"); |
|
1282 | - $sth->execute([$id]); |
|
1281 | + $sth = $pdo->prepare("SELECT title FROM ttrss_feeds WHERE id = ?"); |
|
1282 | + $sth->execute([$id]); |
|
1283 | 1283 | |
1284 | - if ($row = $sth->fetch()) { |
|
1284 | + if ($row = $sth->fetch()) { |
|
1285 | 1285 | return $row["title"]; |
1286 | 1286 | } else { |
1287 | 1287 | return "Unknown feed ($id)"; |
@@ -1300,7 +1300,7 @@ discard block |
||
1300 | 1300 | |
1301 | 1301 | if ($cat >= 0) { |
1302 | 1302 | |
1303 | - if (!$cat) $cat = null; |
|
1303 | + if (!$cat) $cat = null; |
|
1304 | 1304 | |
1305 | 1305 | $sth = $pdo->prepare("SELECT id FROM ttrss_feeds |
1306 | 1306 | WHERE (cat_id = :cat OR (:cat IS NULL AND cat_id IS NULL)) |
@@ -1340,7 +1340,7 @@ discard block |
||
1340 | 1340 | WHERE article_id = ref_id AND unread = true |
1341 | 1341 | AND ttrss_user_entries.owner_uid = ?"); |
1342 | 1342 | $sth->execute([$owner_uid]); |
1343 | - $row = $sth->fetch(); |
|
1343 | + $row = $sth->fetch(); |
|
1344 | 1344 | |
1345 | 1345 | return $row["unread"]; |
1346 | 1346 | } |
@@ -1388,7 +1388,7 @@ discard block |
||
1388 | 1388 | return __("Labels"); |
1389 | 1389 | } else { |
1390 | 1390 | |
1391 | - $pdo = Db::pdo(); |
|
1391 | + $pdo = Db::pdo(); |
|
1392 | 1392 | |
1393 | 1393 | $sth = $pdo->prepare("SELECT title FROM ttrss_feed_categories WHERE |
1394 | 1394 | id = ?"); |
@@ -1424,7 +1424,7 @@ discard block |
||
1424 | 1424 | $pdo = Db::pdo(); |
1425 | 1425 | |
1426 | 1426 | // WARNING: due to highly dynamic nature of this query its going to quote parameters |
1427 | - // right before adding them to SQL part |
|
1427 | + // right before adding them to SQL part |
|
1428 | 1428 | |
1429 | 1429 | $feed = $params["feed"]; |
1430 | 1430 | $limit = isset($params["limit"]) ? $params["limit"] : 30; |
@@ -1668,7 +1668,7 @@ discard block |
||
1668 | 1668 | $ssth = $pdo->prepare("SELECT title,site_url,last_error,last_updated |
1669 | 1669 | FROM ttrss_feeds WHERE id = ? AND owner_uid = ?"); |
1670 | 1670 | $ssth->execute([$feed, $owner_uid]); |
1671 | - $row = $ssth->fetch(); |
|
1671 | + $row = $ssth->fetch(); |
|
1672 | 1672 | |
1673 | 1673 | $feed_title = $row["title"]; |
1674 | 1674 | $feed_site_url = $row["site_url"]; |
@@ -1906,9 +1906,9 @@ discard block |
||
1906 | 1906 | static function getFeedCategory($feed) { |
1907 | 1907 | $pdo = Db::pdo(); |
1908 | 1908 | |
1909 | - $sth = $pdo->prepare("SELECT cat_id FROM ttrss_feeds |
|
1909 | + $sth = $pdo->prepare("SELECT cat_id FROM ttrss_feeds |
|
1910 | 1910 | WHERE id = ?"); |
1911 | - $sth->execute([$feed]); |
|
1911 | + $sth->execute([$feed]); |
|
1912 | 1912 | |
1913 | 1913 | if ($row = $sth->fetch()) { |
1914 | 1914 | return $row["cat_id"]; |
@@ -1918,20 +1918,20 @@ discard block |
||
1918 | 1918 | |
1919 | 1919 | } |
1920 | 1920 | |
1921 | - function color_of($name) { |
|
1922 | - $colormap = [ "#1cd7d7","#d91111","#1212d7","#8e16e5","#7b7b7b", |
|
1923 | - "#39f110","#0bbea6","#ec0e0e","#1534f2","#b9e416", |
|
1924 | - "#479af2","#f36b14","#10c7e9","#1e8fe7","#e22727" ]; |
|
1921 | + function color_of($name) { |
|
1922 | + $colormap = [ "#1cd7d7","#d91111","#1212d7","#8e16e5","#7b7b7b", |
|
1923 | + "#39f110","#0bbea6","#ec0e0e","#1534f2","#b9e416", |
|
1924 | + "#479af2","#f36b14","#10c7e9","#1e8fe7","#e22727" ]; |
|
1925 | 1925 | |
1926 | - $sum = 0; |
|
1926 | + $sum = 0; |
|
1927 | 1927 | |
1928 | - for ($i = 0; $i < strlen($name); $i++) { |
|
1929 | - $sum += ord($name[$i]); |
|
1930 | - } |
|
1928 | + for ($i = 0; $i < strlen($name); $i++) { |
|
1929 | + $sum += ord($name[$i]); |
|
1930 | + } |
|
1931 | 1931 | |
1932 | - $sum %= count($colormap); |
|
1932 | + $sum %= count($colormap); |
|
1933 | 1933 | |
1934 | - return $colormap[$sum]; |
|
1934 | + return $colormap[$sum]; |
|
1935 | 1935 | } |
1936 | 1936 | |
1937 | 1937 | static function get_feeds_from_html($url, $content) { |
@@ -398,21 +398,21 @@ discard block |
||
398 | 398 | $message = $query_error_override; |
399 | 399 | } else { |
400 | 400 | switch ($view_mode) { |
401 | - case "unread": |
|
402 | - $message = __("No unread articles found to display."); |
|
403 | - break; |
|
404 | - case "updated": |
|
405 | - $message = __("No updated articles found to display."); |
|
406 | - break; |
|
407 | - case "marked": |
|
408 | - $message = __("No starred articles found to display."); |
|
409 | - break; |
|
410 | - default: |
|
411 | - if ($feed < LABEL_BASE_INDEX) { |
|
412 | - $message = __("No articles found to display. You can assign articles to labels manually from article header context menu (applies to all selected articles) or use a filter."); |
|
413 | - } else { |
|
414 | - $message = __("No articles found to display."); |
|
415 | - } |
|
401 | + case "unread": |
|
402 | + $message = __("No unread articles found to display."); |
|
403 | + break; |
|
404 | + case "updated": |
|
405 | + $message = __("No updated articles found to display."); |
|
406 | + break; |
|
407 | + case "marked": |
|
408 | + $message = __("No starred articles found to display."); |
|
409 | + break; |
|
410 | + default: |
|
411 | + if ($feed < LABEL_BASE_INDEX) { |
|
412 | + $message = __("No articles found to display. You can assign articles to labels manually from article header context menu (applies to all selected articles) or use a filter."); |
|
413 | + } else { |
|
414 | + $message = __("No articles found to display."); |
|
415 | + } |
|
416 | 416 | } |
417 | 417 | } |
418 | 418 | |
@@ -874,29 +874,29 @@ discard block |
||
874 | 874 | // TODO: all this interval stuff needs some generic generator function |
875 | 875 | |
876 | 876 | switch ($mode) { |
877 | - case "1day": |
|
878 | - if (DB_TYPE == "pgsql") { |
|
879 | - $date_qpart = "date_entered < NOW() - INTERVAL '1 day' "; |
|
880 | - } else { |
|
881 | - $date_qpart = "date_entered < DATE_SUB(NOW(), INTERVAL 1 DAY) "; |
|
882 | - } |
|
883 | - break; |
|
884 | - case "1week": |
|
885 | - if (DB_TYPE == "pgsql") { |
|
886 | - $date_qpart = "date_entered < NOW() - INTERVAL '1 week' "; |
|
887 | - } else { |
|
888 | - $date_qpart = "date_entered < DATE_SUB(NOW(), INTERVAL 1 WEEK) "; |
|
889 | - } |
|
890 | - break; |
|
891 | - case "2week": |
|
892 | - if (DB_TYPE == "pgsql") { |
|
893 | - $date_qpart = "date_entered < NOW() - INTERVAL '2 week' "; |
|
894 | - } else { |
|
895 | - $date_qpart = "date_entered < DATE_SUB(NOW(), INTERVAL 2 WEEK) "; |
|
896 | - } |
|
897 | - break; |
|
898 | - default: |
|
899 | - $date_qpart = "true"; |
|
877 | + case "1day": |
|
878 | + if (DB_TYPE == "pgsql") { |
|
879 | + $date_qpart = "date_entered < NOW() - INTERVAL '1 day' "; |
|
880 | + } else { |
|
881 | + $date_qpart = "date_entered < DATE_SUB(NOW(), INTERVAL 1 DAY) "; |
|
882 | + } |
|
883 | + break; |
|
884 | + case "1week": |
|
885 | + if (DB_TYPE == "pgsql") { |
|
886 | + $date_qpart = "date_entered < NOW() - INTERVAL '1 week' "; |
|
887 | + } else { |
|
888 | + $date_qpart = "date_entered < DATE_SUB(NOW(), INTERVAL 1 WEEK) "; |
|
889 | + } |
|
890 | + break; |
|
891 | + case "2week": |
|
892 | + if (DB_TYPE == "pgsql") { |
|
893 | + $date_qpart = "date_entered < NOW() - INTERVAL '2 week' "; |
|
894 | + } else { |
|
895 | + $date_qpart = "date_entered < DATE_SUB(NOW(), INTERVAL 2 WEEK) "; |
|
896 | + } |
|
897 | + break; |
|
898 | + default: |
|
899 | + $date_qpart = "true"; |
|
900 | 900 | } |
901 | 901 | |
902 | 902 | if (is_numeric($feed)) { |
@@ -1212,35 +1212,35 @@ discard block |
||
1212 | 1212 | |
1213 | 1213 | static function getFeedIcon($id) { |
1214 | 1214 | switch ($id) { |
1215 | - case 0: |
|
1216 | - return "archive"; |
|
1217 | - break; |
|
1218 | - case -1: |
|
1219 | - return "star"; |
|
1220 | - break; |
|
1221 | - case -2: |
|
1222 | - return "rss_feed"; |
|
1223 | - break; |
|
1224 | - case -3: |
|
1225 | - return "whatshot"; |
|
1226 | - break; |
|
1227 | - case -4: |
|
1228 | - return "inbox"; |
|
1229 | - break; |
|
1230 | - case -6: |
|
1231 | - return "restore"; |
|
1232 | - break; |
|
1233 | - default: |
|
1234 | - if ($id < LABEL_BASE_INDEX) { |
|
1235 | - return "label"; |
|
1236 | - } else { |
|
1237 | - $icon = self::getIconFile($id); |
|
1215 | + case 0: |
|
1216 | + return "archive"; |
|
1217 | + break; |
|
1218 | + case -1: |
|
1219 | + return "star"; |
|
1220 | + break; |
|
1221 | + case -2: |
|
1222 | + return "rss_feed"; |
|
1223 | + break; |
|
1224 | + case -3: |
|
1225 | + return "whatshot"; |
|
1226 | + break; |
|
1227 | + case -4: |
|
1228 | + return "inbox"; |
|
1229 | + break; |
|
1230 | + case -6: |
|
1231 | + return "restore"; |
|
1232 | + break; |
|
1233 | + default: |
|
1234 | + if ($id < LABEL_BASE_INDEX) { |
|
1235 | + return "label"; |
|
1236 | + } else { |
|
1237 | + $icon = self::getIconFile($id); |
|
1238 | 1238 | |
1239 | 1239 | if ($icon && file_exists($icon)) { |
1240 | - return ICONS_URL . "/" . basename($icon) . "?" . filemtime($icon); |
|
1241 | - } |
|
1240 | + return ICONS_URL . "/" . basename($icon) . "?" . filemtime($icon); |
|
1242 | 1241 | } |
1243 | - break; |
|
1242 | + } |
|
1243 | + break; |
|
1244 | 1244 | } |
1245 | 1245 | |
1246 | 1246 | return false; |
@@ -2208,102 +2208,102 @@ discard block |
||
2208 | 2208 | $commandpair = explode(":", mb_strtolower($k), 2); |
2209 | 2209 | |
2210 | 2210 | switch ($commandpair[0]) { |
2211 | - case "title": |
|
2212 | - if ($commandpair[1]) { |
|
2213 | - array_push($query_keywords, "($not (LOWER(ttrss_entries.title) LIKE ". |
|
2214 | - $pdo->quote('%' . mb_strtolower($commandpair[1]) . '%') ."))"); |
|
2215 | - } else { |
|
2216 | - array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%') |
|
2211 | + case "title": |
|
2212 | + if ($commandpair[1]) { |
|
2213 | + array_push($query_keywords, "($not (LOWER(ttrss_entries.title) LIKE ". |
|
2214 | + $pdo->quote('%' . mb_strtolower($commandpair[1]) . '%') ."))"); |
|
2215 | + } else { |
|
2216 | + array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%') |
|
2217 | 2217 | OR UPPER(ttrss_entries.content) $not LIKE UPPER(".$pdo->quote("%$k%")."))"); |
2218 | - array_push($search_words, $k); |
|
2219 | - } |
|
2220 | - break; |
|
2221 | - case "author": |
|
2222 | - if ($commandpair[1]) { |
|
2223 | - array_push($query_keywords, "($not (LOWER(author) LIKE ". |
|
2224 | - $pdo->quote('%' . mb_strtolower($commandpair[1]) . '%')."))"); |
|
2225 | - } else { |
|
2226 | - array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%') |
|
2218 | + array_push($search_words, $k); |
|
2219 | + } |
|
2220 | + break; |
|
2221 | + case "author": |
|
2222 | + if ($commandpair[1]) { |
|
2223 | + array_push($query_keywords, "($not (LOWER(author) LIKE ". |
|
2224 | + $pdo->quote('%' . mb_strtolower($commandpair[1]) . '%')."))"); |
|
2225 | + } else { |
|
2226 | + array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%') |
|
2227 | 2227 | OR UPPER(ttrss_entries.content) $not LIKE UPPER(".$pdo->quote("%$k%")."))"); |
2228 | - array_push($search_words, $k); |
|
2229 | - } |
|
2230 | - break; |
|
2231 | - case "note": |
|
2232 | - if ($commandpair[1]) { |
|
2233 | - if ($commandpair[1] == "true") |
|
2234 | - array_push($query_keywords, "($not (note IS NOT NULL AND note != ''))"); |
|
2235 | - else if ($commandpair[1] == "false") |
|
2236 | - array_push($query_keywords, "($not (note IS NULL OR note = ''))"); |
|
2237 | - else |
|
2238 | - array_push($query_keywords, "($not (LOWER(note) LIKE ". |
|
2239 | - $pdo->quote('%' . mb_strtolower($commandpair[1]) . '%')."))"); |
|
2240 | - } else { |
|
2241 | - array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER(".$pdo->quote("%$k%").") |
|
2228 | + array_push($search_words, $k); |
|
2229 | + } |
|
2230 | + break; |
|
2231 | + case "note": |
|
2232 | + if ($commandpair[1]) { |
|
2233 | + if ($commandpair[1] == "true") |
|
2234 | + array_push($query_keywords, "($not (note IS NOT NULL AND note != ''))"); |
|
2235 | + else if ($commandpair[1] == "false") |
|
2236 | + array_push($query_keywords, "($not (note IS NULL OR note = ''))"); |
|
2237 | + else |
|
2238 | + array_push($query_keywords, "($not (LOWER(note) LIKE ". |
|
2239 | + $pdo->quote('%' . mb_strtolower($commandpair[1]) . '%')."))"); |
|
2240 | + } else { |
|
2241 | + array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER(".$pdo->quote("%$k%").") |
|
2242 | 2242 | OR UPPER(ttrss_entries.content) $not LIKE UPPER(".$pdo->quote("%$k%")."))"); |
2243 | - if (!$not) array_push($search_words, $k); |
|
2244 | - } |
|
2245 | - break; |
|
2246 | - case "star": |
|
2243 | + if (!$not) array_push($search_words, $k); |
|
2244 | + } |
|
2245 | + break; |
|
2246 | + case "star": |
|
2247 | 2247 | |
2248 | - if ($commandpair[1]) { |
|
2249 | - if ($commandpair[1] == "true") |
|
2250 | - array_push($query_keywords, "($not (marked = true))"); |
|
2251 | - else |
|
2252 | - array_push($query_keywords, "($not (marked = false))"); |
|
2253 | - } else { |
|
2254 | - array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER(".$pdo->quote("%$k%").") |
|
2248 | + if ($commandpair[1]) { |
|
2249 | + if ($commandpair[1] == "true") |
|
2250 | + array_push($query_keywords, "($not (marked = true))"); |
|
2251 | + else |
|
2252 | + array_push($query_keywords, "($not (marked = false))"); |
|
2253 | + } else { |
|
2254 | + array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER(".$pdo->quote("%$k%").") |
|
2255 | 2255 | OR UPPER(ttrss_entries.content) $not LIKE UPPER(".$pdo->quote("%$k%")."))"); |
2256 | - if (!$not) array_push($search_words, $k); |
|
2257 | - } |
|
2258 | - break; |
|
2259 | - case "pub": |
|
2260 | - if ($commandpair[1]) { |
|
2261 | - if ($commandpair[1] == "true") |
|
2262 | - array_push($query_keywords, "($not (published = true))"); |
|
2263 | - else |
|
2264 | - array_push($query_keywords, "($not (published = false))"); |
|
2256 | + if (!$not) array_push($search_words, $k); |
|
2257 | + } |
|
2258 | + break; |
|
2259 | + case "pub": |
|
2260 | + if ($commandpair[1]) { |
|
2261 | + if ($commandpair[1] == "true") |
|
2262 | + array_push($query_keywords, "($not (published = true))"); |
|
2263 | + else |
|
2264 | + array_push($query_keywords, "($not (published = false))"); |
|
2265 | 2265 | |
2266 | - } else { |
|
2267 | - array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%') |
|
2266 | + } else { |
|
2267 | + array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%') |
|
2268 | 2268 | OR UPPER(ttrss_entries.content) $not LIKE UPPER(".$pdo->quote("%$k%")."))"); |
2269 | - if (!$not) array_push($search_words, $k); |
|
2270 | - } |
|
2271 | - break; |
|
2272 | - case "unread": |
|
2273 | - if ($commandpair[1]) { |
|
2274 | - if ($commandpair[1] == "true") |
|
2275 | - array_push($query_keywords, "($not (unread = true))"); |
|
2276 | - else |
|
2277 | - array_push($query_keywords, "($not (unread = false))"); |
|
2269 | + if (!$not) array_push($search_words, $k); |
|
2270 | + } |
|
2271 | + break; |
|
2272 | + case "unread": |
|
2273 | + if ($commandpair[1]) { |
|
2274 | + if ($commandpair[1] == "true") |
|
2275 | + array_push($query_keywords, "($not (unread = true))"); |
|
2276 | + else |
|
2277 | + array_push($query_keywords, "($not (unread = false))"); |
|
2278 | 2278 | |
2279 | - } else { |
|
2280 | - array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER(".$pdo->quote("%$k%").") |
|
2279 | + } else { |
|
2280 | + array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER(".$pdo->quote("%$k%").") |
|
2281 | 2281 | OR UPPER(ttrss_entries.content) $not LIKE UPPER(".$pdo->quote("%$k%")."))"); |
2282 | - if (!$not) array_push($search_words, $k); |
|
2283 | - } |
|
2284 | - break; |
|
2285 | - default: |
|
2286 | - if (strpos($k, "@") === 0) { |
|
2282 | + if (!$not) array_push($search_words, $k); |
|
2283 | + } |
|
2284 | + break; |
|
2285 | + default: |
|
2286 | + if (strpos($k, "@") === 0) { |
|
2287 | 2287 | |
2288 | - $user_tz_string = get_pref('USER_TIMEZONE', $_SESSION['uid']); |
|
2289 | - $orig_ts = strtotime(substr($k, 1)); |
|
2290 | - $k = date("Y-m-d", convert_timestamp($orig_ts, $user_tz_string, 'UTC')); |
|
2288 | + $user_tz_string = get_pref('USER_TIMEZONE', $_SESSION['uid']); |
|
2289 | + $orig_ts = strtotime(substr($k, 1)); |
|
2290 | + $k = date("Y-m-d", convert_timestamp($orig_ts, $user_tz_string, 'UTC')); |
|
2291 | 2291 | |
2292 | - //$k = date("Y-m-d", strtotime(substr($k, 1))); |
|
2292 | + //$k = date("Y-m-d", strtotime(substr($k, 1))); |
|
2293 | 2293 | |
2294 | - array_push($query_keywords, "(".SUBSTRING_FOR_DATE."(updated,1,LENGTH('$k')) $not = '$k')"); |
|
2295 | - } else { |
|
2294 | + array_push($query_keywords, "(".SUBSTRING_FOR_DATE."(updated,1,LENGTH('$k')) $not = '$k')"); |
|
2295 | + } else { |
|
2296 | 2296 | |
2297 | - if (DB_TYPE == "pgsql") { |
|
2298 | - $k = mb_strtolower($k); |
|
2299 | - array_push($search_query_leftover, $not ? "!$k" : $k); |
|
2300 | - } else { |
|
2301 | - array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER(".$pdo->quote("%$k%").") |
|
2297 | + if (DB_TYPE == "pgsql") { |
|
2298 | + $k = mb_strtolower($k); |
|
2299 | + array_push($search_query_leftover, $not ? "!$k" : $k); |
|
2300 | + } else { |
|
2301 | + array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER(".$pdo->quote("%$k%").") |
|
2302 | 2302 | OR UPPER(ttrss_entries.content) $not LIKE UPPER(".$pdo->quote("%$k%")."))"); |
2303 | - } |
|
2304 | - |
|
2305 | - if (!$not) array_push($search_words, $k); |
|
2306 | 2303 | } |
2304 | + |
|
2305 | + if (!$not) array_push($search_words, $k); |
|
2306 | + } |
|
2307 | 2307 | } |
2308 | 2308 | } |
2309 | 2309 |
@@ -2,8 +2,8 @@ discard block |
||
2 | 2 | require_once "colors.php"; |
3 | 3 | |
4 | 4 | class Feeds extends Handler_Protected { |
5 | - const NEVER_GROUP_FEEDS = [ -6, 0 ]; |
|
6 | - const NEVER_GROUP_BY_DATE = [ -2, -1, -3 ]; |
|
5 | + const NEVER_GROUP_FEEDS = [ -6, 0]; |
|
6 | + const NEVER_GROUP_BY_DATE = [ -2, -1, -3]; |
|
7 | 7 | |
8 | 8 | private $params; |
9 | 9 | |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | |
28 | 28 | $reply = ""; |
29 | 29 | |
30 | - $rss_link = htmlspecialchars(get_self_url_prefix() . |
|
30 | + $rss_link = htmlspecialchars(get_self_url_prefix(). |
|
31 | 31 | "/public.php?op=rss&id=$feed_id$cat_q$search_q"); |
32 | 32 | |
33 | 33 | $reply .= "<span class='left'>"; |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | } |
50 | 50 | |
51 | 51 | if ($error) |
52 | - $reply .= " <i title=\"" . htmlspecialchars($error) . "\" class='material-icons icon-error'>error</i>"; |
|
52 | + $reply .= " <i title=\"".htmlspecialchars($error)."\" class='material-icons icon-error'>error</i>"; |
|
53 | 53 | |
54 | 54 | $reply .= "</span>"; |
55 | 55 | $reply .= "<span id='feed_current_unread' style='display: none'></span>"; |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | $sth->execute([$feed]); |
140 | 140 | } |
141 | 141 | |
142 | - if ($method_split[0] == "MarkAllReadGR") { |
|
142 | + if ($method_split[0] == "MarkAllReadGR") { |
|
143 | 143 | $this->catchup_feed($method_split[1], false); |
144 | 144 | } |
145 | 145 | |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | if (!get_pref('SHOW_CONTENT_PREVIEW')) { |
244 | 244 | $line["content_preview"] = ""; |
245 | 245 | } else { |
246 | - $line["content_preview"] = "— " . truncate_string(strip_tags($line["content"]), 250); |
|
246 | + $line["content_preview"] = "— ".truncate_string(strip_tags($line["content"]), 250); |
|
247 | 247 | |
248 | 248 | foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) { |
249 | 249 | $line = $p->hook_query_headlines($line, 250, false); |
@@ -322,10 +322,10 @@ discard block |
||
322 | 322 | if (!get_pref("CDM_EXPANDED")) { |
323 | 323 | $line["cdm_excerpt"] = "<span class='collapse'> |
324 | 324 | <i class='material-icons' onclick='return Article.cdmUnsetActive(event)' |
325 | - title=\"" . __("Collapse article") . "\">remove_circle</i></span>"; |
|
325 | + title=\"" . __("Collapse article")."\">remove_circle</i></span>"; |
|
326 | 326 | |
327 | 327 | if (get_pref('SHOW_CONTENT_PREVIEW')) { |
328 | - $line["cdm_excerpt"] .= "<span class='excerpt'>" . $line["content_preview"] . "</span>"; |
|
328 | + $line["cdm_excerpt"] .= "<span class='excerpt'>".$line["content_preview"]."</span>"; |
|
329 | 329 | } |
330 | 330 | } |
331 | 331 | |
@@ -339,11 +339,11 @@ discard block |
||
339 | 339 | $ofgh->execute([$line["orig_feed_id"], $_SESSION['uid']]); |
340 | 340 | |
341 | 341 | if ($tmp_line = $ofgh->fetch()) { |
342 | - $line["orig_feed"] = [ $tmp_line["title"], $tmp_line["site_url"], $tmp_line["feed_url"] ]; |
|
342 | + $line["orig_feed"] = [$tmp_line["title"], $tmp_line["site_url"], $tmp_line["feed_url"]]; |
|
343 | 343 | } |
344 | 344 | } |
345 | 345 | |
346 | - $line["updated_long"] = make_local_datetime($line["updated"],true); |
|
346 | + $line["updated_long"] = make_local_datetime($line["updated"], true); |
|
347 | 347 | $line["updated"] = make_local_datetime($line["updated"], false, false, false, true); |
348 | 348 | |
349 | 349 | |
@@ -377,7 +377,7 @@ discard block |
||
377 | 377 | } |
378 | 378 | |
379 | 379 | if (isset($rgba_cache[$feed_id])) { |
380 | - $line['feed_bg_color'] = 'rgba(' . implode(",", $rgba_cache[$feed_id]) . ',0.3)'; |
|
380 | + $line['feed_bg_color'] = 'rgba('.implode(",", $rgba_cache[$feed_id]).',0.3)'; |
|
381 | 381 | } |
382 | 382 | |
383 | 383 | /* we don't need those */ |
@@ -421,7 +421,7 @@ discard block |
||
421 | 421 | |
422 | 422 | $reply['content'] .= "<p><span class=\"text-muted\">"; |
423 | 423 | |
424 | - $sth = $this->pdo->prepare("SELECT " . SUBSTRING_FOR_DATE . "(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds |
|
424 | + $sth = $this->pdo->prepare("SELECT ".SUBSTRING_FOR_DATE."(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds |
|
425 | 425 | WHERE owner_uid = ?"); |
426 | 426 | $sth->execute([$_SESSION['uid']]); |
427 | 427 | $row = $sth->fetch(); |
@@ -439,8 +439,8 @@ discard block |
||
439 | 439 | |
440 | 440 | if ($num_errors > 0) { |
441 | 441 | $reply['content'] .= "<br/>"; |
442 | - $reply['content'] .= "<a class=\"text-muted\" href=\"#\" onclick=\"CommonDialogs.showFeedsWithErrors()\">" . |
|
443 | - __('Some feeds have update errors (click for details)') . "</a>"; |
|
442 | + $reply['content'] .= "<a class=\"text-muted\" href=\"#\" onclick=\"CommonDialogs.showFeedsWithErrors()\">". |
|
443 | + __('Some feeds have update errors (click for details)')."</a>"; |
|
444 | 444 | } |
445 | 445 | $reply['content'] .= "</span></p></div>"; |
446 | 446 | |
@@ -635,7 +635,7 @@ discard block |
||
635 | 635 | $reply['headlines']['is_cat'] = false; |
636 | 636 | |
637 | 637 | $reply['headlines']['toolbar'] = ''; |
638 | - $reply['headlines']['content'] = "<div class='whiteBox'>". $error . "</div>"; |
|
638 | + $reply['headlines']['content'] = "<div class='whiteBox'>".$error."</div>"; |
|
639 | 639 | |
640 | 640 | $reply['headlines-info'] = array("count" => 0, |
641 | 641 | "unread" => 0, |
@@ -669,7 +669,7 @@ discard block |
||
669 | 669 | print "<fieldset>"; |
670 | 670 | |
671 | 671 | if (get_pref('ENABLE_FEED_CATS')) { |
672 | - print "<label class='inline'>" . __('Place in category:') . "</label> "; |
|
672 | + print "<label class='inline'>".__('Place in category:')."</label> "; |
|
673 | 673 | print_feed_cat_select("cat", false, 'dojoType="fox.form.Select"'); |
674 | 674 | } |
675 | 675 | |
@@ -678,7 +678,7 @@ discard block |
||
678 | 678 | print "</section>"; |
679 | 679 | |
680 | 680 | print '<div id="feedDlg_feedsContainer" style="display : none"> |
681 | - <header>' . __('Available feeds') . '</header> |
|
681 | + <header>' . __('Available feeds').'</header> |
|
682 | 682 | <section> |
683 | 683 | <fieldset> |
684 | 684 | <select id="feedDlg_feedContainerSelect" |
@@ -743,7 +743,7 @@ discard block |
||
743 | 743 | |
744 | 744 | if (DB_TYPE == "pgsql") { |
745 | 745 | print "<fieldset>"; |
746 | - print "<label class='inline'>" . __("Language:") . "</label>"; |
|
746 | + print "<label class='inline'>".__("Language:")."</label>"; |
|
747 | 747 | print_select("search_language", get_pref('DEFAULT_SEARCH_LANGUAGE'), Pref_Feeds::get_ts_languages(), |
748 | 748 | "dojoType='fox.form.Select' title=\"".__('Used for word stemming')."\""); |
749 | 749 | print "</fieldset>"; |
@@ -772,7 +772,7 @@ discard block |
||
772 | 772 | Debug::set_enabled(true); |
773 | 773 | Debug::set_loglevel($_REQUEST["xdebug"]); |
774 | 774 | |
775 | - $feed_id = (int)$_REQUEST["feed_id"]; |
|
775 | + $feed_id = (int) $_REQUEST["feed_id"]; |
|
776 | 776 | @$do_update = $_REQUEST["action"] == "do_update"; |
777 | 777 | $csrf_token = $_REQUEST["csrf_token"]; |
778 | 778 | |
@@ -811,7 +811,7 @@ discard block |
||
811 | 811 | </script> |
812 | 812 | |
813 | 813 | <div class="container"> |
814 | - <h1>Feed Debugger: <?php echo "$feed_id: " . $this->getFeedTitle($feed_id) ?></h1> |
|
814 | + <h1>Feed Debugger: <?php echo "$feed_id: ".$this->getFeedTitle($feed_id) ?></h1> |
|
815 | 815 | <div class="content"> |
816 | 816 | <form method="GET" action=""> |
817 | 817 | <input type="hidden" name="op" value="feeds"> |
@@ -1074,7 +1074,7 @@ discard block |
||
1074 | 1074 | } else if ($n_feed >= 0) { |
1075 | 1075 | |
1076 | 1076 | if ($n_feed != 0) { |
1077 | - $match_part = "feed_id = " . (int)$n_feed; |
|
1077 | + $match_part = "feed_id = ".(int) $n_feed; |
|
1078 | 1078 | } else { |
1079 | 1079 | $match_part = "feed_id IS NULL"; |
1080 | 1080 | } |
@@ -1184,7 +1184,7 @@ discard block |
||
1184 | 1184 | (owner_uid,feed_url,title,cat_id, auth_login,auth_pass,update_method,auth_pass_encrypted) |
1185 | 1185 | VALUES (?, ?, ?, ?, ?, ?, 0, false)"); |
1186 | 1186 | |
1187 | - $sth->execute([$_SESSION['uid'], $url, "[Unknown]", $cat_id, (string)$auth_login, (string)$auth_pass]); |
|
1187 | + $sth->execute([$_SESSION['uid'], $url, "[Unknown]", $cat_id, (string) $auth_login, (string) $auth_pass]); |
|
1188 | 1188 | |
1189 | 1189 | $sth = $pdo->prepare("SELECT id FROM ttrss_feeds WHERE feed_url = ? |
1190 | 1190 | AND owner_uid = ?"); |
@@ -1203,11 +1203,11 @@ discard block |
||
1203 | 1203 | } |
1204 | 1204 | |
1205 | 1205 | static function getIconFile($feed_id) { |
1206 | - return ICONS_DIR . "/$feed_id.ico"; |
|
1206 | + return ICONS_DIR."/$feed_id.ico"; |
|
1207 | 1207 | } |
1208 | 1208 | |
1209 | 1209 | static function feedHasIcon($id) { |
1210 | - return is_file(ICONS_DIR . "/$id.ico") && filesize(ICONS_DIR . "/$id.ico") > 0; |
|
1210 | + return is_file(ICONS_DIR."/$id.ico") && filesize(ICONS_DIR."/$id.ico") > 0; |
|
1211 | 1211 | } |
1212 | 1212 | |
1213 | 1213 | static function getFeedIcon($id) { |
@@ -1237,7 +1237,7 @@ discard block |
||
1237 | 1237 | $icon = self::getIconFile($id); |
1238 | 1238 | |
1239 | 1239 | if ($icon && file_exists($icon)) { |
1240 | - return ICONS_URL . "/" . basename($icon) . "?" . filemtime($icon); |
|
1240 | + return ICONS_URL."/".basename($icon)."?".filemtime($icon); |
|
1241 | 1241 | } |
1242 | 1242 | } |
1243 | 1243 | break; |
@@ -1310,7 +1310,7 @@ discard block |
||
1310 | 1310 | |
1311 | 1311 | $cat_feeds = array(); |
1312 | 1312 | while ($line = $sth->fetch()) { |
1313 | - array_push($cat_feeds, "feed_id = " . (int)$line["id"]); |
|
1313 | + array_push($cat_feeds, "feed_id = ".(int) $line["id"]); |
|
1314 | 1314 | } |
1315 | 1315 | |
1316 | 1316 | if (count($cat_feeds) == 0) return 0; |
@@ -1524,7 +1524,7 @@ discard block |
||
1524 | 1524 | } |
1525 | 1525 | |
1526 | 1526 | if ($limit > 0) { |
1527 | - $limit_query_part = "LIMIT " . (int)$limit; |
|
1527 | + $limit_query_part = "LIMIT ".(int) $limit; |
|
1528 | 1528 | } |
1529 | 1529 | |
1530 | 1530 | $allow_archived = false; |
@@ -1551,7 +1551,7 @@ discard block |
||
1551 | 1551 | implode(",", $subcats).")"; |
1552 | 1552 | |
1553 | 1553 | } else { |
1554 | - $query_strategy_part = "cat_id = " . $pdo->quote($feed); |
|
1554 | + $query_strategy_part = "cat_id = ".$pdo->quote($feed); |
|
1555 | 1555 | } |
1556 | 1556 | |
1557 | 1557 | } else { |
@@ -1561,7 +1561,7 @@ discard block |
||
1561 | 1561 | $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; |
1562 | 1562 | |
1563 | 1563 | } else { |
1564 | - $query_strategy_part = "feed_id = " . $pdo->quote($feed); |
|
1564 | + $query_strategy_part = "feed_id = ".$pdo->quote($feed); |
|
1565 | 1565 | } |
1566 | 1566 | } else if ($feed == 0 && !$cat_view) { // archive virtual feed |
1567 | 1567 | $query_strategy_part = "feed_id IS NULL"; |
@@ -1683,7 +1683,7 @@ discard block |
||
1683 | 1683 | $content_query_part = "content, "; |
1684 | 1684 | |
1685 | 1685 | if ($limit_query_part) { |
1686 | - $offset_query_part = "OFFSET " . (int)$offset; |
|
1686 | + $offset_query_part = "OFFSET ".(int) $offset; |
|
1687 | 1687 | } else { |
1688 | 1688 | $offset_query_part = ""; |
1689 | 1689 | } |
@@ -1772,7 +1772,7 @@ discard block |
||
1772 | 1772 | $res = $pdo->query($query); |
1773 | 1773 | |
1774 | 1774 | if ($row = $res->fetch()) { |
1775 | - $first_id = (int)$row["id"]; |
|
1775 | + $first_id = (int) $row["id"]; |
|
1776 | 1776 | |
1777 | 1777 | if ($offset > 0 && $first_id && $check_first_id && $first_id != $check_first_id) { |
1778 | 1778 | return array(-1, $feed_title, $feed_site_url, $last_error, $last_updated, $search_words, $first_id, $vfeed_query_part != "", $query_error_override); |
@@ -1919,9 +1919,9 @@ discard block |
||
1919 | 1919 | } |
1920 | 1920 | |
1921 | 1921 | function color_of($name) { |
1922 | - $colormap = [ "#1cd7d7","#d91111","#1212d7","#8e16e5","#7b7b7b", |
|
1923 | - "#39f110","#0bbea6","#ec0e0e","#1534f2","#b9e416", |
|
1924 | - "#479af2","#f36b14","#10c7e9","#1e8fe7","#e22727" ]; |
|
1922 | + $colormap = ["#1cd7d7", "#d91111", "#1212d7", "#8e16e5", "#7b7b7b", |
|
1923 | + "#39f110", "#0bbea6", "#ec0e0e", "#1534f2", "#b9e416", |
|
1924 | + "#479af2", "#f36b14", "#10c7e9", "#1e8fe7", "#e22727"]; |
|
1925 | 1925 | |
1926 | 1926 | $sum = 0; |
1927 | 1927 | |
@@ -1985,13 +1985,13 @@ discard block |
||
1985 | 1985 | |
1986 | 1986 | // support schema-less urls |
1987 | 1987 | if (strpos($url, '//') === 0) { |
1988 | - $url = 'https:' . $url; |
|
1988 | + $url = 'https:'.$url; |
|
1989 | 1989 | } |
1990 | 1990 | |
1991 | 1991 | if (strpos($url, '://') === false) { |
1992 | - $url = 'http://' . $url; |
|
1992 | + $url = 'http://'.$url; |
|
1993 | 1993 | } else if (substr($url, 0, 5) == 'feed:') { |
1994 | - $url = 'http:' . substr($url, 5); |
|
1994 | + $url = 'http:'.substr($url, 5); |
|
1995 | 1995 | } |
1996 | 1996 | |
1997 | 1997 | //prepend slash if the URL has no slash in it |
@@ -2041,7 +2041,7 @@ discard block |
||
2041 | 2041 | |
2042 | 2042 | $sth = $pdo->prepare("INSERT INTO ttrss_feed_categories (owner_uid,title,parent_cat,order_id) |
2043 | 2043 | VALUES (?, ?, ?, ?)"); |
2044 | - $sth->execute([$_SESSION['uid'], $feed_cat, $parent_cat_id, (int)$order_id]); |
|
2044 | + $sth->execute([$_SESSION['uid'], $feed_cat, $parent_cat_id, (int) $order_id]); |
|
2045 | 2045 | |
2046 | 2046 | if (!$tr_in_progress) $pdo->commit(); |
2047 | 2047 | |
@@ -2141,7 +2141,7 @@ discard block |
||
2141 | 2141 | $sth->execute([$feed_id]); |
2142 | 2142 | |
2143 | 2143 | } else { |
2144 | - $sth = $pdo->prepare("DELETE FROM ttrss_user_entries |
|
2144 | + $sth = $pdo->prepare("DELETE FROM ttrss_user_entries |
|
2145 | 2145 | USING ttrss_user_entries, ttrss_entries |
2146 | 2146 | WHERE ttrss_entries.id = ref_id AND |
2147 | 2147 | marked = false AND |
@@ -2211,7 +2211,7 @@ discard block |
||
2211 | 2211 | case "title": |
2212 | 2212 | if ($commandpair[1]) { |
2213 | 2213 | array_push($query_keywords, "($not (LOWER(ttrss_entries.title) LIKE ". |
2214 | - $pdo->quote('%' . mb_strtolower($commandpair[1]) . '%') ."))"); |
|
2214 | + $pdo->quote('%'.mb_strtolower($commandpair[1]).'%')."))"); |
|
2215 | 2215 | } else { |
2216 | 2216 | array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%') |
2217 | 2217 | OR UPPER(ttrss_entries.content) $not LIKE UPPER(".$pdo->quote("%$k%")."))"); |
@@ -2221,7 +2221,7 @@ discard block |
||
2221 | 2221 | case "author": |
2222 | 2222 | if ($commandpair[1]) { |
2223 | 2223 | array_push($query_keywords, "($not (LOWER(author) LIKE ". |
2224 | - $pdo->quote('%' . mb_strtolower($commandpair[1]) . '%')."))"); |
|
2224 | + $pdo->quote('%'.mb_strtolower($commandpair[1]).'%')."))"); |
|
2225 | 2225 | } else { |
2226 | 2226 | array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%') |
2227 | 2227 | OR UPPER(ttrss_entries.content) $not LIKE UPPER(".$pdo->quote("%$k%")."))"); |
@@ -2236,7 +2236,7 @@ discard block |
||
2236 | 2236 | array_push($query_keywords, "($not (note IS NULL OR note = ''))"); |
2237 | 2237 | else |
2238 | 2238 | array_push($query_keywords, "($not (LOWER(note) LIKE ". |
2239 | - $pdo->quote('%' . mb_strtolower($commandpair[1]) . '%')."))"); |
|
2239 | + $pdo->quote('%'.mb_strtolower($commandpair[1]).'%')."))"); |
|
2240 | 2240 | } else { |
2241 | 2241 | array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER(".$pdo->quote("%$k%").") |
2242 | 2242 | OR UPPER(ttrss_entries.content) $not LIKE UPPER(".$pdo->quote("%$k%")."))"); |
@@ -2313,7 +2313,7 @@ discard block |
||
2313 | 2313 | |
2314 | 2314 | // if there's no joiners consider this a "simple" search and |
2315 | 2315 | // concatenate everything with &, otherwise don't try to mess with tsquery syntax |
2316 | - if (preg_match("/[&|]/", implode(" " , $search_query_leftover))) { |
|
2316 | + if (preg_match("/[&|]/", implode(" ", $search_query_leftover))) { |
|
2317 | 2317 | $tsquery = $pdo->quote(implode(" ", $search_query_leftover)); |
2318 | 2318 | } else { |
2319 | 2319 | $tsquery = $pdo->quote(implode(" & ", $search_query_leftover)); |
@@ -17,7 +17,9 @@ discard block |
||
17 | 17 | $feed_id, $is_cat, $search, |
18 | 18 | $error, $feed_last_updated) { |
19 | 19 | |
20 | - if ($is_cat) $cat_q = "&is_cat=$is_cat"; |
|
20 | + if ($is_cat) { |
|
21 | + $cat_q = "&is_cat=$is_cat"; |
|
22 | + } |
|
21 | 23 | |
22 | 24 | if ($search) { |
23 | 25 | $search_q = "&q=$search"; |
@@ -48,8 +50,9 @@ discard block |
||
48 | 50 | $reply .= strip_tags($feed_title); |
49 | 51 | } |
50 | 52 | |
51 | - if ($error) |
|
52 | - $reply .= " <i title=\"" . htmlspecialchars($error) . "\" class='material-icons icon-error'>error</i>"; |
|
53 | + if ($error) { |
|
54 | + $reply .= " <i title=\"" . htmlspecialchars($error) . "\" class='material-icons icon-error'>error</i>"; |
|
55 | + } |
|
53 | 56 | |
54 | 57 | $reply .= "</span>"; |
55 | 58 | $reply .= "<span id='feed_current_unread' style='display: none'></span>"; |
@@ -127,8 +130,12 @@ discard block |
||
127 | 130 | $rgba_cache = array(); |
128 | 131 | $topmost_article_ids = array(); |
129 | 132 | |
130 | - if (!$offset) $offset = 0; |
|
131 | - if ($method == "undefined") $method = ""; |
|
133 | + if (!$offset) { |
|
134 | + $offset = 0; |
|
135 | + } |
|
136 | + if ($method == "undefined") { |
|
137 | + $method = ""; |
|
138 | + } |
|
132 | 139 | |
133 | 140 | $method_split = explode(":", $method); |
134 | 141 | |
@@ -274,14 +281,17 @@ discard block |
||
274 | 281 | $label_cache = json_decode($label_cache, true); |
275 | 282 | |
276 | 283 | if ($label_cache) { |
277 | - if ($label_cache["no-labels"] == 1) |
|
278 | - $labels = array(); |
|
279 | - else |
|
280 | - $labels = $label_cache; |
|
284 | + if ($label_cache["no-labels"] == 1) { |
|
285 | + $labels = array(); |
|
286 | + } else { |
|
287 | + $labels = $label_cache; |
|
288 | + } |
|
281 | 289 | } |
282 | 290 | } |
283 | 291 | |
284 | - if (!is_array($labels)) $labels = Article::get_article_labels($id); |
|
292 | + if (!is_array($labels)) { |
|
293 | + $labels = Article::get_article_labels($id); |
|
294 | + } |
|
285 | 295 | |
286 | 296 | $labels_str = "<span class=\"HLLCTR-$id\">"; |
287 | 297 | $labels_str .= Article::format_article_labels($labels); |
@@ -293,7 +303,9 @@ discard block |
||
293 | 303 | array_push($topmost_article_ids, $id); |
294 | 304 | } |
295 | 305 | |
296 | - if (!$line["feed_title"]) $line["feed_title"] = ""; |
|
306 | + if (!$line["feed_title"]) { |
|
307 | + $line["feed_title"] = ""; |
|
308 | + } |
|
297 | 309 | |
298 | 310 | $line["buttons_left"] = ""; |
299 | 311 | foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_LEFT_BUTTON) as $p) { |
@@ -314,10 +326,11 @@ discard block |
||
314 | 326 | |
315 | 327 | $line['content'] = DiskCache::rewriteUrls($line['content']); |
316 | 328 | |
317 | - if ($line['note']) |
|
318 | - $line['note'] = Article::format_article_note($id, $line['note']); |
|
319 | - else |
|
320 | - $line['note'] = ""; |
|
329 | + if ($line['note']) { |
|
330 | + $line['note'] = Article::format_article_note($id, $line['note']); |
|
331 | + } else { |
|
332 | + $line['note'] = ""; |
|
333 | + } |
|
321 | 334 | |
322 | 335 | if (!get_pref("CDM_EXPANDED")) { |
323 | 336 | $line["cdm_excerpt"] = "<span class='collapse'> |
@@ -350,10 +363,11 @@ discard block |
||
350 | 363 | $line['imported'] = T_sprintf("Imported at %s", |
351 | 364 | make_local_datetime($line["date_entered"], false)); |
352 | 365 | |
353 | - if ($line["tag_cache"]) |
|
354 | - $tags = explode(",", $line["tag_cache"]); |
|
355 | - else |
|
356 | - $tags = false; |
|
366 | + if ($line["tag_cache"]) { |
|
367 | + $tags = explode(",", $line["tag_cache"]); |
|
368 | + } else { |
|
369 | + $tags = false; |
|
370 | + } |
|
357 | 371 | |
358 | 372 | $line["tags_str"] = Article::format_tags_string($tags, $id); |
359 | 373 | |
@@ -383,8 +397,9 @@ discard block |
||
383 | 397 | /* we don't need those */ |
384 | 398 | |
385 | 399 | foreach (["date_entered", "guid", "last_published", "last_marked", "tag_cache", "favicon_avg_color", |
386 | - "uuid", "label_cache", "yyiw"] as $k) |
|
387 | - unset($line[$k]); |
|
400 | + "uuid", "label_cache", "yyiw"] as $k) { |
|
401 | + unset($line[$k]); |
|
402 | + } |
|
388 | 403 | |
389 | 404 | array_push($reply['content'], $line); |
390 | 405 | } |
@@ -474,7 +489,9 @@ discard block |
||
474 | 489 | $order_by = $_REQUEST["order_by"]; |
475 | 490 | $check_first_id = $_REQUEST["fid"]; |
476 | 491 | |
477 | - if (is_numeric($feed)) $feed = (int) $feed; |
|
492 | + if (is_numeric($feed)) { |
|
493 | + $feed = (int) $feed; |
|
494 | + } |
|
478 | 495 | |
479 | 496 | /* Feed -5 is a special case: it is used to display auxiliary information |
480 | 497 | * when there's nothing to load - e.g. no stuff in fresh feed */ |
@@ -562,10 +579,11 @@ discard block |
||
562 | 579 | $disable_cache = $ret[3]; |
563 | 580 | $reply['headlines'] = $ret[4]; |
564 | 581 | |
565 | - if (!$next_unread_feed) |
|
566 | - $reply['headlines']['id'] = $feed; |
|
567 | - else |
|
568 | - $reply['headlines']['id'] = $next_unread_feed; |
|
582 | + if (!$next_unread_feed) { |
|
583 | + $reply['headlines']['id'] = $feed; |
|
584 | + } else { |
|
585 | + $reply['headlines']['id'] = $next_unread_feed; |
|
586 | + } |
|
569 | 587 | |
570 | 588 | $reply['headlines']['is_cat'] = (bool) $cat_view; |
571 | 589 | |
@@ -851,7 +869,9 @@ discard block |
||
851 | 869 | |
852 | 870 | static function catchup_feed($feed, $cat_view, $owner_uid = false, $mode = 'all', $search = false) { |
853 | 871 | |
854 | - if (!$owner_uid) $owner_uid = $_SESSION['uid']; |
|
872 | + if (!$owner_uid) { |
|
873 | + $owner_uid = $_SESSION['uid']; |
|
874 | + } |
|
855 | 875 | |
856 | 876 | $pdo = Db::pdo(); |
857 | 877 | |
@@ -1026,7 +1046,9 @@ discard block |
||
1026 | 1046 | |
1027 | 1047 | $pdo = Db::pdo(); |
1028 | 1048 | |
1029 | - if (!$owner_uid) $owner_uid = $_SESSION["uid"]; |
|
1049 | + if (!$owner_uid) { |
|
1050 | + $owner_uid = $_SESSION["uid"]; |
|
1051 | + } |
|
1030 | 1052 | |
1031 | 1053 | if ($unread_only) { |
1032 | 1054 | $unread_qpart = "unread = true"; |
@@ -1142,7 +1164,9 @@ discard block |
||
1142 | 1164 | |
1143 | 1165 | $url = Feeds::fix_url($url); |
1144 | 1166 | |
1145 | - if (!$url || !Feeds::validate_feed_url($url)) return array("code" => 2); |
|
1167 | + if (!$url || !Feeds::validate_feed_url($url)) { |
|
1168 | + return array("code" => 2); |
|
1169 | + } |
|
1146 | 1170 | |
1147 | 1171 | $contents = @fetch_file_contents($url, false, $auth_login, $auth_pass); |
1148 | 1172 | |
@@ -1170,7 +1194,9 @@ discard block |
||
1170 | 1194 | $url = key($feedUrls); |
1171 | 1195 | } |
1172 | 1196 | |
1173 | - if (!$cat_id) $cat_id = null; |
|
1197 | + if (!$cat_id) { |
|
1198 | + $cat_id = null; |
|
1199 | + } |
|
1174 | 1200 | |
1175 | 1201 | $sth = $pdo->prepare("SELECT id FROM ttrss_feeds |
1176 | 1202 | WHERE feed_url = ? AND owner_uid = ?"); |
@@ -1294,13 +1320,17 @@ discard block |
||
1294 | 1320 | |
1295 | 1321 | static function getCategoryUnread($cat, $owner_uid = false) { |
1296 | 1322 | |
1297 | - if (!$owner_uid) $owner_uid = $_SESSION["uid"]; |
|
1323 | + if (!$owner_uid) { |
|
1324 | + $owner_uid = $_SESSION["uid"]; |
|
1325 | + } |
|
1298 | 1326 | |
1299 | 1327 | $pdo = Db::pdo(); |
1300 | 1328 | |
1301 | 1329 | if ($cat >= 0) { |
1302 | 1330 | |
1303 | - if (!$cat) $cat = null; |
|
1331 | + if (!$cat) { |
|
1332 | + $cat = null; |
|
1333 | + } |
|
1304 | 1334 | |
1305 | 1335 | $sth = $pdo->prepare("SELECT id FROM ttrss_feeds |
1306 | 1336 | WHERE (cat_id = :cat OR (:cat IS NULL AND cat_id IS NULL)) |
@@ -1313,7 +1343,9 @@ discard block |
||
1313 | 1343 | array_push($cat_feeds, "feed_id = " . (int)$line["id"]); |
1314 | 1344 | } |
1315 | 1345 | |
1316 | - if (count($cat_feeds) == 0) return 0; |
|
1346 | + if (count($cat_feeds) == 0) { |
|
1347 | + return 0; |
|
1348 | + } |
|
1317 | 1349 | |
1318 | 1350 | $match_part = implode(" OR ", $cat_feeds); |
1319 | 1351 | |
@@ -1348,7 +1380,9 @@ discard block |
||
1348 | 1380 | |
1349 | 1381 | // only accepts real cats (>= 0) |
1350 | 1382 | static function getCategoryChildrenUnread($cat, $owner_uid = false) { |
1351 | - if (!$owner_uid) $owner_uid = $_SESSION["uid"]; |
|
1383 | + if (!$owner_uid) { |
|
1384 | + $owner_uid = $_SESSION["uid"]; |
|
1385 | + } |
|
1352 | 1386 | |
1353 | 1387 | $pdo = Db::pdo(); |
1354 | 1388 | |
@@ -1368,7 +1402,9 @@ discard block |
||
1368 | 1402 | |
1369 | 1403 | static function getGlobalUnread($user_id = false) { |
1370 | 1404 | |
1371 | - if (!$user_id) $user_id = $_SESSION["uid"]; |
|
1405 | + if (!$user_id) { |
|
1406 | + $user_id = $_SESSION["uid"]; |
|
1407 | + } |
|
1372 | 1408 | |
1373 | 1409 | $pdo = Db::pdo(); |
1374 | 1410 | |
@@ -1403,7 +1439,9 @@ discard block |
||
1403 | 1439 | } |
1404 | 1440 | |
1405 | 1441 | static function getLabelUnread($label_id, $owner_uid = false) { |
1406 | - if (!$owner_uid) $owner_uid = $_SESSION["uid"]; |
|
1442 | + if (!$owner_uid) { |
|
1443 | + $owner_uid = $_SESSION["uid"]; |
|
1444 | + } |
|
1407 | 1445 | |
1408 | 1446 | $pdo = Db::pdo(); |
1409 | 1447 | |
@@ -1498,8 +1536,9 @@ discard block |
||
1498 | 1536 | |
1499 | 1537 | $unread = getFeedUnread($feed, $cat_view); |
1500 | 1538 | |
1501 | - if ($cat_view && $feed > 0 && $include_children) |
|
1502 | - $unread += Feeds::getCategoryChildrenUnread($feed); |
|
1539 | + if ($cat_view && $feed > 0 && $include_children) { |
|
1540 | + $unread += Feeds::getCategoryChildrenUnread($feed); |
|
1541 | + } |
|
1503 | 1542 | |
1504 | 1543 | if ($unread > 0) { |
1505 | 1544 | $view_query_part = " unread = true AND "; |
@@ -1611,7 +1650,9 @@ discard block |
||
1611 | 1650 | $allow_archived = true; |
1612 | 1651 | $ignore_vfeed_group = true; |
1613 | 1652 | |
1614 | - if (!$override_order) $override_order = "last_read DESC"; |
|
1653 | + if (!$override_order) { |
|
1654 | + $override_order = "last_read DESC"; |
|
1655 | + } |
|
1615 | 1656 | |
1616 | 1657 | } else if ($feed == -3) { // fresh virtual feed |
1617 | 1658 | $query_strategy_part = "unread = true AND score >= 0"; |
@@ -1722,13 +1763,16 @@ discard block |
||
1722 | 1763 | LEFT JOIN ttrss_feeds ON (feed_id = ttrss_feeds.id)"; |
1723 | 1764 | } |
1724 | 1765 | |
1725 | - if ($vfeed_query_part) $vfeed_query_part .= "favicon_avg_color,"; |
|
1766 | + if ($vfeed_query_part) { |
|
1767 | + $vfeed_query_part .= "favicon_avg_color,"; |
|
1768 | + } |
|
1726 | 1769 | |
1727 | 1770 | $first_id = 0; |
1728 | 1771 | $first_id_query_strategy_part = $query_strategy_part; |
1729 | 1772 | |
1730 | - if ($feed == -3) |
|
1731 | - $first_id_query_strategy_part = "true"; |
|
1773 | + if ($feed == -3) { |
|
1774 | + $first_id_query_strategy_part = "true"; |
|
1775 | + } |
|
1732 | 1776 | |
1733 | 1777 | if (DB_TYPE == "pgsql") { |
1734 | 1778 | $sanity_interval_qpart = "date_entered >= NOW() - INTERVAL '1 hour' AND"; |
@@ -1860,7 +1904,9 @@ discard block |
||
1860 | 1904 | $query_strategy_part ORDER BY $order_by |
1861 | 1905 | $limit_query_part $offset_query_part"; |
1862 | 1906 | |
1863 | - if ($_REQUEST["debug"]) print $query; |
|
1907 | + if ($_REQUEST["debug"]) { |
|
1908 | + print $query; |
|
1909 | + } |
|
1864 | 1910 | |
1865 | 1911 | $res = $pdo->query($query); |
1866 | 1912 | } |
@@ -2010,18 +2056,23 @@ discard block |
||
2010 | 2056 | } |
2011 | 2057 | } |
2012 | 2058 | |
2013 | - if ($url != "http:///") |
|
2014 | - return $url; |
|
2015 | - else |
|
2016 | - return ''; |
|
2059 | + if ($url != "http:///") { |
|
2060 | + return $url; |
|
2061 | + } else { |
|
2062 | + return ''; |
|
2063 | + } |
|
2017 | 2064 | } |
2018 | 2065 | |
2019 | 2066 | static function add_feed_category($feed_cat, $parent_cat_id = false, $order_id = 0) { |
2020 | 2067 | |
2021 | - if (!$feed_cat) return false; |
|
2068 | + if (!$feed_cat) { |
|
2069 | + return false; |
|
2070 | + } |
|
2022 | 2071 | |
2023 | 2072 | $feed_cat = mb_substr($feed_cat, 0, 250); |
2024 | - if (!$parent_cat_id) $parent_cat_id = null; |
|
2073 | + if (!$parent_cat_id) { |
|
2074 | + $parent_cat_id = null; |
|
2075 | + } |
|
2025 | 2076 | |
2026 | 2077 | $pdo = Db::pdo(); |
2027 | 2078 | $tr_in_progress = false; |
@@ -2043,7 +2094,9 @@ discard block |
||
2043 | 2094 | VALUES (?, ?, ?, ?)"); |
2044 | 2095 | $sth->execute([$_SESSION['uid'], $feed_cat, $parent_cat_id, (int)$order_id]); |
2045 | 2096 | |
2046 | - if (!$tr_in_progress) $pdo->commit(); |
|
2097 | + if (!$tr_in_progress) { |
|
2098 | + $pdo->commit(); |
|
2099 | + } |
|
2047 | 2100 | |
2048 | 2101 | return true; |
2049 | 2102 | } |
@@ -2055,7 +2108,9 @@ discard block |
||
2055 | 2108 | |
2056 | 2109 | static function get_feed_access_key($feed_id, $is_cat, $owner_uid = false) { |
2057 | 2110 | |
2058 | - if (!$owner_uid) $owner_uid = $_SESSION["uid"]; |
|
2111 | + if (!$owner_uid) { |
|
2112 | + $owner_uid = $_SESSION["uid"]; |
|
2113 | + } |
|
2059 | 2114 | |
2060 | 2115 | $is_cat = bool_to_sql_bool($is_cat); |
2061 | 2116 | |
@@ -2093,7 +2148,9 @@ discard block |
||
2093 | 2148 | */ |
2094 | 2149 | static function purge_feed($feed_id, $purge_interval) { |
2095 | 2150 | |
2096 | - if (!$purge_interval) $purge_interval = Feeds::feed_purge_interval($feed_id); |
|
2151 | + if (!$purge_interval) { |
|
2152 | + $purge_interval = Feeds::feed_purge_interval($feed_id); |
|
2153 | + } |
|
2097 | 2154 | |
2098 | 2155 | $pdo = Db::pdo(); |
2099 | 2156 | |
@@ -2113,7 +2170,9 @@ discard block |
||
2113 | 2170 | return; |
2114 | 2171 | } |
2115 | 2172 | |
2116 | - if (!$owner_uid) return; |
|
2173 | + if (!$owner_uid) { |
|
2174 | + return; |
|
2175 | + } |
|
2117 | 2176 | |
2118 | 2177 | if (FORCE_ARTICLE_PURGE == 0) { |
2119 | 2178 | $purge_unread = get_pref("PURGE_UNREAD_ARTICLES", |
@@ -2123,10 +2182,11 @@ discard block |
||
2123 | 2182 | $purge_interval = FORCE_ARTICLE_PURGE; |
2124 | 2183 | } |
2125 | 2184 | |
2126 | - if (!$purge_unread) |
|
2127 | - $query_limit = " unread = false AND "; |
|
2128 | - else |
|
2129 | - $query_limit = ""; |
|
2185 | + if (!$purge_unread) { |
|
2186 | + $query_limit = " unread = false AND "; |
|
2187 | + } else { |
|
2188 | + $query_limit = ""; |
|
2189 | + } |
|
2130 | 2190 | |
2131 | 2191 | $purge_interval = (int) $purge_interval; |
2132 | 2192 | |
@@ -2173,8 +2233,10 @@ discard block |
||
2173 | 2233 | $purge_interval = $row["purge_interval"]; |
2174 | 2234 | $owner_uid = $row["owner_uid"]; |
2175 | 2235 | |
2176 | - if ($purge_interval == 0) $purge_interval = get_pref( |
|
2236 | + if ($purge_interval == 0) { |
|
2237 | + $purge_interval = get_pref( |
|
2177 | 2238 | 'PURGE_OLD_DAYS', $owner_uid); |
2239 | + } |
|
2178 | 2240 | |
2179 | 2241 | return $purge_interval; |
2180 | 2242 | |
@@ -2192,10 +2254,11 @@ discard block |
||
2192 | 2254 | |
2193 | 2255 | $pdo = Db::pdo(); |
2194 | 2256 | |
2195 | - if ($search_language) |
|
2196 | - $search_language = $pdo->quote(mb_strtolower($search_language)); |
|
2197 | - else |
|
2198 | - $search_language = $pdo->quote("english"); |
|
2257 | + if ($search_language) { |
|
2258 | + $search_language = $pdo->quote(mb_strtolower($search_language)); |
|
2259 | + } else { |
|
2260 | + $search_language = $pdo->quote("english"); |
|
2261 | + } |
|
2199 | 2262 | |
2200 | 2263 | foreach ($keywords as $k) { |
2201 | 2264 | if (strpos($k, "-") === 0) { |
@@ -2230,56 +2293,68 @@ discard block |
||
2230 | 2293 | break; |
2231 | 2294 | case "note": |
2232 | 2295 | if ($commandpair[1]) { |
2233 | - if ($commandpair[1] == "true") |
|
2234 | - array_push($query_keywords, "($not (note IS NOT NULL AND note != ''))"); |
|
2235 | - else if ($commandpair[1] == "false") |
|
2236 | - array_push($query_keywords, "($not (note IS NULL OR note = ''))"); |
|
2237 | - else |
|
2238 | - array_push($query_keywords, "($not (LOWER(note) LIKE ". |
|
2296 | + if ($commandpair[1] == "true") { |
|
2297 | + array_push($query_keywords, "($not (note IS NOT NULL AND note != ''))"); |
|
2298 | + } else if ($commandpair[1] == "false") { |
|
2299 | + array_push($query_keywords, "($not (note IS NULL OR note = ''))"); |
|
2300 | + } else { |
|
2301 | + array_push($query_keywords, "($not (LOWER(note) LIKE ". |
|
2239 | 2302 | $pdo->quote('%' . mb_strtolower($commandpair[1]) . '%')."))"); |
2303 | + } |
|
2240 | 2304 | } else { |
2241 | 2305 | array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER(".$pdo->quote("%$k%").") |
2242 | 2306 | OR UPPER(ttrss_entries.content) $not LIKE UPPER(".$pdo->quote("%$k%")."))"); |
2243 | - if (!$not) array_push($search_words, $k); |
|
2307 | + if (!$not) { |
|
2308 | + array_push($search_words, $k); |
|
2309 | + } |
|
2244 | 2310 | } |
2245 | 2311 | break; |
2246 | 2312 | case "star": |
2247 | 2313 | |
2248 | 2314 | if ($commandpair[1]) { |
2249 | - if ($commandpair[1] == "true") |
|
2250 | - array_push($query_keywords, "($not (marked = true))"); |
|
2251 | - else |
|
2252 | - array_push($query_keywords, "($not (marked = false))"); |
|
2315 | + if ($commandpair[1] == "true") { |
|
2316 | + array_push($query_keywords, "($not (marked = true))"); |
|
2317 | + } else { |
|
2318 | + array_push($query_keywords, "($not (marked = false))"); |
|
2319 | + } |
|
2253 | 2320 | } else { |
2254 | 2321 | array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER(".$pdo->quote("%$k%").") |
2255 | 2322 | OR UPPER(ttrss_entries.content) $not LIKE UPPER(".$pdo->quote("%$k%")."))"); |
2256 | - if (!$not) array_push($search_words, $k); |
|
2323 | + if (!$not) { |
|
2324 | + array_push($search_words, $k); |
|
2325 | + } |
|
2257 | 2326 | } |
2258 | 2327 | break; |
2259 | 2328 | case "pub": |
2260 | 2329 | if ($commandpair[1]) { |
2261 | - if ($commandpair[1] == "true") |
|
2262 | - array_push($query_keywords, "($not (published = true))"); |
|
2263 | - else |
|
2264 | - array_push($query_keywords, "($not (published = false))"); |
|
2330 | + if ($commandpair[1] == "true") { |
|
2331 | + array_push($query_keywords, "($not (published = true))"); |
|
2332 | + } else { |
|
2333 | + array_push($query_keywords, "($not (published = false))"); |
|
2334 | + } |
|
2265 | 2335 | |
2266 | 2336 | } else { |
2267 | 2337 | array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%') |
2268 | 2338 | OR UPPER(ttrss_entries.content) $not LIKE UPPER(".$pdo->quote("%$k%")."))"); |
2269 | - if (!$not) array_push($search_words, $k); |
|
2339 | + if (!$not) { |
|
2340 | + array_push($search_words, $k); |
|
2341 | + } |
|
2270 | 2342 | } |
2271 | 2343 | break; |
2272 | 2344 | case "unread": |
2273 | 2345 | if ($commandpair[1]) { |
2274 | - if ($commandpair[1] == "true") |
|
2275 | - array_push($query_keywords, "($not (unread = true))"); |
|
2276 | - else |
|
2277 | - array_push($query_keywords, "($not (unread = false))"); |
|
2346 | + if ($commandpair[1] == "true") { |
|
2347 | + array_push($query_keywords, "($not (unread = true))"); |
|
2348 | + } else { |
|
2349 | + array_push($query_keywords, "($not (unread = false))"); |
|
2350 | + } |
|
2278 | 2351 | |
2279 | 2352 | } else { |
2280 | 2353 | array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER(".$pdo->quote("%$k%").") |
2281 | 2354 | OR UPPER(ttrss_entries.content) $not LIKE UPPER(".$pdo->quote("%$k%")."))"); |
2282 | - if (!$not) array_push($search_words, $k); |
|
2355 | + if (!$not) { |
|
2356 | + array_push($search_words, $k); |
|
2357 | + } |
|
2283 | 2358 | } |
2284 | 2359 | break; |
2285 | 2360 | default: |
@@ -2302,7 +2377,9 @@ discard block |
||
2302 | 2377 | OR UPPER(ttrss_entries.content) $not LIKE UPPER(".$pdo->quote("%$k%")."))"); |
2303 | 2378 | } |
2304 | 2379 | |
2305 | - if (!$not) array_push($search_words, $k); |
|
2380 | + if (!$not) { |
|
2381 | + array_push($search_words, $k); |
|
2382 | + } |
|
2306 | 2383 | } |
2307 | 2384 | } |
2308 | 2385 | } |
@@ -52,9 +52,9 @@ |
||
52 | 52 | $this->pdo->query($line); // PDO returns errors as exceptions now |
53 | 53 | } catch (PDOException $e) { |
54 | 54 | if ($html_output) { |
55 | - print "<div class='text-error'>Error: " . $e->getMessage() . "</div>"; |
|
55 | + print "<div class='text-error'>Error: ".$e->getMessage()."</div>"; |
|
56 | 56 | } else { |
57 | - Debug::log("Error: " . $e->getMessage()); |
|
57 | + Debug::log("Error: ".$e->getMessage()); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | $this->pdo->rollBack(); |
@@ -43,10 +43,11 @@ |
||
43 | 43 | foreach ($lines as $line) { |
44 | 44 | if (strpos($line, "--") !== 0 && $line) { |
45 | 45 | |
46 | - if ($html_output) |
|
47 | - print "<pre>$line</pre>"; |
|
48 | - else |
|
49 | - Debug::log("> $line"); |
|
46 | + if ($html_output) { |
|
47 | + print "<pre>$line</pre>"; |
|
48 | + } else { |
|
49 | + Debug::log("> $line"); |
|
50 | + } |
|
50 | 51 | |
51 | 52 | try { |
52 | 53 | $this->pdo->query($line); // PDO returns errors as exceptions now |
@@ -28,7 +28,9 @@ |
||
28 | 28 | if ($login && defined('AUTH_AUTO_CREATE') && AUTH_AUTO_CREATE) { |
29 | 29 | $user_id = $this->find_user_by_login($login); |
30 | 30 | |
31 | - if (!$password) $password = make_password(); |
|
31 | + if (!$password) { |
|
32 | + $password = make_password(); |
|
33 | + } |
|
32 | 34 | |
33 | 35 | if (!$user_id) { |
34 | 36 | $salt = substr(bin2hex(get_random_bytes(125)), 0, 250); |
@@ -143,9 +143,9 @@ discard block |
||
143 | 143 | |
144 | 144 | return $pdo; |
145 | 145 | } catch (Exception $e) { |
146 | - print "<div class='alert alert-danger'>" . $e->getMessage() . "</div>"; |
|
147 | - return null; |
|
148 | - } |
|
146 | + print "<div class='alert alert-danger'>" . $e->getMessage() . "</div>"; |
|
147 | + return null; |
|
148 | + } |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | function make_config($DB_TYPE, $DB_HOST, $DB_USER, $DB_NAME, $DB_PASS, |
@@ -322,13 +322,13 @@ discard block |
||
322 | 322 | array_push($notices, "PHP support for Internationalization Functions is required to handle Internationalized Domain Names."); |
323 | 323 | } |
324 | 324 | |
325 | - if ($DB_TYPE == "mysql" && !function_exists("mysqli_connect")) { |
|
326 | - array_push($notices, "PHP extension for MySQL (mysqli) is missing. This may prevent legacy plugins from working."); |
|
327 | - } |
|
325 | + if ($DB_TYPE == "mysql" && !function_exists("mysqli_connect")) { |
|
326 | + array_push($notices, "PHP extension for MySQL (mysqli) is missing. This may prevent legacy plugins from working."); |
|
327 | + } |
|
328 | 328 | |
329 | - if ($DB_TYPE == "pgsql" && !function_exists("pg_connect")) { |
|
329 | + if ($DB_TYPE == "pgsql" && !function_exists("pg_connect")) { |
|
330 | 330 | array_push($notices, "PHP extension for PostgreSQL is missing. This may prevent legacy plugins from working."); |
331 | - } |
|
331 | + } |
|
332 | 332 | |
333 | 333 | if (count($notices) > 0) { |
334 | 334 | print_notice("Configuration check succeeded with minor problems:"); |
@@ -429,7 +429,7 @@ discard block |
||
429 | 429 | print "<h2>Initializing database...</h2>"; |
430 | 430 | |
431 | 431 | $lines = explode(";", preg_replace("/[\r\n]/", "", |
432 | - file_get_contents("../schema/ttrss_schema_".basename($DB_TYPE).".sql"))); |
|
432 | + file_get_contents("../schema/ttrss_schema_".basename($DB_TYPE).".sql"))); |
|
433 | 433 | |
434 | 434 | foreach ($lines as $line) { |
435 | 435 | if (strpos($line, "--") !== 0 && $line) { |
@@ -438,7 +438,7 @@ discard block |
||
438 | 438 | if (!$res) { |
439 | 439 | print_notice("Query: $line"); |
440 | 440 | print_error("Error: " . implode(", ", $pdo->errorInfo())); |
441 | - } |
|
441 | + } |
|
442 | 442 | } |
443 | 443 | } |
444 | 444 |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | $query = ""; |
12 | 12 | |
13 | 13 | if (!(strpos($filename, "?") === FALSE)) { |
14 | - $query = substr($filename, strpos($filename, "?")+1); |
|
14 | + $query = substr($filename, strpos($filename, "?") + 1); |
|
15 | 15 | $filename = substr($filename, 0, strpos($filename, "?")); |
16 | 16 | } |
17 | 17 | |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | $errors = array(); |
86 | 86 | |
87 | 87 | if (version_compare(PHP_VERSION, '5.6.0', '<')) { |
88 | - array_push($errors, "PHP version 5.6.0 or newer required. You're using " . PHP_VERSION . "."); |
|
88 | + array_push($errors, "PHP version 5.6.0 or newer required. You're using ".PHP_VERSION."."); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | if (!function_exists("curl_init") && !ini_get("allow_url_fopen")) { |
@@ -133,17 +133,17 @@ discard block |
||
133 | 133 | |
134 | 134 | function pdo_connect($host, $user, $pass, $db, $type, $port = false) { |
135 | 135 | |
136 | - $db_port = $port ? ';port=' . $port : ''; |
|
137 | - $db_host = $host ? ';host=' . $host : ''; |
|
136 | + $db_port = $port ? ';port='.$port : ''; |
|
137 | + $db_host = $host ? ';host='.$host : ''; |
|
138 | 138 | |
139 | 139 | try { |
140 | - $pdo = new PDO($type . ':dbname=' . $db . $db_host . $db_port, |
|
140 | + $pdo = new PDO($type.':dbname='.$db.$db_host.$db_port, |
|
141 | 141 | $user, |
142 | 142 | $pass); |
143 | 143 | |
144 | 144 | return $pdo; |
145 | 145 | } catch (Exception $e) { |
146 | - print "<div class='alert alert-danger'>" . $e->getMessage() . "</div>"; |
|
146 | + print "<div class='alert alert-danger'>".$e->getMessage()."</div>"; |
|
147 | 147 | return null; |
148 | 148 | } |
149 | 149 | } |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | } |
190 | 190 | |
191 | 191 | function make_self_url_path() { |
192 | - $url_path = (is_server_https() ? 'https://' : 'http://') . $_SERVER["HTTP_HOST"] . parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH); |
|
192 | + $url_path = (is_server_https() ? 'https://' : 'http://').$_SERVER["HTTP_HOST"].parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH); |
|
193 | 193 | |
194 | 194 | return $url_path; |
195 | 195 | } |
@@ -437,7 +437,7 @@ discard block |
||
437 | 437 | |
438 | 438 | if (!$res) { |
439 | 439 | print_notice("Query: $line"); |
440 | - print_error("Error: " . implode(", ", $pdo->errorInfo())); |
|
440 | + print_error("Error: ".implode(", ", $pdo->errorInfo())); |
|
441 | 441 | } |
442 | 442 | } |
443 | 443 | } |
@@ -17,7 +17,9 @@ |
||
17 | 17 | |
18 | 18 | $timestamp = filemtime($filename); |
19 | 19 | |
20 | - if ($query) $timestamp .= "&$query"; |
|
20 | + if ($query) { |
|
21 | + $timestamp .= "&$query"; |
|
22 | + } |
|
21 | 23 | |
22 | 24 | return "<script type=\"text/javascript\" charset=\"utf-8\" src=\"$filename?$timestamp\"></script>\n"; |
23 | 25 | } |
@@ -87,8 +87,8 @@ discard block |
||
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
90 | - * @SuppressWarnings(unused) |
|
91 | - */ |
|
90 | + * @SuppressWarnings(unused) |
|
91 | + */ |
|
92 | 92 | function sigchld_handler($signal) { |
93 | 93 | $running_jobs = reap_children(); |
94 | 94 | |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | print "Tiny Tiny RSS update daemon.\n\n"; |
143 | 143 | print "Options:\n"; |
144 | 144 | print " --log FILE - log messages to FILE\n"; |
145 | - print " --log-level N - log verbosity level\n"; |
|
145 | + print " --log-level N - log verbosity level\n"; |
|
146 | 146 | print " --tasks N - amount of update tasks to spawn\n"; |
147 | 147 | print " default: " . MAX_JOBS . "\n"; |
148 | 148 | print " --interval N - task spawn interval\n"; |
@@ -151,21 +151,21 @@ discard block |
||
151 | 151 | return; |
152 | 152 | } |
153 | 153 | |
154 | - Debug::set_enabled(true); |
|
155 | - |
|
156 | - if (isset($options["log-level"])) { |
|
157 | - Debug::set_loglevel((int)$options["log-level"]); |
|
158 | - } |
|
159 | - |
|
160 | - if (isset($options["log"])) { |
|
161 | - Debug::set_quiet(isset($options['quiet'])); |
|
162 | - Debug::set_logfile($options["log"]); |
|
163 | - Debug::log("Logging to " . $options["log"]); |
|
164 | - } else { |
|
165 | - if (isset($options['quiet'])) { |
|
166 | - Debug::set_loglevel(Debug::$LOG_DISABLED); |
|
167 | - } |
|
168 | - } |
|
154 | + Debug::set_enabled(true); |
|
155 | + |
|
156 | + if (isset($options["log-level"])) { |
|
157 | + Debug::set_loglevel((int)$options["log-level"]); |
|
158 | + } |
|
159 | + |
|
160 | + if (isset($options["log"])) { |
|
161 | + Debug::set_quiet(isset($options['quiet'])); |
|
162 | + Debug::set_logfile($options["log"]); |
|
163 | + Debug::log("Logging to " . $options["log"]); |
|
164 | + } else { |
|
165 | + if (isset($options['quiet'])) { |
|
166 | + Debug::set_loglevel(Debug::$LOG_DISABLED); |
|
167 | + } |
|
168 | + } |
|
169 | 169 | |
170 | 170 | if (isset($options["tasks"])) { |
171 | 171 | Debug::log("Set to spawn " . $options["tasks"] . " children."); |
@@ -1,9 +1,9 @@ discard block |
||
1 | 1 | #!/usr/bin/env php |
2 | 2 | <?php |
3 | - set_include_path(dirname(__FILE__) ."/include" . PATH_SEPARATOR . |
|
3 | + set_include_path(dirname(__FILE__)."/include".PATH_SEPARATOR. |
|
4 | 4 | get_include_path()); |
5 | 5 | |
6 | - declare(ticks = 1); |
|
6 | + declare(ticks=1); |
|
7 | 7 | chdir(dirname(__FILE__)); |
8 | 8 | |
9 | 9 | define('DISABLE_SESSIONS', true); |
@@ -99,9 +99,9 @@ discard block |
||
99 | 99 | |
100 | 100 | function shutdown($caller_pid) { |
101 | 101 | if ($caller_pid == posix_getpid()) { |
102 | - if (file_exists(LOCK_DIRECTORY . "/update_daemon.lock")) { |
|
102 | + if (file_exists(LOCK_DIRECTORY."/update_daemon.lock")) { |
|
103 | 103 | Debug::log("removing lockfile (master)..."); |
104 | - unlink(LOCK_DIRECTORY . "/update_daemon.lock"); |
|
104 | + unlink(LOCK_DIRECTORY."/update_daemon.lock"); |
|
105 | 105 | } |
106 | 106 | } |
107 | 107 | } |
@@ -109,9 +109,9 @@ discard block |
||
109 | 109 | function task_shutdown() { |
110 | 110 | $pid = posix_getpid(); |
111 | 111 | |
112 | - if (file_exists(LOCK_DIRECTORY . "/update_daemon-$pid.lock")) { |
|
112 | + if (file_exists(LOCK_DIRECTORY."/update_daemon-$pid.lock")) { |
|
113 | 113 | Debug::log("removing lockfile ($pid)..."); |
114 | - unlink(LOCK_DIRECTORY . "/update_daemon-$pid.lock"); |
|
114 | + unlink(LOCK_DIRECTORY."/update_daemon-$pid.lock"); |
|
115 | 115 | } |
116 | 116 | } |
117 | 117 | |
@@ -138,15 +138,15 @@ discard block |
||
138 | 138 | |
139 | 139 | $options = getopt("", $longopts); |
140 | 140 | |
141 | - if (isset($options["help"]) ) { |
|
141 | + if (isset($options["help"])) { |
|
142 | 142 | print "Tiny Tiny RSS update daemon.\n\n"; |
143 | 143 | print "Options:\n"; |
144 | 144 | print " --log FILE - log messages to FILE\n"; |
145 | 145 | print " --log-level N - log verbosity level\n"; |
146 | 146 | print " --tasks N - amount of update tasks to spawn\n"; |
147 | - print " default: " . MAX_JOBS . "\n"; |
|
147 | + print " default: ".MAX_JOBS."\n"; |
|
148 | 148 | print " --interval N - task spawn interval\n"; |
149 | - print " default: " . SPAWN_INTERVAL . " seconds.\n"; |
|
149 | + print " default: ".SPAWN_INTERVAL." seconds.\n"; |
|
150 | 150 | print " --quiet - don't output messages to stdout\n"; |
151 | 151 | return; |
152 | 152 | } |
@@ -154,13 +154,13 @@ discard block |
||
154 | 154 | Debug::set_enabled(true); |
155 | 155 | |
156 | 156 | if (isset($options["log-level"])) { |
157 | - Debug::set_loglevel((int)$options["log-level"]); |
|
157 | + Debug::set_loglevel((int) $options["log-level"]); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | if (isset($options["log"])) { |
161 | 161 | Debug::set_quiet(isset($options['quiet'])); |
162 | 162 | Debug::set_logfile($options["log"]); |
163 | - Debug::log("Logging to " . $options["log"]); |
|
163 | + Debug::log("Logging to ".$options["log"]); |
|
164 | 164 | } else { |
165 | 165 | if (isset($options['quiet'])) { |
166 | 166 | Debug::set_loglevel(Debug::$LOG_DISABLED); |
@@ -168,14 +168,14 @@ discard block |
||
168 | 168 | } |
169 | 169 | |
170 | 170 | if (isset($options["tasks"])) { |
171 | - Debug::log("Set to spawn " . $options["tasks"] . " children."); |
|
171 | + Debug::log("Set to spawn ".$options["tasks"]." children."); |
|
172 | 172 | $max_jobs = $options["tasks"]; |
173 | 173 | } else { |
174 | 174 | $max_jobs = MAX_JOBS; |
175 | 175 | } |
176 | 176 | |
177 | 177 | if (isset($options["interval"])) { |
178 | - Debug::log("Spawn interval: " . $options["interval"] . " seconds."); |
|
178 | + Debug::log("Spawn interval: ".$options["interval"]." seconds."); |
|
179 | 179 | $spawn_interval = $options["interval"]; |
180 | 180 | } else { |
181 | 181 | $spawn_interval = SPAWN_INTERVAL; |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | |
251 | 251 | $my_pid = posix_getpid(); |
252 | 252 | |
253 | - passthru(PHP_EXECUTABLE . " update.php --daemon-loop $quiet $log --task $j --pidlock $my_pid"); |
|
253 | + passthru(PHP_EXECUTABLE." update.php --daemon-loop $quiet $log --task $j --pidlock $my_pid"); |
|
254 | 254 | |
255 | 255 | sleep(1); |
256 | 256 |
@@ -1,15 +1,15 @@ |
||
1 | 1 | <?php |
2 | - set_include_path(dirname(__FILE__) ."/include" . PATH_SEPARATOR . |
|
2 | + set_include_path(dirname(__FILE__)."/include".PATH_SEPARATOR. |
|
3 | 3 | get_include_path()); |
4 | 4 | |
5 | 5 | require_once "functions.php"; |
6 | 6 | |
7 | 7 | $ERRORS[0] = ""; |
8 | 8 | |
9 | - $ERRORS[1] = __("This program requires XmlHttpRequest " . |
|
9 | + $ERRORS[1] = __("This program requires XmlHttpRequest ". |
|
10 | 10 | "to function properly. Your browser doesn't seem to support it."); |
11 | 11 | |
12 | - $ERRORS[2] = __("This program requires cookies " . |
|
12 | + $ERRORS[2] = __("This program requires cookies ". |
|
13 | 13 | "to function properly. Your browser doesn't seem to support them."); |
14 | 14 | |
15 | 15 | $ERRORS[3] = __("Backend sanity check failed."); |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | - set_include_path(dirname(__FILE__) ."/include" . PATH_SEPARATOR . |
|
2 | + set_include_path(dirname(__FILE__)."/include".PATH_SEPARATOR. |
|
3 | 3 | get_include_path()); |
4 | 4 | |
5 | 5 | require_once "autoload.php"; |
@@ -14,11 +14,11 @@ discard block |
||
14 | 14 | |
15 | 15 | $op = $_REQUEST['op']; |
16 | 16 | |
17 | - if ($op == "publish"){ |
|
17 | + if ($op == "publish") { |
|
18 | 18 | $key = $_REQUEST["key"]; |
19 | 19 | $pdo = Db::pdo(); |
20 | 20 | |
21 | - $sth = $pdo->prepare( "SELECT owner_uid |
|
21 | + $sth = $pdo->prepare("SELECT owner_uid |
|
22 | 22 | FROM ttrss_access_keys WHERE |
23 | 23 | access_key = ? AND feed_id = 'OPML:Publish'"); |
24 | 24 | $sth->execute([$key]); |
@@ -10,7 +10,9 @@ |
||
10 | 10 | require_once "db.php"; |
11 | 11 | require_once "db-prefs.php"; |
12 | 12 | |
13 | - if (!init_plugins()) return; |
|
13 | + if (!init_plugins()) { |
|
14 | + return; |
|
15 | + } |
|
14 | 16 | |
15 | 17 | $op = $_REQUEST['op']; |
16 | 18 |
@@ -93,56 +93,56 @@ discard block |
||
93 | 93 | var $maxInclTemplateSize = 1000000; // maximum length of template string when including subtemplates |
94 | 94 | var $template; // Template file data |
95 | 95 | var $varTab; // variables table, array index is variable no |
96 | - // Fields: |
|
97 | - // varName // variable name |
|
98 | - // varValue // variable value |
|
96 | + // Fields: |
|
97 | + // varName // variable name |
|
98 | + // varValue // variable value |
|
99 | 99 | var $varTabCnt; // no of entries used in VarTab |
100 | 100 | var $varNameToNoMap; // maps variable names to variable numbers |
101 | 101 | var $varRefTab; // variable references table |
102 | - // Contains an entry for each variable reference in the template. Ordered by TemplatePos. |
|
103 | - // Fields: |
|
104 | - // varNo // variable no |
|
105 | - // tPosBegin // template position of begin of variable reference |
|
106 | - // tPosEnd // template position of end of variable reference |
|
107 | - // blockNo // block no of the (innermost) block that contains this variable reference |
|
108 | - // blockVarNo // block variable no. Index into BlockInstTab.BlockVarTab |
|
102 | + // Contains an entry for each variable reference in the template. Ordered by TemplatePos. |
|
103 | + // Fields: |
|
104 | + // varNo // variable no |
|
105 | + // tPosBegin // template position of begin of variable reference |
|
106 | + // tPosEnd // template position of end of variable reference |
|
107 | + // blockNo // block no of the (innermost) block that contains this variable reference |
|
108 | + // blockVarNo // block variable no. Index into BlockInstTab.BlockVarTab |
|
109 | 109 | var $varRefTabCnt; // no of entries used in VarRefTab |
110 | 110 | var $blockTab; // Blocks table, array index is block no |
111 | - // Contains an entry for each block in the template. Ordered by TPosBegin. |
|
112 | - // Fields: |
|
113 | - // blockName // block name |
|
114 | - // nextWithSameName; // block no of next block with same name or -1 (blocks are backward linked in relation to template position) |
|
115 | - // tPosBegin // template position of begin of block |
|
116 | - // tPosContentsBegin // template pos of begin of block contents |
|
117 | - // tPosContentsEnd // template pos of end of block contents |
|
118 | - // tPosEnd // template position of end of block |
|
119 | - // nestingLevel // block nesting level |
|
120 | - // parentBlockNo // block no of parent block |
|
121 | - // definitionIsOpen // true while $BeginBlock processed but no $EndBlock |
|
122 | - // instances // number of instances of this block |
|
123 | - // firstBlockInstNo // block instance no of first instance of this block or -1 |
|
124 | - // lastBlockInstNo // block instance no of last instance of this block or -1 |
|
125 | - // currBlockInstNo // current block instance no, used during generation of output file |
|
126 | - // blockVarCnt // no of variables in block |
|
127 | - // blockVarNoToVarNoMap // maps block variable numbers to variable numbers |
|
128 | - // firstVarRefNo // variable reference no of first variable of this block or -1 |
|
111 | + // Contains an entry for each block in the template. Ordered by TPosBegin. |
|
112 | + // Fields: |
|
113 | + // blockName // block name |
|
114 | + // nextWithSameName; // block no of next block with same name or -1 (blocks are backward linked in relation to template position) |
|
115 | + // tPosBegin // template position of begin of block |
|
116 | + // tPosContentsBegin // template pos of begin of block contents |
|
117 | + // tPosContentsEnd // template pos of end of block contents |
|
118 | + // tPosEnd // template position of end of block |
|
119 | + // nestingLevel // block nesting level |
|
120 | + // parentBlockNo // block no of parent block |
|
121 | + // definitionIsOpen // true while $BeginBlock processed but no $EndBlock |
|
122 | + // instances // number of instances of this block |
|
123 | + // firstBlockInstNo // block instance no of first instance of this block or -1 |
|
124 | + // lastBlockInstNo // block instance no of last instance of this block or -1 |
|
125 | + // currBlockInstNo // current block instance no, used during generation of output file |
|
126 | + // blockVarCnt // no of variables in block |
|
127 | + // blockVarNoToVarNoMap // maps block variable numbers to variable numbers |
|
128 | + // firstVarRefNo // variable reference no of first variable of this block or -1 |
|
129 | 129 | var $blockTabCnt; // no of entries used in BlockTab |
130 | 130 | var $blockNameToNoMap; // maps block names to block numbers |
131 | 131 | var $openBlocksTab; |
132 | - // During parsing, this table contains the block numbers of the open parent blocks (nested outer blocks). |
|
133 | - // Indexed by the block nesting level. |
|
132 | + // During parsing, this table contains the block numbers of the open parent blocks (nested outer blocks). |
|
133 | + // Indexed by the block nesting level. |
|
134 | 134 | var $blockInstTab; // block instances table |
135 | - // This table contains an entry for each block instance that has been added. |
|
136 | - // Indexed by BlockInstNo. |
|
137 | - // Fields: |
|
138 | - // blockNo // block number |
|
139 | - // instanceLevel // instance level of this block |
|
140 | - // InstanceLevel is an instance counter per block. |
|
141 | - // (In contrast to blockInstNo, which is an instance counter over the instances of all blocks) |
|
142 | - // parentInstLevel // instance level of parent block |
|
143 | - // nextBlockInstNo // pointer to next instance of this block or -1 |
|
144 | - // Forward chain for instances of same block. |
|
145 | - // blockVarTab // block instance variables |
|
135 | + // This table contains an entry for each block instance that has been added. |
|
136 | + // Indexed by BlockInstNo. |
|
137 | + // Fields: |
|
138 | + // blockNo // block number |
|
139 | + // instanceLevel // instance level of this block |
|
140 | + // InstanceLevel is an instance counter per block. |
|
141 | + // (In contrast to blockInstNo, which is an instance counter over the instances of all blocks) |
|
142 | + // parentInstLevel // instance level of parent block |
|
143 | + // nextBlockInstNo // pointer to next instance of this block or -1 |
|
144 | + // Forward chain for instances of same block. |
|
145 | + // blockVarTab // block instance variables |
|
146 | 146 | var $blockInstTabCnt; // no of entries used in BlockInstTab |
147 | 147 | |
148 | 148 | var $currentNestingLevel; // Current block nesting level during parsing. |
@@ -173,8 +173,8 @@ discard block |
||
173 | 173 | */ |
174 | 174 | function readTemplateFromFile ($fileName) { |
175 | 175 | if (!$this->readFileIntoString($fileName,$s)) { |
176 | - $this->triggerError ("Error while reading template file " . $fileName . "."); |
|
177 | - return false; } |
|
176 | + $this->triggerError ("Error while reading template file " . $fileName . "."); |
|
177 | + return false; } |
|
178 | 178 | if (!$this->setTemplateString($s)) return false; |
179 | 179 | return true; } |
180 | 180 | |
@@ -200,8 +200,8 @@ discard block |
||
200 | 200 | function loadSubtemplate ($subtemplateName, &$s) { |
201 | 201 | $subtemplateFileName = $this->combineFileSystemPath($this->subtemplateBasePath,$subtemplateName); |
202 | 202 | if (!$this->readFileIntoString($subtemplateFileName,$s)) { |
203 | - $this->triggerError ("Error while reading subtemplate file " . $subtemplateFileName . "."); |
|
204 | - return false; } |
|
203 | + $this->triggerError ("Error while reading subtemplate file " . $subtemplateFileName . "."); |
|
204 | + return false; } |
|
205 | 205 | return true; } |
206 | 206 | |
207 | 207 | //--- template parsing ---------------------------------------------------------------------------------------------- |
@@ -271,17 +271,17 @@ discard block |
||
271 | 271 | function parseTemplateCommands() { |
272 | 272 | $p = 0; |
273 | 273 | while (true) { |
274 | - $p0 = strpos($this->template,'<!--',$p); |
|
275 | - if ($p0 === false) break; |
|
276 | - $p = strpos($this->template,'-->',$p0); |
|
277 | - if ($p === false) { |
|
278 | - $this->triggerError ("Invalid HTML comment in template at offset $p0."); |
|
279 | - return false; } |
|
280 | - $p += 3; |
|
281 | - $cmdL = substr($this->template,$p0+4,$p-$p0-7); |
|
282 | - if (!$this->processTemplateCommand($cmdL,$p0,$p,$resumeFromStart)) |
|
283 | - return false; |
|
284 | - if ($resumeFromStart) $p = $p0; } |
|
274 | + $p0 = strpos($this->template,'<!--',$p); |
|
275 | + if ($p0 === false) break; |
|
276 | + $p = strpos($this->template,'-->',$p0); |
|
277 | + if ($p === false) { |
|
278 | + $this->triggerError ("Invalid HTML comment in template at offset $p0."); |
|
279 | + return false; } |
|
280 | + $p += 3; |
|
281 | + $cmdL = substr($this->template,$p0+4,$p-$p0-7); |
|
282 | + if (!$this->processTemplateCommand($cmdL,$p0,$p,$resumeFromStart)) |
|
283 | + return false; |
|
284 | + if ($resumeFromStart) $p = $p0; } |
|
285 | 285 | return true; } |
286 | 286 | |
287 | 287 | /** |
@@ -295,24 +295,24 @@ discard block |
||
295 | 295 | if (!$this->parseWord($cmdL,$p,$cmd)) return true; |
296 | 296 | $parms = substr($cmdL,$p); |
297 | 297 | switch (strtoupper($cmd)) { |
298 | - case '$BEGINBLOCK': |
|
299 | - if (!$this->processBeginBlockCmd($parms,$cmdTPosBegin,$cmdTPosEnd)) |
|
300 | - return false; |
|
301 | - break; |
|
302 | - case '$ENDBLOCK': |
|
303 | - if (!$this->processEndBlockCmd($parms,$cmdTPosBegin,$cmdTPosEnd)) |
|
304 | - return false; |
|
305 | - break; |
|
306 | - case '$INCLUDE': |
|
307 | - if (!$this->processincludeCmd($parms,$cmdTPosBegin,$cmdTPosEnd)) |
|
308 | - return false; |
|
309 | - $resumeFromStart = true; |
|
310 | - break; |
|
311 | - default: |
|
312 | - if ($cmd{0} == '$' && !(strlen($cmd) >= 2 && $cmd{1} == '{')) { |
|
313 | - $this->triggerError ("Unknown command \"$cmd\" in template at offset $cmdTPosBegin."); |
|
314 | - return false; }} |
|
315 | - return true; } |
|
298 | + case '$BEGINBLOCK': |
|
299 | + if (!$this->processBeginBlockCmd($parms,$cmdTPosBegin,$cmdTPosEnd)) |
|
300 | + return false; |
|
301 | + break; |
|
302 | + case '$ENDBLOCK': |
|
303 | + if (!$this->processEndBlockCmd($parms,$cmdTPosBegin,$cmdTPosEnd)) |
|
304 | + return false; |
|
305 | + break; |
|
306 | + case '$INCLUDE': |
|
307 | + if (!$this->processincludeCmd($parms,$cmdTPosBegin,$cmdTPosEnd)) |
|
308 | + return false; |
|
309 | + $resumeFromStart = true; |
|
310 | + break; |
|
311 | + default: |
|
312 | + if ($cmd{0} == '$' && !(strlen($cmd) >= 2 && $cmd{1} == '{')) { |
|
313 | + $this->triggerError ("Unknown command \"$cmd\" in template at offset $cmdTPosBegin."); |
|
314 | + return false; }} |
|
315 | + return true; } |
|
316 | 316 | |
317 | 317 | /** |
318 | 318 | * Processes the $BeginBlock command. |
@@ -322,11 +322,11 @@ discard block |
||
322 | 322 | function processBeginBlockCmd ($parms, $cmdTPosBegin, $cmdTPosEnd) { |
323 | 323 | $p = 0; |
324 | 324 | if (!$this->parseWord($parms,$p,$blockName)) { |
325 | - $this->triggerError ("Missing block name in \$BeginBlock command in template at offset $cmdTPosBegin."); |
|
326 | - return false; } |
|
325 | + $this->triggerError ("Missing block name in \$BeginBlock command in template at offset $cmdTPosBegin."); |
|
326 | + return false; } |
|
327 | 327 | if (trim(substr($parms,$p)) != '') { |
328 | - $this->triggerError ("Extra parameter in \$BeginBlock command in template at offset $cmdTPosBegin."); |
|
329 | - return false; } |
|
328 | + $this->triggerError ("Extra parameter in \$BeginBlock command in template at offset $cmdTPosBegin."); |
|
329 | + return false; } |
|
330 | 330 | $this->registerBlock ($blockName, $blockNo); |
331 | 331 | $btr =& $this->blockTab[$blockNo]; |
332 | 332 | $btr['tPosBegin'] = $cmdTPosBegin; |
@@ -336,8 +336,8 @@ discard block |
||
336 | 336 | $this->openBlocksTab[$this->currentNestingLevel] = $blockNo; |
337 | 337 | $this->currentNestingLevel += 1; |
338 | 338 | if ($this->currentNestingLevel > $this->maxNestingLevel) { |
339 | - $this->triggerError ("Block nesting overflow in template at offset $cmdTPosBegin."); |
|
340 | - return false; } |
|
339 | + $this->triggerError ("Block nesting overflow in template at offset $cmdTPosBegin."); |
|
340 | + return false; } |
|
341 | 341 | return true; } |
342 | 342 | |
343 | 343 | /** |
@@ -348,22 +348,22 @@ discard block |
||
348 | 348 | function processEndBlockCmd ($parms, $cmdTPosBegin, $cmdTPosEnd) { |
349 | 349 | $p = 0; |
350 | 350 | if (!$this->parseWord($parms,$p,$blockName)) { |
351 | - $this->triggerError ("Missing block name in \$EndBlock command in template at offset $cmdTPosBegin."); |
|
352 | - return false; } |
|
351 | + $this->triggerError ("Missing block name in \$EndBlock command in template at offset $cmdTPosBegin."); |
|
352 | + return false; } |
|
353 | 353 | if (trim(substr($parms,$p)) != '') { |
354 | - $this->triggerError ("Extra parameter in \$EndBlock command in template at offset $cmdTPosBegin."); |
|
355 | - return false; } |
|
354 | + $this->triggerError ("Extra parameter in \$EndBlock command in template at offset $cmdTPosBegin."); |
|
355 | + return false; } |
|
356 | 356 | if (!$this->lookupBlockName($blockName,$blockNo)) { |
357 | - $this->triggerError ("Undefined block name \"$blockName\" in \$EndBlock command in template at offset $cmdTPosBegin."); |
|
358 | - return false; } |
|
357 | + $this->triggerError ("Undefined block name \"$blockName\" in \$EndBlock command in template at offset $cmdTPosBegin."); |
|
358 | + return false; } |
|
359 | 359 | $this->currentNestingLevel -= 1; |
360 | 360 | $btr =& $this->blockTab[$blockNo]; |
361 | 361 | if (!$btr['definitionIsOpen']) { |
362 | - $this->triggerError ("Multiple \$EndBlock command for block \"$blockName\" in template at offset $cmdTPosBegin."); |
|
363 | - return false; } |
|
362 | + $this->triggerError ("Multiple \$EndBlock command for block \"$blockName\" in template at offset $cmdTPosBegin."); |
|
363 | + return false; } |
|
364 | 364 | if ($btr['nestingLevel'] != $this->currentNestingLevel) { |
365 | - $this->triggerError ("Block nesting level mismatch at \$EndBlock command for block \"$blockName\" in template at offset $cmdTPosBegin."); |
|
366 | - return false; } |
|
365 | + $this->triggerError ("Block nesting level mismatch at \$EndBlock command for block \"$blockName\" in template at offset $cmdTPosBegin."); |
|
366 | + return false; } |
|
367 | 367 | $btr['tPosContentsEnd'] = $cmdTPosBegin; |
368 | 368 | $btr['tPosEnd'] = $cmdTPosEnd; |
369 | 369 | $btr['definitionIsOpen'] = false; |
@@ -378,7 +378,7 @@ discard block |
||
378 | 378 | $btr = array(); |
379 | 379 | $btr['blockName'] = $blockName; |
380 | 380 | if (!$this->lookupBlockName($blockName,$btr['nextWithSameName'])) |
381 | - $btr['nextWithSameName'] = -1; |
|
381 | + $btr['nextWithSameName'] = -1; |
|
382 | 382 | $btr['definitionIsOpen'] = true; |
383 | 383 | $btr['instances'] = 0; |
384 | 384 | $btr['firstBlockInstNo'] = -1; |
@@ -395,13 +395,13 @@ discard block |
||
395 | 395 | */ |
396 | 396 | function checkBlockDefinitionsComplete() { |
397 | 397 | for ($blockNo=0; $blockNo < $this->blockTabCnt; $blockNo++) { |
398 | - $btr =& $this->blockTab[$blockNo]; |
|
399 | - if ($btr['definitionIsOpen']) { |
|
400 | - $this->triggerError ("Missing \$EndBlock command in template for block " . $btr['blockName'] . "."); |
|
401 | - return false; }} |
|
398 | + $btr =& $this->blockTab[$blockNo]; |
|
399 | + if ($btr['definitionIsOpen']) { |
|
400 | + $this->triggerError ("Missing \$EndBlock command in template for block " . $btr['blockName'] . "."); |
|
401 | + return false; }} |
|
402 | 402 | if ($this->currentNestingLevel != 0) { |
403 | - $this->triggerError ("Block nesting level error at end of template."); |
|
404 | - return false; } |
|
403 | + $this->triggerError ("Block nesting level error at end of template."); |
|
404 | + return false; } |
|
405 | 405 | return true; } |
406 | 406 | |
407 | 407 | /** |
@@ -412,11 +412,11 @@ discard block |
||
412 | 412 | function processIncludeCmd ($parms, $cmdTPosBegin, $cmdTPosEnd) { |
413 | 413 | $p = 0; |
414 | 414 | if (!$this->parseWordOrQuotedString($parms,$p,$subtemplateName)) { |
415 | - $this->triggerError ("Missing or invalid subtemplate name in \$Include command in template at offset $cmdTPosBegin."); |
|
416 | - return false; } |
|
415 | + $this->triggerError ("Missing or invalid subtemplate name in \$Include command in template at offset $cmdTPosBegin."); |
|
416 | + return false; } |
|
417 | 417 | if (trim(substr($parms,$p)) != '') { |
418 | - $this->triggerError ("Extra parameter in \$include command in template at offset $cmdTPosBegin."); |
|
419 | - return false; } |
|
418 | + $this->triggerError ("Extra parameter in \$include command in template at offset $cmdTPosBegin."); |
|
419 | + return false; } |
|
420 | 420 | return $this->insertSubtemplate($subtemplateName,$cmdTPosBegin,$cmdTPosEnd); } |
421 | 421 | |
422 | 422 | /** |
@@ -426,8 +426,8 @@ discard block |
||
426 | 426 | */ |
427 | 427 | function insertSubtemplate ($subtemplateName, $tPos1, $tPos2) { |
428 | 428 | if (strlen($this->template) > $this->maxInclTemplateSize) { |
429 | - $this->triggerError ("Subtemplate include aborted because the internal template string is longer than $this->maxInclTemplateSize characters."); |
|
430 | - return false; } |
|
429 | + $this->triggerError ("Subtemplate include aborted because the internal template string is longer than $this->maxInclTemplateSize characters."); |
|
430 | + return false; } |
|
431 | 431 | if (!$this->loadSubtemplate($subtemplateName,$subtemplate)) return false; |
432 | 432 | // (Copying the template to insert a subtemplate is a bit slow. In a future implementation of MiniTemplator, |
433 | 433 | // a table could be used that contains references to the string fragments.) |
@@ -442,19 +442,19 @@ discard block |
||
442 | 442 | function parseTemplateVariables() { |
443 | 443 | $p = 0; |
444 | 444 | while (true) { |
445 | - $p = strpos($this->template, '${', $p); |
|
446 | - if ($p === false) break; |
|
447 | - $p0 = $p; |
|
448 | - $p = strpos($this->template, '}', $p); |
|
449 | - if ($p === false) { |
|
450 | - $this->triggerError ("Invalid variable reference in template at offset $p0."); |
|
451 | - return false; } |
|
452 | - $p += 1; |
|
453 | - $varName = trim(substr($this->template, $p0+2, $p-$p0-3)); |
|
454 | - if (strlen($varName) == 0) { |
|
455 | - $this->triggerError ("Empty variable name in template at offset $p0."); |
|
456 | - return false; } |
|
457 | - $this->registerVariableReference ($varName, $p0, $p); } |
|
445 | + $p = strpos($this->template, '${', $p); |
|
446 | + if ($p === false) break; |
|
447 | + $p0 = $p; |
|
448 | + $p = strpos($this->template, '}', $p); |
|
449 | + if ($p === false) { |
|
450 | + $this->triggerError ("Invalid variable reference in template at offset $p0."); |
|
451 | + return false; } |
|
452 | + $p += 1; |
|
453 | + $varName = trim(substr($this->template, $p0+2, $p-$p0-3)); |
|
454 | + if (strlen($varName) == 0) { |
|
455 | + $this->triggerError ("Empty variable name in template at offset $p0."); |
|
456 | + return false; } |
|
457 | + $this->registerVariableReference ($varName, $p0, $p); } |
|
458 | 458 | return true; } |
459 | 459 | |
460 | 460 | /** |
@@ -462,7 +462,7 @@ discard block |
||
462 | 462 | */ |
463 | 463 | function registerVariableReference ($varName, $tPosBegin, $tPosEnd) { |
464 | 464 | if (!$this->lookupVariableName($varName,$varNo)) |
465 | - $this->registerVariable($varName,$varNo); |
|
465 | + $this->registerVariable($varName,$varNo); |
|
466 | 466 | $varRefNo = $this->varRefTabCnt++; |
467 | 467 | $vrtr =& $this->varRefTab[$varRefNo]; |
468 | 468 | $vrtr = array(); |
@@ -490,27 +490,27 @@ discard block |
||
490 | 490 | $activeBlockNo = 0; |
491 | 491 | $nextBlockNo = 1; |
492 | 492 | while ($varRefNo < $this->varRefTabCnt) { |
493 | - $vrtr =& $this->varRefTab[$varRefNo]; |
|
494 | - $varRefTPos = $vrtr['tPosBegin']; |
|
495 | - $varNo = $vrtr['varNo']; |
|
496 | - if ($varRefTPos >= $this->blockTab[$activeBlockNo]['tPosEnd']) { |
|
497 | - $activeBlockNo = $this->blockTab[$activeBlockNo]['parentBlockNo']; |
|
498 | - continue; } |
|
499 | - if ($nextBlockNo < $this->blockTabCnt) { |
|
500 | - if ($varRefTPos >= $this->blockTab[$nextBlockNo]['tPosBegin']) { |
|
501 | - $activeBlockNo = $nextBlockNo; |
|
502 | - $nextBlockNo += 1; |
|
503 | - continue; }} |
|
504 | - $btr =& $this->blockTab[$activeBlockNo]; |
|
505 | - if ($varRefTPos < $btr['tPosBegin']) |
|
506 | - $this->programLogicError(1); |
|
507 | - $blockVarNo = $btr['blockVarCnt']++; |
|
508 | - $btr['blockVarNoToVarNoMap'][$blockVarNo] = $varNo; |
|
509 | - if ($btr['firstVarRefNo'] == -1) |
|
510 | - $btr['firstVarRefNo'] = $varRefNo; |
|
511 | - $vrtr['blockNo'] = $activeBlockNo; |
|
512 | - $vrtr['blockVarNo'] = $blockVarNo; |
|
513 | - $varRefNo += 1; }} |
|
493 | + $vrtr =& $this->varRefTab[$varRefNo]; |
|
494 | + $varRefTPos = $vrtr['tPosBegin']; |
|
495 | + $varNo = $vrtr['varNo']; |
|
496 | + if ($varRefTPos >= $this->blockTab[$activeBlockNo]['tPosEnd']) { |
|
497 | + $activeBlockNo = $this->blockTab[$activeBlockNo]['parentBlockNo']; |
|
498 | + continue; } |
|
499 | + if ($nextBlockNo < $this->blockTabCnt) { |
|
500 | + if ($varRefTPos >= $this->blockTab[$nextBlockNo]['tPosBegin']) { |
|
501 | + $activeBlockNo = $nextBlockNo; |
|
502 | + $nextBlockNo += 1; |
|
503 | + continue; }} |
|
504 | + $btr =& $this->blockTab[$activeBlockNo]; |
|
505 | + if ($varRefTPos < $btr['tPosBegin']) |
|
506 | + $this->programLogicError(1); |
|
507 | + $blockVarNo = $btr['blockVarCnt']++; |
|
508 | + $btr['blockVarNoToVarNoMap'][$blockVarNo] = $varNo; |
|
509 | + if ($btr['firstVarRefNo'] == -1) |
|
510 | + $btr['firstVarRefNo'] = $varRefNo; |
|
511 | + $vrtr['blockNo'] = $activeBlockNo; |
|
512 | + $vrtr['blockVarNo'] = $blockVarNo; |
|
513 | + $varRefNo += 1; }} |
|
514 | 514 | |
515 | 515 | //--- build up (template variables and blocks) ---------------------------------------------------------------------- |
516 | 516 | |
@@ -524,12 +524,12 @@ discard block |
||
524 | 524 | */ |
525 | 525 | function reset() { |
526 | 526 | for ($varNo=0; $varNo<$this->varTabCnt; $varNo++) |
527 | - $this->varTab[$varNo]['varValue'] = ''; |
|
527 | + $this->varTab[$varNo]['varValue'] = ''; |
|
528 | 528 | for ($blockNo=0; $blockNo<$this->blockTabCnt; $blockNo++) { |
529 | - $btr =& $this->blockTab[$blockNo]; |
|
530 | - $btr['instances'] = 0; |
|
531 | - $btr['firstBlockInstNo'] = -1; |
|
532 | - $btr['lastBlockInstNo'] = -1; } |
|
529 | + $btr =& $this->blockTab[$blockNo]; |
|
530 | + $btr['instances'] = 0; |
|
531 | + $btr['firstBlockInstNo'] = -1; |
|
532 | + $btr['lastBlockInstNo'] = -1; } |
|
533 | 533 | $this->blockInstTab = array(); |
534 | 534 | $this->blockInstTabCnt = 0; } |
535 | 535 | |
@@ -551,9 +551,9 @@ discard block |
||
551 | 551 | function setVariable ($variableName, $variableValue, $isOptional=false) { |
552 | 552 | if (!$this->templateValid) {$this->triggerError ("Template not valid."); return false; } |
553 | 553 | if (!$this->lookupVariableName($variableName,$varNo)) { |
554 | - if ($isOptional) return true; |
|
555 | - $this->triggerError ("Variable \"$variableName\" not defined in template."); |
|
556 | - return false; } |
|
554 | + if ($isOptional) return true; |
|
555 | + $this->triggerError ("Variable \"$variableName\" not defined in template."); |
|
556 | + return false; } |
|
557 | 557 | $this->varTab[$varNo]['varValue'] = $variableValue; |
558 | 558 | return true; } |
559 | 559 | |
@@ -605,11 +605,11 @@ discard block |
||
605 | 605 | function addBlock($blockName) { |
606 | 606 | if (!$this->templateValid) {$this->triggerError ("Template not valid."); return false; } |
607 | 607 | if (!$this->lookupBlockName($blockName,$blockNo)) { |
608 | - $this->triggerError ("Block \"$blockName\" not defined in template."); |
|
609 | - return false; } |
|
608 | + $this->triggerError ("Block \"$blockName\" not defined in template."); |
|
609 | + return false; } |
|
610 | 610 | while ($blockNo != -1) { |
611 | - $this->addBlockByNo($blockNo); |
|
612 | - $blockNo = $this->blockTab[$blockNo]['nextWithSameName']; } |
|
611 | + $this->addBlockByNo($blockNo); |
|
612 | + $blockNo = $this->blockTab[$blockNo]['nextWithSameName']; } |
|
613 | 613 | return true; } |
614 | 614 | |
615 | 615 | /** |
@@ -620,25 +620,25 @@ discard block |
||
620 | 620 | $this->registerBlockInstance ($blockInstNo); |
621 | 621 | $bitr =& $this->blockInstTab[$blockInstNo]; |
622 | 622 | if ($btr['firstBlockInstNo'] == -1) |
623 | - $btr['firstBlockInstNo'] = $blockInstNo; |
|
623 | + $btr['firstBlockInstNo'] = $blockInstNo; |
|
624 | 624 | if ($btr['lastBlockInstNo'] != -1) |
625 | - $this->blockInstTab[$btr['lastBlockInstNo']]['nextBlockInstNo'] = $blockInstNo; |
|
626 | - // set forward pointer of chain |
|
625 | + $this->blockInstTab[$btr['lastBlockInstNo']]['nextBlockInstNo'] = $blockInstNo; |
|
626 | + // set forward pointer of chain |
|
627 | 627 | $btr['lastBlockInstNo'] = $blockInstNo; |
628 | 628 | $parentBlockNo = $btr['parentBlockNo']; |
629 | 629 | $blockVarCnt = $btr['blockVarCnt']; |
630 | 630 | $bitr['blockNo'] = $blockNo; |
631 | 631 | $bitr['instanceLevel'] = $btr['instances']++; |
632 | 632 | if ($parentBlockNo == -1) |
633 | - $bitr['parentInstLevel'] = -1; |
|
634 | - else |
|
635 | - $bitr['parentInstLevel'] = $this->blockTab[$parentBlockNo]['instances']; |
|
633 | + $bitr['parentInstLevel'] = -1; |
|
634 | + else |
|
635 | + $bitr['parentInstLevel'] = $this->blockTab[$parentBlockNo]['instances']; |
|
636 | 636 | $bitr['nextBlockInstNo'] = -1; |
637 | 637 | $bitr['blockVarTab'] = array(); |
638 | 638 | // copy instance variables for this block |
639 | 639 | for ($blockVarNo=0; $blockVarNo<$blockVarCnt; $blockVarNo++) { |
640 | - $varNo = $btr['blockVarNoToVarNoMap'][$blockVarNo]; |
|
641 | - $bitr['blockVarTab'][$blockVarNo] = $this->varTab[$varNo]['varValue']; }} |
|
640 | + $varNo = $btr['blockVarNoToVarNoMap'][$blockVarNo]; |
|
641 | + $bitr['blockVarTab'][$blockVarNo] = $this->varTab[$varNo]['varValue']; }} |
|
642 | 642 | |
643 | 643 | /** |
644 | 644 | * @access private |
@@ -706,10 +706,10 @@ discard block |
||
706 | 706 | function generateOutputPage() { |
707 | 707 | if (!$this->templateValid) {$this->triggerError ("Template not valid."); return false; } |
708 | 708 | if ($this->blockTab[0]['instances'] == 0) |
709 | - $this->addBlockByNo (0); // add main block |
|
709 | + $this->addBlockByNo (0); // add main block |
|
710 | 710 | for ($blockNo=0; $blockNo < $this->blockTabCnt; $blockNo++) { |
711 | - $btr =& $this->blockTab[$blockNo]; |
|
712 | - $btr['currBlockInstNo'] = $btr['firstBlockInstNo']; } |
|
711 | + $btr =& $this->blockTab[$blockNo]; |
|
712 | + $btr['currBlockInstNo'] = $btr['firstBlockInstNo']; } |
|
713 | 713 | $this->outputError = false; |
714 | 714 | $this->writeBlockInstances (0, -1); |
715 | 715 | if ($this->outputError) return false; |
@@ -724,14 +724,14 @@ discard block |
||
724 | 724 | function writeBlockInstances ($blockNo, $parentInstLevel) { |
725 | 725 | $btr =& $this->blockTab[$blockNo]; |
726 | 726 | while (!$this->outputError) { |
727 | - $blockInstNo = $btr['currBlockInstNo']; |
|
728 | - if ($blockInstNo == -1) break; |
|
729 | - $bitr =& $this->blockInstTab[$blockInstNo]; |
|
730 | - if ($bitr['parentInstLevel'] < $parentInstLevel) |
|
731 | - $this->programLogicError (2); |
|
732 | - if ($bitr['parentInstLevel'] > $parentInstLevel) break; |
|
733 | - $this->writeBlockInstance ($blockInstNo); |
|
734 | - $btr['currBlockInstNo'] = $bitr['nextBlockInstNo']; }} |
|
727 | + $blockInstNo = $btr['currBlockInstNo']; |
|
728 | + if ($blockInstNo == -1) break; |
|
729 | + $bitr =& $this->blockInstTab[$blockInstNo]; |
|
730 | + if ($bitr['parentInstLevel'] < $parentInstLevel) |
|
731 | + $this->programLogicError (2); |
|
732 | + if ($bitr['parentInstLevel'] > $parentInstLevel) break; |
|
733 | + $this->writeBlockInstance ($blockInstNo); |
|
734 | + $btr['currBlockInstNo'] = $bitr['nextBlockInstNo']; }} |
|
735 | 735 | |
736 | 736 | /** |
737 | 737 | * @access private |
@@ -744,46 +744,46 @@ discard block |
||
744 | 744 | $subBlockNo = $blockNo + 1; |
745 | 745 | $varRefNo = $btr['firstVarRefNo']; |
746 | 746 | while (!$this->outputError) { |
747 | - $tPos2 = $btr['tPosContentsEnd']; |
|
748 | - $kind = 0; // assume end-of-block |
|
749 | - if ($varRefNo != -1 && $varRefNo < $this->varRefTabCnt) { // check for variable reference |
|
750 | - $vrtr =& $this->varRefTab[$varRefNo]; |
|
751 | - if ($vrtr['tPosBegin'] < $tPos) { |
|
752 | - $varRefNo += 1; |
|
753 | - continue; } |
|
754 | - if ($vrtr['tPosBegin'] < $tPos2) { |
|
755 | - $tPos2 = $vrtr['tPosBegin']; |
|
756 | - $kind = 1; }} |
|
757 | - if ($subBlockNo < $this->blockTabCnt) { // check for subblock |
|
758 | - $subBtr =& $this->blockTab[$subBlockNo]; |
|
759 | - if ($subBtr['tPosBegin'] < $tPos) { |
|
760 | - $subBlockNo += 1; |
|
761 | - continue; } |
|
762 | - if ($subBtr['tPosBegin'] < $tPos2) { |
|
763 | - $tPos2 = $subBtr['tPosBegin']; |
|
764 | - $kind = 2; }} |
|
765 | - if ($tPos2 > $tPos) |
|
766 | - $this->writeString (substr($this->template,$tPos,$tPos2-$tPos)); |
|
767 | - switch ($kind) { |
|
768 | - case 0: // end of block |
|
769 | - return; |
|
770 | - case 1: // variable |
|
771 | - $vrtr =& $this->varRefTab[$varRefNo]; |
|
772 | - if ($vrtr['blockNo'] != $blockNo) |
|
773 | - $this->programLogicError (4); |
|
774 | - $variableValue = $bitr['blockVarTab'][$vrtr['blockVarNo']]; |
|
775 | - $this->writeString ($variableValue); |
|
776 | - $tPos = $vrtr['tPosEnd']; |
|
777 | - $varRefNo += 1; |
|
778 | - break; |
|
779 | - case 2: // sub block |
|
780 | - $subBtr =& $this->blockTab[$subBlockNo]; |
|
781 | - if ($subBtr['parentBlockNo'] != $blockNo) |
|
782 | - $this->programLogicError (3); |
|
783 | - $this->writeBlockInstances ($subBlockNo, $bitr['instanceLevel']); // recursive call |
|
784 | - $tPos = $subBtr['tPosEnd']; |
|
785 | - $subBlockNo += 1; |
|
786 | - break; }}} |
|
747 | + $tPos2 = $btr['tPosContentsEnd']; |
|
748 | + $kind = 0; // assume end-of-block |
|
749 | + if ($varRefNo != -1 && $varRefNo < $this->varRefTabCnt) { // check for variable reference |
|
750 | + $vrtr =& $this->varRefTab[$varRefNo]; |
|
751 | + if ($vrtr['tPosBegin'] < $tPos) { |
|
752 | + $varRefNo += 1; |
|
753 | + continue; } |
|
754 | + if ($vrtr['tPosBegin'] < $tPos2) { |
|
755 | + $tPos2 = $vrtr['tPosBegin']; |
|
756 | + $kind = 1; }} |
|
757 | + if ($subBlockNo < $this->blockTabCnt) { // check for subblock |
|
758 | + $subBtr =& $this->blockTab[$subBlockNo]; |
|
759 | + if ($subBtr['tPosBegin'] < $tPos) { |
|
760 | + $subBlockNo += 1; |
|
761 | + continue; } |
|
762 | + if ($subBtr['tPosBegin'] < $tPos2) { |
|
763 | + $tPos2 = $subBtr['tPosBegin']; |
|
764 | + $kind = 2; }} |
|
765 | + if ($tPos2 > $tPos) |
|
766 | + $this->writeString (substr($this->template,$tPos,$tPos2-$tPos)); |
|
767 | + switch ($kind) { |
|
768 | + case 0: // end of block |
|
769 | + return; |
|
770 | + case 1: // variable |
|
771 | + $vrtr =& $this->varRefTab[$varRefNo]; |
|
772 | + if ($vrtr['blockNo'] != $blockNo) |
|
773 | + $this->programLogicError (4); |
|
774 | + $variableValue = $bitr['blockVarTab'][$vrtr['blockVarNo']]; |
|
775 | + $this->writeString ($variableValue); |
|
776 | + $tPos = $vrtr['tPosEnd']; |
|
777 | + $varRefNo += 1; |
|
778 | + break; |
|
779 | + case 2: // sub block |
|
780 | + $subBtr =& $this->blockTab[$subBlockNo]; |
|
781 | + if ($subBtr['parentBlockNo'] != $blockNo) |
|
782 | + $this->programLogicError (3); |
|
783 | + $this->writeBlockInstances ($subBlockNo, $bitr['instanceLevel']); // recursive call |
|
784 | + $tPos = $subBtr['tPosEnd']; |
|
785 | + $subBlockNo += 1; |
|
786 | + break; }}} |
|
787 | 787 | |
788 | 788 | /** |
789 | 789 | * @access private |
@@ -791,17 +791,17 @@ discard block |
||
791 | 791 | function writeString ($s) { |
792 | 792 | if ($this->outputError) return; |
793 | 793 | switch ($this->outputMode) { |
794 | - case 0: // output to PHP output stream |
|
795 | - if (!print($s)) |
|
796 | - $this->outputError = true; |
|
797 | - break; |
|
798 | - case 1: // output to file |
|
799 | - $rc = fwrite($this->outputFileHandle, $s); |
|
800 | - if ($rc === false) $this->outputError = true; |
|
801 | - break; |
|
802 | - case 2: // output to string |
|
803 | - $this->outputString .= $s; |
|
804 | - break; }} |
|
794 | + case 0: // output to PHP output stream |
|
795 | + if (!print($s)) |
|
796 | + $this->outputError = true; |
|
797 | + break; |
|
798 | + case 1: // output to file |
|
799 | + $rc = fwrite($this->outputFileHandle, $s); |
|
800 | + if ($rc === false) $this->outputError = true; |
|
801 | + break; |
|
802 | + case 2: // output to string |
|
803 | + $this->outputString .= $s; |
|
804 | + break; }} |
|
805 | 805 | |
806 | 806 | //--- name lookup routines ------------------------------------------------------------------------------------------ |
807 | 807 | |
@@ -838,9 +838,9 @@ discard block |
||
838 | 838 | */ |
839 | 839 | function readFileIntoString ($fileName, &$s) { |
840 | 840 | if (function_exists('version_compare') && version_compare(phpversion(),"4.3.0",">=")) { |
841 | - $s = file_get_contents($fileName); |
|
842 | - if ($s === false) return false; |
|
843 | - return true; } |
|
841 | + $s = file_get_contents($fileName); |
|
842 | + if ($s === false) return false; |
|
843 | + return true; } |
|
844 | 844 | $fh = fopen($fileName,"rb"); |
845 | 845 | if ($fh === false) return false; |
846 | 846 | $fileSize = filesize($fileName); |
@@ -888,9 +888,9 @@ discard block |
||
888 | 888 | while ($p < $sLen && ord($s{$p}) <= 32) $p++; |
889 | 889 | if ($p >= $sLen) return false; |
890 | 890 | if (substr($s,$p,1) == '"') |
891 | - return $this->parseQuotedString($s,$p,$w); |
|
892 | - else |
|
893 | - return $this->parseWord($s,$p,$w); } |
|
891 | + return $this->parseQuotedString($s,$p,$w); |
|
892 | + else |
|
893 | + return $this->parseWord($s,$p,$w); } |
|
894 | 894 | |
895 | 895 | /** |
896 | 896 | * Combine two file system paths. |
@@ -901,9 +901,9 @@ discard block |
||
901 | 901 | $s = $path1; |
902 | 902 | if (substr($s,-1) != '\\' && substr($s,-1) != '/') $s = $s . "/"; |
903 | 903 | if (substr($path2,0,1) == '\\' || substr($path2,0,1) == '/') |
904 | - $s = $s . substr($path2,1); |
|
905 | - else |
|
906 | - $s = $s . $path2; |
|
904 | + $s = $s . substr($path2,1); |
|
905 | + else |
|
906 | + $s = $s . $path2; |
|
907 | 907 | return $s; } |
908 | 908 | |
909 | 909 | /** |
@@ -295,23 +295,23 @@ discard block |
||
295 | 295 | if (!$this->parseWord($cmdL,$p,$cmd)) return true; |
296 | 296 | $parms = substr($cmdL,$p); |
297 | 297 | switch (strtoupper($cmd)) { |
298 | - case '$BEGINBLOCK': |
|
299 | - if (!$this->processBeginBlockCmd($parms,$cmdTPosBegin,$cmdTPosEnd)) |
|
300 | - return false; |
|
301 | - break; |
|
302 | - case '$ENDBLOCK': |
|
303 | - if (!$this->processEndBlockCmd($parms,$cmdTPosBegin,$cmdTPosEnd)) |
|
304 | - return false; |
|
305 | - break; |
|
306 | - case '$INCLUDE': |
|
307 | - if (!$this->processincludeCmd($parms,$cmdTPosBegin,$cmdTPosEnd)) |
|
308 | - return false; |
|
309 | - $resumeFromStart = true; |
|
310 | - break; |
|
311 | - default: |
|
312 | - if ($cmd{0} == '$' && !(strlen($cmd) >= 2 && $cmd{1} == '{')) { |
|
313 | - $this->triggerError ("Unknown command \"$cmd\" in template at offset $cmdTPosBegin."); |
|
314 | - return false; }} |
|
298 | + case '$BEGINBLOCK': |
|
299 | + if (!$this->processBeginBlockCmd($parms,$cmdTPosBegin,$cmdTPosEnd)) |
|
300 | + return false; |
|
301 | + break; |
|
302 | + case '$ENDBLOCK': |
|
303 | + if (!$this->processEndBlockCmd($parms,$cmdTPosBegin,$cmdTPosEnd)) |
|
304 | + return false; |
|
305 | + break; |
|
306 | + case '$INCLUDE': |
|
307 | + if (!$this->processincludeCmd($parms,$cmdTPosBegin,$cmdTPosEnd)) |
|
308 | + return false; |
|
309 | + $resumeFromStart = true; |
|
310 | + break; |
|
311 | + default: |
|
312 | + if ($cmd{0} == '$' && !(strlen($cmd) >= 2 && $cmd{1} == '{')) { |
|
313 | + $this->triggerError ("Unknown command \"$cmd\" in template at offset $cmdTPosBegin."); |
|
314 | + return false; }} |
|
315 | 315 | return true; } |
316 | 316 | |
317 | 317 | /** |
@@ -765,25 +765,25 @@ discard block |
||
765 | 765 | if ($tPos2 > $tPos) |
766 | 766 | $this->writeString (substr($this->template,$tPos,$tPos2-$tPos)); |
767 | 767 | switch ($kind) { |
768 | - case 0: // end of block |
|
769 | - return; |
|
770 | - case 1: // variable |
|
771 | - $vrtr =& $this->varRefTab[$varRefNo]; |
|
772 | - if ($vrtr['blockNo'] != $blockNo) |
|
773 | - $this->programLogicError (4); |
|
774 | - $variableValue = $bitr['blockVarTab'][$vrtr['blockVarNo']]; |
|
775 | - $this->writeString ($variableValue); |
|
776 | - $tPos = $vrtr['tPosEnd']; |
|
777 | - $varRefNo += 1; |
|
778 | - break; |
|
779 | - case 2: // sub block |
|
780 | - $subBtr =& $this->blockTab[$subBlockNo]; |
|
781 | - if ($subBtr['parentBlockNo'] != $blockNo) |
|
782 | - $this->programLogicError (3); |
|
783 | - $this->writeBlockInstances ($subBlockNo, $bitr['instanceLevel']); // recursive call |
|
784 | - $tPos = $subBtr['tPosEnd']; |
|
785 | - $subBlockNo += 1; |
|
786 | - break; }}} |
|
768 | + case 0: // end of block |
|
769 | + return; |
|
770 | + case 1: // variable |
|
771 | + $vrtr =& $this->varRefTab[$varRefNo]; |
|
772 | + if ($vrtr['blockNo'] != $blockNo) |
|
773 | + $this->programLogicError (4); |
|
774 | + $variableValue = $bitr['blockVarTab'][$vrtr['blockVarNo']]; |
|
775 | + $this->writeString ($variableValue); |
|
776 | + $tPos = $vrtr['tPosEnd']; |
|
777 | + $varRefNo += 1; |
|
778 | + break; |
|
779 | + case 2: // sub block |
|
780 | + $subBtr =& $this->blockTab[$subBlockNo]; |
|
781 | + if ($subBtr['parentBlockNo'] != $blockNo) |
|
782 | + $this->programLogicError (3); |
|
783 | + $this->writeBlockInstances ($subBlockNo, $bitr['instanceLevel']); // recursive call |
|
784 | + $tPos = $subBtr['tPosEnd']; |
|
785 | + $subBlockNo += 1; |
|
786 | + break; }}} |
|
787 | 787 | |
788 | 788 | /** |
789 | 789 | * @access private |
@@ -791,17 +791,17 @@ discard block |
||
791 | 791 | function writeString ($s) { |
792 | 792 | if ($this->outputError) return; |
793 | 793 | switch ($this->outputMode) { |
794 | - case 0: // output to PHP output stream |
|
795 | - if (!print($s)) |
|
796 | - $this->outputError = true; |
|
797 | - break; |
|
798 | - case 1: // output to file |
|
799 | - $rc = fwrite($this->outputFileHandle, $s); |
|
800 | - if ($rc === false) $this->outputError = true; |
|
801 | - break; |
|
802 | - case 2: // output to string |
|
803 | - $this->outputString .= $s; |
|
804 | - break; }} |
|
794 | + case 0: // output to PHP output stream |
|
795 | + if (!print($s)) |
|
796 | + $this->outputError = true; |
|
797 | + break; |
|
798 | + case 1: // output to file |
|
799 | + $rc = fwrite($this->outputFileHandle, $s); |
|
800 | + if ($rc === false) $this->outputError = true; |
|
801 | + break; |
|
802 | + case 2: // output to string |
|
803 | + $this->outputString .= $s; |
|
804 | + break; }} |
|
805 | 805 | |
806 | 806 | //--- name lookup routines ------------------------------------------------------------------------------------------ |
807 | 807 |
@@ -89,16 +89,16 @@ discard block |
||
89 | 89 | * @access private |
90 | 90 | */ |
91 | 91 | |
92 | -var $maxNestingLevel = 50; // maximum number of block nestings |
|
93 | -var $maxInclTemplateSize = 1000000; // maximum length of template string when including subtemplates |
|
94 | -var $template; // Template file data |
|
95 | -var $varTab; // variables table, array index is variable no |
|
92 | +var $maxNestingLevel = 50; // maximum number of block nestings |
|
93 | +var $maxInclTemplateSize = 1000000; // maximum length of template string when including subtemplates |
|
94 | +var $template; // Template file data |
|
95 | +var $varTab; // variables table, array index is variable no |
|
96 | 96 | // Fields: |
97 | 97 | // varName // variable name |
98 | 98 | // varValue // variable value |
99 | -var $varTabCnt; // no of entries used in VarTab |
|
100 | -var $varNameToNoMap; // maps variable names to variable numbers |
|
101 | -var $varRefTab; // variable references table |
|
99 | +var $varTabCnt; // no of entries used in VarTab |
|
100 | +var $varNameToNoMap; // maps variable names to variable numbers |
|
101 | +var $varRefTab; // variable references table |
|
102 | 102 | // Contains an entry for each variable reference in the template. Ordered by TemplatePos. |
103 | 103 | // Fields: |
104 | 104 | // varNo // variable no |
@@ -106,8 +106,8 @@ discard block |
||
106 | 106 | // tPosEnd // template position of end of variable reference |
107 | 107 | // blockNo // block no of the (innermost) block that contains this variable reference |
108 | 108 | // blockVarNo // block variable no. Index into BlockInstTab.BlockVarTab |
109 | -var $varRefTabCnt; // no of entries used in VarRefTab |
|
110 | -var $blockTab; // Blocks table, array index is block no |
|
109 | +var $varRefTabCnt; // no of entries used in VarRefTab |
|
110 | +var $blockTab; // Blocks table, array index is block no |
|
111 | 111 | // Contains an entry for each block in the template. Ordered by TPosBegin. |
112 | 112 | // Fields: |
113 | 113 | // blockName // block name |
@@ -126,12 +126,12 @@ discard block |
||
126 | 126 | // blockVarCnt // no of variables in block |
127 | 127 | // blockVarNoToVarNoMap // maps block variable numbers to variable numbers |
128 | 128 | // firstVarRefNo // variable reference no of first variable of this block or -1 |
129 | -var $blockTabCnt; // no of entries used in BlockTab |
|
130 | -var $blockNameToNoMap; // maps block names to block numbers |
|
129 | +var $blockTabCnt; // no of entries used in BlockTab |
|
130 | +var $blockNameToNoMap; // maps block names to block numbers |
|
131 | 131 | var $openBlocksTab; |
132 | 132 | // During parsing, this table contains the block numbers of the open parent blocks (nested outer blocks). |
133 | 133 | // Indexed by the block nesting level. |
134 | -var $blockInstTab; // block instances table |
|
134 | +var $blockInstTab; // block instances table |
|
135 | 135 | // This table contains an entry for each block instance that has been added. |
136 | 136 | // Indexed by BlockInstNo. |
137 | 137 | // Fields: |
@@ -143,14 +143,14 @@ discard block |
||
143 | 143 | // nextBlockInstNo // pointer to next instance of this block or -1 |
144 | 144 | // Forward chain for instances of same block. |
145 | 145 | // blockVarTab // block instance variables |
146 | -var $blockInstTabCnt; // no of entries used in BlockInstTab |
|
146 | +var $blockInstTabCnt; // no of entries used in BlockInstTab |
|
147 | 147 | |
148 | -var $currentNestingLevel; // Current block nesting level during parsing. |
|
149 | -var $templateValid; // true if a valid template is prepared |
|
150 | -var $outputMode; // 0 = to PHP output stream, 1 = to file, 2 = to string |
|
151 | -var $outputFileHandle; // file handle during writing of output file |
|
152 | -var $outputError; // true when an output error occurred |
|
153 | -var $outputString; // string buffer for the generated HTML page |
|
148 | +var $currentNestingLevel; // Current block nesting level during parsing. |
|
149 | +var $templateValid; // true if a valid template is prepared |
|
150 | +var $outputMode; // 0 = to PHP output stream, 1 = to file, 2 = to string |
|
151 | +var $outputFileHandle; // file handle during writing of output file |
|
152 | +var $outputError; // true when an output error occurred |
|
153 | +var $outputString; // string buffer for the generated HTML page |
|
154 | 154 | |
155 | 155 | /**#@-*/ |
156 | 156 | |
@@ -171,9 +171,9 @@ discard block |
||
171 | 171 | * @return boolean true on success, false on error. |
172 | 172 | * @access public |
173 | 173 | */ |
174 | -function readTemplateFromFile ($fileName) { |
|
175 | - if (!$this->readFileIntoString($fileName,$s)) { |
|
176 | - $this->triggerError ("Error while reading template file " . $fileName . "."); |
|
174 | +function readTemplateFromFile($fileName) { |
|
175 | + if (!$this->readFileIntoString($fileName, $s)) { |
|
176 | + $this->triggerError("Error while reading template file ".$fileName."."); |
|
177 | 177 | return false; } |
178 | 178 | if (!$this->setTemplateString($s)) return false; |
179 | 179 | return true; } |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | * @return boolean true on success, false on error. |
185 | 185 | * @access public |
186 | 186 | */ |
187 | -function setTemplateString ($templateString) { |
|
187 | +function setTemplateString($templateString) { |
|
188 | 188 | $this->templateValid = false; |
189 | 189 | $this->template = $templateString; |
190 | 190 | if (!$this->parseTemplate()) return false; |
@@ -197,10 +197,10 @@ discard block |
||
197 | 197 | * @return boolean true on success, false on error. |
198 | 198 | * @access private |
199 | 199 | */ |
200 | -function loadSubtemplate ($subtemplateName, &$s) { |
|
201 | - $subtemplateFileName = $this->combineFileSystemPath($this->subtemplateBasePath,$subtemplateName); |
|
202 | - if (!$this->readFileIntoString($subtemplateFileName,$s)) { |
|
203 | - $this->triggerError ("Error while reading subtemplate file " . $subtemplateFileName . "."); |
|
200 | +function loadSubtemplate($subtemplateName, &$s) { |
|
201 | + $subtemplateFileName = $this->combineFileSystemPath($this->subtemplateBasePath, $subtemplateName); |
|
202 | + if (!$this->readFileIntoString($subtemplateFileName, $s)) { |
|
203 | + $this->triggerError("Error while reading subtemplate file ".$subtemplateFileName."."); |
|
204 | 204 | return false; } |
205 | 205 | return true; } |
206 | 206 | |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | function beginMainBlock() { |
244 | 244 | $blockNo = 0; |
245 | 245 | $this->registerBlock('@@InternalMainBlock@@', $blockNo); |
246 | - $bte =& $this->blockTab[$blockNo]; |
|
246 | + $bte = & $this->blockTab[$blockNo]; |
|
247 | 247 | $bte['tPosBegin'] = 0; |
248 | 248 | $bte['tPosContentsBegin'] = 0; |
249 | 249 | $bte['nestingLevel'] = 0; |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | * @access private |
258 | 258 | */ |
259 | 259 | function endMainBlock() { |
260 | - $bte =& $this->blockTab[0]; |
|
260 | + $bte = & $this->blockTab[0]; |
|
261 | 261 | $bte['tPosContentsEnd'] = strlen($this->template); |
262 | 262 | $bte['tPosEnd'] = strlen($this->template); |
263 | 263 | $bte['definitionIsOpen'] = false; |
@@ -271,15 +271,15 @@ discard block |
||
271 | 271 | function parseTemplateCommands() { |
272 | 272 | $p = 0; |
273 | 273 | while (true) { |
274 | - $p0 = strpos($this->template,'<!--',$p); |
|
274 | + $p0 = strpos($this->template, '<!--', $p); |
|
275 | 275 | if ($p0 === false) break; |
276 | - $p = strpos($this->template,'-->',$p0); |
|
276 | + $p = strpos($this->template, '-->', $p0); |
|
277 | 277 | if ($p === false) { |
278 | - $this->triggerError ("Invalid HTML comment in template at offset $p0."); |
|
278 | + $this->triggerError("Invalid HTML comment in template at offset $p0."); |
|
279 | 279 | return false; } |
280 | 280 | $p += 3; |
281 | - $cmdL = substr($this->template,$p0+4,$p-$p0-7); |
|
282 | - if (!$this->processTemplateCommand($cmdL,$p0,$p,$resumeFromStart)) |
|
281 | + $cmdL = substr($this->template, $p0 + 4, $p - $p0 - 7); |
|
282 | + if (!$this->processTemplateCommand($cmdL, $p0, $p, $resumeFromStart)) |
|
283 | 283 | return false; |
284 | 284 | if ($resumeFromStart) $p = $p0; } |
285 | 285 | return true; } |
@@ -288,29 +288,29 @@ discard block |
||
288 | 288 | * @return boolean true on success, false on error. |
289 | 289 | * @access private |
290 | 290 | */ |
291 | -function processTemplateCommand ($cmdL, $cmdTPosBegin, $cmdTPosEnd, &$resumeFromStart) { |
|
291 | +function processTemplateCommand($cmdL, $cmdTPosBegin, $cmdTPosEnd, &$resumeFromStart) { |
|
292 | 292 | $resumeFromStart = false; |
293 | 293 | $p = 0; |
294 | 294 | $cmd = ''; |
295 | - if (!$this->parseWord($cmdL,$p,$cmd)) return true; |
|
296 | - $parms = substr($cmdL,$p); |
|
295 | + if (!$this->parseWord($cmdL, $p, $cmd)) return true; |
|
296 | + $parms = substr($cmdL, $p); |
|
297 | 297 | switch (strtoupper($cmd)) { |
298 | 298 | case '$BEGINBLOCK': |
299 | - if (!$this->processBeginBlockCmd($parms,$cmdTPosBegin,$cmdTPosEnd)) |
|
299 | + if (!$this->processBeginBlockCmd($parms, $cmdTPosBegin, $cmdTPosEnd)) |
|
300 | 300 | return false; |
301 | 301 | break; |
302 | 302 | case '$ENDBLOCK': |
303 | - if (!$this->processEndBlockCmd($parms,$cmdTPosBegin,$cmdTPosEnd)) |
|
303 | + if (!$this->processEndBlockCmd($parms, $cmdTPosBegin, $cmdTPosEnd)) |
|
304 | 304 | return false; |
305 | 305 | break; |
306 | 306 | case '$INCLUDE': |
307 | - if (!$this->processincludeCmd($parms,$cmdTPosBegin,$cmdTPosEnd)) |
|
307 | + if (!$this->processincludeCmd($parms, $cmdTPosBegin, $cmdTPosEnd)) |
|
308 | 308 | return false; |
309 | 309 | $resumeFromStart = true; |
310 | 310 | break; |
311 | 311 | default: |
312 | 312 | if ($cmd{0} == '$' && !(strlen($cmd) >= 2 && $cmd{1} == '{')) { |
313 | - $this->triggerError ("Unknown command \"$cmd\" in template at offset $cmdTPosBegin."); |
|
313 | + $this->triggerError("Unknown command \"$cmd\" in template at offset $cmdTPosBegin."); |
|
314 | 314 | return false; }} |
315 | 315 | return true; } |
316 | 316 | |
@@ -319,24 +319,24 @@ discard block |
||
319 | 319 | * @return boolean true on success, false on error. |
320 | 320 | * @access private |
321 | 321 | */ |
322 | -function processBeginBlockCmd ($parms, $cmdTPosBegin, $cmdTPosEnd) { |
|
322 | +function processBeginBlockCmd($parms, $cmdTPosBegin, $cmdTPosEnd) { |
|
323 | 323 | $p = 0; |
324 | - if (!$this->parseWord($parms,$p,$blockName)) { |
|
325 | - $this->triggerError ("Missing block name in \$BeginBlock command in template at offset $cmdTPosBegin."); |
|
324 | + if (!$this->parseWord($parms, $p, $blockName)) { |
|
325 | + $this->triggerError("Missing block name in \$BeginBlock command in template at offset $cmdTPosBegin."); |
|
326 | 326 | return false; } |
327 | - if (trim(substr($parms,$p)) != '') { |
|
328 | - $this->triggerError ("Extra parameter in \$BeginBlock command in template at offset $cmdTPosBegin."); |
|
327 | + if (trim(substr($parms, $p)) != '') { |
|
328 | + $this->triggerError("Extra parameter in \$BeginBlock command in template at offset $cmdTPosBegin."); |
|
329 | 329 | return false; } |
330 | - $this->registerBlock ($blockName, $blockNo); |
|
331 | - $btr =& $this->blockTab[$blockNo]; |
|
330 | + $this->registerBlock($blockName, $blockNo); |
|
331 | + $btr = & $this->blockTab[$blockNo]; |
|
332 | 332 | $btr['tPosBegin'] = $cmdTPosBegin; |
333 | 333 | $btr['tPosContentsBegin'] = $cmdTPosEnd; |
334 | 334 | $btr['nestingLevel'] = $this->currentNestingLevel; |
335 | - $btr['parentBlockNo'] = $this->openBlocksTab[$this->currentNestingLevel-1]; |
|
335 | + $btr['parentBlockNo'] = $this->openBlocksTab[$this->currentNestingLevel - 1]; |
|
336 | 336 | $this->openBlocksTab[$this->currentNestingLevel] = $blockNo; |
337 | 337 | $this->currentNestingLevel += 1; |
338 | 338 | if ($this->currentNestingLevel > $this->maxNestingLevel) { |
339 | - $this->triggerError ("Block nesting overflow in template at offset $cmdTPosBegin."); |
|
339 | + $this->triggerError("Block nesting overflow in template at offset $cmdTPosBegin."); |
|
340 | 340 | return false; } |
341 | 341 | return true; } |
342 | 342 | |
@@ -345,24 +345,24 @@ discard block |
||
345 | 345 | * @return boolean true on success, false on error. |
346 | 346 | * @access private |
347 | 347 | */ |
348 | -function processEndBlockCmd ($parms, $cmdTPosBegin, $cmdTPosEnd) { |
|
348 | +function processEndBlockCmd($parms, $cmdTPosBegin, $cmdTPosEnd) { |
|
349 | 349 | $p = 0; |
350 | - if (!$this->parseWord($parms,$p,$blockName)) { |
|
351 | - $this->triggerError ("Missing block name in \$EndBlock command in template at offset $cmdTPosBegin."); |
|
350 | + if (!$this->parseWord($parms, $p, $blockName)) { |
|
351 | + $this->triggerError("Missing block name in \$EndBlock command in template at offset $cmdTPosBegin."); |
|
352 | 352 | return false; } |
353 | - if (trim(substr($parms,$p)) != '') { |
|
354 | - $this->triggerError ("Extra parameter in \$EndBlock command in template at offset $cmdTPosBegin."); |
|
353 | + if (trim(substr($parms, $p)) != '') { |
|
354 | + $this->triggerError("Extra parameter in \$EndBlock command in template at offset $cmdTPosBegin."); |
|
355 | 355 | return false; } |
356 | - if (!$this->lookupBlockName($blockName,$blockNo)) { |
|
357 | - $this->triggerError ("Undefined block name \"$blockName\" in \$EndBlock command in template at offset $cmdTPosBegin."); |
|
356 | + if (!$this->lookupBlockName($blockName, $blockNo)) { |
|
357 | + $this->triggerError("Undefined block name \"$blockName\" in \$EndBlock command in template at offset $cmdTPosBegin."); |
|
358 | 358 | return false; } |
359 | 359 | $this->currentNestingLevel -= 1; |
360 | - $btr =& $this->blockTab[$blockNo]; |
|
360 | + $btr = & $this->blockTab[$blockNo]; |
|
361 | 361 | if (!$btr['definitionIsOpen']) { |
362 | - $this->triggerError ("Multiple \$EndBlock command for block \"$blockName\" in template at offset $cmdTPosBegin."); |
|
362 | + $this->triggerError("Multiple \$EndBlock command for block \"$blockName\" in template at offset $cmdTPosBegin."); |
|
363 | 363 | return false; } |
364 | 364 | if ($btr['nestingLevel'] != $this->currentNestingLevel) { |
365 | - $this->triggerError ("Block nesting level mismatch at \$EndBlock command for block \"$blockName\" in template at offset $cmdTPosBegin."); |
|
365 | + $this->triggerError("Block nesting level mismatch at \$EndBlock command for block \"$blockName\" in template at offset $cmdTPosBegin."); |
|
366 | 366 | return false; } |
367 | 367 | $btr['tPosContentsEnd'] = $cmdTPosBegin; |
368 | 368 | $btr['tPosEnd'] = $cmdTPosEnd; |
@@ -374,10 +374,10 @@ discard block |
||
374 | 374 | */ |
375 | 375 | function registerBlock($blockName, &$blockNo) { |
376 | 376 | $blockNo = $this->blockTabCnt++; |
377 | - $btr =& $this->blockTab[$blockNo]; |
|
377 | + $btr = & $this->blockTab[$blockNo]; |
|
378 | 378 | $btr = array(); |
379 | 379 | $btr['blockName'] = $blockName; |
380 | - if (!$this->lookupBlockName($blockName,$btr['nextWithSameName'])) |
|
380 | + if (!$this->lookupBlockName($blockName, $btr['nextWithSameName'])) |
|
381 | 381 | $btr['nextWithSameName'] = -1; |
382 | 382 | $btr['definitionIsOpen'] = true; |
383 | 383 | $btr['instances'] = 0; |
@@ -394,13 +394,13 @@ discard block |
||
394 | 394 | * @access private |
395 | 395 | */ |
396 | 396 | function checkBlockDefinitionsComplete() { |
397 | - for ($blockNo=0; $blockNo < $this->blockTabCnt; $blockNo++) { |
|
398 | - $btr =& $this->blockTab[$blockNo]; |
|
397 | + for ($blockNo = 0; $blockNo < $this->blockTabCnt; $blockNo++) { |
|
398 | + $btr = & $this->blockTab[$blockNo]; |
|
399 | 399 | if ($btr['definitionIsOpen']) { |
400 | - $this->triggerError ("Missing \$EndBlock command in template for block " . $btr['blockName'] . "."); |
|
400 | + $this->triggerError("Missing \$EndBlock command in template for block ".$btr['blockName']."."); |
|
401 | 401 | return false; }} |
402 | 402 | if ($this->currentNestingLevel != 0) { |
403 | - $this->triggerError ("Block nesting level error at end of template."); |
|
403 | + $this->triggerError("Block nesting level error at end of template."); |
|
404 | 404 | return false; } |
405 | 405 | return true; } |
406 | 406 | |
@@ -409,29 +409,29 @@ discard block |
||
409 | 409 | * @return boolean true on success, false on error. |
410 | 410 | * @access private |
411 | 411 | */ |
412 | -function processIncludeCmd ($parms, $cmdTPosBegin, $cmdTPosEnd) { |
|
412 | +function processIncludeCmd($parms, $cmdTPosBegin, $cmdTPosEnd) { |
|
413 | 413 | $p = 0; |
414 | - if (!$this->parseWordOrQuotedString($parms,$p,$subtemplateName)) { |
|
415 | - $this->triggerError ("Missing or invalid subtemplate name in \$Include command in template at offset $cmdTPosBegin."); |
|
414 | + if (!$this->parseWordOrQuotedString($parms, $p, $subtemplateName)) { |
|
415 | + $this->triggerError("Missing or invalid subtemplate name in \$Include command in template at offset $cmdTPosBegin."); |
|
416 | 416 | return false; } |
417 | - if (trim(substr($parms,$p)) != '') { |
|
418 | - $this->triggerError ("Extra parameter in \$include command in template at offset $cmdTPosBegin."); |
|
417 | + if (trim(substr($parms, $p)) != '') { |
|
418 | + $this->triggerError("Extra parameter in \$include command in template at offset $cmdTPosBegin."); |
|
419 | 419 | return false; } |
420 | - return $this->insertSubtemplate($subtemplateName,$cmdTPosBegin,$cmdTPosEnd); } |
|
420 | + return $this->insertSubtemplate($subtemplateName, $cmdTPosBegin, $cmdTPosEnd); } |
|
421 | 421 | |
422 | 422 | /** |
423 | 423 | * Processes the $Include command. |
424 | 424 | * @return boolean true on success, false on error. |
425 | 425 | * @access private |
426 | 426 | */ |
427 | -function insertSubtemplate ($subtemplateName, $tPos1, $tPos2) { |
|
427 | +function insertSubtemplate($subtemplateName, $tPos1, $tPos2) { |
|
428 | 428 | if (strlen($this->template) > $this->maxInclTemplateSize) { |
429 | - $this->triggerError ("Subtemplate include aborted because the internal template string is longer than $this->maxInclTemplateSize characters."); |
|
429 | + $this->triggerError("Subtemplate include aborted because the internal template string is longer than $this->maxInclTemplateSize characters."); |
|
430 | 430 | return false; } |
431 | - if (!$this->loadSubtemplate($subtemplateName,$subtemplate)) return false; |
|
431 | + if (!$this->loadSubtemplate($subtemplateName, $subtemplate)) return false; |
|
432 | 432 | // (Copying the template to insert a subtemplate is a bit slow. In a future implementation of MiniTemplator, |
433 | 433 | // a table could be used that contains references to the string fragments.) |
434 | - $this->template = substr($this->template,0,$tPos1) . $subtemplate . substr($this->template,$tPos2); |
|
434 | + $this->template = substr($this->template, 0, $tPos1).$subtemplate.substr($this->template, $tPos2); |
|
435 | 435 | return true; } |
436 | 436 | |
437 | 437 | /** |
@@ -447,24 +447,24 @@ discard block |
||
447 | 447 | $p0 = $p; |
448 | 448 | $p = strpos($this->template, '}', $p); |
449 | 449 | if ($p === false) { |
450 | - $this->triggerError ("Invalid variable reference in template at offset $p0."); |
|
450 | + $this->triggerError("Invalid variable reference in template at offset $p0."); |
|
451 | 451 | return false; } |
452 | 452 | $p += 1; |
453 | - $varName = trim(substr($this->template, $p0+2, $p-$p0-3)); |
|
453 | + $varName = trim(substr($this->template, $p0 + 2, $p - $p0 - 3)); |
|
454 | 454 | if (strlen($varName) == 0) { |
455 | - $this->triggerError ("Empty variable name in template at offset $p0."); |
|
455 | + $this->triggerError("Empty variable name in template at offset $p0."); |
|
456 | 456 | return false; } |
457 | - $this->registerVariableReference ($varName, $p0, $p); } |
|
457 | + $this->registerVariableReference($varName, $p0, $p); } |
|
458 | 458 | return true; } |
459 | 459 | |
460 | 460 | /** |
461 | 461 | * @access private |
462 | 462 | */ |
463 | -function registerVariableReference ($varName, $tPosBegin, $tPosEnd) { |
|
464 | - if (!$this->lookupVariableName($varName,$varNo)) |
|
465 | - $this->registerVariable($varName,$varNo); |
|
463 | +function registerVariableReference($varName, $tPosBegin, $tPosEnd) { |
|
464 | + if (!$this->lookupVariableName($varName, $varNo)) |
|
465 | + $this->registerVariable($varName, $varNo); |
|
466 | 466 | $varRefNo = $this->varRefTabCnt++; |
467 | - $vrtr =& $this->varRefTab[$varRefNo]; |
|
467 | + $vrtr = & $this->varRefTab[$varRefNo]; |
|
468 | 468 | $vrtr = array(); |
469 | 469 | $vrtr['tPosBegin'] = $tPosBegin; |
470 | 470 | $vrtr['tPosEnd'] = $tPosEnd; |
@@ -473,9 +473,9 @@ discard block |
||
473 | 473 | /** |
474 | 474 | * @access private |
475 | 475 | */ |
476 | -function registerVariable ($varName, &$varNo) { |
|
476 | +function registerVariable($varName, &$varNo) { |
|
477 | 477 | $varNo = $this->varTabCnt++; |
478 | - $vtr =& $this->varTab[$varNo]; |
|
478 | + $vtr = & $this->varTab[$varNo]; |
|
479 | 479 | $vtr = array(); |
480 | 480 | $vtr['varName'] = $varName; |
481 | 481 | $vtr['varValue'] = ''; |
@@ -490,7 +490,7 @@ discard block |
||
490 | 490 | $activeBlockNo = 0; |
491 | 491 | $nextBlockNo = 1; |
492 | 492 | while ($varRefNo < $this->varRefTabCnt) { |
493 | - $vrtr =& $this->varRefTab[$varRefNo]; |
|
493 | + $vrtr = & $this->varRefTab[$varRefNo]; |
|
494 | 494 | $varRefTPos = $vrtr['tPosBegin']; |
495 | 495 | $varNo = $vrtr['varNo']; |
496 | 496 | if ($varRefTPos >= $this->blockTab[$activeBlockNo]['tPosEnd']) { |
@@ -501,7 +501,7 @@ discard block |
||
501 | 501 | $activeBlockNo = $nextBlockNo; |
502 | 502 | $nextBlockNo += 1; |
503 | 503 | continue; }} |
504 | - $btr =& $this->blockTab[$activeBlockNo]; |
|
504 | + $btr = & $this->blockTab[$activeBlockNo]; |
|
505 | 505 | if ($varRefTPos < $btr['tPosBegin']) |
506 | 506 | $this->programLogicError(1); |
507 | 507 | $blockVarNo = $btr['blockVarCnt']++; |
@@ -523,10 +523,10 @@ discard block |
||
523 | 523 | * @access public |
524 | 524 | */ |
525 | 525 | function reset() { |
526 | - for ($varNo=0; $varNo<$this->varTabCnt; $varNo++) |
|
526 | + for ($varNo = 0; $varNo < $this->varTabCnt; $varNo++) |
|
527 | 527 | $this->varTab[$varNo]['varValue'] = ''; |
528 | - for ($blockNo=0; $blockNo<$this->blockTabCnt; $blockNo++) { |
|
529 | - $btr =& $this->blockTab[$blockNo]; |
|
528 | + for ($blockNo = 0; $blockNo < $this->blockTabCnt; $blockNo++) { |
|
529 | + $btr = & $this->blockTab[$blockNo]; |
|
530 | 530 | $btr['instances'] = 0; |
531 | 531 | $btr['firstBlockInstNo'] = -1; |
532 | 532 | $btr['lastBlockInstNo'] = -1; } |
@@ -548,11 +548,11 @@ discard block |
||
548 | 548 | * $isOptional is false). |
549 | 549 | * @access public |
550 | 550 | */ |
551 | -function setVariable ($variableName, $variableValue, $isOptional=false) { |
|
552 | - if (!$this->templateValid) {$this->triggerError ("Template not valid."); return false; } |
|
553 | - if (!$this->lookupVariableName($variableName,$varNo)) { |
|
551 | +function setVariable($variableName, $variableValue, $isOptional = false) { |
|
552 | + if (!$this->templateValid) {$this->triggerError("Template not valid."); return false; } |
|
553 | + if (!$this->lookupVariableName($variableName, $varNo)) { |
|
554 | 554 | if ($isOptional) return true; |
555 | - $this->triggerError ("Variable \"$variableName\" not defined in template."); |
|
555 | + $this->triggerError("Variable \"$variableName\" not defined in template."); |
|
556 | 556 | return false; } |
557 | 557 | $this->varTab[$varNo]['varValue'] = $variableValue; |
558 | 558 | return true; } |
@@ -575,8 +575,8 @@ discard block |
||
575 | 575 | * $isOptional is false). |
576 | 576 | * @access public |
577 | 577 | */ |
578 | -function setVariableEsc ($variableName, $variableValue, $isOptional=false) { |
|
579 | - return $this->setVariable($variableName,htmlspecialchars($variableValue,ENT_QUOTES),$isOptional); } |
|
578 | +function setVariableEsc($variableName, $variableValue, $isOptional = false) { |
|
579 | + return $this->setVariable($variableName, htmlspecialchars($variableValue, ENT_QUOTES), $isOptional); } |
|
580 | 580 | |
581 | 581 | /** |
582 | 582 | * Checks whether a variable with the specified name exists within the template. |
@@ -585,9 +585,9 @@ discard block |
||
585 | 585 | * variable with the specified name exists in the template. |
586 | 586 | * @access public |
587 | 587 | */ |
588 | -function variableExists ($variableName) { |
|
589 | - if (!$this->templateValid) {$this->triggerError ("Template not valid."); return false; } |
|
590 | - return $this->lookupVariableName($variableName,$varNo); } |
|
588 | +function variableExists($variableName) { |
|
589 | + if (!$this->templateValid) {$this->triggerError("Template not valid."); return false; } |
|
590 | + return $this->lookupVariableName($variableName, $varNo); } |
|
591 | 591 | |
592 | 592 | /** |
593 | 593 | * Adds an instance of a template block. |
@@ -603,9 +603,9 @@ discard block |
||
603 | 603 | * @access public |
604 | 604 | */ |
605 | 605 | function addBlock($blockName) { |
606 | - if (!$this->templateValid) {$this->triggerError ("Template not valid."); return false; } |
|
607 | - if (!$this->lookupBlockName($blockName,$blockNo)) { |
|
608 | - $this->triggerError ("Block \"$blockName\" not defined in template."); |
|
606 | + if (!$this->templateValid) {$this->triggerError("Template not valid."); return false; } |
|
607 | + if (!$this->lookupBlockName($blockName, $blockNo)) { |
|
608 | + $this->triggerError("Block \"$blockName\" not defined in template."); |
|
609 | 609 | return false; } |
610 | 610 | while ($blockNo != -1) { |
611 | 611 | $this->addBlockByNo($blockNo); |
@@ -615,10 +615,10 @@ discard block |
||
615 | 615 | /** |
616 | 616 | * @access private |
617 | 617 | */ |
618 | -function addBlockByNo ($blockNo) { |
|
619 | - $btr =& $this->blockTab[$blockNo]; |
|
620 | - $this->registerBlockInstance ($blockInstNo); |
|
621 | - $bitr =& $this->blockInstTab[$blockInstNo]; |
|
618 | +function addBlockByNo($blockNo) { |
|
619 | + $btr = & $this->blockTab[$blockNo]; |
|
620 | + $this->registerBlockInstance($blockInstNo); |
|
621 | + $bitr = & $this->blockInstTab[$blockInstNo]; |
|
622 | 622 | if ($btr['firstBlockInstNo'] == -1) |
623 | 623 | $btr['firstBlockInstNo'] = $blockInstNo; |
624 | 624 | if ($btr['lastBlockInstNo'] != -1) |
@@ -636,14 +636,14 @@ discard block |
||
636 | 636 | $bitr['nextBlockInstNo'] = -1; |
637 | 637 | $bitr['blockVarTab'] = array(); |
638 | 638 | // copy instance variables for this block |
639 | - for ($blockVarNo=0; $blockVarNo<$blockVarCnt; $blockVarNo++) { |
|
639 | + for ($blockVarNo = 0; $blockVarNo < $blockVarCnt; $blockVarNo++) { |
|
640 | 640 | $varNo = $btr['blockVarNoToVarNoMap'][$blockVarNo]; |
641 | 641 | $bitr['blockVarTab'][$blockVarNo] = $this->varTab[$varNo]['varValue']; }} |
642 | 642 | |
643 | 643 | /** |
644 | 644 | * @access private |
645 | 645 | */ |
646 | -function registerBlockInstance (&$blockInstNo) { |
|
646 | +function registerBlockInstance(&$blockInstNo) { |
|
647 | 647 | $blockInstNo = $this->blockInstTabCnt++; } |
648 | 648 | |
649 | 649 | /** |
@@ -653,9 +653,9 @@ discard block |
||
653 | 653 | * block with the specified name exists in the template. |
654 | 654 | * @access public |
655 | 655 | */ |
656 | -function blockExists ($blockName) { |
|
657 | - if (!$this->templateValid) {$this->triggerError ("Template not valid."); return false; } |
|
658 | - return $this->lookupBlockName($blockName,$blockNo); } |
|
656 | +function blockExists($blockName) { |
|
657 | + if (!$this->templateValid) {$this->triggerError("Template not valid."); return false; } |
|
658 | + return $this->lookupBlockName($blockName, $blockNo); } |
|
659 | 659 | |
660 | 660 | //--- output generation --------------------------------------------------------------------------------------------- |
661 | 661 | |
@@ -664,7 +664,7 @@ discard block |
||
664 | 664 | * @return boolean true on success, false on error. |
665 | 665 | * @access public |
666 | 666 | */ |
667 | -function generateOutput () { |
|
667 | +function generateOutput() { |
|
668 | 668 | $this->outputMode = 0; |
669 | 669 | if (!$this->generateOutputPage()) return false; |
670 | 670 | return true; } |
@@ -675,13 +675,13 @@ discard block |
||
675 | 675 | * @return boolean true on success, false on error. |
676 | 676 | * @access public |
677 | 677 | */ |
678 | -function generateOutputToFile ($fileName) { |
|
679 | - $fh = fopen($fileName,"wb"); |
|
678 | +function generateOutputToFile($fileName) { |
|
679 | + $fh = fopen($fileName, "wb"); |
|
680 | 680 | if ($fh === false) return false; |
681 | 681 | $this->outputMode = 1; |
682 | 682 | $this->outputFileHandle = $fh; |
683 | 683 | $ok = $this->generateOutputPage(); |
684 | - fclose ($fh); |
|
684 | + fclose($fh); |
|
685 | 685 | return $ok; } |
686 | 686 | |
687 | 687 | /** |
@@ -691,7 +691,7 @@ discard block |
||
691 | 691 | * @return boolean true on success, false on error. |
692 | 692 | * @access public |
693 | 693 | */ |
694 | -function generateOutputToString (&$outputString) { |
|
694 | +function generateOutputToString(&$outputString) { |
|
695 | 695 | $outputString = "Error"; |
696 | 696 | $this->outputMode = 2; |
697 | 697 | $this->outputString = ""; |
@@ -704,14 +704,14 @@ discard block |
||
704 | 704 | * @return boolean true on success, false on error. |
705 | 705 | */ |
706 | 706 | function generateOutputPage() { |
707 | - if (!$this->templateValid) {$this->triggerError ("Template not valid."); return false; } |
|
707 | + if (!$this->templateValid) {$this->triggerError("Template not valid."); return false; } |
|
708 | 708 | if ($this->blockTab[0]['instances'] == 0) |
709 | - $this->addBlockByNo (0); // add main block |
|
710 | - for ($blockNo=0; $blockNo < $this->blockTabCnt; $blockNo++) { |
|
711 | - $btr =& $this->blockTab[$blockNo]; |
|
709 | + $this->addBlockByNo(0); // add main block |
|
710 | + for ($blockNo = 0; $blockNo < $this->blockTabCnt; $blockNo++) { |
|
711 | + $btr = & $this->blockTab[$blockNo]; |
|
712 | 712 | $btr['currBlockInstNo'] = $btr['firstBlockInstNo']; } |
713 | 713 | $this->outputError = false; |
714 | - $this->writeBlockInstances (0, -1); |
|
714 | + $this->writeBlockInstances(0, -1); |
|
715 | 715 | if ($this->outputError) return false; |
716 | 716 | return true; } |
717 | 717 | |
@@ -721,33 +721,33 @@ discard block |
||
721 | 721 | * Called recursively. |
722 | 722 | * @access private |
723 | 723 | */ |
724 | -function writeBlockInstances ($blockNo, $parentInstLevel) { |
|
725 | - $btr =& $this->blockTab[$blockNo]; |
|
724 | +function writeBlockInstances($blockNo, $parentInstLevel) { |
|
725 | + $btr = & $this->blockTab[$blockNo]; |
|
726 | 726 | while (!$this->outputError) { |
727 | 727 | $blockInstNo = $btr['currBlockInstNo']; |
728 | 728 | if ($blockInstNo == -1) break; |
729 | - $bitr =& $this->blockInstTab[$blockInstNo]; |
|
729 | + $bitr = & $this->blockInstTab[$blockInstNo]; |
|
730 | 730 | if ($bitr['parentInstLevel'] < $parentInstLevel) |
731 | - $this->programLogicError (2); |
|
731 | + $this->programLogicError(2); |
|
732 | 732 | if ($bitr['parentInstLevel'] > $parentInstLevel) break; |
733 | - $this->writeBlockInstance ($blockInstNo); |
|
733 | + $this->writeBlockInstance($blockInstNo); |
|
734 | 734 | $btr['currBlockInstNo'] = $bitr['nextBlockInstNo']; }} |
735 | 735 | |
736 | 736 | /** |
737 | 737 | * @access private |
738 | 738 | */ |
739 | 739 | function writeBlockInstance($blockInstNo) { |
740 | - $bitr =& $this->blockInstTab[$blockInstNo]; |
|
740 | + $bitr = & $this->blockInstTab[$blockInstNo]; |
|
741 | 741 | $blockNo = $bitr['blockNo']; |
742 | - $btr =& $this->blockTab[$blockNo]; |
|
742 | + $btr = & $this->blockTab[$blockNo]; |
|
743 | 743 | $tPos = $btr['tPosContentsBegin']; |
744 | 744 | $subBlockNo = $blockNo + 1; |
745 | 745 | $varRefNo = $btr['firstVarRefNo']; |
746 | 746 | while (!$this->outputError) { |
747 | 747 | $tPos2 = $btr['tPosContentsEnd']; |
748 | - $kind = 0; // assume end-of-block |
|
748 | + $kind = 0; // assume end-of-block |
|
749 | 749 | if ($varRefNo != -1 && $varRefNo < $this->varRefTabCnt) { // check for variable reference |
750 | - $vrtr =& $this->varRefTab[$varRefNo]; |
|
750 | + $vrtr = & $this->varRefTab[$varRefNo]; |
|
751 | 751 | if ($vrtr['tPosBegin'] < $tPos) { |
752 | 752 | $varRefNo += 1; |
753 | 753 | continue; } |
@@ -755,7 +755,7 @@ discard block |
||
755 | 755 | $tPos2 = $vrtr['tPosBegin']; |
756 | 756 | $kind = 1; }} |
757 | 757 | if ($subBlockNo < $this->blockTabCnt) { // check for subblock |
758 | - $subBtr =& $this->blockTab[$subBlockNo]; |
|
758 | + $subBtr = & $this->blockTab[$subBlockNo]; |
|
759 | 759 | if ($subBtr['tPosBegin'] < $tPos) { |
760 | 760 | $subBlockNo += 1; |
761 | 761 | continue; } |
@@ -763,24 +763,24 @@ discard block |
||
763 | 763 | $tPos2 = $subBtr['tPosBegin']; |
764 | 764 | $kind = 2; }} |
765 | 765 | if ($tPos2 > $tPos) |
766 | - $this->writeString (substr($this->template,$tPos,$tPos2-$tPos)); |
|
766 | + $this->writeString(substr($this->template, $tPos, $tPos2 - $tPos)); |
|
767 | 767 | switch ($kind) { |
768 | 768 | case 0: // end of block |
769 | 769 | return; |
770 | 770 | case 1: // variable |
771 | - $vrtr =& $this->varRefTab[$varRefNo]; |
|
771 | + $vrtr = & $this->varRefTab[$varRefNo]; |
|
772 | 772 | if ($vrtr['blockNo'] != $blockNo) |
773 | - $this->programLogicError (4); |
|
773 | + $this->programLogicError(4); |
|
774 | 774 | $variableValue = $bitr['blockVarTab'][$vrtr['blockVarNo']]; |
775 | - $this->writeString ($variableValue); |
|
775 | + $this->writeString($variableValue); |
|
776 | 776 | $tPos = $vrtr['tPosEnd']; |
777 | 777 | $varRefNo += 1; |
778 | 778 | break; |
779 | 779 | case 2: // sub block |
780 | - $subBtr =& $this->blockTab[$subBlockNo]; |
|
780 | + $subBtr = & $this->blockTab[$subBlockNo]; |
|
781 | 781 | if ($subBtr['parentBlockNo'] != $blockNo) |
782 | - $this->programLogicError (3); |
|
783 | - $this->writeBlockInstances ($subBlockNo, $bitr['instanceLevel']); // recursive call |
|
782 | + $this->programLogicError(3); |
|
783 | + $this->writeBlockInstances($subBlockNo, $bitr['instanceLevel']); // recursive call |
|
784 | 784 | $tPos = $subBtr['tPosEnd']; |
785 | 785 | $subBlockNo += 1; |
786 | 786 | break; }}} |
@@ -788,7 +788,7 @@ discard block |
||
788 | 788 | /** |
789 | 789 | * @access private |
790 | 790 | */ |
791 | -function writeString ($s) { |
|
791 | +function writeString($s) { |
|
792 | 792 | if ($this->outputError) return; |
793 | 793 | switch ($this->outputMode) { |
794 | 794 | case 0: // output to PHP output stream |
@@ -810,8 +810,8 @@ discard block |
||
810 | 810 | * @return boolean true on success, false if the variable is not found. |
811 | 811 | * @access private |
812 | 812 | */ |
813 | -function lookupVariableName ($varName, &$varNo) { |
|
814 | - $x =& $this->varNameToNoMap[strtoupper($varName)]; |
|
813 | +function lookupVariableName($varName, &$varNo) { |
|
814 | + $x = & $this->varNameToNoMap[strtoupper($varName)]; |
|
815 | 815 | if (!isset($x)) return false; |
816 | 816 | $varNo = $x; |
817 | 817 | return true; } |
@@ -823,8 +823,8 @@ discard block |
||
823 | 823 | * @return boolean true on success, false when the block is not found. |
824 | 824 | * @access private |
825 | 825 | */ |
826 | -function lookupBlockName ($blockName, &$blockNo) { |
|
827 | - $x =& $this->blockNameToNoMap[strtoupper($blockName)]; |
|
826 | +function lookupBlockName($blockName, &$blockNo) { |
|
827 | + $x = & $this->blockNameToNoMap[strtoupper($blockName)]; |
|
828 | 828 | if (!isset($x)) return false; |
829 | 829 | $blockNo = $x; |
830 | 830 | return true; } |
@@ -836,17 +836,17 @@ discard block |
||
836 | 836 | * @return boolean true on success, false on error. |
837 | 837 | * @access private |
838 | 838 | */ |
839 | -function readFileIntoString ($fileName, &$s) { |
|
840 | - if (function_exists('version_compare') && version_compare(phpversion(),"4.3.0",">=")) { |
|
839 | +function readFileIntoString($fileName, &$s) { |
|
840 | + if (function_exists('version_compare') && version_compare(phpversion(), "4.3.0", ">=")) { |
|
841 | 841 | $s = file_get_contents($fileName); |
842 | 842 | if ($s === false) return false; |
843 | 843 | return true; } |
844 | - $fh = fopen($fileName,"rb"); |
|
844 | + $fh = fopen($fileName, "rb"); |
|
845 | 845 | if ($fh === false) return false; |
846 | 846 | $fileSize = filesize($fileName); |
847 | - if ($fileSize === false) {fclose ($fh); return false; } |
|
848 | - $s = fread($fh,$fileSize); |
|
849 | - fclose ($fh); |
|
847 | + if ($fileSize === false) {fclose($fh); return false; } |
|
848 | + $s = fread($fh, $fileSize); |
|
849 | + fclose($fh); |
|
850 | 850 | if (strlen($s) != $fileSize) return false; |
851 | 851 | return true; } |
852 | 852 | |
@@ -854,7 +854,7 @@ discard block |
||
854 | 854 | * @access private |
855 | 855 | * @return boolean true on success, false when the end of the string is reached. |
856 | 856 | */ |
857 | -function parseWord ($s, &$p, &$w) { |
|
857 | +function parseWord($s, &$p, &$w) { |
|
858 | 858 | $sLen = strlen($s); |
859 | 859 | while ($p < $sLen && ord($s{$p}) <= 32) $p++; |
860 | 860 | if ($p >= $sLen) return false; |
@@ -867,11 +867,11 @@ discard block |
||
867 | 867 | * @access private |
868 | 868 | * @return boolean true on success, false on error. |
869 | 869 | */ |
870 | -function parseQuotedString ($s, &$p, &$w) { |
|
870 | +function parseQuotedString($s, &$p, &$w) { |
|
871 | 871 | $sLen = strlen($s); |
872 | 872 | while ($p < $sLen && ord($s{$p}) <= 32) $p++; |
873 | 873 | if ($p >= $sLen) return false; |
874 | - if (substr($s,$p,1) != '"') return false; |
|
874 | + if (substr($s, $p, 1) != '"') return false; |
|
875 | 875 | $p++; $p0 = $p; |
876 | 876 | while ($p < $sLen && $s{$p} != '"') $p++; |
877 | 877 | if ($p >= $sLen) return false; |
@@ -883,39 +883,39 @@ discard block |
||
883 | 883 | * @access private |
884 | 884 | * @return boolean true on success, false on error. |
885 | 885 | */ |
886 | -function parseWordOrQuotedString ($s, &$p, &$w) { |
|
886 | +function parseWordOrQuotedString($s, &$p, &$w) { |
|
887 | 887 | $sLen = strlen($s); |
888 | 888 | while ($p < $sLen && ord($s{$p}) <= 32) $p++; |
889 | 889 | if ($p >= $sLen) return false; |
890 | - if (substr($s,$p,1) == '"') |
|
891 | - return $this->parseQuotedString($s,$p,$w); |
|
890 | + if (substr($s, $p, 1) == '"') |
|
891 | + return $this->parseQuotedString($s, $p, $w); |
|
892 | 892 | else |
893 | - return $this->parseWord($s,$p,$w); } |
|
893 | + return $this->parseWord($s, $p, $w); } |
|
894 | 894 | |
895 | 895 | /** |
896 | 896 | * Combine two file system paths. |
897 | 897 | * @access private |
898 | 898 | */ |
899 | -function combineFileSystemPath ($path1, $path2) { |
|
899 | +function combineFileSystemPath($path1, $path2) { |
|
900 | 900 | if ($path1 == '' || $path2 == '') return $path2; |
901 | 901 | $s = $path1; |
902 | - if (substr($s,-1) != '\\' && substr($s,-1) != '/') $s = $s . "/"; |
|
903 | - if (substr($path2,0,1) == '\\' || substr($path2,0,1) == '/') |
|
904 | - $s = $s . substr($path2,1); |
|
902 | + if (substr($s, -1) != '\\' && substr($s, -1) != '/') $s = $s."/"; |
|
903 | + if (substr($path2, 0, 1) == '\\' || substr($path2, 0, 1) == '/') |
|
904 | + $s = $s.substr($path2, 1); |
|
905 | 905 | else |
906 | - $s = $s . $path2; |
|
906 | + $s = $s.$path2; |
|
907 | 907 | return $s; } |
908 | 908 | |
909 | 909 | /** |
910 | 910 | * @access private |
911 | 911 | */ |
912 | -function triggerError ($msg) { |
|
913 | - trigger_error ("MiniTemplator error: $msg", E_USER_ERROR); } |
|
912 | +function triggerError($msg) { |
|
913 | + trigger_error("MiniTemplator error: $msg", E_USER_ERROR); } |
|
914 | 914 | |
915 | 915 | /** |
916 | 916 | * @access private |
917 | 917 | */ |
918 | -function programLogicError ($errorId) { |
|
918 | +function programLogicError($errorId) { |
|
919 | 919 | die ("MiniTemplator: Program logic error $errorId.\n"); } |
920 | 920 | |
921 | 921 | } |
@@ -175,7 +175,9 @@ discard block |
||
175 | 175 | if (!$this->readFileIntoString($fileName,$s)) { |
176 | 176 | $this->triggerError ("Error while reading template file " . $fileName . "."); |
177 | 177 | return false; } |
178 | - if (!$this->setTemplateString($s)) return false; |
|
178 | + if (!$this->setTemplateString($s)) { |
|
179 | + return false; |
|
180 | + } |
|
179 | 181 | return true; } |
180 | 182 | |
181 | 183 | /** |
@@ -187,7 +189,9 @@ discard block |
||
187 | 189 | function setTemplateString ($templateString) { |
188 | 190 | $this->templateValid = false; |
189 | 191 | $this->template = $templateString; |
190 | - if (!$this->parseTemplate()) return false; |
|
192 | + if (!$this->parseTemplate()) { |
|
193 | + return false; |
|
194 | + } |
|
191 | 195 | $this->reset(); |
192 | 196 | $this->templateValid = true; |
193 | 197 | return true; } |
@@ -214,10 +218,16 @@ discard block |
||
214 | 218 | function parseTemplate() { |
215 | 219 | $this->initParsing(); |
216 | 220 | $this->beginMainBlock(); |
217 | - if (!$this->parseTemplateCommands()) return false; |
|
221 | + if (!$this->parseTemplateCommands()) { |
|
222 | + return false; |
|
223 | + } |
|
218 | 224 | $this->endMainBlock(); |
219 | - if (!$this->checkBlockDefinitionsComplete()) return false; |
|
220 | - if (!$this->parseTemplateVariables()) return false; |
|
225 | + if (!$this->checkBlockDefinitionsComplete()) { |
|
226 | + return false; |
|
227 | + } |
|
228 | + if (!$this->parseTemplateVariables()) { |
|
229 | + return false; |
|
230 | + } |
|
221 | 231 | $this->associateVariablesWithBlocks(); |
222 | 232 | return true; } |
223 | 233 | |
@@ -272,16 +282,22 @@ discard block |
||
272 | 282 | $p = 0; |
273 | 283 | while (true) { |
274 | 284 | $p0 = strpos($this->template,'<!--',$p); |
275 | - if ($p0 === false) break; |
|
285 | + if ($p0 === false) { |
|
286 | + break; |
|
287 | + } |
|
276 | 288 | $p = strpos($this->template,'-->',$p0); |
277 | 289 | if ($p === false) { |
278 | 290 | $this->triggerError ("Invalid HTML comment in template at offset $p0."); |
279 | 291 | return false; } |
280 | 292 | $p += 3; |
281 | 293 | $cmdL = substr($this->template,$p0+4,$p-$p0-7); |
282 | - if (!$this->processTemplateCommand($cmdL,$p0,$p,$resumeFromStart)) |
|
283 | - return false; |
|
284 | - if ($resumeFromStart) $p = $p0; } |
|
294 | + if (!$this->processTemplateCommand($cmdL,$p0,$p,$resumeFromStart)) { |
|
295 | + return false; |
|
296 | + } |
|
297 | + if ($resumeFromStart) { |
|
298 | + $p = $p0; |
|
299 | + } |
|
300 | + } |
|
285 | 301 | return true; } |
286 | 302 | |
287 | 303 | /** |
@@ -292,20 +308,25 @@ discard block |
||
292 | 308 | $resumeFromStart = false; |
293 | 309 | $p = 0; |
294 | 310 | $cmd = ''; |
295 | - if (!$this->parseWord($cmdL,$p,$cmd)) return true; |
|
311 | + if (!$this->parseWord($cmdL,$p,$cmd)) { |
|
312 | + return true; |
|
313 | + } |
|
296 | 314 | $parms = substr($cmdL,$p); |
297 | 315 | switch (strtoupper($cmd)) { |
298 | 316 | case '$BEGINBLOCK': |
299 | - if (!$this->processBeginBlockCmd($parms,$cmdTPosBegin,$cmdTPosEnd)) |
|
300 | - return false; |
|
317 | + if (!$this->processBeginBlockCmd($parms,$cmdTPosBegin,$cmdTPosEnd)) { |
|
318 | + return false; |
|
319 | + } |
|
301 | 320 | break; |
302 | 321 | case '$ENDBLOCK': |
303 | - if (!$this->processEndBlockCmd($parms,$cmdTPosBegin,$cmdTPosEnd)) |
|
304 | - return false; |
|
322 | + if (!$this->processEndBlockCmd($parms,$cmdTPosBegin,$cmdTPosEnd)) { |
|
323 | + return false; |
|
324 | + } |
|
305 | 325 | break; |
306 | 326 | case '$INCLUDE': |
307 | - if (!$this->processincludeCmd($parms,$cmdTPosBegin,$cmdTPosEnd)) |
|
308 | - return false; |
|
327 | + if (!$this->processincludeCmd($parms,$cmdTPosBegin,$cmdTPosEnd)) { |
|
328 | + return false; |
|
329 | + } |
|
309 | 330 | $resumeFromStart = true; |
310 | 331 | break; |
311 | 332 | default: |
@@ -377,8 +398,9 @@ discard block |
||
377 | 398 | $btr =& $this->blockTab[$blockNo]; |
378 | 399 | $btr = array(); |
379 | 400 | $btr['blockName'] = $blockName; |
380 | - if (!$this->lookupBlockName($blockName,$btr['nextWithSameName'])) |
|
381 | - $btr['nextWithSameName'] = -1; |
|
401 | + if (!$this->lookupBlockName($blockName,$btr['nextWithSameName'])) { |
|
402 | + $btr['nextWithSameName'] = -1; |
|
403 | + } |
|
382 | 404 | $btr['definitionIsOpen'] = true; |
383 | 405 | $btr['instances'] = 0; |
384 | 406 | $btr['firstBlockInstNo'] = -1; |
@@ -428,7 +450,9 @@ discard block |
||
428 | 450 | if (strlen($this->template) > $this->maxInclTemplateSize) { |
429 | 451 | $this->triggerError ("Subtemplate include aborted because the internal template string is longer than $this->maxInclTemplateSize characters."); |
430 | 452 | return false; } |
431 | - if (!$this->loadSubtemplate($subtemplateName,$subtemplate)) return false; |
|
453 | + if (!$this->loadSubtemplate($subtemplateName,$subtemplate)) { |
|
454 | + return false; |
|
455 | + } |
|
432 | 456 | // (Copying the template to insert a subtemplate is a bit slow. In a future implementation of MiniTemplator, |
433 | 457 | // a table could be used that contains references to the string fragments.) |
434 | 458 | $this->template = substr($this->template,0,$tPos1) . $subtemplate . substr($this->template,$tPos2); |
@@ -443,7 +467,9 @@ discard block |
||
443 | 467 | $p = 0; |
444 | 468 | while (true) { |
445 | 469 | $p = strpos($this->template, '${', $p); |
446 | - if ($p === false) break; |
|
470 | + if ($p === false) { |
|
471 | + break; |
|
472 | + } |
|
447 | 473 | $p0 = $p; |
448 | 474 | $p = strpos($this->template, '}', $p); |
449 | 475 | if ($p === false) { |
@@ -461,8 +487,9 @@ discard block |
||
461 | 487 | * @access private |
462 | 488 | */ |
463 | 489 | function registerVariableReference ($varName, $tPosBegin, $tPosEnd) { |
464 | - if (!$this->lookupVariableName($varName,$varNo)) |
|
465 | - $this->registerVariable($varName,$varNo); |
|
490 | + if (!$this->lookupVariableName($varName,$varNo)) { |
|
491 | + $this->registerVariable($varName,$varNo); |
|
492 | + } |
|
466 | 493 | $varRefNo = $this->varRefTabCnt++; |
467 | 494 | $vrtr =& $this->varRefTab[$varRefNo]; |
468 | 495 | $vrtr = array(); |
@@ -502,12 +529,14 @@ discard block |
||
502 | 529 | $nextBlockNo += 1; |
503 | 530 | continue; }} |
504 | 531 | $btr =& $this->blockTab[$activeBlockNo]; |
505 | - if ($varRefTPos < $btr['tPosBegin']) |
|
506 | - $this->programLogicError(1); |
|
532 | + if ($varRefTPos < $btr['tPosBegin']) { |
|
533 | + $this->programLogicError(1); |
|
534 | + } |
|
507 | 535 | $blockVarNo = $btr['blockVarCnt']++; |
508 | 536 | $btr['blockVarNoToVarNoMap'][$blockVarNo] = $varNo; |
509 | - if ($btr['firstVarRefNo'] == -1) |
|
510 | - $btr['firstVarRefNo'] = $varRefNo; |
|
537 | + if ($btr['firstVarRefNo'] == -1) { |
|
538 | + $btr['firstVarRefNo'] = $varRefNo; |
|
539 | + } |
|
511 | 540 | $vrtr['blockNo'] = $activeBlockNo; |
512 | 541 | $vrtr['blockVarNo'] = $blockVarNo; |
513 | 542 | $varRefNo += 1; }} |
@@ -523,8 +552,9 @@ discard block |
||
523 | 552 | * @access public |
524 | 553 | */ |
525 | 554 | function reset() { |
526 | - for ($varNo=0; $varNo<$this->varTabCnt; $varNo++) |
|
527 | - $this->varTab[$varNo]['varValue'] = ''; |
|
555 | + for ($varNo=0; $varNo<$this->varTabCnt; $varNo++) { |
|
556 | + $this->varTab[$varNo]['varValue'] = ''; |
|
557 | + } |
|
528 | 558 | for ($blockNo=0; $blockNo<$this->blockTabCnt; $blockNo++) { |
529 | 559 | $btr =& $this->blockTab[$blockNo]; |
530 | 560 | $btr['instances'] = 0; |
@@ -551,7 +581,9 @@ discard block |
||
551 | 581 | function setVariable ($variableName, $variableValue, $isOptional=false) { |
552 | 582 | if (!$this->templateValid) {$this->triggerError ("Template not valid."); return false; } |
553 | 583 | if (!$this->lookupVariableName($variableName,$varNo)) { |
554 | - if ($isOptional) return true; |
|
584 | + if ($isOptional) { |
|
585 | + return true; |
|
586 | + } |
|
555 | 587 | $this->triggerError ("Variable \"$variableName\" not defined in template."); |
556 | 588 | return false; } |
557 | 589 | $this->varTab[$varNo]['varValue'] = $variableValue; |
@@ -619,20 +651,23 @@ discard block |
||
619 | 651 | $btr =& $this->blockTab[$blockNo]; |
620 | 652 | $this->registerBlockInstance ($blockInstNo); |
621 | 653 | $bitr =& $this->blockInstTab[$blockInstNo]; |
622 | - if ($btr['firstBlockInstNo'] == -1) |
|
623 | - $btr['firstBlockInstNo'] = $blockInstNo; |
|
624 | - if ($btr['lastBlockInstNo'] != -1) |
|
625 | - $this->blockInstTab[$btr['lastBlockInstNo']]['nextBlockInstNo'] = $blockInstNo; |
|
654 | + if ($btr['firstBlockInstNo'] == -1) { |
|
655 | + $btr['firstBlockInstNo'] = $blockInstNo; |
|
656 | + } |
|
657 | + if ($btr['lastBlockInstNo'] != -1) { |
|
658 | + $this->blockInstTab[$btr['lastBlockInstNo']]['nextBlockInstNo'] = $blockInstNo; |
|
659 | + } |
|
626 | 660 | // set forward pointer of chain |
627 | 661 | $btr['lastBlockInstNo'] = $blockInstNo; |
628 | 662 | $parentBlockNo = $btr['parentBlockNo']; |
629 | 663 | $blockVarCnt = $btr['blockVarCnt']; |
630 | 664 | $bitr['blockNo'] = $blockNo; |
631 | 665 | $bitr['instanceLevel'] = $btr['instances']++; |
632 | - if ($parentBlockNo == -1) |
|
633 | - $bitr['parentInstLevel'] = -1; |
|
634 | - else |
|
635 | - $bitr['parentInstLevel'] = $this->blockTab[$parentBlockNo]['instances']; |
|
666 | + if ($parentBlockNo == -1) { |
|
667 | + $bitr['parentInstLevel'] = -1; |
|
668 | + } else { |
|
669 | + $bitr['parentInstLevel'] = $this->blockTab[$parentBlockNo]['instances']; |
|
670 | + } |
|
636 | 671 | $bitr['nextBlockInstNo'] = -1; |
637 | 672 | $bitr['blockVarTab'] = array(); |
638 | 673 | // copy instance variables for this block |
@@ -666,7 +701,9 @@ discard block |
||
666 | 701 | */ |
667 | 702 | function generateOutput () { |
668 | 703 | $this->outputMode = 0; |
669 | - if (!$this->generateOutputPage()) return false; |
|
704 | + if (!$this->generateOutputPage()) { |
|
705 | + return false; |
|
706 | + } |
|
670 | 707 | return true; } |
671 | 708 | |
672 | 709 | /** |
@@ -677,7 +714,9 @@ discard block |
||
677 | 714 | */ |
678 | 715 | function generateOutputToFile ($fileName) { |
679 | 716 | $fh = fopen($fileName,"wb"); |
680 | - if ($fh === false) return false; |
|
717 | + if ($fh === false) { |
|
718 | + return false; |
|
719 | + } |
|
681 | 720 | $this->outputMode = 1; |
682 | 721 | $this->outputFileHandle = $fh; |
683 | 722 | $ok = $this->generateOutputPage(); |
@@ -695,7 +734,9 @@ discard block |
||
695 | 734 | $outputString = "Error"; |
696 | 735 | $this->outputMode = 2; |
697 | 736 | $this->outputString = ""; |
698 | - if (!$this->generateOutputPage()) return false; |
|
737 | + if (!$this->generateOutputPage()) { |
|
738 | + return false; |
|
739 | + } |
|
699 | 740 | $outputString = $this->outputString; |
700 | 741 | return true; } |
701 | 742 | |
@@ -705,14 +746,18 @@ discard block |
||
705 | 746 | */ |
706 | 747 | function generateOutputPage() { |
707 | 748 | if (!$this->templateValid) {$this->triggerError ("Template not valid."); return false; } |
708 | - if ($this->blockTab[0]['instances'] == 0) |
|
709 | - $this->addBlockByNo (0); // add main block |
|
749 | + if ($this->blockTab[0]['instances'] == 0) { |
|
750 | + $this->addBlockByNo (0); |
|
751 | + } |
|
752 | + // add main block |
|
710 | 753 | for ($blockNo=0; $blockNo < $this->blockTabCnt; $blockNo++) { |
711 | 754 | $btr =& $this->blockTab[$blockNo]; |
712 | 755 | $btr['currBlockInstNo'] = $btr['firstBlockInstNo']; } |
713 | 756 | $this->outputError = false; |
714 | 757 | $this->writeBlockInstances (0, -1); |
715 | - if ($this->outputError) return false; |
|
758 | + if ($this->outputError) { |
|
759 | + return false; |
|
760 | + } |
|
716 | 761 | return true; } |
717 | 762 | |
718 | 763 | /** |
@@ -725,11 +770,16 @@ discard block |
||
725 | 770 | $btr =& $this->blockTab[$blockNo]; |
726 | 771 | while (!$this->outputError) { |
727 | 772 | $blockInstNo = $btr['currBlockInstNo']; |
728 | - if ($blockInstNo == -1) break; |
|
773 | + if ($blockInstNo == -1) { |
|
774 | + break; |
|
775 | + } |
|
729 | 776 | $bitr =& $this->blockInstTab[$blockInstNo]; |
730 | - if ($bitr['parentInstLevel'] < $parentInstLevel) |
|
731 | - $this->programLogicError (2); |
|
732 | - if ($bitr['parentInstLevel'] > $parentInstLevel) break; |
|
777 | + if ($bitr['parentInstLevel'] < $parentInstLevel) { |
|
778 | + $this->programLogicError (2); |
|
779 | + } |
|
780 | + if ($bitr['parentInstLevel'] > $parentInstLevel) { |
|
781 | + break; |
|
782 | + } |
|
733 | 783 | $this->writeBlockInstance ($blockInstNo); |
734 | 784 | $btr['currBlockInstNo'] = $bitr['nextBlockInstNo']; }} |
735 | 785 | |
@@ -762,15 +812,17 @@ discard block |
||
762 | 812 | if ($subBtr['tPosBegin'] < $tPos2) { |
763 | 813 | $tPos2 = $subBtr['tPosBegin']; |
764 | 814 | $kind = 2; }} |
765 | - if ($tPos2 > $tPos) |
|
766 | - $this->writeString (substr($this->template,$tPos,$tPos2-$tPos)); |
|
815 | + if ($tPos2 > $tPos) { |
|
816 | + $this->writeString (substr($this->template,$tPos,$tPos2-$tPos)); |
|
817 | + } |
|
767 | 818 | switch ($kind) { |
768 | 819 | case 0: // end of block |
769 | 820 | return; |
770 | 821 | case 1: // variable |
771 | 822 | $vrtr =& $this->varRefTab[$varRefNo]; |
772 | - if ($vrtr['blockNo'] != $blockNo) |
|
773 | - $this->programLogicError (4); |
|
823 | + if ($vrtr['blockNo'] != $blockNo) { |
|
824 | + $this->programLogicError (4); |
|
825 | + } |
|
774 | 826 | $variableValue = $bitr['blockVarTab'][$vrtr['blockVarNo']]; |
775 | 827 | $this->writeString ($variableValue); |
776 | 828 | $tPos = $vrtr['tPosEnd']; |
@@ -778,8 +830,9 @@ discard block |
||
778 | 830 | break; |
779 | 831 | case 2: // sub block |
780 | 832 | $subBtr =& $this->blockTab[$subBlockNo]; |
781 | - if ($subBtr['parentBlockNo'] != $blockNo) |
|
782 | - $this->programLogicError (3); |
|
833 | + if ($subBtr['parentBlockNo'] != $blockNo) { |
|
834 | + $this->programLogicError (3); |
|
835 | + } |
|
783 | 836 | $this->writeBlockInstances ($subBlockNo, $bitr['instanceLevel']); // recursive call |
784 | 837 | $tPos = $subBtr['tPosEnd']; |
785 | 838 | $subBlockNo += 1; |
@@ -789,15 +842,20 @@ discard block |
||
789 | 842 | * @access private |
790 | 843 | */ |
791 | 844 | function writeString ($s) { |
792 | - if ($this->outputError) return; |
|
845 | + if ($this->outputError) { |
|
846 | + return; |
|
847 | + } |
|
793 | 848 | switch ($this->outputMode) { |
794 | 849 | case 0: // output to PHP output stream |
795 | - if (!print($s)) |
|
796 | - $this->outputError = true; |
|
850 | + if (!print($s)) { |
|
851 | + $this->outputError = true; |
|
852 | + } |
|
797 | 853 | break; |
798 | 854 | case 1: // output to file |
799 | 855 | $rc = fwrite($this->outputFileHandle, $s); |
800 | - if ($rc === false) $this->outputError = true; |
|
856 | + if ($rc === false) { |
|
857 | + $this->outputError = true; |
|
858 | + } |
|
801 | 859 | break; |
802 | 860 | case 2: // output to string |
803 | 861 | $this->outputString .= $s; |
@@ -812,7 +870,9 @@ discard block |
||
812 | 870 | */ |
813 | 871 | function lookupVariableName ($varName, &$varNo) { |
814 | 872 | $x =& $this->varNameToNoMap[strtoupper($varName)]; |
815 | - if (!isset($x)) return false; |
|
873 | + if (!isset($x)) { |
|
874 | + return false; |
|
875 | + } |
|
816 | 876 | $varNo = $x; |
817 | 877 | return true; } |
818 | 878 | |
@@ -825,7 +885,9 @@ discard block |
||
825 | 885 | */ |
826 | 886 | function lookupBlockName ($blockName, &$blockNo) { |
827 | 887 | $x =& $this->blockNameToNoMap[strtoupper($blockName)]; |
828 | - if (!isset($x)) return false; |
|
888 | + if (!isset($x)) { |
|
889 | + return false; |
|
890 | + } |
|
829 | 891 | $blockNo = $x; |
830 | 892 | return true; } |
831 | 893 | |
@@ -839,15 +901,21 @@ discard block |
||
839 | 901 | function readFileIntoString ($fileName, &$s) { |
840 | 902 | if (function_exists('version_compare') && version_compare(phpversion(),"4.3.0",">=")) { |
841 | 903 | $s = file_get_contents($fileName); |
842 | - if ($s === false) return false; |
|
904 | + if ($s === false) { |
|
905 | + return false; |
|
906 | + } |
|
843 | 907 | return true; } |
844 | 908 | $fh = fopen($fileName,"rb"); |
845 | - if ($fh === false) return false; |
|
909 | + if ($fh === false) { |
|
910 | + return false; |
|
911 | + } |
|
846 | 912 | $fileSize = filesize($fileName); |
847 | 913 | if ($fileSize === false) {fclose ($fh); return false; } |
848 | 914 | $s = fread($fh,$fileSize); |
849 | 915 | fclose ($fh); |
850 | - if (strlen($s) != $fileSize) return false; |
|
916 | + if (strlen($s) != $fileSize) { |
|
917 | + return false; |
|
918 | + } |
|
851 | 919 | return true; } |
852 | 920 | |
853 | 921 | /** |
@@ -856,10 +924,16 @@ discard block |
||
856 | 924 | */ |
857 | 925 | function parseWord ($s, &$p, &$w) { |
858 | 926 | $sLen = strlen($s); |
859 | - while ($p < $sLen && ord($s{$p}) <= 32) $p++; |
|
860 | - if ($p >= $sLen) return false; |
|
927 | + while ($p < $sLen && ord($s{$p}) <= 32) { |
|
928 | + $p++; |
|
929 | + } |
|
930 | + if ($p >= $sLen) { |
|
931 | + return false; |
|
932 | + } |
|
861 | 933 | $p0 = $p; |
862 | - while ($p < $sLen && ord($s{$p}) > 32) $p++; |
|
934 | + while ($p < $sLen && ord($s{$p}) > 32) { |
|
935 | + $p++; |
|
936 | + } |
|
863 | 937 | $w = substr($s, $p0, $p - $p0); |
864 | 938 | return true; } |
865 | 939 | |
@@ -869,12 +943,22 @@ discard block |
||
869 | 943 | */ |
870 | 944 | function parseQuotedString ($s, &$p, &$w) { |
871 | 945 | $sLen = strlen($s); |
872 | - while ($p < $sLen && ord($s{$p}) <= 32) $p++; |
|
873 | - if ($p >= $sLen) return false; |
|
874 | - if (substr($s,$p,1) != '"') return false; |
|
946 | + while ($p < $sLen && ord($s{$p}) <= 32) { |
|
947 | + $p++; |
|
948 | + } |
|
949 | + if ($p >= $sLen) { |
|
950 | + return false; |
|
951 | + } |
|
952 | + if (substr($s,$p,1) != '"') { |
|
953 | + return false; |
|
954 | + } |
|
875 | 955 | $p++; $p0 = $p; |
876 | - while ($p < $sLen && $s{$p} != '"') $p++; |
|
877 | - if ($p >= $sLen) return false; |
|
956 | + while ($p < $sLen && $s{$p} != '"') { |
|
957 | + $p++; |
|
958 | + } |
|
959 | + if ($p >= $sLen) { |
|
960 | + return false; |
|
961 | + } |
|
878 | 962 | $w = substr($s, $p0, $p - $p0); |
879 | 963 | $p++; |
880 | 964 | return true; } |
@@ -885,25 +969,36 @@ discard block |
||
885 | 969 | */ |
886 | 970 | function parseWordOrQuotedString ($s, &$p, &$w) { |
887 | 971 | $sLen = strlen($s); |
888 | - while ($p < $sLen && ord($s{$p}) <= 32) $p++; |
|
889 | - if ($p >= $sLen) return false; |
|
890 | - if (substr($s,$p,1) == '"') |
|
891 | - return $this->parseQuotedString($s,$p,$w); |
|
892 | - else |
|
893 | - return $this->parseWord($s,$p,$w); } |
|
972 | + while ($p < $sLen && ord($s{$p}) <= 32) { |
|
973 | + $p++; |
|
974 | + } |
|
975 | + if ($p >= $sLen) { |
|
976 | + return false; |
|
977 | + } |
|
978 | + if (substr($s,$p,1) == '"') { |
|
979 | + return $this->parseQuotedString($s,$p,$w); |
|
980 | + } else { |
|
981 | + return $this->parseWord($s,$p,$w); |
|
982 | + } |
|
983 | + } |
|
894 | 984 | |
895 | 985 | /** |
896 | 986 | * Combine two file system paths. |
897 | 987 | * @access private |
898 | 988 | */ |
899 | 989 | function combineFileSystemPath ($path1, $path2) { |
900 | - if ($path1 == '' || $path2 == '') return $path2; |
|
990 | + if ($path1 == '' || $path2 == '') { |
|
991 | + return $path2; |
|
992 | + } |
|
901 | 993 | $s = $path1; |
902 | - if (substr($s,-1) != '\\' && substr($s,-1) != '/') $s = $s . "/"; |
|
903 | - if (substr($path2,0,1) == '\\' || substr($path2,0,1) == '/') |
|
904 | - $s = $s . substr($path2,1); |
|
905 | - else |
|
906 | - $s = $s . $path2; |
|
994 | + if (substr($s,-1) != '\\' && substr($s,-1) != '/') { |
|
995 | + $s = $s . "/"; |
|
996 | + } |
|
997 | + if (substr($path2,0,1) == '\\' || substr($path2,0,1) == '/') { |
|
998 | + $s = $s . substr($path2,1); |
|
999 | + } else { |
|
1000 | + $s = $s . $path2; |
|
1001 | + } |
|
907 | 1002 | return $s; } |
908 | 1003 | |
909 | 1004 | /** |