Passed
Pull Request — master (#5)
by Cody
03:17
created
classes/handler/public.php 4 patches
Switch Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -760,24 +760,24 @@
 block discarded – undo
760 760
 				$feed_urls = false;
761 761
 
762 762
 				switch ($rc['code']) {
763
-					case 0:
764
-						print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
765
-						break;
766
-					case 1:
767
-						print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
768
-						break;
769
-					case 2:
770
-						print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url));
771
-						break;
772
-					case 3:
773
-						print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url));
774
-						break;
775
-					case 4:
776
-						$feed_urls = $rc["feeds"];
777
-						break;
778
-					case 5:
779
-						print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url));
780
-						break;
763
+				case 0:
764
+					print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
765
+					break;
766
+				case 1:
767
+					print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
768
+					break;
769
+				case 2:
770
+					print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url));
771
+					break;
772
+				case 3:
773
+					print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url));
774
+					break;
775
+				case 4:
776
+					$feed_urls = $rc["feeds"];
777
+					break;
778
+				case 5:
779
+					print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url));
780
+					break;
781 781
 				}
782 782
 
783 783
 				if ($feed_urls) {
Please login to merge, or discard this patch.
Spacing   +28 added lines, -29 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 
8 8
 		require_once "lib/MiniTemplator.class.php";
9 9
 
10
-		$note_style = 	"background-color : #fff7d5;
10
+		$note_style = "background-color : #fff7d5;
11 11
 			border-width : 1px; ".
12 12
 			"padding : 5px; border-style : dashed; border-color : #e7d796;".
13 13
 			"margin-bottom : 1em; color : #9a8c59;";
@@ -73,8 +73,8 @@  discard block
 block discarded – undo
73 73
 		$feed_site_url = $qfh_ret[2];
74 74
 		/* $last_error = $qfh_ret[3]; */
75 75
 
76
-		$feed_self_url = get_self_url_prefix() .
77
-			"/public.php?op=rss&id=$feed&key=" .
76
+		$feed_self_url = get_self_url_prefix().
77
+			"/public.php?op=rss&id=$feed&key=".
78 78
 			Feeds::get_feed_access_key($feed, false, $owner_uid);
79 79
 
80 80
 		if (!$feed_site_url) $feed_site_url = get_self_url_prefix();
@@ -102,8 +102,7 @@  discard block
 block discarded – undo
102 102
 				}
103 103
 
104 104
 				$tpl->setVariable('ARTICLE_ID',
105
-					htmlspecialchars($orig_guid ? $line['link'] :
106
-							$this->make_article_tag_uri($line['id'], $line['date_entered'])), true);
105
+					htmlspecialchars($orig_guid ? $line['link'] : $this->make_article_tag_uri($line['id'], $line['date_entered'])), true);
107 106
 				$tpl->setVariable('ARTICLE_LINK', htmlspecialchars($line['link']), true);
108 107
 				$tpl->setVariable('ARTICLE_TITLE', htmlspecialchars($line['title']), true);
109 108
 				$tpl->setVariable('ARTICLE_EXCERPT', $line["content_preview"], true);
@@ -112,7 +111,7 @@  discard block
 block discarded – undo
112 111
 					$feed_site_url, false, $line["id"]);
113 112
 
114 113
 				if ($line['note']) {
115
-					$content = "<div style=\"$note_style\">Article note: " . $line['note'] . "</div>" .
114
+					$content = "<div style=\"$note_style\">Article note: ".$line['note']."</div>".
116 115
 						$content;
117 116
 					$tpl->setVariable('ARTICLE_NOTE', htmlspecialchars($line['note']), true);
118 117
 				}
@@ -201,7 +200,7 @@  discard block
 block discarded – undo
201 200
 				$article = array();
202 201
 
203 202
 				$article['id'] = $line['link'];
204
-				$article['link']	= $line['link'];
203
+				$article['link'] = $line['link'];
205 204
 				$article['title'] = $line['title'];
206 205
 				$article['excerpt'] = $line["content_preview"];
207 206
 				$article['content'] = sanitize($line["content"], false, $owner_uid, $feed_site_url, false, $line["id"]);
@@ -277,13 +276,13 @@  discard block
 block discarded – undo
277 276
 			WHERE ttrss_users.id = ttrss_settings_profiles.owner_uid AND login = ? ORDER BY title");
278 277
 			$sth->execute([$login]);
279 278
 
280
-			$rv = [ [ "value" => 0, "label" => __("Default profile") ] ];
279
+			$rv = [["value" => 0, "label" => __("Default profile")]];
281 280
 
282 281
 			while ($line = $sth->fetch()) {
283 282
 				$id = $line["id"];
284 283
 				$title = $line["title"];
285 284
 
286
-				array_push($rv, [ "label" => $title, "value" => $id ]);
285
+				array_push($rv, ["label" => $title, "value" => $id]);
287 286
 			}
288 287
 	    }
289 288
 
@@ -384,7 +383,7 @@  discard block
 block discarded – undo
384 383
             list ($og_image, $og_stream) = Article::get_article_image($enclosures, $line['content'], $line["site_url"]);
385 384
 
386 385
             if ($og_image) {
387
-                $rv .= "<meta property='og:image' content=\"" . htmlspecialchars($og_image) . "\"/>";
386
+                $rv .= "<meta property='og:image' content=\"".htmlspecialchars($og_image)."\"/>";
388 387
             }
389 388
 
390 389
             $rv .= "<body class='flat ttrss_utility ttrss_zoom'>";
@@ -393,9 +392,9 @@  discard block
 block discarded – undo
393 392
 			if ($line["link"]) {
394 393
 				$rv .= "<h1><a target='_blank' rel='noopener noreferrer'
395 394
 					title=\"".htmlspecialchars($line['title'])."\"
396
-					href=\"" .htmlspecialchars($line["link"]) . "\">" .	$line["title"] . "</a></h1>";
395
+					href=\"" .htmlspecialchars($line["link"])."\">".$line["title"]."</a></h1>";
397 396
 			} else {
398
-				$rv .= "<h1>" . $line["title"] . "</h1>";
397
+				$rv .= "<h1>".$line["title"]."</h1>";
399 398
 			}
400 399
 
401 400
 			$rv .= "<div class='content post'>";
@@ -448,8 +447,8 @@  discard block
 block discarded – undo
448 447
 		$feed = clean($_REQUEST["id"]);
449 448
 		$key = clean($_REQUEST["key"]);
450 449
 		$is_cat = clean($_REQUEST["is_cat"]);
451
-		$limit = (int)clean($_REQUEST["limit"]);
452
-		$offset = (int)clean($_REQUEST["offset"]);
450
+		$limit = (int) clean($_REQUEST["limit"]);
451
+		$offset = (int) clean($_REQUEST["offset"]);
453 452
 
454 453
 		$search = clean($_REQUEST["q"]);
455 454
 		$view_mode = clean($_REQUEST["view-mode"]);
@@ -692,9 +691,9 @@  discard block
 block discarded – undo
692 691
 			$return = clean($_REQUEST['return']);
693 692
 
694 693
 			if ($_REQUEST['return'] && mb_strpos($return, SELF_URL_PATH) === 0) {
695
-				header("Location: " . clean($_REQUEST['return']));
694
+				header("Location: ".clean($_REQUEST['return']));
696 695
 			} else {
697
-				header("Location: " . get_self_url_prefix());
696
+				header("Location: ".get_self_url_prefix());
698 697
 			}
699 698
 		}
700 699
 	}
@@ -786,7 +785,7 @@  discard block
 block discarded – undo
786 785
 					print "<input type='hidden' name='op' value='subscribe'>";
787 786
 
788 787
 					print "<fieldset>";
789
-					print "<label style='display : inline'>" . __("Multiple feed URLs found:") . "</label>";
788
+					print "<label style='display : inline'>".__("Multiple feed URLs found:")."</label>";
790 789
 					print "<select name='feed_url' dojoType='dijit.form.Select'>";
791 790
 
792 791
 					foreach ($feed_urls as $url => $name) {
@@ -805,9 +804,9 @@  discard block
 block discarded – undo
805 804
 					print "</form>";
806 805
 				}
807 806
 
808
-				$tp_uri = get_self_url_prefix() . "/prefs.php";
807
+				$tp_uri = get_self_url_prefix()."/prefs.php";
809 808
 
810
-				if ($rc['code'] <= 2){
809
+				if ($rc['code'] <= 2) {
811 810
 					$sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE
812 811
 					feed_url = ? AND owner_uid = ?");
813 812
 					$sth->execute([$feed_url, $_SESSION['uid']]);
@@ -895,7 +894,7 @@  discard block
 block discarded – undo
895 894
 					list($timestamp, $resetpass_token) = explode(":", $resetpass_token_full);
896 895
 
897 896
 					if ($timestamp && $resetpass_token &&
898
-						$timestamp >= time() - 15*60*60 &&
897
+						$timestamp >= time() - 15 * 60 * 60 &&
899 898
 						$resetpass_token == $hash) {
900 899
 
901 900
 							$sth = $this->pdo->prepare("UPDATE ttrss_users SET resetpass_token = NULL
@@ -935,8 +934,8 @@  discard block
 block discarded – undo
935 934
 				<input dojoType='dijit.form.TextBox' type='email' name='email' value='' required>
936 935
 				</fieldset>";
937 936
 
938
-			$_SESSION["pwdreset:testvalue1"] = rand(1,10);
939
-			$_SESSION["pwdreset:testvalue2"] = rand(1,10);
937
+			$_SESSION["pwdreset:testvalue1"] = rand(1, 10);
938
+			$_SESSION["pwdreset:testvalue2"] = rand(1, 10);
940 939
 
941 940
 			print "<fieldset>
942 941
 				<label>".T_sprintf("How much is %d + %d:", $_SESSION["pwdreset:testvalue1"], $_SESSION["pwdreset:testvalue2"])."</label>
@@ -981,8 +980,8 @@  discard block
 block discarded – undo
981 980
 
982 981
 					if ($id) {
983 982
 						$resetpass_token = sha1(get_random_bytes(128));
984
-						$resetpass_link = get_self_url_prefix() . "/public.php?op=forgotpass&hash=" . $resetpass_token .
985
-							"&login=" . urlencode($login);
983
+						$resetpass_link = get_self_url_prefix()."/public.php?op=forgotpass&hash=".$resetpass_token.
984
+							"&login=".urlencode($login);
986 985
 
987 986
 						require_once "lib/MiniTemplator.class.php";
988 987
 
@@ -1009,7 +1008,7 @@  discard block
 block discarded – undo
1009 1008
 
1010 1009
 						if (!$rc) print_error($mailer->error());
1011 1010
 
1012
-						$resetpass_token_full = time() . ":" . $resetpass_token;
1011
+						$resetpass_token_full = time().":".$resetpass_token;
1013 1012
 
1014 1013
 						$sth = $this->pdo->prepare("UPDATE ttrss_users
1015 1014
 							SET resetpass_token = ?
@@ -1099,12 +1098,12 @@  discard block
 block discarded – undo
1099 1098
 				if ($op == "performupdate") {
1100 1099
 					if ($updater->isUpdateRequired()) {
1101 1100
 
1102
-						print "<h2>" . T_sprintf("Performing updates to version %d", SCHEMA_VERSION) . "</h2>";
1101
+						print "<h2>".T_sprintf("Performing updates to version %d", SCHEMA_VERSION)."</h2>";
1103 1102
 
1104 1103
 						for ($i = $updater->getSchemaVersion() + 1; $i <= SCHEMA_VERSION; $i++) {
1105 1104
 							print "<ul>";
1106 1105
 
1107
-							print "<li class='text-info'>" . T_sprintf("Updating to version %d", $i) . "</li>";
1106
+							print "<li class='text-info'>".T_sprintf("Updating to version %d", $i)."</li>";
1108 1107
 
1109 1108
 							print "<li>";
1110 1109
 							$result = $updater->performUpdateTo($i, true);
@@ -1123,7 +1122,7 @@  discard block
 block discarded – undo
1123 1122
 
1124 1123
 								return;
1125 1124
 							} else {
1126
-								print "<li class='text-success'>" . __("Completed.") . "</li>";
1125
+								print "<li class='text-success'>".__("Completed.")."</li>";
1127 1126
 								print "</ul>";
1128 1127
 							}
1129 1128
 						}
@@ -1191,7 +1190,7 @@  discard block
 block discarded – undo
1191 1190
 
1192 1191
 		$timestamp = date("Y-m-d", strtotime($timestamp));
1193 1192
 
1194
-		return "tag:" . parse_url(get_self_url_prefix(), PHP_URL_HOST) . ",$timestamp:/$id";
1193
+		return "tag:".parse_url(get_self_url_prefix(), PHP_URL_HOST).",$timestamp:/$id";
1195 1194
 	}
1196 1195
 
1197 1196
 	// this should be used very carefully because this endpoint is exposed to unauthenticated users
Please login to merge, or discard this patch.
Indentation   +716 added lines, -716 removed lines patch added patch discarded remove patch
@@ -1,329 +1,329 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 class Handler_Public extends Handler {
3 3
 
4
-	private function generate_syndicated_feed($owner_uid, $feed, $is_cat,
5
-		$limit, $offset, $search,
6
-		$view_mode = false, $format = 'atom', $order = false, $orig_guid = false, $start_ts = false) {
4
+    private function generate_syndicated_feed($owner_uid, $feed, $is_cat,
5
+        $limit, $offset, $search,
6
+        $view_mode = false, $format = 'atom', $order = false, $orig_guid = false, $start_ts = false) {
7 7
 
8
-		require_once "lib/MiniTemplator.class.php";
8
+        require_once "lib/MiniTemplator.class.php";
9 9
 
10
-		$note_style = 	"background-color : #fff7d5;
10
+        $note_style = 	"background-color : #fff7d5;
11 11
 			border-width : 1px; ".
12
-			"padding : 5px; border-style : dashed; border-color : #e7d796;".
13
-			"margin-bottom : 1em; color : #9a8c59;";
14
-
15
-		if (!$limit) $limit = 60;
16
-
17
-		$date_sort_field = "date_entered DESC, updated DESC";
18
-
19
-		if ($feed == -2 && !$is_cat) {
20
-			$date_sort_field = "last_published DESC";
21
-		} else if ($feed == -1 && !$is_cat) {
22
-			$date_sort_field = "last_marked DESC";
23
-		}
24
-
25
-		switch ($order) {
26
-		case "title":
27
-			$date_sort_field = "ttrss_entries.title, date_entered, updated";
28
-			break;
29
-		case "date_reverse":
30
-			$date_sort_field = "date_entered, updated";
31
-			break;
32
-		case "feed_dates":
33
-			$date_sort_field = "updated DESC";
34
-			break;
35
-		}
36
-
37
-		$params = array(
38
-			"owner_uid" => $owner_uid,
39
-			"feed" => $feed,
40
-			"limit" => $limit,
41
-			"view_mode" => $view_mode,
42
-			"cat_view" => $is_cat,
43
-			"search" => $search,
44
-			"override_order" => $date_sort_field,
45
-			"include_children" => true,
46
-			"ignore_vfeed_group" => true,
47
-			"offset" => $offset,
48
-			"start_ts" => $start_ts
49
-		);
50
-
51
-		if (!$is_cat && is_numeric($feed) && $feed < PLUGIN_FEED_BASE_INDEX && $feed > LABEL_BASE_INDEX) {
52
-
53
-			$user_plugins = get_pref("_ENABLED_PLUGINS", $owner_uid);
54
-
55
-			$tmppluginhost = new PluginHost();
56
-			$tmppluginhost->load(PLUGINS, PluginHost::KIND_ALL);
57
-			$tmppluginhost->load($user_plugins, PluginHost::KIND_USER, $owner_uid);
58
-			$tmppluginhost->load_data();
59
-
60
-			$handler = $tmppluginhost->get_feed_handler(
61
-				PluginHost::feed_to_pfeed_id($feed));
62
-
63
-			if ($handler) {
64
-				$qfh_ret = $handler->get_headlines(PluginHost::feed_to_pfeed_id($feed), $params);
65
-			}
66
-
67
-		} else {
68
-			$qfh_ret = Feeds::queryFeedHeadlines($params);
69
-		}
70
-
71
-		$result = $qfh_ret[0];
72
-		$feed_title = htmlspecialchars($qfh_ret[1]);
73
-		$feed_site_url = $qfh_ret[2];
74
-		/* $last_error = $qfh_ret[3]; */
75
-
76
-		$feed_self_url = get_self_url_prefix() .
77
-			"/public.php?op=rss&id=$feed&key=" .
78
-			Feeds::get_feed_access_key($feed, false, $owner_uid);
79
-
80
-		if (!$feed_site_url) $feed_site_url = get_self_url_prefix();
81
-
82
-		if ($format == 'atom') {
83
-			$tpl = new MiniTemplator;
84
-
85
-			$tpl->readTemplateFromFile("templates/generated_feed.txt");
86
-
87
-			$tpl->setVariable('FEED_TITLE', $feed_title, true);
88
-			$tpl->setVariable('VERSION', get_version(), true);
89
-			$tpl->setVariable('FEED_URL', htmlspecialchars($feed_self_url), true);
90
-
91
-			$tpl->setVariable('SELF_URL', htmlspecialchars(get_self_url_prefix()), true);
92
-			while ($line = $result->fetch()) {
93
-
94
-				$line["content_preview"] = sanitize(truncate_string(strip_tags($line["content"]), 100, '...'));
95
-
96
-				foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) {
97
-					$line = $p->hook_query_headlines($line);
98
-				}
12
+            "padding : 5px; border-style : dashed; border-color : #e7d796;".
13
+            "margin-bottom : 1em; color : #9a8c59;";
14
+
15
+        if (!$limit) $limit = 60;
16
+
17
+        $date_sort_field = "date_entered DESC, updated DESC";
18
+
19
+        if ($feed == -2 && !$is_cat) {
20
+            $date_sort_field = "last_published DESC";
21
+        } else if ($feed == -1 && !$is_cat) {
22
+            $date_sort_field = "last_marked DESC";
23
+        }
24
+
25
+        switch ($order) {
26
+        case "title":
27
+            $date_sort_field = "ttrss_entries.title, date_entered, updated";
28
+            break;
29
+        case "date_reverse":
30
+            $date_sort_field = "date_entered, updated";
31
+            break;
32
+        case "feed_dates":
33
+            $date_sort_field = "updated DESC";
34
+            break;
35
+        }
36
+
37
+        $params = array(
38
+            "owner_uid" => $owner_uid,
39
+            "feed" => $feed,
40
+            "limit" => $limit,
41
+            "view_mode" => $view_mode,
42
+            "cat_view" => $is_cat,
43
+            "search" => $search,
44
+            "override_order" => $date_sort_field,
45
+            "include_children" => true,
46
+            "ignore_vfeed_group" => true,
47
+            "offset" => $offset,
48
+            "start_ts" => $start_ts
49
+        );
50
+
51
+        if (!$is_cat && is_numeric($feed) && $feed < PLUGIN_FEED_BASE_INDEX && $feed > LABEL_BASE_INDEX) {
52
+
53
+            $user_plugins = get_pref("_ENABLED_PLUGINS", $owner_uid);
54
+
55
+            $tmppluginhost = new PluginHost();
56
+            $tmppluginhost->load(PLUGINS, PluginHost::KIND_ALL);
57
+            $tmppluginhost->load($user_plugins, PluginHost::KIND_USER, $owner_uid);
58
+            $tmppluginhost->load_data();
59
+
60
+            $handler = $tmppluginhost->get_feed_handler(
61
+                PluginHost::feed_to_pfeed_id($feed));
62
+
63
+            if ($handler) {
64
+                $qfh_ret = $handler->get_headlines(PluginHost::feed_to_pfeed_id($feed), $params);
65
+            }
99 66
 
100
-				foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_EXPORT_FEED) as $p) {
101
-					$line = $p->hook_article_export_feed($line, $feed, $is_cat);
102
-				}
67
+        } else {
68
+            $qfh_ret = Feeds::queryFeedHeadlines($params);
69
+        }
103 70
 
104
-				$tpl->setVariable('ARTICLE_ID',
105
-					htmlspecialchars($orig_guid ? $line['link'] :
106
-							$this->make_article_tag_uri($line['id'], $line['date_entered'])), true);
107
-				$tpl->setVariable('ARTICLE_LINK', htmlspecialchars($line['link']), true);
108
-				$tpl->setVariable('ARTICLE_TITLE', htmlspecialchars($line['title']), true);
109
-				$tpl->setVariable('ARTICLE_EXCERPT', $line["content_preview"], true);
71
+        $result = $qfh_ret[0];
72
+        $feed_title = htmlspecialchars($qfh_ret[1]);
73
+        $feed_site_url = $qfh_ret[2];
74
+        /* $last_error = $qfh_ret[3]; */
110 75
 
111
-				$content = sanitize($line["content"], false, $owner_uid,
112
-					$feed_site_url, false, $line["id"]);
76
+        $feed_self_url = get_self_url_prefix() .
77
+            "/public.php?op=rss&id=$feed&key=" .
78
+            Feeds::get_feed_access_key($feed, false, $owner_uid);
113 79
 
114
-				if ($line['note']) {
115
-					$content = "<div style=\"$note_style\">Article note: " . $line['note'] . "</div>" .
116
-						$content;
117
-					$tpl->setVariable('ARTICLE_NOTE', htmlspecialchars($line['note']), true);
118
-				}
80
+        if (!$feed_site_url) $feed_site_url = get_self_url_prefix();
119 81
 
120
-				$tpl->setVariable('ARTICLE_CONTENT', $content, true);
82
+        if ($format == 'atom') {
83
+            $tpl = new MiniTemplator;
121 84
 
122
-				$tpl->setVariable('ARTICLE_UPDATED_ATOM',
123
-					date('c', strtotime($line["updated"])), true);
124
-				$tpl->setVariable('ARTICLE_UPDATED_RFC822',
125
-					date(DATE_RFC822, strtotime($line["updated"])), true);
85
+            $tpl->readTemplateFromFile("templates/generated_feed.txt");
126 86
 
127
-				$tpl->setVariable('ARTICLE_AUTHOR', htmlspecialchars($line['author']), true);
87
+            $tpl->setVariable('FEED_TITLE', $feed_title, true);
88
+            $tpl->setVariable('VERSION', get_version(), true);
89
+            $tpl->setVariable('FEED_URL', htmlspecialchars($feed_self_url), true);
128 90
 
129
-				$tpl->setVariable('ARTICLE_SOURCE_LINK', htmlspecialchars($line['site_url'] ? $line["site_url"] : get_self_url_prefix()), true);
130
-				$tpl->setVariable('ARTICLE_SOURCE_TITLE', htmlspecialchars($line['feed_title'] ? $line['feed_title'] : $feed_title), true);
91
+            $tpl->setVariable('SELF_URL', htmlspecialchars(get_self_url_prefix()), true);
92
+            while ($line = $result->fetch()) {
131 93
 
132
-				$tags = Article::get_article_tags($line["id"], $owner_uid);
94
+                $line["content_preview"] = sanitize(truncate_string(strip_tags($line["content"]), 100, '...'));
133 95
 
134
-				foreach ($tags as $tag) {
135
-					$tpl->setVariable('ARTICLE_CATEGORY', htmlspecialchars($tag), true);
136
-					$tpl->addBlock('category');
137
-				}
96
+                foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) {
97
+                    $line = $p->hook_query_headlines($line);
98
+                }
138 99
 
139
-				$enclosures = Article::get_article_enclosures($line["id"]);
100
+                foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_EXPORT_FEED) as $p) {
101
+                    $line = $p->hook_article_export_feed($line, $feed, $is_cat);
102
+                }
140 103
 
141
-				if (count($enclosures) > 0) {
142
-					foreach ($enclosures as $e) {
143
-						$type = htmlspecialchars($e['content_type']);
144
-						$url = htmlspecialchars($e['content_url']);
145
-						$length = $e['duration'] ? $e['duration'] : 1;
104
+                $tpl->setVariable('ARTICLE_ID',
105
+                    htmlspecialchars($orig_guid ? $line['link'] :
106
+                            $this->make_article_tag_uri($line['id'], $line['date_entered'])), true);
107
+                $tpl->setVariable('ARTICLE_LINK', htmlspecialchars($line['link']), true);
108
+                $tpl->setVariable('ARTICLE_TITLE', htmlspecialchars($line['title']), true);
109
+                $tpl->setVariable('ARTICLE_EXCERPT', $line["content_preview"], true);
146 110
 
147
-						$tpl->setVariable('ARTICLE_ENCLOSURE_URL', $url, true);
148
-						$tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', $type, true);
149
-						$tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', $length, true);
111
+                $content = sanitize($line["content"], false, $owner_uid,
112
+                    $feed_site_url, false, $line["id"]);
150 113
 
151
-						$tpl->addBlock('enclosure');
152
-					}
153
-				} else {
154
-					$tpl->setVariable('ARTICLE_ENCLOSURE_URL', null, true);
155
-					$tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', null, true);
156
-					$tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', null, true);
157
-				}
114
+                if ($line['note']) {
115
+                    $content = "<div style=\"$note_style\">Article note: " . $line['note'] . "</div>" .
116
+                        $content;
117
+                    $tpl->setVariable('ARTICLE_NOTE', htmlspecialchars($line['note']), true);
118
+                }
158 119
 
159
-				list ($og_image, $og_stream) = Article::get_article_image($enclosures, $line['content'], $feed_site_url);
120
+                $tpl->setVariable('ARTICLE_CONTENT', $content, true);
160 121
 
161
-				$tpl->setVariable('ARTICLE_OG_IMAGE', $og_image, true);
122
+                $tpl->setVariable('ARTICLE_UPDATED_ATOM',
123
+                    date('c', strtotime($line["updated"])), true);
124
+                $tpl->setVariable('ARTICLE_UPDATED_RFC822',
125
+                    date(DATE_RFC822, strtotime($line["updated"])), true);
162 126
 
163
-				$tpl->addBlock('entry');
164
-			}
127
+                $tpl->setVariable('ARTICLE_AUTHOR', htmlspecialchars($line['author']), true);
165 128
 
166
-			$tmp = "";
129
+                $tpl->setVariable('ARTICLE_SOURCE_LINK', htmlspecialchars($line['site_url'] ? $line["site_url"] : get_self_url_prefix()), true);
130
+                $tpl->setVariable('ARTICLE_SOURCE_TITLE', htmlspecialchars($line['feed_title'] ? $line['feed_title'] : $feed_title), true);
167 131
 
168
-			$tpl->addBlock('feed');
169
-			$tpl->generateOutputToString($tmp);
132
+                $tags = Article::get_article_tags($line["id"], $owner_uid);
170 133
 
171
-			if (@!clean($_REQUEST["noxml"])) {
172
-				header("Content-Type: text/xml; charset=utf-8");
173
-			} else {
174
-				header("Content-Type: text/plain; charset=utf-8");
175
-			}
134
+                foreach ($tags as $tag) {
135
+                    $tpl->setVariable('ARTICLE_CATEGORY', htmlspecialchars($tag), true);
136
+                    $tpl->addBlock('category');
137
+                }
176 138
 
177
-			print $tmp;
178
-		} else if ($format == 'json') {
139
+                $enclosures = Article::get_article_enclosures($line["id"]);
179 140
 
180
-			$feed = array();
141
+                if (count($enclosures) > 0) {
142
+                    foreach ($enclosures as $e) {
143
+                        $type = htmlspecialchars($e['content_type']);
144
+                        $url = htmlspecialchars($e['content_url']);
145
+                        $length = $e['duration'] ? $e['duration'] : 1;
181 146
 
182
-			$feed['title'] = $feed_title;
183
-			$feed['feed_url'] = $feed_self_url;
147
+                        $tpl->setVariable('ARTICLE_ENCLOSURE_URL', $url, true);
148
+                        $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', $type, true);
149
+                        $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', $length, true);
184 150
 
185
-			$feed['self_url'] = get_self_url_prefix();
151
+                        $tpl->addBlock('enclosure');
152
+                    }
153
+                } else {
154
+                    $tpl->setVariable('ARTICLE_ENCLOSURE_URL', null, true);
155
+                    $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', null, true);
156
+                    $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', null, true);
157
+                }
186 158
 
187
-			$feed['articles'] = array();
159
+                list ($og_image, $og_stream) = Article::get_article_image($enclosures, $line['content'], $feed_site_url);
188 160
 
189
-			while ($line = $result->fetch()) {
161
+                $tpl->setVariable('ARTICLE_OG_IMAGE', $og_image, true);
190 162
 
191
-				$line["content_preview"] = sanitize(truncate_string(strip_tags($line["content_preview"]), 100, '...'));
163
+                $tpl->addBlock('entry');
164
+            }
192 165
 
193
-				foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) {
194
-					$line = $p->hook_query_headlines($line, 100);
195
-				}
166
+            $tmp = "";
196 167
 
197
-				foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_EXPORT_FEED) as $p) {
198
-					$line = $p->hook_article_export_feed($line, $feed, $is_cat);
199
-				}
168
+            $tpl->addBlock('feed');
169
+            $tpl->generateOutputToString($tmp);
200 170
 
201
-				$article = array();
171
+            if (@!clean($_REQUEST["noxml"])) {
172
+                header("Content-Type: text/xml; charset=utf-8");
173
+            } else {
174
+                header("Content-Type: text/plain; charset=utf-8");
175
+            }
202 176
 
203
-				$article['id'] = $line['link'];
204
-				$article['link']	= $line['link'];
205
-				$article['title'] = $line['title'];
206
-				$article['excerpt'] = $line["content_preview"];
207
-				$article['content'] = sanitize($line["content"], false, $owner_uid, $feed_site_url, false, $line["id"]);
208
-				$article['updated'] = date('c', strtotime($line["updated"]));
177
+            print $tmp;
178
+        } else if ($format == 'json') {
209 179
 
210
-				if ($line['note']) $article['note'] = $line['note'];
211
-				if ($article['author']) $article['author'] = $line['author'];
180
+            $feed = array();
212 181
 
213
-				$tags = Article::get_article_tags($line["id"], $owner_uid);
182
+            $feed['title'] = $feed_title;
183
+            $feed['feed_url'] = $feed_self_url;
214 184
 
215
-				if (count($tags) > 0) {
216
-					$article['tags'] = array();
185
+            $feed['self_url'] = get_self_url_prefix();
217 186
 
218
-					foreach ($tags as $tag) {
219
-						array_push($article['tags'], $tag);
220
-					}
221
-				}
187
+            $feed['articles'] = array();
222 188
 
223
-				$enclosures = Article::get_article_enclosures($line["id"]);
189
+            while ($line = $result->fetch()) {
224 190
 
225
-				if (count($enclosures) > 0) {
226
-					$article['enclosures'] = array();
191
+                $line["content_preview"] = sanitize(truncate_string(strip_tags($line["content_preview"]), 100, '...'));
227 192
 
228
-					foreach ($enclosures as $e) {
229
-						$type = $e['content_type'];
230
-						$url = $e['content_url'];
231
-						$length = $e['duration'];
193
+                foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) {
194
+                    $line = $p->hook_query_headlines($line, 100);
195
+                }
232 196
 
233
-						array_push($article['enclosures'], array("url" => $url, "type" => $type, "length" => $length));
234
-					}
235
-				}
197
+                foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_EXPORT_FEED) as $p) {
198
+                    $line = $p->hook_article_export_feed($line, $feed, $is_cat);
199
+                }
200
+
201
+                $article = array();
202
+
203
+                $article['id'] = $line['link'];
204
+                $article['link']	= $line['link'];
205
+                $article['title'] = $line['title'];
206
+                $article['excerpt'] = $line["content_preview"];
207
+                $article['content'] = sanitize($line["content"], false, $owner_uid, $feed_site_url, false, $line["id"]);
208
+                $article['updated'] = date('c', strtotime($line["updated"]));
209
+
210
+                if ($line['note']) $article['note'] = $line['note'];
211
+                if ($article['author']) $article['author'] = $line['author'];
212
+
213
+                $tags = Article::get_article_tags($line["id"], $owner_uid);
214
+
215
+                if (count($tags) > 0) {
216
+                    $article['tags'] = array();
236 217
 
237
-				array_push($feed['articles'], $article);
238
-			}
218
+                    foreach ($tags as $tag) {
219
+                        array_push($article['tags'], $tag);
220
+                    }
221
+                }
222
+
223
+                $enclosures = Article::get_article_enclosures($line["id"]);
239 224
 
