Passed
Push — master ( 678db7...164b32 )
by Cody
06:12 queued 03:06
created
classes/counters.php 1 patch
Indentation   +128 added lines, -128 removed lines patch added patch discarded remove patch
@@ -1,174 +1,174 @@  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;
102
-			}
98
+            if ($i == 0 || $i == -1 || $i == -2) {
99
+                            $auxctr = Feeds::getFeedArticles($i, false);
100
+            } else {
101
+                            $auxctr = 0;
102
+            }
103 103
 
104
-			$cv = array("id" => $i,
105
-				"counter" => (int) $count,
106
-				"auxcounter" => (int) $auxctr);
104
+            $cv = array("id" => $i,
105
+                "counter" => (int) $count,
106
+                "auxcounter" => (int) $auxctr);
107 107
 
108 108
 //			if (get_pref('EXTENDED_FEEDLIST'))
109 109
 //				$cv["xmsg"] = getFeedArticles($i)." ".__("total");
110 110
 
111
-			array_push($ret_arr, $cv);
112
-		}
111
+            array_push($ret_arr, $cv);
112
+        }
113 113
 
114
-		$feeds = PluginHost::getInstance()->get_feeds(-1);
114
+        $feeds = PluginHost::getInstance()->get_feeds(-1);
115 115
 
116
-		if (is_array($feeds)) {
117
-			foreach ($feeds as $feed) {
118
-				$cv = array("id" => PluginHost::pfeed_to_feed_id($feed['id']),
119
-					"counter" => $feed['sender']->get_unread($feed['id']));
116
+        if (is_array($feeds)) {
117
+            foreach ($feeds as $feed) {
118
+                $cv = array("id" => PluginHost::pfeed_to_feed_id($feed['id']),
119
+                    "counter" => $feed['sender']->get_unread($feed['id']));
120 120
 
121
-				if (method_exists($feed['sender'], 'get_total')) {
122
-									$cv["auxcounter"] = $feed['sender']->get_total($feed['id']);
123
-				}
121
+                if (method_exists($feed['sender'], 'get_total')) {
122
+                                    $cv["auxcounter"] = $feed['sender']->get_total($feed['id']);
123
+                }
124 124
 
125
-				array_push($ret_arr, $cv);
126
-			}
127
-		}
125
+                array_push($ret_arr, $cv);
126
+            }
127
+        }
128 128
 
129
-		return $ret_arr;
130
-	}
129
+        return $ret_arr;
130
+    }
131 131
 
132
-	public static function getLabelCounters($descriptions = false) {
132
+    public static function getLabelCounters($descriptions = false) {
133 133
 
134
-		$ret_arr = array();
134
+        $ret_arr = array();
135 135
 
136
-		$pdo = Db::pdo();
136
+        $pdo = Db::pdo();
137 137
 
138
-		$sth = $pdo->prepare("SELECT id,caption,SUM(CASE WHEN u1.unread = true THEN 1 ELSE 0 END) AS unread, COUNT(u1.unread) AS total
138
+        $sth = $pdo->prepare("SELECT id,caption,SUM(CASE WHEN u1.unread = true THEN 1 ELSE 0 END) AS unread, COUNT(u1.unread) AS total
139 139
 			FROM ttrss_labels2 LEFT JOIN ttrss_user_labels2 ON
140 140
 				(ttrss_labels2.id = label_id)
141 141
 				LEFT JOIN ttrss_user_entries AS u1 ON u1.ref_id = article_id
142 142
 				WHERE ttrss_labels2.owner_uid = :uid AND u1.owner_uid = :uid
143 143
 				GROUP BY ttrss_labels2.id,
144 144
 					ttrss_labels2.caption");
145
-		$sth->execute([":uid" => $_SESSION['uid']]);
145
+        $sth->execute([":uid" => $_SESSION['uid']]);
146 146
 
147
-		while ($line = $sth->fetch()) {
147
+        while ($line = $sth->fetch()) {
148 148
 
149
-			$id = Labels::label_to_feed_id($line["id"]);
149
+            $id = Labels::label_to_feed_id($line["id"]);
150 150
 
151
-			$cv = array("id" => $id,
152
-				"counter" => (int) $line["unread"],
153
-				"auxcounter" => (int) $line["total"]);
151
+            $cv = array("id" => $id,
152
+                "counter" => (int) $line["unread"],
153
+                "auxcounter" => (int) $line["total"]);
154 154
 
155
-			if ($descriptions) {
156
-							$cv["description"] = $line["caption"];
157
-			}
155
+            if ($descriptions) {
156
+                            $cv["description"] = $line["caption"];
157
+            }
158 158
 
159
-			array_push($ret_arr, $cv);
160
-		}
159
+            array_push($ret_arr, $cv);
160
+        }
161 161
 
162
-		return $ret_arr;
163
-	}
162
+        return $ret_arr;
163
+    }
164 164
 
165
-	public static function getFeedCounters($active_feed = false) {
165
+    public static function getFeedCounters($active_feed = false) {
166 166
 
167
-		$ret_arr = array();
167
+        $ret_arr = array();
168 168
 
169
-		$pdo = Db::pdo();
169
+        $pdo = Db::pdo();
170 170
 
171
-		$sth = $pdo->prepare("SELECT ttrss_feeds.id,
171
+        $sth = $pdo->prepare("SELECT ttrss_feeds.id,
172 172
 				ttrss_feeds.title,
173 173
 				".SUBSTRING_FOR_DATE."(ttrss_feeds.last_updated,1,19) AS last_updated,
174 174
 				last_error, value AS count
@@ -176,47 +176,47 @@  discard block
 block discarded – undo
176 176
 			WHERE ttrss_feeds.owner_uid = ?
177 177
 				AND ttrss_counters_cache.owner_uid = ttrss_feeds.owner_uid
178 178
 				AND ttrss_counters_cache.feed_id = ttrss_feeds.id");
179
-		$sth->execute([$_SESSION['uid']]);
179
+        $sth->execute([$_SESSION['uid']]);
180 180
 
181
-		while ($line = $sth->fetch()) {
181
+        while ($line = $sth->fetch()) {
182 182
 
183
-			$id = $line["id"];
184
-			$count = $line["count"];
185
-			$last_error = htmlspecialchars($line["last_error"]);
183
+            $id = $line["id"];
184
+            $count = $line["count"];
185
+            $last_error = htmlspecialchars($line["last_error"]);
186 186
 
187
-			$last_updated = make_local_datetime($line['last_updated'], false);
187
+            $last_updated = make_local_datetime($line['last_updated'], false);
188 188
 
189
-			if (Feeds::feedHasIcon($id)) {
190
-				$has_img = filemtime(Feeds::getIconFile($id));
191
-			} else {
192
-				$has_img = false;
193
-			}
189
+            if (Feeds::feedHasIcon($id)) {
190
+                $has_img = filemtime(Feeds::getIconFile($id));
191
+            } else {
192
+                $has_img = false;
193
+            }
194 194
 
195
-			if (date('Y') - date('Y', strtotime($line['last_updated'])) > 2) {
196
-							$last_updated = '';
197
-			}
195
+            if (date('Y') - date('Y', strtotime($line['last_updated'])) > 2) {
196
+                            $last_updated = '';
197
+            }
198 198
 
199
-			$cv = array("id" => $id,
200
-				"updated" => $last_updated,
201
-				"counter" => (int) $count,
202
-				"has_img" => (int) $has_img);
199
+            $cv = array("id" => $id,
200
+                "updated" => $last_updated,
201
+                "counter" => (int) $count,
202
+                "has_img" => (int) $has_img);
203 203
 
204
-			if ($last_error) {
205
-							$cv["error"] = $last_error;
206
-			}
204
+            if ($last_error) {
205
+                            $cv["error"] = $last_error;
206
+            }
207 207
 
208 208
 //			if (get_pref('EXTENDED_FEEDLIST'))
209 209
 //				$cv["xmsg"] = getFeedArticles($id)." ".__("total");
210 210
 
211
-			if ($active_feed && $id == $active_feed) {
212
-							$cv["title"] = truncate_string($line["title"], 30);
213
-			}
211
+            if ($active_feed && $id == $active_feed) {
212
+                            $cv["title"] = truncate_string($line["title"], 30);
213
+            }
214 214
 
215
-			array_push($ret_arr, $cv);
215
+            array_push($ret_arr, $cv);
216 216
 
217
-		}
217
+        }
218 218
 
219
-		return $ret_arr;
220
-	}
219
+        return $ret_arr;
220
+    }
221 221
 
222 222
 }
Please login to merge, or discard this patch.
classes/rssutils.php 3 patches
Indentation   +1292 added lines, -1292 removed lines patch added patch discarded remove patch
@@ -1,50 +1,50 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 class RSSUtils {
3
-	public static function calculate_article_hash($article, $pluginhost) {
4
-		$tmp = "";
5
-
6
-		foreach ($article as $k => $v) {
7
-			if ($k != "feed" && isset($v)) {
8
-				$x = strip_tags(is_array($v) ? implode(",", $v) : $v);
9
-
10
-				$tmp .= sha1("$k:".sha1($x));
11
-			}
12
-		}
13
-
14
-		return sha1(implode(",", $pluginhost->get_plugin_names()).$tmp);
15
-	}
16
-
17
-	// Strips utf8mb4 characters (i.e. emoji) for mysql
18
-	public static function strip_utf8mb4($str) {
19
-		return preg_replace('/[\x{10000}-\x{10FFFF}]/u', "\xEF\xBF\xBD", $str);
20
-	}
21
-
22
-	public static function cleanup_feed_browser() {
23
-		$pdo = Db::pdo();
24
-		$pdo->query("DELETE FROM ttrss_feedbrowser_cache");
25
-	}
26
-
27
-	public static function update_daemon_common($limit = DAEMON_FEED_LIMIT) {
28
-		$schema_version = get_schema_version();
29
-
30
-		if ($schema_version != SCHEMA_VERSION) {
31
-			die("Schema version is wrong, please upgrade the database.\n");
32
-		}
33
-
34
-		$pdo = Db::pdo();
35
-
36
-		if (!SINGLE_USER_MODE && DAEMON_UPDATE_LOGIN_LIMIT > 0) {
37
-			if (DB_TYPE == "pgsql") {
38
-				$login_thresh_qpart = "AND ttrss_users.last_login >= NOW() - INTERVAL '".DAEMON_UPDATE_LOGIN_LIMIT." days'";
39
-			} else {
40
-				$login_thresh_qpart = "AND ttrss_users.last_login >= DATE_SUB(NOW(), INTERVAL ".DAEMON_UPDATE_LOGIN_LIMIT." DAY)";
41
-			}
42
-		} else {
43
-			$login_thresh_qpart = "";
44
-		}
45
-
46
-		if (DB_TYPE == "pgsql") {
47
-			$update_limit_qpart = "AND ((
3
+    public static function calculate_article_hash($article, $pluginhost) {
4
+        $tmp = "";
5
+
6
+        foreach ($article as $k => $v) {
7
+            if ($k != "feed" && isset($v)) {
8
+                $x = strip_tags(is_array($v) ? implode(",", $v) : $v);
9
+
10
+                $tmp .= sha1("$k:".sha1($x));
11
+            }
12
+        }
13
+
14
+        return sha1(implode(",", $pluginhost->get_plugin_names()).$tmp);
15
+    }
16
+
17
+    // Strips utf8mb4 characters (i.e. emoji) for mysql
18
+    public static function strip_utf8mb4($str) {
19
+        return preg_replace('/[\x{10000}-\x{10FFFF}]/u', "\xEF\xBF\xBD", $str);
20
+    }
21
+
22
+    public static function cleanup_feed_browser() {
23
+        $pdo = Db::pdo();
24
+        $pdo->query("DELETE FROM ttrss_feedbrowser_cache");
25
+    }
26
+
27
+    public static function update_daemon_common($limit = DAEMON_FEED_LIMIT) {
28
+        $schema_version = get_schema_version();
29
+
30
+        if ($schema_version != SCHEMA_VERSION) {
31
+            die("Schema version is wrong, please upgrade the database.\n");
32
+        }
33
+
34
+        $pdo = Db::pdo();
35
+
36
+        if (!SINGLE_USER_MODE && DAEMON_UPDATE_LOGIN_LIMIT > 0) {
37
+            if (DB_TYPE == "pgsql") {
38
+                $login_thresh_qpart = "AND ttrss_users.last_login >= NOW() - INTERVAL '".DAEMON_UPDATE_LOGIN_LIMIT." days'";
39
+            } else {
40
+                $login_thresh_qpart = "AND ttrss_users.last_login >= DATE_SUB(NOW(), INTERVAL ".DAEMON_UPDATE_LOGIN_LIMIT." DAY)";
41
+            }
42
+        } else {
43
+            $login_thresh_qpart = "";
44
+        }
45
+
46
+        if (DB_TYPE == "pgsql") {
47
+            $update_limit_qpart = "AND ((
48 48
 					ttrss_feeds.update_interval = 0
49 49
 					AND ttrss_user_prefs.value != '-1'
50 50
 					AND ttrss_feeds.last_updated < NOW() - CAST((ttrss_user_prefs.value || ' minutes') AS INTERVAL)
@@ -55,8 +55,8 @@  discard block
 block discarded – undo
55 55
 					AND ttrss_user_prefs.value != '-1')
56 56
 				OR (last_updated = '1970-01-01 00:00:00'
57 57
 					AND ttrss_user_prefs.value != '-1'))";
58
-		} else {
59
-			$update_limit_qpart = "AND ((
58
+        } else {
59
+            $update_limit_qpart = "AND ((
60 60
 					ttrss_feeds.update_interval = 0
61 61
 					AND ttrss_user_prefs.value != '-1'
62 62
 					AND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL CONVERT(ttrss_user_prefs.value, SIGNED INTEGER) MINUTE)
@@ -67,24 +67,24 @@  discard block
 block discarded – undo
67 67
 					AND ttrss_user_prefs.value != '-1')
68 68
 				OR (last_updated = '1970-01-01 00:00:00'
69 69
 					AND ttrss_user_prefs.value != '-1'))";
70
-		}
70
+        }
71 71
 
72
-		// Test if feed is currently being updated by another process.
73
-		if (DB_TYPE == "pgsql") {
74
-			$updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < NOW() - INTERVAL '10 minutes')";
75
-		} else {
76
-			$updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < DATE_SUB(NOW(), INTERVAL 10 MINUTE))";
77
-		}
72
+        // Test if feed is currently being updated by another process.
73
+        if (DB_TYPE == "pgsql") {
74
+            $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < NOW() - INTERVAL '10 minutes')";
75
+        } else {
76
+            $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < DATE_SUB(NOW(), INTERVAL 10 MINUTE))";
77
+        }
78 78
 
79
-		$query_limit = $limit ? sprintf("LIMIT %d", $limit) : "";
79
+        $query_limit = $limit ? sprintf("LIMIT %d", $limit) : "";
80 80
 
81
-		// Update the least recently updated feeds first
82
-		$query_order = "ORDER BY last_updated";
83
-		if (DB_TYPE == "pgsql") {
84
-		    $query_order .= " NULLS FIRST";
85
-		}
81
+        // Update the least recently updated feeds first
82
+        $query_order = "ORDER BY last_updated";
83
+        if (DB_TYPE == "pgsql") {
84
+            $query_order .= " NULLS FIRST";
85
+        }
86 86
 
87
-		$query = "SELECT DISTINCT ttrss_feeds.feed_url, ttrss_feeds.last_updated
87
+        $query = "SELECT DISTINCT ttrss_feeds.feed_url, ttrss_feeds.last_updated
88 88
 			FROM
89 89
 				ttrss_feeds, ttrss_users, ttrss_user_prefs
90 90
 			WHERE
@@ -96,32 +96,32 @@  discard block
 block discarded – undo
96 96
 				$updstart_thresh_qpart
97 97
 				$query_order $query_limit";
98 98
 
99
-		$res = $pdo->query($query);
99
+        $res = $pdo->query($query);
100 100
 
101
-		$feeds_to_update = array();
102
-		while ($line = $res->fetch()) {
103
-			array_push($feeds_to_update, $line['feed_url']);
104
-		}
101
+        $feeds_to_update = array();
102
+        while ($line = $res->fetch()) {
103
+            array_push($feeds_to_update, $line['feed_url']);
104
+        }
105 105
 
106
-		Debug::log(sprintf("Scheduled %d feeds to update...", count($feeds_to_update)));
106
+        Debug::log(sprintf("Scheduled %d feeds to update...", count($feeds_to_update)));
107 107
 
108
-		// Update last_update_started before actually starting the batch
109
-		// in order to minimize collision risk for parallel daemon tasks
110
-		if (count($feeds_to_update) > 0) {
111
-			$feeds_qmarks = arr_qmarks($feeds_to_update);
108
+        // Update last_update_started before actually starting the batch
109
+        // in order to minimize collision risk for parallel daemon tasks
110
+        if (count($feeds_to_update) > 0) {
111
+            $feeds_qmarks = arr_qmarks($feeds_to_update);
112 112
 
113
-			$tmph = $pdo->prepare("UPDATE ttrss_feeds SET last_update_started = NOW()
113
+            $tmph = $pdo->prepare("UPDATE ttrss_feeds SET last_update_started = NOW()
114 114
 				WHERE feed_url IN ($feeds_qmarks)");
115
-			$tmph->execute($feeds_to_update);
116
-		}
115
+            $tmph->execute($feeds_to_update);
116
+        }
117 117
 
118
-		$nf = 0;
119
-		$bstarted = microtime(true);
118
+        $nf = 0;
119
+        $bstarted = microtime(true);
120 120
 
121
-		$batch_owners = array();
121
+        $batch_owners = array();
122 122
 
123
-		// since we have the data cached, we can deal with other feeds with the same url
124
-		$usth = $pdo->prepare("SELECT DISTINCT ttrss_feeds.id,last_updated,ttrss_feeds.owner_uid
123
+        // since we have the data cached, we can deal with other feeds with the same url
124
+        $usth = $pdo->prepare("SELECT DISTINCT ttrss_feeds.id,last_updated,ttrss_feeds.owner_uid
125 125
 			FROM ttrss_feeds, ttrss_users, ttrss_user_prefs WHERE
126 126
 				ttrss_user_prefs.owner_uid = ttrss_feeds.owner_uid AND
127 127
 				ttrss_users.id = ttrss_user_prefs.owner_uid AND
@@ -132,724 +132,724 @@  discard block
 block discarded – undo
132 132
 				$login_thresh_qpart
133 133
 			ORDER BY ttrss_feeds.id $query_limit");
134 134
 
135
-		foreach ($feeds_to_update as $feed) {
136
-			Debug::log("Base feed: $feed");
135
+        foreach ($feeds_to_update as $feed) {
136
+            Debug::log("Base feed: $feed");
137 137
 
138
-			$usth->execute([$feed]);
139
-			//update_rss_feed($line["id"], true);
138
+            $usth->execute([$feed]);
139
+            //update_rss_feed($line["id"], true);
140 140
 
141
-			if ($tline = $usth->fetch()) {
142
-				Debug::log(" => ".$tline["last_updated"].", ".$tline["id"]." ".$tline["owner_uid"]);
141
+            if ($tline = $usth->fetch()) {
142
+                Debug::log(" => ".$tline["last_updated"].", ".$tline["id"]." ".$tline["owner_uid"]);
143 143
 
144
-				if (array_search($tline["owner_uid"], $batch_owners) === false) {
145
-									array_push($batch_owners, $tline["owner_uid"]);
146
-				}
144
+                if (array_search($tline["owner_uid"], $batch_owners) === false) {
145
+                                    array_push($batch_owners, $tline["owner_uid"]);
146
+                }
147 147
 
148
-				$fstarted = microtime(true);
148
+                $fstarted = microtime(true);
149 149
 
150
-				try {
151
-					RSSUtils::update_rss_feed($tline["id"], true, false);
152
-				} catch (PDOException $e) {
153
-					Logger::get()->log_error(E_USER_NOTICE, $e->getMessage(), $e->getFile(), $e->getLine(), $e->getTraceAsString());
150
+                try {
151
+                    RSSUtils::update_rss_feed($tline["id"], true, false);
152
+                } catch (PDOException $e) {
153
+                    Logger::get()->log_error(E_USER_NOTICE, $e->getMessage(), $e->getFile(), $e->getLine(), $e->getTraceAsString());
154 154
 
155
-					try {
156
-						$pdo->rollback();
157
-					} catch (PDOException $e) {
158
-						// it doesn't matter if there wasn't actually anything to rollback, PDO Exception can be
159
-						// thrown outside of an active transaction during feed update
160
-					}
161
-				}
155
+                    try {
156
+                        $pdo->rollback();
157
+                    } catch (PDOException $e) {
158
+                        // it doesn't matter if there wasn't actually anything to rollback, PDO Exception can be
159
+                        // thrown outside of an active transaction during feed update
160
+                    }
161
+                }
162 162
 
163
-				Debug::log(sprintf("    %.4f (sec)", microtime(true) - $fstarted));
163
+                Debug::log(sprintf("    %.4f (sec)", microtime(true) - $fstarted));
164 164
 
165
-				++$nf;
166
-			}
167
-		}
165
+                ++$nf;
166
+            }
167
+        }
168 168
 
169
-		if ($nf > 0) {
170
-			Debug::log(sprintf("Processed %d feeds in %.4f (sec), %.4f (sec/feed avg)", $nf,
171
-				microtime(true) - $bstarted, (microtime(true) - $bstarted) / $nf));
172
-		}
169
+        if ($nf > 0) {
170
+            Debug::log(sprintf("Processed %d feeds in %.4f (sec), %.4f (sec/feed avg)", $nf,
171
+                microtime(true) - $bstarted, (microtime(true) - $bstarted) / $nf));
172
+        }
173 173
 
174
-		foreach ($batch_owners as $owner_uid) {
175
-			Debug::log("Running housekeeping tasks for user $owner_uid...");
174
+        foreach ($batch_owners as $owner_uid) {
175
+            Debug::log("Running housekeeping tasks for user $owner_uid...");
176 176
 
177
-			RSSUtils::housekeeping_user($owner_uid);
178
-		}
177
+            RSSUtils::housekeeping_user($owner_uid);
178
+        }
179 179
 
180
-		// Send feed digests by email if needed.
181
-		Digest::send_headlines_digests();
180
+        // Send feed digests by email if needed.
181
+        Digest::send_headlines_digests();
182 182
 
183
-		return $nf;
184
-	}
183
+        return $nf;
184
+    }
185 185
 
186
-	// this is used when subscribing
187
-	public static function set_basic_feed_info($feed) {
186
+    // this is used when subscribing
187
+    public static function set_basic_feed_info($feed) {
188 188
 
189
-		$pdo = Db::pdo();
189
+        $pdo = Db::pdo();
190 190
 
191
-		$sth = $pdo->prepare("SELECT owner_uid,feed_url,auth_pass,auth_login
191
+        $sth = $pdo->prepare("SELECT owner_uid,feed_url,auth_pass,auth_login
192 192
 				FROM ttrss_feeds WHERE id = ?");
193
-		$sth->execute([$feed]);
193
+        $sth->execute([$feed]);
194 194
 
195
-		if ($row = $sth->fetch()) {
195
+        if ($row = $sth->fetch()) {
196 196
 
197
-			$owner_uid = $row["owner_uid"];
198
-			$auth_login = $row["auth_login"];
199
-			$auth_pass = $row["auth_pass"];
200
-			$fetch_url = $row["feed_url"];
197
+            $owner_uid = $row["owner_uid"];
198
+            $auth_login = $row["auth_login"];
199
+            $auth_pass = $row["auth_pass"];
200
+            $fetch_url = $row["feed_url"];
201 201
 
202
-			$pluginhost = new PluginHost();
203
-			$user_plugins = get_pref("_ENABLED_PLUGINS", $owner_uid);
202
+            $pluginhost = new PluginHost();
203
+            $user_plugins = get_pref("_ENABLED_PLUGINS", $owner_uid);
204 204
 
205
-			$pluginhost->load(PLUGINS, PluginHost::KIND_ALL);
206
-			$pluginhost->load($user_plugins, PluginHost::KIND_USER, $owner_uid);
207
-			$pluginhost->load_data();
205
+            $pluginhost->load(PLUGINS, PluginHost::KIND_ALL);
206
+            $pluginhost->load($user_plugins, PluginHost::KIND_USER, $owner_uid);
207
+            $pluginhost->load_data();
208 208
 
209
-			$basic_info = array();
210
-			foreach ($pluginhost->get_hooks(PluginHost::HOOK_FEED_BASIC_INFO) as $plugin) {
211
-				$basic_info = $plugin->hook_feed_basic_info($basic_info, $fetch_url, $owner_uid, $feed, $auth_login, $auth_pass);
212
-			}
209
+            $basic_info = array();
210
+            foreach ($pluginhost->get_hooks(PluginHost::HOOK_FEED_BASIC_INFO) as $plugin) {
211
+                $basic_info = $plugin->hook_feed_basic_info($basic_info, $fetch_url, $owner_uid, $feed, $auth_login, $auth_pass);
212
+            }
213 213
 
214
-			if (!$basic_info) {
215
-				$feed_data = fetch_file_contents($fetch_url, false,
216
-					$auth_login, $auth_pass, false,
217
-					FEED_FETCH_TIMEOUT,
218
-					0);
214
+            if (!$basic_info) {
215
+                $feed_data = fetch_file_contents($fetch_url, false,
216
+                    $auth_login, $auth_pass, false,
217
+                    FEED_FETCH_TIMEOUT,
218
+                    0);
219 219
 
220
-				$feed_data = trim($feed_data);
220
+                $feed_data = trim($feed_data);
221 221
 
222
-				$rss = new FeedParser($feed_data);
223
-				$rss->init();
222
+                $rss = new FeedParser($feed_data);
223
+                $rss->init();
224 224
 
225
-				if (!$rss->error()) {
226
-					$basic_info = array(
227
-						'title' => mb_substr(clean($rss->get_title()), 0, 199),
228
-						'site_url' => mb_substr(rewrite_relative_url($fetch_url, clean($rss->get_link())), 0, 245)
229
-					);
230
-				}
231
-			}
225
+                if (!$rss->error()) {
226
+                    $basic_info = array(
227
+                        'title' => mb_substr(clean($rss->get_title()), 0, 199),
228
+                        'site_url' => mb_substr(rewrite_relative_url($fetch_url, clean($rss->get_link())), 0, 245)
229
+                    );
230
+                }
231
+            }
232 232
 
233
-			if ($basic_info && is_array($basic_info)) {
234
-				$sth = $pdo->prepare("SELECT title, site_url FROM ttrss_feeds WHERE id = ?");
235
-				$sth->execute([$feed]);
233
+            if ($basic_info && is_array($basic_info)) {
234
+                $sth = $pdo->prepare("SELECT title, site_url FROM ttrss_feeds WHERE id = ?");
235
+                $sth->execute([$feed]);
236 236
 
237
-				if ($row = $sth->fetch()) {
237
+                if ($row = $sth->fetch()) {
238 238
 
239
-					$registered_title = $row["title"];
240
-					$orig_site_url = $row["site_url"];
239
+                    $registered_title = $row["title"];
240
+                    $orig_site_url = $row["site_url"];
241 241
 
242
-					if ($basic_info['title'] && (!$registered_title || $registered_title == "[Unknown]")) {
242
+                    if ($basic_info['title'] && (!$registered_title || $registered_title == "[Unknown]")) {
243 243
 
244
-						$sth = $pdo->prepare("UPDATE ttrss_feeds SET
244
+                        $sth = $pdo->prepare("UPDATE ttrss_feeds SET
245 245
 							title = ? WHERE id = ?");
246
-						$sth->execute([$basic_info['title'], $feed]);
247
-					}
246
+                        $sth->execute([$basic_info['title'], $feed]);
247
+                    }
248 248
 
249
-					if ($basic_info['site_url'] && $orig_site_url != $basic_info['site_url']) {
250
-						$sth = $pdo->prepare("UPDATE ttrss_feeds SET
249
+                    if ($basic_info['site_url'] && $orig_site_url != $basic_info['site_url']) {
250
+                        $sth = $pdo->prepare("UPDATE ttrss_feeds SET
251 251
 							site_url = ? WHERE id = ?");
252
-						$sth->execute([$basic_info['site_url'], $feed]);
253
-					}
252
+                        $sth->execute([$basic_info['site_url'], $feed]);
253
+                    }
254 254
 
255
-				}
256
-			}
257
-		}
258
-	}
255
+                }
256
+            }
257
+        }
258
+    }
259 259
 
260
-	/**
261
-	 * @SuppressWarnings(PHPMD.UnusedFormalParameter)
262
-	 */
263
-	public static function update_rss_feed($feed, $no_cache = false) {
260
+    /**
261
+     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
262
+     */
263
+    public static function update_rss_feed($feed, $no_cache = false) {
264 264
 
265
-		reset_fetch_domain_quota();
265
+        reset_fetch_domain_quota();
266 266
 
267
-		Debug::log("start", Debug::$LOG_VERBOSE);
267
+        Debug::log("start", Debug::$LOG_VERBOSE);
268 268
 
269
-		$pdo = Db::pdo();
269
+        $pdo = Db::pdo();
270 270
 
271
-		$sth = $pdo->prepare("SELECT title, site_url FROM ttrss_feeds WHERE id = ?");
272
-		$sth->execute([$feed]);
271
+        $sth = $pdo->prepare("SELECT title, site_url FROM ttrss_feeds WHERE id = ?");
272
+        $sth->execute([$feed]);
273 273
 
274
-		if (!$row = $sth->fetch()) {
275
-			Debug::log("feed $feed not found, skipping.");
276
-			user_error("Attempt to update unknown/invalid feed $feed", E_USER_WARNING);
277
-			return false;
278
-		}
274
+        if (!$row = $sth->fetch()) {
275
+            Debug::log("feed $feed not found, skipping.");
276
+            user_error("Attempt to update unknown/invalid feed $feed", E_USER_WARNING);
277
+            return false;
278
+        }
279 279
 
280
-		$title = $row["title"];
281
-		$site_url = $row["site_url"];
280
+        $title = $row["title"];
281
+        $site_url = $row["site_url"];
282 282
 
283
-		// feed was batch-subscribed or something, we need to get basic info
284
-		// this is not optimal currently as it fetches stuff separately TODO: optimize
285
-		if ($title == "[Unknown]" || !$title || !$site_url) {
286
-			Debug::log("setting basic feed info for $feed [$title, $site_url]...");
287
-			RSSUtils::set_basic_feed_info($feed);
288
-		}
283
+        // feed was batch-subscribed or something, we need to get basic info
284
+        // this is not optimal currently as it fetches stuff separately TODO: optimize
285
+        if ($title == "[Unknown]" || !$title || !$site_url) {
286
+            Debug::log("setting basic feed info for $feed [$title, $site_url]...");
287
+            RSSUtils::set_basic_feed_info($feed);
288
+        }
289 289
 
290
-		$sth = $pdo->prepare("SELECT id,update_interval,auth_login,
290
+        $sth = $pdo->prepare("SELECT id,update_interval,auth_login,
291 291
 			feed_url,auth_pass,cache_images,
292 292
 			mark_unread_on_update, owner_uid,
293 293
 			auth_pass_encrypted, feed_language,
294 294
 			last_modified,
295 295
 			".SUBSTRING_FOR_DATE."(last_unconditional, 1, 19) AS last_unconditional
296 296
 			FROM ttrss_feeds WHERE id = ?");
297
-		$sth->execute([$feed]);
297
+        $sth->execute([$feed]);
298 298
 
299
-		if ($row = $sth->fetch()) {
299
+        if ($row = $sth->fetch()) {
300 300
 
301
-			$owner_uid = $row["owner_uid"];
302
-			$mark_unread_on_update = $row["mark_unread_on_update"];
301
+            $owner_uid = $row["owner_uid"];
302
+            $mark_unread_on_update = $row["mark_unread_on_update"];
303 303
 
304
-			$sth = $pdo->prepare("UPDATE ttrss_feeds SET last_update_started = NOW()
304
+            $sth = $pdo->prepare("UPDATE ttrss_feeds SET last_update_started = NOW()
305 305
 				WHERE id = ?");
306
-			$sth->execute([$feed]);
306
+            $sth->execute([$feed]);
307 307
 
308
-			$auth_login = $row["auth_login"];
309
-			$auth_pass = $row["auth_pass"];
310
-			$stored_last_modified = $row["last_modified"];
311
-			$last_unconditional = $row["last_unconditional"];
312
-			$cache_images = $row["cache_images"];
313
-			$fetch_url = $row["feed_url"];
308
+            $auth_login = $row["auth_login"];
309
+            $auth_pass = $row["auth_pass"];
310
+            $stored_last_modified = $row["last_modified"];
311
+            $last_unconditional = $row["last_unconditional"];
312
+            $cache_images = $row["cache_images"];
313
+            $fetch_url = $row["feed_url"];
314 314
 
315
-			$feed_language = mb_strtolower($row["feed_language"]);
315
+            $feed_language = mb_strtolower($row["feed_language"]);
316 316
 
317
-			if (!$feed_language) {
318
-							$feed_language = mb_strtolower(get_pref('DEFAULT_SEARCH_LANGUAGE', $owner_uid));
319
-			}
317
+            if (!$feed_language) {
318
+                            $feed_language = mb_strtolower(get_pref('DEFAULT_SEARCH_LANGUAGE', $owner_uid));
319
+            }
320 320
 
321
-			if (!$feed_language) {
322
-							$feed_language = 'simple';
323
-			}
321
+            if (!$feed_language) {
322
+                            $feed_language = 'simple';
323
+            }
324 324
 
325
-		} else {
326
-			return false;
327
-		}
325
+        } else {
326
+            return false;
327
+        }
328 328
 
329
-		$date_feed_processed = date('Y-m-d H:i');
329
+        $date_feed_processed = date('Y-m-d H:i');
330 330
 
331
-		$cache_filename = CACHE_DIR."/feeds/".sha1($fetch_url).".xml";
331
+        $cache_filename = CACHE_DIR."/feeds/".sha1($fetch_url).".xml";
332 332
 
333
-		$pluginhost = new PluginHost();
334
-		$user_plugins = get_pref("_ENABLED_PLUGINS", $owner_uid);
333
+        $pluginhost = new PluginHost();
334
+        $user_plugins = get_pref("_ENABLED_PLUGINS", $owner_uid);
335 335
 
336
-		$pluginhost->load(PLUGINS, PluginHost::KIND_ALL);
337
-		$pluginhost->load($user_plugins, PluginHost::KIND_USER, $owner_uid);
338
-		$pluginhost->load_data();
336
+        $pluginhost->load(PLUGINS, PluginHost::KIND_ALL);
337
+        $pluginhost->load($user_plugins, PluginHost::KIND_USER, $owner_uid);
338
+        $pluginhost->load_data();
339 339
 
340
-		$rss_hash = false;
340
+        $rss_hash = false;
341 341
 
342
-		$force_refetch = isset($_REQUEST["force_refetch"]);
343
-		$feed_data = "";
342
+        $force_refetch = isset($_REQUEST["force_refetch"]);
343
+        $feed_data = "";
344 344
 
345
-		Debug::log("running HOOK_FETCH_FEED handlers...", Debug::$LOG_VERBOSE);
345
+        Debug::log("running HOOK_FETCH_FEED handlers...", Debug::$LOG_VERBOSE);
346 346
 
347
-		foreach ($pluginhost->get_hooks(PluginHost::HOOK_FETCH_FEED) as $plugin) {
348
-			Debug::log("... ".get_class($plugin), Debug::$LOG_VERBOSE);
349
-			$start = microtime(true);
350
-			$feed_data = $plugin->hook_fetch_feed($feed_data, $fetch_url, $owner_uid, $feed, 0, $auth_login, $auth_pass);
351
-			Debug::log(sprintf("=== %.4f (sec)", microtime(true) - $start), Debug::$LOG_VERBOSE);
352
-		}
347
+        foreach ($pluginhost->get_hooks(PluginHost::HOOK_FETCH_FEED) as $plugin) {
348
+            Debug::log("... ".get_class($plugin), Debug::$LOG_VERBOSE);
349
+            $start = microtime(true);
350
+            $feed_data = $plugin->hook_fetch_feed($feed_data, $fetch_url, $owner_uid, $feed, 0, $auth_login, $auth_pass);
351
+            Debug::log(sprintf("=== %.4f (sec)", microtime(true) - $start), Debug::$LOG_VERBOSE);
352
+        }
353 353
 
354
-		if ($feed_data) {
355
-			Debug::log("feed data has been modified by a plugin.", Debug::$LOG_VERBOSE);
356
-		} else {
357
-			Debug::log("feed data has not been modified by a plugin.", Debug::$LOG_VERBOSE);
358
-		}
354
+        if ($feed_data) {
355
+            Debug::log("feed data has been modified by a plugin.", Debug::$LOG_VERBOSE);
356
+        } else {
357
+            Debug::log("feed data has not been modified by a plugin.", Debug::$LOG_VERBOSE);
358
+        }
359 359
 
360
-		// try cache
361
-		if (!$feed_data &&
362
-			file_exists($cache_filename) &&
363
-			is_readable($cache_filename) &&
364
-			!$auth_login && !$auth_pass &&
365
-			filemtime($cache_filename) > time() - 30) {
360
+        // try cache
361
+        if (!$feed_data &&
362
+            file_exists($cache_filename) &&
363
+            is_readable($cache_filename) &&
364
+            !$auth_login && !$auth_pass &&
365
+            filemtime($cache_filename) > time() - 30) {
366 366
 
367
-			Debug::log("using local cache [$cache_filename].", Debug::$LOG_VERBOSE);
367
+            Debug::log("using local cache [$cache_filename].", Debug::$LOG_VERBOSE);
368 368
 
369
-			@$feed_data = file_get_contents($cache_filename);
369
+            @$feed_data = file_get_contents($cache_filename);
370 370
 
371
-			if ($feed_data) {
372
-				$rss_hash = sha1($feed_data);
373
-			}
371
+            if ($feed_data) {
372
+                $rss_hash = sha1($feed_data);
373
+            }
374 374
 
375
-		} else {
376
-			Debug::log("local cache will not be used for this feed", Debug::$LOG_VERBOSE);
377
-		}
375
+        } else {
376
+            Debug::log("local cache will not be used for this feed", Debug::$LOG_VERBOSE);
377
+        }
378 378
 
379
-		global $fetch_last_modified;
379
+        global $fetch_last_modified;
380 380
 
381
-		// fetch feed from source
382
-		if (!$feed_data) {
383
-			Debug::log("last unconditional update request: $last_unconditional", Debug::$LOG_VERBOSE);
381
+        // fetch feed from source
382
+        if (!$feed_data) {
383
+            Debug::log("last unconditional update request: $last_unconditional", Debug::$LOG_VERBOSE);
384 384
 
385
-			if (ini_get("open_basedir") && function_exists("curl_init")) {
386
-				Debug::log("not using CURL due to open_basedir restrictions", Debug::$LOG_VERBOSE);
387
-			}
385
+            if (ini_get("open_basedir") && function_exists("curl_init")) {
386
+                Debug::log("not using CURL due to open_basedir restrictions", Debug::$LOG_VERBOSE);
387
+            }
388 388
 
389
-			if (time() - strtotime($last_unconditional) > MAX_CONDITIONAL_INTERVAL) {
390
-				Debug::log("maximum allowed interval for conditional requests exceeded, forcing refetch", Debug::$LOG_VERBOSE);
389
+            if (time() - strtotime($last_unconditional) > MAX_CONDITIONAL_INTERVAL) {
390
+                Debug::log("maximum allowed interval for conditional requests exceeded, forcing refetch", Debug::$LOG_VERBOSE);
391 391
 
392
-				$force_refetch = true;
393
-			} else {
394
-				Debug::log("stored last modified for conditional request: $stored_last_modified", Debug::$LOG_VERBOSE);
395
-			}
392
+                $force_refetch = true;
393
+            } else {
394
+                Debug::log("stored last modified for conditional request: $stored_last_modified", Debug::$LOG_VERBOSE);
395
+            }
396 396
 
397
-			Debug::log("fetching [$fetch_url] (force_refetch: $force_refetch)...", Debug::$LOG_VERBOSE);
397
+            Debug::log("fetching [$fetch_url] (force_refetch: $force_refetch)...", Debug::$LOG_VERBOSE);
398 398
 
399
-			$feed_data = fetch_file_contents([
400
-				"url" => $fetch_url,
401
-				"login" => $auth_login,
402
-				"pass" => $auth_pass,
403
-				"timeout" => $no_cache ? FEED_FETCH_NO_CACHE_TIMEOUT : FEED_FETCH_TIMEOUT,
404
-				"last_modified" => $force_refetch ? "" : $stored_last_modified
405
-			]);
399
+            $feed_data = fetch_file_contents([
400
+                "url" => $fetch_url,
401
+                "login" => $auth_login,
402
+                "pass" => $auth_pass,
403
+                "timeout" => $no_cache ? FEED_FETCH_NO_CACHE_TIMEOUT : FEED_FETCH_TIMEOUT,
404
+                "last_modified" => $force_refetch ? "" : $stored_last_modified
405
+            ]);
406 406
 
407
-			$feed_data = trim($feed_data);
407
+            $feed_data = trim($feed_data);
408 408
 
409
-			Debug::log("fetch done.", Debug::$LOG_VERBOSE);
410
-			Debug::log("source last modified: ".$fetch_last_modified, Debug::$LOG_VERBOSE);
409
+            Debug::log("fetch done.", Debug::$LOG_VERBOSE);
410
+            Debug::log("source last modified: ".$fetch_last_modified, Debug::$LOG_VERBOSE);
411 411
 
412
-			if ($feed_data && $fetch_last_modified != $stored_last_modified) {
413
-				$sth = $pdo->prepare("UPDATE ttrss_feeds SET last_modified = ? WHERE id = ?");
414
-				$sth->execute([substr($fetch_last_modified, 0, 245), $feed]);
415
-			}
412
+            if ($feed_data && $fetch_last_modified != $stored_last_modified) {
413
+                $sth = $pdo->prepare("UPDATE ttrss_feeds SET last_modified = ? WHERE id = ?");
414
+                $sth->execute([substr($fetch_last_modified, 0, 245), $feed]);
415
+            }
416 416
 
417
-			// cache vanilla feed data for re-use
418
-			if ($feed_data && !$auth_pass && !$auth_login && is_writable(CACHE_DIR."/feeds")) {
419
-				$new_rss_hash = sha1($feed_data);
417
+            // cache vanilla feed data for re-use
418
+            if ($feed_data && !$auth_pass && !$auth_login && is_writable(CACHE_DIR."/feeds")) {
419
+                $new_rss_hash = sha1($feed_data);
420 420
 
421
-				if ($new_rss_hash != $rss_hash) {
422
-					Debug::log("saving $cache_filename", Debug::$LOG_VERBOSE);
423
-					@file_put_contents($cache_filename, $feed_data);
424
-				}
425
-			}
426
-		}
421
+                if ($new_rss_hash != $rss_hash) {
422
+                    Debug::log("saving $cache_filename", Debug::$LOG_VERBOSE);
423
+                    @file_put_contents($cache_filename, $feed_data);
424
+                }
425
+            }
426
+        }
427 427
 
428
-		if (!$feed_data) {
429
-			global $fetch_last_error;
430
-			global $fetch_last_error_code;
428
+        if (!$feed_data) {
429
+            global $fetch_last_error;
430
+            global $fetch_last_error_code;
431 431
 
432
-			Debug::log("unable to fetch: $fetch_last_error [$fetch_last_error_code]", Debug::$LOG_VERBOSE);
432
+            Debug::log("unable to fetch: $fetch_last_error [$fetch_last_error_code]", Debug::$LOG_VERBOSE);
433 433
 
434
-			// If-Modified-Since
435
-			if ($fetch_last_error_code != 304) {
436
-				$error_message = $fetch_last_error;
437
-			} else {
438
-				Debug::log("source claims data not modified, nothing to do.", Debug::$LOG_VERBOSE);
439
-				$error_message = "";
440
-			}
434
+            // If-Modified-Since
435
+            if ($fetch_last_error_code != 304) {
436
+                $error_message = $fetch_last_error;
437
+            } else {
438
+                Debug::log("source claims data not modified, nothing to do.", Debug::$LOG_VERBOSE);
439
+                $error_message = "";
440
+            }
441 441
 
442
-			$sth = $pdo->prepare("UPDATE ttrss_feeds SET last_error = ?,
442
+            $sth = $pdo->prepare("UPDATE ttrss_feeds SET last_error = ?,
443 443
 					last_updated = NOW() WHERE id = ?");
444
-			$sth->execute([$error_message, $feed]);
444
+            $sth->execute([$error_message, $feed]);
445 445
 
446
-			return;
447
-		}
446
+            return;
447
+        }
448 448
 
449
-		Debug::log("running HOOK_FEED_FETCHED handlers...", Debug::$LOG_VERBOSE);
450
-		$feed_data_checksum = md5($feed_data);
449
+        Debug::log("running HOOK_FEED_FETCHED handlers...", Debug::$LOG_VERBOSE);
450
+        $feed_data_checksum = md5($feed_data);
451 451
 
452
-		foreach ($pluginhost->get_hooks(PluginHost::HOOK_FEED_FETCHED) as $plugin) {
453
-			Debug::log("... ".get_class($plugin), Debug::$LOG_VERBOSE);
454
-			$start = microtime(true);
455
-			$feed_data = $plugin->hook_feed_fetched($feed_data, $fetch_url, $owner_uid, $feed);
456
-			Debug::log(sprintf("=== %.4f (sec)", microtime(true) - $start), Debug::$LOG_VERBOSE);
457
-		}
452
+        foreach ($pluginhost->get_hooks(PluginHost::HOOK_FEED_FETCHED) as $plugin) {
453
+            Debug::log("... ".get_class($plugin), Debug::$LOG_VERBOSE);
454
+            $start = microtime(true);
455
+            $feed_data = $plugin->hook_feed_fetched($feed_data, $fetch_url, $owner_uid, $feed);
456
+            Debug::log(sprintf("=== %.4f (sec)", microtime(true) - $start), Debug::$LOG_VERBOSE);
457
+        }
458 458
 
459
-		if (md5($feed_data) != $feed_data_checksum) {
460
-			Debug::log("feed data has been modified by a plugin.", Debug::$LOG_VERBOSE);
461
-		} else {
462
-			Debug::log("feed data has not been modified by a plugin.", Debug::$LOG_VERBOSE);
463
-		}
459
+        if (md5($feed_data) != $feed_data_checksum) {
460
+            Debug::log("feed data has been modified by a plugin.", Debug::$LOG_VERBOSE);
461
+        } else {
462
+            Debug::log("feed data has not been modified by a plugin.", Debug::$LOG_VERBOSE);
463
+        }
464 464
 
465
-		$rss = new FeedParser($feed_data);
466
-		$rss->init();
465
+        $rss = new FeedParser($feed_data);
466
+        $rss->init();
467 467
 
468
-		if (!$rss->error()) {
468
+        if (!$rss->error()) {
469 469
 
470
-			Debug::log("running HOOK_FEED_PARSED handlers...", Debug::$LOG_VERBOSE);
470
+            Debug::log("running HOOK_FEED_PARSED handlers...", Debug::$LOG_VERBOSE);
471 471
 
472
-			// We use local pluginhost here because we need to load different per-user feed plugins
472
+            // We use local pluginhost here because we need to load different per-user feed plugins
473 473
 
474
-			foreach ($pluginhost->get_hooks(PluginHost::HOOK_FEED_PARSED) as $plugin) {
475
-				Debug::log("... ".get_class($plugin), Debug::$LOG_VERBOSE);
476
-				$start = microtime(true);
477
-				$plugin->hook_feed_parsed($rss);
478
-				Debug::log(sprintf("=== %.4f (sec)", microtime(true) - $start), Debug::$LOG_VERBOSE);
479
-			}
474
+            foreach ($pluginhost->get_hooks(PluginHost::HOOK_FEED_PARSED) as $plugin) {
475
+                Debug::log("... ".get_class($plugin), Debug::$LOG_VERBOSE);
476
+                $start = microtime(true);
477
+                $plugin->hook_feed_parsed($rss);
478
+                Debug::log(sprintf("=== %.4f (sec)", microtime(true) - $start), Debug::$LOG_VERBOSE);
479
+            }
480 480
 
481
-			Debug::log("language: $feed_language", Debug::$LOG_VERBOSE);
482
-			Debug::log("processing feed data...", Debug::$LOG_VERBOSE);
481
+            Debug::log("language: $feed_language", Debug::$LOG_VERBOSE);
482
+            Debug::log("processing feed data...", Debug::$LOG_VERBOSE);
483 483
 
484
-			if (DB_TYPE == "pgsql") {
485
-				$favicon_interval_qpart = "favicon_last_checked < NOW() - INTERVAL '12 hour'";
486
-			} else {
487
-				$favicon_interval_qpart = "favicon_last_checked < DATE_SUB(NOW(), INTERVAL 12 HOUR)";
488
-			}
484
+            if (DB_TYPE == "pgsql") {
485
+                $favicon_interval_qpart = "favicon_last_checked < NOW() - INTERVAL '12 hour'";
486
+            } else {
487
+                $favicon_interval_qpart = "favicon_last_checked < DATE_SUB(NOW(), INTERVAL 12 HOUR)";
488
+            }
489 489
 
490
-			$sth = $pdo->prepare("SELECT owner_uid,favicon_avg_color,
490
+            $sth = $pdo->prepare("SELECT owner_uid,favicon_avg_color,
491 491
 				(favicon_last_checked IS NULL OR $favicon_interval_qpart) AS
492 492
 						favicon_needs_check
493 493
 				FROM ttrss_feeds WHERE id = ?");
494
-			$sth->execute([$feed]);
494
+            $sth->execute([$feed]);
495 495
 
496
-			if ($row = $sth->fetch()) {
497
-				$favicon_needs_check = $row["favicon_needs_check"];
498
-				$favicon_avg_color = $row["favicon_avg_color"];
499
-				$owner_uid = $row["owner_uid"];
500
-			} else {
501
-				return false;
502
-			}
496
+            if ($row = $sth->fetch()) {
497
+                $favicon_needs_check = $row["favicon_needs_check"];
498
+                $favicon_avg_color = $row["favicon_avg_color"];
499
+                $owner_uid = $row["owner_uid"];
500
+            } else {
501
+                return false;
502
+            }
503 503
 
504
-			$site_url = mb_substr(rewrite_relative_url($fetch_url, clean($rss->get_link())), 0, 245);
504
+            $site_url = mb_substr(rewrite_relative_url($fetch_url, clean($rss->get_link())), 0, 245);
505 505
 
506
-			Debug::log("site_url: $site_url", Debug::$LOG_VERBOSE);
507
-			Debug::log("feed_title: ".clean($rss->get_title()), Debug::$LOG_VERBOSE);
506
+            Debug::log("site_url: $site_url", Debug::$LOG_VERBOSE);
507
+            Debug::log("feed_title: ".clean($rss->get_title()), Debug::$LOG_VERBOSE);
508 508
 
509
-			if ($favicon_needs_check || $force_refetch) {
509
+            if ($favicon_needs_check || $force_refetch) {
510 510
 
511
-				/* terrible hack: if we crash on floicon shit here, we won't check
511
+                /* terrible hack: if we crash on floicon shit here, we won't check
512 512
 				 * the icon avgcolor again (unless the icon got updated) */
513 513
 
514
-				$favicon_file = ICONS_DIR."/$feed.ico";
515
-				$favicon_modified = @filemtime($favicon_file);
514
+                $favicon_file = ICONS_DIR."/$feed.ico";
515
+                $favicon_modified = @filemtime($favicon_file);
516 516
 
517
-				Debug::log("checking favicon...", Debug::$LOG_VERBOSE);
517
+                Debug::log("checking favicon...", Debug::$LOG_VERBOSE);
518 518
 
519
-				RSSUtils::check_feed_favicon($site_url, $feed);
520
-				$favicon_modified_new = @filemtime($favicon_file);
519
+                RSSUtils::check_feed_favicon($site_url, $feed);
520
+                $favicon_modified_new = @filemtime($favicon_file);
521 521
 
522
-				if ($favicon_modified_new > $favicon_modified) {
523
-									$favicon_avg_color = '';
524
-				}
522
+                if ($favicon_modified_new > $favicon_modified) {
523
+                                    $favicon_avg_color = '';
524
+                }
525 525
 
526
-				$favicon_colorstring = "";
527
-				if (file_exists($favicon_file) && function_exists("imagecreatefromstring") && $favicon_avg_color == '') {
528
-					require_once "colors.php";
526
+                $favicon_colorstring = "";
527
+                if (file_exists($favicon_file) && function_exists("imagecreatefromstring") && $favicon_avg_color == '') {
528
+                    require_once "colors.php";
529 529
 
530
-					$sth = $pdo->prepare("UPDATE ttrss_feeds SET favicon_avg_color = 'fail' WHERE
530
+                    $sth = $pdo->prepare("UPDATE ttrss_feeds SET favicon_avg_color = 'fail' WHERE
531 531
 							id = ?");
532
-					$sth->execute([$feed]);
532
+                    $sth->execute([$feed]);
533 533
 
534
-					$favicon_color = calculate_avg_color($favicon_file);
534
+                    $favicon_color = calculate_avg_color($favicon_file);
535 535
 
536
-					$favicon_colorstring = ",favicon_avg_color = ".$pdo->quote($favicon_color);
536
+                    $favicon_colorstring = ",favicon_avg_color = ".$pdo->quote($favicon_color);
537 537
 
538
-				} else if ($favicon_avg_color == 'fail') {
539
-					Debug::log("floicon failed on this file, not trying to recalculate avg color", Debug::$LOG_VERBOSE);
540
-				}
538
+                } else if ($favicon_avg_color == 'fail') {
539
+                    Debug::log("floicon failed on this file, not trying to recalculate avg color", Debug::$LOG_VERBOSE);
540
+                }
541 541
 
542
-				$sth = $pdo->prepare("UPDATE ttrss_feeds SET favicon_last_checked = NOW()
542
+                $sth = $pdo->prepare("UPDATE ttrss_feeds SET favicon_last_checked = NOW()
543 543
 					$favicon_colorstring WHERE id = ?");
544
-				$sth->execute([$feed]);
545
-			}
544
+                $sth->execute([$feed]);
545
+            }
546 546
 
547
-			Debug::log("loading filters & labels...", Debug::$LOG_VERBOSE);
547
+            Debug::log("loading filters & labels...", Debug::$LOG_VERBOSE);
548 548
 
549
-			$filters = RSSUtils::load_filters($feed, $owner_uid);
549
+            $filters = RSSUtils::load_filters($feed, $owner_uid);
550 550
 
551
-			if (Debug::get_loglevel() >= Debug::$LOG_EXTENDED) {
552
-				print_r($filters);
553
-			}
551
+            if (Debug::get_loglevel() >= Debug::$LOG_EXTENDED) {
552
+                print_r($filters);
553
+            }
554 554
 
555
-			Debug::log("".count($filters)." filters loaded.", Debug::$LOG_VERBOSE);
555
+            Debug::log("".count($filters)." filters loaded.", Debug::$LOG_VERBOSE);
556 556
 
557
-			$items = $rss->get_items();
557
+            $items = $rss->get_items();
558 558
 
559
-			if (!is_array($items)) {
560
-				Debug::log("no articles found.", Debug::$LOG_VERBOSE);
559
+            if (!is_array($items)) {
560
+                Debug::log("no articles found.", Debug::$LOG_VERBOSE);
561 561
 
562
-				$sth = $pdo->prepare("UPDATE ttrss_feeds
562
+                $sth = $pdo->prepare("UPDATE ttrss_feeds
563 563
 					SET last_updated = NOW(), last_unconditional = NOW(), last_error = '' WHERE id = ?");
564
-				$sth->execute([$feed]);
564
+                $sth->execute([$feed]);
565 565
 
566
-				return true; // no articles
567
-			}
566
+                return true; // no articles
567
+            }
568 568
 
569
-			Debug::log("processing articles...", Debug::$LOG_VERBOSE);
569
+            Debug::log("processing articles...", Debug::$LOG_VERBOSE);
570 570
 
571
-			$tstart = time();
571
+            $tstart = time();
572 572
 
573
-			foreach ($items as $item) {
574
-				$pdo->beginTransaction();
573
+            foreach ($items as $item) {
574
+                $pdo->beginTransaction();
575 575
 
576
-				if (Debug::get_loglevel() >= 3) {
577
-					print_r($item);
578
-				}
576
+                if (Debug::get_loglevel() >= 3) {
577
+                    print_r($item);
578
+                }
579 579
 
580
-				if (ini_get("max_execution_time") > 0 && time() - $tstart >= ini_get("max_execution_time") * 0.7) {
581
-					Debug::log("looks like there's too many articles to process at once, breaking out", Debug::$LOG_VERBOSE);
582
-					$pdo->commit();
583
-					break;
584
-				}
580
+                if (ini_get("max_execution_time") > 0 && time() - $tstart >= ini_get("max_execution_time") * 0.7) {
581
+                    Debug::log("looks like there's too many articles to process at once, breaking out", Debug::$LOG_VERBOSE);
582
+                    $pdo->commit();
583
+                    break;
584
+                }
585 585
 
586
-				$entry_guid = strip_tags($item->get_id());
587
-				if (!$entry_guid) {
588
-				    $entry_guid = strip_tags($item->get_link());
589
-				}
590
-				if (!$entry_guid) {
591
-				    $entry_guid = RSSUtils::make_guid_from_title($item->get_title());
592
-				}
586
+                $entry_guid = strip_tags($item->get_id());
587
+                if (!$entry_guid) {
588
+                    $entry_guid = strip_tags($item->get_link());
589
+                }
590
+                if (!$entry_guid) {
591
+                    $entry_guid = RSSUtils::make_guid_from_title($item->get_title());
592
+                }
593 593
 
594
-				if (!$entry_guid) {
595
-					$pdo->commit();
596
-					continue;
597
-				}
594
+                if (!$entry_guid) {
595
+                    $pdo->commit();
596
+                    continue;
597
+                }
598 598
 
599
-				$entry_guid = "$owner_uid,$entry_guid";
599
+                $entry_guid = "$owner_uid,$entry_guid";
600 600
 
601
-				$entry_guid_hashed = 'SHA1:'.sha1($entry_guid);
601
+                $entry_guid_hashed = 'SHA1:'.sha1($entry_guid);
602 602
 
603
-				Debug::log("guid $entry_guid / $entry_guid_hashed", Debug::$LOG_VERBOSE);
603
+                Debug::log("guid $entry_guid / $entry_guid_hashed", Debug::$LOG_VERBOSE);
604 604
 
605
-				$entry_timestamp = (int) $item->get_date();
605
+                $entry_timestamp = (int) $item->get_date();
606 606
 
607
-				Debug::log("orig date: ".$item->get_date(), Debug::$LOG_VERBOSE);
607
+                Debug::log("orig date: ".$item->get_date(), Debug::$LOG_VERBOSE);
608 608
 
609
-				$entry_title = strip_tags($item->get_title());
609
+                $entry_title = strip_tags($item->get_title());
610 610
 
611
-				$entry_link = rewrite_relative_url($site_url, clean($item->get_link()));
611
+                $entry_link = rewrite_relative_url($site_url, clean($item->get_link()));
612 612
 
613
-				$entry_language = mb_substr(trim($item->get_language()), 0, 2);
613
+                $entry_language = mb_substr(trim($item->get_language()), 0, 2);
614 614
 
615
-				Debug::log("title $entry_title", Debug::$LOG_VERBOSE);
616
-				Debug::log("link $entry_link", Debug::$LOG_VERBOSE);
617
-				Debug::log("language $entry_language", Debug::$LOG_VERBOSE);
615
+                Debug::log("title $entry_title", Debug::$LOG_VERBOSE);
616
+                Debug::log("link $entry_link", Debug::$LOG_VERBOSE);
617
+                Debug::log("language $entry_language", Debug::$LOG_VERBOSE);
618 618
 
619
-				if (!$entry_title) $entry_title = date("Y-m-d H:i:s", $entry_timestamp); ;
619
+                if (!$entry_title) $entry_title = date("Y-m-d H:i:s", $entry_timestamp); ;
620 620
 
621
-				$entry_content = $item->get_content();
622
-				if (!$entry_content) $entry_content = $item->get_description();
621
+                $entry_content = $item->get_content();
622
+                if (!$entry_content) $entry_content = $item->get_description();
623 623
 
624
-				if (Debug::get_loglevel() >= 3) {
625
-					print "content: ";
626
-					print htmlspecialchars($entry_content);
627
-					print "\n";
628
-				}
624
+                if (Debug::get_loglevel() >= 3) {
625
+                    print "content: ";
626
+                    print htmlspecialchars($entry_content);
627
+                    print "\n";
628
+                }
629 629
 
630
-				$entry_comments = mb_substr(strip_tags($item->get_comments_url()), 0, 245);
631
-				$num_comments = (int) $item->get_comments_count();
630
+                $entry_comments = mb_substr(strip_tags($item->get_comments_url()), 0, 245);
631
+                $num_comments = (int) $item->get_comments_count();
632 632
 
633
-				$entry_author = strip_tags($item->get_author());
634
-				$entry_guid = mb_substr($entry_guid, 0, 245);
633
+                $entry_author = strip_tags($item->get_author());
634
+                $entry_guid = mb_substr($entry_guid, 0, 245);
635 635
 
636
-				Debug::log("author $entry_author", Debug::$LOG_VERBOSE);
637
-				Debug::log("looking for tags...", Debug::$LOG_VERBOSE);
636
+                Debug::log("author $entry_author", Debug::$LOG_VERBOSE);
637
+                Debug::log("looking for tags...", Debug::$LOG_VERBOSE);
638 638
 
639
-				$entry_tags = $item->get_categories();
640
-				Debug::log("tags found: ".join(", ", $entry_tags), Debug::$LOG_VERBOSE);
639
+                $entry_tags = $item->get_categories();
640
+                Debug::log("tags found: ".join(", ", $entry_tags), Debug::$LOG_VERBOSE);
641 641
 
642
-				Debug::log("done collecting data.", Debug::$LOG_VERBOSE);
642
+                Debug::log("done collecting data.", Debug::$LOG_VERBOSE);
643 643
 
644
-				$sth = $pdo->prepare("SELECT id, content_hash, lang FROM ttrss_entries
644
+                $sth = $pdo->prepare("SELECT id, content_hash, lang FROM ttrss_entries
645 645
 					WHERE guid = ? OR guid = ?");
646
-				$sth->execute([$entry_guid, $entry_guid_hashed]);
647
-
648
-				if ($row = $sth->fetch()) {
649
-					$base_entry_id = $row["id"];
650
-					$entry_stored_hash = $row["content_hash"];
651
-					$article_labels = Article::get_article_labels($base_entry_id, $owner_uid);
652
-
653
-					$existing_tags = Article::get_article_tags($base_entry_id, $owner_uid);
654
-					$entry_tags = array_unique(array_merge($entry_tags, $existing_tags));
655
-				} else {
656
-					$base_entry_id = false;
657
-					$entry_stored_hash = "";
658
-					$article_labels = array();
659
-				}
660
-
661
-				$article = array("owner_uid" => $owner_uid, // read only
662
-					"guid" => $entry_guid, // read only
663
-					"guid_hashed" => $entry_guid_hashed, // read only
664
-					"title" => $entry_title,
665
-					"content" => $entry_content,
666
-					"link" => $entry_link,
667
-					"labels" => $article_labels, // current limitation: can add labels to article, can't remove them
668
-					"tags" => $entry_tags,
669
-					"author" => $entry_author,
670
-					"force_catchup" => false, // ugly hack for the time being
671
-					"score_modifier" => 0, // no previous value, plugin should recalculate score modifier based on content if needed
672
-					"language" => $entry_language,
673
-					"timestamp" => $entry_timestamp,
674
-					"num_comments" => $num_comments,
675
-					"feed" => array("id" => $feed,
676
-						"fetch_url" => $fetch_url,
677
-						"site_url" => $site_url,
678
-						"cache_images" => $cache_images)
679
-				);
680
-
681
-				$entry_plugin_data = "";
682
-				$entry_current_hash = RSSUtils::calculate_article_hash($article, $pluginhost);
683
-
684
-				Debug::log("article hash: $entry_current_hash [stored=$entry_stored_hash]", Debug::$LOG_VERBOSE);
685
-
686
-				if ($entry_current_hash == $entry_stored_hash && !isset($_REQUEST["force_rehash"])) {
687
-					Debug::log("stored article seems up to date [IID: $base_entry_id], updating timestamp only", Debug::$LOG_VERBOSE);
688
-
689
-					// we keep encountering the entry in feeds, so we need to
690
-					// update date_updated column so that we don't get horrible
691
-					// dupes when the entry gets purged and reinserted again e.g.
692
-					// in the case of SLOW SLOW OMG SLOW updating feeds
693
-
694
-					$sth = $pdo->prepare("UPDATE ttrss_entries SET date_updated = NOW()
646
+                $sth->execute([$entry_guid, $entry_guid_hashed]);
647
+
648
+                if ($row = $sth->fetch()) {
649
+                    $base_entry_id = $row["id"];
650
+                    $entry_stored_hash = $row["content_hash"];
651
+                    $article_labels = Article::get_article_labels($base_entry_id, $owner_uid);
652
+
653
+                    $existing_tags = Article::get_article_tags($base_entry_id, $owner_uid);
654
+                    $entry_tags = array_unique(array_merge($entry_tags, $existing_tags));
655
+                } else {
656
+                    $base_entry_id = false;
657
+                    $entry_stored_hash = "";
658
+                    $article_labels = array();
659
+                }
660
+
661
+                $article = array("owner_uid" => $owner_uid, // read only
662
+                    "guid" => $entry_guid, // read only
663
+                    "guid_hashed" => $entry_guid_hashed, // read only
664
+                    "title" => $entry_title,
665
+                    "content" => $entry_content,
666
+                    "link" => $entry_link,
667
+                    "labels" => $article_labels, // current limitation: can add labels to article, can't remove them
668
+                    "tags" => $entry_tags,
669
+                    "author" => $entry_author,
670
+                    "force_catchup" => false, // ugly hack for the time being
671
+                    "score_modifier" => 0, // no previous value, plugin should recalculate score modifier based on content if needed
672
+                    "language" => $entry_language,
673
+                    "timestamp" => $entry_timestamp,
674
+                    "num_comments" => $num_comments,
675
+                    "feed" => array("id" => $feed,
676
+                        "fetch_url" => $fetch_url,
677
+                        "site_url" => $site_url,
678
+                        "cache_images" => $cache_images)
679
+                );
680
+
681
+                $entry_plugin_data = "";
682
+                $entry_current_hash = RSSUtils::calculate_article_hash($article, $pluginhost);
683
+
684
+                Debug::log("article hash: $entry_current_hash [stored=$entry_stored_hash]", Debug::$LOG_VERBOSE);
685
+
686
+                if ($entry_current_hash == $entry_stored_hash && !isset($_REQUEST["force_rehash"])) {
687
+                    Debug::log("stored article seems up to date [IID: $base_entry_id], updating timestamp only", Debug::$LOG_VERBOSE);
688
+
689
+                    // we keep encountering the entry in feeds, so we need to
690
+                    // update date_updated column so that we don't get horrible
691
+                    // dupes when the entry gets purged and reinserted again e.g.
692
+                    // in the case of SLOW SLOW OMG SLOW updating feeds
693
+
694
+                    $sth = $pdo->prepare("UPDATE ttrss_entries SET date_updated = NOW()
695 695
 						WHERE id = ?");
696
-					$sth->execute([$base_entry_id]);
696
+                    $sth->execute([$base_entry_id]);
697 697
 
698
-					$pdo->commit();
699
-					continue;
700
-				}
698
+                    $pdo->commit();
699
+                    continue;
700
+                }
701 701
 
702
-				Debug::log("hash differs, applying plugin filters:", Debug::$LOG_VERBOSE);
702
+                Debug::log("hash differs, applying plugin filters:", Debug::$LOG_VERBOSE);
703 703
 
704
-				foreach ($pluginhost->get_hooks(PluginHost::HOOK_ARTICLE_FILTER) as $plugin) {
705
-					Debug::log("... ".get_class($plugin), Debug::$LOG_VERBOSE);
704
+                foreach ($pluginhost->get_hooks(PluginHost::HOOK_ARTICLE_FILTER) as $plugin) {
705
+                    Debug::log("... ".get_class($plugin), Debug::$LOG_VERBOSE);
706 706
 
707
-					$start = microtime(true);
708
-					$article = $plugin->hook_article_filter($article);
707
+                    $start = microtime(true);
708
+                    $article = $plugin->hook_article_filter($article);
709 709
 
710
-					Debug::log(sprintf("=== %.4f (sec)", microtime(true) - $start), Debug::$LOG_VERBOSE);
710
+                    Debug::log(sprintf("=== %.4f (sec)", microtime(true) - $start), Debug::$LOG_VERBOSE);
711 711
 
712
-					$entry_plugin_data .= mb_strtolower(get_class($plugin)).",";
713
-				}
712
+                    $entry_plugin_data .= mb_strtolower(get_class($plugin)).",";
713
+                }
714 714
 
715 715
                 if (Debug::get_loglevel() >= 3) {
716
-					print "processed content: ";
717
-					print htmlspecialchars($article["content"]);
718
-					print "\n";
719
-				}
716
+                    print "processed content: ";
717
+                    print htmlspecialchars($article["content"]);
718
+                    print "\n";
719
+                }
720 720
 
721
-				Debug::log("plugin data: $entry_plugin_data", Debug::$LOG_VERBOSE);
721
+                Debug::log("plugin data: $entry_plugin_data", Debug::$LOG_VERBOSE);
722 722
 
723
-				// Workaround: 4-byte unicode requires utf8mb4 in MySQL. See https://tt-rss.org/forum/viewtopic.php?f=1&t=3377&p=20077#p20077
724
-				if (DB_TYPE == "mysql" && MYSQL_CHARSET != "UTF8MB4") {
725
-					foreach ($article as $k => $v) {
726
-						// i guess we'll have to take the risk of 4byte unicode labels & tags here
727
-						if (is_string($article[$k])) {
728
-							$article[$k] = RSSUtils::strip_utf8mb4($v);
729
-						}
730
-					}
731
-				}
723
+                // Workaround: 4-byte unicode requires utf8mb4 in MySQL. See https://tt-rss.org/forum/viewtopic.php?f=1&t=3377&p=20077#p20077
724
+                if (DB_TYPE == "mysql" && MYSQL_CHARSET != "UTF8MB4") {
725
+                    foreach ($article as $k => $v) {
726
+                        // i guess we'll have to take the risk of 4byte unicode labels & tags here
727
+                        if (is_string($article[$k])) {
728
+                            $article[$k] = RSSUtils::strip_utf8mb4($v);
729
+                        }
730
+                    }
731
+                }
732 732
 
733
-				/* Collect article tags here so we could filter by them: */
733
+                /* Collect article tags here so we could filter by them: */
734 734
 
735
-				$matched_rules = [];
736
-				$matched_filters = [];
735
+                $matched_rules = [];
736
+                $matched_filters = [];
737 737
 
738
-				$article_filters = RSSUtils::get_article_filters($filters, $article["title"],
739
-					$article["content"], $article["link"], $article["author"],
740
-					$article["tags"], $matched_rules, $matched_filters);
738
+                $article_filters = RSSUtils::get_article_filters($filters, $article["title"],
739
+                    $article["content"], $article["link"], $article["author"],
740
+                    $article["tags"], $matched_rules, $matched_filters);
741 741
 
742
-				// $article_filters should be renamed to something like $filter_actions; actual filter objects are in $matched_filters
743
-				foreach ($pluginhost->get_hooks(PluginHost::HOOK_FILTER_TRIGGERED) as $plugin) {
744
-					$plugin->hook_filter_triggered($feed, $owner_uid, $article, $matched_filters, $matched_rules, $article_filters);
745
-				}
742
+                // $article_filters should be renamed to something like $filter_actions; actual filter objects are in $matched_filters
743
+                foreach ($pluginhost->get_hooks(PluginHost::HOOK_FILTER_TRIGGERED) as $plugin) {
744
+                    $plugin->hook_filter_triggered($feed, $owner_uid, $article, $matched_filters, $matched_rules, $article_filters);
745
+                }
746 746
 
747
-				$matched_filter_ids = array_map(function($f) { return $f['id']; }, $matched_filters);
747
+                $matched_filter_ids = array_map(function($f) { return $f['id']; }, $matched_filters);
748 748
 
749
-				if (count($matched_filter_ids) > 0) {
750
-					$filter_ids_qmarks = arr_qmarks($matched_filter_ids);
749
+                if (count($matched_filter_ids) > 0) {
750
+                    $filter_ids_qmarks = arr_qmarks($matched_filter_ids);
751 751
 
752
-					$fsth = $pdo->prepare("UPDATE ttrss_filters2 SET last_triggered = NOW() WHERE
752
+                    $fsth = $pdo->prepare("UPDATE ttrss_filters2 SET last_triggered = NOW() WHERE
753 753
 							   id IN ($filter_ids_qmarks) AND owner_uid = ?");
754 754
 
755
-					$fsth->execute(array_merge($matched_filter_ids, [$owner_uid]));
756
-				}
755
+                    $fsth->execute(array_merge($matched_filter_ids, [$owner_uid]));
756
+                }
757 757
 
758
-				if (Debug::get_loglevel() >= Debug::$LOG_EXTENDED) {
759
-					Debug::log("matched filters: ", Debug::$LOG_VERBOSE);
758
+                if (Debug::get_loglevel() >= Debug::$LOG_EXTENDED) {
759
+                    Debug::log("matched filters: ", Debug::$LOG_VERBOSE);
760 760
 
761
-					if (count($matched_filters != 0)) {
762
-						print_r($matched_filters);
763
-					}
761
+                    if (count($matched_filters != 0)) {
762
+                        print_r($matched_filters);
763
+                    }
764 764
 
765
-					Debug::log("matched filter rules: ", Debug::$LOG_VERBOSE);
765
+                    Debug::log("matched filter rules: ", Debug::$LOG_VERBOSE);
766 766
 
767
-					if (count($matched_rules) != 0) {
768
-						print_r($matched_rules);
769
-					}
767
+                    if (count($matched_rules) != 0) {
768
+                        print_r($matched_rules);
769
+                    }
770 770
 
771
-					Debug::log("filter actions: ", Debug::$LOG_VERBOSE);
771
+                    Debug::log("filter actions: ", Debug::$LOG_VERBOSE);
772 772
 
773
-					if (count($article_filters) != 0) {
774
-						print_r($article_filters);
775
-					}
776
-				}
773
+                    if (count($article_filters) != 0) {
774
+                        print_r($article_filters);
775
+                    }
776
+                }
777 777
 
778
-				$plugin_filter_names = RSSUtils::find_article_filters($article_filters, "plugin");
779
-				$plugin_filter_actions = $pluginhost->get_filter_actions();
778
+                $plugin_filter_names = RSSUtils::find_article_filters($article_filters, "plugin");
779
+                $plugin_filter_actions = $pluginhost->get_filter_actions();
780 780
 
781
-				if (count($plugin_filter_names) > 0) {
782
-					Debug::log("applying plugin filter actions...", Debug::$LOG_VERBOSE);
781
+                if (count($plugin_filter_names) > 0) {
782
+                    Debug::log("applying plugin filter actions...", Debug::$LOG_VERBOSE);
783 783
 
784
-					foreach ($plugin_filter_names as $pfn) {
785
-						list($pfclass, $pfaction) = explode(":", $pfn["param"]);
784
+                    foreach ($plugin_filter_names as $pfn) {
785
+                        list($pfclass, $pfaction) = explode(":", $pfn["param"]);
786 786
 
787
-						if (isset($plugin_filter_actions[$pfclass])) {
788
-							$plugin = $pluginhost->get_plugin($pfclass);
787
+                        if (isset($plugin_filter_actions[$pfclass])) {
788
+                            $plugin = $pluginhost->get_plugin($pfclass);
789 789
 
790
-							Debug::log("... $pfclass: $pfaction", Debug::$LOG_VERBOSE);
790
+                            Debug::log("... $pfclass: $pfaction", Debug::$LOG_VERBOSE);
791 791
 
792
-							if ($plugin) {
793
-								$start = microtime(true);
794
-								$article = $plugin->hook_article_filter_action($article, $pfaction);
792
+                            if ($plugin) {
793
+                                $start = microtime(true);
794
+                                $article = $plugin->hook_article_filter_action($article, $pfaction);
795 795
 
796
-								Debug::log(sprintf("=== %.4f (sec)", microtime(true) - $start), Debug::$LOG_VERBOSE);
797
-							} else {
798
-								Debug::log("??? $pfclass: plugin object not found.", Debug::$LOG_VERBOSE);
799
-							}
800
-						} else {
801
-							Debug::log("??? $pfclass: filter plugin not registered.", Debug::$LOG_VERBOSE);
802
-						}
803
-					}
804
-				}
796
+                                Debug::log(sprintf("=== %.4f (sec)", microtime(true) - $start), Debug::$LOG_VERBOSE);
797
+                            } else {
798
+                                Debug::log("??? $pfclass: plugin object not found.", Debug::$LOG_VERBOSE);
799
+                            }
800
+                        } else {
801
+                            Debug::log("??? $pfclass: filter plugin not registered.", Debug::$LOG_VERBOSE);
802
+                        }
803
+                    }
804
+                }
805 805
 
806
-				$entry_tags = $article["tags"];
807
-				$entry_title = strip_tags($article["title"]);
808
-				$entry_author = mb_substr(strip_tags($article["author"]), 0, 245);
809
-				$entry_link = strip_tags($article["link"]);
810
-				$entry_content = $article["content"]; // escaped below
811
-				$entry_force_catchup = $article["force_catchup"];
812
-				$article_labels = $article["labels"];
813
-				$entry_score_modifier = (int) $article["score_modifier"];
814
-				$entry_language = $article["language"];
815
-				$entry_timestamp = $article["timestamp"];
816
-				$num_comments = $article["num_comments"];
806
+                $entry_tags = $article["tags"];
807
+                $entry_title = strip_tags($article["title"]);
808
+                $entry_author = mb_substr(strip_tags($article["author"]), 0, 245);
809
+                $entry_link = strip_tags($article["link"]);
810
+                $entry_content = $article["content"]; // escaped below
811
+                $entry_force_catchup = $article["force_catchup"];
812
+                $article_labels = $article["labels"];
813
+                $entry_score_modifier = (int) $article["score_modifier"];
814
+                $entry_language = $article["language"];
815
+                $entry_timestamp = $article["timestamp"];
816
+                $num_comments = $article["num_comments"];
817 817
 
818
-				if ($entry_timestamp == -1 || !$entry_timestamp || $entry_timestamp > time()) {
819
-					$entry_timestamp = time();
820
-				}
818
+                if ($entry_timestamp == -1 || !$entry_timestamp || $entry_timestamp > time()) {
819
+                    $entry_timestamp = time();
820
+                }
821 821
 
822
-				$entry_timestamp_fmt = strftime("%Y/%m/%d %H:%M:%S", $entry_timestamp);
822
+                $entry_timestamp_fmt = strftime("%Y/%m/%d %H:%M:%S", $entry_timestamp);
823 823
 
824
-				Debug::log("date $entry_timestamp [$entry_timestamp_fmt]", Debug::$LOG_VERBOSE);
825
-				Debug::log("num_comments: $num_comments", Debug::$LOG_VERBOSE);
824
+                Debug::log("date $entry_timestamp [$entry_timestamp_fmt]", Debug::$LOG_VERBOSE);
825
+                Debug::log("num_comments: $num_comments", Debug::$LOG_VERBOSE);
826 826
 
827
-				if (Debug::get_loglevel() >= Debug::$LOG_EXTENDED) {
828
-					Debug::log("article labels:", Debug::$LOG_VERBOSE);
827
+                if (Debug::get_loglevel() >= Debug::$LOG_EXTENDED) {
828
+                    Debug::log("article labels:", Debug::$LOG_VERBOSE);
829 829
 
830
-					if (count($article_labels) != 0) {
831
-						print_r($article_labels);
832
-					}
833
-				}
830
+                    if (count($article_labels) != 0) {
831
+                        print_r($article_labels);
832
+                    }
833
+                }
834 834
 
835
-				Debug::log("force catchup: $entry_force_catchup", Debug::$LOG_VERBOSE);
835
+                Debug::log("force catchup: $entry_force_catchup", Debug::$LOG_VERBOSE);
836 836
 
837
-				if ($cache_images) {
838
-									RSSUtils::cache_media($entry_content, $site_url);
839
-				}
837
+                if ($cache_images) {
838
+                                    RSSUtils::cache_media($entry_content, $site_url);
839
+                }
840 840
 
841
-				$csth = $pdo->prepare("SELECT id FROM ttrss_entries
841
+                $csth = $pdo->prepare("SELECT id FROM ttrss_entries
842 842
 					WHERE guid = ? OR guid = ?");
843
-				$csth->execute([$entry_guid, $entry_guid_hashed]);
843
+                $csth->execute([$entry_guid, $entry_guid_hashed]);
844 844
 
845
-				if (!$row = $csth->fetch()) {
845
+                if (!$row = $csth->fetch()) {
846 846
 
847
-					Debug::log("base guid [$entry_guid or $entry_guid_hashed] not found, creating...", Debug::$LOG_VERBOSE);
847
+                    Debug::log("base guid [$entry_guid or $entry_guid_hashed] not found, creating...", Debug::$LOG_VERBOSE);
848 848
 
849
-					// base post entry does not exist, create it
849
+                    // base post entry does not exist, create it
850 850
 
851
-					$usth = $pdo->prepare(
852
-						"INSERT INTO ttrss_entries
851
+                    $usth = $pdo->prepare(
852
+                        "INSERT INTO ttrss_entries
853 853
 							(title,
854 854
 							guid,
855 855
 							link,
@@ -870,112 +870,112 @@  discard block
 block discarded – undo
870 870
 							NOW(),
871 871
 							?, ?, ?, ?,	?, ?)");
872 872
 
873
-						$usth->execute([$entry_title,
874
-							$entry_guid_hashed,
875
-							$entry_link,
876
-							$entry_timestamp_fmt,
877
-							"$entry_content",
878
-							$entry_current_hash,
879
-							$date_feed_processed,
880
-							$entry_comments,
881
-							(int) $num_comments,
882
-							$entry_plugin_data,
883
-							"$entry_language",
884
-							"$entry_author"]);
873
+                        $usth->execute([$entry_title,
874
+                            $entry_guid_hashed,
875
+                            $entry_link,
876
+                            $entry_timestamp_fmt,
877
+                            "$entry_content",
878
+                            $entry_current_hash,
879
+                            $date_feed_processed,
880
+                            $entry_comments,
881
+                            (int) $num_comments,
882
+                            $entry_plugin_data,
883
+                            "$entry_language",
884
+                            "$entry_author"]);
885 885
 
886
-				}
886
+                }
887 887
 
888
-				$csth->execute([$entry_guid, $entry_guid_hashed]);
888
+                $csth->execute([$entry_guid, $entry_guid_hashed]);
889 889
 
890
-				$entry_ref_id = 0;
891
-				$entry_int_id = 0;
890
+                $entry_ref_id = 0;
891
+                $entry_int_id = 0;
892 892
 
893
-				if ($row = $csth->fetch()) {
893
+                if ($row = $csth->fetch()) {
894 894
 
895
-					Debug::log("base guid found, checking for user record", Debug::$LOG_VERBOSE);
895
+                    Debug::log("base guid found, checking for user record", Debug::$LOG_VERBOSE);
896 896
 
897
-					$ref_id = $row['id'];
898
-					$entry_ref_id = $ref_id;
897
+                    $ref_id = $row['id'];
898
+                    $entry_ref_id = $ref_id;
899 899
 
900
-					if (RSSUtils::find_article_filter($article_filters, "filter")) {
901
-						Debug::log("article is filtered out, nothing to do.", Debug::$LOG_VERBOSE);
902
-						$pdo->commit();
903
-						continue;
904
-					}
900
+                    if (RSSUtils::find_article_filter($article_filters, "filter")) {
901
+                        Debug::log("article is filtered out, nothing to do.", Debug::$LOG_VERBOSE);
902
+                        $pdo->commit();
903
+                        continue;
904
+                    }
905 905
 
906
-					$score = RSSUtils::calculate_article_score($article_filters) + $entry_score_modifier;
906
+                    $score = RSSUtils::calculate_article_score($article_filters) + $entry_score_modifier;
907 907
 
908
-					Debug::log("initial score: $score [including plugin modifier: $entry_score_modifier]", Debug::$LOG_VERBOSE);
908
+                    Debug::log("initial score: $score [including plugin modifier: $entry_score_modifier]", Debug::$LOG_VERBOSE);
909 909
 
910
-					// check for user post link to main table
910
+                    // check for user post link to main table
911 911
 
912
-					$sth = $pdo->prepare("SELECT ref_id, int_id FROM ttrss_user_entries WHERE
912
+                    $sth = $pdo->prepare("SELECT ref_id, int_id FROM ttrss_user_entries WHERE
913 913
 							ref_id = ? AND owner_uid = ?");
914
-					$sth->execute([$ref_id, $owner_uid]);
915
-
916
-					// okay it doesn't exist - create user entry
917
-					if ($row = $sth->fetch()) {
918
-						$entry_ref_id = $row["ref_id"];
919
-						$entry_int_id = $row["int_id"];
920
-
921
-						Debug::log("user record FOUND: RID: $entry_ref_id, IID: $entry_int_id", Debug::$LOG_VERBOSE);
922
-					} else {
923
-
924
-						Debug::log("user record not found, creating...", Debug::$LOG_VERBOSE);
925
-
926
-						if ($score >= -500 && !RSSUtils::find_article_filter($article_filters, 'catchup') && !$entry_force_catchup) {
927
-							$unread = 1;
928
-							$last_read_qpart = null;
929
-						} else {
930
-							$unread = 0;
931
-							$last_read_qpart = date("Y-m-d H:i"); // we can't use NOW() here because it gets quoted
932
-						}
933
-
934
-						if (RSSUtils::find_article_filter($article_filters, 'mark') || $score > 1000) {
935
-							$marked = 1;
936
-						} else {
937
-							$marked = 0;
938
-						}
939
-
940
-						if (RSSUtils::find_article_filter($article_filters, 'publish')) {
941
-							$published = 1;
942
-						} else {
943
-							$published = 0;
944
-						}
945
-
946
-						$last_marked = ($marked == 1) ? 'NOW()' : 'NULL';
947
-						$last_published = ($published == 1) ? 'NOW()' : 'NULL';
948
-
949
-						$sth = $pdo->prepare(
950
-							"INSERT INTO ttrss_user_entries
914
+                    $sth->execute([$ref_id, $owner_uid]);
915
+
916
+                    // okay it doesn't exist - create user entry
917
+                    if ($row = $sth->fetch()) {
918
+                        $entry_ref_id = $row["ref_id"];
919
+                        $entry_int_id = $row["int_id"];
920
+
921
+                        Debug::log("user record FOUND: RID: $entry_ref_id, IID: $entry_int_id", Debug::$LOG_VERBOSE);
922
+                    } else {
923
+
924
+                        Debug::log("user record not found, creating...", Debug::$LOG_VERBOSE);
925
+
926
+                        if ($score >= -500 && !RSSUtils::find_article_filter($article_filters, 'catchup') && !$entry_force_catchup) {
927
+                            $unread = 1;
928
+                            $last_read_qpart = null;
929
+                        } else {
930
+                            $unread = 0;
931
+                            $last_read_qpart = date("Y-m-d H:i"); // we can't use NOW() here because it gets quoted
932
+                        }
933
+
934
+                        if (RSSUtils::find_article_filter($article_filters, 'mark') || $score > 1000) {
935
+                            $marked = 1;
936
+                        } else {
937
+                            $marked = 0;
938
+                        }
939
+
940
+                        if (RSSUtils::find_article_filter($article_filters, 'publish')) {
941
+                            $published = 1;
942
+                        } else {
943
+                            $published = 0;
944
+                        }
945
+
946
+                        $last_marked = ($marked == 1) ? 'NOW()' : 'NULL';
947
+                        $last_published = ($published == 1) ? 'NOW()' : 'NULL';
948
+
949
+                        $sth = $pdo->prepare(
950
+                            "INSERT INTO ttrss_user_entries
951 951
 								(ref_id, owner_uid, feed_id, unread, last_read, marked,
952 952
 								published, score, tag_cache, label_cache, uuid,
953 953
 								last_marked, last_published)
954 954
 							VALUES (?, ?, ?, ?, ?, ?, ?, ?, '', '', '', ".$last_marked.", ".$last_published.")");
955 955
 
956
-						$sth->execute([$ref_id, $owner_uid, $feed, $unread, $last_read_qpart, $marked,
957
-							$published, $score]);
956
+                        $sth->execute([$ref_id, $owner_uid, $feed, $unread, $last_read_qpart, $marked,
957
+                            $published, $score]);
958 958
 
959
-						$sth = $pdo->prepare("SELECT int_id FROM ttrss_user_entries WHERE
959
+                        $sth = $pdo->prepare("SELECT int_id FROM ttrss_user_entries WHERE
960 960
 								ref_id = ? AND owner_uid = ? AND
961 961
 								feed_id = ? LIMIT 1");
962 962
 
963
-						$sth->execute([$ref_id, $owner_uid, $feed]);
963
+                        $sth->execute([$ref_id, $owner_uid, $feed]);
964 964
 
965
-						if ($row = $sth->fetch()) {
966
-													$entry_int_id = $row['int_id'];
967
-						}
968
-					}
965
+                        if ($row = $sth->fetch()) {
966
+                                                    $entry_int_id = $row['int_id'];
967
+                        }
968
+                    }
969 969
 
970
-					Debug::log("resulting RID: $entry_ref_id, IID: $entry_int_id", Debug::$LOG_VERBOSE);
970
+                    Debug::log("resulting RID: $entry_ref_id, IID: $entry_int_id", Debug::$LOG_VERBOSE);
971 971
 
972
-					if (DB_TYPE == "pgsql") {
973
-											$tsvector_qpart = "tsvector_combined = to_tsvector(:ts_lang, :ts_content),";
974
-					} else {
975
-											$tsvector_qpart = "";
976
-					}
972
+                    if (DB_TYPE == "pgsql") {
973
+                                            $tsvector_qpart = "tsvector_combined = to_tsvector(:ts_lang, :ts_content),";
974
+                    } else {
975
+                                            $tsvector_qpart = "";
976
+                    }
977 977
 
978
-					$sth = $pdo->prepare("UPDATE ttrss_entries
978
+                    $sth = $pdo->prepare("UPDATE ttrss_entries
979 979
 						SET title = :title,
980 980
 							$tsvector_qpart
981 981
 							content = :content,
@@ -988,642 +988,642 @@  discard block
 block discarded – undo
988 988
 							lang = :lang
989 989
 						WHERE id = :id");
990 990
 
991
-					$params = [":title" => $entry_title,
992
-						":content" => "$entry_content",
993
-						":content_hash" => $entry_current_hash,
994
-						":updated" => $entry_timestamp_fmt,
995
-						":num_comments" => (int) $num_comments,
996
-						":plugin_data" => $entry_plugin_data,
997
-						":author" => "$entry_author",
998
-						":lang" => $entry_language,
999
-						":id" => $ref_id];
1000
-
1001
-					if (DB_TYPE == "pgsql") {
1002
-						$params[":ts_lang"] = $feed_language;
1003
-						$params[":ts_content"] = mb_substr(strip_tags($entry_title." ".$entry_content), 0, 900000);
1004
-					}
1005
-
1006
-					$sth->execute($params);
1007
-
1008
-					// update aux data
1009
-					$sth = $pdo->prepare("UPDATE ttrss_user_entries
991
+                    $params = [":title" => $entry_title,
992
+                        ":content" => "$entry_content",
993
+                        ":content_hash" => $entry_current_hash,
994
+                        ":updated" => $entry_timestamp_fmt,
995
+                        ":num_comments" => (int) $num_comments,
996
+                        ":plugin_data" => $entry_plugin_data,
997
+                        ":author" => "$entry_author",
998
+                        ":lang" => $entry_language,
999
+                        ":id" => $ref_id];
1000
+
1001
+                    if (DB_TYPE == "pgsql") {
1002
+                        $params[":ts_lang"] = $feed_language;
1003
+                        $params[":ts_content"] = mb_substr(strip_tags($entry_title." ".$entry_content), 0, 900000);
1004
+                    }
1005
+
1006
+                    $sth->execute($params);
1007
+
1008
+                    // update aux data
1009
+                    $sth = $pdo->prepare("UPDATE ttrss_user_entries
1010 1010
 							SET score = ? WHERE ref_id = ?");
1011
-					$sth->execute([$score, $ref_id]);
1011
+                    $sth->execute([$score, $ref_id]);
1012 1012
 
1013
-					if ($mark_unread_on_update &&
1014
-						!$entry_force_catchup &&
1015
-						!RSSUtils::find_article_filter($article_filters, 'catchup')) {
1013
+                    if ($mark_unread_on_update &&
1014
+                        !$entry_force_catchup &&
1015
+                        !RSSUtils::find_article_filter($article_filters, 'catchup')) {
1016 1016
 
1017
-						Debug::log("article updated, marking unread as requested.", Debug::$LOG_VERBOSE);
1017
+                        Debug::log("article updated, marking unread as requested.", Debug::$LOG_VERBOSE);
1018 1018
 
1019
-						$sth = $pdo->prepare("UPDATE ttrss_user_entries
1019
+                        $sth = $pdo->prepare("UPDATE ttrss_user_entries
1020 1020
 							SET last_read = null, unread = true WHERE ref_id = ?");
1021
-						$sth->execute([$ref_id]);
1022
-					} else {
1023
-						Debug::log("article updated, but we're forbidden to mark it unread.", Debug::$LOG_VERBOSE);
1024
-					}
1025
-				}
1021
+                        $sth->execute([$ref_id]);
1022
+                    } else {
1023
+                        Debug::log("article updated, but we're forbidden to mark it unread.", Debug::$LOG_VERBOSE);
1024
+                    }
1025
+                }
1026 1026
 
1027
-				Debug::log("assigning labels [other]...", Debug::$LOG_VERBOSE);
1027
+                Debug::log("assigning labels [other]...", Debug::$LOG_VERBOSE);
1028 1028
 
1029
-				foreach ($article_labels as $label) {
1030
-					Labels::add_article($entry_ref_id, $label[1], $owner_uid);
1031
-				}
1029
+                foreach ($article_labels as $label) {
1030
+                    Labels::add_article($entry_ref_id, $label[1], $owner_uid);
1031
+                }
1032 1032
 
1033
-				Debug::log("assigning labels [filters]...", Debug::$LOG_VERBOSE);
1033
+                Debug::log("assigning labels [filters]...", Debug::$LOG_VERBOSE);
1034 1034
 
1035
-				RSSUtils::assign_article_to_label_filters($entry_ref_id, $article_filters,
1036
-					$owner_uid, $article_labels);
1035
+                RSSUtils::assign_article_to_label_filters($entry_ref_id, $article_filters,
1036
+                    $owner_uid, $article_labels);
1037 1037
 
1038
-				Debug::log("looking for enclosures...", Debug::$LOG_VERBOSE);
1038
+                Debug::log("looking for enclosures...", Debug::$LOG_VERBOSE);
1039 1039
 
1040
-				// enclosures
1040
+                // enclosures
1041 1041
 
1042
-				$enclosures = array();
1042
+                $enclosures = array();
1043 1043
 
1044
-				$encs = $item->get_enclosures();
1044
+                $encs = $item->get_enclosures();
1045 1045
 
1046
-				if (is_array($encs)) {
1047
-					foreach ($encs as $e) {
1048
-						$e_item = array(
1049
-							rewrite_relative_url($site_url, $e->link),
1050
-							$e->type, $e->length, $e->title, $e->width, $e->height);
1046
+                if (is_array($encs)) {
1047
+                    foreach ($encs as $e) {
1048
+                        $e_item = array(
1049
+                            rewrite_relative_url($site_url, $e->link),
1050
+                            $e->type, $e->length, $e->title, $e->width, $e->height);
1051 1051
 
1052
-						// Yet another episode of "mysql utf8_general_ci is gimped"
1053
-						if (DB_TYPE == "mysql" && MYSQL_CHARSET != "UTF8MB4") {
1054
-							for ($i = 0; $i < count($e_item); $i++) {
1055
-								if (is_string($e_item[$i])) {
1056
-									$e_item[$i] = RSSUtils::strip_utf8mb4($e_item[$i]);
1057
-								}
1058
-							}
1059
-						}
1052
+                        // Yet another episode of "mysql utf8_general_ci is gimped"
1053
+                        if (DB_TYPE == "mysql" && MYSQL_CHARSET != "UTF8MB4") {
1054
+                            for ($i = 0; $i < count($e_item); $i++) {
1055
+                                if (is_string($e_item[$i])) {
1056
+                                    $e_item[$i] = RSSUtils::strip_utf8mb4($e_item[$i]);
1057
+                                }
1058
+                            }
1059
+                        }
1060 1060
 
1061
-						array_push($enclosures, $e_item);
1062
-					}
1063
-				}
1061
+                        array_push($enclosures, $e_item);
1062
+                    }
1063
+                }
1064 1064
 
1065
-				if ($cache_images) {
1066
-									RSSUtils::cache_enclosures($enclosures, $site_url);
1067
-				}
1065
+                if ($cache_images) {
1066
+                                    RSSUtils::cache_enclosures($enclosures, $site_url);
1067
+                }
1068 1068
 
1069
-				if (Debug::get_loglevel() >= Debug::$LOG_EXTENDED) {
1070
-					Debug::log("article enclosures:", Debug::$LOG_VERBOSE);
1071
-					print_r($enclosures);
1072
-				}
1069
+                if (Debug::get_loglevel() >= Debug::$LOG_EXTENDED) {
1070
+                    Debug::log("article enclosures:", Debug::$LOG_VERBOSE);
1071
+                    print_r($enclosures);
1072
+                }
1073 1073
 
1074
-				$esth = $pdo->prepare("SELECT id FROM ttrss_enclosures
1074
+                $esth = $pdo->prepare("SELECT id FROM ttrss_enclosures
1075 1075
 						WHERE content_url = ? AND content_type = ? AND post_id = ?");
1076 1076
 
1077
-				$usth = $pdo->prepare("INSERT INTO ttrss_enclosures
1077
+                $usth = $pdo->prepare("INSERT INTO ttrss_enclosures
1078 1078
 							(content_url, content_type, title, duration, post_id, width, height) VALUES
1079 1079
 							(?, ?, ?, ?, ?, ?, ?)");
1080 1080
 
1081
-				foreach ($enclosures as $enc) {
1082
-					$enc_url = $enc[0];
1083
-					$enc_type = $enc[1];
1084
-					$enc_dur = (int) $enc[2];
1085
-					$enc_title = $enc[3];
1086
-					$enc_width = intval($enc[4]);
1087
-					$enc_height = intval($enc[5]);
1081
+                foreach ($enclosures as $enc) {
1082
+                    $enc_url = $enc[0];
1083
+                    $enc_type = $enc[1];
1084
+                    $enc_dur = (int) $enc[2];
1085
+                    $enc_title = $enc[3];
1086
+                    $enc_width = intval($enc[4]);
1087
+                    $enc_height = intval($enc[5]);
1088 1088
 
1089
-					$esth->execute([$enc_url, $enc_type, $entry_ref_id]);
1089
+                    $esth->execute([$enc_url, $enc_type, $entry_ref_id]);
1090 1090
 
1091
-					if (!$esth->fetch()) {
1092
-						$usth->execute([$enc_url, $enc_type, (string) $enc_title, $enc_dur, $entry_ref_id, $enc_width, $enc_height]);
1093
-					}
1094
-				}
1091
+                    if (!$esth->fetch()) {
1092
+                        $usth->execute([$enc_url, $enc_type, (string) $enc_title, $enc_dur, $entry_ref_id, $enc_width, $enc_height]);
1093
+                    }
1094
+                }
1095 1095
 
1096
-				// check for manual tags (we have to do it here since they're loaded from filters)
1096
+                // check for manual tags (we have to do it here since they're loaded from filters)
1097 1097
 
1098
-				foreach ($article_filters as $f) {
1099
-					if ($f["type"] == "tag") {
1098
+                foreach ($article_filters as $f) {
1099
+                    if ($f["type"] == "tag") {
1100 1100
 
1101
-						$manual_tags = trim_array(explode(",", $f["param"]));
1101
+                        $manual_tags = trim_array(explode(",", $f["param"]));
1102 1102
 
1103
-						foreach ($manual_tags as $tag) {
1104
-							array_push($entry_tags, $tag);
1105
-						}
1106
-					}
1107
-				}
1103
+                        foreach ($manual_tags as $tag) {
1104
+                            array_push($entry_tags, $tag);
1105
+                        }
1106
+                    }
1107
+                }
1108 1108
 
1109
-				// Skip boring tags
1109
+                // Skip boring tags
1110 1110
 
1111
-				$boring_tags = trim_array(explode(",", mb_strtolower(get_pref(
1112
-					'BLACKLISTED_TAGS', $owner_uid, ''), 'utf-8')));
1111
+                $boring_tags = trim_array(explode(",", mb_strtolower(get_pref(
1112
+                    'BLACKLISTED_TAGS', $owner_uid, ''), 'utf-8')));
1113 1113
 
1114
-				$filtered_tags = array();
1115
-				$tags_to_cache = array();
1114
+                $filtered_tags = array();
1115
+                $tags_to_cache = array();
1116 1116
 
1117
-				foreach ($entry_tags as $tag) {
1118
-					if (array_search($tag, $boring_tags) === false) {
1119
-						array_push($filtered_tags, $tag);
1120
-					}
1121
-				}
1117
+                foreach ($entry_tags as $tag) {
1118
+                    if (array_search($tag, $boring_tags) === false) {
1119
+                        array_push($filtered_tags, $tag);
1120
+                    }
1121
+                }
1122 1122
 
1123
-				$filtered_tags = array_unique($filtered_tags);
1123
+                $filtered_tags = array_unique($filtered_tags);
1124 1124
 
1125
-				if (Debug::get_loglevel() >= Debug::$LOG_VERBOSE) {
1126
-					Debug::log("filtered tags: ".implode(", ", $filtered_tags), Debug::$LOG_VERBOSE);
1125
+                if (Debug::get_loglevel() >= Debug::$LOG_VERBOSE) {
1126
+                    Debug::log("filtered tags: ".implode(", ", $filtered_tags), Debug::$LOG_VERBOSE);
1127 1127
 
1128
-				}
1128
+                }
1129 1129
 
1130
-				// Save article tags in the database
1130
+                // Save article tags in the database
1131 1131
 
1132
-				if (count($filtered_tags) > 0) {
1132
+                if (count($filtered_tags) > 0) {
1133 1133
 
1134
-					$tsth = $pdo->prepare("SELECT id FROM ttrss_tags
1134
+                    $tsth = $pdo->prepare("SELECT id FROM ttrss_tags
1135 1135
 							WHERE tag_name = ? AND post_int_id = ? AND
1136 1136
 							owner_uid = ? LIMIT 1");
1137 1137
 
1138
-					$usth = $pdo->prepare("INSERT INTO ttrss_tags
1138
+                    $usth = $pdo->prepare("INSERT INTO ttrss_tags
1139 1139
 									(owner_uid,tag_name,post_int_id)
1140 1140
 									VALUES (?, ?, ?)");
1141 1141
 
1142
-					$filtered_tags = FeedItem_Common::normalize_categories($filtered_tags);
1142
+                    $filtered_tags = FeedItem_Common::normalize_categories($filtered_tags);
1143 1143
 
1144
-					foreach ($filtered_tags as $tag) {
1145
-						$tsth->execute([$tag, $entry_int_id, $owner_uid]);
1144
+                    foreach ($filtered_tags as $tag) {
1145
+                        $tsth->execute([$tag, $entry_int_id, $owner_uid]);
1146 1146
 
1147
-						if (!$tsth->fetch()) {
1148
-							$usth->execute([$owner_uid, $tag, $entry_int_id]);
1149
-						}
1147
+                        if (!$tsth->fetch()) {
1148
+                            $usth->execute([$owner_uid, $tag, $entry_int_id]);
1149
+                        }
1150 1150
 
1151
-						array_push($tags_to_cache, $tag);
1152
-					}
1151
+                        array_push($tags_to_cache, $tag);
1152
+                    }
1153 1153
 
1154
-					/* update the cache */
1155
-					$tags_str = join(",", $tags_to_cache);
1154
+                    /* update the cache */
1155
+                    $tags_str = join(",", $tags_to_cache);
1156 1156
 
1157
-					$tsth = $pdo->prepare("UPDATE ttrss_user_entries
1157
+                    $tsth = $pdo->prepare("UPDATE ttrss_user_entries
1158 1158
 						SET tag_cache = ? WHERE ref_id = ?
1159 1159
 						AND owner_uid = ?");
1160
-					$tsth->execute([$tags_str, $entry_ref_id, $owner_uid]);
1161
-				}
1160
+                    $tsth->execute([$tags_str, $entry_ref_id, $owner_uid]);
1161
+                }
1162 1162
 
1163
-				Debug::log("article processed", Debug::$LOG_VERBOSE);
1163
+                Debug::log("article processed", Debug::$LOG_VERBOSE);
1164 1164
 
1165
-				$pdo->commit();
1166
-			}
1165
+                $pdo->commit();
1166
+            }
1167 1167
 
1168
-			Debug::log("purging feed...", Debug::$LOG_VERBOSE);
1168
+            Debug::log("purging feed...", Debug::$LOG_VERBOSE);
1169 1169
 
1170
-			Feeds::purge_feed($feed, 0);
1170
+            Feeds::purge_feed($feed, 0);
1171 1171
 
1172
-			$sth = $pdo->prepare("UPDATE ttrss_feeds
1172
+            $sth = $pdo->prepare("UPDATE ttrss_feeds
1173 1173
 				SET last_updated = NOW(), last_unconditional = NOW(), last_error = '' WHERE id = ?");
1174
-			$sth->execute([$feed]);
1174
+            $sth->execute([$feed]);
1175 1175
 
1176
-		} else {
1176
+        } else {
1177 1177
 
1178
-			$error_msg = mb_substr($rss->error(), 0, 245);
1178
+            $error_msg = mb_substr($rss->error(), 0, 245);
1179 1179
 
1180
-			Debug::log("fetch error: $error_msg", Debug::$LOG_VERBOSE);
1180
+            Debug::log("fetch error: $error_msg", Debug::$LOG_VERBOSE);
1181 1181
 
1182
-			if (count($rss->errors()) > 1) {
1183
-				foreach ($rss->errors() as $error) {
1184
-					Debug::log("+ $error", Debug::$LOG_VERBOSE);
1185
-				}
1186
-			}
1182
+            if (count($rss->errors()) > 1) {
1183
+                foreach ($rss->errors() as $error) {
1184
+                    Debug::log("+ $error", Debug::$LOG_VERBOSE);
1185
+                }
1186
+            }
1187 1187
 
1188
-			$sth = $pdo->prepare("UPDATE ttrss_feeds SET last_error = ?,
1188
+            $sth = $pdo->prepare("UPDATE ttrss_feeds SET last_error = ?,
1189 1189
 				last_updated = NOW(), last_unconditional = NOW() WHERE id = ?");
1190
-			$sth->execute([$error_msg, $feed]);
1190
+            $sth->execute([$error_msg, $feed]);
1191 1191
 
1192
-			unset($rss);
1192
+            unset($rss);
1193 1193
 
1194
-			Debug::log("update failed.", Debug::$LOG_VERBOSE);
1195
-			return false;
1196
-		}
1194
+            Debug::log("update failed.", Debug::$LOG_VERBOSE);
1195
+            return false;
1196
+        }
1197 1197
 
1198
-		Debug::log("update done.", Debug::$LOG_VERBOSE);
1198
+        Debug::log("update done.", Debug::$LOG_VERBOSE);
1199 1199
 
1200
-		return true;
1201
-	}
1200
+        return true;
1201
+    }
1202 1202
 
1203
-	public static function cache_enclosures($enclosures, $site_url) {
1204
-		$cache = new DiskCache("images");
1203
+    public static function cache_enclosures($enclosures, $site_url) {
1204
+        $cache = new DiskCache("images");
1205 1205
 
1206
-		if ($cache->isWritable()) {
1207
-			foreach ($enclosures as $enc) {
1206
+        if ($cache->isWritable()) {
1207
+            foreach ($enclosures as $enc) {
1208 1208
 
1209
-				if (preg_match("/(image|audio|video)/", $enc[1])) {
1210
-					$src = rewrite_relative_url($site_url, $enc[0]);
1209
+                if (preg_match("/(image|audio|video)/", $enc[1])) {
1210
+                    $src = rewrite_relative_url($site_url, $enc[0]);
1211 1211
 
1212
-					$local_filename = sha1($src);
1212
+                    $local_filename = sha1($src);
1213 1213
 
1214
-					Debug::log("cache_enclosures: downloading: $src to $local_filename", Debug::$LOG_VERBOSE);
1214
+                    Debug::log("cache_enclosures: downloading: $src to $local_filename", Debug::$LOG_VERBOSE);
1215 1215
 
1216
-					if (!$cache->exists($local_filename)) {
1216
+                    if (!$cache->exists($local_filename)) {
1217 1217
 
1218
-						global $fetch_last_error_code;
1219
-						global $fetch_last_error;
1218
+                        global $fetch_last_error_code;
1219
+                        global $fetch_last_error;
1220 1220
 
1221
-						$file_content = fetch_file_contents(array("url" => $src,
1222
-							"http_referrer" => $src,
1223
-							"max_size" => MAX_CACHE_FILE_SIZE));
1221
+                        $file_content = fetch_file_contents(array("url" => $src,
1222
+                            "http_referrer" => $src,
1223
+                            "max_size" => MAX_CACHE_FILE_SIZE));
1224 1224
 
1225
-						if ($file_content) {
1226
-							$cache->put($local_filename, $file_content);
1227
-						} else {
1228
-							Debug::log("cache_enclosures: failed with $fetch_last_error_code: $fetch_last_error");
1229
-						}
1230
-					} else if (is_writable($local_filename)) {
1231
-						$cache->touch($local_filename);
1232
-					}
1233
-				}
1234
-			}
1235
-		}
1236
-	}
1225
+                        if ($file_content) {
1226
+                            $cache->put($local_filename, $file_content);
1227
+                        } else {
1228
+                            Debug::log("cache_enclosures: failed with $fetch_last_error_code: $fetch_last_error");
1229
+                        }
1230
+                    } else if (is_writable($local_filename)) {
1231
+                        $cache->touch($local_filename);
1232
+                    }
1233
+                }
1234
+            }
1235
+        }
1236
+    }
1237 1237
 
1238
-	public static function cache_media($html, $site_url) {
1239
-		$cache = new DiskCache("images");
1238
+    public static function cache_media($html, $site_url) {
1239
+        $cache = new DiskCache("images");
1240 1240
 
1241
-		if ($cache->isWritable()) {
1242
-			$doc = new DOMDocument();
1243
-			if ($doc->loadHTML($html)) {
1244
-				$xpath = new DOMXPath($doc);
1241
+        if ($cache->isWritable()) {
1242
+            $doc = new DOMDocument();
1243
+            if ($doc->loadHTML($html)) {
1244
+                $xpath = new DOMXPath($doc);
1245 1245
 
1246
-				$entries = $xpath->query('(//img[@src])|(//video/source[@src])|(//audio/source[@src])');
1246
+                $entries = $xpath->query('(//img[@src])|(//video/source[@src])|(//audio/source[@src])');
1247 1247
 
1248
-				foreach ($entries as $entry) {
1249
-					if ($entry->hasAttribute('src') && strpos($entry->getAttribute('src'), "data:") !== 0) {
1250
-						$src = rewrite_relative_url($site_url, $entry->getAttribute('src'));
1248
+                foreach ($entries as $entry) {
1249
+                    if ($entry->hasAttribute('src') && strpos($entry->getAttribute('src'), "data:") !== 0) {
1250
+                        $src = rewrite_relative_url($site_url, $entry->getAttribute('src'));
1251 1251
 
1252
-						$local_filename = sha1($src);
1252
+                        $local_filename = sha1($src);
1253 1253
 
1254
-						Debug::log("cache_media: checking $src", Debug::$LOG_VERBOSE);
1254
+                        Debug::log("cache_media: checking $src", Debug::$LOG_VERBOSE);
1255 1255
 
1256
-						if (!$cache->exists($local_filename)) {
1257
-							Debug::log("cache_media: downloading: $src to $local_filename", Debug::$LOG_VERBOSE);
1256
+                        if (!$cache->exists($local_filename)) {
1257
+                            Debug::log("cache_media: downloading: $src to $local_filename", Debug::$LOG_VERBOSE);
1258 1258
 
1259
-							global $fetch_last_error_code;
1260
-							global $fetch_last_error;
1259
+                            global $fetch_last_error_code;
1260
+                            global $fetch_last_error;
1261 1261
 
1262
-							$file_content = fetch_file_contents(array("url" => $src,
1263
-								"http_referrer" => $src,
1264
-								"max_size" => MAX_CACHE_FILE_SIZE));
1262
+                            $file_content = fetch_file_contents(array("url" => $src,
1263
+                                "http_referrer" => $src,
1264
+                                "max_size" => MAX_CACHE_FILE_SIZE));
1265 1265
 
1266
-							if ($file_content) {
1267
-								$cache->put($local_filename, $file_content);
1268
-							} else {
1269
-								Debug::log("cache_media: failed with $fetch_last_error_code: $fetch_last_error");
1270
-							}
1271
-						} else if ($cache->isWritable($local_filename)) {
1272
-							$cache->touch($local_filename);
1273
-						}
1274
-					}
1275
-				}
1276
-			}
1277
-		}
1278
-	}
1266
+                            if ($file_content) {
1267
+                                $cache->put($local_filename, $file_content);
1268
+                            } else {
1269
+                                Debug::log("cache_media: failed with $fetch_last_error_code: $fetch_last_error");
1270
+                            }
1271
+                        } else if ($cache->isWritable($local_filename)) {
1272
+                            $cache->touch($local_filename);
1273
+                        }
1274
+                    }
1275
+                }
1276
+            }
1277
+        }
1278
+    }
1279 1279
 
1280
-	public static function expire_error_log() {
1281
-		Debug::log("Removing old error log entries...");
1280
+    public static function expire_error_log() {
1281
+        Debug::log("Removing old error log entries...");
1282 1282
 
1283
-		$pdo = Db::pdo();
1283
+        $pdo = Db::pdo();
1284 1284
 
1285
-		if (DB_TYPE == "pgsql") {
1286
-			$pdo->query("DELETE FROM ttrss_error_log
1285
+        if (DB_TYPE == "pgsql") {
1286
+            $pdo->query("DELETE FROM ttrss_error_log
1287 1287
 				WHERE created_at < NOW() - INTERVAL '7 days'");
1288
-		} else {
1289
-			$pdo->query("DELETE FROM ttrss_error_log
1288
+        } else {
1289
+            $pdo->query("DELETE FROM ttrss_error_log
1290 1290
 				WHERE created_at < DATE_SUB(NOW(), INTERVAL 7 DAY)");
1291
-		}
1292
-	}
1291
+        }
1292
+    }
1293 1293
 
1294
-	public static function expire_feed_archive() {
1295
-		Debug::log("Removing old archived feeds...");
1294
+    public static function expire_feed_archive() {
1295
+        Debug::log("Removing old archived feeds...");
1296 1296
 
1297
-		$pdo = Db::pdo();
1297
+        $pdo = Db::pdo();
1298 1298
 
1299
-		if (DB_TYPE == "pgsql") {
1300
-			$pdo->query("DELETE FROM ttrss_archived_feeds
1299
+        if (DB_TYPE == "pgsql") {
1300
+            $pdo->query("DELETE FROM ttrss_archived_feeds
1301 1301
 				WHERE created < NOW() - INTERVAL '1 month'");
1302
-		} else {
1303
-			$pdo->query("DELETE FROM ttrss_archived_feeds
1302
+        } else {
1303
+            $pdo->query("DELETE FROM ttrss_archived_feeds
1304 1304
 				WHERE created < DATE_SUB(NOW(), INTERVAL 1 MONTH)");
1305
-		}
1306
-	}
1307
-
1308
-	public static function expire_lock_files() {
1309
-		Debug::log("Removing old lock files...", Debug::$LOG_VERBOSE);
1310
-
1311
-		$num_deleted = 0;
1312
-
1313
-		if (is_writable(LOCK_DIRECTORY)) {
1314
-			$files = glob(LOCK_DIRECTORY."/*.lock");
1315
-
1316
-			if ($files) {
1317
-				foreach ($files as $file) {
1318
-					if (!file_is_locked(basename($file)) && time() - filemtime($file) > 86400 * 2) {
1319
-						unlink($file);
1320
-						++$num_deleted;
1321
-					}
1322
-				}
1323
-			}
1324
-		}
1325
-
1326
-		Debug::log("removed $num_deleted old lock files.");
1327
-	}
1328
-
1329
-	/**
1330
-	 * Source: http://www.php.net/manual/en/function.parse-url.php#104527
1331
-	 * Returns the url query as associative array
1332
-	 *
1333
-	 * @param    string    query
1334
-	 * @return    array    params
1335
-	 */
1336
-	public static function convertUrlQuery($query) {
1337
-		$queryParts = explode('&', $query);
1338
-
1339
-		$params = array();
1340
-
1341
-		foreach ($queryParts as $param) {
1342
-			$item = explode('=', $param);
1343
-			$params[$item[0]] = $item[1];
1344
-		}
1345
-
1346
-		return $params;
1347
-	}
1348
-
1349
-	public static function get_article_filters($filters, $title, $content, $link, $author, $tags, &$matched_rules = false, &$matched_filters = false) {
1350
-		$matches = array();
1351
-
1352
-		foreach ($filters as $filter) {
1353
-			$match_any_rule = $filter["match_any_rule"];
1354
-			$inverse = $filter["inverse"];
1355
-			$filter_match = false;
1356
-
1357
-			foreach ($filter["rules"] as $rule) {
1358
-				$match = false;
1359
-				$reg_exp = str_replace('/', '\/', $rule["reg_exp"]);
1360
-				$rule_inverse = $rule["inverse"];
1361
-
1362
-				if (!$reg_exp) {
1363
-									continue;
1364
-				}
1365
-
1366
-				switch ($rule["type"]) {
1367
-					case "title":
1368
-						$match = @preg_match("/$reg_exp/iu", $title);
1369
-						break;
1370
-					case "content":
1371
-						// we don't need to deal with multiline regexps
1372
-						$content = preg_replace("/[\r\n\t]/", "", $content);
1373
-
1374
-						$match = @preg_match("/$reg_exp/iu", $content);
1375
-						break;
1376
-					case "both":
1377
-						// we don't need to deal with multiline regexps
1378
-						$content = preg_replace("/[\r\n\t]/", "", $content);
1379
-
1380
-						$match = (@preg_match("/$reg_exp/iu", $title) || @preg_match("/$reg_exp/iu", $content));
1381
-						break;
1382
-					case "link":
1383
-						$match = @preg_match("/$reg_exp/iu", $link);
1384
-						break;
1385
-					case "author":
1386
-						$match = @preg_match("/$reg_exp/iu", $author);
1387
-						break;
1388
-					case "tag":
1389
-						foreach ($tags as $tag) {
1390
-							if (@preg_match("/$reg_exp/iu", $tag)) {
1391
-								$match = true;
1392
-								break;
1393
-							}
1394
-						}
1395
-						break;
1396
-				}
1397
-
1398
-				if ($rule_inverse) {
1399
-				    $match = !$match;
1400
-				}
1401
-
1402
-				if ($match_any_rule) {
1403
-					if ($match) {
1404
-						$filter_match = true;
1405
-						break;
1406
-					}
1407
-				} else {
1408
-					$filter_match = $match;
1409
-					if (!$match) {
1410
-						break;
1411
-					}
1412
-				}
1413
-			}
1414
-
1415
-			if ($inverse) {
1416
-			    $filter_match = !$filter_match;
1417
-			}
1418
-
1419
-			if ($filter_match) {
1420
-				if (is_array($matched_rules)) {
1421
-				    array_push($matched_rules, $rule);
1422
-				}
1423
-				if (is_array($matched_filters)) {
1424
-				    array_push($matched_filters, $filter);
1425
-				}
1426
-
1427
-				foreach ($filter["actions"] as $action) {
1428
-					array_push($matches, $action);
1429
-
1430
-					// if Stop action encountered, perform no further processing
1431
-					if (isset($action["type"]) && $action["type"] == "stop") {
1432
-					    return $matches;
1433
-					}
1434
-				}
1435
-			}
1436
-		}
1437
-
1438
-		return $matches;
1439
-	}
1440
-
1441
-	public static function find_article_filter($filters, $filter_name) {
1442
-		foreach ($filters as $f) {
1443
-			if ($f["type"] == $filter_name) {
1444
-				return $f;
1445
-			};
1446
-		}
1447
-		return false;
1448
-	}
1449
-
1450
-	public static function find_article_filters($filters, $filter_name) {
1451
-		$results = array();
1452
-
1453
-		foreach ($filters as $f) {
1454
-			if ($f["type"] == $filter_name) {
1455
-				array_push($results, $f);
1456
-			};
1457
-		}
1458
-		return $results;
1459
-	}
1460
-
1461
-	public static function calculate_article_score($filters) {
1462
-		$score = 0;
1463
-
1464
-		foreach ($filters as $f) {
1465
-			if ($f["type"] == "score") {
1466
-				$score += $f["param"];
1467
-			};
1468
-		}
1469
-		return $score;
1470
-	}
1471
-
1472
-	public static function labels_contains_caption($labels, $caption) {
1473
-		foreach ($labels as $label) {
1474
-			if ($label[1] == $caption) {
1475
-				return true;
1476
-			}
1477
-		}
1478
-
1479
-		return false;
1480
-	}
1481
-
1482
-	public static function assign_article_to_label_filters($id, $filters, $owner_uid, $article_labels) {
1483
-		foreach ($filters as $f) {
1484
-			if ($f["type"] == "label") {
1485
-				if (!RSSUtils::labels_contains_caption($article_labels, $f["param"])) {
1486
-					Labels::add_article($id, $f["param"], $owner_uid);
1487
-				}
1488
-			}
1489
-		}
1490
-	}
1491
-
1492
-	public static function make_guid_from_title($title) {
1493
-		return preg_replace("/[ \"\',.:;]/", "-",
1494
-			mb_strtolower(strip_tags($title), 'utf-8'));
1495
-	}
1496
-
1497
-	public static function cleanup_counters_cache() {
1498
-		$pdo = Db::pdo();
1499
-
1500
-		$res = $pdo->query("DELETE FROM ttrss_counters_cache
1305
+        }
1306
+    }
1307
+
1308
+    public static function expire_lock_files() {
1309
+        Debug::log("Removing old lock files...", Debug::$LOG_VERBOSE);
1310
+
1311
+        $num_deleted = 0;
1312
+
1313
+        if (is_writable(LOCK_DIRECTORY)) {
1314
+            $files = glob(LOCK_DIRECTORY."/*.lock");
1315
+
1316
+            if ($files) {
1317
+                foreach ($files as $file) {
1318
+                    if (!file_is_locked(basename($file)) && time() - filemtime($file) > 86400 * 2) {
1319
+                        unlink($file);
1320
+                        ++$num_deleted;
1321
+                    }
1322
+                }
1323
+            }
1324
+        }
1325
+
1326
+        Debug::log("removed $num_deleted old lock files.");
1327
+    }
1328
+
1329
+    /**
1330
+     * Source: http://www.php.net/manual/en/function.parse-url.php#104527
1331
+     * Returns the url query as associative array
1332
+     *
1333
+     * @param    string    query
1334
+     * @return    array    params
1335
+     */
1336
+    public static function convertUrlQuery($query) {
1337
+        $queryParts = explode('&', $query);
1338
+
1339
+        $params = array();
1340
+
1341
+        foreach ($queryParts as $param) {
1342
+            $item = explode('=', $param);
1343
+            $params[$item[0]] = $item[1];
1344
+        }
1345
+
1346
+        return $params;
1347
+    }
1348
+
1349
+    public static function get_article_filters($filters, $title, $content, $link, $author, $tags, &$matched_rules = false, &$matched_filters = false) {
1350
+        $matches = array();
1351
+
1352
+        foreach ($filters as $filter) {
1353
+            $match_any_rule = $filter["match_any_rule"];
1354
+            $inverse = $filter["inverse"];
1355
+            $filter_match = false;
1356
+
1357
+            foreach ($filter["rules"] as $rule) {
1358
+                $match = false;
1359
+                $reg_exp = str_replace('/', '\/', $rule["reg_exp"]);
1360
+                $rule_inverse = $rule["inverse"];
1361
+
1362
+                if (!$reg_exp) {
1363
+                                    continue;
1364
+                }
1365
+
1366
+                switch ($rule["type"]) {
1367
+                    case "title":
1368
+                        $match = @preg_match("/$reg_exp/iu", $title);
1369
+                        break;
1370
+                    case "content":
1371
+                        // we don't need to deal with multiline regexps
1372
+                        $content = preg_replace("/[\r\n\t]/", "", $content);
1373
+
1374
+                        $match = @preg_match("/$reg_exp/iu", $content);
1375
+                        break;
1376
+                    case "both":
1377
+                        // we don't need to deal with multiline regexps
1378
+                        $content = preg_replace("/[\r\n\t]/", "", $content);
1379
+
1380
+                        $match = (@preg_match("/$reg_exp/iu", $title) || @preg_match("/$reg_exp/iu", $content));
1381
+                        break;
1382
+                    case "link":
1383
+                        $match = @preg_match("/$reg_exp/iu", $link);
1384
+                        break;
1385
+                    case "author":
1386
+                        $match = @preg_match("/$reg_exp/iu", $author);
1387
+                        break;
1388
+                    case "tag":
1389
+                        foreach ($tags as $tag) {
1390
+                            if (@preg_match("/$reg_exp/iu", $tag)) {
1391
+                                $match = true;
1392
+                                break;
1393
+                            }
1394
+                        }
1395
+                        break;
1396
+                }
1397
+
1398
+                if ($rule_inverse) {
1399
+                    $match = !$match;
1400
+                }
1401
+
1402
+                if ($match_any_rule) {
1403
+                    if ($match) {
1404
+                        $filter_match = true;
1405
+                        break;
1406
+                    }
1407
+                } else {
1408
+                    $filter_match = $match;
1409
+                    if (!$match) {
1410
+                        break;
1411
+                    }
1412
+                }
1413
+            }
1414
+
1415
+            if ($inverse) {
1416
+                $filter_match = !$filter_match;
1417
+            }
1418
+
1419
+            if ($filter_match) {
1420
+                if (is_array($matched_rules)) {
1421
+                    array_push($matched_rules, $rule);
1422
+                }
1423
+                if (is_array($matched_filters)) {
1424
+                    array_push($matched_filters, $filter);
1425
+                }
1426
+
1427
+                foreach ($filter["actions"] as $action) {
1428
+                    array_push($matches, $action);
1429
+
1430
+                    // if Stop action encountered, perform no further processing
1431
+                    if (isset($action["type"]) && $action["type"] == "stop") {
1432
+                        return $matches;
1433
+                    }
1434
+                }
1435
+            }
1436
+        }
1437
+
1438
+        return $matches;
1439
+    }
1440
+
1441
+    public static function find_article_filter($filters, $filter_name) {
1442
+        foreach ($filters as $f) {
1443
+            if ($f["type"] == $filter_name) {
1444
+                return $f;
1445
+            };
1446
+        }
1447
+        return false;
1448
+    }
1449
+
1450
+    public static function find_article_filters($filters, $filter_name) {
1451
+        $results = array();
1452
+
1453
+        foreach ($filters as $f) {
1454
+            if ($f["type"] == $filter_name) {
1455
+                array_push($results, $f);
1456
+            };
1457
+        }
1458
+        return $results;
1459
+    }
1460
+
1461
+    public static function calculate_article_score($filters) {
1462
+        $score = 0;
1463
+
1464
+        foreach ($filters as $f) {
1465
+            if ($f["type"] == "score") {
1466
+                $score += $f["param"];
1467
+            };
1468
+        }
1469
+        return $score;
1470
+    }
1471
+
1472
+    public static function labels_contains_caption($labels, $caption) {
1473
+        foreach ($labels as $label) {
1474
+            if ($label[1] == $caption) {
1475
+                return true;
1476
+            }
1477
+        }
1478
+
1479
+        return false;
1480
+    }
1481
+
1482
+    public static function assign_article_to_label_filters($id, $filters, $owner_uid, $article_labels) {
1483
+        foreach ($filters as $f) {
1484
+            if ($f["type"] == "label") {
1485
+                if (!RSSUtils::labels_contains_caption($article_labels, $f["param"])) {
1486
+                    Labels::add_article($id, $f["param"], $owner_uid);
1487
+                }
1488
+            }
1489
+        }
1490
+    }
1491
+
1492
+    public static function make_guid_from_title($title) {
1493
+        return preg_replace("/[ \"\',.:;]/", "-",
1494
+            mb_strtolower(strip_tags($title), 'utf-8'));
1495
+    }
1496
+
1497
+    public static function cleanup_counters_cache() {
1498
+        $pdo = Db::pdo();
1499
+
1500
+        $res = $pdo->query("DELETE FROM ttrss_counters_cache
1501 1501
 			WHERE feed_id > 0 AND
1502 1502
 			(SELECT COUNT(id) FROM ttrss_feeds WHERE
1503 1503
 				id = feed_id AND
1504 1504
 				ttrss_counters_cache.owner_uid = ttrss_feeds.owner_uid) = 0");
1505 1505
 
1506
-		$frows = $res->rowCount();
1506
+        $frows = $res->rowCount();
1507 1507
 
1508
-		$res = $pdo->query("DELETE FROM ttrss_cat_counters_cache
1508
+        $res = $pdo->query("DELETE FROM ttrss_cat_counters_cache
1509 1509
 			WHERE feed_id > 0 AND
1510 1510
 			(SELECT COUNT(id) FROM ttrss_feed_categories WHERE
1511 1511
 				id = feed_id AND
1512 1512
 				ttrss_cat_counters_cache.owner_uid = ttrss_feed_categories.owner_uid) = 0");
1513 1513
 
1514
-		$crows = $res->rowCount();
1515
-
1516
-		Debug::log("removed $frows (feeds) $crows (cats) orphaned counter cache entries.");
1517
-	}
1518
-
1519
-	public static function housekeeping_user($owner_uid) {
1520
-		$tmph = new PluginHost();
1521
-
1522
-		load_user_plugins($owner_uid, $tmph);
1523
-
1524
-		$tmph->run_hooks(PluginHost::HOOK_HOUSE_KEEPING, "hook_house_keeping", "");
1525
-	}
1526
-
1527
-	public static function housekeeping_common() {
1528
-		DiskCache::expire();
1529
-
1530
-		RSSUtils::expire_lock_files();
1531
-		RSSUtils::expire_error_log();
1532
-		RSSUtils::expire_feed_archive();
1533
-		RSSUtils::cleanup_feed_browser();
1534
-
1535
-		Article::purge_orphans();
1536
-		RSSUtils::cleanup_counters_cache();
1537
-
1538
-		PluginHost::getInstance()->run_hooks(PluginHost::HOOK_HOUSE_KEEPING, "hook_house_keeping", "");
1539
-	}
1540
-
1541
-	public static function check_feed_favicon($site_url, $feed) {
1542
-		#		print "FAVICON [$site_url]: $favicon_url\n";
1543
-
1544
-		$icon_file = ICONS_DIR."/$feed.ico";
1545
-
1546
-		if (!file_exists($icon_file)) {
1547
-			$favicon_url = RSSUtils::get_favicon_url($site_url);
1548
-
1549
-			if ($favicon_url) {
1550
-				// Limiting to "image" type misses those served with text/plain
1551
-				$contents = fetch_file_contents($favicon_url); // , "image");
1552
-
1553
-				if ($contents) {
1554
-					// Crude image type matching.
1555
-					// Patterns gleaned from the file(1) source code.
1556
-					if (preg_match('/^\x00\x00\x01\x00/', $contents)) {
1557
-						// 0       string  \000\000\001\000        MS Windows icon resource
1558
-						//error_log("check_feed_favicon: favicon_url=$favicon_url isa MS Windows icon resource");
1559
-					} elseif (preg_match('/^GIF8/', $contents)) {
1560
-						// 0       string          GIF8            GIF image data
1561
-						//error_log("check_feed_favicon: favicon_url=$favicon_url isa GIF image");
1562
-					} elseif (preg_match('/^\x89PNG\x0d\x0a\x1a\x0a/', $contents)) {
1563
-						// 0       string          \x89PNG\x0d\x0a\x1a\x0a         PNG image data
1564
-						//error_log("check_feed_favicon: favicon_url=$favicon_url isa PNG image");
1565
-					} elseif (preg_match('/^\xff\xd8/', $contents)) {
1566
-						// 0       beshort         0xffd8          JPEG image data
1567
-						//error_log("check_feed_favicon: favicon_url=$favicon_url isa JPG image");
1568
-					} elseif (preg_match('/^BM/', $contents)) {
1569
-						// 0	string		BM	PC bitmap (OS2, Windows BMP files)
1570
-						//error_log("check_feed_favicon, favicon_url=$favicon_url isa BMP image");
1571
-					} else {
1572
-						//error_log("check_feed_favicon: favicon_url=$favicon_url isa UNKNOWN type");
1573
-						$contents = "";
1574
-					}
1575
-				}
1576
-
1577
-				if ($contents) {
1578
-					$fp = @fopen($icon_file, "w");
1579
-
1580
-					if ($fp) {
1581
-						fwrite($fp, $contents);
1582
-						fclose($fp);
1583
-						chmod($icon_file, 0644);
1584
-					}
1585
-				}
1586
-			}
1587
-			return $icon_file;
1588
-		}
1589
-	}
1590
-
1591
-	public static function is_gzipped($feed_data) {
1592
-		return strpos(substr($feed_data, 0, 3),
1593
-				"\x1f"."\x8b"."\x08", 0) === 0;
1594
-	}
1595
-
1596
-	public static function load_filters($feed_id, $owner_uid) {
1597
-		$filters = array();
1598
-
1599
-		$feed_id = (int) $feed_id;
1600
-		$cat_id = (int) Feeds::getFeedCategory($feed_id);
1601
-
1602
-		if ($cat_id == 0) {
1603
-					$null_cat_qpart = "cat_id IS NULL OR";
1604
-		} else {
1605
-					$null_cat_qpart = "";
1606
-		}
1607
-
1608
-		$pdo = Db::pdo();
1609
-
1610
-		$sth = $pdo->prepare("SELECT * FROM ttrss_filters2 WHERE
1514
+        $crows = $res->rowCount();
1515
+
1516
+        Debug::log("removed $frows (feeds) $crows (cats) orphaned counter cache entries.");
1517
+    }
1518
+
1519
+    public static function housekeeping_user($owner_uid) {
1520
+        $tmph = new PluginHost();
1521
+
1522
+        load_user_plugins($owner_uid, $tmph);
1523
+
1524
+        $tmph->run_hooks(PluginHost::HOOK_HOUSE_KEEPING, "hook_house_keeping", "");
1525
+    }
1526
+
1527
+    public static function housekeeping_common() {
1528
+        DiskCache::expire();
1529
+
1530
+        RSSUtils::expire_lock_files();
1531
+        RSSUtils::expire_error_log();
1532
+        RSSUtils::expire_feed_archive();
1533
+        RSSUtils::cleanup_feed_browser();
1534
+
1535
+        Article::purge_orphans();
1536
+        RSSUtils::cleanup_counters_cache();
1537
+
1538
+        PluginHost::getInstance()->run_hooks(PluginHost::HOOK_HOUSE_KEEPING, "hook_house_keeping", "");
1539
+    }
1540
+
1541
+    public static function check_feed_favicon($site_url, $feed) {
1542
+        #		print "FAVICON [$site_url]: $favicon_url\n";
1543
+
1544
+        $icon_file = ICONS_DIR."/$feed.ico";
1545
+
1546
+        if (!file_exists($icon_file)) {
1547
+            $favicon_url = RSSUtils::get_favicon_url($site_url);
1548
+
1549
+            if ($favicon_url) {
1550
+                // Limiting to "image" type misses those served with text/plain
1551
+                $contents = fetch_file_contents($favicon_url); // , "image");
1552
+
1553
+                if ($contents) {
1554
+                    // Crude image type matching.
1555
+                    // Patterns gleaned from the file(1) source code.
1556
+                    if (preg_match('/^\x00\x00\x01\x00/', $contents)) {
1557
+                        // 0       string  \000\000\001\000        MS Windows icon resource
1558
+                        //error_log("check_feed_favicon: favicon_url=$favicon_url isa MS Windows icon resource");
1559
+                    } elseif (preg_match('/^GIF8/', $contents)) {
1560
+                        // 0       string          GIF8            GIF image data
1561
+                        //error_log("check_feed_favicon: favicon_url=$favicon_url isa GIF image");
1562
+                    } elseif (preg_match('/^\x89PNG\x0d\x0a\x1a\x0a/', $contents)) {
1563
+                        // 0       string          \x89PNG\x0d\x0a\x1a\x0a         PNG image data
1564
+                        //error_log("check_feed_favicon: favicon_url=$favicon_url isa PNG image");
1565
+                    } elseif (preg_match('/^\xff\xd8/', $contents)) {
1566
+                        // 0       beshort         0xffd8          JPEG image data
1567
+                        //error_log("check_feed_favicon: favicon_url=$favicon_url isa JPG image");
1568
+                    } elseif (preg_match('/^BM/', $contents)) {
1569
+                        // 0	string		BM	PC bitmap (OS2, Windows BMP files)
1570
+                        //error_log("check_feed_favicon, favicon_url=$favicon_url isa BMP image");
1571
+                    } else {
1572
+                        //error_log("check_feed_favicon: favicon_url=$favicon_url isa UNKNOWN type");
1573
+                        $contents = "";
1574
+                    }
1575
+                }
1576
+
1577
+                if ($contents) {
1578
+                    $fp = @fopen($icon_file, "w");
1579
+
1580
+                    if ($fp) {
1581
+                        fwrite($fp, $contents);
1582
+                        fclose($fp);
1583
+                        chmod($icon_file, 0644);
1584
+                    }
1585
+                }
1586
+            }
1587
+            return $icon_file;
1588
+        }
1589
+    }
1590
+
1591
+    public static function is_gzipped($feed_data) {
1592
+        return strpos(substr($feed_data, 0, 3),
1593
+                "\x1f"."\x8b"."\x08", 0) === 0;
1594
+    }
1595
+
1596
+    public static function load_filters($feed_id, $owner_uid) {
1597
+        $filters = array();
1598
+
1599
+        $feed_id = (int) $feed_id;
1600
+        $cat_id = (int) Feeds::getFeedCategory($feed_id);
1601
+
1602
+        if ($cat_id == 0) {
1603
+                    $null_cat_qpart = "cat_id IS NULL OR";
1604
+        } else {
1605
+                    $null_cat_qpart = "";
1606
+        }
1607
+
1608
+        $pdo = Db::pdo();
1609
+
1610
+        $sth = $pdo->prepare("SELECT * FROM ttrss_filters2 WHERE
1611 1611
 				owner_uid = ? AND enabled = true ORDER BY order_id, title");
1612
-		$sth->execute([$owner_uid]);
1612
+        $sth->execute([$owner_uid]);
1613 1613
 
1614
-		$check_cats = array_merge(
1615
-			Feeds::getParentCategories($cat_id, $owner_uid),
1616
-			[$cat_id]);
1614
+        $check_cats = array_merge(
1615
+            Feeds::getParentCategories($cat_id, $owner_uid),
1616
+            [$cat_id]);
1617 1617
 
1618
-		$check_cats_str = join(",", $check_cats);
1619
-		$check_cats_fullids = array_map(function($a) { return "CAT:$a"; }, $check_cats);
1618
+        $check_cats_str = join(",", $check_cats);
1619
+        $check_cats_fullids = array_map(function($a) { return "CAT:$a"; }, $check_cats);
1620 1620
 
1621
-		while ($line = $sth->fetch()) {
1622
-			$filter_id = $line["id"];
1621
+        while ($line = $sth->fetch()) {
1622
+            $filter_id = $line["id"];
1623 1623
 
1624
-			$match_any_rule = sql_bool_to_bool($line["match_any_rule"]);
1624
+            $match_any_rule = sql_bool_to_bool($line["match_any_rule"]);
1625 1625
 
1626
-			$sth2 = $pdo->prepare("SELECT
1626
+            $sth2 = $pdo->prepare("SELECT
1627 1627
 					r.reg_exp, r.inverse, r.feed_id, r.cat_id, r.cat_filter, r.match_on, t.name AS type_name
1628 1628
 					FROM ttrss_filters2_rules AS r,
1629 1629
 					ttrss_filter_types AS t
@@ -1632,118 +1632,118 @@  discard block
 block discarded – undo
1632 1632
 						  (($null_cat_qpart (cat_id IS NULL AND cat_filter = false) OR cat_id IN ($check_cats_str)) AND
1633 1633
 						  (feed_id IS NULL OR feed_id = ?))) AND
1634 1634
 						filter_type = t.id AND filter_id = ?");
1635
-			$sth2->execute([$feed_id, $filter_id]);
1635
+            $sth2->execute([$feed_id, $filter_id]);
1636 1636
 
1637
-			$rules = array();
1638
-			$actions = array();
1637
+            $rules = array();
1638
+            $actions = array();
1639 1639
 
1640
-			while ($rule_line = $sth2->fetch()) {
1641
-				#				print_r($rule_line);
1640
+            while ($rule_line = $sth2->fetch()) {
1641
+                #				print_r($rule_line);
1642 1642
 
1643
-				if ($rule_line["match_on"]) {
1644
-					$match_on = json_decode($rule_line["match_on"], true);
1643
+                if ($rule_line["match_on"]) {
1644
+                    $match_on = json_decode($rule_line["match_on"], true);
1645 1645
 
1646
-					if (in_array("0", $match_on) || in_array($feed_id, $match_on) || count(array_intersect($check_cats_fullids, $match_on)) > 0) {
1646
+                    if (in_array("0", $match_on) || in_array($feed_id, $match_on) || count(array_intersect($check_cats_fullids, $match_on)) > 0) {
1647 1647
 
1648
-						$rule = array();
1649
-						$rule["reg_exp"] = $rule_line["reg_exp"];
1650
-						$rule["type"] = $rule_line["type_name"];
1651
-						$rule["inverse"] = sql_bool_to_bool($rule_line["inverse"]);
1648
+                        $rule = array();
1649
+                        $rule["reg_exp"] = $rule_line["reg_exp"];
1650
+                        $rule["type"] = $rule_line["type_name"];
1651
+                        $rule["inverse"] = sql_bool_to_bool($rule_line["inverse"]);
1652 1652
 
1653
-						array_push($rules, $rule);
1654
-					} else if (!$match_any_rule) {
1655
-						// this filter contains a rule that doesn't match to this feed/category combination
1656
-						// thus filter has to be rejected
1653
+                        array_push($rules, $rule);
1654
+                    } else if (!$match_any_rule) {
1655
+                        // this filter contains a rule that doesn't match to this feed/category combination
1656
+                        // thus filter has to be rejected
1657 1657
 
1658
-						$rules = [];
1659
-						break;
1660
-					}
1658
+                        $rules = [];
1659
+                        break;
1660
+                    }
1661 1661
 
1662
-				} else {
1662
+                } else {
1663 1663
 
1664
-					$rule = array();
1665
-					$rule["reg_exp"] = $rule_line["reg_exp"];
1666
-					$rule["type"] = $rule_line["type_name"];
1667
-					$rule["inverse"] = sql_bool_to_bool($rule_line["inverse"]);
1664
+                    $rule = array();
1665
+                    $rule["reg_exp"] = $rule_line["reg_exp"];
1666
+                    $rule["type"] = $rule_line["type_name"];
1667
+                    $rule["inverse"] = sql_bool_to_bool($rule_line["inverse"]);
1668 1668
 
1669
-					array_push($rules, $rule);
1670
-				}
1671
-			}
1669
+                    array_push($rules, $rule);
1670
+                }
1671
+            }
1672 1672
 
1673
-			if (count($rules) > 0) {
1674
-				$sth2 = $pdo->prepare("SELECT a.action_param,t.name AS type_name
1673
+            if (count($rules) > 0) {
1674
+                $sth2 = $pdo->prepare("SELECT a.action_param,t.name AS type_name
1675 1675
 						FROM ttrss_filters2_actions AS a,
1676 1676
 						ttrss_filter_actions AS t
1677 1677
 						WHERE
1678 1678
 							action_id = t.id AND filter_id = ?");
1679
-				$sth2->execute([$filter_id]);
1680
-
1681
-				while ($action_line = $sth2->fetch()) {
1682
-					#				print_r($action_line);
1683
-
1684
-					$action = array();
1685
-					$action["type"] = $action_line["type_name"];
1686
-					$action["param"] = $action_line["action_param"];
1687
-
1688
-					array_push($actions, $action);
1689
-				}
1690
-			}
1691
-
1692
-			$filter = [];
1693
-			$filter["id"] = $filter_id;
1694
-			$filter["match_any_rule"] = sql_bool_to_bool($line["match_any_rule"]);
1695
-			$filter["inverse"] = sql_bool_to_bool($line["inverse"]);
1696
-			$filter["rules"] = $rules;
1697
-			$filter["actions"] = $actions;
1698
-
1699
-			if (count($rules) > 0 && count($actions) > 0) {
1700
-				array_push($filters, $filter);
1701
-			}
1702
-		}
1703
-
1704
-		return $filters;
1705
-	}
1706
-
1707
-	/**
1708
-	 * Try to determine the favicon URL for a feed.
1709
-	 * adapted from wordpress favicon plugin by Jeff Minard (http://thecodepro.com/)
1710
-	 * http://dev.wp-plugins.org/file/favatars/trunk/favatars.php
1711
-	 *
1712
-	 * @param string $url A feed or page URL
1713
-	 * @access public
1714
-	 * @return mixed The favicon URL, or false if none was found.
1715
-	 */
1716
-	public static function get_favicon_url($url) {
1717
-
1718
-		$favicon_url = false;
1719
-
1720
-		if ($html = @fetch_file_contents($url)) {
1721
-
1722
-			$doc = new DOMDocument();
1723
-			if ($doc->loadHTML($html)) {
1724
-				$xpath = new DOMXPath($doc);
1725
-
1726
-				$base = $xpath->query('/html/head/base[@href]');
1727
-				foreach ($base as $b) {
1728
-					$url = rewrite_relative_url($url, $b->getAttribute("href"));
1729
-					break;
1730
-				}
1731
-
1732
-				$entries = $xpath->query('/html/head/link[@rel="shortcut icon" or @rel="icon"]');
1733
-				if (count($entries) > 0) {
1734
-					foreach ($entries as $entry) {
1735
-						$favicon_url = rewrite_relative_url($url, $entry->getAttribute("href"));
1736
-						break;
1737
-					}
1738
-				}
1739
-			}
1740
-		}
1741
-
1742
-		if (!$favicon_url) {
1743
-					$favicon_url = rewrite_relative_url($url, "/favicon.ico");
1744
-		}
1745
-
1746
-		return $favicon_url;
1747
-	}
1679
+                $sth2->execute([$filter_id]);
1680
+
1681
+                while ($action_line = $sth2->fetch()) {
1682
+                    #				print_r($action_line);
1683
+
1684
+                    $action = array();
1685
+                    $action["type"] = $action_line["type_name"];
1686
+                    $action["param"] = $action_line["action_param"];
1687
+
1688
+                    array_push($actions, $action);
1689
+                }
1690
+            }
1691
+
1692
+            $filter = [];
1693
+            $filter["id"] = $filter_id;
1694
+            $filter["match_any_rule"] = sql_bool_to_bool($line["match_any_rule"]);
1695
+            $filter["inverse"] = sql_bool_to_bool($line["inverse"]);
1696
+            $filter["rules"] = $rules;
1697
+            $filter["actions"] = $actions;
1698
+
1699
+            if (count($rules) > 0 && count($actions) > 0) {
1700
+                array_push($filters, $filter);
1701
+            }
1702
+        }
1703
+
1704
+        return $filters;
1705
+    }
1706
+
1707
+    /**
1708
+     * Try to determine the favicon URL for a feed.
1709
+     * adapted from wordpress favicon plugin by Jeff Minard (http://thecodepro.com/)
1710
+     * http://dev.wp-plugins.org/file/favatars/trunk/favatars.php
1711
+     *
1712
+     * @param string $url A feed or page URL
1713
+     * @access public
1714
+     * @return mixed The favicon URL, or false if none was found.
1715
+     */
1716
+    public static function get_favicon_url($url) {
1717
+
1718
+        $favicon_url = false;
1719
+
1720
+        if ($html = @fetch_file_contents($url)) {
1721
+
1722
+            $doc = new DOMDocument();
1723
+            if ($doc->loadHTML($html)) {
1724
+                $xpath = new DOMXPath($doc);
1725
+
1726
+                $base = $xpath->query('/html/head/base[@href]');
1727
+                foreach ($base as $b) {
1728
+                    $url = rewrite_relative_url($url, $b->getAttribute("href"));
1729
+                    break;
1730
+                }
1731
+
1732
+                $entries = $xpath->query('/html/head/link[@rel="shortcut icon" or @rel="icon"]');
1733
+                if (count($entries) > 0) {
1734
+                    foreach ($entries as $entry) {
1735
+                        $favicon_url = rewrite_relative_url($url, $entry->getAttribute("href"));
1736
+                        break;
1737
+                    }
1738
+                }
1739
+            }
1740
+        }
1741
+
1742
+        if (!$favicon_url) {
1743
+                    $favicon_url = rewrite_relative_url($url, "/favicon.ico");
1744
+        }
1745
+
1746
+        return $favicon_url;
1747
+    }
1748 1748
 
1749 1749
 }
Please login to merge, or discard this patch.
Switch Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -1364,35 +1364,35 @@
 block discarded – undo
1364 1364
 				}
1365 1365
 
1366 1366
 				switch ($rule["type"]) {
1367
-					case "title":
1368
-						$match = @preg_match("/$reg_exp/iu", $title);
1369
-						break;
1370
-					case "content":
1371
-						// we don't need to deal with multiline regexps
1372
-						$content = preg_replace("/[\r\n\t]/", "", $content);
1367
+				case "title":
1368
+					$match = @preg_match("/$reg_exp/iu", $title);
1369
+					break;
1370
+				case "content":
1371
+					// we don't need to deal with multiline regexps
1372
+					$content = preg_replace("/[\r\n\t]/", "", $content);
1373 1373
 
1374
-						$match = @preg_match("/$reg_exp/iu", $content);
1375
-						break;
1376
-					case "both":
1377
-						// we don't need to deal with multiline regexps
1378
-						$content = preg_replace("/[\r\n\t]/", "", $content);
1374
+					$match = @preg_match("/$reg_exp/iu", $content);
1375
+					break;
1376
+				case "both":
1377
+					// we don't need to deal with multiline regexps
1378
+					$content = preg_replace("/[\r\n\t]/", "", $content);
1379 1379
 
1380
-						$match = (@preg_match("/$reg_exp/iu", $title) || @preg_match("/$reg_exp/iu", $content));
1381
-						break;
1382
-					case "link":
1383
-						$match = @preg_match("/$reg_exp/iu", $link);
1384
-						break;
1385
-					case "author":
1386
-						$match = @preg_match("/$reg_exp/iu", $author);
1387
-						break;
1388
-					case "tag":
1389
-						foreach ($tags as $tag) {
1390
-							if (@preg_match("/$reg_exp/iu", $tag)) {
1391
-								$match = true;
1392
-								break;
1393
-							}
1380
+					$match = (@preg_match("/$reg_exp/iu", $title) || @preg_match("/$reg_exp/iu", $content));
1381
+					break;
1382
+				case "link":
1383
+					$match = @preg_match("/$reg_exp/iu", $link);
1384
+					break;
1385
+				case "author":
1386
+					$match = @preg_match("/$reg_exp/iu", $author);
1387
+					break;
1388
+				case "tag":
1389
+					foreach ($tags as $tag) {
1390
+						if (@preg_match("/$reg_exp/iu", $tag)) {
1391
+							$match = true;
1392
+							break;
1394 1393
 						}
1395
-						break;
1394
+					}
1395
+					break;
1396 1396
 				}
1397 1397
 
1398 1398
 				if ($rule_inverse) {
Please login to merge, or discard this patch.
Braces   +7 added lines, -2 removed lines patch added patch discarded remove patch
@@ -616,10 +616,15 @@
 block discarded – undo
616 616
 				Debug::log("link $entry_link", Debug::$LOG_VERBOSE);
617 617
 				Debug::log("language $entry_language", Debug::$LOG_VERBOSE);
618 618
 
619
-				if (!$entry_title) $entry_title = date("Y-m-d H:i:s", $entry_timestamp); ;
619
+				if (!$entry_title) {
620
+				    $entry_title = date("Y-m-d H:i:s", $entry_timestamp);
621
+				}
622
+				;
620 623
 
621 624
 				$entry_content = $item->get_content();
622
-				if (!$entry_content) $entry_content = $item->get_description();
625
+				if (!$entry_content) {
626
+				    $entry_content = $item->get_description();
627
+				}
623 628
 
624 629
 				if (Debug::get_loglevel() >= 3) {
625 630
 					print "content: ";
Please login to merge, or discard this patch.
classes/backend.php 3 patches
Indentation   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -1,101 +1,101 @@
 block discarded – undo
1 1
 <?php
2 2
 class Backend extends Handler {
3
-	public function loading() {
4
-		header("Content-type: text/html");
5
-		print __("Loading, please wait...")." ".
6
-			"<img src='images/indicator_tiny.gif'>";
7
-	}
8
-
9
-	public function digestTest() {
10
-		if (isset($_SESSION['uid'])) {
11
-			header("Content-type: text/html");
12
-
13
-			$rv = Digest::prepare_headlines_digest($_SESSION['uid'], 1, 1000);
14
-
15
-			print "<h1>HTML</h1>";
16
-			print $rv[0];
17
-			print "<h1>Plain text</h1>";
18
-			print "<pre>".$rv[3]."</pre>";
19
-		} else {
20
-			print error_json(6);
21
-		}
22
-	}
23
-
24
-	public function help() {
25
-		$topic = clean_filename($_REQUEST["topic"]); // only one for now
26
-
27
-		if ($topic == "main") {
28
-			$info = get_hotkeys_info();
29
-			$imap = get_hotkeys_map();
30
-			$omap = array();
31
-
32
-			foreach ($imap[1] as $sequence => $action) {
33
-				if (!isset($omap[$action])) {
34
-				    $omap[$action] = array();
35
-				}
36
-
37
-				array_push($omap[$action], $sequence);
38
-			}
39
-
40
-			print "<ul class='panel panel-scrollable hotkeys-help' style='height : 300px'>";
41
-
42
-			$cur_section = "";
43
-			foreach ($info as $section => $hotkeys) {
44
-
45
-				if ($cur_section) {
46
-				    print "<li>&nbsp;</li>";
47
-				}
48
-				print "<li><h3>" . $section . "</h3></li>";
49
-				$cur_section = $section;
50
-
51
-				foreach ($hotkeys as $action => $description) {
52
-
53
-					if (is_array($omap[$action])) {
54
-						foreach ($omap[$action] as $sequence) {
55
-							if (strpos($sequence, "|") !== false) {
56
-								$sequence = substr($sequence,
57
-									strpos($sequence, "|") + 1,
58
-									strlen($sequence));
59
-							} else {
60
-								$keys = explode(" ", $sequence);
61
-
62
-								for ($i = 0; $i < count($keys); $i++) {
63
-									if (strlen($keys[$i]) > 1) {
64
-										$tmp = '';
65
-										foreach (str_split($keys[$i]) as $c) {
66
-											switch ($c) {
67
-												case '*':
68
-													$tmp .= __('Shift').'+';
69
-													break;
70
-												case '^':
71
-													$tmp .= __('Ctrl').'+';
72
-													break;
73
-												default:
74
-													$tmp .= $c;
75
-											}
76
-										}
77
-										$keys[$i] = $tmp;
78
-									}
79
-								}
80
-								$sequence = join(" ", $keys);
81
-							}
82
-
83
-							print "<li>";
84
-							print "<div class='hk'><code>$sequence</code></div>";
85
-							print "<div class='desc'>$description</div>";
86
-							print "</li>";
87
-						}
88
-					}
89
-				}
90
-			}
91
-
92
-			print "</ul>";
93
-		}
94
-
95
-		print "<footer class='text-center'>";
96
-		print "<button dojoType='dijit.form.Button'
3
+    public function loading() {
4
+        header("Content-type: text/html");
5
+        print __("Loading, please wait...")." ".
6
+            "<img src='images/indicator_tiny.gif'>";
7
+    }
8
+
9
+    public function digestTest() {
10
+        if (isset($_SESSION['uid'])) {
11
+            header("Content-type: text/html");
12
+
13
+            $rv = Digest::prepare_headlines_digest($_SESSION['uid'], 1, 1000);
14
+
15
+            print "<h1>HTML</h1>";
16
+            print $rv[0];
17
+            print "<h1>Plain text</h1>";
18
+            print "<pre>".$rv[3]."</pre>";
19
+        } else {
20
+            print error_json(6);
21
+        }
22
+    }
23
+
24
+    public function help() {
25
+        $topic = clean_filename($_REQUEST["topic"]); // only one for now
26
+
27
+        if ($topic == "main") {
28
+            $info = get_hotkeys_info();
29
+            $imap = get_hotkeys_map();
30
+            $omap = array();
31
+
32
+            foreach ($imap[1] as $sequence => $action) {
33
+                if (!isset($omap[$action])) {
34
+                    $omap[$action] = array();
35
+                }
36
+
37
+                array_push($omap[$action], $sequence);
38
+            }
39
+
40
+            print "<ul class='panel panel-scrollable hotkeys-help' style='height : 300px'>";
41
+
42
+            $cur_section = "";
43
+            foreach ($info as $section => $hotkeys) {
44
+
45
+                if ($cur_section) {
46
+                    print "<li>&nbsp;</li>";
47
+                }
48
+                print "<li><h3>" . $section . "</h3></li>";
49
+                $cur_section = $section;
50
+
51
+                foreach ($hotkeys as $action => $description) {
52
+
53
+                    if (is_array($omap[$action])) {
54
+                        foreach ($omap[$action] as $sequence) {
55
+                            if (strpos($sequence, "|") !== false) {
56
+                                $sequence = substr($sequence,
57
+                                    strpos($sequence, "|") + 1,
58
+                                    strlen($sequence));
59
+                            } else {
60
+                                $keys = explode(" ", $sequence);
61
+
62
+                                for ($i = 0; $i < count($keys); $i++) {
63
+                                    if (strlen($keys[$i]) > 1) {
64
+                                        $tmp = '';
65
+                                        foreach (str_split($keys[$i]) as $c) {
66
+                                            switch ($c) {
67
+                                                case '*':
68
+                                                    $tmp .= __('Shift').'+';
69
+                                                    break;
70
+                                                case '^':
71
+                                                    $tmp .= __('Ctrl').'+';
72
+                                                    break;
73
+                                                default:
74
+                                                    $tmp .= $c;
75
+                                            }
76
+                                        }
77
+                                        $keys[$i] = $tmp;
78
+                                    }
79
+                                }
80
+                                $sequence = join(" ", $keys);
81
+                            }
82
+
83
+                            print "<li>";
84
+                            print "<div class='hk'><code>$sequence</code></div>";
85
+                            print "<div class='desc'>$description</div>";
86
+                            print "</li>";
87
+                        }
88
+                    }
89
+                }
90
+            }
91
+
92
+            print "</ul>";
93
+        }
94
+
95
+        print "<footer class='text-center'>";
96
+        print "<button dojoType='dijit.form.Button'
97 97
 			onclick=\"return dijit.byId('helpDlg').hide()\">".__('Close this window')."</button>";
98
-		print "</footer>";
98
+        print "</footer>";
99 99
 
100
-	}
100
+    }
101 101
 }
Please login to merge, or discard this patch.
Switch Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -64,14 +64,14 @@
 block discarded – undo
64 64
 										$tmp = '';
65 65
 										foreach (str_split($keys[$i]) as $c) {
66 66
 											switch ($c) {
67
-												case '*':
68
-													$tmp .= __('Shift').'+';
69
-													break;
70
-												case '^':
71
-													$tmp .= __('Ctrl').'+';
72
-													break;
73
-												default:
74
-													$tmp .= $c;
67
+											case '*':
68
+												$tmp .= __('Shift').'+';
69
+												break;
70
+											case '^':
71
+												$tmp .= __('Ctrl').'+';
72
+												break;
73
+											default:
74
+												$tmp .= $c;
75 75
 											}
76 76
 										}
77 77
 										$keys[$i] = $tmp;
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@
 block discarded – undo
45 45
 				if ($cur_section) {
46 46
 				    print "<li>&nbsp;</li>";
47 47
 				}
48
-				print "<li><h3>" . $section . "</h3></li>";
48
+				print "<li><h3>".$section."</h3></li>";
49 49
 				$cur_section = $section;
50 50
 
51 51
 				foreach ($hotkeys as $action => $description) {
Please login to merge, or discard this patch.
classes/handler/public.php 1 patch
Indentation   +737 added lines, -737 removed lines patch added patch discarded remove patch
@@ -1,336 +1,336 @@  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) {
16
-		    $limit = 60;
17
-		}
18
-
19
-		$date_sort_field = "date_entered DESC, updated DESC";
20
-
21
-		if ($feed == -2 && !$is_cat) {
22
-			$date_sort_field = "last_published DESC";
23
-		} else if ($feed == -1 && !$is_cat) {
24
-			$date_sort_field = "last_marked DESC";
25
-		}
26
-
27
-		switch ($order) {
28
-		case "title":
29
-			$date_sort_field = "ttrss_entries.title, date_entered, updated";
30
-			break;
31
-		case "date_reverse":
32
-			$date_sort_field = "date_entered, updated";
33
-			break;
34
-		case "feed_dates":
35
-			$date_sort_field = "updated DESC";
36
-			break;
37
-		}
38
-
39
-		$params = array(
40
-			"owner_uid" => $owner_uid,
41
-			"feed" => $feed,
42
-			"limit" => $limit,
43
-			"view_mode" => $view_mode,
44
-			"cat_view" => $is_cat,
45
-			"search" => $search,
46
-			"override_order" => $date_sort_field,
47
-			"include_children" => true,
48
-			"ignore_vfeed_group" => true,
49
-			"offset" => $offset,
50
-			"start_ts" => $start_ts
51
-		);
52
-
53
-		if (!$is_cat && is_numeric($feed) && $feed < PLUGIN_FEED_BASE_INDEX && $feed > LABEL_BASE_INDEX) {
54
-
55
-			$user_plugins = get_pref("_ENABLED_PLUGINS", $owner_uid);
56
-
57
-			$tmppluginhost = new PluginHost();
58
-			$tmppluginhost->load(PLUGINS, PluginHost::KIND_ALL);
59
-			$tmppluginhost->load($user_plugins, PluginHost::KIND_USER, $owner_uid);
60
-			$tmppluginhost->load_data();
61
-
62
-			$handler = $tmppluginhost->get_feed_handler(
63
-				PluginHost::feed_to_pfeed_id($feed));
64
-
65
-			if ($handler) {
66
-				$qfh_ret = $handler->get_headlines(PluginHost::feed_to_pfeed_id($feed), $params);
67
-			}
68
-
69
-		} else {
70
-			$qfh_ret = Feeds::queryFeedHeadlines($params);
71
-		}
72
-
73
-		$result = $qfh_ret[0];
74
-		$feed_title = htmlspecialchars($qfh_ret[1]);
75
-		$feed_site_url = $qfh_ret[2];
76
-		/* $last_error = $qfh_ret[3]; */
77
-
78
-		$feed_self_url = get_self_url_prefix().
79
-			"/public.php?op=rss&id=$feed&key=".
80
-			Feeds::get_feed_access_key($feed, false, $owner_uid);
81
-
82
-		if (!$feed_site_url) {
83
-		    $feed_site_url = get_self_url_prefix();
84
-		}
85
-
86
-		if ($format == 'atom') {
87
-			$tpl = new MiniTemplator;
88
-
89
-			$tpl->readTemplateFromFile("templates/generated_feed.txt");
90
-
91
-			$tpl->setVariable('FEED_TITLE', $feed_title, true);
92
-			$tpl->setVariable('VERSION', get_version(), true);
93
-			$tpl->setVariable('FEED_URL', htmlspecialchars($feed_self_url), true);
94
-
95
-			$tpl->setVariable('SELF_URL', htmlspecialchars(get_self_url_prefix()), true);
96
-			while ($line = $result->fetch()) {
97
-
98
-				$line["content_preview"] = sanitize(truncate_string(strip_tags($line["content"]), 100, '...'));
99
-
100
-				foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) {
101
-					$line = $p->hook_query_headlines($line);
102
-				}
12
+            "padding : 5px; border-style : dashed; border-color : #e7d796;".
13
+            "margin-bottom : 1em; color : #9a8c59;";
14
+
15
+        if (!$limit) {
16
+            $limit = 60;
17
+        }
18
+
19
+        $date_sort_field = "date_entered DESC, updated DESC";
20
+
21
+        if ($feed == -2 && !$is_cat) {
22
+            $date_sort_field = "last_published DESC";
23
+        } else if ($feed == -1 && !$is_cat) {
24
+            $date_sort_field = "last_marked DESC";
25
+        }
26
+
27
+        switch ($order) {
28
+        case "title":
29
+            $date_sort_field = "ttrss_entries.title, date_entered, updated";
30
+            break;
31
+        case "date_reverse":
32
+            $date_sort_field = "date_entered, updated";
33
+            break;
34
+        case "feed_dates":
35
+            $date_sort_field = "updated DESC";
36
+            break;
37
+        }
38
+
39
+        $params = array(
40
+            "owner_uid" => $owner_uid,
41
+            "feed" => $feed,
42
+            "limit" => $limit,
43
+            "view_mode" => $view_mode,
44
+            "cat_view" => $is_cat,
45
+            "search" => $search,
46
+            "override_order" => $date_sort_field,
47
+            "include_children" => true,
48
+            "ignore_vfeed_group" => true,
49
+            "offset" => $offset,
50
+            "start_ts" => $start_ts
51
+        );
52
+
53
+        if (!$is_cat && is_numeric($feed) && $feed < PLUGIN_FEED_BASE_INDEX && $feed > LABEL_BASE_INDEX) {
54
+
55
+            $user_plugins = get_pref("_ENABLED_PLUGINS", $owner_uid);
56
+
57
+            $tmppluginhost = new PluginHost();
58
+            $tmppluginhost->load(PLUGINS, PluginHost::KIND_ALL);
59
+            $tmppluginhost->load($user_plugins, PluginHost::KIND_USER, $owner_uid);
60
+            $tmppluginhost->load_data();
61
+
62
+            $handler = $tmppluginhost->get_feed_handler(
63
+                PluginHost::feed_to_pfeed_id($feed));
64
+
65
+            if ($handler) {
66
+                $qfh_ret = $handler->get_headlines(PluginHost::feed_to_pfeed_id($feed), $params);
67
+            }
103 68
 
104
-				foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_EXPORT_FEED) as $p) {
105
-					$line = $p->hook_article_export_feed($line, $feed, $is_cat);
106
-				}
69
+        } else {
70
+            $qfh_ret = Feeds::queryFeedHeadlines($params);
71
+        }
107 72
 
108
-				$tpl->setVariable('ARTICLE_ID',
109
-					htmlspecialchars($orig_guid ? $line['link'] : $this->make_article_tag_uri($line['id'], $line['date_entered'])), true);
110
-				$tpl->setVariable('ARTICLE_LINK', htmlspecialchars($line['link']), true);
111
-				$tpl->setVariable('ARTICLE_TITLE', htmlspecialchars($line['title']), true);
112
-				$tpl->setVariable('ARTICLE_EXCERPT', $line["content_preview"], true);
73
+        $result = $qfh_ret[0];
74
+        $feed_title = htmlspecialchars($qfh_ret[1]);
75
+        $feed_site_url = $qfh_ret[2];
76
+        /* $last_error = $qfh_ret[3]; */
113 77
 
114
-				$content = sanitize($line["content"], false, $owner_uid,
115
-					$feed_site_url, false, $line["id"]);
78
+        $feed_self_url = get_self_url_prefix().
79
+            "/public.php?op=rss&id=$feed&key=".
80
+            Feeds::get_feed_access_key($feed, false, $owner_uid);
116 81
 
117
-				if ($line['note']) {
118
-					$content = "<div style=\"$note_style\">Article note: ".$line['note']."</div>".
119
-						$content;
120
-					$tpl->setVariable('ARTICLE_NOTE', htmlspecialchars($line['note']), true);
121
-				}
82
+        if (!$feed_site_url) {
83
+            $feed_site_url = get_self_url_prefix();
84
+        }
122 85
 
123
-				$tpl->setVariable('ARTICLE_CONTENT', $content, true);
86
+        if ($format == 'atom') {
87
+            $tpl = new MiniTemplator;
124 88
 
125
-				$tpl->setVariable('ARTICLE_UPDATED_ATOM',
126
-					date('c', strtotime($line["updated"])), true);
127
-				$tpl->setVariable('ARTICLE_UPDATED_RFC822',
128
-					date(DATE_RFC822, strtotime($line["updated"])), true);
89
+            $tpl->readTemplateFromFile("templates/generated_feed.txt");
129 90
 
130
-				$tpl->setVariable('ARTICLE_AUTHOR', htmlspecialchars($line['author']), true);
91
+            $tpl->setVariable('FEED_TITLE', $feed_title, true);
92
+            $tpl->setVariable('VERSION', get_version(), true);
93
+            $tpl->setVariable('FEED_URL', htmlspecialchars($feed_self_url), true);
131 94
 
132
-				$tpl->setVariable('ARTICLE_SOURCE_LINK', htmlspecialchars($line['site_url'] ? $line["site_url"] : get_self_url_prefix()), true);
133
-				$tpl->setVariable('ARTICLE_SOURCE_TITLE', htmlspecialchars($line['feed_title'] ? $line['feed_title'] : $feed_title), true);
95
+            $tpl->setVariable('SELF_URL', htmlspecialchars(get_self_url_prefix()), true);
96
+            while ($line = $result->fetch()) {
134 97
 
135
-				$tags = Article::get_article_tags($line["id"], $owner_uid);
98
+                $line["content_preview"] = sanitize(truncate_string(strip_tags($line["content"]), 100, '...'));
136 99
 
137
-				foreach ($tags as $tag) {
138
-					$tpl->setVariable('ARTICLE_CATEGORY', htmlspecialchars($tag), true);
139
-					$tpl->addBlock('category');
140
-				}
100
+                foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) {
101
+                    $line = $p->hook_query_headlines($line);
102
+                }
141 103
 
142
-				$enclosures = Article::get_article_enclosures($line["id"]);
104
+                foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_EXPORT_FEED) as $p) {
105
+                    $line = $p->hook_article_export_feed($line, $feed, $is_cat);
106
+                }
143 107
 
144
-				if (count($enclosures) > 0) {
145
-					foreach ($enclosures as $e) {
146
-						$type = htmlspecialchars($e['content_type']);
147
-						$url = htmlspecialchars($e['content_url']);
148
-						$length = $e['duration'] ? $e['duration'] : 1;
108
+                $tpl->setVariable('ARTICLE_ID',
109
+                    htmlspecialchars($orig_guid ? $line['link'] : $this->make_article_tag_uri($line['id'], $line['date_entered'])), true);
110
+                $tpl->setVariable('ARTICLE_LINK', htmlspecialchars($line['link']), true);
111
+                $tpl->setVariable('ARTICLE_TITLE', htmlspecialchars($line['title']), true);
112
+                $tpl->setVariable('ARTICLE_EXCERPT', $line["content_preview"], true);
149 113
 
150
-						$tpl->setVariable('ARTICLE_ENCLOSURE_URL', $url, true);
151
-						$tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', $type, true);
152
-						$tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', $length, true);
114
+                $content = sanitize($line["content"], false, $owner_uid,
115
+                    $feed_site_url, false, $line["id"]);
153 116
 
154
-						$tpl->addBlock('enclosure');
155
-					}
156
-				} else {
157
-					$tpl->setVariable('ARTICLE_ENCLOSURE_URL', null, true);
158
-					$tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', null, true);
159
-					$tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', null, true);
160
-				}
117
+                if ($line['note']) {
118
+                    $content = "<div style=\"$note_style\">Article note: ".$line['note']."</div>".
119
+                        $content;
120
+                    $tpl->setVariable('ARTICLE_NOTE', htmlspecialchars($line['note']), true);
121
+                }
161 122
 
162
-				list ($og_image, $og_stream) = Article::get_article_image($enclosures, $line['content'], $feed_site_url);
123
+                $tpl->setVariable('ARTICLE_CONTENT', $content, true);
163 124
 
164
-				$tpl->setVariable('ARTICLE_OG_IMAGE', $og_image, true);
125
+                $tpl->setVariable('ARTICLE_UPDATED_ATOM',
126
+                    date('c', strtotime($line["updated"])), true);
127
+                $tpl->setVariable('ARTICLE_UPDATED_RFC822',
128
+                    date(DATE_RFC822, strtotime($line["updated"])), true);
165 129
 
166
-				$tpl->addBlock('entry');
167
-			}
130
+                $tpl->setVariable('ARTICLE_AUTHOR', htmlspecialchars($line['author']), true);
168 131
 
169
-			$tmp = "";
132
+                $tpl->setVariable('ARTICLE_SOURCE_LINK', htmlspecialchars($line['site_url'] ? $line["site_url"] : get_self_url_prefix()), true);
133
+                $tpl->setVariable('ARTICLE_SOURCE_TITLE', htmlspecialchars($line['feed_title'] ? $line['feed_title'] : $feed_title), true);
170 134
 
171
-			$tpl->addBlock('feed');
172
-			$tpl->generateOutputToString($tmp);
135
+                $tags = Article::get_article_tags($line["id"], $owner_uid);
173 136
 
174
-			if (@!clean($_REQUEST["noxml"])) {
175
-				header("Content-Type: text/xml; charset=utf-8");
176
-			} else {
177
-				header("Content-Type: text/plain; charset=utf-8");
178
-			}
137
+                foreach ($tags as $tag) {
138
+                    $tpl->setVariable('ARTICLE_CATEGORY', htmlspecialchars($tag), true);
139
+                    $tpl->addBlock('category');
140
+                }
179 141
 
180
-			print $tmp;
181
-		} else if ($format == 'json') {
142
+                $enclosures = Article::get_article_enclosures($line["id"]);
182 143
 
183
-			$feed = array();
144
+                if (count($enclosures) > 0) {
145
+                    foreach ($enclosures as $e) {
146
+                        $type = htmlspecialchars($e['content_type']);
147
+                        $url = htmlspecialchars($e['content_url']);
148
+                        $length = $e['duration'] ? $e['duration'] : 1;
184 149
 
185
-			$feed['title'] = $feed_title;
186
-			$feed['feed_url'] = $feed_self_url;
150
+                        $tpl->setVariable('ARTICLE_ENCLOSURE_URL', $url, true);
151
+                        $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', $type, true);
152
+                        $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', $length, true);
187 153
 
188
-			$feed['self_url'] = get_self_url_prefix();
154
+                        $tpl->addBlock('enclosure');
155
+                    }
156
+                } else {
157
+                    $tpl->setVariable('ARTICLE_ENCLOSURE_URL', null, true);
158
+                    $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', null, true);
159
+                    $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', null, true);
160
+                }
189 161
 
190
-			$feed['articles'] = array();
162
+                list ($og_image, $og_stream) = Article::get_article_image($enclosures, $line['content'], $feed_site_url);
191 163
 
192
-			while ($line = $result->fetch()) {
164
+                $tpl->setVariable('ARTICLE_OG_IMAGE', $og_image, true);
193 165
 
194
-				$line["content_preview"] = sanitize(truncate_string(strip_tags($line["content_preview"]), 100, '...'));
166
+                $tpl->addBlock('entry');
167
+            }
195 168
 
196
-				foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) {
197
-					$line = $p->hook_query_headlines($line, 100);
198
-				}
169
+            $tmp = "";
199 170
 
200
-				foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_EXPORT_FEED) as $p) {
201
-					$line = $p->hook_article_export_feed($line, $feed, $is_cat);
202
-				}
171
+            $tpl->addBlock('feed');
172
+            $tpl->generateOutputToString($tmp);
203 173
 
204
-				$article = array();
174
+            if (@!clean($_REQUEST["noxml"])) {
175
+                header("Content-Type: text/xml; charset=utf-8");
176
+            } else {
177
+                header("Content-Type: text/plain; charset=utf-8");
178
+            }
205 179
 
206
-				$article['id'] = $line['link'];
207
-				$article['link'] = $line['link'];
208
-				$article['title'] = $line['title'];
209
-				$article['excerpt'] = $line["content_preview"];
210
-				$article['content'] = sanitize($line["content"], false, $owner_uid, $feed_site_url, false, $line["id"]);
211
-				$article['updated'] = date('c', strtotime($line["updated"]));
180
+            print $tmp;
181
+        } else if ($format == 'json') {
212 182
 
213
-				if ($line['note']) {
214
-				    $article['note'] = $line['note'];
215
-				}
216
-				if ($article['author']) {
217
-				    $article['author'] = $line['author'];
218
-				}
183
+            $feed = array();
219 184
 
220
-				$tags = Article::get_article_tags($line["id"], $owner_uid);
185
+            $feed['title'] = $feed_title;
186
+            $feed['feed_url'] = $feed_self_url;
221 187
 
222
-				if (count($tags) > 0) {
223
-					$article['tags'] = array();
188
+            $feed['self_url'] = get_self_url_prefix();
224 189
 
225
-					foreach ($tags as $tag) {
226
-						array_push($article['tags'], $tag);
227
-					}
228
-				}
190
+            $feed['articles'] = array();
229 191
 
230
-				$enclosures = Article::get_article_enclosures($line["id"]);
192
+            while ($line = $result->fetch()) {
231 193
 
232
-				if (count($enclosures) > 0) {
233
-					$article['enclosures'] = array();
194
+                $line["content_preview"] = sanitize(truncate_string(strip_tags($line["content_preview"]), 100, '...'));
234 195
 
235
-					foreach ($enclosures as $e) {
236
-						$type = $e['content_type'];
237
-						$url = $e['content_url'];
238
-						$length = $e['duration'];
196
+                foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) {
197
+                    $line = $p->hook_query_headlines($line, 100);
198
+                }
239 199
 
240
-						array_push($article['enclosures'], array("url" => $url, "type" => $type, "length" => $length));
241
-					}
242
-				}
200
+                foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_EXPORT_FEED) as $p) {
201
+                    $line = $p->hook_article_export_feed($line, $feed, $is_cat);
202
+                }
203
+
204
+                $article = array();
205
+
206
+                $article['id'] = $line['link'];
207
+                $article['link'] = $line['link'];
208
+                $article['title'] = $line['title'];
209
+                $article['excerpt'] = $line["content_preview"];
210
+                $article['content'] = sanitize($line["content"], false, $owner_uid, $feed_site_url, false, $line["id"]);
211
+                $article['updated'] = date('c', strtotime($line["updated"]));
212
+
213
+                if ($line['note']) {
214
+                    $article['note'] = $line['note'];
215
+                }
216
+                if ($article['author']) {
217
+                    $article['author'] = $line['author'];
218
+                }
219
+
220
+                $tags = Article::get_article_tags($line["id"], $owner_uid);
221
+
222
+                if (count($tags) > 0) {
223
+                    $article['tags'] = array();
224
+
225
+                    foreach ($tags as $tag) {
226
+                        array_push($article['tags'], $tag);
227
+                    }
228
+                }
229
+
230
+                $enclosures = Article::get_article_enclosures($line["id"]);
231
+
232
+                if (count($enclosures) > 0) {
233
+                    $article['enclosures'] = array();
243 234
 
244
-				array_push($feed['articles'], $article);
245
-			}
235
+                    foreach ($enclosures as $e) {
236
+                        $type = $e['content_type'];
237
+                        $url = $e['content_url'];
238
+                        $length = $e['duration'];
246 239
 
247
-			header("Content-Type: text/json; charset=utf-8");
248
-			print json_encode($feed);
240
+                        array_push($article['enclosures'], array("url" => $url, "type" => $type, "length" => $length));
241
+                    }
242
+                }
249 243
 
250
-		} else {
251
-			header("Content-Type: text/plain; charset=utf-8");
252
-			print json_encode(array("error" => array("message" => "Unknown format")));
253
-		}
254
-	}
244
+                array_push($feed['articles'], $article);
245
+            }
255 246
 
256
-	public function getUnread() {
257
-		$login = clean($_REQUEST["login"]);
258
-		$fresh = clean($_REQUEST["fresh"]) == "1";
247
+            header("Content-Type: text/json; charset=utf-8");
248
+            print json_encode($feed);
259 249
 
260
-		$sth = $this->pdo->prepare("SELECT id FROM ttrss_users WHERE login = ?");
261
-		$sth->execute([$login]);
250
+        } else {
251
+            header("Content-Type: text/plain; charset=utf-8");
252
+            print json_encode(array("error" => array("message" => "Unknown format")));
253
+        }
254
+    }
262 255
 
263
-		if ($row = $sth->fetch()) {
264
-			$uid = $row["id"];
256
+    public function getUnread() {
257
+        $login = clean($_REQUEST["login"]);
258
+        $fresh = clean($_REQUEST["fresh"]) == "1";
265 259
 
266
-			print Feeds::getGlobalUnread($uid);
260
+        $sth = $this->pdo->prepare("SELECT id FROM ttrss_users WHERE login = ?");
261
+        $sth->execute([$login]);
267 262
 
268
-			if ($fresh) {
269
-				print ";";
270
-				print Feeds::getFeedArticles(-3, false, true, $uid);
271
-			}
263
+        if ($row = $sth->fetch()) {
264
+            $uid = $row["id"];
272 265
 
273
-		} else {
274
-			print "-1;User not found";
275
-		}
276
-	}
266
+            print Feeds::getGlobalUnread($uid);
277 267
 
278
-	public function getProfiles() {
279
-		$login = clean($_REQUEST["login"]);
280
-		$rv = [];
268
+            if ($fresh) {
269
+                print ";";
270
+                print Feeds::getFeedArticles(-3, false, true, $uid);
271
+            }
281 272
 
282
-		if ($login) {
283
-			$sth = $this->pdo->prepare("SELECT ttrss_settings_profiles.* FROM ttrss_settings_profiles,ttrss_users
273
+        } else {
274
+            print "-1;User not found";
275
+        }
276
+    }
277
+
278
+    public function getProfiles() {
279
+        $login = clean($_REQUEST["login"]);
280
+        $rv = [];
281
+
282
+        if ($login) {
283
+            $sth = $this->pdo->prepare("SELECT ttrss_settings_profiles.* FROM ttrss_settings_profiles,ttrss_users
284 284
 			WHERE ttrss_users.id = ttrss_settings_profiles.owner_uid AND login = ? ORDER BY title");
285
-			$sth->execute([$login]);
285
+            $sth->execute([$login]);
286 286
 
287
-			$rv = [["value" => 0, "label" => __("Default profile")]];
287
+            $rv = [["value" => 0, "label" => __("Default profile")]];
288 288
 
289
-			while ($line = $sth->fetch()) {
290
-				$id = $line["id"];
291
-				$title = $line["title"];
289
+            while ($line = $sth->fetch()) {
290
+                $id = $line["id"];
291
+                $title = $line["title"];
292 292
 
293
-				array_push($rv, ["label" => $title, "value" => $id]);
294
-			}
295
-	    }
293
+                array_push($rv, ["label" => $title, "value" => $id]);
294
+            }
295
+        }
296 296
 
297
-		print json_encode($rv);
298
-	}
297
+        print json_encode($rv);
298
+    }
299 299
 
300
-	public function logout() {
301
-		logout_user();
302
-		header("Location: index.php");
303
-	}
300
+    public function logout() {
301
+        logout_user();
302
+        header("Location: index.php");
303
+    }
304 304
 
305
-	public function share() {
306
-		$uuid = clean($_REQUEST["key"]);
305
+    public function share() {
306
+        $uuid = clean($_REQUEST["key"]);
307 307
 
308
-		if ($uuid) {
309
-			$sth = $this->pdo->prepare("SELECT ref_id, owner_uid
308
+        if ($uuid) {
309
+            $sth = $this->pdo->prepare("SELECT ref_id, owner_uid
310 310
 						FROM ttrss_user_entries WHERE uuid = ?");
311
-			$sth->execute([$uuid]);
311
+            $sth->execute([$uuid]);
312 312
 
313
-			if ($row = $sth->fetch()) {
314
-				header("Content-Type: text/html");
313
+            if ($row = $sth->fetch()) {
314
+                header("Content-Type: text/html");
315 315
 
316
-				$id = $row["ref_id"];
317
-				$owner_uid = $row["owner_uid"];
316
+                $id = $row["ref_id"];
317
+                $owner_uid = $row["owner_uid"];
318 318
 
319
-				print $this->format_article($id, $owner_uid);
319
+                print $this->format_article($id, $owner_uid);
320 320
 
321
-				return;
322
-			}
323
-		}
321
+                return;
322
+            }
323
+        }
324 324
 
325
-		header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
326
-		print "Article not found.";
327
-	}
325
+        header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
326
+        print "Article not found.";
327
+    }
328 328
 
329
-	private function format_article($id, $owner_uid) {
329
+    private function format_article($id, $owner_uid) {
330 330
 
331
-		$pdo = Db::pdo();
331
+        $pdo = Db::pdo();
332 332
 
333
-		$sth = $pdo->prepare("SELECT id,title,link,content,feed_id,comments,int_id,lang,
333
+        $sth = $pdo->prepare("SELECT id,title,link,content,feed_id,comments,int_id,lang,
334 334
 			".SUBSTRING_FOR_DATE."(updated,1,16) as updated,
335 335
 			(SELECT site_url FROM ttrss_feeds WHERE id = feed_id) as site_url,
336 336
 			(SELECT title FROM ttrss_feeds WHERE id = feed_id) as feed_title,
@@ -344,26 +344,26 @@  discard block
 block discarded – undo
344 344
 			note
345 345
 			FROM ttrss_entries,ttrss_user_entries
346 346
 			WHERE	id = ? AND ref_id = id AND owner_uid = ?");
347
-		$sth->execute([$id, $owner_uid]);
347
+        $sth->execute([$id, $owner_uid]);
348 348
 
349
-		$rv = '';
349
+        $rv = '';
350 350
 
351
-		if ($line = $sth->fetch()) {
351
+        if ($line = $sth->fetch()) {
352 352
 
353
-			$line["tags"] = Article::get_article_tags($id, $owner_uid, $line["tag_cache"]);
354
-			unset($line["tag_cache"]);
353
+            $line["tags"] = Article::get_article_tags($id, $owner_uid, $line["tag_cache"]);
354
+            unset($line["tag_cache"]);
355 355
 
356
-			$line["content"] = sanitize($line["content"],
357
-				$line['hide_images'],
358
-				$owner_uid, $line["site_url"], false, $line["id"]);
356
+            $line["content"] = sanitize($line["content"],
357
+                $line['hide_images'],
358
+                $owner_uid, $line["site_url"], false, $line["id"]);
359 359
 
360
-			foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ARTICLE) as $p) {
361
-				$line = $p->hook_render_article($line);
362
-			}
360
+            foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ARTICLE) as $p) {
361
+                $line = $p->hook_render_article($line);
362
+            }
363 363
 
364
-			$line['content'] = DiskCache::rewriteUrls($line['content']);
364
+            $line['content'] = DiskCache::rewriteUrls($line['content']);
365 365
 
366
-			$enclosures = Article::get_article_enclosures($line["id"]);
366
+            $enclosures = Article::get_article_enclosures($line["id"]);
367 367
 
368 368
             header("Content-Type: text/html");
369 369
 
@@ -378,13 +378,13 @@  discard block
 block discarded – undo
378 378
             $rv .= "<meta property='og:title' content=\"".htmlspecialchars(html_entity_decode($line["title"], ENT_NOQUOTES | ENT_HTML401))."\"/>\n";
379 379
             $rv .= "<meta property='og:description' content=\"".
380 380
                 htmlspecialchars(
381
-                	truncate_string(
382
-                		preg_replace("/[\r\n\t]/", "",
383
-							preg_replace("/ {1,}/", " ",
384
-								strip_tags(html_entity_decode($line["content"], ENT_NOQUOTES | ENT_HTML401))
385
-							)
386
-					), 500, "...")
387
-				)."\"/>\n";
381
+                    truncate_string(
382
+                        preg_replace("/[\r\n\t]/", "",
383
+                            preg_replace("/ {1,}/", " ",
384
+                                strip_tags(html_entity_decode($line["content"], ENT_NOQUOTES | ENT_HTML401))
385
+                            )
386
+                    ), 500, "...")
387
+                )."\"/>\n";
388 388
 
389 389
             $rv .= "</head>";
390 390
 
@@ -397,135 +397,135 @@  discard block
 block discarded – undo
397 397
             $rv .= "<body class='flat ttrss_utility ttrss_zoom'>";
398 398
             $rv .= "<div class='container'>";
399 399
 
400
-			if ($line["link"]) {
401
-				$rv .= "<h1><a target='_blank' rel='noopener noreferrer'
400
+            if ($line["link"]) {
401
+                $rv .= "<h1><a target='_blank' rel='noopener noreferrer'
402 402
 					title=\"".htmlspecialchars($line['title'])."\"
403 403
 					href=\"" .htmlspecialchars($line["link"])."\">".$line["title"]."</a></h1>";
404
-			} else {
405
-				$rv .= "<h1>".$line["title"]."</h1>";
406
-			}
404
+            } else {
405
+                $rv .= "<h1>".$line["title"]."</h1>";
406
+            }
407 407
 
408
-			$rv .= "<div class='content post'>";
408
+            $rv .= "<div class='content post'>";
409 409
 
410
-			/* header */
410
+            /* header */
411 411
 
412
-			$rv .= "<div class='header'>";
413
-			$rv .= "<div class='row'>"; # row
412
+            $rv .= "<div class='header'>";
413
+            $rv .= "<div class='row'>"; # row
414 414
 
415
-			//$entry_author = $line["author"] ? " - " . $line["author"] : "";
416
-			$parsed_updated = make_local_datetime($line["updated"], true,
417
-				$owner_uid, true);
415
+            //$entry_author = $line["author"] ? " - " . $line["author"] : "";
416
+            $parsed_updated = make_local_datetime($line["updated"], true,
417
+                $owner_uid, true);
418 418
 
419
-			$rv .= "<div>".$line['author']."</div>";
419
+            $rv .= "<div>".$line['author']."</div>";
420 420
             $rv .= "<div>$parsed_updated</div>";
421 421
 
422
-			$rv .= "</div>"; # row
422
+            $rv .= "</div>"; # row
423 423
 
424
-			$rv .= "</div>"; # header
424
+            $rv .= "</div>"; # header
425 425
 
426
-			/* content */
426
+            /* content */
427 427
 
428
-			$lang = $line['lang'] ? $line['lang'] : "en";
429
-			$rv .= "<div class='content' lang='$lang'>";
428
+            $lang = $line['lang'] ? $line['lang'] : "en";
429
+            $rv .= "<div class='content' lang='$lang'>";
430 430
 
431
-			/* content body */
431
+            /* content body */
432 432
 
433
-			$rv .= $line["content"];
433
+            $rv .= $line["content"];
434 434
 
435 435
             $rv .= Article::format_article_enclosures($id,
436 436
                 $line["always_display_enclosures"],
437 437
                 $line["content"],
438 438
                 $line["hide_images"]);
439 439
 
440
-			$rv .= "</div>"; # content
440
+            $rv .= "</div>"; # content
441 441
 
442
-			$rv .= "</div>"; # post
442
+            $rv .= "</div>"; # post
443 443
 
444
-		}
444
+        }
445 445
 
446
-		foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FORMAT_ARTICLE) as $p) {
447
-			$rv = $p->hook_format_article($rv, $line, true);
448
-		}
446
+        foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FORMAT_ARTICLE) as $p) {
447
+            $rv = $p->hook_format_article($rv, $line, true);
448
+        }
449 449
 
450
-		return $rv;
450
+        return $rv;
451 451
 
452
-	}
452
+    }
453 453
 
454
-	public function rss() {
455
-		$feed = clean($_REQUEST["id"]);
456
-		$key = clean($_REQUEST["key"]);
457
-		$is_cat = clean($_REQUEST["is_cat"]);
458
-		$limit = (int) clean($_REQUEST["limit"]);
459
-		$offset = (int) clean($_REQUEST["offset"]);
454
+    public function rss() {
455
+        $feed = clean($_REQUEST["id"]);
456
+        $key = clean($_REQUEST["key"]);
457
+        $is_cat = clean($_REQUEST["is_cat"]);
458
+        $limit = (int) clean($_REQUEST["limit"]);
459
+        $offset = (int) clean($_REQUEST["offset"]);
460 460
 
461
-		$search = clean($_REQUEST["q"]);
462
-		$view_mode = clean($_REQUEST["view-mode"]);
463
-		$order = clean($_REQUEST["order"]);
464
-		$start_ts = clean($_REQUEST["ts"]);
461
+        $search = clean($_REQUEST["q"]);
462
+        $view_mode = clean($_REQUEST["view-mode"]);
463
+        $order = clean($_REQUEST["order"]);
464
+        $start_ts = clean($_REQUEST["ts"]);
465 465
 
466
-		$format = clean($_REQUEST['format']);
467
-		$orig_guid = clean($_REQUEST["orig_guid"]);
466
+        $format = clean($_REQUEST['format']);
467
+        $orig_guid = clean($_REQUEST["orig_guid"]);
468 468
 
469
-		if (!$format) {
470
-		    $format = 'atom';
471
-		}
469
+        if (!$format) {
470
+            $format = 'atom';
471
+        }
472 472
 
473
-		if (SINGLE_USER_MODE) {
474
-			authenticate_user("admin", null);
475
-		}
473
+        if (SINGLE_USER_MODE) {
474
+            authenticate_user("admin", null);
475
+        }
476 476
 
477
-		$owner_id = false;
477
+        $owner_id = false;
478 478
 
479
-		if ($key) {
480
-			$sth = $this->pdo->prepare("SELECT owner_uid FROM
479
+        if ($key) {
480
+            $sth = $this->pdo->prepare("SELECT owner_uid FROM
481 481
 				ttrss_access_keys WHERE access_key = ? AND feed_id = ?");
482
-			$sth->execute([$key, $feed]);
483
-
484
-			if ($row = $sth->fetch()) {
485
-							$owner_id = $row["owner_uid"];
486
-			}
487
-		}
488
-
489
-		if ($owner_id) {
490
-			$this->generate_syndicated_feed($owner_id, $feed, $is_cat, $limit,
491
-				$offset, $search, $view_mode, $format, $order, $orig_guid, $start_ts);
492
-		} else {
493
-			header('HTTP/1.1 403 Forbidden');
494
-		}
495
-	}
496
-
497
-	public function updateTask() {
498
-		PluginHost::getInstance()->run_hooks(PluginHost::HOOK_UPDATE_TASK, "hook_update_task", false);
499
-	}
500
-
501
-	public function housekeepingTask() {
502
-		PluginHost::getInstance()->run_hooks(PluginHost::HOOK_HOUSE_KEEPING, "hook_house_keeping", false);
503
-	}
504
-
505
-	public function globalUpdateFeeds() {
506
-		RPC::updaterandomfeed_real();
507
-
508
-		PluginHost::getInstance()->run_hooks(PluginHost::HOOK_UPDATE_TASK, "hook_update_task", false);
509
-	}
510
-
511
-	public function sharepopup() {
512
-		if (SINGLE_USER_MODE) {
513
-			login_sequence();
514
-		}
515
-
516
-		header('Content-Type: text/html; charset=utf-8');
517
-		?>
482
+            $sth->execute([$key, $feed]);
483
+
484
+            if ($row = $sth->fetch()) {
485
+                            $owner_id = $row["owner_uid"];
486
+            }
487
+        }
488
+
489
+        if ($owner_id) {
490
+            $this->generate_syndicated_feed($owner_id, $feed, $is_cat, $limit,
491
+                $offset, $search, $view_mode, $format, $order, $orig_guid, $start_ts);
492
+        } else {
493
+            header('HTTP/1.1 403 Forbidden');
494
+        }
495
+    }
496
+
497
+    public function updateTask() {
498
+        PluginHost::getInstance()->run_hooks(PluginHost::HOOK_UPDATE_TASK, "hook_update_task", false);
499
+    }
500
+
501
+    public function housekeepingTask() {
502
+        PluginHost::getInstance()->run_hooks(PluginHost::HOOK_HOUSE_KEEPING, "hook_house_keeping", false);
503
+    }
504
+
505
+    public function globalUpdateFeeds() {
506
+        RPC::updaterandomfeed_real();
507
+
508
+        PluginHost::getInstance()->run_hooks(PluginHost::HOOK_UPDATE_TASK, "hook_update_task", false);
509
+    }
510
+
511
+    public function sharepopup() {
512
+        if (SINGLE_USER_MODE) {
513
+            login_sequence();
514
+        }
515
+
516
+        header('Content-Type: text/html; charset=utf-8');
517
+        ?>
518 518
 		<!DOCTYPE html>
519 519
 		<html>
520 520
 		<head>
521 521
 			<title><?php echo __("Share with Tiny Tiny RSS") ?></title>
522 522
 			<?php
523
-			echo stylesheet_tag("css/default.css");
524
-			echo javascript_tag("lib/prototype.js");
525
-			echo javascript_tag("lib/dojo/dojo.js");
526
-			echo javascript_tag("lib/dojo/tt-rss-layer.js");
527
-			echo javascript_tag("lib/scriptaculous/scriptaculous.js?load=effects,controls")
528
-			?>
523
+            echo stylesheet_tag("css/default.css");
524
+            echo javascript_tag("lib/prototype.js");
525
+            echo javascript_tag("lib/dojo/dojo.js");
526
+            echo javascript_tag("lib/dojo/tt-rss-layer.js");
527
+            echo javascript_tag("lib/scriptaculous/scriptaculous.js?load=effects,controls")
528
+            ?>
529 529
 			<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
530 530
 			<link rel="shortcut icon" type="image/png" href="images/favicon.png">
531 531
 			<link rel="icon" type="image/png" sizes="72x72" href="images/favicon-72px.png">
@@ -547,29 +547,29 @@  discard block
 block discarded – undo
547 547
 
548 548
 		<?php
549 549
 
550
-		$action = clean($_REQUEST["action"]);
550
+        $action = clean($_REQUEST["action"]);
551 551
 
552
-		if ($_SESSION["uid"]) {
552
+        if ($_SESSION["uid"]) {
553 553
 
554
-			if ($action == 'share') {
554
+            if ($action == 'share') {
555 555
 
556
-				$title = strip_tags(clean($_REQUEST["title"]));
557
-				$url = strip_tags(clean($_REQUEST["url"]));
558
-				$content = strip_tags(clean($_REQUEST["content"]));
559
-				$labels = strip_tags(clean($_REQUEST["labels"]));
556
+                $title = strip_tags(clean($_REQUEST["title"]));
557
+                $url = strip_tags(clean($_REQUEST["url"]));
558
+                $content = strip_tags(clean($_REQUEST["content"]));
559
+                $labels = strip_tags(clean($_REQUEST["labels"]));
560 560
 
561
-				Article::create_published_article($title, $url, $content, $labels,
562
-					$_SESSION["uid"]);
561
+                Article::create_published_article($title, $url, $content, $labels,
562
+                    $_SESSION["uid"]);
563 563
 
564
-				print "<script type='text/javascript'>";
565
-				print "window.close();";
566
-				print "</script>";
564
+                print "<script type='text/javascript'>";
565
+                print "window.close();";
566
+                print "</script>";
567 567
 
568
-			} else {
569
-				$title = htmlspecialchars(clean($_REQUEST["title"]));
570
-				$url = htmlspecialchars(clean($_REQUEST["url"]));
568
+            } else {
569
+                $title = htmlspecialchars(clean($_REQUEST["title"]));
570
+                $url = htmlspecialchars(clean($_REQUEST["url"]));
571 571
 
572
-				?>
572
+                ?>
573 573
 				<form id='share_form' name='share_form'>
574 574
 
575 575
 					<input type="hidden" name="op" value="sharepopup">
@@ -609,12 +609,12 @@  discard block
 block discarded – undo
609 609
 				</form>
610 610
 				<?php
611 611
 
612
-			}
612
+            }
613 613
 
614
-		} else {
614
+        } else {
615 615
 
616
-			$return = urlencode(make_self_url());
617
-			print_error("Not logged in"); ?>
616
+            $return = urlencode(make_self_url());
617
+            print_error("Not logged in"); ?>
618 618
 
619 619
 			<form action="public.php?return=<?php echo $return ?>" method="post">
620 620
 
@@ -646,91 +646,91 @@  discard block
 block discarded – undo
646 646
 
647 647
 			</form>
648 648
 			<?php
649
-		}
649
+        }
650 650
 
651
-		print "</div></body></html>";
652
-	}
651
+        print "</div></body></html>";
652
+    }
653 653
 
654
-	public function login() {
655
-		if (!SINGLE_USER_MODE) {
654
+    public function login() {
655
+        if (!SINGLE_USER_MODE) {
656 656
 
657
-			$login = clean($_POST["login"]);
658
-			$password = clean($_POST["password"]);
659
-			$remember_me = clean($_POST["remember_me"]);
657
+            $login = clean($_POST["login"]);
658
+            $password = clean($_POST["password"]);
659
+            $remember_me = clean($_POST["remember_me"]);
660 660
 
661
-			if ($remember_me) {
662
-				session_set_cookie_params(SESSION_COOKIE_LIFETIME);
663
-			} else {
664
-				session_set_cookie_params(0);
665
-			}
661
+            if ($remember_me) {
662
+                session_set_cookie_params(SESSION_COOKIE_LIFETIME);
663
+            } else {
664
+                session_set_cookie_params(0);
665
+            }
666 666
 
667
-			if (authenticate_user($login, $password)) {
668
-				$_POST["password"] = "";
667
+            if (authenticate_user($login, $password)) {
668
+                $_POST["password"] = "";
669 669
 
670
-				if (get_schema_version() >= 120) {
671
-					$_SESSION["language"] = get_pref("USER_LANGUAGE", $_SESSION["uid"]);
672
-				}
670
+                if (get_schema_version() >= 120) {
671
+                    $_SESSION["language"] = get_pref("USER_LANGUAGE", $_SESSION["uid"]);
672
+                }
673 673
 
674
-				$_SESSION["ref_schema_version"] = get_schema_version(true);
675
-				$_SESSION["bw_limit"] = !!clean($_POST["bw_limit"]);
674
+                $_SESSION["ref_schema_version"] = get_schema_version(true);
675
+                $_SESSION["bw_limit"] = !!clean($_POST["bw_limit"]);
676 676
 
677
-				if (clean($_POST["profile"])) {
677
+                if (clean($_POST["profile"])) {
678 678
 
679
-					$profile = (int) clean($_POST["profile"]);
679
+                    $profile = (int) clean($_POST["profile"]);
680 680
 
681
-					$sth = $this->pdo->prepare("SELECT id FROM ttrss_settings_profiles
681
+                    $sth = $this->pdo->prepare("SELECT id FROM ttrss_settings_profiles
682 682
 						WHERE id = ? AND owner_uid = ?");
683
-					$sth->execute([$profile, $_SESSION['uid']]);
683
+                    $sth->execute([$profile, $_SESSION['uid']]);
684 684
 
685
-					if ($sth->fetch()) {
686
-						$_SESSION["profile"] = $profile;
687
- 					} else {
688
-					    $_SESSION["profile"] = null;
685
+                    if ($sth->fetch()) {
686
+                        $_SESSION["profile"] = $profile;
687
+                        } else {
688
+                        $_SESSION["profile"] = null;
689 689
                     }
690
-				}
691
-			} else {
690
+                }
691
+            } else {
692 692
 
693
-				// start an empty session to deliver login error message
694
-				@session_start();
693
+                // start an empty session to deliver login error message
694
+                @session_start();
695 695
 
696
-				if (!isset($_SESSION["login_error_msg"])) {
697
-									$_SESSION["login_error_msg"] = __("Incorrect username or password");
698
-				}
696
+                if (!isset($_SESSION["login_error_msg"])) {
697
+                                    $_SESSION["login_error_msg"] = __("Incorrect username or password");
698
+                }
699 699
 
700
-				user_error("Failed login attempt for $login from {$_SERVER['REMOTE_ADDR']}", E_USER_WARNING);
701
-			}
700
+                user_error("Failed login attempt for $login from {$_SERVER['REMOTE_ADDR']}", E_USER_WARNING);
701
+            }
702 702
 
703
-			$return = clean($_REQUEST['return']);
703
+            $return = clean($_REQUEST['return']);
704 704
 
705
-			if ($_REQUEST['return'] && mb_strpos($return, SELF_URL_PATH) === 0) {
706
-				header("Location: ".clean($_REQUEST['return']));
707
-			} else {
708
-				header("Location: ".get_self_url_prefix());
709
-			}
710
-		}
711
-	}
705
+            if ($_REQUEST['return'] && mb_strpos($return, SELF_URL_PATH) === 0) {
706
+                header("Location: ".clean($_REQUEST['return']));
707
+            } else {
708
+                header("Location: ".get_self_url_prefix());
709
+            }
710
+        }
711
+    }
712 712
 
713
-	public function subscribe() {
714
-		if (SINGLE_USER_MODE) {
715
-			login_sequence();
716
-		}
713
+    public function subscribe() {
714
+        if (SINGLE_USER_MODE) {
715
+            login_sequence();
716
+        }
717 717
 
718
-		if ($_SESSION["uid"]) {
718
+        if ($_SESSION["uid"]) {
719 719
 
720
-			$feed_url = trim(clean($_REQUEST["feed_url"]));
720
+            $feed_url = trim(clean($_REQUEST["feed_url"]));
721 721
 
722
-			header('Content-Type: text/html; charset=utf-8');
723
-			?>
722
+            header('Content-Type: text/html; charset=utf-8');
723
+            ?>
724 724
 			<!DOCTYPE html>
725 725
 			<html>
726 726
 			<head>
727 727
 				<title>Tiny Tiny RSS</title>
728 728
 				<?php
729
-					echo stylesheet_tag("css/default.css");
730
-					echo javascript_tag("lib/prototype.js");
731
-					echo javascript_tag("lib/dojo/dojo.js");
732
-					echo javascript_tag("lib/dojo/tt-rss-layer.js");
733
-				?>
729
+                    echo stylesheet_tag("css/default.css");
730
+                    echo javascript_tag("lib/prototype.js");
731
+                    echo javascript_tag("lib/dojo/dojo.js");
732
+                    echo javascript_tag("lib/dojo/tt-rss-layer.js");
733
+                ?>
734 734
 				<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
735 735
 				<link rel="shortcut icon" type="image/png" href="images/favicon.png">
736 736
 				<link rel="icon" type="image/png" sizes="72x72" href="images/favicon-72px.png">
@@ -749,8 +749,8 @@  discard block
 block discarded – undo
749 749
 			<div class='content'>
750 750
 			<?php
751 751
 
752
-			if (!$feed_url) {
753
-				?>
752
+            if (!$feed_url) {
753
+                ?>
754 754
 				<form method="post">
755 755
 					<input type="hidden" name="op" value="subscribe">
756 756
 					<fieldset>
@@ -765,101 +765,101 @@  discard block
 block discarded – undo
765 765
 					<a href="index.php"><?php echo __("Return to Tiny Tiny RSS") ?></a>
766 766
 				</form>
767 767
 				<?php
768
-			} else {
769
-
770
-				$rc = Feeds::subscribe_to_feed($feed_url);
771
-				$feed_urls = false;
772
-
773
-				switch ($rc['code']) {
774
-					case 0:
775
-						print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
776
-						break;
777
-					case 1:
778
-						print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
779
-						break;
780
-					case 2:
781
-						print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url));
782
-						break;
783
-					case 3:
784
-						print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url));
785
-						break;
786
-					case 4:
787
-						$feed_urls = $rc["feeds"];
788
-						break;
789
-					case 5:
790
-						print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url));
791
-						break;
792
-				}
793
-
794
-				if ($feed_urls) {
795
-
796
-					print "<form action='public.php'>";
797
-					print "<input type='hidden' name='op' value='subscribe'>";
798
-
799
-					print "<fieldset>";
800
-					print "<label style='display : inline'>".__("Multiple feed URLs found:")."</label>";
801
-					print "<select name='feed_url' dojoType='dijit.form.Select'>";
802
-
803
-					foreach ($feed_urls as $url => $name) {
804
-						$url = htmlspecialchars($url);
805
-						$name = htmlspecialchars($name);
768
+            } else {
769
+
770
+                $rc = Feeds::subscribe_to_feed($feed_url);
771
+                $feed_urls = false;
772
+
773
+                switch ($rc['code']) {
774
+                    case 0:
775
+                        print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
776
+                        break;
777
+                    case 1:
778
+                        print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
779
+                        break;
780
+                    case 2:
781
+                        print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url));
782
+                        break;
783
+                    case 3:
784
+                        print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url));
785
+                        break;
786
+                    case 4:
787
+                        $feed_urls = $rc["feeds"];
788
+                        break;
789
+                    case 5:
790
+                        print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url));
791
+                        break;
792
+                }
793
+
794
+                if ($feed_urls) {
795
+
796
+                    print "<form action='public.php'>";
797
+                    print "<input type='hidden' name='op' value='subscribe'>";
798
+
799
+                    print "<fieldset>";
800
+                    print "<label style='display : inline'>".__("Multiple feed URLs found:")."</label>";
801
+                    print "<select name='feed_url' dojoType='dijit.form.Select'>";
802
+
803
+                    foreach ($feed_urls as $url => $name) {
804
+                        $url = htmlspecialchars($url);
805
+                        $name = htmlspecialchars($name);
806
+
807
+                        print "<option value=\"$url\">$name</option>";
808
+                    }
806 809
 
807
-						print "<option value=\"$url\">$name</option>";
808
-					}
810
+                    print "</select>";
811
+                    print "</fieldset>";
809 812
 
810
-					print "</select>";
811
-					print "</fieldset>";
813
+                    print "<button class='alt-primary' dojoType='dijit.form.Button' type='submit'>".__("Subscribe to selected feed")."</button>";
814
+                    print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>";
812 815
 
813
-					print "<button class='alt-primary' dojoType='dijit.form.Button' type='submit'>".__("Subscribe to selected feed")."</button>";
814
-					print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>";
816
+                    print "</form>";
817
+                }
815 818
 
816
-					print "</form>";
817
-				}
819
+                $tp_uri = get_self_url_prefix()."/prefs.php";
818 820
 
819
-				$tp_uri = get_self_url_prefix()."/prefs.php";
820
-
821
-				if ($rc['code'] <= 2) {
822
-					$sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE
821
+                if ($rc['code'] <= 2) {
822
+                    $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE
823 823
 					feed_url = ? AND owner_uid = ?");
824
-					$sth->execute([$feed_url, $_SESSION['uid']]);
825
-					$row = $sth->fetch();
824
+                    $sth->execute([$feed_url, $_SESSION['uid']]);
825
+                    $row = $sth->fetch();
826 826
 
827
-					$feed_id = $row["id"];
828
-				} else {
829
-					$feed_id = 0;
830
-				}
827
+                    $feed_id = $row["id"];
828
+                } else {
829
+                    $feed_id = 0;
830
+                }
831 831
 
832
-				if ($feed_id) {
833
-					print "<form method='GET' action=\"$tp_uri\">
832
+                if ($feed_id) {
833
+                    print "<form method='GET' action=\"$tp_uri\">
834 834
 					<input type='hidden' name='tab' value='feedConfig'>
835 835
 					<input type='hidden' name='method' value='editfeed'>
836 836
 					<input type='hidden' name='methodparam' value='$feed_id'>
837 837
 					<button dojoType='dijit.form.Button' class='alt-info' type='submit'>".__("Edit subscription options")."</button>
838 838
 					<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>
839 839
 					</form>";
840
-				}
841
-			}
840
+                }
841
+            }
842 842
 
843
-			print "</div></div></body></html>";
843
+            print "</div></div></body></html>";
844 844
 
845
-		} else {
846
-			render_login_form();
847
-		}
848
-	}
845
+        } else {
846
+            render_login_form();
847
+        }
848
+    }
849 849
 
850
-	public function index() {
851
-		header("Content-Type: text/plain");
852
-		print error_json(13);
853
-	}
850
+    public function index() {
851
+        header("Content-Type: text/plain");
852
+        print error_json(13);
853
+    }
854 854
 
855
-	public function forgotpass() {
856
-		startup_gettext();
857
-		session_start();
855
+    public function forgotpass() {
856
+        startup_gettext();
857
+        session_start();
858 858
 
859
-		@$hash = clean($_REQUEST["hash"]);
859
+        @$hash = clean($_REQUEST["hash"]);
860 860
 
861
-		header('Content-Type: text/html; charset=utf-8');
862
-		?>
861
+        header('Content-Type: text/html; charset=utf-8');
862
+        ?>
863 863
 		<!DOCTYPE html>
864 864
 		<html>
865 865
 		<head>
@@ -868,11 +868,11 @@  discard block
 block discarded – undo
868 868
 			<link rel="icon" type="image/png" sizes="72x72" href="images/favicon-72px.png">
869 869
 			<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
870 870
 			<?php
871
-				echo stylesheet_tag("css/default.css");
872
-				echo javascript_tag("lib/prototype.js");
873
-				echo javascript_tag("lib/dojo/dojo.js");
874
-				echo javascript_tag("lib/dojo/tt-rss-layer.js");
875
-			?>
871
+                echo stylesheet_tag("css/default.css");
872
+                echo javascript_tag("lib/prototype.js");
873
+                echo javascript_tag("lib/dojo/dojo.js");
874
+                echo javascript_tag("lib/dojo/tt-rss-layer.js");
875
+            ?>
876 876
 		</head>
877 877
 		<body class='flat ttrss_utility'>
878 878
 		<div class='container'>
@@ -887,52 +887,52 @@  discard block
 block discarded – undo
887 887
 		</script>
888 888
 		<?php
889 889
 
890
-		print "<h1>".__("Password recovery")."</h1>";
891
-		print "<div class='content'>";
890
+        print "<h1>".__("Password recovery")."</h1>";
891
+        print "<div class='content'>";
892 892
 
893
-		@$method = clean($_POST['method']);
893
+        @$method = clean($_POST['method']);
894 894
 
895
-		if ($hash) {
896
-			$login = clean($_REQUEST["login"]);
895
+        if ($hash) {
896
+            $login = clean($_REQUEST["login"]);
897 897
 
898
-			if ($login) {
899
-				$sth = $this->pdo->prepare("SELECT id, resetpass_token FROM ttrss_users
898
+            if ($login) {
899
+                $sth = $this->pdo->prepare("SELECT id, resetpass_token FROM ttrss_users
900 900
 					WHERE login = ?");
901
-				$sth->execute([$login]);
901
+                $sth->execute([$login]);
902 902
 
903
-				if ($row = $sth->fetch()) {
904
-					$id = $row["id"];
905
-					$resetpass_token_full = $row["resetpass_token"];
906
-					list($timestamp, $resetpass_token) = explode(":", $resetpass_token_full);
903
+                if ($row = $sth->fetch()) {
904
+                    $id = $row["id"];
905
+                    $resetpass_token_full = $row["resetpass_token"];
906
+                    list($timestamp, $resetpass_token) = explode(":", $resetpass_token_full);
907 907
 
908
-					if ($timestamp && $resetpass_token &&
909
-						$timestamp >= time() - 15 * 60 * 60 &&
910
-						$resetpass_token == $hash) {
908
+                    if ($timestamp && $resetpass_token &&
909
+                        $timestamp >= time() - 15 * 60 * 60 &&
910
+                        $resetpass_token == $hash) {
911 911
 
912
-							$sth = $this->pdo->prepare("UPDATE ttrss_users SET resetpass_token = NULL
912
+                            $sth = $this->pdo->prepare("UPDATE ttrss_users SET resetpass_token = NULL
913 913
 								WHERE id = ?");
914
-							$sth->execute([$id]);
914
+                            $sth->execute([$id]);
915 915
 
916
-							Pref_Users::resetUserPassword($id, true);
916
+                            Pref_Users::resetUserPassword($id, true);
917 917
 
918
-							print "<p>"."Completed."."</p>";
918
+                            print "<p>"."Completed."."</p>";
919 919
 
920
-					} else {
921
-						print_error("Some of the information provided is missing or incorrect.");
922
-					}
923
-				} else {
924
-					print_error("Some of the information provided is missing or incorrect.");
925
-				}
926
-			} else {
927
-				print_error("Some of the information provided is missing or incorrect.");
928
-			}
920
+                    } else {
921
+                        print_error("Some of the information provided is missing or incorrect.");
922
+                    }
923
+                } else {
924
+                    print_error("Some of the information provided is missing or incorrect.");
925
+                }
926
+            } else {
927
+                print_error("Some of the information provided is missing or incorrect.");
928
+            }
929 929
 
930
-			print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>";
930
+            print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>";
931 931
 
932
-		} else if (!$method) {
933
-			print_notice(__("You will need to provide valid account name and email. Password reset link will be sent to your email address."));
932
+        } else if (!$method) {
933
+            print_notice(__("You will need to provide valid account name and email. Password reset link will be sent to your email address."));
934 934
 
935
-			print "<form method='POST' action='public.php'>
935
+            print "<form method='POST' action='public.php'>
936 936
 				<input type='hidden' name='method' value='do'>
937 937
 				<input type='hidden' name='op' value='forgotpass'>
938 938
 
@@ -946,10 +946,10 @@  discard block
 block discarded – undo
946 946
 				<input dojoType='dijit.form.TextBox' type='email' name='email' value='' required>
947 947
 				</fieldset>";
948 948
 
949
-			$_SESSION["pwdreset:testvalue1"] = rand(1, 10);
950
-			$_SESSION["pwdreset:testvalue2"] = rand(1, 10);
949
+            $_SESSION["pwdreset:testvalue1"] = rand(1, 10);
950
+            $_SESSION["pwdreset:testvalue2"] = rand(1, 10);
951 951
 
952
-			print "<fieldset>
952
+            print "<fieldset>
953 953
 				<label>".T_sprintf("How much is %d + %d:", $_SESSION["pwdreset:testvalue1"], $_SESSION["pwdreset:testvalue2"])."</label>
954 954
 				<input dojoType='dijit.form.TextBox' type='text' name='test' value='' required>
955 955
 				</fieldset>
@@ -961,111 +961,111 @@  discard block
 block discarded – undo
961 961
 				</fieldset>
962 962
 
963 963
 				</form>";
964
-		} else if ($method == 'do') {
964
+        } else if ($method == 'do') {
965 965
 
966
-			$login = clean($_POST["login"]);
967
-			$email = clean($_POST["email"]);
968
-			$test = clean($_POST["test"]);
966
+            $login = clean($_POST["login"]);
967
+            $email = clean($_POST["email"]);
968
+            $test = clean($_POST["test"]);
969 969
 
970
-			if ($test != ($_SESSION["pwdreset:testvalue1"] + $_SESSION["pwdreset:testvalue2"]) || !$email || !$login) {
971
-				print_error(__('Some of the required form parameters are missing or incorrect.'));
970
+            if ($test != ($_SESSION["pwdreset:testvalue1"] + $_SESSION["pwdreset:testvalue2"]) || !$email || !$login) {
971
+                print_error(__('Some of the required form parameters are missing or incorrect.'));
972 972
 
973
-				print "<form method='GET' action='public.php'>
973
+                print "<form method='GET' action='public.php'>
974 974
 					<input type='hidden' name='op' value='forgotpass'>
975 975
 					<button dojoType='dijit.form.Button' type='submit' class='alt-primary'>".__("Go back")."</button>
976 976
 					</form>";
977 977
 
978
-			} else {
978
+            } else {
979 979
 
980
-				// prevent submitting this form multiple times
981
-				$_SESSION["pwdreset:testvalue1"] = rand(1, 1000);
982
-				$_SESSION["pwdreset:testvalue2"] = rand(1, 1000);
980
+                // prevent submitting this form multiple times
981
+                $_SESSION["pwdreset:testvalue1"] = rand(1, 1000);
982
+                $_SESSION["pwdreset:testvalue2"] = rand(1, 1000);
983 983
 
984
-				$sth = $this->pdo->prepare("SELECT id FROM ttrss_users
984
+                $sth = $this->pdo->prepare("SELECT id FROM ttrss_users
985 985
 					WHERE login = ? AND email = ?");
986
-				$sth->execute([$login, $email]);
986
+                $sth->execute([$login, $email]);
987 987
 
988
-				if ($row = $sth->fetch()) {
989
-					print_notice("Password reset instructions are being sent to your email address.");
988
+                if ($row = $sth->fetch()) {
989
+                    print_notice("Password reset instructions are being sent to your email address.");
990 990
 
991
-					$id = $row["id"];
991
+                    $id = $row["id"];
992 992
 
993
-					if ($id) {
994
-						$resetpass_token = sha1(get_random_bytes(128));
995
-						$resetpass_link = get_self_url_prefix()."/public.php?op=forgotpass&hash=".$resetpass_token.
996
-							"&login=".urlencode($login);
993
+                    if ($id) {
994
+                        $resetpass_token = sha1(get_random_bytes(128));
995
+                        $resetpass_link = get_self_url_prefix()."/public.php?op=forgotpass&hash=".$resetpass_token.
996
+                            "&login=".urlencode($login);
997 997
 
998
-						require_once "lib/MiniTemplator.class.php";
998
+                        require_once "lib/MiniTemplator.class.php";
999 999
 
1000
-						$tpl = new MiniTemplator;
1000
+                        $tpl = new MiniTemplator;
1001 1001
 
1002
-						$tpl->readTemplateFromFile("templates/resetpass_link_template.txt");
1002
+                        $tpl->readTemplateFromFile("templates/resetpass_link_template.txt");
1003 1003
 
1004
-						$tpl->setVariable('LOGIN', $login);
1005
-						$tpl->setVariable('RESETPASS_LINK', $resetpass_link);
1006
-						$tpl->setVariable('TTRSS_HOST', SELF_URL_PATH);
1004
+                        $tpl->setVariable('LOGIN', $login);
1005
+                        $tpl->setVariable('RESETPASS_LINK', $resetpass_link);
1006
+                        $tpl->setVariable('TTRSS_HOST', SELF_URL_PATH);
1007 1007
 
1008
-						$tpl->addBlock('message');
1008
+                        $tpl->addBlock('message');
1009 1009
 
1010
-						$message = "";
1010
+                        $message = "";
1011 1011
 
1012
-						$tpl->generateOutputToString($message);
1012
+                        $tpl->generateOutputToString($message);
1013 1013
 
1014
-						$mailer = new Mailer();
1014
+                        $mailer = new Mailer();
1015 1015
 
1016
-						$rc = $mailer->mail(["to_name" => $login,
1017
-							"to_address" => $email,
1018
-							"subject" => __("[tt-rss] Password reset request"),
1019
-							"message" => $message]);
1016
+                        $rc = $mailer->mail(["to_name" => $login,
1017
+                            "to_address" => $email,
1018
+                            "subject" => __("[tt-rss] Password reset request"),
1019
+                            "message" => $message]);
1020 1020
 
1021
-						if (!$rc) {
1022
-						    print_error($mailer->error());
1023
-						}
1021
+                        if (!$rc) {
1022
+                            print_error($mailer->error());
1023
+                        }
1024 1024
 
1025
-						$resetpass_token_full = time().":".$resetpass_token;
1025
+                        $resetpass_token_full = time().":".$resetpass_token;
1026 1026
 
1027
-						$sth = $this->pdo->prepare("UPDATE ttrss_users
1027
+                        $sth = $this->pdo->prepare("UPDATE ttrss_users
1028 1028
 							SET resetpass_token = ?
1029 1029
 							WHERE login = ? AND email = ?");
1030 1030
 
1031
-						$sth->execute([$resetpass_token_full, $login, $email]);
1031
+                        $sth->execute([$resetpass_token_full, $login, $email]);
1032 1032
 
1033
-					} else {
1034
-						print_error("User ID not found.");
1035
-					}
1033
+                    } else {
1034
+                        print_error("User ID not found.");
1035
+                    }
1036 1036
 
1037
-					print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>";
1037
+                    print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>";
1038 1038
 
1039
-				} else {
1040
-					print_error(__("Sorry, login and email combination not found."));
1039
+                } else {
1040
+                    print_error(__("Sorry, login and email combination not found."));
1041 1041
 
1042
-					print "<form method='GET' action='public.php'>
1042
+                    print "<form method='GET' action='public.php'>
1043 1043
 						<input type='hidden' name='op' value='forgotpass'>
1044 1044
 						<button dojoType='dijit.form.Button' type='submit'>".__("Go back")."</button>
1045 1045
 						</form>";
1046 1046
 
1047
-				}
1048
-			}
1047
+                }
1048
+            }
1049 1049
 
1050
-		}
1050
+        }
1051 1051
 
1052
-		print "</div>";
1053
-		print "</div>";
1054
-		print "</body>";
1055
-		print "</html>";
1052
+        print "</div>";
1053
+        print "</div>";
1054
+        print "</body>";
1055
+        print "</html>";
1056 1056
 
1057
-	}
1057
+    }
1058 1058
 
1059
-	public function dbupdate() {
1060
-		startup_gettext();
1059
+    public function dbupdate() {
1060
+        startup_gettext();
1061 1061
 
1062
-		if (!SINGLE_USER_MODE && $_SESSION["access_level"] < 10) {
1063
-			$_SESSION["login_error_msg"] = __("Your access level is insufficient to run this script.");
1064
-			render_login_form();
1065
-			exit;
1066
-		}
1062
+        if (!SINGLE_USER_MODE && $_SESSION["access_level"] < 10) {
1063
+            $_SESSION["login_error_msg"] = __("Your access level is insufficient to run this script.");
1064
+            render_login_form();
1065
+            exit;
1066
+        }
1067 1067
 
1068
-		?>
1068
+        ?>
1069 1069
 		<!DOCTYPE html>
1070 1070
 		<html>
1071 1071
 			<head>
@@ -1075,11 +1075,11 @@  discard block
 block discarded – undo
1075 1075
 			<link rel="shortcut icon" type="image/png" href="images/favicon.png">
1076 1076
 			<link rel="icon" type="image/png" sizes="72x72" href="images/favicon-72px.png">
1077 1077
 			<?php
1078
-				echo stylesheet_tag("css/default.css");
1079
-				echo javascript_tag("lib/prototype.js");
1080
-				echo javascript_tag("lib/dojo/dojo.js");
1081
-				echo javascript_tag("lib/dojo/tt-rss-layer.js");
1082
-			?>
1078
+                echo stylesheet_tag("css/default.css");
1079
+                echo javascript_tag("lib/prototype.js");
1080
+                echo javascript_tag("lib/dojo/dojo.js");
1081
+                echo javascript_tag("lib/dojo/tt-rss-layer.js");
1082
+            ?>
1083 1083
 			<style type="text/css">
1084 1084
 				span.ok { color : #009000; font-weight : bold; }
1085 1085
 				span.err { color : #ff0000; font-weight : bold; }
@@ -1106,139 +1106,139 @@  discard block
 block discarded – undo
1106 1106
 			<div class="content">
1107 1107
 
1108 1108
 			<?php
1109
-				@$op = clean($_REQUEST["subop"]);
1110
-				$updater = new DbUpdater(DB_TYPE, SCHEMA_VERSION);
1109
+                @$op = clean($_REQUEST["subop"]);
1110
+                $updater = new DbUpdater(DB_TYPE, SCHEMA_VERSION);
1111 1111
 
1112
-				if ($op == "performupdate") {
1113
-					if ($updater->isUpdateRequired()) {
1112
+                if ($op == "performupdate") {
1113
+                    if ($updater->isUpdateRequired()) {
1114 1114
 
1115
-						print "<h2>".T_sprintf("Performing updates to version %d", SCHEMA_VERSION)."</h2>";
1115
+                        print "<h2>".T_sprintf("Performing updates to version %d", SCHEMA_VERSION)."</h2>";
1116 1116
 
1117
-						for ($i = $updater->getSchemaVersion() + 1; $i <= SCHEMA_VERSION; $i++) {
1118
-							print "<ul>";
1117
+                        for ($i = $updater->getSchemaVersion() + 1; $i <= SCHEMA_VERSION; $i++) {
1118
+                            print "<ul>";
1119 1119
 
1120
-							print "<li class='text-info'>".T_sprintf("Updating to version %d", $i)."</li>";
1120
+                            print "<li class='text-info'>".T_sprintf("Updating to version %d", $i)."</li>";
1121 1121
 
1122
-							print "<li>";
1123
-							$result = $updater->performUpdateTo($i, true);
1124
-							print "</li>";
1122
+                            print "<li>";
1123
+                            $result = $updater->performUpdateTo($i, true);
1124
+                            print "</li>";
1125 1125
 
1126
-							if (!$result) {
1127
-								print "</ul>";
1126
+                            if (!$result) {
1127
+                                print "</ul>";
1128 1128
 
1129
-								print_error("One of the updates failed. Either retry the process or perform updates manually.");
1129
+                                print_error("One of the updates failed. Either retry the process or perform updates manually.");
1130 1130
 
1131
-								print "<form method='POST'>
1131
+                                print "<form method='POST'>
1132 1132
 									<input type='hidden' name='subop' value='performupdate'>
1133 1133
 									<button type='submit' dojoType='dijit.form.Button' class='alt-danger' onclick='return confirmOP()'>".__("Try again")."</button>
1134 1134
 									<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>
1135 1135
 								</form>";
1136 1136
 
1137
-								return;
1138
-							} else {
1139
-								print "<li class='text-success'>".__("Completed.")."</li>";
1140
-								print "</ul>";
1141
-							}
1142
-						}
1137
+                                return;
1138
+                            } else {
1139
+                                print "<li class='text-success'>".__("Completed.")."</li>";
1140
+                                print "</ul>";
1141
+                            }
1142
+                        }
1143 1143
 
1144
-						print_notice("Your Tiny Tiny RSS database is now updated to the latest version.");
1144
+                        print_notice("Your Tiny Tiny RSS database is now updated to the latest version.");
1145 1145
 
1146
-						print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>";
1146
+                        print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>";
1147 1147
 
1148
-					} else {
1149
-						print_notice("Tiny Tiny RSS database is up to date.");
1148
+                    } else {
1149
+                        print_notice("Tiny Tiny RSS database is up to date.");
1150 1150
 
1151
-						print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>";
1152
-					}
1153
-				} else {
1154
-					if ($updater->isUpdateRequired()) {
1151
+                        print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>";
1152
+                    }
1153
+                } else {
1154
+                    if ($updater->isUpdateRequired()) {
1155 1155
 
1156
-						print "<h2>".T_sprintf("Tiny Tiny RSS database needs update to the latest version (%d to %d).",
1157
-							$updater->getSchemaVersion(), SCHEMA_VERSION)."</h2>";
1156
+                        print "<h2>".T_sprintf("Tiny Tiny RSS database needs update to the latest version (%d to %d).",
1157
+                            $updater->getSchemaVersion(), SCHEMA_VERSION)."</h2>";
1158 1158
 
1159
-						if (DB_TYPE == "mysql") {
1160
-							print_error("<strong>READ THIS:</strong> Due to MySQL limitations, your database is not completely protected while updating. ".
1161
-								"Errors may put it in an inconsistent state requiring manual rollback. <strong>BACKUP YOUR DATABASE BEFORE CONTINUING.</strong>");
1162
-						} else {
1163
-							print_warning("Please backup your database before proceeding.");
1164
-						}
1159
+                        if (DB_TYPE == "mysql") {
1160
+                            print_error("<strong>READ THIS:</strong> Due to MySQL limitations, your database is not completely protected while updating. ".
1161
+                                "Errors may put it in an inconsistent state requiring manual rollback. <strong>BACKUP YOUR DATABASE BEFORE CONTINUING.</strong>");
1162
+                        } else {
1163
+                            print_warning("Please backup your database before proceeding.");
1164
+                        }
1165 1165
 
1166
-						print "<form method='POST'>
1166
+                        print "<form method='POST'>
1167 1167
 							<input type='hidden' name='subop' value='performupdate'>
1168 1168
 							<button type='submit' dojoType='dijit.form.Button' class='alt-danger' onclick='return confirmOP()'>".__("Perform updates")."</button>
1169 1169
 						</form>";
1170 1170
 
1171
-					} else {
1171
+                    } else {
1172 1172
 
1173
-						print_notice("Tiny Tiny RSS database is up to date.");
1173
+                        print_notice("Tiny Tiny RSS database is up to date.");
1174 1174
 
1175
-						print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>";
1176
-					}
1177
-				}
1178
-			?>
1175
+                        print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>";
1176
+                    }
1177
+                }
1178
+            ?>
1179 1179
 
1180 1180
 			</div>
1181 1181
 			</div>
1182 1182
 			</body>
1183 1183
 			</html>
1184 1184
 		<?php
1185
-	}
1186
-
1187
-	public function cached_url() {
1188
-		list ($cache_dir, $filename) = explode("/", $_GET["file"], 2);
1189
-
1190
-		// we do not allow files with extensions at the moment
1191
-		$filename = str_replace(".", "", $filename);
1192
-
1193
-		$cache = new DiskCache($cache_dir);
1194
-
1195
-		if ($cache->exists($filename)) {
1196
-			$cache->send($filename);
1197
-		} else {
1198
-			header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
1199
-			echo "File not found.";
1200
-		}
1201
-	}
1202
-
1203
-	private function make_article_tag_uri($id, $timestamp) {
1204
-
1205
-		$timestamp = date("Y-m-d", strtotime($timestamp));
1206
-
1207
-		return "tag:".parse_url(get_self_url_prefix(), PHP_URL_HOST).",$timestamp:/$id";
1208
-	}
1209
-
1210
-	// this should be used very carefully because this endpoint is exposed to unauthenticated users
1211
-	// plugin data is not loaded because there's no user context and owner_uid/session may or may not be available
1212
-	// in general, don't do anything user-related in here and do not modify $_SESSION
1213
-	public function pluginhandler() {
1214
-		$host = new PluginHost();
1215
-
1216
-		$plugin_name = clean_filename($_REQUEST["plugin"]);
1217
-		$method = clean($_REQUEST["pmethod"]);
1218
-
1219
-		$host->load($plugin_name, PluginHost::KIND_USER, 0);
1220
-		$host->load_data();
1221
-
1222
-		$plugin = $host->get_plugin($plugin_name);
1223
-
1224
-		if ($plugin) {
1225
-			if (method_exists($plugin, $method)) {
1226
-				if ($plugin->is_public_method($method)) {
1227
-					$plugin->$method();
1228
-				} else {
1229
-					user_error("PluginHandler[PUBLIC]: Requested private method '$method' of plugin '$plugin_name'.", E_USER_WARNING);
1230
-					header("Content-Type: text/json");
1231
-					print error_json(6);
1232
-				}
1233
-			} else {
1234
-				user_error("PluginHandler[PUBLIC]: Requested unknown method '$method' of plugin '$plugin_name'.", E_USER_WARNING);
1235
-				header("Content-Type: text/json");
1236
-				print error_json(13);
1237
-			}
1238
-		} else {
1239
-			user_error("PluginHandler[PUBLIC]: Requested method '$method' of unknown plugin '$plugin_name'.", E_USER_WARNING);
1240
-			header("Content-Type: text/json");
1241
-			print error_json(14);
1242
-		}
1243
-	}
1185
+    }
1186
+
1187
+    public function cached_url() {
1188
+        list ($cache_dir, $filename) = explode("/", $_GET["file"], 2);
1189
+
1190
+        // we do not allow files with extensions at the moment
1191
+        $filename = str_replace(".", "", $filename);
1192
+
1193
+        $cache = new DiskCache($cache_dir);
1194
+
1195
+        if ($cache->exists($filename)) {
1196
+            $cache->send($filename);
1197
+        } else {
1198
+            header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
1199
+            echo "File not found.";
1200
+        }
1201
+    }
1202
+
1203
+    private function make_article_tag_uri($id, $timestamp) {
1204
+
1205
+        $timestamp = date("Y-m-d", strtotime($timestamp));
1206
+
1207
+        return "tag:".parse_url(get_self_url_prefix(), PHP_URL_HOST).",$timestamp:/$id";
1208
+    }
1209
+
1210
+    // this should be used very carefully because this endpoint is exposed to unauthenticated users
1211
+    // plugin data is not loaded because there's no user context and owner_uid/session may or may not be available
1212
+    // in general, don't do anything user-related in here and do not modify $_SESSION
1213
+    public function pluginhandler() {
1214
+        $host = new PluginHost();
1215
+
1216
+        $plugin_name = clean_filename($_REQUEST["plugin"]);
1217
+        $method = clean($_REQUEST["pmethod"]);
1218
+
1219
+        $host->load($plugin_name, PluginHost::KIND_USER, 0);
1220
+        $host->load_data();
1221
+
1222
+        $plugin = $host->get_plugin($plugin_name);
1223
+
1224
+        if ($plugin) {
1225
+            if (method_exists($plugin, $method)) {
1226
+                if ($plugin->is_public_method($method)) {
1227
+                    $plugin->$method();
1228
+                } else {
1229
+                    user_error("PluginHandler[PUBLIC]: Requested private method '$method' of plugin '$plugin_name'.", E_USER_WARNING);
1230
+                    header("Content-Type: text/json");
1231
+                    print error_json(6);
1232
+                }
1233
+            } else {
1234
+                user_error("PluginHandler[PUBLIC]: Requested unknown method '$method' of plugin '$plugin_name'.", E_USER_WARNING);
1235
+                header("Content-Type: text/json");
1236
+                print error_json(13);
1237
+            }
1238
+        } else {
1239
+            user_error("PluginHandler[PUBLIC]: Requested method '$method' of unknown plugin '$plugin_name'.", E_USER_WARNING);
1240
+            header("Content-Type: text/json");
1241
+            print error_json(14);
1242
+        }
1243
+    }
1244 1244
 }
Please login to merge, or discard this patch.
classes/ccache.php 1 patch
Indentation   +134 added lines, -134 removed lines patch added patch discarded remove patch
@@ -1,215 +1,215 @@
 block discarded – undo
1 1
 <?php
2 2
 class CCache {
3
-	public static function zero_all($owner_uid) {
4
-		$pdo = Db::pdo();
3
+    public static function zero_all($owner_uid) {
4
+        $pdo = Db::pdo();
5 5
 
6
-		$sth = $pdo->prepare("UPDATE ttrss_counters_cache SET
6
+        $sth = $pdo->prepare("UPDATE ttrss_counters_cache SET
7 7
 			value = 0 WHERE owner_uid = ?");
8
-		$sth->execute([$owner_uid]);
8
+        $sth->execute([$owner_uid]);
9 9
 
10
-		$sth = $pdo->prepare("UPDATE ttrss_cat_counters_cache SET
10
+        $sth = $pdo->prepare("UPDATE ttrss_cat_counters_cache SET
11 11
 			value = 0 WHERE owner_uid = ?");
12
-		$sth->execute([$owner_uid]);
13
-	}
12
+        $sth->execute([$owner_uid]);
13
+    }
14 14
 
15
-	public static function remove($feed_id, $owner_uid, $is_cat = false) {
15
+    public static function remove($feed_id, $owner_uid, $is_cat = false) {
16 16
 
17
-		$feed_id = (int) $feed_id;
17
+        $feed_id = (int) $feed_id;
18 18
 
19
-		if (!$is_cat) {
20
-			$table = "ttrss_counters_cache";
21
-		} else {
22
-			$table = "ttrss_cat_counters_cache";
23
-		}
19
+        if (!$is_cat) {
20
+            $table = "ttrss_counters_cache";
21
+        } else {
22
+            $table = "ttrss_cat_counters_cache";
23
+        }
24 24
 
25
-		$pdo = Db::pdo();
25
+        $pdo = Db::pdo();
26 26
 
27
-		$sth = $pdo->prepare("DELETE FROM $table WHERE
27
+        $sth = $pdo->prepare("DELETE FROM $table WHERE
28 28
 			feed_id = ? AND owner_uid = ?");
29
-		$sth->execute([$feed_id, $owner_uid]);
29
+        $sth->execute([$feed_id, $owner_uid]);
30 30
 
31
-	}
31
+    }
32 32
 
33
-	public static function update_all($owner_uid) {
33
+    public static function update_all($owner_uid) {
34 34
 
35
-		$pdo = Db::pdo();
35
+        $pdo = Db::pdo();
36 36
 
37
-		if (get_pref('ENABLE_FEED_CATS', $owner_uid)) {
37
+        if (get_pref('ENABLE_FEED_CATS', $owner_uid)) {
38 38
 
39
-			$sth = $pdo->prepare("SELECT feed_id FROM ttrss_cat_counters_cache
39
+            $sth = $pdo->prepare("SELECT feed_id FROM ttrss_cat_counters_cache
40 40
 				WHERE feed_id > 0 AND owner_uid = ?");
41
-			$sth->execute([$owner_uid]);
41
+            $sth->execute([$owner_uid]);
42 42
 
43
-			while ($line = $sth->fetch()) {
44
-				CCache::update($line["feed_id"], $owner_uid, true);
45
-			}
43
+            while ($line = $sth->fetch()) {
44
+                CCache::update($line["feed_id"], $owner_uid, true);
45
+            }
46 46
 
47
-			/* We have to manually include category 0 */
47
+            /* We have to manually include category 0 */
48 48
 
49
-			CCache::update(0, $owner_uid, true);
49
+            CCache::update(0, $owner_uid, true);
50 50
 
51
-		} else {
52
-			$sth = $pdo->prepare("SELECT feed_id FROM ttrss_counters_cache
51
+        } else {
52
+            $sth = $pdo->prepare("SELECT feed_id FROM ttrss_counters_cache
53 53
 				WHERE feed_id > 0 AND owner_uid = ?");
54
-			$sth->execute([$owner_uid]);
54
+            $sth->execute([$owner_uid]);
55 55
 
56
-			while ($line = $sth->fetch()) {
57
-				print CCache::update($line["feed_id"], $owner_uid);
56
+            while ($line = $sth->fetch()) {
57
+                print CCache::update($line["feed_id"], $owner_uid);
58 58
 
59
-			}
59
+            }
60 60
 
61
-		}
62
-	}
61
+        }
62
+    }
63 63
 
64
-	public static function find($feed_id, $owner_uid, $is_cat = false,
65
-						 $no_update = false) {
64
+    public static function find($feed_id, $owner_uid, $is_cat = false,
65
+                            $no_update = false) {
66 66
 
67
-		// "" (null) is valid and should be cast to 0 (uncategorized)
68
-		// everything else i.e. tags are not
69
-		if (!is_numeric($feed_id) && $feed_id) {
70
-					return;
71
-		}
67
+        // "" (null) is valid and should be cast to 0 (uncategorized)
68
+        // everything else i.e. tags are not
69
+        if (!is_numeric($feed_id) && $feed_id) {
70
+                    return;
71
+        }
72 72
 
73
-		$feed_id = (int) $feed_id;
73
+        $feed_id = (int) $feed_id;
74 74
 
75
-		if (!$is_cat) {
76
-			$table = "ttrss_counters_cache";
77
-		} else {
78
-			$table = "ttrss_cat_counters_cache";
79
-		}
75
+        if (!$is_cat) {
76
+            $table = "ttrss_counters_cache";
77
+        } else {
78
+            $table = "ttrss_cat_counters_cache";
79
+        }
80 80
 
81
-		$pdo = Db::pdo();
81
+        $pdo = Db::pdo();
82 82
 
83
-		$sth = $pdo->prepare("SELECT value FROM $table
83
+        $sth = $pdo->prepare("SELECT value FROM $table
84 84
 			WHERE owner_uid = ? AND feed_id = ?
85 85
 			LIMIT 1");
86 86
 
87
-		$sth->execute([$owner_uid, $feed_id]);
87
+        $sth->execute([$owner_uid, $feed_id]);
88 88
 
89
-		if ($row = $sth->fetch()) {
90
-			return $row["value"];
91
-		} else {
92
-			if ($no_update) {
93
-				return -1;
94
-			} else {
95
-				return CCache::update($feed_id, $owner_uid, $is_cat);
96
-			}
97
-		}
89
+        if ($row = $sth->fetch()) {
90
+            return $row["value"];
91
+        } else {
92
+            if ($no_update) {
93
+                return -1;
94
+            } else {
95
+                return CCache::update($feed_id, $owner_uid, $is_cat);
96
+            }
97
+        }
98 98
 
99
-	}
99
+    }
100 100
 
101
-	public static function update($feed_id, $owner_uid, $is_cat = false,
102
-						   $update_pcat = true, $pcat_fast = false) {
101
+    public static function update($feed_id, $owner_uid, $is_cat = false,
102
+                            $update_pcat = true, $pcat_fast = false) {
103 103
 
104
-		// "" (null) is valid and should be cast to 0 (uncategorized)
105
-		// everything else i.e. tags are not
106
-		if (!is_numeric($feed_id) && $feed_id) {
107
-					return;
108
-		}
104
+        // "" (null) is valid and should be cast to 0 (uncategorized)
105
+        // everything else i.e. tags are not
106
+        if (!is_numeric($feed_id) && $feed_id) {
107
+                    return;
108
+        }
109 109
 
110
-		$feed_id = (int) $feed_id;
110
+        $feed_id = (int) $feed_id;
111 111
 
112
-		$prev_unread = CCache::find($feed_id, $owner_uid, $is_cat, true);
112
+        $prev_unread = CCache::find($feed_id, $owner_uid, $is_cat, true);
113 113
 
114
-		/* When updating a label, all we need to do is recalculate feed counters
114
+        /* When updating a label, all we need to do is recalculate feed counters
115 115
 		 * because labels are not cached */
116 116
 
117
-		if ($feed_id < 0) {
118
-			CCache::update_all($owner_uid);
119
-			return;
120
-		}
117
+        if ($feed_id < 0) {
118
+            CCache::update_all($owner_uid);
119
+            return;
120
+        }
121 121
 
122
-		if (!$is_cat) {
123
-			$table = "ttrss_counters_cache";
124
-		} else {
125
-			$table = "ttrss_cat_counters_cache";
126
-		}
122
+        if (!$is_cat) {
123
+            $table = "ttrss_counters_cache";
124
+        } else {
125
+            $table = "ttrss_cat_counters_cache";
126
+        }
127 127
 
128
-		$pdo = Db::pdo();
128
+        $pdo = Db::pdo();
129 129
 
130
-		if ($is_cat && $feed_id >= 0) {
131
-			/* Recalculate counters for child feeds */
130
+        if ($is_cat && $feed_id >= 0) {
131
+            /* Recalculate counters for child feeds */
132 132
 
133
-			if (!$pcat_fast) {
134
-				$sth = $pdo->prepare("SELECT id FROM ttrss_feeds
133
+            if (!$pcat_fast) {
134
+                $sth = $pdo->prepare("SELECT id FROM ttrss_feeds
135 135
 						WHERE owner_uid = :uid AND
136 136
 							(cat_id = :cat OR (:cat = 0 AND cat_id IS NULL))");
137
-				$sth->execute([":uid" => $owner_uid, ":cat" => $feed_id]);
137
+                $sth->execute([":uid" => $owner_uid, ":cat" => $feed_id]);
138 138
 
139
-				while ($line = $sth->fetch()) {
140
-					CCache::update((int) $line["id"], $owner_uid, false, false);
141
-				}
142
-			}
139
+                while ($line = $sth->fetch()) {
140
+                    CCache::update((int) $line["id"], $owner_uid, false, false);
141
+                }
142
+            }
143 143
 
144
-			$sth = $pdo->prepare("SELECT SUM(value) AS sv
144
+            $sth = $pdo->prepare("SELECT SUM(value) AS sv
145 145
 				FROM ttrss_counters_cache, ttrss_feeds
146 146
 				WHERE ttrss_feeds.id = feed_id AND
147 147
 				(cat_id = :cat OR (:cat = 0 AND cat_id IS NULL)) AND
148 148
 				ttrss_counters_cache.owner_uid = :uid AND
149 149
 				ttrss_feeds.owner_uid = :uid");
150
-			$sth->execute([":uid" => $owner_uid, ":cat" => $feed_id]);
151
-			$row = $sth->fetch();
150
+            $sth->execute([":uid" => $owner_uid, ":cat" => $feed_id]);
151
+            $row = $sth->fetch();
152 152
 
153
-			$unread = (int) $row["sv"];
153
+            $unread = (int) $row["sv"];
154 154
 
155
-		} else {
156
-			$unread = (int) Feeds::getFeedArticles($feed_id, $is_cat, true, $owner_uid);
157
-		}
155
+        } else {
156
+            $unread = (int) Feeds::getFeedArticles($feed_id, $is_cat, true, $owner_uid);
157
+        }
158 158
 
159
-		$tr_in_progress = false;
159
+        $tr_in_progress = false;
160 160
 
161
-		try {
162
-			$pdo->beginTransaction();
163
-		} catch (Exception $e) {
164
-			$tr_in_progress = true;
165
-		}
161
+        try {
162
+            $pdo->beginTransaction();
163
+        } catch (Exception $e) {
164
+            $tr_in_progress = true;
165
+        }
166 166
 
167
-		$sth = $pdo->prepare("SELECT feed_id FROM $table
167
+        $sth = $pdo->prepare("SELECT feed_id FROM $table
168 168
 			WHERE owner_uid = ? AND feed_id = ? LIMIT 1");
169
-		$sth->execute([$owner_uid, $feed_id]);
169
+        $sth->execute([$owner_uid, $feed_id]);
170 170
 
171
-		if ($sth->fetch()) {
171
+        if ($sth->fetch()) {
172 172
 
173
-			$sth = $pdo->prepare("update $table SET
173
+            $sth = $pdo->prepare("update $table SET
174 174
 				value = ?, updated = NOW() WHERE
175 175
 				feed_id = ? AND owner_uid = ?");
176 176
 
177
-			$sth->execute([$unread, $feed_id, $owner_uid]);
177
+            $sth->execute([$unread, $feed_id, $owner_uid]);
178 178
 
179
-		} else {
180
-			$sth = $pdo->prepare("INSERT INTO $table
179
+        } else {
180
+            $sth = $pdo->prepare("INSERT INTO $table
181 181
 				(feed_id, value, owner_uid, updated)
182 182
 				VALUES
183 183
 				(?, ?, ?, NOW())");
184
-			$sth->execute([$feed_id, $unread, $owner_uid]);
185
-		}
184
+            $sth->execute([$feed_id, $unread, $owner_uid]);
185
+        }
186 186
 
187
-		if (!$tr_in_progress) {
188
-		    $pdo->commit();
189
-		}
187
+        if (!$tr_in_progress) {
188
+            $pdo->commit();
189
+        }
190 190
 
191
-		if ($feed_id > 0 && $prev_unread != $unread) {
191
+        if ($feed_id > 0 && $prev_unread != $unread) {
192 192
 
193
-			if (!$is_cat) {
193
+            if (!$is_cat) {
194 194
 
195
-				/* Update parent category */
195
+                /* Update parent category */
196 196
 
197
-				if ($update_pcat) {
197
+                if ($update_pcat) {
198 198
 
199
-					$sth = $pdo->prepare("SELECT cat_id FROM ttrss_feeds
199
+                    $sth = $pdo->prepare("SELECT cat_id FROM ttrss_feeds
200 200
 						WHERE owner_uid = ? AND id = ?");
201
-					$sth->execute([$owner_uid, $feed_id]);
202
-
203
-					if ($row = $sth->fetch()) {
204
-						CCache::update((int) $row["cat_id"], $owner_uid, true, true, true);
205
-					}
206
-				}
207
-			}
208
-		} else if ($feed_id < 0) {
209
-			CCache::update_all($owner_uid);
210
-		}
211
-
212
-		return $unread;
213
-	}
201
+                    $sth->execute([$owner_uid, $feed_id]);
202
+
203
+                    if ($row = $sth->fetch()) {
204
+                        CCache::update((int) $row["cat_id"], $owner_uid, true, true, true);
205
+                    }
206
+                }
207
+            }
208
+        } else if ($feed_id < 0) {
209
+            CCache::update_all($owner_uid);
210
+        }
211
+
212
+        return $unread;
213
+    }
214 214
 
215 215
 }
Please login to merge, or discard this patch.
classes/rpc.php 1 patch
Indentation   +396 added lines, -396 removed lines patch added patch discarded remove patch
@@ -1,444 +1,444 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 class RPC extends Handler_Protected {
3 3
 
4
-	public function csrf_ignore($method) {
5
-		$csrf_ignored = array("sanitycheck", "completelabels", "saveprofile");
4
+    public function csrf_ignore($method) {
5
+        $csrf_ignored = array("sanitycheck", "completelabels", "saveprofile");
6 6
 
7
-		return array_search($method, $csrf_ignored) !== false;
8
-	}
7
+        return array_search($method, $csrf_ignored) !== false;
8
+    }
9 9
 
10
-	public function setprofile() {
11
-		$_SESSION["profile"] = (int) clean($_REQUEST["id"]);
10
+    public function setprofile() {
11
+        $_SESSION["profile"] = (int) clean($_REQUEST["id"]);
12 12
 
13
-		// default value
14
-		if (!$_SESSION["profile"]) {
15
-		    $_SESSION["profile"] = null;
16
-		}
17
-	}
13
+        // default value
14
+        if (!$_SESSION["profile"]) {
15
+            $_SESSION["profile"] = null;
16
+        }
17
+    }
18 18
 
19
-	public function remprofiles() {
20
-		$ids = explode(",", trim(clean($_REQUEST["ids"])));
19
+    public function remprofiles() {
20
+        $ids = explode(",", trim(clean($_REQUEST["ids"])));
21 21
 
22
-		foreach ($ids as $id) {
23
-			if ($_SESSION["profile"] != $id) {
24
-				$sth = $this->pdo->prepare("DELETE FROM ttrss_settings_profiles WHERE id = ? AND
22
+        foreach ($ids as $id) {
23
+            if ($_SESSION["profile"] != $id) {
24
+                $sth = $this->pdo->prepare("DELETE FROM ttrss_settings_profiles WHERE id = ? AND
25 25
 							owner_uid = ?");
26
-				$sth->execute([$id, $_SESSION['uid']]);
27
-			}
28
-		}
29
-	}
26
+                $sth->execute([$id, $_SESSION['uid']]);
27
+            }
28
+        }
29
+    }
30 30
 
31
-	// Silent
32
-	public function addprofile() {
33
-		$title = trim(clean($_REQUEST["title"]));
31
+    // Silent
32
+    public function addprofile() {
33
+        $title = trim(clean($_REQUEST["title"]));
34 34
 
35
-		if ($title) {
36
-			$this->pdo->beginTransaction();
35
+        if ($title) {
36
+            $this->pdo->beginTransaction();
37 37
 
38
-			$sth = $this->pdo->prepare("SELECT id FROM ttrss_settings_profiles
38
+            $sth = $this->pdo->prepare("SELECT id FROM ttrss_settings_profiles
39 39
 				WHERE title = ? AND owner_uid = ?");
40
-			$sth->execute([$title, $_SESSION['uid']]);
40
+            $sth->execute([$title, $_SESSION['uid']]);
41 41
 
42
-			if (!$sth->fetch()) {
42
+            if (!$sth->fetch()) {
43 43
 
44
-				$sth = $this->pdo->prepare("INSERT INTO ttrss_settings_profiles (title, owner_uid)
44
+                $sth = $this->pdo->prepare("INSERT INTO ttrss_settings_profiles (title, owner_uid)
45 45
 							VALUES (?, ?)");
46 46
 
47
-				$sth->execute([$title, $_SESSION['uid']]);
47
+                $sth->execute([$title, $_SESSION['uid']]);
48 48
 
49
-				$sth = $this->pdo->prepare("SELECT id FROM ttrss_settings_profiles WHERE
49
+                $sth = $this->pdo->prepare("SELECT id FROM ttrss_settings_profiles WHERE
50 50
 					title = ? AND owner_uid = ?");
51
-				$sth->execute([$title, $_SESSION['uid']]);
51
+                $sth->execute([$title, $_SESSION['uid']]);
52 52
 
53
-				if ($row = $sth->fetch()) {
54
-					$profile_id = $row['id'];
53
+                if ($row = $sth->fetch()) {
54
+                    $profile_id = $row['id'];
55 55
 
56
-					if ($profile_id) {
57
-						initialize_user_prefs($_SESSION["uid"], $profile_id);
58
-					}
59
-				}
60
-			}
56
+                    if ($profile_id) {
57
+                        initialize_user_prefs($_SESSION["uid"], $profile_id);
58
+                    }
59
+                }
60
+            }
61 61
 
62
-			$this->pdo->commit();
63
-		}
64
-	}
62
+            $this->pdo->commit();
63
+        }
64
+    }
65 65
 
66
-	public function saveprofile() {
67
-		$id = clean($_REQUEST["id"]);
68
-		$title = trim(clean($_REQUEST["value"]));
66
+    public function saveprofile() {
67
+        $id = clean($_REQUEST["id"]);
68
+        $title = trim(clean($_REQUEST["value"]));
69 69
 
70
-		if ($id == 0) {
71
-			print __("Default profile");
72
-			return;
73
-		}
70
+        if ($id == 0) {
71
+            print __("Default profile");
72
+            return;
73
+        }
74 74
 
75
-		if ($title) {
76
-			$sth = $this->pdo->prepare("UPDATE ttrss_settings_profiles
75
+        if ($title) {
76
+            $sth = $this->pdo->prepare("UPDATE ttrss_settings_profiles
77 77
 				SET title = ? WHERE id = ? AND
78 78
 					owner_uid = ?");
79 79
 
80
-			$sth->execute([$title, $id, $_SESSION['uid']]);
81
-			print $title;
82
-		}
83
-	}
80
+            $sth->execute([$title, $id, $_SESSION['uid']]);
81
+            print $title;
82
+        }
83
+    }
84 84
 
85
-	// Silent
86
-	public function remarchive() {
87
-		$ids = explode(",", clean($_REQUEST["ids"]));
85
+    // Silent
86
+    public function remarchive() {
87
+        $ids = explode(",", clean($_REQUEST["ids"]));
88 88
 
89
-		$sth = $this->pdo->prepare("DELETE FROM ttrss_archived_feeds WHERE
89
+        $sth = $this->pdo->prepare("DELETE FROM ttrss_archived_feeds WHERE
90 90
 		  		(SELECT COUNT(*) FROM ttrss_user_entries
91 91
 					WHERE orig_feed_id = :id) = 0 AND
92 92
 						id = :id AND owner_uid = :uid");
93 93
 
94
-		foreach ($ids as $id) {
95
-			$sth->execute([":id" => $id, ":uid" => $_SESSION['uid']]);
96
-		}
97
-	}
94
+        foreach ($ids as $id) {
95
+            $sth->execute([":id" => $id, ":uid" => $_SESSION['uid']]);
96
+        }
97
+    }
98 98
 
99
-	public function addfeed() {
100
-		$feed = clean($_REQUEST['feed']);
101
-		$cat = clean($_REQUEST['cat']);
102
-		$need_auth = isset($_REQUEST['need_auth']);
103
-		$login = $need_auth ? clean($_REQUEST['login']) : '';
104
-		$pass = $need_auth ? trim(clean($_REQUEST['pass'])) : '';
99
+    public function addfeed() {
100
+        $feed = clean($_REQUEST['feed']);
101
+        $cat = clean($_REQUEST['cat']);
102
+        $need_auth = isset($_REQUEST['need_auth']);
103
+        $login = $need_auth ? clean($_REQUEST['login']) : '';
104
+        $pass = $need_auth ? trim(clean($_REQUEST['pass'])) : '';
105 105
 
106
-		$rc = Feeds::subscribe_to_feed($feed, $cat, $login, $pass);
106
+        $rc = Feeds::subscribe_to_feed($feed, $cat, $login, $pass);
107 107
 
108
-		print json_encode(array("result" => $rc));
109
-	}
108
+        print json_encode(array("result" => $rc));
109
+    }
110 110
 
111
-	public function togglepref() {
112
-		$key = clean($_REQUEST["key"]);
113
-		set_pref($key, !get_pref($key));
114
-		$value = get_pref($key);
111
+    public function togglepref() {
112
+        $key = clean($_REQUEST["key"]);
113
+        set_pref($key, !get_pref($key));
114
+        $value = get_pref($key);
115 115
 
116
-		print json_encode(array("param" =>$key, "value" => $value));
117
-	}
116
+        print json_encode(array("param" =>$key, "value" => $value));
117
+    }
118 118
 
119
-	public function setpref() {
120
-		// set_pref escapes input, so no need to double escape it here
121
-		$key = clean($_REQUEST['key']);
122
-		$value = $_REQUEST['value'];
119
+    public function setpref() {
120
+        // set_pref escapes input, so no need to double escape it here
121
+        $key = clean($_REQUEST['key']);
122
+        $value = $_REQUEST['value'];
123 123
 
124
-		set_pref($key, $value, false, $key != 'USER_STYLESHEET');
124
+        set_pref($key, $value, false, $key != 'USER_STYLESHEET');
125 125
 
126
-		print json_encode(array("param" =>$key, "value" => $value));
127
-	}
126
+        print json_encode(array("param" =>$key, "value" => $value));
127
+    }
128 128
 
129
-	public function mark() {
130
-		$mark = clean($_REQUEST["mark"]);
131
-		$id = clean($_REQUEST["id"]);
129
+    public function mark() {
130
+        $mark = clean($_REQUEST["mark"]);
131
+        $id = clean($_REQUEST["id"]);
132 132
 
133
-		$sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET marked = ?,
133
+        $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET marked = ?,
134 134
 					last_marked = NOW()
135 135
 					WHERE ref_id = ? AND owner_uid = ?");
136 136
 
137
-		$sth->execute([$mark, $id, $_SESSION['uid']]);
137
+        $sth->execute([$mark, $id, $_SESSION['uid']]);
138 138
 
139
-		print json_encode(array("message" => "UPDATE_COUNTERS"));
140
-	}
139
+        print json_encode(array("message" => "UPDATE_COUNTERS"));
140
+    }
141 141
 
142
-	public function delete() {
143
-		$ids = explode(",", clean($_REQUEST["ids"]));
144
-		$ids_qmarks = arr_qmarks($ids);
142
+    public function delete() {
143
+        $ids = explode(",", clean($_REQUEST["ids"]));
144
+        $ids_qmarks = arr_qmarks($ids);
145 145
 
146
-		$sth = $this->pdo->prepare("DELETE FROM ttrss_user_entries
146
+        $sth = $this->pdo->prepare("DELETE FROM ttrss_user_entries
147 147
 			WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?");
148
-		$sth->execute(array_merge($ids, [$_SESSION['uid']]));
148
+        $sth->execute(array_merge($ids, [$_SESSION['uid']]));
149 149
 
150
-		Article::purge_orphans();
150
+        Article::purge_orphans();
151 151
 
152
-		print json_encode(array("message" => "UPDATE_COUNTERS"));
153
-	}
152
+        print json_encode(array("message" => "UPDATE_COUNTERS"));
153
+    }
154 154
 
155
-	public function unarchive() {
156
-		$ids = explode(",", clean($_REQUEST["ids"]));
155
+    public function unarchive() {
156
+        $ids = explode(",", clean($_REQUEST["ids"]));
157 157
 
158
-		foreach ($ids as $id) {
159
-			$this->pdo->beginTransaction();
158
+        foreach ($ids as $id) {
159
+            $this->pdo->beginTransaction();
160 160
 
161
-			$sth = $this->pdo->prepare("SELECT feed_url,site_url,title FROM ttrss_archived_feeds
161
+            $sth = $this->pdo->prepare("SELECT feed_url,site_url,title FROM ttrss_archived_feeds
162 162
 				WHERE id = (SELECT orig_feed_id FROM ttrss_user_entries WHERE ref_id = :id
163 163
 				AND owner_uid = :uid) AND owner_uid = :uid");
164
-			$sth->execute([":uid" => $_SESSION['uid'], ":id" => $id]);
164
+            $sth->execute([":uid" => $_SESSION['uid'], ":id" => $id]);
165 165
 
166
-			if ($row = $sth->fetch()) {
167
-				$feed_url = $row['feed_url'];
168
-				$site_url = $row['site_url'];
169
-				$title = $row['title'];
166
+            if ($row = $sth->fetch()) {
167
+                $feed_url = $row['feed_url'];
168
+                $site_url = $row['site_url'];
169
+                $title = $row['title'];
170 170
 
171
-				$sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE feed_url = ?
171
+                $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE feed_url = ?
172 172
 					AND owner_uid = ?");
173
-				$sth->execute([$feed_url, $_SESSION['uid']]);
173
+                $sth->execute([$feed_url, $_SESSION['uid']]);
174 174
 
175
-				if ($row = $sth->fetch()) {
176
-					$feed_id = $row["id"];
177
-				} else {
178
-					if (!$title) {
179
-					    $title = '[Unknown]';
180
-					}
175
+                if ($row = $sth->fetch()) {
176
+                    $feed_id = $row["id"];
177
+                } else {
178
+                    if (!$title) {
179
+                        $title = '[Unknown]';
180
+                    }
181 181
 
182
-					$sth = $this->pdo->prepare("INSERT INTO ttrss_feeds
182
+                    $sth = $this->pdo->prepare("INSERT INTO ttrss_feeds
183 183
 							(owner_uid,feed_url,site_url,title,cat_id,auth_login,auth_pass,update_method)
184 184
 							VALUES (?, ?, ?, ?, NULL, '', '', 0)");
185
-					$sth->execute([$_SESSION['uid'], $feed_url, $site_url, $title]);
185
+                    $sth->execute([$_SESSION['uid'], $feed_url, $site_url, $title]);
186 186
 
187
-					$sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE feed_url = ?
187
+                    $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE feed_url = ?
188 188
 						AND owner_uid = ?");
189
-					$sth->execute([$feed_url, $_SESSION['uid']]);
189
+                    $sth->execute([$feed_url, $_SESSION['uid']]);
190 190
 
191
-					if ($row = $sth->fetch()) {
192
-						$feed_id = $row['id'];
193
-					}
194
-				}
191
+                    if ($row = $sth->fetch()) {
192
+                        $feed_id = $row['id'];
193
+                    }
194
+                }
195 195
 
196
-				if ($feed_id) {
197
-					$sth = $this->pdo->prepare("UPDATE ttrss_user_entries
196
+                if ($feed_id) {
197
+                    $sth = $this->pdo->prepare("UPDATE ttrss_user_entries
198 198
 						SET feed_id = ?, orig_feed_id = NULL
199 199
 						WHERE ref_id = ? AND owner_uid = ?");
200
-					$sth->execute([$feed_id, $id, $_SESSION['uid']]);
201
-				}
202
-			}
200
+                    $sth->execute([$feed_id, $id, $_SESSION['uid']]);
201
+                }
202
+            }
203 203
 
204
-			$this->pdo->commit();
205
-		}
204
+            $this->pdo->commit();
205
+        }
206 206
 
207
-		print json_encode(array("message" => "UPDATE_COUNTERS"));
208
-	}
207
+        print json_encode(array("message" => "UPDATE_COUNTERS"));
208
+    }
209 209
 
210
-	public function archive() {
211
-		$ids = explode(",", clean($_REQUEST["ids"]));
210
+    public function archive() {
211
+        $ids = explode(",", clean($_REQUEST["ids"]));
212 212
 
213
-		foreach ($ids as $id) {
214
-			$this->archive_article($id, $_SESSION["uid"]);
215
-		}
213
+        foreach ($ids as $id) {
214
+            $this->archive_article($id, $_SESSION["uid"]);
215
+        }
216 216
 
217
-		print json_encode(array("message" => "UPDATE_COUNTERS"));
218
-	}
217
+        print json_encode(array("message" => "UPDATE_COUNTERS"));
218
+    }
219 219
 
220
-	private function archive_article($id, $owner_uid) {
221
-		$this->pdo->beginTransaction();
220
+    private function archive_article($id, $owner_uid) {
221
+        $this->pdo->beginTransaction();
222 222
 
223
-		if (!$owner_uid) {
224
-		    $owner_uid = $_SESSION['uid'];
225
-		}
223
+        if (!$owner_uid) {
224
+            $owner_uid = $_SESSION['uid'];
225
+        }
226 226
 
227
-		$sth = $this->pdo->prepare("SELECT feed_id FROM ttrss_user_entries
227
+        $sth = $this->pdo->prepare("SELECT feed_id FROM ttrss_user_entries
228 228
 			WHERE ref_id = ? AND owner_uid = ?");
229
-		$sth->execute([$id, $owner_uid]);
229
+        $sth->execute([$id, $owner_uid]);
230 230
 
231
-		if ($row = $sth->fetch()) {
231
+        if ($row = $sth->fetch()) {
232 232
 
233
-			/* prepare the archived table */
233
+            /* prepare the archived table */
234 234
 
235
-			$feed_id = (int) $row['feed_id'];
235
+            $feed_id = (int) $row['feed_id'];
236 236
 
237
-			if ($feed_id) {
238
-				$sth = $this->pdo->prepare("SELECT id FROM ttrss_archived_feeds
237
+            if ($feed_id) {
238
+                $sth = $this->pdo->prepare("SELECT id FROM ttrss_archived_feeds
239 239
 					WHERE id = ? AND owner_uid = ?");
240
-				$sth->execute([$feed_id, $owner_uid]);
240
+                $sth->execute([$feed_id, $owner_uid]);
241 241
 
242
-				if ($row = $sth->fetch()) {
243
-					$new_feed_id = $row['id'];
244
-				} else {
245
-					$row = $this->pdo->query("SELECT MAX(id) AS id FROM ttrss_archived_feeds")->fetch();
246
-					$new_feed_id = (int) $row['id'] + 1;
242
+                if ($row = $sth->fetch()) {
243
+                    $new_feed_id = $row['id'];
244
+                } else {
245
+                    $row = $this->pdo->query("SELECT MAX(id) AS id FROM ttrss_archived_feeds")->fetch();
246
+                    $new_feed_id = (int) $row['id'] + 1;
247 247
 
248
-					$sth = $this->pdo->prepare("INSERT INTO ttrss_archived_feeds
248
+                    $sth = $this->pdo->prepare("INSERT INTO ttrss_archived_feeds
249 249
 						(id, owner_uid, title, feed_url, site_url, created)
250 250
 							SELECT ?, owner_uid, title, feed_url, site_url, NOW() from ttrss_feeds
251 251
 							  	WHERE id = ?");
252 252
 
253
-					$sth->execute([$new_feed_id, $feed_id]);
254
-				}
253
+                    $sth->execute([$new_feed_id, $feed_id]);
254
+                }
255 255
 
256
-				$sth = $this->pdo->prepare("UPDATE ttrss_user_entries
256
+                $sth = $this->pdo->prepare("UPDATE ttrss_user_entries
257 257
 					SET orig_feed_id = ?, feed_id = NULL
258 258
 					WHERE ref_id = ? AND owner_uid = ?");
259
-				$sth->execute([$new_feed_id, $id, $owner_uid]);
260
-			}
261
-		}
259
+                $sth->execute([$new_feed_id, $id, $owner_uid]);
260
+            }
261
+        }
262 262
 
263
-		$this->pdo->commit();
264
-	}
263
+        $this->pdo->commit();
264
+    }
265 265
 
266
-	public function publ() {
267
-		$pub = clean($_REQUEST["pub"]);
268
-		$id = clean($_REQUEST["id"]);
266
+    public function publ() {
267
+        $pub = clean($_REQUEST["pub"]);
268
+        $id = clean($_REQUEST["id"]);
269 269
 
270
-		$sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET
270
+        $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET
271 271
 			published = ?, last_published = NOW()
272 272
 			WHERE ref_id = ? AND owner_uid = ?");
273 273
 
274
-		$sth->execute([$pub, $id, $_SESSION['uid']]);
274
+        $sth->execute([$pub, $id, $_SESSION['uid']]);
275 275
 
276
-		print json_encode(array("message" => "UPDATE_COUNTERS"));
277
-	}
276
+        print json_encode(array("message" => "UPDATE_COUNTERS"));
277
+    }
278 278
 
279
-	public function getAllCounters() {
280
-		@$seq = (int) $_REQUEST['seq'];
279
+    public function getAllCounters() {
280
+        @$seq = (int) $_REQUEST['seq'];
281 281
 
282
-		$reply = [
283
-			'counters' => Counters::getAllCounters(),
284
-			'seq' => $seq
285
-		];
282
+        $reply = [
283
+            'counters' => Counters::getAllCounters(),
284
+            'seq' => $seq
285
+        ];
286 286
 
287
-		if ($seq % 2 == 0) {
288
-					$reply['runtime-info'] = make_runtime_info();
289
-		}
287
+        if ($seq % 2 == 0) {
288
+                    $reply['runtime-info'] = make_runtime_info();
289
+        }
290 290
 
291
-		print json_encode($reply);
292
-	}
291
+        print json_encode($reply);
292
+    }
293 293
 
294
-	/* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */
295
-	public function catchupSelected() {
296
-		$ids = explode(",", clean($_REQUEST["ids"]));
297
-		$cmode = (int) clean($_REQUEST["cmode"]);
294
+    /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */
295
+    public function catchupSelected() {
296
+        $ids = explode(",", clean($_REQUEST["ids"]));
297
+        $cmode = (int) clean($_REQUEST["cmode"]);
298 298
 
299
-		Article::catchupArticlesById($ids, $cmode);
299
+        Article::catchupArticlesById($ids, $cmode);
300 300
 
301
-		print json_encode(array("message" => "UPDATE_COUNTERS", "ids" => $ids));
302
-	}
301
+        print json_encode(array("message" => "UPDATE_COUNTERS", "ids" => $ids));
302
+    }
303 303
 
304
-	public function markSelected() {
305
-		$ids = explode(",", clean($_REQUEST["ids"]));
306
-		$cmode = (int) clean($_REQUEST["cmode"]);
304
+    public function markSelected() {
305
+        $ids = explode(",", clean($_REQUEST["ids"]));
306
+        $cmode = (int) clean($_REQUEST["cmode"]);
307 307
 
308
-		$this->markArticlesById($ids, $cmode);
308
+        $this->markArticlesById($ids, $cmode);
309 309
 
310
-		print json_encode(array("message" => "UPDATE_COUNTERS"));
311
-	}
310
+        print json_encode(array("message" => "UPDATE_COUNTERS"));
311
+    }
312 312
 
313
-	public function publishSelected() {
314
-		$ids = explode(",", clean($_REQUEST["ids"]));
315
-		$cmode = (int) clean($_REQUEST["cmode"]);
313
+    public function publishSelected() {
314
+        $ids = explode(",", clean($_REQUEST["ids"]));
315
+        $cmode = (int) clean($_REQUEST["cmode"]);
316 316
 
317
-		$this->publishArticlesById($ids, $cmode);
317
+        $this->publishArticlesById($ids, $cmode);
318 318
 
319
-		print json_encode(array("message" => "UPDATE_COUNTERS"));
320
-	}
319
+        print json_encode(array("message" => "UPDATE_COUNTERS"));
320
+    }
321 321
 
322
-	public function sanityCheck() {
323
-		$_SESSION["hasAudio"] = clean($_REQUEST["hasAudio"]) === "true";
324
-		$_SESSION["hasSandbox"] = clean($_REQUEST["hasSandbox"]) === "true";
325
-		$_SESSION["hasMp3"] = clean($_REQUEST["hasMp3"]) === "true";
326
-		$_SESSION["clientTzOffset"] = clean($_REQUEST["clientTzOffset"]);
322
+    public function sanityCheck() {
323
+        $_SESSION["hasAudio"] = clean($_REQUEST["hasAudio"]) === "true";
324
+        $_SESSION["hasSandbox"] = clean($_REQUEST["hasSandbox"]) === "true";
325
+        $_SESSION["hasMp3"] = clean($_REQUEST["hasMp3"]) === "true";
326
+        $_SESSION["clientTzOffset"] = clean($_REQUEST["clientTzOffset"]);
327 327
 
328
-		$reply = array();
328
+        $reply = array();
329 329
 
330
-		$reply['error'] = sanity_check();
330
+        $reply['error'] = sanity_check();
331 331
 
332
-		if ($reply['error']['code'] == 0) {
333
-			$reply['init-params'] = make_init_params();
334
-			$reply['runtime-info'] = make_runtime_info();
335
-		}
332
+        if ($reply['error']['code'] == 0) {
333
+            $reply['init-params'] = make_init_params();
334
+            $reply['runtime-info'] = make_runtime_info();
335
+        }
336 336
 
337
-		print json_encode($reply);
338
-	}
337
+        print json_encode($reply);
338
+    }
339 339
 
340
-	public function completeLabels() {
341
-		$search = clean($_REQUEST["search"]);
340
+    public function completeLabels() {
341
+        $search = clean($_REQUEST["search"]);
342 342
 
343
-		$sth = $this->pdo->prepare("SELECT DISTINCT caption FROM
343
+        $sth = $this->pdo->prepare("SELECT DISTINCT caption FROM
344 344
 				ttrss_labels2
345 345
 				WHERE owner_uid = ? AND
346 346
 				LOWER(caption) LIKE LOWER(?) ORDER BY caption
347 347
 				LIMIT 5");
348
-		$sth->execute([$_SESSION['uid'], "%$search%"]);
348
+        $sth->execute([$_SESSION['uid'], "%$search%"]);
349 349
 
350
-		print "<ul>";
351
-		while ($line = $sth->fetch()) {
352
-			print "<li>".$line["caption"]."</li>";
353
-		}
354
-		print "</ul>";
355
-	}
350
+        print "<ul>";
351
+        while ($line = $sth->fetch()) {
352
+            print "<li>".$line["caption"]."</li>";
353
+        }
354
+        print "</ul>";
355
+    }
356 356
 
357
-	// Silent
358
-	public function massSubscribe() {
357
+    // Silent
358
+    public function massSubscribe() {
359 359
 
360
-		$payload = json_decode(clean($_REQUEST["payload"]), false);
361
-		$mode = clean($_REQUEST["mode"]);
360
+        $payload = json_decode(clean($_REQUEST["payload"]), false);
361
+        $mode = clean($_REQUEST["mode"]);
362 362
 
363
-		if (!$payload || !is_array($payload)) {
364
-		    return;
365
-		}
363
+        if (!$payload || !is_array($payload)) {
364
+            return;
365
+        }
366 366
 
367
-		if ($mode == 1) {
368
-			foreach ($payload as $feed) {
367
+        if ($mode == 1) {
368
+            foreach ($payload as $feed) {
369 369
 
370
-				$title = $feed[0];
371
-				$feed_url = $feed[1];
370
+                $title = $feed[0];
371
+                $feed_url = $feed[1];
372 372
 
373
-				$sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE
373
+                $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE
374 374
 					feed_url = ? AND owner_uid = ?");
375
-				$sth->execute([$feed_url, $_SESSION['uid']]);
375
+                $sth->execute([$feed_url, $_SESSION['uid']]);
376 376
 
377
-				if (!$sth->fetch()) {
378
-					$sth = $this->pdo->prepare("INSERT INTO ttrss_feeds
377
+                if (!$sth->fetch()) {
378
+                    $sth = $this->pdo->prepare("INSERT INTO ttrss_feeds
379 379
 									(owner_uid,feed_url,title,cat_id,site_url)
380 380
 									VALUES (?, ?, ?, NULL, '')");
381 381
 
382
-					$sth->execute([$_SESSION['uid'], $feed_url, $title]);
383
-				}
384
-			}
385
-		} else if ($mode == 2) {
386
-			// feed archive
387
-			foreach ($payload as $id) {
388
-				$sth = $this->pdo->prepare("SELECT * FROM ttrss_archived_feeds
382
+                    $sth->execute([$_SESSION['uid'], $feed_url, $title]);
383
+                }
384
+            }
385
+        } else if ($mode == 2) {
386
+            // feed archive
387
+            foreach ($payload as $id) {
388
+                $sth = $this->pdo->prepare("SELECT * FROM ttrss_archived_feeds
389 389
 					WHERE id = ? AND owner_uid = ?");
390
-				$sth->execute([$id, $_SESSION['uid']]);
390
+                $sth->execute([$id, $_SESSION['uid']]);
391 391
 
392
-				if ($row = $sth->fetch()) {
393
-					$site_url = $row['site_url'];
394
-					$feed_url = $row['feed_url'];
395
-					$title = $row['title'];
392
+                if ($row = $sth->fetch()) {
393
+                    $site_url = $row['site_url'];
394
+                    $feed_url = $row['feed_url'];
395
+                    $title = $row['title'];
396 396
 
397
-					$sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE
397
+                    $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE
398 398
 						feed_url = ? AND owner_uid = ?");
399
-					$sth->execute([$feed_url, $_SESSION['uid']]);
399
+                    $sth->execute([$feed_url, $_SESSION['uid']]);
400 400
 
401
-					if (!$sth->fetch()) {
402
-						$sth = $this->pdo->prepare("INSERT INTO ttrss_feeds
401
+                    if (!$sth->fetch()) {
402
+                        $sth = $this->pdo->prepare("INSERT INTO ttrss_feeds
403 403
 								(owner_uid,feed_url,title,cat_id,site_url)
404 404
 									VALUES (?, ?, ?, NULL, ?)");
405 405
 
406
-						$sth->execute([$_SESSION['uid'], $feed_url, $title, $site_url]);
407
-					}
408
-				}
409
-			}
410
-		}
411
-	}
406
+                        $sth->execute([$_SESSION['uid'], $feed_url, $title, $site_url]);
407
+                    }
408
+                }
409
+            }
410
+        }
411
+    }
412 412
 
413
-	public function catchupFeed() {
414
-		$feed_id = clean($_REQUEST['feed_id']);
415
-		$is_cat = clean($_REQUEST['is_cat']) == "true";
416
-		$mode = clean($_REQUEST['mode']);
417
-		$search_query = clean($_REQUEST['search_query']);
418
-		$search_lang = clean($_REQUEST['search_lang']);
413
+    public function catchupFeed() {
414
+        $feed_id = clean($_REQUEST['feed_id']);
415
+        $is_cat = clean($_REQUEST['is_cat']) == "true";
416
+        $mode = clean($_REQUEST['mode']);
417
+        $search_query = clean($_REQUEST['search_query']);
418
+        $search_lang = clean($_REQUEST['search_lang']);
419 419
 
420
-		Feeds::catchup_feed($feed_id, $is_cat, false, $mode, [$search_query, $search_lang]);
420
+        Feeds::catchup_feed($feed_id, $is_cat, false, $mode, [$search_query, $search_lang]);
421 421
 
422
-		// return counters here synchronously so that frontend can figure out next unread feed properly
423
-		print json_encode(['counters' => Counters::getAllCounters()]);
422
+        // return counters here synchronously so that frontend can figure out next unread feed properly
423
+        print json_encode(['counters' => Counters::getAllCounters()]);
424 424
 
425
-		//print json_encode(array("message" => "UPDATE_COUNTERS"));
426
-	}
425
+        //print json_encode(array("message" => "UPDATE_COUNTERS"));
426
+    }
427 427
 
428
-	public function setpanelmode() {
429
-		$wide = (int) clean($_REQUEST["wide"]);
428
+    public function setpanelmode() {
429
+        $wide = (int) clean($_REQUEST["wide"]);
430 430
 
431
-		setcookie("ttrss_widescreen", $wide,
432
-			time() + COOKIE_LIFETIME_LONG);
431
+        setcookie("ttrss_widescreen", $wide,
432
+            time() + COOKIE_LIFETIME_LONG);
433 433
 
434
-		print json_encode(array("wide" => $wide));
435
-	}
434
+        print json_encode(array("wide" => $wide));
435
+    }
436 436
 
437
-	public static function updaterandomfeed_real() {
437
+    public static function updaterandomfeed_real() {
438 438
 
439
-		// Test if the feed need a update (update interval exceded).
440
-		if (DB_TYPE == "pgsql") {
441
-			$update_limit_qpart = "AND ((
439
+        // Test if the feed need a update (update interval exceded).
440
+        if (DB_TYPE == "pgsql") {
441
+            $update_limit_qpart = "AND ((
442 442
 					ttrss_feeds.update_interval = 0
443 443
 					AND ttrss_feeds.last_updated < NOW() - CAST((ttrss_user_prefs.value || ' minutes') AS INTERVAL)
444 444
 				) OR (
@@ -446,8 +446,8 @@  discard block
 block discarded – undo
446 446
 					AND ttrss_feeds.last_updated < NOW() - CAST((ttrss_feeds.update_interval || ' minutes') AS INTERVAL)
447 447
 				) OR ttrss_feeds.last_updated IS NULL
448 448
 				OR last_updated = '1970-01-01 00:00:00')";
449
-		} else {
450
-			$update_limit_qpart = "AND ((
449
+        } else {
450
+            $update_limit_qpart = "AND ((
451 451
 					ttrss_feeds.update_interval = 0
452 452
 					AND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL CONVERT(ttrss_user_prefs.value, SIGNED INTEGER) MINUTE)
453 453
 				) OR (
@@ -455,28 +455,28 @@  discard block
 block discarded – undo
455 455
 					AND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL ttrss_feeds.update_interval MINUTE)
456 456
 				) OR ttrss_feeds.last_updated IS NULL
457 457
 				OR last_updated = '1970-01-01 00:00:00')";
458
-		}
458
+        }
459 459
 
460
-		// Test if feed is currently being updated by another process.
461
-		if (DB_TYPE == "pgsql") {
462
-			$updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < NOW() - INTERVAL '5 minutes')";
463
-		} else {
464
-			$updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < DATE_SUB(NOW(), INTERVAL 5 MINUTE))";
465
-		}
460
+        // Test if feed is currently being updated by another process.
461
+        if (DB_TYPE == "pgsql") {
462
+            $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < NOW() - INTERVAL '5 minutes')";
463
+        } else {
464
+            $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < DATE_SUB(NOW(), INTERVAL 5 MINUTE))";
465
+        }
466 466
 
467
-		$random_qpart = sql_random_function();
467
+        $random_qpart = sql_random_function();
468 468
 
469
-		$pdo = Db::pdo();
469
+        $pdo = Db::pdo();
470 470
 
471
-		// we could be invoked from public.php with no active session
472
-		if ($_SESSION["uid"]) {
473
-			$owner_check_qpart = "AND ttrss_feeds.owner_uid = ".$pdo->quote($_SESSION["uid"]);
474
-		} else {
475
-			$owner_check_qpart = "";
476
-		}
471
+        // we could be invoked from public.php with no active session
472
+        if ($_SESSION["uid"]) {
473
+            $owner_check_qpart = "AND ttrss_feeds.owner_uid = ".$pdo->quote($_SESSION["uid"]);
474
+        } else {
475
+            $owner_check_qpart = "";
476
+        }
477 477
 
478
-		// We search for feed needing update.
479
-		$res = $pdo->query("SELECT ttrss_feeds.feed_url,ttrss_feeds.id
478
+        // We search for feed needing update.
479
+        $res = $pdo->query("SELECT ttrss_feeds.feed_url,ttrss_feeds.id
480 480
 			FROM
481 481
 				ttrss_feeds, ttrss_users, ttrss_user_prefs
482 482
 			WHERE
@@ -488,139 +488,139 @@  discard block
 block discarded – undo
488 488
 				$updstart_thresh_qpart
489 489
 			ORDER BY $random_qpart LIMIT 30");
490 490
 
491
-		$num_updated = 0;
491
+        $num_updated = 0;
492 492
 
493
-		$tstart = time();
493
+        $tstart = time();
494 494
 
495
-		while ($line = $res->fetch()) {
496
-			$feed_id = $line["id"];
495
+        while ($line = $res->fetch()) {
496
+            $feed_id = $line["id"];
497 497
 
498
-			if (time() - $tstart < ini_get("max_execution_time") * 0.7) {
499
-				RSSUtils::update_rss_feed($feed_id, true);
500
-				++$num_updated;
501
-			} else {
502
-				break;
503
-			}
504
-		}
498
+            if (time() - $tstart < ini_get("max_execution_time") * 0.7) {
499
+                RSSUtils::update_rss_feed($feed_id, true);
500
+                ++$num_updated;
501
+            } else {
502
+                break;
503
+            }
504
+        }
505 505
 
506
-		// Purge orphans and cleanup tags
507
-		Article::purge_orphans();
508
-		//cleanup_tags(14, 50000);
506
+        // Purge orphans and cleanup tags
507
+        Article::purge_orphans();
508
+        //cleanup_tags(14, 50000);
509 509
 
510
-		if ($num_updated > 0) {
511
-			print json_encode(array("message" => "UPDATE_COUNTERS",
512
-				"num_updated" => $num_updated));
513
-		} else {
514
-			print json_encode(array("message" => "NOTHING_TO_UPDATE"));
515
-		}
510
+        if ($num_updated > 0) {
511
+            print json_encode(array("message" => "UPDATE_COUNTERS",
512
+                "num_updated" => $num_updated));
513
+        } else {
514
+            print json_encode(array("message" => "NOTHING_TO_UPDATE"));
515
+        }
516 516
 
517
-	}
517
+    }
518 518
 
519
-	public function updaterandomfeed() {
520
-		RPC::updaterandomfeed_real();
521
-	}
519
+    public function updaterandomfeed() {
520
+        RPC::updaterandomfeed_real();
521
+    }
522 522
 
523
-	private function markArticlesById($ids, $cmode) {
523
+    private function markArticlesById($ids, $cmode) {
524 524
 
525
-		$ids_qmarks = arr_qmarks($ids);
525
+        $ids_qmarks = arr_qmarks($ids);
526 526
 
527
-		if ($cmode == 0) {
528
-			$sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET
527
+        if ($cmode == 0) {
528
+            $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET
529 529
 				marked = false, last_marked = NOW()
530 530
 					WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?");
531
-		} else if ($cmode == 1) {
532
-			$sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET
531
+        } else if ($cmode == 1) {
532
+            $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET
533 533
 				marked = true, last_marked = NOW()
534 534
 					WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?");
535
-		} else {
536
-			$sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET
535
+        } else {
536
+            $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET
537 537
 				marked = NOT marked,last_marked = NOW()
538 538
 					WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?");
539
-		}
539
+        }
540 540
 
541
-		$sth->execute(array_merge($ids, [$_SESSION['uid']]));
542
-	}
541
+        $sth->execute(array_merge($ids, [$_SESSION['uid']]));
542
+    }
543 543
 
544
-	private function publishArticlesById($ids, $cmode) {
544
+    private function publishArticlesById($ids, $cmode) {
545 545
 
546
-		$ids_qmarks = arr_qmarks($ids);
546
+        $ids_qmarks = arr_qmarks($ids);
547 547
 
548
-		if ($cmode == 0) {
549
-			$sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET
548
+        if ($cmode == 0) {
549
+            $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET
550 550
 				published = false, last_published = NOW()
551 551
 					WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?");
552
-		} else if ($cmode == 1) {
553
-			$sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET
552
+        } else if ($cmode == 1) {
553
+            $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET
554 554
 				published = true, last_published = NOW()
555 555
 					WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?");
556
-		} else {
557
-			$sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET
556
+        } else {
557
+            $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET
558 558
 				published = NOT published,last_published = NOW()
559 559
 					WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?");
560
-		}
560
+        }
561 561
 
562
-		$sth->execute(array_merge($ids, [$_SESSION['uid']]));
563
-	}
562
+        $sth->execute(array_merge($ids, [$_SESSION['uid']]));
563
+    }
564 564
 
565
-	public function getlinktitlebyid() {
566
-		$id = clean($_REQUEST['id']);
565
+    public function getlinktitlebyid() {
566
+        $id = clean($_REQUEST['id']);
567 567
 
568
-		$sth = $this->pdo->prepare("SELECT link, title FROM ttrss_entries, ttrss_user_entries
568
+        $sth = $this->pdo->prepare("SELECT link, title FROM ttrss_entries, ttrss_user_entries
569 569
 			WHERE ref_id = ? AND ref_id = id AND owner_uid = ?");
570
-		$sth->execute([$id, $_SESSION['uid']]);
570
+        $sth->execute([$id, $_SESSION['uid']]);
571 571
 
572
-		if ($row = $sth->fetch()) {
573
-			$link = $row['link'];
574
-			$title = $row['title'];
572
+        if ($row = $sth->fetch()) {
573
+            $link = $row['link'];
574
+            $title = $row['title'];
575 575
 
576
-			echo json_encode(array("link" => $link, "title" => $title));
577
-		} else {
578
-			echo json_encode(array("error" => "ARTICLE_NOT_FOUND"));
579
-		}
580
-	}
576
+            echo json_encode(array("link" => $link, "title" => $title));
577
+        } else {
578
+            echo json_encode(array("error" => "ARTICLE_NOT_FOUND"));
579
+        }
580
+    }
581 581
 
582
-	public function log() {
583
-		$msg = clean($_REQUEST['msg']);
584
-		$file = clean_filename($_REQUEST['file']);
585
-		$line = (int) clean($_REQUEST['line']);
586
-		$context = clean($_REQUEST['context']);
582
+    public function log() {
583
+        $msg = clean($_REQUEST['msg']);
584
+        $file = clean_filename($_REQUEST['file']);
585
+        $line = (int) clean($_REQUEST['line']);
586
+        $context = clean($_REQUEST['context']);
587 587
 
588
-		if ($msg) {
589
-			Logger::get()->log_error(E_USER_WARNING,
590
-				$msg, 'client-js:'.$file, $line, $context);
588
+        if ($msg) {
589
+            Logger::get()->log_error(E_USER_WARNING,
590
+                $msg, 'client-js:'.$file, $line, $context);
591 591
 
592
-			echo json_encode(array("message" => "HOST_ERROR_LOGGED"));
593
-		} else {
594
-			echo json_encode(array("error" => "MESSAGE_NOT_FOUND"));
595
-		}
592
+            echo json_encode(array("message" => "HOST_ERROR_LOGGED"));
593
+        } else {
594
+            echo json_encode(array("error" => "MESSAGE_NOT_FOUND"));
595
+        }
596 596
 
597
-	}
597
+    }
598 598
 
599
-	public function checkforupdates() {
600
-		$rv = [];
599
+    public function checkforupdates() {
600
+        $rv = [];
601 601
 
602
-		$git_timestamp = false;
603
-		$git_commit = false;
602
+        $git_timestamp = false;
603
+        $git_commit = false;
604 604
 
605
-		get_version($git_commit, $git_timestamp);
605
+        get_version($git_commit, $git_timestamp);
606 606
 
607
-		if (CHECK_FOR_UPDATES && $_SESSION["access_level"] >= 10 && $git_timestamp) {
608
-			$content = @fetch_file_contents(["url" => "https://srv.tt-rss.org/version.json"]);
607
+        if (CHECK_FOR_UPDATES && $_SESSION["access_level"] >= 10 && $git_timestamp) {
608
+            $content = @fetch_file_contents(["url" => "https://srv.tt-rss.org/version.json"]);
609 609
 
610
-			if ($content) {
611
-				$content = json_decode($content, true);
610
+            if ($content) {
611
+                $content = json_decode($content, true);
612 612
 
613
-				if ($content && isset($content["changeset"])) {
614
-					if ($git_timestamp < (int) $content["changeset"]["timestamp"] &&
615
-						$git_commit != $content["changeset"]["id"]) {
613
+                if ($content && isset($content["changeset"])) {
614
+                    if ($git_timestamp < (int) $content["changeset"]["timestamp"] &&
615
+                        $git_commit != $content["changeset"]["id"]) {
616 616
 
617
-						$rv = $content["changeset"];
618
-					}
619
-				}
620
-			}
621
-		}
617
+                        $rv = $content["changeset"];
618
+                    }
619
+                }
620
+            }
621
+        }
622 622
 
623
-		print json_encode($rv);
624
-	}
623
+        print json_encode($rv);
624
+    }
625 625
 
626 626
 }
Please login to merge, or discard this patch.
classes/logger/syslog.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -1,33 +1,33 @@
 block discarded – undo
1 1
 <?php
2 2
 class Logger_Syslog {
3 3
 
4
-	/**
5
-	 * @SuppressWarnings(PHPMD.UnusedFormalParameter)
6
-	 */
7
-	public function log_error($errno, $errstr, $file, $line, $context) {
4
+    /**
5
+     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
6
+     */
7
+    public function log_error($errno, $errstr, $file, $line, $context) {
8 8
 
9
-		switch ($errno) {
10
-		case E_ERROR:
11
-		case E_PARSE:
12
-		case E_CORE_ERROR:
13
-		case E_COMPILE_ERROR:
14
-		case E_USER_ERROR:
15
-			$priority = LOG_ERR;
16
-			break;
17
-		case E_WARNING:
18
-		case E_CORE_WARNING:
19
-		case E_COMPILE_WARNING:
20
-		case E_USER_WARNING:
21
-			$priority = LOG_WARNING;
22
-			break;
23
-		default:
24
-			$priority = LOG_INFO;
25
-		}
9
+        switch ($errno) {
10
+        case E_ERROR:
11
+        case E_PARSE:
12
+        case E_CORE_ERROR:
13
+        case E_COMPILE_ERROR:
14
+        case E_USER_ERROR:
15
+            $priority = LOG_ERR;
16
+            break;
17
+        case E_WARNING:
18
+        case E_CORE_WARNING:
19
+        case E_COMPILE_WARNING:
20
+        case E_USER_WARNING:
21
+            $priority = LOG_WARNING;
22
+            break;
23
+        default:
24
+            $priority = LOG_INFO;
25
+        }
26 26
 
27
-		$errname = Logger::$errornames[$errno]." ($errno)";
27
+        $errname = Logger::$errornames[$errno]." ($errno)";
28 28
 
29
-		syslog($priority, "[tt-rss] $errname ($file:$line) $errstr");
29
+        syslog($priority, "[tt-rss] $errname ($file:$line) $errstr");
30 30
 
31
-	}
31
+    }
32 32
 
33 33
 }
Please login to merge, or discard this patch.
classes/pluginhost.php 1 patch
Indentation   +516 added lines, -516 removed lines patch added patch discarded remove patch
@@ -1,545 +1,545 @@
 block discarded – undo
1 1
 <?php
2 2
 class PluginHost {
3
-	private $pdo;
4
-	private $hooks = array();
5
-	private $plugins = array();
6
-	private $handlers = array();
7
-	private $commands = array();
8
-	private $storage = array();
9
-	private $feeds = array();
10
-	private $api_methods = array();
11
-	private $plugin_actions = array();
12
-	private $owner_uid;
13
-	private $last_registered;
14
-	private static $instance;
15
-
16
-	const API_VERSION = 2;
17
-
18
-	// Hooks marked with *1 are run in global context and available
19
-	// to plugins loaded in config.php only
20
-
21
-	const HOOK_ARTICLE_BUTTON = 1;
22
-	const HOOK_ARTICLE_FILTER = 2;
23
-	const HOOK_PREFS_TAB = 3;
24
-	const HOOK_PREFS_TAB_SECTION = 4;
25
-	const HOOK_PREFS_TABS = 5;
26
-	const HOOK_FEED_PARSED = 6;
27
-	const HOOK_UPDATE_TASK = 7; // *1
28
-	const HOOK_AUTH_USER = 8;
29
-	const HOOK_HOTKEY_MAP = 9;
30
-	const HOOK_RENDER_ARTICLE = 10;
31
-	const HOOK_RENDER_ARTICLE_CDM = 11;
32
-	const HOOK_FEED_FETCHED = 12;
33
-	const HOOK_SANITIZE = 13;
34
-	const HOOK_RENDER_ARTICLE_API = 14;
35
-	const HOOK_TOOLBAR_BUTTON = 15;
36
-	const HOOK_ACTION_ITEM = 16;
37
-	const HOOK_HEADLINE_TOOLBAR_BUTTON = 17;
38
-	const HOOK_HOTKEY_INFO = 18;
39
-	const HOOK_ARTICLE_LEFT_BUTTON = 19;
40
-	const HOOK_PREFS_EDIT_FEED = 20;
41
-	const HOOK_PREFS_SAVE_FEED = 21;
42
-	const HOOK_FETCH_FEED = 22;
43
-	const HOOK_QUERY_HEADLINES = 23;
44
-	const HOOK_HOUSE_KEEPING = 24; // *1
45
-	const HOOK_SEARCH = 25;
46
-	const HOOK_FORMAT_ENCLOSURES = 26;
47
-	const HOOK_SUBSCRIBE_FEED = 27;
48
-	const HOOK_HEADLINES_BEFORE = 28;
49
-	const HOOK_RENDER_ENCLOSURE = 29;
50
-	const HOOK_ARTICLE_FILTER_ACTION = 30;
51
-	const HOOK_ARTICLE_EXPORT_FEED = 31;
52
-	const HOOK_MAIN_TOOLBAR_BUTTON = 32;
53
-	const HOOK_ENCLOSURE_ENTRY = 33;
54
-	const HOOK_FORMAT_ARTICLE = 34;
55
-	const HOOK_FORMAT_ARTICLE_CDM = 35; /* RIP */
56
-	const HOOK_FEED_BASIC_INFO = 36;
57
-	const HOOK_SEND_LOCAL_FILE = 37;
58
-	const HOOK_UNSUBSCRIBE_FEED = 38;
59
-	const HOOK_SEND_MAIL = 39;
60
-	const HOOK_FILTER_TRIGGERED = 40;
61
-	const HOOK_GET_FULL_TEXT = 41;
62
-	const HOOK_ARTICLE_IMAGE = 42;
63
-	const HOOK_FEED_TREE = 43;
64
-	const HOOK_IFRAME_WHITELISTED = 44;
65
-
66
-	const KIND_ALL = 1;
67
-	const KIND_SYSTEM = 2;
68
-	const KIND_USER = 3;
69
-
70
-	public static function object_to_domain($plugin) {
71
-		return strtolower(get_class($plugin));
72
-	}
73
-
74
-	public function __construct() {
75
-		$this->pdo = Db::pdo();
76
-
77
-		$this->storage = array();
78
-	}
79
-
80
-	private function __clone() {
81
-		//
82
-	}
83
-
84
-	public static function getInstance() {
85
-		if (self::$instance == null) {
86
-					self::$instance = new self();
87
-		}
88
-
89
-		return self::$instance;
90
-	}
91
-
92
-	private function register_plugin($name, $plugin) {
93
-		//array_push($this->plugins, $plugin);
94
-		$this->plugins[$name] = $plugin;
95
-	}
96
-
97
-	// needed for compatibility with API 1
98
-	public function get_link() {
99
-		return false;
100
-	}
101
-
102
-	public function get_dbh() {
103
-		return Db::get();
104
-	}
105
-
106
-	public function get_pdo() {
107
-		return $this->pdo;
108
-	}
109
-
110
-	public function get_plugin_names() {
111
-		$names = array();
112
-
113
-		foreach ($this->plugins as $p) {
114
-			array_push($names, get_class($p));
115
-		}
116
-
117
-		return $names;
118
-	}
119
-
120
-	public function get_plugins() {
121
-		return $this->plugins;
122
-	}
123
-
124
-	public function get_plugin($name) {
125
-		return $this->plugins[strtolower($name)];
126
-	}
127
-
128
-	public function run_hooks($type, $method, $args) {
129
-		foreach ($this->get_hooks($type) as $hook) {
130
-			$hook->$method($args);
131
-		}
132
-	}
133
-
134
-	public function add_hook($type, $sender, $priority = 50) {
135
-		$priority = (int) $priority;
136
-
137
-		if (!is_array($this->hooks[$type])) {
138
-			$this->hooks[$type] = [];
139
-		}
140
-
141
-		if (!is_array($this->hooks[$type][$priority])) {
142
-			$this->hooks[$type][$priority] = [];
143
-		}
144
-
145
-		array_push($this->hooks[$type][$priority], $sender);
146
-		ksort($this->hooks[$type]);
147
-	}
148
-
149
-	public function del_hook($type, $sender) {
150
-		if (is_array($this->hooks[$type])) {
151
-			foreach (array_keys($this->hooks[$type]) as $prio) {
152
-				$key = array_search($sender, $this->hooks[$type][$prio]);
153
-
154
-				if ($key !== false) {
155
-					unset($this->hooks[$type][$prio][$key]);
156
-				}
157
-			}
158
-		}
159
-	}
160
-
161
-	public function get_hooks($type) {
162
-		if (isset($this->hooks[$type])) {
163
-			$tmp = [];
164
-
165
-			foreach (array_keys($this->hooks[$type]) as $prio) {
166
-				$tmp = array_merge($tmp, $this->hooks[$type][$prio]);
167
-			}
168
-
169
-			return $tmp;
170
-		} else {
171
-			return [];
172
-		}
173
-	}
174
-	public function load_all($kind, $owner_uid = false, $skip_init = false) {
175
-
176
-		$plugins = array_merge(glob("plugins/*"), glob("plugins.local/*"));
177
-		$plugins = array_filter($plugins, "is_dir");
178
-		$plugins = array_map("basename", $plugins);
179
-
180
-		asort($plugins);
181
-
182
-		$this->load(join(",", $plugins), $kind, $owner_uid, $skip_init);
183
-	}
184
-
185
-	public function load($classlist, $kind, $owner_uid = false, $skip_init = false) {
186
-		$plugins = explode(",", $classlist);
187
-
188
-		$this->owner_uid = (int) $owner_uid;
189
-
190
-		foreach ($plugins as $class) {
191
-			$class = trim($class);
192
-			$class_file = strtolower(clean_filename($class));
193
-
194
-			if (!is_dir(__DIR__."/../plugins/$class_file") &&
195
-					!is_dir(__DIR__."/../plugins.local/$class_file")) {
196
-			    continue;
197
-			}
198
-
199
-			// try system plugin directory first
200
-			$file = __DIR__."/../plugins/$class_file/init.php";
201
-			$vendor_dir = __DIR__."/../plugins/$class_file/vendor";
202
-
203
-			if (!file_exists($file)) {
204
-				$file = __DIR__."/../plugins.local/$class_file/init.php";
205
-				$vendor_dir = __DIR__."/../plugins.local/$class_file/vendor";
206
-			}
207
-
208
-			if (!isset($this->plugins[$class])) {
209
-				if (file_exists($file)) {
210
-				    require_once $file;
211
-				}
212
-
213
-				if (class_exists($class) && is_subclass_of($class, "Plugin")) {
214
-
215
-					// register plugin autoloader if necessary, for namespaced classes ONLY
216
-					// layout corresponds to tt-rss main /vendor/author/Package/Class.php
217
-
218
-					if (file_exists($vendor_dir)) {
219
-						spl_autoload_register(function($class) use ($vendor_dir) {
220
-
221
-							if (strpos($class, '\\') !== false) {
222
-								list ($namespace, $class_name) = explode('\\', $class, 2);
223
-
224
-								if ($namespace && $class_name) {
225
-									$class_file = "$vendor_dir/$namespace/".str_replace('\\', '/', $class_name).".php";
226
-
227
-									if (file_exists($class_file)) {
228
-																			require_once $class_file;
229
-									}
230
-								}
231
-							}
232
-						});
233
-					}
234
-
235
-					$plugin = new $class($this);
236
-
237
-					$plugin_api = $plugin->api_version();
238
-
239
-					if ($plugin_api < PluginHost::API_VERSION) {
240
-						user_error("plugin $class is not compatible with current API version (need: ".PluginHost::API_VERSION.", got: $plugin_api)", E_USER_WARNING);
241
-						continue;
242
-					}
243
-
244
-					if (file_exists(dirname($file)."/locale")) {
245
-						_bindtextdomain($class, dirname($file)."/locale");
246
-						_bind_textdomain_codeset($class, "UTF-8");
247
-					}
248
-
249
-					$this->last_registered = $class;
250
-
251
-					switch ($kind) {
252
-					case $this::KIND_SYSTEM:
253
-						if ($this->is_system($plugin)) {
254
-							if (!$skip_init) {
255
-							    $plugin->init($this);
256
-							}
257
-							$this->register_plugin($class, $plugin);
258
-						}
259
-						break;
260
-					case $this::KIND_USER:
261
-						if (!$this->is_system($plugin)) {
262
-							if (!$skip_init) {
263
-							    $plugin->init($this);
264
-							}
265
-							$this->register_plugin($class, $plugin);
266
-						}
267
-						break;
268
-					case $this::KIND_ALL:
269
-						if (!$skip_init) {
270
-						    $plugin->init($this);
271
-						}
272
-						$this->register_plugin($class, $plugin);
273
-						break;
274
-					}
275
-				}
276
-			}
277
-		}
278
-	}
279
-
280
-	public function is_system($plugin) {
281
-		$about = $plugin->about();
282
-
283
-		return @$about[3];
284
-	}
285
-
286
-	// only system plugins are allowed to modify routing
287
-	public function add_handler($handler, $method, $sender) {
288
-		$handler = str_replace("-", "_", strtolower($handler));
289
-		$method = strtolower($method);
290
-
291
-		if ($this->is_system($sender)) {
292
-			if (!is_array($this->handlers[$handler])) {
293
-				$this->handlers[$handler] = array();
294
-			}
295
-
296
-			$this->handlers[$handler][$method] = $sender;
297
-		}
298
-	}
299
-
300
-	public function del_handler($handler, $method, $sender) {
301
-		$handler = str_replace("-", "_", strtolower($handler));
302
-		$method = strtolower($method);
303
-
304
-		if ($this->is_system($sender)) {
305
-			unset($this->handlers[$handler][$method]);
306
-		}
307
-	}
308
-
309
-	public function lookup_handler($handler, $method) {
310
-		$handler = str_replace("-", "_", strtolower($handler));
311
-		$method = strtolower($method);
312
-
313
-		if (is_array($this->handlers[$handler])) {
314
-			if (isset($this->handlers[$handler]["*"])) {
315
-				return $this->handlers[$handler]["*"];
316
-			} else {
317
-				return $this->handlers[$handler][$method];
318
-			}
319
-		}
320
-
321
-		return false;
322
-	}
323
-
324
-	public function add_command($command, $description, $sender, $suffix = "", $arghelp = "") {
325
-		$command = str_replace("-", "_", strtolower($command));
326
-
327
-		$this->commands[$command] = array("description" => $description,
328
-			"suffix" => $suffix,
329
-			"arghelp" => $arghelp,
330
-			"class" => $sender);
331
-	}
332
-
333
-	public function del_command($command) {
334
-		$command = "-".strtolower($command);
335
-
336
-		unset($this->commands[$command]);
337
-	}
338
-
339
-	public function lookup_command($command) {
340
-		$command = "-".strtolower($command);
341
-
342
-		if (is_array($this->commands[$command])) {
343
-			return $this->commands[$command]["class"];
344
-		} else {
345
-			return false;
346
-		}
347
-	}
348
-
349
-	public function get_commands() {
350
-		return $this->commands;
351
-	}
352
-
353
-	public function run_commands($args) {
354
-		foreach ($this->get_commands() as $command => $data) {
355
-			if (isset($args[$command])) {
356
-				$command = str_replace("-", "", $command);
357
-				$data["class"]->$command($args);
358
-			}
359
-		}
360
-	}
361
-
362
-	public function load_data() {
363
-		if ($this->owner_uid) {
364
-			$sth = $this->pdo->prepare("SELECT name, content FROM ttrss_plugin_storage
3
+    private $pdo;
4
+    private $hooks = array();
5
+    private $plugins = array();
6
+    private $handlers = array();
7
+    private $commands = array();
8
+    private $storage = array();
9
+    private $feeds = array();
10
+    private $api_methods = array();
11
+    private $plugin_actions = array();
12
+    private $owner_uid;
13
+    private $last_registered;
14
+    private static $instance;
15
+
16
+    const API_VERSION = 2;
17
+
18
+    // Hooks marked with *1 are run in global context and available
19
+    // to plugins loaded in config.php only
20
+
21
+    const HOOK_ARTICLE_BUTTON = 1;
22
+    const HOOK_ARTICLE_FILTER = 2;
23
+    const HOOK_PREFS_TAB = 3;
24
+    const HOOK_PREFS_TAB_SECTION = 4;
25
+    const HOOK_PREFS_TABS = 5;
26
+    const HOOK_FEED_PARSED = 6;
27
+    const HOOK_UPDATE_TASK = 7; // *1
28
+    const HOOK_AUTH_USER = 8;
29
+    const HOOK_HOTKEY_MAP = 9;
30
+    const HOOK_RENDER_ARTICLE = 10;
31
+    const HOOK_RENDER_ARTICLE_CDM = 11;
32
+    const HOOK_FEED_FETCHED = 12;
33
+    const HOOK_SANITIZE = 13;
34
+    const HOOK_RENDER_ARTICLE_API = 14;
35
+    const HOOK_TOOLBAR_BUTTON = 15;
36
+    const HOOK_ACTION_ITEM = 16;
37
+    const HOOK_HEADLINE_TOOLBAR_BUTTON = 17;
38
+    const HOOK_HOTKEY_INFO = 18;
39
+    const HOOK_ARTICLE_LEFT_BUTTON = 19;
40
+    const HOOK_PREFS_EDIT_FEED = 20;
41
+    const HOOK_PREFS_SAVE_FEED = 21;
42
+    const HOOK_FETCH_FEED = 22;
43
+    const HOOK_QUERY_HEADLINES = 23;
44
+    const HOOK_HOUSE_KEEPING = 24; // *1
45
+    const HOOK_SEARCH = 25;
46
+    const HOOK_FORMAT_ENCLOSURES = 26;
47
+    const HOOK_SUBSCRIBE_FEED = 27;
48
+    const HOOK_HEADLINES_BEFORE = 28;
49
+    const HOOK_RENDER_ENCLOSURE = 29;
50
+    const HOOK_ARTICLE_FILTER_ACTION = 30;
51
+    const HOOK_ARTICLE_EXPORT_FEED = 31;
52
+    const HOOK_MAIN_TOOLBAR_BUTTON = 32;
53
+    const HOOK_ENCLOSURE_ENTRY = 33;
54
+    const HOOK_FORMAT_ARTICLE = 34;
55
+    const HOOK_FORMAT_ARTICLE_CDM = 35; /* RIP */
56
+    const HOOK_FEED_BASIC_INFO = 36;
57
+    const HOOK_SEND_LOCAL_FILE = 37;
58
+    const HOOK_UNSUBSCRIBE_FEED = 38;
59
+    const HOOK_SEND_MAIL = 39;
60
+    const HOOK_FILTER_TRIGGERED = 40;
61
+    const HOOK_GET_FULL_TEXT = 41;
62
+    const HOOK_ARTICLE_IMAGE = 42;
63
+    const HOOK_FEED_TREE = 43;
64
+    const HOOK_IFRAME_WHITELISTED = 44;
65
+
66
+    const KIND_ALL = 1;
67
+    const KIND_SYSTEM = 2;
68
+    const KIND_USER = 3;
69
+
70
+    public static function object_to_domain($plugin) {
71
+        return strtolower(get_class($plugin));
72
+    }
73
+
74
+    public function __construct() {
75
+        $this->pdo = Db::pdo();
76
+
77
+        $this->storage = array();
78
+    }
79
+
80
+    private function __clone() {
81
+        //
82
+    }
83
+
84
+    public static function getInstance() {
85
+        if (self::$instance == null) {
86
+                    self::$instance = new self();
87
+        }
88
+
89
+        return self::$instance;
90
+    }
91
+
92
+    private function register_plugin($name, $plugin) {
93
+        //array_push($this->plugins, $plugin);
94
+        $this->plugins[$name] = $plugin;
95
+    }
96
+
97
+    // needed for compatibility with API 1
98
+    public function get_link() {
99
+        return false;
100
+    }
101
+
102
+    public function get_dbh() {
103
+        return Db::get();
104
+    }
105
+
106
+    public function get_pdo() {
107
+        return $this->pdo;
108
+    }
109
+
110
+    public function get_plugin_names() {
111
+        $names = array();
112
+
113
+        foreach ($this->plugins as $p) {
114
+            array_push($names, get_class($p));
115
+        }
116
+
117
+        return $names;
118
+    }
119
+
120
+    public function get_plugins() {
121
+        return $this->plugins;
122
+    }
123
+
124
+    public function get_plugin($name) {
125
+        return $this->plugins[strtolower($name)];
126
+    }
127
+
128
+    public function run_hooks($type, $method, $args) {
129
+        foreach ($this->get_hooks($type) as $hook) {
130
+            $hook->$method($args);
131
+        }
132
+    }
133
+
134
+    public function add_hook($type, $sender, $priority = 50) {
135
+        $priority = (int) $priority;
136
+
137
+        if (!is_array($this->hooks[$type])) {
138
+            $this->hooks[$type] = [];
139
+        }
140
+
141
+        if (!is_array($this->hooks[$type][$priority])) {
142
+            $this->hooks[$type][$priority] = [];
143
+        }
144
+
145
+        array_push($this->hooks[$type][$priority], $sender);
146
+        ksort($this->hooks[$type]);
147
+    }
148
+
149
+    public function del_hook($type, $sender) {
150
+        if (is_array($this->hooks[$type])) {
151
+            foreach (array_keys($this->hooks[$type]) as $prio) {
152
+                $key = array_search($sender, $this->hooks[$type][$prio]);
153
+
154
+                if ($key !== false) {
155
+                    unset($this->hooks[$type][$prio][$key]);
156
+                }
157
+            }
158
+        }
159
+    }
160
+
161
+    public function get_hooks($type) {
162
+        if (isset($this->hooks[$type])) {
163
+            $tmp = [];
164
+
165
+            foreach (array_keys($this->hooks[$type]) as $prio) {
166
+                $tmp = array_merge($tmp, $this->hooks[$type][$prio]);
167
+            }
168
+
169
+            return $tmp;
170
+        } else {
171
+            return [];
172
+        }
173
+    }
174
+    public function load_all($kind, $owner_uid = false, $skip_init = false) {
175
+
176
+        $plugins = array_merge(glob("plugins/*"), glob("plugins.local/*"));
177
+        $plugins = array_filter($plugins, "is_dir");
178
+        $plugins = array_map("basename", $plugins);
179
+
180
+        asort($plugins);
181
+
182
+        $this->load(join(",", $plugins), $kind, $owner_uid, $skip_init);
183
+    }
184
+
185
+    public function load($classlist, $kind, $owner_uid = false, $skip_init = false) {
186
+        $plugins = explode(",", $classlist);
187
+
188
+        $this->owner_uid = (int) $owner_uid;
189
+
190
+        foreach ($plugins as $class) {
191
+            $class = trim($class);
192
+            $class_file = strtolower(clean_filename($class));
193
+
194
+            if (!is_dir(__DIR__."/../plugins/$class_file") &&
195
+                    !is_dir(__DIR__."/../plugins.local/$class_file")) {
196
+                continue;
197
+            }
198
+
199
+            // try system plugin directory first
200
+            $file = __DIR__."/../plugins/$class_file/init.php";
201
+            $vendor_dir = __DIR__."/../plugins/$class_file/vendor";
202
+
203
+            if (!file_exists($file)) {
204
+                $file = __DIR__."/../plugins.local/$class_file/init.php";
205
+                $vendor_dir = __DIR__."/../plugins.local/$class_file/vendor";
206
+            }
207
+
208
+            if (!isset($this->plugins[$class])) {
209
+                if (file_exists($file)) {
210
+                    require_once $file;
211
+                }
212
+
213
+                if (class_exists($class) && is_subclass_of($class, "Plugin")) {
214
+
215
+                    // register plugin autoloader if necessary, for namespaced classes ONLY
216
+                    // layout corresponds to tt-rss main /vendor/author/Package/Class.php
217
+
218
+                    if (file_exists($vendor_dir)) {
219
+                        spl_autoload_register(function($class) use ($vendor_dir) {
220
+
221
+                            if (strpos($class, '\\') !== false) {
222
+                                list ($namespace, $class_name) = explode('\\', $class, 2);
223
+
224
+                                if ($namespace && $class_name) {
225
+                                    $class_file = "$vendor_dir/$namespace/".str_replace('\\', '/', $class_name).".php";
226
+
227
+                                    if (file_exists($class_file)) {
228
+                                                                            require_once $class_file;
229
+                                    }
230
+                                }
231
+                            }
232
+                        });
233
+                    }
234
+
235
+                    $plugin = new $class($this);
236
+
237
+                    $plugin_api = $plugin->api_version();
238
+
239
+                    if ($plugin_api < PluginHost::API_VERSION) {
240
+                        user_error("plugin $class is not compatible with current API version (need: ".PluginHost::API_VERSION.", got: $plugin_api)", E_USER_WARNING);
241
+                        continue;
242
+                    }
243
+
244
+                    if (file_exists(dirname($file)."/locale")) {
245
+                        _bindtextdomain($class, dirname($file)."/locale");
246
+                        _bind_textdomain_codeset($class, "UTF-8");
247
+                    }
248
+
249
+                    $this->last_registered = $class;
250
+
251
+                    switch ($kind) {
252
+                    case $this::KIND_SYSTEM:
253
+                        if ($this->is_system($plugin)) {
254
+                            if (!$skip_init) {
255
+                                $plugin->init($this);
256
+                            }
257
+                            $this->register_plugin($class, $plugin);
258
+                        }
259
+                        break;
260
+                    case $this::KIND_USER:
261
+                        if (!$this->is_system($plugin)) {
262
+                            if (!$skip_init) {
263
+                                $plugin->init($this);
264
+                            }
265
+                            $this->register_plugin($class, $plugin);
266
+                        }
267
+                        break;
268
+                    case $this::KIND_ALL:
269
+                        if (!$skip_init) {
270
+                            $plugin->init($this);
271
+                        }
272
+                        $this->register_plugin($class, $plugin);
273
+                        break;
274
+                    }
275
+                }
276
+            }
277
+        }
278
+    }
279
+
280
+    public function is_system($plugin) {
281
+        $about = $plugin->about();
282
+
283
+        return @$about[3];
284
+    }
285
+
286
+    // only system plugins are allowed to modify routing
287
+    public function add_handler($handler, $method, $sender) {
288
+        $handler = str_replace("-", "_", strtolower($handler));
289
+        $method = strtolower($method);
290
+
291
+        if ($this->is_system($sender)) {
292
+            if (!is_array($this->handlers[$handler])) {
293
+                $this->handlers[$handler] = array();
294
+            }
295
+
296
+            $this->handlers[$handler][$method] = $sender;
297
+        }
298
+    }
299
+
300
+    public function del_handler($handler, $method, $sender) {
301
+        $handler = str_replace("-", "_", strtolower($handler));
302
+        $method = strtolower($method);
303
+
304
+        if ($this->is_system($sender)) {
305
+            unset($this->handlers[$handler][$method]);
306
+        }
307
+    }
308
+
309
+    public function lookup_handler($handler, $method) {
310
+        $handler = str_replace("-", "_", strtolower($handler));
311
+        $method = strtolower($method);
312
+
313
+        if (is_array($this->handlers[$handler])) {
314
+            if (isset($this->handlers[$handler]["*"])) {
315
+                return $this->handlers[$handler]["*"];
316
+            } else {
317
+                return $this->handlers[$handler][$method];
318
+            }
319
+        }
320
+
321
+        return false;
322
+    }
323
+
324
+    public function add_command($command, $description, $sender, $suffix = "", $arghelp = "") {
325
+        $command = str_replace("-", "_", strtolower($command));
326
+
327
+        $this->commands[$command] = array("description" => $description,
328
+            "suffix" => $suffix,
329
+            "arghelp" => $arghelp,
330
+            "class" => $sender);
331
+    }
332
+
333
+    public function del_command($command) {
334
+        $command = "-".strtolower($command);
335
+
336
+        unset($this->commands[$command]);
337
+    }
338
+
339
+    public function lookup_command($command) {
340
+        $command = "-".strtolower($command);
341
+
342
+        if (is_array($this->commands[$command])) {
343
+            return $this->commands[$command]["class"];
344
+        } else {
345
+            return false;
346
+        }
347
+    }
348
+
349
+    public function get_commands() {
350
+        return $this->commands;
351
+    }
352
+
353
+    public function run_commands($args) {
354
+        foreach ($this->get_commands() as $command => $data) {
355
+            if (isset($args[$command])) {
356
+                $command = str_replace("-", "", $command);
357
+                $data["class"]->$command($args);
358
+            }
359
+        }
360
+    }
361
+
362
+    public function load_data() {
363
+        if ($this->owner_uid) {
364
+            $sth = $this->pdo->prepare("SELECT name, content FROM ttrss_plugin_storage
365 365
 				WHERE owner_uid = ?");
366
-			$sth->execute([$this->owner_uid]);
366
+            $sth->execute([$this->owner_uid]);
367 367
 
368
-			while ($line = $sth->fetch()) {
369
-				$this->storage[$line["name"]] = unserialize($line["content"]);
370
-			}
371
-		}
372
-	}
368
+            while ($line = $sth->fetch()) {
369
+                $this->storage[$line["name"]] = unserialize($line["content"]);
370
+            }
371
+        }
372
+    }
373 373
 
374
-	private function save_data($plugin) {
375
-		if ($this->owner_uid) {
376
-			$this->pdo->beginTransaction();
374
+    private function save_data($plugin) {
375
+        if ($this->owner_uid) {
376
+            $this->pdo->beginTransaction();
377 377
 
378
-			$sth = $this->pdo->prepare("SELECT id FROM ttrss_plugin_storage WHERE
378
+            $sth = $this->pdo->prepare("SELECT id FROM ttrss_plugin_storage WHERE
379 379
 				owner_uid= ? AND name = ?");
380
-			$sth->execute([$this->owner_uid, $plugin]);
380
+            $sth->execute([$this->owner_uid, $plugin]);
381 381
 
382
-			if (!isset($this->storage[$plugin])) {
383
-							$this->storage[$plugin] = array();
384
-			}
382
+            if (!isset($this->storage[$plugin])) {
383
+                            $this->storage[$plugin] = array();
384
+            }
385 385
 
386
-			$content = serialize($this->storage[$plugin]);
386
+            $content = serialize($this->storage[$plugin]);
387 387
 
388
-			if ($sth->fetch()) {
389
-				$sth = $this->pdo->prepare("UPDATE ttrss_plugin_storage SET content = ?
388
+            if ($sth->fetch()) {
389
+                $sth = $this->pdo->prepare("UPDATE ttrss_plugin_storage SET content = ?
390 390
 					WHERE owner_uid= ? AND name = ?");
391
-				$sth->execute([(string) $content, $this->owner_uid, $plugin]);
391
+                $sth->execute([(string) $content, $this->owner_uid, $plugin]);
392 392
 
393
-			} else {
394
-				$sth = $this->pdo->prepare("INSERT INTO ttrss_plugin_storage
393
+            } else {
394
+                $sth = $this->pdo->prepare("INSERT INTO ttrss_plugin_storage
395 395
 					(name,owner_uid,content) VALUES
396 396
 					(?, ?, ?)");
397
-				$sth->execute([$plugin, $this->owner_uid, (string) $content]);
398
-			}
397
+                $sth->execute([$plugin, $this->owner_uid, (string) $content]);
398
+            }
399 399
 
400
-			$this->pdo->commit();
401
-		}
402
-	}
400
+            $this->pdo->commit();
401
+        }
402
+    }
403 403
 
404
-	public function set($sender, $name, $value, $sync = true) {
405
-		$idx = get_class($sender);
404
+    public function set($sender, $name, $value, $sync = true) {
405
+        $idx = get_class($sender);
406 406
 
407
-		if (!isset($this->storage[$idx])) {
408
-					$this->storage[$idx] = array();
409
-		}
407
+        if (!isset($this->storage[$idx])) {
408
+                    $this->storage[$idx] = array();
409
+        }
410 410
 
411
-		$this->storage[$idx][$name] = $value;
411
+        $this->storage[$idx][$name] = $value;
412 412
 
413
-		if ($sync) {
414
-		    $this->save_data(get_class($sender));
415
-		}
416
-	}
413
+        if ($sync) {
414
+            $this->save_data(get_class($sender));
415
+        }
416
+    }
417 417
 
418
-	public function get($sender, $name, $default_value = false) {
419
-		$idx = get_class($sender);
418
+    public function get($sender, $name, $default_value = false) {
419
+        $idx = get_class($sender);
420 420
 
421
-		if (isset($this->storage[$idx][$name])) {
422
-			return $this->storage[$idx][$name];
423
-		} else {
424
-			return $default_value;
425
-		}
426
-	}
421
+        if (isset($this->storage[$idx][$name])) {
422
+            return $this->storage[$idx][$name];
423
+        } else {
424
+            return $default_value;
425
+        }
426
+    }
427 427
 
428
-	public function get_all($sender) {
429
-		$idx = get_class($sender);
428
+    public function get_all($sender) {
429
+        $idx = get_class($sender);
430 430
 
431
-		$data = $this->storage[$idx];
431
+        $data = $this->storage[$idx];
432 432
 
433
-		return $data ? $data : [];
434
-	}
433
+        return $data ? $data : [];
434
+    }
435 435
 
436
-	public function clear_data($sender) {
437
-		if ($this->owner_uid) {
438
-			$idx = get_class($sender);
436
+    public function clear_data($sender) {
437
+        if ($this->owner_uid) {
438
+            $idx = get_class($sender);
439 439
 
440
-			unset($this->storage[$idx]);
440
+            unset($this->storage[$idx]);
441 441
 
442
-			$sth = $this->pdo->prepare("DELETE FROM ttrss_plugin_storage WHERE name = ?
442
+            $sth = $this->pdo->prepare("DELETE FROM ttrss_plugin_storage WHERE name = ?
443 443
 				AND owner_uid = ?");
444
-			$sth->execute([$idx, $this->owner_uid]);
445
-		}
446
-	}
447
-
448
-	// Plugin feed functions are *EXPERIMENTAL*!
449
-
450
-	// cat_id: only -1 is supported (Special)
451
-	public function add_feed($cat_id, $title, $icon, $sender) {
452
-		if (!$this->feeds[$cat_id]) {
453
-		    $this->feeds[$cat_id] = array();
454
-		}
455
-
456
-		$id = count($this->feeds[$cat_id]);
457
-
458
-		array_push($this->feeds[$cat_id],
459
-			array('id' => $id, 'title' => $title, 'sender' => $sender, 'icon' => $icon));
460
-
461
-		return $id;
462
-	}
463
-
464
-	public function get_feeds($cat_id) {
465
-		return $this->feeds[$cat_id];
466
-	}
467
-
468
-	// convert feed_id (e.g. -129) to pfeed_id first
469
-	public function get_feed_handler($pfeed_id) {
470
-		foreach ($this->feeds as $cat) {
471
-			foreach ($cat as $feed) {
472
-				if ($feed['id'] == $pfeed_id) {
473
-					return $feed['sender'];
474
-				}
475
-			}
476
-		}
477
-	}
478
-
479
-	public static function pfeed_to_feed_id($label) {
480
-		return PLUGIN_FEED_BASE_INDEX - 1 - abs($label);
481
-	}
482
-
483
-	public static function feed_to_pfeed_id($feed) {
484
-		return PLUGIN_FEED_BASE_INDEX - 1 + abs($feed);
485
-	}
486
-
487
-	public function add_api_method($name, $sender) {
488
-		if ($this->is_system($sender)) {
489
-			$this->api_methods[strtolower($name)] = $sender;
490
-		}
491
-	}
492
-
493
-	public function get_api_method($name) {
494
-		return $this->api_methods[$name];
495
-	}
496
-
497
-	public function add_filter_action($sender, $action_name, $action_desc) {
498
-		$sender_class = get_class($sender);
499
-
500
-		if (!isset($this->plugin_actions[$sender_class])) {
501
-					$this->plugin_actions[$sender_class] = array();
502
-		}
503
-
504
-		array_push($this->plugin_actions[$sender_class],
505
-			array("action" => $action_name, "description" => $action_desc, "sender" => $sender));
506
-	}
507
-
508
-	public function get_filter_actions() {
509
-		return $this->plugin_actions;
510
-	}
511
-
512
-	public function get_owner_uid() {
513
-		return $this->owner_uid;
514
-	}
515
-
516
-	// handled by classes/pluginhandler.php, requires valid session
517
-	public function get_method_url($sender, $method, $params) {
518
-		return get_self_url_prefix()."/backend.php?".
519
-			http_build_query(
520
-				array_merge(
521
-					[
522
-						"op" => "pluginhandler",
523
-						"plugin" => strtolower(get_class($sender)),
524
-						"method" => $method
525
-					],
526
-					$params));
527
-	}
528
-
529
-	// WARNING: endpoint in public.php, exposed to unauthenticated users
530
-	public function get_public_method_url($sender, $method, $params) {
531
-		if ($sender->is_public_method($method)) {
532
-			return get_self_url_prefix()."/public.php?".
533
-				http_build_query(
534
-					array_merge(
535
-						[
536
-							"op" => "pluginhandler",
537
-							"plugin" => strtolower(get_class($sender)),
538
-							"pmethod" => $method
539
-						],
540
-						$params));
541
-		} else {
542
-			user_error("get_public_method_url: requested method '$method' of '".get_class($sender)."' is private.");
543
-		}
544
-	}
444
+            $sth->execute([$idx, $this->owner_uid]);
445
+        }
446
+    }
447
+
448
+    // Plugin feed functions are *EXPERIMENTAL*!
449
+
450
+    // cat_id: only -1 is supported (Special)
451
+    public function add_feed($cat_id, $title, $icon, $sender) {
452
+        if (!$this->feeds[$cat_id]) {
453
+            $this->feeds[$cat_id] = array();
454
+        }
455
+
456
+        $id = count($this->feeds[$cat_id]);
457
+
458
+        array_push($this->feeds[$cat_id],
459
+            array('id' => $id, 'title' => $title, 'sender' => $sender, 'icon' => $icon));
460
+
461
+        return $id;
462
+    }
463
+
464
+    public function get_feeds($cat_id) {
465
+        return $this->feeds[$cat_id];
466
+    }
467
+
468
+    // convert feed_id (e.g. -129) to pfeed_id first
469
+    public function get_feed_handler($pfeed_id) {
470
+        foreach ($this->feeds as $cat) {
471
+            foreach ($cat as $feed) {
472
+                if ($feed['id'] == $pfeed_id) {
473
+                    return $feed['sender'];
474
+                }
475
+            }
476
+        }
477
+    }
478
+
479
+    public static function pfeed_to_feed_id($label) {
480
+        return PLUGIN_FEED_BASE_INDEX - 1 - abs($label);
481
+    }
482
+
483
+    public static function feed_to_pfeed_id($feed) {
484
+        return PLUGIN_FEED_BASE_INDEX - 1 + abs($feed);
485
+    }
486
+
487
+    public function add_api_method($name, $sender) {
488
+        if ($this->is_system($sender)) {
489
+            $this->api_methods[strtolower($name)] = $sender;
490
+        }
491
+    }
492
+
493
+    public function get_api_method($name) {
494
+        return $this->api_methods[$name];
495
+    }
496
+
497
+    public function add_filter_action($sender, $action_name, $action_desc) {
498
+        $sender_class = get_class($sender);
499
+
500
+        if (!isset($this->plugin_actions[$sender_class])) {
501
+                    $this->plugin_actions[$sender_class] = array();
502
+        }
503
+
504
+        array_push($this->plugin_actions[$sender_class],
505
+            array("action" => $action_name, "description" => $action_desc, "sender" => $sender));
506
+    }
507
+
508
+    public function get_filter_actions() {
509
+        return $this->plugin_actions;
510
+    }
511
+
512
+    public function get_owner_uid() {
513
+        return $this->owner_uid;
514
+    }
515
+
516
+    // handled by classes/pluginhandler.php, requires valid session
517
+    public function get_method_url($sender, $method, $params) {
518
+        return get_self_url_prefix()."/backend.php?".
519
+            http_build_query(
520
+                array_merge(
521
+                    [
522
+                        "op" => "pluginhandler",
523
+                        "plugin" => strtolower(get_class($sender)),
524
+                        "method" => $method
525
+                    ],
526
+                    $params));
527
+    }
528
+
529
+    // WARNING: endpoint in public.php, exposed to unauthenticated users
530
+    public function get_public_method_url($sender, $method, $params) {
531
+        if ($sender->is_public_method($method)) {
532
+            return get_self_url_prefix()."/public.php?".
533
+                http_build_query(
534
+                    array_merge(
535
+                        [
536
+                            "op" => "pluginhandler",
537
+                            "plugin" => strtolower(get_class($sender)),
538
+                            "pmethod" => $method
539
+                        ],
540
+                        $params));
541
+        } else {
542
+            user_error("get_public_method_url: requested method '$method' of '".get_class($sender)."' is private.");
543
+        }
544
+    }
545 545
 }
Please login to merge, or discard this patch.
classes/feeditem/atom.php 1 patch
Indentation   +147 added lines, -147 removed lines patch added patch discarded remove patch
@@ -1,162 +1,162 @@
 block discarded – undo
1 1
 <?php
2 2
 class FeedItem_Atom extends FeedItem_Common {
3
-	const NS_XML = "http://www.w3.org/XML/1998/namespace";
3
+    const NS_XML = "http://www.w3.org/XML/1998/namespace";
4 4
 
5
-	public function get_id() {
6
-		$id = $this->elem->getElementsByTagName("id")->item(0);
7
-
8
-		if ($id) {
9
-			return $id->nodeValue;
10
-		} else {
11
-			return clean($this->get_link());
12
-		}
13
-	}
14
-
15
-	public function get_date() {
16
-		$updated = $this->elem->getElementsByTagName("updated")->item(0);
5
+    public function get_id() {
6
+        $id = $this->elem->getElementsByTagName("id")->item(0);
7
+
8
+        if ($id) {
9
+            return $id->nodeValue;
10
+        } else {
11
+            return clean($this->get_link());
12
+        }
13
+    }
14
+
15
+    public function get_date() {
16
+        $updated = $this->elem->getElementsByTagName("updated")->item(0);
17 17
 
18
-		if ($updated) {
19
-			return strtotime($updated->nodeValue);
20
-		}
18
+        if ($updated) {
19
+            return strtotime($updated->nodeValue);
20
+        }
21 21
 
22
-		$published = $this->elem->getElementsByTagName("published")->item(0);
22
+        $published = $this->elem->getElementsByTagName("published")->item(0);
23 23
 
24
-		if ($published) {
25
-			return strtotime($published->nodeValue);
26
-		}
24
+        if ($published) {
25
+            return strtotime($published->nodeValue);
26
+        }
27 27
 
28
-		$date = $this->xpath->query("dc:date", $this->elem)->item(0);
28
+        $date = $this->xpath->query("dc:date", $this->elem)->item(0);
29 29
 
30
-		if ($date) {
31
-			return strtotime($date->nodeValue);
32
-		}
33
-	}
30
+        if ($date) {
31
+            return strtotime($date->nodeValue);
32
+        }
33
+    }
34 34
 
35 35
 
36
-	public function get_link() {
37
-		$links = $this->elem->getElementsByTagName("link");
36
+    public function get_link() {
37
+        $links = $this->elem->getElementsByTagName("link");
38 38
 
39
-		foreach ($links as $link) {
40
-			if ($link && $link->hasAttribute("href") &&
41
-				(!$link->hasAttribute("rel")
42
-					|| $link->getAttribute("rel") == "alternate"
43
-					|| $link->getAttribute("rel") == "standout")) {
44
-				$base = $this->xpath->evaluate("string(ancestor-or-self::*[@xml:base][1]/@xml:base)", $link);
39
+        foreach ($links as $link) {
40
+            if ($link && $link->hasAttribute("href") &&
41
+                (!$link->hasAttribute("rel")
42
+                    || $link->getAttribute("rel") == "alternate"
43
+                    || $link->getAttribute("rel") == "standout")) {
44
+                $base = $this->xpath->evaluate("string(ancestor-or-self::*[@xml:base][1]/@xml:base)", $link);
45 45
 
46
-				if ($base) {
47
-									return rewrite_relative_url($base, clean(trim($link->getAttribute("href"))));
48
-				} else {
49
-									return clean(trim($link->getAttribute("href")));
50
-				}
46
+                if ($base) {
47
+                                    return rewrite_relative_url($base, clean(trim($link->getAttribute("href"))));
48
+                } else {
49
+                                    return clean(trim($link->getAttribute("href")));
50
+                }
51 51
 
52
-			}
53
-		}
54
-	}
52
+            }
53
+        }
54
+    }
55 55
 
56
-	public function get_title() {
57
-		$title = $this->elem->getElementsByTagName("title")->item(0);
58
-
59
-		if ($title) {
60
-			return clean(trim($title->nodeValue));
61
-		}
62
-	}
63
-
64
-	public function get_content() {
65
-		$content = $this->elem->getElementsByTagName("content")->item(0);
66
-
67
-		if ($content) {
68
-			if ($content->hasAttribute('type')) {
69
-				if ($content->getAttribute('type') == 'xhtml') {
70
-					for ($i = 0; $i < $content->childNodes->length; $i++) {
71
-						$child = $content->childNodes->item($i);
72
-
73
-						if ($child->hasChildNodes()) {
74
-							return $this->doc->saveHTML($child);
75
-						}
76
-					}
77
-				}
78
-			}
79
-
80
-			return $this->subtree_or_text($content);
81
-		}
82
-	}
83
-
84
-	public function get_description() {
85
-		$content = $this->elem->getElementsByTagName("summary")->item(0);
86
-
87
-		if ($content) {
88
-			if ($content->hasAttribute('type')) {
89
-				if ($content->getAttribute('type') == 'xhtml') {
90
-					for ($i = 0; $i < $content->childNodes->length; $i++) {
91
-						$child = $content->childNodes->item($i);
92
-
93
-						if ($child->hasChildNodes()) {
94
-							return $this->doc->saveHTML($child);
95
-						}
96
-					}
97
-				}
98
-			}
99
-
100
-			return $this->subtree_or_text($content);
101
-		}
102
-
103
-	}
104
-
105
-	public function get_categories() {
106
-		$categories = $this->elem->getElementsByTagName("category");
107
-		$cats = [];
108
-
109
-		foreach ($categories as $cat) {
110
-			if ($cat->hasAttribute("term")) {
111
-							array_push($cats, $cat->getAttribute("term"));
112
-			}
113
-		}
114
-
115
-		$categories = $this->xpath->query("dc:subject", $this->elem);
116
-
117
-		foreach ($categories as $cat) {
118
-			array_push($cats, $cat->nodeValue);
119
-		}
120
-
121
-		return $this->normalize_categories($cats);
122
-	}
123
-
124
-	public function get_enclosures() {
125
-		$links = $this->elem->getElementsByTagName("link");
126
-
127
-		$encs = array();
128
-
129
-		foreach ($links as $link) {
130
-			if ($link && $link->hasAttribute("href") && $link->hasAttribute("rel")) {
131
-				if ($link->getAttribute("rel") == "enclosure") {
132
-					$enc = new FeedEnclosure();
133
-
134
-					$enc->type = clean($link->getAttribute("type"));
135
-					$enc->link = clean($link->getAttribute("href"));
136
-					$enc->length = clean($link->getAttribute("length"));
137
-
138
-					array_push($encs, $enc);
139
-				}
140
-			}
141
-		}
142
-
143
-		$encs = array_merge($encs, parent::get_enclosures());
144
-
145
-		return $encs;
146
-	}
147
-
148
-	public function get_language() {
149
-		$lang = $this->elem->getAttributeNS(self::NS_XML, "lang");
150
-
151
-		if (!empty($lang)) {
152
-			return clean($lang);
153
-		} else {
154
-			// Fall back to the language declared on the feed, if any.
155
-			foreach ($this->doc->childNodes as $child) {
156
-				if (method_exists($child, "getAttributeNS")) {
157
-					return clean($child->getAttributeNS(self::NS_XML, "lang"));
158
-				}
159
-			}
160
-		}
161
-	}
56
+    public function get_title() {
57
+        $title = $this->elem->getElementsByTagName("title")->item(0);
58
+
59
+        if ($title) {
60
+            return clean(trim($title->nodeValue));
61
+        }
62
+    }
63
+
64
+    public function get_content() {
65
+        $content = $this->elem->getElementsByTagName("content")->item(0);
66
+
67
+        if ($content) {
68
+            if ($content->hasAttribute('type')) {
69
+                if ($content->getAttribute('type') == 'xhtml') {
70
+                    for ($i = 0; $i < $content->childNodes->length; $i++) {
71
+                        $child = $content->childNodes->item($i);
72
+
73
+                        if ($child->hasChildNodes()) {
74
+                            return $this->doc->saveHTML($child);
75
+                        }
76
+                    }
77
+                }
78
+            }
79
+
80
+            return $this->subtree_or_text($content);
81
+        }
82
+    }
83
+
84
+    public function get_description() {
85
+        $content = $this->elem->getElementsByTagName("summary")->item(0);
86
+
87
+        if ($content) {
88
+            if ($content->hasAttribute('type')) {
89
+                if ($content->getAttribute('type') == 'xhtml') {
90
+                    for ($i = 0; $i < $content->childNodes->length; $i++) {
91
+                        $child = $content->childNodes->item($i);
92
+
93
+                        if ($child->hasChildNodes()) {
94
+                            return $this->doc->saveHTML($child);
95
+                        }
96
+                    }
97
+                }
98
+            }
99
+
100
+            return $this->subtree_or_text($content);
101
+        }
102
+
103
+    }
104
+
105
+    public function get_categories() {
106
+        $categories = $this->elem->getElementsByTagName("category");
107
+        $cats = [];
108
+
109
+        foreach ($categories as $cat) {
110
+            if ($cat->hasAttribute("term")) {
111
+                            array_push($cats, $cat->getAttribute("term"));
112
+            }
113
+        }
114
+
115
+        $categories = $this->xpath->query("dc:subject", $this->elem);
116
+
117
+        foreach ($categories as $cat) {
118
+            array_push($cats, $cat->nodeValue);
119
+        }
120
+
121
+        return $this->normalize_categories($cats);
122
+    }
123
+
124
+    public function get_enclosures() {
125
+        $links = $this->elem->getElementsByTagName("link");
126
+
127
+        $encs = array();
128
+
129
+        foreach ($links as $link) {
130
+            if ($link && $link->hasAttribute("href") && $link->hasAttribute("rel")) {
131
+                if ($link->getAttribute("rel") == "enclosure") {
132
+                    $enc = new FeedEnclosure();
133
+
134
+                    $enc->type = clean($link->getAttribute("type"));
135
+                    $enc->link = clean($link->getAttribute("href"));
136
+                    $enc->length = clean($link->getAttribute("length"));
137
+
138
+                    array_push($encs, $enc);
139
+                }
140
+            }
141
+        }
142
+
143
+        $encs = array_merge($encs, parent::get_enclosures());
144
+
145
+        return $encs;
146
+    }
147
+
148
+    public function get_language() {
149
+        $lang = $this->elem->getAttributeNS(self::NS_XML, "lang");
150
+
151
+        if (!empty($lang)) {
152
+            return clean($lang);
153
+        } else {
154
+            // Fall back to the language declared on the feed, if any.
155
+            foreach ($this->doc->childNodes as $child) {
156
+                if (method_exists($child, "getAttributeNS")) {
157
+                    return clean($child->getAttributeNS(self::NS_XML, "lang"));
158
+                }
159
+            }
160
+        }
161
+    }
162 162
 }
Please login to merge, or discard this patch.