@@ -23,7 +23,7 @@ |
||
23 | 23 | |
24 | 24 | foreach ($server_params as $n => $p) { |
25 | 25 | if (isset($_SERVER[$p])) |
26 | - $context .= "\n$n: " . $_SERVER[$p]; |
|
26 | + $context .= "\n$n: ".$_SERVER[$p]; |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | // passed error message may contain invalid unicode characters, failing to insert an error here |
@@ -1,45 +1,45 @@ |
||
1 | 1 | <?php |
2 | 2 | class Logger_SQL { |
3 | 3 | |
4 | - private $pdo; |
|
4 | + private $pdo; |
|
5 | 5 | |
6 | - public function log_error($errno, $errstr, $file, $line, $context) { |
|
6 | + public function log_error($errno, $errstr, $file, $line, $context) { |
|
7 | 7 | |
8 | - // separate PDO connection object is used for logging |
|
9 | - if (!$this->pdo) $this->pdo = Db::instance()->pdo_connect(); |
|
8 | + // separate PDO connection object is used for logging |
|
9 | + if (!$this->pdo) $this->pdo = Db::instance()->pdo_connect(); |
|
10 | 10 | |
11 | - if ($this->pdo && get_schema_version() > 117) { |
|
11 | + if ($this->pdo && get_schema_version() > 117) { |
|
12 | 12 | |
13 | - $owner_uid = $_SESSION["uid"] ? $_SESSION["uid"] : null; |
|
13 | + $owner_uid = $_SESSION["uid"] ? $_SESSION["uid"] : null; |
|
14 | 14 | |
15 | - // limit context length, DOMDocument dumps entire XML in here sometimes, which may be huge |
|
16 | - $context = mb_substr($context, 0, 8192); |
|
15 | + // limit context length, DOMDocument dumps entire XML in here sometimes, which may be huge |
|
16 | + $context = mb_substr($context, 0, 8192); |
|
17 | 17 | |
18 | - $server_params = [ |
|
19 | - "IP" => "REMOTE_ADDR", |
|
20 | - "Request URI" => "REQUEST_URI", |
|
21 | - "User agent" => "HTTP_USER_AGENT", |
|
22 | - ]; |
|
18 | + $server_params = [ |
|
19 | + "IP" => "REMOTE_ADDR", |
|
20 | + "Request URI" => "REQUEST_URI", |
|
21 | + "User agent" => "HTTP_USER_AGENT", |
|
22 | + ]; |
|
23 | 23 | |
24 | - foreach ($server_params as $n => $p) { |
|
25 | - if (isset($_SERVER[$p])) |
|
26 | - $context .= "\n$n: " . $_SERVER[$p]; |
|
27 | - } |
|
24 | + foreach ($server_params as $n => $p) { |
|
25 | + if (isset($_SERVER[$p])) |
|
26 | + $context .= "\n$n: " . $_SERVER[$p]; |
|
27 | + } |
|
28 | 28 | |
29 | - // passed error message may contain invalid unicode characters, failing to insert an error here |
|
30 | - // would break the execution entirely by generating an actual fatal error instead of a E_WARNING etc |
|
31 | - $errstr = UConverter::transcode($errstr, 'UTF-8', 'UTF-8'); |
|
32 | - $context = UConverter::transcode($context, 'UTF-8', 'UTF-8'); |
|
29 | + // passed error message may contain invalid unicode characters, failing to insert an error here |
|
30 | + // would break the execution entirely by generating an actual fatal error instead of a E_WARNING etc |
|
31 | + $errstr = UConverter::transcode($errstr, 'UTF-8', 'UTF-8'); |
|
32 | + $context = UConverter::transcode($context, 'UTF-8', 'UTF-8'); |
|
33 | 33 | |
34 | - $sth = $this->pdo->prepare("INSERT INTO ttrss_error_log |
|
34 | + $sth = $this->pdo->prepare("INSERT INTO ttrss_error_log |
|
35 | 35 | (errno, errstr, filename, lineno, context, owner_uid, created_at) VALUES |
36 | 36 | (?, ?, ?, ?, ?, ?, NOW())"); |
37 | - $sth->execute([$errno, $errstr, $file, $line, $context, $owner_uid]); |
|
37 | + $sth->execute([$errno, $errstr, $file, $line, $context, $owner_uid]); |
|
38 | 38 | |
39 | - return $sth->rowCount(); |
|
40 | - } |
|
39 | + return $sth->rowCount(); |
|
40 | + } |
|
41 | 41 | |
42 | - return false; |
|
43 | - } |
|
42 | + return false; |
|
43 | + } |
|
44 | 44 | |
45 | 45 | } |
@@ -6,7 +6,9 @@ discard block |
||
6 | 6 | public function log_error($errno, $errstr, $file, $line, $context) { |
7 | 7 | |
8 | 8 | // separate PDO connection object is used for logging |
9 | - if (!$this->pdo) $this->pdo = Db::instance()->pdo_connect(); |
|
9 | + if (!$this->pdo) { |
|
10 | + $this->pdo = Db::instance()->pdo_connect(); |
|
11 | + } |
|
10 | 12 | |
11 | 13 | if ($this->pdo && get_schema_version() > 117) { |
12 | 14 | |
@@ -22,8 +24,9 @@ discard block |
||
22 | 24 | ]; |
23 | 25 | |
24 | 26 | foreach ($server_params as $n => $p) { |
25 | - if (isset($_SERVER[$p])) |
|
26 | - $context .= "\n$n: " . $_SERVER[$p]; |
|
27 | + if (isset($_SERVER[$p])) { |
|
28 | + $context .= "\n$n: " . $_SERVER[$p]; |
|
29 | + } |
|
27 | 30 | } |
28 | 31 | |
29 | 32 | // passed error message may contain invalid unicode characters, failing to insert an error here |
@@ -1349,35 +1349,35 @@ |
||
1349 | 1349 | continue; |
1350 | 1350 | |
1351 | 1351 | switch ($rule["type"]) { |
1352 | - case "title": |
|
1353 | - $match = @preg_match("/$reg_exp/iu", $title); |
|
1354 | - break; |
|
1355 | - case "content": |
|
1356 | - // we don't need to deal with multiline regexps |
|
1357 | - $content = preg_replace("/[\r\n\t]/", "", $content); |
|
1352 | + case "title": |
|
1353 | + $match = @preg_match("/$reg_exp/iu", $title); |
|
1354 | + break; |
|
1355 | + case "content": |
|
1356 | + // we don't need to deal with multiline regexps |
|
1357 | + $content = preg_replace("/[\r\n\t]/", "", $content); |
|
1358 | 1358 | |
1359 | - $match = @preg_match("/$reg_exp/iu", $content); |
|
1360 | - break; |
|
1361 | - case "both": |
|
1362 | - // we don't need to deal with multiline regexps |
|
1363 | - $content = preg_replace("/[\r\n\t]/", "", $content); |
|
1359 | + $match = @preg_match("/$reg_exp/iu", $content); |
|
1360 | + break; |
|
1361 | + case "both": |
|
1362 | + // we don't need to deal with multiline regexps |
|
1363 | + $content = preg_replace("/[\r\n\t]/", "", $content); |
|
1364 | 1364 | |
1365 | - $match = (@preg_match("/$reg_exp/iu", $title) || @preg_match("/$reg_exp/iu", $content)); |
|
1366 | - break; |
|
1367 | - case "link": |
|
1368 | - $match = @preg_match("/$reg_exp/iu", $link); |
|
1369 | - break; |
|
1370 | - case "author": |
|
1371 | - $match = @preg_match("/$reg_exp/iu", $author); |
|
1372 | - break; |
|
1373 | - case "tag": |
|
1374 | - foreach ($tags as $tag) { |
|
1375 | - if (@preg_match("/$reg_exp/iu", $tag)) { |
|
1376 | - $match = true; |
|
1377 | - break; |
|
1378 | - } |
|
1365 | + $match = (@preg_match("/$reg_exp/iu", $title) || @preg_match("/$reg_exp/iu", $content)); |
|
1366 | + break; |
|
1367 | + case "link": |
|
1368 | + $match = @preg_match("/$reg_exp/iu", $link); |
|
1369 | + break; |
|
1370 | + case "author": |
|
1371 | + $match = @preg_match("/$reg_exp/iu", $author); |
|
1372 | + break; |
|
1373 | + case "tag": |
|
1374 | + foreach ($tags as $tag) { |
|
1375 | + if (@preg_match("/$reg_exp/iu", $tag)) { |
|
1376 | + $match = true; |
|
1377 | + break; |
|
1379 | 1378 | } |
1380 | - break; |
|
1379 | + } |
|
1380 | + break; |
|
1381 | 1381 | } |
1382 | 1382 | |
1383 | 1383 | if ($rule_inverse) $match = !$match; |
@@ -1,50 +1,50 @@ discard block |
||
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 |
||
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,22 +67,22 @@ discard block |
||
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") $query_order .= " NULLS FIRST"; |
|
81 | + // Update the least recently updated feeds first |
|
82 | + $query_order = "ORDER BY last_updated"; |
|
83 | + if (DB_TYPE == "pgsql") $query_order .= " NULLS FIRST"; |
|
84 | 84 | |
85 | - $query = "SELECT DISTINCT ttrss_feeds.feed_url, ttrss_feeds.last_updated |
|
85 | + $query = "SELECT DISTINCT ttrss_feeds.feed_url, ttrss_feeds.last_updated |
|
86 | 86 | FROM |
87 | 87 | ttrss_feeds, ttrss_users, ttrss_user_prefs |
88 | 88 | WHERE |
@@ -94,32 +94,32 @@ discard block |
||
94 | 94 | $updstart_thresh_qpart |
95 | 95 | $query_order $query_limit"; |
96 | 96 | |
97 | - $res = $pdo->query($query); |
|
97 | + $res = $pdo->query($query); |
|
98 | 98 | |
99 | - $feeds_to_update = array(); |
|
100 | - while ($line = $res->fetch()) { |
|
101 | - array_push($feeds_to_update, $line['feed_url']); |
|
102 | - } |
|
99 | + $feeds_to_update = array(); |
|
100 | + while ($line = $res->fetch()) { |
|
101 | + array_push($feeds_to_update, $line['feed_url']); |
|
102 | + } |
|
103 | 103 | |
104 | - Debug::log(sprintf("Scheduled %d feeds to update...", count($feeds_to_update))); |
|
104 | + Debug::log(sprintf("Scheduled %d feeds to update...", count($feeds_to_update))); |
|
105 | 105 | |
106 | - // Update last_update_started before actually starting the batch |
|
107 | - // in order to minimize collision risk for parallel daemon tasks |
|
108 | - if (count($feeds_to_update) > 0) { |
|
109 | - $feeds_qmarks = arr_qmarks($feeds_to_update); |
|
106 | + // Update last_update_started before actually starting the batch |
|
107 | + // in order to minimize collision risk for parallel daemon tasks |
|
108 | + if (count($feeds_to_update) > 0) { |
|
109 | + $feeds_qmarks = arr_qmarks($feeds_to_update); |
|
110 | 110 | |
111 | - $tmph = $pdo->prepare("UPDATE ttrss_feeds SET last_update_started = NOW() |
|
111 | + $tmph = $pdo->prepare("UPDATE ttrss_feeds SET last_update_started = NOW() |
|
112 | 112 | WHERE feed_url IN ($feeds_qmarks)"); |
113 | - $tmph->execute($feeds_to_update); |
|
114 | - } |
|
113 | + $tmph->execute($feeds_to_update); |
|
114 | + } |
|
115 | 115 | |
116 | - $nf = 0; |
|
117 | - $bstarted = microtime(true); |
|
116 | + $nf = 0; |
|
117 | + $bstarted = microtime(true); |
|
118 | 118 | |
119 | - $batch_owners = array(); |
|
119 | + $batch_owners = array(); |
|
120 | 120 | |
121 | - // since we have the data cached, we can deal with other feeds with the same url |
|
122 | - $usth = $pdo->prepare("SELECT DISTINCT ttrss_feeds.id,last_updated,ttrss_feeds.owner_uid |
|
121 | + // since we have the data cached, we can deal with other feeds with the same url |
|
122 | + $usth = $pdo->prepare("SELECT DISTINCT ttrss_feeds.id,last_updated,ttrss_feeds.owner_uid |
|
123 | 123 | FROM ttrss_feeds, ttrss_users, ttrss_user_prefs WHERE |
124 | 124 | ttrss_user_prefs.owner_uid = ttrss_feeds.owner_uid AND |
125 | 125 | ttrss_users.id = ttrss_user_prefs.owner_uid AND |
@@ -130,715 +130,715 @@ discard block |
||
130 | 130 | $login_thresh_qpart |
131 | 131 | ORDER BY ttrss_feeds.id $query_limit"); |
132 | 132 | |
133 | - foreach ($feeds_to_update as $feed) { |
|
134 | - Debug::log("Base feed: $feed"); |
|
133 | + foreach ($feeds_to_update as $feed) { |
|
134 | + Debug::log("Base feed: $feed"); |
|
135 | 135 | |
136 | - $usth->execute([$feed]); |
|
137 | - //update_rss_feed($line["id"], true); |
|
136 | + $usth->execute([$feed]); |
|
137 | + //update_rss_feed($line["id"], true); |
|
138 | 138 | |
139 | - if ($tline = $usth->fetch()) { |
|
140 | - Debug::log(" => " . $tline["last_updated"] . ", " . $tline["id"] . " " . $tline["owner_uid"]); |
|
139 | + if ($tline = $usth->fetch()) { |
|
140 | + Debug::log(" => " . $tline["last_updated"] . ", " . $tline["id"] . " " . $tline["owner_uid"]); |
|
141 | 141 | |
142 | - if (array_search($tline["owner_uid"], $batch_owners) === false) |
|
143 | - array_push($batch_owners, $tline["owner_uid"]); |
|
142 | + if (array_search($tline["owner_uid"], $batch_owners) === false) |
|
143 | + array_push($batch_owners, $tline["owner_uid"]); |
|
144 | 144 | |
145 | - $fstarted = microtime(true); |
|
145 | + $fstarted = microtime(true); |
|
146 | 146 | |
147 | - try { |
|
148 | - RSSUtils::update_rss_feed($tline["id"], true, false); |
|
149 | - } catch (PDOException $e) { |
|
150 | - Logger::get()->log_error(E_USER_NOTICE, $e->getMessage(), $e->getFile(), $e->getLine(), $e->getTraceAsString()); |
|
147 | + try { |
|
148 | + RSSUtils::update_rss_feed($tline["id"], true, false); |
|
149 | + } catch (PDOException $e) { |
|
150 | + Logger::get()->log_error(E_USER_NOTICE, $e->getMessage(), $e->getFile(), $e->getLine(), $e->getTraceAsString()); |
|
151 | 151 | |
152 | - try { |
|
153 | - $pdo->rollback(); |
|
154 | - } catch (PDOException $e) { |
|
155 | - // it doesn't matter if there wasn't actually anything to rollback, PDO Exception can be |
|
156 | - // thrown outside of an active transaction during feed update |
|
157 | - } |
|
158 | - } |
|
152 | + try { |
|
153 | + $pdo->rollback(); |
|
154 | + } catch (PDOException $e) { |
|
155 | + // it doesn't matter if there wasn't actually anything to rollback, PDO Exception can be |
|
156 | + // thrown outside of an active transaction during feed update |
|
157 | + } |
|
158 | + } |
|
159 | 159 | |
160 | - Debug::log(sprintf(" %.4f (sec)", microtime(true) - $fstarted)); |
|
160 | + Debug::log(sprintf(" %.4f (sec)", microtime(true) - $fstarted)); |
|
161 | 161 | |
162 | - ++$nf; |
|
163 | - } |
|
164 | - } |
|
162 | + ++$nf; |
|
163 | + } |
|
164 | + } |
|
165 | 165 | |
166 | - if ($nf > 0) { |
|
167 | - Debug::log(sprintf("Processed %d feeds in %.4f (sec), %.4f (sec/feed avg)", $nf, |
|
168 | - microtime(true) - $bstarted, (microtime(true) - $bstarted) / $nf)); |
|
169 | - } |
|
166 | + if ($nf > 0) { |
|
167 | + Debug::log(sprintf("Processed %d feeds in %.4f (sec), %.4f (sec/feed avg)", $nf, |
|
168 | + microtime(true) - $bstarted, (microtime(true) - $bstarted) / $nf)); |
|
169 | + } |
|
170 | 170 | |
171 | - foreach ($batch_owners as $owner_uid) { |
|
172 | - Debug::log("Running housekeeping tasks for user $owner_uid..."); |
|
171 | + foreach ($batch_owners as $owner_uid) { |
|
172 | + Debug::log("Running housekeeping tasks for user $owner_uid..."); |
|
173 | 173 | |
174 | - RSSUtils::housekeeping_user($owner_uid); |
|
175 | - } |
|
174 | + RSSUtils::housekeeping_user($owner_uid); |
|
175 | + } |
|
176 | 176 | |
177 | - // Send feed digests by email if needed. |
|
178 | - Digest::send_headlines_digests(); |
|
177 | + // Send feed digests by email if needed. |
|
178 | + Digest::send_headlines_digests(); |
|
179 | 179 | |
180 | - return $nf; |
|
181 | - } |
|
180 | + return $nf; |
|
181 | + } |
|
182 | 182 | |
183 | - // this is used when subscribing |
|
184 | - public static function set_basic_feed_info($feed) { |
|
183 | + // this is used when subscribing |
|
184 | + public static function set_basic_feed_info($feed) { |
|
185 | 185 | |
186 | - $pdo = Db::pdo(); |
|
186 | + $pdo = Db::pdo(); |
|
187 | 187 | |
188 | - $sth = $pdo->prepare("SELECT owner_uid,feed_url,auth_pass,auth_login |
|
188 | + $sth = $pdo->prepare("SELECT owner_uid,feed_url,auth_pass,auth_login |
|
189 | 189 | FROM ttrss_feeds WHERE id = ?"); |
190 | - $sth->execute([$feed]); |
|
190 | + $sth->execute([$feed]); |
|
191 | 191 | |
192 | - if ($row = $sth->fetch()) { |
|
192 | + if ($row = $sth->fetch()) { |
|
193 | 193 | |
194 | - $owner_uid = $row["owner_uid"]; |
|
195 | - $auth_login = $row["auth_login"]; |
|
196 | - $auth_pass = $row["auth_pass"]; |
|
197 | - $fetch_url = $row["feed_url"]; |
|
194 | + $owner_uid = $row["owner_uid"]; |
|
195 | + $auth_login = $row["auth_login"]; |
|
196 | + $auth_pass = $row["auth_pass"]; |
|
197 | + $fetch_url = $row["feed_url"]; |
|
198 | 198 | |
199 | - $pluginhost = new PluginHost(); |
|
200 | - $user_plugins = get_pref("_ENABLED_PLUGINS", $owner_uid); |
|
199 | + $pluginhost = new PluginHost(); |
|
200 | + $user_plugins = get_pref("_ENABLED_PLUGINS", $owner_uid); |
|
201 | 201 | |
202 | - $pluginhost->load(PLUGINS, PluginHost::KIND_ALL); |
|
203 | - $pluginhost->load($user_plugins, PluginHost::KIND_USER, $owner_uid); |
|
204 | - $pluginhost->load_data(); |
|
202 | + $pluginhost->load(PLUGINS, PluginHost::KIND_ALL); |
|
203 | + $pluginhost->load($user_plugins, PluginHost::KIND_USER, $owner_uid); |
|
204 | + $pluginhost->load_data(); |
|
205 | 205 | |
206 | - $basic_info = array(); |
|
207 | - foreach ($pluginhost->get_hooks(PluginHost::HOOK_FEED_BASIC_INFO) as $plugin) { |
|
208 | - $basic_info = $plugin->hook_feed_basic_info($basic_info, $fetch_url, $owner_uid, $feed, $auth_login, $auth_pass); |
|
209 | - } |
|
206 | + $basic_info = array(); |
|
207 | + foreach ($pluginhost->get_hooks(PluginHost::HOOK_FEED_BASIC_INFO) as $plugin) { |
|
208 | + $basic_info = $plugin->hook_feed_basic_info($basic_info, $fetch_url, $owner_uid, $feed, $auth_login, $auth_pass); |
|
209 | + } |
|
210 | 210 | |
211 | - if (!$basic_info) { |
|
212 | - $feed_data = fetch_file_contents($fetch_url, false, |
|
213 | - $auth_login, $auth_pass, false, |
|
214 | - FEED_FETCH_TIMEOUT, |
|
215 | - 0); |
|
211 | + if (!$basic_info) { |
|
212 | + $feed_data = fetch_file_contents($fetch_url, false, |
|
213 | + $auth_login, $auth_pass, false, |
|
214 | + FEED_FETCH_TIMEOUT, |
|
215 | + 0); |
|
216 | 216 | |
217 | - $feed_data = trim($feed_data); |
|
217 | + $feed_data = trim($feed_data); |
|
218 | 218 | |
219 | - $rss = new FeedParser($feed_data); |
|
220 | - $rss->init(); |
|
219 | + $rss = new FeedParser($feed_data); |
|
220 | + $rss->init(); |
|
221 | 221 | |
222 | - if (!$rss->error()) { |
|
223 | - $basic_info = array( |
|
224 | - 'title' => mb_substr(clean($rss->get_title()), 0, 199), |
|
225 | - 'site_url' => mb_substr(rewrite_relative_url($fetch_url, clean($rss->get_link())), 0, 245) |
|
226 | - ); |
|
227 | - } |
|
228 | - } |
|
222 | + if (!$rss->error()) { |
|
223 | + $basic_info = array( |
|
224 | + 'title' => mb_substr(clean($rss->get_title()), 0, 199), |
|
225 | + 'site_url' => mb_substr(rewrite_relative_url($fetch_url, clean($rss->get_link())), 0, 245) |
|
226 | + ); |
|
227 | + } |
|
228 | + } |
|
229 | 229 | |
230 | - if ($basic_info && is_array($basic_info)) { |
|
231 | - $sth = $pdo->prepare("SELECT title, site_url FROM ttrss_feeds WHERE id = ?"); |
|
232 | - $sth->execute([$feed]); |
|
230 | + if ($basic_info && is_array($basic_info)) { |
|
231 | + $sth = $pdo->prepare("SELECT title, site_url FROM ttrss_feeds WHERE id = ?"); |
|
232 | + $sth->execute([$feed]); |
|
233 | 233 | |
234 | - if ($row = $sth->fetch()) { |
|
234 | + if ($row = $sth->fetch()) { |
|
235 | 235 | |
236 | - $registered_title = $row["title"]; |
|
237 | - $orig_site_url = $row["site_url"]; |
|
236 | + $registered_title = $row["title"]; |
|
237 | + $orig_site_url = $row["site_url"]; |
|
238 | 238 | |
239 | - if ($basic_info['title'] && (!$registered_title || $registered_title == "[Unknown]")) { |
|
239 | + if ($basic_info['title'] && (!$registered_title || $registered_title == "[Unknown]")) { |
|
240 | 240 | |
241 | - $sth = $pdo->prepare("UPDATE ttrss_feeds SET |
|
241 | + $sth = $pdo->prepare("UPDATE ttrss_feeds SET |
|
242 | 242 | title = ? WHERE id = ?"); |
243 | - $sth->execute([$basic_info['title'], $feed]); |
|
244 | - } |
|
243 | + $sth->execute([$basic_info['title'], $feed]); |
|
244 | + } |
|
245 | 245 | |
246 | - if ($basic_info['site_url'] && $orig_site_url != $basic_info['site_url']) { |
|
247 | - $sth = $pdo->prepare("UPDATE ttrss_feeds SET |
|
246 | + if ($basic_info['site_url'] && $orig_site_url != $basic_info['site_url']) { |
|
247 | + $sth = $pdo->prepare("UPDATE ttrss_feeds SET |
|
248 | 248 | site_url = ? WHERE id = ?"); |
249 | - $sth->execute([$basic_info['site_url'], $feed]); |
|
250 | - } |
|
249 | + $sth->execute([$basic_info['site_url'], $feed]); |
|
250 | + } |
|
251 | 251 | |
252 | - } |
|
253 | - } |
|
254 | - } |
|
255 | - } |
|
252 | + } |
|
253 | + } |
|
254 | + } |
|
255 | + } |
|
256 | 256 | |
257 | - /** |
|
258 | - * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
|
259 | - */ |
|
260 | - public static function update_rss_feed($feed, $no_cache = false) { |
|
257 | + /** |
|
258 | + * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
|
259 | + */ |
|
260 | + public static function update_rss_feed($feed, $no_cache = false) { |
|
261 | 261 | |
262 | - reset_fetch_domain_quota(); |
|
262 | + reset_fetch_domain_quota(); |
|
263 | 263 | |
264 | - Debug::log("start", Debug::$LOG_VERBOSE); |
|
264 | + Debug::log("start", Debug::$LOG_VERBOSE); |
|
265 | 265 | |
266 | - $pdo = Db::pdo(); |
|
266 | + $pdo = Db::pdo(); |
|
267 | 267 | |
268 | - $sth = $pdo->prepare("SELECT title, site_url FROM ttrss_feeds WHERE id = ?"); |
|
269 | - $sth->execute([$feed]); |
|
268 | + $sth = $pdo->prepare("SELECT title, site_url FROM ttrss_feeds WHERE id = ?"); |
|
269 | + $sth->execute([$feed]); |
|
270 | 270 | |
271 | - if (!$row = $sth->fetch()) { |
|
272 | - Debug::log("feed $feed not found, skipping."); |
|
273 | - user_error("Attempt to update unknown/invalid feed $feed", E_USER_WARNING); |
|
274 | - return false; |
|
275 | - } |
|
271 | + if (!$row = $sth->fetch()) { |
|
272 | + Debug::log("feed $feed not found, skipping."); |
|
273 | + user_error("Attempt to update unknown/invalid feed $feed", E_USER_WARNING); |
|
274 | + return false; |
|
275 | + } |
|
276 | 276 | |
277 | - $title = $row["title"]; |
|
278 | - $site_url = $row["site_url"]; |
|
277 | + $title = $row["title"]; |
|
278 | + $site_url = $row["site_url"]; |
|
279 | 279 | |
280 | - // feed was batch-subscribed or something, we need to get basic info |
|
281 | - // this is not optimal currently as it fetches stuff separately TODO: optimize |
|
282 | - if ($title == "[Unknown]" || !$title || !$site_url) { |
|
283 | - Debug::log("setting basic feed info for $feed [$title, $site_url]..."); |
|
284 | - RSSUtils::set_basic_feed_info($feed); |
|
285 | - } |
|
280 | + // feed was batch-subscribed or something, we need to get basic info |
|
281 | + // this is not optimal currently as it fetches stuff separately TODO: optimize |
|
282 | + if ($title == "[Unknown]" || !$title || !$site_url) { |
|
283 | + Debug::log("setting basic feed info for $feed [$title, $site_url]..."); |
|
284 | + RSSUtils::set_basic_feed_info($feed); |
|
285 | + } |
|
286 | 286 | |
287 | - $sth = $pdo->prepare("SELECT id,update_interval,auth_login, |
|
287 | + $sth = $pdo->prepare("SELECT id,update_interval,auth_login, |
|
288 | 288 | feed_url,auth_pass,cache_images, |
289 | 289 | mark_unread_on_update, owner_uid, |
290 | 290 | auth_pass_encrypted, feed_language, |
291 | 291 | last_modified, |
292 | 292 | ".SUBSTRING_FOR_DATE."(last_unconditional, 1, 19) AS last_unconditional |
293 | 293 | FROM ttrss_feeds WHERE id = ?"); |
294 | - $sth->execute([$feed]); |
|
294 | + $sth->execute([$feed]); |
|
295 | 295 | |
296 | - if ($row = $sth->fetch()) { |
|
296 | + if ($row = $sth->fetch()) { |
|
297 | 297 | |
298 | - $owner_uid = $row["owner_uid"]; |
|
299 | - $mark_unread_on_update = $row["mark_unread_on_update"]; |
|
298 | + $owner_uid = $row["owner_uid"]; |
|
299 | + $mark_unread_on_update = $row["mark_unread_on_update"]; |
|
300 | 300 | |
301 | - $sth = $pdo->prepare("UPDATE ttrss_feeds SET last_update_started = NOW() |
|
301 | + $sth = $pdo->prepare("UPDATE ttrss_feeds SET last_update_started = NOW() |
|
302 | 302 | WHERE id = ?"); |
303 | - $sth->execute([$feed]); |
|
303 | + $sth->execute([$feed]); |
|
304 | 304 | |
305 | - $auth_login = $row["auth_login"]; |
|
306 | - $auth_pass = $row["auth_pass"]; |
|
307 | - $stored_last_modified = $row["last_modified"]; |
|
308 | - $last_unconditional = $row["last_unconditional"]; |
|
309 | - $cache_images = $row["cache_images"]; |
|
310 | - $fetch_url = $row["feed_url"]; |
|
305 | + $auth_login = $row["auth_login"]; |
|
306 | + $auth_pass = $row["auth_pass"]; |
|
307 | + $stored_last_modified = $row["last_modified"]; |
|
308 | + $last_unconditional = $row["last_unconditional"]; |
|
309 | + $cache_images = $row["cache_images"]; |
|
310 | + $fetch_url = $row["feed_url"]; |
|
311 | 311 | |
312 | - $feed_language = mb_strtolower($row["feed_language"]); |
|
312 | + $feed_language = mb_strtolower($row["feed_language"]); |
|
313 | 313 | |
314 | - if (!$feed_language) |
|
315 | - $feed_language = mb_strtolower(get_pref('DEFAULT_SEARCH_LANGUAGE', $owner_uid)); |
|
314 | + if (!$feed_language) |
|
315 | + $feed_language = mb_strtolower(get_pref('DEFAULT_SEARCH_LANGUAGE', $owner_uid)); |
|
316 | 316 | |
317 | - if (!$feed_language) |
|
318 | - $feed_language = 'simple'; |
|
317 | + if (!$feed_language) |
|
318 | + $feed_language = 'simple'; |
|
319 | 319 | |
320 | - } else { |
|
321 | - return false; |
|
322 | - } |
|
320 | + } else { |
|
321 | + return false; |
|
322 | + } |
|
323 | 323 | |
324 | - $date_feed_processed = date('Y-m-d H:i'); |
|
324 | + $date_feed_processed = date('Y-m-d H:i'); |
|
325 | 325 | |
326 | - $cache_filename = CACHE_DIR . "/feeds/" . sha1($fetch_url) . ".xml"; |
|
326 | + $cache_filename = CACHE_DIR . "/feeds/" . sha1($fetch_url) . ".xml"; |
|
327 | 327 | |
328 | - $pluginhost = new PluginHost(); |
|
329 | - $user_plugins = get_pref("_ENABLED_PLUGINS", $owner_uid); |
|
328 | + $pluginhost = new PluginHost(); |
|
329 | + $user_plugins = get_pref("_ENABLED_PLUGINS", $owner_uid); |
|
330 | 330 | |
331 | - $pluginhost->load(PLUGINS, PluginHost::KIND_ALL); |
|
332 | - $pluginhost->load($user_plugins, PluginHost::KIND_USER, $owner_uid); |
|
333 | - $pluginhost->load_data(); |
|
331 | + $pluginhost->load(PLUGINS, PluginHost::KIND_ALL); |
|
332 | + $pluginhost->load($user_plugins, PluginHost::KIND_USER, $owner_uid); |
|
333 | + $pluginhost->load_data(); |
|
334 | 334 | |
335 | - $rss_hash = false; |
|
335 | + $rss_hash = false; |
|
336 | 336 | |
337 | - $force_refetch = isset($_REQUEST["force_refetch"]); |
|
338 | - $feed_data = ""; |
|
337 | + $force_refetch = isset($_REQUEST["force_refetch"]); |
|
338 | + $feed_data = ""; |
|
339 | 339 | |
340 | - Debug::log("running HOOK_FETCH_FEED handlers...", Debug::$LOG_VERBOSE); |
|
340 | + Debug::log("running HOOK_FETCH_FEED handlers...", Debug::$LOG_VERBOSE); |
|
341 | 341 | |
342 | - foreach ($pluginhost->get_hooks(PluginHost::HOOK_FETCH_FEED) as $plugin) { |
|
343 | - Debug::log("... " . get_class($plugin), Debug::$LOG_VERBOSE); |
|
344 | - $start = microtime(true); |
|
345 | - $feed_data = $plugin->hook_fetch_feed($feed_data, $fetch_url, $owner_uid, $feed, 0, $auth_login, $auth_pass); |
|
346 | - Debug::log(sprintf("=== %.4f (sec)", microtime(true) - $start), Debug::$LOG_VERBOSE); |
|
347 | - } |
|
342 | + foreach ($pluginhost->get_hooks(PluginHost::HOOK_FETCH_FEED) as $plugin) { |
|
343 | + Debug::log("... " . get_class($plugin), Debug::$LOG_VERBOSE); |
|
344 | + $start = microtime(true); |
|
345 | + $feed_data = $plugin->hook_fetch_feed($feed_data, $fetch_url, $owner_uid, $feed, 0, $auth_login, $auth_pass); |
|
346 | + Debug::log(sprintf("=== %.4f (sec)", microtime(true) - $start), Debug::$LOG_VERBOSE); |
|
347 | + } |
|
348 | 348 | |
349 | - if ($feed_data) { |
|
350 | - Debug::log("feed data has been modified by a plugin.", Debug::$LOG_VERBOSE); |
|
351 | - } else { |
|
352 | - Debug::log("feed data has not been modified by a plugin.", Debug::$LOG_VERBOSE); |
|
353 | - } |
|
349 | + if ($feed_data) { |
|
350 | + Debug::log("feed data has been modified by a plugin.", Debug::$LOG_VERBOSE); |
|
351 | + } else { |
|
352 | + Debug::log("feed data has not been modified by a plugin.", Debug::$LOG_VERBOSE); |
|
353 | + } |
|
354 | 354 | |
355 | - // try cache |
|
356 | - if (!$feed_data && |
|
357 | - file_exists($cache_filename) && |
|
358 | - is_readable($cache_filename) && |
|
359 | - !$auth_login && !$auth_pass && |
|
360 | - filemtime($cache_filename) > time() - 30) { |
|
355 | + // try cache |
|
356 | + if (!$feed_data && |
|
357 | + file_exists($cache_filename) && |
|
358 | + is_readable($cache_filename) && |
|
359 | + !$auth_login && !$auth_pass && |
|
360 | + filemtime($cache_filename) > time() - 30) { |
|
361 | 361 | |
362 | - Debug::log("using local cache [$cache_filename].", Debug::$LOG_VERBOSE); |
|
362 | + Debug::log("using local cache [$cache_filename].", Debug::$LOG_VERBOSE); |
|
363 | 363 | |
364 | - @$feed_data = file_get_contents($cache_filename); |
|
364 | + @$feed_data = file_get_contents($cache_filename); |
|
365 | 365 | |
366 | - if ($feed_data) { |
|
367 | - $rss_hash = sha1($feed_data); |
|
368 | - } |
|
366 | + if ($feed_data) { |
|
367 | + $rss_hash = sha1($feed_data); |
|
368 | + } |
|
369 | 369 | |
370 | - } else { |
|
371 | - Debug::log("local cache will not be used for this feed", Debug::$LOG_VERBOSE); |
|
372 | - } |
|
370 | + } else { |
|
371 | + Debug::log("local cache will not be used for this feed", Debug::$LOG_VERBOSE); |
|
372 | + } |
|
373 | 373 | |
374 | - global $fetch_last_modified; |
|
374 | + global $fetch_last_modified; |
|
375 | 375 | |
376 | - // fetch feed from source |
|
377 | - if (!$feed_data) { |
|
378 | - Debug::log("last unconditional update request: $last_unconditional", Debug::$LOG_VERBOSE); |
|
376 | + // fetch feed from source |
|
377 | + if (!$feed_data) { |
|
378 | + Debug::log("last unconditional update request: $last_unconditional", Debug::$LOG_VERBOSE); |
|
379 | 379 | |
380 | - if (ini_get("open_basedir") && function_exists("curl_init")) { |
|
381 | - Debug::log("not using CURL due to open_basedir restrictions", Debug::$LOG_VERBOSE); |
|
382 | - } |
|
380 | + if (ini_get("open_basedir") && function_exists("curl_init")) { |
|
381 | + Debug::log("not using CURL due to open_basedir restrictions", Debug::$LOG_VERBOSE); |
|
382 | + } |
|
383 | 383 | |
384 | - if (time() - strtotime($last_unconditional) > MAX_CONDITIONAL_INTERVAL) { |
|
385 | - Debug::log("maximum allowed interval for conditional requests exceeded, forcing refetch", Debug::$LOG_VERBOSE); |
|
384 | + if (time() - strtotime($last_unconditional) > MAX_CONDITIONAL_INTERVAL) { |
|
385 | + Debug::log("maximum allowed interval for conditional requests exceeded, forcing refetch", Debug::$LOG_VERBOSE); |
|
386 | 386 | |
387 | - $force_refetch = true; |
|
388 | - } else { |
|
389 | - Debug::log("stored last modified for conditional request: $stored_last_modified", Debug::$LOG_VERBOSE); |
|
390 | - } |
|
387 | + $force_refetch = true; |
|
388 | + } else { |
|
389 | + Debug::log("stored last modified for conditional request: $stored_last_modified", Debug::$LOG_VERBOSE); |
|
390 | + } |
|
391 | 391 | |
392 | - Debug::log("fetching [$fetch_url] (force_refetch: $force_refetch)...", Debug::$LOG_VERBOSE); |
|
392 | + Debug::log("fetching [$fetch_url] (force_refetch: $force_refetch)...", Debug::$LOG_VERBOSE); |
|
393 | 393 | |
394 | - $feed_data = fetch_file_contents([ |
|
395 | - "url" => $fetch_url, |
|
396 | - "login" => $auth_login, |
|
397 | - "pass" => $auth_pass, |
|
398 | - "timeout" => $no_cache ? FEED_FETCH_NO_CACHE_TIMEOUT : FEED_FETCH_TIMEOUT, |
|
399 | - "last_modified" => $force_refetch ? "" : $stored_last_modified |
|
400 | - ]); |
|
394 | + $feed_data = fetch_file_contents([ |
|
395 | + "url" => $fetch_url, |
|
396 | + "login" => $auth_login, |
|
397 | + "pass" => $auth_pass, |
|
398 | + "timeout" => $no_cache ? FEED_FETCH_NO_CACHE_TIMEOUT : FEED_FETCH_TIMEOUT, |
|
399 | + "last_modified" => $force_refetch ? "" : $stored_last_modified |
|
400 | + ]); |
|
401 | 401 | |
402 | - $feed_data = trim($feed_data); |
|
402 | + $feed_data = trim($feed_data); |
|
403 | 403 | |
404 | - Debug::log("fetch done.", Debug::$LOG_VERBOSE); |
|
405 | - Debug::log("source last modified: " . $fetch_last_modified, Debug::$LOG_VERBOSE); |
|
404 | + Debug::log("fetch done.", Debug::$LOG_VERBOSE); |
|
405 | + Debug::log("source last modified: " . $fetch_last_modified, Debug::$LOG_VERBOSE); |
|
406 | 406 | |
407 | - if ($feed_data && $fetch_last_modified != $stored_last_modified) { |
|
408 | - $sth = $pdo->prepare("UPDATE ttrss_feeds SET last_modified = ? WHERE id = ?"); |
|
409 | - $sth->execute([substr($fetch_last_modified, 0, 245), $feed]); |
|
410 | - } |
|
407 | + if ($feed_data && $fetch_last_modified != $stored_last_modified) { |
|
408 | + $sth = $pdo->prepare("UPDATE ttrss_feeds SET last_modified = ? WHERE id = ?"); |
|
409 | + $sth->execute([substr($fetch_last_modified, 0, 245), $feed]); |
|
410 | + } |
|
411 | 411 | |
412 | - // cache vanilla feed data for re-use |
|
413 | - if ($feed_data && !$auth_pass && !$auth_login && is_writable(CACHE_DIR . "/feeds")) { |
|
414 | - $new_rss_hash = sha1($feed_data); |
|
412 | + // cache vanilla feed data for re-use |
|
413 | + if ($feed_data && !$auth_pass && !$auth_login && is_writable(CACHE_DIR . "/feeds")) { |
|
414 | + $new_rss_hash = sha1($feed_data); |
|
415 | 415 | |
416 | - if ($new_rss_hash != $rss_hash) { |
|
417 | - Debug::log("saving $cache_filename", Debug::$LOG_VERBOSE); |
|
418 | - @file_put_contents($cache_filename, $feed_data); |
|
419 | - } |
|
420 | - } |
|
421 | - } |
|
416 | + if ($new_rss_hash != $rss_hash) { |
|
417 | + Debug::log("saving $cache_filename", Debug::$LOG_VERBOSE); |
|
418 | + @file_put_contents($cache_filename, $feed_data); |
|
419 | + } |
|
420 | + } |
|
421 | + } |
|
422 | 422 | |
423 | - if (!$feed_data) { |
|
424 | - global $fetch_last_error; |
|
425 | - global $fetch_last_error_code; |
|
423 | + if (!$feed_data) { |
|
424 | + global $fetch_last_error; |
|
425 | + global $fetch_last_error_code; |
|
426 | 426 | |
427 | - Debug::log("unable to fetch: $fetch_last_error [$fetch_last_error_code]", Debug::$LOG_VERBOSE); |
|
427 | + Debug::log("unable to fetch: $fetch_last_error [$fetch_last_error_code]", Debug::$LOG_VERBOSE); |
|
428 | 428 | |
429 | - // If-Modified-Since |
|
430 | - if ($fetch_last_error_code != 304) { |
|
431 | - $error_message = $fetch_last_error; |
|
432 | - } else { |
|
433 | - Debug::log("source claims data not modified, nothing to do.", Debug::$LOG_VERBOSE); |
|
434 | - $error_message = ""; |
|
435 | - } |
|
429 | + // If-Modified-Since |
|
430 | + if ($fetch_last_error_code != 304) { |
|
431 | + $error_message = $fetch_last_error; |
|
432 | + } else { |
|
433 | + Debug::log("source claims data not modified, nothing to do.", Debug::$LOG_VERBOSE); |
|
434 | + $error_message = ""; |
|
435 | + } |
|
436 | 436 | |
437 | - $sth = $pdo->prepare("UPDATE ttrss_feeds SET last_error = ?, |
|
437 | + $sth = $pdo->prepare("UPDATE ttrss_feeds SET last_error = ?, |
|
438 | 438 | last_updated = NOW() WHERE id = ?"); |
439 | - $sth->execute([$error_message, $feed]); |
|
439 | + $sth->execute([$error_message, $feed]); |
|
440 | 440 | |
441 | - return; |
|
442 | - } |
|
441 | + return; |
|
442 | + } |
|
443 | 443 | |
444 | - Debug::log("running HOOK_FEED_FETCHED handlers...", Debug::$LOG_VERBOSE); |
|
445 | - $feed_data_checksum = md5($feed_data); |
|
444 | + Debug::log("running HOOK_FEED_FETCHED handlers...", Debug::$LOG_VERBOSE); |
|
445 | + $feed_data_checksum = md5($feed_data); |
|
446 | 446 | |
447 | - foreach ($pluginhost->get_hooks(PluginHost::HOOK_FEED_FETCHED) as $plugin) { |
|
448 | - Debug::log("... " . get_class($plugin), Debug::$LOG_VERBOSE); |
|
449 | - $start = microtime(true); |
|
450 | - $feed_data = $plugin->hook_feed_fetched($feed_data, $fetch_url, $owner_uid, $feed); |
|
451 | - Debug::log(sprintf("=== %.4f (sec)", microtime(true) - $start), Debug::$LOG_VERBOSE); |
|
452 | - } |
|
447 | + foreach ($pluginhost->get_hooks(PluginHost::HOOK_FEED_FETCHED) as $plugin) { |
|
448 | + Debug::log("... " . get_class($plugin), Debug::$LOG_VERBOSE); |
|
449 | + $start = microtime(true); |
|
450 | + $feed_data = $plugin->hook_feed_fetched($feed_data, $fetch_url, $owner_uid, $feed); |
|
451 | + Debug::log(sprintf("=== %.4f (sec)", microtime(true) - $start), Debug::$LOG_VERBOSE); |
|
452 | + } |
|
453 | 453 | |
454 | - if (md5($feed_data) != $feed_data_checksum) { |
|
455 | - Debug::log("feed data has been modified by a plugin.", Debug::$LOG_VERBOSE); |
|
456 | - } else { |
|
457 | - Debug::log("feed data has not been modified by a plugin.", Debug::$LOG_VERBOSE); |
|
458 | - } |
|
454 | + if (md5($feed_data) != $feed_data_checksum) { |
|
455 | + Debug::log("feed data has been modified by a plugin.", Debug::$LOG_VERBOSE); |
|
456 | + } else { |
|
457 | + Debug::log("feed data has not been modified by a plugin.", Debug::$LOG_VERBOSE); |
|
458 | + } |
|
459 | 459 | |
460 | - $rss = new FeedParser($feed_data); |
|
461 | - $rss->init(); |
|
460 | + $rss = new FeedParser($feed_data); |
|
461 | + $rss->init(); |
|
462 | 462 | |
463 | - if (!$rss->error()) { |
|
463 | + if (!$rss->error()) { |
|
464 | 464 | |
465 | - Debug::log("running HOOK_FEED_PARSED handlers...", Debug::$LOG_VERBOSE); |
|
465 | + Debug::log("running HOOK_FEED_PARSED handlers...", Debug::$LOG_VERBOSE); |
|
466 | 466 | |
467 | - // We use local pluginhost here because we need to load different per-user feed plugins |
|
467 | + // We use local pluginhost here because we need to load different per-user feed plugins |
|
468 | 468 | |
469 | - foreach ($pluginhost->get_hooks(PluginHost::HOOK_FEED_PARSED) as $plugin) { |
|
470 | - Debug::log("... " . get_class($plugin), Debug::$LOG_VERBOSE); |
|
471 | - $start = microtime(true); |
|
472 | - $plugin->hook_feed_parsed($rss); |
|
473 | - Debug::log(sprintf("=== %.4f (sec)", microtime(true) - $start), Debug::$LOG_VERBOSE); |
|
474 | - } |
|
469 | + foreach ($pluginhost->get_hooks(PluginHost::HOOK_FEED_PARSED) as $plugin) { |
|
470 | + Debug::log("... " . get_class($plugin), Debug::$LOG_VERBOSE); |
|
471 | + $start = microtime(true); |
|
472 | + $plugin->hook_feed_parsed($rss); |
|
473 | + Debug::log(sprintf("=== %.4f (sec)", microtime(true) - $start), Debug::$LOG_VERBOSE); |
|
474 | + } |
|
475 | 475 | |
476 | - Debug::log("language: $feed_language", Debug::$LOG_VERBOSE); |
|
477 | - Debug::log("processing feed data...", Debug::$LOG_VERBOSE); |
|
476 | + Debug::log("language: $feed_language", Debug::$LOG_VERBOSE); |
|
477 | + Debug::log("processing feed data...", Debug::$LOG_VERBOSE); |
|
478 | 478 | |
479 | - if (DB_TYPE == "pgsql") { |
|
480 | - $favicon_interval_qpart = "favicon_last_checked < NOW() - INTERVAL '12 hour'"; |
|
481 | - } else { |
|
482 | - $favicon_interval_qpart = "favicon_last_checked < DATE_SUB(NOW(), INTERVAL 12 HOUR)"; |
|
483 | - } |
|
479 | + if (DB_TYPE == "pgsql") { |
|
480 | + $favicon_interval_qpart = "favicon_last_checked < NOW() - INTERVAL '12 hour'"; |
|
481 | + } else { |
|
482 | + $favicon_interval_qpart = "favicon_last_checked < DATE_SUB(NOW(), INTERVAL 12 HOUR)"; |
|
483 | + } |
|
484 | 484 | |
485 | - $sth = $pdo->prepare("SELECT owner_uid,favicon_avg_color, |
|
485 | + $sth = $pdo->prepare("SELECT owner_uid,favicon_avg_color, |
|
486 | 486 | (favicon_last_checked IS NULL OR $favicon_interval_qpart) AS |
487 | 487 | favicon_needs_check |
488 | 488 | FROM ttrss_feeds WHERE id = ?"); |
489 | - $sth->execute([$feed]); |
|
489 | + $sth->execute([$feed]); |
|
490 | 490 | |
491 | - if ($row = $sth->fetch()) { |
|
492 | - $favicon_needs_check = $row["favicon_needs_check"]; |
|
493 | - $favicon_avg_color = $row["favicon_avg_color"]; |
|
494 | - $owner_uid = $row["owner_uid"]; |
|
495 | - } else { |
|
496 | - return false; |
|
497 | - } |
|
491 | + if ($row = $sth->fetch()) { |
|
492 | + $favicon_needs_check = $row["favicon_needs_check"]; |
|
493 | + $favicon_avg_color = $row["favicon_avg_color"]; |
|
494 | + $owner_uid = $row["owner_uid"]; |
|
495 | + } else { |
|
496 | + return false; |
|
497 | + } |
|
498 | 498 | |
499 | - $site_url = mb_substr(rewrite_relative_url($fetch_url, clean($rss->get_link())), 0, 245); |
|
499 | + $site_url = mb_substr(rewrite_relative_url($fetch_url, clean($rss->get_link())), 0, 245); |
|
500 | 500 | |
501 | - Debug::log("site_url: $site_url", Debug::$LOG_VERBOSE); |
|
502 | - Debug::log("feed_title: " . clean($rss->get_title()), Debug::$LOG_VERBOSE); |
|
501 | + Debug::log("site_url: $site_url", Debug::$LOG_VERBOSE); |
|
502 | + Debug::log("feed_title: " . clean($rss->get_title()), Debug::$LOG_VERBOSE); |
|
503 | 503 | |
504 | - if ($favicon_needs_check || $force_refetch) { |
|
504 | + if ($favicon_needs_check || $force_refetch) { |
|
505 | 505 | |
506 | - /* terrible hack: if we crash on floicon shit here, we won't check |
|
506 | + /* terrible hack: if we crash on floicon shit here, we won't check |
|
507 | 507 | * the icon avgcolor again (unless the icon got updated) */ |
508 | 508 | |
509 | - $favicon_file = ICONS_DIR . "/$feed.ico"; |
|
510 | - $favicon_modified = @filemtime($favicon_file); |
|
509 | + $favicon_file = ICONS_DIR . "/$feed.ico"; |
|
510 | + $favicon_modified = @filemtime($favicon_file); |
|
511 | 511 | |
512 | - Debug::log("checking favicon...", Debug::$LOG_VERBOSE); |
|
512 | + Debug::log("checking favicon...", Debug::$LOG_VERBOSE); |
|
513 | 513 | |
514 | - RSSUtils::check_feed_favicon($site_url, $feed); |
|
515 | - $favicon_modified_new = @filemtime($favicon_file); |
|
514 | + RSSUtils::check_feed_favicon($site_url, $feed); |
|
515 | + $favicon_modified_new = @filemtime($favicon_file); |
|
516 | 516 | |
517 | - if ($favicon_modified_new > $favicon_modified) |
|
518 | - $favicon_avg_color = ''; |
|
517 | + if ($favicon_modified_new > $favicon_modified) |
|
518 | + $favicon_avg_color = ''; |
|
519 | 519 | |
520 | - $favicon_colorstring = ""; |
|
521 | - if (file_exists($favicon_file) && function_exists("imagecreatefromstring") && $favicon_avg_color == '') { |
|
522 | - require_once "colors.php"; |
|
520 | + $favicon_colorstring = ""; |
|
521 | + if (file_exists($favicon_file) && function_exists("imagecreatefromstring") && $favicon_avg_color == '') { |
|
522 | + require_once "colors.php"; |
|
523 | 523 | |
524 | - $sth = $pdo->prepare("UPDATE ttrss_feeds SET favicon_avg_color = 'fail' WHERE |
|
524 | + $sth = $pdo->prepare("UPDATE ttrss_feeds SET favicon_avg_color = 'fail' WHERE |
|
525 | 525 | id = ?"); |
526 | - $sth->execute([$feed]); |
|
526 | + $sth->execute([$feed]); |
|
527 | 527 | |
528 | - $favicon_color = calculate_avg_color($favicon_file); |
|
528 | + $favicon_color = calculate_avg_color($favicon_file); |
|
529 | 529 | |
530 | - $favicon_colorstring = ",favicon_avg_color = " . $pdo->quote($favicon_color); |
|
530 | + $favicon_colorstring = ",favicon_avg_color = " . $pdo->quote($favicon_color); |
|
531 | 531 | |
532 | - } else if ($favicon_avg_color == 'fail') { |
|
533 | - Debug::log("floicon failed on this file, not trying to recalculate avg color", Debug::$LOG_VERBOSE); |
|
534 | - } |
|
532 | + } else if ($favicon_avg_color == 'fail') { |
|
533 | + Debug::log("floicon failed on this file, not trying to recalculate avg color", Debug::$LOG_VERBOSE); |
|
534 | + } |
|
535 | 535 | |
536 | - $sth = $pdo->prepare("UPDATE ttrss_feeds SET favicon_last_checked = NOW() |
|
536 | + $sth = $pdo->prepare("UPDATE ttrss_feeds SET favicon_last_checked = NOW() |
|
537 | 537 | $favicon_colorstring WHERE id = ?"); |
538 | - $sth->execute([$feed]); |
|
539 | - } |
|
538 | + $sth->execute([$feed]); |
|
539 | + } |
|
540 | 540 | |
541 | - Debug::log("loading filters & labels...", Debug::$LOG_VERBOSE); |
|
541 | + Debug::log("loading filters & labels...", Debug::$LOG_VERBOSE); |
|
542 | 542 | |
543 | - $filters = RSSUtils::load_filters($feed, $owner_uid); |
|
543 | + $filters = RSSUtils::load_filters($feed, $owner_uid); |
|
544 | 544 | |
545 | - if (Debug::get_loglevel() >= Debug::$LOG_EXTENDED) { |
|
546 | - print_r($filters); |
|
547 | - } |
|
545 | + if (Debug::get_loglevel() >= Debug::$LOG_EXTENDED) { |
|
546 | + print_r($filters); |
|
547 | + } |
|
548 | 548 | |
549 | - Debug::log("" . count($filters) . " filters loaded.", Debug::$LOG_VERBOSE); |
|
549 | + Debug::log("" . count($filters) . " filters loaded.", Debug::$LOG_VERBOSE); |
|
550 | 550 | |
551 | - $items = $rss->get_items(); |
|
551 | + $items = $rss->get_items(); |
|
552 | 552 | |
553 | - if (!is_array($items)) { |
|
554 | - Debug::log("no articles found.", Debug::$LOG_VERBOSE); |
|
553 | + if (!is_array($items)) { |
|
554 | + Debug::log("no articles found.", Debug::$LOG_VERBOSE); |
|
555 | 555 | |
556 | - $sth = $pdo->prepare("UPDATE ttrss_feeds |
|
556 | + $sth = $pdo->prepare("UPDATE ttrss_feeds |
|
557 | 557 | SET last_updated = NOW(), last_unconditional = NOW(), last_error = '' WHERE id = ?"); |
558 | - $sth->execute([$feed]); |
|
558 | + $sth->execute([$feed]); |
|
559 | 559 | |
560 | - return true; // no articles |
|
561 | - } |
|
560 | + return true; // no articles |
|
561 | + } |
|
562 | 562 | |
563 | - Debug::log("processing articles...", Debug::$LOG_VERBOSE); |
|
563 | + Debug::log("processing articles...", Debug::$LOG_VERBOSE); |
|
564 | 564 | |
565 | - $tstart = time(); |
|
565 | + $tstart = time(); |
|
566 | 566 | |
567 | - foreach ($items as $item) { |
|
568 | - $pdo->beginTransaction(); |
|
567 | + foreach ($items as $item) { |
|
568 | + $pdo->beginTransaction(); |
|
569 | 569 | |
570 | - if (Debug::get_loglevel() >= 3) { |
|
571 | - print_r($item); |
|
572 | - } |
|
570 | + if (Debug::get_loglevel() >= 3) { |
|
571 | + print_r($item); |
|
572 | + } |
|
573 | 573 | |
574 | - if (ini_get("max_execution_time") > 0 && time() - $tstart >= ini_get("max_execution_time") * 0.7) { |
|
575 | - Debug::log("looks like there's too many articles to process at once, breaking out", Debug::$LOG_VERBOSE); |
|
576 | - $pdo->commit(); |
|
577 | - break; |
|
578 | - } |
|
574 | + if (ini_get("max_execution_time") > 0 && time() - $tstart >= ini_get("max_execution_time") * 0.7) { |
|
575 | + Debug::log("looks like there's too many articles to process at once, breaking out", Debug::$LOG_VERBOSE); |
|
576 | + $pdo->commit(); |
|
577 | + break; |
|
578 | + } |
|
579 | 579 | |
580 | - $entry_guid = strip_tags($item->get_id()); |
|
581 | - if (!$entry_guid) $entry_guid = strip_tags($item->get_link()); |
|
582 | - if (!$entry_guid) $entry_guid = RSSUtils::make_guid_from_title($item->get_title()); |
|
580 | + $entry_guid = strip_tags($item->get_id()); |
|
581 | + if (!$entry_guid) $entry_guid = strip_tags($item->get_link()); |
|
582 | + if (!$entry_guid) $entry_guid = RSSUtils::make_guid_from_title($item->get_title()); |
|
583 | 583 | |
584 | - if (!$entry_guid) { |
|
585 | - $pdo->commit(); |
|
586 | - continue; |
|
587 | - } |
|
584 | + if (!$entry_guid) { |
|
585 | + $pdo->commit(); |
|
586 | + continue; |
|
587 | + } |
|
588 | 588 | |
589 | - $entry_guid = "$owner_uid,$entry_guid"; |
|
589 | + $entry_guid = "$owner_uid,$entry_guid"; |
|
590 | 590 | |
591 | - $entry_guid_hashed = 'SHA1:' . sha1($entry_guid); |
|
591 | + $entry_guid_hashed = 'SHA1:' . sha1($entry_guid); |
|
592 | 592 | |
593 | - Debug::log("guid $entry_guid / $entry_guid_hashed", Debug::$LOG_VERBOSE); |
|
593 | + Debug::log("guid $entry_guid / $entry_guid_hashed", Debug::$LOG_VERBOSE); |
|
594 | 594 | |
595 | - $entry_timestamp = (int)$item->get_date(); |
|
595 | + $entry_timestamp = (int)$item->get_date(); |
|
596 | 596 | |
597 | - Debug::log("orig date: " . $item->get_date(), Debug::$LOG_VERBOSE); |
|
597 | + Debug::log("orig date: " . $item->get_date(), Debug::$LOG_VERBOSE); |
|
598 | 598 | |
599 | - $entry_title = strip_tags($item->get_title()); |
|
599 | + $entry_title = strip_tags($item->get_title()); |
|
600 | 600 | |
601 | - $entry_link = rewrite_relative_url($site_url, clean($item->get_link())); |
|
601 | + $entry_link = rewrite_relative_url($site_url, clean($item->get_link())); |
|
602 | 602 | |
603 | - $entry_language = mb_substr(trim($item->get_language()), 0, 2); |
|
603 | + $entry_language = mb_substr(trim($item->get_language()), 0, 2); |
|
604 | 604 | |
605 | - Debug::log("title $entry_title", Debug::$LOG_VERBOSE); |
|
606 | - Debug::log("link $entry_link", Debug::$LOG_VERBOSE); |
|
607 | - Debug::log("language $entry_language", Debug::$LOG_VERBOSE); |
|
605 | + Debug::log("title $entry_title", Debug::$LOG_VERBOSE); |
|
606 | + Debug::log("link $entry_link", Debug::$LOG_VERBOSE); |
|
607 | + Debug::log("language $entry_language", Debug::$LOG_VERBOSE); |
|
608 | 608 | |
609 | - if (!$entry_title) $entry_title = date("Y-m-d H:i:s", $entry_timestamp);; |
|
609 | + if (!$entry_title) $entry_title = date("Y-m-d H:i:s", $entry_timestamp);; |
|
610 | 610 | |
611 | - $entry_content = $item->get_content(); |
|
612 | - if (!$entry_content) $entry_content = $item->get_description(); |
|
611 | + $entry_content = $item->get_content(); |
|
612 | + if (!$entry_content) $entry_content = $item->get_description(); |
|
613 | 613 | |
614 | - if (Debug::get_loglevel() >= 3) { |
|
615 | - print "content: "; |
|
616 | - print htmlspecialchars($entry_content); |
|
617 | - print "\n"; |
|
618 | - } |
|
614 | + if (Debug::get_loglevel() >= 3) { |
|
615 | + print "content: "; |
|
616 | + print htmlspecialchars($entry_content); |
|
617 | + print "\n"; |
|
618 | + } |
|
619 | 619 | |
620 | - $entry_comments = mb_substr(strip_tags($item->get_comments_url()), 0, 245); |
|
621 | - $num_comments = (int) $item->get_comments_count(); |
|
620 | + $entry_comments = mb_substr(strip_tags($item->get_comments_url()), 0, 245); |
|
621 | + $num_comments = (int) $item->get_comments_count(); |
|
622 | 622 | |
623 | - $entry_author = strip_tags($item->get_author()); |
|
624 | - $entry_guid = mb_substr($entry_guid, 0, 245); |
|
623 | + $entry_author = strip_tags($item->get_author()); |
|
624 | + $entry_guid = mb_substr($entry_guid, 0, 245); |
|
625 | 625 | |
626 | - Debug::log("author $entry_author", Debug::$LOG_VERBOSE); |
|
627 | - Debug::log("looking for tags...", Debug::$LOG_VERBOSE); |
|
626 | + Debug::log("author $entry_author", Debug::$LOG_VERBOSE); |
|
627 | + Debug::log("looking for tags...", Debug::$LOG_VERBOSE); |
|
628 | 628 | |
629 | - $entry_tags = $item->get_categories(); |
|
630 | - Debug::log("tags found: " . join(", ", $entry_tags), Debug::$LOG_VERBOSE); |
|
629 | + $entry_tags = $item->get_categories(); |
|
630 | + Debug::log("tags found: " . join(", ", $entry_tags), Debug::$LOG_VERBOSE); |
|
631 | 631 | |
632 | - Debug::log("done collecting data.", Debug::$LOG_VERBOSE); |
|
632 | + Debug::log("done collecting data.", Debug::$LOG_VERBOSE); |
|
633 | 633 | |
634 | - $sth = $pdo->prepare("SELECT id, content_hash, lang FROM ttrss_entries |
|
634 | + $sth = $pdo->prepare("SELECT id, content_hash, lang FROM ttrss_entries |
|
635 | 635 | WHERE guid = ? OR guid = ?"); |
636 | - $sth->execute([$entry_guid, $entry_guid_hashed]); |
|
637 | - |
|
638 | - if ($row = $sth->fetch()) { |
|
639 | - $base_entry_id = $row["id"]; |
|
640 | - $entry_stored_hash = $row["content_hash"]; |
|
641 | - $article_labels = Article::get_article_labels($base_entry_id, $owner_uid); |
|
642 | - |
|
643 | - $existing_tags = Article::get_article_tags($base_entry_id, $owner_uid); |
|
644 | - $entry_tags = array_unique(array_merge($entry_tags, $existing_tags)); |
|
645 | - } else { |
|
646 | - $base_entry_id = false; |
|
647 | - $entry_stored_hash = ""; |
|
648 | - $article_labels = array(); |
|
649 | - } |
|
650 | - |
|
651 | - $article = array("owner_uid" => $owner_uid, // read only |
|
652 | - "guid" => $entry_guid, // read only |
|
653 | - "guid_hashed" => $entry_guid_hashed, // read only |
|
654 | - "title" => $entry_title, |
|
655 | - "content" => $entry_content, |
|
656 | - "link" => $entry_link, |
|
657 | - "labels" => $article_labels, // current limitation: can add labels to article, can't remove them |
|
658 | - "tags" => $entry_tags, |
|
659 | - "author" => $entry_author, |
|
660 | - "force_catchup" => false, // ugly hack for the time being |
|
661 | - "score_modifier" => 0, // no previous value, plugin should recalculate score modifier based on content if needed |
|
662 | - "language" => $entry_language, |
|
663 | - "timestamp" => $entry_timestamp, |
|
664 | - "num_comments" => $num_comments, |
|
665 | - "feed" => array("id" => $feed, |
|
666 | - "fetch_url" => $fetch_url, |
|
667 | - "site_url" => $site_url, |
|
668 | - "cache_images" => $cache_images) |
|
669 | - ); |
|
670 | - |
|
671 | - $entry_plugin_data = ""; |
|
672 | - $entry_current_hash = RSSUtils::calculate_article_hash($article, $pluginhost); |
|
673 | - |
|
674 | - Debug::log("article hash: $entry_current_hash [stored=$entry_stored_hash]", Debug::$LOG_VERBOSE); |
|
675 | - |
|
676 | - if ($entry_current_hash == $entry_stored_hash && !isset($_REQUEST["force_rehash"])) { |
|
677 | - Debug::log("stored article seems up to date [IID: $base_entry_id], updating timestamp only", Debug::$LOG_VERBOSE); |
|
678 | - |
|
679 | - // we keep encountering the entry in feeds, so we need to |
|
680 | - // update date_updated column so that we don't get horrible |
|
681 | - // dupes when the entry gets purged and reinserted again e.g. |
|
682 | - // in the case of SLOW SLOW OMG SLOW updating feeds |
|
683 | - |
|
684 | - $sth = $pdo->prepare("UPDATE ttrss_entries SET date_updated = NOW() |
|
636 | + $sth->execute([$entry_guid, $entry_guid_hashed]); |
|
637 | + |
|
638 | + if ($row = $sth->fetch()) { |
|
639 | + $base_entry_id = $row["id"]; |
|
640 | + $entry_stored_hash = $row["content_hash"]; |
|
641 | + $article_labels = Article::get_article_labels($base_entry_id, $owner_uid); |
|
642 | + |
|
643 | + $existing_tags = Article::get_article_tags($base_entry_id, $owner_uid); |
|
644 | + $entry_tags = array_unique(array_merge($entry_tags, $existing_tags)); |
|
645 | + } else { |
|
646 | + $base_entry_id = false; |
|
647 | + $entry_stored_hash = ""; |
|
648 | + $article_labels = array(); |
|
649 | + } |
|
650 | + |
|
651 | + $article = array("owner_uid" => $owner_uid, // read only |
|
652 | + "guid" => $entry_guid, // read only |
|
653 | + "guid_hashed" => $entry_guid_hashed, // read only |
|
654 | + "title" => $entry_title, |
|
655 | + "content" => $entry_content, |
|
656 | + "link" => $entry_link, |
|
657 | + "labels" => $article_labels, // current limitation: can add labels to article, can't remove them |
|
658 | + "tags" => $entry_tags, |
|
659 | + "author" => $entry_author, |
|
660 | + "force_catchup" => false, // ugly hack for the time being |
|
661 | + "score_modifier" => 0, // no previous value, plugin should recalculate score modifier based on content if needed |
|
662 | + "language" => $entry_language, |
|
663 | + "timestamp" => $entry_timestamp, |
|
664 | + "num_comments" => $num_comments, |
|
665 | + "feed" => array("id" => $feed, |
|
666 | + "fetch_url" => $fetch_url, |
|
667 | + "site_url" => $site_url, |
|
668 | + "cache_images" => $cache_images) |
|
669 | + ); |
|
670 | + |
|
671 | + $entry_plugin_data = ""; |
|
672 | + $entry_current_hash = RSSUtils::calculate_article_hash($article, $pluginhost); |
|
673 | + |
|
674 | + Debug::log("article hash: $entry_current_hash [stored=$entry_stored_hash]", Debug::$LOG_VERBOSE); |
|
675 | + |
|
676 | + if ($entry_current_hash == $entry_stored_hash && !isset($_REQUEST["force_rehash"])) { |
|
677 | + Debug::log("stored article seems up to date [IID: $base_entry_id], updating timestamp only", Debug::$LOG_VERBOSE); |
|
678 | + |
|
679 | + // we keep encountering the entry in feeds, so we need to |
|
680 | + // update date_updated column so that we don't get horrible |
|
681 | + // dupes when the entry gets purged and reinserted again e.g. |
|
682 | + // in the case of SLOW SLOW OMG SLOW updating feeds |
|
683 | + |
|
684 | + $sth = $pdo->prepare("UPDATE ttrss_entries SET date_updated = NOW() |
|
685 | 685 | WHERE id = ?"); |
686 | - $sth->execute([$base_entry_id]); |
|
686 | + $sth->execute([$base_entry_id]); |
|
687 | 687 | |
688 | - $pdo->commit(); |
|
689 | - continue; |
|
690 | - } |
|
688 | + $pdo->commit(); |
|
689 | + continue; |
|
690 | + } |
|
691 | 691 | |
692 | - Debug::log("hash differs, applying plugin filters:", Debug::$LOG_VERBOSE); |
|
692 | + Debug::log("hash differs, applying plugin filters:", Debug::$LOG_VERBOSE); |
|
693 | 693 | |
694 | - foreach ($pluginhost->get_hooks(PluginHost::HOOK_ARTICLE_FILTER) as $plugin) { |
|
695 | - Debug::log("... " . get_class($plugin), Debug::$LOG_VERBOSE); |
|
694 | + foreach ($pluginhost->get_hooks(PluginHost::HOOK_ARTICLE_FILTER) as $plugin) { |
|
695 | + Debug::log("... " . get_class($plugin), Debug::$LOG_VERBOSE); |
|
696 | 696 | |
697 | - $start = microtime(true); |
|
698 | - $article = $plugin->hook_article_filter($article); |
|
697 | + $start = microtime(true); |
|
698 | + $article = $plugin->hook_article_filter($article); |
|
699 | 699 | |
700 | - Debug::log(sprintf("=== %.4f (sec)", microtime(true) - $start), Debug::$LOG_VERBOSE); |
|
700 | + Debug::log(sprintf("=== %.4f (sec)", microtime(true) - $start), Debug::$LOG_VERBOSE); |
|
701 | 701 | |
702 | - $entry_plugin_data .= mb_strtolower(get_class($plugin)) . ","; |
|
703 | - } |
|
702 | + $entry_plugin_data .= mb_strtolower(get_class($plugin)) . ","; |
|
703 | + } |
|
704 | 704 | |
705 | 705 | if (Debug::get_loglevel() >= 3) { |
706 | - print "processed content: "; |
|
707 | - print htmlspecialchars($article["content"]); |
|
708 | - print "\n"; |
|
709 | - } |
|
706 | + print "processed content: "; |
|
707 | + print htmlspecialchars($article["content"]); |
|
708 | + print "\n"; |
|
709 | + } |
|
710 | 710 | |
711 | - Debug::log("plugin data: $entry_plugin_data", Debug::$LOG_VERBOSE); |
|
711 | + Debug::log("plugin data: $entry_plugin_data", Debug::$LOG_VERBOSE); |
|
712 | 712 | |
713 | - // Workaround: 4-byte unicode requires utf8mb4 in MySQL. See https://tt-rss.org/forum/viewtopic.php?f=1&t=3377&p=20077#p20077 |
|
714 | - if (DB_TYPE == "mysql" && MYSQL_CHARSET != "UTF8MB4") { |
|
715 | - foreach ($article as $k => $v) { |
|
716 | - // i guess we'll have to take the risk of 4byte unicode labels & tags here |
|
717 | - if (is_string($article[$k])) { |
|
718 | - $article[$k] = RSSUtils::strip_utf8mb4($v); |
|
719 | - } |
|
720 | - } |
|
721 | - } |
|
713 | + // Workaround: 4-byte unicode requires utf8mb4 in MySQL. See https://tt-rss.org/forum/viewtopic.php?f=1&t=3377&p=20077#p20077 |
|
714 | + if (DB_TYPE == "mysql" && MYSQL_CHARSET != "UTF8MB4") { |
|
715 | + foreach ($article as $k => $v) { |
|
716 | + // i guess we'll have to take the risk of 4byte unicode labels & tags here |
|
717 | + if (is_string($article[$k])) { |
|
718 | + $article[$k] = RSSUtils::strip_utf8mb4($v); |
|
719 | + } |
|
720 | + } |
|
721 | + } |
|
722 | 722 | |
723 | - /* Collect article tags here so we could filter by them: */ |
|
723 | + /* Collect article tags here so we could filter by them: */ |
|
724 | 724 | |
725 | - $matched_rules = []; |
|
726 | - $matched_filters = []; |
|
725 | + $matched_rules = []; |
|
726 | + $matched_filters = []; |
|
727 | 727 | |
728 | - $article_filters = RSSUtils::get_article_filters($filters, $article["title"], |
|
729 | - $article["content"], $article["link"], $article["author"], |
|
730 | - $article["tags"], $matched_rules, $matched_filters); |
|
728 | + $article_filters = RSSUtils::get_article_filters($filters, $article["title"], |
|
729 | + $article["content"], $article["link"], $article["author"], |
|
730 | + $article["tags"], $matched_rules, $matched_filters); |
|
731 | 731 | |
732 | - // $article_filters should be renamed to something like $filter_actions; actual filter objects are in $matched_filters |
|
733 | - foreach ($pluginhost->get_hooks(PluginHost::HOOK_FILTER_TRIGGERED) as $plugin) { |
|
734 | - $plugin->hook_filter_triggered($feed, $owner_uid, $article, $matched_filters, $matched_rules, $article_filters); |
|
735 | - } |
|
732 | + // $article_filters should be renamed to something like $filter_actions; actual filter objects are in $matched_filters |
|
733 | + foreach ($pluginhost->get_hooks(PluginHost::HOOK_FILTER_TRIGGERED) as $plugin) { |
|
734 | + $plugin->hook_filter_triggered($feed, $owner_uid, $article, $matched_filters, $matched_rules, $article_filters); |
|
735 | + } |
|
736 | 736 | |
737 | - $matched_filter_ids = array_map(function($f) { return $f['id']; }, $matched_filters); |
|
737 | + $matched_filter_ids = array_map(function($f) { return $f['id']; }, $matched_filters); |
|
738 | 738 | |
739 | - if (count($matched_filter_ids) > 0) { |
|
740 | - $filter_ids_qmarks = arr_qmarks($matched_filter_ids); |
|
739 | + if (count($matched_filter_ids) > 0) { |
|
740 | + $filter_ids_qmarks = arr_qmarks($matched_filter_ids); |
|
741 | 741 | |
742 | - $fsth = $pdo->prepare("UPDATE ttrss_filters2 SET last_triggered = NOW() WHERE |
|
742 | + $fsth = $pdo->prepare("UPDATE ttrss_filters2 SET last_triggered = NOW() WHERE |
|
743 | 743 | id IN ($filter_ids_qmarks) AND owner_uid = ?"); |
744 | 744 | |
745 | - $fsth->execute(array_merge($matched_filter_ids, [$owner_uid])); |
|
746 | - } |
|
745 | + $fsth->execute(array_merge($matched_filter_ids, [$owner_uid])); |
|
746 | + } |
|
747 | 747 | |
748 | - if (Debug::get_loglevel() >= Debug::$LOG_EXTENDED) { |
|
749 | - Debug::log("matched filters: ", Debug::$LOG_VERBOSE); |
|
748 | + if (Debug::get_loglevel() >= Debug::$LOG_EXTENDED) { |
|
749 | + Debug::log("matched filters: ", Debug::$LOG_VERBOSE); |
|
750 | 750 | |
751 | - if (count($matched_filters != 0)) { |
|
752 | - print_r($matched_filters); |
|
753 | - } |
|
751 | + if (count($matched_filters != 0)) { |
|
752 | + print_r($matched_filters); |
|
753 | + } |
|
754 | 754 | |
755 | - Debug::log("matched filter rules: ", Debug::$LOG_VERBOSE); |
|
755 | + Debug::log("matched filter rules: ", Debug::$LOG_VERBOSE); |
|
756 | 756 | |
757 | - if (count($matched_rules) != 0) { |
|
758 | - print_r($matched_rules); |
|
759 | - } |
|
757 | + if (count($matched_rules) != 0) { |
|
758 | + print_r($matched_rules); |
|
759 | + } |
|
760 | 760 | |
761 | - Debug::log("filter actions: ", Debug::$LOG_VERBOSE); |
|
761 | + Debug::log("filter actions: ", Debug::$LOG_VERBOSE); |
|
762 | 762 | |
763 | - if (count($article_filters) != 0) { |
|
764 | - print_r($article_filters); |
|
765 | - } |
|
766 | - } |
|
763 | + if (count($article_filters) != 0) { |
|
764 | + print_r($article_filters); |
|
765 | + } |
|
766 | + } |
|
767 | 767 | |
768 | - $plugin_filter_names = RSSUtils::find_article_filters($article_filters, "plugin"); |
|
769 | - $plugin_filter_actions = $pluginhost->get_filter_actions(); |
|
768 | + $plugin_filter_names = RSSUtils::find_article_filters($article_filters, "plugin"); |
|
769 | + $plugin_filter_actions = $pluginhost->get_filter_actions(); |
|
770 | 770 | |
771 | - if (count($plugin_filter_names) > 0) { |
|
772 | - Debug::log("applying plugin filter actions...", Debug::$LOG_VERBOSE); |
|
771 | + if (count($plugin_filter_names) > 0) { |
|
772 | + Debug::log("applying plugin filter actions...", Debug::$LOG_VERBOSE); |
|
773 | 773 | |
774 | - foreach ($plugin_filter_names as $pfn) { |
|
775 | - list($pfclass,$pfaction) = explode(":", $pfn["param"]); |
|
774 | + foreach ($plugin_filter_names as $pfn) { |
|
775 | + list($pfclass,$pfaction) = explode(":", $pfn["param"]); |
|
776 | 776 | |
777 | - if (isset($plugin_filter_actions[$pfclass])) { |
|
778 | - $plugin = $pluginhost->get_plugin($pfclass); |
|
777 | + if (isset($plugin_filter_actions[$pfclass])) { |
|
778 | + $plugin = $pluginhost->get_plugin($pfclass); |
|
779 | 779 | |
780 | - Debug::log("... $pfclass: $pfaction", Debug::$LOG_VERBOSE); |
|
780 | + Debug::log("... $pfclass: $pfaction", Debug::$LOG_VERBOSE); |
|
781 | 781 | |
782 | - if ($plugin) { |
|
783 | - $start = microtime(true); |
|
784 | - $article = $plugin->hook_article_filter_action($article, $pfaction); |
|
782 | + if ($plugin) { |
|
783 | + $start = microtime(true); |
|
784 | + $article = $plugin->hook_article_filter_action($article, $pfaction); |
|
785 | 785 | |
786 | - Debug::log(sprintf("=== %.4f (sec)", microtime(true) - $start), Debug::$LOG_VERBOSE); |
|
787 | - } else { |
|
788 | - Debug::log("??? $pfclass: plugin object not found.", Debug::$LOG_VERBOSE); |
|
789 | - } |
|
790 | - } else { |
|
791 | - Debug::log("??? $pfclass: filter plugin not registered.", Debug::$LOG_VERBOSE); |
|
792 | - } |
|
793 | - } |
|
794 | - } |
|
786 | + Debug::log(sprintf("=== %.4f (sec)", microtime(true) - $start), Debug::$LOG_VERBOSE); |
|
787 | + } else { |
|
788 | + Debug::log("??? $pfclass: plugin object not found.", Debug::$LOG_VERBOSE); |
|
789 | + } |
|
790 | + } else { |
|
791 | + Debug::log("??? $pfclass: filter plugin not registered.", Debug::$LOG_VERBOSE); |
|
792 | + } |
|
793 | + } |
|
794 | + } |
|
795 | 795 | |
796 | - $entry_tags = $article["tags"]; |
|
797 | - $entry_title = strip_tags($article["title"]); |
|
798 | - $entry_author = mb_substr(strip_tags($article["author"]), 0, 245); |
|
799 | - $entry_link = strip_tags($article["link"]); |
|
800 | - $entry_content = $article["content"]; // escaped below |
|
801 | - $entry_force_catchup = $article["force_catchup"]; |
|
802 | - $article_labels = $article["labels"]; |
|
803 | - $entry_score_modifier = (int) $article["score_modifier"]; |
|
804 | - $entry_language = $article["language"]; |
|
805 | - $entry_timestamp = $article["timestamp"]; |
|
806 | - $num_comments = $article["num_comments"]; |
|
796 | + $entry_tags = $article["tags"]; |
|
797 | + $entry_title = strip_tags($article["title"]); |
|
798 | + $entry_author = mb_substr(strip_tags($article["author"]), 0, 245); |
|
799 | + $entry_link = strip_tags($article["link"]); |
|
800 | + $entry_content = $article["content"]; // escaped below |
|
801 | + $entry_force_catchup = $article["force_catchup"]; |
|
802 | + $article_labels = $article["labels"]; |
|
803 | + $entry_score_modifier = (int) $article["score_modifier"]; |
|
804 | + $entry_language = $article["language"]; |
|
805 | + $entry_timestamp = $article["timestamp"]; |
|
806 | + $num_comments = $article["num_comments"]; |
|
807 | 807 | |
808 | - if ($entry_timestamp == -1 || !$entry_timestamp || $entry_timestamp > time()) { |
|
809 | - $entry_timestamp = time(); |
|
810 | - } |
|
808 | + if ($entry_timestamp == -1 || !$entry_timestamp || $entry_timestamp > time()) { |
|
809 | + $entry_timestamp = time(); |
|
810 | + } |
|
811 | 811 | |
812 | - $entry_timestamp_fmt = strftime("%Y/%m/%d %H:%M:%S", $entry_timestamp); |
|
812 | + $entry_timestamp_fmt = strftime("%Y/%m/%d %H:%M:%S", $entry_timestamp); |
|
813 | 813 | |
814 | - Debug::log("date $entry_timestamp [$entry_timestamp_fmt]", Debug::$LOG_VERBOSE); |
|
815 | - Debug::log("num_comments: $num_comments", Debug::$LOG_VERBOSE); |
|
814 | + Debug::log("date $entry_timestamp [$entry_timestamp_fmt]", Debug::$LOG_VERBOSE); |
|
815 | + Debug::log("num_comments: $num_comments", Debug::$LOG_VERBOSE); |
|
816 | 816 | |
817 | - if (Debug::get_loglevel() >= Debug::$LOG_EXTENDED) { |
|
818 | - Debug::log("article labels:", Debug::$LOG_VERBOSE); |
|
817 | + if (Debug::get_loglevel() >= Debug::$LOG_EXTENDED) { |
|
818 | + Debug::log("article labels:", Debug::$LOG_VERBOSE); |
|
819 | 819 | |
820 | - if (count($article_labels) != 0) { |
|
821 | - print_r($article_labels); |
|
822 | - } |
|
823 | - } |
|
820 | + if (count($article_labels) != 0) { |
|
821 | + print_r($article_labels); |
|
822 | + } |
|
823 | + } |
|
824 | 824 | |
825 | - Debug::log("force catchup: $entry_force_catchup", Debug::$LOG_VERBOSE); |
|
825 | + Debug::log("force catchup: $entry_force_catchup", Debug::$LOG_VERBOSE); |
|
826 | 826 | |
827 | - if ($cache_images) |
|
828 | - RSSUtils::cache_media($entry_content, $site_url); |
|
827 | + if ($cache_images) |
|
828 | + RSSUtils::cache_media($entry_content, $site_url); |
|
829 | 829 | |
830 | - $csth = $pdo->prepare("SELECT id FROM ttrss_entries |
|
830 | + $csth = $pdo->prepare("SELECT id FROM ttrss_entries |
|
831 | 831 | WHERE guid = ? OR guid = ?"); |
832 | - $csth->execute([$entry_guid, $entry_guid_hashed]); |
|
832 | + $csth->execute([$entry_guid, $entry_guid_hashed]); |
|
833 | 833 | |
834 | - if (!$row = $csth->fetch()) { |
|
834 | + if (!$row = $csth->fetch()) { |
|
835 | 835 | |
836 | - Debug::log("base guid [$entry_guid or $entry_guid_hashed] not found, creating...", Debug::$LOG_VERBOSE); |
|
836 | + Debug::log("base guid [$entry_guid or $entry_guid_hashed] not found, creating...", Debug::$LOG_VERBOSE); |
|
837 | 837 | |
838 | - // base post entry does not exist, create it |
|
838 | + // base post entry does not exist, create it |
|
839 | 839 | |
840 | - $usth = $pdo->prepare( |
|
841 | - "INSERT INTO ttrss_entries |
|
840 | + $usth = $pdo->prepare( |
|
841 | + "INSERT INTO ttrss_entries |
|
842 | 842 | (title, |
843 | 843 | guid, |
844 | 844 | link, |
@@ -859,110 +859,110 @@ discard block |
||
859 | 859 | NOW(), |
860 | 860 | ?, ?, ?, ?, ?, ?)"); |
861 | 861 | |
862 | - $usth->execute([$entry_title, |
|
863 | - $entry_guid_hashed, |
|
864 | - $entry_link, |
|
865 | - $entry_timestamp_fmt, |
|
866 | - "$entry_content", |
|
867 | - $entry_current_hash, |
|
868 | - $date_feed_processed, |
|
869 | - $entry_comments, |
|
870 | - (int)$num_comments, |
|
871 | - $entry_plugin_data, |
|
872 | - "$entry_language", |
|
873 | - "$entry_author"]); |
|
862 | + $usth->execute([$entry_title, |
|
863 | + $entry_guid_hashed, |
|
864 | + $entry_link, |
|
865 | + $entry_timestamp_fmt, |
|
866 | + "$entry_content", |
|
867 | + $entry_current_hash, |
|
868 | + $date_feed_processed, |
|
869 | + $entry_comments, |
|
870 | + (int)$num_comments, |
|
871 | + $entry_plugin_data, |
|
872 | + "$entry_language", |
|
873 | + "$entry_author"]); |
|
874 | 874 | |
875 | - } |
|
875 | + } |
|
876 | 876 | |
877 | - $csth->execute([$entry_guid, $entry_guid_hashed]); |
|
877 | + $csth->execute([$entry_guid, $entry_guid_hashed]); |
|
878 | 878 | |
879 | - $entry_ref_id = 0; |
|
880 | - $entry_int_id = 0; |
|
879 | + $entry_ref_id = 0; |
|
880 | + $entry_int_id = 0; |
|
881 | 881 | |
882 | - if ($row = $csth->fetch()) { |
|
882 | + if ($row = $csth->fetch()) { |
|
883 | 883 | |
884 | - Debug::log("base guid found, checking for user record", Debug::$LOG_VERBOSE); |
|
884 | + Debug::log("base guid found, checking for user record", Debug::$LOG_VERBOSE); |
|
885 | 885 | |
886 | - $ref_id = $row['id']; |
|
887 | - $entry_ref_id = $ref_id; |
|
886 | + $ref_id = $row['id']; |
|
887 | + $entry_ref_id = $ref_id; |
|
888 | 888 | |
889 | - if (RSSUtils::find_article_filter($article_filters, "filter")) { |
|
890 | - Debug::log("article is filtered out, nothing to do.", Debug::$LOG_VERBOSE); |
|
891 | - $pdo->commit(); |
|
892 | - continue; |
|
893 | - } |
|
889 | + if (RSSUtils::find_article_filter($article_filters, "filter")) { |
|
890 | + Debug::log("article is filtered out, nothing to do.", Debug::$LOG_VERBOSE); |
|
891 | + $pdo->commit(); |
|
892 | + continue; |
|
893 | + } |
|
894 | 894 | |
895 | - $score = RSSUtils::calculate_article_score($article_filters) + $entry_score_modifier; |
|
895 | + $score = RSSUtils::calculate_article_score($article_filters) + $entry_score_modifier; |
|
896 | 896 | |
897 | - Debug::log("initial score: $score [including plugin modifier: $entry_score_modifier]", Debug::$LOG_VERBOSE); |
|
897 | + Debug::log("initial score: $score [including plugin modifier: $entry_score_modifier]", Debug::$LOG_VERBOSE); |
|
898 | 898 | |
899 | - // check for user post link to main table |
|
899 | + // check for user post link to main table |
|
900 | 900 | |
901 | - $sth = $pdo->prepare("SELECT ref_id, int_id FROM ttrss_user_entries WHERE |
|
901 | + $sth = $pdo->prepare("SELECT ref_id, int_id FROM ttrss_user_entries WHERE |
|
902 | 902 | ref_id = ? AND owner_uid = ?"); |
903 | - $sth->execute([$ref_id, $owner_uid]); |
|
904 | - |
|
905 | - // okay it doesn't exist - create user entry |
|
906 | - if ($row = $sth->fetch()) { |
|
907 | - $entry_ref_id = $row["ref_id"]; |
|
908 | - $entry_int_id = $row["int_id"]; |
|
909 | - |
|
910 | - Debug::log("user record FOUND: RID: $entry_ref_id, IID: $entry_int_id", Debug::$LOG_VERBOSE); |
|
911 | - } else { |
|
912 | - |
|
913 | - Debug::log("user record not found, creating...", Debug::$LOG_VERBOSE); |
|
914 | - |
|
915 | - if ($score >= -500 && !RSSUtils::find_article_filter($article_filters, 'catchup') && !$entry_force_catchup) { |
|
916 | - $unread = 1; |
|
917 | - $last_read_qpart = null; |
|
918 | - } else { |
|
919 | - $unread = 0; |
|
920 | - $last_read_qpart = date("Y-m-d H:i"); // we can't use NOW() here because it gets quoted |
|
921 | - } |
|
922 | - |
|
923 | - if (RSSUtils::find_article_filter($article_filters, 'mark') || $score > 1000) { |
|
924 | - $marked = 1; |
|
925 | - } else { |
|
926 | - $marked = 0; |
|
927 | - } |
|
928 | - |
|
929 | - if (RSSUtils::find_article_filter($article_filters, 'publish')) { |
|
930 | - $published = 1; |
|
931 | - } else { |
|
932 | - $published = 0; |
|
933 | - } |
|
934 | - |
|
935 | - $last_marked = ($marked == 1) ? 'NOW()' : 'NULL'; |
|
936 | - $last_published = ($published == 1) ? 'NOW()' : 'NULL'; |
|
937 | - |
|
938 | - $sth = $pdo->prepare( |
|
939 | - "INSERT INTO ttrss_user_entries |
|
903 | + $sth->execute([$ref_id, $owner_uid]); |
|
904 | + |
|
905 | + // okay it doesn't exist - create user entry |
|
906 | + if ($row = $sth->fetch()) { |
|
907 | + $entry_ref_id = $row["ref_id"]; |
|
908 | + $entry_int_id = $row["int_id"]; |
|
909 | + |
|
910 | + Debug::log("user record FOUND: RID: $entry_ref_id, IID: $entry_int_id", Debug::$LOG_VERBOSE); |
|
911 | + } else { |
|
912 | + |
|
913 | + Debug::log("user record not found, creating...", Debug::$LOG_VERBOSE); |
|
914 | + |
|
915 | + if ($score >= -500 && !RSSUtils::find_article_filter($article_filters, 'catchup') && !$entry_force_catchup) { |
|
916 | + $unread = 1; |
|
917 | + $last_read_qpart = null; |
|
918 | + } else { |
|
919 | + $unread = 0; |
|
920 | + $last_read_qpart = date("Y-m-d H:i"); // we can't use NOW() here because it gets quoted |
|
921 | + } |
|
922 | + |
|
923 | + if (RSSUtils::find_article_filter($article_filters, 'mark') || $score > 1000) { |
|
924 | + $marked = 1; |
|
925 | + } else { |
|
926 | + $marked = 0; |
|
927 | + } |
|
928 | + |
|
929 | + if (RSSUtils::find_article_filter($article_filters, 'publish')) { |
|
930 | + $published = 1; |
|
931 | + } else { |
|
932 | + $published = 0; |
|
933 | + } |
|
934 | + |
|
935 | + $last_marked = ($marked == 1) ? 'NOW()' : 'NULL'; |
|
936 | + $last_published = ($published == 1) ? 'NOW()' : 'NULL'; |
|
937 | + |
|
938 | + $sth = $pdo->prepare( |
|
939 | + "INSERT INTO ttrss_user_entries |
|
940 | 940 | (ref_id, owner_uid, feed_id, unread, last_read, marked, |
941 | 941 | published, score, tag_cache, label_cache, uuid, |
942 | 942 | last_marked, last_published) |
943 | 943 | VALUES (?, ?, ?, ?, ?, ?, ?, ?, '', '', '', ".$last_marked.", ".$last_published.")"); |
944 | 944 | |
945 | - $sth->execute([$ref_id, $owner_uid, $feed, $unread, $last_read_qpart, $marked, |
|
946 | - $published, $score]); |
|
945 | + $sth->execute([$ref_id, $owner_uid, $feed, $unread, $last_read_qpart, $marked, |
|
946 | + $published, $score]); |
|
947 | 947 | |
948 | - $sth = $pdo->prepare("SELECT int_id FROM ttrss_user_entries WHERE |
|
948 | + $sth = $pdo->prepare("SELECT int_id FROM ttrss_user_entries WHERE |
|
949 | 949 | ref_id = ? AND owner_uid = ? AND |
950 | 950 | feed_id = ? LIMIT 1"); |
951 | 951 | |
952 | - $sth->execute([$ref_id, $owner_uid, $feed]); |
|
952 | + $sth->execute([$ref_id, $owner_uid, $feed]); |
|
953 | 953 | |
954 | - if ($row = $sth->fetch()) |
|
955 | - $entry_int_id = $row['int_id']; |
|
956 | - } |
|
954 | + if ($row = $sth->fetch()) |
|
955 | + $entry_int_id = $row['int_id']; |
|
956 | + } |
|
957 | 957 | |
958 | - Debug::log("resulting RID: $entry_ref_id, IID: $entry_int_id", Debug::$LOG_VERBOSE); |
|
958 | + Debug::log("resulting RID: $entry_ref_id, IID: $entry_int_id", Debug::$LOG_VERBOSE); |
|
959 | 959 | |
960 | - if (DB_TYPE == "pgsql") |
|
961 | - $tsvector_qpart = "tsvector_combined = to_tsvector(:ts_lang, :ts_content),"; |
|
962 | - else |
|
963 | - $tsvector_qpart = ""; |
|
960 | + if (DB_TYPE == "pgsql") |
|
961 | + $tsvector_qpart = "tsvector_combined = to_tsvector(:ts_lang, :ts_content),"; |
|
962 | + else |
|
963 | + $tsvector_qpart = ""; |
|
964 | 964 | |
965 | - $sth = $pdo->prepare("UPDATE ttrss_entries |
|
965 | + $sth = $pdo->prepare("UPDATE ttrss_entries |
|
966 | 966 | SET title = :title, |
967 | 967 | $tsvector_qpart |
968 | 968 | content = :content, |
@@ -975,634 +975,634 @@ discard block |
||
975 | 975 | lang = :lang |
976 | 976 | WHERE id = :id"); |
977 | 977 | |
978 | - $params = [":title" => $entry_title, |
|
979 | - ":content" => "$entry_content", |
|
980 | - ":content_hash" => $entry_current_hash, |
|
981 | - ":updated" => $entry_timestamp_fmt, |
|
982 | - ":num_comments" => (int)$num_comments, |
|
983 | - ":plugin_data" => $entry_plugin_data, |
|
984 | - ":author" => "$entry_author", |
|
985 | - ":lang" => $entry_language, |
|
986 | - ":id" => $ref_id]; |
|
987 | - |
|
988 | - if (DB_TYPE == "pgsql") { |
|
989 | - $params[":ts_lang"] = $feed_language; |
|
990 | - $params[":ts_content"] = mb_substr(strip_tags($entry_title . " " . $entry_content), 0, 900000); |
|
991 | - } |
|
992 | - |
|
993 | - $sth->execute($params); |
|
994 | - |
|
995 | - // update aux data |
|
996 | - $sth = $pdo->prepare("UPDATE ttrss_user_entries |
|
978 | + $params = [":title" => $entry_title, |
|
979 | + ":content" => "$entry_content", |
|
980 | + ":content_hash" => $entry_current_hash, |
|
981 | + ":updated" => $entry_timestamp_fmt, |
|
982 | + ":num_comments" => (int)$num_comments, |
|
983 | + ":plugin_data" => $entry_plugin_data, |
|
984 | + ":author" => "$entry_author", |
|
985 | + ":lang" => $entry_language, |
|
986 | + ":id" => $ref_id]; |
|
987 | + |
|
988 | + if (DB_TYPE == "pgsql") { |
|
989 | + $params[":ts_lang"] = $feed_language; |
|
990 | + $params[":ts_content"] = mb_substr(strip_tags($entry_title . " " . $entry_content), 0, 900000); |
|
991 | + } |
|
992 | + |
|
993 | + $sth->execute($params); |
|
994 | + |
|
995 | + // update aux data |
|
996 | + $sth = $pdo->prepare("UPDATE ttrss_user_entries |
|
997 | 997 | SET score = ? WHERE ref_id = ?"); |
998 | - $sth->execute([$score, $ref_id]); |
|
998 | + $sth->execute([$score, $ref_id]); |
|
999 | 999 | |
1000 | - if ($mark_unread_on_update && |
|
1001 | - !$entry_force_catchup && |
|
1002 | - !RSSUtils::find_article_filter($article_filters, 'catchup')) { |
|
1000 | + if ($mark_unread_on_update && |
|
1001 | + !$entry_force_catchup && |
|
1002 | + !RSSUtils::find_article_filter($article_filters, 'catchup')) { |
|
1003 | 1003 | |
1004 | - Debug::log("article updated, marking unread as requested.", Debug::$LOG_VERBOSE); |
|
1004 | + Debug::log("article updated, marking unread as requested.", Debug::$LOG_VERBOSE); |
|
1005 | 1005 | |
1006 | - $sth = $pdo->prepare("UPDATE ttrss_user_entries |
|
1006 | + $sth = $pdo->prepare("UPDATE ttrss_user_entries |
|
1007 | 1007 | SET last_read = null, unread = true WHERE ref_id = ?"); |
1008 | - $sth->execute([$ref_id]); |
|
1009 | - } else { |
|
1010 | - Debug::log("article updated, but we're forbidden to mark it unread.", Debug::$LOG_VERBOSE); |
|
1011 | - } |
|
1012 | - } |
|
1008 | + $sth->execute([$ref_id]); |
|
1009 | + } else { |
|
1010 | + Debug::log("article updated, but we're forbidden to mark it unread.", Debug::$LOG_VERBOSE); |
|
1011 | + } |
|
1012 | + } |
|
1013 | 1013 | |
1014 | - Debug::log("assigning labels [other]...", Debug::$LOG_VERBOSE); |
|
1014 | + Debug::log("assigning labels [other]...", Debug::$LOG_VERBOSE); |
|
1015 | 1015 | |
1016 | - foreach ($article_labels as $label) { |
|
1017 | - Labels::add_article($entry_ref_id, $label[1], $owner_uid); |
|
1018 | - } |
|
1016 | + foreach ($article_labels as $label) { |
|
1017 | + Labels::add_article($entry_ref_id, $label[1], $owner_uid); |
|
1018 | + } |
|
1019 | 1019 | |
1020 | - Debug::log("assigning labels [filters]...", Debug::$LOG_VERBOSE); |
|
1020 | + Debug::log("assigning labels [filters]...", Debug::$LOG_VERBOSE); |
|
1021 | 1021 | |
1022 | - RSSUtils::assign_article_to_label_filters($entry_ref_id, $article_filters, |
|
1023 | - $owner_uid, $article_labels); |
|
1022 | + RSSUtils::assign_article_to_label_filters($entry_ref_id, $article_filters, |
|
1023 | + $owner_uid, $article_labels); |
|
1024 | 1024 | |
1025 | - Debug::log("looking for enclosures...", Debug::$LOG_VERBOSE); |
|
1025 | + Debug::log("looking for enclosures...", Debug::$LOG_VERBOSE); |
|
1026 | 1026 | |
1027 | - // enclosures |
|
1027 | + // enclosures |
|
1028 | 1028 | |
1029 | - $enclosures = array(); |
|
1029 | + $enclosures = array(); |
|
1030 | 1030 | |
1031 | - $encs = $item->get_enclosures(); |
|
1031 | + $encs = $item->get_enclosures(); |
|
1032 | 1032 | |
1033 | - if (is_array($encs)) { |
|
1034 | - foreach ($encs as $e) { |
|
1035 | - $e_item = array( |
|
1036 | - rewrite_relative_url($site_url, $e->link), |
|
1037 | - $e->type, $e->length, $e->title, $e->width, $e->height); |
|
1033 | + if (is_array($encs)) { |
|
1034 | + foreach ($encs as $e) { |
|
1035 | + $e_item = array( |
|
1036 | + rewrite_relative_url($site_url, $e->link), |
|
1037 | + $e->type, $e->length, $e->title, $e->width, $e->height); |
|
1038 | 1038 | |
1039 | - // Yet another episode of "mysql utf8_general_ci is gimped" |
|
1040 | - if (DB_TYPE == "mysql" && MYSQL_CHARSET != "UTF8MB4") { |
|
1041 | - for ($i = 0; $i < count($e_item); $i++) { |
|
1042 | - if (is_string($e_item[$i])) { |
|
1043 | - $e_item[$i] = RSSUtils::strip_utf8mb4($e_item[$i]); |
|
1044 | - } |
|
1045 | - } |
|
1046 | - } |
|
1039 | + // Yet another episode of "mysql utf8_general_ci is gimped" |
|
1040 | + if (DB_TYPE == "mysql" && MYSQL_CHARSET != "UTF8MB4") { |
|
1041 | + for ($i = 0; $i < count($e_item); $i++) { |
|
1042 | + if (is_string($e_item[$i])) { |
|
1043 | + $e_item[$i] = RSSUtils::strip_utf8mb4($e_item[$i]); |
|
1044 | + } |
|
1045 | + } |
|
1046 | + } |
|
1047 | 1047 | |
1048 | - array_push($enclosures, $e_item); |
|
1049 | - } |
|
1050 | - } |
|
1048 | + array_push($enclosures, $e_item); |
|
1049 | + } |
|
1050 | + } |
|
1051 | 1051 | |
1052 | - if ($cache_images) |
|
1053 | - RSSUtils::cache_enclosures($enclosures, $site_url); |
|
1052 | + if ($cache_images) |
|
1053 | + RSSUtils::cache_enclosures($enclosures, $site_url); |
|
1054 | 1054 | |
1055 | - if (Debug::get_loglevel() >= Debug::$LOG_EXTENDED) { |
|
1056 | - Debug::log("article enclosures:", Debug::$LOG_VERBOSE); |
|
1057 | - print_r($enclosures); |
|
1058 | - } |
|
1055 | + if (Debug::get_loglevel() >= Debug::$LOG_EXTENDED) { |
|
1056 | + Debug::log("article enclosures:", Debug::$LOG_VERBOSE); |
|
1057 | + print_r($enclosures); |
|
1058 | + } |
|
1059 | 1059 | |
1060 | - $esth = $pdo->prepare("SELECT id FROM ttrss_enclosures |
|
1060 | + $esth = $pdo->prepare("SELECT id FROM ttrss_enclosures |
|
1061 | 1061 | WHERE content_url = ? AND content_type = ? AND post_id = ?"); |
1062 | 1062 | |
1063 | - $usth = $pdo->prepare("INSERT INTO ttrss_enclosures |
|
1063 | + $usth = $pdo->prepare("INSERT INTO ttrss_enclosures |
|
1064 | 1064 | (content_url, content_type, title, duration, post_id, width, height) VALUES |
1065 | 1065 | (?, ?, ?, ?, ?, ?, ?)"); |
1066 | 1066 | |
1067 | - foreach ($enclosures as $enc) { |
|
1068 | - $enc_url = $enc[0]; |
|
1069 | - $enc_type = $enc[1]; |
|
1070 | - $enc_dur = (int)$enc[2]; |
|
1071 | - $enc_title = $enc[3]; |
|
1072 | - $enc_width = intval($enc[4]); |
|
1073 | - $enc_height = intval($enc[5]); |
|
1067 | + foreach ($enclosures as $enc) { |
|
1068 | + $enc_url = $enc[0]; |
|
1069 | + $enc_type = $enc[1]; |
|
1070 | + $enc_dur = (int)$enc[2]; |
|
1071 | + $enc_title = $enc[3]; |
|
1072 | + $enc_width = intval($enc[4]); |
|
1073 | + $enc_height = intval($enc[5]); |
|
1074 | 1074 | |
1075 | - $esth->execute([$enc_url, $enc_type, $entry_ref_id]); |
|
1075 | + $esth->execute([$enc_url, $enc_type, $entry_ref_id]); |
|
1076 | 1076 | |
1077 | - if (!$esth->fetch()) { |
|
1078 | - $usth->execute([$enc_url, $enc_type, (string)$enc_title, $enc_dur, $entry_ref_id, $enc_width, $enc_height]); |
|
1079 | - } |
|
1080 | - } |
|
1077 | + if (!$esth->fetch()) { |
|
1078 | + $usth->execute([$enc_url, $enc_type, (string)$enc_title, $enc_dur, $entry_ref_id, $enc_width, $enc_height]); |
|
1079 | + } |
|
1080 | + } |
|
1081 | 1081 | |
1082 | - // check for manual tags (we have to do it here since they're loaded from filters) |
|
1082 | + // check for manual tags (we have to do it here since they're loaded from filters) |
|
1083 | 1083 | |
1084 | - foreach ($article_filters as $f) { |
|
1085 | - if ($f["type"] == "tag") { |
|
1084 | + foreach ($article_filters as $f) { |
|
1085 | + if ($f["type"] == "tag") { |
|
1086 | 1086 | |
1087 | - $manual_tags = trim_array(explode(",", $f["param"])); |
|
1087 | + $manual_tags = trim_array(explode(",", $f["param"])); |
|
1088 | 1088 | |
1089 | - foreach ($manual_tags as $tag) { |
|
1090 | - array_push($entry_tags, $tag); |
|
1091 | - } |
|
1092 | - } |
|
1093 | - } |
|
1089 | + foreach ($manual_tags as $tag) { |
|
1090 | + array_push($entry_tags, $tag); |
|
1091 | + } |
|
1092 | + } |
|
1093 | + } |
|
1094 | 1094 | |
1095 | - // Skip boring tags |
|
1095 | + // Skip boring tags |
|
1096 | 1096 | |
1097 | - $boring_tags = trim_array(explode(",", mb_strtolower(get_pref( |
|
1098 | - 'BLACKLISTED_TAGS', $owner_uid, ''), 'utf-8'))); |
|
1097 | + $boring_tags = trim_array(explode(",", mb_strtolower(get_pref( |
|
1098 | + 'BLACKLISTED_TAGS', $owner_uid, ''), 'utf-8'))); |
|
1099 | 1099 | |
1100 | - $filtered_tags = array(); |
|
1101 | - $tags_to_cache = array(); |
|
1100 | + $filtered_tags = array(); |
|
1101 | + $tags_to_cache = array(); |
|
1102 | 1102 | |
1103 | - foreach ($entry_tags as $tag) { |
|
1104 | - if (array_search($tag, $boring_tags) === false) { |
|
1105 | - array_push($filtered_tags, $tag); |
|
1106 | - } |
|
1107 | - } |
|
1103 | + foreach ($entry_tags as $tag) { |
|
1104 | + if (array_search($tag, $boring_tags) === false) { |
|
1105 | + array_push($filtered_tags, $tag); |
|
1106 | + } |
|
1107 | + } |
|
1108 | 1108 | |
1109 | - $filtered_tags = array_unique($filtered_tags); |
|
1109 | + $filtered_tags = array_unique($filtered_tags); |
|
1110 | 1110 | |
1111 | - if (Debug::get_loglevel() >= Debug::$LOG_VERBOSE) { |
|
1112 | - Debug::log("filtered tags: " . implode(", ", $filtered_tags), Debug::$LOG_VERBOSE); |
|
1111 | + if (Debug::get_loglevel() >= Debug::$LOG_VERBOSE) { |
|
1112 | + Debug::log("filtered tags: " . implode(", ", $filtered_tags), Debug::$LOG_VERBOSE); |
|
1113 | 1113 | |
1114 | - } |
|
1114 | + } |
|
1115 | 1115 | |
1116 | - // Save article tags in the database |
|
1116 | + // Save article tags in the database |
|
1117 | 1117 | |
1118 | - if (count($filtered_tags) > 0) { |
|
1118 | + if (count($filtered_tags) > 0) { |
|
1119 | 1119 | |
1120 | - $tsth = $pdo->prepare("SELECT id FROM ttrss_tags |
|
1120 | + $tsth = $pdo->prepare("SELECT id FROM ttrss_tags |
|
1121 | 1121 | WHERE tag_name = ? AND post_int_id = ? AND |
1122 | 1122 | owner_uid = ? LIMIT 1"); |
1123 | 1123 | |
1124 | - $usth = $pdo->prepare("INSERT INTO ttrss_tags |
|
1124 | + $usth = $pdo->prepare("INSERT INTO ttrss_tags |
|
1125 | 1125 | (owner_uid,tag_name,post_int_id) |
1126 | 1126 | VALUES (?, ?, ?)"); |
1127 | 1127 | |
1128 | - $filtered_tags = FeedItem_Common::normalize_categories($filtered_tags); |
|
1128 | + $filtered_tags = FeedItem_Common::normalize_categories($filtered_tags); |
|
1129 | 1129 | |
1130 | - foreach ($filtered_tags as $tag) { |
|
1131 | - $tsth->execute([$tag, $entry_int_id, $owner_uid]); |
|
1130 | + foreach ($filtered_tags as $tag) { |
|
1131 | + $tsth->execute([$tag, $entry_int_id, $owner_uid]); |
|
1132 | 1132 | |
1133 | - if (!$tsth->fetch()) { |
|
1134 | - $usth->execute([$owner_uid, $tag, $entry_int_id]); |
|
1135 | - } |
|
1133 | + if (!$tsth->fetch()) { |
|
1134 | + $usth->execute([$owner_uid, $tag, $entry_int_id]); |
|
1135 | + } |
|
1136 | 1136 | |
1137 | - array_push($tags_to_cache, $tag); |
|
1138 | - } |
|
1137 | + array_push($tags_to_cache, $tag); |
|
1138 | + } |
|
1139 | 1139 | |
1140 | - /* update the cache */ |
|
1141 | - $tags_str = join(",", $tags_to_cache); |
|
1140 | + /* update the cache */ |
|
1141 | + $tags_str = join(",", $tags_to_cache); |
|
1142 | 1142 | |
1143 | - $tsth = $pdo->prepare("UPDATE ttrss_user_entries |
|
1143 | + $tsth = $pdo->prepare("UPDATE ttrss_user_entries |
|
1144 | 1144 | SET tag_cache = ? WHERE ref_id = ? |
1145 | 1145 | AND owner_uid = ?"); |
1146 | - $tsth->execute([$tags_str, $entry_ref_id, $owner_uid]); |
|
1147 | - } |
|
1146 | + $tsth->execute([$tags_str, $entry_ref_id, $owner_uid]); |
|
1147 | + } |
|
1148 | 1148 | |
1149 | - Debug::log("article processed", Debug::$LOG_VERBOSE); |
|
1149 | + Debug::log("article processed", Debug::$LOG_VERBOSE); |
|
1150 | 1150 | |
1151 | - $pdo->commit(); |
|
1152 | - } |
|
1151 | + $pdo->commit(); |
|
1152 | + } |
|
1153 | 1153 | |
1154 | - Debug::log("purging feed...", Debug::$LOG_VERBOSE); |
|
1154 | + Debug::log("purging feed...", Debug::$LOG_VERBOSE); |
|
1155 | 1155 | |
1156 | - Feeds::purge_feed($feed, 0); |
|
1156 | + Feeds::purge_feed($feed, 0); |
|
1157 | 1157 | |
1158 | - $sth = $pdo->prepare("UPDATE ttrss_feeds |
|
1158 | + $sth = $pdo->prepare("UPDATE ttrss_feeds |
|
1159 | 1159 | SET last_updated = NOW(), last_unconditional = NOW(), last_error = '' WHERE id = ?"); |
1160 | - $sth->execute([$feed]); |
|
1160 | + $sth->execute([$feed]); |
|
1161 | 1161 | |
1162 | - } else { |
|
1162 | + } else { |
|
1163 | 1163 | |
1164 | - $error_msg = mb_substr($rss->error(), 0, 245); |
|
1164 | + $error_msg = mb_substr($rss->error(), 0, 245); |
|
1165 | 1165 | |
1166 | - Debug::log("fetch error: $error_msg", Debug::$LOG_VERBOSE); |
|
1166 | + Debug::log("fetch error: $error_msg", Debug::$LOG_VERBOSE); |
|
1167 | 1167 | |
1168 | - if (count($rss->errors()) > 1) { |
|
1169 | - foreach ($rss->errors() as $error) { |
|
1170 | - Debug::log("+ $error", Debug::$LOG_VERBOSE); |
|
1171 | - } |
|
1172 | - } |
|
1168 | + if (count($rss->errors()) > 1) { |
|
1169 | + foreach ($rss->errors() as $error) { |
|
1170 | + Debug::log("+ $error", Debug::$LOG_VERBOSE); |
|
1171 | + } |
|
1172 | + } |
|
1173 | 1173 | |
1174 | - $sth = $pdo->prepare("UPDATE ttrss_feeds SET last_error = ?, |
|
1174 | + $sth = $pdo->prepare("UPDATE ttrss_feeds SET last_error = ?, |
|
1175 | 1175 | last_updated = NOW(), last_unconditional = NOW() WHERE id = ?"); |
1176 | - $sth->execute([$error_msg, $feed]); |
|
1176 | + $sth->execute([$error_msg, $feed]); |
|
1177 | 1177 | |
1178 | - unset($rss); |
|
1178 | + unset($rss); |
|
1179 | 1179 | |
1180 | - Debug::log("update failed.", Debug::$LOG_VERBOSE); |
|
1181 | - return false; |
|
1182 | - } |
|
1180 | + Debug::log("update failed.", Debug::$LOG_VERBOSE); |
|
1181 | + return false; |
|
1182 | + } |
|
1183 | 1183 | |
1184 | - Debug::log("update done.", Debug::$LOG_VERBOSE); |
|
1184 | + Debug::log("update done.", Debug::$LOG_VERBOSE); |
|
1185 | 1185 | |
1186 | - return true; |
|
1187 | - } |
|
1186 | + return true; |
|
1187 | + } |
|
1188 | 1188 | |
1189 | - public static function cache_enclosures($enclosures, $site_url) { |
|
1190 | - $cache = new DiskCache("images"); |
|
1189 | + public static function cache_enclosures($enclosures, $site_url) { |
|
1190 | + $cache = new DiskCache("images"); |
|
1191 | 1191 | |
1192 | - if ($cache->isWritable()) { |
|
1193 | - foreach ($enclosures as $enc) { |
|
1192 | + if ($cache->isWritable()) { |
|
1193 | + foreach ($enclosures as $enc) { |
|
1194 | 1194 | |
1195 | - if (preg_match("/(image|audio|video)/", $enc[1])) { |
|
1196 | - $src = rewrite_relative_url($site_url, $enc[0]); |
|
1195 | + if (preg_match("/(image|audio|video)/", $enc[1])) { |
|
1196 | + $src = rewrite_relative_url($site_url, $enc[0]); |
|
1197 | 1197 | |
1198 | - $local_filename = sha1($src); |
|
1198 | + $local_filename = sha1($src); |
|
1199 | 1199 | |
1200 | - Debug::log("cache_enclosures: downloading: $src to $local_filename", Debug::$LOG_VERBOSE); |
|
1200 | + Debug::log("cache_enclosures: downloading: $src to $local_filename", Debug::$LOG_VERBOSE); |
|
1201 | 1201 | |
1202 | - if (!$cache->exists($local_filename)) { |
|
1202 | + if (!$cache->exists($local_filename)) { |
|
1203 | 1203 | |
1204 | - global $fetch_last_error_code; |
|
1205 | - global $fetch_last_error; |
|
1204 | + global $fetch_last_error_code; |
|
1205 | + global $fetch_last_error; |
|
1206 | 1206 | |
1207 | - $file_content = fetch_file_contents(array("url" => $src, |
|
1208 | - "http_referrer" => $src, |
|
1209 | - "max_size" => MAX_CACHE_FILE_SIZE)); |
|
1207 | + $file_content = fetch_file_contents(array("url" => $src, |
|
1208 | + "http_referrer" => $src, |
|
1209 | + "max_size" => MAX_CACHE_FILE_SIZE)); |
|
1210 | 1210 | |
1211 | - if ($file_content) { |
|
1212 | - $cache->put($local_filename, $file_content); |
|
1213 | - } else { |
|
1214 | - Debug::log("cache_enclosures: failed with $fetch_last_error_code: $fetch_last_error"); |
|
1215 | - } |
|
1216 | - } else if (is_writable($local_filename)) { |
|
1217 | - $cache->touch($local_filename); |
|
1218 | - } |
|
1219 | - } |
|
1220 | - } |
|
1221 | - } |
|
1222 | - } |
|
1211 | + if ($file_content) { |
|
1212 | + $cache->put($local_filename, $file_content); |
|
1213 | + } else { |
|
1214 | + Debug::log("cache_enclosures: failed with $fetch_last_error_code: $fetch_last_error"); |
|
1215 | + } |
|
1216 | + } else if (is_writable($local_filename)) { |
|
1217 | + $cache->touch($local_filename); |
|
1218 | + } |
|
1219 | + } |
|
1220 | + } |
|
1221 | + } |
|
1222 | + } |
|
1223 | 1223 | |
1224 | - public static function cache_media($html, $site_url) { |
|
1225 | - $cache = new DiskCache("images"); |
|
1224 | + public static function cache_media($html, $site_url) { |
|
1225 | + $cache = new DiskCache("images"); |
|
1226 | 1226 | |
1227 | - if ($cache->isWritable()) { |
|
1228 | - $doc = new DOMDocument(); |
|
1229 | - if ($doc->loadHTML($html)) { |
|
1230 | - $xpath = new DOMXPath($doc); |
|
1227 | + if ($cache->isWritable()) { |
|
1228 | + $doc = new DOMDocument(); |
|
1229 | + if ($doc->loadHTML($html)) { |
|
1230 | + $xpath = new DOMXPath($doc); |
|
1231 | 1231 | |
1232 | - $entries = $xpath->query('(//img[@src])|(//video/source[@src])|(//audio/source[@src])'); |
|
1232 | + $entries = $xpath->query('(//img[@src])|(//video/source[@src])|(//audio/source[@src])'); |
|
1233 | 1233 | |
1234 | - foreach ($entries as $entry) { |
|
1235 | - if ($entry->hasAttribute('src') && strpos($entry->getAttribute('src'), "data:") !== 0) { |
|
1236 | - $src = rewrite_relative_url($site_url, $entry->getAttribute('src')); |
|
1234 | + foreach ($entries as $entry) { |
|
1235 | + if ($entry->hasAttribute('src') && strpos($entry->getAttribute('src'), "data:") !== 0) { |
|
1236 | + $src = rewrite_relative_url($site_url, $entry->getAttribute('src')); |
|
1237 | 1237 | |
1238 | - $local_filename = sha1($src); |
|
1238 | + $local_filename = sha1($src); |
|
1239 | 1239 | |
1240 | - Debug::log("cache_media: checking $src", Debug::$LOG_VERBOSE); |
|
1240 | + Debug::log("cache_media: checking $src", Debug::$LOG_VERBOSE); |
|
1241 | 1241 | |
1242 | - if (!$cache->exists($local_filename)) { |
|
1243 | - Debug::log("cache_media: downloading: $src to $local_filename", Debug::$LOG_VERBOSE); |
|
1242 | + if (!$cache->exists($local_filename)) { |
|
1243 | + Debug::log("cache_media: downloading: $src to $local_filename", Debug::$LOG_VERBOSE); |
|
1244 | 1244 | |
1245 | - global $fetch_last_error_code; |
|
1246 | - global $fetch_last_error; |
|
1245 | + global $fetch_last_error_code; |
|
1246 | + global $fetch_last_error; |
|
1247 | 1247 | |
1248 | - $file_content = fetch_file_contents(array("url" => $src, |
|
1249 | - "http_referrer" => $src, |
|
1250 | - "max_size" => MAX_CACHE_FILE_SIZE)); |
|
1248 | + $file_content = fetch_file_contents(array("url" => $src, |
|
1249 | + "http_referrer" => $src, |
|
1250 | + "max_size" => MAX_CACHE_FILE_SIZE)); |
|
1251 | 1251 | |
1252 | - if ($file_content) { |
|
1253 | - $cache->put($local_filename, $file_content); |
|
1254 | - } else { |
|
1255 | - Debug::log("cache_media: failed with $fetch_last_error_code: $fetch_last_error"); |
|
1256 | - } |
|
1257 | - } else if ($cache->isWritable($local_filename)) { |
|
1258 | - $cache->touch($local_filename); |
|
1259 | - } |
|
1260 | - } |
|
1261 | - } |
|
1262 | - } |
|
1263 | - } |
|
1264 | - } |
|
1252 | + if ($file_content) { |
|
1253 | + $cache->put($local_filename, $file_content); |
|
1254 | + } else { |
|
1255 | + Debug::log("cache_media: failed with $fetch_last_error_code: $fetch_last_error"); |
|
1256 | + } |
|
1257 | + } else if ($cache->isWritable($local_filename)) { |
|
1258 | + $cache->touch($local_filename); |
|
1259 | + } |
|
1260 | + } |
|
1261 | + } |
|
1262 | + } |
|
1263 | + } |
|
1264 | + } |
|
1265 | 1265 | |
1266 | - public static function expire_error_log() { |
|
1267 | - Debug::log("Removing old error log entries..."); |
|
1266 | + public static function expire_error_log() { |
|
1267 | + Debug::log("Removing old error log entries..."); |
|
1268 | 1268 | |
1269 | - $pdo = Db::pdo(); |
|
1269 | + $pdo = Db::pdo(); |
|
1270 | 1270 | |
1271 | - if (DB_TYPE == "pgsql") { |
|
1272 | - $pdo->query("DELETE FROM ttrss_error_log |
|
1271 | + if (DB_TYPE == "pgsql") { |
|
1272 | + $pdo->query("DELETE FROM ttrss_error_log |
|
1273 | 1273 | WHERE created_at < NOW() - INTERVAL '7 days'"); |
1274 | - } else { |
|
1275 | - $pdo->query("DELETE FROM ttrss_error_log |
|
1274 | + } else { |
|
1275 | + $pdo->query("DELETE FROM ttrss_error_log |
|
1276 | 1276 | WHERE created_at < DATE_SUB(NOW(), INTERVAL 7 DAY)"); |
1277 | - } |
|
1278 | - } |
|
1277 | + } |
|
1278 | + } |
|
1279 | 1279 | |
1280 | - public static function expire_feed_archive() { |
|
1281 | - Debug::log("Removing old archived feeds..."); |
|
1280 | + public static function expire_feed_archive() { |
|
1281 | + Debug::log("Removing old archived feeds..."); |
|
1282 | 1282 | |
1283 | - $pdo = Db::pdo(); |
|
1283 | + $pdo = Db::pdo(); |
|
1284 | 1284 | |
1285 | - if (DB_TYPE == "pgsql") { |
|
1286 | - $pdo->query("DELETE FROM ttrss_archived_feeds |
|
1285 | + if (DB_TYPE == "pgsql") { |
|
1286 | + $pdo->query("DELETE FROM ttrss_archived_feeds |
|
1287 | 1287 | WHERE created < NOW() - INTERVAL '1 month'"); |
1288 | - } else { |
|
1289 | - $pdo->query("DELETE FROM ttrss_archived_feeds |
|
1288 | + } else { |
|
1289 | + $pdo->query("DELETE FROM ttrss_archived_feeds |
|
1290 | 1290 | WHERE created < DATE_SUB(NOW(), INTERVAL 1 MONTH)"); |
1291 | - } |
|
1292 | - } |
|
1293 | - |
|
1294 | - public static function expire_lock_files() { |
|
1295 | - Debug::log("Removing old lock files...", Debug::$LOG_VERBOSE); |
|
1296 | - |
|
1297 | - $num_deleted = 0; |
|
1298 | - |
|
1299 | - if (is_writable(LOCK_DIRECTORY)) { |
|
1300 | - $files = glob(LOCK_DIRECTORY . "/*.lock"); |
|
1301 | - |
|
1302 | - if ($files) { |
|
1303 | - foreach ($files as $file) { |
|
1304 | - if (!file_is_locked(basename($file)) && time() - filemtime($file) > 86400*2) { |
|
1305 | - unlink($file); |
|
1306 | - ++$num_deleted; |
|
1307 | - } |
|
1308 | - } |
|
1309 | - } |
|
1310 | - } |
|
1311 | - |
|
1312 | - Debug::log("removed $num_deleted old lock files."); |
|
1313 | - } |
|
1314 | - |
|
1315 | - /** |
|
1316 | - * Source: http://www.php.net/manual/en/function.parse-url.php#104527 |
|
1317 | - * Returns the url query as associative array |
|
1318 | - * |
|
1319 | - * @param string query |
|
1320 | - * @return array params |
|
1321 | - */ |
|
1322 | - public static function convertUrlQuery($query) { |
|
1323 | - $queryParts = explode('&', $query); |
|
1324 | - |
|
1325 | - $params = array(); |
|
1326 | - |
|
1327 | - foreach ($queryParts as $param) { |
|
1328 | - $item = explode('=', $param); |
|
1329 | - $params[$item[0]] = $item[1]; |
|
1330 | - } |
|
1331 | - |
|
1332 | - return $params; |
|
1333 | - } |
|
1334 | - |
|
1335 | - public static function get_article_filters($filters, $title, $content, $link, $author, $tags, &$matched_rules = false, &$matched_filters = false) { |
|
1336 | - $matches = array(); |
|
1337 | - |
|
1338 | - foreach ($filters as $filter) { |
|
1339 | - $match_any_rule = $filter["match_any_rule"]; |
|
1340 | - $inverse = $filter["inverse"]; |
|
1341 | - $filter_match = false; |
|
1342 | - |
|
1343 | - foreach ($filter["rules"] as $rule) { |
|
1344 | - $match = false; |
|
1345 | - $reg_exp = str_replace('/', '\/', $rule["reg_exp"]); |
|
1346 | - $rule_inverse = $rule["inverse"]; |
|
1347 | - |
|
1348 | - if (!$reg_exp) |
|
1349 | - continue; |
|
1350 | - |
|
1351 | - switch ($rule["type"]) { |
|
1352 | - case "title": |
|
1353 | - $match = @preg_match("/$reg_exp/iu", $title); |
|
1354 | - break; |
|
1355 | - case "content": |
|
1356 | - // we don't need to deal with multiline regexps |
|
1357 | - $content = preg_replace("/[\r\n\t]/", "", $content); |
|
1358 | - |
|
1359 | - $match = @preg_match("/$reg_exp/iu", $content); |
|
1360 | - break; |
|
1361 | - case "both": |
|
1362 | - // we don't need to deal with multiline regexps |
|
1363 | - $content = preg_replace("/[\r\n\t]/", "", $content); |
|
1364 | - |
|
1365 | - $match = (@preg_match("/$reg_exp/iu", $title) || @preg_match("/$reg_exp/iu", $content)); |
|
1366 | - break; |
|
1367 | - case "link": |
|
1368 | - $match = @preg_match("/$reg_exp/iu", $link); |
|
1369 | - break; |
|
1370 | - case "author": |
|
1371 | - $match = @preg_match("/$reg_exp/iu", $author); |
|
1372 | - break; |
|
1373 | - case "tag": |
|
1374 | - foreach ($tags as $tag) { |
|
1375 | - if (@preg_match("/$reg_exp/iu", $tag)) { |
|
1376 | - $match = true; |
|
1377 | - break; |
|
1378 | - } |
|
1379 | - } |
|
1380 | - break; |
|
1381 | - } |
|
1382 | - |
|
1383 | - if ($rule_inverse) $match = !$match; |
|
1384 | - |
|
1385 | - if ($match_any_rule) { |
|
1386 | - if ($match) { |
|
1387 | - $filter_match = true; |
|
1388 | - break; |
|
1389 | - } |
|
1390 | - } else { |
|
1391 | - $filter_match = $match; |
|
1392 | - if (!$match) { |
|
1393 | - break; |
|
1394 | - } |
|
1395 | - } |
|
1396 | - } |
|
1397 | - |
|
1398 | - if ($inverse) $filter_match = !$filter_match; |
|
1399 | - |
|
1400 | - if ($filter_match) { |
|
1401 | - if (is_array($matched_rules)) array_push($matched_rules, $rule); |
|
1402 | - if (is_array($matched_filters)) array_push($matched_filters, $filter); |
|
1403 | - |
|
1404 | - foreach ($filter["actions"] as $action) { |
|
1405 | - array_push($matches, $action); |
|
1406 | - |
|
1407 | - // if Stop action encountered, perform no further processing |
|
1408 | - if (isset($action["type"]) && $action["type"] == "stop") return $matches; |
|
1409 | - } |
|
1410 | - } |
|
1411 | - } |
|
1412 | - |
|
1413 | - return $matches; |
|
1414 | - } |
|
1415 | - |
|
1416 | - public static function find_article_filter($filters, $filter_name) { |
|
1417 | - foreach ($filters as $f) { |
|
1418 | - if ($f["type"] == $filter_name) { |
|
1419 | - return $f; |
|
1420 | - }; |
|
1421 | - } |
|
1422 | - return false; |
|
1423 | - } |
|
1424 | - |
|
1425 | - public static function find_article_filters($filters, $filter_name) { |
|
1426 | - $results = array(); |
|
1427 | - |
|
1428 | - foreach ($filters as $f) { |
|
1429 | - if ($f["type"] == $filter_name) { |
|
1430 | - array_push($results, $f); |
|
1431 | - }; |
|
1432 | - } |
|
1433 | - return $results; |
|
1434 | - } |
|
1435 | - |
|
1436 | - public static function calculate_article_score($filters) { |
|
1437 | - $score = 0; |
|
1438 | - |
|
1439 | - foreach ($filters as $f) { |
|
1440 | - if ($f["type"] == "score") { |
|
1441 | - $score += $f["param"]; |
|
1442 | - }; |
|
1443 | - } |
|
1444 | - return $score; |
|
1445 | - } |
|
1446 | - |
|
1447 | - public static function labels_contains_caption($labels, $caption) { |
|
1448 | - foreach ($labels as $label) { |
|
1449 | - if ($label[1] == $caption) { |
|
1450 | - return true; |
|
1451 | - } |
|
1452 | - } |
|
1453 | - |
|
1454 | - return false; |
|
1455 | - } |
|
1456 | - |
|
1457 | - public static function assign_article_to_label_filters($id, $filters, $owner_uid, $article_labels) { |
|
1458 | - foreach ($filters as $f) { |
|
1459 | - if ($f["type"] == "label") { |
|
1460 | - if (!RSSUtils::labels_contains_caption($article_labels, $f["param"])) { |
|
1461 | - Labels::add_article($id, $f["param"], $owner_uid); |
|
1462 | - } |
|
1463 | - } |
|
1464 | - } |
|
1465 | - } |
|
1466 | - |
|
1467 | - public static function make_guid_from_title($title) { |
|
1468 | - return preg_replace("/[ \"\',.:;]/", "-", |
|
1469 | - mb_strtolower(strip_tags($title), 'utf-8')); |
|
1470 | - } |
|
1471 | - |
|
1472 | - public static function cleanup_counters_cache() { |
|
1473 | - $pdo = Db::pdo(); |
|
1474 | - |
|
1475 | - $res = $pdo->query("DELETE FROM ttrss_counters_cache |
|
1291 | + } |
|
1292 | + } |
|
1293 | + |
|
1294 | + public static function expire_lock_files() { |
|
1295 | + Debug::log("Removing old lock files...", Debug::$LOG_VERBOSE); |
|
1296 | + |
|
1297 | + $num_deleted = 0; |
|
1298 | + |
|
1299 | + if (is_writable(LOCK_DIRECTORY)) { |
|
1300 | + $files = glob(LOCK_DIRECTORY . "/*.lock"); |
|
1301 | + |
|
1302 | + if ($files) { |
|
1303 | + foreach ($files as $file) { |
|
1304 | + if (!file_is_locked(basename($file)) && time() - filemtime($file) > 86400*2) { |
|
1305 | + unlink($file); |
|
1306 | + ++$num_deleted; |
|
1307 | + } |
|
1308 | + } |
|
1309 | + } |
|
1310 | + } |
|
1311 | + |
|
1312 | + Debug::log("removed $num_deleted old lock files."); |
|
1313 | + } |
|
1314 | + |
|
1315 | + /** |
|
1316 | + * Source: http://www.php.net/manual/en/function.parse-url.php#104527 |
|
1317 | + * Returns the url query as associative array |
|
1318 | + * |
|
1319 | + * @param string query |
|
1320 | + * @return array params |
|
1321 | + */ |
|
1322 | + public static function convertUrlQuery($query) { |
|
1323 | + $queryParts = explode('&', $query); |
|
1324 | + |
|
1325 | + $params = array(); |
|
1326 | + |
|
1327 | + foreach ($queryParts as $param) { |
|
1328 | + $item = explode('=', $param); |
|
1329 | + $params[$item[0]] = $item[1]; |
|
1330 | + } |
|
1331 | + |
|
1332 | + return $params; |
|
1333 | + } |
|
1334 | + |
|
1335 | + public static function get_article_filters($filters, $title, $content, $link, $author, $tags, &$matched_rules = false, &$matched_filters = false) { |
|
1336 | + $matches = array(); |
|
1337 | + |
|
1338 | + foreach ($filters as $filter) { |
|
1339 | + $match_any_rule = $filter["match_any_rule"]; |
|
1340 | + $inverse = $filter["inverse"]; |
|
1341 | + $filter_match = false; |
|
1342 | + |
|
1343 | + foreach ($filter["rules"] as $rule) { |
|
1344 | + $match = false; |
|
1345 | + $reg_exp = str_replace('/', '\/', $rule["reg_exp"]); |
|
1346 | + $rule_inverse = $rule["inverse"]; |
|
1347 | + |
|
1348 | + if (!$reg_exp) |
|
1349 | + continue; |
|
1350 | + |
|
1351 | + switch ($rule["type"]) { |
|
1352 | + case "title": |
|
1353 | + $match = @preg_match("/$reg_exp/iu", $title); |
|
1354 | + break; |
|
1355 | + case "content": |
|
1356 | + // we don't need to deal with multiline regexps |
|
1357 | + $content = preg_replace("/[\r\n\t]/", "", $content); |
|
1358 | + |
|
1359 | + $match = @preg_match("/$reg_exp/iu", $content); |
|
1360 | + break; |
|
1361 | + case "both": |
|
1362 | + // we don't need to deal with multiline regexps |
|
1363 | + $content = preg_replace("/[\r\n\t]/", "", $content); |
|
1364 | + |
|
1365 | + $match = (@preg_match("/$reg_exp/iu", $title) || @preg_match("/$reg_exp/iu", $content)); |
|
1366 | + break; |
|
1367 | + case "link": |
|
1368 | + $match = @preg_match("/$reg_exp/iu", $link); |
|
1369 | + break; |
|
1370 | + case "author": |
|
1371 | + $match = @preg_match("/$reg_exp/iu", $author); |
|
1372 | + break; |
|
1373 | + case "tag": |
|
1374 | + foreach ($tags as $tag) { |
|
1375 | + if (@preg_match("/$reg_exp/iu", $tag)) { |
|
1376 | + $match = true; |
|
1377 | + break; |
|
1378 | + } |
|
1379 | + } |
|
1380 | + break; |
|
1381 | + } |
|
1382 | + |
|
1383 | + if ($rule_inverse) $match = !$match; |
|
1384 | + |
|
1385 | + if ($match_any_rule) { |
|
1386 | + if ($match) { |
|
1387 | + $filter_match = true; |
|
1388 | + break; |
|
1389 | + } |
|
1390 | + } else { |
|
1391 | + $filter_match = $match; |
|
1392 | + if (!$match) { |
|
1393 | + break; |
|
1394 | + } |
|
1395 | + } |
|
1396 | + } |
|
1397 | + |
|
1398 | + if ($inverse) $filter_match = !$filter_match; |
|
1399 | + |
|
1400 | + if ($filter_match) { |
|
1401 | + if (is_array($matched_rules)) array_push($matched_rules, $rule); |
|
1402 | + if (is_array($matched_filters)) array_push($matched_filters, $filter); |
|
1403 | + |
|
1404 | + foreach ($filter["actions"] as $action) { |
|
1405 | + array_push($matches, $action); |
|
1406 | + |
|
1407 | + // if Stop action encountered, perform no further processing |
|
1408 | + if (isset($action["type"]) && $action["type"] == "stop") return $matches; |
|
1409 | + } |
|
1410 | + } |
|
1411 | + } |
|
1412 | + |
|
1413 | + return $matches; |
|
1414 | + } |
|
1415 | + |
|
1416 | + public static function find_article_filter($filters, $filter_name) { |
|
1417 | + foreach ($filters as $f) { |
|
1418 | + if ($f["type"] == $filter_name) { |
|
1419 | + return $f; |
|
1420 | + }; |
|
1421 | + } |
|
1422 | + return false; |
|
1423 | + } |
|
1424 | + |
|
1425 | + public static function find_article_filters($filters, $filter_name) { |
|
1426 | + $results = array(); |
|
1427 | + |
|
1428 | + foreach ($filters as $f) { |
|
1429 | + if ($f["type"] == $filter_name) { |
|
1430 | + array_push($results, $f); |
|
1431 | + }; |
|
1432 | + } |
|
1433 | + return $results; |
|
1434 | + } |
|
1435 | + |
|
1436 | + public static function calculate_article_score($filters) { |
|
1437 | + $score = 0; |
|
1438 | + |
|
1439 | + foreach ($filters as $f) { |
|
1440 | + if ($f["type"] == "score") { |
|
1441 | + $score += $f["param"]; |
|
1442 | + }; |
|
1443 | + } |
|
1444 | + return $score; |
|
1445 | + } |
|
1446 | + |
|
1447 | + public static function labels_contains_caption($labels, $caption) { |
|
1448 | + foreach ($labels as $label) { |
|
1449 | + if ($label[1] == $caption) { |
|
1450 | + return true; |
|
1451 | + } |
|
1452 | + } |
|
1453 | + |
|
1454 | + return false; |
|
1455 | + } |
|
1456 | + |
|
1457 | + public static function assign_article_to_label_filters($id, $filters, $owner_uid, $article_labels) { |
|
1458 | + foreach ($filters as $f) { |
|
1459 | + if ($f["type"] == "label") { |
|
1460 | + if (!RSSUtils::labels_contains_caption($article_labels, $f["param"])) { |
|
1461 | + Labels::add_article($id, $f["param"], $owner_uid); |
|
1462 | + } |
|
1463 | + } |
|
1464 | + } |
|
1465 | + } |
|
1466 | + |
|
1467 | + public static function make_guid_from_title($title) { |
|
1468 | + return preg_replace("/[ \"\',.:;]/", "-", |
|
1469 | + mb_strtolower(strip_tags($title), 'utf-8')); |
|
1470 | + } |
|
1471 | + |
|
1472 | + public static function cleanup_counters_cache() { |
|
1473 | + $pdo = Db::pdo(); |
|
1474 | + |
|
1475 | + $res = $pdo->query("DELETE FROM ttrss_counters_cache |
|
1476 | 1476 | WHERE feed_id > 0 AND |
1477 | 1477 | (SELECT COUNT(id) FROM ttrss_feeds WHERE |
1478 | 1478 | id = feed_id AND |
1479 | 1479 | ttrss_counters_cache.owner_uid = ttrss_feeds.owner_uid) = 0"); |
1480 | 1480 | |
1481 | - $frows = $res->rowCount(); |
|
1481 | + $frows = $res->rowCount(); |
|
1482 | 1482 | |
1483 | - $res = $pdo->query("DELETE FROM ttrss_cat_counters_cache |
|
1483 | + $res = $pdo->query("DELETE FROM ttrss_cat_counters_cache |
|
1484 | 1484 | WHERE feed_id > 0 AND |
1485 | 1485 | (SELECT COUNT(id) FROM ttrss_feed_categories WHERE |
1486 | 1486 | id = feed_id AND |
1487 | 1487 | ttrss_cat_counters_cache.owner_uid = ttrss_feed_categories.owner_uid) = 0"); |
1488 | 1488 | |
1489 | - $crows = $res->rowCount(); |
|
1490 | - |
|
1491 | - Debug::log("removed $frows (feeds) $crows (cats) orphaned counter cache entries."); |
|
1492 | - } |
|
1493 | - |
|
1494 | - public static function housekeeping_user($owner_uid) { |
|
1495 | - $tmph = new PluginHost(); |
|
1496 | - |
|
1497 | - load_user_plugins($owner_uid, $tmph); |
|
1498 | - |
|
1499 | - $tmph->run_hooks(PluginHost::HOOK_HOUSE_KEEPING, "hook_house_keeping", ""); |
|
1500 | - } |
|
1501 | - |
|
1502 | - public static function housekeeping_common() { |
|
1503 | - DiskCache::expire(); |
|
1504 | - |
|
1505 | - RSSUtils::expire_lock_files(); |
|
1506 | - RSSUtils::expire_error_log(); |
|
1507 | - RSSUtils::expire_feed_archive(); |
|
1508 | - RSSUtils::cleanup_feed_browser(); |
|
1509 | - |
|
1510 | - Article::purge_orphans(); |
|
1511 | - RSSUtils::cleanup_counters_cache(); |
|
1512 | - |
|
1513 | - PluginHost::getInstance()->run_hooks(PluginHost::HOOK_HOUSE_KEEPING, "hook_house_keeping", ""); |
|
1514 | - } |
|
1515 | - |
|
1516 | - public static function check_feed_favicon($site_url, $feed) { |
|
1517 | - # print "FAVICON [$site_url]: $favicon_url\n"; |
|
1518 | - |
|
1519 | - $icon_file = ICONS_DIR . "/$feed.ico"; |
|
1520 | - |
|
1521 | - if (!file_exists($icon_file)) { |
|
1522 | - $favicon_url = RSSUtils::get_favicon_url($site_url); |
|
1523 | - |
|
1524 | - if ($favicon_url) { |
|
1525 | - // Limiting to "image" type misses those served with text/plain |
|
1526 | - $contents = fetch_file_contents($favicon_url); // , "image"); |
|
1527 | - |
|
1528 | - if ($contents) { |
|
1529 | - // Crude image type matching. |
|
1530 | - // Patterns gleaned from the file(1) source code. |
|
1531 | - if (preg_match('/^\x00\x00\x01\x00/', $contents)) { |
|
1532 | - // 0 string \000\000\001\000 MS Windows icon resource |
|
1533 | - //error_log("check_feed_favicon: favicon_url=$favicon_url isa MS Windows icon resource"); |
|
1534 | - } |
|
1535 | - elseif (preg_match('/^GIF8/', $contents)) { |
|
1536 | - // 0 string GIF8 GIF image data |
|
1537 | - //error_log("check_feed_favicon: favicon_url=$favicon_url isa GIF image"); |
|
1538 | - } |
|
1539 | - elseif (preg_match('/^\x89PNG\x0d\x0a\x1a\x0a/', $contents)) { |
|
1540 | - // 0 string \x89PNG\x0d\x0a\x1a\x0a PNG image data |
|
1541 | - //error_log("check_feed_favicon: favicon_url=$favicon_url isa PNG image"); |
|
1542 | - } |
|
1543 | - elseif (preg_match('/^\xff\xd8/', $contents)) { |
|
1544 | - // 0 beshort 0xffd8 JPEG image data |
|
1545 | - //error_log("check_feed_favicon: favicon_url=$favicon_url isa JPG image"); |
|
1546 | - } |
|
1547 | - elseif (preg_match('/^BM/', $contents)) { |
|
1548 | - // 0 string BM PC bitmap (OS2, Windows BMP files) |
|
1549 | - //error_log("check_feed_favicon, favicon_url=$favicon_url isa BMP image"); |
|
1550 | - } |
|
1551 | - else { |
|
1552 | - //error_log("check_feed_favicon: favicon_url=$favicon_url isa UNKNOWN type"); |
|
1553 | - $contents = ""; |
|
1554 | - } |
|
1555 | - } |
|
1556 | - |
|
1557 | - if ($contents) { |
|
1558 | - $fp = @fopen($icon_file, "w"); |
|
1559 | - |
|
1560 | - if ($fp) { |
|
1561 | - fwrite($fp, $contents); |
|
1562 | - fclose($fp); |
|
1563 | - chmod($icon_file, 0644); |
|
1564 | - } |
|
1565 | - } |
|
1566 | - } |
|
1567 | - return $icon_file; |
|
1568 | - } |
|
1569 | - } |
|
1570 | - |
|
1571 | - public static function is_gzipped($feed_data) { |
|
1572 | - return strpos(substr($feed_data, 0, 3), |
|
1573 | - "\x1f" . "\x8b" . "\x08", 0) === 0; |
|
1574 | - } |
|
1575 | - |
|
1576 | - public static function load_filters($feed_id, $owner_uid) { |
|
1577 | - $filters = array(); |
|
1578 | - |
|
1579 | - $feed_id = (int) $feed_id; |
|
1580 | - $cat_id = (int)Feeds::getFeedCategory($feed_id); |
|
1581 | - |
|
1582 | - if ($cat_id == 0) |
|
1583 | - $null_cat_qpart = "cat_id IS NULL OR"; |
|
1584 | - else |
|
1585 | - $null_cat_qpart = ""; |
|
1586 | - |
|
1587 | - $pdo = Db::pdo(); |
|
1588 | - |
|
1589 | - $sth = $pdo->prepare("SELECT * FROM ttrss_filters2 WHERE |
|
1489 | + $crows = $res->rowCount(); |
|
1490 | + |
|
1491 | + Debug::log("removed $frows (feeds) $crows (cats) orphaned counter cache entries."); |
|
1492 | + } |
|
1493 | + |
|
1494 | + public static function housekeeping_user($owner_uid) { |
|
1495 | + $tmph = new PluginHost(); |
|
1496 | + |
|
1497 | + load_user_plugins($owner_uid, $tmph); |
|
1498 | + |
|
1499 | + $tmph->run_hooks(PluginHost::HOOK_HOUSE_KEEPING, "hook_house_keeping", ""); |
|
1500 | + } |
|
1501 | + |
|
1502 | + public static function housekeeping_common() { |
|
1503 | + DiskCache::expire(); |
|
1504 | + |
|
1505 | + RSSUtils::expire_lock_files(); |
|
1506 | + RSSUtils::expire_error_log(); |
|
1507 | + RSSUtils::expire_feed_archive(); |
|
1508 | + RSSUtils::cleanup_feed_browser(); |
|
1509 | + |
|
1510 | + Article::purge_orphans(); |
|
1511 | + RSSUtils::cleanup_counters_cache(); |
|
1512 | + |
|
1513 | + PluginHost::getInstance()->run_hooks(PluginHost::HOOK_HOUSE_KEEPING, "hook_house_keeping", ""); |
|
1514 | + } |
|
1515 | + |
|
1516 | + public static function check_feed_favicon($site_url, $feed) { |
|
1517 | + # print "FAVICON [$site_url]: $favicon_url\n"; |
|
1518 | + |
|
1519 | + $icon_file = ICONS_DIR . "/$feed.ico"; |
|
1520 | + |
|
1521 | + if (!file_exists($icon_file)) { |
|
1522 | + $favicon_url = RSSUtils::get_favicon_url($site_url); |
|
1523 | + |
|
1524 | + if ($favicon_url) { |
|
1525 | + // Limiting to "image" type misses those served with text/plain |
|
1526 | + $contents = fetch_file_contents($favicon_url); // , "image"); |
|
1527 | + |
|
1528 | + if ($contents) { |
|
1529 | + // Crude image type matching. |
|
1530 | + // Patterns gleaned from the file(1) source code. |
|
1531 | + if (preg_match('/^\x00\x00\x01\x00/', $contents)) { |
|
1532 | + // 0 string \000\000\001\000 MS Windows icon resource |
|
1533 | + //error_log("check_feed_favicon: favicon_url=$favicon_url isa MS Windows icon resource"); |
|
1534 | + } |
|
1535 | + elseif (preg_match('/^GIF8/', $contents)) { |
|
1536 | + // 0 string GIF8 GIF image data |
|
1537 | + //error_log("check_feed_favicon: favicon_url=$favicon_url isa GIF image"); |
|
1538 | + } |
|
1539 | + elseif (preg_match('/^\x89PNG\x0d\x0a\x1a\x0a/', $contents)) { |
|
1540 | + // 0 string \x89PNG\x0d\x0a\x1a\x0a PNG image data |
|
1541 | + //error_log("check_feed_favicon: favicon_url=$favicon_url isa PNG image"); |
|
1542 | + } |
|
1543 | + elseif (preg_match('/^\xff\xd8/', $contents)) { |
|
1544 | + // 0 beshort 0xffd8 JPEG image data |
|
1545 | + //error_log("check_feed_favicon: favicon_url=$favicon_url isa JPG image"); |
|
1546 | + } |
|
1547 | + elseif (preg_match('/^BM/', $contents)) { |
|
1548 | + // 0 string BM PC bitmap (OS2, Windows BMP files) |
|
1549 | + //error_log("check_feed_favicon, favicon_url=$favicon_url isa BMP image"); |
|
1550 | + } |
|
1551 | + else { |
|
1552 | + //error_log("check_feed_favicon: favicon_url=$favicon_url isa UNKNOWN type"); |
|
1553 | + $contents = ""; |
|
1554 | + } |
|
1555 | + } |
|
1556 | + |
|
1557 | + if ($contents) { |
|
1558 | + $fp = @fopen($icon_file, "w"); |
|
1559 | + |
|
1560 | + if ($fp) { |
|
1561 | + fwrite($fp, $contents); |
|
1562 | + fclose($fp); |
|
1563 | + chmod($icon_file, 0644); |
|
1564 | + } |
|
1565 | + } |
|
1566 | + } |
|
1567 | + return $icon_file; |
|
1568 | + } |
|
1569 | + } |
|
1570 | + |
|
1571 | + public static function is_gzipped($feed_data) { |
|
1572 | + return strpos(substr($feed_data, 0, 3), |
|
1573 | + "\x1f" . "\x8b" . "\x08", 0) === 0; |
|
1574 | + } |
|
1575 | + |
|
1576 | + public static function load_filters($feed_id, $owner_uid) { |
|
1577 | + $filters = array(); |
|
1578 | + |
|
1579 | + $feed_id = (int) $feed_id; |
|
1580 | + $cat_id = (int)Feeds::getFeedCategory($feed_id); |
|
1581 | + |
|
1582 | + if ($cat_id == 0) |
|
1583 | + $null_cat_qpart = "cat_id IS NULL OR"; |
|
1584 | + else |
|
1585 | + $null_cat_qpart = ""; |
|
1586 | + |
|
1587 | + $pdo = Db::pdo(); |
|
1588 | + |
|
1589 | + $sth = $pdo->prepare("SELECT * FROM ttrss_filters2 WHERE |
|
1590 | 1590 | owner_uid = ? AND enabled = true ORDER BY order_id, title"); |
1591 | - $sth->execute([$owner_uid]); |
|
1591 | + $sth->execute([$owner_uid]); |
|
1592 | 1592 | |
1593 | - $check_cats = array_merge( |
|
1594 | - Feeds::getParentCategories($cat_id, $owner_uid), |
|
1595 | - [$cat_id]); |
|
1593 | + $check_cats = array_merge( |
|
1594 | + Feeds::getParentCategories($cat_id, $owner_uid), |
|
1595 | + [$cat_id]); |
|
1596 | 1596 | |
1597 | - $check_cats_str = join(",", $check_cats); |
|
1598 | - $check_cats_fullids = array_map(function($a) { return "CAT:$a"; }, $check_cats); |
|
1597 | + $check_cats_str = join(",", $check_cats); |
|
1598 | + $check_cats_fullids = array_map(function($a) { return "CAT:$a"; }, $check_cats); |
|
1599 | 1599 | |
1600 | - while ($line = $sth->fetch()) { |
|
1601 | - $filter_id = $line["id"]; |
|
1600 | + while ($line = $sth->fetch()) { |
|
1601 | + $filter_id = $line["id"]; |
|
1602 | 1602 | |
1603 | - $match_any_rule = sql_bool_to_bool($line["match_any_rule"]); |
|
1603 | + $match_any_rule = sql_bool_to_bool($line["match_any_rule"]); |
|
1604 | 1604 | |
1605 | - $sth2 = $pdo->prepare("SELECT |
|
1605 | + $sth2 = $pdo->prepare("SELECT |
|
1606 | 1606 | r.reg_exp, r.inverse, r.feed_id, r.cat_id, r.cat_filter, r.match_on, t.name AS type_name |
1607 | 1607 | FROM ttrss_filters2_rules AS r, |
1608 | 1608 | ttrss_filter_types AS t |
@@ -1611,117 +1611,117 @@ discard block |
||
1611 | 1611 | (($null_cat_qpart (cat_id IS NULL AND cat_filter = false) OR cat_id IN ($check_cats_str)) AND |
1612 | 1612 | (feed_id IS NULL OR feed_id = ?))) AND |
1613 | 1613 | filter_type = t.id AND filter_id = ?"); |
1614 | - $sth2->execute([$feed_id, $filter_id]); |
|
1614 | + $sth2->execute([$feed_id, $filter_id]); |
|
1615 | 1615 | |
1616 | - $rules = array(); |
|
1617 | - $actions = array(); |
|
1616 | + $rules = array(); |
|
1617 | + $actions = array(); |
|
1618 | 1618 | |
1619 | - while ($rule_line = $sth2->fetch()) { |
|
1620 | - # print_r($rule_line); |
|
1619 | + while ($rule_line = $sth2->fetch()) { |
|
1620 | + # print_r($rule_line); |
|
1621 | 1621 | |
1622 | - if ($rule_line["match_on"]) { |
|
1623 | - $match_on = json_decode($rule_line["match_on"], true); |
|
1622 | + if ($rule_line["match_on"]) { |
|
1623 | + $match_on = json_decode($rule_line["match_on"], true); |
|
1624 | 1624 | |
1625 | - if (in_array("0", $match_on) || in_array($feed_id, $match_on) || count(array_intersect($check_cats_fullids, $match_on)) > 0) { |
|
1625 | + if (in_array("0", $match_on) || in_array($feed_id, $match_on) || count(array_intersect($check_cats_fullids, $match_on)) > 0) { |
|
1626 | 1626 | |
1627 | - $rule = array(); |
|
1628 | - $rule["reg_exp"] = $rule_line["reg_exp"]; |
|
1629 | - $rule["type"] = $rule_line["type_name"]; |
|
1630 | - $rule["inverse"] = sql_bool_to_bool($rule_line["inverse"]); |
|
1627 | + $rule = array(); |
|
1628 | + $rule["reg_exp"] = $rule_line["reg_exp"]; |
|
1629 | + $rule["type"] = $rule_line["type_name"]; |
|
1630 | + $rule["inverse"] = sql_bool_to_bool($rule_line["inverse"]); |
|
1631 | 1631 | |
1632 | - array_push($rules, $rule); |
|
1633 | - } else if (!$match_any_rule) { |
|
1634 | - // this filter contains a rule that doesn't match to this feed/category combination |
|
1635 | - // thus filter has to be rejected |
|
1632 | + array_push($rules, $rule); |
|
1633 | + } else if (!$match_any_rule) { |
|
1634 | + // this filter contains a rule that doesn't match to this feed/category combination |
|
1635 | + // thus filter has to be rejected |
|
1636 | 1636 | |
1637 | - $rules = []; |
|
1638 | - break; |
|
1639 | - } |
|
1637 | + $rules = []; |
|
1638 | + break; |
|
1639 | + } |
|
1640 | 1640 | |
1641 | - } else { |
|
1641 | + } else { |
|
1642 | 1642 | |
1643 | - $rule = array(); |
|
1644 | - $rule["reg_exp"] = $rule_line["reg_exp"]; |
|
1645 | - $rule["type"] = $rule_line["type_name"]; |
|
1646 | - $rule["inverse"] = sql_bool_to_bool($rule_line["inverse"]); |
|
1643 | + $rule = array(); |
|
1644 | + $rule["reg_exp"] = $rule_line["reg_exp"]; |
|
1645 | + $rule["type"] = $rule_line["type_name"]; |
|
1646 | + $rule["inverse"] = sql_bool_to_bool($rule_line["inverse"]); |
|
1647 | 1647 | |
1648 | - array_push($rules, $rule); |
|
1649 | - } |
|
1650 | - } |
|
1648 | + array_push($rules, $rule); |
|
1649 | + } |
|
1650 | + } |
|
1651 | 1651 | |
1652 | - if (count($rules) > 0) { |
|
1653 | - $sth2 = $pdo->prepare("SELECT a.action_param,t.name AS type_name |
|
1652 | + if (count($rules) > 0) { |
|
1653 | + $sth2 = $pdo->prepare("SELECT a.action_param,t.name AS type_name |
|
1654 | 1654 | FROM ttrss_filters2_actions AS a, |
1655 | 1655 | ttrss_filter_actions AS t |
1656 | 1656 | WHERE |
1657 | 1657 | action_id = t.id AND filter_id = ?"); |
1658 | - $sth2->execute([$filter_id]); |
|
1659 | - |
|
1660 | - while ($action_line = $sth2->fetch()) { |
|
1661 | - # print_r($action_line); |
|
1662 | - |
|
1663 | - $action = array(); |
|
1664 | - $action["type"] = $action_line["type_name"]; |
|
1665 | - $action["param"] = $action_line["action_param"]; |
|
1666 | - |
|
1667 | - array_push($actions, $action); |
|
1668 | - } |
|
1669 | - } |
|
1670 | - |
|
1671 | - $filter = []; |
|
1672 | - $filter["id"] = $filter_id; |
|
1673 | - $filter["match_any_rule"] = sql_bool_to_bool($line["match_any_rule"]); |
|
1674 | - $filter["inverse"] = sql_bool_to_bool($line["inverse"]); |
|
1675 | - $filter["rules"] = $rules; |
|
1676 | - $filter["actions"] = $actions; |
|
1677 | - |
|
1678 | - if (count($rules) > 0 && count($actions) > 0) { |
|
1679 | - array_push($filters, $filter); |
|
1680 | - } |
|
1681 | - } |
|
1682 | - |
|
1683 | - return $filters; |
|
1684 | - } |
|
1685 | - |
|
1686 | - /** |
|
1687 | - * Try to determine the favicon URL for a feed. |
|
1688 | - * adapted from wordpress favicon plugin by Jeff Minard (http://thecodepro.com/) |
|
1689 | - * http://dev.wp-plugins.org/file/favatars/trunk/favatars.php |
|
1690 | - * |
|
1691 | - * @param string $url A feed or page URL |
|
1692 | - * @access public |
|
1693 | - * @return mixed The favicon URL, or false if none was found. |
|
1694 | - */ |
|
1695 | - public static function get_favicon_url($url) { |
|
1696 | - |
|
1697 | - $favicon_url = false; |
|
1698 | - |
|
1699 | - if ($html = @fetch_file_contents($url)) { |
|
1700 | - |
|
1701 | - $doc = new DOMDocument(); |
|
1702 | - if ($doc->loadHTML($html)) { |
|
1703 | - $xpath = new DOMXPath($doc); |
|
1704 | - |
|
1705 | - $base = $xpath->query('/html/head/base[@href]'); |
|
1706 | - foreach ($base as $b) { |
|
1707 | - $url = rewrite_relative_url($url, $b->getAttribute("href")); |
|
1708 | - break; |
|
1709 | - } |
|
1710 | - |
|
1711 | - $entries = $xpath->query('/html/head/link[@rel="shortcut icon" or @rel="icon"]'); |
|
1712 | - if (count($entries) > 0) { |
|
1713 | - foreach ($entries as $entry) { |
|
1714 | - $favicon_url = rewrite_relative_url($url, $entry->getAttribute("href")); |
|
1715 | - break; |
|
1716 | - } |
|
1717 | - } |
|
1718 | - } |
|
1719 | - } |
|
1720 | - |
|
1721 | - if (!$favicon_url) |
|
1722 | - $favicon_url = rewrite_relative_url($url, "/favicon.ico"); |
|
1723 | - |
|
1724 | - return $favicon_url; |
|
1725 | - } |
|
1658 | + $sth2->execute([$filter_id]); |
|
1659 | + |
|
1660 | + while ($action_line = $sth2->fetch()) { |
|
1661 | + # print_r($action_line); |
|
1662 | + |
|
1663 | + $action = array(); |
|
1664 | + $action["type"] = $action_line["type_name"]; |
|
1665 | + $action["param"] = $action_line["action_param"]; |
|
1666 | + |
|
1667 | + array_push($actions, $action); |
|
1668 | + } |
|
1669 | + } |
|
1670 | + |
|
1671 | + $filter = []; |
|
1672 | + $filter["id"] = $filter_id; |
|
1673 | + $filter["match_any_rule"] = sql_bool_to_bool($line["match_any_rule"]); |
|
1674 | + $filter["inverse"] = sql_bool_to_bool($line["inverse"]); |
|
1675 | + $filter["rules"] = $rules; |
|
1676 | + $filter["actions"] = $actions; |
|
1677 | + |
|
1678 | + if (count($rules) > 0 && count($actions) > 0) { |
|
1679 | + array_push($filters, $filter); |
|
1680 | + } |
|
1681 | + } |
|
1682 | + |
|
1683 | + return $filters; |
|
1684 | + } |
|
1685 | + |
|
1686 | + /** |
|
1687 | + * Try to determine the favicon URL for a feed. |
|
1688 | + * adapted from wordpress favicon plugin by Jeff Minard (http://thecodepro.com/) |
|
1689 | + * http://dev.wp-plugins.org/file/favatars/trunk/favatars.php |
|
1690 | + * |
|
1691 | + * @param string $url A feed or page URL |
|
1692 | + * @access public |
|
1693 | + * @return mixed The favicon URL, or false if none was found. |
|
1694 | + */ |
|
1695 | + public static function get_favicon_url($url) { |
|
1696 | + |
|
1697 | + $favicon_url = false; |
|
1698 | + |
|
1699 | + if ($html = @fetch_file_contents($url)) { |
|
1700 | + |
|
1701 | + $doc = new DOMDocument(); |
|
1702 | + if ($doc->loadHTML($html)) { |
|
1703 | + $xpath = new DOMXPath($doc); |
|
1704 | + |
|
1705 | + $base = $xpath->query('/html/head/base[@href]'); |
|
1706 | + foreach ($base as $b) { |
|
1707 | + $url = rewrite_relative_url($url, $b->getAttribute("href")); |
|
1708 | + break; |
|
1709 | + } |
|
1710 | + |
|
1711 | + $entries = $xpath->query('/html/head/link[@rel="shortcut icon" or @rel="icon"]'); |
|
1712 | + if (count($entries) > 0) { |
|
1713 | + foreach ($entries as $entry) { |
|
1714 | + $favicon_url = rewrite_relative_url($url, $entry->getAttribute("href")); |
|
1715 | + break; |
|
1716 | + } |
|
1717 | + } |
|
1718 | + } |
|
1719 | + } |
|
1720 | + |
|
1721 | + if (!$favicon_url) |
|
1722 | + $favicon_url = rewrite_relative_url($url, "/favicon.ico"); |
|
1723 | + |
|
1724 | + return $favicon_url; |
|
1725 | + } |
|
1726 | 1726 | |
1727 | 1727 | } |
@@ -7,11 +7,11 @@ discard block |
||
7 | 7 | if ($k != "feed" && isset($v)) { |
8 | 8 | $x = strip_tags(is_array($v) ? implode(",", $v) : $v); |
9 | 9 | |
10 | - $tmp .= sha1("$k:" . sha1($x)); |
|
10 | + $tmp .= sha1("$k:".sha1($x)); |
|
11 | 11 | } |
12 | 12 | } |
13 | 13 | |
14 | - return sha1(implode(",", $pluginhost->get_plugin_names()) . $tmp); |
|
14 | + return sha1(implode(",", $pluginhost->get_plugin_names()).$tmp); |
|
15 | 15 | } |
16 | 16 | |
17 | 17 | // Strips utf8mb4 characters (i.e. emoji) for mysql |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | //update_rss_feed($line["id"], true); |
138 | 138 | |
139 | 139 | if ($tline = $usth->fetch()) { |
140 | - Debug::log(" => " . $tline["last_updated"] . ", " . $tline["id"] . " " . $tline["owner_uid"]); |
|
140 | + Debug::log(" => ".$tline["last_updated"].", ".$tline["id"]." ".$tline["owner_uid"]); |
|
141 | 141 | |
142 | 142 | if (array_search($tline["owner_uid"], $batch_owners) === false) |
143 | 143 | array_push($batch_owners, $tline["owner_uid"]); |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | |
324 | 324 | $date_feed_processed = date('Y-m-d H:i'); |
325 | 325 | |
326 | - $cache_filename = CACHE_DIR . "/feeds/" . sha1($fetch_url) . ".xml"; |
|
326 | + $cache_filename = CACHE_DIR."/feeds/".sha1($fetch_url).".xml"; |
|
327 | 327 | |
328 | 328 | $pluginhost = new PluginHost(); |
329 | 329 | $user_plugins = get_pref("_ENABLED_PLUGINS", $owner_uid); |
@@ -340,7 +340,7 @@ discard block |
||
340 | 340 | Debug::log("running HOOK_FETCH_FEED handlers...", Debug::$LOG_VERBOSE); |
341 | 341 | |
342 | 342 | foreach ($pluginhost->get_hooks(PluginHost::HOOK_FETCH_FEED) as $plugin) { |
343 | - Debug::log("... " . get_class($plugin), Debug::$LOG_VERBOSE); |
|
343 | + Debug::log("... ".get_class($plugin), Debug::$LOG_VERBOSE); |
|
344 | 344 | $start = microtime(true); |
345 | 345 | $feed_data = $plugin->hook_fetch_feed($feed_data, $fetch_url, $owner_uid, $feed, 0, $auth_login, $auth_pass); |
346 | 346 | Debug::log(sprintf("=== %.4f (sec)", microtime(true) - $start), Debug::$LOG_VERBOSE); |
@@ -402,7 +402,7 @@ discard block |
||
402 | 402 | $feed_data = trim($feed_data); |
403 | 403 | |
404 | 404 | Debug::log("fetch done.", Debug::$LOG_VERBOSE); |
405 | - Debug::log("source last modified: " . $fetch_last_modified, Debug::$LOG_VERBOSE); |
|
405 | + Debug::log("source last modified: ".$fetch_last_modified, Debug::$LOG_VERBOSE); |
|
406 | 406 | |
407 | 407 | if ($feed_data && $fetch_last_modified != $stored_last_modified) { |
408 | 408 | $sth = $pdo->prepare("UPDATE ttrss_feeds SET last_modified = ? WHERE id = ?"); |
@@ -410,7 +410,7 @@ discard block |
||
410 | 410 | } |
411 | 411 | |
412 | 412 | // cache vanilla feed data for re-use |
413 | - if ($feed_data && !$auth_pass && !$auth_login && is_writable(CACHE_DIR . "/feeds")) { |
|
413 | + if ($feed_data && !$auth_pass && !$auth_login && is_writable(CACHE_DIR."/feeds")) { |
|
414 | 414 | $new_rss_hash = sha1($feed_data); |
415 | 415 | |
416 | 416 | if ($new_rss_hash != $rss_hash) { |
@@ -445,7 +445,7 @@ discard block |
||
445 | 445 | $feed_data_checksum = md5($feed_data); |
446 | 446 | |
447 | 447 | foreach ($pluginhost->get_hooks(PluginHost::HOOK_FEED_FETCHED) as $plugin) { |
448 | - Debug::log("... " . get_class($plugin), Debug::$LOG_VERBOSE); |
|
448 | + Debug::log("... ".get_class($plugin), Debug::$LOG_VERBOSE); |
|
449 | 449 | $start = microtime(true); |
450 | 450 | $feed_data = $plugin->hook_feed_fetched($feed_data, $fetch_url, $owner_uid, $feed); |
451 | 451 | Debug::log(sprintf("=== %.4f (sec)", microtime(true) - $start), Debug::$LOG_VERBOSE); |
@@ -467,7 +467,7 @@ discard block |
||
467 | 467 | // We use local pluginhost here because we need to load different per-user feed plugins |
468 | 468 | |
469 | 469 | foreach ($pluginhost->get_hooks(PluginHost::HOOK_FEED_PARSED) as $plugin) { |
470 | - Debug::log("... " . get_class($plugin), Debug::$LOG_VERBOSE); |
|
470 | + Debug::log("... ".get_class($plugin), Debug::$LOG_VERBOSE); |
|
471 | 471 | $start = microtime(true); |
472 | 472 | $plugin->hook_feed_parsed($rss); |
473 | 473 | Debug::log(sprintf("=== %.4f (sec)", microtime(true) - $start), Debug::$LOG_VERBOSE); |
@@ -499,14 +499,14 @@ discard block |
||
499 | 499 | $site_url = mb_substr(rewrite_relative_url($fetch_url, clean($rss->get_link())), 0, 245); |
500 | 500 | |
501 | 501 | Debug::log("site_url: $site_url", Debug::$LOG_VERBOSE); |
502 | - Debug::log("feed_title: " . clean($rss->get_title()), Debug::$LOG_VERBOSE); |
|
502 | + Debug::log("feed_title: ".clean($rss->get_title()), Debug::$LOG_VERBOSE); |
|
503 | 503 | |
504 | 504 | if ($favicon_needs_check || $force_refetch) { |
505 | 505 | |
506 | 506 | /* terrible hack: if we crash on floicon shit here, we won't check |
507 | 507 | * the icon avgcolor again (unless the icon got updated) */ |
508 | 508 | |
509 | - $favicon_file = ICONS_DIR . "/$feed.ico"; |
|
509 | + $favicon_file = ICONS_DIR."/$feed.ico"; |
|
510 | 510 | $favicon_modified = @filemtime($favicon_file); |
511 | 511 | |
512 | 512 | Debug::log("checking favicon...", Debug::$LOG_VERBOSE); |
@@ -527,7 +527,7 @@ discard block |
||
527 | 527 | |
528 | 528 | $favicon_color = calculate_avg_color($favicon_file); |
529 | 529 | |
530 | - $favicon_colorstring = ",favicon_avg_color = " . $pdo->quote($favicon_color); |
|
530 | + $favicon_colorstring = ",favicon_avg_color = ".$pdo->quote($favicon_color); |
|
531 | 531 | |
532 | 532 | } else if ($favicon_avg_color == 'fail') { |
533 | 533 | Debug::log("floicon failed on this file, not trying to recalculate avg color", Debug::$LOG_VERBOSE); |
@@ -546,7 +546,7 @@ discard block |
||
546 | 546 | print_r($filters); |
547 | 547 | } |
548 | 548 | |
549 | - Debug::log("" . count($filters) . " filters loaded.", Debug::$LOG_VERBOSE); |
|
549 | + Debug::log("".count($filters)." filters loaded.", Debug::$LOG_VERBOSE); |
|
550 | 550 | |
551 | 551 | $items = $rss->get_items(); |
552 | 552 | |
@@ -588,13 +588,13 @@ discard block |
||
588 | 588 | |
589 | 589 | $entry_guid = "$owner_uid,$entry_guid"; |
590 | 590 | |
591 | - $entry_guid_hashed = 'SHA1:' . sha1($entry_guid); |
|
591 | + $entry_guid_hashed = 'SHA1:'.sha1($entry_guid); |
|
592 | 592 | |
593 | 593 | Debug::log("guid $entry_guid / $entry_guid_hashed", Debug::$LOG_VERBOSE); |
594 | 594 | |
595 | - $entry_timestamp = (int)$item->get_date(); |
|
595 | + $entry_timestamp = (int) $item->get_date(); |
|
596 | 596 | |
597 | - Debug::log("orig date: " . $item->get_date(), Debug::$LOG_VERBOSE); |
|
597 | + Debug::log("orig date: ".$item->get_date(), Debug::$LOG_VERBOSE); |
|
598 | 598 | |
599 | 599 | $entry_title = strip_tags($item->get_title()); |
600 | 600 | |
@@ -606,7 +606,7 @@ discard block |
||
606 | 606 | Debug::log("link $entry_link", Debug::$LOG_VERBOSE); |
607 | 607 | Debug::log("language $entry_language", Debug::$LOG_VERBOSE); |
608 | 608 | |
609 | - if (!$entry_title) $entry_title = date("Y-m-d H:i:s", $entry_timestamp);; |
|
609 | + if (!$entry_title) $entry_title = date("Y-m-d H:i:s", $entry_timestamp); ; |
|
610 | 610 | |
611 | 611 | $entry_content = $item->get_content(); |
612 | 612 | if (!$entry_content) $entry_content = $item->get_description(); |
@@ -627,7 +627,7 @@ discard block |
||
627 | 627 | Debug::log("looking for tags...", Debug::$LOG_VERBOSE); |
628 | 628 | |
629 | 629 | $entry_tags = $item->get_categories(); |
630 | - Debug::log("tags found: " . join(", ", $entry_tags), Debug::$LOG_VERBOSE); |
|
630 | + Debug::log("tags found: ".join(", ", $entry_tags), Debug::$LOG_VERBOSE); |
|
631 | 631 | |
632 | 632 | Debug::log("done collecting data.", Debug::$LOG_VERBOSE); |
633 | 633 | |
@@ -692,14 +692,14 @@ discard block |
||
692 | 692 | Debug::log("hash differs, applying plugin filters:", Debug::$LOG_VERBOSE); |
693 | 693 | |
694 | 694 | foreach ($pluginhost->get_hooks(PluginHost::HOOK_ARTICLE_FILTER) as $plugin) { |
695 | - Debug::log("... " . get_class($plugin), Debug::$LOG_VERBOSE); |
|
695 | + Debug::log("... ".get_class($plugin), Debug::$LOG_VERBOSE); |
|
696 | 696 | |
697 | 697 | $start = microtime(true); |
698 | 698 | $article = $plugin->hook_article_filter($article); |
699 | 699 | |
700 | 700 | Debug::log(sprintf("=== %.4f (sec)", microtime(true) - $start), Debug::$LOG_VERBOSE); |
701 | 701 | |
702 | - $entry_plugin_data .= mb_strtolower(get_class($plugin)) . ","; |
|
702 | + $entry_plugin_data .= mb_strtolower(get_class($plugin)).","; |
|
703 | 703 | } |
704 | 704 | |
705 | 705 | if (Debug::get_loglevel() >= 3) { |
@@ -772,7 +772,7 @@ discard block |
||
772 | 772 | Debug::log("applying plugin filter actions...", Debug::$LOG_VERBOSE); |
773 | 773 | |
774 | 774 | foreach ($plugin_filter_names as $pfn) { |
775 | - list($pfclass,$pfaction) = explode(":", $pfn["param"]); |
|
775 | + list($pfclass, $pfaction) = explode(":", $pfn["param"]); |
|
776 | 776 | |
777 | 777 | if (isset($plugin_filter_actions[$pfclass])) { |
778 | 778 | $plugin = $pluginhost->get_plugin($pfclass); |
@@ -867,7 +867,7 @@ discard block |
||
867 | 867 | $entry_current_hash, |
868 | 868 | $date_feed_processed, |
869 | 869 | $entry_comments, |
870 | - (int)$num_comments, |
|
870 | + (int) $num_comments, |
|
871 | 871 | $entry_plugin_data, |
872 | 872 | "$entry_language", |
873 | 873 | "$entry_author"]); |
@@ -979,7 +979,7 @@ discard block |
||
979 | 979 | ":content" => "$entry_content", |
980 | 980 | ":content_hash" => $entry_current_hash, |
981 | 981 | ":updated" => $entry_timestamp_fmt, |
982 | - ":num_comments" => (int)$num_comments, |
|
982 | + ":num_comments" => (int) $num_comments, |
|
983 | 983 | ":plugin_data" => $entry_plugin_data, |
984 | 984 | ":author" => "$entry_author", |
985 | 985 | ":lang" => $entry_language, |
@@ -987,7 +987,7 @@ discard block |
||
987 | 987 | |
988 | 988 | if (DB_TYPE == "pgsql") { |
989 | 989 | $params[":ts_lang"] = $feed_language; |
990 | - $params[":ts_content"] = mb_substr(strip_tags($entry_title . " " . $entry_content), 0, 900000); |
|
990 | + $params[":ts_content"] = mb_substr(strip_tags($entry_title." ".$entry_content), 0, 900000); |
|
991 | 991 | } |
992 | 992 | |
993 | 993 | $sth->execute($params); |
@@ -1067,7 +1067,7 @@ discard block |
||
1067 | 1067 | foreach ($enclosures as $enc) { |
1068 | 1068 | $enc_url = $enc[0]; |
1069 | 1069 | $enc_type = $enc[1]; |
1070 | - $enc_dur = (int)$enc[2]; |
|
1070 | + $enc_dur = (int) $enc[2]; |
|
1071 | 1071 | $enc_title = $enc[3]; |
1072 | 1072 | $enc_width = intval($enc[4]); |
1073 | 1073 | $enc_height = intval($enc[5]); |
@@ -1075,7 +1075,7 @@ discard block |
||
1075 | 1075 | $esth->execute([$enc_url, $enc_type, $entry_ref_id]); |
1076 | 1076 | |
1077 | 1077 | if (!$esth->fetch()) { |
1078 | - $usth->execute([$enc_url, $enc_type, (string)$enc_title, $enc_dur, $entry_ref_id, $enc_width, $enc_height]); |
|
1078 | + $usth->execute([$enc_url, $enc_type, (string) $enc_title, $enc_dur, $entry_ref_id, $enc_width, $enc_height]); |
|
1079 | 1079 | } |
1080 | 1080 | } |
1081 | 1081 | |
@@ -1109,7 +1109,7 @@ discard block |
||
1109 | 1109 | $filtered_tags = array_unique($filtered_tags); |
1110 | 1110 | |
1111 | 1111 | if (Debug::get_loglevel() >= Debug::$LOG_VERBOSE) { |
1112 | - Debug::log("filtered tags: " . implode(", ", $filtered_tags), Debug::$LOG_VERBOSE); |
|
1112 | + Debug::log("filtered tags: ".implode(", ", $filtered_tags), Debug::$LOG_VERBOSE); |
|
1113 | 1113 | |
1114 | 1114 | } |
1115 | 1115 | |
@@ -1297,11 +1297,11 @@ discard block |
||
1297 | 1297 | $num_deleted = 0; |
1298 | 1298 | |
1299 | 1299 | if (is_writable(LOCK_DIRECTORY)) { |
1300 | - $files = glob(LOCK_DIRECTORY . "/*.lock"); |
|
1300 | + $files = glob(LOCK_DIRECTORY."/*.lock"); |
|
1301 | 1301 | |
1302 | 1302 | if ($files) { |
1303 | 1303 | foreach ($files as $file) { |
1304 | - if (!file_is_locked(basename($file)) && time() - filemtime($file) > 86400*2) { |
|
1304 | + if (!file_is_locked(basename($file)) && time() - filemtime($file) > 86400 * 2) { |
|
1305 | 1305 | unlink($file); |
1306 | 1306 | ++$num_deleted; |
1307 | 1307 | } |
@@ -1516,7 +1516,7 @@ discard block |
||
1516 | 1516 | public static function check_feed_favicon($site_url, $feed) { |
1517 | 1517 | # print "FAVICON [$site_url]: $favicon_url\n"; |
1518 | 1518 | |
1519 | - $icon_file = ICONS_DIR . "/$feed.ico"; |
|
1519 | + $icon_file = ICONS_DIR."/$feed.ico"; |
|
1520 | 1520 | |
1521 | 1521 | if (!file_exists($icon_file)) { |
1522 | 1522 | $favicon_url = RSSUtils::get_favicon_url($site_url); |
@@ -1570,14 +1570,14 @@ discard block |
||
1570 | 1570 | |
1571 | 1571 | public static function is_gzipped($feed_data) { |
1572 | 1572 | return strpos(substr($feed_data, 0, 3), |
1573 | - "\x1f" . "\x8b" . "\x08", 0) === 0; |
|
1573 | + "\x1f"."\x8b"."\x08", 0) === 0; |
|
1574 | 1574 | } |
1575 | 1575 | |
1576 | 1576 | public static function load_filters($feed_id, $owner_uid) { |
1577 | 1577 | $filters = array(); |
1578 | 1578 | |
1579 | 1579 | $feed_id = (int) $feed_id; |
1580 | - $cat_id = (int)Feeds::getFeedCategory($feed_id); |
|
1580 | + $cat_id = (int) Feeds::getFeedCategory($feed_id); |
|
1581 | 1581 | |
1582 | 1582 | if ($cat_id == 0) |
1583 | 1583 | $null_cat_qpart = "cat_id IS NULL OR"; |
@@ -80,7 +80,9 @@ discard block |
||
80 | 80 | |
81 | 81 | // Update the least recently updated feeds first |
82 | 82 | $query_order = "ORDER BY last_updated"; |
83 | - if (DB_TYPE == "pgsql") $query_order .= " NULLS FIRST"; |
|
83 | + if (DB_TYPE == "pgsql") { |
|
84 | + $query_order .= " NULLS FIRST"; |
|
85 | + } |
|
84 | 86 | |
85 | 87 | $query = "SELECT DISTINCT ttrss_feeds.feed_url, ttrss_feeds.last_updated |
86 | 88 | FROM |
@@ -139,8 +141,9 @@ discard block |
||
139 | 141 | if ($tline = $usth->fetch()) { |
140 | 142 | Debug::log(" => " . $tline["last_updated"] . ", " . $tline["id"] . " " . $tline["owner_uid"]); |
141 | 143 | |
142 | - if (array_search($tline["owner_uid"], $batch_owners) === false) |
|
143 | - array_push($batch_owners, $tline["owner_uid"]); |
|
144 | + if (array_search($tline["owner_uid"], $batch_owners) === false) { |
|
145 | + array_push($batch_owners, $tline["owner_uid"]); |
|
146 | + } |
|
144 | 147 | |
145 | 148 | $fstarted = microtime(true); |
146 | 149 | |
@@ -311,11 +314,13 @@ discard block |
||
311 | 314 | |
312 | 315 | $feed_language = mb_strtolower($row["feed_language"]); |
313 | 316 | |
314 | - if (!$feed_language) |
|
315 | - $feed_language = mb_strtolower(get_pref('DEFAULT_SEARCH_LANGUAGE', $owner_uid)); |
|
317 | + if (!$feed_language) { |
|
318 | + $feed_language = mb_strtolower(get_pref('DEFAULT_SEARCH_LANGUAGE', $owner_uid)); |
|
319 | + } |
|
316 | 320 | |
317 | - if (!$feed_language) |
|
318 | - $feed_language = 'simple'; |
|
321 | + if (!$feed_language) { |
|
322 | + $feed_language = 'simple'; |
|
323 | + } |
|
319 | 324 | |
320 | 325 | } else { |
321 | 326 | return false; |
@@ -514,8 +519,9 @@ discard block |
||
514 | 519 | RSSUtils::check_feed_favicon($site_url, $feed); |
515 | 520 | $favicon_modified_new = @filemtime($favicon_file); |
516 | 521 | |
517 | - if ($favicon_modified_new > $favicon_modified) |
|
518 | - $favicon_avg_color = ''; |
|
522 | + if ($favicon_modified_new > $favicon_modified) { |
|
523 | + $favicon_avg_color = ''; |
|
524 | + } |
|
519 | 525 | |
520 | 526 | $favicon_colorstring = ""; |
521 | 527 | if (file_exists($favicon_file) && function_exists("imagecreatefromstring") && $favicon_avg_color == '') { |
@@ -578,8 +584,12 @@ discard block |
||
578 | 584 | } |
579 | 585 | |
580 | 586 | $entry_guid = strip_tags($item->get_id()); |
581 | - if (!$entry_guid) $entry_guid = strip_tags($item->get_link()); |
|
582 | - if (!$entry_guid) $entry_guid = RSSUtils::make_guid_from_title($item->get_title()); |
|
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 | + } |
|
583 | 593 | |
584 | 594 | if (!$entry_guid) { |
585 | 595 | $pdo->commit(); |
@@ -606,10 +616,15 @@ discard block |
||
606 | 616 | Debug::log("link $entry_link", Debug::$LOG_VERBOSE); |
607 | 617 | Debug::log("language $entry_language", Debug::$LOG_VERBOSE); |
608 | 618 | |
609 | - 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 | + ; |
|
610 | 623 | |
611 | 624 | $entry_content = $item->get_content(); |
612 | - if (!$entry_content) $entry_content = $item->get_description(); |
|
625 | + if (!$entry_content) { |
|
626 | + $entry_content = $item->get_description(); |
|
627 | + } |
|
613 | 628 | |
614 | 629 | if (Debug::get_loglevel() >= 3) { |
615 | 630 | print "content: "; |
@@ -824,8 +839,9 @@ discard block |
||
824 | 839 | |
825 | 840 | Debug::log("force catchup: $entry_force_catchup", Debug::$LOG_VERBOSE); |
826 | 841 | |
827 | - if ($cache_images) |
|
828 | - RSSUtils::cache_media($entry_content, $site_url); |
|
842 | + if ($cache_images) { |
|
843 | + RSSUtils::cache_media($entry_content, $site_url); |
|
844 | + } |
|
829 | 845 | |
830 | 846 | $csth = $pdo->prepare("SELECT id FROM ttrss_entries |
831 | 847 | WHERE guid = ? OR guid = ?"); |
@@ -951,16 +967,18 @@ discard block |
||
951 | 967 | |
952 | 968 | $sth->execute([$ref_id, $owner_uid, $feed]); |
953 | 969 | |
954 | - if ($row = $sth->fetch()) |
|
955 | - $entry_int_id = $row['int_id']; |
|
970 | + if ($row = $sth->fetch()) { |
|
971 | + $entry_int_id = $row['int_id']; |
|
972 | + } |
|
956 | 973 | } |
957 | 974 | |
958 | 975 | Debug::log("resulting RID: $entry_ref_id, IID: $entry_int_id", Debug::$LOG_VERBOSE); |
959 | 976 | |
960 | - if (DB_TYPE == "pgsql") |
|
961 | - $tsvector_qpart = "tsvector_combined = to_tsvector(:ts_lang, :ts_content),"; |
|
962 | - else |
|
963 | - $tsvector_qpart = ""; |
|
977 | + if (DB_TYPE == "pgsql") { |
|
978 | + $tsvector_qpart = "tsvector_combined = to_tsvector(:ts_lang, :ts_content),"; |
|
979 | + } else { |
|
980 | + $tsvector_qpart = ""; |
|
981 | + } |
|
964 | 982 | |
965 | 983 | $sth = $pdo->prepare("UPDATE ttrss_entries |
966 | 984 | SET title = :title, |
@@ -1049,8 +1067,9 @@ discard block |
||
1049 | 1067 | } |
1050 | 1068 | } |
1051 | 1069 | |
1052 | - if ($cache_images) |
|
1053 | - RSSUtils::cache_enclosures($enclosures, $site_url); |
|
1070 | + if ($cache_images) { |
|
1071 | + RSSUtils::cache_enclosures($enclosures, $site_url); |
|
1072 | + } |
|
1054 | 1073 | |
1055 | 1074 | if (Debug::get_loglevel() >= Debug::$LOG_EXTENDED) { |
1056 | 1075 | Debug::log("article enclosures:", Debug::$LOG_VERBOSE); |
@@ -1345,8 +1364,9 @@ discard block |
||
1345 | 1364 | $reg_exp = str_replace('/', '\/', $rule["reg_exp"]); |
1346 | 1365 | $rule_inverse = $rule["inverse"]; |
1347 | 1366 | |
1348 | - if (!$reg_exp) |
|
1349 | - continue; |
|
1367 | + if (!$reg_exp) { |
|
1368 | + continue; |
|
1369 | + } |
|
1350 | 1370 | |
1351 | 1371 | switch ($rule["type"]) { |
1352 | 1372 | case "title": |
@@ -1380,7 +1400,9 @@ discard block |
||
1380 | 1400 | break; |
1381 | 1401 | } |
1382 | 1402 | |
1383 | - if ($rule_inverse) $match = !$match; |
|
1403 | + if ($rule_inverse) { |
|
1404 | + $match = !$match; |
|
1405 | + } |
|
1384 | 1406 | |
1385 | 1407 | if ($match_any_rule) { |
1386 | 1408 | if ($match) { |
@@ -1395,17 +1417,25 @@ discard block |
||
1395 | 1417 | } |
1396 | 1418 | } |
1397 | 1419 | |
1398 | - if ($inverse) $filter_match = !$filter_match; |
|
1420 | + if ($inverse) { |
|
1421 | + $filter_match = !$filter_match; |
|
1422 | + } |
|
1399 | 1423 | |
1400 | 1424 | if ($filter_match) { |
1401 | - if (is_array($matched_rules)) array_push($matched_rules, $rule); |
|
1402 | - if (is_array($matched_filters)) array_push($matched_filters, $filter); |
|
1425 | + if (is_array($matched_rules)) { |
|
1426 | + array_push($matched_rules, $rule); |
|
1427 | + } |
|
1428 | + if (is_array($matched_filters)) { |
|
1429 | + array_push($matched_filters, $filter); |
|
1430 | + } |
|
1403 | 1431 | |
1404 | 1432 | foreach ($filter["actions"] as $action) { |
1405 | 1433 | array_push($matches, $action); |
1406 | 1434 | |
1407 | 1435 | // if Stop action encountered, perform no further processing |
1408 | - if (isset($action["type"]) && $action["type"] == "stop") return $matches; |
|
1436 | + if (isset($action["type"]) && $action["type"] == "stop") { |
|
1437 | + return $matches; |
|
1438 | + } |
|
1409 | 1439 | } |
1410 | 1440 | } |
1411 | 1441 | } |
@@ -1531,24 +1561,19 @@ discard block |
||
1531 | 1561 | if (preg_match('/^\x00\x00\x01\x00/', $contents)) { |
1532 | 1562 | // 0 string \000\000\001\000 MS Windows icon resource |
1533 | 1563 | //error_log("check_feed_favicon: favicon_url=$favicon_url isa MS Windows icon resource"); |
1534 | - } |
|
1535 | - elseif (preg_match('/^GIF8/', $contents)) { |
|
1564 | + } elseif (preg_match('/^GIF8/', $contents)) { |
|
1536 | 1565 | // 0 string GIF8 GIF image data |
1537 | 1566 | //error_log("check_feed_favicon: favicon_url=$favicon_url isa GIF image"); |
1538 | - } |
|
1539 | - elseif (preg_match('/^\x89PNG\x0d\x0a\x1a\x0a/', $contents)) { |
|
1567 | + } elseif (preg_match('/^\x89PNG\x0d\x0a\x1a\x0a/', $contents)) { |
|
1540 | 1568 | // 0 string \x89PNG\x0d\x0a\x1a\x0a PNG image data |
1541 | 1569 | //error_log("check_feed_favicon: favicon_url=$favicon_url isa PNG image"); |
1542 | - } |
|
1543 | - elseif (preg_match('/^\xff\xd8/', $contents)) { |
|
1570 | + } elseif (preg_match('/^\xff\xd8/', $contents)) { |
|
1544 | 1571 | // 0 beshort 0xffd8 JPEG image data |
1545 | 1572 | //error_log("check_feed_favicon: favicon_url=$favicon_url isa JPG image"); |
1546 | - } |
|
1547 | - elseif (preg_match('/^BM/', $contents)) { |
|
1573 | + } elseif (preg_match('/^BM/', $contents)) { |
|
1548 | 1574 | // 0 string BM PC bitmap (OS2, Windows BMP files) |
1549 | 1575 | //error_log("check_feed_favicon, favicon_url=$favicon_url isa BMP image"); |
1550 | - } |
|
1551 | - else { |
|
1576 | + } else { |
|
1552 | 1577 | //error_log("check_feed_favicon: favicon_url=$favicon_url isa UNKNOWN type"); |
1553 | 1578 | $contents = ""; |
1554 | 1579 | } |
@@ -1579,10 +1604,11 @@ discard block |
||
1579 | 1604 | $feed_id = (int) $feed_id; |
1580 | 1605 | $cat_id = (int)Feeds::getFeedCategory($feed_id); |
1581 | 1606 | |
1582 | - if ($cat_id == 0) |
|
1583 | - $null_cat_qpart = "cat_id IS NULL OR"; |
|
1584 | - else |
|
1585 | - $null_cat_qpart = ""; |
|
1607 | + if ($cat_id == 0) { |
|
1608 | + $null_cat_qpart = "cat_id IS NULL OR"; |
|
1609 | + } else { |
|
1610 | + $null_cat_qpart = ""; |
|
1611 | + } |
|
1586 | 1612 | |
1587 | 1613 | $pdo = Db::pdo(); |
1588 | 1614 | |
@@ -1718,8 +1744,9 @@ discard block |
||
1718 | 1744 | } |
1719 | 1745 | } |
1720 | 1746 | |
1721 | - if (!$favicon_url) |
|
1722 | - $favicon_url = rewrite_relative_url($url, "/favicon.ico"); |
|
1747 | + if (!$favicon_url) { |
|
1748 | + $favicon_url = rewrite_relative_url($url, "/favicon.ico"); |
|
1749 | + } |
|
1723 | 1750 | |
1724 | 1751 | return $favicon_url; |
1725 | 1752 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | time() - $preferred_ts <= 7200 |
38 | 38 | ) { |
39 | 39 | |
40 | - Debug::log("Sending digest for UID:" . $line['id'] . " - " . $line["email"]); |
|
40 | + Debug::log("Sending digest for UID:".$line['id']." - ".$line["email"]); |
|
41 | 41 | |
42 | 42 | $do_catchup = get_pref('DIGEST_CATCHUP', $line['id'], false); |
43 | 43 | |
@@ -123,13 +123,13 @@ discard block |
||
123 | 123 | |
124 | 124 | $sth = $pdo->prepare("SELECT ttrss_entries.title, |
125 | 125 | ttrss_feeds.title AS feed_title, |
126 | - COALESCE(ttrss_feed_categories.title, '" . __('Uncategorized') . "') AS cat_title, |
|
126 | + COALESCE(ttrss_feed_categories.title, '" . __('Uncategorized')."') AS cat_title, |
|
127 | 127 | date_updated, |
128 | 128 | ttrss_user_entries.ref_id, |
129 | 129 | link, |
130 | 130 | score, |
131 | 131 | content, |
132 | - " . SUBSTRING_FOR_DATE . "(last_updated,1,19) AS last_updated |
|
132 | + " . SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated |
|
133 | 133 | FROM |
134 | 134 | ttrss_user_entries,ttrss_entries,ttrss_feeds |
135 | 135 | LEFT JOIN |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | $user_id); |
166 | 166 | |
167 | 167 | if (get_pref('ENABLE_FEED_CATS', $user_id)) { |
168 | - $line['feed_title'] = $line['cat_title'] . " / " . $line['feed_title']; |
|
168 | + $line['feed_title'] = $line['cat_title']." / ".$line['feed_title']; |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | $article_labels = Article::get_article_labels($line["ref_id"], $user_id); |
@@ -2,126 +2,126 @@ discard block |
||
2 | 2 | class Digest |
3 | 3 | { |
4 | 4 | |
5 | - /** |
|
6 | - * Send by mail a digest of last articles. |
|
7 | - * |
|
8 | - * @param mixed $link The database connection. |
|
9 | - * @param integer $limit The maximum number of articles by digest. |
|
10 | - * @return boolean Return false if digests are not enabled. |
|
11 | - */ |
|
12 | - public static function send_headlines_digests() { |
|
5 | + /** |
|
6 | + * Send by mail a digest of last articles. |
|
7 | + * |
|
8 | + * @param mixed $link The database connection. |
|
9 | + * @param integer $limit The maximum number of articles by digest. |
|
10 | + * @return boolean Return false if digests are not enabled. |
|
11 | + */ |
|
12 | + public static function send_headlines_digests() { |
|
13 | 13 | |
14 | - $user_limit = 15; // amount of users to process (e.g. emails to send out) |
|
15 | - $limit = 1000; // maximum amount of headlines to include |
|
14 | + $user_limit = 15; // amount of users to process (e.g. emails to send out) |
|
15 | + $limit = 1000; // maximum amount of headlines to include |
|
16 | 16 | |
17 | - Debug::log("Sending digests, batch of max $user_limit users, headline limit = $limit"); |
|
17 | + Debug::log("Sending digests, batch of max $user_limit users, headline limit = $limit"); |
|
18 | 18 | |
19 | - if (DB_TYPE == "pgsql") { |
|
20 | - $interval_qpart = "last_digest_sent < NOW() - INTERVAL '1 days'"; |
|
21 | - } else if (DB_TYPE == "mysql") { |
|
22 | - $interval_qpart = "last_digest_sent < DATE_SUB(NOW(), INTERVAL 1 DAY)"; |
|
23 | - } |
|
19 | + if (DB_TYPE == "pgsql") { |
|
20 | + $interval_qpart = "last_digest_sent < NOW() - INTERVAL '1 days'"; |
|
21 | + } else if (DB_TYPE == "mysql") { |
|
22 | + $interval_qpart = "last_digest_sent < DATE_SUB(NOW(), INTERVAL 1 DAY)"; |
|
23 | + } |
|
24 | 24 | |
25 | - $pdo = Db::pdo(); |
|
25 | + $pdo = Db::pdo(); |
|
26 | 26 | |
27 | - $res = $pdo->query("SELECT id,email FROM ttrss_users |
|
27 | + $res = $pdo->query("SELECT id,email FROM ttrss_users |
|
28 | 28 | WHERE email != '' AND (last_digest_sent IS NULL OR $interval_qpart)"); |
29 | 29 | |
30 | - while ($line = $res->fetch()) { |
|
30 | + while ($line = $res->fetch()) { |
|
31 | 31 | |
32 | - if (@get_pref('DIGEST_ENABLE', $line['id'], false)) { |
|
33 | - $preferred_ts = strtotime(get_pref('DIGEST_PREFERRED_TIME', $line['id'], '00:00')); |
|
32 | + if (@get_pref('DIGEST_ENABLE', $line['id'], false)) { |
|
33 | + $preferred_ts = strtotime(get_pref('DIGEST_PREFERRED_TIME', $line['id'], '00:00')); |
|
34 | 34 | |
35 | - // try to send digests within 2 hours of preferred time |
|
36 | - if ($preferred_ts && time() >= $preferred_ts && |
|
37 | - time() - $preferred_ts <= 7200 |
|
38 | - ) { |
|
35 | + // try to send digests within 2 hours of preferred time |
|
36 | + if ($preferred_ts && time() >= $preferred_ts && |
|
37 | + time() - $preferred_ts <= 7200 |
|
38 | + ) { |
|
39 | 39 | |
40 | - Debug::log("Sending digest for UID:" . $line['id'] . " - " . $line["email"]); |
|
40 | + Debug::log("Sending digest for UID:" . $line['id'] . " - " . $line["email"]); |
|
41 | 41 | |
42 | - $do_catchup = get_pref('DIGEST_CATCHUP', $line['id'], false); |
|
42 | + $do_catchup = get_pref('DIGEST_CATCHUP', $line['id'], false); |
|
43 | 43 | |
44 | - global $tz_offset; |
|
44 | + global $tz_offset; |
|
45 | 45 | |
46 | - // reset tz_offset global to prevent tz cache clash between users |
|
47 | - $tz_offset = -1; |
|
46 | + // reset tz_offset global to prevent tz cache clash between users |
|
47 | + $tz_offset = -1; |
|
48 | 48 | |
49 | - $tuple = Digest::prepare_headlines_digest($line["id"], 1, $limit); |
|
50 | - $digest = $tuple[0]; |
|
51 | - $headlines_count = $tuple[1]; |
|
52 | - $affected_ids = $tuple[2]; |
|
53 | - $digest_text = $tuple[3]; |
|
49 | + $tuple = Digest::prepare_headlines_digest($line["id"], 1, $limit); |
|
50 | + $digest = $tuple[0]; |
|
51 | + $headlines_count = $tuple[1]; |
|
52 | + $affected_ids = $tuple[2]; |
|
53 | + $digest_text = $tuple[3]; |
|
54 | 54 | |
55 | - if ($headlines_count > 0) { |
|
55 | + if ($headlines_count > 0) { |
|
56 | 56 | |
57 | - $mailer = new Mailer(); |
|
57 | + $mailer = new Mailer(); |
|
58 | 58 | |
59 | - //$rc = $mail->quickMail($line["email"], $line["login"], DIGEST_SUBJECT, $digest, $digest_text); |
|
59 | + //$rc = $mail->quickMail($line["email"], $line["login"], DIGEST_SUBJECT, $digest, $digest_text); |
|
60 | 60 | |
61 | - $rc = $mailer->mail(["to_name" => $line["login"], |
|
62 | - "to_address" => $line["email"], |
|
63 | - "subject" => DIGEST_SUBJECT, |
|
64 | - "message" => $digest_text, |
|
65 | - "message_html" => $digest]); |
|
61 | + $rc = $mailer->mail(["to_name" => $line["login"], |
|
62 | + "to_address" => $line["email"], |
|
63 | + "subject" => DIGEST_SUBJECT, |
|
64 | + "message" => $digest_text, |
|
65 | + "message_html" => $digest]); |
|
66 | 66 | |
67 | - //if (!$rc && $debug) Debug::log("ERROR: " . $mailer->lastError()); |
|
67 | + //if (!$rc && $debug) Debug::log("ERROR: " . $mailer->lastError()); |
|
68 | 68 | |
69 | - Debug::log("RC=$rc"); |
|
69 | + Debug::log("RC=$rc"); |
|
70 | 70 | |
71 | - if ($rc && $do_catchup) { |
|
72 | - Debug::log("Marking affected articles as read..."); |
|
73 | - Article::catchupArticlesById($affected_ids, 0, $line["id"]); |
|
74 | - } |
|
75 | - } else { |
|
76 | - Debug::log("No headlines"); |
|
77 | - } |
|
71 | + if ($rc && $do_catchup) { |
|
72 | + Debug::log("Marking affected articles as read..."); |
|
73 | + Article::catchupArticlesById($affected_ids, 0, $line["id"]); |
|
74 | + } |
|
75 | + } else { |
|
76 | + Debug::log("No headlines"); |
|
77 | + } |
|
78 | 78 | |
79 | - $sth = $pdo->prepare("UPDATE ttrss_users SET last_digest_sent = NOW() |
|
79 | + $sth = $pdo->prepare("UPDATE ttrss_users SET last_digest_sent = NOW() |
|
80 | 80 | WHERE id = ?"); |
81 | - $sth->execute([$line["id"]]); |
|
81 | + $sth->execute([$line["id"]]); |
|
82 | 82 | |
83 | - } |
|
84 | - } |
|
85 | - } |
|
83 | + } |
|
84 | + } |
|
85 | + } |
|
86 | 86 | |
87 | - Debug::log("All done."); |
|
87 | + Debug::log("All done."); |
|
88 | 88 | |
89 | - } |
|
89 | + } |
|
90 | 90 | |
91 | - public static function prepare_headlines_digest($user_id, $days = 1, $limit = 1000) { |
|
91 | + public static function prepare_headlines_digest($user_id, $days = 1, $limit = 1000) { |
|
92 | 92 | |
93 | - require_once "lib/MiniTemplator.class.php"; |
|
93 | + require_once "lib/MiniTemplator.class.php"; |
|
94 | 94 | |
95 | - $tpl = new MiniTemplator; |
|
96 | - $tpl_t = new MiniTemplator; |
|
95 | + $tpl = new MiniTemplator; |
|
96 | + $tpl_t = new MiniTemplator; |
|
97 | 97 | |
98 | - $tpl->readTemplateFromFile("templates/digest_template_html.txt"); |
|
99 | - $tpl_t->readTemplateFromFile("templates/digest_template.txt"); |
|
98 | + $tpl->readTemplateFromFile("templates/digest_template_html.txt"); |
|
99 | + $tpl_t->readTemplateFromFile("templates/digest_template.txt"); |
|
100 | 100 | |
101 | - $user_tz_string = get_pref('USER_TIMEZONE', $user_id); |
|
102 | - $local_ts = convert_timestamp(time(), 'UTC', $user_tz_string); |
|
101 | + $user_tz_string = get_pref('USER_TIMEZONE', $user_id); |
|
102 | + $local_ts = convert_timestamp(time(), 'UTC', $user_tz_string); |
|
103 | 103 | |
104 | - $tpl->setVariable('CUR_DATE', date('Y/m/d', $local_ts)); |
|
105 | - $tpl->setVariable('CUR_TIME', date('G:i', $local_ts)); |
|
106 | - $tpl->setVariable('TTRSS_HOST', SELF_URL_PATH); |
|
104 | + $tpl->setVariable('CUR_DATE', date('Y/m/d', $local_ts)); |
|
105 | + $tpl->setVariable('CUR_TIME', date('G:i', $local_ts)); |
|
106 | + $tpl->setVariable('TTRSS_HOST', SELF_URL_PATH); |
|
107 | 107 | |
108 | - $tpl_t->setVariable('CUR_DATE', date('Y/m/d', $local_ts)); |
|
109 | - $tpl_t->setVariable('CUR_TIME', date('G:i', $local_ts)); |
|
110 | - $tpl_t->setVariable('TTRSS_HOST', SELF_URL_PATH); |
|
108 | + $tpl_t->setVariable('CUR_DATE', date('Y/m/d', $local_ts)); |
|
109 | + $tpl_t->setVariable('CUR_TIME', date('G:i', $local_ts)); |
|
110 | + $tpl_t->setVariable('TTRSS_HOST', SELF_URL_PATH); |
|
111 | 111 | |
112 | - $affected_ids = array(); |
|
112 | + $affected_ids = array(); |
|
113 | 113 | |
114 | - $days = (int) $days; |
|
114 | + $days = (int) $days; |
|
115 | 115 | |
116 | - if (DB_TYPE == "pgsql") { |
|
117 | - $interval_qpart = "ttrss_entries.date_updated > NOW() - INTERVAL '$days days'"; |
|
118 | - } else if (DB_TYPE == "mysql") { |
|
119 | - $interval_qpart = "ttrss_entries.date_updated > DATE_SUB(NOW(), INTERVAL $days DAY)"; |
|
120 | - } |
|
116 | + if (DB_TYPE == "pgsql") { |
|
117 | + $interval_qpart = "ttrss_entries.date_updated > NOW() - INTERVAL '$days days'"; |
|
118 | + } else if (DB_TYPE == "mysql") { |
|
119 | + $interval_qpart = "ttrss_entries.date_updated > DATE_SUB(NOW(), INTERVAL $days DAY)"; |
|
120 | + } |
|
121 | 121 | |
122 | - $pdo = Db::pdo(); |
|
122 | + $pdo = Db::pdo(); |
|
123 | 123 | |
124 | - $sth = $pdo->prepare("SELECT ttrss_entries.title, |
|
124 | + $sth = $pdo->prepare("SELECT ttrss_entries.title, |
|
125 | 125 | ttrss_feeds.title AS feed_title, |
126 | 126 | COALESCE(ttrss_feed_categories.title, '" . __('Uncategorized') . "') AS cat_title, |
127 | 127 | date_updated, |
@@ -143,76 +143,76 @@ discard block |
||
143 | 143 | AND score >= 0 |
144 | 144 | ORDER BY ttrss_feed_categories.title, ttrss_feeds.title, score DESC, date_updated DESC |
145 | 145 | LIMIT :limit"); |
146 | - $sth->bindParam(':user_id', intval($user_id, 10), PDO::PARAM_INT); |
|
147 | - $sth->bindParam(':limit', intval($limit, 10), PDO::PARAM_INT); |
|
148 | - $sth->execute(); |
|
146 | + $sth->bindParam(':user_id', intval($user_id, 10), PDO::PARAM_INT); |
|
147 | + $sth->bindParam(':limit', intval($limit, 10), PDO::PARAM_INT); |
|
148 | + $sth->execute(); |
|
149 | 149 | |
150 | - $headlines_count = 0; |
|
151 | - $headlines = array(); |
|
150 | + $headlines_count = 0; |
|
151 | + $headlines = array(); |
|
152 | 152 | |
153 | - while ($line = $sth->fetch()) { |
|
154 | - array_push($headlines, $line); |
|
155 | - $headlines_count++; |
|
156 | - } |
|
153 | + while ($line = $sth->fetch()) { |
|
154 | + array_push($headlines, $line); |
|
155 | + $headlines_count++; |
|
156 | + } |
|
157 | 157 | |
158 | - for ($i = 0; $i < sizeof($headlines); $i++) { |
|
158 | + for ($i = 0; $i < sizeof($headlines); $i++) { |
|
159 | 159 | |
160 | - $line = $headlines[$i]; |
|
160 | + $line = $headlines[$i]; |
|
161 | 161 | |
162 | - array_push($affected_ids, $line["ref_id"]); |
|
162 | + array_push($affected_ids, $line["ref_id"]); |
|
163 | 163 | |
164 | - $updated = make_local_datetime($line['last_updated'], false, |
|
165 | - $user_id); |
|
164 | + $updated = make_local_datetime($line['last_updated'], false, |
|
165 | + $user_id); |
|
166 | 166 | |
167 | - if (get_pref('ENABLE_FEED_CATS', $user_id)) { |
|
168 | - $line['feed_title'] = $line['cat_title'] . " / " . $line['feed_title']; |
|
169 | - } |
|
167 | + if (get_pref('ENABLE_FEED_CATS', $user_id)) { |
|
168 | + $line['feed_title'] = $line['cat_title'] . " / " . $line['feed_title']; |
|
169 | + } |
|
170 | 170 | |
171 | - $article_labels = Article::get_article_labels($line["ref_id"], $user_id); |
|
172 | - $article_labels_formatted = ""; |
|
171 | + $article_labels = Article::get_article_labels($line["ref_id"], $user_id); |
|
172 | + $article_labels_formatted = ""; |
|
173 | 173 | |
174 | - if (is_array($article_labels) && count($article_labels) > 0) { |
|
175 | - $article_labels_formatted = implode(", ", array_map(function($a) { |
|
176 | - return $a[1]; |
|
177 | - }, $article_labels)); |
|
178 | - } |
|
174 | + if (is_array($article_labels) && count($article_labels) > 0) { |
|
175 | + $article_labels_formatted = implode(", ", array_map(function($a) { |
|
176 | + return $a[1]; |
|
177 | + }, $article_labels)); |
|
178 | + } |
|
179 | 179 | |
180 | - $tpl->setVariable('FEED_TITLE', $line["feed_title"]); |
|
181 | - $tpl->setVariable('ARTICLE_TITLE', $line["title"]); |
|
182 | - $tpl->setVariable('ARTICLE_LINK', $line["link"]); |
|
183 | - $tpl->setVariable('ARTICLE_UPDATED', $updated); |
|
184 | - $tpl->setVariable('ARTICLE_EXCERPT', |
|
185 | - truncate_string(strip_tags($line["content"]), 300)); |
|
180 | + $tpl->setVariable('FEED_TITLE', $line["feed_title"]); |
|
181 | + $tpl->setVariable('ARTICLE_TITLE', $line["title"]); |
|
182 | + $tpl->setVariable('ARTICLE_LINK', $line["link"]); |
|
183 | + $tpl->setVariable('ARTICLE_UPDATED', $updated); |
|
184 | + $tpl->setVariable('ARTICLE_EXCERPT', |
|
185 | + truncate_string(strip_tags($line["content"]), 300)); |
|
186 | 186 | // $tpl->setVariable('ARTICLE_CONTENT', |
187 | 187 | // strip_tags($article_content)); |
188 | - $tpl->setVariable('ARTICLE_LABELS', $article_labels_formatted, true); |
|
188 | + $tpl->setVariable('ARTICLE_LABELS', $article_labels_formatted, true); |
|
189 | 189 | |
190 | - $tpl->addBlock('article'); |
|
190 | + $tpl->addBlock('article'); |
|
191 | 191 | |
192 | - $tpl_t->setVariable('FEED_TITLE', $line["feed_title"]); |
|
193 | - $tpl_t->setVariable('ARTICLE_TITLE', $line["title"]); |
|
194 | - $tpl_t->setVariable('ARTICLE_LINK', $line["link"]); |
|
195 | - $tpl_t->setVariable('ARTICLE_UPDATED', $updated); |
|
196 | - $tpl_t->setVariable('ARTICLE_LABELS', $article_labels_formatted, true); |
|
197 | - $tpl_t->setVariable('ARTICLE_EXCERPT', |
|
198 | - truncate_string(strip_tags($line["content"]), 300, "..."), true); |
|
192 | + $tpl_t->setVariable('FEED_TITLE', $line["feed_title"]); |
|
193 | + $tpl_t->setVariable('ARTICLE_TITLE', $line["title"]); |
|
194 | + $tpl_t->setVariable('ARTICLE_LINK', $line["link"]); |
|
195 | + $tpl_t->setVariable('ARTICLE_UPDATED', $updated); |
|
196 | + $tpl_t->setVariable('ARTICLE_LABELS', $article_labels_formatted, true); |
|
197 | + $tpl_t->setVariable('ARTICLE_EXCERPT', |
|
198 | + truncate_string(strip_tags($line["content"]), 300, "..."), true); |
|
199 | 199 | |
200 | - $tpl_t->addBlock('article'); |
|
200 | + $tpl_t->addBlock('article'); |
|
201 | 201 | |
202 | - if ($headlines[$i]['feed_title'] != $headlines[$i + 1]['feed_title']) { |
|
203 | - $tpl->addBlock('feed'); |
|
204 | - $tpl_t->addBlock('feed'); |
|
205 | - } |
|
202 | + if ($headlines[$i]['feed_title'] != $headlines[$i + 1]['feed_title']) { |
|
203 | + $tpl->addBlock('feed'); |
|
204 | + $tpl_t->addBlock('feed'); |
|
205 | + } |
|
206 | 206 | |
207 | - } |
|
207 | + } |
|
208 | 208 | |
209 | - $tpl->addBlock('digest'); |
|
210 | - $tpl->generateOutputToString($tmp); |
|
209 | + $tpl->addBlock('digest'); |
|
210 | + $tpl->generateOutputToString($tmp); |
|
211 | 211 | |
212 | - $tpl_t->addBlock('digest'); |
|
213 | - $tpl_t->generateOutputToString($tmp_t); |
|
212 | + $tpl_t->addBlock('digest'); |
|
213 | + $tpl_t->generateOutputToString($tmp_t); |
|
214 | 214 | |
215 | - return array($tmp, $headlines_count, $affected_ids, $tmp_t); |
|
216 | - } |
|
215 | + return array($tmp, $headlines_count, $affected_ids, $tmp_t); |
|
216 | + } |
|
217 | 217 | |
218 | 218 | } |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | $sth->execute([":uid" => $owner_uid, ":cat" => $feed_id]); |
136 | 136 | |
137 | 137 | while ($line = $sth->fetch()) { |
138 | - CCache::update((int)$line["id"], $owner_uid, false, false); |
|
138 | + CCache::update((int) $line["id"], $owner_uid, false, false); |
|
139 | 139 | } |
140 | 140 | } |
141 | 141 | |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | $sth->execute([$owner_uid, $feed_id]); |
198 | 198 | |
199 | 199 | if ($row = $sth->fetch()) { |
200 | - CCache::update((int)$row["cat_id"], $owner_uid, true, true, true); |
|
200 | + CCache::update((int) $row["cat_id"], $owner_uid, true, true, true); |
|
201 | 201 | } |
202 | 202 | } |
203 | 203 | } |
@@ -66,8 +66,9 @@ discard block |
||
66 | 66 | |
67 | 67 | // "" (null) is valid and should be cast to 0 (uncategorized) |
68 | 68 | // everything else i.e. tags are not |
69 | - if (!is_numeric($feed_id) && $feed_id) |
|
70 | - return; |
|
69 | + if (!is_numeric($feed_id) && $feed_id) { |
|
70 | + return; |
|
71 | + } |
|
71 | 72 | |
72 | 73 | $feed_id = (int) $feed_id; |
73 | 74 | |
@@ -102,8 +103,9 @@ discard block |
||
102 | 103 | |
103 | 104 | // "" (null) is valid and should be cast to 0 (uncategorized) |
104 | 105 | // everything else i.e. tags are not |
105 | - if (!is_numeric($feed_id) && $feed_id) |
|
106 | - return; |
|
106 | + if (!is_numeric($feed_id) && $feed_id) { |
|
107 | + return; |
|
108 | + } |
|
107 | 109 | |
108 | 110 | $feed_id = (int) $feed_id; |
109 | 111 | |
@@ -182,7 +184,9 @@ discard block |
||
182 | 184 | $sth->execute([$feed_id, $unread, $owner_uid]); |
183 | 185 | } |
184 | 186 | |
185 | - if (!$tr_in_progress) $pdo->commit(); |
|
187 | + if (!$tr_in_progress) { |
|
188 | + $pdo->commit(); |
|
189 | + } |
|
186 | 190 | |
187 | 191 | if ($feed_id > 0 && $prev_unread != $unread) { |
188 | 192 |
@@ -1,211 +1,211 @@ |
||
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; |
|
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 | 71 | |
72 | - $feed_id = (int) $feed_id; |
|
72 | + $feed_id = (int) $feed_id; |
|
73 | 73 | |
74 | - if (!$is_cat) { |
|
75 | - $table = "ttrss_counters_cache"; |
|
76 | - } else { |
|
77 | - $table = "ttrss_cat_counters_cache"; |
|
78 | - } |
|
74 | + if (!$is_cat) { |
|
75 | + $table = "ttrss_counters_cache"; |
|
76 | + } else { |
|
77 | + $table = "ttrss_cat_counters_cache"; |
|
78 | + } |
|
79 | 79 | |
80 | - $pdo = Db::pdo(); |
|
80 | + $pdo = Db::pdo(); |
|
81 | 81 | |
82 | - $sth = $pdo->prepare("SELECT value FROM $table |
|
82 | + $sth = $pdo->prepare("SELECT value FROM $table |
|
83 | 83 | WHERE owner_uid = ? AND feed_id = ? |
84 | 84 | LIMIT 1"); |
85 | 85 | |
86 | - $sth->execute([$owner_uid, $feed_id]); |
|
86 | + $sth->execute([$owner_uid, $feed_id]); |
|
87 | 87 | |
88 | - if ($row = $sth->fetch()) { |
|
89 | - return $row["value"]; |
|
90 | - } else { |
|
91 | - if ($no_update) { |
|
92 | - return -1; |
|
93 | - } else { |
|
94 | - return CCache::update($feed_id, $owner_uid, $is_cat); |
|
95 | - } |
|
96 | - } |
|
88 | + if ($row = $sth->fetch()) { |
|
89 | + return $row["value"]; |
|
90 | + } else { |
|
91 | + if ($no_update) { |
|
92 | + return -1; |
|
93 | + } else { |
|
94 | + return CCache::update($feed_id, $owner_uid, $is_cat); |
|
95 | + } |
|
96 | + } |
|
97 | 97 | |
98 | - } |
|
98 | + } |
|
99 | 99 | |
100 | - public static function update($feed_id, $owner_uid, $is_cat = false, |
|
101 | - $update_pcat = true, $pcat_fast = false) { |
|
100 | + public static function update($feed_id, $owner_uid, $is_cat = false, |
|
101 | + $update_pcat = true, $pcat_fast = false) { |
|
102 | 102 | |
103 | - // "" (null) is valid and should be cast to 0 (uncategorized) |
|
104 | - // everything else i.e. tags are not |
|
105 | - if (!is_numeric($feed_id) && $feed_id) |
|
106 | - return; |
|
103 | + // "" (null) is valid and should be cast to 0 (uncategorized) |
|
104 | + // everything else i.e. tags are not |
|
105 | + if (!is_numeric($feed_id) && $feed_id) |
|
106 | + return; |
|
107 | 107 | |
108 | - $feed_id = (int) $feed_id; |
|
108 | + $feed_id = (int) $feed_id; |
|
109 | 109 | |
110 | - $prev_unread = CCache::find($feed_id, $owner_uid, $is_cat, true); |
|
110 | + $prev_unread = CCache::find($feed_id, $owner_uid, $is_cat, true); |
|
111 | 111 | |
112 | - /* When updating a label, all we need to do is recalculate feed counters |
|
112 | + /* When updating a label, all we need to do is recalculate feed counters |
|
113 | 113 | * because labels are not cached */ |
114 | 114 | |
115 | - if ($feed_id < 0) { |
|
116 | - CCache::update_all($owner_uid); |
|
117 | - return; |
|
118 | - } |
|
115 | + if ($feed_id < 0) { |
|
116 | + CCache::update_all($owner_uid); |
|
117 | + return; |
|
118 | + } |
|
119 | 119 | |
120 | - if (!$is_cat) { |
|
121 | - $table = "ttrss_counters_cache"; |
|
122 | - } else { |
|
123 | - $table = "ttrss_cat_counters_cache"; |
|
124 | - } |
|
120 | + if (!$is_cat) { |
|
121 | + $table = "ttrss_counters_cache"; |
|
122 | + } else { |
|
123 | + $table = "ttrss_cat_counters_cache"; |
|
124 | + } |
|
125 | 125 | |
126 | - $pdo = Db::pdo(); |
|
126 | + $pdo = Db::pdo(); |
|
127 | 127 | |
128 | - if ($is_cat && $feed_id >= 0) { |
|
129 | - /* Recalculate counters for child feeds */ |
|
128 | + if ($is_cat && $feed_id >= 0) { |
|
129 | + /* Recalculate counters for child feeds */ |
|
130 | 130 | |
131 | - if (!$pcat_fast) { |
|
132 | - $sth = $pdo->prepare("SELECT id FROM ttrss_feeds |
|
131 | + if (!$pcat_fast) { |
|
132 | + $sth = $pdo->prepare("SELECT id FROM ttrss_feeds |
|
133 | 133 | WHERE owner_uid = :uid AND |
134 | 134 | (cat_id = :cat OR (:cat = 0 AND cat_id IS NULL))"); |
135 | - $sth->execute([":uid" => $owner_uid, ":cat" => $feed_id]); |
|
135 | + $sth->execute([":uid" => $owner_uid, ":cat" => $feed_id]); |
|
136 | 136 | |
137 | - while ($line = $sth->fetch()) { |
|
138 | - CCache::update((int)$line["id"], $owner_uid, false, false); |
|
139 | - } |
|
140 | - } |
|
137 | + while ($line = $sth->fetch()) { |
|
138 | + CCache::update((int)$line["id"], $owner_uid, false, false); |
|
139 | + } |
|
140 | + } |
|
141 | 141 | |
142 | - $sth = $pdo->prepare("SELECT SUM(value) AS sv |
|
142 | + $sth = $pdo->prepare("SELECT SUM(value) AS sv |
|
143 | 143 | FROM ttrss_counters_cache, ttrss_feeds |
144 | 144 | WHERE ttrss_feeds.id = feed_id AND |
145 | 145 | (cat_id = :cat OR (:cat = 0 AND cat_id IS NULL)) AND |
146 | 146 | ttrss_counters_cache.owner_uid = :uid AND |
147 | 147 | ttrss_feeds.owner_uid = :uid"); |
148 | - $sth->execute([":uid" => $owner_uid, ":cat" => $feed_id]); |
|
149 | - $row = $sth->fetch(); |
|
148 | + $sth->execute([":uid" => $owner_uid, ":cat" => $feed_id]); |
|
149 | + $row = $sth->fetch(); |
|
150 | 150 | |
151 | - $unread = (int) $row["sv"]; |
|
151 | + $unread = (int) $row["sv"]; |
|
152 | 152 | |
153 | - } else { |
|
154 | - $unread = (int) Feeds::getFeedArticles($feed_id, $is_cat, true, $owner_uid); |
|
155 | - } |
|
153 | + } else { |
|
154 | + $unread = (int) Feeds::getFeedArticles($feed_id, $is_cat, true, $owner_uid); |
|
155 | + } |
|
156 | 156 | |
157 | - $tr_in_progress = false; |
|
157 | + $tr_in_progress = false; |
|
158 | 158 | |
159 | - try { |
|
160 | - $pdo->beginTransaction(); |
|
161 | - } catch (Exception $e) { |
|
162 | - $tr_in_progress = true; |
|
163 | - } |
|
159 | + try { |
|
160 | + $pdo->beginTransaction(); |
|
161 | + } catch (Exception $e) { |
|
162 | + $tr_in_progress = true; |
|
163 | + } |
|
164 | 164 | |
165 | - $sth = $pdo->prepare("SELECT feed_id FROM $table |
|
165 | + $sth = $pdo->prepare("SELECT feed_id FROM $table |
|
166 | 166 | WHERE owner_uid = ? AND feed_id = ? LIMIT 1"); |
167 | - $sth->execute([$owner_uid, $feed_id]); |
|
167 | + $sth->execute([$owner_uid, $feed_id]); |
|
168 | 168 | |
169 | - if ($sth->fetch()) { |
|
169 | + if ($sth->fetch()) { |
|
170 | 170 | |
171 | - $sth = $pdo->prepare("update $table SET |
|
171 | + $sth = $pdo->prepare("update $table SET |
|
172 | 172 | value = ?, updated = NOW() WHERE |
173 | 173 | feed_id = ? AND owner_uid = ?"); |
174 | 174 | |
175 | - $sth->execute([$unread, $feed_id, $owner_uid]); |
|
175 | + $sth->execute([$unread, $feed_id, $owner_uid]); |
|
176 | 176 | |
177 | - } else { |
|
178 | - $sth = $pdo->prepare("INSERT INTO $table |
|
177 | + } else { |
|
178 | + $sth = $pdo->prepare("INSERT INTO $table |
|
179 | 179 | (feed_id, value, owner_uid, updated) |
180 | 180 | VALUES |
181 | 181 | (?, ?, ?, NOW())"); |
182 | - $sth->execute([$feed_id, $unread, $owner_uid]); |
|
183 | - } |
|
182 | + $sth->execute([$feed_id, $unread, $owner_uid]); |
|
183 | + } |
|
184 | 184 | |
185 | - if (!$tr_in_progress) $pdo->commit(); |
|
185 | + if (!$tr_in_progress) $pdo->commit(); |
|
186 | 186 | |
187 | - if ($feed_id > 0 && $prev_unread != $unread) { |
|
187 | + if ($feed_id > 0 && $prev_unread != $unread) { |
|
188 | 188 | |
189 | - if (!$is_cat) { |
|
189 | + if (!$is_cat) { |
|
190 | 190 | |
191 | - /* Update parent category */ |
|
191 | + /* Update parent category */ |
|
192 | 192 | |
193 | - if ($update_pcat) { |
|
193 | + if ($update_pcat) { |
|
194 | 194 | |
195 | - $sth = $pdo->prepare("SELECT cat_id FROM ttrss_feeds |
|
195 | + $sth = $pdo->prepare("SELECT cat_id FROM ttrss_feeds |
|
196 | 196 | WHERE owner_uid = ? AND id = ?"); |
197 | - $sth->execute([$owner_uid, $feed_id]); |
|
198 | - |
|
199 | - if ($row = $sth->fetch()) { |
|
200 | - CCache::update((int)$row["cat_id"], $owner_uid, true, true, true); |
|
201 | - } |
|
202 | - } |
|
203 | - } |
|
204 | - } else if ($feed_id < 0) { |
|
205 | - CCache::update_all($owner_uid); |
|
206 | - } |
|
207 | - |
|
208 | - return $unread; |
|
209 | - } |
|
197 | + $sth->execute([$owner_uid, $feed_id]); |
|
198 | + |
|
199 | + if ($row = $sth->fetch()) { |
|
200 | + CCache::update((int)$row["cat_id"], $owner_uid, true, true, true); |
|
201 | + } |
|
202 | + } |
|
203 | + } |
|
204 | + } else if ($feed_id < 0) { |
|
205 | + CCache::update_all($owner_uid); |
|
206 | + } |
|
207 | + |
|
208 | + return $unread; |
|
209 | + } |
|
210 | 210 | |
211 | 211 | } |
@@ -175,7 +175,7 @@ |
||
175 | 175 | |
176 | 176 | // we don't support numeric tags |
177 | 177 | if (is_numeric($cat)) |
178 | - $cat = 't:' . $cat; |
|
178 | + $cat = 't:'.$cat; |
|
179 | 179 | |
180 | 180 | $cat = preg_replace('/[,\'\"]/', "", $cat); |
181 | 181 |
@@ -1,196 +1,196 @@ |
||
1 | 1 | <?php |
2 | 2 | abstract class FeedItem_Common extends FeedItem { |
3 | - protected $elem; |
|
4 | - protected $xpath; |
|
5 | - protected $doc; |
|
3 | + protected $elem; |
|
4 | + protected $xpath; |
|
5 | + protected $doc; |
|
6 | 6 | |
7 | - public function __construct($elem, $doc, $xpath) { |
|
8 | - $this->elem = $elem; |
|
9 | - $this->xpath = $xpath; |
|
10 | - $this->doc = $doc; |
|
7 | + public function __construct($elem, $doc, $xpath) { |
|
8 | + $this->elem = $elem; |
|
9 | + $this->xpath = $xpath; |
|
10 | + $this->doc = $doc; |
|
11 | 11 | |
12 | - try { |
|
12 | + try { |
|
13 | 13 | |
14 | - $source = $elem->getElementsByTagName("source")->item(0); |
|
14 | + $source = $elem->getElementsByTagName("source")->item(0); |
|
15 | 15 | |
16 | - // we don't need <source> element |
|
17 | - if ($source) |
|
18 | - $elem->removeChild($source); |
|
19 | - } catch (DOMException $e) { |
|
20 | - // |
|
21 | - } |
|
22 | - } |
|
16 | + // we don't need <source> element |
|
17 | + if ($source) |
|
18 | + $elem->removeChild($source); |
|
19 | + } catch (DOMException $e) { |
|
20 | + // |
|
21 | + } |
|
22 | + } |
|
23 | 23 | |
24 | - public function get_element() { |
|
25 | - return $this->elem; |
|
26 | - } |
|
24 | + public function get_element() { |
|
25 | + return $this->elem; |
|
26 | + } |
|
27 | 27 | |
28 | - public function get_author() { |
|
29 | - $author = $this->elem->getElementsByTagName("author")->item(0); |
|
28 | + public function get_author() { |
|
29 | + $author = $this->elem->getElementsByTagName("author")->item(0); |
|
30 | 30 | |
31 | - if ($author) { |
|
32 | - $name = $author->getElementsByTagName("name")->item(0); |
|
31 | + if ($author) { |
|
32 | + $name = $author->getElementsByTagName("name")->item(0); |
|
33 | 33 | |
34 | - if ($name) return clean($name->nodeValue); |
|
34 | + if ($name) return clean($name->nodeValue); |
|
35 | 35 | |
36 | - $email = $author->getElementsByTagName("email")->item(0); |
|
36 | + $email = $author->getElementsByTagName("email")->item(0); |
|
37 | 37 | |
38 | - if ($email) return clean($email->nodeValue); |
|
38 | + if ($email) return clean($email->nodeValue); |
|
39 | 39 | |
40 | - if ($author->nodeValue) |
|
41 | - return clean($author->nodeValue); |
|
42 | - } |
|
40 | + if ($author->nodeValue) |
|
41 | + return clean($author->nodeValue); |
|
42 | + } |
|
43 | 43 | |
44 | - $author_elems = $this->xpath->query("dc:creator", $this->elem); |
|
45 | - $authors = []; |
|
44 | + $author_elems = $this->xpath->query("dc:creator", $this->elem); |
|
45 | + $authors = []; |
|
46 | 46 | |
47 | - foreach ($author_elems as $author) { |
|
48 | - array_push($authors, clean($author->nodeValue)); |
|
49 | - } |
|
47 | + foreach ($author_elems as $author) { |
|
48 | + array_push($authors, clean($author->nodeValue)); |
|
49 | + } |
|
50 | 50 | |
51 | - return implode(", ", $authors); |
|
52 | - } |
|
51 | + return implode(", ", $authors); |
|
52 | + } |
|
53 | 53 | |
54 | - public function get_comments_url() { |
|
55 | - //RSS only. Use a query here to avoid namespace clashes (e.g. with slash). |
|
56 | - //might give a wrong result if a default namespace was declared (possible with XPath 2.0) |
|
57 | - $com_url = $this->xpath->query("comments", $this->elem)->item(0); |
|
54 | + public function get_comments_url() { |
|
55 | + //RSS only. Use a query here to avoid namespace clashes (e.g. with slash). |
|
56 | + //might give a wrong result if a default namespace was declared (possible with XPath 2.0) |
|
57 | + $com_url = $this->xpath->query("comments", $this->elem)->item(0); |
|
58 | 58 | |
59 | - if ($com_url) |
|
60 | - return clean($com_url->nodeValue); |
|
59 | + if ($com_url) |
|
60 | + return clean($com_url->nodeValue); |
|
61 | 61 | |
62 | - //Atom Threading Extension (RFC 4685) stuff. Could be used in RSS feeds, so it's in common. |
|
63 | - //'text/html' for type is too restrictive? |
|
64 | - $com_url = $this->xpath->query("atom:link[@rel='replies' and contains(@type,'text/html')]/@href", $this->elem)->item(0); |
|
62 | + //Atom Threading Extension (RFC 4685) stuff. Could be used in RSS feeds, so it's in common. |
|
63 | + //'text/html' for type is too restrictive? |
|
64 | + $com_url = $this->xpath->query("atom:link[@rel='replies' and contains(@type,'text/html')]/@href", $this->elem)->item(0); |
|
65 | 65 | |
66 | - if ($com_url) |
|
67 | - return clean($com_url->nodeValue); |
|
68 | - } |
|
66 | + if ($com_url) |
|
67 | + return clean($com_url->nodeValue); |
|
68 | + } |
|
69 | 69 | |
70 | - public function get_comments_count() { |
|
71 | - //also query for ATE stuff here |
|
72 | - $query = "slash:comments|thread:total|atom:link[@rel='replies']/@thread:count"; |
|
73 | - $comments = $this->xpath->query($query, $this->elem)->item(0); |
|
70 | + public function get_comments_count() { |
|
71 | + //also query for ATE stuff here |
|
72 | + $query = "slash:comments|thread:total|atom:link[@rel='replies']/@thread:count"; |
|
73 | + $comments = $this->xpath->query($query, $this->elem)->item(0); |
|
74 | 74 | |
75 | - if ($comments) { |
|
76 | - return clean($comments->nodeValue); |
|
77 | - } |
|
78 | - } |
|
75 | + if ($comments) { |
|
76 | + return clean($comments->nodeValue); |
|
77 | + } |
|
78 | + } |
|
79 | 79 | |
80 | - // this is common for both Atom and RSS types and deals with various media: elements |
|
81 | - public function get_enclosures() { |
|
82 | - $encs = []; |
|
80 | + // this is common for both Atom and RSS types and deals with various media: elements |
|
81 | + public function get_enclosures() { |
|
82 | + $encs = []; |
|
83 | 83 | |
84 | - $enclosures = $this->xpath->query("media:content", $this->elem); |
|
84 | + $enclosures = $this->xpath->query("media:content", $this->elem); |
|
85 | 85 | |
86 | - foreach ($enclosures as $enclosure) { |
|
87 | - $enc = new FeedEnclosure(); |
|
86 | + foreach ($enclosures as $enclosure) { |
|
87 | + $enc = new FeedEnclosure(); |
|
88 | 88 | |
89 | - $enc->type = clean($enclosure->getAttribute("type")); |
|
90 | - $enc->link = clean($enclosure->getAttribute("url")); |
|
91 | - $enc->length = clean($enclosure->getAttribute("length")); |
|
92 | - $enc->height = clean($enclosure->getAttribute("height")); |
|
93 | - $enc->width = clean($enclosure->getAttribute("width")); |
|
89 | + $enc->type = clean($enclosure->getAttribute("type")); |
|
90 | + $enc->link = clean($enclosure->getAttribute("url")); |
|
91 | + $enc->length = clean($enclosure->getAttribute("length")); |
|
92 | + $enc->height = clean($enclosure->getAttribute("height")); |
|
93 | + $enc->width = clean($enclosure->getAttribute("width")); |
|
94 | 94 | |
95 | - $medium = clean($enclosure->getAttribute("medium")); |
|
96 | - if (!$enc->type && $medium) { |
|
97 | - $enc->type = strtolower("$medium/generic"); |
|
98 | - } |
|
95 | + $medium = clean($enclosure->getAttribute("medium")); |
|
96 | + if (!$enc->type && $medium) { |
|
97 | + $enc->type = strtolower("$medium/generic"); |
|
98 | + } |
|
99 | 99 | |
100 | - $desc = $this->xpath->query("media:description", $enclosure)->item(0); |
|
101 | - if ($desc) $enc->title = clean($desc->nodeValue); |
|
100 | + $desc = $this->xpath->query("media:description", $enclosure)->item(0); |
|
101 | + if ($desc) $enc->title = clean($desc->nodeValue); |
|
102 | 102 | |
103 | - array_push($encs, $enc); |
|
104 | - } |
|
103 | + array_push($encs, $enc); |
|
104 | + } |
|
105 | 105 | |
106 | - $enclosures = $this->xpath->query("media:group", $this->elem); |
|
106 | + $enclosures = $this->xpath->query("media:group", $this->elem); |
|
107 | 107 | |
108 | - foreach ($enclosures as $enclosure) { |
|
109 | - $enc = new FeedEnclosure(); |
|
108 | + foreach ($enclosures as $enclosure) { |
|
109 | + $enc = new FeedEnclosure(); |
|
110 | 110 | |
111 | - $content = $this->xpath->query("media:content", $enclosure)->item(0); |
|
111 | + $content = $this->xpath->query("media:content", $enclosure)->item(0); |
|
112 | 112 | |
113 | - if ($content) { |
|
114 | - $enc->type = clean($content->getAttribute("type")); |
|
115 | - $enc->link = clean($content->getAttribute("url")); |
|
116 | - $enc->length = clean($content->getAttribute("length")); |
|
117 | - $enc->height = clean($content->getAttribute("height")); |
|
118 | - $enc->width = clean($content->getAttribute("width")); |
|
113 | + if ($content) { |
|
114 | + $enc->type = clean($content->getAttribute("type")); |
|
115 | + $enc->link = clean($content->getAttribute("url")); |
|
116 | + $enc->length = clean($content->getAttribute("length")); |
|
117 | + $enc->height = clean($content->getAttribute("height")); |
|
118 | + $enc->width = clean($content->getAttribute("width")); |
|
119 | 119 | |
120 | - $medium = clean($content->getAttribute("medium")); |
|
121 | - if (!$enc->type && $medium) { |
|
122 | - $enc->type = strtolower("$medium/generic"); |
|
123 | - } |
|
120 | + $medium = clean($content->getAttribute("medium")); |
|
121 | + if (!$enc->type && $medium) { |
|
122 | + $enc->type = strtolower("$medium/generic"); |
|
123 | + } |
|
124 | 124 | |
125 | - $desc = $this->xpath->query("media:description", $content)->item(0); |
|
126 | - if ($desc) { |
|
127 | - $enc->title = clean($desc->nodeValue); |
|
128 | - } else { |
|
129 | - $desc = $this->xpath->query("media:description", $enclosure)->item(0); |
|
130 | - if ($desc) $enc->title = clean($desc->nodeValue); |
|
131 | - } |
|
125 | + $desc = $this->xpath->query("media:description", $content)->item(0); |
|
126 | + if ($desc) { |
|
127 | + $enc->title = clean($desc->nodeValue); |
|
128 | + } else { |
|
129 | + $desc = $this->xpath->query("media:description", $enclosure)->item(0); |
|
130 | + if ($desc) $enc->title = clean($desc->nodeValue); |
|
131 | + } |
|
132 | 132 | |
133 | - array_push($encs, $enc); |
|
134 | - } |
|
135 | - } |
|
133 | + array_push($encs, $enc); |
|
134 | + } |
|
135 | + } |
|
136 | 136 | |
137 | - $enclosures = $this->xpath->query("media:thumbnail", $this->elem); |
|
137 | + $enclosures = $this->xpath->query("media:thumbnail", $this->elem); |
|
138 | 138 | |
139 | - foreach ($enclosures as $enclosure) { |
|
140 | - $enc = new FeedEnclosure(); |
|
139 | + foreach ($enclosures as $enclosure) { |
|
140 | + $enc = new FeedEnclosure(); |
|
141 | 141 | |
142 | - $enc->type = "image/generic"; |
|
143 | - $enc->link = clean($enclosure->getAttribute("url")); |
|
144 | - $enc->height = clean($enclosure->getAttribute("height")); |
|
145 | - $enc->width = clean($enclosure->getAttribute("width")); |
|
142 | + $enc->type = "image/generic"; |
|
143 | + $enc->link = clean($enclosure->getAttribute("url")); |
|
144 | + $enc->height = clean($enclosure->getAttribute("height")); |
|
145 | + $enc->width = clean($enclosure->getAttribute("width")); |
|
146 | 146 | |
147 | - array_push($encs, $enc); |
|
148 | - } |
|
147 | + array_push($encs, $enc); |
|
148 | + } |
|
149 | 149 | |
150 | - return $encs; |
|
151 | - } |
|
150 | + return $encs; |
|
151 | + } |
|
152 | 152 | |
153 | - public function count_children($node) { |
|
154 | - return $node->getElementsByTagName("*")->length; |
|
155 | - } |
|
153 | + public function count_children($node) { |
|
154 | + return $node->getElementsByTagName("*")->length; |
|
155 | + } |
|
156 | 156 | |
157 | - public function subtree_or_text($node) { |
|
158 | - if ($this->count_children($node) == 0) { |
|
159 | - return $node->nodeValue; |
|
160 | - } else { |
|
161 | - return $node->c14n(); |
|
162 | - } |
|
163 | - } |
|
157 | + public function subtree_or_text($node) { |
|
158 | + if ($this->count_children($node) == 0) { |
|
159 | + return $node->nodeValue; |
|
160 | + } else { |
|
161 | + return $node->c14n(); |
|
162 | + } |
|
163 | + } |
|
164 | 164 | |
165 | - public static function normalize_categories($cats) { |
|
165 | + public static function normalize_categories($cats) { |
|
166 | 166 | |
167 | - $tmp = []; |
|
167 | + $tmp = []; |
|
168 | 168 | |
169 | - foreach ($cats as $rawcat) { |
|
170 | - $tmp = array_merge($tmp, explode(",", $rawcat)); |
|
171 | - } |
|
169 | + foreach ($cats as $rawcat) { |
|
170 | + $tmp = array_merge($tmp, explode(",", $rawcat)); |
|
171 | + } |
|
172 | 172 | |
173 | - $tmp = array_map(function($srccat) { |
|
174 | - $cat = clean(trim(mb_strtolower($srccat))); |
|
173 | + $tmp = array_map(function($srccat) { |
|
174 | + $cat = clean(trim(mb_strtolower($srccat))); |
|
175 | 175 | |
176 | - // we don't support numeric tags |
|
177 | - if (is_numeric($cat)) |
|
178 | - $cat = 't:' . $cat; |
|
176 | + // we don't support numeric tags |
|
177 | + if (is_numeric($cat)) |
|
178 | + $cat = 't:' . $cat; |
|
179 | 179 | |
180 | - $cat = preg_replace('/[,\'\"]/', "", $cat); |
|
180 | + $cat = preg_replace('/[,\'\"]/', "", $cat); |
|
181 | 181 | |
182 | - if (DB_TYPE == "mysql") { |
|
183 | - $cat = preg_replace('/[\x{10000}-\x{10FFFF}]/u', "\xEF\xBF\xBD", $cat); |
|
184 | - } |
|
182 | + if (DB_TYPE == "mysql") { |
|
183 | + $cat = preg_replace('/[\x{10000}-\x{10FFFF}]/u', "\xEF\xBF\xBD", $cat); |
|
184 | + } |
|
185 | 185 | |
186 | - if (mb_strlen($cat) > 250) |
|
187 | - $cat = mb_substr($cat, 0, 250); |
|
186 | + if (mb_strlen($cat) > 250) |
|
187 | + $cat = mb_substr($cat, 0, 250); |
|
188 | 188 | |
189 | - return $cat; |
|
190 | - }, $tmp); |
|
189 | + return $cat; |
|
190 | + }, $tmp); |
|
191 | 191 | |
192 | - asort($tmp); |
|
192 | + asort($tmp); |
|
193 | 193 | |
194 | - return array_unique($tmp); |
|
195 | - } |
|
194 | + return array_unique($tmp); |
|
195 | + } |
|
196 | 196 | } |
@@ -14,8 +14,9 @@ discard block |
||
14 | 14 | $source = $elem->getElementsByTagName("source")->item(0); |
15 | 15 | |
16 | 16 | // we don't need <source> element |
17 | - if ($source) |
|
18 | - $elem->removeChild($source); |
|
17 | + if ($source) { |
|
18 | + $elem->removeChild($source); |
|
19 | + } |
|
19 | 20 | } catch (DOMException $e) { |
20 | 21 | // |
21 | 22 | } |
@@ -31,14 +32,19 @@ discard block |
||
31 | 32 | if ($author) { |
32 | 33 | $name = $author->getElementsByTagName("name")->item(0); |
33 | 34 | |
34 | - if ($name) return clean($name->nodeValue); |
|
35 | + if ($name) { |
|
36 | + return clean($name->nodeValue); |
|
37 | + } |
|
35 | 38 | |
36 | 39 | $email = $author->getElementsByTagName("email")->item(0); |
37 | 40 | |
38 | - if ($email) return clean($email->nodeValue); |
|
41 | + if ($email) { |
|
42 | + return clean($email->nodeValue); |
|
43 | + } |
|
39 | 44 | |
40 | - if ($author->nodeValue) |
|
41 | - return clean($author->nodeValue); |
|
45 | + if ($author->nodeValue) { |
|
46 | + return clean($author->nodeValue); |
|
47 | + } |
|
42 | 48 | } |
43 | 49 | |
44 | 50 | $author_elems = $this->xpath->query("dc:creator", $this->elem); |
@@ -56,15 +62,17 @@ discard block |
||
56 | 62 | //might give a wrong result if a default namespace was declared (possible with XPath 2.0) |
57 | 63 | $com_url = $this->xpath->query("comments", $this->elem)->item(0); |
58 | 64 | |
59 | - if ($com_url) |
|
60 | - return clean($com_url->nodeValue); |
|
65 | + if ($com_url) { |
|
66 | + return clean($com_url->nodeValue); |
|
67 | + } |
|
61 | 68 | |
62 | 69 | //Atom Threading Extension (RFC 4685) stuff. Could be used in RSS feeds, so it's in common. |
63 | 70 | //'text/html' for type is too restrictive? |
64 | 71 | $com_url = $this->xpath->query("atom:link[@rel='replies' and contains(@type,'text/html')]/@href", $this->elem)->item(0); |
65 | 72 | |
66 | - if ($com_url) |
|
67 | - return clean($com_url->nodeValue); |
|
73 | + if ($com_url) { |
|
74 | + return clean($com_url->nodeValue); |
|
75 | + } |
|
68 | 76 | } |
69 | 77 | |
70 | 78 | public function get_comments_count() { |
@@ -98,7 +106,9 @@ discard block |
||
98 | 106 | } |
99 | 107 | |
100 | 108 | $desc = $this->xpath->query("media:description", $enclosure)->item(0); |
101 | - if ($desc) $enc->title = clean($desc->nodeValue); |
|
109 | + if ($desc) { |
|
110 | + $enc->title = clean($desc->nodeValue); |
|
111 | + } |
|
102 | 112 | |
103 | 113 | array_push($encs, $enc); |
104 | 114 | } |
@@ -127,7 +137,9 @@ discard block |
||
127 | 137 | $enc->title = clean($desc->nodeValue); |
128 | 138 | } else { |
129 | 139 | $desc = $this->xpath->query("media:description", $enclosure)->item(0); |
130 | - if ($desc) $enc->title = clean($desc->nodeValue); |
|
140 | + if ($desc) { |
|
141 | + $enc->title = clean($desc->nodeValue); |
|
142 | + } |
|
131 | 143 | } |
132 | 144 | |
133 | 145 | array_push($encs, $enc); |
@@ -174,8 +186,9 @@ discard block |
||
174 | 186 | $cat = clean(trim(mb_strtolower($srccat))); |
175 | 187 | |
176 | 188 | // we don't support numeric tags |
177 | - if (is_numeric($cat)) |
|
178 | - $cat = 't:' . $cat; |
|
189 | + if (is_numeric($cat)) { |
|
190 | + $cat = 't:' . $cat; |
|
191 | + } |
|
179 | 192 | |
180 | 193 | $cat = preg_replace('/[,\'\"]/', "", $cat); |
181 | 194 | |
@@ -183,8 +196,9 @@ discard block |
||
183 | 196 | $cat = preg_replace('/[\x{10000}-\x{10FFFF}]/u', "\xEF\xBF\xBD", $cat); |
184 | 197 | } |
185 | 198 | |
186 | - if (mb_strlen($cat) > 250) |
|
187 | - $cat = mb_substr($cat, 0, 250); |
|
199 | + if (mb_strlen($cat) > 250) { |
|
200 | + $cat = mb_substr($cat, 0, 250); |
|
201 | + } |
|
188 | 202 | |
189 | 203 | return $cat; |
190 | 204 | }, $tmp); |
@@ -43,10 +43,11 @@ discard block |
||
43 | 43 | || $link->getAttribute("rel") == "standout")) { |
44 | 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"))); |
|
46 | + if ($base) { |
|
47 | + return rewrite_relative_url($base, clean(trim($link->getAttribute("href")))); |
|
48 | + } else { |
|
49 | + return clean(trim($link->getAttribute("href"))); |
|
50 | + } |
|
50 | 51 | |
51 | 52 | } |
52 | 53 | } |
@@ -106,8 +107,9 @@ discard block |
||
106 | 107 | $cats = []; |
107 | 108 | |
108 | 109 | foreach ($categories as $cat) { |
109 | - if ($cat->hasAttribute("term")) |
|
110 | - array_push($cats, $cat->getAttribute("term")); |
|
110 | + if ($cat->hasAttribute("term")) { |
|
111 | + array_push($cats, $cat->getAttribute("term")); |
|
112 | + } |
|
111 | 113 | } |
112 | 114 | |
113 | 115 | $categories = $this->xpath->query("dc:subject", $this->elem); |
@@ -1,160 +1,160 @@ |
||
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); |
|
5 | + public function get_id() { |
|
6 | + $id = $this->elem->getElementsByTagName("id")->item(0); |
|
7 | 7 | |
8 | - if ($id) { |
|
9 | - return $id->nodeValue; |
|
10 | - } else { |
|
11 | - return clean($this->get_link()); |
|
12 | - } |
|
13 | - } |
|
8 | + if ($id) { |
|
9 | + return $id->nodeValue; |
|
10 | + } else { |
|
11 | + return clean($this->get_link()); |
|
12 | + } |
|
13 | + } |
|
14 | 14 | |
15 | - public function get_date() { |
|
16 | - $updated = $this->elem->getElementsByTagName("updated")->item(0); |
|
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"))); |
|
46 | + if ($base) |
|
47 | + return rewrite_relative_url($base, clean(trim($link->getAttribute("href")))); |
|
48 | + else |
|
49 | + return clean(trim($link->getAttribute("href"))); |
|
50 | 50 | |
51 | - } |
|
52 | - } |
|
53 | - } |
|
51 | + } |
|
52 | + } |
|
53 | + } |
|
54 | 54 | |
55 | - public function get_title() { |
|
56 | - $title = $this->elem->getElementsByTagName("title")->item(0); |
|
55 | + public function get_title() { |
|
56 | + $title = $this->elem->getElementsByTagName("title")->item(0); |
|
57 | 57 | |
58 | - if ($title) { |
|
59 | - return clean(trim($title->nodeValue)); |
|
60 | - } |
|
61 | - } |
|
62 | - |
|
63 | - public function get_content() { |
|
64 | - $content = $this->elem->getElementsByTagName("content")->item(0); |
|
65 | - |
|
66 | - if ($content) { |
|
67 | - if ($content->hasAttribute('type')) { |
|
68 | - if ($content->getAttribute('type') == 'xhtml') { |
|
69 | - for ($i = 0; $i < $content->childNodes->length; $i++) { |
|
70 | - $child = $content->childNodes->item($i); |
|
71 | - |
|
72 | - if ($child->hasChildNodes()) { |
|
73 | - return $this->doc->saveHTML($child); |
|
74 | - } |
|
75 | - } |
|
76 | - } |
|
77 | - } |
|
78 | - |
|
79 | - return $this->subtree_or_text($content); |
|
80 | - } |
|
81 | - } |
|
82 | - |
|
83 | - public function get_description() { |
|
84 | - $content = $this->elem->getElementsByTagName("summary")->item(0); |
|
85 | - |
|
86 | - if ($content) { |
|
87 | - if ($content->hasAttribute('type')) { |
|
88 | - if ($content->getAttribute('type') == 'xhtml') { |
|
89 | - for ($i = 0; $i < $content->childNodes->length; $i++) { |
|
90 | - $child = $content->childNodes->item($i); |
|
91 | - |
|
92 | - if ($child->hasChildNodes()) { |
|
93 | - return $this->doc->saveHTML($child); |
|
94 | - } |
|
95 | - } |
|
96 | - } |
|
97 | - } |
|
98 | - |
|
99 | - return $this->subtree_or_text($content); |
|
100 | - } |
|
101 | - |
|
102 | - } |
|
103 | - |
|
104 | - public function get_categories() { |
|
105 | - $categories = $this->elem->getElementsByTagName("category"); |
|
106 | - $cats = []; |
|
107 | - |
|
108 | - foreach ($categories as $cat) { |
|
109 | - if ($cat->hasAttribute("term")) |
|
110 | - array_push($cats, $cat->getAttribute("term")); |
|
111 | - } |
|
112 | - |
|
113 | - $categories = $this->xpath->query("dc:subject", $this->elem); |
|
58 | + if ($title) { |
|
59 | + return clean(trim($title->nodeValue)); |
|
60 | + } |
|
61 | + } |
|
62 | + |
|
63 | + public function get_content() { |
|
64 | + $content = $this->elem->getElementsByTagName("content")->item(0); |
|
65 | + |
|
66 | + if ($content) { |
|
67 | + if ($content->hasAttribute('type')) { |
|
68 | + if ($content->getAttribute('type') == 'xhtml') { |
|
69 | + for ($i = 0; $i < $content->childNodes->length; $i++) { |
|
70 | + $child = $content->childNodes->item($i); |
|
71 | + |
|
72 | + if ($child->hasChildNodes()) { |
|
73 | + return $this->doc->saveHTML($child); |
|
74 | + } |
|
75 | + } |
|
76 | + } |
|
77 | + } |
|
78 | + |
|
79 | + return $this->subtree_or_text($content); |
|
80 | + } |
|
81 | + } |
|
82 | + |
|
83 | + public function get_description() { |
|
84 | + $content = $this->elem->getElementsByTagName("summary")->item(0); |
|
85 | + |
|
86 | + if ($content) { |
|
87 | + if ($content->hasAttribute('type')) { |
|
88 | + if ($content->getAttribute('type') == 'xhtml') { |
|
89 | + for ($i = 0; $i < $content->childNodes->length; $i++) { |
|
90 | + $child = $content->childNodes->item($i); |
|
91 | + |
|
92 | + if ($child->hasChildNodes()) { |
|
93 | + return $this->doc->saveHTML($child); |
|
94 | + } |
|
95 | + } |
|
96 | + } |
|
97 | + } |
|
98 | + |
|
99 | + return $this->subtree_or_text($content); |
|
100 | + } |
|
101 | + |
|
102 | + } |
|
103 | + |
|
104 | + public function get_categories() { |
|
105 | + $categories = $this->elem->getElementsByTagName("category"); |
|
106 | + $cats = []; |
|
107 | + |
|
108 | + foreach ($categories as $cat) { |
|
109 | + if ($cat->hasAttribute("term")) |
|
110 | + array_push($cats, $cat->getAttribute("term")); |
|
111 | + } |
|
112 | + |
|
113 | + $categories = $this->xpath->query("dc:subject", $this->elem); |
|
114 | 114 | |
115 | - foreach ($categories as $cat) { |
|
116 | - array_push($cats, $cat->nodeValue); |
|
117 | - } |
|
118 | - |
|
119 | - return $this->normalize_categories($cats); |
|
120 | - } |
|
115 | + foreach ($categories as $cat) { |
|
116 | + array_push($cats, $cat->nodeValue); |
|
117 | + } |
|
118 | + |
|
119 | + return $this->normalize_categories($cats); |
|
120 | + } |
|
121 | 121 | |
122 | - public function get_enclosures() { |
|
123 | - $links = $this->elem->getElementsByTagName("link"); |
|
124 | - |
|
125 | - $encs = array(); |
|
126 | - |
|
127 | - foreach ($links as $link) { |
|
128 | - if ($link && $link->hasAttribute("href") && $link->hasAttribute("rel")) { |
|
129 | - if ($link->getAttribute("rel") == "enclosure") { |
|
130 | - $enc = new FeedEnclosure(); |
|
131 | - |
|
132 | - $enc->type = clean($link->getAttribute("type")); |
|
133 | - $enc->link = clean($link->getAttribute("href")); |
|
134 | - $enc->length = clean($link->getAttribute("length")); |
|
135 | - |
|
136 | - array_push($encs, $enc); |
|
137 | - } |
|
138 | - } |
|
139 | - } |
|
140 | - |
|
141 | - $encs = array_merge($encs, parent::get_enclosures()); |
|
142 | - |
|
143 | - return $encs; |
|
144 | - } |
|
145 | - |
|
146 | - public function get_language() { |
|
147 | - $lang = $this->elem->getAttributeNS(self::NS_XML, "lang"); |
|
148 | - |
|
149 | - if (!empty($lang)) { |
|
150 | - return clean($lang); |
|
151 | - } else { |
|
152 | - // Fall back to the language declared on the feed, if any. |
|
153 | - foreach ($this->doc->childNodes as $child) { |
|
154 | - if (method_exists($child, "getAttributeNS")) { |
|
155 | - return clean($child->getAttributeNS(self::NS_XML, "lang")); |
|
156 | - } |
|
157 | - } |
|
158 | - } |
|
159 | - } |
|
122 | + public function get_enclosures() { |
|
123 | + $links = $this->elem->getElementsByTagName("link"); |
|
124 | + |
|
125 | + $encs = array(); |
|
126 | + |
|
127 | + foreach ($links as $link) { |
|
128 | + if ($link && $link->hasAttribute("href") && $link->hasAttribute("rel")) { |
|
129 | + if ($link->getAttribute("rel") == "enclosure") { |
|
130 | + $enc = new FeedEnclosure(); |
|
131 | + |
|
132 | + $enc->type = clean($link->getAttribute("type")); |
|
133 | + $enc->link = clean($link->getAttribute("href")); |
|
134 | + $enc->length = clean($link->getAttribute("length")); |
|
135 | + |
|
136 | + array_push($encs, $enc); |
|
137 | + } |
|
138 | + } |
|
139 | + } |
|
140 | + |
|
141 | + $encs = array_merge($encs, parent::get_enclosures()); |
|
142 | + |
|
143 | + return $encs; |
|
144 | + } |
|
145 | + |
|
146 | + public function get_language() { |
|
147 | + $lang = $this->elem->getAttributeNS(self::NS_XML, "lang"); |
|
148 | + |
|
149 | + if (!empty($lang)) { |
|
150 | + return clean($lang); |
|
151 | + } else { |
|
152 | + // Fall back to the language declared on the feed, if any. |
|
153 | + foreach ($this->doc->childNodes as $child) { |
|
154 | + if (method_exists($child, "getAttributeNS")) { |
|
155 | + return clean($child->getAttributeNS(self::NS_XML, "lang")); |
|
156 | + } |
|
157 | + } |
|
158 | + } |
|
159 | + } |
|
160 | 160 | } |
@@ -760,24 +760,24 @@ |
||
760 | 760 | $feed_urls = false; |
761 | 761 | |
762 | 762 | switch ($rc['code']) { |
763 | - case 0: |
|
764 | - print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url)); |
|
765 | - break; |
|
766 | - case 1: |
|
767 | - print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url)); |
|
768 | - break; |
|
769 | - case 2: |
|
770 | - print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url)); |
|
771 | - break; |
|
772 | - case 3: |
|
773 | - print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url)); |
|
774 | - break; |
|
775 | - case 4: |
|
776 | - $feed_urls = $rc["feeds"]; |
|
777 | - break; |
|
778 | - case 5: |
|
779 | - print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url)); |
|
780 | - break; |
|
763 | + case 0: |
|
764 | + print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url)); |
|
765 | + break; |
|
766 | + case 1: |
|
767 | + print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url)); |
|
768 | + break; |
|
769 | + case 2: |
|
770 | + print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url)); |
|
771 | + break; |
|
772 | + case 3: |
|
773 | + print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url)); |
|
774 | + break; |
|
775 | + case 4: |
|
776 | + $feed_urls = $rc["feeds"]; |
|
777 | + break; |
|
778 | + case 5: |
|
779 | + print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url)); |
|
780 | + break; |
|
781 | 781 | } |
782 | 782 | |
783 | 783 | if ($feed_urls) { |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | |
8 | 8 | require_once "lib/MiniTemplator.class.php"; |
9 | 9 | |
10 | - $note_style = "background-color : #fff7d5; |
|
10 | + $note_style = "background-color : #fff7d5; |
|
11 | 11 | border-width : 1px; ". |
12 | 12 | "padding : 5px; border-style : dashed; border-color : #e7d796;". |
13 | 13 | "margin-bottom : 1em; color : #9a8c59;"; |
@@ -73,8 +73,8 @@ discard block |
||
73 | 73 | $feed_site_url = $qfh_ret[2]; |
74 | 74 | /* $last_error = $qfh_ret[3]; */ |
75 | 75 | |
76 | - $feed_self_url = get_self_url_prefix() . |
|
77 | - "/public.php?op=rss&id=$feed&key=" . |
|
76 | + $feed_self_url = get_self_url_prefix(). |
|
77 | + "/public.php?op=rss&id=$feed&key=". |
|
78 | 78 | Feeds::get_feed_access_key($feed, false, $owner_uid); |
79 | 79 | |
80 | 80 | if (!$feed_site_url) $feed_site_url = get_self_url_prefix(); |
@@ -102,8 +102,7 @@ discard block |
||
102 | 102 | } |
103 | 103 | |
104 | 104 | $tpl->setVariable('ARTICLE_ID', |
105 | - htmlspecialchars($orig_guid ? $line['link'] : |
|
106 | - $this->make_article_tag_uri($line['id'], $line['date_entered'])), true); |
|
105 | + htmlspecialchars($orig_guid ? $line['link'] : $this->make_article_tag_uri($line['id'], $line['date_entered'])), true); |
|
107 | 106 | $tpl->setVariable('ARTICLE_LINK', htmlspecialchars($line['link']), true); |
108 | 107 | $tpl->setVariable('ARTICLE_TITLE', htmlspecialchars($line['title']), true); |
109 | 108 | $tpl->setVariable('ARTICLE_EXCERPT', $line["content_preview"], true); |
@@ -112,7 +111,7 @@ discard block |
||
112 | 111 | $feed_site_url, false, $line["id"]); |
113 | 112 | |
114 | 113 | if ($line['note']) { |
115 | - $content = "<div style=\"$note_style\">Article note: " . $line['note'] . "</div>" . |
|
114 | + $content = "<div style=\"$note_style\">Article note: ".$line['note']."</div>". |
|
116 | 115 | $content; |
117 | 116 | $tpl->setVariable('ARTICLE_NOTE', htmlspecialchars($line['note']), true); |
118 | 117 | } |
@@ -201,7 +200,7 @@ discard block |
||
201 | 200 | $article = array(); |
202 | 201 | |
203 | 202 | $article['id'] = $line['link']; |
204 | - $article['link'] = $line['link']; |
|
203 | + $article['link'] = $line['link']; |
|
205 | 204 | $article['title'] = $line['title']; |
206 | 205 | $article['excerpt'] = $line["content_preview"]; |
207 | 206 | $article['content'] = sanitize($line["content"], false, $owner_uid, $feed_site_url, false, $line["id"]); |
@@ -277,13 +276,13 @@ discard block |
||
277 | 276 | WHERE ttrss_users.id = ttrss_settings_profiles.owner_uid AND login = ? ORDER BY title"); |
278 | 277 | $sth->execute([$login]); |
279 | 278 | |
280 | - $rv = [ [ "value" => 0, "label" => __("Default profile") ] ]; |
|
279 | + $rv = [["value" => 0, "label" => __("Default profile")]]; |
|
281 | 280 | |
282 | 281 | while ($line = $sth->fetch()) { |
283 | 282 | $id = $line["id"]; |
284 | 283 | $title = $line["title"]; |
285 | 284 | |
286 | - array_push($rv, [ "label" => $title, "value" => $id ]); |
|
285 | + array_push($rv, ["label" => $title, "value" => $id]); |
|
287 | 286 | } |
288 | 287 | } |
289 | 288 | |
@@ -384,7 +383,7 @@ discard block |
||
384 | 383 | list ($og_image, $og_stream) = Article::get_article_image($enclosures, $line['content'], $line["site_url"]); |
385 | 384 | |
386 | 385 | if ($og_image) { |
387 | - $rv .= "<meta property='og:image' content=\"" . htmlspecialchars($og_image) . "\"/>"; |
|
386 | + $rv .= "<meta property='og:image' content=\"".htmlspecialchars($og_image)."\"/>"; |
|
388 | 387 | } |
389 | 388 | |
390 | 389 | $rv .= "<body class='flat ttrss_utility ttrss_zoom'>"; |
@@ -393,9 +392,9 @@ discard block |
||
393 | 392 | if ($line["link"]) { |
394 | 393 | $rv .= "<h1><a target='_blank' rel='noopener noreferrer' |
395 | 394 | title=\"".htmlspecialchars($line['title'])."\" |
396 | - href=\"" .htmlspecialchars($line["link"]) . "\">" . $line["title"] . "</a></h1>"; |
|
395 | + href=\"" .htmlspecialchars($line["link"])."\">".$line["title"]."</a></h1>"; |
|
397 | 396 | } else { |
398 | - $rv .= "<h1>" . $line["title"] . "</h1>"; |
|
397 | + $rv .= "<h1>".$line["title"]."</h1>"; |
|
399 | 398 | } |
400 | 399 | |
401 | 400 | $rv .= "<div class='content post'>"; |
@@ -448,8 +447,8 @@ discard block |
||
448 | 447 | $feed = clean($_REQUEST["id"]); |
449 | 448 | $key = clean($_REQUEST["key"]); |
450 | 449 | $is_cat = clean($_REQUEST["is_cat"]); |
451 | - $limit = (int)clean($_REQUEST["limit"]); |
|
452 | - $offset = (int)clean($_REQUEST["offset"]); |
|
450 | + $limit = (int) clean($_REQUEST["limit"]); |
|
451 | + $offset = (int) clean($_REQUEST["offset"]); |
|
453 | 452 | |
454 | 453 | $search = clean($_REQUEST["q"]); |
455 | 454 | $view_mode = clean($_REQUEST["view-mode"]); |
@@ -692,9 +691,9 @@ discard block |
||
692 | 691 | $return = clean($_REQUEST['return']); |
693 | 692 | |
694 | 693 | if ($_REQUEST['return'] && mb_strpos($return, SELF_URL_PATH) === 0) { |
695 | - header("Location: " . clean($_REQUEST['return'])); |
|
694 | + header("Location: ".clean($_REQUEST['return'])); |
|
696 | 695 | } else { |
697 | - header("Location: " . get_self_url_prefix()); |
|
696 | + header("Location: ".get_self_url_prefix()); |
|
698 | 697 | } |
699 | 698 | } |
700 | 699 | } |
@@ -786,7 +785,7 @@ discard block |
||
786 | 785 | print "<input type='hidden' name='op' value='subscribe'>"; |
787 | 786 | |
788 | 787 | print "<fieldset>"; |
789 | - print "<label style='display : inline'>" . __("Multiple feed URLs found:") . "</label>"; |
|
788 | + print "<label style='display : inline'>".__("Multiple feed URLs found:")."</label>"; |
|
790 | 789 | print "<select name='feed_url' dojoType='dijit.form.Select'>"; |
791 | 790 | |
792 | 791 | foreach ($feed_urls as $url => $name) { |
@@ -805,9 +804,9 @@ discard block |
||
805 | 804 | print "</form>"; |
806 | 805 | } |
807 | 806 | |
808 | - $tp_uri = get_self_url_prefix() . "/prefs.php"; |
|
807 | + $tp_uri = get_self_url_prefix()."/prefs.php"; |
|
809 | 808 | |
810 | - if ($rc['code'] <= 2){ |
|
809 | + if ($rc['code'] <= 2) { |
|
811 | 810 | $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE |
812 | 811 | feed_url = ? AND owner_uid = ?"); |
813 | 812 | $sth->execute([$feed_url, $_SESSION['uid']]); |
@@ -895,7 +894,7 @@ discard block |
||
895 | 894 | list($timestamp, $resetpass_token) = explode(":", $resetpass_token_full); |
896 | 895 | |
897 | 896 | if ($timestamp && $resetpass_token && |
898 | - $timestamp >= time() - 15*60*60 && |
|
897 | + $timestamp >= time() - 15 * 60 * 60 && |
|
899 | 898 | $resetpass_token == $hash) { |
900 | 899 | |
901 | 900 | $sth = $this->pdo->prepare("UPDATE ttrss_users SET resetpass_token = NULL |
@@ -935,8 +934,8 @@ discard block |
||
935 | 934 | <input dojoType='dijit.form.TextBox' type='email' name='email' value='' required> |
936 | 935 | </fieldset>"; |
937 | 936 | |
938 | - $_SESSION["pwdreset:testvalue1"] = rand(1,10); |
|
939 | - $_SESSION["pwdreset:testvalue2"] = rand(1,10); |
|
937 | + $_SESSION["pwdreset:testvalue1"] = rand(1, 10); |
|
938 | + $_SESSION["pwdreset:testvalue2"] = rand(1, 10); |
|
940 | 939 | |
941 | 940 | print "<fieldset> |
942 | 941 | <label>".T_sprintf("How much is %d + %d:", $_SESSION["pwdreset:testvalue1"], $_SESSION["pwdreset:testvalue2"])."</label> |
@@ -981,8 +980,8 @@ discard block |
||
981 | 980 | |
982 | 981 | if ($id) { |
983 | 982 | $resetpass_token = sha1(get_random_bytes(128)); |
984 | - $resetpass_link = get_self_url_prefix() . "/public.php?op=forgotpass&hash=" . $resetpass_token . |
|
985 | - "&login=" . urlencode($login); |
|
983 | + $resetpass_link = get_self_url_prefix()."/public.php?op=forgotpass&hash=".$resetpass_token. |
|
984 | + "&login=".urlencode($login); |
|
986 | 985 | |
987 | 986 | require_once "lib/MiniTemplator.class.php"; |
988 | 987 | |
@@ -1009,7 +1008,7 @@ discard block |
||
1009 | 1008 | |
1010 | 1009 | if (!$rc) print_error($mailer->error()); |
1011 | 1010 | |
1012 | - $resetpass_token_full = time() . ":" . $resetpass_token; |
|
1011 | + $resetpass_token_full = time().":".$resetpass_token; |
|
1013 | 1012 | |
1014 | 1013 | $sth = $this->pdo->prepare("UPDATE ttrss_users |
1015 | 1014 | SET resetpass_token = ? |
@@ -1099,12 +1098,12 @@ discard block |
||
1099 | 1098 | if ($op == "performupdate") { |
1100 | 1099 | if ($updater->isUpdateRequired()) { |
1101 | 1100 | |
1102 | - print "<h2>" . T_sprintf("Performing updates to version %d", SCHEMA_VERSION) . "</h2>"; |
|
1101 | + print "<h2>".T_sprintf("Performing updates to version %d", SCHEMA_VERSION)."</h2>"; |
|
1103 | 1102 | |
1104 | 1103 | for ($i = $updater->getSchemaVersion() + 1; $i <= SCHEMA_VERSION; $i++) { |
1105 | 1104 | print "<ul>"; |
1106 | 1105 | |
1107 | - print "<li class='text-info'>" . T_sprintf("Updating to version %d", $i) . "</li>"; |
|
1106 | + print "<li class='text-info'>".T_sprintf("Updating to version %d", $i)."</li>"; |
|
1108 | 1107 | |
1109 | 1108 | print "<li>"; |
1110 | 1109 | $result = $updater->performUpdateTo($i, true); |
@@ -1123,7 +1122,7 @@ discard block |
||
1123 | 1122 | |
1124 | 1123 | return; |
1125 | 1124 | } else { |
1126 | - print "<li class='text-success'>" . __("Completed.") . "</li>"; |
|
1125 | + print "<li class='text-success'>".__("Completed.")."</li>"; |
|
1127 | 1126 | print "</ul>"; |
1128 | 1127 | } |
1129 | 1128 | } |
@@ -1191,7 +1190,7 @@ discard block |
||
1191 | 1190 | |
1192 | 1191 | $timestamp = date("Y-m-d", strtotime($timestamp)); |
1193 | 1192 | |
1194 | - return "tag:" . parse_url(get_self_url_prefix(), PHP_URL_HOST) . ",$timestamp:/$id"; |
|
1193 | + return "tag:".parse_url(get_self_url_prefix(), PHP_URL_HOST).",$timestamp:/$id"; |
|
1195 | 1194 | } |
1196 | 1195 | |
1197 | 1196 | // this should be used very carefully because this endpoint is exposed to unauthenticated users |
@@ -1,329 +1,329 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | class Handler_Public extends Handler { |
3 | 3 | |
4 | - private function generate_syndicated_feed($owner_uid, $feed, $is_cat, |
|
5 | - $limit, $offset, $search, |
|
6 | - $view_mode = false, $format = 'atom', $order = false, $orig_guid = false, $start_ts = false) { |
|
4 | + private function generate_syndicated_feed($owner_uid, $feed, $is_cat, |
|
5 | + $limit, $offset, $search, |
|
6 | + $view_mode = false, $format = 'atom', $order = false, $orig_guid = false, $start_ts = false) { |
|
7 | 7 | |
8 | - require_once "lib/MiniTemplator.class.php"; |
|
8 | + require_once "lib/MiniTemplator.class.php"; |
|
9 | 9 | |
10 | - $note_style = "background-color : #fff7d5; |
|
10 | + $note_style = "background-color : #fff7d5; |
|
11 | 11 | border-width : 1px; ". |
12 | - "padding : 5px; border-style : dashed; border-color : #e7d796;". |
|
13 | - "margin-bottom : 1em; color : #9a8c59;"; |
|
14 | - |
|
15 | - if (!$limit) $limit = 60; |
|
16 | - |
|
17 | - $date_sort_field = "date_entered DESC, updated DESC"; |
|
18 | - |
|
19 | - if ($feed == -2 && !$is_cat) { |
|
20 | - $date_sort_field = "last_published DESC"; |
|
21 | - } else if ($feed == -1 && !$is_cat) { |
|
22 | - $date_sort_field = "last_marked DESC"; |
|
23 | - } |
|
24 | - |
|
25 | - switch ($order) { |
|
26 | - case "title": |
|
27 | - $date_sort_field = "ttrss_entries.title, date_entered, updated"; |
|
28 | - break; |
|
29 | - case "date_reverse": |
|
30 | - $date_sort_field = "date_entered, updated"; |
|
31 | - break; |
|
32 | - case "feed_dates": |
|
33 | - $date_sort_field = "updated DESC"; |
|
34 | - break; |
|
35 | - } |
|
36 | - |
|
37 | - $params = array( |
|
38 | - "owner_uid" => $owner_uid, |
|
39 | - "feed" => $feed, |
|
40 | - "limit" => $limit, |
|
41 | - "view_mode" => $view_mode, |
|
42 | - "cat_view" => $is_cat, |
|
43 | - "search" => $search, |
|
44 | - "override_order" => $date_sort_field, |
|
45 | - "include_children" => true, |
|
46 | - "ignore_vfeed_group" => true, |
|
47 | - "offset" => $offset, |
|
48 | - "start_ts" => $start_ts |
|
49 | - ); |
|
50 | - |
|
51 | - if (!$is_cat && is_numeric($feed) && $feed < PLUGIN_FEED_BASE_INDEX && $feed > LABEL_BASE_INDEX) { |
|
52 | - |
|
53 | - $user_plugins = get_pref("_ENABLED_PLUGINS", $owner_uid); |
|
54 | - |
|
55 | - $tmppluginhost = new PluginHost(); |
|
56 | - $tmppluginhost->load(PLUGINS, PluginHost::KIND_ALL); |
|
57 | - $tmppluginhost->load($user_plugins, PluginHost::KIND_USER, $owner_uid); |
|
58 | - $tmppluginhost->load_data(); |
|
59 | - |
|
60 | - $handler = $tmppluginhost->get_feed_handler( |
|
61 | - PluginHost::feed_to_pfeed_id($feed)); |
|
62 | - |
|
63 | - if ($handler) { |
|
64 | - $qfh_ret = $handler->get_headlines(PluginHost::feed_to_pfeed_id($feed), $params); |
|
65 | - } |
|
66 | - |
|
67 | - } else { |
|
68 | - $qfh_ret = Feeds::queryFeedHeadlines($params); |
|
69 | - } |
|
70 | - |
|
71 | - $result = $qfh_ret[0]; |
|
72 | - $feed_title = htmlspecialchars($qfh_ret[1]); |
|
73 | - $feed_site_url = $qfh_ret[2]; |
|
74 | - /* $last_error = $qfh_ret[3]; */ |
|
75 | - |
|
76 | - $feed_self_url = get_self_url_prefix() . |
|
77 | - "/public.php?op=rss&id=$feed&key=" . |
|
78 | - Feeds::get_feed_access_key($feed, false, $owner_uid); |
|
79 | - |
|
80 | - if (!$feed_site_url) $feed_site_url = get_self_url_prefix(); |
|
81 | - |
|
82 | - if ($format == 'atom') { |
|
83 | - $tpl = new MiniTemplator; |
|
84 | - |
|
85 | - $tpl->readTemplateFromFile("templates/generated_feed.txt"); |
|
86 | - |
|
87 | - $tpl->setVariable('FEED_TITLE', $feed_title, true); |
|
88 | - $tpl->setVariable('VERSION', get_version(), true); |
|
89 | - $tpl->setVariable('FEED_URL', htmlspecialchars($feed_self_url), true); |
|
90 | - |
|
91 | - $tpl->setVariable('SELF_URL', htmlspecialchars(get_self_url_prefix()), true); |
|
92 | - while ($line = $result->fetch()) { |
|
93 | - |
|
94 | - $line["content_preview"] = sanitize(truncate_string(strip_tags($line["content"]), 100, '...')); |
|
95 | - |
|
96 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) { |
|
97 | - $line = $p->hook_query_headlines($line); |
|
98 | - } |
|
12 | + "padding : 5px; border-style : dashed; border-color : #e7d796;". |
|
13 | + "margin-bottom : 1em; color : #9a8c59;"; |
|
14 | + |
|
15 | + if (!$limit) $limit = 60; |
|
16 | + |
|
17 | + $date_sort_field = "date_entered DESC, updated DESC"; |
|
18 | + |
|
19 | + if ($feed == -2 && !$is_cat) { |
|
20 | + $date_sort_field = "last_published DESC"; |
|
21 | + } else if ($feed == -1 && !$is_cat) { |
|
22 | + $date_sort_field = "last_marked DESC"; |
|
23 | + } |
|
24 | + |
|
25 | + switch ($order) { |
|
26 | + case "title": |
|
27 | + $date_sort_field = "ttrss_entries.title, date_entered, updated"; |
|
28 | + break; |
|
29 | + case "date_reverse": |
|
30 | + $date_sort_field = "date_entered, updated"; |
|
31 | + break; |
|
32 | + case "feed_dates": |
|
33 | + $date_sort_field = "updated DESC"; |
|
34 | + break; |
|
35 | + } |
|
36 | + |
|
37 | + $params = array( |
|
38 | + "owner_uid" => $owner_uid, |
|
39 | + "feed" => $feed, |
|
40 | + "limit" => $limit, |
|
41 | + "view_mode" => $view_mode, |
|
42 | + "cat_view" => $is_cat, |
|
43 | + "search" => $search, |
|
44 | + "override_order" => $date_sort_field, |
|
45 | + "include_children" => true, |
|
46 | + "ignore_vfeed_group" => true, |
|
47 | + "offset" => $offset, |
|
48 | + "start_ts" => $start_ts |
|
49 | + ); |
|
50 | + |
|
51 | + if (!$is_cat && is_numeric($feed) && $feed < PLUGIN_FEED_BASE_INDEX && $feed > LABEL_BASE_INDEX) { |
|
52 | + |
|
53 | + $user_plugins = get_pref("_ENABLED_PLUGINS", $owner_uid); |
|
54 | + |
|
55 | + $tmppluginhost = new PluginHost(); |
|
56 | + $tmppluginhost->load(PLUGINS, PluginHost::KIND_ALL); |
|
57 | + $tmppluginhost->load($user_plugins, PluginHost::KIND_USER, $owner_uid); |
|
58 | + $tmppluginhost->load_data(); |
|
59 | + |
|
60 | + $handler = $tmppluginhost->get_feed_handler( |
|
61 | + PluginHost::feed_to_pfeed_id($feed)); |
|
62 | + |
|
63 | + if ($handler) { |
|
64 | + $qfh_ret = $handler->get_headlines(PluginHost::feed_to_pfeed_id($feed), $params); |
|
65 | + } |
|
99 | 66 | |
100 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_EXPORT_FEED) as $p) { |
|
101 | - $line = $p->hook_article_export_feed($line, $feed, $is_cat); |
|
102 | - } |
|
67 | + } else { |
|
68 | + $qfh_ret = Feeds::queryFeedHeadlines($params); |
|
69 | + } |
|
103 | 70 | |
104 | - $tpl->setVariable('ARTICLE_ID', |
|
105 | - htmlspecialchars($orig_guid ? $line['link'] : |
|
106 | - $this->make_article_tag_uri($line['id'], $line['date_entered'])), true); |
|
107 | - $tpl->setVariable('ARTICLE_LINK', htmlspecialchars($line['link']), true); |
|
108 | - $tpl->setVariable('ARTICLE_TITLE', htmlspecialchars($line['title']), true); |
|
109 | - $tpl->setVariable('ARTICLE_EXCERPT', $line["content_preview"], true); |
|
71 | + $result = $qfh_ret[0]; |
|
72 | + $feed_title = htmlspecialchars($qfh_ret[1]); |
|
73 | + $feed_site_url = $qfh_ret[2]; |
|
74 | + /* $last_error = $qfh_ret[3]; */ |
|
110 | 75 | |
111 | - $content = sanitize($line["content"], false, $owner_uid, |
|
112 | - $feed_site_url, false, $line["id"]); |
|
76 | + $feed_self_url = get_self_url_prefix() . |
|
77 | + "/public.php?op=rss&id=$feed&key=" . |
|
78 | + Feeds::get_feed_access_key($feed, false, $owner_uid); |
|
113 | 79 | |
114 | - if ($line['note']) { |
|
115 | - $content = "<div style=\"$note_style\">Article note: " . $line['note'] . "</div>" . |
|
116 | - $content; |
|
117 | - $tpl->setVariable('ARTICLE_NOTE', htmlspecialchars($line['note']), true); |
|
118 | - } |
|
80 | + if (!$feed_site_url) $feed_site_url = get_self_url_prefix(); |
|
119 | 81 | |
120 | - $tpl->setVariable('ARTICLE_CONTENT', $content, true); |
|
82 | + if ($format == 'atom') { |
|
83 | + $tpl = new MiniTemplator; |
|
121 | 84 | |
122 | - $tpl->setVariable('ARTICLE_UPDATED_ATOM', |
|
123 | - date('c', strtotime($line["updated"])), true); |
|
124 | - $tpl->setVariable('ARTICLE_UPDATED_RFC822', |
|
125 | - date(DATE_RFC822, strtotime($line["updated"])), true); |
|
85 | + $tpl->readTemplateFromFile("templates/generated_feed.txt"); |
|
126 | 86 | |
127 | - $tpl->setVariable('ARTICLE_AUTHOR', htmlspecialchars($line['author']), true); |
|
87 | + $tpl->setVariable('FEED_TITLE', $feed_title, true); |
|
88 | + $tpl->setVariable('VERSION', get_version(), true); |
|
89 | + $tpl->setVariable('FEED_URL', htmlspecialchars($feed_self_url), true); |
|
128 | 90 | |
129 | - $tpl->setVariable('ARTICLE_SOURCE_LINK', htmlspecialchars($line['site_url'] ? $line["site_url"] : get_self_url_prefix()), true); |
|
130 | - $tpl->setVariable('ARTICLE_SOURCE_TITLE', htmlspecialchars($line['feed_title'] ? $line['feed_title'] : $feed_title), true); |
|
91 | + $tpl->setVariable('SELF_URL', htmlspecialchars(get_self_url_prefix()), true); |
|
92 | + while ($line = $result->fetch()) { |
|
131 | 93 | |
132 | - $tags = Article::get_article_tags($line["id"], $owner_uid); |
|
94 | + $line["content_preview"] = sanitize(truncate_string(strip_tags($line["content"]), 100, '...')); |
|
133 | 95 | |
134 | - foreach ($tags as $tag) { |
|
135 | - $tpl->setVariable('ARTICLE_CATEGORY', htmlspecialchars($tag), true); |
|
136 | - $tpl->addBlock('category'); |
|
137 | - } |
|
96 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) { |
|
97 | + $line = $p->hook_query_headlines($line); |
|
98 | + } |
|
138 | 99 | |
139 | - $enclosures = Article::get_article_enclosures($line["id"]); |
|
100 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_EXPORT_FEED) as $p) { |
|
101 | + $line = $p->hook_article_export_feed($line, $feed, $is_cat); |
|
102 | + } |
|
140 | 103 | |
141 | - if (count($enclosures) > 0) { |
|
142 | - foreach ($enclosures as $e) { |
|
143 | - $type = htmlspecialchars($e['content_type']); |
|
144 | - $url = htmlspecialchars($e['content_url']); |
|
145 | - $length = $e['duration'] ? $e['duration'] : 1; |
|
104 | + $tpl->setVariable('ARTICLE_ID', |
|
105 | + htmlspecialchars($orig_guid ? $line['link'] : |
|
106 | + $this->make_article_tag_uri($line['id'], $line['date_entered'])), true); |
|
107 | + $tpl->setVariable('ARTICLE_LINK', htmlspecialchars($line['link']), true); |
|
108 | + $tpl->setVariable('ARTICLE_TITLE', htmlspecialchars($line['title']), true); |
|
109 | + $tpl->setVariable('ARTICLE_EXCERPT', $line["content_preview"], true); |
|
146 | 110 | |
147 | - $tpl->setVariable('ARTICLE_ENCLOSURE_URL', $url, true); |
|
148 | - $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', $type, true); |
|
149 | - $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', $length, true); |
|
111 | + $content = sanitize($line["content"], false, $owner_uid, |
|
112 | + $feed_site_url, false, $line["id"]); |
|
150 | 113 | |
151 | - $tpl->addBlock('enclosure'); |
|
152 | - } |
|
153 | - } else { |
|
154 | - $tpl->setVariable('ARTICLE_ENCLOSURE_URL', null, true); |
|
155 | - $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', null, true); |
|
156 | - $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', null, true); |
|
157 | - } |
|
114 | + if ($line['note']) { |
|
115 | + $content = "<div style=\"$note_style\">Article note: " . $line['note'] . "</div>" . |
|
116 | + $content; |
|
117 | + $tpl->setVariable('ARTICLE_NOTE', htmlspecialchars($line['note']), true); |
|
118 | + } |
|
158 | 119 | |
159 | - list ($og_image, $og_stream) = Article::get_article_image($enclosures, $line['content'], $feed_site_url); |
|
120 | + $tpl->setVariable('ARTICLE_CONTENT', $content, true); |
|
160 | 121 | |
161 | - $tpl->setVariable('ARTICLE_OG_IMAGE', $og_image, true); |
|
122 | + $tpl->setVariable('ARTICLE_UPDATED_ATOM', |
|
123 | + date('c', strtotime($line["updated"])), true); |
|
124 | + $tpl->setVariable('ARTICLE_UPDATED_RFC822', |
|
125 | + date(DATE_RFC822, strtotime($line["updated"])), true); |
|
162 | 126 | |
163 | - $tpl->addBlock('entry'); |
|
164 | - } |
|
127 | + $tpl->setVariable('ARTICLE_AUTHOR', htmlspecialchars($line['author']), true); |
|
165 | 128 | |
166 | - $tmp = ""; |
|
129 | + $tpl->setVariable('ARTICLE_SOURCE_LINK', htmlspecialchars($line['site_url'] ? $line["site_url"] : get_self_url_prefix()), true); |
|
130 | + $tpl->setVariable('ARTICLE_SOURCE_TITLE', htmlspecialchars($line['feed_title'] ? $line['feed_title'] : $feed_title), true); |
|
167 | 131 | |
168 | - $tpl->addBlock('feed'); |
|
169 | - $tpl->generateOutputToString($tmp); |
|
132 | + $tags = Article::get_article_tags($line["id"], $owner_uid); |
|
170 | 133 | |
171 | - if (@!clean($_REQUEST["noxml"])) { |
|
172 | - header("Content-Type: text/xml; charset=utf-8"); |
|
173 | - } else { |
|
174 | - header("Content-Type: text/plain; charset=utf-8"); |
|
175 | - } |
|
134 | + foreach ($tags as $tag) { |
|
135 | + $tpl->setVariable('ARTICLE_CATEGORY', htmlspecialchars($tag), true); |
|
136 | + $tpl->addBlock('category'); |
|
137 | + } |
|
176 | 138 | |
177 | - print $tmp; |
|
178 | - } else if ($format == 'json') { |
|
139 | + $enclosures = Article::get_article_enclosures($line["id"]); |
|
179 | 140 | |
180 | - $feed = array(); |
|
141 | + if (count($enclosures) > 0) { |
|
142 | + foreach ($enclosures as $e) { |
|
143 | + $type = htmlspecialchars($e['content_type']); |
|
144 | + $url = htmlspecialchars($e['content_url']); |
|
145 | + $length = $e['duration'] ? $e['duration'] : 1; |
|
181 | 146 | |
182 | - $feed['title'] = $feed_title; |
|
183 | - $feed['feed_url'] = $feed_self_url; |
|
147 | + $tpl->setVariable('ARTICLE_ENCLOSURE_URL', $url, true); |
|
148 | + $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', $type, true); |
|
149 | + $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', $length, true); |
|
184 | 150 | |
185 | - $feed['self_url'] = get_self_url_prefix(); |
|
151 | + $tpl->addBlock('enclosure'); |
|
152 | + } |
|
153 | + } else { |
|
154 | + $tpl->setVariable('ARTICLE_ENCLOSURE_URL', null, true); |
|
155 | + $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', null, true); |
|
156 | + $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', null, true); |
|
157 | + } |
|
186 | 158 | |
187 | - $feed['articles'] = array(); |
|
159 | + list ($og_image, $og_stream) = Article::get_article_image($enclosures, $line['content'], $feed_site_url); |
|
188 | 160 | |
189 | - while ($line = $result->fetch()) { |
|
161 | + $tpl->setVariable('ARTICLE_OG_IMAGE', $og_image, true); |
|
190 | 162 | |
191 | - $line["content_preview"] = sanitize(truncate_string(strip_tags($line["content_preview"]), 100, '...')); |
|
163 | + $tpl->addBlock('entry'); |
|
164 | + } |
|
192 | 165 | |
193 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) { |
|
194 | - $line = $p->hook_query_headlines($line, 100); |
|
195 | - } |
|
166 | + $tmp = ""; |
|
196 | 167 | |
197 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_EXPORT_FEED) as $p) { |
|
198 | - $line = $p->hook_article_export_feed($line, $feed, $is_cat); |
|
199 | - } |
|
168 | + $tpl->addBlock('feed'); |
|
169 | + $tpl->generateOutputToString($tmp); |
|
200 | 170 | |
201 | - $article = array(); |
|
171 | + if (@!clean($_REQUEST["noxml"])) { |
|
172 | + header("Content-Type: text/xml; charset=utf-8"); |
|
173 | + } else { |
|
174 | + header("Content-Type: text/plain; charset=utf-8"); |
|
175 | + } |
|
202 | 176 | |
203 | - $article['id'] = $line['link']; |
|
204 | - $article['link'] = $line['link']; |
|
205 | - $article['title'] = $line['title']; |
|
206 | - $article['excerpt'] = $line["content_preview"]; |
|
207 | - $article['content'] = sanitize($line["content"], false, $owner_uid, $feed_site_url, false, $line["id"]); |
|
208 | - $article['updated'] = date('c', strtotime($line["updated"])); |
|
177 | + print $tmp; |
|
178 | + } else if ($format == 'json') { |
|
209 | 179 | |
210 | - if ($line['note']) $article['note'] = $line['note']; |
|
211 | - if ($article['author']) $article['author'] = $line['author']; |
|
180 | + $feed = array(); |
|
212 | 181 | |
213 | - $tags = Article::get_article_tags($line["id"], $owner_uid); |
|
182 | + $feed['title'] = $feed_title; |
|
183 | + $feed['feed_url'] = $feed_self_url; |
|
214 | 184 | |
215 | - if (count($tags) > 0) { |
|
216 | - $article['tags'] = array(); |
|
185 | + $feed['self_url'] = get_self_url_prefix(); |
|
217 | 186 | |
218 | - foreach ($tags as $tag) { |
|
219 | - array_push($article['tags'], $tag); |
|
220 | - } |
|
221 | - } |
|
187 | + $feed['articles'] = array(); |
|
222 | 188 | |
223 | - $enclosures = Article::get_article_enclosures($line["id"]); |
|
189 | + while ($line = $result->fetch()) { |
|
224 | 190 | |
225 | - if (count($enclosures) > 0) { |
|
226 | - $article['enclosures'] = array(); |
|
191 | + $line["content_preview"] = sanitize(truncate_string(strip_tags($line["content_preview"]), 100, '...')); |
|
227 | 192 | |
228 | - foreach ($enclosures as $e) { |
|
229 | - $type = $e['content_type']; |
|
230 | - $url = $e['content_url']; |
|
231 | - $length = $e['duration']; |
|
193 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) { |
|
194 | + $line = $p->hook_query_headlines($line, 100); |
|
195 | + } |
|
232 | 196 | |
233 | - array_push($article['enclosures'], array("url" => $url, "type" => $type, "length" => $length)); |
|
234 | - } |
|
235 | - } |
|
197 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_EXPORT_FEED) as $p) { |
|
198 | + $line = $p->hook_article_export_feed($line, $feed, $is_cat); |
|
199 | + } |
|
200 | + |
|
201 | + $article = array(); |
|
202 | + |
|
203 | + $article['id'] = $line['link']; |
|
204 | + $article['link'] = $line['link']; |
|
205 | + $article['title'] = $line['title']; |
|
206 | + $article['excerpt'] = $line["content_preview"]; |
|
207 | + $article['content'] = sanitize($line["content"], false, $owner_uid, $feed_site_url, false, $line["id"]); |
|
208 | + $article['updated'] = date('c', strtotime($line["updated"])); |
|
209 | + |
|
210 | + if ($line['note']) $article['note'] = $line['note']; |
|
211 | + if ($article['author']) $article['author'] = $line['author']; |
|
212 | + |
|
213 | + $tags = Article::get_article_tags($line["id"], $owner_uid); |
|
214 | + |
|
215 | + if (count($tags) > 0) { |
|
216 | + $article['tags'] = array(); |
|
236 | 217 | |
237 | - array_push($feed['articles'], $article); |
|
238 | - } |
|
218 | + foreach ($tags as $tag) { |
|
219 | + array_push($article['tags'], $tag); |
|
220 | + } |
|
221 | + } |
|
222 | + |
|
223 | + $enclosures = Article::get_article_enclosures($line["id"]); |
|
239 | 224 | |
240 | - header("Content-Type: text/json; charset=utf-8"); |
|
241 | - print json_encode($feed); |
|
225 | + if (count($enclosures) > 0) { |
|
226 | + $article['enclosures'] = array(); |
|
242 | 227 | |
243 | - } else { |
|
244 | - header("Content-Type: text/plain; charset=utf-8"); |
|
245 | - print json_encode(array("error" => array("message" => "Unknown format"))); |
|
246 | - } |
|
247 | - } |
|
228 | + foreach ($enclosures as $e) { |
|
229 | + $type = $e['content_type']; |
|
230 | + $url = $e['content_url']; |
|
231 | + $length = $e['duration']; |
|
248 | 232 | |
249 | - public function getUnread() { |
|
250 | - $login = clean($_REQUEST["login"]); |
|
251 | - $fresh = clean($_REQUEST["fresh"]) == "1"; |
|
233 | + array_push($article['enclosures'], array("url" => $url, "type" => $type, "length" => $length)); |
|
234 | + } |
|
235 | + } |
|
236 | + |
|
237 | + array_push($feed['articles'], $article); |
|
238 | + } |
|
252 | 239 | |
253 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_users WHERE login = ?"); |
|
254 | - $sth->execute([$login]); |
|
240 | + header("Content-Type: text/json; charset=utf-8"); |
|
241 | + print json_encode($feed); |
|
255 | 242 | |
256 | - if ($row = $sth->fetch()) { |
|
257 | - $uid = $row["id"]; |
|
243 | + } else { |
|
244 | + header("Content-Type: text/plain; charset=utf-8"); |
|
245 | + print json_encode(array("error" => array("message" => "Unknown format"))); |
|
246 | + } |
|
247 | + } |
|
258 | 248 | |
259 | - print Feeds::getGlobalUnread($uid); |
|
249 | + public function getUnread() { |
|
250 | + $login = clean($_REQUEST["login"]); |
|
251 | + $fresh = clean($_REQUEST["fresh"]) == "1"; |
|
260 | 252 | |
261 | - if ($fresh) { |
|
262 | - print ";"; |
|
263 | - print Feeds::getFeedArticles(-3, false, true, $uid); |
|
264 | - } |
|
253 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_users WHERE login = ?"); |
|
254 | + $sth->execute([$login]); |
|
255 | + |
|
256 | + if ($row = $sth->fetch()) { |
|
257 | + $uid = $row["id"]; |
|
258 | + |
|
259 | + print Feeds::getGlobalUnread($uid); |
|
260 | + |
|
261 | + if ($fresh) { |
|
262 | + print ";"; |
|
263 | + print Feeds::getFeedArticles(-3, false, true, $uid); |
|
264 | + } |
|
265 | 265 | |
266 | - } else { |
|
267 | - print "-1;User not found"; |
|
268 | - } |
|
269 | - } |
|
266 | + } else { |
|
267 | + print "-1;User not found"; |
|
268 | + } |
|
269 | + } |
|
270 | 270 | |
271 | - public function getProfiles() { |
|
272 | - $login = clean($_REQUEST["login"]); |
|
273 | - $rv = []; |
|
271 | + public function getProfiles() { |
|
272 | + $login = clean($_REQUEST["login"]); |
|
273 | + $rv = []; |
|
274 | 274 | |
275 | - if ($login) { |
|
276 | - $sth = $this->pdo->prepare("SELECT ttrss_settings_profiles.* FROM ttrss_settings_profiles,ttrss_users |
|
275 | + if ($login) { |
|
276 | + $sth = $this->pdo->prepare("SELECT ttrss_settings_profiles.* FROM ttrss_settings_profiles,ttrss_users |
|
277 | 277 | WHERE ttrss_users.id = ttrss_settings_profiles.owner_uid AND login = ? ORDER BY title"); |
278 | - $sth->execute([$login]); |
|
278 | + $sth->execute([$login]); |
|
279 | 279 | |
280 | - $rv = [ [ "value" => 0, "label" => __("Default profile") ] ]; |
|
280 | + $rv = [ [ "value" => 0, "label" => __("Default profile") ] ]; |
|
281 | 281 | |
282 | - while ($line = $sth->fetch()) { |
|
283 | - $id = $line["id"]; |
|
284 | - $title = $line["title"]; |
|
282 | + while ($line = $sth->fetch()) { |
|
283 | + $id = $line["id"]; |
|
284 | + $title = $line["title"]; |
|
285 | 285 | |
286 | - array_push($rv, [ "label" => $title, "value" => $id ]); |
|
287 | - } |
|
288 | - } |
|
286 | + array_push($rv, [ "label" => $title, "value" => $id ]); |
|
287 | + } |
|
288 | + } |
|
289 | 289 | |
290 | - print json_encode($rv); |
|
291 | - } |
|
290 | + print json_encode($rv); |
|
291 | + } |
|
292 | 292 | |
293 | - public function logout() { |
|
294 | - logout_user(); |
|
295 | - header("Location: index.php"); |
|
296 | - } |
|
293 | + public function logout() { |
|
294 | + logout_user(); |
|
295 | + header("Location: index.php"); |
|
296 | + } |
|
297 | 297 | |
298 | - public function share() { |
|
299 | - $uuid = clean($_REQUEST["key"]); |
|
298 | + public function share() { |
|
299 | + $uuid = clean($_REQUEST["key"]); |
|
300 | 300 | |
301 | - if ($uuid) { |
|
302 | - $sth = $this->pdo->prepare("SELECT ref_id, owner_uid |
|
301 | + if ($uuid) { |
|
302 | + $sth = $this->pdo->prepare("SELECT ref_id, owner_uid |
|
303 | 303 | FROM ttrss_user_entries WHERE uuid = ?"); |
304 | - $sth->execute([$uuid]); |
|
304 | + $sth->execute([$uuid]); |
|
305 | 305 | |
306 | - if ($row = $sth->fetch()) { |
|
307 | - header("Content-Type: text/html"); |
|
306 | + if ($row = $sth->fetch()) { |
|
307 | + header("Content-Type: text/html"); |
|
308 | 308 | |
309 | - $id = $row["ref_id"]; |
|
310 | - $owner_uid = $row["owner_uid"]; |
|
309 | + $id = $row["ref_id"]; |
|
310 | + $owner_uid = $row["owner_uid"]; |
|
311 | 311 | |
312 | - print $this->format_article($id, $owner_uid); |
|
312 | + print $this->format_article($id, $owner_uid); |
|
313 | 313 | |
314 | - return; |
|
315 | - } |
|
316 | - } |
|
314 | + return; |
|
315 | + } |
|
316 | + } |
|
317 | 317 | |
318 | - header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); |
|
319 | - print "Article not found."; |
|
320 | - } |
|
318 | + header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); |
|
319 | + print "Article not found."; |
|
320 | + } |
|
321 | 321 | |
322 | - private function format_article($id, $owner_uid) { |
|
322 | + private function format_article($id, $owner_uid) { |
|
323 | 323 | |
324 | - $pdo = Db::pdo(); |
|
324 | + $pdo = Db::pdo(); |
|
325 | 325 | |
326 | - $sth = $pdo->prepare("SELECT id,title,link,content,feed_id,comments,int_id,lang, |
|
326 | + $sth = $pdo->prepare("SELECT id,title,link,content,feed_id,comments,int_id,lang, |
|
327 | 327 | ".SUBSTRING_FOR_DATE."(updated,1,16) as updated, |
328 | 328 | (SELECT site_url FROM ttrss_feeds WHERE id = feed_id) as site_url, |
329 | 329 | (SELECT title FROM ttrss_feeds WHERE id = feed_id) as feed_title, |
@@ -337,26 +337,26 @@ discard block |
||
337 | 337 | note |
338 | 338 | FROM ttrss_entries,ttrss_user_entries |
339 | 339 | WHERE id = ? AND ref_id = id AND owner_uid = ?"); |
340 | - $sth->execute([$id, $owner_uid]); |
|
340 | + $sth->execute([$id, $owner_uid]); |
|
341 | 341 | |
342 | - $rv = ''; |
|
342 | + $rv = ''; |
|
343 | 343 | |
344 | - if ($line = $sth->fetch()) { |
|
344 | + if ($line = $sth->fetch()) { |
|
345 | 345 | |
346 | - $line["tags"] = Article::get_article_tags($id, $owner_uid, $line["tag_cache"]); |
|
347 | - unset($line["tag_cache"]); |
|
346 | + $line["tags"] = Article::get_article_tags($id, $owner_uid, $line["tag_cache"]); |
|
347 | + unset($line["tag_cache"]); |
|
348 | 348 | |
349 | - $line["content"] = sanitize($line["content"], |
|
350 | - $line['hide_images'], |
|
351 | - $owner_uid, $line["site_url"], false, $line["id"]); |
|
349 | + $line["content"] = sanitize($line["content"], |
|
350 | + $line['hide_images'], |
|
351 | + $owner_uid, $line["site_url"], false, $line["id"]); |
|
352 | 352 | |
353 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ARTICLE) as $p) { |
|
354 | - $line = $p->hook_render_article($line); |
|
355 | - } |
|
353 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ARTICLE) as $p) { |
|
354 | + $line = $p->hook_render_article($line); |
|
355 | + } |
|
356 | 356 | |
357 | - $line['content'] = DiskCache::rewriteUrls($line['content']); |
|
357 | + $line['content'] = DiskCache::rewriteUrls($line['content']); |
|
358 | 358 | |
359 | - $enclosures = Article::get_article_enclosures($line["id"]); |
|
359 | + $enclosures = Article::get_article_enclosures($line["id"]); |
|
360 | 360 | |
361 | 361 | header("Content-Type: text/html"); |
362 | 362 | |
@@ -371,13 +371,13 @@ discard block |
||
371 | 371 | $rv .= "<meta property='og:title' content=\"".htmlspecialchars(html_entity_decode($line["title"], ENT_NOQUOTES | ENT_HTML401))."\"/>\n"; |
372 | 372 | $rv .= "<meta property='og:description' content=\"". |
373 | 373 | htmlspecialchars( |
374 | - truncate_string( |
|
375 | - preg_replace("/[\r\n\t]/", "", |
|
376 | - preg_replace("/ {1,}/", " ", |
|
377 | - strip_tags(html_entity_decode($line["content"], ENT_NOQUOTES | ENT_HTML401)) |
|
378 | - ) |
|
379 | - ), 500, "...") |
|
380 | - )."\"/>\n"; |
|
374 | + truncate_string( |
|
375 | + preg_replace("/[\r\n\t]/", "", |
|
376 | + preg_replace("/ {1,}/", " ", |
|
377 | + strip_tags(html_entity_decode($line["content"], ENT_NOQUOTES | ENT_HTML401)) |
|
378 | + ) |
|
379 | + ), 500, "...") |
|
380 | + )."\"/>\n"; |
|
381 | 381 | |
382 | 382 | $rv .= "</head>"; |
383 | 383 | |
@@ -390,132 +390,132 @@ discard block |
||
390 | 390 | $rv .= "<body class='flat ttrss_utility ttrss_zoom'>"; |
391 | 391 | $rv .= "<div class='container'>"; |
392 | 392 | |
393 | - if ($line["link"]) { |
|
394 | - $rv .= "<h1><a target='_blank' rel='noopener noreferrer' |
|
393 | + if ($line["link"]) { |
|
394 | + $rv .= "<h1><a target='_blank' rel='noopener noreferrer' |
|
395 | 395 | title=\"".htmlspecialchars($line['title'])."\" |
396 | 396 | href=\"" .htmlspecialchars($line["link"]) . "\">" . $line["title"] . "</a></h1>"; |
397 | - } else { |
|
398 | - $rv .= "<h1>" . $line["title"] . "</h1>"; |
|
399 | - } |
|
397 | + } else { |
|
398 | + $rv .= "<h1>" . $line["title"] . "</h1>"; |
|
399 | + } |
|
400 | 400 | |
401 | - $rv .= "<div class='content post'>"; |
|
401 | + $rv .= "<div class='content post'>"; |
|
402 | 402 | |
403 | - /* header */ |
|
403 | + /* header */ |
|
404 | 404 | |
405 | - $rv .= "<div class='header'>"; |
|
406 | - $rv .= "<div class='row'>"; # row |
|
405 | + $rv .= "<div class='header'>"; |
|
406 | + $rv .= "<div class='row'>"; # row |
|
407 | 407 | |
408 | - //$entry_author = $line["author"] ? " - " . $line["author"] : ""; |
|
409 | - $parsed_updated = make_local_datetime($line["updated"], true, |
|
410 | - $owner_uid, true); |
|
408 | + //$entry_author = $line["author"] ? " - " . $line["author"] : ""; |
|
409 | + $parsed_updated = make_local_datetime($line["updated"], true, |
|
410 | + $owner_uid, true); |
|
411 | 411 | |
412 | - $rv .= "<div>".$line['author']."</div>"; |
|
412 | + $rv .= "<div>".$line['author']."</div>"; |
|
413 | 413 | $rv .= "<div>$parsed_updated</div>"; |
414 | 414 | |
415 | - $rv .= "</div>"; # row |
|
415 | + $rv .= "</div>"; # row |
|
416 | 416 | |
417 | - $rv .= "</div>"; # header |
|
417 | + $rv .= "</div>"; # header |
|
418 | 418 | |
419 | - /* content */ |
|
419 | + /* content */ |
|
420 | 420 | |
421 | - $lang = $line['lang'] ? $line['lang'] : "en"; |
|
422 | - $rv .= "<div class='content' lang='$lang'>"; |
|
421 | + $lang = $line['lang'] ? $line['lang'] : "en"; |
|
422 | + $rv .= "<div class='content' lang='$lang'>"; |
|
423 | 423 | |
424 | - /* content body */ |
|
424 | + /* content body */ |
|
425 | 425 | |
426 | - $rv .= $line["content"]; |
|
426 | + $rv .= $line["content"]; |
|
427 | 427 | |
428 | 428 | $rv .= Article::format_article_enclosures($id, |
429 | 429 | $line["always_display_enclosures"], |
430 | 430 | $line["content"], |
431 | 431 | $line["hide_images"]); |
432 | 432 | |
433 | - $rv .= "</div>"; # content |
|
433 | + $rv .= "</div>"; # content |
|
434 | 434 | |
435 | - $rv .= "</div>"; # post |
|
435 | + $rv .= "</div>"; # post |
|
436 | 436 | |
437 | - } |
|
437 | + } |
|
438 | 438 | |
439 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FORMAT_ARTICLE) as $p) { |
|
440 | - $rv = $p->hook_format_article($rv, $line, true); |
|
441 | - } |
|
439 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FORMAT_ARTICLE) as $p) { |
|
440 | + $rv = $p->hook_format_article($rv, $line, true); |
|
441 | + } |
|
442 | 442 | |
443 | - return $rv; |
|
443 | + return $rv; |
|
444 | 444 | |
445 | - } |
|
445 | + } |
|
446 | 446 | |
447 | - public function rss() { |
|
448 | - $feed = clean($_REQUEST["id"]); |
|
449 | - $key = clean($_REQUEST["key"]); |
|
450 | - $is_cat = clean($_REQUEST["is_cat"]); |
|
451 | - $limit = (int)clean($_REQUEST["limit"]); |
|
452 | - $offset = (int)clean($_REQUEST["offset"]); |
|
447 | + public function rss() { |
|
448 | + $feed = clean($_REQUEST["id"]); |
|
449 | + $key = clean($_REQUEST["key"]); |
|
450 | + $is_cat = clean($_REQUEST["is_cat"]); |
|
451 | + $limit = (int)clean($_REQUEST["limit"]); |
|
452 | + $offset = (int)clean($_REQUEST["offset"]); |
|
453 | 453 | |
454 | - $search = clean($_REQUEST["q"]); |
|
455 | - $view_mode = clean($_REQUEST["view-mode"]); |
|
456 | - $order = clean($_REQUEST["order"]); |
|
457 | - $start_ts = clean($_REQUEST["ts"]); |
|
454 | + $search = clean($_REQUEST["q"]); |
|
455 | + $view_mode = clean($_REQUEST["view-mode"]); |
|
456 | + $order = clean($_REQUEST["order"]); |
|
457 | + $start_ts = clean($_REQUEST["ts"]); |
|
458 | 458 | |
459 | - $format = clean($_REQUEST['format']); |
|
460 | - $orig_guid = clean($_REQUEST["orig_guid"]); |
|
459 | + $format = clean($_REQUEST['format']); |
|
460 | + $orig_guid = clean($_REQUEST["orig_guid"]); |
|
461 | 461 | |
462 | - if (!$format) $format = 'atom'; |
|
462 | + if (!$format) $format = 'atom'; |
|
463 | 463 | |
464 | - if (SINGLE_USER_MODE) { |
|
465 | - authenticate_user("admin", null); |
|
466 | - } |
|
464 | + if (SINGLE_USER_MODE) { |
|
465 | + authenticate_user("admin", null); |
|
466 | + } |
|
467 | 467 | |
468 | - $owner_id = false; |
|
468 | + $owner_id = false; |
|
469 | 469 | |
470 | - if ($key) { |
|
471 | - $sth = $this->pdo->prepare("SELECT owner_uid FROM |
|
470 | + if ($key) { |
|
471 | + $sth = $this->pdo->prepare("SELECT owner_uid FROM |
|
472 | 472 | ttrss_access_keys WHERE access_key = ? AND feed_id = ?"); |
473 | - $sth->execute([$key, $feed]); |
|
473 | + $sth->execute([$key, $feed]); |
|
474 | 474 | |
475 | - if ($row = $sth->fetch()) |
|
476 | - $owner_id = $row["owner_uid"]; |
|
477 | - } |
|
475 | + if ($row = $sth->fetch()) |
|
476 | + $owner_id = $row["owner_uid"]; |
|
477 | + } |
|
478 | 478 | |
479 | - if ($owner_id) { |
|
480 | - $this->generate_syndicated_feed($owner_id, $feed, $is_cat, $limit, |
|
481 | - $offset, $search, $view_mode, $format, $order, $orig_guid, $start_ts); |
|
482 | - } else { |
|
483 | - header('HTTP/1.1 403 Forbidden'); |
|
484 | - } |
|
485 | - } |
|
479 | + if ($owner_id) { |
|
480 | + $this->generate_syndicated_feed($owner_id, $feed, $is_cat, $limit, |
|
481 | + $offset, $search, $view_mode, $format, $order, $orig_guid, $start_ts); |
|
482 | + } else { |
|
483 | + header('HTTP/1.1 403 Forbidden'); |
|
484 | + } |
|
485 | + } |
|
486 | 486 | |
487 | - public function updateTask() { |
|
488 | - PluginHost::getInstance()->run_hooks(PluginHost::HOOK_UPDATE_TASK, "hook_update_task", false); |
|
489 | - } |
|
487 | + public function updateTask() { |
|
488 | + PluginHost::getInstance()->run_hooks(PluginHost::HOOK_UPDATE_TASK, "hook_update_task", false); |
|
489 | + } |
|
490 | 490 | |
491 | - public function housekeepingTask() { |
|
492 | - PluginHost::getInstance()->run_hooks(PluginHost::HOOK_HOUSE_KEEPING, "hook_house_keeping", false); |
|
493 | - } |
|
491 | + public function housekeepingTask() { |
|
492 | + PluginHost::getInstance()->run_hooks(PluginHost::HOOK_HOUSE_KEEPING, "hook_house_keeping", false); |
|
493 | + } |
|
494 | 494 | |
495 | - public function globalUpdateFeeds() { |
|
496 | - RPC::updaterandomfeed_real(); |
|
495 | + public function globalUpdateFeeds() { |
|
496 | + RPC::updaterandomfeed_real(); |
|
497 | 497 | |
498 | - PluginHost::getInstance()->run_hooks(PluginHost::HOOK_UPDATE_TASK, "hook_update_task", false); |
|
499 | - } |
|
498 | + PluginHost::getInstance()->run_hooks(PluginHost::HOOK_UPDATE_TASK, "hook_update_task", false); |
|
499 | + } |
|
500 | 500 | |
501 | - public function sharepopup() { |
|
502 | - if (SINGLE_USER_MODE) { |
|
503 | - login_sequence(); |
|
504 | - } |
|
501 | + public function sharepopup() { |
|
502 | + if (SINGLE_USER_MODE) { |
|
503 | + login_sequence(); |
|
504 | + } |
|
505 | 505 | |
506 | - header('Content-Type: text/html; charset=utf-8'); |
|
507 | - ?> |
|
506 | + header('Content-Type: text/html; charset=utf-8'); |
|
507 | + ?> |
|
508 | 508 | <!DOCTYPE html> |
509 | 509 | <html> |
510 | 510 | <head> |
511 | 511 | <title><?php echo __("Share with Tiny Tiny RSS") ?></title> |
512 | 512 | <?php |
513 | - echo stylesheet_tag("css/default.css"); |
|
514 | - echo javascript_tag("lib/prototype.js"); |
|
515 | - echo javascript_tag("lib/dojo/dojo.js"); |
|
516 | - echo javascript_tag("lib/dojo/tt-rss-layer.js"); |
|
517 | - echo javascript_tag("lib/scriptaculous/scriptaculous.js?load=effects,controls") |
|
518 | - ?> |
|
513 | + echo stylesheet_tag("css/default.css"); |
|
514 | + echo javascript_tag("lib/prototype.js"); |
|
515 | + echo javascript_tag("lib/dojo/dojo.js"); |
|
516 | + echo javascript_tag("lib/dojo/tt-rss-layer.js"); |
|
517 | + echo javascript_tag("lib/scriptaculous/scriptaculous.js?load=effects,controls") |
|
518 | + ?> |
|
519 | 519 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> |
520 | 520 | <link rel="shortcut icon" type="image/png" href="images/favicon.png"> |
521 | 521 | <link rel="icon" type="image/png" sizes="72x72" href="images/favicon-72px.png"> |
@@ -537,29 +537,29 @@ discard block |
||
537 | 537 | |
538 | 538 | <?php |
539 | 539 | |
540 | - $action = clean($_REQUEST["action"]); |
|
540 | + $action = clean($_REQUEST["action"]); |
|
541 | 541 | |
542 | - if ($_SESSION["uid"]) { |
|
542 | + if ($_SESSION["uid"]) { |
|
543 | 543 | |
544 | - if ($action == 'share') { |
|
544 | + if ($action == 'share') { |
|
545 | 545 | |
546 | - $title = strip_tags(clean($_REQUEST["title"])); |
|
547 | - $url = strip_tags(clean($_REQUEST["url"])); |
|
548 | - $content = strip_tags(clean($_REQUEST["content"])); |
|
549 | - $labels = strip_tags(clean($_REQUEST["labels"])); |
|
546 | + $title = strip_tags(clean($_REQUEST["title"])); |
|
547 | + $url = strip_tags(clean($_REQUEST["url"])); |
|
548 | + $content = strip_tags(clean($_REQUEST["content"])); |
|
549 | + $labels = strip_tags(clean($_REQUEST["labels"])); |
|
550 | 550 | |
551 | - Article::create_published_article($title, $url, $content, $labels, |
|
552 | - $_SESSION["uid"]); |
|
551 | + Article::create_published_article($title, $url, $content, $labels, |
|
552 | + $_SESSION["uid"]); |
|
553 | 553 | |
554 | - print "<script type='text/javascript'>"; |
|
555 | - print "window.close();"; |
|
556 | - print "</script>"; |
|
554 | + print "<script type='text/javascript'>"; |
|
555 | + print "window.close();"; |
|
556 | + print "</script>"; |
|
557 | 557 | |
558 | - } else { |
|
559 | - $title = htmlspecialchars(clean($_REQUEST["title"])); |
|
560 | - $url = htmlspecialchars(clean($_REQUEST["url"])); |
|
558 | + } else { |
|
559 | + $title = htmlspecialchars(clean($_REQUEST["title"])); |
|
560 | + $url = htmlspecialchars(clean($_REQUEST["url"])); |
|
561 | 561 | |
562 | - ?> |
|
562 | + ?> |
|
563 | 563 | <form id='share_form' name='share_form'> |
564 | 564 | |
565 | 565 | <input type="hidden" name="op" value="sharepopup"> |
@@ -599,12 +599,12 @@ discard block |
||
599 | 599 | </form> |
600 | 600 | <?php |
601 | 601 | |
602 | - } |
|
602 | + } |
|
603 | 603 | |
604 | - } else { |
|
604 | + } else { |
|
605 | 605 | |
606 | - $return = urlencode(make_self_url()); |
|
607 | - print_error("Not logged in"); ?> |
|
606 | + $return = urlencode(make_self_url()); |
|
607 | + print_error("Not logged in"); ?> |
|
608 | 608 | |
609 | 609 | <form action="public.php?return=<?php echo $return ?>" method="post"> |
610 | 610 | |
@@ -636,90 +636,90 @@ discard block |
||
636 | 636 | |
637 | 637 | </form> |
638 | 638 | <?php |
639 | - } |
|
639 | + } |
|
640 | 640 | |
641 | - print "</div></body></html>"; |
|
642 | - } |
|
641 | + print "</div></body></html>"; |
|
642 | + } |
|
643 | 643 | |
644 | - public function login() { |
|
645 | - if (!SINGLE_USER_MODE) { |
|
644 | + public function login() { |
|
645 | + if (!SINGLE_USER_MODE) { |
|
646 | 646 | |
647 | - $login = clean($_POST["login"]); |
|
648 | - $password = clean($_POST["password"]); |
|
649 | - $remember_me = clean($_POST["remember_me"]); |
|
647 | + $login = clean($_POST["login"]); |
|
648 | + $password = clean($_POST["password"]); |
|
649 | + $remember_me = clean($_POST["remember_me"]); |
|
650 | 650 | |
651 | - if ($remember_me) { |
|
652 | - session_set_cookie_params(SESSION_COOKIE_LIFETIME); |
|
653 | - } else { |
|
654 | - session_set_cookie_params(0); |
|
655 | - } |
|
651 | + if ($remember_me) { |
|
652 | + session_set_cookie_params(SESSION_COOKIE_LIFETIME); |
|
653 | + } else { |
|
654 | + session_set_cookie_params(0); |
|
655 | + } |
|
656 | 656 | |
657 | - if (authenticate_user($login, $password)) { |
|
658 | - $_POST["password"] = ""; |
|
657 | + if (authenticate_user($login, $password)) { |
|
658 | + $_POST["password"] = ""; |
|
659 | 659 | |
660 | - if (get_schema_version() >= 120) { |
|
661 | - $_SESSION["language"] = get_pref("USER_LANGUAGE", $_SESSION["uid"]); |
|
662 | - } |
|
660 | + if (get_schema_version() >= 120) { |
|
661 | + $_SESSION["language"] = get_pref("USER_LANGUAGE", $_SESSION["uid"]); |
|
662 | + } |
|
663 | 663 | |
664 | - $_SESSION["ref_schema_version"] = get_schema_version(true); |
|
665 | - $_SESSION["bw_limit"] = !!clean($_POST["bw_limit"]); |
|
664 | + $_SESSION["ref_schema_version"] = get_schema_version(true); |
|
665 | + $_SESSION["bw_limit"] = !!clean($_POST["bw_limit"]); |
|
666 | 666 | |
667 | - if (clean($_POST["profile"])) { |
|
667 | + if (clean($_POST["profile"])) { |
|
668 | 668 | |
669 | - $profile = (int) clean($_POST["profile"]); |
|
669 | + $profile = (int) clean($_POST["profile"]); |
|
670 | 670 | |
671 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_settings_profiles |
|
671 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_settings_profiles |
|
672 | 672 | WHERE id = ? AND owner_uid = ?"); |
673 | - $sth->execute([$profile, $_SESSION['uid']]); |
|
673 | + $sth->execute([$profile, $_SESSION['uid']]); |
|
674 | 674 | |
675 | - if ($sth->fetch()) { |
|
676 | - $_SESSION["profile"] = $profile; |
|
677 | - } else { |
|
678 | - $_SESSION["profile"] = null; |
|
675 | + if ($sth->fetch()) { |
|
676 | + $_SESSION["profile"] = $profile; |
|
677 | + } else { |
|
678 | + $_SESSION["profile"] = null; |
|
679 | 679 | } |
680 | - } |
|
681 | - } else { |
|
680 | + } |
|
681 | + } else { |
|
682 | 682 | |
683 | - // start an empty session to deliver login error message |
|
684 | - @session_start(); |
|
683 | + // start an empty session to deliver login error message |
|
684 | + @session_start(); |
|
685 | 685 | |
686 | - if (!isset($_SESSION["login_error_msg"])) |
|
687 | - $_SESSION["login_error_msg"] = __("Incorrect username or password"); |
|
686 | + if (!isset($_SESSION["login_error_msg"])) |
|
687 | + $_SESSION["login_error_msg"] = __("Incorrect username or password"); |
|
688 | 688 | |
689 | - user_error("Failed login attempt for $login from {$_SERVER['REMOTE_ADDR']}", E_USER_WARNING); |
|
690 | - } |
|
689 | + user_error("Failed login attempt for $login from {$_SERVER['REMOTE_ADDR']}", E_USER_WARNING); |
|
690 | + } |
|
691 | 691 | |
692 | - $return = clean($_REQUEST['return']); |
|
692 | + $return = clean($_REQUEST['return']); |
|
693 | 693 | |
694 | - if ($_REQUEST['return'] && mb_strpos($return, SELF_URL_PATH) === 0) { |
|
695 | - header("Location: " . clean($_REQUEST['return'])); |
|
696 | - } else { |
|
697 | - header("Location: " . get_self_url_prefix()); |
|
698 | - } |
|
699 | - } |
|
700 | - } |
|
694 | + if ($_REQUEST['return'] && mb_strpos($return, SELF_URL_PATH) === 0) { |
|
695 | + header("Location: " . clean($_REQUEST['return'])); |
|
696 | + } else { |
|
697 | + header("Location: " . get_self_url_prefix()); |
|
698 | + } |
|
699 | + } |
|
700 | + } |
|
701 | 701 | |
702 | - public function subscribe() { |
|
703 | - if (SINGLE_USER_MODE) { |
|
704 | - login_sequence(); |
|
705 | - } |
|
702 | + public function subscribe() { |
|
703 | + if (SINGLE_USER_MODE) { |
|
704 | + login_sequence(); |
|
705 | + } |
|
706 | 706 | |
707 | - if ($_SESSION["uid"]) { |
|
707 | + if ($_SESSION["uid"]) { |
|
708 | 708 | |
709 | - $feed_url = trim(clean($_REQUEST["feed_url"])); |
|
709 | + $feed_url = trim(clean($_REQUEST["feed_url"])); |
|
710 | 710 | |
711 | - header('Content-Type: text/html; charset=utf-8'); |
|
712 | - ?> |
|
711 | + header('Content-Type: text/html; charset=utf-8'); |
|
712 | + ?> |
|
713 | 713 | <!DOCTYPE html> |
714 | 714 | <html> |
715 | 715 | <head> |
716 | 716 | <title>Tiny Tiny RSS</title> |
717 | 717 | <?php |
718 | - echo stylesheet_tag("css/default.css"); |
|
719 | - echo javascript_tag("lib/prototype.js"); |
|
720 | - echo javascript_tag("lib/dojo/dojo.js"); |
|
721 | - echo javascript_tag("lib/dojo/tt-rss-layer.js"); |
|
722 | - ?> |
|
718 | + echo stylesheet_tag("css/default.css"); |
|
719 | + echo javascript_tag("lib/prototype.js"); |
|
720 | + echo javascript_tag("lib/dojo/dojo.js"); |
|
721 | + echo javascript_tag("lib/dojo/tt-rss-layer.js"); |
|
722 | + ?> |
|
723 | 723 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> |
724 | 724 | <link rel="shortcut icon" type="image/png" href="images/favicon.png"> |
725 | 725 | <link rel="icon" type="image/png" sizes="72x72" href="images/favicon-72px.png"> |
@@ -738,8 +738,8 @@ discard block |
||
738 | 738 | <div class='content'> |
739 | 739 | <?php |
740 | 740 | |
741 | - if (!$feed_url) { |
|
742 | - ?> |
|
741 | + if (!$feed_url) { |
|
742 | + ?> |
|
743 | 743 | <form method="post"> |
744 | 744 | <input type="hidden" name="op" value="subscribe"> |
745 | 745 | <fieldset> |
@@ -754,101 +754,101 @@ discard block |
||
754 | 754 | <a href="index.php"><?php echo __("Return to Tiny Tiny RSS") ?></a> |
755 | 755 | </form> |
756 | 756 | <?php |
757 | - } else { |
|
758 | - |
|
759 | - $rc = Feeds::subscribe_to_feed($feed_url); |
|
760 | - $feed_urls = false; |
|
761 | - |
|
762 | - switch ($rc['code']) { |
|
763 | - case 0: |
|
764 | - print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url)); |
|
765 | - break; |
|
766 | - case 1: |
|
767 | - print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url)); |
|
768 | - break; |
|
769 | - case 2: |
|
770 | - print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url)); |
|
771 | - break; |
|
772 | - case 3: |
|
773 | - print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url)); |
|
774 | - break; |
|
775 | - case 4: |
|
776 | - $feed_urls = $rc["feeds"]; |
|
777 | - break; |
|
778 | - case 5: |
|
779 | - print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url)); |
|
780 | - break; |
|
781 | - } |
|
782 | - |
|
783 | - if ($feed_urls) { |
|
784 | - |
|
785 | - print "<form action='public.php'>"; |
|
786 | - print "<input type='hidden' name='op' value='subscribe'>"; |
|
787 | - |
|
788 | - print "<fieldset>"; |
|
789 | - print "<label style='display : inline'>" . __("Multiple feed URLs found:") . "</label>"; |
|
790 | - print "<select name='feed_url' dojoType='dijit.form.Select'>"; |
|
791 | - |
|
792 | - foreach ($feed_urls as $url => $name) { |
|
793 | - $url = htmlspecialchars($url); |
|
794 | - $name = htmlspecialchars($name); |
|
795 | - |
|
796 | - print "<option value=\"$url\">$name</option>"; |
|
797 | - } |
|
757 | + } else { |
|
758 | + |
|
759 | + $rc = Feeds::subscribe_to_feed($feed_url); |
|
760 | + $feed_urls = false; |
|
761 | + |
|
762 | + switch ($rc['code']) { |
|
763 | + case 0: |
|
764 | + print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url)); |
|
765 | + break; |
|
766 | + case 1: |
|
767 | + print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url)); |
|
768 | + break; |
|
769 | + case 2: |
|
770 | + print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url)); |
|
771 | + break; |
|
772 | + case 3: |
|
773 | + print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url)); |
|
774 | + break; |
|
775 | + case 4: |
|
776 | + $feed_urls = $rc["feeds"]; |
|
777 | + break; |
|
778 | + case 5: |
|
779 | + print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url)); |
|
780 | + break; |
|
781 | + } |
|
782 | + |
|
783 | + if ($feed_urls) { |
|
784 | + |
|
785 | + print "<form action='public.php'>"; |
|
786 | + print "<input type='hidden' name='op' value='subscribe'>"; |
|
787 | + |
|
788 | + print "<fieldset>"; |
|
789 | + print "<label style='display : inline'>" . __("Multiple feed URLs found:") . "</label>"; |
|
790 | + print "<select name='feed_url' dojoType='dijit.form.Select'>"; |
|
791 | + |
|
792 | + foreach ($feed_urls as $url => $name) { |
|
793 | + $url = htmlspecialchars($url); |
|
794 | + $name = htmlspecialchars($name); |
|
795 | + |
|
796 | + print "<option value=\"$url\">$name</option>"; |
|
797 | + } |
|
798 | 798 | |
799 | - print "</select>"; |
|
800 | - print "</fieldset>"; |
|
799 | + print "</select>"; |
|
800 | + print "</fieldset>"; |
|
801 | 801 | |
802 | - print "<button class='alt-primary' dojoType='dijit.form.Button' type='submit'>".__("Subscribe to selected feed")."</button>"; |
|
803 | - print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>"; |
|
802 | + print "<button class='alt-primary' dojoType='dijit.form.Button' type='submit'>".__("Subscribe to selected feed")."</button>"; |
|
803 | + print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>"; |
|
804 | 804 | |
805 | - print "</form>"; |
|
806 | - } |
|
805 | + print "</form>"; |
|
806 | + } |
|
807 | 807 | |
808 | - $tp_uri = get_self_url_prefix() . "/prefs.php"; |
|
808 | + $tp_uri = get_self_url_prefix() . "/prefs.php"; |
|
809 | 809 | |
810 | - if ($rc['code'] <= 2){ |
|
811 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE |
|
810 | + if ($rc['code'] <= 2){ |
|
811 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE |
|
812 | 812 | feed_url = ? AND owner_uid = ?"); |
813 | - $sth->execute([$feed_url, $_SESSION['uid']]); |
|
814 | - $row = $sth->fetch(); |
|
813 | + $sth->execute([$feed_url, $_SESSION['uid']]); |
|
814 | + $row = $sth->fetch(); |
|
815 | 815 | |
816 | - $feed_id = $row["id"]; |
|
817 | - } else { |
|
818 | - $feed_id = 0; |
|
819 | - } |
|
816 | + $feed_id = $row["id"]; |
|
817 | + } else { |
|
818 | + $feed_id = 0; |
|
819 | + } |
|
820 | 820 | |
821 | - if ($feed_id) { |
|
822 | - print "<form method='GET' action=\"$tp_uri\"> |
|
821 | + if ($feed_id) { |
|
822 | + print "<form method='GET' action=\"$tp_uri\"> |
|
823 | 823 | <input type='hidden' name='tab' value='feedConfig'> |
824 | 824 | <input type='hidden' name='method' value='editfeed'> |
825 | 825 | <input type='hidden' name='methodparam' value='$feed_id'> |
826 | 826 | <button dojoType='dijit.form.Button' class='alt-info' type='submit'>".__("Edit subscription options")."</button> |
827 | 827 | <a href='index.php'>".__("Return to Tiny Tiny RSS")."</a> |
828 | 828 | </form>"; |
829 | - } |
|
830 | - } |
|
829 | + } |
|
830 | + } |
|
831 | 831 | |
832 | - print "</div></div></body></html>"; |
|
832 | + print "</div></div></body></html>"; |
|
833 | 833 | |
834 | - } else { |
|
835 | - render_login_form(); |
|
836 | - } |
|
837 | - } |
|
834 | + } else { |
|
835 | + render_login_form(); |
|
836 | + } |
|
837 | + } |
|
838 | 838 | |
839 | - public function index() { |
|
840 | - header("Content-Type: text/plain"); |
|
841 | - print error_json(13); |
|
842 | - } |
|
839 | + public function index() { |
|
840 | + header("Content-Type: text/plain"); |
|
841 | + print error_json(13); |
|
842 | + } |
|
843 | 843 | |
844 | - public function forgotpass() { |
|
845 | - startup_gettext(); |
|
846 | - session_start(); |
|
844 | + public function forgotpass() { |
|
845 | + startup_gettext(); |
|
846 | + session_start(); |
|
847 | 847 | |
848 | - @$hash = clean($_REQUEST["hash"]); |
|
848 | + @$hash = clean($_REQUEST["hash"]); |
|
849 | 849 | |
850 | - header('Content-Type: text/html; charset=utf-8'); |
|
851 | - ?> |
|
850 | + header('Content-Type: text/html; charset=utf-8'); |
|
851 | + ?> |
|
852 | 852 | <!DOCTYPE html> |
853 | 853 | <html> |
854 | 854 | <head> |
@@ -857,11 +857,11 @@ discard block |
||
857 | 857 | <link rel="icon" type="image/png" sizes="72x72" href="images/favicon-72px.png"> |
858 | 858 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> |
859 | 859 | <?php |
860 | - echo stylesheet_tag("css/default.css"); |
|
861 | - echo javascript_tag("lib/prototype.js"); |
|
862 | - echo javascript_tag("lib/dojo/dojo.js"); |
|
863 | - echo javascript_tag("lib/dojo/tt-rss-layer.js"); |
|
864 | - ?> |
|
860 | + echo stylesheet_tag("css/default.css"); |
|
861 | + echo javascript_tag("lib/prototype.js"); |
|
862 | + echo javascript_tag("lib/dojo/dojo.js"); |
|
863 | + echo javascript_tag("lib/dojo/tt-rss-layer.js"); |
|
864 | + ?> |
|
865 | 865 | </head> |
866 | 866 | <body class='flat ttrss_utility'> |
867 | 867 | <div class='container'> |
@@ -876,52 +876,52 @@ discard block |
||
876 | 876 | </script> |
877 | 877 | <?php |
878 | 878 | |
879 | - print "<h1>".__("Password recovery")."</h1>"; |
|
880 | - print "<div class='content'>"; |
|
879 | + print "<h1>".__("Password recovery")."</h1>"; |
|
880 | + print "<div class='content'>"; |
|
881 | 881 | |
882 | - @$method = clean($_POST['method']); |
|
882 | + @$method = clean($_POST['method']); |
|
883 | 883 | |
884 | - if ($hash) { |
|
885 | - $login = clean($_REQUEST["login"]); |
|
884 | + if ($hash) { |
|
885 | + $login = clean($_REQUEST["login"]); |
|
886 | 886 | |
887 | - if ($login) { |
|
888 | - $sth = $this->pdo->prepare("SELECT id, resetpass_token FROM ttrss_users |
|
887 | + if ($login) { |
|
888 | + $sth = $this->pdo->prepare("SELECT id, resetpass_token FROM ttrss_users |
|
889 | 889 | WHERE login = ?"); |
890 | - $sth->execute([$login]); |
|
890 | + $sth->execute([$login]); |
|
891 | 891 | |
892 | - if ($row = $sth->fetch()) { |
|
893 | - $id = $row["id"]; |
|
894 | - $resetpass_token_full = $row["resetpass_token"]; |
|
895 | - list($timestamp, $resetpass_token) = explode(":", $resetpass_token_full); |
|
892 | + if ($row = $sth->fetch()) { |
|
893 | + $id = $row["id"]; |
|
894 | + $resetpass_token_full = $row["resetpass_token"]; |
|
895 | + list($timestamp, $resetpass_token) = explode(":", $resetpass_token_full); |
|
896 | 896 | |
897 | - if ($timestamp && $resetpass_token && |
|
898 | - $timestamp >= time() - 15*60*60 && |
|
899 | - $resetpass_token == $hash) { |
|
897 | + if ($timestamp && $resetpass_token && |
|
898 | + $timestamp >= time() - 15*60*60 && |
|
899 | + $resetpass_token == $hash) { |
|
900 | 900 | |
901 | - $sth = $this->pdo->prepare("UPDATE ttrss_users SET resetpass_token = NULL |
|
901 | + $sth = $this->pdo->prepare("UPDATE ttrss_users SET resetpass_token = NULL |
|
902 | 902 | WHERE id = ?"); |
903 | - $sth->execute([$id]); |
|
903 | + $sth->execute([$id]); |
|
904 | 904 | |
905 | - Pref_Users::resetUserPassword($id, true); |
|
905 | + Pref_Users::resetUserPassword($id, true); |
|
906 | 906 | |
907 | - print "<p>"."Completed."."</p>"; |
|
907 | + print "<p>"."Completed."."</p>"; |
|
908 | 908 | |
909 | - } else { |
|
910 | - print_error("Some of the information provided is missing or incorrect."); |
|
911 | - } |
|
912 | - } else { |
|
913 | - print_error("Some of the information provided is missing or incorrect."); |
|
914 | - } |
|
915 | - } else { |
|
916 | - print_error("Some of the information provided is missing or incorrect."); |
|
917 | - } |
|
909 | + } else { |
|
910 | + print_error("Some of the information provided is missing or incorrect."); |
|
911 | + } |
|
912 | + } else { |
|
913 | + print_error("Some of the information provided is missing or incorrect."); |
|
914 | + } |
|
915 | + } else { |
|
916 | + print_error("Some of the information provided is missing or incorrect."); |
|
917 | + } |
|
918 | 918 | |
919 | - print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>"; |
|
919 | + print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>"; |
|
920 | 920 | |
921 | - } else if (!$method) { |
|
922 | - print_notice(__("You will need to provide valid account name and email. Password reset link will be sent to your email address.")); |
|
921 | + } else if (!$method) { |
|
922 | + print_notice(__("You will need to provide valid account name and email. Password reset link will be sent to your email address.")); |
|
923 | 923 | |
924 | - print "<form method='POST' action='public.php'> |
|
924 | + print "<form method='POST' action='public.php'> |
|
925 | 925 | <input type='hidden' name='method' value='do'> |
926 | 926 | <input type='hidden' name='op' value='forgotpass'> |
927 | 927 | |
@@ -935,10 +935,10 @@ discard block |
||
935 | 935 | <input dojoType='dijit.form.TextBox' type='email' name='email' value='' required> |
936 | 936 | </fieldset>"; |
937 | 937 | |
938 | - $_SESSION["pwdreset:testvalue1"] = rand(1,10); |
|
939 | - $_SESSION["pwdreset:testvalue2"] = rand(1,10); |
|
938 | + $_SESSION["pwdreset:testvalue1"] = rand(1,10); |
|
939 | + $_SESSION["pwdreset:testvalue2"] = rand(1,10); |
|
940 | 940 | |
941 | - print "<fieldset> |
|
941 | + print "<fieldset> |
|
942 | 942 | <label>".T_sprintf("How much is %d + %d:", $_SESSION["pwdreset:testvalue1"], $_SESSION["pwdreset:testvalue2"])."</label> |
943 | 943 | <input dojoType='dijit.form.TextBox' type='text' name='test' value='' required> |
944 | 944 | </fieldset> |
@@ -950,109 +950,109 @@ discard block |
||
950 | 950 | </fieldset> |
951 | 951 | |
952 | 952 | </form>"; |
953 | - } else if ($method == 'do') { |
|
953 | + } else if ($method == 'do') { |
|
954 | 954 | |
955 | - $login = clean($_POST["login"]); |
|
956 | - $email = clean($_POST["email"]); |
|
957 | - $test = clean($_POST["test"]); |
|
955 | + $login = clean($_POST["login"]); |
|
956 | + $email = clean($_POST["email"]); |
|
957 | + $test = clean($_POST["test"]); |
|
958 | 958 | |
959 | - if ($test != ($_SESSION["pwdreset:testvalue1"] + $_SESSION["pwdreset:testvalue2"]) || !$email || !$login) { |
|
960 | - print_error(__('Some of the required form parameters are missing or incorrect.')); |
|
959 | + if ($test != ($_SESSION["pwdreset:testvalue1"] + $_SESSION["pwdreset:testvalue2"]) || !$email || !$login) { |
|
960 | + print_error(__('Some of the required form parameters are missing or incorrect.')); |
|
961 | 961 | |
962 | - print "<form method='GET' action='public.php'> |
|
962 | + print "<form method='GET' action='public.php'> |
|
963 | 963 | <input type='hidden' name='op' value='forgotpass'> |
964 | 964 | <button dojoType='dijit.form.Button' type='submit' class='alt-primary'>".__("Go back")."</button> |
965 | 965 | </form>"; |
966 | 966 | |
967 | - } else { |
|
967 | + } else { |
|
968 | 968 | |
969 | - // prevent submitting this form multiple times |
|
970 | - $_SESSION["pwdreset:testvalue1"] = rand(1, 1000); |
|
971 | - $_SESSION["pwdreset:testvalue2"] = rand(1, 1000); |
|
969 | + // prevent submitting this form multiple times |
|
970 | + $_SESSION["pwdreset:testvalue1"] = rand(1, 1000); |
|
971 | + $_SESSION["pwdreset:testvalue2"] = rand(1, 1000); |
|
972 | 972 | |
973 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_users |
|
973 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_users |
|
974 | 974 | WHERE login = ? AND email = ?"); |
975 | - $sth->execute([$login, $email]); |
|
975 | + $sth->execute([$login, $email]); |
|
976 | 976 | |
977 | - if ($row = $sth->fetch()) { |
|
978 | - print_notice("Password reset instructions are being sent to your email address."); |
|
977 | + if ($row = $sth->fetch()) { |
|
978 | + print_notice("Password reset instructions are being sent to your email address."); |
|
979 | 979 | |
980 | - $id = $row["id"]; |
|
980 | + $id = $row["id"]; |
|
981 | 981 | |
982 | - if ($id) { |
|
983 | - $resetpass_token = sha1(get_random_bytes(128)); |
|
984 | - $resetpass_link = get_self_url_prefix() . "/public.php?op=forgotpass&hash=" . $resetpass_token . |
|
985 | - "&login=" . urlencode($login); |
|
982 | + if ($id) { |
|
983 | + $resetpass_token = sha1(get_random_bytes(128)); |
|
984 | + $resetpass_link = get_self_url_prefix() . "/public.php?op=forgotpass&hash=" . $resetpass_token . |
|
985 | + "&login=" . urlencode($login); |
|
986 | 986 | |
987 | - require_once "lib/MiniTemplator.class.php"; |
|
987 | + require_once "lib/MiniTemplator.class.php"; |
|
988 | 988 | |
989 | - $tpl = new MiniTemplator; |
|
989 | + $tpl = new MiniTemplator; |
|
990 | 990 | |
991 | - $tpl->readTemplateFromFile("templates/resetpass_link_template.txt"); |
|
991 | + $tpl->readTemplateFromFile("templates/resetpass_link_template.txt"); |
|
992 | 992 | |
993 | - $tpl->setVariable('LOGIN', $login); |
|
994 | - $tpl->setVariable('RESETPASS_LINK', $resetpass_link); |
|
995 | - $tpl->setVariable('TTRSS_HOST', SELF_URL_PATH); |
|
993 | + $tpl->setVariable('LOGIN', $login); |
|
994 | + $tpl->setVariable('RESETPASS_LINK', $resetpass_link); |
|
995 | + $tpl->setVariable('TTRSS_HOST', SELF_URL_PATH); |
|
996 | 996 | |
997 | - $tpl->addBlock('message'); |
|
997 | + $tpl->addBlock('message'); |
|
998 | 998 | |
999 | - $message = ""; |
|
999 | + $message = ""; |
|
1000 | 1000 | |
1001 | - $tpl->generateOutputToString($message); |
|
1001 | + $tpl->generateOutputToString($message); |
|
1002 | 1002 | |
1003 | - $mailer = new Mailer(); |
|
1003 | + $mailer = new Mailer(); |
|
1004 | 1004 | |
1005 | - $rc = $mailer->mail(["to_name" => $login, |
|
1006 | - "to_address" => $email, |
|
1007 | - "subject" => __("[tt-rss] Password reset request"), |
|
1008 | - "message" => $message]); |
|
1005 | + $rc = $mailer->mail(["to_name" => $login, |
|
1006 | + "to_address" => $email, |
|
1007 | + "subject" => __("[tt-rss] Password reset request"), |
|
1008 | + "message" => $message]); |
|
1009 | 1009 | |
1010 | - if (!$rc) print_error($mailer->error()); |
|
1010 | + if (!$rc) print_error($mailer->error()); |
|
1011 | 1011 | |
1012 | - $resetpass_token_full = time() . ":" . $resetpass_token; |
|
1012 | + $resetpass_token_full = time() . ":" . $resetpass_token; |
|
1013 | 1013 | |
1014 | - $sth = $this->pdo->prepare("UPDATE ttrss_users |
|
1014 | + $sth = $this->pdo->prepare("UPDATE ttrss_users |
|
1015 | 1015 | SET resetpass_token = ? |
1016 | 1016 | WHERE login = ? AND email = ?"); |
1017 | 1017 | |
1018 | - $sth->execute([$resetpass_token_full, $login, $email]); |
|
1018 | + $sth->execute([$resetpass_token_full, $login, $email]); |
|
1019 | 1019 | |
1020 | - } else { |
|
1021 | - print_error("User ID not found."); |
|
1022 | - } |
|
1020 | + } else { |
|
1021 | + print_error("User ID not found."); |
|
1022 | + } |
|
1023 | 1023 | |
1024 | - print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>"; |
|
1024 | + print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>"; |
|
1025 | 1025 | |
1026 | - } else { |
|
1027 | - print_error(__("Sorry, login and email combination not found.")); |
|
1026 | + } else { |
|
1027 | + print_error(__("Sorry, login and email combination not found.")); |
|
1028 | 1028 | |
1029 | - print "<form method='GET' action='public.php'> |
|
1029 | + print "<form method='GET' action='public.php'> |
|
1030 | 1030 | <input type='hidden' name='op' value='forgotpass'> |
1031 | 1031 | <button dojoType='dijit.form.Button' type='submit'>".__("Go back")."</button> |
1032 | 1032 | </form>"; |
1033 | 1033 | |
1034 | - } |
|
1035 | - } |
|
1034 | + } |
|
1035 | + } |
|
1036 | 1036 | |
1037 | - } |
|
1037 | + } |
|
1038 | 1038 | |
1039 | - print "</div>"; |
|
1040 | - print "</div>"; |
|
1041 | - print "</body>"; |
|
1042 | - print "</html>"; |
|
1039 | + print "</div>"; |
|
1040 | + print "</div>"; |
|
1041 | + print "</body>"; |
|
1042 | + print "</html>"; |
|
1043 | 1043 | |
1044 | - } |
|
1044 | + } |
|
1045 | 1045 | |
1046 | - public function dbupdate() { |
|
1047 | - startup_gettext(); |
|
1046 | + public function dbupdate() { |
|
1047 | + startup_gettext(); |
|
1048 | 1048 | |
1049 | - if (!SINGLE_USER_MODE && $_SESSION["access_level"] < 10) { |
|
1050 | - $_SESSION["login_error_msg"] = __("Your access level is insufficient to run this script."); |
|
1051 | - render_login_form(); |
|
1052 | - exit; |
|
1053 | - } |
|
1049 | + if (!SINGLE_USER_MODE && $_SESSION["access_level"] < 10) { |
|
1050 | + $_SESSION["login_error_msg"] = __("Your access level is insufficient to run this script."); |
|
1051 | + render_login_form(); |
|
1052 | + exit; |
|
1053 | + } |
|
1054 | 1054 | |
1055 | - ?> |
|
1055 | + ?> |
|
1056 | 1056 | <!DOCTYPE html> |
1057 | 1057 | <html> |
1058 | 1058 | <head> |
@@ -1062,11 +1062,11 @@ discard block |
||
1062 | 1062 | <link rel="shortcut icon" type="image/png" href="images/favicon.png"> |
1063 | 1063 | <link rel="icon" type="image/png" sizes="72x72" href="images/favicon-72px.png"> |
1064 | 1064 | <?php |
1065 | - echo stylesheet_tag("css/default.css"); |
|
1066 | - echo javascript_tag("lib/prototype.js"); |
|
1067 | - echo javascript_tag("lib/dojo/dojo.js"); |
|
1068 | - echo javascript_tag("lib/dojo/tt-rss-layer.js"); |
|
1069 | - ?> |
|
1065 | + echo stylesheet_tag("css/default.css"); |
|
1066 | + echo javascript_tag("lib/prototype.js"); |
|
1067 | + echo javascript_tag("lib/dojo/dojo.js"); |
|
1068 | + echo javascript_tag("lib/dojo/tt-rss-layer.js"); |
|
1069 | + ?> |
|
1070 | 1070 | <style type="text/css"> |
1071 | 1071 | span.ok { color : #009000; font-weight : bold; } |
1072 | 1072 | span.err { color : #ff0000; font-weight : bold; } |
@@ -1093,139 +1093,139 @@ discard block |
||
1093 | 1093 | <div class="content"> |
1094 | 1094 | |
1095 | 1095 | <?php |
1096 | - @$op = clean($_REQUEST["subop"]); |
|
1097 | - $updater = new DbUpdater(DB_TYPE, SCHEMA_VERSION); |
|
1096 | + @$op = clean($_REQUEST["subop"]); |
|
1097 | + $updater = new DbUpdater(DB_TYPE, SCHEMA_VERSION); |
|
1098 | 1098 | |
1099 | - if ($op == "performupdate") { |
|
1100 | - if ($updater->isUpdateRequired()) { |
|
1099 | + if ($op == "performupdate") { |
|
1100 | + if ($updater->isUpdateRequired()) { |
|
1101 | 1101 | |
1102 | - print "<h2>" . T_sprintf("Performing updates to version %d", SCHEMA_VERSION) . "</h2>"; |
|
1102 | + print "<h2>" . T_sprintf("Performing updates to version %d", SCHEMA_VERSION) . "</h2>"; |
|
1103 | 1103 | |
1104 | - for ($i = $updater->getSchemaVersion() + 1; $i <= SCHEMA_VERSION; $i++) { |
|
1105 | - print "<ul>"; |
|
1104 | + for ($i = $updater->getSchemaVersion() + 1; $i <= SCHEMA_VERSION; $i++) { |
|
1105 | + print "<ul>"; |
|
1106 | 1106 | |
1107 | - print "<li class='text-info'>" . T_sprintf("Updating to version %d", $i) . "</li>"; |
|
1107 | + print "<li class='text-info'>" . T_sprintf("Updating to version %d", $i) . "</li>"; |
|
1108 | 1108 | |
1109 | - print "<li>"; |
|
1110 | - $result = $updater->performUpdateTo($i, true); |
|
1111 | - print "</li>"; |
|
1109 | + print "<li>"; |
|
1110 | + $result = $updater->performUpdateTo($i, true); |
|
1111 | + print "</li>"; |
|
1112 | 1112 | |
1113 | - if (!$result) { |
|
1114 | - print "</ul>"; |
|
1113 | + if (!$result) { |
|
1114 | + print "</ul>"; |
|
1115 | 1115 | |
1116 | - print_error("One of the updates failed. Either retry the process or perform updates manually."); |
|
1116 | + print_error("One of the updates failed. Either retry the process or perform updates manually."); |
|
1117 | 1117 | |
1118 | - print "<form method='POST'> |
|
1118 | + print "<form method='POST'> |
|
1119 | 1119 | <input type='hidden' name='subop' value='performupdate'> |
1120 | 1120 | <button type='submit' dojoType='dijit.form.Button' class='alt-danger' onclick='return confirmOP()'>".__("Try again")."</button> |
1121 | 1121 | <a href='index.php'>".__("Return to Tiny Tiny RSS")."</a> |
1122 | 1122 | </form>"; |
1123 | 1123 | |
1124 | - return; |
|
1125 | - } else { |
|
1126 | - print "<li class='text-success'>" . __("Completed.") . "</li>"; |
|
1127 | - print "</ul>"; |
|
1128 | - } |
|
1129 | - } |
|
1124 | + return; |
|
1125 | + } else { |
|
1126 | + print "<li class='text-success'>" . __("Completed.") . "</li>"; |
|
1127 | + print "</ul>"; |
|
1128 | + } |
|
1129 | + } |
|
1130 | 1130 | |
1131 | - print_notice("Your Tiny Tiny RSS database is now updated to the latest version."); |
|
1131 | + print_notice("Your Tiny Tiny RSS database is now updated to the latest version."); |
|
1132 | 1132 | |
1133 | - print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>"; |
|
1133 | + print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>"; |
|
1134 | 1134 | |
1135 | - } else { |
|
1136 | - print_notice("Tiny Tiny RSS database is up to date."); |
|
1135 | + } else { |
|
1136 | + print_notice("Tiny Tiny RSS database is up to date."); |
|
1137 | 1137 | |
1138 | - print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>"; |
|
1139 | - } |
|
1140 | - } else { |
|
1141 | - if ($updater->isUpdateRequired()) { |
|
1138 | + print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>"; |
|
1139 | + } |
|
1140 | + } else { |
|
1141 | + if ($updater->isUpdateRequired()) { |
|
1142 | 1142 | |
1143 | - print "<h2>".T_sprintf("Tiny Tiny RSS database needs update to the latest version (%d to %d).", |
|
1144 | - $updater->getSchemaVersion(), SCHEMA_VERSION)."</h2>"; |
|
1143 | + print "<h2>".T_sprintf("Tiny Tiny RSS database needs update to the latest version (%d to %d).", |
|
1144 | + $updater->getSchemaVersion(), SCHEMA_VERSION)."</h2>"; |
|
1145 | 1145 | |
1146 | - if (DB_TYPE == "mysql") { |
|
1147 | - print_error("<strong>READ THIS:</strong> Due to MySQL limitations, your database is not completely protected while updating. ". |
|
1148 | - "Errors may put it in an inconsistent state requiring manual rollback. <strong>BACKUP YOUR DATABASE BEFORE CONTINUING.</strong>"); |
|
1149 | - } else { |
|
1150 | - print_warning("Please backup your database before proceeding."); |
|
1151 | - } |
|
1146 | + if (DB_TYPE == "mysql") { |
|
1147 | + print_error("<strong>READ THIS:</strong> Due to MySQL limitations, your database is not completely protected while updating. ". |
|
1148 | + "Errors may put it in an inconsistent state requiring manual rollback. <strong>BACKUP YOUR DATABASE BEFORE CONTINUING.</strong>"); |
|
1149 | + } else { |
|
1150 | + print_warning("Please backup your database before proceeding."); |
|
1151 | + } |
|
1152 | 1152 | |
1153 | - print "<form method='POST'> |
|
1153 | + print "<form method='POST'> |
|
1154 | 1154 | <input type='hidden' name='subop' value='performupdate'> |
1155 | 1155 | <button type='submit' dojoType='dijit.form.Button' class='alt-danger' onclick='return confirmOP()'>".__("Perform updates")."</button> |
1156 | 1156 | </form>"; |
1157 | 1157 | |
1158 | - } else { |
|
1158 | + } else { |
|
1159 | 1159 | |
1160 | - print_notice("Tiny Tiny RSS database is up to date."); |
|
1160 | + print_notice("Tiny Tiny RSS database is up to date."); |
|
1161 | 1161 | |
1162 | - print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>"; |
|
1163 | - } |
|
1164 | - } |
|
1165 | - ?> |
|
1162 | + print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>"; |
|
1163 | + } |
|
1164 | + } |
|
1165 | + ?> |
|
1166 | 1166 | |
1167 | 1167 | </div> |
1168 | 1168 | </div> |
1169 | 1169 | </body> |
1170 | 1170 | </html> |
1171 | 1171 | <?php |
1172 | - } |
|
1173 | - |
|
1174 | - public function cached_url() { |
|
1175 | - list ($cache_dir, $filename) = explode("/", $_GET["file"], 2); |
|
1176 | - |
|
1177 | - // we do not allow files with extensions at the moment |
|
1178 | - $filename = str_replace(".", "", $filename); |
|
1179 | - |
|
1180 | - $cache = new DiskCache($cache_dir); |
|
1181 | - |
|
1182 | - if ($cache->exists($filename)) { |
|
1183 | - $cache->send($filename); |
|
1184 | - } else { |
|
1185 | - header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); |
|
1186 | - echo "File not found."; |
|
1187 | - } |
|
1188 | - } |
|
1189 | - |
|
1190 | - private function make_article_tag_uri($id, $timestamp) { |
|
1191 | - |
|
1192 | - $timestamp = date("Y-m-d", strtotime($timestamp)); |
|
1193 | - |
|
1194 | - return "tag:" . parse_url(get_self_url_prefix(), PHP_URL_HOST) . ",$timestamp:/$id"; |
|
1195 | - } |
|
1196 | - |
|
1197 | - // this should be used very carefully because this endpoint is exposed to unauthenticated users |
|
1198 | - // plugin data is not loaded because there's no user context and owner_uid/session may or may not be available |
|
1199 | - // in general, don't do anything user-related in here and do not modify $_SESSION |
|
1200 | - public function pluginhandler() { |
|
1201 | - $host = new PluginHost(); |
|
1202 | - |
|
1203 | - $plugin_name = clean_filename($_REQUEST["plugin"]); |
|
1204 | - $method = clean($_REQUEST["pmethod"]); |
|
1205 | - |
|
1206 | - $host->load($plugin_name, PluginHost::KIND_USER, 0); |
|
1207 | - $host->load_data(); |
|
1208 | - |
|
1209 | - $plugin = $host->get_plugin($plugin_name); |
|
1210 | - |
|
1211 | - if ($plugin) { |
|
1212 | - if (method_exists($plugin, $method)) { |
|
1213 | - if ($plugin->is_public_method($method)) { |
|
1214 | - $plugin->$method(); |
|
1215 | - } else { |
|
1216 | - user_error("PluginHandler[PUBLIC]: Requested private method '$method' of plugin '$plugin_name'.", E_USER_WARNING); |
|
1217 | - header("Content-Type: text/json"); |
|
1218 | - print error_json(6); |
|
1219 | - } |
|
1220 | - } else { |
|
1221 | - user_error("PluginHandler[PUBLIC]: Requested unknown method '$method' of plugin '$plugin_name'.", E_USER_WARNING); |
|
1222 | - header("Content-Type: text/json"); |
|
1223 | - print error_json(13); |
|
1224 | - } |
|
1225 | - } else { |
|
1226 | - user_error("PluginHandler[PUBLIC]: Requested method '$method' of unknown plugin '$plugin_name'.", E_USER_WARNING); |
|
1227 | - header("Content-Type: text/json"); |
|
1228 | - print error_json(14); |
|
1229 | - } |
|
1230 | - } |
|
1172 | + } |
|
1173 | + |
|
1174 | + public function cached_url() { |
|
1175 | + list ($cache_dir, $filename) = explode("/", $_GET["file"], 2); |
|
1176 | + |
|
1177 | + // we do not allow files with extensions at the moment |
|
1178 | + $filename = str_replace(".", "", $filename); |
|
1179 | + |
|
1180 | + $cache = new DiskCache($cache_dir); |
|
1181 | + |
|
1182 | + if ($cache->exists($filename)) { |
|
1183 | + $cache->send($filename); |
|
1184 | + } else { |
|
1185 | + header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); |
|
1186 | + echo "File not found."; |
|
1187 | + } |
|
1188 | + } |
|
1189 | + |
|
1190 | + private function make_article_tag_uri($id, $timestamp) { |
|
1191 | + |
|
1192 | + $timestamp = date("Y-m-d", strtotime($timestamp)); |
|
1193 | + |
|
1194 | + return "tag:" . parse_url(get_self_url_prefix(), PHP_URL_HOST) . ",$timestamp:/$id"; |
|
1195 | + } |
|
1196 | + |
|
1197 | + // this should be used very carefully because this endpoint is exposed to unauthenticated users |
|
1198 | + // plugin data is not loaded because there's no user context and owner_uid/session may or may not be available |
|
1199 | + // in general, don't do anything user-related in here and do not modify $_SESSION |
|
1200 | + public function pluginhandler() { |
|
1201 | + $host = new PluginHost(); |
|
1202 | + |
|
1203 | + $plugin_name = clean_filename($_REQUEST["plugin"]); |
|
1204 | + $method = clean($_REQUEST["pmethod"]); |
|
1205 | + |
|
1206 | + $host->load($plugin_name, PluginHost::KIND_USER, 0); |
|
1207 | + $host->load_data(); |
|
1208 | + |
|
1209 | + $plugin = $host->get_plugin($plugin_name); |
|
1210 | + |
|
1211 | + if ($plugin) { |
|
1212 | + if (method_exists($plugin, $method)) { |
|
1213 | + if ($plugin->is_public_method($method)) { |
|
1214 | + $plugin->$method(); |
|
1215 | + } else { |
|
1216 | + user_error("PluginHandler[PUBLIC]: Requested private method '$method' of plugin '$plugin_name'.", E_USER_WARNING); |
|
1217 | + header("Content-Type: text/json"); |
|
1218 | + print error_json(6); |
|
1219 | + } |
|
1220 | + } else { |
|
1221 | + user_error("PluginHandler[PUBLIC]: Requested unknown method '$method' of plugin '$plugin_name'.", E_USER_WARNING); |
|
1222 | + header("Content-Type: text/json"); |
|
1223 | + print error_json(13); |
|
1224 | + } |
|
1225 | + } else { |
|
1226 | + user_error("PluginHandler[PUBLIC]: Requested method '$method' of unknown plugin '$plugin_name'.", E_USER_WARNING); |
|
1227 | + header("Content-Type: text/json"); |
|
1228 | + print error_json(14); |
|
1229 | + } |
|
1230 | + } |
|
1231 | 1231 | } |
@@ -12,7 +12,9 @@ discard block |
||
12 | 12 | "padding : 5px; border-style : dashed; border-color : #e7d796;". |
13 | 13 | "margin-bottom : 1em; color : #9a8c59;"; |
14 | 14 | |
15 | - if (!$limit) $limit = 60; |
|
15 | + if (!$limit) { |
|
16 | + $limit = 60; |
|
17 | + } |
|
16 | 18 | |
17 | 19 | $date_sort_field = "date_entered DESC, updated DESC"; |
18 | 20 | |
@@ -77,7 +79,9 @@ discard block |
||
77 | 79 | "/public.php?op=rss&id=$feed&key=" . |
78 | 80 | Feeds::get_feed_access_key($feed, false, $owner_uid); |
79 | 81 | |
80 | - if (!$feed_site_url) $feed_site_url = get_self_url_prefix(); |
|
82 | + if (!$feed_site_url) { |
|
83 | + $feed_site_url = get_self_url_prefix(); |
|
84 | + } |
|
81 | 85 | |
82 | 86 | if ($format == 'atom') { |
83 | 87 | $tpl = new MiniTemplator; |
@@ -207,8 +211,12 @@ discard block |
||
207 | 211 | $article['content'] = sanitize($line["content"], false, $owner_uid, $feed_site_url, false, $line["id"]); |
208 | 212 | $article['updated'] = date('c', strtotime($line["updated"])); |
209 | 213 | |
210 | - if ($line['note']) $article['note'] = $line['note']; |
|
211 | - if ($article['author']) $article['author'] = $line['author']; |
|
214 | + if ($line['note']) { |
|
215 | + $article['note'] = $line['note']; |
|
216 | + } |
|
217 | + if ($article['author']) { |
|
218 | + $article['author'] = $line['author']; |
|
219 | + } |
|
212 | 220 | |
213 | 221 | $tags = Article::get_article_tags($line["id"], $owner_uid); |
214 | 222 | |
@@ -459,7 +467,9 @@ discard block |
||
459 | 467 | $format = clean($_REQUEST['format']); |
460 | 468 | $orig_guid = clean($_REQUEST["orig_guid"]); |
461 | 469 | |
462 | - if (!$format) $format = 'atom'; |
|
470 | + if (!$format) { |
|
471 | + $format = 'atom'; |
|
472 | + } |
|
463 | 473 | |
464 | 474 | if (SINGLE_USER_MODE) { |
465 | 475 | authenticate_user("admin", null); |
@@ -472,8 +482,9 @@ discard block |
||
472 | 482 | ttrss_access_keys WHERE access_key = ? AND feed_id = ?"); |
473 | 483 | $sth->execute([$key, $feed]); |
474 | 484 | |
475 | - if ($row = $sth->fetch()) |
|
476 | - $owner_id = $row["owner_uid"]; |
|
485 | + if ($row = $sth->fetch()) { |
|
486 | + $owner_id = $row["owner_uid"]; |
|
487 | + } |
|
477 | 488 | } |
478 | 489 | |
479 | 490 | if ($owner_id) { |
@@ -683,8 +694,9 @@ discard block |
||
683 | 694 | // start an empty session to deliver login error message |
684 | 695 | @session_start(); |
685 | 696 | |
686 | - if (!isset($_SESSION["login_error_msg"])) |
|
687 | - $_SESSION["login_error_msg"] = __("Incorrect username or password"); |
|
697 | + if (!isset($_SESSION["login_error_msg"])) { |
|
698 | + $_SESSION["login_error_msg"] = __("Incorrect username or password"); |
|
699 | + } |
|
688 | 700 | |
689 | 701 | user_error("Failed login attempt for $login from {$_SERVER['REMOTE_ADDR']}", E_USER_WARNING); |
690 | 702 | } |
@@ -1007,7 +1019,9 @@ discard block |
||
1007 | 1019 | "subject" => __("[tt-rss] Password reset request"), |
1008 | 1020 | "message" => $message]); |
1009 | 1021 | |
1010 | - if (!$rc) print_error($mailer->error()); |
|
1022 | + if (!$rc) { |
|
1023 | + print_error($mailer->error()); |
|
1024 | + } |
|
1011 | 1025 | |
1012 | 1026 | $resetpass_token_full = time() . ":" . $resetpass_token; |
1013 | 1027 |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | if ($error) { |
27 | 27 | foreach (libxml_get_errors() as $error) { |
28 | 28 | if ($error->level == LIBXML_ERR_FATAL) { |
29 | - if(!isset($this->error)) //currently only the first error is reported |
|
29 | + if (!isset($this->error)) //currently only the first error is reported |
|
30 | 30 | $this->error = $this->format_error($error); |
31 | 31 | $this->libxml_errors [] = $this->format_error($error); |
32 | 32 | } |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | $this->type = $this::FEED_ATOM; |
70 | 70 | break; |
71 | 71 | default: |
72 | - if( !isset($this->error) ){ |
|
72 | + if (!isset($this->error)) { |
|
73 | 73 | $this->error = "Unknown/unsupported feed type"; |
74 | 74 | } |
75 | 75 | return; |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | if ($this->link) $this->link = trim($this->link); |
167 | 167 | |
168 | 168 | } else { |
169 | - if( !isset($this->error) ){ |
|
169 | + if (!isset($this->error)) { |
|
170 | 170 | $this->error = "Unknown/unsupported feed type"; |
171 | 171 | } |
172 | 172 | return; |
@@ -1,233 +1,233 @@ |
||
1 | 1 | <?php |
2 | 2 | class FeedParser { |
3 | - private $doc; |
|
4 | - private $error; |
|
5 | - private $libxml_errors = array(); |
|
6 | - private $items; |
|
7 | - private $link; |
|
8 | - private $title; |
|
9 | - private $type; |
|
10 | - private $xpath; |
|
11 | - |
|
12 | - const FEED_RDF = 0; |
|
13 | - const FEED_RSS = 1; |
|
14 | - const FEED_ATOM = 2; |
|
15 | - |
|
16 | - public function __construct($data) { |
|
17 | - libxml_use_internal_errors(true); |
|
18 | - libxml_clear_errors(); |
|
19 | - $this->doc = new DOMDocument(); |
|
20 | - $this->doc->loadXML($data); |
|
21 | - |
|
22 | - mb_substitute_character("none"); |
|
23 | - |
|
24 | - $error = libxml_get_last_error(); |
|
25 | - |
|
26 | - if ($error) { |
|
27 | - foreach (libxml_get_errors() as $error) { |
|
28 | - if ($error->level == LIBXML_ERR_FATAL) { |
|
29 | - if(!isset($this->error)) //currently only the first error is reported |
|
30 | - $this->error = $this->format_error($error); |
|
31 | - $this->libxml_errors [] = $this->format_error($error); |
|
32 | - } |
|
33 | - } |
|
34 | - } |
|
35 | - libxml_clear_errors(); |
|
36 | - |
|
37 | - $this->items = array(); |
|
38 | - } |
|
39 | - |
|
40 | - public function init() { |
|
41 | - $xpath = new DOMXPath($this->doc); |
|
42 | - $xpath->registerNamespace('atom', 'http://www.w3.org/2005/Atom'); |
|
43 | - $xpath->registerNamespace('atom03', 'http://purl.org/atom/ns#'); |
|
44 | - $xpath->registerNamespace('media', 'http://search.yahoo.com/mrss/'); |
|
45 | - $xpath->registerNamespace('rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'); |
|
46 | - $xpath->registerNamespace('slash', 'http://purl.org/rss/1.0/modules/slash/'); |
|
47 | - $xpath->registerNamespace('dc', 'http://purl.org/dc/elements/1.1/'); |
|
48 | - $xpath->registerNamespace('content', 'http://purl.org/rss/1.0/modules/content/'); |
|
49 | - $xpath->registerNamespace('thread', 'http://purl.org/syndication/thread/1.0'); |
|
50 | - |
|
51 | - $this->xpath = $xpath; |
|
52 | - |
|
53 | - $root = $xpath->query("(//atom03:feed|//atom:feed|//channel|//rdf:rdf|//rdf:RDF)"); |
|
54 | - |
|
55 | - if ($root && $root->length > 0) { |
|
56 | - $root = $root->item(0); |
|
57 | - |
|
58 | - if ($root) { |
|
59 | - switch (mb_strtolower($root->tagName)) { |
|
60 | - case "rdf:rdf": |
|
61 | - $this->type = $this::FEED_RDF; |
|
62 | - break; |
|
63 | - case "channel": |
|
64 | - $this->type = $this::FEED_RSS; |
|
65 | - break; |
|
66 | - case "feed": |
|
67 | - case "atom:feed": |
|
68 | - $this->type = $this::FEED_ATOM; |
|
69 | - break; |
|
70 | - default: |
|
71 | - if( !isset($this->error) ){ |
|
72 | - $this->error = "Unknown/unsupported feed type"; |
|
73 | - } |
|
74 | - return; |
|
75 | - } |
|
76 | - } |
|
77 | - |
|
78 | - switch ($this->type) { |
|
79 | - case $this::FEED_ATOM: |
|
80 | - |
|
81 | - $title = $xpath->query("//atom:feed/atom:title")->item(0); |
|
82 | - |
|
83 | - if (!$title) |
|
84 | - $title = $xpath->query("//atom03:feed/atom03:title")->item(0); |
|
85 | - |
|
86 | - |
|
87 | - if ($title) { |
|
88 | - $this->title = $title->nodeValue; |
|
89 | - } |
|
90 | - |
|
91 | - $link = $xpath->query("//atom:feed/atom:link[not(@rel)]")->item(0); |
|
92 | - |
|
93 | - if (!$link) |
|
94 | - $link = $xpath->query("//atom:feed/atom:link[@rel='alternate']")->item(0); |
|
95 | - |
|
96 | - if (!$link) |
|
97 | - $link = $xpath->query("//atom03:feed/atom03:link[not(@rel)]")->item(0); |
|
98 | - |
|
99 | - if (!$link) |
|
100 | - $link = $xpath->query("//atom03:feed/atom03:link[@rel='alternate']")->item(0); |
|
101 | - |
|
102 | - if ($link && $link->hasAttributes()) { |
|
103 | - $this->link = $link->getAttribute("href"); |
|
104 | - } |
|
105 | - |
|
106 | - $articles = $xpath->query("//atom:entry"); |
|
107 | - |
|
108 | - if (!$articles || $articles->length == 0) |
|
109 | - $articles = $xpath->query("//atom03:entry"); |
|
110 | - |
|
111 | - foreach ($articles as $article) { |
|
112 | - array_push($this->items, new FeedItem_Atom($article, $this->doc, $this->xpath)); |
|
113 | - } |
|
114 | - |
|
115 | - break; |
|
116 | - case $this::FEED_RSS: |
|
117 | - $title = $xpath->query("//channel/title")->item(0); |
|
118 | - |
|
119 | - if ($title) { |
|
120 | - $this->title = $title->nodeValue; |
|
121 | - } |
|
122 | - |
|
123 | - $link = $xpath->query("//channel/link")->item(0); |
|
124 | - |
|
125 | - if ($link) { |
|
126 | - if ($link->getAttribute("href")) |
|
127 | - $this->link = $link->getAttribute("href"); |
|
128 | - else if ($link->nodeValue) |
|
129 | - $this->link = $link->nodeValue; |
|
130 | - } |
|
131 | - |
|
132 | - $articles = $xpath->query("//channel/item"); |
|
133 | - |
|
134 | - foreach ($articles as $article) { |
|
135 | - array_push($this->items, new FeedItem_RSS($article, $this->doc, $this->xpath)); |
|
136 | - } |
|
137 | - |
|
138 | - break; |
|
139 | - case $this::FEED_RDF: |
|
140 | - $xpath->registerNamespace('rssfake', 'http://purl.org/rss/1.0/'); |
|
141 | - |
|
142 | - $title = $xpath->query("//rssfake:channel/rssfake:title")->item(0); |
|
143 | - |
|
144 | - if ($title) { |
|
145 | - $this->title = $title->nodeValue; |
|
146 | - } |
|
147 | - |
|
148 | - $link = $xpath->query("//rssfake:channel/rssfake:link")->item(0); |
|
149 | - |
|
150 | - if ($link) { |
|
151 | - $this->link = $link->nodeValue; |
|
152 | - } |
|
153 | - |
|
154 | - $articles = $xpath->query("//rssfake:item"); |
|
155 | - |
|
156 | - foreach ($articles as $article) { |
|
157 | - array_push($this->items, new FeedItem_RSS($article, $this->doc, $this->xpath)); |
|
158 | - } |
|
159 | - |
|
160 | - break; |
|
161 | - |
|
162 | - } |
|
163 | - |
|
164 | - if ($this->title) $this->title = trim($this->title); |
|
165 | - if ($this->link) $this->link = trim($this->link); |
|
3 | + private $doc; |
|
4 | + private $error; |
|
5 | + private $libxml_errors = array(); |
|
6 | + private $items; |
|
7 | + private $link; |
|
8 | + private $title; |
|
9 | + private $type; |
|
10 | + private $xpath; |
|
11 | + |
|
12 | + const FEED_RDF = 0; |
|
13 | + const FEED_RSS = 1; |
|
14 | + const FEED_ATOM = 2; |
|
15 | + |
|
16 | + public function __construct($data) { |
|
17 | + libxml_use_internal_errors(true); |
|
18 | + libxml_clear_errors(); |
|
19 | + $this->doc = new DOMDocument(); |
|
20 | + $this->doc->loadXML($data); |
|
21 | + |
|
22 | + mb_substitute_character("none"); |
|
23 | + |
|
24 | + $error = libxml_get_last_error(); |
|
25 | + |
|
26 | + if ($error) { |
|
27 | + foreach (libxml_get_errors() as $error) { |
|
28 | + if ($error->level == LIBXML_ERR_FATAL) { |
|
29 | + if(!isset($this->error)) //currently only the first error is reported |
|
30 | + $this->error = $this->format_error($error); |
|
31 | + $this->libxml_errors [] = $this->format_error($error); |
|
32 | + } |
|
33 | + } |
|
34 | + } |
|
35 | + libxml_clear_errors(); |
|
36 | + |
|
37 | + $this->items = array(); |
|
38 | + } |
|
39 | + |
|
40 | + public function init() { |
|
41 | + $xpath = new DOMXPath($this->doc); |
|
42 | + $xpath->registerNamespace('atom', 'http://www.w3.org/2005/Atom'); |
|
43 | + $xpath->registerNamespace('atom03', 'http://purl.org/atom/ns#'); |
|
44 | + $xpath->registerNamespace('media', 'http://search.yahoo.com/mrss/'); |
|
45 | + $xpath->registerNamespace('rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'); |
|
46 | + $xpath->registerNamespace('slash', 'http://purl.org/rss/1.0/modules/slash/'); |
|
47 | + $xpath->registerNamespace('dc', 'http://purl.org/dc/elements/1.1/'); |
|
48 | + $xpath->registerNamespace('content', 'http://purl.org/rss/1.0/modules/content/'); |
|
49 | + $xpath->registerNamespace('thread', 'http://purl.org/syndication/thread/1.0'); |
|
50 | + |
|
51 | + $this->xpath = $xpath; |
|
52 | + |
|
53 | + $root = $xpath->query("(//atom03:feed|//atom:feed|//channel|//rdf:rdf|//rdf:RDF)"); |
|
54 | + |
|
55 | + if ($root && $root->length > 0) { |
|
56 | + $root = $root->item(0); |
|
57 | + |
|
58 | + if ($root) { |
|
59 | + switch (mb_strtolower($root->tagName)) { |
|
60 | + case "rdf:rdf": |
|
61 | + $this->type = $this::FEED_RDF; |
|
62 | + break; |
|
63 | + case "channel": |
|
64 | + $this->type = $this::FEED_RSS; |
|
65 | + break; |
|
66 | + case "feed": |
|
67 | + case "atom:feed": |
|
68 | + $this->type = $this::FEED_ATOM; |
|
69 | + break; |
|
70 | + default: |
|
71 | + if( !isset($this->error) ){ |
|
72 | + $this->error = "Unknown/unsupported feed type"; |
|
73 | + } |
|
74 | + return; |
|
75 | + } |
|
76 | + } |
|
77 | + |
|
78 | + switch ($this->type) { |
|
79 | + case $this::FEED_ATOM: |
|
80 | + |
|
81 | + $title = $xpath->query("//atom:feed/atom:title")->item(0); |
|
82 | + |
|
83 | + if (!$title) |
|
84 | + $title = $xpath->query("//atom03:feed/atom03:title")->item(0); |
|
85 | + |
|
86 | + |
|
87 | + if ($title) { |
|
88 | + $this->title = $title->nodeValue; |
|
89 | + } |
|
90 | + |
|
91 | + $link = $xpath->query("//atom:feed/atom:link[not(@rel)]")->item(0); |
|
92 | + |
|
93 | + if (!$link) |
|
94 | + $link = $xpath->query("//atom:feed/atom:link[@rel='alternate']")->item(0); |
|
95 | + |
|
96 | + if (!$link) |
|
97 | + $link = $xpath->query("//atom03:feed/atom03:link[not(@rel)]")->item(0); |
|
98 | + |
|
99 | + if (!$link) |
|
100 | + $link = $xpath->query("//atom03:feed/atom03:link[@rel='alternate']")->item(0); |
|
101 | + |
|
102 | + if ($link && $link->hasAttributes()) { |
|
103 | + $this->link = $link->getAttribute("href"); |
|
104 | + } |
|
105 | + |
|
106 | + $articles = $xpath->query("//atom:entry"); |
|
107 | + |
|
108 | + if (!$articles || $articles->length == 0) |
|
109 | + $articles = $xpath->query("//atom03:entry"); |
|
110 | + |
|
111 | + foreach ($articles as $article) { |
|
112 | + array_push($this->items, new FeedItem_Atom($article, $this->doc, $this->xpath)); |
|
113 | + } |
|
114 | + |
|
115 | + break; |
|
116 | + case $this::FEED_RSS: |
|
117 | + $title = $xpath->query("//channel/title")->item(0); |
|
118 | + |
|
119 | + if ($title) { |
|
120 | + $this->title = $title->nodeValue; |
|
121 | + } |
|
122 | + |
|
123 | + $link = $xpath->query("//channel/link")->item(0); |
|
124 | + |
|
125 | + if ($link) { |
|
126 | + if ($link->getAttribute("href")) |
|
127 | + $this->link = $link->getAttribute("href"); |
|
128 | + else if ($link->nodeValue) |
|
129 | + $this->link = $link->nodeValue; |
|
130 | + } |
|
131 | + |
|
132 | + $articles = $xpath->query("//channel/item"); |
|
133 | + |
|
134 | + foreach ($articles as $article) { |
|
135 | + array_push($this->items, new FeedItem_RSS($article, $this->doc, $this->xpath)); |
|
136 | + } |
|
137 | + |
|
138 | + break; |
|
139 | + case $this::FEED_RDF: |
|
140 | + $xpath->registerNamespace('rssfake', 'http://purl.org/rss/1.0/'); |
|
141 | + |
|
142 | + $title = $xpath->query("//rssfake:channel/rssfake:title")->item(0); |
|
143 | + |
|
144 | + if ($title) { |
|
145 | + $this->title = $title->nodeValue; |
|
146 | + } |
|
147 | + |
|
148 | + $link = $xpath->query("//rssfake:channel/rssfake:link")->item(0); |
|
149 | + |
|
150 | + if ($link) { |
|
151 | + $this->link = $link->nodeValue; |
|
152 | + } |
|
153 | + |
|
154 | + $articles = $xpath->query("//rssfake:item"); |
|
155 | + |
|
156 | + foreach ($articles as $article) { |
|
157 | + array_push($this->items, new FeedItem_RSS($article, $this->doc, $this->xpath)); |
|
158 | + } |
|
159 | + |
|
160 | + break; |
|
161 | + |
|
162 | + } |
|
163 | + |
|
164 | + if ($this->title) $this->title = trim($this->title); |
|
165 | + if ($this->link) $this->link = trim($this->link); |
|
166 | 166 | |
167 | - } else { |
|
168 | - if( !isset($this->error) ){ |
|
169 | - $this->error = "Unknown/unsupported feed type"; |
|
170 | - } |
|
171 | - return; |
|
172 | - } |
|
173 | - } |
|
167 | + } else { |
|
168 | + if( !isset($this->error) ){ |
|
169 | + $this->error = "Unknown/unsupported feed type"; |
|
170 | + } |
|
171 | + return; |
|
172 | + } |
|
173 | + } |
|
174 | 174 | |
175 | - public function format_error($error) { |
|
176 | - if ($error) { |
|
177 | - return sprintf("LibXML error %s at line %d (column %d): %s", |
|
178 | - $error->code, $error->line, $error->column, |
|
179 | - $error->message); |
|
180 | - } else { |
|
181 | - return ""; |
|
182 | - } |
|
183 | - } |
|
175 | + public function format_error($error) { |
|
176 | + if ($error) { |
|
177 | + return sprintf("LibXML error %s at line %d (column %d): %s", |
|
178 | + $error->code, $error->line, $error->column, |
|
179 | + $error->message); |
|
180 | + } else { |
|
181 | + return ""; |
|
182 | + } |
|
183 | + } |
|
184 | 184 | |
185 | - // libxml may have invalid unicode data in error messages |
|
186 | - public function error() { |
|
187 | - return UConverter::transcode($this->error, 'UTF-8', 'UTF-8'); |
|
188 | - } |
|
185 | + // libxml may have invalid unicode data in error messages |
|
186 | + public function error() { |
|
187 | + return UConverter::transcode($this->error, 'UTF-8', 'UTF-8'); |
|
188 | + } |
|
189 | 189 | |
190 | - // WARNING: may return invalid unicode data |
|
191 | - public function errors() { |
|
192 | - return $this->libxml_errors; |
|
193 | - } |
|
190 | + // WARNING: may return invalid unicode data |
|
191 | + public function errors() { |
|
192 | + return $this->libxml_errors; |
|
193 | + } |
|
194 | 194 | |
195 | - public function get_link() { |
|
196 | - return clean($this->link); |
|
197 | - } |
|
195 | + public function get_link() { |
|
196 | + return clean($this->link); |
|
197 | + } |
|
198 | 198 | |
199 | - public function get_title() { |
|
200 | - return clean($this->title); |
|
201 | - } |
|
202 | - |
|
203 | - public function get_items() { |
|
204 | - return $this->items; |
|
205 | - } |
|
206 | - |
|
207 | - public function get_links($rel) { |
|
208 | - $rv = array(); |
|
209 | - |
|
210 | - switch ($this->type) { |
|
211 | - case $this::FEED_ATOM: |
|
212 | - $links = $this->xpath->query("//atom:feed/atom:link"); |
|
213 | - |
|
214 | - foreach ($links as $link) { |
|
215 | - if (!$rel || $link->hasAttribute('rel') && $link->getAttribute('rel') == $rel) { |
|
216 | - array_push($rv, clean(trim($link->getAttribute('href')))); |
|
217 | - } |
|
218 | - } |
|
219 | - break; |
|
220 | - case $this::FEED_RSS: |
|
221 | - $links = $this->xpath->query("//atom:link"); |
|
222 | - |
|
223 | - foreach ($links as $link) { |
|
224 | - if (!$rel || $link->hasAttribute('rel') && $link->getAttribute('rel') == $rel) { |
|
225 | - array_push($rv, clean(trim($link->getAttribute('href')))); |
|
226 | - } |
|
227 | - } |
|
228 | - break; |
|
229 | - } |
|
230 | - |
|
231 | - return $rv; |
|
232 | - } |
|
199 | + public function get_title() { |
|
200 | + return clean($this->title); |
|
201 | + } |
|
202 | + |
|
203 | + public function get_items() { |
|
204 | + return $this->items; |
|
205 | + } |
|
206 | + |
|
207 | + public function get_links($rel) { |
|
208 | + $rv = array(); |
|
209 | + |
|
210 | + switch ($this->type) { |
|
211 | + case $this::FEED_ATOM: |
|
212 | + $links = $this->xpath->query("//atom:feed/atom:link"); |
|
213 | + |
|
214 | + foreach ($links as $link) { |
|
215 | + if (!$rel || $link->hasAttribute('rel') && $link->getAttribute('rel') == $rel) { |
|
216 | + array_push($rv, clean(trim($link->getAttribute('href')))); |
|
217 | + } |
|
218 | + } |
|
219 | + break; |
|
220 | + case $this::FEED_RSS: |
|
221 | + $links = $this->xpath->query("//atom:link"); |
|
222 | + |
|
223 | + foreach ($links as $link) { |
|
224 | + if (!$rel || $link->hasAttribute('rel') && $link->getAttribute('rel') == $rel) { |
|
225 | + array_push($rv, clean(trim($link->getAttribute('href')))); |
|
226 | + } |
|
227 | + } |
|
228 | + break; |
|
229 | + } |
|
230 | + |
|
231 | + return $rv; |
|
232 | + } |
|
233 | 233 | } |
@@ -26,8 +26,10 @@ discard block |
||
26 | 26 | if ($error) { |
27 | 27 | foreach (libxml_get_errors() as $error) { |
28 | 28 | if ($error->level == LIBXML_ERR_FATAL) { |
29 | - if(!isset($this->error)) //currently only the first error is reported |
|
29 | + if(!isset($this->error)) { |
|
30 | + //currently only the first error is reported |
|
30 | 31 | $this->error = $this->format_error($error); |
32 | + } |
|
31 | 33 | $this->libxml_errors [] = $this->format_error($error); |
32 | 34 | } |
33 | 35 | } |
@@ -80,8 +82,9 @@ discard block |
||
80 | 82 | |
81 | 83 | $title = $xpath->query("//atom:feed/atom:title")->item(0); |
82 | 84 | |
83 | - if (!$title) |
|
84 | - $title = $xpath->query("//atom03:feed/atom03:title")->item(0); |
|
85 | + if (!$title) { |
|
86 | + $title = $xpath->query("//atom03:feed/atom03:title")->item(0); |
|
87 | + } |
|
85 | 88 | |
86 | 89 | |
87 | 90 | if ($title) { |
@@ -90,14 +93,17 @@ discard block |
||
90 | 93 | |
91 | 94 | $link = $xpath->query("//atom:feed/atom:link[not(@rel)]")->item(0); |
92 | 95 | |
93 | - if (!$link) |
|
94 | - $link = $xpath->query("//atom:feed/atom:link[@rel='alternate']")->item(0); |
|
96 | + if (!$link) { |
|
97 | + $link = $xpath->query("//atom:feed/atom:link[@rel='alternate']")->item(0); |
|
98 | + } |
|
95 | 99 | |
96 | - if (!$link) |
|
97 | - $link = $xpath->query("//atom03:feed/atom03:link[not(@rel)]")->item(0); |
|
100 | + if (!$link) { |
|
101 | + $link = $xpath->query("//atom03:feed/atom03:link[not(@rel)]")->item(0); |
|
102 | + } |
|
98 | 103 | |
99 | - if (!$link) |
|
100 | - $link = $xpath->query("//atom03:feed/atom03:link[@rel='alternate']")->item(0); |
|
104 | + if (!$link) { |
|
105 | + $link = $xpath->query("//atom03:feed/atom03:link[@rel='alternate']")->item(0); |
|
106 | + } |
|
101 | 107 | |
102 | 108 | if ($link && $link->hasAttributes()) { |
103 | 109 | $this->link = $link->getAttribute("href"); |
@@ -105,8 +111,9 @@ discard block |
||
105 | 111 | |
106 | 112 | $articles = $xpath->query("//atom:entry"); |
107 | 113 | |
108 | - if (!$articles || $articles->length == 0) |
|
109 | - $articles = $xpath->query("//atom03:entry"); |
|
114 | + if (!$articles || $articles->length == 0) { |
|
115 | + $articles = $xpath->query("//atom03:entry"); |
|
116 | + } |
|
110 | 117 | |
111 | 118 | foreach ($articles as $article) { |
112 | 119 | array_push($this->items, new FeedItem_Atom($article, $this->doc, $this->xpath)); |
@@ -123,10 +130,11 @@ discard block |
||
123 | 130 | $link = $xpath->query("//channel/link")->item(0); |
124 | 131 | |
125 | 132 | if ($link) { |
126 | - if ($link->getAttribute("href")) |
|
127 | - $this->link = $link->getAttribute("href"); |
|
128 | - else if ($link->nodeValue) |
|
129 | - $this->link = $link->nodeValue; |
|
133 | + if ($link->getAttribute("href")) { |
|
134 | + $this->link = $link->getAttribute("href"); |
|
135 | + } else if ($link->nodeValue) { |
|
136 | + $this->link = $link->nodeValue; |
|
137 | + } |
|
130 | 138 | } |
131 | 139 | |
132 | 140 | $articles = $xpath->query("//channel/item"); |
@@ -161,8 +169,12 @@ discard block |
||
161 | 169 | |
162 | 170 | } |
163 | 171 | |
164 | - if ($this->title) $this->title = trim($this->title); |
|
165 | - if ($this->link) $this->link = trim($this->link); |
|
172 | + if ($this->title) { |
|
173 | + $this->title = trim($this->title); |
|
174 | + } |
|
175 | + if ($this->link) { |
|
176 | + $this->link = trim($this->link); |
|
177 | + } |
|
166 | 178 | |
167 | 179 | } else { |
168 | 180 | if( !isset($this->error) ){ |
@@ -95,10 +95,11 @@ discard block |
||
95 | 95 | |
96 | 96 | $count = getFeedUnread($i); |
97 | 97 | |
98 | - if ($i == 0 || $i == -1 || $i == -2) |
|
99 | - $auxctr = Feeds::getFeedArticles($i, false); |
|
100 | - else |
|
101 | - $auxctr = 0; |
|
98 | + if ($i == 0 || $i == -1 || $i == -2) { |
|
99 | + $auxctr = Feeds::getFeedArticles($i, false); |
|
100 | + } else { |
|
101 | + $auxctr = 0; |
|
102 | + } |
|
102 | 103 | |
103 | 104 | $cv = array("id" => $i, |
104 | 105 | "counter" => (int) $count, |
@@ -117,8 +118,9 @@ discard block |
||
117 | 118 | $cv = array("id" => PluginHost::pfeed_to_feed_id($feed['id']), |
118 | 119 | "counter" => $feed['sender']->get_unread($feed['id'])); |
119 | 120 | |
120 | - if (method_exists($feed['sender'], 'get_total')) |
|
121 | - $cv["auxcounter"] = $feed['sender']->get_total($feed['id']); |
|
121 | + if (method_exists($feed['sender'], 'get_total')) { |
|
122 | + $cv["auxcounter"] = $feed['sender']->get_total($feed['id']); |
|
123 | + } |
|
122 | 124 | |
123 | 125 | array_push($ret_arr, $cv); |
124 | 126 | } |
@@ -150,8 +152,9 @@ discard block |
||
150 | 152 | "counter" => (int) $line["unread"], |
151 | 153 | "auxcounter" => (int) $line["total"]); |
152 | 154 | |
153 | - if ($descriptions) |
|
154 | - $cv["description"] = $line["caption"]; |
|
155 | + if ($descriptions) { |
|
156 | + $cv["description"] = $line["caption"]; |
|
157 | + } |
|
155 | 158 | |
156 | 159 | array_push($ret_arr, $cv); |
157 | 160 | } |
@@ -189,22 +192,25 @@ discard block |
||
189 | 192 | $has_img = false; |
190 | 193 | } |
191 | 194 | |
192 | - if (date('Y') - date('Y', strtotime($line['last_updated'])) > 2) |
|
193 | - $last_updated = ''; |
|
195 | + if (date('Y') - date('Y', strtotime($line['last_updated'])) > 2) { |
|
196 | + $last_updated = ''; |
|
197 | + } |
|
194 | 198 | |
195 | 199 | $cv = array("id" => $id, |
196 | 200 | "updated" => $last_updated, |
197 | 201 | "counter" => (int) $count, |
198 | 202 | "has_img" => (int) $has_img); |
199 | 203 | |
200 | - if ($last_error) |
|
201 | - $cv["error"] = $last_error; |
|
204 | + if ($last_error) { |
|
205 | + $cv["error"] = $last_error; |
|
206 | + } |
|
202 | 207 | |
203 | 208 | // if (get_pref('EXTENDED_FEEDLIST')) |
204 | 209 | // $cv["xmsg"] = getFeedArticles($id)." ".__("total"); |
205 | 210 | |
206 | - if ($active_feed && $id == $active_feed) |
|
207 | - $cv["title"] = truncate_string($line["title"], 30); |
|
211 | + if ($active_feed && $id == $active_feed) { |
|
212 | + $cv["title"] = truncate_string($line["title"], 30); |
|
213 | + } |
|
208 | 214 | |
209 | 215 | array_push($ret_arr, $cv); |
210 | 216 |
@@ -1,171 +1,171 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | class Counters { |
3 | 3 | |
4 | - public static function getAllCounters() { |
|
5 | - $data = Counters::getGlobalCounters(); |
|
4 | + public static function getAllCounters() { |
|
5 | + $data = Counters::getGlobalCounters(); |
|
6 | 6 | |
7 | - $data = array_merge($data, Counters::getVirtCounters()); |
|
8 | - $data = array_merge($data, Counters::getLabelCounters()); |
|
9 | - $data = array_merge($data, Counters::getFeedCounters()); |
|
10 | - $data = array_merge($data, Counters::getCategoryCounters()); |
|
7 | + $data = array_merge($data, Counters::getVirtCounters()); |
|
8 | + $data = array_merge($data, Counters::getLabelCounters()); |
|
9 | + $data = array_merge($data, Counters::getFeedCounters()); |
|
10 | + $data = array_merge($data, Counters::getCategoryCounters()); |
|
11 | 11 | |
12 | - return $data; |
|
13 | - } |
|
12 | + return $data; |
|
13 | + } |
|
14 | 14 | |
15 | - public static function getCategoryCounters() { |
|
16 | - $ret_arr = array(); |
|
15 | + public static function getCategoryCounters() { |
|
16 | + $ret_arr = array(); |
|
17 | 17 | |
18 | - /* Labels category */ |
|
18 | + /* Labels category */ |
|
19 | 19 | |
20 | - $cv = array("id" => -2, "kind" => "cat", |
|
21 | - "counter" => Feeds::getCategoryUnread(-2)); |
|
20 | + $cv = array("id" => -2, "kind" => "cat", |
|
21 | + "counter" => Feeds::getCategoryUnread(-2)); |
|
22 | 22 | |
23 | - array_push($ret_arr, $cv); |
|
23 | + array_push($ret_arr, $cv); |
|
24 | 24 | |
25 | - $pdo = DB::pdo(); |
|
25 | + $pdo = DB::pdo(); |
|
26 | 26 | |
27 | - $sth = $pdo->prepare("SELECT ttrss_feed_categories.id AS cat_id, value AS unread, |
|
27 | + $sth = $pdo->prepare("SELECT ttrss_feed_categories.id AS cat_id, value AS unread, |
|
28 | 28 | (SELECT COUNT(id) FROM ttrss_feed_categories AS c2 |
29 | 29 | WHERE c2.parent_cat = ttrss_feed_categories.id) AS num_children |
30 | 30 | FROM ttrss_feed_categories, ttrss_cat_counters_cache |
31 | 31 | WHERE ttrss_cat_counters_cache.feed_id = ttrss_feed_categories.id AND |
32 | 32 | ttrss_cat_counters_cache.owner_uid = ttrss_feed_categories.owner_uid AND |
33 | 33 | ttrss_feed_categories.owner_uid = ?"); |
34 | - $sth->execute([$_SESSION['uid']]); |
|
34 | + $sth->execute([$_SESSION['uid']]); |
|
35 | 35 | |
36 | - while ($line = $sth->fetch()) { |
|
37 | - $line["cat_id"] = (int) $line["cat_id"]; |
|
36 | + while ($line = $sth->fetch()) { |
|
37 | + $line["cat_id"] = (int) $line["cat_id"]; |
|
38 | 38 | |
39 | - if ($line["num_children"] > 0) { |
|
40 | - $child_counter = Feeds::getCategoryChildrenUnread($line["cat_id"], $_SESSION["uid"]); |
|
41 | - } else { |
|
42 | - $child_counter = 0; |
|
43 | - } |
|
39 | + if ($line["num_children"] > 0) { |
|
40 | + $child_counter = Feeds::getCategoryChildrenUnread($line["cat_id"], $_SESSION["uid"]); |
|
41 | + } else { |
|
42 | + $child_counter = 0; |
|
43 | + } |
|
44 | 44 | |
45 | - $cv = array("id" => $line["cat_id"], "kind" => "cat", |
|
46 | - "counter" => $line["unread"] + $child_counter); |
|
45 | + $cv = array("id" => $line["cat_id"], "kind" => "cat", |
|
46 | + "counter" => $line["unread"] + $child_counter); |
|
47 | 47 | |
48 | - array_push($ret_arr, $cv); |
|
49 | - } |
|
48 | + array_push($ret_arr, $cv); |
|
49 | + } |
|
50 | 50 | |
51 | - /* Special case: NULL category doesn't actually exist in the DB */ |
|
51 | + /* Special case: NULL category doesn't actually exist in the DB */ |
|
52 | 52 | |
53 | - $cv = array("id" => 0, "kind" => "cat", |
|
54 | - "counter" => (int) CCache::find(0, $_SESSION["uid"], true)); |
|
53 | + $cv = array("id" => 0, "kind" => "cat", |
|
54 | + "counter" => (int) CCache::find(0, $_SESSION["uid"], true)); |
|
55 | 55 | |
56 | - array_push($ret_arr, $cv); |
|
56 | + array_push($ret_arr, $cv); |
|
57 | 57 | |
58 | - return $ret_arr; |
|
59 | - } |
|
58 | + return $ret_arr; |
|
59 | + } |
|
60 | 60 | |
61 | - public static function getGlobalCounters($global_unread = -1) { |
|
62 | - $ret_arr = array(); |
|
61 | + public static function getGlobalCounters($global_unread = -1) { |
|
62 | + $ret_arr = array(); |
|
63 | 63 | |
64 | - if ($global_unread == -1) { |
|
65 | - $global_unread = Feeds::getGlobalUnread(); |
|
66 | - } |
|
64 | + if ($global_unread == -1) { |
|
65 | + $global_unread = Feeds::getGlobalUnread(); |
|
66 | + } |
|
67 | 67 | |
68 | - $cv = array("id" => "global-unread", |
|
69 | - "counter" => (int) $global_unread); |
|
68 | + $cv = array("id" => "global-unread", |
|
69 | + "counter" => (int) $global_unread); |
|
70 | 70 | |
71 | - array_push($ret_arr, $cv); |
|
71 | + array_push($ret_arr, $cv); |
|
72 | 72 | |
73 | - $pdo = Db::pdo(); |
|
73 | + $pdo = Db::pdo(); |
|
74 | 74 | |
75 | - $sth = $pdo->prepare("SELECT COUNT(id) AS fn FROM |
|
75 | + $sth = $pdo->prepare("SELECT COUNT(id) AS fn FROM |
|
76 | 76 | ttrss_feeds WHERE owner_uid = ?"); |
77 | - $sth->execute([$_SESSION['uid']]); |
|
78 | - $row = $sth->fetch(); |
|
77 | + $sth->execute([$_SESSION['uid']]); |
|
78 | + $row = $sth->fetch(); |
|
79 | 79 | |
80 | - $subscribed_feeds = $row["fn"]; |
|
80 | + $subscribed_feeds = $row["fn"]; |
|
81 | 81 | |
82 | - $cv = array("id" => "subscribed-feeds", |
|
83 | - "counter" => (int) $subscribed_feeds); |
|
82 | + $cv = array("id" => "subscribed-feeds", |
|
83 | + "counter" => (int) $subscribed_feeds); |
|
84 | 84 | |
85 | - array_push($ret_arr, $cv); |
|
85 | + array_push($ret_arr, $cv); |
|
86 | 86 | |
87 | - return $ret_arr; |
|
88 | - } |
|
87 | + return $ret_arr; |
|
88 | + } |
|
89 | 89 | |
90 | - public static function getVirtCounters() { |
|
90 | + public static function getVirtCounters() { |
|
91 | 91 | |
92 | - $ret_arr = array(); |
|
92 | + $ret_arr = array(); |
|
93 | 93 | |
94 | - for ($i = 0; $i >= -4; $i--) { |
|
94 | + for ($i = 0; $i >= -4; $i--) { |
|
95 | 95 | |
96 | - $count = getFeedUnread($i); |
|
96 | + $count = getFeedUnread($i); |
|
97 | 97 | |
98 | - if ($i == 0 || $i == -1 || $i == -2) |
|
99 | - $auxctr = Feeds::getFeedArticles($i, false); |
|
100 | - else |
|
101 | - $auxctr = 0; |
|
98 | + if ($i == 0 || $i == -1 || $i == -2) |
|
99 | + $auxctr = Feeds::getFeedArticles($i, false); |
|
100 | + else |
|
101 | + $auxctr = 0; |
|
102 | 102 | |
103 | - $cv = array("id" => $i, |
|
104 | - "counter" => (int) $count, |
|
105 | - "auxcounter" => (int) $auxctr); |
|
103 | + $cv = array("id" => $i, |
|
104 | + "counter" => (int) $count, |
|
105 | + "auxcounter" => (int) $auxctr); |
|
106 | 106 | |
107 | 107 | // if (get_pref('EXTENDED_FEEDLIST')) |
108 | 108 | // $cv["xmsg"] = getFeedArticles($i)." ".__("total"); |
109 | 109 | |
110 | - array_push($ret_arr, $cv); |
|
111 | - } |
|
110 | + array_push($ret_arr, $cv); |
|
111 | + } |
|
112 | 112 | |
113 | - $feeds = PluginHost::getInstance()->get_feeds(-1); |
|
113 | + $feeds = PluginHost::getInstance()->get_feeds(-1); |
|
114 | 114 | |
115 | - if (is_array($feeds)) { |
|
116 | - foreach ($feeds as $feed) { |
|
117 | - $cv = array("id" => PluginHost::pfeed_to_feed_id($feed['id']), |
|
118 | - "counter" => $feed['sender']->get_unread($feed['id'])); |
|
115 | + if (is_array($feeds)) { |
|
116 | + foreach ($feeds as $feed) { |
|
117 | + $cv = array("id" => PluginHost::pfeed_to_feed_id($feed['id']), |
|
118 | + "counter" => $feed['sender']->get_unread($feed['id'])); |
|
119 | 119 | |
120 | - if (method_exists($feed['sender'], 'get_total')) |
|
121 | - $cv["auxcounter"] = $feed['sender']->get_total($feed['id']); |
|
120 | + if (method_exists($feed['sender'], 'get_total')) |
|
121 | + $cv["auxcounter"] = $feed['sender']->get_total($feed['id']); |
|
122 | 122 | |
123 | - array_push($ret_arr, $cv); |
|
124 | - } |
|
125 | - } |
|
123 | + array_push($ret_arr, $cv); |
|
124 | + } |
|
125 | + } |
|
126 | 126 | |
127 | - return $ret_arr; |
|
128 | - } |
|
127 | + return $ret_arr; |
|
128 | + } |
|
129 | 129 | |
130 | - public static function getLabelCounters($descriptions = false) { |
|
130 | + public static function getLabelCounters($descriptions = false) { |
|
131 | 131 | |
132 | - $ret_arr = array(); |
|
132 | + $ret_arr = array(); |
|
133 | 133 | |
134 | - $pdo = Db::pdo(); |
|
134 | + $pdo = Db::pdo(); |
|
135 | 135 | |
136 | - $sth = $pdo->prepare("SELECT id,caption,SUM(CASE WHEN u1.unread = true THEN 1 ELSE 0 END) AS unread, COUNT(u1.unread) AS total |
|
136 | + $sth = $pdo->prepare("SELECT id,caption,SUM(CASE WHEN u1.unread = true THEN 1 ELSE 0 END) AS unread, COUNT(u1.unread) AS total |
|
137 | 137 | FROM ttrss_labels2 LEFT JOIN ttrss_user_labels2 ON |
138 | 138 | (ttrss_labels2.id = label_id) |
139 | 139 | LEFT JOIN ttrss_user_entries AS u1 ON u1.ref_id = article_id |
140 | 140 | WHERE ttrss_labels2.owner_uid = :uid AND u1.owner_uid = :uid |
141 | 141 | GROUP BY ttrss_labels2.id, |
142 | 142 | ttrss_labels2.caption"); |
143 | - $sth->execute([":uid" => $_SESSION['uid']]); |
|
143 | + $sth->execute([":uid" => $_SESSION['uid']]); |
|
144 | 144 | |
145 | - while ($line = $sth->fetch()) { |
|
145 | + while ($line = $sth->fetch()) { |
|
146 | 146 | |
147 | - $id = Labels::label_to_feed_id($line["id"]); |
|
147 | + $id = Labels::label_to_feed_id($line["id"]); |
|
148 | 148 | |
149 | - $cv = array("id" => $id, |
|
150 | - "counter" => (int) $line["unread"], |
|
151 | - "auxcounter" => (int) $line["total"]); |
|
149 | + $cv = array("id" => $id, |
|
150 | + "counter" => (int) $line["unread"], |
|
151 | + "auxcounter" => (int) $line["total"]); |
|
152 | 152 | |
153 | - if ($descriptions) |
|
154 | - $cv["description"] = $line["caption"]; |
|
153 | + if ($descriptions) |
|
154 | + $cv["description"] = $line["caption"]; |
|
155 | 155 | |
156 | - array_push($ret_arr, $cv); |
|
157 | - } |
|
156 | + array_push($ret_arr, $cv); |
|
157 | + } |
|
158 | 158 | |
159 | - return $ret_arr; |
|
160 | - } |
|
159 | + return $ret_arr; |
|
160 | + } |
|
161 | 161 | |
162 | - public static function getFeedCounters($active_feed = false) { |
|
162 | + public static function getFeedCounters($active_feed = false) { |
|
163 | 163 | |
164 | - $ret_arr = array(); |
|
164 | + $ret_arr = array(); |
|
165 | 165 | |
166 | - $pdo = Db::pdo(); |
|
166 | + $pdo = Db::pdo(); |
|
167 | 167 | |
168 | - $sth = $pdo->prepare("SELECT ttrss_feeds.id, |
|
168 | + $sth = $pdo->prepare("SELECT ttrss_feeds.id, |
|
169 | 169 | ttrss_feeds.title, |
170 | 170 | ".SUBSTRING_FOR_DATE."(ttrss_feeds.last_updated,1,19) AS last_updated, |
171 | 171 | last_error, value AS count |
@@ -173,44 +173,44 @@ discard block |
||
173 | 173 | WHERE ttrss_feeds.owner_uid = ? |
174 | 174 | AND ttrss_counters_cache.owner_uid = ttrss_feeds.owner_uid |
175 | 175 | AND ttrss_counters_cache.feed_id = ttrss_feeds.id"); |
176 | - $sth->execute([$_SESSION['uid']]); |
|
176 | + $sth->execute([$_SESSION['uid']]); |
|
177 | 177 | |
178 | - while ($line = $sth->fetch()) { |
|
178 | + while ($line = $sth->fetch()) { |
|
179 | 179 | |
180 | - $id = $line["id"]; |
|
181 | - $count = $line["count"]; |
|
182 | - $last_error = htmlspecialchars($line["last_error"]); |
|
180 | + $id = $line["id"]; |
|
181 | + $count = $line["count"]; |
|
182 | + $last_error = htmlspecialchars($line["last_error"]); |
|
183 | 183 | |
184 | - $last_updated = make_local_datetime($line['last_updated'], false); |
|
184 | + $last_updated = make_local_datetime($line['last_updated'], false); |
|
185 | 185 | |
186 | - if (Feeds::feedHasIcon($id)) { |
|
187 | - $has_img = filemtime(Feeds::getIconFile($id)); |
|
188 | - } else { |
|
189 | - $has_img = false; |
|
190 | - } |
|
186 | + if (Feeds::feedHasIcon($id)) { |
|
187 | + $has_img = filemtime(Feeds::getIconFile($id)); |
|
188 | + } else { |
|
189 | + $has_img = false; |
|
190 | + } |
|
191 | 191 | |
192 | - if (date('Y') - date('Y', strtotime($line['last_updated'])) > 2) |
|
193 | - $last_updated = ''; |
|
192 | + if (date('Y') - date('Y', strtotime($line['last_updated'])) > 2) |
|
193 | + $last_updated = ''; |
|
194 | 194 | |
195 | - $cv = array("id" => $id, |
|
196 | - "updated" => $last_updated, |
|
197 | - "counter" => (int) $count, |
|
198 | - "has_img" => (int) $has_img); |
|
195 | + $cv = array("id" => $id, |
|
196 | + "updated" => $last_updated, |
|
197 | + "counter" => (int) $count, |
|
198 | + "has_img" => (int) $has_img); |
|
199 | 199 | |
200 | - if ($last_error) |
|
201 | - $cv["error"] = $last_error; |
|
200 | + if ($last_error) |
|
201 | + $cv["error"] = $last_error; |
|
202 | 202 | |
203 | 203 | // if (get_pref('EXTENDED_FEEDLIST')) |
204 | 204 | // $cv["xmsg"] = getFeedArticles($id)." ".__("total"); |
205 | 205 | |
206 | - if ($active_feed && $id == $active_feed) |
|
207 | - $cv["title"] = truncate_string($line["title"], 30); |
|
206 | + if ($active_feed && $id == $active_feed) |
|
207 | + $cv["title"] = truncate_string($line["title"], 30); |
|
208 | 208 | |
209 | - array_push($ret_arr, $cv); |
|
209 | + array_push($ret_arr, $cv); |
|
210 | 210 | |
211 | - } |
|
211 | + } |
|
212 | 212 | |
213 | - return $ret_arr; |
|
214 | - } |
|
213 | + return $ret_arr; |
|
214 | + } |
|
215 | 215 | |
216 | 216 | } |