240
-			header("Content-Type: text/json; charset=utf-8");
241
-			print json_encode($feed);
225
+                if (count($enclosures) > 0) {
226
+                    $article['enclosures'] = array();
242 227
 
243
-		} else {
244
-			header("Content-Type: text/plain; charset=utf-8");
245
-			print json_encode(array("error" => array("message" => "Unknown format")));
246
-		}
247
-	}
228
+                    foreach ($enclosures as $e) {
229
+                        $type = $e['content_type'];
230
+                        $url = $e['content_url'];
231
+                        $length = $e['duration'];
248 232
 
249
-	public function getUnread() {
250
-		$login = clean($_REQUEST["login"]);
251
-		$fresh = clean($_REQUEST["fresh"]) == "1";
233
+                        array_push($article['enclosures'], array("url" => $url, "type" => $type, "length" => $length));
234
+                    }
235
+                }
236
+
237
+                array_push($feed['articles'], $article);
238
+            }
252 239
 
253
-		$sth = $this->pdo->prepare("SELECT id FROM ttrss_users WHERE login = ?");
254
-		$sth->execute([$login]);
240
+            header("Content-Type: text/json; charset=utf-8");
241
+            print json_encode($feed);
255 242
 
256
-		if ($row = $sth->fetch()) {
257
-			$uid = $row["id"];
243
+        } else {
244
+            header("Content-Type: text/plain; charset=utf-8");
245
+            print json_encode(array("error" => array("message" => "Unknown format")));
246
+        }
247
+    }
258 248
 
259
-			print Feeds::getGlobalUnread($uid);
249
+    public function getUnread() {
250
+        $login = clean($_REQUEST["login"]);
251
+        $fresh = clean($_REQUEST["fresh"]) == "1";
260 252
 
261
-			if ($fresh) {
262
-				print ";";
263
-				print Feeds::getFeedArticles(-3, false, true, $uid);
264
-			}
253
+        $sth = $this->pdo->prepare("SELECT id FROM ttrss_users WHERE login = ?");
254
+        $sth->execute([$login]);
255
+
256
+        if ($row = $sth->fetch()) {
257
+            $uid = $row["id"];
258
+
259
+            print Feeds::getGlobalUnread($uid);
260
+
261
+            if ($fresh) {
262
+                print ";";
263
+                print Feeds::getFeedArticles(-3, false, true, $uid);
264
+            }
265 265
 
266
-		} else {
267
-			print "-1;User not found";
268
-		}
269
-	}
266
+        } else {
267
+            print "-1;User not found";
268
+        }
269
+    }
270 270
 
271
-	public function getProfiles() {
272
-		$login = clean($_REQUEST["login"]);
273
-		$rv = [];
271
+    public function getProfiles() {
272
+        $login = clean($_REQUEST["login"]);
273
+        $rv = [];
274 274
 
275
-		if ($login) {
276
-			$sth = $this->pdo->prepare("SELECT ttrss_settings_profiles.* FROM ttrss_settings_profiles,ttrss_users
275
+        if ($login) {
276
+            $sth = $this->pdo->prepare("SELECT ttrss_settings_profiles.* FROM ttrss_settings_profiles,ttrss_users
277 277
 			WHERE ttrss_users.id = ttrss_settings_profiles.owner_uid AND login = ? ORDER BY title");
278
-			$sth->execute([$login]);
278
+            $sth->execute([$login]);
279 279
 
280
-			$rv = [ [ "value" => 0, "label" => __("Default profile") ] ];
280
+            $rv = [ [ "value" => 0, "label" => __("Default profile") ] ];
281 281
 
282
-			while ($line = $sth->fetch()) {
283
-				$id = $line["id"];
284
-				$title = $line["title"];
282
+            while ($line = $sth->fetch()) {
283
+                $id = $line["id"];
284
+                $title = $line["title"];
285 285
 
286
-				array_push($rv, [ "label" => $title, "value" => $id ]);
287
-			}
288
-	    }
286
+                array_push($rv, [ "label" => $title, "value" => $id ]);
287
+            }
288
+        }
289 289
 
290
-		print json_encode($rv);
291
-	}
290
+        print json_encode($rv);
291
+    }
292 292
 
293
-	public function logout() {
294
-		logout_user();
295
-		header("Location: index.php");
296
-	}
293
+    public function logout() {
294
+        logout_user();
295
+        header("Location: index.php");
296
+    }
297 297
 
298
-	public function share() {
299
-		$uuid = clean($_REQUEST["key"]);
298
+    public function share() {
299
+        $uuid = clean($_REQUEST["key"]);
300 300
 
301
-		if ($uuid) {
302
-			$sth = $this->pdo->prepare("SELECT ref_id, owner_uid
301
+        if ($uuid) {
302
+            $sth = $this->pdo->prepare("SELECT ref_id, owner_uid
303 303
 						FROM ttrss_user_entries WHERE uuid = ?");
304
-			$sth->execute([$uuid]);
304
+            $sth->execute([$uuid]);
305 305
 
306
-			if ($row = $sth->fetch()) {
307
-				header("Content-Type: text/html");
306
+            if ($row = $sth->fetch()) {
307
+                header("Content-Type: text/html");
308 308
 
309
-				$id = $row["ref_id"];
310
-				$owner_uid = $row["owner_uid"];
309
+                $id = $row["ref_id"];
310
+                $owner_uid = $row["owner_uid"];
311 311
 
312
-				print $this->format_article($id, $owner_uid);
312
+                print $this->format_article($id, $owner_uid);
313 313
 
314
-				return;
315
-			}
316
-		}
314
+                return;
315
+            }
316
+        }
317 317
 
318
-		header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
319
-		print "Article not found.";
320
-	}
318
+        header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
319
+        print "Article not found.";
320
+    }
321 321
 
322
-	private function format_article($id, $owner_uid) {
322
+    private function format_article($id, $owner_uid) {
323 323
 
324
-		$pdo = Db::pdo();
324
+        $pdo = Db::pdo();
325 325
 
326
-		$sth = $pdo->prepare("SELECT id,title,link,content,feed_id,comments,int_id,lang,
326
+        $sth = $pdo->prepare("SELECT id,title,link,content,feed_id,comments,int_id,lang,
327 327
 			".SUBSTRING_FOR_DATE."(updated,1,16) as updated,
328 328
 			(SELECT site_url FROM ttrss_feeds WHERE id = feed_id) as site_url,
329 329
 			(SELECT title FROM ttrss_feeds WHERE id = feed_id) as feed_title,
@@ -337,26 +337,26 @@  discard block
 block discarded – undo
337 337
 			note
338 338
 			FROM ttrss_entries,ttrss_user_entries
339 339
 			WHERE	id = ? AND ref_id = id AND owner_uid = ?");
340
-		$sth->execute([$id, $owner_uid]);
340
+        $sth->execute([$id, $owner_uid]);
341 341
 
342
-		$rv = '';
342
+        $rv = '';
343 343
 
344
-		if ($line = $sth->fetch()) {
344
+        if ($line = $sth->fetch()) {
345 345
 
346
-			$line["tags"] = Article::get_article_tags($id, $owner_uid, $line["tag_cache"]);
347
-			unset($line["tag_cache"]);
346
+            $line["tags"] = Article::get_article_tags($id, $owner_uid, $line["tag_cache"]);
347
+            unset($line["tag_cache"]);
348 348
 
349
-			$line["content"] = sanitize($line["content"],
350
-				$line['hide_images'],
351
-				$owner_uid, $line["site_url"], false, $line["id"]);
349
+            $line["content"] = sanitize($line["content"],
350
+                $line['hide_images'],
351
+                $owner_uid, $line["site_url"], false, $line["id"]);
352 352
 
353
-			foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ARTICLE) as $p) {
354
-				$line = $p->hook_render_article($line);
355
-			}
353
+            foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ARTICLE) as $p) {
354
+                $line = $p->hook_render_article($line);
355
+            }
356 356
 
357
-			$line['content'] = DiskCache::rewriteUrls($line['content']);
357
+            $line['content'] = DiskCache::rewriteUrls($line['content']);
358 358
 
359
-			$enclosures = Article::get_article_enclosures($line["id"]);
359
+            $enclosures = Article::get_article_enclosures($line["id"]);
360 360
 
361 361
             header("Content-Type: text/html");
362 362
 
@@ -371,13 +371,13 @@  discard block
 block discarded – undo
371 371
             $rv .= "<meta property='og:title' content=\"".htmlspecialchars(html_entity_decode($line["title"], ENT_NOQUOTES | ENT_HTML401))."\"/>\n";
372 372
             $rv .= "<meta property='og:description' content=\"".
373 373
                 htmlspecialchars(
374
-                	truncate_string(
375
-                		preg_replace("/[\r\n\t]/", "",
376
-							preg_replace("/ {1,}/", " ",
377
-								strip_tags(html_entity_decode($line["content"], ENT_NOQUOTES | ENT_HTML401))
378
-							)
379
-					), 500, "...")
380
-				)."\"/>\n";
374
+                    truncate_string(
375
+                        preg_replace("/[\r\n\t]/", "",
376
+                            preg_replace("/ {1,}/", " ",
377
+                                strip_tags(html_entity_decode($line["content"], ENT_NOQUOTES | ENT_HTML401))
378
+                            )
379
+                    ), 500, "...")
380
+                )."\"/>\n";
381 381
 
382 382
             $rv .= "</head>";
383 383
 
@@ -390,132 +390,132 @@  discard block
 block discarded – undo
390 390
             $rv .= "<body class='flat ttrss_utility ttrss_zoom'>";
391 391
             $rv .= "<div class='container'>";
392 392
 
393
-			if ($line["link"]) {
394
-				$rv .= "<h1><a target='_blank' rel='noopener noreferrer'
393
+            if ($line["link"]) {
394
+                $rv .= "<h1><a target='_blank' rel='noopener noreferrer'
395 395
 					title=\"".htmlspecialchars($line['title'])."\"
396 396
 					href=\"" .htmlspecialchars($line["link"]) . "\">" .	$line["title"] . "</a></h1>";
397
-			} else {
398
-				$rv .= "<h1>" . $line["title"] . "</h1>";
399
-			}
397
+            } else {
398
+                $rv .= "<h1>" . $line["title"] . "</h1>";
399
+            }
400 400
 
401
-			$rv .= "<div class='content post'>";
401
+            $rv .= "<div class='content post'>";
402 402
 
403
-			/* header */
403
+            /* header */
404 404
 
405
-			$rv .= "<div class='header'>";
406
-			$rv .= "<div class='row'>"; # row
405
+            $rv .= "<div class='header'>";
406
+            $rv .= "<div class='row'>"; # row
407 407
 
408
-			//$entry_author = $line["author"] ? " - " . $line["author"] : "";
409
-			$parsed_updated = make_local_datetime($line["updated"], true,
410
-				$owner_uid, true);
408
+            //$entry_author = $line["author"] ? " - " . $line["author"] : "";
409
+            $parsed_updated = make_local_datetime($line["updated"], true,
410
+                $owner_uid, true);
411 411
 
412
-			$rv .= "<div>".$line['author']."</div>";
412
+            $rv .= "<div>".$line['author']."</div>";
413 413
             $rv .= "<div>$parsed_updated</div>";
414 414
 
415
-			$rv .= "</div>"; # row
415
+            $rv .= "</div>"; # row
416 416
 
417
-			$rv .= "</div>"; # header
417
+            $rv .= "</div>"; # header
418 418
 
419
-			/* content */
419
+            /* content */
420 420
 
421
-			$lang = $line['lang'] ? $line['lang'] : "en";
422
-			$rv .= "<div class='content' lang='$lang'>";
421
+            $lang = $line['lang'] ? $line['lang'] : "en";
422
+            $rv .= "<div class='content' lang='$lang'>";
423 423
 
424
-			/* content body */
424
+            /* content body */
425 425
 
426
-			$rv .= $line["content"];
426
+            $rv .= $line["content"];
427 427
 
428 428
             $rv .= Article::format_article_enclosures($id,
429 429
                 $line["always_display_enclosures"],
430 430
                 $line["content"],
431 431
                 $line["hide_images"]);
432 432
 
433
-			$rv .= "</div>"; # content
433
+            $rv .= "</div>"; # content
434 434
 
435
-			$rv .= "</div>"; # post
435
+            $rv .= "</div>"; # post
436 436
 
437
-		}
437
+        }
438 438
 
439
-		foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FORMAT_ARTICLE) as $p) {
440
-			$rv = $p->hook_format_article($rv, $line, true);
441
-		}
439
+        foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FORMAT_ARTICLE) as $p) {
440
+            $rv = $p->hook_format_article($rv, $line, true);
441
+        }
442 442
 
443
-		return $rv;
443
+        return $rv;
444 444
 
445
-	}
445
+    }
446 446
 
447
-	public function rss() {
448
-		$feed = clean($_REQUEST["id"]);
449
-		$key = clean($_REQUEST["key"]);
450
-		$is_cat = clean($_REQUEST["is_cat"]);
451
-		$limit = (int)clean($_REQUEST["limit"]);
452
-		$offset = (int)clean($_REQUEST["offset"]);
447
+    public function rss() {
448
+        $feed = clean($_REQUEST["id"]);
449
+        $key = clean($_REQUEST["key"]);
450
+        $is_cat = clean($_REQUEST["is_cat"]);
451
+        $limit = (int)clean($_REQUEST["limit"]);
452
+        $offset = (int)clean($_REQUEST["offset"]);
453 453
 
454
-		$search = clean($_REQUEST["q"]);
455
-		$view_mode = clean($_REQUEST["view-mode"]);
456
-		$order = clean($_REQUEST["order"]);
457
-		$start_ts = clean($_REQUEST["ts"]);
454
+        $search = clean($_REQUEST["q"]);
455
+        $view_mode = clean($_REQUEST["view-mode"]);
456
+        $order = clean($_REQUEST["order"]);
457
+        $start_ts = clean($_REQUEST["ts"]);
458 458
 
459
-		$format = clean($_REQUEST['format']);
460
-		$orig_guid = clean($_REQUEST["orig_guid"]);
459
+        $format = clean($_REQUEST['format']);
460
+        $orig_guid = clean($_REQUEST["orig_guid"]);
461 461
 
462
-		if (!$format) $format = 'atom';
462
+        if (!$format) $format = 'atom';
463 463
 
464
-		if (SINGLE_USER_MODE) {
465
-			authenticate_user("admin", null);
466
-		}
464
+        if (SINGLE_USER_MODE) {
465
+            authenticate_user("admin", null);
466
+        }
467 467
 
468
-		$owner_id = false;
468
+        $owner_id = false;
469 469
 
470
-		if ($key) {
471
-			$sth = $this->pdo->prepare("SELECT owner_uid FROM
470
+        if ($key) {
471
+            $sth = $this->pdo->prepare("SELECT owner_uid FROM
472 472
 				ttrss_access_keys WHERE access_key = ? AND feed_id = ?");
473
-			$sth->execute([$key, $feed]);
473
+            $sth->execute([$key, $feed]);
474 474
 
475
-			if ($row = $sth->fetch())
476
-				$owner_id = $row["owner_uid"];
477
-		}
475
+            if ($row = $sth->fetch())
476
+                $owner_id = $row["owner_uid"];
477
+        }
478 478
 
479
-		if ($owner_id) {
480
-			$this->generate_syndicated_feed($owner_id, $feed, $is_cat, $limit,
481
-				$offset, $search, $view_mode, $format, $order, $orig_guid, $start_ts);
482
-		} else {
483
-			header('HTTP/1.1 403 Forbidden');
484
-		}
485
-	}
479
+        if ($owner_id) {
480
+            $this->generate_syndicated_feed($owner_id, $feed, $is_cat, $limit,
481
+                $offset, $search, $view_mode, $format, $order, $orig_guid, $start_ts);
482
+        } else {
483
+            header('HTTP/1.1 403 Forbidden');
484
+        }
485
+    }
486 486
 
487
-	public function updateTask() {
488
-		PluginHost::getInstance()->run_hooks(PluginHost::HOOK_UPDATE_TASK, "hook_update_task", false);
489
-	}
487
+    public function updateTask() {
488
+        PluginHost::getInstance()->run_hooks(PluginHost::HOOK_UPDATE_TASK, "hook_update_task", false);
489
+    }
490 490
 
491
-	public function housekeepingTask() {
492
-		PluginHost::getInstance()->run_hooks(PluginHost::HOOK_HOUSE_KEEPING, "hook_house_keeping", false);
493
-	}
491
+    public function housekeepingTask() {
492
+        PluginHost::getInstance()->run_hooks(PluginHost::HOOK_HOUSE_KEEPING, "hook_house_keeping", false);
493
+    }
494 494
 
495
-	public function globalUpdateFeeds() {
496
-		RPC::updaterandomfeed_real();
495
+    public function globalUpdateFeeds() {
496
+        RPC::updaterandomfeed_real();
497 497
 
498
-		PluginHost::getInstance()->run_hooks(PluginHost::HOOK_UPDATE_TASK, "hook_update_task", false);
499
-	}
498
+        PluginHost::getInstance()->run_hooks(PluginHost::HOOK_UPDATE_TASK, "hook_update_task", false);
499
+    }
500 500
 
501
-	public function sharepopup() {
502
-		if (SINGLE_USER_MODE) {
503
-			login_sequence();
504
-		}
501
+    public function sharepopup() {
502
+        if (SINGLE_USER_MODE) {
503
+            login_sequence();
504
+        }
505 505
 
506
-		header('Content-Type: text/html; charset=utf-8');
507
-		?>
506
+        header('Content-Type: text/html; charset=utf-8');
507
+        ?>
508 508
 		<!DOCTYPE html>
509 509
 		<html>
510 510
 		<head>
511 511
 			<title><?php echo __("Share with Tiny Tiny RSS") ?></title>
512 512
 			<?php
513
-			echo stylesheet_tag("css/default.css");
514
-			echo javascript_tag("lib/prototype.js");
515
-			echo javascript_tag("lib/dojo/dojo.js");
516
-			echo javascript_tag("lib/dojo/tt-rss-layer.js");
517
-			echo javascript_tag("lib/scriptaculous/scriptaculous.js?load=effects,controls")
518
-			?>
513
+            echo stylesheet_tag("css/default.css");
514
+            echo javascript_tag("lib/prototype.js");
515
+            echo javascript_tag("lib/dojo/dojo.js");
516
+            echo javascript_tag("lib/dojo/tt-rss-layer.js");
517
+            echo javascript_tag("lib/scriptaculous/scriptaculous.js?load=effects,controls")
518
+            ?>
519 519
 			<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
520 520
 			<link rel="shortcut icon" type="image/png" href="images/favicon.png">
521 521
 			<link rel="icon" type="image/png" sizes="72x72" href="images/favicon-72px.png">
@@ -537,29 +537,29 @@  discard block
 block discarded – undo
537 537
 
538 538
 		<?php
539 539
 
540
-		$action = clean($_REQUEST["action"]);
540
+        $action = clean($_REQUEST["action"]);
541 541
 
542
-		if ($_SESSION["uid"]) {
542
+        if ($_SESSION["uid"]) {
543 543
 
544
-			if ($action == 'share') {
544
+            if ($action == 'share') {
545 545
 
546
-				$title = strip_tags(clean($_REQUEST["title"]));
547
-				$url = strip_tags(clean($_REQUEST["url"]));
548
-				$content = strip_tags(clean($_REQUEST["content"]));
549
-				$labels = strip_tags(clean($_REQUEST["labels"]));
546
+                $title = strip_tags(clean($_REQUEST["title"]));
547
+                $url = strip_tags(clean($_REQUEST["url"]));
548
+                $content = strip_tags(clean($_REQUEST["content"]));
549
+                $labels = strip_tags(clean($_REQUEST["labels"]));
550 550
 
551
-				Article::create_published_article($title, $url, $content, $labels,
552
-					$_SESSION["uid"]);
551
+                Article::create_published_article($title, $url, $content, $labels,
552
+                    $_SESSION["uid"]);
553 553
 
554
-				print "<script type='text/javascript'>";
555
-				print "window.close();";
556
-				print "</script>";
554
+                print "<script type='text/javascript'>";
555
+                print "window.close();";
556
+                print "</script>";
557 557
 
558
-			} else {
559
-				$title = htmlspecialchars(clean($_REQUEST["title"]));
560
-				$url = htmlspecialchars(clean($_REQUEST["url"]));
558
+            } else {
559
+                $title = htmlspecialchars(clean($_REQUEST["title"]));
560
+                $url = htmlspecialchars(clean($_REQUEST["url"]));
561 561
 
562
-				?>
562
+                ?>
563 563
 				<form id='share_form' name='share_form'>
564 564
 
565 565
 					<input type="hidden" name="op" value="sharepopup">
@@ -599,12 +599,12 @@  discard block
 block discarded – undo
599 599
 				</form>
600 600
 				<?php
601 601
 
602
-			}
602
+            }
603 603
 
604
-		} else {
604
+        } else {
605 605
 
606
-			$return = urlencode(make_self_url());
607
-			print_error("Not logged in"); ?>
606
+            $return = urlencode(make_self_url());
607
+            print_error("Not logged in"); ?>
608 608
 
609 609
 			<form action="public.php?return=<?php echo $return ?>" method="post">
610 610
 
@@ -636,90 +636,90 @@  discard block
 block discarded – undo
636 636
 
637 637
 			</form>
638 638
 			<?php
639
-		}
639
+        }
640 640
 
641
-		print "</div></body></html>";
642
-	}
641
+        print "</div></body></html>";
642
+    }
643 643
 
644
-	public function login() {
645
-		if (!SINGLE_USER_MODE) {
644
+    public function login() {
645
+        if (!SINGLE_USER_MODE) {
646 646
 
647
-			$login = clean($_POST["login"]);
648
-			$password = clean($_POST["password"]);
649
-			$remember_me = clean($_POST["remember_me"]);
647
+            $login = clean($_POST["login"]);
648
+            $password = clean($_POST["password"]);
649
+            $remember_me = clean($_POST["remember_me"]);
650 650
 
651
-			if ($remember_me) {
652
-				session_set_cookie_params(SESSION_COOKIE_LIFETIME);
653
-			} else {
654
-				session_set_cookie_params(0);
655
-			}
651
+            if ($remember_me) {
652
+                session_set_cookie_params(SESSION_COOKIE_LIFETIME);
653
+            } else {
654
+                session_set_cookie_params(0);
655
+            }
656 656
 
657
-			if (authenticate_user($login, $password)) {
658
-				$_POST["password"] = "";
657
+            if (authenticate_user($login, $password)) {
658
+                $_POST["password"] = "";
659 659
 
660
-				if (get_schema_version() >= 120) {
661
-					$_SESSION["language"] = get_pref("USER_LANGUAGE", $_SESSION["uid"]);
662
-				}
660
+                if (get_schema_version() >= 120) {
661
+                    $_SESSION["language"] = get_pref("USER_LANGUAGE", $_SESSION["uid"]);
662
+                }
663 663
 
664
-				$_SESSION["ref_schema_version"] = get_schema_version(true);
665
-				$_SESSION["bw_limit"] = !!clean($_POST["bw_limit"]);
664
+                $_SESSION["ref_schema_version"] = get_schema_version(true);
665
+                $_SESSION["bw_limit"] = !!clean($_POST["bw_limit"]);
666 666
 
667
-				if (clean($_POST["profile"])) {
667
+                if (clean($_POST["profile"])) {
668 668
 
669
-					$profile = (int) clean($_POST["profile"]);
669
+                    $profile = (int) clean($_POST["profile"]);
670 670
 
671
-					$sth = $this->pdo->prepare("SELECT id FROM ttrss_settings_profiles
671
+                    $sth = $this->pdo->prepare("SELECT id FROM ttrss_settings_profiles
672 672
 						WHERE id = ? AND owner_uid = ?");
673
-					$sth->execute([$profile, $_SESSION['uid']]);
673
+                    $sth->execute([$profile, $_SESSION['uid']]);
674 674
 
675
-					if ($sth->fetch()) {
676
-						$_SESSION["profile"] = $profile;
677
- 					} else {
678
-					    $_SESSION["profile"] = null;
675
+                    if ($sth->fetch()) {
676
+                        $_SESSION["profile"] = $profile;
677
+                        } else {
678
+                        $_SESSION["profile"] = null;
679 679
                     }
680
-				}
681
-			} else {
680
+                }
681
+            } else {
682 682
 
683
-				// start an empty session to deliver login error message
684
-				@session_start();
683
+                // start an empty session to deliver login error message
684
+                @session_start();
685 685
 
686
-				if (!isset($_SESSION["login_error_msg"]))
687
-					$_SESSION["login_error_msg"] = __("Incorrect username or password");
686
+                if (!isset($_SESSION["login_error_msg"]))
687
+                    $_SESSION["login_error_msg"] = __("Incorrect username or password");
688 688
 
689
-				user_error("Failed login attempt for $login from {$_SERVER['REMOTE_ADDR']}", E_USER_WARNING);
690
-			}
689
+                user_error("Failed login attempt for $login from {$_SERVER['REMOTE_ADDR']}", E_USER_WARNING);
690
+            }
691 691
 
692
-			$return = clean($_REQUEST['return']);
692
+            $return = clean($_REQUEST['return']);
693 693
 
694
-			if ($_REQUEST['return'] && mb_strpos($return, SELF_URL_PATH) === 0) {
695
-				header("Location: " . clean($_REQUEST['return']));
696
-			} else {
697
-				header("Location: " . get_self_url_prefix());
698
-			}
699
-		}
700
-	}
694
+            if ($_REQUEST['return'] && mb_strpos($return, SELF_URL_PATH) === 0) {
695
+                header("Location: " . clean($_REQUEST['return']));
696
+            } else {
697
+                header("Location: " . get_self_url_prefix());
698
+            }
699
+        }
700
+    }
701 701
 
702
-	public function subscribe() {
703
-		if (SINGLE_USER_MODE) {
704
-			login_sequence();
705
-		}
702
+    public function subscribe() {
703
+        if (SINGLE_USER_MODE) {
704
+            login_sequence();
705
+        }
706 706
 
707
-		if ($_SESSION["uid"]) {
707
+        if ($_SESSION["uid"]) {
708 708
 
709
-			$feed_url = trim(clean($_REQUEST["feed_url"]));
709
+            $feed_url = trim(clean($_REQUEST["feed_url"]));
710 710
 
711
-			header('Content-Type: text/html; charset=utf-8');
712
-			?>
711
+            header('Content-Type: text/html; charset=utf-8');
712
+            ?>
713 713
 			<!DOCTYPE html>
714 714
 			<html>
715 715
 			<head>
716 716
 				<title>Tiny Tiny RSS</title>
717 717
 				<?php
718
-					echo stylesheet_tag("css/default.css");
719
-					echo javascript_tag("lib/prototype.js");
720
-					echo javascript_tag("lib/dojo/dojo.js");
721
-					echo javascript_tag("lib/dojo/tt-rss-layer.js");
722
-				?>
718
+                    echo stylesheet_tag("css/default.css");
719
+                    echo javascript_tag("lib/prototype.js");
720
+                    echo javascript_tag("lib/dojo/dojo.js");
721
+                    echo javascript_tag("lib/dojo/tt-rss-layer.js");
722
+                ?>
723 723
 				<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
724 724
 				<link rel="shortcut icon" type="image/png" href="images/favicon.png">
725 725
 				<link rel="icon" type="image/png" sizes="72x72" href="images/favicon-72px.png">
@@ -738,8 +738,8 @@  discard block
 block discarded – undo
738 738
 			<div class='content'>
739 739
 			<?php
740 740
 
741
-			if (!$feed_url) {
742
-				?>
741
+            if (!$feed_url) {
742
+                ?>
743 743
 				<form method="post">
744 744
 					<input type="hidden" name="op" value="subscribe">
745 745
 					<fieldset>
@@ -754,101 +754,101 @@  discard block
 block discarded – undo
754 754
 					<a href="index.php"><?php echo __("Return to Tiny Tiny RSS") ?></a>
755 755
 				</form>
756 756
 				<?php
757
-			} else {
758
-
759
-				$rc = Feeds::subscribe_to_feed($feed_url);
760
-				$feed_urls = false;
761
-
762
-				switch ($rc['code']) {
763
-					case 0:
764
-						print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
765
-						break;
766
-					case 1:
767
-						print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
768
-						break;
769
-					case 2:
770
-						print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url));
771
-						break;
772
-					case 3:
773
-						print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url));
774
-						break;
775
-					case 4:
776
-						$feed_urls = $rc["feeds"];
777
-						break;
778
-					case 5:
779
-						print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url));
780
-						break;
781
-				}
782
-
783
-				if ($feed_urls) {
784
-
785
-					print "<form action='public.php'>";
786
-					print "<input type='hidden' name='op' value='subscribe'>";
787
-
788
-					print "<fieldset>";
789
-					print "<label style='display : inline'>" . __("Multiple feed URLs found:") . "</label>";
790
-					print "<select name='feed_url' dojoType='dijit.form.Select'>";
791
-
792
-					foreach ($feed_urls as $url => $name) {
793
-						$url = htmlspecialchars($url);
794
-						$name = htmlspecialchars($name);
795
-
796
-						print "<option value=\"$url\">$name</option>";
797
-					}
757
+            } else {
758
+
759
+                $rc = Feeds::subscribe_to_feed($feed_url);
760
+                $feed_urls = false;
761
+
762
+                switch ($rc['code']) {
763
+                    case 0:
764
+                        print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
765
+                        break;
766
+                    case 1:
767
+                        print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
768
+                        break;
769
+                    case 2:
770
+                        print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url));
771
+                        break;
772
+                    case 3:
773
+                        print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url));
774
+                        break;
775
+                    case 4:
776
+                        $feed_urls = $rc["feeds"];
777
+                        break;
778
+                    case 5:
779
+                        print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url));
780
+                        break;
781
+                }
782
+
783
+                if ($feed_urls) {
784
+
785
+                    print "<form action='public.php'>";
786
+                    print "<input type='hidden' name='op' value='subscribe'>";
787
+
788
+                    print "<fieldset>";
789
+                    print "<label style='display : inline'>" . __("Multiple feed URLs found:") . "</label>";
790
+                    print "<select name='feed_url' dojoType='dijit.form.Select'>";
791
+
792
+                    foreach ($feed_urls as $url => $name) {
793
+                        $url = htmlspecialchars($url);
794
+                        $name = htmlspecialchars($name);
795
+
796
+                        print "<option value=\"$url\">$name</option>";
797
+                    }
798 798
 
799
-					print "</select>";
800
-					print "</fieldset>";
799
+                    print "</select>";
800
+                    print "</fieldset>";
801 801
 
802
-					print "<button class='alt-primary' dojoType='dijit.form.Button' type='submit'>".__("Subscribe to selected feed")."</button>";
803
-					print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>";
802
+                    print "<button class='alt-primary' dojoType='dijit.form.Button' type='submit'>".__("Subscribe to selected feed")."</button>";
803
+                    print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>";
804 804
 
805
-					print "</form>";
806
-				}
805
+                    print "</form>";
806
+                }
807 807
 
808
-				$tp_uri = get_self_url_prefix() . "/prefs.php";
808
+                $tp_uri = get_self_url_prefix() . "/prefs.php";
809 809
 
810
-				if ($rc['code'] <= 2){
811
-					$sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE
810
+                if ($rc['code'] <= 2){
811
+                    $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE
812 812
 					feed_url = ? AND owner_uid = ?");
813
-					$sth->execute([$feed_url, $_SESSION['uid']]);
814
-					$row = $sth->fetch();
813
+                    $sth->execute([$feed_url, $_SESSION['uid']]);
814
+                    $row = $sth->fetch();
815 815
 
816
-					$feed_id = $row["id"];
817
-				} else {
818
-					$feed_id = 0;
819
-				}
816
+                    $feed_id = $row["id"];
817
+                } else {
818
+                    $feed_id = 0;
819
+                }
820 820
 
821
-				if ($feed_id) {
822
-					print "<form method='GET' action=\"$tp_uri\">
821
+                if ($feed_id) {
822
+                    print "<form method='GET' action=\"$tp_uri\">
823 823
 					<input type='hidden' name='tab' value='feedConfig'>
824 824
 					<input type='hidden' name='method' value='editfeed'>
825 825
 					<input type='hidden' name='methodparam' value='$feed_id'>
826 826
 					<button dojoType='dijit.form.Button' class='alt-info' type='submit'>".__("Edit subscription options")."</button>
827 827
 					<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>
828 828
 					</form>";
829
-				}
830
-			}
829
+                }
830
+            }
831 831
 
832
-			print "</div></div></body></html>";
832
+            print "</div></div></body></html>";
833 833
 
834
-		} else {
835
-			render_login_form();
836
-		}
837
-	}
834
+        } else {
835
+            render_login_form();
836
+        }
837
+    }
838 838
 
839
-	public function index() {
840
-		header("Content-Type: text/plain");
841
-		print error_json(13);
842
-	}
839
+    public function index() {
840
+        header("Content-Type: text/plain");
841
+        print error_json(13);
842
+    }
843 843
 
844
-	public function forgotpass() {
845
-		startup_gettext();
846
-		session_start();
844
+    public function forgotpass() {
845
+        startup_gettext();
846
+        session_start();
847 847
 
848
-		@$hash = clean($_REQUEST["hash"]);
848
+        @$hash = clean($_REQUEST["hash"]);
849 849
 
850
-		header('Content-Type: text/html; charset=utf-8');
851
-		?>
850
+        header('Content-Type: text/html; charset=utf-8');
851
+        ?>
852 852
 		<!DOCTYPE html>
853 853
 		<html>
854 854
 		<head>
@@ -857,11 +857,11 @@  discard block
 block discarded – undo
857 857
 			<link rel="icon" type="image/png" sizes="72x72" href="images/favicon-72px.png">
858 858
 			<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
859 859
 			<?php
860
-				echo stylesheet_tag("css/default.css");
861
-				echo javascript_tag("lib/prototype.js");
862
-				echo javascript_tag("lib/dojo/dojo.js");
863
-				echo javascript_tag("lib/dojo/tt-rss-layer.js");
864
-			?>
860
+                echo stylesheet_tag("css/default.css");
861
+                echo javascript_tag("lib/prototype.js");
862
+                echo javascript_tag("lib/dojo/dojo.js");
863
+                echo javascript_tag("lib/dojo/tt-rss-layer.js");
864
+            ?>
865 865
 		</head>
866 866
 		<body class='flat ttrss_utility'>
867 867
 		<div class='container'>
@@ -876,52 +876,52 @@  discard block
 block discarded – undo
876 876
 		</script>
877 877
 		<?php
878 878
 
879
-		print "<h1>".__("Password recovery")."</h1>";
880
-		print "<div class='content'>";
879
+        print "<h1>".__("Password recovery")."</h1>";
880
+        print "<div class='content'>";
881 881
 
882
-		@$method = clean($_POST['method']);
882
+        @$method = clean($_POST['method']);
883 883
 
884
-		if ($hash) {
885
-			$login = clean($_REQUEST["login"]);
884
+        if ($hash) {
885
+            $login = clean($_REQUEST["login"]);
886 886
 
887
-			if ($login) {
888
-				$sth = $this->pdo->prepare("SELECT id, resetpass_token FROM ttrss_users
887
+            if ($login) {
888
+                $sth = $this->pdo->prepare("SELECT id, resetpass_token FROM ttrss_users
889 889
 					WHERE login = ?");
890
-				$sth->execute([$login]);
890
+                $sth->execute([$login]);
891 891
 
892
-				if ($row = $sth->fetch()) {
893
-					$id = $row["id"];
894
-					$resetpass_token_full = $row["resetpass_token"];
895
-					list($timestamp, $resetpass_token) = explode(":", $resetpass_token_full);
892
+                if ($row = $sth->fetch()) {
893
+                    $id = $row["id"];
894
+                    $resetpass_token_full = $row["resetpass_token"];
895
+                    list($timestamp, $resetpass_token) = explode(":", $resetpass_token_full);
896 896
 
897
-					if ($timestamp && $resetpass_token &&
898
-						$timestamp >= time() - 15*60*60 &&
899
-						$resetpass_token == $hash) {
897
+                    if ($timestamp && $resetpass_token &&
898
+                        $timestamp >= time() - 15*60*60 &&
899
+                        $resetpass_token == $hash) {
900 900
 
901
-							$sth = $this->pdo->prepare("UPDATE ttrss_users SET resetpass_token = NULL
901
+                            $sth = $this->pdo->prepare("UPDATE ttrss_users SET resetpass_token = NULL
902 902
 								WHERE id = ?");
903
-							$sth->execute([$id]);
903
+                            $sth->execute([$id]);
904 904
 
905
-							Pref_Users::resetUserPassword($id, true);
905
+                            Pref_Users::resetUserPassword($id, true);
906 906
 
907
-							print "<p>"."Completed."."</p>";
907
+                            print "<p>"."Completed."."</p>";
908 908
 
909
-					} else {
910
-						print_error("Some of the information provided is missing or incorrect.");
911
-					}
912
-				} else {
913
-					print_error("Some of the information provided is missing or incorrect.");
914
-				}
915
-			} else {
916
-				print_error("Some of the information provided is missing or incorrect.");
917
-			}
909
+                    } else {
910
+                        print_error("Some of the information provided is missing or incorrect.");
911
+                    }
912
+                } else {
913
+                    print_error("Some of the information provided is missing or incorrect.");
914
+                }
915
+            } else {
916
+                print_error("Some of the information provided is missing or incorrect.");
917
+            }
918 918
 
919
-			print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>";
919
+            print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>";
920 920
 
921
-		} else if (!$method) {
922
-			print_notice(__("You will need to provide valid account name and email. Password reset link will be sent to your email address."));
921
+        } else if (!$method) {
922
+            print_notice(__("You will need to provide valid account name and email. Password reset link will be sent to your email address."));
923 923
 
924
-			print "<form method='POST' action='public.php'>
924
+            print "<form method='POST' action='public.php'>
925 925
 				<input type='hidden' name='method' value='do'>
926 926
 				<input type='hidden' name='op' value='forgotpass'>
927 927
 
@@ -935,10 +935,10 @@  discard block
 block discarded – undo
935 935
 				<input dojoType='dijit.form.TextBox' type='email' name='email' value='' required>
936 936
 				</fieldset>";
937 937
 
938
-			$_SESSION["pwdreset:testvalue1"] = rand(1,10);
939
-			$_SESSION["pwdreset:testvalue2"] = rand(1,10);
938
+            $_SESSION["pwdreset:testvalue1"] = rand(1,10);
939
+            $_SESSION["pwdreset:testvalue2"] = rand(1,10);
940 940
 
941
-			print "<fieldset>
941
+            print "<fieldset>
942 942
 				<label>".T_sprintf("How much is %d + %d:", $_SESSION["pwdreset:testvalue1"], $_SESSION["pwdreset:testvalue2"])."</label>
943 943
 				<input dojoType='dijit.form.TextBox' type='text' name='test' value='' required>
944 944
 				</fieldset>
@@ -950,109 +950,109 @@  discard block
 block discarded – undo
950 950
 				</fieldset>
951 951
 
952 952
 				</form>";
953
-		} else if ($method == 'do') {
953
+        } else if ($method == 'do') {
954 954
 
955
-			$login = clean($_POST["login"]);
956
-			$email = clean($_POST["email"]);
957
-			$test = clean($_POST["test"]);
955
+            $login = clean($_POST["login"]);
956
+            $email = clean($_POST["email"]);
957
+            $test = clean($_POST["test"]);
958 958
 
959
-			if ($test != ($_SESSION["pwdreset:testvalue1"] + $_SESSION["pwdreset:testvalue2"]) || !$email || !$login) {
960
-				print_error(__('Some of the required form parameters are missing or incorrect.'));
959
+            if ($test != ($_SESSION["pwdreset:testvalue1"] + $_SESSION["pwdreset:testvalue2"]) || !$email || !$login) {
960
+                print_error(__('Some of the required form parameters are missing or incorrect.'));
961 961
 
962
-				print "<form method='GET' action='public.php'>
962
+                print "<form method='GET' action='public.php'>
963 963
 					<input type='hidden' name='op' value='forgotpass'>
964 964
 					<button dojoType='dijit.form.Button' type='submit' class='alt-primary'>".__("Go back")."</button>
965 965
 					</form>";
966 966
 
967
-			} else {
967
+            } else {
968 968
 
969
-				// prevent submitting this form multiple times
970
-				$_SESSION["pwdreset:testvalue1"] = rand(1, 1000);
971
-				$_SESSION["pwdreset:testvalue2"] = rand(1, 1000);
969
+                // prevent submitting this form multiple times
970
+                $_SESSION["pwdreset:testvalue1"] = rand(1, 1000);
971
+                $_SESSION["pwdreset:testvalue2"] = rand(1, 1000);
972 972
 
973
-				$sth = $this->pdo->prepare("SELECT id FROM ttrss_users
973
+                $sth = $this->pdo->prepare("SELECT id FROM ttrss_users
974 974
 					WHERE login = ? AND email = ?");
975
-				$sth->execute([$login, $email]);
975
+                $sth->execute([$login, $email]);
976 976
 
977
-				if ($row = $sth->fetch()) {
978
-					print_notice("Password reset instructions are being sent to your email address.");
977
+                if ($row = $sth->fetch()) {
978
+                    print_notice("Password reset instructions are being sent to your email address.");
979 979
 
980
-					$id = $row["id"];
980
+                    $id = $row["id"];
981 981
 
982
-					if ($id) {
983
-						$resetpass_token = sha1(get_random_bytes(128));
984
-						$resetpass_link = get_self_url_prefix() . "/public.php?op=forgotpass&hash=" . $resetpass_token .
985
-							"&login=" . urlencode($login);
982
+                    if ($id) {
983
+                        $resetpass_token = sha1(get_random_bytes(128));
984
+                        $resetpass_link = get_self_url_prefix() . "/public.php?op=forgotpass&hash=" . $resetpass_token .
985
+                            "&login=" . urlencode($login);
986 986
 
987
-						require_once "lib/MiniTemplator.class.php";
987
+                        require_once "lib/MiniTemplator.class.php";
988 988
 
989
-						$tpl = new MiniTemplator;
989
+                        $tpl = new MiniTemplator;
990 990
 
991
-						$tpl->readTemplateFromFile("templates/resetpass_link_template.txt");
991
+                        $tpl->readTemplateFromFile("templates/resetpass_link_template.txt");
992 992
 
993
-						$tpl->setVariable('LOGIN', $login);
994
-						$tpl->setVariable('RESETPASS_LINK', $resetpass_link);
995
-						$tpl->setVariable('TTRSS_HOST', SELF_URL_PATH);
993
+                        $tpl->setVariable('LOGIN', $login);
994
+                        $tpl->setVariable('RESETPASS_LINK', $resetpass_link);
995
+                        $tpl->setVariable('TTRSS_HOST', SELF_URL_PATH);
996 996
 
997
-						$tpl->addBlock('message');
997
+                        $tpl->addBlock('message');
998 998
 
999
-						$message = "";
999
+                        $message = "";
1000 1000
 
1001
-						$tpl->generateOutputToString($message);
1001
+                        $tpl->generateOutputToString($message);
1002 1002
 
1003
-						$mailer = new Mailer();
1003
+                        $mailer = new Mailer();
1004 1004
 
1005
-						$rc = $mailer->mail(["to_name" => $login,
1006
-							"to_address" => $email,
1007
-							"subject" => __("[tt-rss] Password reset request"),
1008
-							"message" => $message]);
1005
+                        $rc = $mailer->mail(["to_name" => $login,
1006
+                            "to_address" => $email,
1007
+                            "subject" => __("[tt-rss] Password reset request"),
1008
+                            "message" => $message]);
1009 1009
 
1010
-						if (!$rc) print_error($mailer->error());
1010
+                        if (!$rc) print_error($mailer->error());
1011 1011
 
1012
-						$resetpass_token_full = time() . ":" . $resetpass_token;
1012
+                        $resetpass_token_full = time() . ":" . $resetpass_token;
1013 1013
 
1014
-						$sth = $this->pdo->prepare("UPDATE ttrss_users
1014
+                        $sth = $this->pdo->prepare("UPDATE ttrss_users
1015 1015
 							SET resetpass_token = ?
1016 1016
 							WHERE login = ? AND email = ?");
1017 1017
 
1018
-						$sth->execute([$resetpass_token_full, $login, $email]);
1018
+                        $sth->execute([$resetpass_token_full, $login, $email]);
1019 1019
 
1020
-					} else {
1021
-						print_error("User ID not found.");
1022
-					}
1020
+                    } else {
1021
+                        print_error("User ID not found.");
1022
+                    }
1023 1023
 
1024
-					print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>";
1024
+                    print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>";
1025 1025
 
1026
-				} else {
1027
-					print_error(__("Sorry, login and email combination not found."));
1026
+                } else {
1027
+                    print_error(__("Sorry, login and email combination not found."));
1028 1028
 
1029
-					print "<form method='GET' action='public.php'>
1029
+                    print "<form method='GET' action='public.php'>
1030 1030
 						<input type='hidden' name='op' value='forgotpass'>
1031 1031
 						<button dojoType='dijit.form.Button' type='submit'>".__("Go back")."</button>
1032 1032
 						</form>";
1033 1033
 
1034
-				}
1035
-			}
1034
+                }
1035
+            }
1036 1036
 
1037
-		}
1037
+        }
1038 1038
 
1039
-		print "</div>";
1040
-		print "</div>";
1041
-		print "</body>";
1042
-		print "</html>";
1039
+        print "</div>";
1040
+        print "</div>";
1041
+        print "</body>";
1042
+        print "</html>";
1043 1043
 
1044
-	}
1044
+    }
1045 1045
 
1046
-	public function dbupdate() {
1047
-		startup_gettext();
1046
+    public function dbupdate() {
1047
+        startup_gettext();
1048 1048
 
1049
-		if (!SINGLE_USER_MODE && $_SESSION["access_level"] < 10) {
1050
-			$_SESSION["login_error_msg"] = __("Your access level is insufficient to run this script.");
1051
-			render_login_form();
1052
-			exit;
1053
-		}
1049
+        if (!SINGLE_USER_MODE && $_SESSION["access_level"] < 10) {
1050
+            $_SESSION["login_error_msg"] = __("Your access level is insufficient to run this script.");
1051
+            render_login_form();
1052
+            exit;
1053
+        }
1054 1054
 
1055
-		?>
1055
+        ?>
1056 1056
 		<!DOCTYPE html>
1057 1057
 		<html>
1058 1058
 			<head>
@@ -1062,11 +1062,11 @@  discard block
 block discarded – undo
1062 1062
 			<link rel="shortcut icon" type="image/png" href="images/favicon.png">
1063 1063
 			<link rel="icon" type="image/png" sizes="72x72" href="images/favicon-72px.png">
1064 1064
 			<?php
1065
-				echo stylesheet_tag("css/default.css");
1066
-				echo javascript_tag("lib/prototype.js");
1067
-				echo javascript_tag("lib/dojo/dojo.js");
1068
-				echo javascript_tag("lib/dojo/tt-rss-layer.js");
1069
-			?>
1065
+                echo stylesheet_tag("css/default.css");
1066
+                echo javascript_tag("lib/prototype.js");
1067
+                echo javascript_tag("lib/dojo/dojo.js");
1068
+                echo javascript_tag("lib/dojo/tt-rss-layer.js");
1069
+            ?>
1070 1070
 			<style type="text/css">
1071 1071
 				span.ok { color : #009000; font-weight : bold; }
1072 1072
 				span.err { color : #ff0000; font-weight : bold; }
@@ -1093,139 +1093,139 @@  discard block
 block discarded – undo
1093 1093
 			<div class="content">
1094 1094
 
1095 1095
 			<?php
1096
-				@$op = clean($_REQUEST["subop"]);
1097
-				$updater = new DbUpdater(DB_TYPE, SCHEMA_VERSION);
1096
+                @$op = clean($_REQUEST["subop"]);
1097
+                $updater = new DbUpdater(DB_TYPE, SCHEMA_VERSION);
1098 1098
 
1099
-				if ($op == "performupdate") {
1100
-					if ($updater->isUpdateRequired()) {
1099
+                if ($op == "performupdate") {
1100
+                    if ($updater->isUpdateRequired()) {
1101 1101
 
1102
-						print "<h2>" . T_sprintf("Performing updates to version %d", SCHEMA_VERSION) . "</h2>";
1102
+                        print "<h2>" . T_sprintf("Performing updates to version %d", SCHEMA_VERSION) . "</h2>";
1103 1103
 
1104
-						for ($i = $updater->getSchemaVersion() + 1; $i <= SCHEMA_VERSION; $i++) {
1105
-							print "<ul>";
1104
+                        for ($i = $updater->getSchemaVersion() + 1; $i <= SCHEMA_VERSION; $i++) {
1105
+                            print "<ul>";
1106 1106
 
1107
-							print "<li class='text-info'>" . T_sprintf("Updating to version %d", $i) . "</li>";
1107
+                            print "<li class='text-info'>" . T_sprintf("Updating to version %d", $i) . "</li>";
1108 1108
 
1109
-							print "<li>";
1110
-							$result = $updater->performUpdateTo($i, true);
1111
-							print "</li>";
1109
+                            print "<li>";
1110
+                            $result = $updater->performUpdateTo($i, true);
1111
+                            print "</li>";
1112 1112
 
1113
-							if (!$result) {
1114
-								print "</ul>";
1113
+                            if (!$result) {
1114
+                                print "</ul>";
1115 1115
 
1116
-								print_error("One of the updates failed. Either retry the process or perform updates manually.");
1116
+                                print_error("One of the updates failed. Either retry the process or perform updates manually.");
1117 1117
 
1118
-								print "<form method='POST'>
1118
+                                print "<form method='POST'>
1119 1119
 									<input type='hidden' name='subop' value='performupdate'>
1120 1120
 									<button type='submit' dojoType='dijit.form.Button' class='alt-danger' onclick='return confirmOP()'>".__("Try again")."</button>
1121 1121
 									<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>
1122 1122
 								</form>";
1123 1123
 
1124
-								return;
1125
-							} else {
1126
-								print "<li class='text-success'>" . __("Completed.") . "</li>";
1127
-								print "</ul>";
1128
-							}
1129
-						}
1124
+                                return;
1125
+                            } else {
1126
+                                print "<li class='text-success'>" . __("Completed.") . "</li>";
1127
+                                print "</ul>";
1128
+                            }
1129
+                        }
1130 1130
 
1131
-						print_notice("Your Tiny Tiny RSS database is now updated to the latest version.");
1131
+                        print_notice("Your Tiny Tiny RSS database is now updated to the latest version.");
1132 1132
 
1133
-						print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>";
1133
+                        print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>";
1134 1134
 
1135
-					} else {
1136
-						print_notice("Tiny Tiny RSS database is up to date.");
1135
+                    } else {
1136
+                        print_notice("Tiny Tiny RSS database is up to date.");
1137 1137
 
1138
-						print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>";
1139
-					}
1140
-				} else {
1141
-					if ($updater->isUpdateRequired()) {
1138
+                        print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>";
1139
+                    }
1140
+                } else {
1141
+                    if ($updater->isUpdateRequired()) {
1142 1142
 
1143
-						print "<h2>".T_sprintf("Tiny Tiny RSS database needs update to the latest version (%d to %d).",
1144
-							$updater->getSchemaVersion(), SCHEMA_VERSION)."</h2>";
1143
+                        print "<h2>".T_sprintf("Tiny Tiny RSS database needs update to the latest version (%d to %d).",
1144
+                            $updater->getSchemaVersion(), SCHEMA_VERSION)."</h2>";
1145 1145
 
1146
-						if (DB_TYPE == "mysql") {
1147
-							print_error("<strong>READ THIS:</strong> Due to MySQL limitations, your database is not completely protected while updating. ".
1148
-								"Errors may put it in an inconsistent state requiring manual rollback. <strong>BACKUP YOUR DATABASE BEFORE CONTINUING.</strong>");
1149
-						} else {
1150
-							print_warning("Please backup your database before proceeding.");
1151
-						}
1146
+                        if (DB_TYPE == "mysql") {
1147
+                            print_error("<strong>READ THIS:</strong> Due to MySQL limitations, your database is not completely protected while updating. ".
1148
+                                "Errors may put it in an inconsistent state requiring manual rollback. <strong>BACKUP YOUR DATABASE BEFORE CONTINUING.</strong>");
1149
+                        } else {
1150
+                            print_warning("Please backup your database before proceeding.");
1151
+                        }
1152 1152
 
1153
-						print "<form method='POST'>
1153
+                        print "<form method='POST'>
1154 1154
 							<input type='hidden' name='subop' value='performupdate'>
1155 1155
 							<button type='submit' dojoType='dijit.form.Button' class='alt-danger' onclick='return confirmOP()'>".__("Perform updates")."</button>
1156 1156
 						</form>";
1157 1157
 
1158
-					} else {
1158
+                    } else {
1159 1159
 
1160
-						print_notice("Tiny Tiny RSS database is up to date.");
1160
+                        print_notice("Tiny Tiny RSS database is up to date.");
1161 1161
 
1162
-						print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>";
1163
-					}
1164
-				}
1165
-			?>
1162
+                        print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>";
1163
+                    }
1164
+                }
1165
+            ?>
1166 1166
 
1167 1167
 			</div>
1168 1168
 			</div>
1169 1169
 			</body>
1170 1170
 			</html>
1171 1171
 		<?php
1172
-	}
1173
-
1174
-	public function cached_url() {
1175
-		list ($cache_dir, $filename) = explode("/", $_GET["file"], 2);
1176
-
1177
-		// we do not allow files with extensions at the moment
1178
-		$filename = str_replace(".", "", $filename);
1179
-
1180
-		$cache = new DiskCache($cache_dir);
1181
-
1182
-		if ($cache->exists($filename)) {
1183
-			$cache->send($filename);
1184
-		} else {
1185
-			header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
1186
-			echo "File not found.";
1187
-		}
1188
-	}
1189
-
1190
-	private function make_article_tag_uri($id, $timestamp) {
1191
-
1192
-		$timestamp = date("Y-m-d", strtotime($timestamp));
1193
-
1194
-		return "tag:" . parse_url(get_self_url_prefix(), PHP_URL_HOST) . ",$timestamp:/$id";
1195
-	}
1196
-
1197
-	// this should be used very carefully because this endpoint is exposed to unauthenticated users
1198
-	// plugin data is not loaded because there's no user context and owner_uid/session may or may not be available
1199
-	// in general, don't do anything user-related in here and do not modify $_SESSION
1200
-	public function pluginhandler() {
1201
-		$host = new PluginHost();
1202
-
1203
-		$plugin_name = clean_filename($_REQUEST["plugin"]);
1204
-		$method = clean($_REQUEST["pmethod"]);
1205
-
1206
-		$host->load($plugin_name, PluginHost::KIND_USER, 0);
1207
-		$host->load_data();
1208
-
1209
-		$plugin = $host->get_plugin($plugin_name);
1210
-
1211
-		if ($plugin) {
1212
-			if (method_exists($plugin, $method)) {
1213
-				if ($plugin->is_public_method($method)) {
1214
-					$plugin->$method();
1215
-				} else {
1216
-					user_error("PluginHandler[PUBLIC]: Requested private method '$method' of plugin '$plugin_name'.", E_USER_WARNING);
1217
-					header("Content-Type: text/json");
1218
-					print error_json(6);
1219
-				}
1220
-			} else {
1221
-				user_error("PluginHandler[PUBLIC]: Requested unknown method '$method' of plugin '$plugin_name'.", E_USER_WARNING);
1222
-				header("Content-Type: text/json");
1223
-				print error_json(13);
1224
-			}
1225
-		} else {
1226
-			user_error("PluginHandler[PUBLIC]: Requested method '$method' of unknown plugin '$plugin_name'.", E_USER_WARNING);
1227
-			header("Content-Type: text/json");
1228
-			print error_json(14);
1229
-		}
1230
-	}
1172
+    }
1173
+
1174
+    public function cached_url() {
1175
+        list ($cache_dir, $filename) = explode("/", $_GET["file"], 2);
1176
+
1177
+        // we do not allow files with extensions at the moment
1178
+        $filename = str_replace(".", "", $filename);
1179
+
1180
+        $cache = new DiskCache($cache_dir);
1181
+
1182
+        if ($cache->exists($filename)) {
1183
+            $cache->send($filename);
1184
+        } else {
1185
+            header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
1186
+            echo "File not found.";
1187
+        }
1188
+    }
1189
+
1190
+    private function make_article_tag_uri($id, $timestamp) {
1191
+
1192
+        $timestamp = date("Y-m-d", strtotime($timestamp));
1193
+
1194
+        return "tag:" . parse_url(get_self_url_prefix(), PHP_URL_HOST) . ",$timestamp:/$id";
1195
+    }
1196
+
1197
+    // this should be used very carefully because this endpoint is exposed to unauthenticated users
1198
+    // plugin data is not loaded because there's no user context and owner_uid/session may or may not be available
1199
+    // in general, don't do anything user-related in here and do not modify $_SESSION
1200
+    public function pluginhandler() {
1201
+        $host = new PluginHost();
1202
+
1203
+        $plugin_name = clean_filename($_REQUEST["plugin"]);
1204
+        $method = clean($_REQUEST["pmethod"]);
1205
+
1206
+        $host->load($plugin_name, PluginHost::KIND_USER, 0);
1207
+        $host->load_data();
1208
+
1209
+        $plugin = $host->get_plugin($plugin_name);
1210
+
1211
+        if ($plugin) {
1212
+            if (method_exists($plugin, $method)) {
1213
+                if ($plugin->is_public_method($method)) {
1214
+                    $plugin->$method();
1215
+                } else {
1216
+                    user_error("PluginHandler[PUBLIC]: Requested private method '$method' of plugin '$plugin_name'.", E_USER_WARNING);
1217
+                    header("Content-Type: text/json");
1218
+                    print error_json(6);
1219
+                }
1220
+            } else {
1221
+                user_error("PluginHandler[PUBLIC]: Requested unknown method '$method' of plugin '$plugin_name'.", E_USER_WARNING);
1222
+                header("Content-Type: text/json");
1223
+                print error_json(13);
1224
+            }
1225
+        } else {
1226
+            user_error("PluginHandler[PUBLIC]: Requested method '$method' of unknown plugin '$plugin_name'.", E_USER_WARNING);
1227
+            header("Content-Type: text/json");
1228
+            print error_json(14);
1229
+        }
1230
+    }
1231 1231
 }
Please login to merge, or discard this patch.
Braces   +24 added lines, -10 removed lines patch added patch discarded remove patch
@@ -12,7 +12,9 @@  discard block
 block discarded – undo
12 12
 			"padding : 5px; border-style : dashed; border-color : #e7d796;".
13 13
 			"margin-bottom : 1em; color : #9a8c59;";
14 14
 
15
-		if (!$limit) $limit = 60;
15
+		if (!$limit) {
16
+		    $limit = 60;
17
+		}
16 18
 
17 19
 		$date_sort_field = "date_entered DESC, updated DESC";
18 20
 
@@ -77,7 +79,9 @@  discard block
 block discarded – undo
77 79
 			"/public.php?op=rss&id=$feed&key=" .
78 80
 			Feeds::get_feed_access_key($feed, false, $owner_uid);
79 81
 
80
-		if (!$feed_site_url) $feed_site_url = get_self_url_prefix();
82
+		if (!$feed_site_url) {
83
+		    $feed_site_url = get_self_url_prefix();
84
+		}
81 85
 
82 86
 		if ($format == 'atom') {
83 87
 			$tpl = new MiniTemplator;
@@ -207,8 +211,12 @@  discard block
 block discarded – undo
207 211
 				$article['content'] = sanitize($line["content"], false, $owner_uid, $feed_site_url, false, $line["id"]);
208 212
 				$article['updated'] = date('c', strtotime($line["updated"]));
209 213
 
210
-				if ($line['note']) $article['note'] = $line['note'];
211
-				if ($article['author']) $article['author'] = $line['author'];
214
+				if ($line['note']) {
215
+				    $article['note'] = $line['note'];
216
+				}
217
+				if ($article['author']) {
218
+				    $article['author'] = $line['author'];
219
+				}
212 220
 
213 221
 				$tags = Article::get_article_tags($line["id"], $owner_uid);
214 222
 
@@ -459,7 +467,9 @@  discard block
 block discarded – undo
459 467
 		$format = clean($_REQUEST['format']);
460 468
 		$orig_guid = clean($_REQUEST["orig_guid"]);
461 469
 
462
-		if (!$format) $format = 'atom';
470
+		if (!$format) {
471
+		    $format = 'atom';
472
+		}
463 473
 
464 474
 		if (SINGLE_USER_MODE) {
465 475
 			authenticate_user("admin", null);
@@ -472,8 +482,9 @@  discard block
 block discarded – undo
472 482
 				ttrss_access_keys WHERE access_key = ? AND feed_id = ?");
473 483
 			$sth->execute([$key, $feed]);
474 484
 
475
-			if ($row = $sth->fetch())
476
-				$owner_id = $row["owner_uid"];
485
+			if ($row = $sth->fetch()) {
486
+							$owner_id = $row["owner_uid"];
487
+			}
477 488
 		}
478 489
 
479 490
 		if ($owner_id) {
@@ -683,8 +694,9 @@  discard block
 block discarded – undo
683 694
 				// start an empty session to deliver login error message
684 695
 				@session_start();
685 696
 
686
-				if (!isset($_SESSION["login_error_msg"]))
687
-					$_SESSION["login_error_msg"] = __("Incorrect username or password");
697
+				if (!isset($_SESSION["login_error_msg"])) {
698
+									$_SESSION["login_error_msg"] = __("Incorrect username or password");
699
+				}
688 700
 
689 701
 				user_error("Failed login attempt for $login from {$_SERVER['REMOTE_ADDR']}", E_USER_WARNING);
690 702
 			}
@@ -1007,7 +1019,9 @@  discard block
 block discarded – undo
1007 1019
 							"subject" => __("[tt-rss] Password reset request"),
1008 1020
 							"message" => $message]);
1009 1021
 
1010
-						if (!$rc) print_error($mailer->error());
1022
+						if (!$rc) {
1023
+						    print_error($mailer->error());
1024
+						}
1011 1025
 
1012 1026
 						$resetpass_token_full = time() . ":" . $resetpass_token;
1013 1027
 
Please login to merge, or discard this patch.
classes/feedparser.php 3 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 		if ($error) {
27 27
 			foreach (libxml_get_errors() as $error) {
28 28
 				if ($error->level == LIBXML_ERR_FATAL) {
29
-					if(!isset($this->error)) //currently only the first error is reported
29
+					if (!isset($this->error)) //currently only the first error is reported
30 30
 						$this->error = $this->format_error($error);
31 31
 					$this->libxml_errors [] = $this->format_error($error);
32 32
 				}
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 					$this->type = $this::FEED_ATOM;
70 70
 					break;
71 71
 				default:
72
-					if( !isset($this->error) ){
72
+					if (!isset($this->error)) {
73 73
 						$this->error = "Unknown/unsupported feed type";
74 74
 					}
75 75
 					return;
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
 			if ($this->link) $this->link = trim($this->link);
167 167
 
168 168
 		} else {
169
-			if( !isset($this->error) ){
169
+			if (!isset($this->error)) {
170 170
 				$this->error = "Unknown/unsupported feed type";
171 171
 			}
172 172
 			return;
Please login to merge, or discard this patch.
Indentation   +224 added lines, -224 removed lines patch added patch discarded remove patch
@@ -1,233 +1,233 @@
 block discarded – undo
1 1
 <?php
2 2
 class FeedParser {
3
-	private $doc;
4
-	private $error;
5
-	private $libxml_errors = array();
6
-	private $items;
7
-	private $link;
8
-	private $title;
9
-	private $type;
10
-	private $xpath;
11
-
12
-	const FEED_RDF = 0;
13
-	const FEED_RSS = 1;
14
-	const FEED_ATOM = 2;
15
-
16
-	public function __construct($data) {
17
-		libxml_use_internal_errors(true);
18
-		libxml_clear_errors();
19
-		$this->doc = new DOMDocument();
20
-		$this->doc->loadXML($data);
21
-
22
-		mb_substitute_character("none");
23
-
24
-		$error = libxml_get_last_error();
25
-
26
-		if ($error) {
27
-			foreach (libxml_get_errors() as $error) {
28
-				if ($error->level == LIBXML_ERR_FATAL) {
29
-					if(!isset($this->error)) //currently only the first error is reported
30
-						$this->error = $this->format_error($error);
31
-					$this->libxml_errors [] = $this->format_error($error);
32
-				}
33
-			}
34
-		}
35
-		libxml_clear_errors();
36
-
37
-		$this->items = array();
38
-	}
39
-
40
-	public function init() {
41
-		$xpath = new DOMXPath($this->doc);
42
-		$xpath->registerNamespace('atom', 'http://www.w3.org/2005/Atom');
43
-		$xpath->registerNamespace('atom03', 'http://purl.org/atom/ns#');
44
-		$xpath->registerNamespace('media', 'http://search.yahoo.com/mrss/');
45
-		$xpath->registerNamespace('rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
46
-		$xpath->registerNamespace('slash', 'http://purl.org/rss/1.0/modules/slash/');
47
-		$xpath->registerNamespace('dc', 'http://purl.org/dc/elements/1.1/');
48
-		$xpath->registerNamespace('content', 'http://purl.org/rss/1.0/modules/content/');
49
-		$xpath->registerNamespace('thread', 'http://purl.org/syndication/thread/1.0');
50
-
51
-		$this->xpath = $xpath;
52
-
53
-		$root = $xpath->query("(//atom03:feed|//atom:feed|//channel|//rdf:rdf|//rdf:RDF)");
54
-
55
-		if ($root && $root->length > 0) {
56
-			$root = $root->item(0);
57
-
58
-			if ($root) {
59
-				switch (mb_strtolower($root->tagName)) {
60
-				case "rdf:rdf":
61
-					$this->type = $this::FEED_RDF;
62
-					break;
63
-				case "channel":
64
-					$this->type = $this::FEED_RSS;
65
-					break;
66
-				case "feed":
67
-				case "atom:feed":
68
-					$this->type = $this::FEED_ATOM;
69
-					break;
70
-				default:
71
-					if( !isset($this->error) ){
72
-						$this->error = "Unknown/unsupported feed type";
73
-					}
74
-					return;
75
-				}
76
-			}
77
-
78
-			switch ($this->type) {
79
-			case $this::FEED_ATOM:
80
-
81
-				$title = $xpath->query("//atom:feed/atom:title")->item(0);
82
-
83
-				if (!$title)
84
-					$title = $xpath->query("//atom03:feed/atom03:title")->item(0);
85
-
86
-
87
-				if ($title) {
88
-					$this->title = $title->nodeValue;
89
-				}
90
-
91
-				$link = $xpath->query("//atom:feed/atom:link[not(@rel)]")->item(0);
92
-
93
-				if (!$link)
94
-					$link = $xpath->query("//atom:feed/atom:link[@rel='alternate']")->item(0);
95
-
96
-				if (!$link)
97
-					$link = $xpath->query("//atom03:feed/atom03:link[not(@rel)]")->item(0);
98
-
99
-				if (!$link)
100
-					$link = $xpath->query("//atom03:feed/atom03:link[@rel='alternate']")->item(0);
101
-
102
-				if ($link && $link->hasAttributes()) {
103
-					$this->link = $link->getAttribute("href");
104
-				}
105
-
106
-				$articles = $xpath->query("//atom:entry");
107
-
108
-				if (!$articles || $articles->length == 0)
109
-					$articles = $xpath->query("//atom03:entry");
110
-
111
-				foreach ($articles as $article) {
112
-					array_push($this->items, new FeedItem_Atom($article, $this->doc, $this->xpath));
113
-				}
114
-
115
-				break;
116
-			case $this::FEED_RSS:
117
-				$title = $xpath->query("//channel/title")->item(0);
118
-
119
-				if ($title) {
120
-					$this->title = $title->nodeValue;
121
-				}
122
-
123
-				$link = $xpath->query("//channel/link")->item(0);
124
-
125
-				if ($link) {
126
-					if ($link->getAttribute("href"))
127
-						$this->link = $link->getAttribute("href");
128
-					else if ($link->nodeValue)
129
-						$this->link = $link->nodeValue;
130
-				}
131
-
132
-				$articles = $xpath->query("//channel/item");
133
-
134
-				foreach ($articles as $article) {
135
-					array_push($this->items, new FeedItem_RSS($article, $this->doc, $this->xpath));
136
-				}
137
-
138
-				break;
139
-			case $this::FEED_RDF:
140
-				$xpath->registerNamespace('rssfake', 'http://purl.org/rss/1.0/');
141
-
142
-				$title = $xpath->query("//rssfake:channel/rssfake:title")->item(0);
143
-
144
-				if ($title) {
145
-					$this->title = $title->nodeValue;
146
-				}
147
-
148
-				$link = $xpath->query("//rssfake:channel/rssfake:link")->item(0);
149
-
150
-				if ($link) {
151
-					$this->link = $link->nodeValue;
152
-				}
153
-
154
-				$articles = $xpath->query("//rssfake:item");
155
-
156
-				foreach ($articles as $article) {
157
-					array_push($this->items, new FeedItem_RSS($article, $this->doc, $this->xpath));
158
-				}
159
-
160
-				break;
161
-
162
-			}
163
-
164
-			if ($this->title) $this->title = trim($this->title);
165
-			if ($this->link) $this->link = trim($this->link);
3
+    private $doc;
4
+    private $error;
5
+    private $libxml_errors = array();
6
+    private $items;
7
+    private $link;
8
+    private $title;
9
+    private $type;
10
+    private $xpath;
11
+
12
+    const FEED_RDF = 0;
13
+    const FEED_RSS = 1;
14
+    const FEED_ATOM = 2;
15
+
16
+    public function __construct($data) {
17
+        libxml_use_internal_errors(true);
18
+        libxml_clear_errors();
19
+        $this->doc = new DOMDocument();
20
+        $this->doc->loadXML($data);
21
+
22
+        mb_substitute_character("none");
23
+
24
+        $error = libxml_get_last_error();
25
+
26
+        if ($error) {
27
+            foreach (libxml_get_errors() as $error) {
28
+                if ($error->level == LIBXML_ERR_FATAL) {
29
+                    if(!isset($this->error)) //currently only the first error is reported
30
+                        $this->error = $this->format_error($error);
31
+                    $this->libxml_errors [] = $this->format_error($error);
32
+                }
33
+            }
34
+        }
35
+        libxml_clear_errors();
36
+
37
+        $this->items = array();
38
+    }
39
+
40
+    public function init() {
41
+        $xpath = new DOMXPath($this->doc);
42
+        $xpath->registerNamespace('atom', 'http://www.w3.org/2005/Atom');
43
+        $xpath->registerNamespace('atom03', 'http://purl.org/atom/ns#');
44
+        $xpath->registerNamespace('media', 'http://search.yahoo.com/mrss/');
45
+        $xpath->registerNamespace('rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
46
+        $xpath->registerNamespace('slash', 'http://purl.org/rss/1.0/modules/slash/');
47
+        $xpath->registerNamespace('dc', 'http://purl.org/dc/elements/1.1/');
48
+        $xpath->registerNamespace('content', 'http://purl.org/rss/1.0/modules/content/');
49
+        $xpath->registerNamespace('thread', 'http://purl.org/syndication/thread/1.0');
50
+
51
+        $this->xpath = $xpath;
52
+
53
+        $root = $xpath->query("(//atom03:feed|//atom:feed|//channel|//rdf:rdf|//rdf:RDF)");
54
+
55
+        if ($root && $root->length > 0) {
56
+            $root = $root->item(0);
57
+
58
+            if ($root) {
59
+                switch (mb_strtolower($root->tagName)) {
60
+                case "rdf:rdf":
61
+                    $this->type = $this::FEED_RDF;
62
+                    break;
63
+                case "channel":
64
+                    $this->type = $this::FEED_RSS;
65
+                    break;
66
+                case "feed":
67
+                case "atom:feed":
68
+                    $this->type = $this::FEED_ATOM;
69
+                    break;
70
+                default:
71
+                    if( !isset($this->error) ){
72
+                        $this->error = "Unknown/unsupported feed type";
73
+                    }
74
+                    return;
75
+                }
76
+            }
77
+
78
+            switch ($this->type) {
79
+            case $this::FEED_ATOM:
80
+
81
+                $title = $xpath->query("//atom:feed/atom:title")->item(0);
82
+
83
+                if (!$title)
84
+                    $title = $xpath->query("//atom03:feed/atom03:title")->item(0);
85
+
86
+
87
+                if ($title) {
88
+                    $this->title = $title->nodeValue;
89
+                }
90
+
91
+                $link = $xpath->query("//atom:feed/atom:link[not(@rel)]")->item(0);
92
+
93
+                if (!$link)
94
+                    $link = $xpath->query("//atom:feed/atom:link[@rel='alternate']")->item(0);
95
+
96
+                if (!$link)
97
+                    $link = $xpath->query("//atom03:feed/atom03:link[not(@rel)]")->item(0);
98
+
99
+                if (!$link)
100
+                    $link = $xpath->query("//atom03:feed/atom03:link[@rel='alternate']")->item(0);
101
+
102
+                if ($link && $link->hasAttributes()) {
103
+                    $this->link = $link->getAttribute("href");
104
+                }
105
+
106
+                $articles = $xpath->query("//atom:entry");
107
+
108
+                if (!$articles || $articles->length == 0)
109
+                    $articles = $xpath->query("//atom03:entry");
110
+
111
+                foreach ($articles as $article) {
112
+                    array_push($this->items, new FeedItem_Atom($article, $this->doc, $this->xpath));
113
+                }
114
+
115
+                break;
116
+            case $this::FEED_RSS:
117
+                $title = $xpath->query("//channel/title")->item(0);
118
+
119
+                if ($title) {
120
+                    $this->title = $title->nodeValue;
121
+                }
122
+
123
+                $link = $xpath->query("//channel/link")->item(0);
124
+
125
+                if ($link) {
126
+                    if ($link->getAttribute("href"))
127
+                        $this->link = $link->getAttribute("href");
128
+                    else if ($link->nodeValue)
129
+                        $this->link = $link->nodeValue;
130
+                }
131
+
132
+                $articles = $xpath->query("//channel/item");
133
+
134
+                foreach ($articles as $article) {
135
+                    array_push($this->items, new FeedItem_RSS($article, $this->doc, $this->xpath));
136
+                }
137
+
138
+                break;
139
+            case $this::FEED_RDF:
140
+                $xpath->registerNamespace('rssfake', 'http://purl.org/rss/1.0/');
141
+
142
+                $title = $xpath->query("//rssfake:channel/rssfake:title")->item(0);
143
+
144
+                if ($title) {
145
+                    $this->title = $title->nodeValue;
146
+                }
147
+
148
+                $link = $xpath->query("//rssfake:channel/rssfake:link")->item(0);
149
+
150
+                if ($link) {
151
+                    $this->link = $link->nodeValue;
152
+                }
153
+
154
+                $articles = $xpath->query("//rssfake:item");
155
+
156
+                foreach ($articles as $article) {
157
+                    array_push($this->items, new FeedItem_RSS($article, $this->doc, $this->xpath));
158
+                }
159
+
160
+                break;
161
+
162
+            }
163
+
164
+            if ($this->title) $this->title = trim($this->title);
165
+            if ($this->link) $this->link = trim($this->link);
166 166
 
167
-		} else {
168
-			if( !isset($this->error) ){
169
-				$this->error = "Unknown/unsupported feed type";
170
-			}
171
-			return;
172
-		}
173
-	}
167
+        } else {
168
+            if( !isset($this->error) ){
169
+                $this->error = "Unknown/unsupported feed type";
170
+            }
171
+            return;
172
+        }
173
+    }
174 174
 
175
-	public function format_error($error) {
176
-		if ($error) {
177
-			return sprintf("LibXML error %s at line %d (column %d): %s",
178
-				$error->code, $error->line, $error->column,
179
-				$error->message);
180
-		} else {
181
-			return "";
182
-		}
183
-	}
175
+    public function format_error($error) {
176
+        if ($error) {
177
+            return sprintf("LibXML error %s at line %d (column %d): %s",
178
+                $error->code, $error->line, $error->column,
179
+                $error->message);
180
+        } else {
181
+            return "";
182
+        }
183
+    }
184 184
 
185
-	// libxml may have invalid unicode data in error messages
186
-	public function error() {
187
-		return UConverter::transcode($this->error, 'UTF-8', 'UTF-8');
188
-	}
185
+    // libxml may have invalid unicode data in error messages
186
+    public function error() {
187
+        return UConverter::transcode($this->error, 'UTF-8', 'UTF-8');
188
+    }
189 189
 
190
-	// WARNING: may return invalid unicode data
191
-	public function errors() {
192
-		return $this->libxml_errors;
193
-	}
190
+    // WARNING: may return invalid unicode data
191
+    public function errors() {
192
+        return $this->libxml_errors;
193
+    }
194 194
 
195
-	public function get_link() {
196
-		return clean($this->link);
197
-	}
195
+    public function get_link() {
196
+        return clean($this->link);
197
+    }
198 198
 
199
-	public function get_title() {
200
-		return clean($this->title);
201
-	}
202
-
203
-	public function get_items() {
204
-		return $this->items;
205
-	}
206
-
207
-	public function get_links($rel) {
208
-		$rv = array();
209
-
210
-		switch ($this->type) {
211
-		case $this::FEED_ATOM:
212
-			$links = $this->xpath->query("//atom:feed/atom:link");
213
-
214
-			foreach ($links as $link) {
215
-				if (!$rel || $link->hasAttribute('rel') && $link->getAttribute('rel') == $rel) {
216
-					array_push($rv, clean(trim($link->getAttribute('href'))));
217
-				}
218
-			}
219
-			break;
220
-		case $this::FEED_RSS:
221
-			$links = $this->xpath->query("//atom:link");
222
-
223
-			foreach ($links as $link) {
224
-				if (!$rel || $link->hasAttribute('rel') && $link->getAttribute('rel') == $rel) {
225
-					array_push($rv, clean(trim($link->getAttribute('href'))));
226
-				}
227
-			}
228
-			break;
229
-		}
230
-
231
-		return $rv;
232
-	}
199
+    public function get_title() {
200
+        return clean($this->title);
201
+    }
202
+
203
+    public function get_items() {
204
+        return $this->items;
205
+    }
206
+
207
+    public function get_links($rel) {
208
+        $rv = array();
209
+
210
+        switch ($this->type) {
211
+        case $this::FEED_ATOM:
212
+            $links = $this->xpath->query("//atom:feed/atom:link");
213
+
214
+            foreach ($links as $link) {
215
+                if (!$rel || $link->hasAttribute('rel') && $link->getAttribute('rel') == $rel) {
216
+                    array_push($rv, clean(trim($link->getAttribute('href'))));
217
+                }
218
+            }
219
+            break;
220
+        case $this::FEED_RSS:
221
+            $links = $this->xpath->query("//atom:link");
222
+
223
+            foreach ($links as $link) {
224
+                if (!$rel || $link->hasAttribute('rel') && $link->getAttribute('rel') == $rel) {
225
+                    array_push($rv, clean(trim($link->getAttribute('href'))));
226
+                }
227
+            }
228
+            break;
229
+        }
230
+
231
+        return $rv;
232
+    }
233 233
 }
Please login to merge, or discard this patch.
Braces   +29 added lines, -17 removed lines patch added patch discarded remove patch
@@ -26,8 +26,10 @@  discard block
 block discarded – undo
26 26
 		if ($error) {
27 27
 			foreach (libxml_get_errors() as $error) {
28 28
 				if ($error->level == LIBXML_ERR_FATAL) {
29
-					if(!isset($this->error)) //currently only the first error is reported
29
+					if(!isset($this->error)) {
30
+					    //currently only the first error is reported
30 31
 						$this->error = $this->format_error($error);
32
+					}
31 33
 					$this->libxml_errors [] = $this->format_error($error);
32 34
 				}
33 35
 			}
@@ -80,8 +82,9 @@  discard block
 block discarded – undo
80 82
 
81 83
 				$title = $xpath->query("//atom:feed/atom:title")->item(0);
82 84
 
83
-				if (!$title)
84
-					$title = $xpath->query("//atom03:feed/atom03:title")->item(0);
85
+				if (!$title) {
86
+									$title = $xpath->query("//atom03:feed/atom03:title")->item(0);
87
+				}
85 88
 
86 89
 
87 90
 				if ($title) {
@@ -90,14 +93,17 @@  discard block
 block discarded – undo
90 93
 
91 94
 				$link = $xpath->query("//atom:feed/atom:link[not(@rel)]")->item(0);
92 95
 
93
-				if (!$link)
94
-					$link = $xpath->query("//atom:feed/atom:link[@rel='alternate']")->item(0);
96
+				if (!$link) {
97
+									$link = $xpath->query("//atom:feed/atom:link[@rel='alternate']")->item(0);
98
+				}
95 99
 
96
-				if (!$link)
97
-					$link = $xpath->query("//atom03:feed/atom03:link[not(@rel)]")->item(0);
100
+				if (!$link) {
101
+									$link = $xpath->query("//atom03:feed/atom03:link[not(@rel)]")->item(0);
102
+				}
98 103
 
99
-				if (!$link)
100
-					$link = $xpath->query("//atom03:feed/atom03:link[@rel='alternate']")->item(0);
104
+				if (!$link) {
105
+									$link = $xpath->query("//atom03:feed/atom03:link[@rel='alternate']")->item(0);
106
+				}
101 107
 
102 108
 				if ($link && $link->hasAttributes()) {
103 109
 					$this->link = $link->getAttribute("href");
@@ -105,8 +111,9 @@  discard block
 block discarded – undo
105 111
 
106 112
 				$articles = $xpath->query("//atom:entry");
107 113
 
108
-				if (!$articles || $articles->length == 0)
109
-					$articles = $xpath->query("//atom03:entry");
114
+				if (!$articles || $articles->length == 0) {
115
+									$articles = $xpath->query("//atom03:entry");
116
+				}
110 117
 
111 118
 				foreach ($articles as $article) {
112 119
 					array_push($this->items, new FeedItem_Atom($article, $this->doc, $this->xpath));
@@ -123,10 +130,11 @@  discard block
 block discarded – undo
123 130
 				$link = $xpath->query("//channel/link")->item(0);
124 131
 
125 132
 				if ($link) {
126
-					if ($link->getAttribute("href"))
127
-						$this->link = $link->getAttribute("href");
128
-					else if ($link->nodeValue)
129
-						$this->link = $link->nodeValue;
133
+					if ($link->getAttribute("href")) {
134
+											$this->link = $link->getAttribute("href");
135
+					} else if ($link->nodeValue) {
136
+											$this->link = $link->nodeValue;
137
+					}
130 138
 				}
131 139
 
132 140
 				$articles = $xpath->query("//channel/item");
@@ -161,8 +169,12 @@  discard block
 block discarded – undo
161 169
 
162 170
 			}
163 171
 
164
-			if ($this->title) $this->title = trim($this->title);
165
-			if ($this->link) $this->link = trim($this->link);
172
+			if ($this->title) {
173
+			    $this->title = trim($this->title);
174
+			}
175
+			if ($this->link) {
176
+			    $this->link = trim($this->link);
177
+			}
166 178
 
167 179
 		} else {
168 180
 			if( !isset($this->error) ){
Please login to merge, or discard this patch.
classes/counters.php 2 patches
Braces   +20 added lines, -14 removed lines patch added patch discarded remove patch
@@ -95,10 +95,11 @@  discard block
 block discarded – undo
95 95
 
96 96
 			$count = getFeedUnread($i);
97 97
 
98
-			if ($i == 0 || $i == -1 || $i == -2)
99
-				$auxctr = Feeds::getFeedArticles($i, false);
100
-			else
101
-				$auxctr = 0;
98
+			if ($i == 0 || $i == -1 || $i == -2) {
99
+							$auxctr = Feeds::getFeedArticles($i, false);
100
+			} else {
101
+							$auxctr = 0;
102
+			}
102 103
 
103 104
 			$cv = array("id" => $i,
104 105
 				"counter" => (int) $count,
@@ -117,8 +118,9 @@  discard block
 block discarded – undo
117 118
 				$cv = array("id" => PluginHost::pfeed_to_feed_id($feed['id']),
118 119
 					"counter" => $feed['sender']->get_unread($feed['id']));
119 120
 
120
-				if (method_exists($feed['sender'], 'get_total'))
121
-					$cv["auxcounter"] = $feed['sender']->get_total($feed['id']);
121
+				if (method_exists($feed['sender'], 'get_total')) {
122
+									$cv["auxcounter"] = $feed['sender']->get_total($feed['id']);
123
+				}
122 124
 
123 125
 				array_push($ret_arr, $cv);
124 126
 			}
@@ -150,8 +152,9 @@  discard block
 block discarded – undo
150 152
 				"counter" => (int) $line["unread"],
151 153
 				"auxcounter" => (int) $line["total"]);
152 154
 
153
-			if ($descriptions)
154
-				$cv["description"] = $line["caption"];
155
+			if ($descriptions) {
156
+							$cv["description"] = $line["caption"];
157
+			}
155 158
 
156 159
 			array_push($ret_arr, $cv);
157 160
 		}
@@ -189,22 +192,25 @@  discard block
 block discarded – undo
189 192
 				$has_img = false;
190 193
 			}
191 194
 
192
-			if (date('Y') - date('Y', strtotime($line['last_updated'])) > 2)
193
-				$last_updated = '';
195
+			if (date('Y') - date('Y', strtotime($line['last_updated'])) > 2) {
196
+							$last_updated = '';
197
+			}
194 198
 
195 199
 			$cv = array("id" => $id,
196 200
 				"updated" => $last_updated,
197 201
 				"counter" => (int) $count,
198 202
 				"has_img" => (int) $has_img);
199 203
 
200
-			if ($last_error)
201
-				$cv["error"] = $last_error;
204
+			if ($last_error) {
205
+							$cv["error"] = $last_error;
206
+			}
202 207
 
203 208
 //			if (get_pref('EXTENDED_FEEDLIST'))
204 209
 //				$cv["xmsg"] = getFeedArticles($id)." ".__("total");
205 210
 
206
-			if ($active_feed && $id == $active_feed)
207
-				$cv["title"] = truncate_string($line["title"], 30);
211
+			if ($active_feed && $id == $active_feed) {
212
+							$cv["title"] = truncate_string($line["title"], 30);
213
+			}
208 214
 
209 215
 			array_push($ret_arr, $cv);
210 216
 
Please login to merge, or discard this patch.
Indentation   +122 added lines, -122 removed lines patch added patch discarded remove patch
@@ -1,171 +1,171 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 class Counters {
3 3
 
4
-	public static function getAllCounters() {
5
-		$data = Counters::getGlobalCounters();
4
+    public static function getAllCounters() {
5
+        $data = Counters::getGlobalCounters();
6 6
 
7
-		$data = array_merge($data, Counters::getVirtCounters());
8
-		$data = array_merge($data, Counters::getLabelCounters());
9
-		$data = array_merge($data, Counters::getFeedCounters());
10
-		$data = array_merge($data, Counters::getCategoryCounters());
7
+        $data = array_merge($data, Counters::getVirtCounters());
8
+        $data = array_merge($data, Counters::getLabelCounters());
9
+        $data = array_merge($data, Counters::getFeedCounters());
10
+        $data = array_merge($data, Counters::getCategoryCounters());
11 11
 
12
-		return $data;
13
-	}
12
+        return $data;
13
+    }
14 14
 
15
-	public static function getCategoryCounters() {
16
-		$ret_arr = array();
15
+    public static function getCategoryCounters() {
16
+        $ret_arr = array();
17 17
 
18
-		/* Labels category */
18
+        /* Labels category */
19 19
 
20
-		$cv = array("id" => -2, "kind" => "cat",
21
-			"counter" => Feeds::getCategoryUnread(-2));
20
+        $cv = array("id" => -2, "kind" => "cat",
21
+            "counter" => Feeds::getCategoryUnread(-2));
22 22
 
23
-		array_push($ret_arr, $cv);
23
+        array_push($ret_arr, $cv);
24 24
 
25
-		$pdo = DB::pdo();
25
+        $pdo = DB::pdo();
26 26
 
27
-		$sth = $pdo->prepare("SELECT ttrss_feed_categories.id AS cat_id, value AS unread,
27
+        $sth = $pdo->prepare("SELECT ttrss_feed_categories.id AS cat_id, value AS unread,
28 28
 			(SELECT COUNT(id) FROM ttrss_feed_categories AS c2
29 29
 				WHERE c2.parent_cat = ttrss_feed_categories.id) AS num_children
30 30
 			FROM ttrss_feed_categories, ttrss_cat_counters_cache
31 31
 			WHERE ttrss_cat_counters_cache.feed_id = ttrss_feed_categories.id AND
32 32
 			ttrss_cat_counters_cache.owner_uid = ttrss_feed_categories.owner_uid AND
33 33
 			ttrss_feed_categories.owner_uid = ?");
34
-		$sth->execute([$_SESSION['uid']]);
34
+        $sth->execute([$_SESSION['uid']]);
35 35
 
36
-		while ($line = $sth->fetch()) {
37
-			$line["cat_id"] = (int) $line["cat_id"];
36
+        while ($line = $sth->fetch()) {
37
+            $line["cat_id"] = (int) $line["cat_id"];
38 38
 
39
-			if ($line["num_children"] > 0) {
40
-				$child_counter = Feeds::getCategoryChildrenUnread($line["cat_id"], $_SESSION["uid"]);
41
-			} else {
42
-				$child_counter = 0;
43
-			}
39
+            if ($line["num_children"] > 0) {
40
+                $child_counter = Feeds::getCategoryChildrenUnread($line["cat_id"], $_SESSION["uid"]);
41
+            } else {
42
+                $child_counter = 0;
43
+            }
44 44
 
45
-			$cv = array("id" => $line["cat_id"], "kind" => "cat",
46
-				"counter" => $line["unread"] + $child_counter);
45
+            $cv = array("id" => $line["cat_id"], "kind" => "cat",
46
+                "counter" => $line["unread"] + $child_counter);
47 47
 
48
-			array_push($ret_arr, $cv);
49
-		}
48
+            array_push($ret_arr, $cv);
49
+        }
50 50
 
51
-		/* Special case: NULL category doesn't actually exist in the DB */
51
+        /* Special case: NULL category doesn't actually exist in the DB */
52 52
 
53
-		$cv = array("id" => 0, "kind" => "cat",
54
-			"counter" => (int) CCache::find(0, $_SESSION["uid"], true));
53
+        $cv = array("id" => 0, "kind" => "cat",
54
+            "counter" => (int) CCache::find(0, $_SESSION["uid"], true));
55 55
 
56
-		array_push($ret_arr, $cv);
56
+        array_push($ret_arr, $cv);
57 57
 
58
-		return $ret_arr;
59
-	}
58
+        return $ret_arr;
59
+    }
60 60
 
61
-	public static function getGlobalCounters($global_unread = -1) {
62
-		$ret_arr = array();
61
+    public static function getGlobalCounters($global_unread = -1) {
62
+        $ret_arr = array();
63 63
 
64
-		if ($global_unread == -1) {
65
-			$global_unread = Feeds::getGlobalUnread();
66
-		}
64
+        if ($global_unread == -1) {
65
+            $global_unread = Feeds::getGlobalUnread();
66
+        }
67 67
 
68
-		$cv = array("id" => "global-unread",
69
-			"counter" => (int) $global_unread);
68
+        $cv = array("id" => "global-unread",
69
+            "counter" => (int) $global_unread);
70 70
 
71
-		array_push($ret_arr, $cv);
71
+        array_push($ret_arr, $cv);
72 72
 
73
-		$pdo = Db::pdo();
73
+        $pdo = Db::pdo();
74 74
 
75
-		$sth = $pdo->prepare("SELECT COUNT(id) AS fn FROM
75
+        $sth = $pdo->prepare("SELECT COUNT(id) AS fn FROM
76 76
 			ttrss_feeds WHERE owner_uid = ?");
77
-		$sth->execute([$_SESSION['uid']]);
78
-		$row = $sth->fetch();
77
+        $sth->execute([$_SESSION['uid']]);
78
+        $row = $sth->fetch();
79 79
 
80
-		$subscribed_feeds = $row["fn"];
80
+        $subscribed_feeds = $row["fn"];
81 81
 
82
-		$cv = array("id" => "subscribed-feeds",
83
-			"counter" => (int) $subscribed_feeds);
82
+        $cv = array("id" => "subscribed-feeds",
83
+            "counter" => (int) $subscribed_feeds);
84 84
 
85
-		array_push($ret_arr, $cv);
85
+        array_push($ret_arr, $cv);
86 86
 
87
-		return $ret_arr;
88
-	}
87
+        return $ret_arr;
88
+    }
89 89
 
90
-	public static function getVirtCounters() {
90
+    public static function getVirtCounters() {
91 91
 
92
-		$ret_arr = array();
92
+        $ret_arr = array();
93 93
 
94
-		for ($i = 0; $i >= -4; $i--) {
94
+        for ($i = 0; $i >= -4; $i--) {
95 95
 
96
-			$count = getFeedUnread($i);
96
+            $count = getFeedUnread($i);
97 97
 
98
-			if ($i == 0 || $i == -1 || $i == -2)
99
-				$auxctr = Feeds::getFeedArticles($i, false);
100
-			else
101
-				$auxctr = 0;
98
+            if ($i == 0 || $i == -1 || $i == -2)
99
+                $auxctr = Feeds::getFeedArticles($i, false);
100
+            else
101
+                $auxctr = 0;
102 102
 
103
-			$cv = array("id" => $i,
104
-				"counter" => (int) $count,
105
-				"auxcounter" => (int) $auxctr);
103
+            $cv = array("id" => $i,
104
+                "counter" => (int) $count,
105
+                "auxcounter" => (int) $auxctr);
106 106
 
107 107
 //			if (get_pref('EXTENDED_FEEDLIST'))
108 108
 //				$cv["xmsg"] = getFeedArticles($i)." ".__("total");
109 109
 
110
-			array_push($ret_arr, $cv);
111
-		}
110
+            array_push($ret_arr, $cv);
111
+        }
112 112
 
113
-		$feeds = PluginHost::getInstance()->get_feeds(-1);
113
+        $feeds = PluginHost::getInstance()->get_feeds(-1);
114 114
 
115
-		if (is_array($feeds)) {
116
-			foreach ($feeds as $feed) {
117
-				$cv = array("id" => PluginHost::pfeed_to_feed_id($feed['id']),
118
-					"counter" => $feed['sender']->get_unread($feed['id']));
115
+        if (is_array($feeds)) {
116
+            foreach ($feeds as $feed) {
117
+                $cv = array("id" => PluginHost::pfeed_to_feed_id($feed['id']),
118
+                    "counter" => $feed['sender']->get_unread($feed['id']));
119 119
 
120
-				if (method_exists($feed['sender'], 'get_total'))
121
-					$cv["auxcounter"] = $feed['sender']->get_total($feed['id']);
120
+                if (method_exists($feed['sender'], 'get_total'))
121
+                    $cv["auxcounter"] = $feed['sender']->get_total($feed['id']);
122 122
 
123
-				array_push($ret_arr, $cv);
124
-			}
125
-		}
123
+                array_push($ret_arr, $cv);
124
+            }
125
+        }
126 126
 
127
-		return $ret_arr;
128
-	}
127
+        return $ret_arr;
128
+    }
129 129
 
130
-	public static function getLabelCounters($descriptions = false) {
130
+    public static function getLabelCounters($descriptions = false) {
131 131
 
132
-		$ret_arr = array();
132
+        $ret_arr = array();
133 133
 
134
-		$pdo = Db::pdo();
134
+        $pdo = Db::pdo();
135 135
 
136
-		$sth = $pdo->prepare("SELECT id,caption,SUM(CASE WHEN u1.unread = true THEN 1 ELSE 0 END) AS unread, COUNT(u1.unread) AS total
136
+        $sth = $pdo->prepare("SELECT id,caption,SUM(CASE WHEN u1.unread = true THEN 1 ELSE 0 END) AS unread, COUNT(u1.unread) AS total
137 137
 			FROM ttrss_labels2 LEFT JOIN ttrss_user_labels2 ON
138 138
 				(ttrss_labels2.id = label_id)
139 139
 				LEFT JOIN ttrss_user_entries AS u1 ON u1.ref_id = article_id
140 140
 				WHERE ttrss_labels2.owner_uid = :uid AND u1.owner_uid = :uid
141 141
 				GROUP BY ttrss_labels2.id,
142 142
 					ttrss_labels2.caption");
143
-		$sth->execute([":uid" => $_SESSION['uid']]);
143
+        $sth->execute([":uid" => $_SESSION['uid']]);
144 144
 
145
-		while ($line = $sth->fetch()) {
145
+        while ($line = $sth->fetch()) {
146 146
 
147
-			$id = Labels::label_to_feed_id($line["id"]);
147
+            $id = Labels::label_to_feed_id($line["id"]);
148 148
 
149
-			$cv = array("id" => $id,
150
-				"counter" => (int) $line["unread"],
151
-				"auxcounter" => (int) $line["total"]);
149
+            $cv = array("id" => $id,
150
+                "counter" => (int) $line["unread"],
151
+                "auxcounter" => (int) $line["total"]);
152 152
 
153
-			if ($descriptions)
154
-				$cv["description"] = $line["caption"];
153
+            if ($descriptions)
154
+                $cv["description"] = $line["caption"];
155 155
 
156
-			array_push($ret_arr, $cv);
157
-		}
156
+            array_push($ret_arr, $cv);
157
+        }
158 158
 
159
-		return $ret_arr;
160
-	}
159
+        return $ret_arr;
160
+    }
161 161
 
162
-	public static function getFeedCounters($active_feed = false) {
162
+    public static function getFeedCounters($active_feed = false) {
163 163
 
164
-		$ret_arr = array();
164
+        $ret_arr = array();
165 165
 
166
-		$pdo = Db::pdo();
166
+        $pdo = Db::pdo();
167 167
 
168
-		$sth = $pdo->prepare("SELECT ttrss_feeds.id,
168
+        $sth = $pdo->prepare("SELECT ttrss_feeds.id,
169 169
 				ttrss_feeds.title,
170 170
 				".SUBSTRING_FOR_DATE."(ttrss_feeds.last_updated,1,19) AS last_updated,
171 171
 				last_error, value AS count
@@ -173,44 +173,44 @@  discard block
 block discarded – undo
173 173
 			WHERE ttrss_feeds.owner_uid = ?
174 174
 				AND ttrss_counters_cache.owner_uid = ttrss_feeds.owner_uid
175 175
 				AND ttrss_counters_cache.feed_id = ttrss_feeds.id");
176
-		$sth->execute([$_SESSION['uid']]);
176
+        $sth->execute([$_SESSION['uid']]);
177 177
 
178
-		while ($line = $sth->fetch()) {
178
+        while ($line = $sth->fetch()) {
179 179
 
180
-			$id = $line["id"];
181
-			$count = $line["count"];
182
-			$last_error = htmlspecialchars($line["last_error"]);
180
+            $id = $line["id"];
181
+            $count = $line["count"];
182
+            $last_error = htmlspecialchars($line["last_error"]);
183 183
 
184
-			$last_updated = make_local_datetime($line['last_updated'], false);
184
+            $last_updated = make_local_datetime($line['last_updated'], false);
185 185
 
186
-			if (Feeds::feedHasIcon($id)) {
187
-				$has_img = filemtime(Feeds::getIconFile($id));
188
-			} else {
189
-				$has_img = false;
190
-			}
186
+            if (Feeds::feedHasIcon($id)) {
187
+                $has_img = filemtime(Feeds::getIconFile($id));
188
+            } else {
189
+                $has_img = false;
190
+            }
191 191
 
192
-			if (date('Y') - date('Y', strtotime($line['last_updated'])) > 2)
193
-				$last_updated = '';
192
+            if (date('Y') - date('Y', strtotime($line['last_updated'])) > 2)
193
+                $last_updated = '';
194 194
 
195
-			$cv = array("id" => $id,
196
-				"updated" => $last_updated,
197
-				"counter" => (int) $count,
198
-				"has_img" => (int) $has_img);
195
+            $cv = array("id" => $id,
196
+                "updated" => $last_updated,
197
+                "counter" => (int) $count,
198
+                "has_img" => (int) $has_img);
199 199
 
200
-			if ($last_error)
201
-				$cv["error"] = $last_error;
200
+            if ($last_error)
201
+                $cv["error"] = $last_error;
202 202
 
203 203
 //			if (get_pref('EXTENDED_FEEDLIST'))
204 204
 //				$cv["xmsg"] = getFeedArticles($id)." ".__("total");
205 205
 
206
-			if ($active_feed && $id == $active_feed)
207
-				$cv["title"] = truncate_string($line["title"], 30);
206
+            if ($active_feed && $id == $active_feed)
207
+                $cv["title"] = truncate_string($line["title"], 30);
208 208
 
209
-			array_push($ret_arr, $cv);
209
+            array_push($ret_arr, $cv);
210 210
 
211
-		}
211
+        }
212 212
 
213
-		return $ret_arr;
214
-	}
213
+        return $ret_arr;
214
+    }
215 215
 
216 216
 }
Please login to merge, or discard this patch.
classes/dbupdater.php 3 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -52,9 +52,9 @@
 block discarded – undo
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();
Please login to merge, or discard this patch.
Braces   +5 added lines, -4 removed lines patch added patch discarded remove patch
@@ -43,10 +43,11 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
Indentation   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -2,83 +2,83 @@
 block discarded – undo
2 2
 
3 3
 class DbUpdater {
4 4
 
5
-	private $pdo;
6
-	private $db_type;
7
-	private $need_version;
8
-
9
-	public function __construct($db_type, $need_version) {
10
-		$this->pdo = Db::pdo();
11
-		$this->db_type = $db_type;
12
-		$this->need_version = (int) $need_version;
13
-	}
14
-
15
-	public function getSchemaVersion() {
16
-		$row = $this->pdo->query("SELECT schema_version FROM ttrss_version")->fetch();
17
-		return (int) $row['schema_version'];
18
-	}
19
-
20
-	public function isUpdateRequired() {
21
-		return $this->getSchemaVersion() < $this->need_version;
22
-	}
23
-
24
-	public function getSchemaLines($version) {
25
-		$filename = "schema/versions/".$this->db_type."/$version.sql";
26
-
27
-		if (file_exists($filename)) {
28
-			return explode(";", preg_replace("/[\r\n]/", "", file_get_contents($filename)));
29
-		} else {
30
-			user_error("DB Updater: schema file for version $version is not found.");
31
-			return false;
32
-		}
33
-	}
34
-
35
-	public function performUpdateTo($version, $html_output = true) {
36
-		if ($this->getSchemaVersion() == $version - 1) {
37
-
38
-			$lines = $this->getSchemaLines($version);
39
-
40
-			if (is_array($lines)) {
41
-
42
-				$this->pdo->beginTransaction();
43
-
44
-				foreach ($lines as $line) {
45
-					if (strpos($line, "--") !== 0 && $line) {
46
-
47
-						if ($html_output)
48
-							print "<pre>$line</pre>";
49
-						else
50
-							Debug::log("> $line");
51
-
52
-						try {
53
-							$this->pdo->query($line); // PDO returns errors as exceptions now
54
-						} catch (PDOException $e) {
55
-							if ($html_output) {
56
-								print "<div class='text-error'>Error: " . $e->getMessage() . "</div>";
57
-							} else {
58
-								Debug::log("Error: " . $e->getMessage());
59
-							}
60
-
61
-							$this->pdo->rollBack();
62
-							return false;
63
-						}
64
-					}
65
-				}
66
-
67
-				$db_version = $this->getSchemaVersion();
68
-
69
-				if ($db_version == $version) {
70
-					$this->pdo->commit();
71
-					return true;
72
-				} else {
73
-					$this->pdo->rollBack();
74
-					return false;
75
-				}
76
-			} else {
77
-				return false;
78
-			}
79
-		} else {
80
-			return false;
81
-		}
82
-	}
5
+    private $pdo;
6
+    private $db_type;
7
+    private $need_version;
8
+
9
+    public function __construct($db_type, $need_version) {
10
+        $this->pdo = Db::pdo();
11
+        $this->db_type = $db_type;
12
+        $this->need_version = (int) $need_version;
13
+    }
14
+
15
+    public function getSchemaVersion() {
16
+        $row = $this->pdo->query("SELECT schema_version FROM ttrss_version")->fetch();
17
+        return (int) $row['schema_version'];
18
+    }
19
+
20
+    public function isUpdateRequired() {
21
+        return $this->getSchemaVersion() < $this->need_version;
22
+    }
23
+
24
+    public function getSchemaLines($version) {
25
+        $filename = "schema/versions/".$this->db_type."/$version.sql";
26
+
27
+        if (file_exists($filename)) {
28
+            return explode(";", preg_replace("/[\r\n]/", "", file_get_contents($filename)));
29
+        } else {
30
+            user_error("DB Updater: schema file for version $version is not found.");
31
+            return false;
32
+        }
33
+    }
34
+
35
+    public function performUpdateTo($version, $html_output = true) {
36
+        if ($this->getSchemaVersion() == $version - 1) {
37
+
38
+            $lines = $this->getSchemaLines($version);
39
+
40
+            if (is_array($lines)) {
41
+
42
+                $this->pdo->beginTransaction();
43
+
44
+                foreach ($lines as $line) {
45
+                    if (strpos($line, "--") !== 0 && $line) {
46
+
47
+                        if ($html_output)
48
+                            print "<pre>$line</pre>";
49
+                        else
50
+                            Debug::log("> $line");
51
+
52
+                        try {
53
+                            $this->pdo->query($line); // PDO returns errors as exceptions now
54
+                        } catch (PDOException $e) {
55
+                            if ($html_output) {
56
+                                print "<div class='text-error'>Error: " . $e->getMessage() . "</div>";
57
+                            } else {
58
+                                Debug::log("Error: " . $e->getMessage());
59
+                            }
60
+
61
+                            $this->pdo->rollBack();
62
+                            return false;
63
+                        }
64
+                    }
65
+                }
66
+
67
+                $db_version = $this->getSchemaVersion();
68
+
69
+                if ($db_version == $version) {
70
+                    $this->pdo->commit();
71
+                    return true;
72
+                } else {
73
+                    $this->pdo->rollBack();
74
+                    return false;
75
+                }
76
+            } else {
77
+                return false;
78
+            }
79
+        } else {
80
+            return false;
81
+        }
82
+    }
83 83
 
84 84
 }
Please login to merge, or discard this patch.
install/index.php 4 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 				}
Please login to merge, or discard this patch.
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@
 block discarded – undo
10 10
 	function javascript_tag($filename) {
11 11
 		$query = "";
12 12
 
13
-		if (!(strpos($filename, "?") === FALSE)) {
13
+		if (!(strpos($filename, "?") === false)) {
14 14
 			$query = substr($filename, strpos($filename, "?")+1);
15 15
 			$filename = substr($filename, 0, strpos($filename, "?"));
16 16
 		}
Please login to merge, or discard this patch.
Indentation   +261 added lines, -261 removed lines patch added patch discarded remove patch
@@ -1,26 +1,26 @@  discard block
 block discarded – undo
1 1
 <?php
2
-	function stylesheet_tag($filename, $id = false) {
3
-		$timestamp = filemtime($filename);
2
+    function stylesheet_tag($filename, $id = false) {
3
+        $timestamp = filemtime($filename);
4 4
 
5
-		$id_part = $id ? "id=\"$id\"" : "";
5
+        $id_part = $id ? "id=\"$id\"" : "";
6 6
 
7
-		return "<link rel=\"stylesheet\" $id_part type=\"text/css\" href=\"$filename?$timestamp\"/>\n";
8
-	}
7
+        return "<link rel=\"stylesheet\" $id_part type=\"text/css\" href=\"$filename?$timestamp\"/>\n";
8
+    }
9 9
 
10
-	function javascript_tag($filename) {
11
-		$query = "";
10
+    function javascript_tag($filename) {
11
+        $query = "";
12 12
 
13
-		if (!(strpos($filename, "?") === FALSE)) {
14
-			$query = substr($filename, strpos($filename, "?")+1);
15
-			$filename = substr($filename, 0, strpos($filename, "?"));
16
-		}
13
+        if (!(strpos($filename, "?") === FALSE)) {
14
+            $query = substr($filename, strpos($filename, "?")+1);
15
+            $filename = substr($filename, 0, strpos($filename, "?"));
16
+        }
17 17
 
18
-		$timestamp = filemtime($filename);
18
+        $timestamp = filemtime($filename);
19 19
 
20
-		if ($query) $timestamp .= "&$query";
20
+        if ($query) $timestamp .= "&$query";
21 21
 
22
-		return "<script type=\"text/javascript\" charset=\"utf-8\" src=\"$filename?$timestamp\"></script>\n";
23
-	}
22
+        return "<script type=\"text/javascript\" charset=\"utf-8\" src=\"$filename?$timestamp\"></script>\n";
23
+    }
24 24
 ?>
25 25
 <!DOCTYPE html>
26 26
 <html>
@@ -31,11 +31,11 @@  discard block
 block discarded – undo
31 31
 		textarea { font-size : 12px; }
32 32
 	</style>
33 33
 	<?php
34
-		echo stylesheet_tag("../css/default.css");
35
-		echo javascript_tag("../lib/prototype.js");
36
-		echo javascript_tag("../lib/dojo/dojo.js");
37
-		echo javascript_tag("../lib/dojo/tt-rss-layer.js");
38
-	?>
34
+        echo stylesheet_tag("../css/default.css");
35
+        echo javascript_tag("../lib/prototype.js");
36
+        echo javascript_tag("../lib/dojo/dojo.js");
37
+        echo javascript_tag("../lib/dojo/tt-rss-layer.js");
38
+    ?>
39 39
 </head>
40 40
 <body class="flat ttrss_utility installer">
41 41
 
@@ -50,149 +50,149 @@  discard block
 block discarded – undo
50 50
 
51 51
 <?php
52 52
 
53
-	// could be needed because of existing config.php
54
-	function define_default($param, $value) {
55
-		//
56
-	}
53
+    // could be needed because of existing config.php
54
+    function define_default($param, $value) {
55
+        //
56
+    }
57 57
 
58
-	function make_password($length = 12) {
59
-		$password = "";
60
-		$possible = "0123456789abcdfghjkmnpqrstvwxyzABCDFGHJKMNPQRSTVWXYZ*%+^";
58
+    function make_password($length = 12) {
59
+        $password = "";
60
+        $possible = "0123456789abcdfghjkmnpqrstvwxyzABCDFGHJKMNPQRSTVWXYZ*%+^";
61 61
 
62
-		$i = 0;
62
+        $i = 0;
63 63
 
64
-		while ($i < $length) {
64
+        while ($i < $length) {
65 65
 
66
-			try {
67
-				$idx = function_exists("random_int") ? random_int(0, strlen($possible) - 1) : mt_rand(0, strlen($possible) - 1);
68
-			} catch (Exception $e) {
69
-				$idx = mt_rand(0, strlen($possible) - 1);
70
-			}
66
+            try {
67
+                $idx = function_exists("random_int") ? random_int(0, strlen($possible) - 1) : mt_rand(0, strlen($possible) - 1);
68
+            } catch (Exception $e) {
69
+                $idx = mt_rand(0, strlen($possible) - 1);
70
+            }
71 71
 
72
-			$char = substr($possible, $idx, 1);
72
+            $char = substr($possible, $idx, 1);
73 73
 
74
-			if (!strstr($password, $char)) {
75
-				$password .= $char;
76
-				$i++;
77
-			}
78
-		}
74
+            if (!strstr($password, $char)) {
75
+                $password .= $char;
76
+                $i++;
77
+            }
78
+        }
79 79
 
80
-		return $password;
81
-	}
80
+        return $password;
81
+    }
82 82
 
83 83
 
84
-	function sanity_check($db_type) {
85
-		$errors = array();
84
+    function sanity_check($db_type) {
85
+        $errors = array();
86 86
 
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 . ".");
89
-		}
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 . ".");
89
+        }
90 90
 
91
-		if (!function_exists("curl_init") && !ini_get("allow_url_fopen")) {
92
-			array_push($errors, "PHP configuration option allow_url_fopen is disabled, and CURL functions are not present. Either enable allow_url_fopen or install PHP extension for CURL.");
93
-		}
91
+        if (!function_exists("curl_init") && !ini_get("allow_url_fopen")) {
92
+            array_push($errors, "PHP configuration option allow_url_fopen is disabled, and CURL functions are not present. Either enable allow_url_fopen or install PHP extension for CURL.");
93
+        }
94 94
 
95
-		if (!function_exists("json_encode")) {
96
-			array_push($errors, "PHP support for JSON is required, but was not found.");
97
-		}
95
+        if (!function_exists("json_encode")) {
96
+            array_push($errors, "PHP support for JSON is required, but was not found.");
97
+        }
98 98
 
99
-		if (!class_exists("PDO")) {
100
-			array_push($errors, "PHP support for PDO is required but was not found.");
101
-		}
99
+        if (!class_exists("PDO")) {
100
+            array_push($errors, "PHP support for PDO is required but was not found.");
101
+        }
102 102
 
103
-		if (!function_exists("mb_strlen")) {
104
-			array_push($errors, "PHP support for mbstring functions is required but was not found.");
105
-		}
103
+        if (!function_exists("mb_strlen")) {
104
+            array_push($errors, "PHP support for mbstring functions is required but was not found.");
105
+        }
106 106
 
107
-		if (!function_exists("hash")) {
108
-			array_push($errors, "PHP support for hash() function is required but was not found.");
109
-		}
107
+        if (!function_exists("hash")) {
108
+            array_push($errors, "PHP support for hash() function is required but was not found.");
109
+        }
110 110
 
111
-		if (!function_exists("iconv")) {
112
-			array_push($errors, "PHP support for iconv is required to handle multiple charsets.");
113
-		}
111
+        if (!function_exists("iconv")) {
112
+            array_push($errors, "PHP support for iconv is required to handle multiple charsets.");
113
+        }
114 114
 
115
-		if (ini_get("safe_mode")) {
116
-			array_push($errors, "PHP safe mode setting is obsolete and not supported by tt-rss.");
117
-		}
115
+        if (ini_get("safe_mode")) {
116
+            array_push($errors, "PHP safe mode setting is obsolete and not supported by tt-rss.");
117
+        }
118 118
 
119
-		if (!class_exists("DOMDocument")) {
120
-			array_push($errors, "PHP support for DOMDocument is required, but was not found.");
121
-		}
119
+        if (!class_exists("DOMDocument")) {
120
+            array_push($errors, "PHP support for DOMDocument is required, but was not found.");
121
+        }
122 122
 
123
-		return $errors;
124
-	}
123
+        return $errors;
124
+    }
125 125
 
126
-	function print_error($msg) {
127
-		print "<div class='alert alert-error'>$msg</div>";
128
-	}
126
+    function print_error($msg) {
127
+        print "<div class='alert alert-error'>$msg</div>";
128
+    }
129 129
 
130
-	function print_notice($msg) {
131
-		print "<div class=\"alert alert-info\">$msg</div>";
132
-	}
130
+    function print_notice($msg) {
131
+        print "<div class=\"alert alert-info\">$msg</div>";
132
+    }
133 133
 
134
-	function pdo_connect($host, $user, $pass, $db, $type, $port = false) {
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
-		try {
140
-			$pdo = new PDO($type . ':dbname=' . $db . $db_host . $db_port,
141
-				$user,
142
-				$pass);
139
+        try {
140
+            $pdo = new PDO($type . ':dbname=' . $db . $db_host . $db_port,
141
+                $user,
142
+                $pass);
143 143
 
144
-			return $pdo;
145
-		} catch (Exception $e) {
146
-		    print "<div class='alert alert-danger'>" . $e->getMessage() . "</div>";
147
-		    return null;
144
+            return $pdo;
145
+        } catch (Exception $e) {
146
+            print "<div class='alert alert-danger'>" . $e->getMessage() . "</div>";
147
+            return null;
148 148
         }
149
-	}
150
-
151
-	function make_config($DB_TYPE, $DB_HOST, $DB_USER, $DB_NAME, $DB_PASS,
152
-			$DB_PORT, $SELF_URL_PATH) {
153
-
154
-		$data = explode("\n", file_get_contents("../config.php-dist"));
155
-
156
-		$rv = "";
157
-
158
-		$finished = false;
159
-
160
-		foreach ($data as $line) {
161
-			if (preg_match("/define\('DB_TYPE'/", $line)) {
162
-				$rv .= "\tdefine('DB_TYPE', '$DB_TYPE');\n";
163
-			} else if (preg_match("/define\('DB_HOST'/", $line)) {
164
-				$rv .= "\tdefine('DB_HOST', '$DB_HOST');\n";
165
-			} else if (preg_match("/define\('DB_USER'/", $line)) {
166
-				$rv .= "\tdefine('DB_USER', '$DB_USER');\n";
167
-			} else if (preg_match("/define\('DB_NAME'/", $line)) {
168
-				$rv .= "\tdefine('DB_NAME', '$DB_NAME');\n";
169
-			} else if (preg_match("/define\('DB_PASS'/", $line)) {
170
-				$rv .= "\tdefine('DB_PASS', '$DB_PASS');\n";
171
-			} else if (preg_match("/define\('DB_PORT'/", $line)) {
172
-				$rv .= "\tdefine('DB_PORT', '$DB_PORT');\n";
173
-			} else if (preg_match("/define\('SELF_URL_PATH'/", $line)) {
174
-				$rv .= "\tdefine('SELF_URL_PATH', '$SELF_URL_PATH');\n";
175
-			} else if (!$finished) {
176
-				$rv .= "$line\n";
177
-			}
178
-
179
-			if (preg_match("/\?\>/", $line)) {
180
-				$finished = true;
181
-			}
182
-		}
183
-
184
-		return $rv;
185
-	}
186
-
187
-	function is_server_https() {
188
-		return (!empty($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] != 'off')) || (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https');
189
-	}
190
-
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);
193
-
194
-		return $url_path;
195
-	}
149
+    }
150
+
151
+    function make_config($DB_TYPE, $DB_HOST, $DB_USER, $DB_NAME, $DB_PASS,
152
+            $DB_PORT, $SELF_URL_PATH) {
153
+
154
+        $data = explode("\n", file_get_contents("../config.php-dist"));
155
+
156
+        $rv = "";
157
+
158
+        $finished = false;
159
+
160
+        foreach ($data as $line) {
161
+            if (preg_match("/define\('DB_TYPE'/", $line)) {
162
+                $rv .= "\tdefine('DB_TYPE', '$DB_TYPE');\n";
163
+            } else if (preg_match("/define\('DB_HOST'/", $line)) {
164
+                $rv .= "\tdefine('DB_HOST', '$DB_HOST');\n";
165
+            } else if (preg_match("/define\('DB_USER'/", $line)) {
166
+                $rv .= "\tdefine('DB_USER', '$DB_USER');\n";
167
+            } else if (preg_match("/define\('DB_NAME'/", $line)) {
168
+                $rv .= "\tdefine('DB_NAME', '$DB_NAME');\n";
169
+            } else if (preg_match("/define\('DB_PASS'/", $line)) {
170
+                $rv .= "\tdefine('DB_PASS', '$DB_PASS');\n";
171
+            } else if (preg_match("/define\('DB_PORT'/", $line)) {
172
+                $rv .= "\tdefine('DB_PORT', '$DB_PORT');\n";
173
+            } else if (preg_match("/define\('SELF_URL_PATH'/", $line)) {
174
+                $rv .= "\tdefine('SELF_URL_PATH', '$SELF_URL_PATH');\n";
175
+            } else if (!$finished) {
176
+                $rv .= "$line\n";
177
+            }
178
+
179
+            if (preg_match("/\?\>/", $line)) {
180
+                $finished = true;
181
+            }
182
+        }
183
+
184
+        return $rv;
185
+    }
186
+
187
+    function is_server_https() {
188
+        return (!empty($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] != 'off')) || (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https');
189
+    }
190
+
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);
193
+
194
+        return $url_path;
195
+    }
196 196
 
197 197
 ?>
198 198
 
@@ -202,32 +202,32 @@  discard block
 block discarded – undo
202 202
 
203 203
 <?php
204 204
 
205
-	if (file_exists("../config.php")) {
206
-		require "../config.php";
205
+    if (file_exists("../config.php")) {
206
+        require "../config.php";
207 207
 
208
-		if (!defined('_INSTALLER_IGNORE_CONFIG_CHECK')) {
209
-			print_error("Error: config.php already exists in tt-rss directory; aborting.");
208
+        if (!defined('_INSTALLER_IGNORE_CONFIG_CHECK')) {
209
+            print_error("Error: config.php already exists in tt-rss directory; aborting.");
210 210
 
211
-			print "<form method='GET' action='../index.php'>
211
+            print "<form method='GET' action='../index.php'>
212 212
 				<button type='submit' dojoType='dijit.form.Button' class='alt-primary'>Return to Tiny Tiny RSS</button>
213 213
 				</form>";
214
-			exit;
215
-		}
216
-	}
217
-
218
-	@$op = $_REQUEST['op'];
219
-
220
-	@$DB_HOST = strip_tags($_POST['DB_HOST']);
221
-	@$DB_TYPE = strip_tags($_POST['DB_TYPE']);
222
-	@$DB_USER = strip_tags($_POST['DB_USER']);
223
-	@$DB_NAME = strip_tags($_POST['DB_NAME']);
224
-	@$DB_PASS = strip_tags($_POST['DB_PASS']);
225
-	@$DB_PORT = strip_tags($_POST['DB_PORT']);
226
-	@$SELF_URL_PATH = strip_tags($_POST['SELF_URL_PATH']);
227
-
228
-	if (!$SELF_URL_PATH) {
229
-		$SELF_URL_PATH = preg_replace("/\/install\/$/", "/", make_self_url_path());
230
-	}
214
+            exit;
215
+        }
216
+    }
217
+
218
+    @$op = $_REQUEST['op'];
219
+
220
+    @$DB_HOST = strip_tags($_POST['DB_HOST']);
221
+    @$DB_TYPE = strip_tags($_POST['DB_TYPE']);
222
+    @$DB_USER = strip_tags($_POST['DB_USER']);
223
+    @$DB_NAME = strip_tags($_POST['DB_NAME']);
224
+    @$DB_PASS = strip_tags($_POST['DB_PASS']);
225
+    @$DB_PORT = strip_tags($_POST['DB_PORT']);
226
+    @$SELF_URL_PATH = strip_tags($_POST['SELF_URL_PATH']);
227
+
228
+    if (!$SELF_URL_PATH) {
229
+        $SELF_URL_PATH = preg_replace("/\/install\/$/", "/", make_self_url_path());
230
+    }
231 231
 ?>
232 232
 
233 233
 <form action="" method="post">
@@ -236,9 +236,9 @@  discard block
 block discarded – undo
236 236
 	<h2>Database settings</h2>
237 237
 
238 238
 	<?php
239
-		$issel_pgsql = $DB_TYPE == "pgsql" ? "selected='selected'" : "";
240
-		$issel_mysql = $DB_TYPE == "mysql" ? "selected='selected'" : "";
241
-	?>
239
+        $issel_pgsql = $DB_TYPE == "pgsql" ? "selected='selected'" : "";
240
+        $issel_mysql = $DB_TYPE == "mysql" ? "selected='selected'" : "";
241
+    ?>
242 242
 
243 243
 	<fieldset>
244 244
 		<label>Database type:</label>
@@ -292,87 +292,87 @@  discard block
 block discarded – undo
292 292
 	<h2>Checking configuration</h2>
293 293
 
294 294
 	<?php
295
-		$errors = sanity_check($DB_TYPE);
295
+        $errors = sanity_check($DB_TYPE);
296 296
 
297
-		if (count($errors) > 0) {
298
-			print "<p>Some configuration tests failed. Please correct them before continuing.</p>";
297
+        if (count($errors) > 0) {
298
+            print "<p>Some configuration tests failed. Please correct them before continuing.</p>";
299 299
 
300
-			print "<ul>";
300
+            print "<ul>";
301 301
 
302
-			foreach ($errors as $error) {
303
-				print "<li style='color : red'>$error</li>";
304
-			}
302
+            foreach ($errors as $error) {
303
+                print "<li style='color : red'>$error</li>";
304
+            }
305 305
 
306
-			print "</ul>";
306
+            print "</ul>";
307 307
 
308
-			exit;
309
-		}
308
+            exit;
309
+        }
310 310
 
311
-		$notices = array();
311
+        $notices = array();
312 312
 
313
-		if (!function_exists("curl_init")) {
314
-			array_push($notices, "It is highly recommended to enable support for CURL in PHP.");
315
-		}
313
+        if (!function_exists("curl_init")) {
314
+            array_push($notices, "It is highly recommended to enable support for CURL in PHP.");
315
+        }
316 316
 
317
-		if (function_exists("curl_init") && ini_get("open_basedir")) {
318
-			array_push($notices, "CURL and open_basedir combination breaks support for HTTP redirects. See the FAQ for more information.");
319
-		}
317
+        if (function_exists("curl_init") && ini_get("open_basedir")) {
318
+            array_push($notices, "CURL and open_basedir combination breaks support for HTTP redirects. See the FAQ for more information.");
319
+        }
320 320
 
321
-		if (!function_exists("idn_to_ascii")) {
322
-			array_push($notices, "PHP support for Internationalization Functions is required to handle Internationalized Domain Names.");
323
-		}
321
+        if (!function_exists("idn_to_ascii")) {
322
+            array_push($notices, "PHP support for Internationalization Functions is required to handle Internationalized Domain Names.");
323
+        }
324 324
 
325 325
         if ($DB_TYPE == "mysql" && !function_exists("mysqli_connect")) {
326 326
             array_push($notices, "PHP extension for MySQL (mysqli) is missing. This may prevent legacy plugins from working.");
327 327
         }
328 328
 
329 329
         if ($DB_TYPE == "pgsql" && !function_exists("pg_connect")) {
330
-			array_push($notices, "PHP extension for PostgreSQL is missing. This may prevent legacy plugins from working.");
330
+            array_push($notices, "PHP extension for PostgreSQL is missing. This may prevent legacy plugins from working.");
331 331
         }
332 332
 
333
-		if (count($notices) > 0) {
334
-			print_notice("Configuration check succeeded with minor problems:");
333
+        if (count($notices) > 0) {
334
+            print_notice("Configuration check succeeded with minor problems:");
335 335
 
336
-			print "<ul>";
336
+            print "<ul>";
337 337
 
338
-			foreach ($notices as $notice) {
339
-				print "<li>$notice</li>";
340
-			}
338
+            foreach ($notices as $notice) {
339
+                print "<li>$notice</li>";
340
+            }
341 341
 
342
-			print "</ul>";
343
-		} else {
344
-			print_notice("Configuration check succeeded.");
345
-		}
342
+            print "</ul>";
343
+        } else {
344
+            print_notice("Configuration check succeeded.");
345
+        }
346 346
 
347
-	?>
347
+    ?>
348 348
 
349 349
 	<h2>Checking database</h2>
350 350
 
351 351
 	<?php
352
-		$pdo = pdo_connect($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME, $DB_TYPE, $DB_PORT);
352
+        $pdo = pdo_connect($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME, $DB_TYPE, $DB_PORT);
353 353
 
354
-		if (!$pdo) {
355
-			print_error("Unable to connect to database using specified parameters (driver: $DB_TYPE).");
356
-			exit;
357
-		}
354
+        if (!$pdo) {
355
+            print_error("Unable to connect to database using specified parameters (driver: $DB_TYPE).");
356
+            exit;
357
+        }
358 358
 
359
-		print_notice("Database test succeeded.");
360
-	?>
359
+        print_notice("Database test succeeded.");
360
+    ?>
361 361
 
362 362
 	<h2>Initialize database</h2>
363 363
 
364 364
 	<p>Before you can start using tt-rss, database needs to be initialized. Click on the button below to do that now.</p>
365 365
 
366 366
 	<?php
367
-		$res = $pdo->query("SELECT true FROM ttrss_feeds");
367
+        $res = $pdo->query("SELECT true FROM ttrss_feeds");
368 368
 
369
-		if ($res && $res->fetch()) {
370
-			print_error("Some tt-rss data already exists in this database. If you continue with database initialization your current data <b>WILL BE LOST</b>.");
371
-			$need_confirm = true;
372
-		} else {
373
-			$need_confirm = false;
374
-		}
375
-	?>
369
+        if ($res && $res->fetch()) {
370
+            print_error("Some tt-rss data already exists in this database. If you continue with database initialization your current data <b>WILL BE LOST</b>.");
371
+            $need_confirm = true;
372
+        } else {
373
+            $need_confirm = false;
374
+        }
375
+    ?>
376 376
 
377 377
 	<table><tr><td>
378 378
 	<form method="post">
@@ -415,44 +415,44 @@  discard block
 block discarded – undo
415 415
 
416 416
 	<?php
417 417
 
418
-		} else if ($op == 'installschema' || $op == 'skipschema') {
418
+        } else if ($op == 'installschema' || $op == 'skipschema') {
419 419
 
420
-			$pdo = pdo_connect($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME, $DB_TYPE, $DB_PORT);
420
+            $pdo = pdo_connect($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME, $DB_TYPE, $DB_PORT);
421 421
 
422
-			if (!$pdo) {
423
-				print_error("Unable to connect to database using specified parameters.");
424
-				exit;
425
-			}
422
+            if (!$pdo) {
423
+                print_error("Unable to connect to database using specified parameters.");
424
+                exit;
425
+            }
426 426
 
427
-			if ($op == 'installschema') {
427
+            if ($op == 'installschema') {
428 428
 
429
-				print "<h2>Initializing database...</h2>";
429
+                print "<h2>Initializing database...</h2>";
430 430
 
431
-				$lines = explode(";", preg_replace("/[\r\n]/", "",
431
+                $lines = explode(";", preg_replace("/[\r\n]/", "",
432 432
                     file_get_contents("../schema/ttrss_schema_".basename($DB_TYPE).".sql")));
433 433
 
434
-				foreach ($lines as $line) {
435
-					if (strpos($line, "--") !== 0 && $line) {
436
-						$res = $pdo->query($line);
434
+                foreach ($lines as $line) {
435
+                    if (strpos($line, "--") !== 0 && $line) {
436
+                        $res = $pdo->query($line);
437 437
 
438
-						if (!$res) {
439
-							print_notice("Query: $line");
440
-							print_error("Error: " . implode(", ", $pdo->errorInfo()));
438
+                        if (!$res) {
439
+                            print_notice("Query: $line");
440
+                            print_error("Error: " . implode(", ", $pdo->errorInfo()));
441 441
                         }
442
-					}
443
-				}
442
+                    }
443
+                }
444 444
 
445
-				print_notice("Database initialization completed.");
445
+                print_notice("Database initialization completed.");
446 446
 
447
-			} else {
448
-				print_notice("Database initialization skipped.");
449
-			}
447
+            } else {
448
+                print_notice("Database initialization skipped.");
449
+            }
450 450
 
451
-			print "<h2>Generated configuration file</h2>";
451
+            print "<h2>Generated configuration file</h2>";
452 452
 
453
-			print "<p>Copy following text and save as <code>config.php</code> in tt-rss main directory. It is suggested to read through the file to the end in case you need any options changed fom default values.</p>";
453
+            print "<p>Copy following text and save as <code>config.php</code> in tt-rss main directory. It is suggested to read through the file to the end in case you need any options changed fom default values.</p>";
454 454
 
455
-			print "<p>After copying the file, you will be able to login with default username and password combination: <code>admin</code> and <code>password</code>. Don't forget to change the password immediately!</p>"; ?>
455
+            print "<p>After copying the file, you will be able to login with default username and password combination: <code>admin</code> and <code>password</code>. Don't forget to change the password immediately!</p>"; ?>
456 456
 
457 457
 			<form action="" method="post">
458 458
 				<input type="hidden" name="op" value="saveconfig">
@@ -464,9 +464,9 @@  discard block
 block discarded – undo
464 464
 				<input type="hidden" name="DB_TYPE" value="<?php echo $DB_TYPE ?>"/>
465 465
 				<input type="hidden" name="SELF_URL_PATH" value="<?php echo $SELF_URL_PATH ?>"/>
466 466
 			<?php print "<textarea rows='20' style='width : 100%'>";
467
-			echo make_config($DB_TYPE, $DB_HOST, $DB_USER, $DB_NAME, $DB_PASS,
468
-				$DB_PORT, $SELF_URL_PATH);
469
-			print "</textarea>"; ?>
467
+            echo make_config($DB_TYPE, $DB_HOST, $DB_USER, $DB_NAME, $DB_PASS,
468
+                $DB_PORT, $SELF_URL_PATH);
469
+            print "</textarea>"; ?>
470 470
 
471 471
 			<hr/>
472 472
 
@@ -476,40 +476,40 @@  discard block
 block discarded – undo
476 476
 				<p><button type="submit" dojoType='dijit.form.Button' class='alt-primary'>Save configuration</button></p>
477 477
 				</form>
478 478
 			<?php } else {
479
-				print_error("Unfortunately, parent directory is not writable, so we're unable to save config.php automatically.");
480
-			}
479
+                print_error("Unfortunately, parent directory is not writable, so we're unable to save config.php automatically.");
480
+            }
481 481
 
482
-		   print_notice("You can generate the file again by changing the form above.");
482
+            print_notice("You can generate the file again by changing the form above.");
483 483
 
484
-		} else if ($op == "saveconfig") {
484
+        } else if ($op == "saveconfig") {
485 485
 
486
-			print "<h2>Saving configuration file to parent directory...</h2>";
486
+            print "<h2>Saving configuration file to parent directory...</h2>";
487 487
 
488
-			if (!file_exists("../config.php")) {
488
+            if (!file_exists("../config.php")) {
489 489
 
490
-				$fp = fopen("../config.php", "w");
490
+                $fp = fopen("../config.php", "w");
491 491
 
492
-				if ($fp) {
493
-					$written = fwrite($fp, make_config($DB_TYPE, $DB_HOST,
494
-						$DB_USER, $DB_NAME, $DB_PASS,
495
-						$DB_PORT, $SELF_URL_PATH));
492
+                if ($fp) {
493
+                    $written = fwrite($fp, make_config($DB_TYPE, $DB_HOST,
494
+                        $DB_USER, $DB_NAME, $DB_PASS,
495
+                        $DB_PORT, $SELF_URL_PATH));
496 496
 
497
-					if ($written > 0) {
498
-						print_notice("Successfully saved config.php. You can try <a href=\"..\">loading tt-rss now</a>.");
497
+                    if ($written > 0) {
498
+                        print_notice("Successfully saved config.php. You can try <a href=\"..\">loading tt-rss now</a>.");
499 499
 
500
-					} else {
501
-						print_notice("Unable to write into config.php in tt-rss directory.");
502
-					}
500
+                    } else {
501
+                        print_notice("Unable to write into config.php in tt-rss directory.");
502
+                    }
503 503
 
504
-					fclose($fp);
505
-				} else {
506
-					print_error("Unable to open config.php in tt-rss directory for writing.");
507
-				}
508
-			} else {
509
-				print_error("config.php already present in tt-rss directory, refusing to overwrite.");
510
-			}
511
-		}
512
-	?>
504
+                    fclose($fp);
505
+                } else {
506
+                    print_error("Unable to open config.php in tt-rss directory for writing.");
507
+                }
508
+            } else {
509
+                print_error("config.php already present in tt-rss directory, refusing to overwrite.");
510
+            }
511
+        }
512
+    ?>
513 513
 
514 514
 </div>
515 515
 
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -17,7 +17,9 @@
 block discarded – undo
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
 	}
Please login to merge, or discard this patch.
opml.php 3 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
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
 block discarded – undo
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]);
Please login to merge, or discard this patch.
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -1,35 +1,35 @@
 block discarded – undo
1 1
 <?php
2
-	set_include_path(dirname(__FILE__) ."/include" . PATH_SEPARATOR .
3
-		get_include_path());
2
+    set_include_path(dirname(__FILE__) ."/include" . PATH_SEPARATOR .
3
+        get_include_path());
4 4
 
5
-	require_once "autoload.php";
6
-	require_once "functions.php";
7
-	require_once "sessions.php";
8
-	require_once "sanity_check.php";
9
-	require_once "config.php";
10
-	require_once "db.php";
11
-	require_once "db-prefs.php";
5
+    require_once "autoload.php";
6
+    require_once "functions.php";
7
+    require_once "sessions.php";
8
+    require_once "sanity_check.php";
9
+    require_once "config.php";
10
+    require_once "db.php";
11
+    require_once "db-prefs.php";
12 12
 
13
-	if (!init_plugins()) return;
13
+    if (!init_plugins()) return;
14 14
 
15
-	$op = $_REQUEST['op'];
15
+    $op = $_REQUEST['op'];
16 16
 
17
-	if ($op == "publish"){
18
-		$key = $_REQUEST["key"];
19
-		$pdo = Db::pdo();
17
+    if ($op == "publish"){
18
+        $key = $_REQUEST["key"];
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
-		$sth->execute([$key]);
24
+        $sth->execute([$key]);
25 25
 
26
-		if ($row = $sth->fetch()) {
27
-			$owner_uid = $row['owner_uid'];
26
+        if ($row = $sth->fetch()) {
27
+            $owner_uid = $row['owner_uid'];
28 28
 
29
-			$opml = new Opml($_REQUEST);
30
-			$opml->opml_export("", $owner_uid, true, false);
29
+            $opml = new Opml($_REQUEST);
30
+            $opml->opml_export("", $owner_uid, true, false);
31 31
 
32
-		} else {
33
-			print "<error>User not found</error>";
34
-		}
35
-	}
32
+        } else {
33
+            print "<error>User not found</error>";
34
+        }
35
+    }
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -10,7 +10,9 @@
 block discarded – undo
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
 
Please login to merge, or discard this patch.
lib/MiniTemplator.class.php 4 patches
Switch Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -295,23 +295,23 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
Spacing   +165 added lines, -165 removed lines patch added patch discarded remove patch
@@ -89,16 +89,16 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
Indentation   +383 added lines, -383 removed lines patch added patch discarded remove patch
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
 * @access public
162 162
 */
163 163
 function __construct() {
164
-   $this->templateValid = false; }
164
+    $this->templateValid = false; }
165 165
 
166 166
 //--- template string handling --------------------------------------------------------------------------------------
167 167
 
@@ -172,11 +172,11 @@  discard block
 block discarded – undo
172 172
 * @access public
173 173
 */
174 174
 function readTemplateFromFile ($fileName) {
175
-   if (!$this->readFileIntoString($fileName,$s)) {
176
-      $this->triggerError ("Error while reading template file " . $fileName . ".");
177
-      return false; }
178
-   if (!$this->setTemplateString($s)) return false;
179
-   return true; }
175
+    if (!$this->readFileIntoString($fileName,$s)) {
176
+        $this->triggerError ("Error while reading template file " . $fileName . ".");
177
+        return false; }
178
+    if (!$this->setTemplateString($s)) return false;
179
+    return true; }
180 180
 
181 181
 /**
182 182
 * Assigns a new template string.
@@ -185,12 +185,12 @@  discard block
 block discarded – undo
185 185
 * @access public
186 186
 */
187 187
 function setTemplateString ($templateString) {
188
-   $this->templateValid = false;
189
-   $this->template = $templateString;
190
-   if (!$this->parseTemplate()) return false;
191
-   $this->reset();
192
-   $this->templateValid = true;
193
-   return true; }
188
+    $this->templateValid = false;
189
+    $this->template = $templateString;
190
+    if (!$this->parseTemplate()) return false;
191
+    $this->reset();
192
+    $this->templateValid = true;
193
+    return true; }
194 194
 
195 195
 /**
196 196
 * Loads the template string for a subtemplate (used for the $Include command).
@@ -198,11 +198,11 @@  discard block
 block discarded – undo
198 198
 * @access private
199 199
 */
200 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
-      return false; }
205
-   return true; }
201
+    $subtemplateFileName = $this->combineFileSystemPath($this->subtemplateBasePath,$subtemplateName);
202
+    if (!$this->readFileIntoString($subtemplateFileName,$s)) {
203
+        $this->triggerError ("Error while reading subtemplate file " . $subtemplateFileName . ".");
204
+        return false; }
205
+    return true; }
206 206
 
207 207
 //--- template parsing ----------------------------------------------------------------------------------------------
208 208
 
@@ -212,28 +212,28 @@  discard block
 block discarded – undo
212 212
 * @access private
213 213
 */
214 214
 function parseTemplate() {
215
-   $this->initParsing();
216
-   $this->beginMainBlock();
217
-   if (!$this->parseTemplateCommands()) return false;
218
-   $this->endMainBlock();
219
-   if (!$this->checkBlockDefinitionsComplete()) return false;
220
-   if (!$this->parseTemplateVariables()) return false;
221
-   $this->associateVariablesWithBlocks();
222
-   return true; }
215
+    $this->initParsing();
216
+    $this->beginMainBlock();
217
+    if (!$this->parseTemplateCommands()) return false;
218
+    $this->endMainBlock();
219
+    if (!$this->checkBlockDefinitionsComplete()) return false;
220
+    if (!$this->parseTemplateVariables()) return false;
221
+    $this->associateVariablesWithBlocks();
222
+    return true; }
223 223
 
224 224
 /**
225 225
 * @access private
226 226
 */
227 227
 function initParsing() {
228
-   $this->varTab = array();
229
-   $this->varTabCnt = 0;
230
-   $this->varNameToNoMap = array();
231
-   $this->varRefTab = array();
232
-   $this->varRefTabCnt = 0;
233
-   $this->blockTab = array();
234
-   $this->blockTabCnt = 0;
235
-   $this->blockNameToNoMap = array();
236
-   $this->openBlocksTab = array(); }
228
+    $this->varTab = array();
229
+    $this->varTabCnt = 0;
230
+    $this->varNameToNoMap = array();
231
+    $this->varRefTab = array();
232
+    $this->varRefTabCnt = 0;
233
+    $this->blockTab = array();
234
+    $this->blockTabCnt = 0;
235
+    $this->blockNameToNoMap = array();
236
+    $this->openBlocksTab = array(); }
237 237
 
238 238
 /**
239 239
 * Registers the main block.
@@ -241,27 +241,27 @@  discard block
 block discarded – undo
241 241
 * @access private
242 242
 */
243 243
 function beginMainBlock() {
244
-   $blockNo = 0;
245
-   $this->registerBlock('@@InternalMainBlock@@', $blockNo);
246
-   $bte =& $this->blockTab[$blockNo];
247
-   $bte['tPosBegin'] = 0;
248
-   $bte['tPosContentsBegin'] = 0;
249
-   $bte['nestingLevel'] = 0;
250
-   $bte['parentBlockNo'] = -1;
251
-   $bte['definitionIsOpen'] = true;
252
-   $this->openBlocksTab[0] = $blockNo;
253
-   $this->currentNestingLevel = 1; }
244
+    $blockNo = 0;
245
+    $this->registerBlock('@@InternalMainBlock@@', $blockNo);
246
+    $bte =& $this->blockTab[$blockNo];
247
+    $bte['tPosBegin'] = 0;
248
+    $bte['tPosContentsBegin'] = 0;
249
+    $bte['nestingLevel'] = 0;
250
+    $bte['parentBlockNo'] = -1;
251
+    $bte['definitionIsOpen'] = true;
252
+    $this->openBlocksTab[0] = $blockNo;
253
+    $this->currentNestingLevel = 1; }
254 254
 
255 255
 /**
256 256
 * Completes the main block registration.
257 257
 * @access private
258 258
 */
259 259
 function endMainBlock() {
260
-   $bte =& $this->blockTab[0];
261
-   $bte['tPosContentsEnd'] = strlen($this->template);
262
-   $bte['tPosEnd'] = strlen($this->template);
263
-   $bte['definitionIsOpen'] = false;
264
-   $this->currentNestingLevel -= 1; }
260
+    $bte =& $this->blockTab[0];
261
+    $bte['tPosContentsEnd'] = strlen($this->template);
262
+    $bte['tPosEnd'] = strlen($this->template);
263
+    $bte['definitionIsOpen'] = false;
264
+    $this->currentNestingLevel -= 1; }
265 265
 
266 266
 /**
267 267
 * Parses commands within the template in the format "<!-- $command parameters -->".
@@ -269,46 +269,46 @@  discard block
 block discarded – undo
269 269
 * @access private
270 270
 */
271 271
 function parseTemplateCommands() {
272
-   $p = 0;
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; }
285
-   return true; }
272
+    $p = 0;
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; }
285
+    return true; }
286 286
 
287 287
 /**
288 288
 * @return boolean  true on success, false on error.
289 289
 * @access private
290 290
 */
291 291
 function processTemplateCommand ($cmdL, $cmdTPosBegin, $cmdTPosEnd, &$resumeFromStart) {
292
-   $resumeFromStart = false;
293
-   $p = 0;
294
-   $cmd = '';
295
-   if (!$this->parseWord($cmdL,$p,$cmd)) return true;
296
-   $parms = substr($cmdL,$p);
297
-   switch (strtoupper($cmd)) {
298
-      case '$BEGINBLOCK':
292
+    $resumeFromStart = false;
293
+    $p = 0;
294
+    $cmd = '';
295
+    if (!$this->parseWord($cmdL,$p,$cmd)) return true;
296
+    $parms = substr($cmdL,$p);
297
+    switch (strtoupper($cmd)) {
298
+        case '$BEGINBLOCK':
299 299
          if (!$this->processBeginBlockCmd($parms,$cmdTPosBegin,$cmdTPosEnd))
300 300
             return false;
301
-         break;
302
-      case '$ENDBLOCK':
301
+            break;
302
+        case '$ENDBLOCK':
303 303
          if (!$this->processEndBlockCmd($parms,$cmdTPosBegin,$cmdTPosEnd))
304 304
             return false;
305
-         break;
306
-      case '$INCLUDE':
305
+            break;
306
+        case '$INCLUDE':
307 307
          if (!$this->processincludeCmd($parms,$cmdTPosBegin,$cmdTPosEnd))
308 308
             return false;
309
-         $resumeFromStart = true;
310
-         break;
311
-      default:
309
+            $resumeFromStart = true;
310
+            break;
311
+        default:
312 312
          if ($cmd{0} == '$' && !(strlen($cmd) >= 2 && $cmd{1} == '{')) {
313 313
             $this->triggerError ("Unknown command \"$cmd\" in template at offset $cmdTPosBegin.");
314 314
             return false; }}
@@ -320,25 +320,25 @@  discard block
 block discarded – undo
320 320
 * @access private
321 321
 */
322 322
 function processBeginBlockCmd ($parms, $cmdTPosBegin, $cmdTPosEnd) {
323
-   $p = 0;
324
-   if (!$this->parseWord($parms,$p,$blockName)) {
325
-      $this->triggerError ("Missing block name in \$BeginBlock command in template at offset $cmdTPosBegin.");
326
-      return false; }
327
-   if (trim(substr($parms,$p)) != '') {
328
-      $this->triggerError ("Extra parameter in \$BeginBlock command in template at offset $cmdTPosBegin.");
329
-      return false; }
330
-   $this->registerBlock ($blockName, $blockNo);
331
-   $btr =& $this->blockTab[$blockNo];
332
-   $btr['tPosBegin'] = $cmdTPosBegin;
333
-   $btr['tPosContentsBegin'] = $cmdTPosEnd;
334
-   $btr['nestingLevel'] = $this->currentNestingLevel;
335
-   $btr['parentBlockNo'] = $this->openBlocksTab[$this->currentNestingLevel-1];
336
-   $this->openBlocksTab[$this->currentNestingLevel] = $blockNo;
337
-   $this->currentNestingLevel += 1;
338
-   if ($this->currentNestingLevel > $this->maxNestingLevel) {
339
-      $this->triggerError ("Block nesting overflow in template at offset $cmdTPosBegin.");
340
-      return false; }
341
-   return true; }
323
+    $p = 0;
324
+    if (!$this->parseWord($parms,$p,$blockName)) {
325
+        $this->triggerError ("Missing block name in \$BeginBlock command in template at offset $cmdTPosBegin.");
326
+        return false; }
327
+    if (trim(substr($parms,$p)) != '') {
328
+        $this->triggerError ("Extra parameter in \$BeginBlock command in template at offset $cmdTPosBegin.");
329
+        return false; }
330
+    $this->registerBlock ($blockName, $blockNo);
331
+    $btr =& $this->blockTab[$blockNo];
332
+    $btr['tPosBegin'] = $cmdTPosBegin;
333
+    $btr['tPosContentsBegin'] = $cmdTPosEnd;
334
+    $btr['nestingLevel'] = $this->currentNestingLevel;
335
+    $btr['parentBlockNo'] = $this->openBlocksTab[$this->currentNestingLevel-1];
336
+    $this->openBlocksTab[$this->currentNestingLevel] = $blockNo;
337
+    $this->currentNestingLevel += 1;
338
+    if ($this->currentNestingLevel > $this->maxNestingLevel) {
339
+        $this->triggerError ("Block nesting overflow in template at offset $cmdTPosBegin.");
340
+        return false; }
341
+    return true; }
342 342
 
343 343
 /**
344 344
 * Processes the $EndBlock command.
@@ -346,47 +346,47 @@  discard block
 block discarded – undo
346 346
 * @access private
347 347
 */
348 348
 function processEndBlockCmd ($parms, $cmdTPosBegin, $cmdTPosEnd) {
349
-   $p = 0;
350
-   if (!$this->parseWord($parms,$p,$blockName)) {
351
-      $this->triggerError ("Missing block name in \$EndBlock command in template at offset $cmdTPosBegin.");
352
-      return false; }
353
-   if (trim(substr($parms,$p)) != '') {
354
-      $this->triggerError ("Extra parameter in \$EndBlock command in template at offset $cmdTPosBegin.");
355
-      return false; }
356
-   if (!$this->lookupBlockName($blockName,$blockNo)) {
357
-      $this->triggerError ("Undefined block name \"$blockName\" in \$EndBlock command in template at offset $cmdTPosBegin.");
358
-      return false; }
359
-   $this->currentNestingLevel -= 1;
360
-   $btr =& $this->blockTab[$blockNo];
361
-   if (!$btr['definitionIsOpen']) {
362
-      $this->triggerError ("Multiple \$EndBlock command for block \"$blockName\" in template at offset $cmdTPosBegin.");
363
-      return false; }
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; }
367
-   $btr['tPosContentsEnd'] = $cmdTPosBegin;
368
-   $btr['tPosEnd'] = $cmdTPosEnd;
369
-   $btr['definitionIsOpen'] = false;
370
-   return true; }
349
+    $p = 0;
350
+    if (!$this->parseWord($parms,$p,$blockName)) {
351
+        $this->triggerError ("Missing block name in \$EndBlock command in template at offset $cmdTPosBegin.");
352
+        return false; }
353
+    if (trim(substr($parms,$p)) != '') {
354
+        $this->triggerError ("Extra parameter in \$EndBlock command in template at offset $cmdTPosBegin.");
355
+        return false; }
356
+    if (!$this->lookupBlockName($blockName,$blockNo)) {
357
+        $this->triggerError ("Undefined block name \"$blockName\" in \$EndBlock command in template at offset $cmdTPosBegin.");
358
+        return false; }
359
+    $this->currentNestingLevel -= 1;
360
+    $btr =& $this->blockTab[$blockNo];
361
+    if (!$btr['definitionIsOpen']) {
362
+        $this->triggerError ("Multiple \$EndBlock command for block \"$blockName\" in template at offset $cmdTPosBegin.");
363
+        return false; }
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; }
367
+    $btr['tPosContentsEnd'] = $cmdTPosBegin;
368
+    $btr['tPosEnd'] = $cmdTPosEnd;
369
+    $btr['definitionIsOpen'] = false;
370
+    return true; }
371 371
 
372 372
 /**
373 373
 * @access private
374 374
 */
375 375
 function registerBlock($blockName, &$blockNo) {
376
-   $blockNo = $this->blockTabCnt++;
377
-   $btr =& $this->blockTab[$blockNo];
378
-   $btr = array();
379
-   $btr['blockName'] = $blockName;
380
-   if (!$this->lookupBlockName($blockName,$btr['nextWithSameName']))
381
-      $btr['nextWithSameName'] = -1;
382
-   $btr['definitionIsOpen'] = true;
383
-   $btr['instances'] = 0;
384
-   $btr['firstBlockInstNo'] = -1;
385
-   $btr['lastBlockInstNo'] = -1;
386
-   $btr['blockVarCnt'] = 0;
387
-   $btr['firstVarRefNo'] = -1;
388
-   $btr['blockVarNoToVarNoMap'] = array();
389
-   $this->blockNameToNoMap[strtoupper($blockName)] = $blockNo; }
376
+    $blockNo = $this->blockTabCnt++;
377
+    $btr =& $this->blockTab[$blockNo];
378
+    $btr = array();
379
+    $btr['blockName'] = $blockName;
380
+    if (!$this->lookupBlockName($blockName,$btr['nextWithSameName']))
381
+        $btr['nextWithSameName'] = -1;
382
+    $btr['definitionIsOpen'] = true;
383
+    $btr['instances'] = 0;
384
+    $btr['firstBlockInstNo'] = -1;
385
+    $btr['lastBlockInstNo'] = -1;
386
+    $btr['blockVarCnt'] = 0;
387
+    $btr['firstVarRefNo'] = -1;
388
+    $btr['blockVarNoToVarNoMap'] = array();
389
+    $this->blockNameToNoMap[strtoupper($blockName)] = $blockNo; }
390 390
 
391 391
 /**
392 392
 * Checks that all block definitions are closed.
@@ -394,15 +394,15 @@  discard block
 block discarded – undo
394 394
 * @access private
395 395
 */
396 396
 function checkBlockDefinitionsComplete() {
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; }}
402
-   if ($this->currentNestingLevel != 0) {
403
-      $this->triggerError ("Block nesting level error at end of template.");
404
-      return false; }
405
-   return true; }
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; }}
402
+    if ($this->currentNestingLevel != 0) {
403
+        $this->triggerError ("Block nesting level error at end of template.");
404
+        return false; }
405
+    return true; }
406 406
 
407 407
 /**
408 408
 * Processes the $Include command.
@@ -410,14 +410,14 @@  discard block
 block discarded – undo
410 410
 * @access private
411 411
 */
412 412
 function processIncludeCmd ($parms, $cmdTPosBegin, $cmdTPosEnd) {
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.");
416
-      return false; }
417
-   if (trim(substr($parms,$p)) != '') {
418
-      $this->triggerError ("Extra parameter in \$include command in template at offset $cmdTPosBegin.");
419
-      return false; }
420
-   return $this->insertSubtemplate($subtemplateName,$cmdTPosBegin,$cmdTPosEnd); }
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.");
416
+        return false; }
417
+    if (trim(substr($parms,$p)) != '') {
418
+        $this->triggerError ("Extra parameter in \$include command in template at offset $cmdTPosBegin.");
419
+        return false; }
420
+    return $this->insertSubtemplate($subtemplateName,$cmdTPosBegin,$cmdTPosEnd); }
421 421
 
422 422
 /**
423 423
 * Processes the $Include command.
@@ -425,14 +425,14 @@  discard block
 block discarded – undo
425 425
 * @access private
426 426
 */
427 427
 function insertSubtemplate ($subtemplateName, $tPos1, $tPos2) {
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; }
431
-   if (!$this->loadSubtemplate($subtemplateName,$subtemplate)) return false;
432
-   // (Copying the template to insert a subtemplate is a bit slow. In a future implementation of MiniTemplator,
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);
435
-   return true; }
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; }
431
+    if (!$this->loadSubtemplate($subtemplateName,$subtemplate)) return false;
432
+    // (Copying the template to insert a subtemplate is a bit slow. In a future implementation of MiniTemplator,
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);
435
+    return true; }
436 436
 
437 437
 /**
438 438
 * Parses variable references within the template in the format "${VarName}".
@@ -440,77 +440,77 @@  discard block
 block discarded – undo
440 440
 * @access private
441 441
 */
442 442
 function parseTemplateVariables() {
443
-   $p = 0;
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); }
458
-   return true; }
443
+    $p = 0;
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); }
458
+    return true; }
459 459
 
460 460
 /**
461 461
 * @access private
462 462
 */
463 463
 function registerVariableReference ($varName, $tPosBegin, $tPosEnd) {
464
-   if (!$this->lookupVariableName($varName,$varNo))
465
-      $this->registerVariable($varName,$varNo);
466
-   $varRefNo = $this->varRefTabCnt++;
467
-   $vrtr =& $this->varRefTab[$varRefNo];
468
-   $vrtr = array();
469
-   $vrtr['tPosBegin'] = $tPosBegin;
470
-   $vrtr['tPosEnd'] = $tPosEnd;
471
-   $vrtr['varNo'] = $varNo; }
464
+    if (!$this->lookupVariableName($varName,$varNo))
465
+        $this->registerVariable($varName,$varNo);
466
+    $varRefNo = $this->varRefTabCnt++;
467
+    $vrtr =& $this->varRefTab[$varRefNo];
468
+    $vrtr = array();
469
+    $vrtr['tPosBegin'] = $tPosBegin;
470
+    $vrtr['tPosEnd'] = $tPosEnd;
471
+    $vrtr['varNo'] = $varNo; }
472 472
 
473 473
 /**
474 474
 * @access private
475 475
 */
476 476
 function registerVariable ($varName, &$varNo) {
477
-   $varNo = $this->varTabCnt++;
478
-   $vtr =& $this->varTab[$varNo];
479
-   $vtr = array();
480
-   $vtr['varName'] = $varName;
481
-   $vtr['varValue'] = '';
482
-   $this->varNameToNoMap[strtoupper($varName)] = $varNo; }
477
+    $varNo = $this->varTabCnt++;
478
+    $vtr =& $this->varTab[$varNo];
479
+    $vtr = array();
480
+    $vtr['varName'] = $varName;
481
+    $vtr['varValue'] = '';
482
+    $this->varNameToNoMap[strtoupper($varName)] = $varNo; }
483 483
 
484 484
 /**
485 485
 * Associates variable references with blocks.
486 486
 * @access private
487 487
 */
488 488
 function associateVariablesWithBlocks() {
489
-   $varRefNo = 0;
490
-   $activeBlockNo = 0;
491
-   $nextBlockNo = 1;
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']) {
489
+    $varRefNo = 0;
490
+    $activeBlockNo = 0;
491
+    $nextBlockNo = 1;
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 501
             $activeBlockNo = $nextBlockNo;
502 502
             $nextBlockNo += 1;
503 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; }}
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
 
@@ -523,15 +523,15 @@  discard block
 block discarded – undo
523 523
 * @access public
524 524
 */
525 525
 function reset() {
526
-   for ($varNo=0; $varNo<$this->varTabCnt; $varNo++)
527
-      $this->varTab[$varNo]['varValue'] = '';
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; }
533
-   $this->blockInstTab = array();
534
-   $this->blockInstTabCnt = 0; }
526
+    for ($varNo=0; $varNo<$this->varTabCnt; $varNo++)
527
+        $this->varTab[$varNo]['varValue'] = '';
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; }
533
+    $this->blockInstTab = array();
534
+    $this->blockInstTabCnt = 0; }
535 535
 
536 536
 /**
537 537
 * Sets a template variable.
@@ -549,13 +549,13 @@  discard block
 block discarded – undo
549 549
 * @access public
550 550
 */
551 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
-      if ($isOptional) return true;
555
-      $this->triggerError ("Variable \"$variableName\" not defined in template.");
556
-      return false; }
557
-   $this->varTab[$varNo]['varValue'] = $variableValue;
558
-   return true; }
552
+    if (!$this->templateValid) {$this->triggerError ("Template not valid."); return false; }
553
+    if (!$this->lookupVariableName($variableName,$varNo)) {
554
+        if ($isOptional) return true;
555
+        $this->triggerError ("Variable \"$variableName\" not defined in template.");
556
+        return false; }
557
+    $this->varTab[$varNo]['varValue'] = $variableValue;
558
+    return true; }
559 559
 
560 560
 /**
561 561
 * Sets a template variable to an escaped string.
@@ -576,7 +576,7 @@  discard block
 block discarded – undo
576 576
 * @access public
577 577
 */
578 578
 function setVariableEsc ($variableName, $variableValue, $isOptional=false) {
579
-   return $this->setVariable($variableName,htmlspecialchars($variableValue,ENT_QUOTES),$isOptional); }
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.
@@ -586,8 +586,8 @@  discard block
 block discarded – undo
586 586
 * @access public
587 587
 */
588 588
 function variableExists ($variableName) {
589
-   if (!$this->templateValid) {$this->triggerError ("Template not valid."); return false; }
590
-   return $this->lookupVariableName($variableName,$varNo); }
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,48 +603,48 @@  discard block
 block discarded – undo
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.");
609
-      return false; }
610
-   while ($blockNo != -1) {
611
-      $this->addBlockByNo($blockNo);
612
-      $blockNo = $this->blockTab[$blockNo]['nextWithSameName']; }
613
-   return true; }
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
+        return false; }
610
+    while ($blockNo != -1) {
611
+        $this->addBlockByNo($blockNo);
612
+        $blockNo = $this->blockTab[$blockNo]['nextWithSameName']; }
613
+    return true; }
614 614
 
615 615
 /**
616 616
 * @access private
617 617
 */
618 618
 function addBlockByNo ($blockNo) {
619
-   $btr =& $this->blockTab[$blockNo];
620
-   $this->registerBlockInstance ($blockInstNo);
621
-   $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;
626
-         // set forward pointer of chain
627
-   $btr['lastBlockInstNo'] = $blockInstNo;
628
-   $parentBlockNo = $btr['parentBlockNo'];
629
-   $blockVarCnt = $btr['blockVarCnt'];
630
-   $bitr['blockNo'] = $blockNo;
631
-   $bitr['instanceLevel'] = $btr['instances']++;
632
-   if ($parentBlockNo == -1)
633
-      $bitr['parentInstLevel'] = -1;
619
+    $btr =& $this->blockTab[$blockNo];
620
+    $this->registerBlockInstance ($blockInstNo);
621
+    $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;
626
+            // set forward pointer of chain
627
+    $btr['lastBlockInstNo'] = $blockInstNo;
628
+    $parentBlockNo = $btr['parentBlockNo'];
629
+    $blockVarCnt = $btr['blockVarCnt'];
630
+    $bitr['blockNo'] = $blockNo;
631
+    $bitr['instanceLevel'] = $btr['instances']++;
632
+    if ($parentBlockNo == -1)
633
+        $bitr['parentInstLevel'] = -1;
634 634
     else
635
-      $bitr['parentInstLevel'] = $this->blockTab[$parentBlockNo]['instances'];
636
-   $bitr['nextBlockInstNo'] = -1;
637
-   $bitr['blockVarTab'] = array();
638
-   // copy instance variables for this block
639
-   for ($blockVarNo=0; $blockVarNo<$blockVarCnt; $blockVarNo++) {
640
-      $varNo = $btr['blockVarNoToVarNoMap'][$blockVarNo];
641
-      $bitr['blockVarTab'][$blockVarNo] = $this->varTab[$varNo]['varValue']; }}
635
+        $bitr['parentInstLevel'] = $this->blockTab[$parentBlockNo]['instances'];
636
+    $bitr['nextBlockInstNo'] = -1;
637
+    $bitr['blockVarTab'] = array();
638
+    // copy instance variables for this block
639
+    for ($blockVarNo=0; $blockVarNo<$blockVarCnt; $blockVarNo++) {
640
+        $varNo = $btr['blockVarNoToVarNoMap'][$blockVarNo];
641
+        $bitr['blockVarTab'][$blockVarNo] = $this->varTab[$varNo]['varValue']; }}
642 642
 
643 643
 /**
644 644
 * @access private
645 645
 */
646 646
 function registerBlockInstance (&$blockInstNo) {
647
-   $blockInstNo = $this->blockInstTabCnt++; }
647
+    $blockInstNo = $this->blockInstTabCnt++; }
648 648
 
649 649
 /**
650 650
 * Checks whether a block with the specified name exists within the template.
@@ -654,8 +654,8 @@  discard block
 block discarded – undo
654 654
 * @access public
655 655
 */
656 656
 function blockExists ($blockName) {
657
-   if (!$this->templateValid) {$this->triggerError ("Template not valid."); return false; }
658
-   return $this->lookupBlockName($blockName,$blockNo); }
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
 
@@ -665,9 +665,9 @@  discard block
 block discarded – undo
665 665
 * @access public
666 666
 */
667 667
 function generateOutput () {
668
-   $this->outputMode = 0;
669
-   if (!$this->generateOutputPage()) return false;
670
-   return true; }
668
+    $this->outputMode = 0;
669
+    if (!$this->generateOutputPage()) return false;
670
+    return true; }
671 671
 
672 672
 /**
673 673
 * Generates the HTML page and writes it to a file.
@@ -676,13 +676,13 @@  discard block
 block discarded – undo
676 676
 * @access public
677 677
 */
678 678
 function generateOutputToFile ($fileName) {
679
-   $fh = fopen($fileName,"wb");
680
-   if ($fh === false) return false;
681
-   $this->outputMode = 1;
682
-   $this->outputFileHandle = $fh;
683
-   $ok = $this->generateOutputPage();
684
-   fclose ($fh);
685
-   return $ok; }
679
+    $fh = fopen($fileName,"wb");
680
+    if ($fh === false) return false;
681
+    $this->outputMode = 1;
682
+    $this->outputFileHandle = $fh;
683
+    $ok = $this->generateOutputPage();
684
+    fclose ($fh);
685
+    return $ok; }
686 686
 
687 687
 /**
688 688
 * Generates the HTML page and writes it to a string.
@@ -692,28 +692,28 @@  discard block
 block discarded – undo
692 692
 * @access public
693 693
 */
694 694
 function generateOutputToString (&$outputString) {
695
-   $outputString = "Error";
696
-   $this->outputMode = 2;
697
-   $this->outputString = "";
698
-   if (!$this->generateOutputPage()) return false;
699
-   $outputString = $this->outputString;
700
-   return true; }
695
+    $outputString = "Error";
696
+    $this->outputMode = 2;
697
+    $this->outputString = "";
698
+    if (!$this->generateOutputPage()) return false;
699
+    $outputString = $this->outputString;
700
+    return true; }
701 701
 
702 702
 /**
703 703
 * @access private
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; }
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];
712
-       $btr['currBlockInstNo'] = $btr['firstBlockInstNo']; }
713
-   $this->outputError = false;
714
-   $this->writeBlockInstances (0, -1);
715
-   if ($this->outputError) return false;
716
-   return true; }
707
+    if (!$this->templateValid) {$this->triggerError ("Template not valid."); return false; }
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];
712
+        $btr['currBlockInstNo'] = $btr['firstBlockInstNo']; }
713
+    $this->outputError = false;
714
+    $this->writeBlockInstances (0, -1);
715
+    if ($this->outputError) return false;
716
+    return true; }
717 717
 
718 718
 /**
719 719
 * Writes all instances of a block that are contained within a specific
@@ -722,64 +722,64 @@  discard block
 block discarded – undo
722 722
 * @access private
723 723
 */
724 724
 function writeBlockInstances ($blockNo, $parentInstLevel) {
725
-   $btr =& $this->blockTab[$blockNo];
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']; }}
725
+    $btr =& $this->blockTab[$blockNo];
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']; }}
735 735
 
736 736
 /**
737 737
 * @access private
738 738
 */
739 739
 function writeBlockInstance($blockInstNo) {
740
-   $bitr =& $this->blockInstTab[$blockInstNo];
741
-   $blockNo = $bitr['blockNo'];
742
-   $btr =& $this->blockTab[$blockNo];
743
-   $tPos = $btr['tPosContentsBegin'];
744
-   $subBlockNo = $blockNo + 1;
745
-   $varRefNo = $btr['firstVarRefNo'];
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) {
740
+    $bitr =& $this->blockInstTab[$blockInstNo];
741
+    $blockNo = $bitr['blockNo'];
742
+    $btr =& $this->blockTab[$blockNo];
743
+    $tPos = $btr['tPosContentsBegin'];
744
+    $subBlockNo = $blockNo + 1;
745
+    $varRefNo = $btr['firstVarRefNo'];
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 752
             $varRefNo += 1;
753 753
             continue; }
754
-         if ($vrtr['tPosBegin'] < $tPos2) {
754
+            if ($vrtr['tPosBegin'] < $tPos2) {
755 755
             $tPos2 = $vrtr['tPosBegin'];
756 756
             $kind = 1; }}
757
-      if ($subBlockNo < $this->blockTabCnt) {   // check for subblock
758
-         $subBtr =& $this->blockTab[$subBlockNo];
759
-         if ($subBtr['tPosBegin'] < $tPos) {
757
+        if ($subBlockNo < $this->blockTabCnt) {   // check for subblock
758
+            $subBtr =& $this->blockTab[$subBlockNo];
759
+            if ($subBtr['tPosBegin'] < $tPos) {
760 760
             $subBlockNo += 1;
761 761
             continue; }
762
-         if ($subBtr['tPosBegin'] < $tPos2) {
762
+            if ($subBtr['tPosBegin'] < $tPos2) {
763 763
             $tPos2 = $subBtr['tPosBegin'];
764 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
765
+        if ($tPos2 > $tPos)
766
+            $this->writeString (substr($this->template,$tPos,$tPos2-$tPos));
767
+        switch ($kind) {
768
+            case 0:         // end of block
769 769
             return;
770
-         case 1:         // variable
770
+            case 1:         // variable
771 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 775
             $this->writeString ($variableValue);
776 776
             $tPos = $vrtr['tPosEnd'];
777 777
             $varRefNo += 1;
778 778
             break;
779
-         case 2:         // sub block
779
+            case 2:         // sub block
780 780
             $subBtr =& $this->blockTab[$subBlockNo];
781 781
             if ($subBtr['parentBlockNo'] != $blockNo)
782
-               $this->programLogicError (3);
782
+                $this->programLogicError (3);
783 783
             $this->writeBlockInstances ($subBlockNo, $bitr['instanceLevel']);  // recursive call
784 784
             $tPos = $subBtr['tPosEnd'];
785 785
             $subBlockNo += 1;
@@ -789,19 +789,19 @@  discard block
 block discarded – undo
789 789
 * @access private
790 790
 */
791 791
 function writeString ($s) {
792
-   if ($this->outputError) return;
793
-   switch ($this->outputMode) {
794
-      case 0:            // output to PHP output stream
792
+    if ($this->outputError) return;
793
+    switch ($this->outputMode) {
794
+        case 0:            // output to PHP output stream
795 795
          if (!print($s))
796 796
             $this->outputError = true;
797
-         break;
798
-      case 1:            // output to file
797
+            break;
798
+        case 1:            // output to file
799 799
          $rc = fwrite($this->outputFileHandle, $s);
800
-         if ($rc === false) $this->outputError = true;
801
-         break;
802
-      case 2:            // output to string
800
+            if ($rc === false) $this->outputError = true;
801
+            break;
802
+        case 2:            // output to string
803 803
          $this->outputString .= $s;
804
-         break; }}
804
+            break; }}
805 805
 
806 806
 //--- name lookup routines ------------------------------------------------------------------------------------------
807 807
 
@@ -811,10 +811,10 @@  discard block
 block discarded – undo
811 811
 * @access private
812 812
 */
813 813
 function lookupVariableName ($varName, &$varNo) {
814
-   $x =& $this->varNameToNoMap[strtoupper($varName)];
815
-   if (!isset($x)) return false;
816
-   $varNo = $x;
817
-   return true; }
814
+    $x =& $this->varNameToNoMap[strtoupper($varName)];
815
+    if (!isset($x)) return false;
816
+    $varNo = $x;
817
+    return true; }
818 818
 
819 819
 /**
820 820
 * Maps block name to block number.
@@ -824,10 +824,10 @@  discard block
 block discarded – undo
824 824
 * @access private
825 825
 */
826 826
 function lookupBlockName ($blockName, &$blockNo) {
827
-   $x =& $this->blockNameToNoMap[strtoupper($blockName)];
828
-   if (!isset($x)) return false;
829
-   $blockNo = $x;
830
-   return true; }
827
+    $x =& $this->blockNameToNoMap[strtoupper($blockName)];
828
+    if (!isset($x)) return false;
829
+    $blockNo = $x;
830
+    return true; }
831 831
 
832 832
 //--- general utility routines -----------------------------------------------------------------------------------------
833 833
 
@@ -837,86 +837,86 @@  discard block
 block discarded – undo
837 837
 * @access private
838 838
 */
839 839
 function readFileIntoString ($fileName, &$s) {
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; }
844
-   $fh = fopen($fileName,"rb");
845
-   if ($fh === false) return false;
846
-   $fileSize = filesize($fileName);
847
-   if ($fileSize === false) {fclose ($fh); return false; }
848
-   $s = fread($fh,$fileSize);
849
-   fclose ($fh);
850
-   if (strlen($s) != $fileSize) return false;
851
-   return true; }
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; }
844
+    $fh = fopen($fileName,"rb");
845
+    if ($fh === false) return false;
846
+    $fileSize = filesize($fileName);
847
+    if ($fileSize === false) {fclose ($fh); return false; }
848
+    $s = fread($fh,$fileSize);
849
+    fclose ($fh);
850
+    if (strlen($s) != $fileSize) return false;
851
+    return true; }
852 852
 
853 853
 /**
854 854
 * @access private
855 855
 * @return boolean  true on success, false when the end of the string is reached.
856 856
 */
857 857
 function parseWord ($s, &$p, &$w) {
858
-   $sLen = strlen($s);
859
-   while ($p < $sLen && ord($s{$p}) <= 32) $p++;
860
-   if ($p >= $sLen) return false;
861
-   $p0 = $p;
862
-   while ($p < $sLen && ord($s{$p}) > 32) $p++;
863
-   $w = substr($s, $p0, $p - $p0);
864
-   return true; }
858
+    $sLen = strlen($s);
859
+    while ($p < $sLen && ord($s{$p}) <= 32) $p++;
860
+    if ($p >= $sLen) return false;
861
+    $p0 = $p;
862
+    while ($p < $sLen && ord($s{$p}) > 32) $p++;
863
+    $w = substr($s, $p0, $p - $p0);
864
+    return true; }
865 865
 
866 866
 /**
867 867
 * @access private
868 868
 * @return boolean  true on success, false on error.
869 869
 */
870 870
 function parseQuotedString ($s, &$p, &$w) {
871
-   $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;
875
-   $p++; $p0 = $p;
876
-   while ($p < $sLen && $s{$p} != '"') $p++;
877
-   if ($p >= $sLen) return false;
878
-   $w = substr($s, $p0, $p - $p0);
879
-   $p++;
880
-   return true; }
871
+    $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;
875
+    $p++; $p0 = $p;
876
+    while ($p < $sLen && $s{$p} != '"') $p++;
877
+    if ($p >= $sLen) return false;
878
+    $w = substr($s, $p0, $p - $p0);
879
+    $p++;
880
+    return true; }
881 881
 
882 882
 /**
883 883
 * @access private
884 884
 * @return boolean  true on success, false on error.
885 885
 */
886 886
 function parseWordOrQuotedString ($s, &$p, &$w) {
887
-   $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);
887
+    $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 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 899
 function combineFileSystemPath ($path1, $path2) {
900
-   if ($path1 == '' || $path2 == '') return $path2;
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);
900
+    if ($path1 == '' || $path2 == '') return $path2;
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);
905 905
     else
906
-      $s = $s . $path2;
907
-   return $s; }
906
+        $s = $s . $path2;
907
+    return $s; }
908 908
 
909 909
 /**
910 910
 * @access private
911 911
 */
912 912
 function triggerError ($msg) {
913
-   trigger_error ("MiniTemplator error: $msg", E_USER_ERROR); }
913
+    trigger_error ("MiniTemplator error: $msg", E_USER_ERROR); }
914 914
 
915 915
 /**
916 916
 * @access private
917 917
 */
918 918
 function programLogicError ($errorId) {
919
-   die ("MiniTemplator: Program logic error $errorId.\n"); }
919
+    die ("MiniTemplator: Program logic error $errorId.\n"); }
920 920
 
921 921
 }
922 922
 ?>
Please login to merge, or discard this patch.
Braces   +177 added lines, -82 removed lines patch added patch discarded remove patch
@@ -175,7 +175,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 /**
Please login to merge, or discard this patch.
lib/jimIcon.php 3 patches
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -67,13 +67,13 @@  discard block
 block discarded – undo
67 67
                         $entry = substr($ico, 6 + 16 * $i, 16);
68 68
                         if (!$entry || strlen($entry) < 16)
69 69
                                 continue;
70
-                        $e = unpack("Cwidth/" .
71
-                                    "Cheight/" .
72
-                                    "Ccolors/" .
73
-                                    "Czero/" .
74
-                                    "vplanes/" .
75
-                                    "vbpp/" .
76
-                                    "Vsize/" .
70
+                        $e = unpack("Cwidth/".
71
+                                    "Cheight/".
72
+                                    "Ccolors/".
73
+                                    "Czero/".
74
+                                    "vplanes/".
75
+                                    "vbpp/".
76
+                                    "Vsize/".
77 77
                                     "Voffset/",
78 78
                                     $entry);
79 79
                         if ($e["width"] == 0)
@@ -122,16 +122,16 @@  discard block
 block discarded – undo
122 122
                 // directory entry.
123 123
                 $bitmapinfo = unpack("Vsize", $data);
124 124
                 if ($bitmapinfo["size"] == 40) {
125
-                        $info = unpack("Vsize/" .
126
-                                       "Vwidth/" .
127
-                                       "Vheight/" .
128
-                                       "vplanes/" .
129
-                                       "vbpp/" .
130
-                                       "Vcompress/" .
131
-                                       "Vsize/" .
132
-                                       "Vxres/" .
133
-                                       "Vyres/" .
134
-                                       "Vpalcolors/" .
125
+                        $info = unpack("Vsize/".
126
+                                       "Vwidth/".
127
+                                       "Vheight/".
128
+                                       "vplanes/".
129
+                                       "vbpp/".
130
+                                       "Vcompress/".
131
+                                       "Vsize/".
132
+                                       "Vxres/".
133
+                                       "Vyres/".
134
+                                       "Vpalcolors/".
135 135
                                        "Vimpcolors/", $data);
136 136
                         if ($e["bpp"] == 0) {
137 137
                                 $e["bpp"] = $info["bpp"];
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
                                         $pixel1 = $palette[$p >> 4];
213 213
                                         $pixel2 = $palette[$p & 0x0f];
214 214
                                         $XOR[$y][$x] = $pixel1;
215
-                                        $XOR[$y][$x+1] = $pixel2;
215
+                                        $XOR[$y][$x + 1] = $pixel2;
216 216
                                         $x += 2;
217 217
                                         $offset++;
218 218
                                 } elseif ($bpp == 8) {
Please login to merge, or discard this patch.
Braces   +21 added lines, -14 removed lines patch added patch discarded remove patch
@@ -24,13 +24,15 @@  discard block
 block discarded – undo
24 24
                 $r = ord($str[2]);
25 25
                 if (strlen($str) > 3) {
26 26
                         $a = 127 - (ord($str[3]) / 2);
27
-                        if ($a != 0 && $a != 127)
28
-                                $this->had_alpha = 1;
27
+                        if ($a != 0 && $a != 127) {
28
+                                                        $this->had_alpha = 1;
29
+                        }
29 30
                 } else {
30 31
                         $a = 0;
31 32
                 }
32
-                if ($a != 127)
33
-                        $this->all_transaprent = 0;
33
+                if ($a != 127) {
34
+                                        $this->all_transaprent = 0;
35
+                }
34 36
                 return imagecolorallocatealpha($img, $r, $g, $b, $a);
35 37
         }
36 38
 
@@ -65,8 +67,9 @@  discard block
 block discarded – undo
65 67
                 $most_pixels = 0;
66 68
                 for ($i = 0; $i < $h["num"]; $i++) {
67 69
                         $entry = substr($ico, 6 + 16 * $i, 16);
68
-                        if (!$entry || strlen($entry) < 16)
69
-                                continue;
70
+                        if (!$entry || strlen($entry) < 16) {
71
+                                                        continue;
72
+                        }
70 73
                         $e = unpack("Cwidth/" .
71 74
                                     "Cheight/" .
72 75
                                     "Ccolors/" .
@@ -76,10 +79,12 @@  discard block
 block discarded – undo
76 79
                                     "Vsize/" .
77 80
                                     "Voffset/",
78 81
                                     $entry);
79
-                        if ($e["width"] == 0)
80
-                                $e["width"] = 256;
81
-                        if ($e["height"] == 0)
82
-                                $e["height"] = 256;
82
+                        if ($e["width"] == 0) {
83
+                                                        $e["width"] = 256;
84
+                        }
85
+                        if ($e["height"] == 0) {
86
+                                                        $e["height"] = 256;
87
+                        }
83 88
                         if ($e["zero"] != 0) {
84 89
                                 $this->error = "nonzero reserved field";
85 90
                                 return false;
@@ -226,8 +231,9 @@  discard block
 block discarded – undo
226 231
                                 }
227 232
                         }
228 233
                         // End of row padding
229
-                        while ($offset & 3)
230
-                                $offset++;
234
+                        while ($offset & 3) {
235
+                                                        $offset++;
236
+                        }
231 237
                 }
232 238
 
233 239
                 // Now the "AND" image, which is 1 bit per pixel.  Ignore
@@ -261,8 +267,9 @@  discard block
 block discarded – undo
261 267
                         }
262 268
 
263 269
                         // End of row padding
264
-                        while ($offset & 3)
265
-                                $offset++;
270
+                        while ($offset & 3) {
271
+                                                        $offset++;
272
+                        }
266 273
                 }
267 274
                 return $img;
268 275
         }
Please login to merge, or discard this patch.
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -123,16 +123,16 @@  discard block
 block discarded – undo
123 123
                 $bitmapinfo = unpack("Vsize", $data);
124 124
                 if ($bitmapinfo["size"] == 40) {
125 125
                         $info = unpack("Vsize/" .
126
-                                       "Vwidth/" .
127
-                                       "Vheight/" .
128
-                                       "vplanes/" .
129
-                                       "vbpp/" .
130
-                                       "Vcompress/" .
131
-                                       "Vsize/" .
132
-                                       "Vxres/" .
133
-                                       "Vyres/" .
134
-                                       "Vpalcolors/" .
135
-                                       "Vimpcolors/", $data);
126
+                                        "Vwidth/" .
127
+                                        "Vheight/" .
128
+                                        "vplanes/" .
129
+                                        "vbpp/" .
130
+                                        "Vcompress/" .
131
+                                        "Vsize/" .
132
+                                        "Vxres/" .
133
+                                        "Vyres/" .
134
+                                        "Vpalcolors/" .
135
+                                        "Vimpcolors/", $data);
136 136
                         if ($e["bpp"] == 0) {
137 137
                                 $e["bpp"] = $info["bpp"];
138 138
                         }
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
                         for ($y = 0; $y < $height; $y++) {
240 240
                                 for ($x = 0; $x < $width; $x++) {
241 241
                                         imagesetpixel($img, $x, $y,
242
-                                                      $XOR[$y][$x]);
242
+                                                        $XOR[$y][$x]);
243 243
                                 }
244 244
                         }
245 245
                         return $img;
@@ -250,10 +250,10 @@  discard block
 block discarded – undo
250 250
                         $x = 0;
251 251
                         while ($x < $width) {
252 252
                                 for ($b = 0x80;
253
-                                     $b > 0 && $x < $width; $b >>= 1) {
253
+                                        $b > 0 && $x < $width; $b >>= 1) {
254 254
                                         if (!(ord($data[$offset]) & $b)) {
255 255
                                                 imagesetpixel($img, $x, $y,
256
-                                                              $XOR[$y][$x]);
256
+                                                                $XOR[$y][$x]);
257 257
                                         }
258 258
                                         $x++;
259 259
                                 }
Please login to merge, or discard this patch.
lib/phpqrcode/qrconst.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -45,10 +45,10 @@
 block discarded – undo
45 45
 	// Supported output formats
46 46
 	
47 47
 	define('QR_FORMAT_TEXT', 0);
48
-	define('QR_FORMAT_PNG',  1);
48
+	define('QR_FORMAT_PNG', 1);
49 49
 	
50 50
 	class qrstr {
51 51
 		public static function set(&$srctab, $x, $y, $repl, $replLen = false) {
52
-			$srctab[$y] = substr_replace($srctab[$y], ($replLen !== false)?substr($repl,0,$replLen):$repl, $x, ($replLen !== false)?$replLen:strlen($repl));
52
+			$srctab[$y] = substr_replace($srctab[$y], ($replLen !== false) ?substr($repl, 0, $replLen) : $repl, $x, ($replLen !== false) ? $replLen : strlen($repl));
53 53
 		}
54 54
 	}	
55 55
\ No newline at end of file
Please login to merge, or discard this patch.
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -26,29 +26,29 @@
 block discarded – undo
26 26
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 27
  */
28 28
  
29
-	// Encoding modes
29
+    // Encoding modes
30 30
 	 
31
-	define('QR_MODE_NUL', -1);
32
-	define('QR_MODE_NUM', 0);
33
-	define('QR_MODE_AN', 1);
34
-	define('QR_MODE_8', 2);
35
-	define('QR_MODE_KANJI', 3);
36
-	define('QR_MODE_STRUCTURE', 4);
31
+    define('QR_MODE_NUL', -1);
32
+    define('QR_MODE_NUM', 0);
33
+    define('QR_MODE_AN', 1);
34
+    define('QR_MODE_8', 2);
35
+    define('QR_MODE_KANJI', 3);
36
+    define('QR_MODE_STRUCTURE', 4);
37 37
 
38
-	// Levels of error correction.
38
+    // Levels of error correction.
39 39
 
40
-	define('QR_ECLEVEL_L', 0);
41
-	define('QR_ECLEVEL_M', 1);
42
-	define('QR_ECLEVEL_Q', 2);
43
-	define('QR_ECLEVEL_H', 3);
40
+    define('QR_ECLEVEL_L', 0);
41
+    define('QR_ECLEVEL_M', 1);
42
+    define('QR_ECLEVEL_Q', 2);
43
+    define('QR_ECLEVEL_H', 3);
44 44
 	
45
-	// Supported output formats
45
+    // Supported output formats
46 46
 	
47
-	define('QR_FORMAT_TEXT', 0);
48
-	define('QR_FORMAT_PNG',  1);
47
+    define('QR_FORMAT_TEXT', 0);
48
+    define('QR_FORMAT_PNG',  1);
49 49
 	
50
-	class qrstr {
51
-		public static function set(&$srctab, $x, $y, $repl, $replLen = false) {
52
-			$srctab[$y] = substr_replace($srctab[$y], ($replLen !== false)?substr($repl,0,$replLen):$repl, $x, ($replLen !== false)?$replLen:strlen($repl));
53
-		}
54
-	}	
55 50
\ No newline at end of file
51
+    class qrstr {
52
+        public static function set(&$srctab, $x, $y, $repl, $replLen = false) {
53
+            $srctab[$y] = substr_replace($srctab[$y], ($replLen !== false)?substr($repl,0,$replLen):$repl, $x, ($replLen !== false)?$replLen:strlen($repl));
54
+        }
55
+    }	
56 56
\ No newline at end of file
Please login to merge, or discard this patch.